Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include "TableConnection.hxx"
21 : : #include "ConnectionLine.hxx"
22 : : #include "TableConnectionData.hxx"
23 : : #include "JoinTableView.hxx"
24 : : #include <comphelper/stl_types.hxx>
25 : : #include "ConnectionLineAccess.hxx"
26 : : #include <algorithm>
27 : :
28 : :
29 : : using namespace dbaui;
30 : : using namespace comphelper;
31 : : using namespace ::com::sun::star::uno;
32 : : using namespace ::com::sun::star::accessibility;
33 : :
34 : : //========================================================================
35 : : // class OTableConnection
36 : : //========================================================================
37 : : namespace dbaui
38 : : {
39 : : DBG_NAME(OTableConnection)
40 : : //------------------------------------------------------------------------
41 : 0 : OTableConnection::OTableConnection( OJoinTableView* _pContainer,const TTableConnectionData::value_type& _pTabConnData )
42 : : :Window(_pContainer)
43 : : ,m_pData( _pTabConnData )
44 : : ,m_pParent( _pContainer )
45 [ # # ][ # # ]: 0 : ,m_bSelected( sal_False )
46 : : {
47 : : DBG_CTOR(OTableConnection,NULL);
48 [ # # ]: 0 : Init();
49 [ # # ]: 0 : Show();
50 : 0 : }
51 : :
52 : : //------------------------------------------------------------------------
53 : 0 : OTableConnection::OTableConnection( const OTableConnection& _rConn ) : Window(_rConn.m_pParent)
54 [ # # ][ # # ]: 0 : ,m_pData(_rConn.GetData()->NewInstance())
[ # # ][ # # ]
[ # # ]
55 : : {
56 : : DBG_CTOR(OTableConnection,NULL);
57 [ # # ]: 0 : *this = _rConn;
58 : 0 : }
59 : :
60 : : //------------------------------------------------------------------------
61 : 0 : void OTableConnection::Init()
62 : : {
63 : : //////////////////////////////////////////////////////////////////////
64 : : // Linienliste mit Defaults initialisieren
65 [ # # ][ # # ]: 0 : OConnectionLineDataVec* pLineData = GetData()->GetConnLineDataList();
66 [ # # ]: 0 : OConnectionLineDataVec::const_iterator aIter = pLineData->begin();
67 [ # # ]: 0 : OConnectionLineDataVec::const_iterator aEnd = pLineData->end();
68 [ # # ]: 0 : m_vConnLine.reserve(pLineData->size());
69 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
70 [ # # ][ # # ]: 0 : m_vConnLine.push_back( new OConnectionLine(this, *aIter) );
[ # # ][ # # ]
[ # # ]
71 : 0 : }
72 : :
73 : : //------------------------------------------------------------------------
74 : 0 : OConnectionLine* OTableConnection::CreateConnLine( const OConnectionLine& rConnLine )
75 : : {
76 [ # # ]: 0 : return new OConnectionLine( rConnLine );
77 : : }
78 : : // -----------------------------------------------------------------------------
79 : 0 : void OTableConnection::clearLineData()
80 : : {
81 : 0 : ::std::vector<OConnectionLine*>::iterator aLineEnd = m_vConnLine.end();
82 [ # # ][ # # ]: 0 : for(::std::vector<OConnectionLine*>::iterator aLineIter = m_vConnLine.begin();aLineIter != aLineEnd;++aLineIter)
83 [ # # ][ # # ]: 0 : delete *aLineIter;
84 : 0 : m_vConnLine.clear();
85 : 0 : }
86 : : //------------------------------------------------------------------------
87 : 0 : void OTableConnection::UpdateLineList()
88 : : {
89 : : //////////////////////////////////////////////////////////////////////
90 : : // Linienliste loeschen
91 : 0 : clearLineData();
92 : :
93 : 0 : Init();
94 : 0 : }
95 : :
96 : : //------------------------------------------------------------------------
97 : 0 : OTableConnection& OTableConnection::operator=( const OTableConnection& rConn )
98 : : {
99 [ # # ]: 0 : if( &rConn == this )
100 : 0 : return *this;
101 : :
102 : : // Linienliste loeschen
103 : 0 : clearLineData();
104 : :
105 : : // Linienliste kopieren
106 [ # # ]: 0 : if(! rConn.GetConnLineList()->empty() )
107 : : {
108 : 0 : const ::std::vector<OConnectionLine*>* pLine = rConn.GetConnLineList();
109 : 0 : ::std::vector<OConnectionLine*>::const_iterator aIter = pLine->begin();
110 : 0 : ::std::vector<OConnectionLine*>::const_iterator aEnd = pLine->end();
111 [ # # ]: 0 : m_vConnLine.reserve(pLine->size());
112 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
113 [ # # ][ # # ]: 0 : m_vConnLine.push_back( CreateConnLine( **aIter ));
114 : : }
115 : :
116 : : // da mir die Daten nicht gehoeren, loesche ich die alten nicht
117 [ # # ]: 0 : m_pData->CopyFrom(*rConn.GetData());
118 : : // CopyFrom ist virtuell, damit ist es kein Problem, wenn m_pData von einem von OTableConnectionData abgeleiteten Typ ist
119 : :
120 : 0 : m_bSelected = rConn.m_bSelected;
121 : 0 : m_pParent = rConn.m_pParent;
122 : :
123 : 0 : return *this;
124 : : }
125 : :
126 : :
127 : : //------------------------------------------------------------------------
128 : 0 : bool OTableConnection::RecalcLines()
129 : : {
130 : : // call RecalcLines on each line
131 : 0 : ::std::for_each(m_vConnLine.begin(),m_vConnLine.end(),::std::mem_fun(&OConnectionLine::RecalcLine));
132 : 0 : return true;
133 : : }
134 : : //------------------------------------------------------------------------
135 : 0 : OTableWindow* OTableConnection::GetSourceWin() const
136 : : {
137 [ # # ][ # # ]: 0 : TTableWindowData::value_type pRef = GetData()->getReferencingTable();
[ # # ]
138 [ # # ][ # # ]: 0 : OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
[ # # ]
139 [ # # ]: 0 : if ( !pRet )
140 : : {
141 [ # # ][ # # ]: 0 : pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
[ # # ]
142 : : }
143 [ # # ]: 0 : return pRet;
144 : : }
145 : : //------------------------------------------------------------------------
146 : 0 : OTableWindow* OTableConnection::GetDestWin() const
147 : : {
148 [ # # ][ # # ]: 0 : TTableWindowData::value_type pRef = GetData()->getReferencedTable();
[ # # ]
149 [ # # ][ # # ]: 0 : OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
[ # # ]
150 [ # # ]: 0 : if ( !pRet )
151 : : {
152 [ # # ][ # # ]: 0 : pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
[ # # ]
153 : : }
154 [ # # ]: 0 : return pRet;
155 : : }
156 : :
157 : : //------------------------------------------------------------------------
158 : 0 : void OTableConnection::Select()
159 : : {
160 : 0 : m_bSelected = sal_True;
161 [ # # ]: 0 : m_pParent->Invalidate( GetBoundingRect(), INVALIDATE_NOCHILDREN);
162 : 0 : }
163 : :
164 : : //------------------------------------------------------------------------
165 : 0 : void OTableConnection::Deselect()
166 : : {
167 : 0 : m_bSelected = sal_False;
168 : 0 : InvalidateConnection();
169 : 0 : }
170 : :
171 : : //------------------------------------------------------------------------
172 : 0 : sal_Bool OTableConnection::CheckHit( const Point& rMousePos ) const
173 : : {
174 : : //////////////////////////////////////////////////////////////////////
175 : : // check if the point hit our line
176 : : ::std::vector<OConnectionLine*>::const_iterator aIter = ::std::find_if(m_vConnLine.begin(),
177 : : m_vConnLine.end(),
178 [ # # ][ # # ]: 0 : ::std::bind2nd(TConnectionLineCheckHitFunctor(),rMousePos));
179 [ # # ]: 0 : return aIter != m_vConnLine.end();
180 : : }
181 : :
182 : : //------------------------------------------------------------------------
183 : 0 : bool OTableConnection::InvalidateConnection()
184 : : {
185 [ # # ]: 0 : Rectangle rcBounding = GetBoundingRect();
186 : 0 : rcBounding.Bottom() += 1;
187 : 0 : rcBounding.Right() += 1;
188 : : // ich glaube, dass sich Invalidate und Draw(Rectangle) nicht konsistent verhalten : jedenfalls waere dadurch zu
189 : : // erklaeren, warum ohne diesen Fake hier beim Loeschen einer Connection ein Strich an ihrem unteren Ende stehen bleibt :
190 : : // Invalidate erfasst dabei offensichtlich eine Pixelzeile weniger als Draw.
191 : : // Oder alles haengt ganz anders zusammen ... jedenfalls klappt es so ...
192 [ # # ]: 0 : m_pParent->Invalidate( rcBounding, INVALIDATE_NOCHILDREN );
193 : :
194 : 0 : return true;
195 : : }
196 : :
197 : : //------------------------------------------------------------------------
198 : 0 : Rectangle OTableConnection::GetBoundingRect() const
199 : : {
200 : : //////////////////////////////////////////////////////////////////////
201 : : // Aus allen Linien das umgebende Rechteck bestimmen
202 [ # # ]: 0 : Rectangle aBoundingRect( Point(0,0), Point(0,0) );
203 [ # # ]: 0 : Rectangle aTempRect;
204 : 0 : ::std::vector<OConnectionLine*>::const_iterator aEnd = m_vConnLine.end();
205 [ # # ][ # # ]: 0 : for(::std::vector<OConnectionLine*>::const_iterator aIter = m_vConnLine.begin();aIter != aEnd;++aIter)
206 : : {
207 [ # # ]: 0 : aTempRect = (*aIter)->GetBoundingRect();
208 : :
209 : : //////////////////////////////////////////////////////////////////////
210 : : // Ist das BoundingRect dieser Linie gueltig?
211 [ # # ][ # # ]: 0 : if( (aTempRect.GetWidth()!=1) && (aTempRect.GetHeight()!=1) )
[ # # ][ # # ]
[ # # ]
212 : : {
213 [ # # ][ # # ]: 0 : if( (aBoundingRect.GetWidth()==1) && (aBoundingRect.GetHeight()==1) )
[ # # ][ # # ]
[ # # ]
214 : 0 : aBoundingRect = aTempRect;
215 : : else
216 [ # # ]: 0 : aBoundingRect.Union( aTempRect );
217 : : }
218 : : }
219 : :
220 : 0 : return aBoundingRect;
221 : : }
222 : :
223 : : //------------------------------------------------------------------------
224 : 0 : void OTableConnection::Draw( const Rectangle& /*rRect*/ )
225 : : {
226 : : //////////////////////////////////////////////////////////////////////
227 : : // Linien zeichnen
228 [ # # ]: 0 : ::std::for_each(m_vConnLine.begin(),m_vConnLine.end(),TConnectionLineDrawFunctor(m_pParent));
229 : 0 : }
230 : : // -----------------------------------------------------------------------------
231 : : }
232 : :
233 : :
234 : :
235 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|