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 :
21 : #include <vcl/svapp.hxx>
22 : #include <vcl/window.hxx>
23 : #include <vcl/wall.hxx>
24 : #include <osl/mutex.hxx>
25 : #include <toolkit/controls/dialogcontrol.hxx>
26 : #include <toolkit/helper/property.hxx>
27 : #include <toolkit/helper/unopropertyarrayhelper.hxx>
28 : #include <toolkit/controls/stdtabcontroller.hxx>
29 : #include <com/sun/star/awt/PosSize.hpp>
30 : #include <com/sun/star/awt/WindowAttribute.hpp>
31 : #include <com/sun/star/resource/XStringResourceResolver.hpp>
32 : #include <com/sun/star/graphic/XGraphicProvider.hpp>
33 : #include <cppuhelper/typeprovider.hxx>
34 : #include <tools/debug.hxx>
35 : #include <tools/diagnose_ex.h>
36 : #include <comphelper/sequence.hxx>
37 : #include <vcl/outdev.hxx>
38 :
39 : #include <toolkit/helper/vclunohelper.hxx>
40 : #include <unotools/ucbstreamhelper.hxx>
41 : #include <vcl/graph.hxx>
42 : #include <vcl/image.hxx>
43 : #include <map>
44 : #include <boost/unordered_map.hpp>
45 : #include <cppuhelper/implbase1.hxx>
46 : #include <algorithm>
47 : #include <functional>
48 : #include "osl/file.hxx"
49 :
50 : #include <vcl/tabctrl.hxx>
51 : #include <toolkit/awt/vclxwindows.hxx>
52 : #include "toolkit/controls/unocontrols.hxx"
53 :
54 : using namespace ::com::sun::star;
55 : using namespace ::com::sun::star::uno;
56 : using namespace ::com::sun::star::awt;
57 : using namespace ::com::sun::star::lang;
58 : using namespace ::com::sun::star::container;
59 : using namespace ::com::sun::star::beans;
60 : using namespace ::com::sun::star::util;
61 :
62 : #define PROPERTY_DIALOGSOURCEURL OUString( "DialogSourceURL" )
63 : #define PROPERTY_IMAGEURL OUString( "ImageURL" )
64 : #define PROPERTY_GRAPHIC OUString( "Graphic" )
65 : //
66 :
67 : // we probably will need both a hash of control models and hash of controls
68 : // => use some template magic
69 :
70 : typedef ::cppu::WeakImplHelper1< container::XNameContainer > SimpleNameContainer_BASE;
71 :
72 : template< typename T >
73 23 : class SimpleNamedThingContainer : public SimpleNameContainer_BASE
74 : {
75 : typedef boost::unordered_map< OUString, Reference< T >, OUStringHash,
76 : ::std::equal_to< OUString > > NamedThingsHash;
77 : NamedThingsHash things;
78 : ::osl::Mutex m_aMutex;
79 : public:
80 : // ::com::sun::star::container::XNameContainer, XNameReplace, XNameAccess
81 0 : virtual void SAL_CALL replaceByName( const OUString& aName, const Any& aElement ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
82 : {
83 0 : ::osl::MutexGuard aGuard( m_aMutex );
84 0 : if ( !hasByName( aName ) )
85 0 : throw NoSuchElementException();
86 0 : Reference< T > xElement;
87 0 : if ( ! ( aElement >>= xElement ) )
88 0 : throw IllegalArgumentException();
89 0 : things[ aName ] = xElement;
90 0 : }
91 9 : virtual Any SAL_CALL getByName( const OUString& aName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
92 : {
93 9 : ::osl::MutexGuard aGuard( m_aMutex );
94 9 : if ( !hasByName( aName ) )
95 0 : throw NoSuchElementException();
96 9 : return uno::makeAny( things[ aName ] );
97 : }
98 1 : virtual Sequence< OUString > SAL_CALL getElementNames( ) throw(RuntimeException)
99 : {
100 1 : ::osl::MutexGuard aGuard( m_aMutex );
101 1 : Sequence< OUString > aResult( things.size() );
102 1 : typename NamedThingsHash::iterator it = things.begin();
103 1 : typename NamedThingsHash::iterator it_end = things.end();
104 1 : OUString* pName = aResult.getArray();
105 3 : for (; it != it_end; ++it, ++pName )
106 2 : *pName = it->first;
107 1 : return aResult;
108 : }
109 58 : virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) throw(RuntimeException)
110 : {
111 58 : ::osl::MutexGuard aGuard( m_aMutex );
112 58 : return ( things.find( aName ) != things.end() );
113 : }
114 28 : virtual void SAL_CALL insertByName( const OUString& aName, const Any& aElement ) throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
115 : {
116 28 : ::osl::MutexGuard aGuard( m_aMutex );
117 28 : if ( hasByName( aName ) )
118 0 : throw ElementExistException();
119 56 : Reference< T > xElement;
120 28 : if ( ! ( aElement >>= xElement ) )
121 0 : throw IllegalArgumentException();
122 56 : things[ aName ] = xElement;
123 28 : }
124 7 : virtual void SAL_CALL removeByName( const OUString& aName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
125 : {
126 7 : ::osl::MutexGuard aGuard( m_aMutex );
127 7 : if ( !hasByName( aName ) )
128 0 : throw NoSuchElementException();
129 7 : things.erase( things.find( aName ) );
130 7 : }
131 0 : virtual Type SAL_CALL getElementType( ) throw (RuntimeException)
132 : {
133 0 : return T::static_type( NULL );
134 : }
135 0 : virtual ::sal_Bool SAL_CALL hasElements( ) throw (RuntimeException)
136 : {
137 0 : ::osl::MutexGuard aGuard( m_aMutex );
138 0 : return ( things.size() > 0 );
139 : }
140 : };
141 :
142 : ////HELPER
143 : OUString getPhysicalLocation( const ::com::sun::star::uno::Any& rbase, const ::com::sun::star::uno::Any& rUrl );
144 :
145 : // ----------------------------------------------------
146 : // class UnoControlDialogModel
147 : // ----------------------------------------------------
148 9 : UnoControlDialogModel::UnoControlDialogModel( const Reference< XComponentContext >& rxContext )
149 9 : :ControlModelContainerBase( rxContext )
150 : {
151 9 : ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
152 : // ImplRegisterProperty( BASEPROPERTY_BORDER );
153 9 : ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
154 9 : ImplRegisterProperty( BASEPROPERTY_ENABLED );
155 9 : ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR );
156 : // ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
157 9 : ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
158 9 : ImplRegisterProperty( BASEPROPERTY_HELPURL );
159 9 : ImplRegisterProperty( BASEPROPERTY_TITLE );
160 9 : ImplRegisterProperty( BASEPROPERTY_SIZEABLE );
161 9 : ImplRegisterProperty( BASEPROPERTY_DESKTOP_AS_PARENT );
162 9 : ImplRegisterProperty( BASEPROPERTY_DECORATION );
163 9 : ImplRegisterProperty( BASEPROPERTY_DIALOGSOURCEURL );
164 9 : ImplRegisterProperty( BASEPROPERTY_GRAPHIC );
165 9 : ImplRegisterProperty( BASEPROPERTY_IMAGEURL );
166 9 : ImplRegisterProperty( BASEPROPERTY_HSCROLL );
167 9 : ImplRegisterProperty( BASEPROPERTY_VSCROLL );
168 9 : ImplRegisterProperty( BASEPROPERTY_SCROLLWIDTH );
169 9 : ImplRegisterProperty( BASEPROPERTY_SCROLLHEIGHT );
170 9 : ImplRegisterProperty( BASEPROPERTY_SCROLLTOP );
171 9 : ImplRegisterProperty( BASEPROPERTY_SCROLLLEFT );
172 :
173 9 : Any aBool;
174 9 : aBool <<= (sal_Bool) sal_True;
175 9 : ImplRegisterProperty( BASEPROPERTY_MOVEABLE, aBool );
176 9 : ImplRegisterProperty( BASEPROPERTY_CLOSEABLE, aBool );
177 : // #TODO separate class for 'UserForm' ( instead of re-using Dialog ? )
178 18 : uno::Reference< XNameContainer > xNameCont = new SimpleNamedThingContainer< XControlModel >();
179 18 : ImplRegisterProperty( BASEPROPERTY_USERFORMCONTAINEES, uno::makeAny( xNameCont ) );
180 9 : }
181 :
182 1 : UnoControlDialogModel::UnoControlDialogModel( const UnoControlDialogModel& rModel )
183 1 : : ControlModelContainerBase( rModel )
184 : {
185 : // need to clone BASEPROPERTY_USERFORMCONTAINEES too
186 1 : Reference< XNameContainer > xSrcNameCont( const_cast< UnoControlDialogModel& >(rModel).getPropertyValue( GetPropertyName( BASEPROPERTY_USERFORMCONTAINEES ) ), UNO_QUERY );
187 2 : Reference<XNameContainer > xNameCont( new SimpleNamedThingContainer< XControlModel >() );
188 :
189 2 : uno::Sequence< OUString > sNames = xSrcNameCont->getElementNames();
190 1 : OUString* pName = sNames.getArray();
191 1 : OUString* pNamesEnd = pName + sNames.getLength();
192 3 : for ( ; pName != pNamesEnd; ++pName )
193 : {
194 2 : if ( xSrcNameCont->hasByName( *pName ) )
195 2 : xNameCont->insertByName( *pName, xSrcNameCont->getByName( *pName ) );
196 : }
197 2 : setFastPropertyValue_NoBroadcast( BASEPROPERTY_USERFORMCONTAINEES, makeAny( xNameCont ) );
198 1 : }
199 :
200 4 : UnoControlDialogModel::~UnoControlDialogModel()
201 : {
202 4 : }
203 :
204 1 : UnoControlModel* UnoControlDialogModel::Clone() const
205 : {
206 : // clone the container itself
207 1 : UnoControlDialogModel* pClone = new UnoControlDialogModel( *this );
208 :
209 1 : Clone_Impl(*pClone);
210 :
211 1 : return pClone;
212 : }
213 :
214 :
215 0 : OUString UnoControlDialogModel::getServiceName( ) throw(RuntimeException)
216 : {
217 0 : return OUString::createFromAscii( szServiceName_UnoControlDialogModel );
218 : }
219 :
220 245 : Any UnoControlDialogModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
221 : {
222 245 : Any aAny;
223 :
224 245 : switch ( nPropId )
225 : {
226 : case BASEPROPERTY_DEFAULTCONTROL:
227 9 : aAny <<= OUString::createFromAscii( szServiceName_UnoControlDialog );
228 9 : break;
229 : case BASEPROPERTY_SCROLLWIDTH:
230 : case BASEPROPERTY_SCROLLHEIGHT:
231 : case BASEPROPERTY_SCROLLTOP:
232 : case BASEPROPERTY_SCROLLLEFT:
233 44 : aAny <<= sal_Int32(0);
234 44 : break;
235 : default:
236 192 : aAny = UnoControlModel::ImplGetDefaultValue( nPropId );
237 : }
238 :
239 245 : return aAny;
240 : }
241 :
242 3213 : ::cppu::IPropertyArrayHelper& UnoControlDialogModel::getInfoHelper()
243 : {
244 : static UnoPropertyArrayHelper* pHelper = NULL;
245 3213 : if ( !pHelper )
246 : {
247 3 : Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
248 3 : pHelper = new UnoPropertyArrayHelper( aIDs );
249 : }
250 3213 : return *pHelper;
251 : }
252 :
253 : // XMultiPropertySet
254 3 : Reference< XPropertySetInfo > UnoControlDialogModel::getPropertySetInfo( ) throw(RuntimeException)
255 : {
256 3 : static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
257 3 : return xInfo;
258 : }
259 :
260 222 : void SAL_CALL UnoControlDialogModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception)
261 : {
262 222 : ControlModelContainerBase::setFastPropertyValue_NoBroadcast( nHandle, rValue );
263 : try
264 : {
265 222 : if ( nHandle == BASEPROPERTY_IMAGEURL && ImplHasProperty( BASEPROPERTY_GRAPHIC ) )
266 : {
267 2 : OUString sImageURL;
268 2 : OSL_VERIFY( rValue >>= sImageURL );
269 2 : setPropertyValue( GetPropertyName( BASEPROPERTY_GRAPHIC ), uno::makeAny( ImageHelper::getGraphicAndGraphicObjectFromURL_nothrow( mxGrfObj, sImageURL ) ) );
270 : }
271 : }
272 0 : catch( const ::com::sun::star::uno::Exception& )
273 : {
274 : OSL_ENSURE( sal_False, "UnoControlDialogModel::setFastPropertyValue_NoBroadcast: caught an exception while setting ImageURL properties!" );
275 : }
276 222 : }
277 : // ============================================================================
278 : // = class UnoDialogControl
279 : // ============================================================================
280 :
281 7 : UnoDialogControl::UnoDialogControl( const uno::Reference< uno::XComponentContext >& rxContext )
282 : :UnoDialogControl_Base( rxContext )
283 : ,maTopWindowListeners( *this )
284 7 : ,mbWindowListener(false)
285 : {
286 7 : maComponentInfos.nWidth = 300;
287 7 : maComponentInfos.nHeight = 450;
288 7 : }
289 :
290 2 : UnoDialogControl::~UnoDialogControl()
291 : {
292 2 : }
293 :
294 4 : OUString UnoDialogControl::GetComponentServiceName()
295 : {
296 :
297 4 : sal_Bool bDecoration( sal_True );
298 4 : ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_DECORATION )) >>= bDecoration;
299 4 : if ( bDecoration )
300 4 : return OUString("Dialog");
301 : else
302 0 : return OUString("TabPage");
303 : }
304 :
305 3 : void UnoDialogControl::dispose() throw(RuntimeException)
306 : {
307 3 : SolarMutexGuard aGuard;
308 :
309 6 : EventObject aEvt;
310 3 : aEvt.Source = static_cast< ::cppu::OWeakObject* >( this );
311 3 : maTopWindowListeners.disposeAndClear( aEvt );
312 6 : ControlContainerBase::dispose();
313 3 : }
314 :
315 4 : void SAL_CALL UnoDialogControl::disposing(
316 : const EventObject& Source )
317 : throw(RuntimeException)
318 : {
319 4 : ControlContainerBase::disposing( Source );
320 4 : }
321 :
322 10 : sal_Bool UnoDialogControl::setModel( const Reference< XControlModel >& rxModel ) throw(RuntimeException)
323 : {
324 : // #Can we move all the Resource stuff to the ControlContainerBase ?
325 10 : SolarMutexGuard aGuard;
326 10 : sal_Bool bRet = ControlContainerBase::setModel( rxModel );
327 10 : ImplStartListingForResourceEvents();
328 10 : return bRet;
329 : }
330 :
331 4 : void UnoDialogControl::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) throw(RuntimeException)
332 : {
333 4 : SolarMutexGuard aGuard;
334 :
335 4 : UnoControlContainer::createPeer( rxToolkit, rParentPeer );
336 :
337 8 : Reference < XTopWindow > xTW( getPeer(), UNO_QUERY );
338 4 : if ( xTW.is() )
339 : {
340 4 : xTW->setMenuBar( mxMenuBar );
341 :
342 4 : if ( !mbWindowListener )
343 : {
344 4 : Reference< XWindowListener > xWL( static_cast< cppu::OWeakObject*>( this ), UNO_QUERY );
345 4 : addWindowListener( xWL );
346 4 : mbWindowListener = true;
347 : }
348 :
349 4 : if ( maTopWindowListeners.getLength() )
350 0 : xTW->addTopWindowListener( &maTopWindowListeners );
351 : // there must be a better way than doing this, we can't
352 : // process the scrolltop & scrollleft in XDialog because
353 : // the children haven't been added when those props are applied
354 4 : ImplSetPeerProperty( GetPropertyName( BASEPROPERTY_SCROLLTOP ), ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLTOP ) ) );
355 4 : ImplSetPeerProperty( GetPropertyName( BASEPROPERTY_SCROLLLEFT ), ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLLEFT ) ) );
356 :
357 4 : }
358 4 : }
359 :
360 4 : void UnoDialogControl::PrepareWindowDescriptor( ::com::sun::star::awt::WindowDescriptor& rDesc )
361 : {
362 4 : UnoControlContainer::PrepareWindowDescriptor( rDesc );
363 4 : sal_Bool bDecoration( sal_True );
364 4 : ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_DECORATION )) >>= bDecoration;
365 4 : if ( !bDecoration )
366 : {
367 : // Now we have to manipulate the WindowDescriptor
368 0 : rDesc.WindowAttributes = rDesc.WindowAttributes | ::com::sun::star::awt::WindowAttribute::NODECORATION;
369 : }
370 :
371 : // We have to set the graphic property before the peer
372 : // will be created. Otherwise the properties will be copied
373 : // into the peer via propertiesChangeEvents. As the order of
374 : // can lead to overwrites we have to set the graphic property
375 : // before the propertiesChangeEvents are sent!
376 4 : OUString aImageURL;
377 8 : Reference< graphic::XGraphic > xGraphic;
378 8 : if (( ImplGetPropertyValue( PROPERTY_IMAGEURL ) >>= aImageURL ) &&
379 4 : ( !aImageURL.isEmpty() ))
380 : {
381 0 : OUString absoluteUrl = aImageURL;
382 0 : if ( !aImageURL.startsWith( UNO_NAME_GRAPHOBJ_URLPREFIX ) )
383 0 : absoluteUrl = getPhysicalLocation( ImplGetPropertyValue( PROPERTY_DIALOGSOURCEURL ),
384 0 : uno::makeAny( aImageURL ) );
385 :
386 0 : xGraphic = ImageHelper::getGraphicFromURL_nothrow( absoluteUrl );
387 0 : ImplSetPropertyValue( PROPERTY_GRAPHIC, uno::makeAny( xGraphic ), sal_True );
388 4 : }
389 4 : }
390 :
391 2 : void UnoDialogControl::addTopWindowListener( const Reference< XTopWindowListener >& rxListener ) throw (RuntimeException)
392 : {
393 2 : maTopWindowListeners.addInterface( rxListener );
394 2 : if( getPeer().is() && maTopWindowListeners.getLength() == 1 )
395 : {
396 2 : Reference < XTopWindow > xTW( getPeer(), UNO_QUERY );
397 2 : xTW->addTopWindowListener( &maTopWindowListeners );
398 : }
399 2 : }
400 :
401 2 : void UnoDialogControl::removeTopWindowListener( const Reference< XTopWindowListener >& rxListener ) throw (RuntimeException)
402 : {
403 2 : if( getPeer().is() && maTopWindowListeners.getLength() == 1 )
404 : {
405 2 : Reference < XTopWindow > xTW( getPeer(), UNO_QUERY );
406 2 : xTW->removeTopWindowListener( &maTopWindowListeners );
407 : }
408 2 : maTopWindowListeners.removeInterface( rxListener );
409 2 : }
410 :
411 0 : void UnoDialogControl::toFront( ) throw (RuntimeException)
412 : {
413 0 : SolarMutexGuard aGuard;
414 0 : if ( getPeer().is() )
415 : {
416 0 : Reference< XTopWindow > xTW( getPeer(), UNO_QUERY );
417 0 : if( xTW.is() )
418 0 : xTW->toFront();
419 0 : }
420 0 : }
421 :
422 0 : void UnoDialogControl::toBack( ) throw (RuntimeException)
423 : {
424 0 : SolarMutexGuard aGuard;
425 0 : if ( getPeer().is() )
426 : {
427 0 : Reference< XTopWindow > xTW( getPeer(), UNO_QUERY );
428 0 : if( xTW.is() )
429 0 : xTW->toBack();
430 0 : }
431 0 : }
432 :
433 0 : void UnoDialogControl::setMenuBar( const Reference< XMenuBar >& rxMenuBar ) throw (RuntimeException)
434 : {
435 0 : SolarMutexGuard aGuard;
436 0 : mxMenuBar = rxMenuBar;
437 0 : if ( getPeer().is() )
438 : {
439 0 : Reference< XTopWindow > xTW( getPeer(), UNO_QUERY );
440 0 : if( xTW.is() )
441 0 : xTW->setMenuBar( mxMenuBar );
442 0 : }
443 0 : }
444 2 : static ::Size ImplMapPixelToAppFont( OutputDevice* pOutDev, const ::Size& aSize )
445 : {
446 2 : ::Size aTmp = pOutDev->PixelToLogic( aSize, MAP_APPFONT );
447 2 : return aTmp;
448 : }
449 : // ::com::sun::star::awt::XWindowListener
450 2 : void SAL_CALL UnoDialogControl::windowResized( const ::com::sun::star::awt::WindowEvent& e )
451 : throw (::com::sun::star::uno::RuntimeException)
452 : {
453 2 : OutputDevice*pOutDev = Application::GetDefaultDevice();
454 : DBG_ASSERT( pOutDev, "Missing Default Device!" );
455 2 : if ( pOutDev && !mbSizeModified )
456 : {
457 : // Currentley we are simply using MAP_APPFONT
458 2 : ::Size aAppFontSize( e.Width, e.Height );
459 :
460 2 : Reference< XControl > xDialogControl( *this, UNO_QUERY_THROW );
461 4 : Reference< XDevice > xDialogDevice( xDialogControl->getPeer(), UNO_QUERY );
462 : OSL_ENSURE( xDialogDevice.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" );
463 :
464 : // #i87592 In design mode the drawing layer works with sizes with decoration.
465 : // Therefore we have to substract them before writing back to the properties (model).
466 2 : if ( xDialogDevice.is() && mbDesignMode )
467 : {
468 0 : DeviceInfo aDeviceInfo( xDialogDevice->getInfo() );
469 0 : aAppFontSize.Width() -= aDeviceInfo.LeftInset + aDeviceInfo.RightInset;
470 0 : aAppFontSize.Height() -= aDeviceInfo.TopInset + aDeviceInfo.BottomInset;
471 : }
472 :
473 2 : aAppFontSize = ImplMapPixelToAppFont( pOutDev, aAppFontSize );
474 :
475 : // Remember that changes have been done by listener. No need to
476 : // update the position because of property change event.
477 2 : mbSizeModified = true;
478 4 : Sequence< OUString > aProps( 2 );
479 4 : Sequence< Any > aValues( 2 );
480 : // Properties in a sequence must be sorted!
481 2 : aProps[0] = OUString( "Height" );
482 2 : aProps[1] = OUString( "Width" );
483 2 : aValues[0] <<= aAppFontSize.Height();
484 2 : aValues[1] <<= aAppFontSize.Width();
485 :
486 2 : ImplSetPropertyValues( aProps, aValues, true );
487 4 : mbSizeModified = false;
488 : }
489 2 : }
490 :
491 0 : void SAL_CALL UnoDialogControl::windowMoved( const ::com::sun::star::awt::WindowEvent& e )
492 : throw (::com::sun::star::uno::RuntimeException)
493 : {
494 0 : OutputDevice*pOutDev = Application::GetDefaultDevice();
495 : DBG_ASSERT( pOutDev, "Missing Default Device!" );
496 0 : if ( pOutDev && !mbPosModified )
497 : {
498 : // Currentley we are simply using MAP_APPFONT
499 0 : Any aAny;
500 0 : ::Size aTmp( e.X, e.Y );
501 0 : aTmp = ImplMapPixelToAppFont( pOutDev, aTmp );
502 :
503 : // Remember that changes have been done by listener. No need to
504 : // update the position because of property change event.
505 0 : mbPosModified = true;
506 0 : Sequence< OUString > aProps( 2 );
507 0 : Sequence< Any > aValues( 2 );
508 0 : aProps[0] = OUString( "PositionX" );
509 0 : aProps[1] = OUString( "PositionY" );
510 0 : aValues[0] <<= aTmp.Width();
511 0 : aValues[1] <<= aTmp.Height();
512 :
513 0 : ImplSetPropertyValues( aProps, aValues, true );
514 0 : mbPosModified = false;
515 : }
516 0 : }
517 :
518 0 : void SAL_CALL UnoDialogControl::windowShown( const EventObject& e ) throw (RuntimeException)
519 : {
520 : (void)e;
521 0 : }
522 :
523 0 : void SAL_CALL UnoDialogControl::windowHidden( const EventObject& e ) throw (RuntimeException)
524 : {
525 : (void)e;
526 0 : }
527 :
528 0 : void SAL_CALL UnoDialogControl::endDialog( ::sal_Int32 i_result ) throw (RuntimeException)
529 : {
530 0 : Reference< XDialog2 > xPeerDialog( getPeer(), UNO_QUERY );
531 0 : if ( xPeerDialog.is() )
532 0 : xPeerDialog->endDialog( i_result );
533 0 : }
534 :
535 0 : void SAL_CALL UnoDialogControl::setHelpId( const OUString& i_id ) throw (RuntimeException)
536 : {
537 0 : Reference< XDialog2 > xPeerDialog( getPeer(), UNO_QUERY );
538 0 : if ( xPeerDialog.is() )
539 0 : xPeerDialog->setHelpId( i_id );
540 0 : }
541 :
542 0 : void UnoDialogControl::setTitle( const OUString& Title ) throw(RuntimeException)
543 : {
544 0 : SolarMutexGuard aGuard;
545 0 : Any aAny;
546 0 : aAny <<= Title;
547 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TITLE ), aAny, sal_True );
548 0 : }
549 :
550 0 : OUString UnoDialogControl::getTitle() throw(RuntimeException)
551 : {
552 0 : SolarMutexGuard aGuard;
553 0 : return ImplGetPropertyValue_UString( BASEPROPERTY_TITLE );
554 : }
555 :
556 0 : sal_Int16 UnoDialogControl::execute() throw(RuntimeException)
557 : {
558 0 : SolarMutexGuard aGuard;
559 0 : sal_Int16 nDone = -1;
560 0 : if ( getPeer().is() )
561 : {
562 0 : Reference< XDialog > xDlg( getPeer(), UNO_QUERY );
563 0 : if( xDlg.is() )
564 : {
565 0 : GetComponentInfos().bVisible = sal_True;
566 0 : nDone = xDlg->execute();
567 0 : GetComponentInfos().bVisible = sal_False;
568 0 : }
569 : }
570 0 : return nDone;
571 : }
572 :
573 0 : void UnoDialogControl::endExecute() throw(RuntimeException)
574 : {
575 0 : SolarMutexGuard aGuard;
576 0 : if ( getPeer().is() )
577 : {
578 0 : Reference< XDialog > xDlg( getPeer(), UNO_QUERY );
579 0 : if( xDlg.is() )
580 : {
581 0 : xDlg->endExecute();
582 0 : GetComponentInfos().bVisible = sal_False;
583 0 : }
584 0 : }
585 0 : }
586 :
587 : // XModifyListener
588 0 : void SAL_CALL UnoDialogControl::modified(
589 : const lang::EventObject& /*rEvent*/ )
590 : throw (RuntimeException)
591 : {
592 0 : ImplUpdateResourceResolver();
593 0 : }
594 :
595 247 : void UnoDialogControl::ImplModelPropertiesChanged( const Sequence< PropertyChangeEvent >& rEvents ) throw(RuntimeException)
596 : {
597 247 : sal_Int32 nLen = rEvents.getLength();
598 657 : for( sal_Int32 i = 0; i < nLen; i++ )
599 : {
600 416 : const PropertyChangeEvent& rEvt = rEvents.getConstArray()[i];
601 416 : Reference< XControlModel > xModel( rEvt.Source, UNO_QUERY );
602 416 : sal_Bool bOwnModel = (XControlModel*)xModel.get() == (XControlModel*)getModel().get();
603 416 : if ( bOwnModel && rEvt.PropertyName.equalsAsciiL( "ImageURL", 8 ))
604 : {
605 6 : OUString aImageURL;
606 12 : Reference< graphic::XGraphic > xGraphic;
607 12 : if (( ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_IMAGEURL ) ) >>= aImageURL ) &&
608 6 : ( !aImageURL.isEmpty() ))
609 : {
610 2 : OUString absoluteUrl = aImageURL;
611 2 : if ( !aImageURL.startsWith( UNO_NAME_GRAPHOBJ_URLPREFIX ) )
612 :
613 4 : absoluteUrl = getPhysicalLocation( ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_DIALOGSOURCEURL )),
614 2 : uno::makeAny(aImageURL));
615 :
616 2 : xGraphic = ImageHelper::getGraphicFromURL_nothrow( absoluteUrl );
617 : }
618 6 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_GRAPHIC), uno::makeAny( xGraphic ), sal_True );
619 12 : break;
620 : }
621 410 : }
622 247 : ControlContainerBase::ImplModelPropertiesChanged(rEvents);
623 247 : }
624 :
625 : // ----------------------------------------------------
626 : // class MultiPageControl
627 : // ----------------------------------------------------
628 0 : UnoMultiPageControl::UnoMultiPageControl( const uno::Reference< uno::XComponentContext >& rxContext ) : ControlContainerBase(rxContext), maTabListeners( *this )
629 : {
630 0 : maComponentInfos.nWidth = 280;
631 0 : maComponentInfos.nHeight = 400;
632 0 : }
633 :
634 0 : UnoMultiPageControl::~UnoMultiPageControl()
635 : {
636 0 : }
637 : // XTabListener
638 :
639 0 : void SAL_CALL UnoMultiPageControl::inserted( SAL_UNUSED_PARAMETER ::sal_Int32 ) throw (RuntimeException)
640 : {
641 0 : }
642 0 : void SAL_CALL UnoMultiPageControl::removed( SAL_UNUSED_PARAMETER ::sal_Int32 ) throw (RuntimeException)
643 : {
644 0 : }
645 0 : void SAL_CALL UnoMultiPageControl::changed( SAL_UNUSED_PARAMETER ::sal_Int32,
646 : SAL_UNUSED_PARAMETER const Sequence< NamedValue >& ) throw (RuntimeException)
647 : {
648 0 : }
649 0 : void SAL_CALL UnoMultiPageControl::activated( ::sal_Int32 ID ) throw (RuntimeException)
650 : {
651 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_MULTIPAGEVALUE ), uno::makeAny( ID ), sal_False );
652 :
653 0 : }
654 0 : void SAL_CALL UnoMultiPageControl::deactivated( SAL_UNUSED_PARAMETER ::sal_Int32 ) throw (RuntimeException)
655 : {
656 0 : }
657 0 : void SAL_CALL UnoMultiPageControl::disposing(const EventObject&) throw (RuntimeException)
658 : {
659 0 : }
660 :
661 0 : void SAL_CALL UnoMultiPageControl::dispose() throw (RuntimeException)
662 : {
663 0 : lang::EventObject aEvt;
664 0 : aEvt.Source = (::cppu::OWeakObject*)this;
665 0 : maTabListeners.disposeAndClear( aEvt );
666 0 : ControlContainerBase::dispose();
667 0 : }
668 :
669 : // com::sun::star::awt::XSimpleTabController
670 0 : ::sal_Int32 SAL_CALL UnoMultiPageControl::insertTab() throw (RuntimeException)
671 : {
672 0 : Reference< XSimpleTabController > xMultiPage( getPeer(), UNO_QUERY );
673 0 : if ( !xMultiPage.is() )
674 0 : throw RuntimeException();
675 0 : return xMultiPage->insertTab();
676 : }
677 :
678 0 : void SAL_CALL UnoMultiPageControl::removeTab( ::sal_Int32 ID ) throw (IndexOutOfBoundsException, RuntimeException)
679 : {
680 0 : Reference< XSimpleTabController > xMultiPage( getPeer(), UNO_QUERY );
681 0 : if ( !xMultiPage.is() )
682 0 : throw RuntimeException();
683 0 : xMultiPage->removeTab( ID );
684 0 : }
685 :
686 0 : void SAL_CALL UnoMultiPageControl::setTabProps( ::sal_Int32 ID, const Sequence< NamedValue >& Properties ) throw (IndexOutOfBoundsException, RuntimeException)
687 : {
688 0 : Reference< XSimpleTabController > xMultiPage( getPeer(), UNO_QUERY );
689 0 : if ( !xMultiPage.is() )
690 0 : throw RuntimeException();
691 0 : xMultiPage->setTabProps( ID, Properties );
692 0 : }
693 :
694 0 : Sequence< NamedValue > SAL_CALL UnoMultiPageControl::getTabProps( ::sal_Int32 ID ) throw (IndexOutOfBoundsException, RuntimeException)
695 : {
696 0 : Reference< XSimpleTabController > xMultiPage( getPeer(), UNO_QUERY );
697 0 : if ( !xMultiPage.is() )
698 0 : throw RuntimeException();
699 0 : return xMultiPage->getTabProps( ID );
700 : }
701 :
702 0 : void SAL_CALL UnoMultiPageControl::activateTab( ::sal_Int32 ID ) throw (IndexOutOfBoundsException, RuntimeException)
703 : {
704 0 : Reference< XSimpleTabController > xMultiPage( getPeer(), UNO_QUERY );
705 0 : if ( !xMultiPage.is() )
706 0 : throw RuntimeException();
707 0 : xMultiPage->activateTab( ID );
708 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_MULTIPAGEVALUE ), uno::makeAny( ID ), sal_True );
709 :
710 0 : }
711 :
712 0 : ::sal_Int32 SAL_CALL UnoMultiPageControl::getActiveTabID() throw (RuntimeException)
713 : {
714 0 : Reference< XSimpleTabController > xMultiPage( getPeer(), UNO_QUERY );
715 0 : if ( !xMultiPage.is() )
716 0 : throw RuntimeException();
717 0 : return xMultiPage->getActiveTabID();
718 : }
719 :
720 0 : void SAL_CALL UnoMultiPageControl::addTabListener( const Reference< XTabListener >& Listener ) throw (RuntimeException)
721 : {
722 0 : maTabListeners.addInterface( Listener );
723 0 : Reference< XSimpleTabController > xMultiPage( getPeer(), UNO_QUERY );
724 0 : if ( xMultiPage.is() && maTabListeners.getLength() == 1 )
725 0 : xMultiPage->addTabListener( &maTabListeners );
726 0 : }
727 :
728 0 : void SAL_CALL UnoMultiPageControl::removeTabListener( const Reference< XTabListener >& Listener ) throw (RuntimeException)
729 : {
730 0 : Reference< XSimpleTabController > xMultiPage( getPeer(), UNO_QUERY );
731 0 : if ( xMultiPage.is() && maTabListeners.getLength() == 1 )
732 0 : xMultiPage->removeTabListener( &maTabListeners );
733 0 : maTabListeners.removeInterface( Listener );
734 0 : }
735 :
736 :
737 : // lang::XTypeProvider
738 0 : IMPL_XTYPEPROVIDER_START( UnoMultiPageControl )
739 0 : getCppuType( ( uno::Reference< awt::XSimpleTabController>* ) NULL ),
740 0 : getCppuType( ( uno::Reference< awt::XTabListener>* ) NULL ),
741 : ControlContainerBase::getTypes()
742 0 : IMPL_XTYPEPROVIDER_END
743 :
744 : // uno::XInterface
745 0 : uno::Any UnoMultiPageControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException)
746 : {
747 : uno::Any aRet = ::cppu::queryInterface( rType,
748 0 : (static_cast< awt::XTabListener* >(this)), (static_cast< awt::XSimpleTabController* >(this)) );
749 0 : return (aRet.hasValue() ? aRet : ControlContainerBase::queryAggregation( rType ));
750 : }
751 :
752 0 : OUString UnoMultiPageControl::GetComponentServiceName()
753 : {
754 0 : sal_Bool bDecoration( sal_True );
755 0 : ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_DECORATION )) >>= bDecoration;
756 0 : if ( bDecoration )
757 0 : return OUString("tabcontrol");
758 : // Hopefully we can tweak the tabcontrol to display without tabs
759 0 : return OUString("tabcontrolnotabs");
760 : }
761 :
762 0 : void UnoMultiPageControl::bindPage( const uno::Reference< awt::XControl >& _rxControl )
763 : {
764 0 : uno::Reference< awt::XWindowPeer > xPage( _rxControl->getPeer() );
765 0 : uno::Reference< awt::XSimpleTabController > xTabCntrl( getPeer(), uno::UNO_QUERY );
766 0 : uno::Reference< beans::XPropertySet > xProps( _rxControl->getModel(), uno::UNO_QUERY );
767 :
768 0 : VCLXTabPage* pXPage = dynamic_cast< VCLXTabPage* >( xPage.get() );
769 0 : TabPage* pPage = pXPage ? pXPage->getTabPage() : NULL;
770 0 : if ( xTabCntrl.is() && pPage )
771 : {
772 0 : VCLXMultiPage* pXTab = dynamic_cast< VCLXMultiPage* >( xTabCntrl.get() );
773 0 : if ( pXTab )
774 : {
775 0 : OUString sTitle;
776 0 : xProps->getPropertyValue( GetPropertyName( BASEPROPERTY_TITLE ) ) >>= sTitle;
777 0 : pXTab->insertTab( pPage, sTitle);
778 : }
779 0 : }
780 :
781 0 : }
782 :
783 0 : void UnoMultiPageControl::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer > & rParentPeer ) throw(RuntimeException)
784 : {
785 0 : SolarMutexGuard aSolarGuard;
786 :
787 0 : UnoControlContainer::createPeer( rxToolkit, rParentPeer );
788 :
789 0 : uno::Sequence< uno::Reference< awt::XControl > > aCtrls = getControls();
790 0 : sal_uInt32 nCtrls = aCtrls.getLength();
791 0 : for( sal_uInt32 n = 0; n < nCtrls; n++ )
792 0 : bindPage( aCtrls[ n ] );
793 0 : sal_Int32 nActiveTab(0);
794 0 : Reference< XPropertySet > xMultiProps( getModel(), UNO_QUERY );
795 0 : xMultiProps->getPropertyValue( GetPropertyName( BASEPROPERTY_MULTIPAGEVALUE ) ) >>= nActiveTab;
796 :
797 0 : uno::Reference< awt::XSimpleTabController > xTabCntrl( getPeer(), uno::UNO_QUERY );
798 0 : if ( xTabCntrl.is() )
799 : {
800 0 : xTabCntrl->addTabListener( this );
801 0 : if ( nActiveTab && nCtrls ) // Ensure peer is initialise with correct activated tab
802 : {
803 0 : xTabCntrl->activateTab( nActiveTab );
804 0 : ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_MULTIPAGEVALUE ), uno::makeAny( nActiveTab ), sal_True );
805 : }
806 0 : }
807 0 : }
808 :
809 0 : void UnoMultiPageControl::impl_createControlPeerIfNecessary( const uno::Reference< awt::XControl >& _rxControl)
810 : {
811 : OSL_PRECOND( _rxControl.is(), "UnoMultiPageControl::impl_createControlPeerIfNecessary: invalid control, this will crash!" );
812 :
813 : // if the container already has a peer, then also create a peer for the control
814 0 : uno::Reference< awt::XWindowPeer > xMyPeer( getPeer() );
815 :
816 0 : if( xMyPeer.is() )
817 : {
818 0 : _rxControl->createPeer( NULL, xMyPeer );
819 0 : bindPage( _rxControl );
820 0 : ImplActivateTabControllers();
821 0 : }
822 :
823 0 : }
824 :
825 : // ------------- UnoMultiPageModel -----------------
826 :
827 1 : UnoMultiPageModel::UnoMultiPageModel( const Reference< XComponentContext >& rxContext ) : ControlModelContainerBase( rxContext )
828 : {
829 1 : ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
830 1 : ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
831 1 : ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
832 1 : ImplRegisterProperty( BASEPROPERTY_ENABLED );
833 :
834 1 : ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR );
835 1 : ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
836 1 : ImplRegisterProperty( BASEPROPERTY_HELPURL );
837 1 : ImplRegisterProperty( BASEPROPERTY_SIZEABLE );
838 : //ImplRegisterProperty( BASEPROPERTY_DIALOGSOURCEURL );
839 1 : ImplRegisterProperty( BASEPROPERTY_MULTIPAGEVALUE );
840 1 : ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
841 1 : ImplRegisterProperty( BASEPROPERTY_USERFORMCONTAINEES );
842 :
843 1 : Any aBool;
844 1 : aBool <<= (sal_Bool) sal_True;
845 1 : ImplRegisterProperty( BASEPROPERTY_MOVEABLE, aBool );
846 1 : ImplRegisterProperty( BASEPROPERTY_CLOSEABLE, aBool );
847 1 : ImplRegisterProperty( BASEPROPERTY_DECORATION, aBool );
848 : // MultiPage Control has the tab stop property. And the default value is True.
849 1 : ImplRegisterProperty( BASEPROPERTY_TABSTOP, aBool );
850 :
851 2 : uno::Reference< XNameContainer > xNameCont = new SimpleNamedThingContainer< XControlModel >();
852 2 : ImplRegisterProperty( BASEPROPERTY_USERFORMCONTAINEES, uno::makeAny( xNameCont ) );
853 1 : }
854 :
855 0 : UnoMultiPageModel::UnoMultiPageModel( const UnoMultiPageModel& rModel )
856 0 : : ControlModelContainerBase( rModel )
857 : {
858 0 : }
859 :
860 2 : UnoMultiPageModel::~UnoMultiPageModel()
861 : {
862 2 : }
863 :
864 : UnoControlModel*
865 0 : UnoMultiPageModel::Clone() const
866 : {
867 : // clone the container itself
868 0 : UnoMultiPageModel* pClone = new UnoMultiPageModel( *this );
869 0 : Clone_Impl( *pClone );
870 0 : return pClone;
871 : }
872 :
873 0 : OUString UnoMultiPageModel::getServiceName() throw(::com::sun::star::uno::RuntimeException)
874 : {
875 0 : return OUString::createFromAscii( szServiceName_UnoMultiPageModel );
876 : }
877 :
878 15 : uno::Any UnoMultiPageModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
879 : {
880 15 : if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
881 : {
882 1 : uno::Any aAny;
883 1 : aAny <<= OUString::createFromAscii( szServiceName_UnoMultiPageControl );
884 1 : return aAny;
885 : }
886 14 : return ControlModelContainerBase::ImplGetDefaultValue( nPropId );
887 : }
888 :
889 0 : ::cppu::IPropertyArrayHelper& UnoMultiPageModel::getInfoHelper()
890 : {
891 : static UnoPropertyArrayHelper* pHelper = NULL;
892 0 : if ( !pHelper )
893 : {
894 0 : uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
895 0 : pHelper = new UnoPropertyArrayHelper( aIDs );
896 : }
897 0 : return *pHelper;
898 : }
899 :
900 : // beans::XMultiPropertySet
901 0 : uno::Reference< beans::XPropertySetInfo > UnoMultiPageModel::getPropertySetInfo( ) throw(uno::RuntimeException)
902 : {
903 0 : static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
904 0 : return xInfo;
905 : }
906 :
907 0 : void UnoMultiPageModel::insertByName( const OUString& aName, const Any& aElement ) throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
908 : {
909 0 : Reference< XServiceInfo > xInfo;
910 0 : aElement >>= xInfo;
911 :
912 0 : if ( !xInfo.is() )
913 0 : throw IllegalArgumentException();
914 :
915 : // Only a Page model can be inserted into the multipage
916 0 : if ( !xInfo->supportsService( OUString::createFromAscii( szServiceName_UnoPageModel ) ) )
917 0 : throw IllegalArgumentException();
918 :
919 0 : return ControlModelContainerBase::insertByName( aName, aElement );
920 : }
921 :
922 : // ----------------------------------------------------------------------------
923 0 : sal_Bool SAL_CALL UnoMultiPageModel::getGroupControl( ) throw (RuntimeException)
924 : {
925 0 : return sal_True;
926 : }
927 :
928 : // ----------------------------------------------------
929 : // class UnoPageControl
930 : // ----------------------------------------------------
931 0 : UnoPageControl::UnoPageControl( const uno::Reference< uno::XComponentContext >& rxContext ) : ControlContainerBase(rxContext)
932 : {
933 0 : maComponentInfos.nWidth = 280;
934 0 : maComponentInfos.nHeight = 400;
935 0 : }
936 :
937 0 : UnoPageControl::~UnoPageControl()
938 : {
939 0 : }
940 :
941 0 : OUString UnoPageControl::GetComponentServiceName()
942 : {
943 0 : return OUString("tabpage");
944 : }
945 :
946 :
947 : // ------------- UnoPageModel -----------------
948 :
949 0 : UnoPageModel::UnoPageModel( const Reference< XComponentContext >& rxContext ) : ControlModelContainerBase( rxContext )
950 : {
951 0 : ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
952 0 : ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
953 0 : ImplRegisterProperty( BASEPROPERTY_ENABLED );
954 0 : ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
955 :
956 0 : ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR );
957 0 : ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
958 0 : ImplRegisterProperty( BASEPROPERTY_HELPURL );
959 0 : ImplRegisterProperty( BASEPROPERTY_TITLE );
960 0 : ImplRegisterProperty( BASEPROPERTY_SIZEABLE );
961 0 : ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
962 0 : ImplRegisterProperty( BASEPROPERTY_USERFORMCONTAINEES );
963 : // ImplRegisterProperty( BASEPROPERTY_DIALOGSOURCEURL );
964 :
965 0 : Any aBool;
966 0 : aBool <<= (sal_Bool) sal_True;
967 0 : ImplRegisterProperty( BASEPROPERTY_MOVEABLE, aBool );
968 0 : ImplRegisterProperty( BASEPROPERTY_CLOSEABLE, aBool );
969 : //ImplRegisterProperty( BASEPROPERTY_TABSTOP, aBool );
970 :
971 0 : uno::Reference< XNameContainer > xNameCont = new SimpleNamedThingContainer< XControlModel >();
972 0 : ImplRegisterProperty( BASEPROPERTY_USERFORMCONTAINEES, uno::makeAny( xNameCont ) );
973 0 : }
974 :
975 0 : UnoPageModel::UnoPageModel( const UnoPageModel& rModel )
976 0 : : ControlModelContainerBase( rModel )
977 : {
978 0 : }
979 :
980 0 : UnoPageModel::~UnoPageModel()
981 : {
982 0 : }
983 :
984 : UnoControlModel*
985 0 : UnoPageModel::Clone() const
986 : {
987 : // clone the container itself
988 0 : UnoPageModel* pClone = new UnoPageModel( *this );
989 0 : Clone_Impl( *pClone );
990 0 : return pClone;
991 : }
992 :
993 0 : OUString UnoPageModel::getServiceName() throw(::com::sun::star::uno::RuntimeException)
994 : {
995 0 : return OUString::createFromAscii( szServiceName_UnoPageModel );
996 : }
997 :
998 0 : uno::Any UnoPageModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
999 : {
1000 0 : if ( nPropId == BASEPROPERTY_DEFAULTCONTROL )
1001 : {
1002 0 : uno::Any aAny;
1003 0 : aAny <<= OUString::createFromAscii( szServiceName_UnoPageControl );
1004 0 : return aAny;
1005 : }
1006 0 : return ControlModelContainerBase::ImplGetDefaultValue( nPropId );
1007 : }
1008 :
1009 0 : ::cppu::IPropertyArrayHelper& UnoPageModel::getInfoHelper()
1010 : {
1011 : static UnoPropertyArrayHelper* pHelper = NULL;
1012 0 : if ( !pHelper )
1013 : {
1014 0 : uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
1015 0 : pHelper = new UnoPropertyArrayHelper( aIDs );
1016 : }
1017 0 : return *pHelper;
1018 : }
1019 :
1020 : // beans::XMultiPropertySet
1021 0 : uno::Reference< beans::XPropertySetInfo > UnoPageModel::getPropertySetInfo( ) throw(uno::RuntimeException)
1022 : {
1023 0 : static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
1024 0 : return xInfo;
1025 : }
1026 :
1027 : // ----------------------------------------------------------------------------
1028 0 : sal_Bool SAL_CALL UnoPageModel::getGroupControl( ) throw (RuntimeException)
1029 : {
1030 0 : return sal_False;
1031 : }
1032 :
1033 : // Frame control
1034 :
1035 : // ----------------------------------------------------
1036 : // class UnoFrameControl
1037 : // ----------------------------------------------------
1038 0 : UnoFrameControl::UnoFrameControl( const uno::Reference< uno::XComponentContext >& rxContext ) : ControlContainerBase(rxContext)
1039 : {
1040 0 : maComponentInfos.nWidth = 280;
1041 0 : maComponentInfos.nHeight = 400;
1042 0 : }
1043 :
1044 0 : UnoFrameControl::~UnoFrameControl()
1045 : {
1046 0 : }
1047 :
1048 0 : OUString UnoFrameControl::GetComponentServiceName()
1049 : {
1050 0 : return OUString("frame");
1051 : }
1052 :
1053 0 : void UnoFrameControl::ImplSetPosSize( Reference< XControl >& rxCtrl )
1054 : {
1055 0 : bool bOwnCtrl = false;
1056 0 : OUString sTitle;
1057 0 : if ( rxCtrl.get() == Reference<XControl>( this ).get() )
1058 0 : bOwnCtrl = true;
1059 0 : Reference< XPropertySet > xProps( getModel(), UNO_QUERY );
1060 : //xProps->getPropertyValue( GetPropertyName( BASEPROPERTY_TITLE ) ) >>= sTitle;
1061 0 : xProps->getPropertyValue( GetPropertyName( BASEPROPERTY_LABEL ) ) >>= sTitle;
1062 :
1063 0 : ControlContainerBase::ImplSetPosSize( rxCtrl );
1064 0 : Reference < XWindow > xW( rxCtrl, UNO_QUERY );
1065 0 : if ( !bOwnCtrl && xW.is() && !sTitle.isEmpty() )
1066 : {
1067 0 : awt::Rectangle aSizePos = xW->getPosSize();
1068 :
1069 0 : sal_Int32 nX = aSizePos.X, nY = aSizePos.Y, nWidth = aSizePos.Width, nHeight = aSizePos.Height;
1070 : // Retrieve the values set by the base class
1071 0 : OutputDevice*pOutDev = Application::GetDefaultDevice();
1072 0 : if ( pOutDev )
1073 : {
1074 0 : if ( !bOwnCtrl && !sTitle.isEmpty() )
1075 : {
1076 : // Adjust Y based on height of Title
1077 0 : ::Rectangle aRect;
1078 0 : aRect = pOutDev->GetTextRect( aRect, sTitle );
1079 0 : nY = nY + ( aRect.GetHeight() / 2 );
1080 : }
1081 : }
1082 : else
1083 : {
1084 0 : Reference< XWindowPeer > xPeer = ImplGetCompatiblePeer( sal_True );
1085 0 : Reference< XDevice > xD( xPeer, UNO_QUERY );
1086 :
1087 0 : SimpleFontMetric aFM;
1088 0 : FontDescriptor aFD;
1089 0 : Any aVal = ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_FONTDESCRIPTOR ) );
1090 :
1091 0 : aVal >>= aFD;
1092 0 : if ( !aFD.StyleName.isEmpty() )
1093 : {
1094 0 : Reference< XFont > xFont = xD->getFont( aFD );
1095 0 : aFM = xFont->getFontMetric();
1096 : }
1097 : else
1098 : {
1099 0 : Reference< XGraphics > xG = xD->createGraphics();
1100 0 : aFM = xG->getFontMetric();
1101 : }
1102 :
1103 0 : sal_Int16 nH = aFM.Ascent + aFM.Descent;
1104 0 : if ( !bOwnCtrl && !sTitle.isEmpty() )
1105 : // offset y based on height of font ( not sure if my guess at the correct calculation is correct here )
1106 0 : nY = nY + ( nH / 8); // how do I test this
1107 : }
1108 0 : xW->setPosSize( nX, nY, nWidth, nHeight, PosSize::POSSIZE );
1109 0 : }
1110 0 : }
1111 :
1112 : // ------------- UnoFrameModel -----------------
1113 :
1114 1 : UnoFrameModel::UnoFrameModel( const Reference< XComponentContext >& rxContext ) : ControlModelContainerBase( rxContext )
1115 : {
1116 1 : ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
1117 1 : ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
1118 1 : ImplRegisterProperty( BASEPROPERTY_ENABLED );
1119 1 : ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
1120 1 : ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR );
1121 1 : ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
1122 1 : ImplRegisterProperty( BASEPROPERTY_HELPURL );
1123 1 : ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
1124 1 : ImplRegisterProperty( BASEPROPERTY_LABEL );
1125 1 : ImplRegisterProperty( BASEPROPERTY_WRITING_MODE );
1126 1 : ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE );
1127 1 : ImplRegisterProperty( BASEPROPERTY_USERFORMCONTAINEES );
1128 1 : ImplRegisterProperty( BASEPROPERTY_HSCROLL );
1129 1 : ImplRegisterProperty( BASEPROPERTY_VSCROLL );
1130 1 : ImplRegisterProperty( BASEPROPERTY_SCROLLWIDTH );
1131 1 : ImplRegisterProperty( BASEPROPERTY_SCROLLHEIGHT );
1132 1 : ImplRegisterProperty( BASEPROPERTY_SCROLLTOP );
1133 1 : ImplRegisterProperty( BASEPROPERTY_SCROLLLEFT );
1134 :
1135 :
1136 1 : uno::Reference< XNameContainer > xNameCont = new SimpleNamedThingContainer< XControlModel >();
1137 1 : ImplRegisterProperty( BASEPROPERTY_USERFORMCONTAINEES, uno::makeAny( xNameCont ) );
1138 1 : }
1139 :
1140 0 : UnoFrameModel::UnoFrameModel( const UnoFrameModel& rModel )
1141 0 : : ControlModelContainerBase( rModel )
1142 : {
1143 0 : }
1144 :
1145 2 : UnoFrameModel::~UnoFrameModel()
1146 : {
1147 2 : }
1148 :
1149 : UnoControlModel*
1150 0 : UnoFrameModel::Clone() const
1151 : {
1152 : // clone the container itself
1153 0 : UnoFrameModel* pClone = new UnoFrameModel( *this );
1154 0 : Clone_Impl( *pClone );
1155 0 : return pClone;
1156 : }
1157 :
1158 0 : OUString UnoFrameModel::getServiceName() throw(::com::sun::star::uno::RuntimeException)
1159 : {
1160 0 : return OUString::createFromAscii( szServiceName_UnoFrameModel );
1161 : }
1162 :
1163 22 : uno::Any UnoFrameModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
1164 : {
1165 22 : uno::Any aAny;
1166 22 : switch ( nPropId )
1167 : {
1168 : case BASEPROPERTY_DEFAULTCONTROL:
1169 : {
1170 1 : aAny <<= OUString::createFromAscii( szServiceName_UnoFrameControl );
1171 1 : return aAny;
1172 : }
1173 : case BASEPROPERTY_SCROLLWIDTH:
1174 : case BASEPROPERTY_SCROLLHEIGHT:
1175 : case BASEPROPERTY_SCROLLTOP:
1176 : case BASEPROPERTY_SCROLLLEFT:
1177 4 : aAny <<= sal_Int32(0);
1178 4 : return aAny;
1179 : case BASEPROPERTY_USERFORMCONTAINEES:
1180 : {
1181 1 : uno::Reference< XNameContainer > xNameCont = new SimpleNamedThingContainer< XControlModel >();
1182 1 : return makeAny( xNameCont );
1183 : }
1184 : }
1185 16 : return ControlModelContainerBase::ImplGetDefaultValue( nPropId );
1186 : }
1187 :
1188 0 : ::cppu::IPropertyArrayHelper& UnoFrameModel::getInfoHelper()
1189 : {
1190 : static UnoPropertyArrayHelper* pHelper = NULL;
1191 0 : if ( !pHelper )
1192 : {
1193 0 : uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
1194 0 : pHelper = new UnoPropertyArrayHelper( aIDs );
1195 : }
1196 0 : return *pHelper;
1197 : }
1198 :
1199 : // beans::XMultiPropertySet
1200 0 : uno::Reference< beans::XPropertySetInfo > UnoFrameModel::getPropertySetInfo( ) throw(uno::RuntimeException)
1201 : {
1202 0 : static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
1203 0 : return xInfo;
1204 465 : }
1205 :
1206 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|