Line data Source code
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 :
20 : #include <toolkit/controls/tabpagemodel.hxx>
21 :
22 : #include <vcl/svapp.hxx>
23 : #include <vcl/window.hxx>
24 : #include <vcl/wall.hxx>
25 : #include <toolkit/helper/property.hxx>
26 : #include <toolkit/helper/unopropertyarrayhelper.hxx>
27 : #include <toolkit/controls/stdtabcontroller.hxx>
28 : #include <com/sun/star/awt/UnoControlDialogModelProvider.hpp>
29 : #include <com/sun/star/awt/tab/XTabPage.hpp>
30 : #include <com/sun/star/beans/XPropertySet.hpp>
31 : #include <cppuhelper/supportsservice.hxx>
32 : #include <cppuhelper/typeprovider.hxx>
33 : #include <tools/debug.hxx>
34 : #include <tools/diagnose_ex.h>
35 : #include <comphelper/sequence.hxx>
36 : #include <vcl/outdev.hxx>
37 :
38 : #include <toolkit/helper/vclunohelper.hxx>
39 : #include <unotools/ucbstreamhelper.hxx>
40 : #include <vcl/graph.hxx>
41 : #include <vcl/image.hxx>
42 : #include <toolkit/controls/geometrycontrolmodel.hxx>
43 : #include <toolkit/controls/controlmodelcontainerbase.hxx>
44 : #include <toolkit/controls/unocontrolcontainer.hxx>
45 : #include <cppuhelper/basemutex.hxx>
46 : #include <cppuhelper/implbase2.hxx>
47 :
48 : using namespace ::com::sun::star;
49 : using namespace ::com::sun::star::uno;
50 : using namespace ::com::sun::star::awt;
51 :
52 0 : UnoControlTabPageModel::UnoControlTabPageModel( Reference< XComponentContext > const & i_factory )
53 0 : :ControlModelContainerBase( i_factory )
54 : {
55 0 : ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
56 0 : ImplRegisterProperty( BASEPROPERTY_TITLE );
57 0 : ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
58 0 : ImplRegisterProperty( BASEPROPERTY_HELPURL );
59 0 : }
60 :
61 0 : OUString SAL_CALL UnoControlTabPageModel::getImplementationName() throw(css::uno::RuntimeException, std::exception)
62 : {
63 0 : return OUString("stardiv.Toolkit.UnoControlTabPageModel");
64 : }
65 :
66 0 : css::uno::Sequence< OUString > SAL_CALL UnoControlTabPageModel::getSupportedServiceNames() throw(css::uno::RuntimeException, std::exception)
67 : {
68 0 : css::uno::Sequence< OUString > aNames = ControlModelContainerBase::getSupportedServiceNames( );
69 0 : aNames.realloc( aNames.getLength() + 1 );
70 0 : aNames[ aNames.getLength() - 1 ] = OUString("com.sun.star.awt.tab.UnoControlTabPageModel");
71 0 : return aNames;
72 : }
73 :
74 0 : OUString UnoControlTabPageModel::getServiceName( ) throw(RuntimeException, std::exception)
75 : {
76 0 : return OUString("com.sun.star.awt.tab.UnoControlTabPageModel");
77 : }
78 :
79 0 : Any UnoControlTabPageModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
80 : {
81 0 : Any aAny;
82 :
83 0 : switch ( nPropId )
84 : {
85 : case BASEPROPERTY_DEFAULTCONTROL:
86 0 : aAny <<= OUString("com.sun.star.awt.tab.UnoControlTabPage");
87 0 : break;
88 : default:
89 0 : aAny = UnoControlModel::ImplGetDefaultValue( nPropId );
90 : }
91 :
92 0 : return aAny;
93 : }
94 :
95 0 : ::cppu::IPropertyArrayHelper& UnoControlTabPageModel::getInfoHelper()
96 : {
97 : static UnoPropertyArrayHelper* pHelper = NULL;
98 0 : if ( !pHelper )
99 : {
100 0 : Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
101 0 : pHelper = new UnoPropertyArrayHelper( aIDs );
102 : }
103 0 : return *pHelper;
104 : }
105 : // beans::XMultiPropertySet
106 0 : uno::Reference< beans::XPropertySetInfo > UnoControlTabPageModel::getPropertySetInfo( ) throw(uno::RuntimeException, std::exception)
107 : {
108 0 : static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
109 0 : return xInfo;
110 : }
111 : ////----- XInitialization -------------------------------------------------------------------
112 0 : void SAL_CALL UnoControlTabPageModel::initialize (const Sequence<Any>& rArguments)
113 : throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException, std::exception)
114 : {
115 0 : sal_Int16 nPageId = -1;
116 0 : if ( rArguments.getLength() == 1 )
117 : {
118 0 : if ( !( rArguments[ 0 ] >>= nPageId ))
119 0 : throw lang::IllegalArgumentException();
120 0 : m_nTabPageId = nPageId;
121 : }
122 0 : else if ( rArguments.getLength() == 2 )
123 : {
124 0 : if ( !( rArguments[ 0 ] >>= nPageId ))
125 0 : throw lang::IllegalArgumentException();
126 0 : m_nTabPageId = nPageId;
127 0 : OUString sURL;
128 0 : if ( !( rArguments[ 1 ] >>= sURL ))
129 0 : throw lang::IllegalArgumentException();
130 0 : Reference<container::XNameContainer > xDialogModel = awt::UnoControlDialogModelProvider::create( m_xContext, sURL );
131 0 : if ( xDialogModel.is() )
132 : {
133 0 : Sequence< OUString> aNames = xDialogModel->getElementNames();
134 0 : const OUString* pIter = aNames.getConstArray();
135 0 : const OUString* pEnd = pIter + aNames.getLength();
136 0 : for(;pIter != pEnd;++pIter)
137 : {
138 : try
139 : {
140 0 : Any aElement(xDialogModel->getByName(*pIter));
141 0 : xDialogModel->removeByName(*pIter);
142 0 : insertByName(*pIter,aElement);
143 : }
144 0 : catch(const Exception& ex)
145 : {
146 : (void)ex;
147 : }
148 : }
149 0 : Reference<XPropertySet> xDialogProp(xDialogModel,UNO_QUERY);
150 0 : if ( xDialogProp.is() )
151 : {
152 0 : static const OUString s_sResourceResolver("ResourceResolver");
153 0 : Reference<XPropertySet> xThis(*this,UNO_QUERY);
154 0 : xThis->setPropertyValue(s_sResourceResolver,xDialogProp->getPropertyValue(s_sResourceResolver));
155 0 : xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_TITLE),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_TITLE)));
156 0 : xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPTEXT)));
157 0 : xThis->setPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL),xDialogProp->getPropertyValue(GetPropertyName(BASEPROPERTY_HELPURL)));
158 0 : }
159 0 : }
160 : }
161 : else
162 0 : m_nTabPageId = -1;
163 0 : }
164 :
165 :
166 0 : UnoControlTabPage::UnoControlTabPage( const uno::Reference< uno::XComponentContext >& rxContext )
167 : :UnoControlTabPage_Base(rxContext)
168 0 : ,m_bWindowListener(false)
169 : {
170 0 : maComponentInfos.nWidth = 280;
171 0 : maComponentInfos.nHeight = 400;
172 0 : }
173 0 : UnoControlTabPage::~UnoControlTabPage()
174 : {
175 0 : }
176 :
177 0 : OUString UnoControlTabPage::GetComponentServiceName()
178 : {
179 0 : return OUString("TabPageModel");
180 : }
181 :
182 0 : OUString SAL_CALL UnoControlTabPage::getImplementationName()
183 : throw (css::uno::RuntimeException, std::exception)
184 : {
185 0 : return OUString("stardiv.Toolkit.UnoControlTabPage");
186 : }
187 :
188 0 : sal_Bool SAL_CALL UnoControlTabPage::supportsService(OUString const & ServiceName)
189 : throw (css::uno::RuntimeException, std::exception)
190 : {
191 0 : return cppu::supportsService(this, ServiceName);
192 : }
193 :
194 0 : css::uno::Sequence<OUString> SAL_CALL UnoControlTabPage::getSupportedServiceNames()
195 : throw (css::uno::RuntimeException, std::exception)
196 : {
197 0 : css::uno::Sequence< OUString > aSeq(1);
198 0 : aSeq[0] = OUString("com.sun.star.awt.tab.UnoControlTabPage");
199 0 : return aSeq;
200 : }
201 :
202 0 : void UnoControlTabPage::dispose() throw(RuntimeException, std::exception)
203 : {
204 0 : SolarMutexGuard aSolarGuard;
205 :
206 0 : lang::EventObject aEvt;
207 0 : aEvt.Source = static_cast< ::cppu::OWeakObject* >( this );
208 0 : ControlContainerBase::dispose();
209 0 : }
210 :
211 0 : void SAL_CALL UnoControlTabPage::disposing( const lang::EventObject& Source )throw(RuntimeException, std::exception)
212 : {
213 0 : ControlContainerBase::disposing( Source );
214 0 : }
215 :
216 0 : void UnoControlTabPage::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) throw(RuntimeException, std::exception)
217 : {
218 0 : SolarMutexGuard aSolarGuard;
219 0 : ImplUpdateResourceResolver();
220 :
221 0 : UnoControlContainer::createPeer( rxToolkit, rParentPeer );
222 :
223 0 : Reference < tab::XTabPage > xTabPage( getPeer(), UNO_QUERY );
224 0 : if ( xTabPage.is() )
225 : {
226 0 : if ( !m_bWindowListener )
227 : {
228 0 : Reference< XWindowListener > xWL( static_cast< cppu::OWeakObject*>( this ), UNO_QUERY );
229 0 : addWindowListener( xWL );
230 0 : m_bWindowListener = true;
231 : }
232 0 : }
233 0 : }
234 :
235 0 : static ::Size ImplMapPixelToAppFont( OutputDevice* pOutDev, const ::Size& aSize )
236 : {
237 0 : ::Size aTmp = pOutDev->PixelToLogic( aSize, MAP_APPFONT );
238 0 : return aTmp;
239 : }
240 : // ::com::sun::star::awt::XWindowListener
241 0 : void SAL_CALL UnoControlTabPage::windowResized( const ::com::sun::star::awt::WindowEvent& e )
242 : throw (::com::sun::star::uno::RuntimeException, std::exception)
243 : {
244 0 : OutputDevice*pOutDev = Application::GetDefaultDevice();
245 : DBG_ASSERT( pOutDev, "Missing Default Device!" );
246 0 : if ( pOutDev && !mbSizeModified )
247 : {
248 : // Currentley we are simply using MAP_APPFONT
249 0 : ::Size aAppFontSize( e.Width, e.Height );
250 :
251 0 : Reference< XControl > xDialogControl( *this, UNO_QUERY_THROW );
252 0 : Reference< XDevice > xDialogDevice( xDialogControl->getPeer(), UNO_QUERY );
253 : OSL_ENSURE( xDialogDevice.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" );
254 0 : if ( xDialogDevice.is() )
255 : {
256 0 : DeviceInfo aDeviceInfo( xDialogDevice->getInfo() );
257 0 : aAppFontSize.Width() -= aDeviceInfo.LeftInset + aDeviceInfo.RightInset;
258 0 : aAppFontSize.Height() -= aDeviceInfo.TopInset + aDeviceInfo.BottomInset;
259 : }
260 :
261 0 : aAppFontSize = ImplMapPixelToAppFont( pOutDev, aAppFontSize );
262 :
263 : // Remember that changes have been done by listener. No need to
264 : // update the position because of property change event.
265 0 : mbSizeModified = true;
266 0 : Sequence< OUString > aProps( 2 );
267 0 : Sequence< Any > aValues( 2 );
268 : // Properties in a sequence must be sorted!
269 0 : aProps[0] = "Height";
270 0 : aProps[1] = "Width";
271 0 : aValues[0] <<= aAppFontSize.Height();
272 0 : aValues[1] <<= aAppFontSize.Width();
273 :
274 0 : ImplSetPropertyValues( aProps, aValues, true );
275 0 : mbSizeModified = false;
276 : }
277 0 : }
278 :
279 0 : void SAL_CALL UnoControlTabPage::windowMoved( const ::com::sun::star::awt::WindowEvent& e )
280 : throw (::com::sun::star::uno::RuntimeException, std::exception)
281 : {
282 0 : OutputDevice*pOutDev = Application::GetDefaultDevice();
283 : DBG_ASSERT( pOutDev, "Missing Default Device!" );
284 0 : if ( pOutDev && !mbPosModified )
285 : {
286 : // Currentley we are simply using MAP_APPFONT
287 0 : ::Size aTmp( e.X, e.Y );
288 0 : aTmp = ImplMapPixelToAppFont( pOutDev, aTmp );
289 :
290 : // Remember that changes have been done by listener. No need to
291 : // update the position because of property change event.
292 0 : mbPosModified = true;
293 0 : Sequence< OUString > aProps( 2 );
294 0 : Sequence< Any > aValues( 2 );
295 0 : aProps[0] = "PositionX";
296 0 : aProps[1] = "PositionY";
297 0 : aValues[0] <<= aTmp.Width();
298 0 : aValues[1] <<= aTmp.Height();
299 :
300 0 : ImplSetPropertyValues( aProps, aValues, true );
301 0 : mbPosModified = false;
302 : }
303 0 : }
304 :
305 0 : void SAL_CALL UnoControlTabPage::windowShown( const ::com::sun::star::lang::EventObject& e )
306 : throw (::com::sun::star::uno::RuntimeException, std::exception)
307 : {
308 : (void)e;
309 0 : }
310 :
311 0 : void SAL_CALL UnoControlTabPage::windowHidden( const ::com::sun::star::lang::EventObject& e )
312 : throw (::com::sun::star::uno::RuntimeException, std::exception)
313 : {
314 : (void)e;
315 0 : }
316 :
317 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
318 0 : stardiv_Toolkit_UnoControlTabPageModel_get_implementation(
319 : css::uno::XComponentContext *context,
320 : css::uno::Sequence<css::uno::Any> const &)
321 : {
322 0 : return cppu::acquire(new UnoControlTabPageModel(context));
323 : }
324 :
325 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
326 0 : stardiv_Toolkit_UnoControlTabPage_get_implementation(
327 : css::uno::XComponentContext *context,
328 : css::uno::Sequence<css::uno::Any> const &)
329 : {
330 0 : return cppu::acquire(new UnoControlTabPage(context));
331 : }
332 :
333 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|