LCOV - code coverage report
Current view: top level - dbaccess/source/ui/browser - brwview.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 122 167 73.1 %
Date: 2015-06-13 12:38:46 Functions: 19 22 86.4 %
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           1 : 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           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 != nullptr, "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           1 :     disposeOnce();
     121           2 : }
     122             : 
     123           1 : void UnoDataBrowserView::dispose()
     124             : {
     125           1 :     m_pSplitter.disposeAndClear();
     126           1 :     setTreeView(NULL);
     127             : 
     128           1 :     m_pStatus.disposeAndClear();
     129             : 
     130             :     try
     131             :     {
     132           1 :         ::comphelper::disposeComponent(m_xGrid);
     133           1 :         ::comphelper::disposeComponent(m_xMe);
     134             :     }
     135           0 :     catch(const Exception&)
     136             :     {}
     137           1 :     m_pTreeView.clear();
     138           1 :     m_pVclControl.clear();
     139           1 :     ODataView::dispose();
     140           1 : }
     141             : 
     142           2 : IMPL_LINK_NOARG( UnoDataBrowserView, SplitHdl )
     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.get() != _pTreeView)
     161             :     {
     162           2 :         m_pTreeView.disposeAndClear();
     163           2 :         m_pTreeView = _pTreeView;
     164             :     }
     165           3 : }
     166             : 
     167           4 : void UnoDataBrowserView::showStatus( const OUString& _rStatus )
     168             : {
     169           4 :     if (_rStatus.isEmpty())
     170           2 :         hideStatus();
     171             :     else
     172             :     {
     173           2 :         if (!m_pStatus)
     174           1 :             m_pStatus = VclPtr<FixedText>::Create(this);
     175           2 :         m_pStatus->SetText(_rStatus);
     176           2 :         m_pStatus->Show();
     177           2 :         Resize();
     178           2 :         Update();
     179             :     }
     180           4 : }
     181             : 
     182           2 : void UnoDataBrowserView::hideStatus()
     183             : {
     184           2 :     if (!m_pStatus || !m_pStatus->IsVisible())
     185             :         // nothing to do
     186           2 :         return;
     187           2 :     m_pStatus->Hide();
     188           2 :     Resize();
     189           2 :     Update();
     190             : }
     191             : 
     192           9 : void UnoDataBrowserView::resizeDocumentView(Rectangle& _rPlayground)
     193             : {
     194           9 :     Point   aSplitPos;
     195           9 :     Size    aSplitSize;
     196           9 :     Point   aPlaygroundPos( _rPlayground.TopLeft() );
     197           9 :     Size    aPlaygroundSize( _rPlayground.GetSize() );
     198             : 
     199           9 :     if (m_pTreeView && m_pTreeView->IsVisible() && m_pSplitter)
     200             :     {
     201             :         // calculate the splitter pos and size
     202           7 :         aSplitPos   = m_pSplitter->GetPosPixel();
     203           7 :         aSplitPos.Y() = aPlaygroundPos.Y();
     204           7 :         aSplitSize  = m_pSplitter->GetOutputSizePixel();
     205           7 :         aSplitSize.Height() = aPlaygroundSize.Height();
     206             : 
     207           7 :         if( ( aSplitPos.X() + aSplitSize.Width() ) > ( aPlaygroundSize.Width() ))
     208           1 :             aSplitPos.X() = aPlaygroundSize.Width() - aSplitSize.Width();
     209             : 
     210           7 :         if( aSplitPos.X() <= aPlaygroundPos.X() )
     211           2 :             aSplitPos.X() = aPlaygroundPos.X() + sal_Int32(aPlaygroundSize.Width() * 0.2);
     212             : 
     213             :         // the tree pos and size
     214           7 :         Point   aTreeViewPos( aPlaygroundPos );
     215           7 :         Size    aTreeViewSize( aSplitPos.X(), aPlaygroundSize.Height() );
     216             : 
     217             :         // the status pos and size
     218           7 :         if (m_pStatus && m_pStatus->IsVisible())
     219             :         {
     220           2 :             Size aStatusSize(aPlaygroundPos.X(), GetTextHeight() + 2);
     221           2 :             aStatusSize = LogicToPixel(aStatusSize, MAP_APPFONT);
     222           2 :             aStatusSize.Width() = aTreeViewSize.Width() - 2 - 2;
     223             : 
     224           2 :             Point aStatusPos( aPlaygroundPos.X() + 2, aTreeViewPos.Y() + aTreeViewSize.Height() - aStatusSize.Height() );
     225           2 :             m_pStatus->SetPosSizePixel( aStatusPos, aStatusSize );
     226           2 :             aTreeViewSize.Height() -= aStatusSize.Height();
     227             :         }
     228             : 
     229             :         // set the size of treelistbox
     230           7 :         m_pTreeView->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
     231             : 
     232             :         //set the size of the splitter
     233           7 :         m_pSplitter->SetPosSizePixel( aSplitPos, Size( aSplitSize.Width(), aPlaygroundSize.Height() ) );
     234           7 :         m_pSplitter->SetDragRectPixel( _rPlayground );
     235             :     }
     236             : 
     237             :     // set the size of grid control
     238           9 :     Reference< ::com::sun::star::awt::XWindow >  xGridAsWindow(m_xGrid, UNO_QUERY);
     239           9 :     if (xGridAsWindow.is())
     240          36 :         xGridAsWindow->setPosSize( aSplitPos.X() + aSplitSize.Width(), aPlaygroundPos.Y(),
     241          36 :                                    aPlaygroundSize.Width() - aSplitSize.Width() - aSplitPos.X(), aPlaygroundSize.Height(), ::com::sun::star::awt::PosSize::POSSIZE);
     242             : 
     243             :     // just for completeness: there is no space left, we occupied it all ...
     244           9 :     _rPlayground.SetPos( _rPlayground.BottomRight() );
     245           9 :     _rPlayground.SetSize( Size( 0, 0 ) );
     246           9 : }
     247             : 
     248          15 : sal_uInt16 UnoDataBrowserView::View2ModelPos(sal_uInt16 nPos) const
     249             : {
     250          15 :     return m_pVclControl ? m_pVclControl->GetModelColumnPos(m_pVclControl->GetColumnIdFromViewPos(nPos)) : -1;
     251             : }
     252             : 
     253         447 : SbaGridControl* UnoDataBrowserView::getVclControl() const
     254             : {
     255         447 :     if ( !m_pVclControl )
     256             :     {
     257             :         OSL_ENSURE(m_xGrid.is(),"Grid not set!");
     258           1 :         if ( m_xGrid.is() )
     259             :         {
     260           1 :             Reference< ::com::sun::star::awt::XWindowPeer >  xPeer = m_xGrid->getPeer();
     261           1 :             if ( xPeer.is() )
     262             :             {
     263           1 :                 SbaXGridPeer* pPeer = SbaXGridPeer::getImplementation(xPeer);
     264           1 :                 UnoDataBrowserView* pTHIS = const_cast<UnoDataBrowserView*>(this);
     265           1 :                 if ( pPeer )
     266             :                 {
     267           1 :                     m_pVclControl = static_cast<SbaGridControl*>(pPeer->GetWindow().get());
     268           1 :                     pTHIS->startComponentListening(Reference<XComponent>(VCLUnoHelper::GetInterface(m_pVclControl),UNO_QUERY));
     269             :                 }
     270           1 :             }
     271             :         }
     272             :     }
     273         447 :     return m_pVclControl;
     274             : }
     275             : 
     276           0 : void UnoDataBrowserView::GetFocus()
     277             : {
     278           0 :     ODataView::GetFocus();
     279           0 :     if( m_pTreeView && m_pTreeView->IsVisible() && !m_pTreeView->HasChildPathFocus())
     280           0 :         m_pTreeView->GrabFocus();
     281           0 :     else if (m_pVclControl && m_xGrid.is())
     282             :     {
     283           0 :         bool bGrabFocus = false;
     284           0 :         if(!m_pVclControl->HasChildPathFocus())
     285             :         {
     286           0 :             bGrabFocus = isGrabVclControlFocusAllowed(this);
     287           0 :             if( bGrabFocus )
     288           0 :                 m_pVclControl->GrabFocus();
     289             :         }
     290           0 :         if(!bGrabFocus && m_pTreeView && m_pTreeView->IsVisible() )
     291           0 :             m_pTreeView->GrabFocus();
     292             :     }
     293           0 : }
     294             : 
     295           1 : void UnoDataBrowserView::_disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ )
     296             : {
     297           1 :     stopComponentListening(Reference<XComponent>(VCLUnoHelper::GetInterface(m_pVclControl),UNO_QUERY));
     298           1 :     m_pVclControl = NULL;
     299           1 : }
     300             : 
     301           0 : bool UnoDataBrowserView::PreNotify( NotifyEvent& rNEvt )
     302             : {
     303           0 :     bool nDone = false;
     304           0 :     if(rNEvt.GetType() == MouseNotifyEvent::KEYINPUT)
     305             :     {
     306           0 :         bool bGrabAllowed = isGrabVclControlFocusAllowed(this);
     307           0 :         if ( bGrabAllowed )
     308             :         {
     309           0 :             const KeyEvent* pKeyEvt = rNEvt.GetKeyEvent();
     310           0 :             const vcl::KeyCode& rKeyCode = pKeyEvt->GetKeyCode();
     311           0 :             if (  ( rKeyCode == vcl::KeyCode( KEY_E, true, true, false, false ) )
     312           0 :                || ( rKeyCode == vcl::KeyCode( KEY_TAB, true, false, false, false ) )
     313             :                )
     314             :             {
     315           0 :                 if ( m_pTreeView && m_pVclControl && m_pTreeView->HasChildPathFocus() )
     316           0 :                     m_pVclControl->GrabFocus();
     317           0 :                 else if ( m_pTreeView && m_pVclControl && m_pVclControl->HasChildPathFocus() )
     318           0 :                     m_pTreeView->GrabFocus();
     319             : 
     320           0 :                 nDone = true;
     321             :             }
     322             :         }
     323             :     }
     324           0 :     return nDone || ODataView::PreNotify(rNEvt);
     325             : }
     326             : 
     327           2 : BrowserViewStatusDisplay::BrowserViewStatusDisplay( UnoDataBrowserView* _pView, const OUString& _rStatus )
     328           2 :     :m_pView(_pView)
     329             : {
     330             : 
     331           2 :     if (m_pView)
     332           2 :         m_pView->showStatus(_rStatus);
     333           2 : }
     334             : 
     335           4 : BrowserViewStatusDisplay::~BrowserViewStatusDisplay( )
     336             : {
     337           2 :     if (m_pView)
     338           2 :         m_pView->showStatus(OUString());
     339             : 
     340          38 : }
     341             : 
     342             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11