1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
28 using namespace dbaui
;
29 using namespace comphelper
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::accessibility
;
33 // class OTableConnection
36 OTableConnection::OTableConnection( OJoinTableView
* _pContainer
,const TTableConnectionData::value_type
& _pTabConnData
)
38 ,m_pData( _pTabConnData
)
39 ,m_pParent( _pContainer
)
46 OTableConnection::OTableConnection( const OTableConnection
& _rConn
) : Window(_rConn
.m_pParent
.get())
47 ,m_pData(_rConn
.GetData()->NewInstance())
53 void OTableConnection::Init()
55 // initialise linelist with defaults
56 OConnectionLineDataVec
& rLineData
= GetData()->GetConnLineDataList();
57 OConnectionLineDataVec::const_iterator aIter
= rLineData
.begin();
58 OConnectionLineDataVec::const_iterator aEnd
= rLineData
.end();
59 m_vConnLine
.reserve(rLineData
.size());
60 for(;aIter
!= aEnd
;++aIter
)
61 m_vConnLine
.push_back( new OConnectionLine(this, *aIter
) );
64 OConnectionLine
* OTableConnection::CreateConnLine( const OConnectionLine
& rConnLine
)
66 return new OConnectionLine( rConnLine
);
68 void OTableConnection::clearLineData()
70 ::std::vector
<OConnectionLine
*>::iterator aLineEnd
= m_vConnLine
.end();
71 for(::std::vector
<OConnectionLine
*>::iterator aLineIter
= m_vConnLine
.begin();aLineIter
!= aLineEnd
;++aLineIter
)
75 void OTableConnection::UpdateLineList()
83 OTableConnection
& OTableConnection::operator=( const OTableConnection
& rConn
)
92 if(! rConn
.GetConnLineList().empty() )
94 const ::std::vector
<OConnectionLine
*>& rLine
= rConn
.GetConnLineList();
95 ::std::vector
<OConnectionLine
*>::const_iterator aIter
= rLine
.begin();
96 ::std::vector
<OConnectionLine
*>::const_iterator aEnd
= rLine
.end();
97 m_vConnLine
.reserve(rLine
.size());
98 for(;aIter
!= aEnd
;++aIter
)
99 m_vConnLine
.push_back( CreateConnLine( **aIter
));
102 // as the data are not mine, I also do not delete the old
103 m_pData
->CopyFrom(*rConn
.GetData());
104 // CopyFrom is virtual, therefore it is not a problem if m_pData is a derived type of OTableConnectionData
106 m_bSelected
= rConn
.m_bSelected
;
107 m_pParent
= rConn
.m_pParent
;
112 bool OTableConnection::RecalcLines()
114 // call RecalcLines on each line
115 ::std::for_each(m_vConnLine
.begin(),m_vConnLine
.end(),::std::mem_fun(&OConnectionLine::RecalcLine
));
118 OTableWindow
* OTableConnection::GetSourceWin() const
120 TTableWindowData::value_type pRef
= GetData()->getReferencingTable();
121 OTableWindow
* pRet
= m_pParent
->GetTabWindow( pRef
->GetWinName() );
124 pRet
= m_pParent
->GetTabWindow( pRef
->GetComposedName() );
128 OTableWindow
* OTableConnection::GetDestWin() const
130 TTableWindowData::value_type pRef
= GetData()->getReferencedTable();
131 OTableWindow
* pRet
= m_pParent
->GetTabWindow( pRef
->GetWinName() );
134 pRet
= m_pParent
->GetTabWindow( pRef
->GetComposedName() );
139 void OTableConnection::Select()
142 m_pParent
->Invalidate( GetBoundingRect(), INVALIDATE_NOCHILDREN
);
145 void OTableConnection::Deselect()
148 InvalidateConnection();
151 bool OTableConnection::CheckHit( const Point
& rMousePos
) const
153 // check if the point hit our line
154 return ::std::any_of(m_vConnLine
.begin(),
156 ::std::bind2nd(TConnectionLineCheckHitFunctor(),rMousePos
));
159 bool OTableConnection::InvalidateConnection()
161 Rectangle rcBounding
= GetBoundingRect();
162 rcBounding
.Bottom() += 1;
163 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 m_pParent
->Invalidate( rcBounding
, INVALIDATE_NOCHILDREN
);
173 Rectangle
OTableConnection::GetBoundingRect() const
175 // determine all lines of the surrounding rectangle
176 Rectangle
aBoundingRect( Point(0,0), Point(0,0) );
178 ::std::vector
<OConnectionLine
*>::const_iterator aEnd
= m_vConnLine
.end();
179 for(::std::vector
<OConnectionLine
*>::const_iterator aIter
= m_vConnLine
.begin();aIter
!= aEnd
;++aIter
)
181 aTempRect
= (*aIter
)->GetBoundingRect();
183 // is the BoundingRect of this line valid?
184 if( (aTempRect
.GetWidth()!=1) && (aTempRect
.GetHeight()!=1) )
186 if( (aBoundingRect
.GetWidth()==1) && (aBoundingRect
.GetHeight()==1) )
187 aBoundingRect
= aTempRect
;
189 aBoundingRect
.Union( aTempRect
);
193 return aBoundingRect
;
196 void OTableConnection::Draw(vcl::RenderContext
& rRenderContext
, const Rectangle
& /*rRect*/)
199 std::for_each(m_vConnLine
.begin(), m_vConnLine
.end(), TConnectionLineDrawFunctor(&rRenderContext
));
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */