merged tag ooo/DEV300_m102
[LibreOffice.git] / soldep / source / connctr.cxx
blobe8fba662cfb5b39fe72a93f8542652122f0a711c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 #ifdef _MSC_VER
28 #pragma warning(disable:4100)
29 #endif
30 #include <soldep/connctr.hxx>
31 #include <soldep/objwin.hxx>
32 #include <soldep/depwin.hxx>
33 #include "math.h"
35 sal_Bool Connector::msbHideMode = sal_False;
37 Connector::Connector( DepWin* pParent, WinBits nWinStyle ) :
38 mpStartWin( 0L ),
39 mpEndWin( 0L ),
40 mnStartId( 0 ),
41 mnEndId( 0 ),
42 bVisible( sal_False ),
43 len( 70 )
45 mpParent = pParent;
46 if ( mpParent )
47 mpParent->AddConnector( this );
50 Connector::~Connector()
52 if ( mpStartWin )
53 mpStartWin->RemoveConnector( this );
54 if ( mpEndWin )
55 mpEndWin->RemoveConnector( this );
56 if ( mpParent )
57 mpParent->RemoveConnector( this );
58 mpParent->Invalidate( Rectangle( mStart, mEnd ));
59 mpParent->Invalidate( Rectangle( mEnd - Point( 3, 3), mEnd + Point( 3, 3)));
62 void Connector::Initialize( ObjectWin* pStartWin, ObjectWin* pEndWin, sal_Bool bVis )
64 mpStartWin = pStartWin;
65 mpEndWin = pEndWin;
66 mpStartWin->AddConnector( this );
67 mpEndWin->AddConnector( this );
68 mCenter = GetMiddle();
69 mStart = pStartWin->GetFixPoint( mCenter );
70 mEnd = pEndWin->GetFixPoint( mCenter );
71 mnStartId = pStartWin->GetId();
72 mnEndId = pEndWin->GetId();
73 bVisible = bVis;
75 // if ( mpParent->IsPaintEnabled())
76 if ( IsVisible() )
78 mpParent->DrawLine( mEnd, mStart );
79 mpParent->DrawEllipse( Rectangle( mEnd - Point( 2, 2), mEnd + Point( 2, 2)));
81 UpdateVisibility(); //null_Project
84 void Connector::UpdateVisibility()
86 bVisible = mpStartWin->IsVisible() && mpEndWin->IsVisible();
90 Point Connector::GetMiddle()
92 Point aStartPoint = mpStartWin->GetPosPixel();
93 Size aStartSize = mpStartWin->GetSizePixel();
94 int nMoveHorz, nMoveVert;
95 aStartPoint.Move( aStartSize.Width() / 2, aStartSize.Height() / 2 );
97 Point aEndPoint = mpEndWin->GetPosPixel();
98 Size aEndSize = mpEndWin->GetSizePixel();
100 aEndPoint.Move( aEndSize.Width() / 2, aEndSize.Height() / 2 );
102 Point aRetPoint = aEndPoint;
104 nMoveHorz = aStartPoint.X() - aEndPoint.X();
105 if ( nMoveHorz )
106 nMoveHorz /= 2;
107 nMoveVert = aStartPoint.Y() - aEndPoint.Y();
108 if ( nMoveVert )
109 nMoveVert /= 2;
110 aRetPoint.Move( nMoveHorz, nMoveVert );
111 return aRetPoint;
115 void Connector::Paint( const Rectangle& rRect )
117 //MyApp *pApp = (MyApp*)GetpApp();
118 //SolDep *pSoldep = pApp->GetSolDep();
119 if (msbHideMode)
121 if (!(mpStartWin->IsNullObject())) //null_project
123 if ( mpStartWin->GetMarkMode() == 0 || mpStartWin->GetMarkMode() == MARKMODE_DEPENDING )
125 mpStartWin->SetViewMask(0); //objwin invisible
126 } else
128 mpStartWin->SetViewMask(1); //objwin visible
131 if (!(mpEndWin->IsNullObject()))
133 if ( mpEndWin->GetMarkMode() == 0 || mpEndWin->GetMarkMode() == MARKMODE_DEPENDING )
135 mpEndWin->SetViewMask(0); //objwin invisible
136 } else
138 mpEndWin->SetViewMask(1); //objwin visible
141 UpdateVisibility();
142 } else //IsHideMode
144 //bVisible = sal_True;
145 if (!(mpStartWin->IsNullObject())) //null_project
147 mpStartWin->SetViewMask(1);
149 if (!(mpEndWin->IsNullObject())) //null_project
151 mpEndWin->SetViewMask(1);
153 UpdateVisibility();
155 if ( (mpStartWin->GetBodyText() != ByteString("null")) && //null_project
156 (mpEndWin->GetBodyText() != ByteString("null")) && IsVisible()) //null_project
158 mpParent->DrawLine( mEnd, mStart );
159 mpParent->DrawEllipse( Rectangle( mEnd - Point( 2, 2), mEnd + Point( 2, 2)));
163 void Connector::DrawOutput( OutputDevice* pDevice, const Point& rOffset )
165 if ( (mpStartWin->GetBodyText() != ByteString("null")) && //null_project
166 (mpEndWin->GetBodyText() != ByteString("null")) && IsVisible()) //null_project
168 pDevice->DrawLine( pDevice->PixelToLogic( mEnd ) - rOffset, pDevice->PixelToLogic( mStart ) - rOffset );
169 Rectangle aRect( pDevice->PixelToLogic( Rectangle( mEnd - Point( 2, 2), mEnd + Point( 2, 2) ) ) );
170 aRect.Move( -rOffset.X(), -rOffset.Y() );
171 pDevice->DrawEllipse( aRect );
175 void Connector::UpdatePosition( ObjectWin* pWin, sal_Bool bPaint )
177 // more than one call ?
179 Point OldStart, OldEnd;
180 static sal_uIntPtr nCallCount = 0;
182 //MyApp *pApp = (MyApp*)GetpApp();
183 //SolDep *pSoldep = pApp->GetSolDep();
184 if (msbHideMode)
185 bVisible = 1;
187 if ( nCallCount ) // only one call
188 nCallCount++;
189 else
191 nCallCount++;
192 while ( nCallCount )
194 if ( bPaint )
196 OldStart = mStart;
197 OldEnd = mEnd;
199 mCenter = GetMiddle();
200 mStart=mpStartWin->GetFixPoint( mCenter, bPaint );
201 mEnd=mpEndWin->GetFixPoint( mCenter, bPaint );
202 if ( bPaint )
204 mpParent->Invalidate( Rectangle( OldStart, OldEnd ));
205 mpParent->Invalidate( Rectangle( OldEnd - Point( 2, 2), OldEnd + Point( 2, 2)));
206 //Don't paint "null_project" connectors
207 if ( (mpStartWin->GetBodyText() != ByteString("null")) && //null_project
208 (mpEndWin->GetBodyText() != ByteString("null"))) //null_project
210 Paint ( Rectangle( mEnd - Point( 3, 3), mEnd + Point( 3, 3)));
211 Paint ( Rectangle( mEnd, mStart ));
214 nCallCount--;
219 sal_uInt16 Connector::Save( SvFileStream& rOutFile )
221 rOutFile << mpStartWin->GetId();
222 rOutFile << mpEndWin->GetId();
224 return 0;
227 sal_uInt16 Connector::Load( SvFileStream& rInFile )
229 rInFile >> mnStartId;
230 rInFile >> mnEndId;
232 return 0;
235 ObjectWin* Connector::GetOtherWin( ObjectWin* pWin )
237 // get correspondent object ptr
238 if ( mpStartWin == pWin )
239 return mpEndWin;
240 else
241 if ( mpEndWin == pWin )
242 return mpStartWin;
244 return NULL;
247 sal_uIntPtr Connector::GetOtherId( sal_uIntPtr nId )
249 // get correspondent object id
250 if ( mnStartId == nId )
251 return mnEndId;
252 else
253 if ( mnEndId == nId )
254 return mnStartId;
256 return NULL;
259 sal_uIntPtr Connector::GetLen()
261 double dx, dy;
263 dx = mStart.X() - mEnd.X();
264 dy = mStart.Y() - mEnd.Y();
266 return (sal_uIntPtr) sqrt( dx * dx + dy * dy );
269 sal_Bool Connector::IsStart( ObjectWin* pWin )
271 return pWin == mpStartWin;