LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/ui/querydesign - TableWindow.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 380 0.3 %
Date: 2013-07-09 Functions: 2 41 4.9 %
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 "TableWindow.hxx"
      21             : #include "TableWindowListBox.hxx"
      22             : #include "QueryTableView.hxx"
      23             : #include "QueryDesignView.hxx"
      24             : #include "TableWindowData.hxx"
      25             : #include "imageprovider.hxx"
      26             : #include <tools/diagnose_ex.h>
      27             : #include <osl/diagnose.h>
      28             : #include <vcl/svapp.hxx>
      29             : #include <vcl/wall.hxx>
      30             : 
      31             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      32             : #include <com/sun/star/container/XNameAccess.hpp>
      33             : #include <com/sun/star/beans/XPropertySet.hpp>
      34             : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      35             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      36             : #include "querycontroller.hxx"
      37             : #include "dbu_qry.hrc"
      38             : #include "dbustrings.hrc"
      39             : #include "Query.hrc"
      40             : #include <comphelper/extract.hxx>
      41             : #include "UITools.hxx"
      42             : #include "TableWindowAccess.hxx"
      43             : #include "browserids.hxx"
      44             : #include <connectivity/dbtools.hxx>
      45             : #include "svtools/treelistentry.hxx"
      46             : 
      47             : using namespace dbaui;
      48             : using namespace ::utl;
      49             : using namespace ::com::sun::star;
      50             : using namespace ::com::sun::star::sdb;
      51             : using namespace ::com::sun::star::sdbc;
      52             : using namespace ::com::sun::star::sdbcx;
      53             : using namespace ::com::sun::star::uno;
      54             : using namespace ::com::sun::star::beans;
      55             : using namespace ::com::sun::star::container;
      56             : using namespace ::com::sun::star::lang;
      57             : using namespace ::com::sun::star::accessibility;
      58             : 
      59             : #define TABWIN_SIZING_AREA      4
      60             : #define TABWIN_WIDTH_MIN    90
      61             : #define TABWIN_HEIGHT_MIN   80
      62             : 
      63             : //========================================================================
      64             : // class OTableWindow
      65             : //========================================================================
      66             : DBG_NAME(OTableWindow)
      67             : //------------------------------------------------------------------------------
      68           0 : OTableWindow::OTableWindow( Window* pParent, const TTableWindowData::value_type& pTabWinData )
      69             :           : ::comphelper::OContainerListener(m_aMutex)
      70             :           ,Window( pParent, WB_3DLOOK|WB_MOVEABLE )
      71             :           ,m_aTypeImage( this )
      72             :           ,m_aTitle( this )
      73             :           ,m_pListBox(NULL)
      74             :           ,m_pAccessible(NULL)
      75             :           ,m_pData( pTabWinData )
      76             :           ,m_nMoveCount(0)
      77             :           ,m_nMoveIncrement(1)
      78             :           ,m_nSizingFlags( SIZING_NONE )
      79           0 :           ,m_bActive( sal_False )
      80             : {
      81             :     DBG_CTOR(OTableWindow,NULL);
      82             : 
      83             :     // Set position and size
      84           0 :     if( GetData()->HasPosition() )
      85           0 :         SetPosPixel( GetData()->GetPosition() );
      86             : 
      87           0 :     if( GetData()->HasSize() )
      88           0 :         SetSizePixel( GetData()->GetSize() );
      89             : 
      90             :     // Set background
      91           0 :     const StyleSettings&  aSystemStyle = Application::GetSettings().GetStyleSettings();
      92           0 :     SetBackground(Wallpaper(aSystemStyle.GetFaceColor()));
      93             :     // Set the text colour even though there is no text,
      94             :     // because derived classes might need it
      95           0 :     SetTextColor(aSystemStyle.GetButtonTextColor());
      96             : 
      97           0 :     EnableClipSiblings();
      98           0 : }
      99             : 
     100             : //------------------------------------------------------------------------------
     101           0 : OTableWindow::~OTableWindow()
     102             : {
     103             :     DBG_DTOR(OTableWindow,NULL);
     104             : 
     105           0 :     if (m_pListBox)
     106             :     {
     107             :         OSL_ENSURE(m_pListBox->GetEntryCount()==0,"Forgot to call EmptyListbox()!");
     108           0 :         ::std::auto_ptr<Window> aTemp(m_pListBox);
     109           0 :         m_pListBox = NULL;
     110             :     }
     111           0 :     if ( m_pContainerListener.is() )
     112           0 :         m_pContainerListener->dispose();
     113             : 
     114           0 :     m_pAccessible = NULL;
     115           0 : }
     116             : // -----------------------------------------------------------------------------
     117           0 : const OJoinTableView* OTableWindow::getTableView() const
     118             : {
     119             :     OSL_ENSURE(static_cast<OJoinTableView*>(GetParent()),"No OJoinTableView!");
     120           0 :     return static_cast<OJoinTableView*>(GetParent());
     121             : }
     122             : // -----------------------------------------------------------------------------
     123           0 : OJoinTableView* OTableWindow::getTableView()
     124             : {
     125             :     OSL_ENSURE(static_cast<OJoinTableView*>(GetParent()),"No OJoinTableView!");
     126           0 :     return static_cast<OJoinTableView*>(GetParent());
     127             : }
     128             : // -----------------------------------------------------------------------------
     129           0 : OJoinDesignView* OTableWindow::getDesignView()
     130             : {
     131             :     OSL_ENSURE(static_cast<OJoinDesignView*>(GetParent()->GetParent()->GetParent()),"No OJoinDesignView!");
     132           0 :     return static_cast<OJoinDesignView*>(GetParent()->GetParent()->GetParent());
     133             : }
     134             : //------------------------------------------------------------------------------
     135           0 : void OTableWindow::SetPosPixel( const Point& rNewPos )
     136             : {
     137           0 :     Point aNewPosData = rNewPos + getTableView()->GetScrollOffset();
     138           0 :     GetData()->SetPosition( aNewPosData );
     139           0 :     Window::SetPosPixel( rNewPos );
     140           0 : }
     141             : 
     142             : //------------------------------------------------------------------------------
     143           0 : void OTableWindow::SetSizePixel( const Size& rNewSize )
     144             : {
     145           0 :     Size aOutSize(rNewSize);
     146           0 :     if( aOutSize.Width() < TABWIN_WIDTH_MIN )
     147           0 :         aOutSize.Width() = TABWIN_WIDTH_MIN;
     148           0 :     if( aOutSize.Height() < TABWIN_HEIGHT_MIN )
     149           0 :         aOutSize.Height() = TABWIN_HEIGHT_MIN;
     150             : 
     151           0 :     GetData()->SetSize( aOutSize );
     152           0 :     Window::SetSizePixel( aOutSize );
     153           0 : }
     154             : //------------------------------------------------------------------------------
     155           0 : void OTableWindow::SetPosSizePixel( const Point& rNewPos, const Size& rNewSize )
     156             : {
     157           0 :     SetPosPixel( rNewPos );
     158           0 :     SetSizePixel( rNewSize );
     159           0 : }
     160             : //------------------------------------------------------------------------------
     161           0 : OTableWindowListBox* OTableWindow::CreateListBox()
     162             : {
     163           0 :     return new OTableWindowListBox(this);
     164             : }
     165             : 
     166             : //------------------------------------------------------------------------------
     167           0 : sal_Bool OTableWindow::FillListBox()
     168             : {
     169           0 :     m_pListBox->Clear();
     170           0 :     if ( !m_pContainerListener.is() )
     171             :     {
     172           0 :         Reference< XContainer> xContainer(m_pData->getColumns(),UNO_QUERY);
     173           0 :         if ( xContainer.is() )
     174           0 :             m_pContainerListener = new ::comphelper::OContainerListenerAdapter(this,xContainer);
     175             :     }
     176             :     // mark all primary keys with special image
     177           0 :     ModuleRes TmpRes(IMG_JOINS);
     178           0 :     ImageList aImageList(TmpRes);
     179           0 :     Image aPrimKeyImage = aImageList.GetImage(IMG_PRIMARY_KEY);
     180             : 
     181           0 :     if (GetData()->IsShowAll())
     182             :     {
     183           0 :         SvTreeListEntry* pEntry = m_pListBox->InsertEntry( OUString("*") );
     184           0 :         pEntry->SetUserData( createUserData(NULL,false) );
     185             :     }
     186             : 
     187           0 :     Reference<XNameAccess> xPKeyColumns;
     188             :     try
     189             :     {
     190           0 :         xPKeyColumns = dbtools::getPrimaryKeyColumns_throw(m_pData->getTable());
     191             :     }
     192           0 :     catch(Exception&)
     193             :     {
     194             :         OSL_FAIL("Exception occurred!");
     195             :     }
     196             :     try
     197             :     {
     198           0 :         Reference< XNameAccess > xColumns = m_pData->getColumns();
     199           0 :         if( xColumns.is() )
     200             :         {
     201           0 :             Sequence< OUString> aColumns = xColumns->getElementNames();
     202           0 :             const OUString* pIter = aColumns.getConstArray();
     203           0 :             const OUString* pEnd = pIter + aColumns.getLength();
     204             : 
     205           0 :             SvTreeListEntry* pEntry = NULL;
     206           0 :             for (; pIter != pEnd; ++pIter)
     207             :             {
     208           0 :                 bool bPrimaryKeyColumn = xPKeyColumns.is() && xPKeyColumns->hasByName( *pIter );
     209             :                 // is this column in the primary key
     210           0 :                 if ( bPrimaryKeyColumn )
     211           0 :                     pEntry = m_pListBox->InsertEntry(*pIter, aPrimKeyImage, aPrimKeyImage);
     212             :                 else
     213           0 :                     pEntry = m_pListBox->InsertEntry(*pIter);
     214             : 
     215           0 :                 Reference<XPropertySet> xColumn(xColumns->getByName(*pIter),UNO_QUERY);
     216           0 :                 if ( xColumn.is() )
     217           0 :                     pEntry->SetUserData( createUserData(xColumn,bPrimaryKeyColumn) );
     218           0 :             }
     219           0 :         }
     220             :     }
     221           0 :     catch(Exception&)
     222             :     {
     223             :         OSL_FAIL("Exception occurred!");
     224             :     }
     225             : 
     226           0 :     return sal_True;
     227             : }
     228             : // -----------------------------------------------------------------------------
     229           0 : void* OTableWindow::createUserData(const Reference< XPropertySet>& /*_xColumn*/,bool /*_bPrimaryKey*/)
     230             : {
     231           0 :     return NULL;
     232             : }
     233             : // -----------------------------------------------------------------------------
     234           0 : void OTableWindow::deleteUserData(void*& _pUserData)
     235             : {
     236             :     OSL_ENSURE(!_pUserData,"INVALID call. Need to delete the userclass!");
     237           0 :     _pUserData = NULL;
     238           0 : }
     239             : //------------------------------------------------------------------------------
     240           0 : void OTableWindow::clearListBox()
     241             : {
     242           0 :     if ( m_pListBox )
     243             :     {
     244           0 :         SvTreeListEntry* pEntry = m_pListBox->First();
     245             : 
     246           0 :         while(pEntry)
     247             :         {
     248           0 :             void* pUserData = pEntry->GetUserData();
     249           0 :             deleteUserData(pUserData);
     250           0 :             SvTreeListEntry* pNextEntry = m_pListBox->Next(pEntry);
     251           0 :             m_pListBox->GetModel()->Remove(pEntry);
     252           0 :             pEntry = pNextEntry;
     253             :         }
     254             :     }
     255           0 : }
     256             : 
     257             : //------------------------------------------------------------------------------
     258           0 : void OTableWindow::impl_updateImage()
     259             : {
     260           0 :     ImageProvider aImageProvider( getDesignView()->getController().getConnection() );
     261             : 
     262           0 :     Image aImage;
     263           0 :     aImageProvider.getImages( GetComposedName(), m_pData->isQuery() ? DatabaseObject::QUERY : DatabaseObject::TABLE, aImage );
     264             : 
     265           0 :     if ( !aImage )
     266             :     {
     267             :         OSL_FAIL( "OTableWindow::impl_updateImage: no images!" );
     268           0 :         return;
     269             :     }
     270             : 
     271           0 :     m_aTypeImage.SetModeImage( aImage );
     272           0 :     m_aTypeImage.Show();
     273             : }
     274             : 
     275             : //------------------------------------------------------------------------------
     276           0 : sal_Bool OTableWindow::Init()
     277             : {
     278             :     // create list box if necessary
     279           0 :     if ( !m_pListBox )
     280             :     {
     281           0 :         m_pListBox = CreateListBox();
     282             :         OSL_ENSURE( m_pListBox != NULL, "OTableWindow::Init() : CreateListBox returned NULL !" );
     283           0 :         m_pListBox->SetSelectionMode( MULTIPLE_SELECTION );
     284             :     }
     285             : 
     286             :     // Set the title
     287           0 :     m_aTitle.SetText( m_pData->GetWinName() );
     288           0 :     m_aTitle.Show();
     289             : 
     290           0 :     m_pListBox->Show();
     291             : 
     292             :     // add the fields to the ListBox
     293           0 :     clearListBox();
     294           0 :     sal_Bool bSuccess = FillListBox();
     295           0 :     if ( bSuccess )
     296           0 :         m_pListBox->SelectAll( sal_False );
     297             : 
     298           0 :     impl_updateImage();
     299             : 
     300           0 :     return bSuccess;
     301             : }
     302             : //------------------------------------------------------------------------------
     303           0 : void OTableWindow::DataChanged(const DataChangedEvent& rDCEvt)
     304             : {
     305           0 :     if (rDCEvt.GetType() == DATACHANGED_SETTINGS)
     306             :     {
     307             :         // In the worst-case the colours have changed so
     308             :         // adapt myself to the new colours
     309           0 :         const StyleSettings&  aSystemStyle = Application::GetSettings().GetStyleSettings();
     310           0 :         SetBackground(Wallpaper(Color(aSystemStyle.GetFaceColor())));
     311           0 :         SetTextColor(aSystemStyle.GetButtonTextColor());
     312             :     }
     313           0 : }
     314             : //------------------------------------------------------------------------------
     315           0 : void OTableWindow::Paint( const Rectangle& rRect )
     316             : {
     317           0 :     Rectangle aRect( Point(0,0), GetOutputSizePixel() );
     318           0 :     Window::Paint( rRect );
     319           0 :     Draw3DBorder( aRect );
     320           0 : }
     321             : 
     322             : //------------------------------------------------------------------------------
     323           0 : void OTableWindow::Draw3DBorder(const Rectangle& rRect)
     324             : {
     325             :     // Use the System Style-Settings for my colours
     326           0 :     const StyleSettings& aSystemStyle = Application::GetSettings().GetStyleSettings();
     327             : 
     328             :     // Black lines for bottom and right
     329           0 :     SetLineColor(aSystemStyle.GetDarkShadowColor());
     330           0 :     DrawLine( rRect.BottomLeft(), rRect.BottomRight() );
     331           0 :     DrawLine( rRect.BottomRight(), rRect.TopRight() );
     332             : 
     333             :     // Dark grey lines over the black lines
     334           0 :     SetLineColor(aSystemStyle.GetShadowColor());
     335           0 :     Point aEHvector(1,1);
     336           0 :     DrawLine( rRect.BottomLeft()+Point(1,-1), rRect.BottomRight() - aEHvector );
     337           0 :     DrawLine( rRect.BottomRight() - aEHvector, rRect.TopRight()+Point(-1,1) );
     338             : 
     339             :     // Light grey lines for top and left
     340           0 :     SetLineColor(aSystemStyle.GetLightColor());
     341           0 :     DrawLine( rRect.BottomLeft()+Point(1,-2), rRect.TopLeft() + aEHvector );
     342           0 :     DrawLine( rRect.TopLeft() + aEHvector, rRect.TopRight()+Point(-2,1) );
     343           0 : }
     344             : // -----------------------------------------------------------------------------
     345           0 : Rectangle OTableWindow::getSizingRect(const Point& _rPos,const Size& _rOutputSize) const
     346             : {
     347           0 :     Rectangle aSizingRect = Rectangle( GetPosPixel(), GetSizePixel() );
     348           0 :     sal_uInt16 nSizingFlags = GetSizingFlags();
     349             : 
     350           0 :     if( nSizingFlags & SIZING_TOP )
     351             :     {
     352           0 :         if( _rPos.Y() < 0 )
     353           0 :             aSizingRect.Top() = 0;
     354             :         else
     355           0 :             aSizingRect.Top() = _rPos.Y();
     356             :     }
     357             : 
     358           0 :     if( nSizingFlags & SIZING_BOTTOM )
     359             :     {
     360           0 :         if( _rPos.Y() > _rOutputSize.Height() )
     361           0 :             aSizingRect.Bottom() = _rOutputSize.Height();
     362             :         else
     363           0 :             aSizingRect.Bottom() = _rPos.Y();
     364             :     }
     365             : 
     366             : 
     367           0 :     if( nSizingFlags & SIZING_RIGHT )
     368             :     {
     369           0 :         if( _rPos.X() > _rOutputSize.Width() )
     370           0 :             aSizingRect.Right() = _rOutputSize.Width();
     371             :         else
     372           0 :             aSizingRect.Right() = _rPos.X();
     373             :     }
     374             : 
     375           0 :     if( nSizingFlags & SIZING_LEFT )
     376             :     {
     377           0 :         if( _rPos.X() < 0 )
     378           0 :             aSizingRect.Left() = 0;
     379             :         else
     380           0 :             aSizingRect.Left() = _rPos.X();
     381             :     }
     382           0 :     return aSizingRect;
     383             : }
     384             : // -----------------------------------------------------------------------------
     385           0 : void OTableWindow::setSizingFlag(const Point& _rPos)
     386             : {
     387           0 :     Size    aOutSize = GetOutputSizePixel();
     388             :     //////////////////////////////////////////////////////////////////////
     389             :     // Set the flags when the mouse cursor is in the sizing area
     390           0 :     m_nSizingFlags = SIZING_NONE;
     391             : 
     392           0 :     if( _rPos.X() < TABWIN_SIZING_AREA )
     393           0 :         m_nSizingFlags |= SIZING_LEFT;
     394             : 
     395           0 :     if( _rPos.Y() < TABWIN_SIZING_AREA )
     396           0 :         m_nSizingFlags |= SIZING_TOP;
     397             : 
     398           0 :     if( _rPos.X() > aOutSize.Width()-TABWIN_SIZING_AREA )
     399           0 :         m_nSizingFlags |= SIZING_RIGHT;
     400             : 
     401           0 :     if( _rPos.Y() > aOutSize.Height()-TABWIN_SIZING_AREA )
     402           0 :         m_nSizingFlags |= SIZING_BOTTOM;
     403           0 : }
     404             : //------------------------------------------------------------------------------
     405           0 : void OTableWindow::MouseMove( const MouseEvent& rEvt )
     406             : {
     407           0 :     Window::MouseMove(rEvt);
     408             : 
     409           0 :     OJoinTableView* pCont = getTableView();
     410           0 :     if (pCont->getDesignView()->getController().isReadOnly())
     411           0 :         return;
     412             : 
     413           0 :     Point   aPos = rEvt.GetPosPixel();
     414           0 :     setSizingFlag(aPos);
     415           0 :     Pointer aPointer;
     416             : 
     417             : 
     418             :     //////////////////////////////////////////////////////////////////////
     419             :     // Set the mouse cursor when it is in the sizing area
     420           0 :     switch( m_nSizingFlags )
     421             :     {
     422             :     case SIZING_TOP:
     423             :     case SIZING_BOTTOM:
     424           0 :         aPointer = Pointer( POINTER_SSIZE );
     425           0 :         break;
     426             : 
     427             :     case SIZING_LEFT:
     428             :     case SIZING_RIGHT:
     429           0 :         aPointer = Pointer( POINTER_ESIZE );
     430           0 :         break;
     431             : 
     432             :     case SIZING_LEFT+SIZING_TOP:
     433             :     case SIZING_RIGHT+SIZING_BOTTOM:
     434           0 :         aPointer = Pointer( POINTER_SESIZE );
     435           0 :         break;
     436             : 
     437             :     case SIZING_RIGHT+SIZING_TOP:
     438             :     case SIZING_LEFT+SIZING_BOTTOM:
     439           0 :         aPointer = Pointer( POINTER_NESIZE );
     440           0 :         break;
     441             :     }
     442             : 
     443           0 :     SetPointer( aPointer );
     444             : }
     445             : 
     446             : //------------------------------------------------------------------------------
     447           0 : void OTableWindow::MouseButtonDown( const MouseEvent& rEvt )
     448             : {
     449             :     //////////////////////////////////////////////////////////////////////
     450             :     // When resizing, the parent must be informed that
     451             :     // the window size of its child has changed
     452           0 :     if( m_nSizingFlags )
     453           0 :         getTableView()->BeginChildSizing( this, GetPointer() );
     454             : 
     455           0 :     Window::MouseButtonDown( rEvt );
     456           0 : }
     457             : 
     458             : 
     459             : 
     460             : //------------------------------------------------------------------------------
     461           0 : void OTableWindow::Resize()
     462             : {
     463             :     //////////////////////////////////////////////////////////////////////
     464             :     // The window must not disappear so we enforce a minimum size
     465           0 :     Size    aOutSize = GetOutputSizePixel();
     466           0 :     aOutSize = Size(CalcZoom(aOutSize.Width()),CalcZoom(aOutSize.Height()));
     467             : 
     468           0 :     long nTitleHeight = CalcZoom( GetTextHeight() )+ CalcZoom( 4 );
     469             : 
     470             :     //////////////////////////////////////////////////////////////////////
     471             :     // Set the title and ListBox
     472           0 :     long n5Pos = CalcZoom(5);
     473           0 :     long nPositionX = n5Pos;
     474           0 :     long nPositionY = n5Pos;
     475             : 
     476             :     // position the image which indicates the type
     477           0 :     m_aTypeImage.SetPosPixel( Point( nPositionX, nPositionY ) );
     478           0 :     Size aImageSize( m_aTypeImage.GetImage().GetSizePixel() );
     479           0 :     m_aTypeImage.SetSizePixel( aImageSize );
     480             : 
     481           0 :     if ( nTitleHeight < aImageSize.Height() )
     482           0 :         nTitleHeight = aImageSize.Height();
     483             : 
     484           0 :     nPositionX += aImageSize.Width() + CalcZoom( 2 );
     485           0 :     m_aTitle.SetPosSizePixel( Point( nPositionX, nPositionY ), Size( aOutSize.Width() - nPositionX - n5Pos, nTitleHeight ) );
     486             : 
     487           0 :     long nTitleToList = CalcZoom( 3 );
     488             : 
     489             :     m_pListBox->SetPosSizePixel(
     490           0 :         Point( n5Pos, nPositionY + nTitleHeight + nTitleToList ),
     491           0 :         Size( aOutSize.Width() - 2 * n5Pos, aOutSize.Height() - ( nPositionY + nTitleHeight + nTitleToList ) - n5Pos )
     492           0 :     );
     493             : 
     494           0 :     Window::Invalidate();
     495           0 : }
     496             : 
     497             : //------------------------------------------------------------------------------
     498           0 : void OTableWindow::SetBoldTitle( sal_Bool bBold )
     499             : {
     500           0 :     Font aFont = m_aTitle.GetFont();
     501           0 :     aFont.SetWeight( bBold?WEIGHT_BOLD:WEIGHT_NORMAL );
     502           0 :     m_aTitle.SetFont( aFont );
     503           0 :     m_aTitle.Invalidate();
     504           0 : }
     505             : 
     506             : //------------------------------------------------------------------------------
     507           0 : void OTableWindow::GetFocus()
     508             : {
     509           0 :     Window::GetFocus();
     510             :     // we have to forward the focus to our listbox to enable keystokes
     511           0 :     if(m_pListBox)
     512           0 :         m_pListBox->GrabFocus();
     513           0 : }
     514             : // -----------------------------------------------------------------------------
     515           0 : void OTableWindow::setActive(sal_Bool _bActive)
     516             : {
     517           0 :     SetBoldTitle( _bActive );
     518           0 :     m_bActive = _bActive;
     519           0 :     if (!_bActive && m_pListBox && m_pListBox->GetSelectionCount() != 0)
     520           0 :         m_pListBox->SelectAll(sal_False);
     521           0 : }
     522             : 
     523             : //------------------------------------------------------------------------------
     524           0 : void OTableWindow::Remove()
     525             : {
     526             :     //////////////////////////////////////////////////////////////////
     527             :     // Delete the window
     528           0 :     OJoinTableView* pTabWinCont = getTableView();
     529           0 :     pTabWinCont->RemoveTabWin( this );
     530           0 :     pTabWinCont->Invalidate();
     531           0 : }
     532             : //------------------------------------------------------------------------------
     533           0 : sal_Bool OTableWindow::HandleKeyInput( const KeyEvent& rEvt )
     534             : {
     535           0 :     const KeyCode& rCode = rEvt.GetKeyCode();
     536           0 :     sal_uInt16 nCode = rCode.GetCode();
     537           0 :     sal_Bool   bShift = rCode.IsShift();
     538           0 :     sal_Bool   bCtrl = rCode.IsMod1();
     539             : 
     540           0 :     sal_Bool bHandle = sal_False;
     541             : 
     542           0 :     if( !bCtrl && !bShift && (nCode==KEY_DELETE) )
     543             :     {
     544           0 :         Remove();
     545           0 :         bHandle = sal_True;
     546             :     }
     547           0 :     return bHandle;
     548             : }
     549             : 
     550             : //------------------------------------------------------------------------------
     551           0 : sal_Bool OTableWindow::ExistsAConn() const
     552             : {
     553           0 :     return getTableView()->ExistsAConn(this);
     554             : }
     555             : //------------------------------------------------------------------------------
     556           0 : void OTableWindow::EnumValidFields(::std::vector< OUString>& arrstrFields)
     557             : {
     558           0 :     arrstrFields.clear();
     559             :     // This default implementation counts every item in the ListBox ... for any other behaviour it must be over-written
     560           0 :     if ( m_pListBox )
     561             :     {
     562           0 :         arrstrFields.reserve(m_pListBox->GetEntryCount());
     563           0 :         SvTreeListEntry* pEntryLoop = m_pListBox->First();
     564           0 :         while (pEntryLoop)
     565             :         {
     566           0 :             arrstrFields.push_back(m_pListBox->GetEntryText(pEntryLoop));
     567           0 :             pEntryLoop = m_pListBox->Next(pEntryLoop);
     568             :         }
     569             :     }
     570           0 : }
     571             : // -----------------------------------------------------------------------------
     572           0 : void OTableWindow::StateChanged( StateChangedType nType )
     573             : {
     574           0 :     Window::StateChanged( nType );
     575             : 
     576           0 :     if ( nType == STATE_CHANGE_ZOOM )
     577             :     {
     578           0 :         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     579             : 
     580           0 :         Font aFont = rStyleSettings.GetGroupFont();
     581           0 :         if ( IsControlFont() )
     582           0 :             aFont.Merge( GetControlFont() );
     583           0 :         SetZoomedPointFont( aFont );
     584             : 
     585           0 :         m_aTitle.SetZoom(GetZoom());
     586           0 :         m_pListBox->SetZoom(GetZoom());
     587           0 :         Resize();
     588           0 :         Invalidate();
     589             :     }
     590           0 : }
     591             : // -----------------------------------------------------------------------------
     592           0 : Reference< XAccessible > OTableWindow::CreateAccessible()
     593             : {
     594           0 :     OTableWindowAccess* pAccessible = new OTableWindowAccess(this);
     595           0 :     m_pAccessible = pAccessible;
     596           0 :     return pAccessible;
     597             : }
     598             : // -----------------------------------------------------------------------------
     599           0 : void OTableWindow::Command(const CommandEvent& rEvt)
     600             : {
     601           0 :     switch (rEvt.GetCommand())
     602             :     {
     603             :         case COMMAND_CONTEXTMENU:
     604             :         {
     605           0 :             OJoinController& rController = getDesignView()->getController();
     606           0 :             if(!rController.isReadOnly() && rController.isConnected())
     607             :             {
     608           0 :                 Point ptWhere;
     609           0 :                 if ( rEvt.IsMouseEvent() )
     610           0 :                     ptWhere = rEvt.GetMousePosPixel();
     611             :                 else
     612             :                 {
     613           0 :                     SvTreeListEntry* pCurrent = m_pListBox->GetCurEntry();
     614           0 :                     if ( pCurrent )
     615           0 :                         ptWhere = m_pListBox->GetEntryPosition(pCurrent);
     616             :                     else
     617           0 :                         ptWhere = m_aTitle.GetPosPixel();
     618             :                 }
     619             : 
     620           0 :                 PopupMenu aContextMenu(ModuleRes(RID_MENU_JOINVIEW_TABLE));
     621           0 :                 switch (aContextMenu.Execute(this, ptWhere))
     622             :                 {
     623             :                     case SID_DELETE:
     624           0 :                         Remove();
     625           0 :                         break;
     626           0 :                 }
     627             :             }
     628           0 :             break;
     629             :         }
     630             :         default:
     631           0 :             Window::Command(rEvt);
     632             :     }
     633           0 : }
     634             : // -----------------------------------------------------------------------------
     635           0 : long OTableWindow::PreNotify(NotifyEvent& rNEvt)
     636             : {
     637           0 :     sal_Bool bHandled = sal_False;
     638           0 :     switch (rNEvt.GetType())
     639             :     {
     640             :         case EVENT_KEYINPUT:
     641             :         {
     642           0 :             if ( getDesignView()->getController().isReadOnly() )
     643           0 :                 break;
     644             : 
     645           0 :             const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
     646           0 :             const KeyCode& rCode = pKeyEvent->GetKeyCode();
     647           0 :             if ( rCode.IsMod1() )
     648             :             {
     649           0 :                 Point aStartPoint = GetPosPixel();
     650           0 :                 if ( rCode.IsShift() )
     651             :                 {
     652           0 :                     aStartPoint.X() = GetSizePixel().Width();
     653           0 :                     aStartPoint.Y() = GetSizePixel().Height();
     654             :                 }
     655             : 
     656           0 :                 switch( rCode.GetCode() )
     657             :                 {
     658             :                     case KEY_DOWN:
     659           0 :                         bHandled = sal_True;
     660           0 :                         aStartPoint.Y() += m_nMoveIncrement;
     661           0 :                         break;
     662             :                     case KEY_UP:
     663           0 :                         bHandled = sal_True;
     664           0 :                         aStartPoint.Y() += -m_nMoveIncrement;
     665           0 :                         break;
     666             :                     case KEY_LEFT:
     667           0 :                         bHandled = sal_True;
     668           0 :                         aStartPoint.X() += -m_nMoveIncrement;
     669           0 :                         break;
     670             :                     case KEY_RIGHT:
     671           0 :                         bHandled = sal_True;
     672           0 :                         aStartPoint.X()  += m_nMoveIncrement;
     673           0 :                         break;
     674             :                 }
     675           0 :                 if ( bHandled )
     676             :                 {
     677           0 :                     if ( rCode.IsShift() )
     678             :                     {
     679           0 :                         OJoinTableView* pView = getTableView();
     680           0 :                         Point ptOld = GetPosPixel();
     681           0 :                         Size aSize = pView->getRealOutputSize();
     682           0 :                         Size aNewSize(aStartPoint.X(),aStartPoint.Y());
     683           0 :                         if (   ((ptOld.X() + aNewSize.Width())  <= aSize.Width())
     684           0 :                             && ((ptOld.Y() + aNewSize.Height()) <= aSize.Height()) )
     685             :                         {
     686           0 :                             if ( aNewSize.Width() < TABWIN_WIDTH_MIN )
     687           0 :                                 aNewSize.Width() = TABWIN_WIDTH_MIN;
     688           0 :                             if ( aNewSize.Height() < TABWIN_HEIGHT_MIN )
     689           0 :                                 aNewSize.Height() = TABWIN_HEIGHT_MIN;
     690             : 
     691           0 :                             Size szOld = GetSizePixel();
     692             : 
     693           0 :                             aNewSize = Size(pView->CalcZoom(aNewSize.Width()),pView->CalcZoom(aNewSize.Height()));
     694           0 :                             SetPosSizePixel( ptOld, aNewSize );
     695           0 :                             pView->TabWinSized(this, ptOld, szOld);
     696           0 :                             Invalidate( INVALIDATE_NOCHILDREN );
     697             :                         }
     698             :                     }
     699             :                     else
     700             :                     {
     701             :                         // remember how often the user moved our window
     702           0 :                         ++m_nMoveCount;
     703           0 :                         if( m_nMoveCount == 5 )
     704           0 :                             m_nMoveIncrement = 10;
     705           0 :                         else if( m_nMoveCount > 15 )
     706           0 :                             m_nMoveCount = m_nMoveIncrement = 20;
     707             : 
     708           0 :                         Point aOldDataPoint = GetData()->GetPosition();
     709           0 :                         Point aNewDataPoint = aStartPoint + getTableView()->GetScrollOffset();
     710           0 :                         if ( aNewDataPoint.X() > -1 && aNewDataPoint.Y() > -1 )
     711             :                         {
     712           0 :                             OJoinTableView* pView = getTableView();
     713           0 :                             if ( pView->isMovementAllowed(aNewDataPoint, GetData()->GetSize()) )
     714             :                             {
     715           0 :                                 SetPosPixel(aStartPoint);
     716             : 
     717             :                                 // aNewDataPoint can not be used here because SetPosPixel reset it
     718           0 :                                 pView->EnsureVisible(GetData()->GetPosition(), GetData()->GetSize());
     719           0 :                                 pView->TabWinMoved(this,aOldDataPoint);
     720           0 :                                 Invalidate(INVALIDATE_NOCHILDREN);
     721           0 :                                 getDesignView()->getController().setModified( sal_True );
     722             :                             }
     723             :                             else
     724             :                             {
     725           0 :                                 m_nMoveCount        = 0; // reset our movement count
     726           0 :                                 m_nMoveIncrement    = 1;
     727             :                             }
     728             :                         }
     729             :                         else
     730             :                         {
     731           0 :                             m_nMoveCount        = 0; // reset our movement count
     732           0 :                             m_nMoveIncrement    = 1;
     733             :                         }
     734             :                     }
     735           0 :                     resetSizingFlag();
     736             :                 }
     737             :                 else
     738             :                 {
     739           0 :                     m_nMoveCount        = 0; // reset our movement count
     740           0 :                     m_nMoveIncrement    = 1;
     741             :                 }
     742             :             }
     743             :             else
     744             :             {
     745           0 :                 m_nMoveCount        = 0; // reset our movement count
     746           0 :                 m_nMoveIncrement    = 1;
     747             :             }
     748             :         }
     749           0 :             break;
     750             :         case EVENT_KEYUP:
     751             :         {
     752           0 :             const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
     753           0 :             const KeyCode& rCode = pKeyEvent->GetKeyCode();
     754           0 :             sal_uInt16 nKeyCode = rCode.GetCode();
     755           0 :             if ( rCode.IsMod2() && nKeyCode != KEY_UP && nKeyCode != KEY_DOWN && nKeyCode != KEY_LEFT && nKeyCode != KEY_RIGHT )
     756             :             {
     757           0 :                 m_nMoveCount        = 0; // reset our movement count
     758           0 :                 m_nMoveIncrement    = 1;
     759             :             }
     760             :         }
     761           0 :             break;
     762             :     }
     763           0 :     if (!bHandled)
     764           0 :         return Window::PreNotify(rNEvt);
     765           0 :     return 1L;
     766             : }
     767             : // -----------------------------------------------------------------------------
     768           0 : String OTableWindow::getTitle() const
     769             : {
     770           0 :     return m_aTitle.GetText();
     771             : }
     772             : // -----------------------------------------------------------------------------
     773           0 : void OTableWindow::_elementInserted( const container::ContainerEvent& /*_rEvent*/ )  throw(::com::sun::star::uno::RuntimeException)
     774             : {
     775           0 :     FillListBox();
     776           0 : }
     777             : // -----------------------------------------------------------------------------
     778           0 : void OTableWindow::_elementRemoved( const container::ContainerEvent& /*_rEvent*/ ) throw(::com::sun::star::uno::RuntimeException)
     779             : {
     780           0 :     FillListBox();
     781           0 : }
     782             : // -----------------------------------------------------------------------------
     783           0 : void OTableWindow::_elementReplaced( const container::ContainerEvent& /*_rEvent*/ ) throw(::com::sun::star::uno::RuntimeException)
     784             : {
     785           0 :     FillListBox();
     786          12 : }
     787             : // -----------------------------------------------------------------------------
     788             : 
     789             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10