LCOV - code coverage report
Current view: top level - dbaccess/source/ui/querydesign - TableWindow.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 379 0.0 %
Date: 2012-08-25 Functions: 0 39 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 581 0.0 %

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

Generated by: LCOV version 1.10