LCOV - code coverage report
Current view: top level - dbaccess/source/ui/browser - brwview.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 121 166 72.9 %
Date: 2014-11-03 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             : #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 :     bool isGrabVclControlFocusAllowed(const UnoDataBrowserView* _pView)
      46             :     {
      47           0 :         bool bGrabFocus = 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 = 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           2 : UnoDataBrowserView::UnoDataBrowserView( vcl::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           2 :     ,m_pStatus(NULL)
      76             : {
      77             : 
      78           2 : }
      79             : 
      80           2 : void UnoDataBrowserView::Construct(const Reference< ::com::sun::star::awt::XControlModel >& xModel)
      81             : {
      82             :     try
      83             :     {
      84           2 :         ODataView::Construct();
      85             : 
      86             :         // our UNO representation
      87           2 :         m_xMe = VCLUnoHelper::CreateControlContainer(this);
      88             : 
      89             :         // create the (UNO-) control
      90           2 :         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           2 :         m_xGrid->setDesignMode(sal_True);
      94             : 
      95           2 :         Reference< ::com::sun::star::awt::XWindow >  xGridWindow(m_xGrid, UNO_QUERY);
      96           2 :         xGridWindow->setVisible(sal_True);
      97           2 :         xGridWindow->setEnable(sal_True);
      98             : 
      99             :         // introduce the model to the grid
     100           2 :         m_xGrid->setModel(xModel);
     101             :         // introduce the container (me) to the grid
     102           4 :         Reference< ::com::sun::star::beans::XPropertySet >  xModelSet(xModel, UNO_QUERY);
     103           2 :         getContainer()->addControl(::comphelper::getString(xModelSet->getPropertyValue(PROPERTY_NAME)), m_xGrid);
     104             : 
     105             :         // get the VCL-control
     106           2 :         m_pVclControl = NULL;
     107           2 :         getVclControl();
     108             : 
     109           2 :         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           2 : }
     117             : 
     118           6 : UnoDataBrowserView::~UnoDataBrowserView()
     119             : {
     120             :     {
     121           2 :         boost::scoped_ptr<Splitter> aTemp(m_pSplitter);
     122           2 :         m_pSplitter = NULL;
     123             :     }
     124           2 :     setTreeView(NULL);
     125             : 
     126           2 :     if ( m_pStatus )
     127             :     {
     128           2 :         delete m_pStatus;
     129           2 :         m_pStatus = NULL;
     130             :     }
     131             : 
     132             :     try
     133             :     {
     134           2 :         ::comphelper::disposeComponent(m_xGrid);
     135           2 :         ::comphelper::disposeComponent(m_xMe);
     136             :     }
     137           0 :     catch(const Exception&)
     138             :     {}
     139             : 
     140           4 : }
     141             : 
     142           4 : IMPL_LINK( UnoDataBrowserView, SplitHdl, void*, /*NOINTERESTEDIN*/ )
     143             : {
     144           2 :     long nYPos = m_pSplitter->GetPosPixel().Y();
     145           2 :     m_pSplitter->SetPosPixel( Point( m_pSplitter->GetSplitPosPixel(), nYPos ) );
     146           2 :     Resize();
     147             : 
     148           2 :     return 0L;
     149             : }
     150             : 
     151           2 : void UnoDataBrowserView::setSplitter(Splitter* _pSplitter)
     152             : {
     153           2 :     m_pSplitter = _pSplitter;
     154           2 :     m_pSplitter->SetSplitHdl( LINK( this, UnoDataBrowserView, SplitHdl ) );
     155           2 :     LINK( this, UnoDataBrowserView, SplitHdl ).Call(m_pSplitter);
     156           2 : }
     157             : 
     158           6 : void UnoDataBrowserView::setTreeView(DBTreeView* _pTreeView)
     159             : {
     160           6 :     if (m_pTreeView != _pTreeView)
     161             :     {
     162           4 :         if (m_pTreeView)
     163             :         {
     164           2 :             boost::scoped_ptr<vcl::Window> aTemp(m_pTreeView);
     165           2 :             m_pTreeView = NULL;
     166             :         }
     167           4 :         m_pTreeView = _pTreeView;
     168             :     }
     169           6 : }
     170             : 
     171           8 : void UnoDataBrowserView::showStatus( const OUString& _rStatus )
     172             : {
     173           8 :     if (_rStatus.isEmpty())
     174           4 :         hideStatus();
     175             :     else
     176             :     {
     177           4 :         if (!m_pStatus)
     178           2 :             m_pStatus = new FixedText(this);
     179           4 :         m_pStatus->SetText(_rStatus);
     180           4 :         m_pStatus->Show();
     181           4 :         Resize();
     182           4 :         Update();
     183             :     }
     184           8 : }
     185             : 
     186           4 : void UnoDataBrowserView::hideStatus()
     187             : {
     188           4 :     if (!m_pStatus || !m_pStatus->IsVisible())
     189             :         // nothing to do
     190           4 :         return;
     191           4 :     m_pStatus->Hide();
     192           4 :     Resize();
     193           4 :     Update();
     194             : }
     195             : 
     196          18 : void UnoDataBrowserView::resizeDocumentView(Rectangle& _rPlayground)
     197             : {
     198          18 :     Point   aSplitPos;
     199          18 :     Size    aSplitSize;
     200          18 :     Point   aPlaygroundPos( _rPlayground.TopLeft() );
     201          18 :     Size    aPlaygroundSize( _rPlayground.GetSize() );
     202             : 
     203          18 :     if (m_pTreeView && m_pTreeView->IsVisible() && m_pSplitter)
     204             :     {
     205             :         // calculate the splitter pos and size
     206          14 :         aSplitPos   = m_pSplitter->GetPosPixel();
     207          14 :         aSplitPos.Y() = aPlaygroundPos.Y();
     208          14 :         aSplitSize  = m_pSplitter->GetOutputSizePixel();
     209          14 :         aSplitSize.Height() = aPlaygroundSize.Height();
     210             : 
     211          14 :         if( ( aSplitPos.X() + aSplitSize.Width() ) > ( aPlaygroundSize.Width() ))
     212           2 :             aSplitPos.X() = aPlaygroundSize.Width() - aSplitSize.Width();
     213             : 
     214          14 :         if( aSplitPos.X() <= aPlaygroundPos.X() )
     215           4 :             aSplitPos.X() = aPlaygroundPos.X() + sal_Int32(aPlaygroundSize.Width() * 0.2);
     216             : 
     217             :         // the tree pos and size
     218          14 :         Point   aTreeViewPos( aPlaygroundPos );
     219          14 :         Size    aTreeViewSize( aSplitPos.X(), aPlaygroundSize.Height() );
     220             : 
     221             :         // the status pos and size
     222          14 :         if (m_pStatus && m_pStatus->IsVisible())
     223             :         {
     224           4 :             Size aStatusSize(aPlaygroundPos.X(), GetTextHeight() + 2);
     225           4 :             aStatusSize = LogicToPixel(aStatusSize, MAP_APPFONT);
     226           4 :             aStatusSize.Width() = aTreeViewSize.Width() - 2 - 2;
     227             : 
     228           4 :             Point aStatusPos( aPlaygroundPos.X() + 2, aTreeViewPos.Y() + aTreeViewSize.Height() - aStatusSize.Height() );
     229           4 :             m_pStatus->SetPosSizePixel( aStatusPos, aStatusSize );
     230           4 :             aTreeViewSize.Height() -= aStatusSize.Height();
     231             :         }
     232             : 
     233             :         // set the size of treelistbox
     234          14 :         m_pTreeView->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
     235             : 
     236             :         //set the size of the splitter
     237          14 :         m_pSplitter->SetPosSizePixel( aSplitPos, Size( aSplitSize.Width(), aPlaygroundSize.Height() ) );
     238          14 :         m_pSplitter->SetDragRectPixel( _rPlayground );
     239             :     }
     240             : 
     241             :     // set the size of grid control
     242          18 :     Reference< ::com::sun::star::awt::XWindow >  xGridAsWindow(m_xGrid, UNO_QUERY);
     243          18 :     if (xGridAsWindow.is())
     244          72 :         xGridAsWindow->setPosSize( aSplitPos.X() + aSplitSize.Width(), aPlaygroundPos.Y(),
     245          72 :                                    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          18 :     _rPlayground.SetPos( _rPlayground.BottomRight() );
     249          18 :     _rPlayground.SetSize( Size( 0, 0 ) );
     250          18 : }
     251             : 
     252          33 : sal_uInt16 UnoDataBrowserView::View2ModelPos(sal_uInt16 nPos) const
     253             : {
     254          33 :     return m_pVclControl ? m_pVclControl->GetModelColumnPos(m_pVclControl->GetColumnIdFromViewPos(nPos)) : -1;
     255             : }
     256             : 
     257         916 : SbaGridControl* UnoDataBrowserView::getVclControl() const
     258             : {
     259         916 :     if ( !m_pVclControl )
     260             :     {
     261             :         OSL_ENSURE(m_xGrid.is(),"Grid not set!");
     262           2 :         if ( m_xGrid.is() )
     263             :         {
     264           2 :             Reference< ::com::sun::star::awt::XWindowPeer >  xPeer = m_xGrid->getPeer();
     265           2 :             if ( xPeer.is() )
     266             :             {
     267           2 :                 SbaXGridPeer* pPeer = SbaXGridPeer::getImplementation(xPeer);
     268           2 :                 UnoDataBrowserView* pTHIS = const_cast<UnoDataBrowserView*>(this);
     269           2 :                 if ( pPeer )
     270             :                 {
     271           2 :                     m_pVclControl = static_cast<SbaGridControl*>(pPeer->GetWindow());
     272           2 :                     pTHIS->startComponentListening(Reference<XComponent>(VCLUnoHelper::GetInterface(m_pVclControl),UNO_QUERY));
     273             :                 }
     274           2 :             }
     275             :         }
     276             :     }
     277         916 :     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 :         bool bGrabFocus = 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           2 : void UnoDataBrowserView::_disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ )
     300             : {
     301           2 :     stopComponentListening(Reference<XComponent>(VCLUnoHelper::GetInterface(m_pVclControl),UNO_QUERY));
     302           2 :     m_pVclControl = NULL;
     303           2 : }
     304             : 
     305           0 : bool UnoDataBrowserView::PreNotify( NotifyEvent& rNEvt )
     306             : {
     307           0 :     bool nDone = false;
     308           0 :     if(rNEvt.GetType() == EVENT_KEYINPUT)
     309             :     {
     310           0 :         bool bGrabAllowed = isGrabVclControlFocusAllowed(this);
     311           0 :         if ( bGrabAllowed )
     312             :         {
     313           0 :             const KeyEvent* pKeyEvt = rNEvt.GetKeyEvent();
     314           0 :             const vcl::KeyCode& rKeyCode = pKeyEvt->GetKeyCode();
     315           0 :             if (  ( rKeyCode == vcl::KeyCode( KEY_E, true, true, false, false ) )
     316           0 :                || ( rKeyCode == vcl::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           4 : BrowserViewStatusDisplay::BrowserViewStatusDisplay( UnoDataBrowserView* _pView, const OUString& _rStatus )
     332           4 :     :m_pView(_pView)
     333             : {
     334             : 
     335           4 :     if (m_pView)
     336           4 :         m_pView->showStatus(_rStatus);
     337           4 : }
     338             : 
     339           4 : BrowserViewStatusDisplay::~BrowserViewStatusDisplay( )
     340             : {
     341           4 :     if (m_pView)
     342           4 :         m_pView->showStatus(OUString());
     343             : 
     344          76 : }
     345             : 
     346             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10