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 comphelper
;
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star::accessibility
;
33 OTableConnection::OTableConnection( OJoinTableView
* _pContainer
, TTableConnectionData::value_type _aTabConnData
)
35 ,m_pData(std::move( _aTabConnData
))
36 ,m_pParent( _pContainer
)
43 OTableConnection::OTableConnection( const OTableConnection
& _rConn
)
45 ,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 m_vConnLine
.reserve(rLineData
.size());
57 for (auto const& elem
: rLineData
)
58 m_vConnLine
.emplace_back( new OConnectionLine(this, elem
) );
61 void OTableConnection::clearLineData()
65 void OTableConnection::UpdateLineList()
73 OTableConnection
& OTableConnection::operator=( const OTableConnection
& rConn
)
82 if(! rConn
.GetConnLineList().empty() )
84 const std::vector
<std::unique_ptr
<OConnectionLine
>>& rLine
= rConn
.GetConnLineList();
85 m_vConnLine
.reserve(rLine
.size());
86 for (auto const& elem
: rLine
)
87 m_vConnLine
.emplace_back( new OConnectionLine(*elem
));
90 // as the data are not mine, I also do not delete the old
91 m_pData
->CopyFrom(*rConn
.GetData());
92 // CopyFrom is virtual, therefore it is not a problem if m_pData is a derived type of OTableConnectionData
94 m_bSelected
= rConn
.m_bSelected
;
95 m_pParent
= rConn
.m_pParent
;
100 void OTableConnection::RecalcLines()
102 // call RecalcLines on each line
103 for( const auto& pLine
: m_vConnLine
)
106 OTableWindow
* OTableConnection::GetSourceWin() const
108 TTableWindowData::value_type pRef
= GetData()->getReferencingTable();
109 OTableWindow
* pRet
= m_pParent
->GetTabWindow( pRef
->GetWinName() );
112 pRet
= m_pParent
->GetTabWindow( pRef
->GetComposedName() );
116 OTableWindow
* OTableConnection::GetDestWin() const
118 TTableWindowData::value_type pRef
= GetData()->getReferencedTable();
119 OTableWindow
* pRet
= m_pParent
->GetTabWindow( pRef
->GetWinName() );
122 pRet
= m_pParent
->GetTabWindow( pRef
->GetComposedName() );
127 void OTableConnection::Select()
130 m_pParent
->Invalidate( GetBoundingRect(), InvalidateFlags::NoChildren
);
133 void OTableConnection::Deselect()
136 InvalidateConnection();
139 bool OTableConnection::CheckHit( const Point
& rMousePos
) const
141 // check if the point hit our line
142 return std::any_of(m_vConnLine
.begin(),
145 ( const std::unique_ptr
<OConnectionLine
> & pLine
)
146 { return pLine
->CheckHit( rMousePos
); } );
149 void OTableConnection::InvalidateConnection()
151 tools::Rectangle rcBounding
= GetBoundingRect();
152 rcBounding
.AdjustBottom(1 );
153 rcBounding
.AdjustRight(1 );
154 // I believe Invalidate and Draw(Rectangle) do not behave consistent: in any case it
155 // could explain, why without the fake here when deleting a connection a dash remains at the lower end:
156 // Invalidate records obviously one pixel line less as Draw.
157 // Or everything works differently... in any case it works...
158 m_pParent
->Invalidate( rcBounding
, InvalidateFlags::NoChildren
);
161 tools::Rectangle
OTableConnection::GetBoundingRect() const
163 // determine all lines of the surrounding rectangle
164 tools::Rectangle
aBoundingRect( Point(0,0), Point(0,0) );
165 tools::Rectangle aTempRect
;
166 for (auto const& elem
: m_vConnLine
)
168 aTempRect
= elem
->GetBoundingRect();
170 // is the BoundingRect of this line valid?
171 if( (aTempRect
.GetWidth()!=1) && (aTempRect
.GetHeight()!=1) )
173 if( (aBoundingRect
.GetWidth()==1) && (aBoundingRect
.GetHeight()==1) )
174 aBoundingRect
= aTempRect
;
176 aBoundingRect
.Union( aTempRect
);
180 return aBoundingRect
;
183 void OTableConnection::Draw(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& /*rRect*/)
186 for( const auto& pLine
: m_vConnLine
)
187 pLine
->Draw( &rRenderContext
);
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */