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 ************************************************************************/
28 #pragma warning(disable:4100)
30 #include <soldep/connctr.hxx>
31 #include <soldep/objwin.hxx>
32 #include <soldep/depwin.hxx>
35 sal_Bool
Connector::msbHideMode
= sal_False
;
37 Connector::Connector( DepWin
* pParent
, WinBits nWinStyle
) :
42 bVisible( sal_False
),
47 mpParent
->AddConnector( this );
50 Connector::~Connector()
53 mpStartWin
->RemoveConnector( this );
55 mpEndWin
->RemoveConnector( this );
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
;
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();
75 // if ( mpParent->IsPaintEnabled())
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();
107 nMoveVert
= aStartPoint
.Y() - aEndPoint
.Y();
110 aRetPoint
.Move( nMoveHorz
, nMoveVert
);
115 void Connector::Paint( const Rectangle
& rRect
)
117 //MyApp *pApp = (MyApp*)GetpApp();
118 //SolDep *pSoldep = pApp->GetSolDep();
121 if (!(mpStartWin
->IsNullObject())) //null_project
123 if ( mpStartWin
->GetMarkMode() == 0 || mpStartWin
->GetMarkMode() == MARKMODE_DEPENDING
)
125 mpStartWin
->SetViewMask(0); //objwin invisible
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
138 mpEndWin
->SetViewMask(1); //objwin visible
144 //bVisible = sal_True;
145 if (!(mpStartWin
->IsNullObject())) //null_project
147 mpStartWin
->SetViewMask(1);
149 if (!(mpEndWin
->IsNullObject())) //null_project
151 mpEndWin
->SetViewMask(1);
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();
187 if ( nCallCount
) // only one call
199 mCenter
= GetMiddle();
200 mStart
=mpStartWin
->GetFixPoint( mCenter
, bPaint
);
201 mEnd
=mpEndWin
->GetFixPoint( mCenter
, 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
));
219 sal_uInt16
Connector::Save( SvFileStream
& rOutFile
)
221 rOutFile
<< mpStartWin
->GetId();
222 rOutFile
<< mpEndWin
->GetId();
227 sal_uInt16
Connector::Load( SvFileStream
& rInFile
)
229 rInFile
>> mnStartId
;
235 ObjectWin
* Connector::GetOtherWin( ObjectWin
* pWin
)
237 // get correspondent object ptr
238 if ( mpStartWin
== pWin
)
241 if ( mpEndWin
== pWin
)
247 sal_uIntPtr
Connector::GetOtherId( sal_uIntPtr nId
)
249 // get correspondent object id
250 if ( mnStartId
== nId
)
253 if ( mnEndId
== nId
)
259 sal_uIntPtr
Connector::GetLen()
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
;