calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / dbaccess / source / ui / querydesign / JoinTableView.cxx
blobe816dfa9e585d4debb2b42f2d501223187db2736
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <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/svapp.hxx>
37 #include <vcl/settings.hxx>
38 #include <vcl/commandevent.hxx>
39 #include <vcl/event.hxx>
40 #include <vcl/ptrstyle.hxx>
41 #include <vcl/weldutils.hxx>
42 #include <TableWindowData.hxx>
43 #include <JAccess.hxx>
44 #include <com/sun/star/accessibility/XAccessible.hpp>
45 #include <com/sun/star/accessibility/AccessibleRole.hpp>
46 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
47 #include <cppuhelper/exc_hlp.hxx>
48 #include <connectivity/dbtools.hxx>
49 #include <comphelper/diagnose_ex.hxx>
50 #include <algorithm>
51 #include <functional>
53 using namespace dbaui;
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::sdbc;
56 using namespace ::com::sun::star::accessibility;
57 using namespace ::com::sun::star::container;
58 using namespace ::com::sun::star::lang;
60 #define LINE_SIZE 50
61 // Constants for the window layout
62 #define TABWIN_SPACING_X 17
63 #define TABWIN_SPACING_Y 17
65 #define TABWIN_WIDTH_STD 120
66 #define TABWIN_HEIGHT_STD 120
68 OScrollWindowHelper::OScrollWindowHelper( vcl::Window* pParent) : Window( pParent)
69 ,m_aHScrollBar( VclPtr<ScrollAdaptor>::Create(this, true) )
70 ,m_aVScrollBar( VclPtr<ScrollAdaptor>::Create(this, false) )
71 ,m_pTableView(nullptr)
73 StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
74 SetBackground(aSystemStyle.GetFaceColor());
76 // ScrollBars
77 GetHScrollBar().SetRange( Range(0, 1000) );
78 GetVScrollBar().SetRange( Range(0, 1000) );
80 GetHScrollBar().SetLineSize( LINE_SIZE );
81 GetVScrollBar().SetLineSize( LINE_SIZE );
83 GetHScrollBar().Show();
84 GetVScrollBar().Show();
86 // normally we should be SCROLL_PANE
87 SetAccessibleRole(AccessibleRole::SCROLL_PANE);
90 OScrollWindowHelper::~OScrollWindowHelper()
92 disposeOnce();
95 void OScrollWindowHelper::dispose()
97 m_aHScrollBar.disposeAndClear();
98 m_aVScrollBar.disposeAndClear();
99 m_pTableView.clear();
100 vcl::Window::dispose();
103 void OScrollWindowHelper::setTableView(OJoinTableView* _pTableView)
105 m_pTableView = _pTableView;
106 // ScrollBars
107 GetHScrollBar().SetScrollHdl( LINK(m_pTableView, OJoinTableView, HorzScrollHdl) );
108 GetVScrollBar().SetScrollHdl( LINK(m_pTableView, OJoinTableView, VertScrollHdl) );
111 void OScrollWindowHelper::resetRange(const Point& _aSize)
113 Point aPos = PixelToLogic(_aSize);
114 GetHScrollBar().SetRange( Range(0, aPos.X() + TABWIN_SPACING_X) );
115 GetVScrollBar().SetRange( Range(0, aPos.Y() + TABWIN_SPACING_Y) );
118 void OScrollWindowHelper::Resize()
120 Window::Resize();
122 Size aTotalOutputSize = GetOutputSizePixel();
123 tools::Long nHScrollHeight = GetHScrollBar().GetSizePixel().Height();
124 tools::Long nVScrollWidth = GetVScrollBar().GetSizePixel().Width();
126 GetHScrollBar().SetPosSizePixel(
127 Point( 0, aTotalOutputSize.Height()-nHScrollHeight ),
128 Size( aTotalOutputSize.Width()-nVScrollWidth, nHScrollHeight )
131 GetVScrollBar().SetPosSizePixel(
132 Point( aTotalOutputSize.Width()-nVScrollWidth, 0 ),
133 Size( nVScrollWidth, aTotalOutputSize.Height()-nHScrollHeight )
136 GetHScrollBar().SetPageSize( aTotalOutputSize.Width() );
137 GetHScrollBar().SetVisibleSize( aTotalOutputSize.Width() );
139 GetVScrollBar().SetPageSize( aTotalOutputSize.Height() );
140 GetVScrollBar().SetVisibleSize( aTotalOutputSize.Height() );
142 // adjust the ranges of the scrollbars if necessary
143 tools::Long lRange = GetHScrollBar().GetRange().Max() - GetHScrollBar().GetRange().Min();
144 if (m_pTableView->GetScrollOffset().X() + aTotalOutputSize.Width() > lRange)
145 GetHScrollBar().SetRangeMax(m_pTableView->GetScrollOffset().X() + aTotalOutputSize.Width() + GetHScrollBar().GetRange().Min());
147 lRange = GetVScrollBar().GetRange().Max() - GetVScrollBar().GetRange().Min();
148 if (m_pTableView->GetScrollOffset().Y() + aTotalOutputSize.Height() > lRange)
149 GetVScrollBar().SetRangeMax(m_pTableView->GetScrollOffset().Y() + aTotalOutputSize.Height() + GetVScrollBar().GetRange().Min());
151 m_pTableView->SetPosSizePixel(Point( 0, 0 ),Size( aTotalOutputSize.Width()-nVScrollWidth, aTotalOutputSize.Height()-nHScrollHeight ));
155 OJoinTableView::OJoinTableView( vcl::Window* pParent, OJoinDesignView* pView )
156 :Window( pParent,WB_BORDER )
157 ,DropTargetHelper(this)
158 ,m_aDragScrollIdle("dbaccess OJoinTableView m_aDragScrollIdle")
159 ,m_aDragOffset( Point(0,0) )
160 ,m_aScrollOffset( Point(0,0) )
161 ,m_pDragWin( nullptr )
162 ,m_pSizingWin( nullptr )
163 ,m_pSelectedConn( nullptr )
164 ,m_pLastFocusTabWin(nullptr)
165 ,m_pView( pView )
167 SetSizePixel( Size(1000, 1000) );
169 InitColors();
171 m_aDragScrollIdle.SetInvokeHandler(LINK(this, OJoinTableView, OnDragScrollTimer));
174 OJoinTableView::~OJoinTableView()
176 disposeOnce();
179 void OJoinTableView::dispose()
181 if( m_pAccessible )
183 m_pAccessible->clearTableView();
184 m_pAccessible = nullptr;
186 // delete lists
187 clearLayoutInformation();
188 m_pDragWin.clear();
189 m_pSizingWin.clear();
190 m_pSelectedConn.clear();
191 m_pLastFocusTabWin.clear();
192 m_pView.clear();
193 m_vTableConnection.clear();
194 vcl::Window::dispose();
197 IMPL_LINK(OJoinTableView, HorzScrollHdl, weld::Scrollbar&, rScrollbar, void)
199 // move all windows
200 ScrollPane(rScrollbar.adjustment_get_value() - m_aScrollOffset.X(), true, false);
203 IMPL_LINK(OJoinTableView, VertScrollHdl, weld::Scrollbar&, rScrollbar, void)
205 // move all windows
206 ScrollPane(rScrollbar.adjustment_get_value() - m_aScrollOffset.Y(), false, false);
209 void OJoinTableView::Resize()
211 Window::Resize();
212 m_aOutputSize = GetSizePixel();
214 // tab win positions may not be up-to-date
215 if (m_aTableMap.empty())
216 // no tab wins ...
217 return;
219 // we have at least one table so resize it
220 m_aScrollOffset.setX( GetHScrollBar().GetThumbPos() );
221 m_aScrollOffset.setY( GetVScrollBar().GetThumbPos() );
223 VclPtr<OTableWindow> pCheck = m_aTableMap.begin()->second;
224 Point aRealPos = pCheck->GetPosPixel();
225 Point aAssumedPos = pCheck->GetData()->GetPosition() - GetScrollOffset();
227 if (aRealPos == aAssumedPos)
228 // all ok
229 return;
231 for (auto const& elem : m_aTableMap)
233 OTableWindow* pCurrent = elem.second;
234 Point aPos(pCurrent->GetData()->GetPosition() - GetScrollOffset());
235 pCurrent->SetPosPixel(aPos);
239 sal_Int64 OJoinTableView::GetTabWinCount() const
241 return m_aTableMap.size();
244 bool OJoinTableView::RemoveConnection(VclPtr<OTableConnection>& rConn, bool _bDelete)
246 VclPtr<OTableConnection> xConn(rConn);
248 DeselectConn(xConn);
250 // to force a redraw
251 xConn->InvalidateConnection();
253 m_pView->getController().removeConnectionData(xConn->GetData());
255 m_vTableConnection.erase(std::find(m_vTableConnection.begin(), m_vTableConnection.end(), xConn));
257 modified();
258 if ( m_pAccessible )
259 m_pAccessible->notifyAccessibleEvent( AccessibleEventId::CHILD,
260 Any(xConn->GetAccessible()),
261 Any());
262 if (_bDelete)
263 xConn->disposeOnce();
265 return true;
268 OTableWindow* OJoinTableView::GetTabWindow( const OUString& rName )
270 OTableWindowMap::const_iterator aIter = m_aTableMap.find(rName);
272 return aIter == m_aTableMap.end() ? nullptr : aIter->second;
275 TTableWindowData::value_type OJoinTableView::createTableWindowData(const OUString& _rComposedName
276 ,const OUString& _sTableName
277 ,const OUString& _rWinName)
279 TTableWindowData::value_type pData( CreateImpl(_rComposedName, _sTableName,_rWinName) );
280 OJoinDesignView* pParent = getDesignView();
283 if ( !pData->init(pParent->getController().getConnection(),allowQueries()) )
285 if ( pData->isValid() )
286 onNoColumns_throw();
287 else
288 pData.reset();
291 catch ( const SQLException& )
293 ::dbtools::showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ),
294 VCLUnoHelper::GetInterface(pParent), pParent->getController().getORB() );
296 catch( const WrappedTargetException& e )
298 SQLException aSql;
299 if ( e.TargetException >>= aSql )
300 ::dbtools::showError( ::dbtools::SQLExceptionInfo( aSql ), VCLUnoHelper::GetInterface(pParent), pParent->getController().getORB() );
302 catch( const Exception& )
304 DBG_UNHANDLED_EXCEPTION("dbaccess");
306 return pData;
309 std::shared_ptr<OTableWindowData> OJoinTableView::CreateImpl(const OUString& _rComposedName
310 ,const OUString& _sTableName
311 ,const OUString& _rWinName)
313 return std::make_shared<OTableWindowData>( nullptr,_rComposedName,_sTableName, _rWinName );
316 void OJoinTableView::AddTabWin(const OUString& _rComposedName, const OUString& rWinName, bool /*bNewTable*/)
318 OSL_ENSURE(!_rComposedName.isEmpty(),"There must be a table name supplied!");
320 TTableWindowData::value_type pNewTabWinData(createTableWindowData( _rComposedName, rWinName,rWinName ));
322 // insert new window in window list
323 VclPtr<OTableWindow> pNewTabWin = createWindow( pNewTabWinData );
324 if ( pNewTabWin->Init() )
326 m_pView->getController().getTableWindowData().push_back( pNewTabWinData);
327 // when we already have a table with this name insert the full qualified one instead
328 if(m_aTableMap.find(rWinName) != m_aTableMap.end())
329 m_aTableMap[_rComposedName] = pNewTabWin;
330 else
331 m_aTableMap[rWinName] = pNewTabWin;
333 SetDefaultTabWinPosSize( pNewTabWin );
334 pNewTabWin->Show();
336 modified();
337 if ( m_pAccessible )
338 m_pAccessible->notifyAccessibleEvent( AccessibleEventId::CHILD,
339 Any(),
340 Any(pNewTabWin->GetAccessible()));
342 else
344 pNewTabWin->clearListBox();
345 pNewTabWin.disposeAndClear();
349 void OJoinTableView::RemoveTabWin( OTableWindow* pTabWin )
351 // first delete all connections of this window to others
352 bool bRemove = true;
353 TTableWindowData::value_type pData = pTabWin->GetData();
354 sal_Int32 nCount = m_vTableConnection.size();
355 auto aIter = m_vTableConnection.rbegin();
356 while(aIter != m_vTableConnection.rend() && bRemove)
358 VclPtr<OTableConnection>& rTabConn = *aIter;
359 if (
360 (pData == rTabConn->GetData()->getReferencingTable()) ||
361 (pData == rTabConn->GetData()->getReferencedTable())
364 bRemove = RemoveConnection(rTabConn, true);
365 aIter = m_vTableConnection.rbegin();
367 else
368 ++aIter;
371 // then delete the window itself
372 if ( bRemove )
374 if ( m_pAccessible )
375 m_pAccessible->notifyAccessibleEvent( AccessibleEventId::CHILD,
376 Any(pTabWin->GetAccessible()),Any()
379 pTabWin->Hide();
380 OJoinController& rController = m_pView->getController();
381 TTableWindowData::iterator aFind = std::find(rController.getTableWindowData().begin(), rController.getTableWindowData().end(), pData);
382 if(aFind != rController.getTableWindowData().end())
384 rController.getTableWindowData().erase(aFind);
385 rController.setModified(true);
388 if ( !m_aTableMap.erase( pTabWin->GetWinName() ) )
389 m_aTableMap.erase( pTabWin->GetComposedName() );
391 if (pTabWin == m_pLastFocusTabWin)
392 m_pLastFocusTabWin = nullptr;
394 pTabWin->clearListBox();
395 pTabWin->disposeOnce();
398 if ( static_cast<sal_Int32>(m_vTableConnection.size()) < (nCount-1) ) // if some connections could be removed
399 modified();
402 namespace
404 bool isScrollAllowed( OJoinTableView* _pView,tools::Long nDelta, bool bHoriz)
406 // adjust ScrollBar-Positions
407 ScrollAdaptor& rBar = bHoriz ? _pView->GetHScrollBar() : _pView->GetVScrollBar();
409 tools::Long nOldThumbPos = rBar.GetThumbPos();
410 tools::Long nNewThumbPos = nOldThumbPos + nDelta;
411 if( nNewThumbPos < 0 )
412 nNewThumbPos = 0;
413 else if( nNewThumbPos > rBar.GetRangeMax() )
414 nNewThumbPos = rBar.GetRangeMax();
416 if ( bHoriz )
418 if( nNewThumbPos == _pView->GetScrollOffset().X() )
419 return false;
421 else if ( nNewThumbPos == _pView->GetScrollOffset().Y() )
422 return false;
424 return true;
426 bool getMovementImpl(OJoinTableView* _pView,const Point& _rPoint,const Size& _rSize,tools::Long& _nScrollX,tools::Long& _nScrollY)
428 _nScrollY = _nScrollX = 0;
429 // data about the tab win
430 Point aUpperLeft = _rPoint;
431 // normalize with respect to visibility
432 aUpperLeft -= _pView->GetScrollOffset();
433 Point aLowerRight(aUpperLeft.X() + _rSize.Width(), aUpperLeft.Y() + _rSize.Height());
435 // data about ourself
436 Size aSize = _pView->getRealOutputSize(); //GetOutputSizePixel();
438 bool bVisible = true;
439 bool bFitsHor = (aUpperLeft.X() >= 0) && (aLowerRight.X() <= aSize.Width());
440 bool bFitsVert= (aUpperLeft.Y() >= 0) && (aLowerRight.Y() <= aSize.Height());
441 if (!bFitsHor || !bFitsVert)
443 if (!bFitsHor)
445 // ensure the visibility of the right border
446 if ( aLowerRight.X() > aSize.Width() )
447 _nScrollX = aLowerRight.X() - aSize.Width() + TABWIN_SPACING_X;
449 // ensure the visibility of the left border (higher priority)
450 if ( aUpperLeft.X() < 0 )
451 _nScrollX = aUpperLeft.X() - TABWIN_SPACING_X;
454 if (!bFitsVert)
456 // lower border
457 if ( aLowerRight.Y() > aSize.Height() )
458 _nScrollY = aLowerRight.Y() - aSize.Height() + TABWIN_SPACING_Y;
459 // upper border
460 if ( aUpperLeft.Y() < 0 )
461 _nScrollY = aUpperLeft.Y() - TABWIN_SPACING_Y;
464 if ( _nScrollX ) // aSize.Width() > _rSize.Width() &&
465 bVisible = isScrollAllowed(_pView,_nScrollX, true);
467 if ( _nScrollY ) // aSize.Height() > _rSize.Height() &&
468 bVisible = bVisible && isScrollAllowed(_pView,_nScrollY, false);
470 if ( bVisible )
472 sal_Int32 nHRangeMax = _pView->GetHScrollBar().GetRangeMax();
473 sal_Int32 nVRangeMax = _pView->GetVScrollBar().GetRangeMax();
475 if ( aSize.Width() + _pView->GetHScrollBar().GetThumbPos() + _nScrollX > nHRangeMax )
476 bVisible = false;
477 if ( bVisible && aSize.Height() + _pView->GetVScrollBar().GetThumbPos() + _nScrollY > nVRangeMax )
478 bVisible = false;
482 return bVisible;
484 } // end of ano namespace
486 bool OJoinTableView::isMovementAllowed(const Point& _rPoint,const Size& _rSize)
488 tools::Long nX,nY;
489 return getMovementImpl(this,_rPoint,_rSize,nX,nY);
492 void OJoinTableView::EnsureVisible(const OTableWindow* _pWin)
494 // data about the tab win
495 TTableWindowData::value_type pData = _pWin->GetData();
496 EnsureVisible( pData->GetPosition() , pData->GetSize());
497 Invalidate(InvalidateFlags::NoChildren);
500 void OJoinTableView::EnsureVisible(const Point& _rPoint,const Size& _rSize)
502 tools::Long nScrollX,nScrollY;
504 if ( getMovementImpl(this,_rPoint,_rSize,nScrollX,nScrollY) )
506 bool bVisible = true;
507 if (nScrollX)
508 bVisible = ScrollPane(nScrollX, true, true);
510 if (nScrollY && bVisible)
511 ScrollPane(nScrollY, false, true);
515 void OJoinTableView::SetDefaultTabWinPosSize( OTableWindow* pTabWin )
517 // determine position:
518 // the window is divided into lines with height TABWIN_SPACING_Y+TABWIN_HEIGHT_STD.
519 // Then for each line is checked, if there is space for another window.
520 // If there is no space, the next line is checked.
521 Size aOutSize = GetSizePixel();
522 Point aNewPos( 0,0 );
523 sal_uInt16 nRow = 0;
524 bool bEnd = false;
525 while( !bEnd )
527 // Set new position to start of line
528 aNewPos.setX( TABWIN_SPACING_X );
529 aNewPos.setY( (nRow+1) * TABWIN_SPACING_Y );
531 // determine rectangle for the corresponding line
532 tools::Rectangle aRowRect( Point(0,0), aOutSize );
533 aRowRect.SetTop( nRow * ( TABWIN_SPACING_Y + TABWIN_HEIGHT_STD ) );
534 aRowRect.SetBottom( (nRow+1) * ( TABWIN_SPACING_Y + TABWIN_HEIGHT_STD ) );
536 // check occupied areas of this line
537 for (auto const& elem : m_aTableMap)
539 OTableWindow* pOtherTabWin = elem.second;
540 tools::Rectangle aOtherTabWinRect( pOtherTabWin->GetPosPixel(), pOtherTabWin->GetSizePixel() );
543 ( (aOtherTabWinRect.Top()>aRowRect.Top()) && (aOtherTabWinRect.Top()<aRowRect.Bottom()) ) ||
544 ( (aOtherTabWinRect.Bottom()>aRowRect.Top()) && (aOtherTabWinRect.Bottom()<aRowRect.Bottom()) )
547 // TabWin is in the line
548 if( aOtherTabWinRect.Right()>aNewPos.X() )
549 aNewPos.setX( aOtherTabWinRect.Right() + TABWIN_SPACING_X );
553 // Is there space left in this line?
554 if( (aNewPos.X()+TABWIN_WIDTH_STD)<aRowRect.Right() )
556 aNewPos.setY( aRowRect.Top() + TABWIN_SPACING_Y );
557 bEnd = true;
559 else
561 if( (aRowRect.Bottom()+aRowRect.GetHeight()) > aOutSize.Height() )
563 // insert it in the first row
564 sal_Int32 nCount = m_aTableMap.size() % (nRow+1);
565 ++nCount;
566 aNewPos.setY( nCount * TABWIN_SPACING_Y + (nCount-1)*CalcZoom(TABWIN_HEIGHT_STD) );
567 bEnd = true;
569 else
570 nRow++;
575 // determine size
576 Size aNewSize( CalcZoom(TABWIN_WIDTH_STD), CalcZoom(TABWIN_HEIGHT_STD) );
578 // check if the new position in inside the scrollbars ranges
579 Point aBottom(aNewPos);
580 aBottom.AdjustX(aNewSize.Width() );
581 aBottom.AdjustY(aNewSize.Height() );
583 if(!GetHScrollBar().GetRange().Contains(aBottom.X()))
584 GetHScrollBar().SetRange( Range(0, aBottom.X()) );
585 if(!GetVScrollBar().GetRange().Contains(aBottom.Y()))
586 GetVScrollBar().SetRange( Range(0, aBottom.Y()) );
588 pTabWin->SetPosSizePixel( aNewPos, aNewSize );
591 void OJoinTableView::DataChanged(const DataChangedEvent& rDCEvt)
593 if (rDCEvt.GetType() == DataChangedEventType::SETTINGS)
595 // consider the worst case: the colors changed, so adjust me
596 InitColors();
597 Invalidate(InvalidateFlags::NoChildren);
598 // due to the Invalidate, the connections are redrawn, so that they are also pictured in the new colors
602 void OJoinTableView::InitColors()
604 // the colors for the illustration should be the system colors
605 StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
606 SetBackground(Wallpaper(aSystemStyle.GetDialogColor()));
609 void OJoinTableView::BeginChildMove( OTableWindow* pTabWin, const Point& rMousePos )
612 if (m_pView->getController().isReadOnly())
613 return;
615 m_pDragWin = pTabWin;
616 SetPointer(PointerStyle::Move);
617 Point aMousePos = ScreenToOutputPixel( rMousePos );
618 m_aDragOffset = aMousePos - pTabWin->GetPosPixel();
619 m_pDragWin->SetZOrder(nullptr, ZOrderFlags::First);
620 StartTracking();
623 void OJoinTableView::NotifyTitleClicked( OTableWindow* pTabWin, const Point& rMousePos )
625 DeselectConn(GetSelectedConn());
626 BeginChildMove(pTabWin, rMousePos);
629 void OJoinTableView::BeginChildSizing( OTableWindow* pTabWin, PointerStyle nPointer )
632 if (m_pView->getController().isReadOnly())
633 return;
635 SetPointer( nPointer );
636 m_pSizingWin = pTabWin;
637 StartTracking();
640 bool OJoinTableView::ScrollPane( tools::Long nDelta, bool bHoriz, bool bPaintScrollBars )
642 bool bRet = true;
644 // adjust ScrollBar-Positions
645 if( bPaintScrollBars )
647 if( bHoriz )
649 tools::Long nOldThumbPos = GetHScrollBar().GetThumbPos();
650 tools::Long nNewThumbPos = nOldThumbPos + nDelta;
651 if( nNewThumbPos < 0 )
653 nNewThumbPos = 0;
654 bRet = false;
656 if( nNewThumbPos > GetHScrollBar().GetRange().Max() )
658 nNewThumbPos = GetHScrollBar().GetRange().Max();
659 bRet = false;
661 GetHScrollBar().SetThumbPos( nNewThumbPos );
662 nDelta = GetHScrollBar().GetThumbPos() - nOldThumbPos;
664 else
666 tools::Long nOldThumbPos = GetVScrollBar().GetThumbPos();
667 tools::Long nNewThumbPos = nOldThumbPos+nDelta;
668 if( nNewThumbPos < 0 )
670 nNewThumbPos = 0;
671 bRet = false;
673 if( nNewThumbPos > GetVScrollBar().GetRange().Max() )
675 nNewThumbPos = GetVScrollBar().GetRange().Max();
676 bRet = false;
678 GetVScrollBar().SetThumbPos( nNewThumbPos );
679 nDelta = GetVScrollBar().GetThumbPos() - nOldThumbPos;
683 // If ScrollOffset hitting borders, no redrawing.
684 if( (GetHScrollBar().GetThumbPos()==m_aScrollOffset.X()) &&
685 (GetVScrollBar().GetThumbPos()==m_aScrollOffset.Y()) )
686 return false;
688 // set ScrollOffset anew
689 if (bHoriz)
690 m_aScrollOffset.setX( GetHScrollBar().GetThumbPos() );
691 else
692 m_aScrollOffset.setY( GetVScrollBar().GetThumbPos() );
694 // move all windows
695 OTableWindow* pTabWin;
696 Point aPos;
698 for (auto const& elem : m_aTableMap)
700 pTabWin = elem.second;
701 aPos = pTabWin->GetPosPixel();
703 if( bHoriz )
704 aPos.AdjustX( -nDelta );
705 else aPos.AdjustY( -nDelta );
707 pTabWin->SetPosPixel( aPos );
710 Invalidate(); // InvalidateFlags::NoChildren
712 return bRet;
715 void OJoinTableView::Tracking( const TrackingEvent& rTEvt )
717 HideTracking();
719 if (rTEvt.IsTrackingEnded())
721 if( m_pDragWin )
723 if (m_aDragScrollIdle.IsActive())
724 m_aDragScrollIdle.Stop();
726 // adjust position of child after moving
727 // windows are not allowed to leave display range
728 Point aDragWinPos = rTEvt.GetMouseEvent().GetPosPixel() - m_aDragOffset;
729 Size aDragWinSize = m_pDragWin->GetSizePixel();
730 if( aDragWinPos.X() < 0 )
731 aDragWinPos.setX( 0 );
732 if( aDragWinPos.Y() < 0 )
733 aDragWinPos.setY( 0 );
734 if( (aDragWinPos.X() + aDragWinSize.Width()) > m_aOutputSize.Width() )
735 aDragWinPos.setX( m_aOutputSize.Width() - aDragWinSize.Width() - 1 );
736 if( (aDragWinPos.Y() + aDragWinSize.Height()) > m_aOutputSize.Height() )
737 aDragWinPos.setY( m_aOutputSize.Height() - aDragWinSize.Height() - 1 );
738 if( aDragWinPos.X() < 0 )
739 aDragWinPos.setX( 0 );
740 if( aDragWinPos.Y() < 0 )
741 aDragWinPos.setY( 0 );
742 // TODO : don't position window anew, if it is leaving range, but just expand the range
744 // position window
745 EndTracking();
746 m_pDragWin->SetZOrder(nullptr, ZOrderFlags::First);
747 // check, if I really moved
748 // (this prevents setting the modified-Flag, when there actually was no change0
749 TTableWindowData::value_type pData = m_pDragWin->GetData();
750 if ( ! (pData && pData->HasPosition() && (pData->GetPosition() == aDragWinPos)))
752 // old logic coordinates
753 Point ptOldPos = m_pDragWin->GetPosPixel() + Point(GetHScrollBar().GetThumbPos(), GetVScrollBar().GetThumbPos());
754 // new positioning
755 m_pDragWin->SetPosPixel(aDragWinPos);
756 TabWinMoved(m_pDragWin, ptOldPos);
758 m_pDragWin->GrabFocus();
760 m_pDragWin = nullptr;
761 SetPointer(PointerStyle::Arrow);
763 // else we handle the resizing
764 else if( m_pSizingWin )
766 SetPointer( PointerStyle::Arrow );
767 EndTracking();
769 // old physical coordinates
771 Size szOld = m_pSizingWin->GetSizePixel();
772 Point ptOld = m_pSizingWin->GetPosPixel();
773 Size aNewSize(CalcZoom(m_aSizingRect.GetSize().Width()),CalcZoom(m_aSizingRect.GetSize().Height()));
774 m_pSizingWin->SetPosSizePixel( m_aSizingRect.TopLeft(), aNewSize );
775 TabWinSized(m_pSizingWin, ptOld, szOld);
777 m_pSizingWin->Invalidate( m_aSizingRect );
778 m_pSizingWin = nullptr;
781 else if (rTEvt.IsTrackingCanceled())
783 if (m_aDragScrollIdle.IsActive())
784 m_aDragScrollIdle.Stop();
785 EndTracking();
787 else
789 if( m_pDragWin )
791 m_ptPrevDraggingPos = rTEvt.GetMouseEvent().GetPosPixel();
792 // scroll at window borders
793 ScrollWhileDragging();
796 if( m_pSizingWin )
798 Point aMousePos = rTEvt.GetMouseEvent().GetPosPixel();
799 m_aSizingRect = m_pSizingWin->getSizingRect(aMousePos,m_aOutputSize);
800 PaintImmediately();
801 ShowTracking( m_aSizingRect, ShowTrackFlags::Small | ShowTrackFlags::TrackWindow );
806 void OJoinTableView::ConnDoubleClicked(VclPtr<OTableConnection>& /*rConnection*/)
810 void OJoinTableView::MouseButtonDown( const MouseEvent& rEvt )
812 GrabFocus();
813 Window::MouseButtonDown(rEvt);
816 void OJoinTableView::MouseButtonUp( const MouseEvent& rEvt )
818 Window::MouseButtonUp(rEvt);
819 // Has a connection been selected?
820 if( m_vTableConnection.empty() )
821 return;
823 DeselectConn(GetSelectedConn());
825 for (auto & elem : m_vTableConnection)
827 if( elem->CheckHit(rEvt.GetPosPixel()) )
829 SelectConn(elem);
831 // Double-click
832 if( rEvt.GetClicks() == 2 )
833 ConnDoubleClicked(elem);
835 break;
840 void OJoinTableView::KeyInput( const KeyEvent& rEvt )
842 sal_uInt16 nCode = rEvt.GetKeyCode().GetCode();
843 bool bShift = rEvt.GetKeyCode().IsShift();
844 bool bCtrl = rEvt.GetKeyCode().IsMod1();
846 if( !bCtrl && !bShift && (nCode==KEY_DELETE) )
848 if (GetSelectedConn())
849 RemoveConnection(GetSelectedConn(), true);
851 else
852 Window::KeyInput( rEvt );
855 void OJoinTableView::DeselectConn(OTableConnection* pConn)
857 if (!pConn || !pConn->IsSelected())
858 return;
860 // deselect the corresponding entries in the ListBox of the table window
861 OTableWindow* pWin = pConn->GetSourceWin();
862 if (pWin && pWin->GetListBox())
863 pWin->GetListBox()->get_widget().unselect_all();
865 pWin = pConn->GetDestWin();
866 if (pWin && pWin->GetListBox())
867 pWin->GetListBox()->get_widget().unselect_all();
869 pConn->Deselect();
870 m_pSelectedConn = nullptr;
873 void OJoinTableView::SelectConn(OTableConnection* pConn)
875 DeselectConn(GetSelectedConn());
877 pConn->Select();
878 m_pSelectedConn = pConn;
879 GrabFocus(); // has to be called here because a table window may still be focused
881 // select the concerned entries in the windows
882 OTableWindow* pConnSource = pConn->GetSourceWin();
883 OTableWindow* pConnDest = pConn->GetDestWin();
884 if (!(pConnSource && pConnDest))
885 return;
887 OTableWindowListBox* pSourceBox = pConnSource->GetListBox().get();
888 OTableWindowListBox* pDestBox = pConnDest->GetListBox().get();
889 if (!(pSourceBox && pDestBox))
890 return;
892 pSourceBox->get_widget().unselect_all();
893 pDestBox->get_widget().unselect_all();
895 bool bScrolled = false;
897 const std::vector<std::unique_ptr<OConnectionLine>>& rLines = pConn->GetConnLineList();
898 auto aIter = rLines.rbegin();
899 for(;aIter != rLines.rend();++aIter)
901 if ((*aIter)->IsValid())
903 int nSourceEntry = pSourceBox->GetEntryFromText((*aIter)->GetData()->GetSourceFieldName());
904 if (nSourceEntry != -1)
906 pSourceBox->get_widget().select(nSourceEntry);
907 pSourceBox->get_widget().scroll_to_row(nSourceEntry);
908 bScrolled = true;
911 int nDestEntry = pDestBox->GetEntryFromText((*aIter)->GetData()->GetDestFieldName());
912 if (nDestEntry != -1)
914 pDestBox->get_widget().select(nDestEntry);
915 pDestBox->get_widget().scroll_to_row(nDestEntry);
916 bScrolled = true;
921 if (bScrolled)
923 // scrolling was done -> redraw
924 Invalidate(InvalidateFlags::NoChildren);
928 void OJoinTableView::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
930 DrawConnections(rRenderContext, rRect);
933 void OJoinTableView::InvalidateConnections()
935 // draw Joins
936 for (auto & conn : m_vTableConnection)
937 conn->InvalidateConnection();
940 void OJoinTableView::DrawConnections(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
942 // draw Joins
943 for(const auto& connection : m_vTableConnection)
944 connection->Draw(rRenderContext, rRect);
945 // finally redraw the selected one above all others
946 if (GetSelectedConn())
947 GetSelectedConn()->Draw(rRenderContext, rRect);
950 std::vector<VclPtr<OTableConnection> >::const_iterator OJoinTableView::getTableConnections(const OTableWindow* _pFromWin) const
952 return std::find_if( m_vTableConnection.begin(),
953 m_vTableConnection.end(),
954 [_pFromWin](OTableConnection * p) { return p->isTableConnection(_pFromWin); });
957 sal_Int32 OJoinTableView::getConnectionCount(const OTableWindow* _pFromWin) const
959 return std::count_if( m_vTableConnection.begin(),
960 m_vTableConnection.end(),
961 [_pFromWin](OTableConnection * p) { return p->isTableConnection(_pFromWin); });
964 bool OJoinTableView::ExistsAConn(const OTableWindow* pFrom) const
966 return getTableConnections(pFrom) != m_vTableConnection.end();
969 void OJoinTableView::ClearAll()
971 SetUpdateMode(false);
973 HideTabWins();
975 // and the same with the Connections
976 for (auto & elem : m_vTableConnection)
978 RemoveConnection(elem, true);
980 m_vTableConnection.clear();
982 m_pLastFocusTabWin = nullptr;
983 m_pSelectedConn = nullptr;
985 // scroll to the upper left
986 ScrollPane(-GetScrollOffset().X(), true, true);
987 ScrollPane(-GetScrollOffset().Y(), false, true);
988 Invalidate();
991 void OJoinTableView::ScrollWhileDragging()
993 OSL_ENSURE(m_pDragWin != nullptr, "OJoinTableView::ScrollWhileDragging must not be called when a window is being dragged !");
995 // kill the timer
996 if (m_aDragScrollIdle.IsActive())
997 m_aDragScrollIdle.Stop();
999 Point aDragWinPos = m_ptPrevDraggingPos - m_aDragOffset;
1000 Size aDragWinSize = m_pDragWin->GetSizePixel();
1001 Point aLowerRight(aDragWinPos.X() + aDragWinSize.Width(), aDragWinPos.Y() + aDragWinSize.Height());
1003 if (aDragWinPos == m_pDragWin->GetPosPixel())
1004 return;
1006 // avoid illustration errors (when scrolling with active TrackingRect)
1007 HideTracking();
1009 bool bScrolling = false;
1010 bool bNeedScrollTimer = false;
1012 // scroll at window borders
1013 // TODO : only catch, if window would disappear completely (don't, if there is still a pixel visible)
1014 if( aDragWinPos.X() < 5 )
1016 bScrolling = ScrollPane( -LINE_SIZE, true, true );
1017 if( !bScrolling && (aDragWinPos.X()<0) )
1018 aDragWinPos.setX( 0 );
1020 // do I need further (timer controlled) scrolling ?
1021 bNeedScrollTimer = bScrolling && (aDragWinPos.X() < 5);
1024 if( aLowerRight.X() > m_aOutputSize.Width() - 5 )
1026 bScrolling = ScrollPane( LINE_SIZE, true, true ) ;
1027 if( !bScrolling && ( aLowerRight.X() > m_aOutputSize.Width() ) )
1028 aDragWinPos.setX( m_aOutputSize.Width() - aDragWinSize.Width() );
1030 // do I need further (timer controlled) scrolling ?
1031 bNeedScrollTimer = bScrolling && (aLowerRight.X() > m_aOutputSize.Width() - 5);
1034 if( aDragWinPos.Y() < 5 )
1036 bScrolling = ScrollPane( -LINE_SIZE, false, true );
1037 if( !bScrolling && (aDragWinPos.Y()<0) )
1038 aDragWinPos.setY( 0 );
1040 bNeedScrollTimer = bScrolling && (aDragWinPos.Y() < 5);
1043 if( aLowerRight.Y() > m_aOutputSize.Height() - 5 )
1045 bScrolling = ScrollPane( LINE_SIZE, false, true );
1046 if( !bScrolling && ( (aDragWinPos.Y() + aDragWinSize.Height()) > m_aOutputSize.Height() ) )
1047 aDragWinPos.setY( m_aOutputSize.Height() - aDragWinSize.Height() );
1049 bNeedScrollTimer = bScrolling && (aLowerRight.Y() > m_aOutputSize.Height() - 5);
1052 // resetting timer, if still necessary
1053 if (bNeedScrollTimer)
1055 m_aDragScrollIdle.SetPriority( TaskPriority::HIGH_IDLE );
1056 m_aDragScrollIdle.Start();
1059 // redraw DraggingRect
1060 m_aDragRect = tools::Rectangle(m_ptPrevDraggingPos - m_aDragOffset, m_pDragWin->GetSizePixel());
1061 PaintImmediately();
1062 ShowTracking( m_aDragRect, ShowTrackFlags::Small | ShowTrackFlags::TrackWindow );
1065 IMPL_LINK_NOARG(OJoinTableView, OnDragScrollTimer, Timer *, void)
1067 ScrollWhileDragging();
1070 void OJoinTableView::invalidateAndModify(std::unique_ptr<SfxUndoAction> _pAction)
1072 Invalidate(InvalidateFlags::NoChildren);
1073 m_pView->getController().addUndoActionAndInvalidate(std::move(_pAction));
1076 void OJoinTableView::TabWinMoved(OTableWindow* ptWhich, const Point& ptOldPosition)
1078 Point ptThumbPos(GetHScrollBar().GetThumbPos(), GetVScrollBar().GetThumbPos());
1079 ptWhich->GetData()->SetPosition(ptWhich->GetPosPixel() + ptThumbPos);
1081 invalidateAndModify(std::make_unique<OJoinMoveTabWinUndoAct>(this, ptOldPosition, ptWhich));
1084 void OJoinTableView::TabWinSized(OTableWindow* ptWhich, const Point& ptOldPosition, const Size& szOldSize)
1086 ptWhich->GetData()->SetSize(ptWhich->GetSizePixel());
1087 ptWhich->GetData()->SetPosition(ptWhich->GetPosPixel());
1089 invalidateAndModify(std::make_unique<OJoinSizeTabWinUndoAct>(this, ptOldPosition, szOldSize, ptWhich));
1092 bool OJoinTableView::IsAddAllowed()
1095 // not, if Db readonly
1096 if (m_pView->getController().isReadOnly())
1097 return false;
1101 Reference< XConnection> xConnection = m_pView->getController().getConnection();
1102 if(!xConnection.is())
1103 return false;
1104 // not, if too many tables already
1105 Reference < XDatabaseMetaData > xMetaData( xConnection->getMetaData() );
1107 sal_Int32 nMax = xMetaData.is() ? xMetaData->getMaxTablesInSelect() : 0;
1108 if (nMax && nMax <= static_cast<sal_Int32>(m_aTableMap.size()))
1109 return false;
1111 catch(SQLException&)
1113 return false;
1116 return true;
1119 void OJoinTableView::executePopup(const Point& rPos, VclPtr<OTableConnection>& rSelConnection)
1121 ::tools::Rectangle aRect(rPos, Size(1, 1));
1122 weld::Window* pPopupParent = weld::GetPopupParent(*this, aRect);
1123 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pPopupParent, "dbaccess/ui/joinviewmenu.ui"));
1124 std::unique_ptr<weld::Menu> xContextMenu(xBuilder->weld_menu("menu"));
1125 OString sIdent = xContextMenu->popup_at_rect(pPopupParent, aRect);
1126 if (sIdent == "delete")
1127 RemoveConnection(rSelConnection, true);
1128 else if (sIdent == "edit")
1129 ConnDoubleClicked(rSelConnection); // is the same as double clicked
1132 void OJoinTableView::Command(const CommandEvent& rEvt)
1135 bool bHandled = false;
1137 switch (rEvt.GetCommand())
1139 case CommandEventId::ContextMenu:
1141 if( m_vTableConnection.empty() )
1142 return;
1144 VclPtr<OTableConnection>& rSelConnection = GetSelectedConn();
1145 // when it wasn't a mouse event use the selected connection
1146 if (!rEvt.IsMouseEvent())
1148 if (rSelConnection)
1150 const std::vector<std::unique_ptr<OConnectionLine>>& rLines = rSelConnection->GetConnLineList();
1151 auto aIter = std::find_if(rLines.begin(), rLines.end(),std::mem_fn(&OConnectionLine::IsValid));
1152 if( aIter != rLines.end() )
1153 executePopup((*aIter)->getMidPoint(), rSelConnection);
1156 else
1158 DeselectConn(rSelConnection);
1160 const Point& aMousePos = rEvt.GetMousePosPixel();
1161 for (auto & elem : m_vTableConnection)
1163 if( elem->CheckHit(aMousePos) )
1165 SelectConn(elem);
1166 if(!getDesignView()->getController().isReadOnly() && getDesignView()->getController().isConnected())
1167 executePopup(rEvt.GetMousePosPixel(),elem);
1168 break;
1172 bHandled = true;
1174 break;
1175 default: break;
1177 if (!bHandled)
1178 Window::Command(rEvt);
1181 OTableConnection* OJoinTableView::GetTabConn(const OTableWindow* pLhs,const OTableWindow* pRhs,bool _bSuppressCrossOrNaturalJoin) const
1183 OTableConnection* pConn = nullptr;
1184 OSL_ENSURE(pRhs || pLhs, "OJoinTableView::GetTabConn : invalid args !");
1185 // only one NULL-arg allowed
1187 if ((!pLhs || pLhs->ExistsAConn()) && (!pRhs || pRhs->ExistsAConn()))
1189 for(VclPtr<OTableConnection> const & pData : m_vTableConnection)
1191 if ( ( (pData->GetSourceWin() == pLhs)
1192 && ( (pData->GetDestWin() == pRhs)
1193 || (nullptr == pRhs)
1196 || ( (pData->GetSourceWin() == pRhs)
1197 && ( (pData->GetDestWin() == pLhs)
1198 || (nullptr == pLhs)
1203 if ( _bSuppressCrossOrNaturalJoin )
1205 if ( suppressCrossNaturalJoin(pData->GetData()) )
1206 continue;
1208 pConn = pData;
1209 break;
1213 return pConn;
1216 bool OJoinTableView::PreNotify(NotifyEvent& rNEvt)
1218 bool bHandled = false;
1219 switch (rNEvt.GetType())
1221 case NotifyEventType::COMMAND:
1223 const CommandEvent* pCommand = rNEvt.GetCommandEvent();
1224 if (pCommand->GetCommand() == CommandEventId::Wheel)
1226 const CommandWheelData* pData = rNEvt.GetCommandEvent()->GetWheelData();
1227 if (pData->GetMode() == CommandWheelMode::SCROLL)
1229 if (pData->GetDelta() > 0)
1230 ScrollPane(-10 * pData->GetScrollLines(), pData->IsHorz(), true);
1231 else
1232 ScrollPane(10 * pData->GetScrollLines(), pData->IsHorz(), true);
1233 bHandled = true;
1237 break;
1238 case NotifyEventType::KEYINPUT:
1240 if (m_aTableMap.empty())
1241 // no tab wins -> no conns -> no traveling
1242 break;
1244 const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
1245 if (!pKeyEvent->GetKeyCode().IsMod1())
1247 switch (pKeyEvent->GetKeyCode().GetCode())
1249 case KEY_TAB:
1251 if (!HasChildPathFocus())
1252 break;
1254 bool bForward = !pKeyEvent->GetKeyCode().IsShift();
1255 // is there an active tab win ?
1256 OTableWindowMap::const_iterator aIter = std::find_if(m_aTableMap.begin(), m_aTableMap.end(),
1257 [](const OTableWindowMap::value_type& rEntry) { return rEntry.second && rEntry.second->HasChildPathFocus(); });
1259 OTableWindow* pNextWin = nullptr;
1260 OTableConnection* pNextConn = nullptr;
1262 if (aIter != m_aTableMap.end())
1263 { // there is a currently active tab win
1264 // check if there is an "overflow" and we should select a conn instead of a win
1265 if (!m_vTableConnection.empty())
1267 if ((aIter->second == m_aTableMap.rbegin()->second) && bForward)
1268 // the last win is active and we're travelling forward -> select the first conn
1269 pNextConn = m_vTableConnection.begin()->get();
1270 if ((aIter == m_aTableMap.begin()) && !bForward)
1271 // the first win is active and we're traveling backward -> select the last conn
1272 pNextConn = m_vTableConnection.rbegin()->get();
1275 if (!pNextConn)
1277 // no conn for any reason -> select the next or previous tab win
1278 if(bForward)
1280 if ( aIter->second == m_aTableMap.rbegin()->second )
1281 pNextWin = m_aTableMap.begin()->second;
1282 else
1284 ++aIter;
1285 pNextWin = aIter->second;
1288 else
1290 if (aIter == m_aTableMap.begin())
1291 pNextWin = m_aTableMap.rbegin()->second;
1292 else
1294 --aIter;
1295 pNextWin = aIter->second;
1300 else
1301 { // no active tab win -> travel the connections
1302 // find the currently selected conn within the conn list
1303 sal_Int32 i(0);
1304 for (auto const& elem : m_vTableConnection)
1306 if ( elem.get() == GetSelectedConn() )
1307 break;
1308 ++i;
1310 if (i == sal_Int32(m_vTableConnection.size() - 1) && bForward)
1311 // the last conn is active and we're travelling forward -> select the first win
1312 pNextWin = m_aTableMap.begin()->second;
1313 if ((i == 0) && !bForward && !m_aTableMap.empty())
1314 // the first conn is active and we're travelling backward -> select the last win
1315 pNextWin = m_aTableMap.rbegin()->second;
1317 if (pNextWin)
1318 DeselectConn(GetSelectedConn());
1319 else
1320 // no win for any reason -> select the next or previous conn
1321 if (i < static_cast<sal_Int32>(m_vTableConnection.size()))
1322 // there is a currently active conn
1323 pNextConn = m_vTableConnection[(i + (bForward ? 1 : m_vTableConnection.size() - 1)) % m_vTableConnection.size()].get();
1324 else
1325 { // no tab win selected, no conn selected
1326 if (!m_vTableConnection.empty())
1327 pNextConn = m_vTableConnection[bForward ? 0 : m_vTableConnection.size() - 1].get();
1328 else if (!m_aTableMap.empty())
1330 if(bForward)
1331 pNextWin = m_aTableMap.begin()->second;
1332 else
1333 pNextWin = m_aTableMap.rbegin()->second;
1338 // now select the object
1339 if (pNextWin)
1341 if (pNextWin->GetListBox())
1342 pNextWin->GetListBox()->GrabFocus();
1343 else
1344 pNextWin->GrabFocus();
1345 EnsureVisible(pNextWin);
1347 else if (pNextConn)
1349 GrabFocus();
1350 // necessary : a conn may be selected even if a tab win has the focus, in this case
1351 // the next travel would select the same conn again if we would not reset the focus ...
1352 SelectConn(pNextConn);
1355 break;
1356 case KEY_RETURN:
1358 if (!pKeyEvent->GetKeyCode().IsShift() && GetSelectedConn() && HasFocus())
1359 ConnDoubleClicked(GetSelectedConn());
1360 break;
1365 break;
1366 case NotifyEventType::GETFOCUS:
1368 if (m_aTableMap.empty())
1369 // no tab wins -> no conns -> no focus change
1370 break;
1371 vcl::Window* pSource = rNEvt.GetWindow();
1372 if (pSource)
1374 vcl::Window* pSearchFor = nullptr;
1375 if (pSource->GetParent() == this)
1376 // it may be one of the tab wins
1377 pSearchFor = pSource;
1378 else if (pSource->GetParent() && (pSource->GetParent()->GetParent() == this))
1379 // it may be one of th list boxes of one of the tab wins
1380 pSearchFor = pSource->GetParent();
1382 if (pSearchFor)
1384 for (auto const& elem : m_aTableMap)
1386 if (elem.second == pSearchFor)
1388 m_pLastFocusTabWin = elem.second;
1389 break;
1395 break;
1396 default:
1397 break;
1400 if (!bHandled)
1401 return Window::PreNotify(rNEvt);
1402 return true;
1405 void OJoinTableView::GrabTabWinFocus()
1407 if (m_pLastFocusTabWin && m_pLastFocusTabWin->IsVisible())
1409 if (m_pLastFocusTabWin->GetListBox())
1410 m_pLastFocusTabWin->GetListBox()->GrabFocus();
1411 else
1412 m_pLastFocusTabWin->GrabFocus();
1414 else if (!m_aTableMap.empty() && m_aTableMap.begin()->second && m_aTableMap.begin()->second->IsVisible())
1416 VclPtr<OTableWindow> pFirstWin = m_aTableMap.begin()->second;
1417 if (pFirstWin->GetListBox())
1418 pFirstWin->GetListBox()->GrabFocus();
1419 else
1420 pFirstWin->GrabFocus();
1424 void OJoinTableView::StateChanged( StateChangedType nType )
1426 Window::StateChanged( nType );
1428 // FIXME RenderContext
1429 if ( nType != StateChangedType::Zoom )
1430 return;
1432 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1434 vcl::Font aFont = rStyleSettings.GetGroupFont();
1435 if ( IsControlFont() )
1436 aFont.Merge( GetControlFont() );
1437 SetZoomedPointFont(*GetOutDev(), aFont);
1439 for (auto const& elem : m_aTableMap)
1441 elem.second->SetZoom(GetZoom());
1442 Size aSize(CalcZoom(elem.second->GetSizePixel().Width()),CalcZoom(elem.second->GetSizePixel().Height()));
1443 elem.second->SetSizePixel(aSize);
1445 Resize();
1448 void OJoinTableView::HideTabWins()
1450 SetUpdateMode(false);
1452 OTableWindowMap& rTabWins = GetTabWinMap();
1454 // working on a copy because the real list will be cleared in inner calls
1455 OTableWindowMap aCopy(rTabWins);
1456 for (auto const& elem : aCopy)
1457 RemoveTabWin(elem.second);
1459 m_pView->getController().setModified(true);
1461 SetUpdateMode(true);
1465 sal_Int8 OJoinTableView::AcceptDrop( const AcceptDropEvent& /*_rEvt*/ )
1467 return DND_ACTION_NONE;
1470 sal_Int8 OJoinTableView::ExecuteDrop( const ExecuteDropEvent& /*_rEvt*/ )
1472 return DND_ACTION_NONE;
1475 void OJoinTableView::dragFinished( )
1479 void OJoinTableView::clearLayoutInformation()
1481 m_pLastFocusTabWin = nullptr;
1482 m_pSelectedConn = nullptr;
1483 // delete lists
1484 for (auto & elem : m_aTableMap)
1486 if ( elem.second )
1487 elem.second->clearListBox();
1488 elem.second.disposeAndClear();
1491 m_aTableMap.clear();
1493 for (auto & elem : m_vTableConnection)
1494 elem.disposeAndClear();
1496 m_vTableConnection.clear();
1499 void OJoinTableView::lookForUiActivities()
1503 void OJoinTableView::LoseFocus()
1505 DeselectConn(GetSelectedConn());
1506 Window::LoseFocus();
1509 void OJoinTableView::GetFocus()
1511 Window::GetFocus();
1512 if ( !m_aTableMap.empty() && !GetSelectedConn() )
1513 GrabTabWinFocus();
1516 Reference< XAccessible > OJoinTableView::CreateAccessible()
1518 m_pAccessible = new OJoinDesignViewAccess(this);
1519 return m_pAccessible;
1522 void OJoinTableView::modified()
1524 OJoinController& rController = m_pView->getController();
1525 rController.setModified( true );
1526 rController.InvalidateFeature(ID_BROWSER_ADDTABLE);
1527 rController.InvalidateFeature(SID_RELATION_ADD_RELATION);
1530 void OJoinTableView::addConnection(OTableConnection* _pConnection,bool _bAddData)
1532 if ( _bAddData )
1534 #if OSL_DEBUG_LEVEL > 0
1535 TTableConnectionData& rTabConnDataList = m_pView->getController().getTableConnectionData();
1536 OSL_ENSURE( std::find(rTabConnDataList.begin(), rTabConnDataList.end(),_pConnection->GetData()) == rTabConnDataList.end(),"Data already in vector!");
1537 #endif
1538 m_pView->getController().getTableConnectionData().push_back(_pConnection->GetData());
1540 m_vTableConnection.emplace_back(_pConnection);
1541 _pConnection->RecalcLines();
1542 _pConnection->InvalidateConnection();
1544 modified();
1545 if ( m_pAccessible )
1546 m_pAccessible->notifyAccessibleEvent( AccessibleEventId::CHILD,
1547 Any(),
1548 Any(_pConnection->GetAccessible()));
1551 bool OJoinTableView::allowQueries() const
1553 return true;
1556 void OJoinTableView::onNoColumns_throw()
1558 OSL_FAIL( "OTableWindow::onNoColumns_throw: cannot really handle this!" );
1559 throw SQLException();
1562 bool OJoinTableView::suppressCrossNaturalJoin(const TTableConnectionData::value_type& ) const
1564 return false;
1567 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */