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