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 : using namespace dbaui;
29 : using namespace comphelper;
30 : using namespace ::com::sun::star::uno;
31 : using namespace ::com::sun::star::accessibility;
32 :
33 : // class OTableConnection
34 : namespace dbaui
35 : {
36 0 : OTableConnection::OTableConnection( OJoinTableView* _pContainer,const TTableConnectionData::value_type& _pTabConnData )
37 : :Window(_pContainer)
38 : ,m_pData( _pTabConnData )
39 : ,m_pParent( _pContainer )
40 0 : ,m_bSelected( sal_False )
41 : {
42 0 : Init();
43 0 : Show();
44 0 : }
45 :
46 0 : OTableConnection::OTableConnection( const OTableConnection& _rConn ) : Window(_rConn.m_pParent)
47 0 : ,m_pData(_rConn.GetData()->NewInstance())
48 : {
49 0 : *this = _rConn;
50 0 : }
51 :
52 0 : void OTableConnection::Init()
53 : {
54 : // initialise linelist with defaults
55 0 : OConnectionLineDataVec* pLineData = GetData()->GetConnLineDataList();
56 0 : OConnectionLineDataVec::const_iterator aIter = pLineData->begin();
57 0 : OConnectionLineDataVec::const_iterator aEnd = pLineData->end();
58 0 : m_vConnLine.reserve(pLineData->size());
59 0 : for(;aIter != aEnd;++aIter)
60 0 : m_vConnLine.push_back( new OConnectionLine(this, *aIter) );
61 0 : }
62 :
63 0 : OConnectionLine* OTableConnection::CreateConnLine( const OConnectionLine& rConnLine )
64 : {
65 0 : return new OConnectionLine( rConnLine );
66 : }
67 0 : void OTableConnection::clearLineData()
68 : {
69 0 : ::std::vector<OConnectionLine*>::iterator aLineEnd = m_vConnLine.end();
70 0 : for(::std::vector<OConnectionLine*>::iterator aLineIter = m_vConnLine.begin();aLineIter != aLineEnd;++aLineIter)
71 0 : delete *aLineIter;
72 0 : m_vConnLine.clear();
73 0 : }
74 0 : void OTableConnection::UpdateLineList()
75 : {
76 : // delete linelist
77 0 : clearLineData();
78 :
79 0 : Init();
80 0 : }
81 :
82 0 : OTableConnection& OTableConnection::operator=( const OTableConnection& rConn )
83 : {
84 0 : if( &rConn == this )
85 0 : return *this;
86 :
87 : // delete linelist
88 0 : clearLineData();
89 :
90 : // copy linelist
91 0 : if(! rConn.GetConnLineList()->empty() )
92 : {
93 0 : const ::std::vector<OConnectionLine*>* pLine = rConn.GetConnLineList();
94 0 : ::std::vector<OConnectionLine*>::const_iterator aIter = pLine->begin();
95 0 : ::std::vector<OConnectionLine*>::const_iterator aEnd = pLine->end();
96 0 : m_vConnLine.reserve(pLine->size());
97 0 : for(;aIter != aEnd;++aIter)
98 0 : m_vConnLine.push_back( CreateConnLine( **aIter ));
99 : }
100 :
101 : // as the data are not mine, I also do not delete the old
102 0 : m_pData->CopyFrom(*rConn.GetData());
103 : // CopyFrom is virtual, therefore it is not a problem if m_pData is a derived type of OTableConnectionData
104 :
105 0 : m_bSelected = rConn.m_bSelected;
106 0 : m_pParent = rConn.m_pParent;
107 :
108 0 : return *this;
109 : }
110 :
111 0 : bool OTableConnection::RecalcLines()
112 : {
113 : // call RecalcLines on each line
114 0 : ::std::for_each(m_vConnLine.begin(),m_vConnLine.end(),::std::mem_fun(&OConnectionLine::RecalcLine));
115 0 : return true;
116 : }
117 0 : OTableWindow* OTableConnection::GetSourceWin() const
118 : {
119 0 : TTableWindowData::value_type pRef = GetData()->getReferencingTable();
120 0 : OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
121 0 : if ( !pRet )
122 : {
123 0 : pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
124 : }
125 0 : return pRet;
126 : }
127 0 : OTableWindow* OTableConnection::GetDestWin() const
128 : {
129 0 : TTableWindowData::value_type pRef = GetData()->getReferencedTable();
130 0 : OTableWindow* pRet = m_pParent->GetTabWindow( pRef->GetWinName() );
131 0 : if ( !pRet )
132 : {
133 0 : pRet = m_pParent->GetTabWindow( pRef->GetComposedName() );
134 : }
135 0 : return pRet;
136 : }
137 :
138 0 : void OTableConnection::Select()
139 : {
140 0 : m_bSelected = sal_True;
141 0 : m_pParent->Invalidate( GetBoundingRect(), INVALIDATE_NOCHILDREN);
142 0 : }
143 :
144 0 : void OTableConnection::Deselect()
145 : {
146 0 : m_bSelected = sal_False;
147 0 : InvalidateConnection();
148 0 : }
149 :
150 0 : sal_Bool OTableConnection::CheckHit( const Point& rMousePos ) const
151 : {
152 : // check if the point hit our line
153 : ::std::vector<OConnectionLine*>::const_iterator aIter = ::std::find_if(m_vConnLine.begin(),
154 : m_vConnLine.end(),
155 0 : ::std::bind2nd(TConnectionLineCheckHitFunctor(),rMousePos));
156 0 : return aIter != m_vConnLine.end();
157 : }
158 :
159 0 : bool OTableConnection::InvalidateConnection()
160 : {
161 0 : Rectangle rcBounding = GetBoundingRect();
162 0 : rcBounding.Bottom() += 1;
163 0 : rcBounding.Right() += 1;
164 : // I believe Invalidate and Draw(Rectangle) do not behave consistent: in any case it
165 : // could explain, why without the fake here when deleting a connection a dash remains at the lower end:
166 : // Invalidate records obviously one pixel line less as Draw.
167 : // Or everything works differently ..... in any case it works ....
168 0 : m_pParent->Invalidate( rcBounding, INVALIDATE_NOCHILDREN );
169 :
170 0 : return true;
171 : }
172 :
173 0 : Rectangle OTableConnection::GetBoundingRect() const
174 : {
175 : // determine all lines of the surrounding rectangle
176 0 : Rectangle aBoundingRect( Point(0,0), Point(0,0) );
177 0 : Rectangle aTempRect;
178 0 : ::std::vector<OConnectionLine*>::const_iterator aEnd = m_vConnLine.end();
179 0 : for(::std::vector<OConnectionLine*>::const_iterator aIter = m_vConnLine.begin();aIter != aEnd;++aIter)
180 : {
181 0 : aTempRect = (*aIter)->GetBoundingRect();
182 :
183 : // is the BoundingRect of this line valid?
184 0 : if( (aTempRect.GetWidth()!=1) && (aTempRect.GetHeight()!=1) )
185 : {
186 0 : if( (aBoundingRect.GetWidth()==1) && (aBoundingRect.GetHeight()==1) )
187 0 : aBoundingRect = aTempRect;
188 : else
189 0 : aBoundingRect.Union( aTempRect );
190 : }
191 : }
192 :
193 0 : return aBoundingRect;
194 : }
195 :
196 0 : void OTableConnection::Draw( const Rectangle& /*rRect*/ )
197 : {
198 : // Draw line
199 0 : ::std::for_each(m_vConnLine.begin(),m_vConnLine.end(),TConnectionLineDrawFunctor(m_pParent));
200 0 : }
201 : }
202 :
203 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|