xref: /aoo41x/main/soldep/source/connctr.cxx (revision d9e04f7d)
1*d9e04f7dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d9e04f7dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d9e04f7dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d9e04f7dSAndrew Rist  * distributed with this work for additional information
6*d9e04f7dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d9e04f7dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d9e04f7dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d9e04f7dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d9e04f7dSAndrew Rist  *
11*d9e04f7dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d9e04f7dSAndrew Rist  *
13*d9e04f7dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d9e04f7dSAndrew Rist  * software distributed under the License is distributed on an
15*d9e04f7dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d9e04f7dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d9e04f7dSAndrew Rist  * specific language governing permissions and limitations
18*d9e04f7dSAndrew Rist  * under the License.
19*d9e04f7dSAndrew Rist  *
20*d9e04f7dSAndrew Rist  *************************************************************/
21*d9e04f7dSAndrew Rist 
22*d9e04f7dSAndrew Rist 
23cdf0e10cSrcweir #ifdef _MSC_VER
24cdf0e10cSrcweir #pragma warning(disable:4100)
25cdf0e10cSrcweir #endif
26cdf0e10cSrcweir #include <soldep/connctr.hxx>
27cdf0e10cSrcweir #include <soldep/objwin.hxx>
28cdf0e10cSrcweir #include <soldep/depwin.hxx>
29cdf0e10cSrcweir #include "math.h"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir sal_Bool Connector::msbHideMode = sal_False;
32cdf0e10cSrcweir 
Connector(DepWin * pParent,WinBits nWinStyle)33cdf0e10cSrcweir Connector::Connector( DepWin* pParent, WinBits nWinStyle ) :
34cdf0e10cSrcweir mpStartWin( 0L ),
35cdf0e10cSrcweir mpEndWin( 0L ),
36cdf0e10cSrcweir mnStartId( 0 ),
37cdf0e10cSrcweir mnEndId( 0 ),
38cdf0e10cSrcweir bVisible( sal_False ),
39cdf0e10cSrcweir len( 70 )
40cdf0e10cSrcweir {
41cdf0e10cSrcweir 	mpParent = pParent;
42cdf0e10cSrcweir 	if ( mpParent )
43cdf0e10cSrcweir 		mpParent->AddConnector( this );
44cdf0e10cSrcweir }
45cdf0e10cSrcweir 
~Connector()46cdf0e10cSrcweir Connector::~Connector()
47cdf0e10cSrcweir {
48cdf0e10cSrcweir 	if ( mpStartWin )
49cdf0e10cSrcweir 		mpStartWin->RemoveConnector( this );
50cdf0e10cSrcweir 	if ( mpEndWin )
51cdf0e10cSrcweir 		mpEndWin->RemoveConnector( this );
52cdf0e10cSrcweir 	if ( mpParent )
53cdf0e10cSrcweir 		mpParent->RemoveConnector( this );
54cdf0e10cSrcweir 	mpParent->Invalidate( Rectangle( mStart, mEnd ));
55cdf0e10cSrcweir 	mpParent->Invalidate( Rectangle( mEnd - Point( 3, 3), mEnd + Point( 3, 3)));
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
Initialize(ObjectWin * pStartWin,ObjectWin * pEndWin,sal_Bool bVis)58cdf0e10cSrcweir void Connector::Initialize( ObjectWin* pStartWin, ObjectWin* pEndWin, sal_Bool bVis )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir 	mpStartWin = pStartWin;
61cdf0e10cSrcweir 	mpEndWin = pEndWin;
62cdf0e10cSrcweir 	mpStartWin->AddConnector( this );
63cdf0e10cSrcweir 	mpEndWin->AddConnector( this );
64cdf0e10cSrcweir 	mCenter = GetMiddle();
65cdf0e10cSrcweir 	mStart = pStartWin->GetFixPoint( mCenter );
66cdf0e10cSrcweir 	mEnd = pEndWin->GetFixPoint( mCenter );
67cdf0e10cSrcweir 	mnStartId = pStartWin->GetId();
68cdf0e10cSrcweir 	mnEndId = pEndWin->GetId();
69cdf0e10cSrcweir     bVisible = bVis;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir //	if ( mpParent->IsPaintEnabled())
72cdf0e10cSrcweir     if ( IsVisible() )
73cdf0e10cSrcweir 	{
74cdf0e10cSrcweir 		mpParent->DrawLine( mEnd, mStart );
75cdf0e10cSrcweir 		mpParent->DrawEllipse( Rectangle( mEnd - Point( 2, 2), mEnd + Point( 2, 2)));
76cdf0e10cSrcweir 	}
77cdf0e10cSrcweir 	UpdateVisibility(); //null_Project
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
UpdateVisibility()80cdf0e10cSrcweir void Connector::UpdateVisibility()
81cdf0e10cSrcweir {
82cdf0e10cSrcweir 	bVisible = mpStartWin->IsVisible() && mpEndWin->IsVisible();
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
GetMiddle()86cdf0e10cSrcweir Point Connector::GetMiddle()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir 	Point aStartPoint = mpStartWin->GetPosPixel();
89cdf0e10cSrcweir 	Size aStartSize = mpStartWin->GetSizePixel();
90cdf0e10cSrcweir 	int nMoveHorz, nMoveVert;
91cdf0e10cSrcweir 	aStartPoint.Move( aStartSize.Width() / 2, aStartSize.Height() / 2 );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	Point aEndPoint = mpEndWin->GetPosPixel();
94cdf0e10cSrcweir 	Size aEndSize = mpEndWin->GetSizePixel();
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	aEndPoint.Move( aEndSize.Width() / 2, aEndSize.Height() / 2 );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	Point aRetPoint = aEndPoint;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 	nMoveHorz = aStartPoint.X() - aEndPoint.X();
101cdf0e10cSrcweir 	if ( nMoveHorz )
102cdf0e10cSrcweir 		nMoveHorz /= 2;
103cdf0e10cSrcweir 	nMoveVert = aStartPoint.Y() - aEndPoint.Y();
104cdf0e10cSrcweir 	if ( nMoveVert )
105cdf0e10cSrcweir 		nMoveVert /= 2;
106cdf0e10cSrcweir 	aRetPoint.Move( nMoveHorz, nMoveVert );
107cdf0e10cSrcweir 	return aRetPoint;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
Paint(const Rectangle & rRect)111cdf0e10cSrcweir void Connector::Paint( const Rectangle& rRect )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir     //MyApp *pApp = (MyApp*)GetpApp();
114cdf0e10cSrcweir     //SolDep *pSoldep = pApp->GetSolDep();
115cdf0e10cSrcweir     if (msbHideMode)
116cdf0e10cSrcweir     {
117cdf0e10cSrcweir     if (!(mpStartWin->IsNullObject())) //null_project
118cdf0e10cSrcweir     {
119cdf0e10cSrcweir         if ( mpStartWin->GetMarkMode() == 0 || mpStartWin->GetMarkMode() == MARKMODE_DEPENDING )
120cdf0e10cSrcweir         {
121cdf0e10cSrcweir             mpStartWin->SetViewMask(0); //objwin invisible
122cdf0e10cSrcweir         } else
123cdf0e10cSrcweir         {
124cdf0e10cSrcweir             mpStartWin->SetViewMask(1); //objwin visible
125cdf0e10cSrcweir         }
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir     if (!(mpEndWin->IsNullObject()))
128cdf0e10cSrcweir     {
129cdf0e10cSrcweir         if ( mpEndWin->GetMarkMode() == 0 || mpEndWin->GetMarkMode() == MARKMODE_DEPENDING )
130cdf0e10cSrcweir         {
131cdf0e10cSrcweir             mpEndWin->SetViewMask(0); //objwin invisible
132cdf0e10cSrcweir         } else
133cdf0e10cSrcweir         {
134cdf0e10cSrcweir             mpEndWin->SetViewMask(1); //objwin visible
135cdf0e10cSrcweir         }
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir     UpdateVisibility();
138cdf0e10cSrcweir     } else //IsHideMode
139cdf0e10cSrcweir     {
140cdf0e10cSrcweir         //bVisible = sal_True;
141cdf0e10cSrcweir         if (!(mpStartWin->IsNullObject())) //null_project
142cdf0e10cSrcweir         {
143cdf0e10cSrcweir              mpStartWin->SetViewMask(1);
144cdf0e10cSrcweir         }
145cdf0e10cSrcweir         if (!(mpEndWin->IsNullObject())) //null_project
146cdf0e10cSrcweir         {
147cdf0e10cSrcweir              mpEndWin->SetViewMask(1);
148cdf0e10cSrcweir         }
149cdf0e10cSrcweir         UpdateVisibility();
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir     if ( (mpStartWin->GetBodyText() != ByteString("null")) &&              //null_project
152cdf0e10cSrcweir          (mpEndWin->GetBodyText() != ByteString("null")) && IsVisible())  //null_project
153cdf0e10cSrcweir     {
154cdf0e10cSrcweir 		mpParent->DrawLine( mEnd, mStart );
155cdf0e10cSrcweir 		mpParent->DrawEllipse( Rectangle( mEnd - Point( 2, 2), mEnd + Point( 2, 2)));
156cdf0e10cSrcweir 	}
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
DrawOutput(OutputDevice * pDevice,const Point & rOffset)159cdf0e10cSrcweir void Connector::DrawOutput( OutputDevice* pDevice, const Point& rOffset )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir     if ( (mpStartWin->GetBodyText() != ByteString("null")) &&              //null_project
162cdf0e10cSrcweir          (mpEndWin->GetBodyText() != ByteString("null")) && IsVisible())  //null_project
163cdf0e10cSrcweir     {
164cdf0e10cSrcweir 		pDevice->DrawLine( pDevice->PixelToLogic( mEnd ) - rOffset, pDevice->PixelToLogic( mStart ) - rOffset );
165cdf0e10cSrcweir 		Rectangle aRect( pDevice->PixelToLogic( Rectangle( mEnd - Point( 2, 2), mEnd + Point( 2, 2) ) ) );
166cdf0e10cSrcweir 		aRect.Move( -rOffset.X(), -rOffset.Y() );
167cdf0e10cSrcweir 		pDevice->DrawEllipse( aRect );
168cdf0e10cSrcweir 	}
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
UpdatePosition(ObjectWin * pWin,sal_Bool bPaint)171cdf0e10cSrcweir void Connector::UpdatePosition( ObjectWin* pWin, sal_Bool bPaint )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir //	more than one call ?
174cdf0e10cSrcweir //
175cdf0e10cSrcweir 	Point OldStart, OldEnd;
176cdf0e10cSrcweir 	static sal_uIntPtr nCallCount = 0;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     //MyApp *pApp = (MyApp*)GetpApp();
179cdf0e10cSrcweir     //SolDep *pSoldep = pApp->GetSolDep();
180cdf0e10cSrcweir     if (msbHideMode)
181cdf0e10cSrcweir 	    bVisible = 1;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 	if ( nCallCount )           // only one call
184cdf0e10cSrcweir 		nCallCount++;
185cdf0e10cSrcweir 	else
186cdf0e10cSrcweir 	{
187cdf0e10cSrcweir 		nCallCount++;
188cdf0e10cSrcweir 		while ( nCallCount )
189cdf0e10cSrcweir 		{
190cdf0e10cSrcweir 			if ( bPaint )
191cdf0e10cSrcweir 			{
192cdf0e10cSrcweir 				OldStart = mStart;
193cdf0e10cSrcweir 				OldEnd = mEnd;
194cdf0e10cSrcweir 			}
195cdf0e10cSrcweir 			mCenter = GetMiddle();
196cdf0e10cSrcweir 			mStart=mpStartWin->GetFixPoint( mCenter, bPaint );
197cdf0e10cSrcweir 			mEnd=mpEndWin->GetFixPoint( mCenter, bPaint );
198cdf0e10cSrcweir 			if ( bPaint )
199cdf0e10cSrcweir 			{
200cdf0e10cSrcweir 				mpParent->Invalidate( Rectangle( OldStart, OldEnd ));
201cdf0e10cSrcweir 				mpParent->Invalidate( Rectangle( OldEnd - Point( 2, 2), OldEnd + Point( 2, 2)));
202cdf0e10cSrcweir //Don't paint "null_project" connectors
203cdf0e10cSrcweir                 if ( (mpStartWin->GetBodyText() != ByteString("null")) &&    			//null_project
204cdf0e10cSrcweir                      (mpEndWin->GetBodyText() != ByteString("null")))        			//null_project
205cdf0e10cSrcweir                 {
206cdf0e10cSrcweir 				    Paint ( Rectangle( mEnd - Point( 3, 3), mEnd + Point( 3, 3)));
207cdf0e10cSrcweir 				    Paint ( Rectangle( mEnd, mStart ));
208cdf0e10cSrcweir                 }
209cdf0e10cSrcweir 			}
210cdf0e10cSrcweir 			nCallCount--;
211cdf0e10cSrcweir 		}
212cdf0e10cSrcweir 	}
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
Save(SvFileStream & rOutFile)215cdf0e10cSrcweir sal_uInt16 Connector::Save( SvFileStream& rOutFile )
216cdf0e10cSrcweir {
217cdf0e10cSrcweir 	rOutFile << mpStartWin->GetId();
218cdf0e10cSrcweir 	rOutFile << mpEndWin->GetId();
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 	return 0;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
Load(SvFileStream & rInFile)223cdf0e10cSrcweir sal_uInt16 Connector::Load( SvFileStream& rInFile )
224cdf0e10cSrcweir {
225cdf0e10cSrcweir 	rInFile >> mnStartId;
226cdf0e10cSrcweir 	rInFile >> mnEndId;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 	return 0;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
GetOtherWin(ObjectWin * pWin)231cdf0e10cSrcweir ObjectWin* Connector::GetOtherWin( ObjectWin* pWin )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir // get correspondent object ptr
234cdf0e10cSrcweir 	if ( mpStartWin == pWin )
235cdf0e10cSrcweir 		return mpEndWin;
236cdf0e10cSrcweir 	else
237cdf0e10cSrcweir 		if ( mpEndWin == pWin )
238cdf0e10cSrcweir 			return mpStartWin;
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 	return NULL;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
GetOtherId(sal_uIntPtr nId)243cdf0e10cSrcweir sal_uIntPtr Connector::GetOtherId( sal_uIntPtr nId )
244cdf0e10cSrcweir {
245cdf0e10cSrcweir // get correspondent object id
246cdf0e10cSrcweir 	if ( mnStartId == nId )
247cdf0e10cSrcweir 		return mnEndId;
248cdf0e10cSrcweir 	else
249cdf0e10cSrcweir 		if ( mnEndId == nId )
250cdf0e10cSrcweir 			return mnStartId;
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 	return NULL;
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
GetLen()255cdf0e10cSrcweir sal_uIntPtr Connector::GetLen()
256cdf0e10cSrcweir {
257cdf0e10cSrcweir 	double dx, dy;
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 	dx = mStart.X() - mEnd.X();
260cdf0e10cSrcweir 	dy = mStart.Y() - mEnd.Y();
261cdf0e10cSrcweir 
262cdf0e10cSrcweir 	return (sal_uIntPtr) sqrt( dx * dx + dy * dy );
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
IsStart(ObjectWin * pWin)265cdf0e10cSrcweir sal_Bool Connector::IsStart( ObjectWin* pWin )
266cdf0e10cSrcweir {
267cdf0e10cSrcweir 	return pWin == mpStartWin;
268cdf0e10cSrcweir }
269