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

Generated by: LCOV version 1.10