1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableConnection.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_TABLECONNECTION_HXX
34 #include "TableConnection.hxx"
36 #ifndef DBAUI_CONNECTIONLINE_HXX
37 #include "ConnectionLine.hxx"
39 #ifndef DBAUI_TABLECONNECTIONDATA_HXX
40 #include "TableConnectionData.hxx"
42 #ifndef DBAUI_JOINTABLEVIEW_HXX
43 #include "JoinTableView.hxx"
45 #ifndef _COMPHELPER_STLTYPES_HXX_
46 #include <comphelper/stl_types.hxx>
48 #ifndef DBACCESS_CONNECTIONLINEACCESS_HXX
49 #include "ConnectionLineAccess.hxx"
54 using namespace dbaui
;
55 using namespace comphelper
;
56 using namespace ::com::sun::star::uno
;
57 using namespace ::com::sun::star::accessibility
;
59 //========================================================================
60 // class OTableConnection
61 //========================================================================
64 DBG_NAME(OTableConnection
)
65 //------------------------------------------------------------------------
66 OTableConnection::OTableConnection( OJoinTableView
* _pContainer
,const TTableConnectionData::value_type
& _pTabConnData
)
68 ,m_pData( _pTabConnData
)
69 ,m_pParent( _pContainer
)
72 DBG_CTOR(OTableConnection
,NULL
);
77 //------------------------------------------------------------------------
78 OTableConnection::OTableConnection( const OTableConnection
& _rConn
) : Window(_rConn
.m_pParent
)
79 ,m_pData(_rConn
.GetData()->NewInstance())
81 DBG_CTOR(OTableConnection
,NULL
);
85 //------------------------------------------------------------------------
86 void OTableConnection::Init()
88 //////////////////////////////////////////////////////////////////////
89 // Linienliste mit Defaults initialisieren
90 OConnectionLineDataVec
* pLineData
= GetData()->GetConnLineDataList();
91 OConnectionLineDataVec::const_iterator aIter
= pLineData
->begin();
92 OConnectionLineDataVec::const_iterator aEnd
= pLineData
->end();
93 m_vConnLine
.reserve(pLineData
->size());
94 for(;aIter
!= aEnd
;++aIter
)
95 m_vConnLine
.push_back( new OConnectionLine(this, *aIter
) );
98 //------------------------------------------------------------------------
99 OConnectionLine
* OTableConnection::CreateConnLine( const OConnectionLine
& rConnLine
)
101 return new OConnectionLine( rConnLine
);
103 // -----------------------------------------------------------------------------
104 void OTableConnection::clearLineData()
106 ::std::vector
<OConnectionLine
*>::iterator aLineEnd
= m_vConnLine
.end();
107 for(::std::vector
<OConnectionLine
*>::iterator aLineIter
= m_vConnLine
.begin();aLineIter
!= aLineEnd
;++aLineIter
)
111 //------------------------------------------------------------------------
112 void OTableConnection::UpdateLineList()
114 //////////////////////////////////////////////////////////////////////
115 // Linienliste loeschen
121 //------------------------------------------------------------------------
122 OTableConnection
& OTableConnection::operator=( const OTableConnection
& rConn
)
127 // Linienliste loeschen
130 // Linienliste kopieren
131 if(! rConn
.GetConnLineList()->empty() )
133 const ::std::vector
<OConnectionLine
*>* pLine
= rConn
.GetConnLineList();
134 ::std::vector
<OConnectionLine
*>::const_iterator aIter
= pLine
->begin();
135 ::std::vector
<OConnectionLine
*>::const_iterator aEnd
= pLine
->end();
136 m_vConnLine
.reserve(pLine
->size());
137 for(;aIter
!= aEnd
;++aIter
)
138 m_vConnLine
.push_back( CreateConnLine( **aIter
));
141 // da mir die Daten nicht gehoeren, loesche ich die alten nicht
142 m_pData
->CopyFrom(*rConn
.GetData());
143 // CopyFrom ist virtuell, damit ist es kein Problem, wenn m_pData von einem von OTableConnectionData abgeleiteten Typ ist
145 m_bSelected
= rConn
.m_bSelected
;
146 m_pParent
= rConn
.m_pParent
;
152 //------------------------------------------------------------------------
153 bool OTableConnection::RecalcLines()
155 // call RecalcLines on each line
156 ::std::for_each(m_vConnLine
.begin(),m_vConnLine
.end(),::std::mem_fun(&OConnectionLine::RecalcLine
));
159 //------------------------------------------------------------------------
160 OTableWindow
* OTableConnection::GetSourceWin() const
162 TTableWindowData::value_type pRef
= GetData()->getReferencingTable();
163 OTableWindow
* pRet
= m_pParent
->GetTabWindow( pRef
->GetWinName() );
166 pRet
= m_pParent
->GetTabWindow( pRef
->GetComposedName() );
170 //------------------------------------------------------------------------
171 OTableWindow
* OTableConnection::GetDestWin() const
173 TTableWindowData::value_type pRef
= GetData()->getReferencedTable();
174 OTableWindow
* pRet
= m_pParent
->GetTabWindow( pRef
->GetWinName() );
177 pRet
= m_pParent
->GetTabWindow( pRef
->GetComposedName() );
182 //------------------------------------------------------------------------
183 void OTableConnection::Select()
186 m_pParent
->Invalidate( GetBoundingRect(), INVALIDATE_NOCHILDREN
);
189 //------------------------------------------------------------------------
190 void OTableConnection::Deselect()
193 InvalidateConnection();
196 //------------------------------------------------------------------------
197 BOOL
OTableConnection::CheckHit( const Point
& rMousePos
) const
199 //////////////////////////////////////////////////////////////////////
200 // check if the point hit our line
201 ::std::vector
<OConnectionLine
*>::const_iterator aIter
= ::std::find_if(m_vConnLine
.begin(),
203 ::std::bind2nd(TConnectionLineCheckHitFunctor(),rMousePos
));
204 return aIter
!= m_vConnLine
.end();
207 //------------------------------------------------------------------------
208 bool OTableConnection::InvalidateConnection()
210 Rectangle rcBounding
= GetBoundingRect();
211 rcBounding
.Bottom() += 1;
212 rcBounding
.Right() += 1;
213 // ich glaube, dass sich Invalidate und Draw(Rectangle) nicht konsistent verhalten : jedenfalls waere dadurch zu
214 // erklaeren, warum ohne diesen Fake hier beim Loeschen einer Connection ein Strich an ihrem unteren Ende stehen bleibt :
215 // Invalidate erfasst dabei offensichtlich eine Pixelzeile weniger als Draw.
216 // Oder alles haengt ganz anders zusammen ... jedenfalls klappt es so ...
217 m_pParent
->Invalidate( rcBounding
, INVALIDATE_NOCHILDREN
);
222 //------------------------------------------------------------------------
223 Rectangle
OTableConnection::GetBoundingRect() const
225 //////////////////////////////////////////////////////////////////////
226 // Aus allen Linien das umgebende Rechteck bestimmen
227 Rectangle
aBoundingRect( Point(0,0), Point(0,0) );
229 ::std::vector
<OConnectionLine
*>::const_iterator aEnd
= m_vConnLine
.end();
230 for(::std::vector
<OConnectionLine
*>::const_iterator aIter
= m_vConnLine
.begin();aIter
!= aEnd
;++aIter
)
232 aTempRect
= (*aIter
)->GetBoundingRect();
234 //////////////////////////////////////////////////////////////////////
235 // Ist das BoundingRect dieser Linie gueltig?
236 if( (aTempRect
.GetWidth()!=1) && (aTempRect
.GetHeight()!=1) )
238 if( (aBoundingRect
.GetWidth()==1) && (aBoundingRect
.GetHeight()==1) )
239 aBoundingRect
= aTempRect
;
241 aBoundingRect
.Union( aTempRect
);
245 return aBoundingRect
;
248 //------------------------------------------------------------------------
249 void OTableConnection::Draw( const Rectangle
& /*rRect*/ )
251 //////////////////////////////////////////////////////////////////////
253 ::std::for_each(m_vConnLine
.begin(),m_vConnLine
.end(),TConnectionLineDrawFunctor(m_pParent
));
255 // -----------------------------------------------------------------------------