1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: connctr.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #pragma warning(disable:4100)
33 #include <soldep/connctr.hxx>
34 #include <soldep/objwin.hxx>
35 #include <soldep/depwin.hxx>
38 BOOL
Connector::msbHideMode
= FALSE
;
40 Connector::Connector( DepWin
* pParent
, WinBits nWinStyle
) :
50 mpParent
->AddConnector( this );
53 Connector::~Connector()
56 mpStartWin
->RemoveConnector( this );
58 mpEndWin
->RemoveConnector( this );
60 mpParent
->RemoveConnector( this );
61 mpParent
->Invalidate( Rectangle( mStart
, mEnd
));
62 mpParent
->Invalidate( Rectangle( mEnd
- Point( 3, 3), mEnd
+ Point( 3, 3)));
65 void Connector::Initialize( ObjectWin
* pStartWin
, ObjectWin
* pEndWin
, BOOL bVis
)
67 mpStartWin
= pStartWin
;
69 mpStartWin
->AddConnector( this );
70 mpEndWin
->AddConnector( this );
71 mCenter
= GetMiddle();
72 mStart
= pStartWin
->GetFixPoint( mCenter
);
73 mEnd
= pEndWin
->GetFixPoint( mCenter
);
74 mnStartId
= pStartWin
->GetId();
75 mnEndId
= pEndWin
->GetId();
78 // if ( mpParent->IsPaintEnabled())
81 mpParent
->DrawLine( mEnd
, mStart
);
82 mpParent
->DrawEllipse( Rectangle( mEnd
- Point( 2, 2), mEnd
+ Point( 2, 2)));
84 UpdateVisibility(); //null_Project
87 void Connector::UpdateVisibility()
89 bVisible
= mpStartWin
->IsVisible() && mpEndWin
->IsVisible();
93 Point
Connector::GetMiddle()
95 Point aStartPoint
= mpStartWin
->GetPosPixel();
96 Size aStartSize
= mpStartWin
->GetSizePixel();
97 int nMoveHorz
, nMoveVert
;
98 aStartPoint
.Move( aStartSize
.Width() / 2, aStartSize
.Height() / 2 );
100 Point aEndPoint
= mpEndWin
->GetPosPixel();
101 Size aEndSize
= mpEndWin
->GetSizePixel();
103 aEndPoint
.Move( aEndSize
.Width() / 2, aEndSize
.Height() / 2 );
105 Point aRetPoint
= aEndPoint
;
107 nMoveHorz
= aStartPoint
.X() - aEndPoint
.X();
110 nMoveVert
= aStartPoint
.Y() - aEndPoint
.Y();
113 aRetPoint
.Move( nMoveHorz
, nMoveVert
);
118 void Connector::Paint( const Rectangle
& rRect
)
120 //MyApp *pApp = (MyApp*)GetpApp();
121 //SolDep *pSoldep = pApp->GetSolDep();
124 if (!(mpStartWin
->IsNullObject())) //null_project
126 if ( mpStartWin
->GetMarkMode() == 0 || mpStartWin
->GetMarkMode() == MARKMODE_DEPENDING
)
128 mpStartWin
->SetViewMask(0); //objwin invisible
131 mpStartWin
->SetViewMask(1); //objwin visible
134 if (!(mpEndWin
->IsNullObject()))
136 if ( mpEndWin
->GetMarkMode() == 0 || mpEndWin
->GetMarkMode() == MARKMODE_DEPENDING
)
138 mpEndWin
->SetViewMask(0); //objwin invisible
141 mpEndWin
->SetViewMask(1); //objwin visible
148 if (!(mpStartWin
->IsNullObject())) //null_project
150 mpStartWin
->SetViewMask(1);
152 if (!(mpEndWin
->IsNullObject())) //null_project
154 mpEndWin
->SetViewMask(1);
158 if ( (mpStartWin
->GetBodyText() != ByteString("null")) && //null_project
159 (mpEndWin
->GetBodyText() != ByteString("null")) && IsVisible()) //null_project
161 mpParent
->DrawLine( mEnd
, mStart
);
162 mpParent
->DrawEllipse( Rectangle( mEnd
- Point( 2, 2), mEnd
+ Point( 2, 2)));
166 void Connector::DrawOutput( OutputDevice
* pDevice
, const Point
& rOffset
)
168 if ( (mpStartWin
->GetBodyText() != ByteString("null")) && //null_project
169 (mpEndWin
->GetBodyText() != ByteString("null")) && IsVisible()) //null_project
171 pDevice
->DrawLine( pDevice
->PixelToLogic( mEnd
) - rOffset
, pDevice
->PixelToLogic( mStart
) - rOffset
);
172 Rectangle
aRect( pDevice
->PixelToLogic( Rectangle( mEnd
- Point( 2, 2), mEnd
+ Point( 2, 2) ) ) );
173 aRect
.Move( -rOffset
.X(), -rOffset
.Y() );
174 pDevice
->DrawEllipse( aRect
);
178 void Connector::UpdatePosition( ObjectWin
* pWin
, BOOL bPaint
)
180 // more than one call ?
182 Point OldStart
, OldEnd
;
183 static ULONG nCallCount
= 0;
185 //MyApp *pApp = (MyApp*)GetpApp();
186 //SolDep *pSoldep = pApp->GetSolDep();
190 if ( nCallCount
) // only one call
202 mCenter
= GetMiddle();
203 mStart
=mpStartWin
->GetFixPoint( mCenter
, bPaint
);
204 mEnd
=mpEndWin
->GetFixPoint( mCenter
, bPaint
);
207 mpParent
->Invalidate( Rectangle( OldStart
, OldEnd
));
208 mpParent
->Invalidate( Rectangle( OldEnd
- Point( 2, 2), OldEnd
+ Point( 2, 2)));
209 //Don't paint "null_project" connectors
210 if ( (mpStartWin
->GetBodyText() != ByteString("null")) && //null_project
211 (mpEndWin
->GetBodyText() != ByteString("null"))) //null_project
213 Paint ( Rectangle( mEnd
- Point( 3, 3), mEnd
+ Point( 3, 3)));
214 Paint ( Rectangle( mEnd
, mStart
));
222 USHORT
Connector::Save( SvFileStream
& rOutFile
)
224 rOutFile
<< mpStartWin
->GetId();
225 rOutFile
<< mpEndWin
->GetId();
230 USHORT
Connector::Load( SvFileStream
& rInFile
)
232 rInFile
>> mnStartId
;
238 ObjectWin
* Connector::GetOtherWin( ObjectWin
* pWin
)
240 // get correspondent object ptr
241 if ( mpStartWin
== pWin
)
244 if ( mpEndWin
== pWin
)
250 ULONG
Connector::GetOtherId( ULONG nId
)
252 // get correspondent object id
253 if ( mnStartId
== nId
)
256 if ( mnEndId
== nId
)
262 ULONG
Connector::GetLen()
266 dx
= mStart
.X() - mEnd
.X();
267 dy
= mStart
.Y() - mEnd
.Y();
269 return (ULONG
) sqrt( dx
* dx
+ dy
* dy
);
272 BOOL
Connector::IsStart( ObjectWin
* pWin
)
274 return pWin
== mpStartWin
;