LCOV - code coverage report
Current view: top level - dbaccess/source/ui/browser - brwview.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 121 166 72.9 %
Date: 2014-04-11 Functions: 16 19 84.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10