LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/ui/browser - brwview.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 121 166 72.9 %
Date: 2013-07-09 Functions: 18 21 85.7 %
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             : 
      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           1 : UnoDataBrowserView::UnoDataBrowserView( Window* pParent,
      74             :                                         IController& _rController,
      75             :                                         const Reference< ::com::sun::star::uno::XComponentContext >& _rxContext)
      76             :     :ODataView(pParent,_rController,_rxContext)
      77             :     ,m_pTreeView(NULL)
      78             :     ,m_pSplitter(NULL)
      79             :     ,m_pVclControl(NULL)
      80           1 :     ,m_pStatus(NULL)
      81             : {
      82             :     DBG_CTOR(UnoDataBrowserView,NULL);
      83             : 
      84           1 : }
      85             : // -------------------------------------------------------------------------
      86           1 : void UnoDataBrowserView::Construct(const Reference< ::com::sun::star::awt::XControlModel >& xModel)
      87             : {
      88             :     try
      89             :     {
      90           1 :         ODataView::Construct();
      91             : 
      92             :         // our UNO representation
      93           1 :         m_xMe = VCLUnoHelper::CreateControlContainer(this);
      94             : 
      95             :         // create the (UNO-) control
      96           1 :         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           1 :         m_xGrid->setDesignMode(sal_True);
     100             : 
     101           1 :         Reference< ::com::sun::star::awt::XWindow >  xGridWindow(m_xGrid, UNO_QUERY);
     102           1 :         xGridWindow->setVisible(sal_True);
     103           1 :         xGridWindow->setEnable(sal_True);
     104             : 
     105             :         // introduce the model to the grid
     106           1 :         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           1 :         getContainer()->addControl(::comphelper::getString(xModelSet->getPropertyValue(PROPERTY_NAME)), m_xGrid);
     110             : 
     111             :         // get the VCL-control
     112           1 :         m_pVclControl = NULL;
     113           1 :         getVclControl();
     114             : 
     115           1 :         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           1 : }
     123             : // -------------------------------------------------------------------------
     124           3 : UnoDataBrowserView::~UnoDataBrowserView()
     125             : {
     126             :     {
     127           1 :         ::std::auto_ptr<Splitter> aTemp(m_pSplitter);
     128           1 :         m_pSplitter = NULL;
     129             :     }
     130           1 :     setTreeView(NULL);
     131             : 
     132           1 :     if ( m_pStatus )
     133             :     {
     134           1 :         delete m_pStatus;
     135           1 :         m_pStatus = NULL;
     136             :     }
     137             : 
     138             :     try
     139             :     {
     140           1 :         ::comphelper::disposeComponent(m_xGrid);
     141           1 :         ::comphelper::disposeComponent(m_xMe);
     142             :     }
     143           0 :     catch(const Exception&)
     144             :     {}
     145             : 
     146             :     DBG_DTOR(UnoDataBrowserView,NULL);
     147           2 : }
     148             : // -----------------------------------------------------------------------------
     149           2 : IMPL_LINK( UnoDataBrowserView, SplitHdl, void*, /*NOINTERESTEDIN*/ )
     150             : {
     151           1 :     long nYPos = m_pSplitter->GetPosPixel().Y();
     152           1 :     m_pSplitter->SetPosPixel( Point( m_pSplitter->GetSplitPosPixel(), nYPos ) );
     153           1 :     Resize();
     154             : 
     155           1 :     return 0L;
     156             : }
     157             : // -------------------------------------------------------------------------
     158           1 : void UnoDataBrowserView::setSplitter(Splitter* _pSplitter)
     159             : {
     160           1 :     m_pSplitter = _pSplitter;
     161           1 :     m_pSplitter->SetSplitHdl( LINK( this, UnoDataBrowserView, SplitHdl ) );
     162           1 :     LINK( this, UnoDataBrowserView, SplitHdl ).Call(m_pSplitter);
     163           1 : }
     164             : // -------------------------------------------------------------------------
     165           3 : void UnoDataBrowserView::setTreeView(DBTreeView* _pTreeView)
     166             : {
     167           3 :     if (m_pTreeView != _pTreeView)
     168             :     {
     169           2 :         if (m_pTreeView)
     170             :         {
     171           1 :             ::std::auto_ptr<Window> aTemp(m_pTreeView);
     172           1 :             m_pTreeView = NULL;
     173             :         }
     174           2 :         m_pTreeView = _pTreeView;
     175             :     }
     176           3 : }
     177             : // -------------------------------------------------------------------------
     178           4 : void UnoDataBrowserView::showStatus( const OUString& _rStatus )
     179             : {
     180           4 :     if (_rStatus.isEmpty())
     181           2 :         hideStatus();
     182             :     else
     183             :     {
     184           2 :         if (!m_pStatus)
     185           1 :             m_pStatus = new FixedText(this);
     186           2 :         m_pStatus->SetText(_rStatus);
     187           2 :         m_pStatus->Show();
     188           2 :         Resize();
     189           2 :         Update();
     190             :     }
     191           4 : }
     192             : 
     193             : // -------------------------------------------------------------------------
     194           2 : void UnoDataBrowserView::hideStatus()
     195             : {
     196           2 :     if (!m_pStatus || !m_pStatus->IsVisible())
     197             :         // nothing to do
     198           2 :         return;
     199           2 :     m_pStatus->Hide();
     200           2 :     Resize();
     201           2 :     Update();
     202             : }
     203             : 
     204             : // -------------------------------------------------------------------------
     205           9 : void UnoDataBrowserView::resizeDocumentView(Rectangle& _rPlayground)
     206             : {
     207           9 :     Point   aSplitPos;
     208           9 :     Size    aSplitSize;
     209           9 :     Point   aPlaygroundPos( _rPlayground.TopLeft() );
     210           9 :     Size    aPlaygroundSize( _rPlayground.GetSize() );
     211             : 
     212           9 :     if (m_pTreeView && m_pTreeView->IsVisible() && m_pSplitter)
     213             :     {
     214             :         // calculate the splitter pos and size
     215           7 :         aSplitPos   = m_pSplitter->GetPosPixel();
     216           7 :         aSplitPos.Y() = aPlaygroundPos.Y();
     217           7 :         aSplitSize  = m_pSplitter->GetOutputSizePixel();
     218           7 :         aSplitSize.Height() = aPlaygroundSize.Height();
     219             : 
     220           7 :         if( ( aSplitPos.X() + aSplitSize.Width() ) > ( aPlaygroundSize.Width() ))
     221           1 :             aSplitPos.X() = aPlaygroundSize.Width() - aSplitSize.Width();
     222             : 
     223           7 :         if( aSplitPos.X() <= aPlaygroundPos.X() )
     224           2 :             aSplitPos.X() = aPlaygroundPos.X() + sal_Int32(aPlaygroundSize.Width() * 0.2);
     225             : 
     226             :         // the tree pos and size
     227           7 :         Point   aTreeViewPos( aPlaygroundPos );
     228           7 :         Size    aTreeViewSize( aSplitPos.X(), aPlaygroundSize.Height() );
     229             : 
     230             :         // the status pos and size
     231           7 :         if (m_pStatus && m_pStatus->IsVisible())
     232             :         {
     233           2 :             Size aStatusSize(aPlaygroundPos.X(), GetTextHeight() + 2);
     234           2 :             aStatusSize = LogicToPixel(aStatusSize, MAP_APPFONT);
     235           2 :             aStatusSize.Width() = aTreeViewSize.Width() - 2 - 2;
     236             : 
     237           2 :             Point aStatusPos( aPlaygroundPos.X() + 2, aTreeViewPos.Y() + aTreeViewSize.Height() - aStatusSize.Height() );
     238           2 :             m_pStatus->SetPosSizePixel( aStatusPos, aStatusSize );
     239           2 :             aTreeViewSize.Height() -= aStatusSize.Height();
     240             :         }
     241             : 
     242             :         // set the size of treelistbox
     243           7 :         m_pTreeView->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
     244             : 
     245             :         //set the size of the splitter
     246           7 :         m_pSplitter->SetPosSizePixel( aSplitPos, Size( aSplitSize.Width(), aPlaygroundSize.Height() ) );
     247           7 :         m_pSplitter->SetDragRectPixel( _rPlayground );
     248             :     }
     249             : 
     250             :     // set the size of grid control
     251           9 :     Reference< ::com::sun::star::awt::XWindow >  xGridAsWindow(m_xGrid, UNO_QUERY);
     252           9 :     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           9 :     _rPlayground.SetPos( _rPlayground.BottomRight() );
     258           9 :     _rPlayground.SetSize( Size( 0, 0 ) );
     259           9 : }
     260             : 
     261             : //------------------------------------------------------------------
     262          12 : sal_uInt16 UnoDataBrowserView::View2ModelPos(sal_uInt16 nPos) const
     263             : {
     264          12 :     return m_pVclControl ? m_pVclControl->GetModelColumnPos(m_pVclControl->GetColumnIdFromViewPos(nPos)) : -1;
     265             : }
     266             : 
     267             : // -----------------------------------------------------------------------------
     268         378 : SbaGridControl* UnoDataBrowserView::getVclControl() const
     269             : {
     270         378 :     if ( !m_pVclControl )
     271             :     {
     272             :         OSL_ENSURE(m_xGrid.is(),"Grid not set!");
     273           1 :         if ( m_xGrid.is() )
     274             :         {
     275           1 :             Reference< ::com::sun::star::awt::XWindowPeer >  xPeer = m_xGrid->getPeer();
     276           1 :             if ( xPeer.is() )
     277             :             {
     278           1 :                 SbaXGridPeer* pPeer = SbaXGridPeer::getImplementation(xPeer);
     279           1 :                 UnoDataBrowserView* pTHIS = const_cast<UnoDataBrowserView*>(this);
     280           1 :                 if ( pPeer )
     281             :                 {
     282           1 :                     m_pVclControl = static_cast<SbaGridControl*>(pPeer->GetWindow());
     283           1 :                     pTHIS->startComponentListening(Reference<XComponent>(VCLUnoHelper::GetInterface(m_pVclControl),UNO_QUERY));
     284             :                 }
     285           1 :             }
     286             :         }
     287             :     }
     288         378 :     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           1 : void UnoDataBrowserView::_disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ )
     311             : {
     312           1 :     stopComponentListening(Reference<XComponent>(VCLUnoHelper::GetInterface(m_pVclControl),UNO_QUERY));
     313           1 :     m_pVclControl = NULL;
     314           1 : }
     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           2 : BrowserViewStatusDisplay::BrowserViewStatusDisplay( UnoDataBrowserView* _pView, const OUString& _rStatus )
     345           2 :     :m_pView(_pView)
     346             : {
     347             :     DBG_CTOR(BrowserViewStatusDisplay,NULL);
     348             : 
     349           2 :     if (m_pView)
     350           2 :         m_pView->showStatus(_rStatus);
     351           2 : }
     352             : 
     353             : // -----------------------------------------------------------------------------
     354           2 : BrowserViewStatusDisplay::~BrowserViewStatusDisplay( )
     355             : {
     356           2 :     if (m_pView)
     357           2 :         m_pView->showStatus(OUString());
     358             : 
     359             :     DBG_DTOR(BrowserViewStatusDisplay,NULL);
     360          14 : }
     361             : // -----------------------------------------------------------------------------
     362             : 
     363             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10