LCOV - code coverage report
Current view: top level - framework/source/classes - fwktabwindow.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 175 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 28 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             : // 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 :         CallEventListeners( 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 :     disposeOnce();
      85           0 : }
      86             : 
      87           0 : void FwkTabPage::dispose()
      88             : {
      89           0 :     Hide();
      90           0 :     DeactivatePage();
      91           0 :     TabPage::dispose();
      92           0 : }
      93             : 
      94           0 : void FwkTabPage::CreateDialog()
      95             : {
      96             :     try
      97             :     {
      98           0 :         uno::Reference< uno::XInterface > xHandler;
      99           0 :         if ( m_xEventHdl.is() )
     100           0 :       xHandler = m_xEventHdl;
     101             : 
     102           0 :         uno::Reference< awt::XWindowPeer > xParent( VCLUnoHelper::GetInterface( this ), uno::UNO_QUERY );
     103           0 :         m_xPage = uno::Reference < awt::XWindow >(
     104           0 :             m_xWinProvider->createContainerWindow(
     105           0 :                 m_sPageURL, OUString(), xParent, xHandler ), uno::UNO_QUERY );
     106             : 
     107           0 :         uno::Reference< awt::XControl > xPageControl( m_xPage, uno::UNO_QUERY );
     108           0 :         if ( xPageControl.is() )
     109             :         {
     110           0 :             uno::Reference< awt::XWindowPeer > xWinPeer( xPageControl->getPeer() );
     111           0 :             if ( xWinPeer.is() )
     112             :             {
     113           0 :                 vcl::Window* pWindow = VCLUnoHelper::GetWindow( xWinPeer );
     114           0 :                 if ( pWindow )
     115           0 :                     pWindow->SetStyle( pWindow->GetStyle() | WB_DIALOGCONTROL | WB_CHILDDLGCTRL );
     116           0 :             }
     117             :         }
     118             : 
     119           0 :         CallMethod( OUString(INITIALIZE_METHOD) );
     120             :     }
     121           0 :     catch ( const lang::IllegalArgumentException& )
     122             :     {
     123             :         SAL_WARN( "fwk", "FwkTabPage::CreateDialog(): illegal argument" );
     124             :     }
     125           0 :     catch ( const uno::Exception& )
     126             :     {
     127             :         SAL_WARN( "fwk", "FwkTabPage::CreateDialog(): exception of XDialogProvider2::createContainerWindow()" );
     128             :     }
     129           0 : }
     130             : 
     131           0 : bool FwkTabPage::CallMethod( const OUString& rMethod )
     132             : {
     133           0 :     bool bRet = false;
     134           0 :     if ( m_xEventHdl.is() )
     135             :     {
     136             :         try
     137             :         {
     138           0 :             bRet = m_xEventHdl->callHandlerMethod( m_xPage, uno::makeAny( rMethod ), OUString(EXTERNAL_EVENT) );
     139             :         }
     140           0 :         catch ( const uno::Exception& )
     141             :         {
     142             :             DBG_UNHANDLED_EXCEPTION();
     143             :         }
     144             :     }
     145           0 :     return bRet;
     146             : }
     147             : 
     148           0 : void FwkTabPage::ActivatePage()
     149             : {
     150           0 :     TabPage::ActivatePage();
     151             : 
     152           0 :     if ( !m_xPage.is() )
     153           0 :         CreateDialog();
     154             : 
     155           0 :     if ( m_xPage.is() )
     156             :     {
     157           0 :         Resize ();
     158           0 :         m_xPage->setVisible( sal_True );
     159             :     }
     160           0 : }
     161             : 
     162           0 : void FwkTabPage::DeactivatePage()
     163             : {
     164           0 :     TabPage::DeactivatePage();
     165             : 
     166           0 :     if ( m_xPage.is() )
     167           0 :         m_xPage->setVisible( sal_False );
     168           0 : }
     169             : 
     170           0 : void FwkTabPage::Resize()
     171             : {
     172           0 :     if ( m_xPage.is () )
     173             :     {
     174           0 :         Size aSize = GetSizePixel();
     175             : 
     176           0 :         m_xPage->setPosSize( 0, 0, aSize.Width()-1 , aSize.Height()-1, awt::PosSize::POSSIZE );
     177             :     }
     178           0 : }
     179             : 
     180             : // class FwkTabWindow ---------------------------------------------
     181           0 : FwkTabWindow::FwkTabWindow( vcl::Window* pParent )
     182             :     : Window(pParent)
     183           0 :     , m_aTabCtrl(VclPtr<FwkTabControl>::Create(this))
     184             : {
     185           0 :     m_xWinProvider = awt::ContainerWindowProvider::create( ::comphelper::getProcessComponentContext() );
     186             : 
     187           0 :     SetPaintTransparent(true);
     188             : 
     189           0 :     m_aTabCtrl->SetActivatePageHdl( LINK( this, FwkTabWindow, ActivatePageHdl ) );
     190           0 :     m_aTabCtrl->SetDeactivatePageHdl( LINK( this, FwkTabWindow, DeactivatePageHdl ) );
     191           0 :     m_aTabCtrl->Show();
     192           0 : }
     193             : 
     194           0 : FwkTabWindow::~FwkTabWindow()
     195             : {
     196           0 :     disposeOnce();
     197           0 : }
     198             : 
     199           0 : void FwkTabWindow::dispose()
     200             : {
     201           0 :     ClearEntryList();
     202           0 :     m_aTabCtrl.disposeAndClear();
     203           0 :     vcl::Window::dispose();
     204           0 : }
     205             : 
     206           0 : void FwkTabWindow::ClearEntryList()
     207             : {
     208           0 :     TabEntryList::const_iterator pIt;
     209           0 :     for (  pIt  = m_TabList.begin();
     210           0 :            pIt != m_TabList.end();
     211             :          ++pIt )
     212             :     {
     213           0 :         delete *pIt;
     214             :     }
     215             : 
     216           0 :     m_TabList.clear();
     217           0 : }
     218             : 
     219           0 : bool FwkTabWindow::RemoveEntry( sal_Int32 nIndex )
     220             : {
     221           0 :     TabEntryList::iterator pIt;
     222           0 :     for (  pIt  = m_TabList.begin();
     223           0 :            pIt != m_TabList.end();
     224             :          ++pIt )
     225             :     {
     226           0 :         if ( (*pIt)->m_nIndex == nIndex )
     227           0 :             break;
     228             :     }
     229             : 
     230             :     // remove entry from vector
     231           0 :     if ( pIt != m_TabList.end())
     232             :     {
     233           0 :         m_TabList.erase(pIt);
     234           0 :         return true;
     235             :     }
     236             :     else
     237           0 :         return false;
     238             : }
     239             : 
     240           0 : TabEntry* FwkTabWindow::FindEntry( sal_Int32 nIndex ) const
     241             : {
     242           0 :     TabEntry* pEntry = NULL;
     243             : 
     244           0 :     TabEntryList::const_iterator pIt;
     245           0 :     for (  pIt  = m_TabList.begin();
     246           0 :            pIt != m_TabList.end();
     247             :          ++pIt )
     248             :     {
     249           0 :         if ( (*pIt)->m_nIndex == nIndex )
     250             :         {
     251           0 :             pEntry = *pIt;
     252           0 :             break;
     253             :         }
     254             :     }
     255             : 
     256           0 :     return pEntry;
     257             : }
     258             : 
     259           0 : IMPL_LINK_NOARG(FwkTabWindow, ActivatePageHdl)
     260             : {
     261           0 :     const sal_uInt16 nId = m_aTabCtrl->GetCurPageId();
     262           0 :     FwkTabPage* pTabPage = static_cast< FwkTabPage* >( m_aTabCtrl->GetTabPage( nId ) );
     263           0 :     if ( !pTabPage )
     264             :     {
     265           0 :         TabEntry* pEntry = FindEntry( nId );
     266           0 :         if ( pEntry )
     267             :         {
     268           0 :             pTabPage = VclPtr<FwkTabPage>::Create( m_aTabCtrl.get(), pEntry->m_sPageURL, pEntry->m_xEventHdl, m_xWinProvider );
     269           0 :             pEntry->m_pPage = pTabPage;
     270           0 :             m_aTabCtrl->SetTabPage( nId, pTabPage );
     271           0 :             pTabPage->Show();
     272           0 :             pTabPage->ActivatePage();
     273             :         }
     274             :     } else {
     275           0 :         pTabPage->ActivatePage();
     276             :     }
     277           0 :     m_aTabCtrl->BroadcastEvent( VCLEVENT_TABPAGE_ACTIVATE );
     278           0 :     return 1;
     279             : }
     280             : 
     281           0 : IMPL_LINK_NOARG_TYPED(FwkTabWindow, DeactivatePageHdl, TabControl *, bool)
     282             : {
     283           0 :     m_aTabCtrl->BroadcastEvent( VCLEVENT_TABPAGE_DEACTIVATE );
     284           0 :     return true;
     285             : }
     286             : 
     287           0 : void FwkTabWindow::AddEventListener( const Link<>& rEventListener )
     288             : {
     289           0 :     m_aTabCtrl->AddEventListener( rEventListener );
     290           0 : }
     291             : 
     292           0 : void FwkTabWindow::RemoveEventListener( const Link<>& rEventListener )
     293             : {
     294           0 :     m_aTabCtrl->RemoveEventListener( rEventListener );
     295           0 : }
     296             : 
     297           0 : FwkTabPage* FwkTabWindow::AddTabPage( sal_Int32 nIndex, const uno::Sequence< beans::NamedValue >& rProperties )
     298             : {
     299           0 :     OUString sTitle, sToolTip, sPageURL;
     300           0 :     uno::Reference< css::awt::XContainerWindowEventHandler > xEventHdl;
     301           0 :     uno::Reference< graphic::XGraphic > xImage;
     302           0 :     bool bDisabled = false;
     303             : 
     304           0 :     sal_Int32 i = 0, nLen = rProperties.getLength();
     305           0 :     for ( i = 0; i < nLen; ++i )
     306             :     {
     307           0 :         beans::NamedValue aValue = rProperties[i];
     308           0 :         OUString sName = aValue.Name;
     309             : 
     310           0 :         if ( sName == "Title" )
     311           0 :             aValue.Value >>= sTitle;
     312           0 :         else if ( sName == "ToolTip" )
     313           0 :             aValue.Value >>= sToolTip;
     314           0 :         else if ( sName == "PageURL" )
     315           0 :             aValue.Value >>= sPageURL;
     316           0 :         else if ( sName == "EventHdl" )
     317           0 :             aValue.Value >>= xEventHdl;
     318           0 :         else if ( sName == "Image" )
     319           0 :             aValue.Value >>= xImage;
     320           0 :         else if ( sName == "Disabled" )
     321           0 :             aValue.Value >>= bDisabled;
     322           0 :     }
     323             : 
     324           0 :     TabEntry* pEntry = new TabEntry( nIndex, sPageURL, xEventHdl );
     325           0 :     m_TabList.push_back( pEntry );
     326           0 :     sal_uInt16 nIdx = static_cast< sal_uInt16 >( nIndex );
     327           0 :     m_aTabCtrl->InsertPage( nIdx, sTitle );
     328           0 :     if ( !sToolTip.isEmpty() )
     329           0 :         m_aTabCtrl->SetHelpText( nIdx, sToolTip );
     330           0 :     if ( xImage.is() )
     331           0 :         m_aTabCtrl->SetPageImage( nIdx, Image( xImage ) );
     332           0 :     if ( bDisabled )
     333           0 :         m_aTabCtrl->EnablePage( nIdx, false );
     334             : 
     335           0 :     return pEntry->m_pPage;
     336             : }
     337             : 
     338           0 : void FwkTabWindow::ActivatePage( sal_Int32 nIndex )
     339             : {
     340           0 :     m_aTabCtrl->SetCurPageId( static_cast< sal_uInt16 >( nIndex ) );
     341           0 :     ActivatePageHdl( m_aTabCtrl.get() );
     342           0 : }
     343             : 
     344           0 : void FwkTabWindow::RemovePage( sal_Int32 nIndex )
     345             : {
     346           0 :     TabEntry* pEntry = FindEntry(nIndex);
     347           0 :     if ( pEntry )
     348             :     {
     349           0 :         m_aTabCtrl->RemovePage( static_cast< sal_uInt16 >( nIndex ) );
     350           0 :         if (RemoveEntry(nIndex))
     351           0 :             delete pEntry;
     352             :     }
     353           0 : }
     354             : 
     355           0 : void FwkTabWindow::Resize()
     356             : {
     357           0 :     Size aPageSize = GetSizePixel();
     358           0 :     m_aTabCtrl->SetTabPageSizePixel( aPageSize );
     359           0 : }
     360             : 
     361             : } // namespace framework
     362             : 
     363             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11