LibreOffice Module toolkit (master) 1
vclxtabpagecontainer.cxx
Go to the documentation of this file.
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
21#include <com/sun/star/awt/tab/XTabPageModel.hpp>
22#include <com/sun/star/awt/XControl.hpp>
23#include <o3tl/safeint.hxx>
24#include <sal/log.hxx>
25#include <helper/property.hxx>
26#include <vcl/image.hxx>
27#include <vcl/tabpage.hxx>
28#include <vcl/tabctrl.hxx>
29#include <vcl/svapp.hxx>
31
32#include <helper/tkresmgr.hxx>
33
34using namespace ::com::sun::star;
35using namespace ::com::sun::star::uno;
36using namespace ::com::sun::star::lang;
37using namespace ::com::sun::star::beans;
38using namespace ::com::sun::star::container;
39using namespace ::com::sun::star::view;
40
41
42void VCLXTabPageContainer::GetPropertyIds( std::vector< sal_uInt16 > &rIds )
43{
45}
46
48 m_aTabPageListeners( *this )
49{
50}
51
53{
54 SAL_INFO("toolkit", __FUNCTION__);
55}
56
57void SAL_CALL VCLXTabPageContainer::draw( sal_Int32 nX, sal_Int32 nY )
58{
59 SolarMutexGuard aGuard;
60 VclPtr<TabControl> pTabControl = GetAs<TabControl>();
61 if ( pTabControl )
62 {
63 TabPage *pTabPage = pTabControl->GetTabPage( sal::static_int_cast< sal_uInt16 >( pTabControl->GetCurPageId( ) ) );
64 OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() );
65 if (pTabPage && pDev)
66 {
67 ::Point aPos( nX, nY );
68 aPos = pDev->PixelToLogic( aPos );
69 pTabPage->Draw( pDev, aPos, SystemTextColorFlags::NONE );
70 }
71 }
72
73 VCLXWindow::draw( nX, nY );
74}
75
76void SAL_CALL VCLXTabPageContainer::setProperty(const OUString& PropertyName, const Any& Value )
77{
78 SolarMutexGuard aGuard;
79 VclPtr<TabControl> pTabPage = GetAs<TabControl>();
80 if ( pTabPage )
81 VCLXWindow::setProperty( PropertyName, Value );
82}
83
85{
86 VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
87 return pTabCtrl ? pTabCtrl->GetCurPageId( ) : 0;
88}
89
90void SAL_CALL VCLXTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid )
91{
92 VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
93 if ( pTabCtrl )
94 pTabCtrl->SelectTabPage(_activetabpageid);
95}
96
98{
99 VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
100 return pTabCtrl ? pTabCtrl->GetPageCount() : 0;
101}
102
103sal_Bool SAL_CALL VCLXTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex )
104{
105 return (getActiveTabPageID() == tabPageIndex);
106}
107
108Reference< css::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex )
109{
110 return (tabPageIndex >= 0 && o3tl::make_unsigned(tabPageIndex) < m_aTabPages.size()) ? m_aTabPages[tabPageIndex] : nullptr;
111}
112
113Reference< css::awt::tab::XTabPage > SAL_CALL VCLXTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID )
114{
115 SolarMutexGuard aGuard;
116 Reference< css::awt::tab::XTabPage > xTabPage;
117 for(const auto& rTabPage : m_aTabPages)
118 {
119 Reference< awt::XControl > xControl(rTabPage,UNO_QUERY );
120 Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY );
121 if ( tabPageID == xP->getTabPageID() )
122 {
123 xTabPage = rTabPage;
124 break;
125 }
126 }
127 return xTabPage;
128}
129
130void SAL_CALL VCLXTabPageContainer::addTabPageContainerListener( const Reference< css::awt::tab::XTabPageContainerListener >& listener )
131{
132 m_aTabPageListeners.addInterface( listener );
133}
134
135void SAL_CALL VCLXTabPageContainer::removeTabPageContainerListener( const Reference< css::awt::tab::XTabPageContainerListener >& listener )
136{
137 m_aTabPageListeners.removeInterface( listener );
138}
139
141{
143 VclPtr<TabControl> pTabControl = GetAs<TabControl>();
144 if ( !pTabControl )
145 return;
146
147 switch ( _rVclWindowEvent.GetId() )
148 {
149 case VclEventId::TabpageActivate:
150 {
151 sal_uLong page = reinterpret_cast<sal_uLong>(_rVclWindowEvent.GetData());
152 awt::tab::TabPageActivatedEvent aEvent(nullptr,page);
153 m_aTabPageListeners.tabPageActivated(aEvent);
154 break;
155 }
156 default:
157 aGuard.clear();
158 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
159 break;
160 }
161}
162void SAL_CALL VCLXTabPageContainer::disposing( const css::lang::EventObject& /*Source*/ )
163{
164}
165void SAL_CALL VCLXTabPageContainer::elementInserted( const css::container::ContainerEvent& Event )
166{
167 SolarMutexGuard aGuard;
168 VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
169 Reference< css::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY);
170 if ( !pTabCtrl || !xTabPage.is() )
171 return;
172
173 Reference< awt::XControl > xControl(xTabPage,UNO_QUERY );
174 Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY );
175 sal_Int16 nPageID = xP->getTabPageID();
176
177 if (!xControl->getPeer().is())
178 throw RuntimeException("No peer for tabpage container!");
179 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xControl->getPeer());
180 TabPage* pPage = static_cast<TabPage*>(pWindow.get());
181 pTabCtrl->InsertPage(nPageID,pPage->GetText());
182
183 pPage->Hide();
184 pTabCtrl->SetTabPage(nPageID,pPage);
185 pTabCtrl->SetHelpText(nPageID,xP->getToolTip());
186 pTabCtrl->SetPageImage(nPageID,TkResMgr::getImageFromURL(xP->getImageURL()));
187 pTabCtrl->SelectTabPage(nPageID);
188 pTabCtrl->SetPageEnabled(nPageID,xP->getEnabled());
189 m_aTabPages.push_back(xTabPage);
190
191}
192void SAL_CALL VCLXTabPageContainer::elementRemoved( const css::container::ContainerEvent& Event )
193{
194 SolarMutexGuard aGuard;
195 VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
196 Reference< css::awt::tab::XTabPage > xTabPage(Event.Element,uno::UNO_QUERY);
197 if ( pTabCtrl && xTabPage.is() )
198 {
199 Reference< awt::XControl > xControl(xTabPage,UNO_QUERY );
200 Reference< awt::tab::XTabPageModel > xP( xControl->getModel(), UNO_QUERY );
201 pTabCtrl->RemovePage(xP->getTabPageID());
202 m_aTabPages.erase(::std::remove(m_aTabPages.begin(),m_aTabPages.end(),xTabPage));
203 }
204}
205void SAL_CALL VCLXTabPageContainer::elementReplaced( const css::container::ContainerEvent& /*Event*/ )
206{
207}
208
209void VCLXTabPageContainer::propertiesChange(const::css::uno::Sequence<PropertyChangeEvent>& rEvents)
210{
211 SolarMutexGuard aGuard;
212 VclPtr<TabControl> pTabCtrl = GetAs<TabControl>();
213 if (!pTabCtrl)
214 return;
215
216 for (const beans::PropertyChangeEvent& rEvent : rEvents) {
217 // handle property changes for tab pages
218 Reference< css::awt::tab::XTabPageModel > xTabPageModel(rEvent.Source, uno::UNO_QUERY);
219 if (!xTabPageModel.is())
220 continue;
221
222 const sal_Int16 nId = xTabPageModel->getTabPageID();
223 if (rEvent.PropertyName == GetPropertyName(BASEPROPERTY_ENABLED)) {
224 pTabCtrl->SetPageEnabled(nId, xTabPageModel->getEnabled());
225 } else if (rEvent.PropertyName == GetPropertyName(BASEPROPERTY_TITLE)) {
226 pTabCtrl->SetPageText(nId, xTabPageModel->getTitle());
227 } else if (rEvent.PropertyName == GetPropertyName(BASEPROPERTY_IMAGEURL)) {
228 pTabCtrl->SetPageImage(nId, TkResMgr::getImageFromURL(xTabPageModel->getImageURL()));
229 }
230 }
231}
232
233/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
virtual void Draw(OutputDevice *pDev, const Point &rPos, SystemTextColorFlags nFlags) override
static OutputDevice * GetOutputDevice(const css::uno::Reference< css::awt::XDevice > &rxDevice)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
virtual ~VCLXTabPageContainer() override
virtual void SAL_CALL setActiveTabPageID(::sal_Int16 _activetabpageid) override
virtual void SAL_CALL elementInserted(const css::container::ContainerEvent &Event) override
virtual ::sal_Int16 SAL_CALL getTabPageCount() override
void SAL_CALL setProperty(const OUString &PropertyName, const css::uno::Any &Value) override
TabPageListenerMultiplexer m_aTabPageListeners
virtual void SAL_CALL removeTabPageContainerListener(const css::uno::Reference< css::awt::tab::XTabPageContainerListener > &listener) override
virtual css::uno::Reference< css::awt::tab::XTabPage > SAL_CALL getTabPage(::sal_Int16 tabPageIndex) override
virtual void SAL_CALL addTabPageContainerListener(const css::uno::Reference< css::awt::tab::XTabPageContainerListener > &listener) override
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
virtual sal_Bool SAL_CALL isTabPageActive(::sal_Int16 tabPageIndex) override
void SAL_CALL draw(sal_Int32 nX, sal_Int32 nY) override
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent) override
::std::vector< css::uno::Reference< css::awt::tab::XTabPage > > m_aTabPages
virtual css::uno::Reference< css::awt::tab::XTabPage > SAL_CALL getTabPageByID(::sal_Int16 tabPageID) override
virtual void SAL_CALL elementRemoved(const css::container::ContainerEvent &Event) override
virtual void SAL_CALL propertiesChange(const ::css::uno::Sequence< ::css::beans::PropertyChangeEvent > &aEvent) override
virtual void SAL_CALL elementReplaced(const css::container::ContainerEvent &Event) override
virtual void GetPropertyIds(std::vector< sal_uInt16 > &aIds) override
virtual ::sal_Int16 SAL_CALL getActiveTabPageID() override
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent)
Definition: vclxwindow.cxx:426
static void ImplGetPropertyIds(std::vector< sal_uInt16 > &aIds, bool bWithDefaults=false)
void SAL_CALL setProperty(const OUString &PropertyName, const css::uno::Any &Value) override
void SAL_CALL draw(sal_Int32 nX, sal_Int32 nY) override
reference_type * get() const
VclEventId GetId() const
void * GetData() const
virtual OUString GetText() const
#define SAL_INFO(area, stream)
Image getImageFromURL(const OUString &i_rImageURL)
Definition: tkresmgr.cxx:35
Value
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
sal_Int16 nId
const OUString & GetPropertyName(sal_uInt16 nPropertyId)
Definition: property.cxx:295
#define BASEPROPERTY_TITLE
Definition: property.hxx:102
#define BASEPROPERTY_IMAGEURL
Definition: property.hxx:75
#define BASEPROPERTY_ENABLED
Definition: property.hxx:77
sal_uIntPtr sal_uLong
unsigned char sal_Bool