update dev300-m58
[ooovba.git] / dbaccess / source / ui / querydesign / TableConnection.cxx
blob84f5fcd0909a54b68a891487f149720852a0f0d5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableConnection.cxx,v $
10 * $Revision: 1.16 $
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"
35 #endif
36 #ifndef DBAUI_CONNECTIONLINE_HXX
37 #include "ConnectionLine.hxx"
38 #endif
39 #ifndef DBAUI_TABLECONNECTIONDATA_HXX
40 #include "TableConnectionData.hxx"
41 #endif
42 #ifndef DBAUI_JOINTABLEVIEW_HXX
43 #include "JoinTableView.hxx"
44 #endif
45 #ifndef _COMPHELPER_STLTYPES_HXX_
46 #include <comphelper/stl_types.hxx>
47 #endif
48 #ifndef DBACCESS_CONNECTIONLINEACCESS_HXX
49 #include "ConnectionLineAccess.hxx"
50 #endif
51 #include <algorithm>
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 //========================================================================
62 namespace dbaui
64 DBG_NAME(OTableConnection)
65 //------------------------------------------------------------------------
66 OTableConnection::OTableConnection( OJoinTableView* _pContainer,const TTableConnectionData::value_type& _pTabConnData )
67 :Window(_pContainer)
68 ,m_pData( _pTabConnData )
69 ,m_pParent( _pContainer )
70 ,m_bSelected( FALSE )
72 DBG_CTOR(OTableConnection,NULL);
73 Init();
74 Show();
77 //------------------------------------------------------------------------
78 OTableConnection::OTableConnection( const OTableConnection& _rConn ) : Window(_rConn.m_pParent)
79 ,m_pData(_rConn.GetData()->NewInstance())
81 DBG_CTOR(OTableConnection,NULL);
82 *this = _rConn;
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)
108 delete *aLineIter;
109 m_vConnLine.clear();
111 //------------------------------------------------------------------------
112 void OTableConnection::UpdateLineList()
114 //////////////////////////////////////////////////////////////////////
115 // Linienliste loeschen
116 clearLineData();
118 Init();
121 //------------------------------------------------------------------------
122 OTableConnection& OTableConnection::operator=( const OTableConnection& rConn )
124 if( &rConn == this )
125 return *this;
127 // Linienliste loeschen
128 clearLineData();
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;
148 return *this;
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));
157 return true;
159 //------------------------------------------------------------------------
160 OTableWindow* OTableConnection::GetSourceWin() const
162 TTableWindowData::value_type pRef = GetData()->getReferencingTable();
163 OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
164 if ( !pRet )
166 pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
168 return pRet;
170 //------------------------------------------------------------------------
171 OTableWindow* OTableConnection::GetDestWin() const
173 TTableWindowData::value_type pRef = GetData()->getReferencedTable();
174 OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
175 if ( !pRet )
177 pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
179 return pRet;
182 //------------------------------------------------------------------------
183 void OTableConnection::Select()
185 m_bSelected = TRUE;
186 m_pParent->Invalidate( GetBoundingRect(), INVALIDATE_NOCHILDREN);
189 //------------------------------------------------------------------------
190 void OTableConnection::Deselect()
192 m_bSelected = FALSE;
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(),
202 m_vConnLine.end(),
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 );
219 return true;
222 //------------------------------------------------------------------------
223 Rectangle OTableConnection::GetBoundingRect() const
225 //////////////////////////////////////////////////////////////////////
226 // Aus allen Linien das umgebende Rechteck bestimmen
227 Rectangle aBoundingRect( Point(0,0), Point(0,0) );
228 Rectangle aTempRect;
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;
240 else
241 aBoundingRect.Union( aTempRect );
245 return aBoundingRect;
248 //------------------------------------------------------------------------
249 void OTableConnection::Draw( const Rectangle& /*rRect*/ )
251 //////////////////////////////////////////////////////////////////////
252 // Linien zeichnen
253 ::std::for_each(m_vConnLine.begin(),m_vConnLine.end(),TConnectionLineDrawFunctor(m_pParent));
255 // -----------------------------------------------------------------------------