LCOV - code coverage report
Current view: top level - libreoffice/dbaccess/source/ui/querydesign - JoinTableView.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 817 0.0 %
Date: 2012-12-17 Functions: 0 75 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10