update dev300-m58
[ooovba.git] / soldep / source / connctr.cxx
blob0ce4f79b9720c6f1dd65608b65ba3a8c61538ccb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: connctr.cxx,v $
10 * $Revision: 1.6 $
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 ************************************************************************/
30 #ifdef _MSC_VER
31 #pragma warning(disable:4100)
32 #endif
33 #include <soldep/connctr.hxx>
34 #include <soldep/objwin.hxx>
35 #include <soldep/depwin.hxx>
36 #include "math.h"
38 BOOL Connector::msbHideMode = FALSE;
40 Connector::Connector( DepWin* pParent, WinBits nWinStyle ) :
41 mpStartWin( 0L ),
42 mpEndWin( 0L ),
43 mnStartId( 0 ),
44 mnEndId( 0 ),
45 bVisible( FALSE ),
46 len( 70 )
48 mpParent = pParent;
49 if ( mpParent )
50 mpParent->AddConnector( this );
53 Connector::~Connector()
55 if ( mpStartWin )
56 mpStartWin->RemoveConnector( this );
57 if ( mpEndWin )
58 mpEndWin->RemoveConnector( this );
59 if ( mpParent )
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;
68 mpEndWin = pEndWin;
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();
76 bVisible = bVis;
78 // if ( mpParent->IsPaintEnabled())
79 if ( IsVisible() )
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();
108 if ( nMoveHorz )
109 nMoveHorz /= 2;
110 nMoveVert = aStartPoint.Y() - aEndPoint.Y();
111 if ( nMoveVert )
112 nMoveVert /= 2;
113 aRetPoint.Move( nMoveHorz, nMoveVert );
114 return aRetPoint;
118 void Connector::Paint( const Rectangle& rRect )
120 //MyApp *pApp = (MyApp*)GetpApp();
121 //SolDep *pSoldep = pApp->GetSolDep();
122 if (msbHideMode)
124 if (!(mpStartWin->IsNullObject())) //null_project
126 if ( mpStartWin->GetMarkMode() == 0 || mpStartWin->GetMarkMode() == MARKMODE_DEPENDING )
128 mpStartWin->SetViewMask(0); //objwin invisible
129 } else
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
139 } else
141 mpEndWin->SetViewMask(1); //objwin visible
144 UpdateVisibility();
145 } else //IsHideMode
147 //bVisible = TRUE;
148 if (!(mpStartWin->IsNullObject())) //null_project
150 mpStartWin->SetViewMask(1);
152 if (!(mpEndWin->IsNullObject())) //null_project
154 mpEndWin->SetViewMask(1);
156 UpdateVisibility();
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();
187 if (msbHideMode)
188 bVisible = 1;
190 if ( nCallCount ) // only one call
191 nCallCount++;
192 else
194 nCallCount++;
195 while ( nCallCount )
197 if ( bPaint )
199 OldStart = mStart;
200 OldEnd = mEnd;
202 mCenter = GetMiddle();
203 mStart=mpStartWin->GetFixPoint( mCenter, bPaint );
204 mEnd=mpEndWin->GetFixPoint( mCenter, bPaint );
205 if ( 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 ));
217 nCallCount--;
222 USHORT Connector::Save( SvFileStream& rOutFile )
224 rOutFile << mpStartWin->GetId();
225 rOutFile << mpEndWin->GetId();
227 return 0;
230 USHORT Connector::Load( SvFileStream& rInFile )
232 rInFile >> mnStartId;
233 rInFile >> mnEndId;
235 return 0;
238 ObjectWin* Connector::GetOtherWin( ObjectWin* pWin )
240 // get correspondent object ptr
241 if ( mpStartWin == pWin )
242 return mpEndWin;
243 else
244 if ( mpEndWin == pWin )
245 return mpStartWin;
247 return NULL;
250 ULONG Connector::GetOtherId( ULONG nId )
252 // get correspondent object id
253 if ( mnStartId == nId )
254 return mnEndId;
255 else
256 if ( mnEndId == nId )
257 return mnStartId;
259 return NULL;
262 ULONG Connector::GetLen()
264 double dx, dy;
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;