1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir #ifndef DBAUI_CONNECTIONLINE_HXX
27cdf0e10cSrcweir #include "ConnectionLine.hxx"
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #ifndef DBAUI_CONNECTIONLINEDATA_HXX
30cdf0e10cSrcweir #include "ConnectionLineData.hxx"
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #ifndef DBAUI_TABLEWINDOW_HXX
33cdf0e10cSrcweir #include "TableWindow.hxx"
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #ifndef DBAUI_TABLEWINDOWLISTBOX_HXX
36cdf0e10cSrcweir #include "TableWindowListBox.hxx"
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #ifndef DBAUI_TABLECONNECTION_HXX
39cdf0e10cSrcweir #include "TableConnection.hxx"
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX
42cdf0e10cSrcweir #include <vcl/svapp.hxx>
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir #ifndef _INC_MATH
45cdf0e10cSrcweir #include <math.h>
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
48cdf0e10cSrcweir #include <tools/debug.hxx>
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir #include <vcl/lineinfo.hxx>
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 
53cdf0e10cSrcweir using namespace dbaui;
54cdf0e10cSrcweir const long DESCRIPT_LINE_WIDTH = 15;
55cdf0e10cSrcweir const long HIT_SENSITIVE_RADIUS = 5;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir namespace
58cdf0e10cSrcweir {
59cdf0e10cSrcweir 	/** calcRect creates a new rectangle with the given points
60cdf0e10cSrcweir 			@param	_rBase		the base point
61cdf0e10cSrcweir 			@param	_aVector	the vector which will be added
62cdf0e10cSrcweir 	*/
calcRect(const Point & _rBase,const Point & _aVector)63cdf0e10cSrcweir 	inline Rectangle calcRect(const Point& _rBase,const Point& _aVector)
64cdf0e10cSrcweir 	{
65cdf0e10cSrcweir 		return Rectangle( _rBase - _aVector, _rBase + _aVector );
66cdf0e10cSrcweir 	}
67cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
68cdf0e10cSrcweir 	/** GetTextPos calculate the rectangle for the connection to be drawn
69cdf0e10cSrcweir 			@param	_pWin			the table window where to draw it
70cdf0e10cSrcweir 			@param	_aConnPos		the connection point
71cdf0e10cSrcweir 			@param	_aDescrLinePos	the description line pos
72cdf0e10cSrcweir 	*/
GetTextPos(const OTableWindow * _pWin,const Point & _aConnPos,const Point & _aDescrLinePos)73cdf0e10cSrcweir 	Rectangle GetTextPos(const OTableWindow* _pWin, const Point& _aConnPos,const Point& _aDescrLinePos)
74cdf0e10cSrcweir 	{
75cdf0e10cSrcweir 		OTableWindowListBox* pListBox = _pWin ? _pWin->GetListBox() : NULL;
76cdf0e10cSrcweir 		DBG_ASSERT(_pWin && pListBox, "OConnectionLine::GetSourceTextPos : invalid call !");
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 		Rectangle aReturn;
79cdf0e10cSrcweir 		if ( pListBox )
80cdf0e10cSrcweir 		{
81cdf0e10cSrcweir 			const long nRowHeight = pListBox->GetEntryHeight();
82cdf0e10cSrcweir 			aReturn.Top() = _aConnPos.Y() - nRowHeight;
83cdf0e10cSrcweir 			aReturn.Bottom() = aReturn.Top() + nRowHeight;
84cdf0e10cSrcweir 			if (_aDescrLinePos.X() < _aConnPos.X())
85cdf0e10cSrcweir 			{
86cdf0e10cSrcweir 				aReturn.Left() = _aDescrLinePos.X();
87cdf0e10cSrcweir 				aReturn.Right() = aReturn.Left() + _aConnPos.X() - _aDescrLinePos.X();
88cdf0e10cSrcweir 			}
89cdf0e10cSrcweir 			else
90cdf0e10cSrcweir 			{
91cdf0e10cSrcweir 				aReturn.Left() = _aConnPos.X();
92cdf0e10cSrcweir 				aReturn.Right() = aReturn.Left() + _aDescrLinePos.X() - _aConnPos.X();
93cdf0e10cSrcweir 			}
94cdf0e10cSrcweir 		}
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 		return aReturn;
97cdf0e10cSrcweir 	}
98cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
99cdf0e10cSrcweir 	/** calcPointsYValue calculate the points Y value in relation to the listbox entry
100cdf0e10cSrcweir 			@param	_pWin			the corresponding window
101cdf0e10cSrcweir 			@param	_pEntry			the source or dest entry
102cdf0e10cSrcweir 			@param	_rNewConPos		(in/out) the connection pos
103cdf0e10cSrcweir 			@param	_rNewDescrPos	(in/out) the description pos
104cdf0e10cSrcweir 	*/
calcPointsYValue(const OTableWindow * _pWin,SvLBoxEntry * _pEntry,Point & _rNewConPos,Point & _rNewDescrPos)105cdf0e10cSrcweir 	void calcPointsYValue(const OTableWindow* _pWin,SvLBoxEntry* _pEntry,Point& _rNewConPos,Point& _rNewDescrPos)
106cdf0e10cSrcweir 	{
107cdf0e10cSrcweir 		const OTableWindowListBox* pListBox = _pWin->GetListBox();
108cdf0e10cSrcweir 		_rNewConPos.Y() = _pWin->GetPosPixel().Y();
109cdf0e10cSrcweir         if ( _pEntry )
110cdf0e10cSrcweir         {
111cdf0e10cSrcweir             const long nRowHeight = pListBox->GetEntryHeight();
112cdf0e10cSrcweir 		    _rNewConPos.Y() += pListBox->GetPosPixel().Y();
113cdf0e10cSrcweir 		    long nEntryPos = pListBox->GetEntryPosition( _pEntry ).Y();
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 		    if( nEntryPos >= 0 )
116cdf0e10cSrcweir 		    {
117cdf0e10cSrcweir 			    _rNewConPos.Y() += nEntryPos;
118cdf0e10cSrcweir 			    _rNewConPos.Y() += (long)( 0.5 * nRowHeight );
119cdf0e10cSrcweir 		    }
120cdf0e10cSrcweir 		    else
121cdf0e10cSrcweir 			    _rNewConPos.Y() -= (long)( 0.5 * nRowHeight );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 		    long nListBoxBottom = _pWin->GetPosPixel().Y()
124cdf0e10cSrcweir 								    + pListBox->GetPosPixel().Y()
125cdf0e10cSrcweir 								    + pListBox->GetSizePixel().Height();
126cdf0e10cSrcweir 		    if( _rNewConPos.Y() > nListBoxBottom )
127cdf0e10cSrcweir 			    _rNewConPos.Y() = nListBoxBottom + 2;
128cdf0e10cSrcweir         }
129cdf0e10cSrcweir         else
130cdf0e10cSrcweir             _rNewConPos.Y() += static_cast<sal_Int32>(pListBox->GetPosPixel().Y()*0.5);
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 		_rNewDescrPos.Y() = _rNewConPos.Y();
133cdf0e10cSrcweir 	}
134cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir //========================================================================
138cdf0e10cSrcweir // class OConnectionLine
139cdf0e10cSrcweir //========================================================================
DBG_NAME(OConnectionLine)140cdf0e10cSrcweir DBG_NAME(OConnectionLine)
141cdf0e10cSrcweir //------------------------------------------------------------------------
142cdf0e10cSrcweir OConnectionLine::OConnectionLine( OTableConnection* _pConn, OConnectionLineDataRef _pLineData )
143cdf0e10cSrcweir 	: m_pTabConn( _pConn )
144cdf0e10cSrcweir 	 ,m_pData( _pLineData )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir 	DBG_CTOR(OConnectionLine,NULL);
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir //------------------------------------------------------------------------
OConnectionLine(const OConnectionLine & _rLine)150cdf0e10cSrcweir OConnectionLine::OConnectionLine( const OConnectionLine& _rLine )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir 	DBG_CTOR(OConnectionLine,NULL);
153cdf0e10cSrcweir 	m_pData = new OConnectionLineData( *_rLine.GetData() );
154cdf0e10cSrcweir 	*this = _rLine;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir //------------------------------------------------------------------------
~OConnectionLine()158cdf0e10cSrcweir OConnectionLine::~OConnectionLine()
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	DBG_DTOR(OConnectionLine,NULL);
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir //------------------------------------------------------------------------
operator =(const OConnectionLine & rLine)164cdf0e10cSrcweir OConnectionLine& OConnectionLine::operator=( const OConnectionLine& rLine )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir 	if( &rLine != this )
167cdf0e10cSrcweir 	{
168cdf0e10cSrcweir 		// da mir die Daten nicht gehoeren, loesche ich die alten nicht
169cdf0e10cSrcweir 		m_pData->CopyFrom(*rLine.GetData());
170cdf0e10cSrcweir 			// CopyFrom ist virtuell, damit ist es kein Problem, wenn m_pData von einem von OTableConnectionData abgeleiteten Typ ist
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 		m_pTabConn = rLine.m_pTabConn;
173cdf0e10cSrcweir 		m_aSourceConnPos = rLine.m_aSourceConnPos;
174cdf0e10cSrcweir 		m_aDestConnPos = rLine.m_aDestConnPos;
175cdf0e10cSrcweir 		m_aSourceDescrLinePos = rLine.m_aSourceDescrLinePos;
176cdf0e10cSrcweir 		m_aDestDescrLinePos = rLine.m_aDestDescrLinePos;
177cdf0e10cSrcweir 	}
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 	return *this;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir //------------------------------------------------------------------------
GetBoundingRect()183cdf0e10cSrcweir Rectangle OConnectionLine::GetBoundingRect()
184cdf0e10cSrcweir {
185cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
186cdf0e10cSrcweir 	// Umgebendes Rechteck bestimmen
187cdf0e10cSrcweir 	Rectangle aBoundingRect( Point(0,0), Point(0,0) );
188cdf0e10cSrcweir 	if( !IsValid() )
189cdf0e10cSrcweir 		return aBoundingRect;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 	Point aTopLeft;
192cdf0e10cSrcweir 	Point aBottomRight;
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 	if( m_aSourceDescrLinePos.Y() <= m_aDestDescrLinePos.Y() )
195cdf0e10cSrcweir 	{
196cdf0e10cSrcweir 		aTopLeft.Y() = m_aSourceDescrLinePos.Y();
197cdf0e10cSrcweir 		aBottomRight.Y() = m_aDestDescrLinePos.Y();
198cdf0e10cSrcweir 	}
199cdf0e10cSrcweir 	else
200cdf0e10cSrcweir 	{
201cdf0e10cSrcweir 		aTopLeft.Y() = m_aDestDescrLinePos.Y();
202cdf0e10cSrcweir 		aBottomRight.Y() = m_aSourceDescrLinePos.Y();
203cdf0e10cSrcweir 	}
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 	if( m_aSourceDescrLinePos.X() <= m_aDestDescrLinePos.X() )
206cdf0e10cSrcweir 	{
207cdf0e10cSrcweir 		aTopLeft.X() = m_aSourceDescrLinePos.X();
208cdf0e10cSrcweir 		aBottomRight.X() = m_aDestDescrLinePos.X();
209cdf0e10cSrcweir 	}
210cdf0e10cSrcweir 	else
211cdf0e10cSrcweir 	{
212cdf0e10cSrcweir 		aTopLeft.X() = m_aDestDescrLinePos.X();
213cdf0e10cSrcweir 		aBottomRight.X() = m_aSourceDescrLinePos.X();
214cdf0e10cSrcweir 	}
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     const OTableWindow* pSourceWin = m_pTabConn->GetSourceWin();
217cdf0e10cSrcweir 	const OTableWindow* pDestWin = m_pTabConn->GetDestWin();
218cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
219cdf0e10cSrcweir 	// Linie verlaeuft in z-Form
220cdf0e10cSrcweir 	if( pSourceWin == pDestWin || Abs(m_aSourceConnPos.X() - m_aDestConnPos.X()) > Abs(m_aSourceDescrLinePos.X() - m_aDestDescrLinePos.X()) )
221cdf0e10cSrcweir 	{
222cdf0e10cSrcweir 		aTopLeft.X() -= DESCRIPT_LINE_WIDTH;
223cdf0e10cSrcweir 		aBottomRight.X() += DESCRIPT_LINE_WIDTH;
224cdf0e10cSrcweir 	}
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 	aBoundingRect = Rectangle( aTopLeft-Point(2,17), aBottomRight+Point(2,2) );
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 	return aBoundingRect;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir // -----------------------------------------------------------------------------
calcPointX1(const OTableWindow * _pWin,Point & _rNewConPos,Point & _rNewDescrPos)231cdf0e10cSrcweir void calcPointX1(const OTableWindow* _pWin,Point& _rNewConPos,Point& _rNewDescrPos)
232cdf0e10cSrcweir {
233cdf0e10cSrcweir 	_rNewConPos.X() = _pWin->GetPosPixel().X() + _pWin->GetSizePixel().Width();
234cdf0e10cSrcweir 	_rNewDescrPos.X() = _rNewConPos.X();
235cdf0e10cSrcweir 	_rNewConPos.X() += DESCRIPT_LINE_WIDTH;
236cdf0e10cSrcweir }
237cdf0e10cSrcweir // -----------------------------------------------------------------------------
calcPointX2(const OTableWindow * _pWin,Point & _rNewConPos,Point & _rNewDescrPos)238cdf0e10cSrcweir void calcPointX2(const OTableWindow* _pWin,Point& _rNewConPos,Point& _rNewDescrPos)
239cdf0e10cSrcweir {
240cdf0e10cSrcweir 	_rNewConPos.X() = _pWin->GetPosPixel().X();
241cdf0e10cSrcweir 	_rNewDescrPos.X() = _rNewConPos.X();
242cdf0e10cSrcweir 	_rNewConPos.X() -= DESCRIPT_LINE_WIDTH;
243cdf0e10cSrcweir }
244cdf0e10cSrcweir //------------------------------------------------------------------------
RecalcLine()245cdf0e10cSrcweir sal_Bool OConnectionLine::RecalcLine()
246cdf0e10cSrcweir {
247cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
248cdf0e10cSrcweir 	// Fenster und Entries muessen gesetzt sein
249cdf0e10cSrcweir 	const OTableWindow* pSourceWin = m_pTabConn->GetSourceWin();
250cdf0e10cSrcweir 	const OTableWindow* pDestWin = m_pTabConn->GetDestWin();
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 	if( !pSourceWin || !pDestWin )
253cdf0e10cSrcweir 		return sal_False;
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 	SvLBoxEntry* pSourceEntry = pSourceWin->GetListBox()->GetEntryFromText( GetData()->GetSourceFieldName() );
256cdf0e10cSrcweir 	SvLBoxEntry* pDestEntry = pDestWin->GetListBox()->GetEntryFromText( GetData()->GetDestFieldName() );
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
259cdf0e10cSrcweir 	// X-Koordinaten bestimmen
260cdf0e10cSrcweir 	Point aSourceCenter( 0, 0 );
261cdf0e10cSrcweir 	Point aDestCenter( 0, 0 );
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 	aSourceCenter.X() = pSourceWin->GetPosPixel().X() + (long)( 0.5*pSourceWin->GetSizePixel().Width() );
264cdf0e10cSrcweir 	aDestCenter.X() = pDestWin->GetPosPixel().X() + (long)( 0.5*pDestWin->GetSizePixel().Width() );
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 	const OTableWindow* pFirstWin	= pDestWin;
267cdf0e10cSrcweir 	const OTableWindow* pSecondWin	= pSourceWin;
268cdf0e10cSrcweir 	Point* pFirstConPos				= &m_aDestConnPos;
269cdf0e10cSrcweir 	Point* pFirstDescrPos			= &m_aDestDescrLinePos;
270cdf0e10cSrcweir 	Point* pSecondConPos			= &m_aSourceConnPos;
271cdf0e10cSrcweir 	Point* pSecondDescrPos			= &m_aSourceDescrLinePos;
272cdf0e10cSrcweir 	if( aDestCenter.X() > aSourceCenter.X() )
273cdf0e10cSrcweir 	{
274cdf0e10cSrcweir 		pFirstWin		= pSourceWin;
275cdf0e10cSrcweir 		pSecondWin		= pDestWin;
276cdf0e10cSrcweir 		pFirstConPos	= &m_aSourceConnPos;
277cdf0e10cSrcweir 		pFirstDescrPos	= &m_aSourceDescrLinePos;
278cdf0e10cSrcweir 		pSecondConPos	= &m_aDestConnPos;
279cdf0e10cSrcweir 		pSecondDescrPos	= &m_aDestDescrLinePos;
280cdf0e10cSrcweir 	}
281cdf0e10cSrcweir 
282cdf0e10cSrcweir     if ( pFirstWin == pSecondWin && pSourceEntry != pDestEntry )
283cdf0e10cSrcweir         calcPointX2(pFirstWin,*pFirstConPos,*pFirstDescrPos);
284cdf0e10cSrcweir     else
285cdf0e10cSrcweir         calcPointX1(pFirstWin,*pFirstConPos,*pFirstDescrPos);
286cdf0e10cSrcweir 	calcPointX2(pSecondWin,*pSecondConPos,*pSecondDescrPos);
287cdf0e10cSrcweir 
288cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
289cdf0e10cSrcweir 	// aSourceConnPosY bestimmen
290cdf0e10cSrcweir     calcPointsYValue(pSourceWin,pSourceEntry,m_aSourceConnPos,m_aSourceDescrLinePos);
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
293cdf0e10cSrcweir 	// aDestConnPosY bestimmen
294cdf0e10cSrcweir     calcPointsYValue(pDestWin,pDestEntry,m_aDestConnPos,m_aDestDescrLinePos);
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 	return sal_True;
297cdf0e10cSrcweir }
298cdf0e10cSrcweir // -----------------------------------------------------------------------------
299cdf0e10cSrcweir 
300cdf0e10cSrcweir //------------------------------------------------------------------------
Draw(OutputDevice * pOutDev)301cdf0e10cSrcweir void OConnectionLine::Draw( OutputDevice* pOutDev )
302cdf0e10cSrcweir {
303cdf0e10cSrcweir 	const sal_uInt16 nRectSize = 3;
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
306cdf0e10cSrcweir 	// Neue Dimensionen berechnen
307cdf0e10cSrcweir 	if( !RecalcLine() )
308cdf0e10cSrcweir 		return;
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
311cdf0e10cSrcweir 	// Zeichnen der Linien
312cdf0e10cSrcweir 	if (m_pTabConn->IsSelected())
313cdf0e10cSrcweir 		pOutDev->SetLineColor(Application::GetSettings().GetStyleSettings().GetHighlightColor());
314cdf0e10cSrcweir 	else
315cdf0e10cSrcweir 		pOutDev->SetLineColor(Application::GetSettings().GetStyleSettings().GetWindowTextColor());
316cdf0e10cSrcweir 
317cdf0e10cSrcweir     LineInfo aLineInfo;
318cdf0e10cSrcweir     if ( m_pTabConn->IsSelected() )
319cdf0e10cSrcweir         aLineInfo.SetWidth(3);
320cdf0e10cSrcweir     Polygon aPoly;
321cdf0e10cSrcweir     aPoly.Insert(0,m_aSourceDescrLinePos);
322cdf0e10cSrcweir     aPoly.Insert(1,m_aSourceConnPos);
323cdf0e10cSrcweir     aPoly.Insert(2,m_aDestConnPos);
324cdf0e10cSrcweir     aPoly.Insert(3,m_aDestDescrLinePos);
325cdf0e10cSrcweir     pOutDev->DrawPolyLine(aPoly,aLineInfo);
326cdf0e10cSrcweir 
327cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
328cdf0e10cSrcweir 	// draw the connection rectangles
329cdf0e10cSrcweir 	pOutDev->SetFillColor(Application::GetSettings().GetStyleSettings().GetWindowColor());
330cdf0e10cSrcweir 
331cdf0e10cSrcweir 	Point aVector(nRectSize,nRectSize);
332cdf0e10cSrcweir 	pOutDev->DrawRect( calcRect(m_aSourceDescrLinePos,aVector) );
333cdf0e10cSrcweir 	pOutDev->DrawRect( calcRect( m_aDestDescrLinePos,aVector) );
334cdf0e10cSrcweir }
335cdf0e10cSrcweir // -----------------------------------------------------------------------------
IsValid() const336cdf0e10cSrcweir sal_Bool OConnectionLine::IsValid() const
337cdf0e10cSrcweir {
338cdf0e10cSrcweir 	return m_pData.isValid();
339cdf0e10cSrcweir }
340cdf0e10cSrcweir //------------------------------------------------------------------------
dist_Euklid(const Point & p1,const Point & p2,const Point & pM,Point & q)341cdf0e10cSrcweir double dist_Euklid(const Point &p1, const Point& p2,const Point& pM, Point& q)
342cdf0e10cSrcweir {
343cdf0e10cSrcweir 	Point v(p2 - p1);
344cdf0e10cSrcweir 	Point w(pM - p1);
345cdf0e10cSrcweir 	double a = sqrt((double)(v.X()*v.X() + v.Y()*v.Y()));
346cdf0e10cSrcweir 	double l = (v.X() * w.Y() - v.Y() * w.X()) / a;
347cdf0e10cSrcweir 	double a2 = w.X()*v.X()+w.Y()*v.Y();
348cdf0e10cSrcweir 	a = a2 / (a * a);
349cdf0e10cSrcweir 	q.X() = long(p1.X() + a * v.X());
350cdf0e10cSrcweir 	q.Y() = long(p1.Y() + a * v.Y());
351cdf0e10cSrcweir 	return l;
352cdf0e10cSrcweir }
353cdf0e10cSrcweir //------------------------------------------------------------------------
CheckHit(const Point & rMousePos) const354cdf0e10cSrcweir bool OConnectionLine::CheckHit( const Point& rMousePos ) const
355cdf0e10cSrcweir {
356cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
357cdf0e10cSrcweir 	/*
358cdf0e10cSrcweir 		Vorgehensweise beim HitTest:
359cdf0e10cSrcweir 		Es wird der Abstand nach Euklid berechnet.
360cdf0e10cSrcweir 	*/
361cdf0e10cSrcweir 	Point q;
362cdf0e10cSrcweir 	double l = fabs(dist_Euklid(m_aSourceConnPos,m_aDestConnPos,rMousePos,q));
363cdf0e10cSrcweir 	if( l < HIT_SENSITIVE_RADIUS)
364cdf0e10cSrcweir 	{
365cdf0e10cSrcweir 		if(::std::min(m_aSourceConnPos.X(),m_aDestConnPos.X()) <= q.X() && ::std::min(m_aSourceConnPos.Y(),m_aDestConnPos.Y()) <= q.Y()
366cdf0e10cSrcweir 			&& q.X() <= ::std::max(m_aDestConnPos.X(),m_aSourceConnPos.X())   && q.Y() <= ::std::max(m_aDestConnPos.Y(),m_aSourceConnPos.Y()))
367cdf0e10cSrcweir 			return true;
368cdf0e10cSrcweir 	}
369cdf0e10cSrcweir 
370cdf0e10cSrcweir 	return false;
371cdf0e10cSrcweir }
372cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetSourceTextPos() const373cdf0e10cSrcweir Rectangle OConnectionLine::GetSourceTextPos() const
374cdf0e10cSrcweir {
375cdf0e10cSrcweir 	return GetTextPos(m_pTabConn->GetSourceWin(),m_aSourceConnPos,m_aSourceDescrLinePos);
376cdf0e10cSrcweir }
377cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetDestTextPos() const378cdf0e10cSrcweir Rectangle OConnectionLine::GetDestTextPos() const
379cdf0e10cSrcweir {
380cdf0e10cSrcweir 	return GetTextPos(m_pTabConn->GetDestWin(),m_aDestConnPos,m_aDestDescrLinePos);
381cdf0e10cSrcweir }
382cdf0e10cSrcweir // -----------------------------------------------------------------------------
getMidPoint() const383cdf0e10cSrcweir Point OConnectionLine::getMidPoint() const
384cdf0e10cSrcweir {
385cdf0e10cSrcweir 	Point aDest = m_aDestConnPos - m_aSourceConnPos;
386cdf0e10cSrcweir 	aDest.X() /= 2;
387cdf0e10cSrcweir 	aDest.Y() /= 2;
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 	return m_aSourceConnPos + aDest;
390cdf0e10cSrcweir }
391cdf0e10cSrcweir // -----------------------------------------------------------------------------
392cdf0e10cSrcweir 
393cdf0e10cSrcweir 
394