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

Generated by: LCOV version 1.10