LCOV - code coverage report
Current view: top level - framework/source/classes - fwktabwindow.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 167 0.6 %
Date: 2014-11-03 Functions: 2 28 7.1 %
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             : // autogen include statement, do not remove
      21             : 
      22             : #include <classes/fwktabwindow.hxx>
      23             : #include <classes/fwkresid.hxx>
      24             : 
      25             : #include <com/sun/star/awt/PosSize.hpp>
      26             : #include <com/sun/star/awt/XContainerWindowEventHandler.hpp>
      27             : #include <com/sun/star/awt/ContainerWindowProvider.hpp>
      28             : #include <com/sun/star/awt/XWindow.hpp>
      29             : #include <com/sun/star/awt/XWindowPeer.hpp>
      30             : #include <com/sun/star/awt/XControl.hpp>
      31             : #include <com/sun/star/beans/NamedValue.hpp>
      32             : #include <com/sun/star/graphic/XGraphic.hpp>
      33             : 
      34             : #include <comphelper/processfactory.hxx>
      35             : #include <toolkit/helper/vclunohelper.hxx>
      36             : #include <tools/stream.hxx>
      37             : #include <tools/diagnose_ex.h>
      38             : #include <vcl/bitmap.hxx>
      39             : #include <vcl/image.hxx>
      40             : #include <vcl/msgbox.hxx>
      41             : 
      42             : const char EXTERNAL_EVENT[] = "external_event";
      43             : const char INITIALIZE_METHOD[] = "initialize";
      44             : 
      45             : using namespace ::com::sun::star;
      46             : 
      47             : namespace framework
      48             : {
      49             : 
      50             : // class FwkTabControl ---------------------------------------------------
      51           0 : FwkTabControl::FwkTabControl(vcl::Window* pParent)
      52           0 :     : TabControl(pParent)
      53             : {
      54           0 : }
      55             : 
      56           0 : void FwkTabControl::BroadcastEvent( sal_uLong nEvent )
      57             : {
      58           0 :     if ( VCLEVENT_TABPAGE_ACTIVATE == nEvent || VCLEVENT_TABPAGE_DEACTIVATE == nEvent )
      59           0 :         ImplCallEventListeners( nEvent, reinterpret_cast<void*>(GetCurPageId()) );
      60             :     else
      61             :     {
      62             :         SAL_WARN( "fwk", "FwkTabControl::BroadcastEvent(): illegal event" );
      63             :     }
      64           0 : }
      65             : 
      66             : // class FwkTabPage ------------------------------------------------
      67             : 
      68           0 : FwkTabPage::FwkTabPage(
      69             :                vcl::Window* pParent, const OUString& rPageURL,
      70             :                const css::uno::Reference< css::awt::XContainerWindowEventHandler >& rEventHdl,
      71             :                const css::uno::Reference< css::awt::XContainerWindowProvider >& rProvider ) :
      72             : 
      73             :     TabPage( pParent, WB_DIALOGCONTROL | WB_TABSTOP | WB_CHILDDLGCTRL ),
      74             : 
      75             :     m_sPageURL          ( rPageURL ),
      76             :     m_xEventHdl         ( rEventHdl ),
      77           0 :     m_xWinProvider      ( rProvider )
      78             : 
      79             : {
      80           0 : }
      81             : 
      82           0 : FwkTabPage::~FwkTabPage()
      83             : {
      84           0 :     Hide();
      85           0 :     DeactivatePage();
      86           0 : }
      87             : 
      88           0 : void FwkTabPage::CreateDialog()
      89             : {
      90             :     try
      91             :     {
      92           0 :         uno::Reference< uno::XInterface > xHandler;
      93           0 :         if ( m_xEventHdl.is() )
      94           0 :       xHandler = m_xEventHdl;
      95             : 
      96           0 :         uno::Reference< awt::XWindowPeer > xParent( VCLUnoHelper::GetInterface( this ), uno::UNO_QUERY );
      97           0 :         m_xPage = uno::Reference < awt::XWindow >(
      98           0 :             m_xWinProvider->createContainerWindow(
      99           0 :                 m_sPageURL, OUString(), xParent, xHandler ), uno::UNO_QUERY );
     100             : 
     101           0 :         uno::Reference< awt::XControl > xPageControl( m_xPage, uno::UNO_QUERY );
     102           0 :         if ( xPageControl.is() )
     103             :         {
     104           0 :             uno::Reference< awt::XWindowPeer > xWinPeer( xPageControl->getPeer() );
     105           0 :             if ( xWinPeer.is() )
     106             :             {
     107           0 :                 vcl::Window* pWindow = VCLUnoHelper::GetWindow( xWinPeer );
     108           0 :                 if ( pWindow )
     109           0 :                     pWindow->SetStyle( pWindow->GetStyle() | WB_DIALOGCONTROL | WB_CHILDDLGCTRL );
     110           0 :             }
     111             :         }
     112             : 
     113           0 :         CallMethod( OUString(INITIALIZE_METHOD) );
     114             :     }
     115           0 :     catch ( const lang::IllegalArgumentException& )
     116             :     {
     117             :         SAL_WARN( "fwk", "FwkTabPage::CreateDialog(): illegal argument" );
     118             :     }
     119           0 :     catch ( const uno::Exception& )
     120             :     {
     121             :         SAL_WARN( "fwk", "FwkTabPage::CreateDialog(): exception of XDialogProvider2::createContainerWindow()" );
     122             :     }
     123           0 : }
     124             : 
     125           0 : bool FwkTabPage::CallMethod( const OUString& rMethod )
     126             : {
     127           0 :     bool bRet = false;
     128           0 :     if ( m_xEventHdl.is() )
     129             :     {
     130             :         try
     131             :         {
     132           0 :             bRet = m_xEventHdl->callHandlerMethod( m_xPage, uno::makeAny( rMethod ), OUString(EXTERNAL_EVENT) );
     133             :         }
     134           0 :         catch ( const uno::Exception& )
     135             :         {
     136             :             DBG_UNHANDLED_EXCEPTION();
     137             :         }
     138             :     }
     139           0 :     return bRet;
     140             : }
     141             : 
     142           0 : void FwkTabPage::ActivatePage()
     143             : {
     144           0 :     TabPage::ActivatePage();
     145             : 
     146           0 :     if ( !m_xPage.is() )
     147           0 :         CreateDialog();
     148             : 
     149           0 :     if ( m_xPage.is() )
     150             :     {
     151           0 :         Resize ();
     152           0 :         m_xPage->setVisible( sal_True );
     153             :     }
     154           0 : }
     155             : 
     156           0 : void FwkTabPage::DeactivatePage()
     157             : {
     158           0 :     TabPage::DeactivatePage();
     159             : 
     160           0 :     if ( m_xPage.is() )
     161           0 :         m_xPage->setVisible( sal_False );
     162           0 : }
     163             : 
     164           0 : void FwkTabPage::Resize()
     165             : {
     166           0 :     if ( m_xPage.is () )
     167             :     {
     168           0 :         Size aSize = GetSizePixel();
     169             : 
     170           0 :         m_xPage->setPosSize( 0, 0, aSize.Width()-1 , aSize.Height()-1, awt::PosSize::POSSIZE );
     171             :     }
     172           0 : }
     173             : 
     174             : // class FwkTabWindow ---------------------------------------------
     175           0 : FwkTabWindow::FwkTabWindow( vcl::Window* pParent )
     176             :     : Window(pParent)
     177           0 :     , m_aTabCtrl(this)
     178             : {
     179           0 :     m_xWinProvider = awt::ContainerWindowProvider::create( ::comphelper::getProcessComponentContext() );
     180             : 
     181           0 :     SetPaintTransparent(true);
     182             : 
     183           0 :     m_aTabCtrl.SetActivatePageHdl( LINK( this, FwkTabWindow, ActivatePageHdl ) );
     184           0 :     m_aTabCtrl.SetDeactivatePageHdl( LINK( this, FwkTabWindow, DeactivatePageHdl ) );
     185           0 :     m_aTabCtrl.Show();
     186           0 : }
     187             : 
     188           0 : FwkTabWindow::~FwkTabWindow()
     189             : {
     190           0 :     ClearEntryList();
     191           0 : }
     192             : 
     193           0 : void FwkTabWindow::ClearEntryList()
     194             : {
     195           0 :     TabEntryList::const_iterator pIt;
     196           0 :     for (  pIt  = m_TabList.begin();
     197           0 :            pIt != m_TabList.end();
     198             :          ++pIt )
     199             :     {
     200           0 :         delete *pIt;
     201             :     }
     202             : 
     203           0 :     m_TabList.clear();
     204           0 : }
     205             : 
     206           0 : bool FwkTabWindow::RemoveEntry( sal_Int32 nIndex )
     207             : {
     208           0 :     TabEntryList::iterator pIt;
     209           0 :     for (  pIt  = m_TabList.begin();
     210           0 :            pIt != m_TabList.end();
     211             :          ++pIt )
     212             :     {
     213           0 :         if ( (*pIt)->m_nIndex == nIndex )
     214           0 :             break;
     215             :     }
     216             : 
     217             :     // remove entry from vector
     218           0 :     if ( pIt != m_TabList.end())
     219             :     {
     220           0 :         m_TabList.erase(pIt);
     221           0 :         return true;
     222             :     }
     223             :     else
     224           0 :         return false;
     225             : }
     226             : 
     227           0 : TabEntry* FwkTabWindow::FindEntry( sal_Int32 nIndex ) const
     228             : {
     229           0 :     TabEntry* pEntry = NULL;
     230             : 
     231           0 :     TabEntryList::const_iterator pIt;
     232           0 :     for (  pIt  = m_TabList.begin();
     233           0 :            pIt != m_TabList.end();
     234             :          ++pIt )
     235             :     {
     236           0 :         if ( (*pIt)->m_nIndex == nIndex )
     237             :         {
     238           0 :             pEntry = *pIt;
     239           0 :             break;
     240             :         }
     241             :     }
     242             : 
     243           0 :     return pEntry;
     244             : }
     245             : 
     246           0 : IMPL_LINK_NOARG(FwkTabWindow, ActivatePageHdl)
     247             : {
     248           0 :     const sal_uInt16 nId = m_aTabCtrl.GetCurPageId();
     249           0 :     FwkTabPage* pTabPage = static_cast< FwkTabPage* >( m_aTabCtrl.GetTabPage( nId ) );
     250           0 :     if ( !pTabPage )
     251             :     {
     252           0 :         TabEntry* pEntry = FindEntry( nId );
     253           0 :         if ( pEntry )
     254             :         {
     255           0 :             pTabPage = new FwkTabPage( &m_aTabCtrl, pEntry->m_sPageURL, pEntry->m_xEventHdl, m_xWinProvider );
     256           0 :             pEntry->m_pPage = pTabPage;
     257           0 :             m_aTabCtrl.SetTabPage( nId, pTabPage );
     258           0 :             pTabPage->Show();
     259           0 :             pTabPage->ActivatePage();
     260             :         }
     261             :     } else {
     262           0 :         pTabPage->ActivatePage();
     263             :     }
     264           0 :     m_aTabCtrl.BroadcastEvent( VCLEVENT_TABPAGE_ACTIVATE );
     265           0 :     return 1;
     266             : }
     267             : 
     268           0 : IMPL_LINK_NOARG(FwkTabWindow, DeactivatePageHdl)
     269             : {
     270           0 :     m_aTabCtrl.BroadcastEvent( VCLEVENT_TABPAGE_DEACTIVATE );
     271           0 :     return 1;
     272             : }
     273             : 
     274           0 : void FwkTabWindow::AddEventListener( const Link& rEventListener )
     275             : {
     276           0 :     m_aTabCtrl.AddEventListener( rEventListener );
     277           0 : }
     278             : 
     279           0 : void FwkTabWindow::RemoveEventListener( const Link& rEventListener )
     280             : {
     281           0 :     m_aTabCtrl.RemoveEventListener( rEventListener );
     282           0 : }
     283             : 
     284           0 : FwkTabPage* FwkTabWindow::AddTabPage( sal_Int32 nIndex, const uno::Sequence< beans::NamedValue >& rProperties )
     285             : {
     286           0 :     OUString sTitle, sToolTip, sPageURL;
     287           0 :     uno::Reference< css::awt::XContainerWindowEventHandler > xEventHdl;
     288           0 :     uno::Reference< graphic::XGraphic > xImage;
     289           0 :     bool bDisabled = false;
     290             : 
     291           0 :     sal_Int32 i = 0, nLen = rProperties.getLength();
     292           0 :     for ( i = 0; i < nLen; ++i )
     293             :     {
     294           0 :         beans::NamedValue aValue = rProperties[i];
     295           0 :         OUString sName = aValue.Name;
     296             : 
     297           0 :         if ( sName == "Title" )
     298           0 :             aValue.Value >>= sTitle;
     299           0 :         else if ( sName == "ToolTip" )
     300           0 :             aValue.Value >>= sToolTip;
     301           0 :         else if ( sName == "PageURL" )
     302           0 :             aValue.Value >>= sPageURL;
     303           0 :         else if ( sName == "EventHdl" )
     304           0 :             aValue.Value >>= xEventHdl;
     305           0 :         else if ( sName == "Image" )
     306           0 :             aValue.Value >>= xImage;
     307           0 :         else if ( sName == "Disabled" )
     308           0 :             aValue.Value >>= bDisabled;
     309           0 :     }
     310             : 
     311           0 :     TabEntry* pEntry = new TabEntry( nIndex, sPageURL, xEventHdl );
     312           0 :     m_TabList.push_back( pEntry );
     313           0 :     sal_uInt16 nIdx = static_cast< sal_uInt16 >( nIndex );
     314           0 :     m_aTabCtrl.InsertPage( nIdx, sTitle );
     315           0 :     if ( !sToolTip.isEmpty() )
     316           0 :         m_aTabCtrl.SetHelpText( nIdx, sToolTip );
     317           0 :     if ( xImage.is() )
     318           0 :         m_aTabCtrl.SetPageImage( nIdx, Image( xImage ) );
     319           0 :     if ( bDisabled )
     320           0 :         m_aTabCtrl.EnablePage( nIdx, false );
     321             : 
     322           0 :     return pEntry->m_pPage;
     323             : }
     324             : 
     325           0 : void FwkTabWindow::ActivatePage( sal_Int32 nIndex )
     326             : {
     327           0 :     m_aTabCtrl.SetCurPageId( static_cast< sal_uInt16 >( nIndex ) );
     328           0 :     ActivatePageHdl( &m_aTabCtrl );
     329           0 : }
     330             : 
     331           0 : void FwkTabWindow::RemovePage( sal_Int32 nIndex )
     332             : {
     333           0 :     TabEntry* pEntry = FindEntry(nIndex);
     334           0 :     if ( pEntry )
     335             :     {
     336           0 :         m_aTabCtrl.RemovePage( static_cast< sal_uInt16 >( nIndex ) );
     337           0 :         if (RemoveEntry(nIndex))
     338           0 :             delete pEntry;
     339             :     }
     340           0 : }
     341             : 
     342           0 : void FwkTabWindow::Resize()
     343             : {
     344           0 :     Size aPageSize = GetSizePixel();
     345           0 :     m_aTabCtrl.SetTabPageSizePixel( aPageSize );
     346           0 : }
     347             : 
     348         951 : } // namespace framework
     349             : 
     350             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10