1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 // autogen include statement, do not remove
22 #include <classes/fwktabwindow.hxx>
23 #include <classes/fwkresid.hxx>
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>
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>
42 const char EXTERNAL_EVENT
[] = "external_event";
43 const char INITIALIZE_METHOD
[] = "initialize";
45 using namespace ::com::sun::star
;
50 // class FwkTabControl ---------------------------------------------------
51 FwkTabControl::FwkTabControl(vcl::Window
* pParent
)
56 void FwkTabControl::BroadcastEvent( sal_uLong nEvent
)
58 if ( VCLEVENT_TABPAGE_ACTIVATE
== nEvent
|| VCLEVENT_TABPAGE_DEACTIVATE
== nEvent
)
59 CallEventListeners( nEvent
, reinterpret_cast<void*>(GetCurPageId()) );
62 SAL_WARN( "fwk", "FwkTabControl::BroadcastEvent(): illegal event" );
66 // class FwkTabPage ------------------------------------------------
68 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
) :
73 TabPage( pParent
, WB_DIALOGCONTROL
| WB_TABSTOP
| WB_CHILDDLGCTRL
),
75 m_sPageURL ( rPageURL
),
76 m_xEventHdl ( rEventHdl
),
77 m_xWinProvider ( rProvider
)
82 FwkTabPage::~FwkTabPage()
87 void FwkTabPage::dispose()
94 void FwkTabPage::CreateDialog()
98 uno::Reference
< uno::XInterface
> xHandler
;
99 if ( m_xEventHdl
.is() )
100 xHandler
= m_xEventHdl
;
102 uno::Reference
< awt::XWindowPeer
> xParent( VCLUnoHelper::GetInterface( this ), uno::UNO_QUERY
);
103 m_xPage
= uno::Reference
< awt::XWindow
>(
104 m_xWinProvider
->createContainerWindow(
105 m_sPageURL
, OUString(), xParent
, xHandler
), uno::UNO_QUERY
);
107 uno::Reference
< awt::XControl
> xPageControl( m_xPage
, uno::UNO_QUERY
);
108 if ( xPageControl
.is() )
110 uno::Reference
< awt::XWindowPeer
> xWinPeer( xPageControl
->getPeer() );
113 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow( xWinPeer
);
115 pWindow
->SetStyle( pWindow
->GetStyle() | WB_DIALOGCONTROL
| WB_CHILDDLGCTRL
);
119 CallMethod( OUString(INITIALIZE_METHOD
) );
121 catch ( const lang::IllegalArgumentException
& )
123 SAL_WARN( "fwk", "FwkTabPage::CreateDialog(): illegal argument" );
125 catch ( const uno::Exception
& )
127 SAL_WARN( "fwk", "FwkTabPage::CreateDialog(): exception of XDialogProvider2::createContainerWindow()" );
131 bool FwkTabPage::CallMethod( const OUString
& rMethod
)
134 if ( m_xEventHdl
.is() )
138 bRet
= m_xEventHdl
->callHandlerMethod( m_xPage
, uno::makeAny( rMethod
), OUString(EXTERNAL_EVENT
) );
140 catch ( const uno::Exception
& )
142 DBG_UNHANDLED_EXCEPTION();
148 void FwkTabPage::ActivatePage()
150 TabPage::ActivatePage();
158 m_xPage
->setVisible( sal_True
);
162 void FwkTabPage::DeactivatePage()
164 TabPage::DeactivatePage();
167 m_xPage
->setVisible( sal_False
);
170 void FwkTabPage::Resize()
174 Size aSize
= GetSizePixel();
176 m_xPage
->setPosSize( 0, 0, aSize
.Width()-1 , aSize
.Height()-1, awt::PosSize::POSSIZE
);
180 // class FwkTabWindow ---------------------------------------------
181 FwkTabWindow::FwkTabWindow( vcl::Window
* pParent
)
183 , m_aTabCtrl(VclPtr
<FwkTabControl
>::Create(this))
185 m_xWinProvider
= awt::ContainerWindowProvider::create( ::comphelper::getProcessComponentContext() );
187 SetPaintTransparent(true);
189 m_aTabCtrl
->SetActivatePageHdl( LINK( this, FwkTabWindow
, ActivatePageHdl
) );
190 m_aTabCtrl
->SetDeactivatePageHdl( LINK( this, FwkTabWindow
, DeactivatePageHdl
) );
194 FwkTabWindow::~FwkTabWindow()
199 void FwkTabWindow::dispose()
202 m_aTabCtrl
.disposeAndClear();
203 vcl::Window::dispose();
206 void FwkTabWindow::ClearEntryList()
208 TabEntryList::const_iterator pIt
;
209 for ( pIt
= m_TabList
.begin();
210 pIt
!= m_TabList
.end();
219 bool FwkTabWindow::RemoveEntry( sal_Int32 nIndex
)
221 TabEntryList::iterator pIt
;
222 for ( pIt
= m_TabList
.begin();
223 pIt
!= m_TabList
.end();
226 if ( (*pIt
)->m_nIndex
== nIndex
)
230 // remove entry from vector
231 if ( pIt
!= m_TabList
.end())
233 m_TabList
.erase(pIt
);
240 TabEntry
* FwkTabWindow::FindEntry( sal_Int32 nIndex
) const
242 TabEntry
* pEntry
= NULL
;
244 TabEntryList::const_iterator pIt
;
245 for ( pIt
= m_TabList
.begin();
246 pIt
!= m_TabList
.end();
249 if ( (*pIt
)->m_nIndex
== nIndex
)
259 IMPL_LINK_NOARG(FwkTabWindow
, ActivatePageHdl
)
261 const sal_uInt16 nId
= m_aTabCtrl
->GetCurPageId();
262 FwkTabPage
* pTabPage
= static_cast< FwkTabPage
* >( m_aTabCtrl
->GetTabPage( nId
) );
265 TabEntry
* pEntry
= FindEntry( nId
);
268 pTabPage
= VclPtr
<FwkTabPage
>::Create( m_aTabCtrl
.get(), pEntry
->m_sPageURL
, pEntry
->m_xEventHdl
, m_xWinProvider
);
269 pEntry
->m_pPage
= pTabPage
;
270 m_aTabCtrl
->SetTabPage( nId
, pTabPage
);
272 pTabPage
->ActivatePage();
275 pTabPage
->ActivatePage();
277 m_aTabCtrl
->BroadcastEvent( VCLEVENT_TABPAGE_ACTIVATE
);
281 IMPL_LINK_NOARG_TYPED(FwkTabWindow
, DeactivatePageHdl
, TabControl
*, bool)
283 m_aTabCtrl
->BroadcastEvent( VCLEVENT_TABPAGE_DEACTIVATE
);
287 void FwkTabWindow::AddEventListener( const Link
<>& rEventListener
)
289 m_aTabCtrl
->AddEventListener( rEventListener
);
292 void FwkTabWindow::RemoveEventListener( const Link
<>& rEventListener
)
294 m_aTabCtrl
->RemoveEventListener( rEventListener
);
297 FwkTabPage
* FwkTabWindow::AddTabPage( sal_Int32 nIndex
, const uno::Sequence
< beans::NamedValue
>& rProperties
)
299 OUString sTitle
, sToolTip
, sPageURL
;
300 uno::Reference
< css::awt::XContainerWindowEventHandler
> xEventHdl
;
301 uno::Reference
< graphic::XGraphic
> xImage
;
302 bool bDisabled
= false;
304 sal_Int32 i
= 0, nLen
= rProperties
.getLength();
305 for ( i
= 0; i
< nLen
; ++i
)
307 beans::NamedValue aValue
= rProperties
[i
];
308 OUString sName
= aValue
.Name
;
310 if ( sName
== "Title" )
311 aValue
.Value
>>= sTitle
;
312 else if ( sName
== "ToolTip" )
313 aValue
.Value
>>= sToolTip
;
314 else if ( sName
== "PageURL" )
315 aValue
.Value
>>= sPageURL
;
316 else if ( sName
== "EventHdl" )
317 aValue
.Value
>>= xEventHdl
;
318 else if ( sName
== "Image" )
319 aValue
.Value
>>= xImage
;
320 else if ( sName
== "Disabled" )
321 aValue
.Value
>>= bDisabled
;
324 TabEntry
* pEntry
= new TabEntry( nIndex
, sPageURL
, xEventHdl
);
325 m_TabList
.push_back( pEntry
);
326 sal_uInt16 nIdx
= static_cast< sal_uInt16
>( nIndex
);
327 m_aTabCtrl
->InsertPage( nIdx
, sTitle
);
328 if ( !sToolTip
.isEmpty() )
329 m_aTabCtrl
->SetHelpText( nIdx
, sToolTip
);
331 m_aTabCtrl
->SetPageImage( nIdx
, Image( xImage
) );
333 m_aTabCtrl
->EnablePage( nIdx
, false );
335 return pEntry
->m_pPage
;
338 void FwkTabWindow::ActivatePage( sal_Int32 nIndex
)
340 m_aTabCtrl
->SetCurPageId( static_cast< sal_uInt16
>( nIndex
) );
341 ActivatePageHdl( m_aTabCtrl
.get() );
344 void FwkTabWindow::RemovePage( sal_Int32 nIndex
)
346 TabEntry
* pEntry
= FindEntry(nIndex
);
349 m_aTabCtrl
->RemovePage( static_cast< sal_uInt16
>( nIndex
) );
350 if (RemoveEntry(nIndex
))
355 void FwkTabWindow::Resize()
357 Size aPageSize
= GetSizePixel();
358 m_aTabCtrl
->SetTabPageSizePixel( aPageSize
);
361 } // namespace framework
363 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */