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

Generated by: LCOV version 1.10