2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-12 17:21:24 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2008-12-16 16:42:03 +00:00
|
|
|
|
|
|
|
// autogen include statement, do not remove
|
|
|
|
|
|
|
|
#include <classes/fwktabwindow.hxx>
|
|
|
|
#include "framework.hrc"
|
2010-11-29 13:41:51 +01:00
|
|
|
#include <classes/fwkresid.hxx>
|
2008-12-16 16:42:03 +00:00
|
|
|
|
|
|
|
#include <com/sun/star/awt/PosSize.hpp>
|
|
|
|
#include <com/sun/star/awt/XContainerWindowEventHandler.hpp>
|
2013-01-31 10:31:47 +02:00
|
|
|
#include <com/sun/star/awt/ContainerWindowProvider.hpp>
|
2008-12-16 16:42:03 +00:00
|
|
|
#include <com/sun/star/awt/XWindow.hpp>
|
|
|
|
#include <com/sun/star/awt/XWindowPeer.hpp>
|
2009-08-26 13:37:34 +00:00
|
|
|
#include <com/sun/star/awt/XControl.hpp>
|
2008-12-16 16:42:03 +00:00
|
|
|
#include <com/sun/star/beans/NamedValue.hpp>
|
|
|
|
#include <com/sun/star/graphic/XGraphic.hpp>
|
|
|
|
|
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
#include <toolkit/helper/vclunohelper.hxx>
|
|
|
|
#include <tools/stream.hxx>
|
2011-01-24 21:40:23 +01:00
|
|
|
#include <tools/diagnose_ex.h>
|
2008-12-16 16:42:03 +00:00
|
|
|
#include <vcl/bitmap.hxx>
|
|
|
|
#include <vcl/image.hxx>
|
|
|
|
#include <vcl/msgbox.hxx>
|
|
|
|
|
2012-03-28 11:52:47 +01:00
|
|
|
const char EXTERNAL_EVENT[] = "external_event";
|
|
|
|
const char INITIALIZE_METHOD[] = "initialize";
|
2008-12-16 16:42:03 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
|
|
|
namespace framework
|
|
|
|
{
|
|
|
|
|
|
|
|
// class FwkTabControl ---------------------------------------------------
|
|
|
|
FwkTabControl::FwkTabControl( Window* pParent, const ResId& rResId ) :
|
|
|
|
|
|
|
|
TabControl( pParent, rResId )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2011-01-13 13:11:20 +01:00
|
|
|
void FwkTabControl::BroadcastEvent( sal_uLong nEvent )
|
2008-12-16 16:42:03 +00:00
|
|
|
{
|
|
|
|
if ( VCLEVENT_TABPAGE_ACTIVATE == nEvent || VCLEVENT_TABPAGE_DEACTIVATE == nEvent )
|
2010-11-05 10:31:15 +08:00
|
|
|
ImplCallEventListeners( nEvent, (void*)(sal_uIntPtr)GetCurPageId() );
|
2008-12-16 16:42:03 +00:00
|
|
|
else
|
|
|
|
{
|
2013-02-23 13:31:09 +01:00
|
|
|
SAL_WARN( "fwk", "FwkTabControl::BroadcastEvent(): illegal event" );
|
2008-12-16 16:42:03 +00:00
|
|
|
}
|
2009-02-19 06:06:12 +00:00
|
|
|
}
|
2008-12-16 16:42:03 +00:00
|
|
|
|
|
|
|
// class FwkTabPage ------------------------------------------------
|
|
|
|
|
|
|
|
FwkTabPage::FwkTabPage(
|
2013-04-07 12:06:47 +02:00
|
|
|
Window* pParent, const OUString& rPageURL,
|
2009-02-19 06:06:12 +00:00
|
|
|
const css::uno::Reference< css::awt::XContainerWindowEventHandler >& rEventHdl,
|
|
|
|
const css::uno::Reference< css::awt::XContainerWindowProvider >& rProvider ) :
|
2008-12-16 16:42:03 +00:00
|
|
|
|
2009-08-26 13:37:34 +00:00
|
|
|
TabPage( pParent, WB_DIALOGCONTROL | WB_TABSTOP | WB_CHILDDLGCTRL ),
|
2008-12-16 16:42:03 +00:00
|
|
|
|
|
|
|
m_sPageURL ( rPageURL ),
|
2009-02-19 06:06:12 +00:00
|
|
|
m_xEventHdl ( rEventHdl ),
|
2008-12-16 16:42:03 +00:00
|
|
|
m_xWinProvider ( rProvider )
|
|
|
|
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
FwkTabPage::~FwkTabPage()
|
|
|
|
{
|
|
|
|
Hide();
|
|
|
|
DeactivatePage();
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void FwkTabPage::CreateDialog()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
uno::Reference< uno::XInterface > xHandler;
|
2009-02-19 06:06:12 +00:00
|
|
|
if ( m_xEventHdl.is() )
|
|
|
|
xHandler = m_xEventHdl;
|
|
|
|
|
2008-12-16 16:42:03 +00:00
|
|
|
uno::Reference< awt::XWindowPeer > xParent( VCLUnoHelper::GetInterface( this ), uno::UNO_QUERY );
|
|
|
|
m_xPage = uno::Reference < awt::XWindow >(
|
|
|
|
m_xWinProvider->createContainerWindow(
|
2013-04-07 12:06:47 +02:00
|
|
|
m_sPageURL, OUString(), xParent, xHandler ), uno::UNO_QUERY );
|
2008-12-16 16:42:03 +00:00
|
|
|
|
2009-08-26 13:37:34 +00:00
|
|
|
uno::Reference< awt::XControl > xPageControl( m_xPage, uno::UNO_QUERY );
|
|
|
|
if ( xPageControl.is() )
|
|
|
|
{
|
|
|
|
uno::Reference< awt::XWindowPeer > xWinPeer( xPageControl->getPeer() );
|
|
|
|
if ( xWinPeer.is() )
|
|
|
|
{
|
|
|
|
Window* pWindow = VCLUnoHelper::GetWindow( xWinPeer );
|
|
|
|
if ( pWindow )
|
|
|
|
pWindow->SetStyle( pWindow->GetStyle() | WB_DIALOGCONTROL | WB_CHILDDLGCTRL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
CallMethod( OUString(INITIALIZE_METHOD) );
|
2008-12-16 16:42:03 +00:00
|
|
|
}
|
2011-12-14 00:03:52 +09:00
|
|
|
catch ( const lang::IllegalArgumentException& )
|
2008-12-16 16:42:03 +00:00
|
|
|
{
|
2013-02-23 13:31:09 +01:00
|
|
|
SAL_WARN( "fwk", "FwkTabPage::CreateDialog(): illegal argument" );
|
2008-12-16 16:42:03 +00:00
|
|
|
}
|
2011-12-14 00:03:52 +09:00
|
|
|
catch ( const uno::Exception& )
|
2008-12-16 16:42:03 +00:00
|
|
|
{
|
2013-02-23 13:31:09 +01:00
|
|
|
SAL_WARN( "fwk", "FwkTabPage::CreateDialog(): exception of XDialogProvider2::createContainerWindow()" );
|
2008-12-16 16:42:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
sal_Bool FwkTabPage::CallMethod( const OUString& rMethod )
|
2008-12-16 16:42:03 +00:00
|
|
|
{
|
|
|
|
sal_Bool bRet = sal_False;
|
|
|
|
if ( m_xEventHdl.is() )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
bRet = m_xEventHdl->callHandlerMethod( m_xPage, uno::makeAny( rMethod ), OUString(EXTERNAL_EVENT) );
|
2008-12-16 16:42:03 +00:00
|
|
|
}
|
2011-12-14 00:03:52 +09:00
|
|
|
catch ( const uno::Exception& )
|
2008-12-16 16:42:03 +00:00
|
|
|
{
|
2011-01-24 21:40:23 +01:00
|
|
|
DBG_UNHANDLED_EXCEPTION();
|
2008-12-16 16:42:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void FwkTabPage::ActivatePage()
|
|
|
|
{
|
|
|
|
TabPage::ActivatePage();
|
|
|
|
|
|
|
|
if ( !m_xPage.is() )
|
|
|
|
CreateDialog();
|
|
|
|
|
2009-02-19 06:06:12 +00:00
|
|
|
if ( m_xPage.is() )
|
|
|
|
{
|
2008-12-16 16:42:03 +00:00
|
|
|
Resize ();
|
2009-02-19 06:06:12 +00:00
|
|
|
m_xPage->setVisible( sal_True );
|
2008-12-16 16:42:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void FwkTabPage::DeactivatePage()
|
|
|
|
{
|
|
|
|
TabPage::DeactivatePage();
|
|
|
|
|
|
|
|
if ( m_xPage.is() )
|
|
|
|
m_xPage->setVisible( sal_False );
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void FwkTabPage::Resize()
|
|
|
|
{
|
|
|
|
if ( m_xPage.is () )
|
|
|
|
{
|
2011-01-27 11:24:02 +00:00
|
|
|
Size aSize = GetSizePixel();
|
2008-12-16 16:42:03 +00:00
|
|
|
|
|
|
|
m_xPage->setPosSize( 0, 0, aSize.Width()-1 , aSize.Height()-1, awt::PosSize::POSSIZE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// class FwkTabWindow ---------------------------------------------
|
|
|
|
|
|
|
|
FwkTabWindow::FwkTabWindow( Window* pParent ) :
|
|
|
|
|
2010-11-29 13:41:51 +01:00
|
|
|
Window( pParent, FwkResId( WIN_TABWINDOW ) ),
|
2008-12-16 16:42:03 +00:00
|
|
|
|
2010-11-29 13:41:51 +01:00
|
|
|
m_aTabCtrl ( this, FwkResId( TC_TABCONTROL ) )
|
2008-12-16 16:42:03 +00:00
|
|
|
{
|
2013-01-31 10:31:47 +02:00
|
|
|
m_xWinProvider = awt::ContainerWindowProvider::create( ::comphelper::getProcessComponentContext() );
|
2009-02-19 06:06:12 +00:00
|
|
|
|
|
|
|
SetPaintTransparent(true);
|
2008-12-16 16:42:03 +00:00
|
|
|
|
|
|
|
m_aTabCtrl.SetActivatePageHdl( LINK( this, FwkTabWindow, ActivatePageHdl ) );
|
|
|
|
m_aTabCtrl.SetDeactivatePageHdl( LINK( this, FwkTabWindow, DeactivatePageHdl ) );
|
|
|
|
m_aTabCtrl.Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
FwkTabWindow::~FwkTabWindow()
|
|
|
|
{
|
|
|
|
ClearEntryList();
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void FwkTabWindow::ClearEntryList()
|
|
|
|
{
|
|
|
|
TabEntryList::const_iterator pIt;
|
|
|
|
for ( pIt = m_TabList.begin();
|
|
|
|
pIt != m_TabList.end();
|
|
|
|
++pIt )
|
|
|
|
{
|
|
|
|
delete *pIt;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_TabList.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2009-04-03 14:45:19 +00:00
|
|
|
bool FwkTabWindow::RemoveEntry( sal_Int32 nIndex )
|
|
|
|
{
|
|
|
|
TabEntryList::iterator pIt;
|
|
|
|
for ( pIt = m_TabList.begin();
|
|
|
|
pIt != m_TabList.end();
|
|
|
|
++pIt )
|
|
|
|
{
|
|
|
|
if ( (*pIt)->m_nIndex == nIndex )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove entry from vector
|
|
|
|
if ( pIt != m_TabList.end())
|
|
|
|
{
|
|
|
|
m_TabList.erase(pIt);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
2008-12-16 16:42:03 +00:00
|
|
|
TabEntry* FwkTabWindow::FindEntry( sal_Int32 nIndex ) const
|
|
|
|
{
|
|
|
|
TabEntry* pEntry = NULL;
|
|
|
|
|
|
|
|
TabEntryList::const_iterator pIt;
|
|
|
|
for ( pIt = m_TabList.begin();
|
|
|
|
pIt != m_TabList.end();
|
|
|
|
++pIt )
|
|
|
|
{
|
|
|
|
if ( (*pIt)->m_nIndex == nIndex )
|
|
|
|
{
|
|
|
|
pEntry = *pIt;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(FwkTabWindow, ActivatePageHdl)
|
2008-12-16 16:42:03 +00:00
|
|
|
{
|
2010-11-05 10:31:15 +08:00
|
|
|
const sal_uInt16 nId = m_aTabCtrl.GetCurPageId();
|
2008-12-16 16:42:03 +00:00
|
|
|
FwkTabPage* pTabPage = static_cast< FwkTabPage* >( m_aTabCtrl.GetTabPage( nId ) );
|
|
|
|
if ( !pTabPage )
|
|
|
|
{
|
|
|
|
TabEntry* pEntry = FindEntry( nId );
|
|
|
|
if ( pEntry )
|
|
|
|
{
|
2009-02-19 06:06:12 +00:00
|
|
|
pTabPage = new FwkTabPage( &m_aTabCtrl, pEntry->m_sPageURL, pEntry->m_xEventHdl, m_xWinProvider );
|
2009-04-03 14:45:19 +00:00
|
|
|
pEntry->m_pPage = pTabPage;
|
|
|
|
m_aTabCtrl.SetTabPage( nId, pTabPage );
|
2008-12-16 16:42:03 +00:00
|
|
|
pTabPage->Show();
|
|
|
|
pTabPage->ActivatePage();
|
|
|
|
}
|
2009-02-19 06:06:12 +00:00
|
|
|
} else {
|
2009-02-12 14:36:30 +00:00
|
|
|
pTabPage->ActivatePage();
|
2009-02-19 06:06:12 +00:00
|
|
|
}
|
2008-12-16 16:42:03 +00:00
|
|
|
m_aTabCtrl.BroadcastEvent( VCLEVENT_TABPAGE_ACTIVATE );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(FwkTabWindow, DeactivatePageHdl)
|
2008-12-16 16:42:03 +00:00
|
|
|
{
|
|
|
|
m_aTabCtrl.BroadcastEvent( VCLEVENT_TABPAGE_DEACTIVATE );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void FwkTabWindow::AddEventListener( const Link& rEventListener )
|
|
|
|
{
|
|
|
|
m_aTabCtrl.AddEventListener( rEventListener );
|
|
|
|
}
|
|
|
|
|
2009-11-25 14:05:01 +00:00
|
|
|
void FwkTabWindow::RemoveEventListener( const Link& rEventListener )
|
|
|
|
{
|
|
|
|
m_aTabCtrl.RemoveEventListener( rEventListener );
|
|
|
|
}
|
|
|
|
|
2008-12-16 16:42:03 +00:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
FwkTabPage* FwkTabWindow::AddTabPage( sal_Int32 nIndex, const uno::Sequence< beans::NamedValue >& rProperties )
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sTitle, sToolTip, sPageURL;
|
2009-02-19 06:06:12 +00:00
|
|
|
uno::Reference< css::awt::XContainerWindowEventHandler > xEventHdl;
|
2008-12-16 16:42:03 +00:00
|
|
|
uno::Reference< graphic::XGraphic > xImage;
|
|
|
|
bool bDisabled = false;
|
|
|
|
|
|
|
|
sal_Int32 i = 0, nLen = rProperties.getLength();
|
|
|
|
for ( i = 0; i < nLen; ++i )
|
|
|
|
{
|
|
|
|
beans::NamedValue aValue = rProperties[i];
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sName = aValue.Name;
|
2008-12-16 16:42:03 +00:00
|
|
|
|
2012-04-06 15:05:52 +02:00
|
|
|
if ( sName == "Title" )
|
2009-09-08 04:57:32 +00:00
|
|
|
aValue.Value >>= sTitle;
|
2012-04-06 15:05:52 +02:00
|
|
|
else if ( sName == "ToolTip" )
|
2009-09-08 04:57:32 +00:00
|
|
|
aValue.Value >>= sToolTip;
|
2012-04-06 15:05:52 +02:00
|
|
|
else if ( sName == "PageURL" )
|
2009-09-08 04:57:32 +00:00
|
|
|
aValue.Value >>= sPageURL;
|
2012-04-06 15:05:52 +02:00
|
|
|
else if ( sName == "EventHdl" )
|
2009-09-08 04:57:32 +00:00
|
|
|
aValue.Value >>= xEventHdl;
|
2012-04-06 15:05:52 +02:00
|
|
|
else if ( sName == "Image" )
|
2009-09-08 04:57:32 +00:00
|
|
|
aValue.Value >>= xImage;
|
2012-04-06 15:05:52 +02:00
|
|
|
else if ( sName == "Disabled" )
|
2009-09-08 04:57:32 +00:00
|
|
|
aValue.Value >>= bDisabled;
|
2008-12-16 16:42:03 +00:00
|
|
|
}
|
|
|
|
|
2009-02-19 06:06:12 +00:00
|
|
|
TabEntry* pEntry = new TabEntry( nIndex, sPageURL, xEventHdl );
|
2008-12-16 16:42:03 +00:00
|
|
|
m_TabList.push_back( pEntry );
|
2010-11-05 10:31:15 +08:00
|
|
|
sal_uInt16 nIdx = static_cast< sal_uInt16 >( nIndex );
|
2008-12-16 16:42:03 +00:00
|
|
|
m_aTabCtrl.InsertPage( nIdx, sTitle );
|
2011-12-26 14:20:50 -02:00
|
|
|
if ( !sToolTip.isEmpty() )
|
2008-12-16 16:42:03 +00:00
|
|
|
m_aTabCtrl.SetHelpText( nIdx, sToolTip );
|
|
|
|
if ( xImage.is() )
|
|
|
|
m_aTabCtrl.SetPageImage( nIdx, Image( xImage ) );
|
|
|
|
if ( bDisabled )
|
2009-02-19 06:06:12 +00:00
|
|
|
m_aTabCtrl.EnablePage( nIdx, false );
|
|
|
|
|
2008-12-16 16:42:03 +00:00
|
|
|
return pEntry->m_pPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void FwkTabWindow::ActivatePage( sal_Int32 nIndex )
|
|
|
|
{
|
2010-11-05 10:31:15 +08:00
|
|
|
m_aTabCtrl.SetCurPageId( static_cast< sal_uInt16 >( nIndex ) );
|
2008-12-16 16:42:03 +00:00
|
|
|
ActivatePageHdl( &m_aTabCtrl );
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void FwkTabWindow::RemovePage( sal_Int32 nIndex )
|
|
|
|
{
|
2009-04-03 14:45:19 +00:00
|
|
|
TabEntry* pEntry = FindEntry(nIndex);
|
|
|
|
if ( pEntry )
|
|
|
|
{
|
2010-11-05 10:31:15 +08:00
|
|
|
m_aTabCtrl.RemovePage( static_cast< sal_uInt16 >( nIndex ) );
|
2009-04-03 14:45:19 +00:00
|
|
|
if (RemoveEntry(nIndex))
|
|
|
|
delete pEntry;
|
|
|
|
}
|
2008-12-16 16:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
2009-02-19 06:06:12 +00:00
|
|
|
void FwkTabWindow::Resize()
|
|
|
|
{
|
2008-12-16 16:42:03 +00:00
|
|
|
Size aPageSize = GetSizePixel();
|
|
|
|
m_aTabCtrl.SetTabPageSizePixel( aPageSize );
|
2009-02-19 06:06:12 +00:00
|
|
|
}
|
2008-12-16 16:42:03 +00:00
|
|
|
|
|
|
|
} // namespace framework
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|