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>
26 using namespace dbaui
;
27 using namespace ::com::sun::star::accessibility
;
31 OTableConnection::OTableConnection( OJoinTableView
* _pContainer
, TTableConnectionData::value_type _aTabConnData
)
33 ,m_pData(std::move( _aTabConnData
))
34 ,m_pParent( _pContainer
)
41 OTableConnection::OTableConnection( const OTableConnection
& _rConn
)
43 ,Window(_rConn
.m_pParent
.get())
44 ,m_pData(_rConn
.GetData()->NewInstance())
50 void OTableConnection::Init()
52 // initialise linelist with defaults
53 OConnectionLineDataVec
& rLineData
= GetData()->GetConnLineDataList();
54 m_vConnLine
.reserve(rLineData
.size());
55 for (auto const& elem
: rLineData
)
56 m_vConnLine
.emplace_back( new OConnectionLine(this, elem
) );
59 void OTableConnection::clearLineData()
63 void OTableConnection::UpdateLineList()
71 OTableConnection
& OTableConnection::operator=( const OTableConnection
& rConn
)
80 if(! rConn
.GetConnLineList().empty() )
82 const std::vector
<std::unique_ptr
<OConnectionLine
>>& rLine
= rConn
.GetConnLineList();
83 m_vConnLine
.reserve(rLine
.size());
84 for (auto const& elem
: rLine
)
85 m_vConnLine
.emplace_back( new OConnectionLine(*elem
));
88 // as the data are not mine, I also do not delete the old
89 m_pData
->CopyFrom(*rConn
.GetData());
90 // CopyFrom is virtual, therefore it is not a problem if m_pData is a derived type of OTableConnectionData
92 m_bSelected
= rConn
.m_bSelected
;
93 m_pParent
= rConn
.m_pParent
;
98 void OTableConnection::RecalcLines()
100 // call RecalcLines on each line
101 for( const auto& pLine
: m_vConnLine
)
104 OTableWindow
* OTableConnection::GetSourceWin() const
106 TTableWindowData::value_type pRef
= GetData()->getReferencingTable();
107 OTableWindow
* pRet
= m_pParent
->GetTabWindow( pRef
->GetWinName() );
110 pRet
= m_pParent
->GetTabWindow( pRef
->GetComposedName() );
114 OTableWindow
* OTableConnection::GetDestWin() const
116 TTableWindowData::value_type pRef
= GetData()->getReferencedTable();
117 OTableWindow
* pRet
= m_pParent
->GetTabWindow( pRef
->GetWinName() );
120 pRet
= m_pParent
->GetTabWindow( pRef
->GetComposedName() );
125 void OTableConnection::Select()
128 m_pParent
->Invalidate( GetBoundingRect(), InvalidateFlags::NoChildren
);
131 void OTableConnection::Deselect()
134 InvalidateConnection();
137 bool OTableConnection::CheckHit( const Point
& rMousePos
) const
139 // check if the point hit our line
140 return std::any_of(m_vConnLine
.begin(),
143 ( const std::unique_ptr
<OConnectionLine
> & pLine
)
144 { return pLine
->CheckHit( rMousePos
); } );
147 void OTableConnection::InvalidateConnection()
149 tools::Rectangle rcBounding
= GetBoundingRect();
150 rcBounding
.AdjustBottom(1 );
151 rcBounding
.AdjustRight(1 );
152 // I believe Invalidate and Draw(Rectangle) do not behave consistent: in any case it
153 // could explain, why without the fake here when deleting a connection a dash remains at the lower end:
154 // Invalidate records obviously one pixel line less as Draw.
155 // Or everything works differently... in any case it works...
156 m_pParent
->Invalidate( rcBounding
, InvalidateFlags::NoChildren
);
159 tools::Rectangle
OTableConnection::GetBoundingRect() const
161 // determine all lines of the surrounding rectangle
162 tools::Rectangle
aBoundingRect( Point(0,0), Point(0,0) );
163 tools::Rectangle aTempRect
;
164 for (auto const& elem
: m_vConnLine
)
166 aTempRect
= elem
->GetBoundingRect();
168 // is the BoundingRect of this line valid?
169 if( (aTempRect
.GetWidth()!=1) && (aTempRect
.GetHeight()!=1) )
171 if( (aBoundingRect
.GetWidth()==1) && (aBoundingRect
.GetHeight()==1) )
172 aBoundingRect
= aTempRect
;
174 aBoundingRect
.Union( aTempRect
);
178 return aBoundingRect
;
181 void OTableConnection::Draw(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& /*rRect*/)
184 for( const auto& pLine
: m_vConnLine
)
185 pLine
->Draw( &rRenderContext
);
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */