xref: /aoo41x/main/soldep/source/connctr.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
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"
34 
35 sal_Bool Connector::msbHideMode = sal_False;
36 
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 )
44 {
45 	mpParent = pParent;
46 	if ( mpParent )
47 		mpParent->AddConnector( this );
48 }
49 
50 Connector::~Connector()
51 {
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)));
60 }
61 
62 void Connector::Initialize( ObjectWin* pStartWin, ObjectWin* pEndWin, sal_Bool bVis )
63 {
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;
74 
75 //	if ( mpParent->IsPaintEnabled())
76     if ( IsVisible() )
77 	{
78 		mpParent->DrawLine( mEnd, mStart );
79 		mpParent->DrawEllipse( Rectangle( mEnd - Point( 2, 2), mEnd + Point( 2, 2)));
80 	}
81 	UpdateVisibility(); //null_Project
82 }
83 
84 void Connector::UpdateVisibility()
85 {
86 	bVisible = mpStartWin->IsVisible() && mpEndWin->IsVisible();
87 }
88 
89 
90 Point Connector::GetMiddle()
91 {
92 	Point aStartPoint = mpStartWin->GetPosPixel();
93 	Size aStartSize = mpStartWin->GetSizePixel();
94 	int nMoveHorz, nMoveVert;
95 	aStartPoint.Move( aStartSize.Width() / 2, aStartSize.Height() / 2 );
96 
97 	Point aEndPoint = mpEndWin->GetPosPixel();
98 	Size aEndSize = mpEndWin->GetSizePixel();
99 
100 	aEndPoint.Move( aEndSize.Width() / 2, aEndSize.Height() / 2 );
101 
102 	Point aRetPoint = aEndPoint;
103 
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;
112 
113 }
114 
115 void Connector::Paint( const Rectangle& rRect )
116 {
117     //MyApp *pApp = (MyApp*)GetpApp();
118     //SolDep *pSoldep = pApp->GetSolDep();
119     if (msbHideMode)
120     {
121     if (!(mpStartWin->IsNullObject())) //null_project
122     {
123         if ( mpStartWin->GetMarkMode() == 0 || mpStartWin->GetMarkMode() == MARKMODE_DEPENDING )
124         {
125             mpStartWin->SetViewMask(0); //objwin invisible
126         } else
127         {
128             mpStartWin->SetViewMask(1); //objwin visible
129         }
130     }
131     if (!(mpEndWin->IsNullObject()))
132     {
133         if ( mpEndWin->GetMarkMode() == 0 || mpEndWin->GetMarkMode() == MARKMODE_DEPENDING )
134         {
135             mpEndWin->SetViewMask(0); //objwin invisible
136         } else
137         {
138             mpEndWin->SetViewMask(1); //objwin visible
139         }
140     }
141     UpdateVisibility();
142     } else //IsHideMode
143     {
144         //bVisible = sal_True;
145         if (!(mpStartWin->IsNullObject())) //null_project
146         {
147              mpStartWin->SetViewMask(1);
148         }
149         if (!(mpEndWin->IsNullObject())) //null_project
150         {
151              mpEndWin->SetViewMask(1);
152         }
153         UpdateVisibility();
154     }
155     if ( (mpStartWin->GetBodyText() != ByteString("null")) &&              //null_project
156          (mpEndWin->GetBodyText() != ByteString("null")) && IsVisible())  //null_project
157     {
158 		mpParent->DrawLine( mEnd, mStart );
159 		mpParent->DrawEllipse( Rectangle( mEnd - Point( 2, 2), mEnd + Point( 2, 2)));
160 	}
161 }
162 
163 void Connector::DrawOutput( OutputDevice* pDevice, const Point& rOffset )
164 {
165     if ( (mpStartWin->GetBodyText() != ByteString("null")) &&              //null_project
166          (mpEndWin->GetBodyText() != ByteString("null")) && IsVisible())  //null_project
167     {
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 );
172 	}
173 }
174 
175 void Connector::UpdatePosition( ObjectWin* pWin, sal_Bool bPaint )
176 {
177 //	more than one call ?
178 //
179 	Point OldStart, OldEnd;
180 	static sal_uIntPtr nCallCount = 0;
181 
182     //MyApp *pApp = (MyApp*)GetpApp();
183     //SolDep *pSoldep = pApp->GetSolDep();
184     if (msbHideMode)
185 	    bVisible = 1;
186 
187 	if ( nCallCount )           // only one call
188 		nCallCount++;
189 	else
190 	{
191 		nCallCount++;
192 		while ( nCallCount )
193 		{
194 			if ( bPaint )
195 			{
196 				OldStart = mStart;
197 				OldEnd = mEnd;
198 			}
199 			mCenter = GetMiddle();
200 			mStart=mpStartWin->GetFixPoint( mCenter, bPaint );
201 			mEnd=mpEndWin->GetFixPoint( mCenter, bPaint );
202 			if ( bPaint )
203 			{
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
209                 {
210 				    Paint ( Rectangle( mEnd - Point( 3, 3), mEnd + Point( 3, 3)));
211 				    Paint ( Rectangle( mEnd, mStart ));
212                 }
213 			}
214 			nCallCount--;
215 		}
216 	}
217 }
218 
219 sal_uInt16 Connector::Save( SvFileStream& rOutFile )
220 {
221 	rOutFile << mpStartWin->GetId();
222 	rOutFile << mpEndWin->GetId();
223 
224 	return 0;
225 }
226 
227 sal_uInt16 Connector::Load( SvFileStream& rInFile )
228 {
229 	rInFile >> mnStartId;
230 	rInFile >> mnEndId;
231 
232 	return 0;
233 }
234 
235 ObjectWin* Connector::GetOtherWin( ObjectWin* pWin )
236 {
237 // get correspondent object ptr
238 	if ( mpStartWin == pWin )
239 		return mpEndWin;
240 	else
241 		if ( mpEndWin == pWin )
242 			return mpStartWin;
243 
244 	return NULL;
245 }
246 
247 sal_uIntPtr Connector::GetOtherId( sal_uIntPtr nId )
248 {
249 // get correspondent object id
250 	if ( mnStartId == nId )
251 		return mnEndId;
252 	else
253 		if ( mnEndId == nId )
254 			return mnStartId;
255 
256 	return NULL;
257 }
258 
259 sal_uIntPtr Connector::GetLen()
260 {
261 	double dx, dy;
262 
263 	dx = mStart.X() - mEnd.X();
264 	dy = mStart.Y() - mEnd.Y();
265 
266 	return (sal_uIntPtr) sqrt( dx * dx + dy * dy );
267 }
268 
269 sal_Bool Connector::IsStart( ObjectWin* pWin )
270 {
271 	return pWin == mpStartWin;
272 }
273