LCOV - code coverage report
Current view: top level - dbaccess/source/ui/browser - brwview.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 121 166 72.9 %
Date: 2012-08-25 Functions: 16 19 84.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 101 292 34.6 %

           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                 :            : 
      21                 :            : #include "brwctrlr.hxx"
      22                 :            : #include "brwview.hxx"
      23                 :            : #include "sbagrid.hxx"
      24                 :            : #include <toolkit/helper/vclunohelper.hxx>
      25                 :            : #include <comphelper/types.hxx>
      26                 :            : #include <vcl/split.hxx>
      27                 :            : #include "dbtreeview.hxx"
      28                 :            : #include "dbustrings.hrc"
      29                 :            : #include "dbu_brw.hrc"
      30                 :            : #include <com/sun/star/form/XLoadable.hpp>
      31                 :            : #include <com/sun/star/awt/XControlContainer.hpp>
      32                 :            : #include "UITools.hxx"
      33                 :            : #include <osl/diagnose.h>
      34                 :            : 
      35                 :            : 
      36                 :            : using namespace dbaui;
      37                 :            : using namespace ::com::sun::star::uno;
      38                 :            : using namespace ::com::sun::star::sdb;
      39                 :            : using namespace ::com::sun::star::form;
      40                 :            : using namespace ::com::sun::star::beans;
      41                 :            : using namespace ::com::sun::star::container;
      42                 :            : using namespace ::com::sun::star::lang;
      43                 :            : 
      44                 :            : 
      45                 :            : namespace
      46                 :            : {
      47                 :          0 :     sal_Bool isGrabVclControlFocusAllowed(const UnoDataBrowserView* _pView)
      48                 :            :     {
      49                 :          0 :         sal_Bool bGrabFocus = sal_False;
      50         [ #  # ]:          0 :         SbaGridControl* pVclControl = _pView->getVclControl();
      51         [ #  # ]:          0 :         Reference< ::com::sun::star::awt::XControl > xGrid = _pView->getGridControl();
      52 [ #  # ][ #  # ]:          0 :         if (pVclControl && xGrid.is())
                 [ #  # ]
      53                 :            :         {
      54                 :          0 :             bGrabFocus = sal_True;
      55 [ #  # ][ #  # ]:          0 :             if(!pVclControl->HasChildPathFocus())
      56                 :            :             {
      57 [ #  # ][ #  # ]:          0 :                 Reference<XChild> xChild(xGrid->getModel(),UNO_QUERY);
                 [ #  # ]
      58                 :          0 :                 Reference<XLoadable> xLoad;
      59         [ #  # ]:          0 :                 if(xChild.is())
      60 [ #  # ][ #  # ]:          0 :                     xLoad.set(xChild->getParent(),UNO_QUERY);
                 [ #  # ]
      61 [ #  # ][ #  # ]:          0 :                 bGrabFocus = xLoad.is() && xLoad->isLoaded();
         [ #  # ][ #  # ]
      62                 :            :             }
      63                 :            :         }
      64                 :          0 :         return bGrabFocus;
      65                 :            :     }
      66                 :            : }
      67                 :            : //==================================================================
      68                 :            : //= UnoDataBrowserView
      69                 :            : //==================================================================
      70                 :            : 
      71                 :            : DBG_NAME(UnoDataBrowserView)
      72                 :            : // -------------------------------------------------------------------------
      73                 :          2 : UnoDataBrowserView::UnoDataBrowserView( Window* pParent,
      74                 :            :                                         IController& _rController,
      75                 :            :                                         const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rFactory)
      76                 :            :     :ODataView(pParent,_rController,_rFactory)
      77                 :            :     ,m_pTreeView(NULL)
      78                 :            :     ,m_pSplitter(NULL)
      79                 :            :     ,m_pVclControl(NULL)
      80         [ +  - ]:          2 :     ,m_pStatus(NULL)
      81                 :            : {
      82                 :            :     DBG_CTOR(UnoDataBrowserView,NULL);
      83                 :            : 
      84                 :          2 : }
      85                 :            : // -------------------------------------------------------------------------
      86                 :          2 : void UnoDataBrowserView::Construct(const Reference< ::com::sun::star::awt::XControlModel >& xModel)
      87                 :            : {
      88                 :            :     try
      89                 :            :     {
      90         [ +  - ]:          2 :         ODataView::Construct();
      91                 :            : 
      92                 :            :         // our UNO representation
      93 [ +  - ][ +  - ]:          2 :         m_xMe = VCLUnoHelper::CreateControlContainer(this);
      94                 :            : 
      95                 :            :         // create the (UNO-) control
      96 [ +  - ][ +  - ]:          2 :         m_xGrid = new SbaXGridControl(getORB());
         [ +  - ][ +  - ]
      97                 :            :         OSL_ENSURE(m_xGrid.is(), "UnoDataBrowserView::Construct : could not create a grid control !");
      98                 :            :         // in design mode (for the moment)
      99 [ +  - ][ +  - ]:          2 :         m_xGrid->setDesignMode(sal_True);
     100                 :            : 
     101         [ +  - ]:          2 :         Reference< ::com::sun::star::awt::XWindow >  xGridWindow(m_xGrid, UNO_QUERY);
     102 [ +  - ][ +  - ]:          2 :         xGridWindow->setVisible(sal_True);
     103 [ +  - ][ +  - ]:          2 :         xGridWindow->setEnable(sal_True);
     104                 :            : 
     105                 :            :         // introduce the model to the grid
     106 [ +  - ][ +  - ]:          2 :         m_xGrid->setModel(xModel);
     107                 :            :         // introduce the container (me) to the grid
     108         [ +  - ]:          2 :         Reference< ::com::sun::star::beans::XPropertySet >  xModelSet(xModel, UNO_QUERY);
     109 [ +  - ][ +  - ]:          2 :         getContainer()->addControl(::comphelper::getString(xModelSet->getPropertyValue(PROPERTY_NAME)), m_xGrid);
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     110                 :            : 
     111                 :            :         // get the VCL-control
     112                 :          2 :         m_pVclControl = NULL;
     113         [ +  - ]:          2 :         getVclControl();
     114                 :            : 
     115                 :          2 :         OSL_ENSURE(m_pVclControl != NULL, "UnoDataBrowserView::Construct : no real grid control !");
     116                 :            :     }
     117         [ #  # ]:          0 :     catch(const Exception&)
     118                 :            :     {
     119         [ #  # ]:          0 :         ::comphelper::disposeComponent(m_xGrid);
     120                 :          0 :         throw;
     121                 :            :     }
     122                 :          2 : }
     123                 :            : // -------------------------------------------------------------------------
     124         [ +  - ]:          2 : UnoDataBrowserView::~UnoDataBrowserView()
     125                 :            : {
     126                 :            :     {
     127                 :          2 :         ::std::auto_ptr<Splitter> aTemp(m_pSplitter);
     128         [ +  - ]:          2 :         m_pSplitter = NULL;
     129                 :            :     }
     130         [ +  - ]:          2 :     setTreeView(NULL);
     131                 :            : 
     132         [ +  - ]:          2 :     if ( m_pStatus )
     133                 :            :     {
     134 [ +  - ][ +  - ]:          2 :         delete m_pStatus;
     135                 :          2 :         m_pStatus = NULL;
     136                 :            :     }
     137                 :            : 
     138                 :            :     try
     139                 :            :     {
     140         [ +  - ]:          2 :         ::comphelper::disposeComponent(m_xGrid);
     141         [ +  - ]:          2 :         ::comphelper::disposeComponent(m_xMe);
     142                 :            :     }
     143         [ #  # ]:          0 :     catch(const Exception&)
     144                 :            :     {}
     145                 :            : 
     146                 :            :     DBG_DTOR(UnoDataBrowserView,NULL);
     147 [ -  + ][ #  # ]:          4 : }
     148                 :            : // -----------------------------------------------------------------------------
     149                 :          2 : IMPL_LINK( UnoDataBrowserView, SplitHdl, void*, /*NOINTERESTEDIN*/ )
     150                 :            : {
     151                 :          2 :     long nYPos = m_pSplitter->GetPosPixel().Y();
     152         [ +  - ]:          2 :     m_pSplitter->SetPosPixel( Point( m_pSplitter->GetSplitPosPixel(), nYPos ) );
     153                 :          2 :     Resize();
     154                 :            : 
     155                 :          2 :     return 0L;
     156                 :            : }
     157                 :            : // -------------------------------------------------------------------------
     158                 :          2 : void UnoDataBrowserView::setSplitter(Splitter* _pSplitter)
     159                 :            : {
     160                 :          2 :     m_pSplitter = _pSplitter;
     161                 :          2 :     m_pSplitter->SetSplitHdl( LINK( this, UnoDataBrowserView, SplitHdl ) );
     162         [ +  - ]:          2 :     LINK( this, UnoDataBrowserView, SplitHdl ).Call(m_pSplitter);
     163                 :          2 : }
     164                 :            : // -------------------------------------------------------------------------
     165                 :          6 : void UnoDataBrowserView::setTreeView(DBTreeView* _pTreeView)
     166                 :            : {
     167         [ +  + ]:          6 :     if (m_pTreeView != _pTreeView)
     168                 :            :     {
     169         [ +  + ]:          4 :         if (m_pTreeView)
     170                 :            :         {
     171                 :          2 :             ::std::auto_ptr<Window> aTemp(m_pTreeView);
     172         [ +  - ]:          2 :             m_pTreeView = NULL;
     173                 :            :         }
     174                 :          4 :         m_pTreeView = _pTreeView;
     175                 :            :     }
     176                 :          6 : }
     177                 :            : // -------------------------------------------------------------------------
     178                 :          8 : void UnoDataBrowserView::showStatus( const String& _rStatus )
     179                 :            : {
     180         [ +  + ]:          8 :     if (0 == _rStatus.Len())
     181                 :          4 :         hideStatus();
     182                 :            :     else
     183                 :            :     {
     184         [ +  + ]:          4 :         if (!m_pStatus)
     185         [ +  - ]:          2 :             m_pStatus = new FixedText(this);
     186                 :          4 :         m_pStatus->SetText(_rStatus);
     187                 :          4 :         m_pStatus->Show();
     188                 :          4 :         Resize();
     189                 :          4 :         Update();
     190                 :            :     }
     191                 :          8 : }
     192                 :            : 
     193                 :            : // -------------------------------------------------------------------------
     194                 :          4 : void UnoDataBrowserView::hideStatus()
     195                 :            : {
     196 [ +  - ][ -  + ]:          4 :     if (!m_pStatus || !m_pStatus->IsVisible())
                 [ -  + ]
     197                 :            :         // nothing to do
     198                 :          4 :         return;
     199                 :          4 :     m_pStatus->Hide();
     200                 :          4 :     Resize();
     201                 :          4 :     Update();
     202                 :            : }
     203                 :            : 
     204                 :            : // -------------------------------------------------------------------------
     205                 :         18 : void UnoDataBrowserView::resizeDocumentView(Rectangle& _rPlayground)
     206                 :            : {
     207                 :         18 :     Point   aSplitPos;
     208                 :         18 :     Size    aSplitSize;
     209                 :         18 :     Point   aPlaygroundPos( _rPlayground.TopLeft() );
     210         [ +  - ]:         18 :     Size    aPlaygroundSize( _rPlayground.GetSize() );
     211                 :            : 
     212 [ +  + ][ +  - ]:         18 :     if (m_pTreeView && m_pTreeView->IsVisible() && m_pSplitter)
         [ +  - ][ +  - ]
                 [ +  + ]
     213                 :            :     {
     214                 :            :         // calculate the splitter pos and size
     215         [ +  - ]:         14 :         aSplitPos   = m_pSplitter->GetPosPixel();
     216                 :         14 :         aSplitPos.Y() = aPlaygroundPos.Y();
     217                 :         14 :         aSplitSize  = m_pSplitter->GetOutputSizePixel();
     218                 :         14 :         aSplitSize.Height() = aPlaygroundSize.Height();
     219                 :            : 
     220         [ +  + ]:         14 :         if( ( aSplitPos.X() + aSplitSize.Width() ) > ( aPlaygroundSize.Width() ))
     221                 :          2 :             aSplitPos.X() = aPlaygroundSize.Width() - aSplitSize.Width();
     222                 :            : 
     223         [ +  + ]:         14 :         if( aSplitPos.X() <= aPlaygroundPos.X() )
     224                 :          4 :             aSplitPos.X() = aPlaygroundPos.X() + sal_Int32(aPlaygroundSize.Width() * 0.2);
     225                 :            : 
     226                 :            :         // the tree pos and size
     227                 :         14 :         Point   aTreeViewPos( aPlaygroundPos );
     228                 :         14 :         Size    aTreeViewSize( aSplitPos.X(), aPlaygroundSize.Height() );
     229                 :            : 
     230                 :            :         // the status pos and size
     231 [ +  - ][ +  + ]:         14 :         if (m_pStatus && m_pStatus->IsVisible())
         [ +  + ][ +  + ]
     232                 :            :         {
     233         [ +  - ]:          4 :             Size aStatusSize(aPlaygroundPos.X(), GetTextHeight() + 2);
     234 [ +  - ][ +  - ]:          4 :             aStatusSize = LogicToPixel(aStatusSize, MAP_APPFONT);
                 [ +  - ]
     235                 :          4 :             aStatusSize.Width() = aTreeViewSize.Width() - 2 - 2;
     236                 :            : 
     237                 :          4 :             Point aStatusPos( aPlaygroundPos.X() + 2, aTreeViewPos.Y() + aTreeViewSize.Height() - aStatusSize.Height() );
     238         [ +  - ]:          4 :             m_pStatus->SetPosSizePixel( aStatusPos, aStatusSize );
     239                 :          4 :             aTreeViewSize.Height() -= aStatusSize.Height();
     240                 :            :         }
     241                 :            : 
     242                 :            :         // set the size of treelistbox
     243         [ +  - ]:         14 :         m_pTreeView->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
     244                 :            : 
     245                 :            :         //set the size of the splitter
     246         [ +  - ]:         14 :         m_pSplitter->SetPosSizePixel( aSplitPos, Size( aSplitSize.Width(), aPlaygroundSize.Height() ) );
     247         [ +  - ]:         14 :         m_pSplitter->SetDragRectPixel( _rPlayground );
     248                 :            :     }
     249                 :            : 
     250                 :            :     // set the size of grid control
     251         [ +  - ]:         18 :     Reference< ::com::sun::star::awt::XWindow >  xGridAsWindow(m_xGrid, UNO_QUERY);
     252         [ +  - ]:         18 :     if (xGridAsWindow.is())
     253         [ +  - ]:         36 :         xGridAsWindow->setPosSize( aSplitPos.X() + aSplitSize.Width(), aPlaygroundPos.Y(),
     254         [ +  - ]:         36 :                                    aPlaygroundSize.Width() - aSplitSize.Width() - aSplitPos.X(), aPlaygroundSize.Height(), ::com::sun::star::awt::PosSize::POSSIZE);
     255                 :            : 
     256                 :            :     // just for completeness: there is no space left, we occupied it all ...
     257         [ +  - ]:         18 :     _rPlayground.SetPos( _rPlayground.BottomRight() );
     258         [ +  - ]:         18 :     _rPlayground.SetSize( Size( 0, 0 ) );
     259                 :         18 : }
     260                 :            : 
     261                 :            : //------------------------------------------------------------------
     262                 :         15 : sal_uInt16 UnoDataBrowserView::View2ModelPos(sal_uInt16 nPos) const
     263                 :            : {
     264         [ +  - ]:         15 :     return m_pVclControl ? m_pVclControl->GetModelColumnPos(m_pVclControl->GetColumnIdFromViewPos(nPos)) : -1;
     265                 :            : }
     266                 :            : 
     267                 :            : // -----------------------------------------------------------------------------
     268                 :        476 : SbaGridControl* UnoDataBrowserView::getVclControl() const
     269                 :            : {
     270         [ +  + ]:        476 :     if ( !m_pVclControl )
     271                 :            :     {
     272                 :            :         OSL_ENSURE(m_xGrid.is(),"Grid not set!");
     273         [ +  - ]:          2 :         if ( m_xGrid.is() )
     274                 :            :         {
     275 [ +  - ][ +  - ]:          2 :             Reference< ::com::sun::star::awt::XWindowPeer >  xPeer = m_xGrid->getPeer();
     276         [ +  - ]:          2 :             if ( xPeer.is() )
     277                 :            :             {
     278         [ +  - ]:          2 :                 SbaXGridPeer* pPeer = SbaXGridPeer::getImplementation(xPeer);
     279                 :          2 :                 UnoDataBrowserView* pTHIS = const_cast<UnoDataBrowserView*>(this);
     280         [ +  - ]:          2 :                 if ( pPeer )
     281                 :            :                 {
     282                 :          2 :                     m_pVclControl = static_cast<SbaGridControl*>(pPeer->GetWindow());
     283 [ +  - ][ +  - ]:          2 :                     pTHIS->startComponentListening(Reference<XComponent>(VCLUnoHelper::GetInterface(m_pVclControl),UNO_QUERY));
                 [ +  - ]
     284                 :            :                 }
     285                 :          2 :             }
     286                 :            :         }
     287                 :            :     }
     288                 :        476 :     return m_pVclControl;
     289                 :            : }
     290                 :            : // -----------------------------------------------------------------------------
     291                 :          0 : void UnoDataBrowserView::GetFocus()
     292                 :            : {
     293                 :          0 :     ODataView::GetFocus();
     294 [ #  # ][ #  # ]:          0 :     if( m_pTreeView && m_pTreeView->IsVisible() && !m_pTreeView->HasChildPathFocus())
         [ #  # ][ #  # ]
     295                 :          0 :         m_pTreeView->GrabFocus();
     296 [ #  # ][ #  # ]:          0 :     else if (m_pVclControl && m_xGrid.is())
                 [ #  # ]
     297                 :            :     {
     298                 :          0 :         sal_Bool bGrabFocus = sal_False;
     299         [ #  # ]:          0 :         if(!m_pVclControl->HasChildPathFocus())
     300                 :            :         {
     301                 :          0 :             bGrabFocus = isGrabVclControlFocusAllowed(this);
     302         [ #  # ]:          0 :             if( bGrabFocus )
     303                 :          0 :                 m_pVclControl->GrabFocus();
     304                 :            :         }
     305 [ #  # ][ #  # ]:          0 :         if(!bGrabFocus && m_pTreeView && m_pTreeView->IsVisible() )
         [ #  # ][ #  # ]
     306                 :          0 :             m_pTreeView->GrabFocus();
     307                 :            :     }
     308                 :          0 : }
     309                 :            : // -----------------------------------------------------------------------------
     310                 :          2 : void UnoDataBrowserView::_disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ )
     311                 :            : {
     312 [ +  - ][ +  - ]:          2 :     stopComponentListening(Reference<XComponent>(VCLUnoHelper::GetInterface(m_pVclControl),UNO_QUERY));
     313                 :          2 :     m_pVclControl = NULL;
     314                 :          2 : }
     315                 :            : // -------------------------------------------------------------------------
     316                 :          0 : long UnoDataBrowserView::PreNotify( NotifyEvent& rNEvt )
     317                 :            : {
     318                 :          0 :     long nDone = 0L;
     319         [ #  # ]:          0 :     if(rNEvt.GetType() == EVENT_KEYINPUT)
     320                 :            :     {
     321                 :          0 :         sal_Bool bGrabAllowed = isGrabVclControlFocusAllowed(this);
     322         [ #  # ]:          0 :         if ( bGrabAllowed )
     323                 :            :         {
     324                 :          0 :             const KeyEvent* pKeyEvt = rNEvt.GetKeyEvent();
     325                 :          0 :             const KeyCode& rKeyCode = pKeyEvt->GetKeyCode();
     326 [ #  # ][ #  # ]:          0 :             if (  ( rKeyCode == KeyCode( KEY_E, sal_True, sal_True, sal_False, sal_False ) )
         [ #  # ][ #  # ]
           [ #  #  #  # ]
                 [ #  # ]
     327 [ #  # ][ #  # ]:          0 :                || ( rKeyCode == KeyCode( KEY_TAB, sal_True, sal_False, sal_False, sal_False ) )
         [ #  # ][ #  # ]
     328                 :            :                )
     329                 :            :             {
     330 [ #  # ][ #  # ]:          0 :                 if ( m_pTreeView && m_pVclControl && m_pTreeView->HasChildPathFocus() )
         [ #  # ][ #  # ]
     331                 :          0 :                     m_pVclControl->GrabFocus();
     332 [ #  # ][ #  # ]:          0 :                 else if ( m_pTreeView && m_pVclControl && m_pVclControl->HasChildPathFocus() )
         [ #  # ][ #  # ]
     333                 :          0 :                     m_pTreeView->GrabFocus();
     334                 :            : 
     335                 :          0 :                 nDone = 1L;
     336                 :            :             }
     337                 :            :         }
     338                 :            :     }
     339         [ #  # ]:          0 :     return nDone ? nDone : ODataView::PreNotify(rNEvt);
     340                 :            : }
     341                 :            : 
     342                 :            : DBG_NAME(BrowserViewStatusDisplay)
     343                 :            : // -----------------------------------------------------------------------------
     344                 :          4 : BrowserViewStatusDisplay::BrowserViewStatusDisplay( UnoDataBrowserView* _pView, const String& _rStatus )
     345                 :          4 :     :m_pView(_pView)
     346                 :            : {
     347                 :            :     DBG_CTOR(BrowserViewStatusDisplay,NULL);
     348                 :            : 
     349         [ +  - ]:          4 :     if (m_pView)
     350                 :          4 :         m_pView->showStatus(_rStatus);
     351                 :          4 : }
     352                 :            : 
     353                 :            : // -----------------------------------------------------------------------------
     354                 :          4 : BrowserViewStatusDisplay::~BrowserViewStatusDisplay( )
     355                 :            : {
     356         [ +  - ]:          4 :     if (m_pView)
     357         [ +  - ]:          4 :         m_pView->showStatus(String());
     358                 :            : 
     359                 :            :     DBG_DTOR(BrowserViewStatusDisplay,NULL);
     360                 :          4 : }
     361                 :            : // -----------------------------------------------------------------------------
     362                 :            : 
     363                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10