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"
27 using namespace dbaui
;
28 using namespace comphelper
;
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::accessibility
;
32 // class OTableConnection
35 OTableConnection::OTableConnection( OJoinTableView
* _pContainer
,const TTableConnectionData::value_type
& _pTabConnData
)
37 ,m_pData( _pTabConnData
)
38 ,m_pParent( _pContainer
)
45 OTableConnection::OTableConnection( const OTableConnection
& _rConn
) : Window(_rConn
.m_pParent
.get())
46 ,m_pData(_rConn
.GetData()->NewInstance())
52 void OTableConnection::Init()
54 // initialise linelist with defaults
55 OConnectionLineDataVec
& rLineData
= GetData()->GetConnLineDataList();
56 OConnectionLineDataVec::const_iterator aIter
= rLineData
.begin();
57 OConnectionLineDataVec::const_iterator aEnd
= rLineData
.end();
58 m_vConnLine
.reserve(rLineData
.size());
59 for(;aIter
!= aEnd
;++aIter
)
60 m_vConnLine
.push_back( new OConnectionLine(this, *aIter
) );
63 OConnectionLine
* OTableConnection::CreateConnLine( const OConnectionLine
& rConnLine
)
65 return new OConnectionLine( rConnLine
);
67 void OTableConnection::clearLineData()
69 ::std::vector
<OConnectionLine
*>::const_iterator aLineEnd
= m_vConnLine
.end();
70 for(::std::vector
<OConnectionLine
*>::const_iterator aLineIter
= m_vConnLine
.begin();aLineIter
!= aLineEnd
;++aLineIter
)
74 void OTableConnection::UpdateLineList()
82 OTableConnection
& OTableConnection::operator=( const OTableConnection
& rConn
)
91 if(! rConn
.GetConnLineList().empty() )
93 const ::std::vector
<OConnectionLine
*>& rLine
= rConn
.GetConnLineList();
94 ::std::vector
<OConnectionLine
*>::const_iterator aIter
= rLine
.begin();
95 ::std::vector
<OConnectionLine
*>::const_iterator aEnd
= rLine
.end();
96 m_vConnLine
.reserve(rLine
.size());
97 for(;aIter
!= aEnd
;++aIter
)
98 m_vConnLine
.push_back( CreateConnLine( **aIter
));
101 // as the data are not mine, I also do not delete the old
102 m_pData
->CopyFrom(*rConn
.GetData());
103 // CopyFrom is virtual, therefore it is not a problem if m_pData is a derived type of OTableConnectionData
105 m_bSelected
= rConn
.m_bSelected
;
106 m_pParent
= rConn
.m_pParent
;
111 void OTableConnection::RecalcLines()
113 // call RecalcLines on each line
114 for( const auto& pLine
: m_vConnLine
)
117 OTableWindow
* OTableConnection::GetSourceWin() const
119 TTableWindowData::value_type pRef
= GetData()->getReferencingTable();
120 OTableWindow
* pRet
= m_pParent
->GetTabWindow( pRef
->GetWinName() );
123 pRet
= m_pParent
->GetTabWindow( pRef
->GetComposedName() );
127 OTableWindow
* OTableConnection::GetDestWin() const
129 TTableWindowData::value_type pRef
= GetData()->getReferencedTable();
130 OTableWindow
* pRet
= m_pParent
->GetTabWindow( pRef
->GetWinName() );
133 pRet
= m_pParent
->GetTabWindow( pRef
->GetComposedName() );
138 void OTableConnection::Select()
141 m_pParent
->Invalidate( GetBoundingRect(), InvalidateFlags::NoChildren
);
144 void OTableConnection::Deselect()
147 InvalidateConnection();
150 bool OTableConnection::CheckHit( const Point
& rMousePos
) const
152 // check if the point hit our line
153 return ::std::any_of(m_vConnLine
.begin(),
156 ( const OConnectionLine
* pLine
)
157 { return pLine
->CheckHit( rMousePos
); } );
160 void OTableConnection::InvalidateConnection()
162 Rectangle rcBounding
= GetBoundingRect();
163 rcBounding
.Bottom() += 1;
164 rcBounding
.Right() += 1;
165 // I believe Invalidate and Draw(Rectangle) do not behave consistent: in any case it
166 // could explain, why without the fake here when deleting a connection a dash remains at the lower end:
167 // Invalidate records obviously one pixel line less as Draw.
168 // Or everything works differently ..... in any case it works ....
169 m_pParent
->Invalidate( rcBounding
, InvalidateFlags::NoChildren
);
172 Rectangle
OTableConnection::GetBoundingRect() const
174 // determine all lines of the surrounding rectangle
175 Rectangle
aBoundingRect( Point(0,0), Point(0,0) );
177 ::std::vector
<OConnectionLine
*>::const_iterator aEnd
= m_vConnLine
.end();
178 for(::std::vector
<OConnectionLine
*>::const_iterator aIter
= m_vConnLine
.begin();aIter
!= aEnd
;++aIter
)
180 aTempRect
= (*aIter
)->GetBoundingRect();
182 // is the BoundingRect of this line valid?
183 if( (aTempRect
.GetWidth()!=1) && (aTempRect
.GetHeight()!=1) )
185 if( (aBoundingRect
.GetWidth()==1) && (aBoundingRect
.GetHeight()==1) )
186 aBoundingRect
= aTempRect
;
188 aBoundingRect
.Union( aTempRect
);
192 return aBoundingRect
;
195 void OTableConnection::Draw(vcl::RenderContext
& rRenderContext
, const Rectangle
& /*rRect*/)
198 for( const auto& pLine
: m_vConnLine
)
199 pLine
->Draw( &rRenderContext
);
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */