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 #include <toolkit/awt/vclxtabpagecontainer.hxx>
21 #include <com/sun/star/awt/tab/XTabPageModel.hpp>
22 #include <com/sun/star/awt/XControl.hpp>
23 #include <vcl/image.hxx>
24 #include <vcl/tabpage.hxx>
25 #include <vcl/tabctrl.hxx>
26 #include <vcl/svapp.hxx>
27 #include <toolkit/helper/property.hxx>
28 #include <toolkit/helper/vclunohelper.hxx>
29 #include <cppuhelper/typeprovider.hxx>
31 #include "helper/tkresmgr.hxx"
33 using namespace ::com::sun::star
;
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::lang
;
36 using namespace ::com::sun::star::beans
;
37 using namespace ::com::sun::star::container
;
38 using namespace ::com::sun::star::view
;
40 // class VCLXTabPageContainer
42 void VCLXTabPageContainer::ImplGetPropertyIds( std::list
< sal_uInt16
> &rIds
)
44 VCLXWindow::ImplGetPropertyIds( rIds
);
47 VCLXTabPageContainer::VCLXTabPageContainer() :
48 m_aTabPageListeners( *this )
52 VCLXTabPageContainer::~VCLXTabPageContainer()
54 OSL_TRACE ("%s", __FUNCTION__
);
57 void SAL_CALL
VCLXTabPageContainer::draw( sal_Int32 nX
, sal_Int32 nY
) throw(RuntimeException
, std::exception
)
59 SolarMutexGuard aGuard
;
60 VclPtr
<TabControl
> pTabControl
= GetAs
<TabControl
>();
63 TabPage
*pTabPage
= pTabControl
->GetTabPage( sal::static_int_cast
< sal_uInt16
>( pTabControl
->GetCurPageId( ) ) );
64 OutputDevice
* pDev
= VCLUnoHelper::GetOutputDevice( getGraphics() );
67 ::Point
aPos( nX
, nY
);
68 ::Size aSize
= pTabPage
->GetSizePixel();
70 aPos
= pDev
->PixelToLogic( aPos
);
71 aSize
= pDev
->PixelToLogic( aSize
);
73 pTabPage
->Draw( pDev
, aPos
, aSize
, 0 );
77 VCLXWindow::draw( nX
, nY
);
80 ::com::sun::star::awt::DeviceInfo
VCLXTabPageContainer::getInfo() throw(RuntimeException
, std::exception
)
82 ::com::sun::star::awt::DeviceInfo aInfo
= VCLXDevice::getInfo();
86 void SAL_CALL
VCLXTabPageContainer::setProperty(const OUString
& PropertyName
, const Any
& Value
) throw(RuntimeException
, std::exception
)
88 SolarMutexGuard aGuard
;
89 VclPtr
<TabControl
> pTabPage
= GetAs
<TabControl
>();
91 VCLXWindow::setProperty( PropertyName
, Value
);
94 ::sal_Int16 SAL_CALL
VCLXTabPageContainer::getActiveTabPageID() throw (RuntimeException
, std::exception
)
96 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
97 return pTabCtrl
? pTabCtrl
->GetCurPageId( ) : 0;
100 void SAL_CALL
VCLXTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid
) throw (RuntimeException
, std::exception
)
102 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
104 pTabCtrl
->SelectTabPage(_activetabpageid
);
107 ::sal_Int16 SAL_CALL
VCLXTabPageContainer::getTabPageCount( ) throw (RuntimeException
, std::exception
)
109 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
110 return pTabCtrl
? pTabCtrl
->GetPageCount() : 0;
113 sal_Bool SAL_CALL
VCLXTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex
) throw (RuntimeException
, std::exception
)
115 return (getActiveTabPageID() == tabPageIndex
);
118 Reference
< ::com::sun::star::awt::tab::XTabPage
> SAL_CALL
VCLXTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex
) throw (RuntimeException
, std::exception
)
120 return (tabPageIndex
>= 0 && tabPageIndex
< static_cast<sal_Int16
>(m_aTabPages
.size())) ? m_aTabPages
[tabPageIndex
] : NULL
;
123 Reference
< ::com::sun::star::awt::tab::XTabPage
> SAL_CALL
VCLXTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID
) throw (RuntimeException
, std::exception
)
125 SolarMutexGuard aGuard
;
126 Reference
< ::com::sun::star::awt::tab::XTabPage
> xTabPage
;
127 ::std::vector
< Reference
< ::com::sun::star::awt::tab::XTabPage
> >::iterator aIter
= m_aTabPages
.begin();
128 ::std::vector
< Reference
< ::com::sun::star::awt::tab::XTabPage
> >::iterator aEnd
= m_aTabPages
.end();
129 for(;aIter
!= aEnd
;++aIter
)
131 Reference
< awt::XControl
> xControl(*aIter
,UNO_QUERY
);
132 Reference
< awt::tab::XTabPageModel
> xP( xControl
->getModel(), UNO_QUERY
);
133 if ( tabPageID
== xP
->getTabPageID() )
142 void SAL_CALL
VCLXTabPageContainer::addTabPageContainerListener( const Reference
< ::com::sun::star::awt::tab::XTabPageContainerListener
>& listener
) throw (RuntimeException
, std::exception
)
144 m_aTabPageListeners
.addInterface( listener
);
147 void SAL_CALL
VCLXTabPageContainer::removeTabPageContainerListener( const Reference
< ::com::sun::star::awt::tab::XTabPageContainerListener
>& listener
) throw (RuntimeException
, std::exception
)
149 m_aTabPageListeners
.removeInterface( listener
);
152 void VCLXTabPageContainer::ProcessWindowEvent( const VclWindowEvent
& _rVclWindowEvent
)
154 SolarMutexClearableGuard aGuard
;
155 VclPtr
<TabControl
> pTabControl
= GetAs
<TabControl
>();
158 switch ( _rVclWindowEvent
.GetId() )
160 case VCLEVENT_TABPAGE_ACTIVATE
:
162 sal_uLong page
= reinterpret_cast<sal_uLong
>(_rVclWindowEvent
.GetData());
163 awt::tab::TabPageActivatedEvent
aEvent(NULL
,page
);
164 m_aTabPageListeners
.tabPageActivated(aEvent
);
169 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent
);
174 void SAL_CALL
VCLXTabPageContainer::disposing( const ::com::sun::star::lang::EventObject
& /*Source*/ ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
177 void SAL_CALL
VCLXTabPageContainer::elementInserted( const ::com::sun::star::container::ContainerEvent
& Event
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
179 SolarMutexGuard aGuard
;
180 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
181 Reference
< ::com::sun::star::awt::tab::XTabPage
> xTabPage(Event
.Element
,uno::UNO_QUERY
);
182 if ( pTabCtrl
&& xTabPage
.is() )
184 Reference
< awt::XControl
> xControl(xTabPage
,UNO_QUERY
);
185 Reference
< awt::tab::XTabPageModel
> xP( xControl
->getModel(), UNO_QUERY
);
186 sal_Int16 nPageID
= xP
->getTabPageID();
188 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow(xControl
->getPeer());
189 TabPage
* pPage
= static_cast<TabPage
*>(pWindow
);
190 pTabCtrl
->InsertPage(nPageID
,pPage
->GetText());
193 pTabCtrl
->SetTabPage(nPageID
,pPage
);
194 pTabCtrl
->SetHelpText(nPageID
,xP
->getToolTip());
195 pTabCtrl
->SetPageImage(nPageID
,TkResMgr::getImageFromURL(xP
->getImageURL()));
196 pTabCtrl
->SelectTabPage(nPageID
);
197 pTabCtrl
->EnablePage(nPageID
,xP
->getEnabled());
198 m_aTabPages
.push_back(xTabPage
);
201 void SAL_CALL
VCLXTabPageContainer::elementRemoved( const ::com::sun::star::container::ContainerEvent
& Event
) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
203 SolarMutexGuard aGuard
;
204 VclPtr
<TabControl
> pTabCtrl
= GetAs
<TabControl
>();
205 Reference
< ::com::sun::star::awt::tab::XTabPage
> xTabPage(Event
.Element
,uno::UNO_QUERY
);
206 if ( pTabCtrl
&& xTabPage
.is() )
208 Reference
< awt::XControl
> xControl(xTabPage
,UNO_QUERY
);
209 Reference
< awt::tab::XTabPageModel
> xP( xControl
->getModel(), UNO_QUERY
);
210 pTabCtrl
->RemovePage(xP
->getTabPageID());
211 m_aTabPages
.erase(::std::remove(m_aTabPages
.begin(),m_aTabPages
.end(),xTabPage
));
214 void SAL_CALL
VCLXTabPageContainer::elementReplaced( const ::com::sun::star::container::ContainerEvent
& /*Event*/ ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */