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

Generated by: LCOV version 1.10