File: | home/maarten/src/libreoffice/core/dbaccess/source/ui/querydesign/JoinTableView.cxx |
Warning: | line 274, column 5 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 <JoinTableView.hxx> | |||
21 | #include <osl/diagnose.h> | |||
22 | #include <JoinController.hxx> | |||
23 | #include <JoinDesignView.hxx> | |||
24 | #include <TableWindow.hxx> | |||
25 | #include <TableWindowListBox.hxx> | |||
26 | #include <TableConnection.hxx> | |||
27 | #include <TableConnectionData.hxx> | |||
28 | #include <ConnectionLine.hxx> | |||
29 | #include <ConnectionLineData.hxx> | |||
30 | #include <browserids.hxx> | |||
31 | #include <com/sun/star/sdbc/XDatabaseMetaData.hpp> | |||
32 | #include <com/sun/star/sdbc/SQLException.hpp> | |||
33 | #include "QueryMoveTabWinUndoAct.hxx" | |||
34 | #include "QuerySizeTabWinUndoAct.hxx" | |||
35 | #include <toolkit/helper/vclunohelper.hxx> | |||
36 | #include <vcl/menu.hxx> | |||
37 | #include <vcl/svapp.hxx> | |||
38 | #include <vcl/settings.hxx> | |||
39 | #include <vcl/commandevent.hxx> | |||
40 | #include <vcl/event.hxx> | |||
41 | #include <vcl/ptrstyle.hxx> | |||
42 | #include <vcl/builder.hxx> | |||
43 | #include <TableWindowData.hxx> | |||
44 | #include <JAccess.hxx> | |||
45 | #include <com/sun/star/accessibility/XAccessible.hpp> | |||
46 | #include <com/sun/star/accessibility/AccessibleRole.hpp> | |||
47 | #include <com/sun/star/accessibility/AccessibleEventId.hpp> | |||
48 | #include <cppuhelper/exc_hlp.hxx> | |||
49 | #include <connectivity/dbtools.hxx> | |||
50 | #include <tools/diagnose_ex.h> | |||
51 | #include <algorithm> | |||
52 | #include <functional> | |||
53 | ||||
54 | using namespace dbaui; | |||
55 | using namespace ::com::sun::star::uno; | |||
56 | using namespace ::com::sun::star::sdbc; | |||
57 | using namespace ::com::sun::star::accessibility; | |||
58 | using namespace ::com::sun::star::container; | |||
59 | using namespace ::com::sun::star::lang; | |||
60 | ||||
61 | #define LINE_SIZE50 50 | |||
62 | // Constants for the window layout | |||
63 | #define TABWIN_SPACING_X17 17 | |||
64 | #define TABWIN_SPACING_Y17 17 | |||
65 | ||||
66 | #define TABWIN_WIDTH_STD120 120 | |||
67 | #define TABWIN_HEIGHT_STD120 120 | |||
68 | ||||
69 | OScrollWindowHelper::OScrollWindowHelper( vcl::Window* pParent) : Window( pParent) | |||
70 | ,m_aHScrollBar( VclPtr<ScrollBar>::Create(this, WB_HSCROLL|WB_REPEAT|WB_DRAG) ) | |||
71 | ,m_aVScrollBar( VclPtr<ScrollBar>::Create(this, WB_VSCROLL|WB_REPEAT|WB_DRAG) ) | |||
72 | ,m_pCornerWindow(VclPtr<ScrollBarBox>::Create(this, WB_3DLOOK)) | |||
73 | ,m_pTableView(nullptr) | |||
74 | { | |||
75 | ||||
76 | // ScrollBars | |||
77 | ||||
78 | GetHScrollBar().SetRange( Range(0, 1000) ); | |||
79 | GetVScrollBar().SetRange( Range(0, 1000) ); | |||
80 | ||||
81 | GetHScrollBar().SetLineSize( LINE_SIZE50 ); | |||
82 | GetVScrollBar().SetLineSize( LINE_SIZE50 ); | |||
83 | ||||
84 | GetHScrollBar().Show(); | |||
85 | GetVScrollBar().Show(); | |||
86 | m_pCornerWindow->Show(); | |||
87 | ||||
88 | // normally we should be SCROLL_PANE | |||
89 | SetAccessibleRole(AccessibleRole::SCROLL_PANE); | |||
90 | } | |||
91 | ||||
92 | OScrollWindowHelper::~OScrollWindowHelper() | |||
93 | { | |||
94 | disposeOnce(); | |||
95 | } | |||
96 | ||||
97 | void OScrollWindowHelper::dispose() | |||
98 | { | |||
99 | m_aHScrollBar.disposeAndClear(); | |||
100 | m_aVScrollBar.disposeAndClear(); | |||
101 | m_pCornerWindow.disposeAndClear(); | |||
102 | m_pTableView.clear(); | |||
103 | vcl::Window::dispose(); | |||
104 | } | |||
105 | ||||
106 | void OScrollWindowHelper::setTableView(OJoinTableView* _pTableView) | |||
107 | { | |||
108 | m_pTableView = _pTableView; | |||
109 | // ScrollBars | |||
110 | GetHScrollBar().SetScrollHdl( LINK(m_pTableView, OJoinTableView, ScrollHdl)::tools::detail::makeLink( ::tools::detail::castTo<OJoinTableView *>(m_pTableView), &OJoinTableView::LinkStubScrollHdl) ); | |||
111 | GetVScrollBar().SetScrollHdl( LINK(m_pTableView, OJoinTableView, ScrollHdl)::tools::detail::makeLink( ::tools::detail::castTo<OJoinTableView *>(m_pTableView), &OJoinTableView::LinkStubScrollHdl) ); | |||
112 | } | |||
113 | ||||
114 | void OScrollWindowHelper::resetRange(const Point& _aSize) | |||
115 | { | |||
116 | Point aPos = PixelToLogic(_aSize); | |||
117 | GetHScrollBar().SetRange( Range(0, aPos.X() + TABWIN_SPACING_X17) ); | |||
118 | GetVScrollBar().SetRange( Range(0, aPos.Y() + TABWIN_SPACING_Y17) ); | |||
119 | } | |||
120 | ||||
121 | void OScrollWindowHelper::Resize() | |||
122 | { | |||
123 | Window::Resize(); | |||
124 | ||||
125 | Size aTotalOutputSize = GetOutputSizePixel(); | |||
126 | long nHScrollHeight = GetHScrollBar().GetSizePixel().Height(); | |||
127 | long nVScrollWidth = GetVScrollBar().GetSizePixel().Width(); | |||
128 | ||||
129 | GetHScrollBar().SetPosSizePixel( | |||
130 | Point( 0, aTotalOutputSize.Height()-nHScrollHeight ), | |||
131 | Size( aTotalOutputSize.Width()-nVScrollWidth, nHScrollHeight ) | |||
132 | ); | |||
133 | ||||
134 | GetVScrollBar().SetPosSizePixel( | |||
135 | Point( aTotalOutputSize.Width()-nVScrollWidth, 0 ), | |||
136 | Size( nVScrollWidth, aTotalOutputSize.Height()-nHScrollHeight ) | |||
137 | ); | |||
138 | ||||
139 | m_pCornerWindow->SetPosSizePixel( | |||
140 | Point( aTotalOutputSize.Width() - nVScrollWidth, aTotalOutputSize.Height() - nHScrollHeight), | |||
141 | Size( nVScrollWidth, nHScrollHeight ) | |||
142 | ); | |||
143 | ||||
144 | GetHScrollBar().SetPageSize( aTotalOutputSize.Width() ); | |||
145 | GetHScrollBar().SetVisibleSize( aTotalOutputSize.Width() ); | |||
146 | ||||
147 | GetVScrollBar().SetPageSize( aTotalOutputSize.Height() ); | |||
148 | GetVScrollBar().SetVisibleSize( aTotalOutputSize.Height() ); | |||
149 | ||||
150 | // adjust the ranges of the scrollbars if necessary | |||
151 | long lRange = GetHScrollBar().GetRange().Max() - GetHScrollBar().GetRange().Min(); | |||
152 | if (m_pTableView->GetScrollOffset().X() + aTotalOutputSize.Width() > lRange) | |||
153 | GetHScrollBar().SetRangeMax(m_pTableView->GetScrollOffset().X() + aTotalOutputSize.Width() + GetHScrollBar().GetRange().Min()); | |||
154 | ||||
155 | lRange = GetVScrollBar().GetRange().Max() - GetVScrollBar().GetRange().Min(); | |||
156 | if (m_pTableView->GetScrollOffset().Y() + aTotalOutputSize.Height() > lRange) | |||
157 | GetVScrollBar().SetRangeMax(m_pTableView->GetScrollOffset().Y() + aTotalOutputSize.Height() + GetVScrollBar().GetRange().Min()); | |||
158 | ||||
159 | m_pTableView->SetPosSizePixel(Point( 0, 0 ),Size( aTotalOutputSize.Width()-nVScrollWidth, aTotalOutputSize.Height()-nHScrollHeight )); | |||
160 | } | |||
161 | ||||
162 | ||||
163 | OJoinTableView::OJoinTableView( vcl::Window* pParent, OJoinDesignView* pView ) | |||
164 | :Window( pParent,WB_BORDER ) | |||
165 | ,DropTargetHelper(this) | |||
166 | ,m_aDragOffset( Point(0,0) ) | |||
167 | ,m_aScrollOffset( Point(0,0) ) | |||
168 | ,m_pDragWin( nullptr ) | |||
169 | ,m_pSizingWin( nullptr ) | |||
170 | ,m_pSelectedConn( nullptr ) | |||
171 | ,m_pLastFocusTabWin(nullptr) | |||
172 | ,m_pView( pView ) | |||
173 | ,m_pAccessible(nullptr) | |||
174 | { | |||
175 | SetSizePixel( Size(1000, 1000) ); | |||
176 | ||||
177 | InitColors(); | |||
178 | ||||
179 | m_aDragScrollIdle.SetInvokeHandler(LINK(this, OJoinTableView, OnDragScrollTimer)::tools::detail::makeLink( ::tools::detail::castTo<OJoinTableView *>(this), &OJoinTableView::LinkStubOnDragScrollTimer)); | |||
180 | } | |||
181 | ||||
182 | OJoinTableView::~OJoinTableView() | |||
183 | { | |||
184 | disposeOnce(); | |||
185 | } | |||
186 | ||||
187 | void OJoinTableView::dispose() | |||
188 | { | |||
189 | if( m_pAccessible ) | |||
190 | { | |||
191 | m_pAccessible->clearTableView(); | |||
192 | m_pAccessible = nullptr; | |||
193 | } | |||
194 | // delete lists | |||
195 | clearLayoutInformation(); | |||
196 | m_pDragWin.clear(); | |||
197 | m_pSizingWin.clear(); | |||
198 | m_pSelectedConn.clear(); | |||
199 | m_pLastFocusTabWin.clear(); | |||
200 | m_pView.clear(); | |||
201 | m_vTableConnection.clear(); | |||
202 | vcl::Window::dispose(); | |||
203 | } | |||
204 | ||||
205 | IMPL_LINK( OJoinTableView, ScrollHdl, ScrollBar*, pScrollBar, void )void OJoinTableView::LinkStubScrollHdl(void * instance, ScrollBar * data) { return static_cast<OJoinTableView *>(instance )->ScrollHdl(data); } void OJoinTableView::ScrollHdl(ScrollBar * pScrollBar) | |||
206 | { | |||
207 | // move all windows | |||
208 | ScrollPane( pScrollBar->GetDelta(), (pScrollBar == &GetHScrollBar()), false ); | |||
209 | } | |||
210 | ||||
211 | void OJoinTableView::Resize() | |||
212 | { | |||
213 | Window::Resize(); | |||
214 | m_aOutputSize = GetSizePixel(); | |||
215 | ||||
216 | // tab win positions may not be up-to-date | |||
217 | if (m_aTableMap.empty()) | |||
218 | // no tab wins ... | |||
219 | return; | |||
220 | ||||
221 | // we have at least one table so resize it | |||
222 | m_aScrollOffset.setX( GetHScrollBar().GetThumbPos() ); | |||
223 | m_aScrollOffset.setY( GetVScrollBar().GetThumbPos() ); | |||
224 | ||||
225 | VclPtr<OTableWindow> pCheck = m_aTableMap.begin()->second; | |||
226 | Point aRealPos = pCheck->GetPosPixel(); | |||
227 | Point aAssumedPos = pCheck->GetData()->GetPosition() - GetScrollOffset(); | |||
228 | ||||
229 | if (aRealPos == aAssumedPos) | |||
230 | // all ok | |||
231 | return; | |||
232 | ||||
233 | for (auto const& elem : m_aTableMap) | |||
234 | { | |||
235 | OTableWindow* pCurrent = elem.second; | |||
236 | Point aPos(pCurrent->GetData()->GetPosition() - GetScrollOffset()); | |||
237 | pCurrent->SetPosPixel(aPos); | |||
238 | } | |||
239 | } | |||
240 | ||||
241 | sal_uLong OJoinTableView::GetTabWinCount() const | |||
242 | { | |||
243 | return m_aTableMap.size(); | |||
244 | } | |||
245 | ||||
246 | bool OJoinTableView::RemoveConnection(VclPtr<OTableConnection>& rConn, bool _bDelete) | |||
247 | { | |||
248 | VclPtr<OTableConnection> xConn(rConn); | |||
249 | ||||
250 | DeselectConn(xConn); | |||
251 | ||||
252 | // to force a redraw | |||
253 | xConn->InvalidateConnection(); | |||
254 | ||||
255 | m_pView->getController().removeConnectionData(xConn->GetData()); | |||
256 | ||||
257 | m_vTableConnection.erase(std::find(m_vTableConnection.begin(), m_vTableConnection.end(), xConn)); | |||
258 | ||||
259 | modified(); | |||
260 | if ( m_pAccessible ) | |||
261 | m_pAccessible->notifyAccessibleEvent( AccessibleEventId::CHILD, | |||
262 | makeAny(xConn->GetAccessible()), | |||
263 | Any()); | |||
264 | if (_bDelete) | |||
265 | xConn->disposeOnce(); | |||
266 | ||||
267 | return true; | |||
268 | } | |||
269 | ||||
270 | OTableWindow* OJoinTableView::GetTabWindow( const OUString& rName ) | |||
271 | { | |||
272 | OTableWindowMap::const_iterator aIter = m_aTableMap.find(rName); | |||
273 | ||||
274 | return aIter == m_aTableMap.end() ? nullptr : aIter->second; | |||
| ||||
| ||||
275 | } | |||
276 | ||||
277 | TTableWindowData::value_type OJoinTableView::createTableWindowData(const OUString& _rComposedName | |||
278 | ,const OUString& _sTableName | |||
279 | ,const OUString& _rWinName) | |||
280 | { | |||
281 | TTableWindowData::value_type pData( CreateImpl(_rComposedName, _sTableName,_rWinName) ); | |||
282 | OJoinDesignView* pParent = getDesignView(); | |||
283 | try | |||
284 | { | |||
285 | if ( !pData->init(pParent->getController().getConnection(),allowQueries()) ) | |||
286 | { | |||
287 | if ( pData->isValid() ) | |||
288 | onNoColumns_throw(); | |||
289 | else | |||
290 | pData.reset(); | |||
291 | } | |||
292 | } | |||
293 | catch ( const SQLException& ) | |||
294 | { | |||
295 | ::dbtools::showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), | |||
296 | VCLUnoHelper::GetInterface(pParent), pParent->getController().getORB() ); | |||
297 | } | |||
298 | catch( const WrappedTargetException& e ) | |||
299 | { | |||
300 | SQLException aSql; | |||
301 | if ( e.TargetException >>= aSql ) | |||
302 | ::dbtools::showError( ::dbtools::SQLExceptionInfo( aSql ), VCLUnoHelper::GetInterface(pParent), pParent->getController().getORB() ); | |||
303 | } | |||
304 | catch( const Exception& ) | |||
305 | { | |||
306 | DBG_UNHANDLED_EXCEPTION("dbaccess")DbgUnhandledException( DbgGetCaughtException(), __func__, "/home/maarten/src/libreoffice/core/dbaccess/source/ui/querydesign/JoinTableView.cxx" ":" "306" ": ", "dbaccess" );; | |||
307 | } | |||
308 | return pData; | |||
309 | } | |||
310 | ||||
311 | std::shared_ptr<OTableWindowData> OJoinTableView::CreateImpl(const OUString& _rComposedName | |||
312 | ,const OUString& _sTableName | |||
313 | ,const OUString& _rWinName) | |||
314 | { | |||
315 | return std::make_shared<OTableWindowData>( nullptr,_rComposedName,_sTableName, _rWinName ); | |||
316 | } | |||
317 | ||||
318 | void OJoinTableView::AddTabWin(const OUString& _rComposedName, const OUString& rWinName, bool /*bNewTable*/) | |||
319 | { | |||
320 | OSL_ENSURE(!_rComposedName.isEmpty(),"There must be a table name supplied!")do { if (true && (!(!_rComposedName.isEmpty()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/querydesign/JoinTableView.cxx" ":" "320" ": "), "%s", "There must be a table name supplied!" ); } } while (false); | |||
321 | ||||
322 | TTableWindowData::value_type pNewTabWinData(createTableWindowData( _rComposedName, rWinName,rWinName )); | |||
323 | ||||
324 | // insert new window in window list | |||
325 | VclPtr<OTableWindow> pNewTabWin = createWindow( pNewTabWinData ); | |||
326 | if ( pNewTabWin->Init() ) | |||
327 | { | |||
328 | m_pView->getController().getTableWindowData().push_back( pNewTabWinData); | |||
329 | // when we already have a table with this name insert the full qualified one instead | |||
330 | if(m_aTableMap.find(rWinName) != m_aTableMap.end()) | |||
331 | m_aTableMap[_rComposedName] = pNewTabWin; | |||
332 | else | |||
333 | m_aTableMap[rWinName] = pNewTabWin; | |||
334 | ||||
335 | SetDefaultTabWinPosSize( pNewTabWin ); | |||
336 | pNewTabWin->Show(); | |||
337 | ||||
338 | modified(); | |||
339 | if ( m_pAccessible ) | |||
340 | m_pAccessible->notifyAccessibleEvent( AccessibleEventId::CHILD, | |||
341 | Any(), | |||
342 | makeAny(pNewTabWin->GetAccessible())); | |||
343 | } | |||
344 | else | |||
345 | { | |||
346 | pNewTabWin->clearListBox(); | |||
347 | pNewTabWin.disposeAndClear(); | |||
348 | } | |||
349 | } | |||
350 | ||||
351 | void OJoinTableView::RemoveTabWin( OTableWindow* pTabWin ) | |||
352 | { | |||
353 | // first delete all connections of this window to others | |||
354 | bool bRemove = true; | |||
355 | TTableWindowData::value_type pData = pTabWin->GetData(); | |||
356 | sal_Int32 nCount = m_vTableConnection.size(); | |||
357 | auto aIter = m_vTableConnection.rbegin(); | |||
358 | while(aIter != m_vTableConnection.rend() && bRemove) | |||
359 | { | |||
360 | VclPtr<OTableConnection>& rTabConn = *aIter; | |||
361 | if ( | |||
362 | (pData == rTabConn->GetData()->getReferencingTable()) || | |||
363 | (pData == rTabConn->GetData()->getReferencedTable()) | |||
364 | ) | |||
365 | { | |||
366 | bRemove = RemoveConnection(rTabConn, true); | |||
367 | aIter = m_vTableConnection.rbegin(); | |||
368 | } | |||
369 | else | |||
370 | ++aIter; | |||
371 | } | |||
372 | ||||
373 | // then delete the window itself | |||
374 | if ( bRemove ) | |||
375 | { | |||
376 | if ( m_pAccessible ) | |||
377 | m_pAccessible->notifyAccessibleEvent( AccessibleEventId::CHILD, | |||
378 | makeAny(pTabWin->GetAccessible()),Any() | |||
379 | ); | |||
380 | ||||
381 | pTabWin->Hide(); | |||
382 | OJoinController& rController = m_pView->getController(); | |||
383 | TTableWindowData::iterator aFind = std::find(rController.getTableWindowData().begin(), rController.getTableWindowData().end(), pData); | |||
384 | if(aFind != rController.getTableWindowData().end()) | |||
385 | { | |||
386 | rController.getTableWindowData().erase(aFind); | |||
387 | rController.setModified(true); | |||
388 | } | |||
389 | ||||
390 | if ( !m_aTableMap.erase( pTabWin->GetWinName() ) ) | |||
391 | m_aTableMap.erase( pTabWin->GetComposedName() ); | |||
392 | ||||
393 | if (pTabWin == m_pLastFocusTabWin) | |||
394 | m_pLastFocusTabWin = nullptr; | |||
395 | ||||
396 | pTabWin->clearListBox(); | |||
397 | pTabWin->disposeOnce(); | |||
398 | } | |||
399 | ||||
400 | if ( static_cast<sal_Int32>(m_vTableConnection.size()) < (nCount-1) ) // if some connections could be removed | |||
401 | modified(); | |||
402 | } | |||
403 | ||||
404 | namespace | |||
405 | { | |||
406 | bool isScrollAllowed( OJoinTableView* _pView,long nDelta, bool bHoriz) | |||
407 | { | |||
408 | // adjust ScrollBar-Positions | |||
409 | ScrollBar& rBar = bHoriz ? _pView->GetHScrollBar() : _pView->GetVScrollBar() ; | |||
410 | ||||
411 | long nOldThumbPos = rBar.GetThumbPos(); | |||
412 | long nNewThumbPos = nOldThumbPos + nDelta; | |||
413 | if( nNewThumbPos < 0 ) | |||
414 | nNewThumbPos = 0; | |||
415 | else if( nNewThumbPos > rBar.GetRangeMax() ) | |||
416 | nNewThumbPos = rBar.GetRangeMax(); | |||
417 | ||||
418 | if ( bHoriz ) | |||
419 | { | |||
420 | if( nNewThumbPos == _pView->GetScrollOffset().X() ) | |||
421 | return false; | |||
422 | } | |||
423 | else if ( nNewThumbPos == _pView->GetScrollOffset().Y() ) | |||
424 | return false; | |||
425 | ||||
426 | return true; | |||
427 | } | |||
428 | bool getMovementImpl(OJoinTableView* _pView,const Point& _rPoint,const Size& _rSize,long& _nScrollX,long& _nScrollY) | |||
429 | { | |||
430 | _nScrollY = _nScrollX = 0; | |||
431 | // data about the tab win | |||
432 | Point aUpperLeft = _rPoint; | |||
433 | // normalize with respect to visibility | |||
434 | aUpperLeft -= _pView->GetScrollOffset(); | |||
435 | Point aLowerRight(aUpperLeft.X() + _rSize.Width(), aUpperLeft.Y() + _rSize.Height()); | |||
436 | ||||
437 | // data about ourself | |||
438 | Size aSize = _pView->getRealOutputSize(); //GetOutputSizePixel(); | |||
439 | ||||
440 | bool bVisible = true; | |||
441 | bool bFitsHor = (aUpperLeft.X() >= 0) && (aLowerRight.X() <= aSize.Width()); | |||
442 | bool bFitsVert= (aUpperLeft.Y() >= 0) && (aLowerRight.Y() <= aSize.Height()); | |||
443 | if (!bFitsHor || !bFitsVert) | |||
444 | { | |||
445 | if (!bFitsHor) | |||
446 | { | |||
447 | // ensure the visibility of the right border | |||
448 | if ( aLowerRight.X() > aSize.Width() ) | |||
449 | _nScrollX = aLowerRight.X() - aSize.Width() + TABWIN_SPACING_X17; | |||
450 | ||||
451 | // ensure the visibility of the left border (higher priority) | |||
452 | if ( aUpperLeft.X() < 0 ) | |||
453 | _nScrollX = aUpperLeft.X() - TABWIN_SPACING_X17; | |||
454 | } | |||
455 | ||||
456 | if (!bFitsVert) | |||
457 | { | |||
458 | // lower border | |||
459 | if ( aLowerRight.Y() > aSize.Height() ) | |||
460 | _nScrollY = aLowerRight.Y() - aSize.Height() + TABWIN_SPACING_Y17; | |||
461 | // upper border | |||
462 | if ( aUpperLeft.Y() < 0 ) | |||
463 | _nScrollY = aUpperLeft.Y() - TABWIN_SPACING_Y17; | |||
464 | } | |||
465 | ||||
466 | if ( _nScrollX ) // aSize.Width() > _rSize.Width() && | |||
467 | bVisible = isScrollAllowed(_pView,_nScrollX, true); | |||
468 | ||||
469 | if ( _nScrollY ) // aSize.Height() > _rSize.Height() && | |||
470 | bVisible = bVisible && isScrollAllowed(_pView,_nScrollY, false); | |||
471 | ||||
472 | if ( bVisible ) | |||
473 | { | |||
474 | sal_Int32 nHRangeMax = _pView->GetHScrollBar().GetRangeMax(); | |||
475 | sal_Int32 nVRangeMax = _pView->GetVScrollBar().GetRangeMax(); | |||
476 | ||||
477 | if ( aSize.Width() + _pView->GetHScrollBar().GetThumbPos() + _nScrollX > nHRangeMax ) | |||
478 | bVisible = false; | |||
479 | if ( bVisible && aSize.Height() + _pView->GetVScrollBar().GetThumbPos() + _nScrollY > nVRangeMax ) | |||
480 | bVisible = false; | |||
481 | } | |||
482 | } | |||
483 | ||||
484 | return bVisible; | |||
485 | } | |||
486 | } // end of ano namespace | |||
487 | ||||
488 | bool OJoinTableView::isMovementAllowed(const Point& _rPoint,const Size& _rSize) | |||
489 | { | |||
490 | long nX,nY; | |||
491 | return getMovementImpl(this,_rPoint,_rSize,nX,nY); | |||
492 | } | |||
493 | ||||
494 | void OJoinTableView::EnsureVisible(const OTableWindow* _pWin) | |||
495 | { | |||
496 | // data about the tab win | |||
497 | TTableWindowData::value_type pData = _pWin->GetData(); | |||
498 | EnsureVisible( pData->GetPosition() , pData->GetSize()); | |||
499 | Invalidate(InvalidateFlags::NoChildren); | |||
500 | } | |||
501 | ||||
502 | void OJoinTableView::EnsureVisible(const Point& _rPoint,const Size& _rSize) | |||
503 | { | |||
504 | long nScrollX,nScrollY; | |||
505 | ||||
506 | if ( getMovementImpl(this,_rPoint,_rSize,nScrollX,nScrollY) ) | |||
507 | { | |||
508 | bool bVisible = true; | |||
509 | if (nScrollX) | |||
510 | bVisible = ScrollPane(nScrollX, true, true); | |||
511 | ||||
512 | if (nScrollY && bVisible) | |||
513 | ScrollPane(nScrollY, false, true); | |||
514 | } | |||
515 | } | |||
516 | ||||
517 | void OJoinTableView::SetDefaultTabWinPosSize( OTableWindow* pTabWin ) | |||
518 | { | |||
519 | // determine position: | |||
520 | // the window is divided into lines with height TABWIN_SPACING_Y+TABWIN_HEIGHT_STD. | |||
521 | // Then for each line is checked, if there is space for another window. | |||
522 | // If there is no space, the next line is checked. | |||
523 | Size aOutSize = GetSizePixel(); | |||
524 | Point aNewPos( 0,0 ); | |||
525 | sal_uInt16 nRow = 0; | |||
526 | bool bEnd = false; | |||
527 | while( !bEnd ) | |||
528 | { | |||
529 | // Set new position to start of line | |||
530 | aNewPos.setX( TABWIN_SPACING_X17 ); | |||
531 | aNewPos.setY( (nRow+1) * TABWIN_SPACING_Y17 ); | |||
532 | ||||
533 | // determine rectangle for the corresponding line | |||
534 | tools::Rectangle aRowRect( Point(0,0), aOutSize ); | |||
535 | aRowRect.SetTop( nRow * ( TABWIN_SPACING_Y17 + TABWIN_HEIGHT_STD120 ) ); | |||
536 | aRowRect.SetBottom( (nRow+1) * ( TABWIN_SPACING_Y17 + TABWIN_HEIGHT_STD120 ) ); | |||
537 | ||||
538 | // check occupied areas of this line | |||
539 | for (auto const& elem : m_aTableMap) | |||
540 | { | |||
541 | OTableWindow* pOtherTabWin = elem.second; | |||
542 | tools::Rectangle aOtherTabWinRect( pOtherTabWin->GetPosPixel(), pOtherTabWin->GetSizePixel() ); | |||
543 | ||||
544 | if( | |||
545 | ( (aOtherTabWinRect.Top()>aRowRect.Top()) && (aOtherTabWinRect.Top()<aRowRect.Bottom()) ) || | |||
546 | ( (aOtherTabWinRect.Bottom()>aRowRect.Top()) && (aOtherTabWinRect.Bottom()<aRowRect.Bottom()) ) | |||
547 | ) | |||
548 | { | |||
549 | // TabWin is in the line | |||
550 | if( aOtherTabWinRect.Right()>aNewPos.X() ) | |||
551 | aNewPos.setX( aOtherTabWinRect.Right() + TABWIN_SPACING_X17 ); | |||
552 | } | |||
553 | } | |||
554 | ||||
555 | // Is there space left in this line? | |||
556 | if( (aNewPos.X()+TABWIN_WIDTH_STD120)<aRowRect.Right() ) | |||
557 | { | |||
558 | aNewPos.setY( aRowRect.Top() + TABWIN_SPACING_Y17 ); | |||
559 | bEnd = true; | |||
560 | } | |||
561 | else | |||
562 | { | |||
563 | if( (aRowRect.Bottom()+aRowRect.GetHeight()) > aOutSize.Height() ) | |||
564 | { | |||
565 | // insert it in the first row | |||
566 | sal_Int32 nCount = m_aTableMap.size() % (nRow+1); | |||
567 | ++nCount; | |||
568 | aNewPos.setY( nCount * TABWIN_SPACING_Y17 + (nCount-1)*CalcZoom(TABWIN_HEIGHT_STD120) ); | |||
569 | bEnd = true; | |||
570 | } | |||
571 | else | |||
572 | nRow++; | |||
573 | ||||
574 | } | |||
575 | } | |||
576 | ||||
577 | // determine size | |||
578 | Size aNewSize( CalcZoom(TABWIN_WIDTH_STD120), CalcZoom(TABWIN_HEIGHT_STD120) ); | |||
579 | ||||
580 | // check if the new position in inside the scrollbars ranges | |||
581 | Point aBottom(aNewPos); | |||
582 | aBottom.AdjustX(aNewSize.Width() ); | |||
583 | aBottom.AdjustY(aNewSize.Height() ); | |||
584 | ||||
585 | if(!GetHScrollBar().GetRange().IsInside(aBottom.X())) | |||
586 | GetHScrollBar().SetRange( Range(0, aBottom.X()) ); | |||
587 | if(!GetVScrollBar().GetRange().IsInside(aBottom.Y())) | |||
588 | GetVScrollBar().SetRange( Range(0, aBottom.Y()) ); | |||
589 | ||||
590 | pTabWin->SetPosSizePixel( aNewPos, aNewSize ); | |||
591 | } | |||
592 | ||||
593 | void OJoinTableView::DataChanged(const DataChangedEvent& rDCEvt) | |||
594 | { | |||
595 | if (rDCEvt.GetType() == DataChangedEventType::SETTINGS) | |||
596 | { | |||
597 | // consider the worst case: the colors changed, so adjust me | |||
598 | InitColors(); | |||
599 | Invalidate(InvalidateFlags::NoChildren); | |||
600 | // due to the Invalidate, the connections are redrawn, so that they are also pictured in the new colors | |||
601 | } | |||
602 | } | |||
603 | ||||
604 | void OJoinTableView::InitColors() | |||
605 | { | |||
606 | // the colors for the illustration should be the system colors | |||
607 | StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings(); | |||
608 | SetBackground(Wallpaper(aSystemStyle.GetDialogColor())); | |||
609 | } | |||
610 | ||||
611 | void OJoinTableView::BeginChildMove( OTableWindow* pTabWin, const Point& rMousePos ) | |||
612 | { | |||
613 | ||||
614 | if (m_pView->getController().isReadOnly()) | |||
615 | return; | |||
616 | ||||
617 | m_pDragWin = pTabWin; | |||
618 | SetPointer(PointerStyle::Move); | |||
619 | Point aMousePos = ScreenToOutputPixel( rMousePos ); | |||
620 | m_aDragOffset = aMousePos - pTabWin->GetPosPixel(); | |||
621 | m_pDragWin->SetZOrder(nullptr, ZOrderFlags::First); | |||
622 | StartTracking(); | |||
623 | } | |||
624 | ||||
625 | void OJoinTableView::NotifyTitleClicked( OTableWindow* pTabWin, const Point& rMousePos ) | |||
626 | { | |||
627 | DeselectConn(GetSelectedConn()); | |||
628 | BeginChildMove(pTabWin, rMousePos); | |||
629 | } | |||
630 | ||||
631 | void OJoinTableView::BeginChildSizing( OTableWindow* pTabWin, PointerStyle nPointer ) | |||
632 | { | |||
633 | ||||
634 | if (m_pView->getController().isReadOnly()) | |||
635 | return; | |||
636 | ||||
637 | SetPointer( nPointer ); | |||
638 | m_pSizingWin = pTabWin; | |||
639 | StartTracking(); | |||
640 | } | |||
641 | ||||
642 | bool OJoinTableView::ScrollPane( long nDelta, bool bHoriz, bool bPaintScrollBars ) | |||
643 | { | |||
644 | bool bRet = true; | |||
645 | ||||
646 | // adjust ScrollBar-Positions | |||
647 | if( bPaintScrollBars ) | |||
648 | { | |||
649 | if( bHoriz ) | |||
650 | { | |||
651 | long nOldThumbPos = GetHScrollBar().GetThumbPos(); | |||
652 | long nNewThumbPos = nOldThumbPos + nDelta; | |||
653 | if( nNewThumbPos < 0 ) | |||
654 | { | |||
655 | nNewThumbPos = 0; | |||
656 | bRet = false; | |||
657 | } | |||
658 | if( nNewThumbPos > GetHScrollBar().GetRange().Max() ) | |||
659 | { | |||
660 | nNewThumbPos = GetHScrollBar().GetRange().Max(); | |||
661 | bRet = false; | |||
662 | } | |||
663 | GetHScrollBar().SetThumbPos( nNewThumbPos ); | |||
664 | nDelta = GetHScrollBar().GetThumbPos() - nOldThumbPos; | |||
665 | } | |||
666 | else | |||
667 | { | |||
668 | long nOldThumbPos = GetVScrollBar().GetThumbPos(); | |||
669 | long nNewThumbPos = nOldThumbPos+nDelta; | |||
670 | if( nNewThumbPos < 0 ) | |||
671 | { | |||
672 | nNewThumbPos = 0; | |||
673 | bRet = false; | |||
674 | } | |||
675 | if( nNewThumbPos > GetVScrollBar().GetRange().Max() ) | |||
676 | { | |||
677 | nNewThumbPos = GetVScrollBar().GetRange().Max(); | |||
678 | bRet = false; | |||
679 | } | |||
680 | GetVScrollBar().SetThumbPos( nNewThumbPos ); | |||
681 | nDelta = GetVScrollBar().GetThumbPos() - nOldThumbPos; | |||
682 | } | |||
683 | } | |||
684 | ||||
685 | // If ScrollOffset hitting borders, no redrawing. | |||
686 | if( (GetHScrollBar().GetThumbPos()==m_aScrollOffset.X()) && | |||
687 | (GetVScrollBar().GetThumbPos()==m_aScrollOffset.Y()) ) | |||
688 | return false; | |||
689 | ||||
690 | // set ScrollOffset anew | |||
691 | if (bHoriz) | |||
692 | m_aScrollOffset.setX( GetHScrollBar().GetThumbPos() ); | |||
693 | else | |||
694 | m_aScrollOffset.setY( GetVScrollBar().GetThumbPos() ); | |||
695 | ||||
696 | // move all windows | |||
697 | OTableWindow* pTabWin; | |||
698 | Point aPos; | |||
699 | ||||
700 | for (auto const& elem : m_aTableMap) | |||
701 | { | |||
702 | pTabWin = elem.second; | |||
703 | aPos = pTabWin->GetPosPixel(); | |||
704 | ||||
705 | if( bHoriz ) | |||
706 | aPos.AdjustX( -nDelta ); | |||
707 | else aPos.AdjustY( -nDelta ); | |||
708 | ||||
709 | pTabWin->SetPosPixel( aPos ); | |||
710 | } | |||
711 | ||||
712 | Invalidate(); // InvalidateFlags::NoChildren | |||
713 | ||||
714 | return bRet; | |||
715 | } | |||
716 | ||||
717 | void OJoinTableView::Tracking( const TrackingEvent& rTEvt ) | |||
718 | { | |||
719 | HideTracking(); | |||
720 | ||||
721 | if (rTEvt.IsTrackingEnded()) | |||
722 | { | |||
723 | if( m_pDragWin ) | |||
724 | { | |||
725 | if (m_aDragScrollIdle.IsActive()) | |||
726 | m_aDragScrollIdle.Stop(); | |||
727 | ||||
728 | // adjust position of child after moving | |||
729 | // windows are not allowed to leave display range | |||
730 | Point aDragWinPos = rTEvt.GetMouseEvent().GetPosPixel() - m_aDragOffset; | |||
731 | Size aDragWinSize = m_pDragWin->GetSizePixel(); | |||
732 | if( aDragWinPos.X() < 0 ) | |||
733 | aDragWinPos.setX( 0 ); | |||
734 | if( aDragWinPos.Y() < 0 ) | |||
735 | aDragWinPos.setY( 0 ); | |||
736 | if( (aDragWinPos.X() + aDragWinSize.Width()) > m_aOutputSize.Width() ) | |||
737 | aDragWinPos.setX( m_aOutputSize.Width() - aDragWinSize.Width() - 1 ); | |||
738 | if( (aDragWinPos.Y() + aDragWinSize.Height()) > m_aOutputSize.Height() ) | |||
739 | aDragWinPos.setY( m_aOutputSize.Height() - aDragWinSize.Height() - 1 ); | |||
740 | if( aDragWinPos.X() < 0 ) | |||
741 | aDragWinPos.setX( 0 ); | |||
742 | if( aDragWinPos.Y() < 0 ) | |||
743 | aDragWinPos.setY( 0 ); | |||
744 | // TODO : don't position window anew, if it is leaving range, but just expand the range | |||
745 | ||||
746 | // position window | |||
747 | EndTracking(); | |||
748 | m_pDragWin->SetZOrder(nullptr, ZOrderFlags::First); | |||
749 | // check, if I really moved | |||
750 | // (this prevents setting the modified-Flag, when there actually was no change0 | |||
751 | TTableWindowData::value_type pData = m_pDragWin->GetData(); | |||
752 | if ( ! (pData && pData->HasPosition() && (pData->GetPosition() == aDragWinPos))) | |||
753 | { | |||
754 | // old logic coordinates | |||
755 | Point ptOldPos = m_pDragWin->GetPosPixel() + Point(GetHScrollBar().GetThumbPos(), GetVScrollBar().GetThumbPos()); | |||
756 | // new positioning | |||
757 | m_pDragWin->SetPosPixel(aDragWinPos); | |||
758 | TabWinMoved(m_pDragWin, ptOldPos); | |||
759 | ||||
760 | m_pDragWin->GrabFocus(); | |||
761 | } | |||
762 | m_pDragWin = nullptr; | |||
763 | SetPointer(PointerStyle::Arrow); | |||
764 | } | |||
765 | // else we handle the resizing | |||
766 | else if( m_pSizingWin ) | |||
767 | { | |||
768 | SetPointer( PointerStyle::Arrow ); | |||
769 | EndTracking(); | |||
770 | ||||
771 | // old physical coordinates | |||
772 | ||||
773 | Size szOld = m_pSizingWin->GetSizePixel(); | |||
774 | Point ptOld = m_pSizingWin->GetPosPixel(); | |||
775 | Size aNewSize(CalcZoom(m_aSizingRect.GetSize().Width()),CalcZoom(m_aSizingRect.GetSize().Height())); | |||
776 | m_pSizingWin->SetPosSizePixel( m_aSizingRect.TopLeft(), aNewSize ); | |||
777 | TabWinSized(m_pSizingWin, ptOld, szOld); | |||
778 | ||||
779 | m_pSizingWin->Invalidate( m_aSizingRect ); | |||
780 | m_pSizingWin = nullptr; | |||
781 | } | |||
782 | } | |||
783 | else if (rTEvt.IsTrackingCanceled()) | |||
784 | { | |||
785 | if (m_aDragScrollIdle.IsActive()) | |||
786 | m_aDragScrollIdle.Stop(); | |||
787 | EndTracking(); | |||
788 | } | |||
789 | else | |||
790 | { | |||
791 | if( m_pDragWin ) | |||
792 | { | |||
793 | m_ptPrevDraggingPos = rTEvt.GetMouseEvent().GetPosPixel(); | |||
794 | // scroll at window borders | |||
795 | ScrollWhileDragging(); | |||
796 | } | |||
797 | ||||
798 | if( m_pSizingWin ) | |||
799 | { | |||
800 | Point aMousePos = rTEvt.GetMouseEvent().GetPosPixel(); | |||
801 | m_aSizingRect = m_pSizingWin->getSizingRect(aMousePos,m_aOutputSize); | |||
802 | PaintImmediately(); | |||
803 | ShowTracking( m_aSizingRect, ShowTrackFlags::Small | ShowTrackFlags::TrackWindow ); | |||
804 | } | |||
805 | } | |||
806 | } | |||
807 | ||||
808 | void OJoinTableView::ConnDoubleClicked(VclPtr<OTableConnection>& /*rConnection*/) | |||
809 | { | |||
810 | } | |||
811 | ||||
812 | void OJoinTableView::MouseButtonDown( const MouseEvent& rEvt ) | |||
813 | { | |||
814 | GrabFocus(); | |||
815 | Window::MouseButtonDown(rEvt); | |||
816 | } | |||
817 | ||||
818 | void OJoinTableView::MouseButtonUp( const MouseEvent& rEvt ) | |||
819 | { | |||
820 | Window::MouseButtonUp(rEvt); | |||
821 | // Has a connection been selected? | |||
822 | if( m_vTableConnection.empty() ) | |||
823 | return; | |||
824 | ||||
825 | DeselectConn(GetSelectedConn()); | |||
826 | ||||
827 | for (auto & elem : m_vTableConnection) | |||
828 | { | |||
829 | if( elem->CheckHit(rEvt.GetPosPixel()) ) | |||
830 | { | |||
831 | SelectConn(elem); | |||
832 | ||||
833 | // Double-click | |||
834 | if( rEvt.GetClicks() == 2 ) | |||
835 | ConnDoubleClicked(elem); | |||
836 | ||||
837 | break; | |||
838 | } | |||
839 | } | |||
840 | } | |||
841 | ||||
842 | void OJoinTableView::KeyInput( const KeyEvent& rEvt ) | |||
843 | { | |||
844 | sal_uInt16 nCode = rEvt.GetKeyCode().GetCode(); | |||
845 | bool bShift = rEvt.GetKeyCode().IsShift(); | |||
846 | bool bCtrl = rEvt.GetKeyCode().IsMod1(); | |||
847 | ||||
848 | if( !bCtrl && !bShift && (nCode==KEY_DELETE) ) | |||
849 | { | |||
850 | if (GetSelectedConn()) | |||
851 | RemoveConnection(GetSelectedConn(), true); | |||
852 | } | |||
853 | else | |||
854 | Window::KeyInput( rEvt ); | |||
855 | } | |||
856 | ||||
857 | void OJoinTableView::DeselectConn(OTableConnection* pConn) | |||
858 | { | |||
859 | if (!pConn || !pConn->IsSelected()) | |||
860 | return; | |||
861 | ||||
862 | // deselect the corresponding entries in the ListBox of the table window | |||
863 | OTableWindow* pWin = pConn->GetSourceWin(); | |||
864 | if (pWin && pWin->GetListBox()) | |||
865 | pWin->GetListBox()->get_widget().unselect_all(); | |||
866 | ||||
867 | pWin = pConn->GetDestWin(); | |||
868 | if (pWin && pWin->GetListBox()) | |||
869 | pWin->GetListBox()->get_widget().unselect_all(); | |||
870 | ||||
871 | pConn->Deselect(); | |||
872 | m_pSelectedConn = nullptr; | |||
873 | } | |||
874 | ||||
875 | void OJoinTableView::SelectConn(OTableConnection* pConn) | |||
876 | { | |||
877 | DeselectConn(GetSelectedConn()); | |||
878 | ||||
879 | pConn->Select(); | |||
880 | m_pSelectedConn = pConn; | |||
881 | GrabFocus(); // has to be called here because a table window may still be focused | |||
882 | ||||
883 | // select the concerned entries in the windows | |||
884 | OTableWindow* pConnSource = pConn->GetSourceWin(); | |||
885 | OTableWindow* pConnDest = pConn->GetDestWin(); | |||
886 | if (!(pConnSource && pConnDest)) | |||
887 | return; | |||
888 | ||||
889 | OTableWindowListBox* pSourceBox = pConnSource->GetListBox().get(); | |||
890 | OTableWindowListBox* pDestBox = pConnDest->GetListBox().get(); | |||
891 | if (!(pSourceBox && pDestBox)) | |||
892 | return; | |||
893 | ||||
894 | pSourceBox->get_widget().unselect_all(); | |||
895 | pDestBox->get_widget().unselect_all(); | |||
896 | ||||
897 | bool bScrolled = false; | |||
898 | ||||
899 | const std::vector<std::unique_ptr<OConnectionLine>>& rLines = pConn->GetConnLineList(); | |||
900 | auto aIter = rLines.rbegin(); | |||
901 | for(;aIter != rLines.rend();++aIter) | |||
902 | { | |||
903 | if ((*aIter)->IsValid()) | |||
904 | { | |||
905 | int nSourceEntry = pSourceBox->GetEntryFromText((*aIter)->GetData()->GetSourceFieldName()); | |||
906 | if (nSourceEntry != -1) | |||
907 | { | |||
908 | pSourceBox->get_widget().select(nSourceEntry); | |||
909 | pSourceBox->get_widget().scroll_to_row(nSourceEntry); | |||
910 | bScrolled = true; | |||
911 | } | |||
912 | ||||
913 | int nDestEntry = pDestBox->GetEntryFromText((*aIter)->GetData()->GetDestFieldName()); | |||
914 | if (nDestEntry != -1) | |||
915 | { | |||
916 | pDestBox->get_widget().select(nDestEntry); | |||
917 | pDestBox->get_widget().scroll_to_row(nDestEntry); | |||
918 | bScrolled = true; | |||
919 | } | |||
920 | } | |||
921 | } | |||
922 | ||||
923 | if (bScrolled) | |||
924 | { | |||
925 | // scrolling was done -> redraw | |||
926 | Invalidate(InvalidateFlags::NoChildren); | |||
927 | } | |||
928 | } | |||
929 | ||||
930 | void OJoinTableView::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) | |||
931 | { | |||
932 | DrawConnections(rRenderContext, rRect); | |||
933 | } | |||
934 | ||||
935 | void OJoinTableView::InvalidateConnections() | |||
936 | { | |||
937 | // draw Joins | |||
938 | for (auto & conn : m_vTableConnection) | |||
939 | conn->InvalidateConnection(); | |||
940 | } | |||
941 | ||||
942 | void OJoinTableView::DrawConnections(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) | |||
943 | { | |||
944 | // draw Joins | |||
945 | for(const auto& connection : m_vTableConnection) | |||
946 | connection->Draw(rRenderContext, rRect); | |||
947 | // finally redraw the selected one above all others | |||
948 | if (GetSelectedConn()) | |||
949 | GetSelectedConn()->Draw(rRenderContext, rRect); | |||
950 | } | |||
951 | ||||
952 | std::vector<VclPtr<OTableConnection> >::const_iterator OJoinTableView::getTableConnections(const OTableWindow* _pFromWin) const | |||
953 | { | |||
954 | return std::find_if( m_vTableConnection.begin(), | |||
955 | m_vTableConnection.end(), | |||
956 | [_pFromWin](OTableConnection * p) { return p->isTableConnection(_pFromWin); }); | |||
957 | } | |||
958 | ||||
959 | sal_Int32 OJoinTableView::getConnectionCount(const OTableWindow* _pFromWin) const | |||
960 | { | |||
961 | return std::count_if( m_vTableConnection.begin(), | |||
962 | m_vTableConnection.end(), | |||
963 | [_pFromWin](OTableConnection * p) { return p->isTableConnection(_pFromWin); }); | |||
964 | } | |||
965 | ||||
966 | bool OJoinTableView::ExistsAConn(const OTableWindow* pFrom) const | |||
967 | { | |||
968 | return getTableConnections(pFrom) != m_vTableConnection.end(); | |||
969 | } | |||
970 | ||||
971 | void OJoinTableView::ClearAll() | |||
972 | { | |||
973 | SetUpdateMode(false); | |||
974 | ||||
975 | HideTabWins(); | |||
976 | ||||
977 | // and the same with the Connections | |||
978 | for (auto & elem : m_vTableConnection) | |||
979 | { | |||
980 | RemoveConnection(elem, true); | |||
981 | } | |||
982 | m_vTableConnection.clear(); | |||
983 | ||||
984 | m_pLastFocusTabWin = nullptr; | |||
985 | m_pSelectedConn = nullptr; | |||
986 | ||||
987 | // scroll to the upper left | |||
988 | ScrollPane(-GetScrollOffset().X(), true, true); | |||
989 | ScrollPane(-GetScrollOffset().Y(), false, true); | |||
990 | Invalidate(); | |||
991 | } | |||
992 | ||||
993 | void OJoinTableView::ScrollWhileDragging() | |||
994 | { | |||
995 | OSL_ENSURE(m_pDragWin != nullptr, "OJoinTableView::ScrollWhileDragging must not be called when a window is being dragged !")do { if (true && (!(m_pDragWin != nullptr))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/querydesign/JoinTableView.cxx" ":" "995" ": "), "%s", "OJoinTableView::ScrollWhileDragging must not be called when a window is being dragged !" ); } } while (false); | |||
996 | ||||
997 | // kill the timer | |||
998 | if (m_aDragScrollIdle.IsActive()) | |||
999 | m_aDragScrollIdle.Stop(); | |||
1000 | ||||
1001 | Point aDragWinPos = m_ptPrevDraggingPos - m_aDragOffset; | |||
1002 | Size aDragWinSize = m_pDragWin->GetSizePixel(); | |||
1003 | Point aLowerRight(aDragWinPos.X() + aDragWinSize.Width(), aDragWinPos.Y() + aDragWinSize.Height()); | |||
1004 | ||||
1005 | if (aDragWinPos == m_pDragWin->GetPosPixel()) | |||
1006 | return; | |||
1007 | ||||
1008 | // avoid illustration errors (when scrolling with active TrackingRect) | |||
1009 | HideTracking(); | |||
1010 | ||||
1011 | bool bScrolling = false; | |||
1012 | bool bNeedScrollTimer = false; | |||
1013 | ||||
1014 | // scroll at window borders | |||
1015 | // TODO : only catch, if window would disappear completely (don't, if there is still a pixel visible) | |||
1016 | if( aDragWinPos.X() < 5 ) | |||
1017 | { | |||
1018 | bScrolling = ScrollPane( -LINE_SIZE50, true, true ); | |||
1019 | if( !bScrolling && (aDragWinPos.X()<0) ) | |||
1020 | aDragWinPos.setX( 0 ); | |||
1021 | ||||
1022 | // do I need further (timer controlled) scrolling ? | |||
1023 | bNeedScrollTimer = bScrolling && (aDragWinPos.X() < 5); | |||
1024 | } | |||
1025 | ||||
1026 | if( aLowerRight.X() > m_aOutputSize.Width() - 5 ) | |||
1027 | { | |||
1028 | bScrolling = ScrollPane( LINE_SIZE50, true, true ) ; | |||
1029 | if( !bScrolling && ( aLowerRight.X() > m_aOutputSize.Width() ) ) | |||
1030 | aDragWinPos.setX( m_aOutputSize.Width() - aDragWinSize.Width() ); | |||
1031 | ||||
1032 | // do I need further (timer controlled) scrolling ? | |||
1033 | bNeedScrollTimer = bScrolling && (aLowerRight.X() > m_aOutputSize.Width() - 5); | |||
1034 | } | |||
1035 | ||||
1036 | if( aDragWinPos.Y() < 5 ) | |||
1037 | { | |||
1038 | bScrolling = ScrollPane( -LINE_SIZE50, false, true ); | |||
1039 | if( !bScrolling && (aDragWinPos.Y()<0) ) | |||
1040 | aDragWinPos.setY( 0 ); | |||
1041 | ||||
1042 | bNeedScrollTimer = bScrolling && (aDragWinPos.Y() < 5); | |||
1043 | } | |||
1044 | ||||
1045 | if( aLowerRight.Y() > m_aOutputSize.Height() - 5 ) | |||
1046 | { | |||
1047 | bScrolling = ScrollPane( LINE_SIZE50, false, true ); | |||
1048 | if( !bScrolling && ( (aDragWinPos.Y() + aDragWinSize.Height()) > m_aOutputSize.Height() ) ) | |||
1049 | aDragWinPos.setY( m_aOutputSize.Height() - aDragWinSize.Height() ); | |||
1050 | ||||
1051 | bNeedScrollTimer = bScrolling && (aLowerRight.Y() > m_aOutputSize.Height() - 5); | |||
1052 | } | |||
1053 | ||||
1054 | // resetting timer, if still necessary | |||
1055 | if (bNeedScrollTimer) | |||
1056 | { | |||
1057 | m_aDragScrollIdle.SetPriority( TaskPriority::HIGH_IDLE ); | |||
1058 | m_aDragScrollIdle.Start(); | |||
1059 | } | |||
1060 | ||||
1061 | // redraw DraggingRect | |||
1062 | m_aDragRect = tools::Rectangle(m_ptPrevDraggingPos - m_aDragOffset, m_pDragWin->GetSizePixel()); | |||
1063 | PaintImmediately(); | |||
1064 | ShowTracking( m_aDragRect, ShowTrackFlags::Small | ShowTrackFlags::TrackWindow ); | |||
1065 | } | |||
1066 | ||||
1067 | IMPL_LINK_NOARG(OJoinTableView, OnDragScrollTimer, Timer *, void)void OJoinTableView::LinkStubOnDragScrollTimer(void * instance , Timer * data) { return static_cast<OJoinTableView *>( instance)->OnDragScrollTimer(data); } void OJoinTableView:: OnDragScrollTimer(__attribute__ ((unused)) Timer *) | |||
1068 | { | |||
1069 | ScrollWhileDragging(); | |||
1070 | } | |||
1071 | ||||
1072 | void OJoinTableView::invalidateAndModify(std::unique_ptr<SfxUndoAction> _pAction) | |||
1073 | { | |||
1074 | Invalidate(InvalidateFlags::NoChildren); | |||
1075 | m_pView->getController().addUndoActionAndInvalidate(std::move(_pAction)); | |||
1076 | } | |||
1077 | ||||
1078 | void OJoinTableView::TabWinMoved(OTableWindow* ptWhich, const Point& ptOldPosition) | |||
1079 | { | |||
1080 | Point ptThumbPos(GetHScrollBar().GetThumbPos(), GetVScrollBar().GetThumbPos()); | |||
1081 | ptWhich->GetData()->SetPosition(ptWhich->GetPosPixel() + ptThumbPos); | |||
1082 | ||||
1083 | invalidateAndModify(std::make_unique<OJoinMoveTabWinUndoAct>(this, ptOldPosition, ptWhich)); | |||
1084 | } | |||
1085 | ||||
1086 | void OJoinTableView::TabWinSized(OTableWindow* ptWhich, const Point& ptOldPosition, const Size& szOldSize) | |||
1087 | { | |||
1088 | ptWhich->GetData()->SetSize(ptWhich->GetSizePixel()); | |||
1089 | ptWhich->GetData()->SetPosition(ptWhich->GetPosPixel()); | |||
1090 | ||||
1091 | invalidateAndModify(std::make_unique<OJoinSizeTabWinUndoAct>(this, ptOldPosition, szOldSize, ptWhich)); | |||
1092 | } | |||
1093 | ||||
1094 | bool OJoinTableView::IsAddAllowed() | |||
1095 | { | |||
1096 | ||||
1097 | // not, if Db readonly | |||
1098 | if (m_pView->getController().isReadOnly()) | |||
1099 | return false; | |||
1100 | ||||
1101 | try | |||
1102 | { | |||
1103 | Reference< XConnection> xConnection = m_pView->getController().getConnection(); | |||
1104 | if(!xConnection.is()) | |||
1105 | return false; | |||
1106 | // not, if too many tables already | |||
1107 | Reference < XDatabaseMetaData > xMetaData( xConnection->getMetaData() ); | |||
1108 | ||||
1109 | sal_Int32 nMax = xMetaData.is() ? xMetaData->getMaxTablesInSelect() : 0; | |||
1110 | if (nMax && nMax <= static_cast<sal_Int32>(m_aTableMap.size())) | |||
1111 | return false; | |||
1112 | } | |||
1113 | catch(SQLException&) | |||
1114 | { | |||
1115 | return false; | |||
1116 | } | |||
1117 | ||||
1118 | return true; | |||
1119 | } | |||
1120 | ||||
1121 | void OJoinTableView::executePopup(const Point& _aPos, VclPtr<OTableConnection>& rSelConnection) | |||
1122 | { | |||
1123 | VclBuilder aBuilder(nullptr, AllSettings::GetUIRootDir(), "dbaccess/ui/joinviewmenu.ui", ""); | |||
1124 | VclPtr<PopupMenu> aContextMenu(aBuilder.get_menu("menu")); | |||
1125 | aContextMenu->Execute(this, _aPos); | |||
1126 | OString sIdent = aContextMenu->GetCurItemIdent(); | |||
1127 | if (sIdent == "delete") | |||
1128 | RemoveConnection(rSelConnection, true); | |||
1129 | else if (sIdent == "edit") | |||
1130 | ConnDoubleClicked(rSelConnection); // is the same as double clicked | |||
1131 | } | |||
1132 | ||||
1133 | void OJoinTableView::Command(const CommandEvent& rEvt) | |||
1134 | { | |||
1135 | ||||
1136 | bool bHandled = false; | |||
1137 | ||||
1138 | switch (rEvt.GetCommand()) | |||
1139 | { | |||
1140 | case CommandEventId::ContextMenu: | |||
1141 | { | |||
1142 | if( m_vTableConnection.empty() ) | |||
1143 | return; | |||
1144 | ||||
1145 | VclPtr<OTableConnection>& rSelConnection = GetSelectedConn(); | |||
1146 | // when it wasn't a mouse event use the selected connection | |||
1147 | if (!rEvt.IsMouseEvent()) | |||
1148 | { | |||
1149 | if (rSelConnection) | |||
1150 | { | |||
1151 | const std::vector<std::unique_ptr<OConnectionLine>>& rLines = rSelConnection->GetConnLineList(); | |||
1152 | auto aIter = std::find_if(rLines.begin(), rLines.end(),std::mem_fn(&OConnectionLine::IsValid)); | |||
1153 | if( aIter != rLines.end() ) | |||
1154 | executePopup((*aIter)->getMidPoint(), rSelConnection); | |||
1155 | } | |||
1156 | } | |||
1157 | else | |||
1158 | { | |||
1159 | DeselectConn(rSelConnection); | |||
1160 | ||||
1161 | const Point& aMousePos = rEvt.GetMousePosPixel(); | |||
1162 | for (auto & elem : m_vTableConnection) | |||
1163 | { | |||
1164 | if( elem->CheckHit(aMousePos) ) | |||
1165 | { | |||
1166 | SelectConn(elem); | |||
1167 | if(!getDesignView()->getController().isReadOnly() && getDesignView()->getController().isConnected()) | |||
1168 | executePopup(rEvt.GetMousePosPixel(),elem); | |||
1169 | break; | |||
1170 | } | |||
1171 | } | |||
1172 | } | |||
1173 | bHandled = true; | |||
1174 | } | |||
1175 | break; | |||
1176 | default: break; | |||
1177 | } | |||
1178 | if (!bHandled) | |||
1179 | Window::Command(rEvt); | |||
1180 | } | |||
1181 | ||||
1182 | OTableConnection* OJoinTableView::GetTabConn(const OTableWindow* pLhs,const OTableWindow* pRhs,bool _bSupressCrossOrNaturalJoin) const | |||
1183 | { | |||
1184 | OTableConnection* pConn = nullptr; | |||
1185 | OSL_ENSURE(pRhs || pLhs, "OJoinTableView::GetTabConn : invalid args !")do { if (true && (!(pRhs || pLhs))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/querydesign/JoinTableView.cxx" ":" "1185" ": "), "%s", "OJoinTableView::GetTabConn : invalid args !" ); } } while (false); | |||
1186 | // only one NULL-arg allowed | |||
1187 | ||||
1188 | if ((!pLhs || pLhs->ExistsAConn()) && (!pRhs || pRhs->ExistsAConn())) | |||
1189 | { | |||
1190 | for(VclPtr<OTableConnection> const & pData : m_vTableConnection) | |||
1191 | { | |||
1192 | if ( ( (pData->GetSourceWin() == pLhs) | |||
1193 | && ( (pData->GetDestWin() == pRhs) | |||
1194 | || (nullptr == pRhs) | |||
1195 | ) | |||
1196 | ) | |||
1197 | || ( (pData->GetSourceWin() == pRhs) | |||
1198 | && ( (pData->GetDestWin() == pLhs) | |||
1199 | || (nullptr == pLhs) | |||
1200 | ) | |||
1201 | ) | |||
1202 | ) | |||
1203 | { | |||
1204 | if ( _bSupressCrossOrNaturalJoin ) | |||
1205 | { | |||
1206 | if ( supressCrossNaturalJoin(pData->GetData()) ) | |||
1207 | continue; | |||
1208 | } | |||
1209 | pConn = pData; | |||
1210 | break; | |||
1211 | } | |||
1212 | } | |||
1213 | } | |||
1214 | return pConn; | |||
1215 | } | |||
1216 | ||||
1217 | bool OJoinTableView::PreNotify(NotifyEvent& rNEvt) | |||
1218 | { | |||
1219 | bool bHandled = false; | |||
1220 | switch (rNEvt.GetType()) | |||
1221 | { | |||
1222 | case MouseNotifyEvent::COMMAND: | |||
1223 | { | |||
1224 | const CommandEvent* pCommand = rNEvt.GetCommandEvent(); | |||
1225 | if (pCommand->GetCommand() == CommandEventId::Wheel) | |||
1226 | { | |||
1227 | const CommandWheelData* pData = rNEvt.GetCommandEvent()->GetWheelData(); | |||
1228 | if (pData->GetMode() == CommandWheelMode::SCROLL) | |||
1229 | { | |||
1230 | if (pData->GetDelta() > 0) | |||
1231 | ScrollPane(-10 * pData->GetScrollLines(), pData->IsHorz(), true); | |||
1232 | else | |||
1233 | ScrollPane(10 * pData->GetScrollLines(), pData->IsHorz(), true); | |||
1234 | bHandled = true; | |||
1235 | } | |||
1236 | } | |||
1237 | } | |||
1238 | break; | |||
1239 | case MouseNotifyEvent::KEYINPUT: | |||
1240 | { | |||
1241 | if (m_aTableMap.empty()) | |||
1242 | // no tab wins -> no conns -> no traveling | |||
1243 | break; | |||
1244 | ||||
1245 | const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent(); | |||
1246 | if (!pKeyEvent->GetKeyCode().IsMod1()) | |||
1247 | { | |||
1248 | switch (pKeyEvent->GetKeyCode().GetCode()) | |||
1249 | { | |||
1250 | case KEY_TAB: | |||
1251 | { | |||
1252 | if (!HasChildPathFocus()) | |||
1253 | break; | |||
1254 | ||||
1255 | bool bForward = !pKeyEvent->GetKeyCode().IsShift(); | |||
1256 | // is there an active tab win ? | |||
1257 | OTableWindowMap::const_iterator aIter = std::find_if(m_aTableMap.begin(), m_aTableMap.end(), | |||
1258 | [](const OTableWindowMap::value_type& rEntry) { return rEntry.second && rEntry.second->HasChildPathFocus(); }); | |||
1259 | ||||
1260 | OTableWindow* pNextWin = nullptr; | |||
1261 | OTableConnection* pNextConn = nullptr; | |||
1262 | ||||
1263 | if (aIter != m_aTableMap.end()) | |||
1264 | { // there is a currently active tab win | |||
1265 | // check if there is an "overflow" and we should select a conn instead of a win | |||
1266 | if (!m_vTableConnection.empty()) | |||
1267 | { | |||
1268 | if ((aIter->second == m_aTableMap.rbegin()->second) && bForward) | |||
1269 | // the last win is active and we're travelling forward -> select the first conn | |||
1270 | pNextConn = m_vTableConnection.begin()->get(); | |||
1271 | if ((aIter == m_aTableMap.begin()) && !bForward) | |||
1272 | // the first win is active and we're traveling backward -> select the last conn | |||
1273 | pNextConn = m_vTableConnection.rbegin()->get(); | |||
1274 | } | |||
1275 | ||||
1276 | if (!pNextConn) | |||
1277 | { | |||
1278 | // no conn for any reason -> select the next or previous tab win | |||
1279 | if(bForward) | |||
1280 | { | |||
1281 | if ( aIter->second == m_aTableMap.rbegin()->second ) | |||
1282 | pNextWin = m_aTableMap.begin()->second; | |||
1283 | else | |||
1284 | { | |||
1285 | ++aIter; | |||
1286 | pNextWin = aIter->second; | |||
1287 | } | |||
1288 | } | |||
1289 | else | |||
1290 | { | |||
1291 | if (aIter == m_aTableMap.begin()) | |||
1292 | pNextWin = m_aTableMap.rbegin()->second; | |||
1293 | else | |||
1294 | { | |||
1295 | --aIter; | |||
1296 | pNextWin = aIter->second; | |||
1297 | } | |||
1298 | } | |||
1299 | } | |||
1300 | } | |||
1301 | else | |||
1302 | { // no active tab win -> travel the connections | |||
1303 | // find the currently selected conn within the conn list | |||
1304 | sal_Int32 i(0); | |||
1305 | for (auto const& elem : m_vTableConnection) | |||
1306 | { | |||
1307 | if ( elem.get() == GetSelectedConn() ) | |||
1308 | break; | |||
1309 | ++i; | |||
1310 | } | |||
1311 | if (i == sal_Int32(m_vTableConnection.size() - 1) && bForward) | |||
1312 | // the last conn is active and we're travelling forward -> select the first win | |||
1313 | pNextWin = m_aTableMap.begin()->second; | |||
1314 | if ((i == 0) && !bForward && !m_aTableMap.empty()) | |||
1315 | // the first conn is active and we're travelling backward -> select the last win | |||
1316 | pNextWin = m_aTableMap.rbegin()->second; | |||
1317 | ||||
1318 | if (pNextWin) | |||
1319 | DeselectConn(GetSelectedConn()); | |||
1320 | else | |||
1321 | // no win for any reason -> select the next or previous conn | |||
1322 | if (i < static_cast<sal_Int32>(m_vTableConnection.size())) | |||
1323 | // there is a currently active conn | |||
1324 | pNextConn = m_vTableConnection[(i + (bForward ? 1 : m_vTableConnection.size() - 1)) % m_vTableConnection.size()].get(); | |||
1325 | else | |||
1326 | { // no tab win selected, no conn selected | |||
1327 | if (!m_vTableConnection.empty()) | |||
1328 | pNextConn = m_vTableConnection[bForward ? 0 : m_vTableConnection.size() - 1].get(); | |||
1329 | else if (!m_aTableMap.empty()) | |||
1330 | { | |||
1331 | if(bForward) | |||
1332 | pNextWin = m_aTableMap.begin()->second; | |||
1333 | else | |||
1334 | pNextWin = m_aTableMap.rbegin()->second; | |||
1335 | } | |||
1336 | } | |||
1337 | } | |||
1338 | ||||
1339 | // now select the object | |||
1340 | if (pNextWin) | |||
1341 | { | |||
1342 | if (pNextWin->GetListBox()) | |||
1343 | pNextWin->GetListBox()->GrabFocus(); | |||
1344 | else | |||
1345 | pNextWin->GrabFocus(); | |||
1346 | EnsureVisible(pNextWin); | |||
1347 | } | |||
1348 | else if (pNextConn) | |||
1349 | { | |||
1350 | GrabFocus(); | |||
1351 | // necessary : a conn may be selected even if a tab win has the focus, in this case | |||
1352 | // the next travel would select the same conn again if we would not reset the focus ... | |||
1353 | SelectConn(pNextConn); | |||
1354 | } | |||
1355 | } | |||
1356 | break; | |||
1357 | case KEY_RETURN: | |||
1358 | { | |||
1359 | if (!pKeyEvent->GetKeyCode().IsShift() && GetSelectedConn() && HasFocus()) | |||
1360 | ConnDoubleClicked(GetSelectedConn()); | |||
1361 | break; | |||
1362 | } | |||
1363 | } | |||
1364 | } | |||
1365 | } | |||
1366 | break; | |||
1367 | case MouseNotifyEvent::GETFOCUS: | |||
1368 | { | |||
1369 | if (m_aTableMap.empty()) | |||
1370 | // no tab wins -> no conns -> no focus change | |||
1371 | break; | |||
1372 | vcl::Window* pSource = rNEvt.GetWindow(); | |||
1373 | if (pSource) | |||
1374 | { | |||
1375 | vcl::Window* pSearchFor = nullptr; | |||
1376 | if (pSource->GetParent() == this) | |||
1377 | // it may be one of the tab wins | |||
1378 | pSearchFor = pSource; | |||
1379 | else if (pSource->GetParent() && (pSource->GetParent()->GetParent() == this)) | |||
1380 | // it may be one of th list boxes of one of the tab wins | |||
1381 | pSearchFor = pSource->GetParent(); | |||
1382 | ||||
1383 | if (pSearchFor) | |||
1384 | { | |||
1385 | for (auto const& elem : m_aTableMap) | |||
1386 | { | |||
1387 | if (elem.second == pSearchFor) | |||
1388 | { | |||
1389 | m_pLastFocusTabWin = elem.second; | |||
1390 | break; | |||
1391 | } | |||
1392 | } | |||
1393 | } | |||
1394 | } | |||
1395 | } | |||
1396 | break; | |||
1397 | default: | |||
1398 | break; | |||
1399 | } | |||
1400 | ||||
1401 | if (!bHandled) | |||
1402 | return Window::PreNotify(rNEvt); | |||
1403 | return true; | |||
1404 | } | |||
1405 | ||||
1406 | void OJoinTableView::GrabTabWinFocus() | |||
1407 | { | |||
1408 | if (m_pLastFocusTabWin && m_pLastFocusTabWin->IsVisible()) | |||
1409 | { | |||
1410 | if (m_pLastFocusTabWin->GetListBox()) | |||
1411 | m_pLastFocusTabWin->GetListBox()->GrabFocus(); | |||
1412 | else | |||
1413 | m_pLastFocusTabWin->GrabFocus(); | |||
1414 | } | |||
1415 | else if (!m_aTableMap.empty() && m_aTableMap.begin()->second && m_aTableMap.begin()->second->IsVisible()) | |||
1416 | { | |||
1417 | VclPtr<OTableWindow> pFirstWin = m_aTableMap.begin()->second; | |||
1418 | if (pFirstWin->GetListBox()) | |||
1419 | pFirstWin->GetListBox()->GrabFocus(); | |||
1420 | else | |||
1421 | pFirstWin->GrabFocus(); | |||
1422 | } | |||
1423 | } | |||
1424 | ||||
1425 | void OJoinTableView::StateChanged( StateChangedType nType ) | |||
1426 | { | |||
1427 | Window::StateChanged( nType ); | |||
1428 | ||||
1429 | // FIXME RenderContext | |||
1430 | if ( nType != StateChangedType::Zoom ) | |||
1431 | return; | |||
1432 | ||||
1433 | const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); | |||
1434 | ||||
1435 | vcl::Font aFont = rStyleSettings.GetGroupFont(); | |||
1436 | if ( IsControlFont() ) | |||
1437 | aFont.Merge( GetControlFont() ); | |||
1438 | SetZoomedPointFont(*this, aFont); | |||
1439 | ||||
1440 | for (auto const& elem : m_aTableMap) | |||
1441 | { | |||
1442 | elem.second->SetZoom(GetZoom()); | |||
1443 | Size aSize(CalcZoom(elem.second->GetSizePixel().Width()),CalcZoom(elem.second->GetSizePixel().Height())); | |||
1444 | elem.second->SetSizePixel(aSize); | |||
1445 | } | |||
1446 | Resize(); | |||
1447 | } | |||
1448 | ||||
1449 | void OJoinTableView::HideTabWins() | |||
1450 | { | |||
1451 | SetUpdateMode(false); | |||
1452 | ||||
1453 | OTableWindowMap& rTabWins = GetTabWinMap(); | |||
1454 | ||||
1455 | // working on a copy because the real list will be cleared in inner calls | |||
1456 | OTableWindowMap aCopy(rTabWins); | |||
1457 | for (auto const& elem : aCopy) | |||
1458 | RemoveTabWin(elem.second); | |||
1459 | ||||
1460 | m_pView->getController().setModified(true); | |||
1461 | ||||
1462 | SetUpdateMode(true); | |||
1463 | ||||
1464 | } | |||
1465 | ||||
1466 | sal_Int8 OJoinTableView::AcceptDrop( const AcceptDropEvent& /*_rEvt*/ ) | |||
1467 | { | |||
1468 | return DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::ACTION_NONE; | |||
1469 | } | |||
1470 | ||||
1471 | sal_Int8 OJoinTableView::ExecuteDrop( const ExecuteDropEvent& /*_rEvt*/ ) | |||
1472 | { | |||
1473 | return DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::ACTION_NONE; | |||
1474 | } | |||
1475 | ||||
1476 | void OJoinTableView::dragFinished( ) | |||
1477 | { | |||
1478 | } | |||
1479 | ||||
1480 | void OJoinTableView::clearLayoutInformation() | |||
1481 | { | |||
1482 | m_pLastFocusTabWin = nullptr; | |||
1483 | m_pSelectedConn = nullptr; | |||
1484 | // delete lists | |||
1485 | for (auto & elem : m_aTableMap) | |||
1486 | { | |||
1487 | if ( elem.second ) | |||
1488 | elem.second->clearListBox(); | |||
1489 | elem.second.disposeAndClear(); | |||
1490 | } | |||
1491 | ||||
1492 | m_aTableMap.clear(); | |||
1493 | ||||
1494 | for (auto & elem : m_vTableConnection) | |||
1495 | elem.disposeAndClear(); | |||
1496 | ||||
1497 | m_vTableConnection.clear(); | |||
1498 | } | |||
1499 | ||||
1500 | void OJoinTableView::lookForUiActivities() | |||
1501 | { | |||
1502 | } | |||
1503 | ||||
1504 | void OJoinTableView::LoseFocus() | |||
1505 | { | |||
1506 | DeselectConn(GetSelectedConn()); | |||
1507 | Window::LoseFocus(); | |||
1508 | } | |||
1509 | ||||
1510 | void OJoinTableView::GetFocus() | |||
1511 | { | |||
1512 | Window::GetFocus(); | |||
1513 | if ( !m_aTableMap.empty() && !GetSelectedConn() ) | |||
1514 | GrabTabWinFocus(); | |||
1515 | } | |||
1516 | ||||
1517 | Reference< XAccessible > OJoinTableView::CreateAccessible() | |||
1518 | { | |||
1519 | m_pAccessible = new OJoinDesignViewAccess(this); | |||
1520 | return m_pAccessible; | |||
1521 | } | |||
1522 | ||||
1523 | void OJoinTableView::modified() | |||
1524 | { | |||
1525 | OJoinController& rController = m_pView->getController(); | |||
1526 | rController.setModified( true ); | |||
1527 | rController.InvalidateFeature(ID_BROWSER_ADDTABLE( 10000 + 722 )); | |||
1528 | rController.InvalidateFeature(SID_RELATION_ADD_RELATION( ((((((((10000 + 1499) + 1) + 499) + 1) + 100) + 1) + 149) + 1) + 45 )); | |||
1529 | } | |||
1530 | ||||
1531 | void OJoinTableView::addConnection(OTableConnection* _pConnection,bool _bAddData) | |||
1532 | { | |||
1533 | if ( _bAddData ) | |||
1534 | { | |||
1535 | #if OSL_DEBUG_LEVEL1 > 0 | |||
1536 | TTableConnectionData& rTabConnDataList = m_pView->getController().getTableConnectionData(); | |||
1537 | OSL_ENSURE( std::find(rTabConnDataList.begin(), rTabConnDataList.end(),_pConnection->GetData()) == rTabConnDataList.end(),"Data already in vector!")do { if (true && (!(std::find(rTabConnDataList.begin( ), rTabConnDataList.end(),_pConnection->GetData()) == rTabConnDataList .end()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/querydesign/JoinTableView.cxx" ":" "1537" ": "), "%s", "Data already in vector!"); } } while (false); | |||
1538 | #endif | |||
1539 | m_pView->getController().getTableConnectionData().push_back(_pConnection->GetData()); | |||
1540 | } | |||
1541 | m_vTableConnection.emplace_back(_pConnection); | |||
1542 | _pConnection->RecalcLines(); | |||
1543 | _pConnection->InvalidateConnection(); | |||
1544 | ||||
1545 | modified(); | |||
1546 | if ( m_pAccessible ) | |||
1547 | m_pAccessible->notifyAccessibleEvent( AccessibleEventId::CHILD, | |||
1548 | Any(), | |||
1549 | makeAny(_pConnection->GetAccessible())); | |||
1550 | } | |||
1551 | ||||
1552 | bool OJoinTableView::allowQueries() const | |||
1553 | { | |||
1554 | return true; | |||
1555 | } | |||
1556 | ||||
1557 | void OJoinTableView::onNoColumns_throw() | |||
1558 | { | |||
1559 | OSL_FAIL( "OTableWindow::onNoColumns_throw: cannot really handle this!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/dbaccess/source/ui/querydesign/JoinTableView.cxx" ":" "1559" ": "), "%s", "OTableWindow::onNoColumns_throw: cannot really handle this!" ); } } while (false); | |||
1560 | throw SQLException(); | |||
1561 | } | |||
1562 | ||||
1563 | bool OJoinTableView::supressCrossNaturalJoin(const TTableConnectionData::value_type& ) const | |||
1564 | { | |||
1565 | return false; | |||
1566 | } | |||
1567 | ||||
1568 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_RTL_REF_HXX | ||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||
22 | |||||||
23 | #include "sal/config.h" | ||||||
24 | |||||||
25 | #include <cassert> | ||||||
26 | #include <cstddef> | ||||||
27 | #include <functional> | ||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||
29 | #include <type_traits> | ||||||
30 | #endif | ||||||
31 | |||||||
32 | #include "sal/types.h" | ||||||
33 | |||||||
34 | namespace rtl | ||||||
35 | { | ||||||
36 | |||||||
37 | /** Template reference class for reference type. | ||||||
38 | */ | ||||||
39 | template <class reference_type> | ||||||
40 | class Reference | ||||||
41 | { | ||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||
43 | */ | ||||||
44 | reference_type * m_pBody; | ||||||
45 | |||||||
46 | |||||||
47 | public: | ||||||
48 | /** Constructor... | ||||||
49 | */ | ||||||
50 | Reference() | ||||||
51 | : m_pBody (NULL__null) | ||||||
52 | {} | ||||||
53 | |||||||
54 | |||||||
55 | /** Constructor... | ||||||
56 | */ | ||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||
58 | : m_pBody (pBody) | ||||||
59 | { | ||||||
60 | } | ||||||
61 | |||||||
62 | /** Constructor... | ||||||
63 | */ | ||||||
64 | Reference (reference_type * pBody) | ||||||
65 | : m_pBody (pBody) | ||||||
66 | { | ||||||
67 | if (m_pBody) | ||||||
68 | m_pBody->acquire(); | ||||||
69 | } | ||||||
70 | |||||||
71 | /** Copy constructor... | ||||||
72 | */ | ||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||
74 | : m_pBody (handle.m_pBody) | ||||||
75 | { | ||||||
76 | if (m_pBody) | ||||||
77 | m_pBody->acquire(); | ||||||
78 | } | ||||||
79 | |||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||
81 | /** Move constructor... | ||||||
82 | */ | ||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||
84 | : m_pBody (handle.m_pBody) | ||||||
85 | { | ||||||
86 | handle.m_pBody = nullptr; | ||||||
87 | } | ||||||
88 | #endif | ||||||
89 | |||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||
92 | |||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||
94 | |||||||
95 | @param rRef another reference | ||||||
96 | */ | ||||||
97 | template< class derived_type > | ||||||
98 | inline Reference( | ||||||
99 | const Reference< derived_type > & rRef, | ||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||
101 | : m_pBody (rRef.get()) | ||||||
102 | { | ||||||
103 | if (m_pBody) | ||||||
104 | m_pBody->acquire(); | ||||||
105 | } | ||||||
106 | #endif | ||||||
107 | |||||||
108 | /** Destructor... | ||||||
109 | */ | ||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||
111 | { | ||||||
112 | if (m_pBody
| ||||||
113 | m_pBody->release(); | ||||||
114 | } | ||||||
115 | |||||||
116 | /** Set... | ||||||
117 | Similar to assignment. | ||||||
118 | */ | ||||||
119 | Reference<reference_type> & | ||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||
121 | { | ||||||
122 | if (pBody) | ||||||
123 | pBody->acquire(); | ||||||
124 | reference_type * const pOld = m_pBody; | ||||||
125 | m_pBody = pBody; | ||||||
126 | if (pOld) | ||||||
127 | pOld->release(); | ||||||
128 | return *this; | ||||||
129 | } | ||||||
130 | |||||||
131 | /** Assignment. | ||||||
132 | Unbinds this instance from its body (if bound) and | ||||||
133 | bind it to the body represented by the handle. | ||||||
134 | */ | ||||||
135 | Reference<reference_type> & | ||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||
137 | { | ||||||
138 | return set( handle.m_pBody ); | ||||||
139 | } | ||||||
140 | |||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||
142 | /** Assignment. | ||||||
143 | * Unbinds this instance from its body (if bound), | ||||||
144 | * bind it to the body represented by the handle, and | ||||||
145 | * set the body represented by the handle to nullptr. | ||||||
146 | */ | ||||||
147 | Reference<reference_type> & | ||||||
148 | operator= (Reference<reference_type> && handle) | ||||||
149 | { | ||||||
150 | // self-movement guts ourself | ||||||
151 | if (m_pBody) | ||||||
152 | m_pBody->release(); | ||||||
153 | m_pBody = handle.m_pBody; | ||||||
154 | handle.m_pBody = nullptr; | ||||||
155 | return *this; | ||||||
156 | } | ||||||
157 | #endif | ||||||
158 | |||||||
159 | /** Assignment... | ||||||
160 | */ | ||||||
161 | Reference<reference_type> & | ||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||
163 | { | ||||||
164 | return set( pBody ); | ||||||
165 | } | ||||||
166 | |||||||
167 | /** Unbind the body from this handle. | ||||||
168 | Note that for a handle representing a large body, | ||||||
169 | "handle.clear().set(new body());" _might_ | ||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||
171 | since in the second case two large objects exist in memory | ||||||
172 | (the old body and the new body). | ||||||
173 | */ | ||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||
175 | { | ||||||
176 | if (m_pBody) | ||||||
177 | { | ||||||
178 | reference_type * const pOld = m_pBody; | ||||||
179 | m_pBody = NULL__null; | ||||||
180 | pOld->release(); | ||||||
181 | } | ||||||
182 | return *this; | ||||||
183 | } | ||||||
184 | |||||||
185 | |||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||
188 | are the same. | ||||||
189 | */ | ||||||
190 | reference_type * SAL_CALL get() const | ||||||
191 | { | ||||||
192 | return m_pBody; | ||||||
193 | } | ||||||
194 | |||||||
195 | |||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||
197 | */ | ||||||
198 | reference_type * SAL_CALL operator->() const | ||||||
199 | { | ||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||
201 | return m_pBody; | ||||||
202 | } | ||||||
203 | |||||||
204 | |||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||
206 | */ | ||||||
207 | reference_type & SAL_CALL operator*() const | ||||||
208 | { | ||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||
210 | return *m_pBody; | ||||||
211 | } | ||||||
212 | |||||||
213 | |||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||
215 | */ | ||||||
216 | bool SAL_CALL is() const | ||||||
217 | { | ||||||
218 | return (m_pBody != NULL__null); | ||||||
219 | } | ||||||
220 | |||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||
223 | */ | ||||||
224 | explicit operator bool() const | ||||||
225 | { | ||||||
226 | return is(); | ||||||
227 | } | ||||||
228 | #endif | ||||||
229 | |||||||
230 | /** Returns True if this points to pBody. | ||||||
231 | */ | ||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||
233 | { | ||||||
234 | return (m_pBody == pBody); | ||||||
235 | } | ||||||
236 | |||||||
237 | |||||||
238 | /** Returns True if handle points to the same body. | ||||||
239 | */ | ||||||
240 | bool | ||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||
242 | { | ||||||
243 | return (m_pBody == handle.m_pBody); | ||||||
244 | } | ||||||
245 | |||||||
246 | |||||||
247 | /** Needed to place References into STL collection. | ||||||
248 | */ | ||||||
249 | bool | ||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||
251 | { | ||||||
252 | return (m_pBody != handle.m_pBody); | ||||||
253 | } | ||||||
254 | |||||||
255 | |||||||
256 | /** Needed to place References into STL collection. | ||||||
257 | */ | ||||||
258 | bool | ||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||
260 | { | ||||||
261 | return (m_pBody < handle.m_pBody); | ||||||
262 | } | ||||||
263 | |||||||
264 | |||||||
265 | /** Needed to place References into STL collection. | ||||||
266 | */ | ||||||
267 | bool | ||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||
269 | { | ||||||
270 | return (m_pBody > handle.m_pBody); | ||||||
271 | } | ||||||
272 | }; | ||||||
273 | |||||||
274 | } // namespace rtl | ||||||
275 | |||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||
277 | namespace std | ||||||
278 | { | ||||||
279 | |||||||
280 | /// @cond INTERNAL | ||||||
281 | /** | ||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||
283 | |||||||
284 | @since LibreOffice 6.3 | ||||||
285 | */ | ||||||
286 | template<typename T> | ||||||
287 | struct hash<::rtl::Reference<T>> | ||||||
288 | { | ||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||
290 | { return std::size_t(s.get()); } | ||||||
291 | }; | ||||||
292 | /// @endcond | ||||||
293 | |||||||
294 | } | ||||||
295 | |||||||
296 | #endif | ||||||
297 | |||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||
299 | |||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |