LibreOffice Module toolkit (master) 1
tabpagemodel.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
22#include <vcl/svapp.hxx>
23#include <helper/property.hxx>
24#include <com/sun/star/awt/UnoControlDialogModelProvider.hpp>
25#include <com/sun/star/awt/tab/XTabPage.hpp>
26#include <com/sun/star/beans/XPropertySet.hpp>
27#include <com/sun/star/uno/XComponentContext.hpp>
29#include <tools/debug.hxx>
30#include <vcl/outdev.hxx>
31
34
36
37using namespace ::com::sun::star;
38using namespace ::com::sun::star::uno;
39using namespace ::com::sun::star::awt;
40
41UnoControlTabPageModel::UnoControlTabPageModel( Reference< XComponentContext > const & i_factory )
42 :ControlModelContainerBase( i_factory )
43{
44 ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
45 ImplRegisterProperty( BASEPROPERTY_TITLE );
46 ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
47 ImplRegisterProperty( BASEPROPERTY_HELPURL );
48 ImplRegisterProperty( BASEPROPERTY_USERFORMCONTAINEES );
49 ImplRegisterProperty( BASEPROPERTY_HSCROLL );
50 ImplRegisterProperty( BASEPROPERTY_VSCROLL );
51 ImplRegisterProperty( BASEPROPERTY_SCROLLWIDTH );
52 ImplRegisterProperty( BASEPROPERTY_SCROLLHEIGHT );
53 ImplRegisterProperty( BASEPROPERTY_SCROLLTOP );
54 ImplRegisterProperty( BASEPROPERTY_SCROLLLEFT );
55 ImplRegisterProperty( BASEPROPERTY_IMAGEURL );
56}
57
59{
60 return "stardiv.Toolkit.UnoControlTabPageModel";
61}
62
63css::uno::Sequence< OUString > SAL_CALL UnoControlTabPageModel::getSupportedServiceNames()
64{
65 css::uno::Sequence< OUString > aNames = ControlModelContainerBase::getSupportedServiceNames( );
66 aNames.realloc( aNames.getLength() + 1 );
67 aNames.getArray()[ aNames.getLength() - 1 ] = "com.sun.star.awt.tab.UnoControlTabPageModel";
68 return aNames;
69}
70
72{
73 return "com.sun.star.awt.tab.UnoControlTabPageModel";
74}
75
77{
78 Any aAny;
79
80 switch ( nPropId )
81 {
83 aAny <<= OUString("com.sun.star.awt.tab.UnoControlTabPage");
84 break;
86 {
87 // We do not have here any usercontainers (yet?), but let's return empty container back
88 // so normal properties could be set without triggering UnknownPropertyException
89 aAny <<= uno::Reference< XNameContainer >();
90 break;
91 }
92 default:
94 }
95
96 return aAny;
97}
98
100{
101 static UnoPropertyArrayHelper aHelper( ImplGetPropertyIds() );
102 return aHelper;
103}
104// beans::XMultiPropertySet
105uno::Reference< beans::XPropertySetInfo > UnoControlTabPageModel::getPropertySetInfo( )
106{
107 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
108 return xInfo;
109}
111void SAL_CALL UnoControlTabPageModel::initialize (const Sequence<Any>& rArguments)
112{
113 sal_Int16 nPageId = -1;
114 if ( rArguments.getLength() == 1 )
115 {
116 if ( !( rArguments[ 0 ] >>= nPageId ))
117 throw lang::IllegalArgumentException();
119 }
120 else if ( rArguments.getLength() == 2 )
121 {
122 if ( !( rArguments[ 0 ] >>= nPageId ))
123 throw lang::IllegalArgumentException();
125 OUString sURL;
126 if ( !( rArguments[ 1 ] >>= sURL ))
127 throw lang::IllegalArgumentException();
128 Reference<container::XNameContainer > xDialogModel = awt::UnoControlDialogModelProvider::create( m_xContext, sURL );
129 if ( xDialogModel.is() )
130 {
131 const Sequence< OUString> aNames = xDialogModel->getElementNames();
132 for(const OUString& rName : aNames)
133 {
134 try
135 {
136 Any aElement(xDialogModel->getByName(rName));
137 xDialogModel->removeByName(rName);
138 insertByName(rName,aElement);
139 }
140 catch(const Exception&) {}
141 }
142 Reference<XPropertySet> xDialogProp(xDialogModel,UNO_QUERY);
143 if ( xDialogProp.is() )
144 {
145 static constexpr OUStringLiteral s_sResourceResolver = u"ResourceResolver";
146 setPropertyValue(s_sResourceResolver,xDialogProp->getPropertyValue(s_sResourceResolver));
150 }
151 }
152 }
153 else
154 m_nTabPageId = -1;
155}
156
157
158UnoControlTabPage::UnoControlTabPage( const uno::Reference< uno::XComponentContext >& rxContext )
159 :UnoControlTabPage_Base(rxContext)
160 ,m_bWindowListener(false)
161{
162 maComponentInfos.nWidth = 280;
163 maComponentInfos.nHeight = 400;
164}
166{
167}
168
170{
171 return "TabPageModel";
172}
173
175{
176 return "stardiv.Toolkit.UnoControlTabPage";
177}
178
179sal_Bool SAL_CALL UnoControlTabPage::supportsService(OUString const & ServiceName)
180{
182}
183
184css::uno::Sequence<OUString> SAL_CALL UnoControlTabPage::getSupportedServiceNames()
185{
186 return { "com.sun.star.awt.tab.UnoControlTabPage" };
187}
188
190{
191 SolarMutexGuard aSolarGuard;
192
193 lang::EventObject aEvt;
194 aEvt.Source = static_cast< ::cppu::OWeakObject* >( this );
196}
197
198void SAL_CALL UnoControlTabPage::disposing( const lang::EventObject& Source )
199{
201}
202
203void UnoControlTabPage::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer )
204{
205 SolarMutexGuard aSolarGuard;
206 ImplUpdateResourceResolver();
207
208 UnoControlContainer::createPeer( rxToolkit, rParentPeer );
209
210 Reference < tab::XTabPage > xTabPage( getPeer(), UNO_QUERY );
211 if ( xTabPage.is() )
212 {
213 if ( !m_bWindowListener )
214 {
215 Reference< XWindowListener > xWL(this);
216 addWindowListener( xWL );
217 m_bWindowListener = true;
218 }
219 }
220}
221
222static ::Size ImplMapPixelToAppFont( OutputDevice const * pOutDev, const ::Size& aSize )
223{
224 ::Size aTmp = pOutDev->PixelToLogic(aSize, MapMode(MapUnit::MapAppFont));
225 return aTmp;
226}
227// css::awt::XWindowListener
228void SAL_CALL UnoControlTabPage::windowResized( const css::awt::WindowEvent& e )
229{
231 DBG_ASSERT( pOutDev, "Missing Default Device!" );
232 if ( !pOutDev || mbSizeModified )
233 return;
234
235 // Currently we are simply using MapUnit::MapAppFont
236 ::Size aAppFontSize( e.Width, e.Height );
237
238 Reference< XControl > xDialogControl( *this, UNO_QUERY_THROW );
239 Reference< XDevice > xDialogDevice( xDialogControl->getPeer(), UNO_QUERY );
240 OSL_ENSURE( xDialogDevice.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" );
241 if ( xDialogDevice.is() )
242 {
243 DeviceInfo aDeviceInfo( xDialogDevice->getInfo() );
244 aAppFontSize.AdjustWidth( -(aDeviceInfo.LeftInset + aDeviceInfo.RightInset) );
245 aAppFontSize.AdjustHeight( -(aDeviceInfo.TopInset + aDeviceInfo.BottomInset) );
246 }
247
248 aAppFontSize = ImplMapPixelToAppFont( pOutDev, aAppFontSize );
249
250 // Remember that changes have been done by listener. No need to
251 // update the position because of property change event.
252 mbSizeModified = true;
253 // Properties in a sequence must be sorted!
254 Sequence< OUString > aProps{ "Height", "Width" };
255 Sequence< Any > aValues{ Any(aAppFontSize.Height()), Any(aAppFontSize.Width()) };
256
257 ImplSetPropertyValues( aProps, aValues, true );
258 mbSizeModified = false;
259
260}
261
262void SAL_CALL UnoControlTabPage::windowMoved( const css::awt::WindowEvent& e )
263{
265 DBG_ASSERT( pOutDev, "Missing Default Device!" );
266 if ( !pOutDev || mbPosModified )
267 return;
268
269 // Currently we are simply using MapUnit::MapAppFont
270 ::Size aTmp( e.X, e.Y );
271 aTmp = ImplMapPixelToAppFont( pOutDev, aTmp );
272
273 // Remember that changes have been done by listener. No need to
274 // update the position because of property change event.
275 mbPosModified = true;
276 Sequence< OUString > aProps{ "PositionX", "PositionY" };
277 Sequence< Any > aValues{ Any(aTmp.Width()), Any(aTmp.Height()) };
278
279 ImplSetPropertyValues( aProps, aValues, true );
280 mbPosModified = false;
281
282}
283
284void SAL_CALL UnoControlTabPage::windowShown( const css::lang::EventObject& ) {}
285
286void SAL_CALL UnoControlTabPage::windowHidden( const css::lang::EventObject& ) {}
287
288extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
290 css::uno::XComponentContext *context,
291 css::uno::Sequence<css::uno::Any> const &)
292{
293 return cppu::acquire(new UnoControlTabPageModel(context));
294}
295
296extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
298 css::uno::XComponentContext *context,
299 css::uno::Sequence<css::uno::Any> const &)
300{
301 return cppu::acquire(new UnoControlTabPage(context));
302}
303
304/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
sal_uInt16 nPageId
static OutputDevice * GetDefaultDevice()
void SAL_CALL dispose() override
void SAL_CALL disposing(const css::lang::EventObject &Source) override
void SAL_CALL insertByName(const OUString &aName, const css::uno::Any &aElement) override
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
tools::Long AdjustWidth(tools::Long n)
constexpr tools::Long Width() const
void SAL_CALL createPeer(const css::uno::Reference< css::awt::XToolkit > &Toolkit, const css::uno::Reference< css::awt::XWindowPeer > &Parent) override
virtual css::uno::Any ImplGetDefaultValue(sal_uInt16 nPropId) const
OUString SAL_CALL getImplementationName() override
css::uno::Any ImplGetDefaultValue(sal_uInt16 nPropId) const override
OUString SAL_CALL getServiceName() override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &rArguments) override
::cppu::IPropertyArrayHelper & getInfoHelper() override
css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
UnoControlTabPageModel(css::uno::Reference< css::uno::XComponentContext > const &i_factory)
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
OUString GetComponentServiceName() const override
virtual ~UnoControlTabPage() override
void SAL_CALL dispose() override
void SAL_CALL createPeer(const css::uno::Reference< css::awt::XToolkit > &Toolkit, const css::uno::Reference< css::awt::XWindowPeer > &Parent) override
void SAL_CALL disposing(const css::lang::EventObject &Source) override
virtual void SAL_CALL windowHidden(const css::lang::EventObject &e) override
virtual void SAL_CALL windowShown(const css::lang::EventObject &e) override
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL windowMoved(const css::awt::WindowEvent &e) override
UnoControlTabPage(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
virtual void SAL_CALL windowResized(const css::awt::WindowEvent &e) override
#define DBG_ASSERT(sCon, aError)
float u
Any aHelper
@ Exception
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
const OUString & GetPropertyName(sal_uInt16 nPropertyId)
Definition: property.cxx:295
#define BASEPROPERTY_HSCROLL
Definition: property.hxx:45
#define BASEPROPERTY_TITLE
Definition: property.hxx:102
#define BASEPROPERTY_HELPURL
Definition: property.hxx:91
#define BASEPROPERTY_SCROLLWIDTH
Definition: property.hxx:197
#define BASEPROPERTY_IMAGEURL
Definition: property.hxx:75
#define BASEPROPERTY_DEFAULTCONTROL
Definition: property.hxx:52
#define BASEPROPERTY_SCROLLLEFT
Definition: property.hxx:200
#define BASEPROPERTY_VSCROLL
Definition: property.hxx:46
#define BASEPROPERTY_SCROLLHEIGHT
Definition: property.hxx:198
#define BASEPROPERTY_HELPTEXT
Definition: property.hxx:106
#define BASEPROPERTY_SCROLLTOP
Definition: property.hxx:199
#define BASEPROPERTY_USERFORMCONTAINEES
Definition: property.hxx:192
::Size ImplMapPixelToAppFont(OutputDevice const *pOutDev, const ::Size &aSize)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * stardiv_Toolkit_UnoControlTabPage_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * stardiv_Toolkit_UnoControlTabPageModel_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
unsigned char sal_Bool