1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_toolkit.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <vcl/svapp.hxx>
32*cdf0e10cSrcweir #include <vcl/window.hxx>
33*cdf0e10cSrcweir #include <vcl/wall.hxx>
34*cdf0e10cSrcweir #include <vos/mutex.hxx>
35*cdf0e10cSrcweir #include <toolkit/controls/dialogcontrol.hxx>
36*cdf0e10cSrcweir #include <toolkit/helper/property.hxx>
37*cdf0e10cSrcweir #include <toolkit/helper/unopropertyarrayhelper.hxx>
38*cdf0e10cSrcweir #include <toolkit/controls/stdtabcontroller.hxx>
39*cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/resource/XStringResourceResolver.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicProvider.hpp>
43*cdf0e10cSrcweir #include <tools/list.hxx>
44*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
45*cdf0e10cSrcweir #include <tools/debug.hxx>
46*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
47*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
48*cdf0e10cSrcweir #include <vcl/svapp.hxx>
49*cdf0e10cSrcweir #include <vcl/outdev.hxx>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
52*cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
53*cdf0e10cSrcweir #include <vcl/graph.hxx>
54*cdf0e10cSrcweir #include <vcl/image.hxx>
55*cdf0e10cSrcweir #include <map>
56*cdf0e10cSrcweir #include <algorithm>
57*cdf0e10cSrcweir #include <functional>
58*cdf0e10cSrcweir #include "tools/urlobj.hxx"
59*cdf0e10cSrcweir #include "osl/file.hxx"
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir using namespace ::com::sun::star;
62*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
63*cdf0e10cSrcweir using namespace ::com::sun::star::awt;
64*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
65*cdf0e10cSrcweir using namespace ::com::sun::star::container;
66*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
67*cdf0e10cSrcweir using namespace ::com::sun::star::util;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir #define PROPERTY_DIALOGSOURCEURL ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DialogSourceURL" ))
70*cdf0e10cSrcweir #define PROPERTY_IMAGEURL ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ImageURL" ))
71*cdf0e10cSrcweir #define PROPERTY_GRAPHIC ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Graphic" ))
72*cdf0e10cSrcweir //
73*cdf0e10cSrcweir ////HELPER
74*cdf0e10cSrcweir ::rtl::OUString getPhysicalLocation( const ::com::sun::star::uno::Any& rbase, const ::com::sun::star::uno::Any& rUrl );
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir //	----------------------------------------------------
77*cdf0e10cSrcweir //	class UnoControlDialogModel
78*cdf0e10cSrcweir //	----------------------------------------------------
79*cdf0e10cSrcweir UnoControlDialogModel::UnoControlDialogModel( const Reference< XMultiServiceFactory >& i_factory )
80*cdf0e10cSrcweir 	:ControlModelContainerBase( i_factory )
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
83*cdf0e10cSrcweir //	ImplRegisterProperty( BASEPROPERTY_BORDER );
84*cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
85*cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_ENABLED );
86*cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR );
87*cdf0e10cSrcweir //	ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
88*cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
89*cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_HELPURL );
90*cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_TITLE );
91*cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_SIZEABLE );
92*cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_DESKTOP_AS_PARENT );
93*cdf0e10cSrcweir     ImplRegisterProperty( BASEPROPERTY_DECORATION );
94*cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_DIALOGSOURCEURL );
95*cdf0e10cSrcweir     ImplRegisterProperty( BASEPROPERTY_GRAPHIC );
96*cdf0e10cSrcweir     ImplRegisterProperty( BASEPROPERTY_IMAGEURL );
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 	Any aBool;
99*cdf0e10cSrcweir 	aBool <<= (sal_Bool) sal_True;
100*cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_MOVEABLE, aBool );
101*cdf0e10cSrcweir 	ImplRegisterProperty( BASEPROPERTY_CLOSEABLE, aBool );
102*cdf0e10cSrcweir }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir UnoControlDialogModel::UnoControlDialogModel( const UnoControlDialogModel& rModel )
105*cdf0e10cSrcweir 	: ControlModelContainerBase( rModel )
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir UnoControlDialogModel::~UnoControlDialogModel()
110*cdf0e10cSrcweir {
111*cdf0e10cSrcweir }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir UnoControlModel* UnoControlDialogModel::Clone() const
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir 	// clone the container itself
116*cdf0e10cSrcweir 	UnoControlDialogModel* pClone = new UnoControlDialogModel( *this );
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	Clone_Impl(*pClone);
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 	return pClone;
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir ::rtl::OUString UnoControlDialogModel::getServiceName( ) throw(RuntimeException)
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir 	return ::rtl::OUString::createFromAscii( szServiceName_UnoControlDialogModel );
127*cdf0e10cSrcweir }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir Any UnoControlDialogModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir     Any aAny;
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir     switch ( nPropId )
134*cdf0e10cSrcweir     {
135*cdf0e10cSrcweir         case BASEPROPERTY_DEFAULTCONTROL:
136*cdf0e10cSrcweir 		    aAny <<= ::rtl::OUString::createFromAscii( szServiceName_UnoControlDialog );
137*cdf0e10cSrcweir             break;
138*cdf0e10cSrcweir         default:
139*cdf0e10cSrcweir             aAny = UnoControlModel::ImplGetDefaultValue( nPropId );
140*cdf0e10cSrcweir     }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir     return aAny;
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& UnoControlDialogModel::getInfoHelper()
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir 	static UnoPropertyArrayHelper* pHelper = NULL;
148*cdf0e10cSrcweir 	if ( !pHelper )
149*cdf0e10cSrcweir 	{
150*cdf0e10cSrcweir 		Sequence<sal_Int32> aIDs = ImplGetPropertyIds();
151*cdf0e10cSrcweir 		pHelper = new UnoPropertyArrayHelper( aIDs );
152*cdf0e10cSrcweir 	}
153*cdf0e10cSrcweir 	return *pHelper;
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir // XMultiPropertySet
157*cdf0e10cSrcweir Reference< XPropertySetInfo > UnoControlDialogModel::getPropertySetInfo(  ) throw(RuntimeException)
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir 	static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
160*cdf0e10cSrcweir 	return xInfo;
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir // ============================================================================
164*cdf0e10cSrcweir // = class UnoDialogControl
165*cdf0e10cSrcweir // ============================================================================
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir UnoDialogControl::UnoDialogControl( const uno::Reference< lang::XMultiServiceFactory >& i_factory )
168*cdf0e10cSrcweir     :UnoDialogControl_Base( i_factory )
169*cdf0e10cSrcweir     ,maTopWindowListeners( *this )
170*cdf0e10cSrcweir     ,mbWindowListener(false)
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir 	maComponentInfos.nWidth = 300;
173*cdf0e10cSrcweir 	maComponentInfos.nHeight = 450;
174*cdf0e10cSrcweir  }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir UnoDialogControl::~UnoDialogControl()
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir ::rtl::OUString UnoDialogControl::GetComponentServiceName()
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir     sal_Bool bDecoration( sal_True );
184*cdf0e10cSrcweir     ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_DECORATION )) >>= bDecoration;
185*cdf0e10cSrcweir     if ( bDecoration )
186*cdf0e10cSrcweir         return ::rtl::OUString::createFromAscii( "Dialog" );
187*cdf0e10cSrcweir     else
188*cdf0e10cSrcweir         return ::rtl::OUString::createFromAscii( "TabPage" );
189*cdf0e10cSrcweir }
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir void UnoDialogControl::dispose() throw(RuntimeException)
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 	EventObject aEvt;
196*cdf0e10cSrcweir 	aEvt.Source = static_cast< ::cppu::OWeakObject* >( this );
197*cdf0e10cSrcweir 	maTopWindowListeners.disposeAndClear( aEvt );
198*cdf0e10cSrcweir     ControlContainerBase::dispose();
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir void SAL_CALL UnoDialogControl::disposing(
202*cdf0e10cSrcweir     const EventObject& Source )
203*cdf0e10cSrcweir throw(RuntimeException)
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir 	ControlContainerBase::disposing( Source );
206*cdf0e10cSrcweir }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir sal_Bool UnoDialogControl::setModel( const Reference< XControlModel >& rxModel ) throw(RuntimeException)
209*cdf0e10cSrcweir {
210*cdf0e10cSrcweir         // #Can we move all the Resource stuff to the ControlContainerBase ?
211*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
212*cdf0e10cSrcweir         sal_Bool bRet = ControlContainerBase::setModel( rxModel );
213*cdf0e10cSrcweir 	ImplStartListingForResourceEvents();
214*cdf0e10cSrcweir 	return bRet;
215*cdf0e10cSrcweir }
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir void UnoDialogControl::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer >  & rParentPeer ) throw(RuntimeException)
218*cdf0e10cSrcweir {
219*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 	UnoControlContainer::createPeer( rxToolkit, rParentPeer );
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 	Reference < XTopWindow > xTW( getPeer(), UNO_QUERY );
224*cdf0e10cSrcweir     if ( xTW.is() )
225*cdf0e10cSrcweir     {
226*cdf0e10cSrcweir         xTW->setMenuBar( mxMenuBar );
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir         if ( !mbWindowListener )
229*cdf0e10cSrcweir         {
230*cdf0e10cSrcweir             Reference< XWindowListener > xWL( static_cast< cppu::OWeakObject*>( this ), UNO_QUERY );
231*cdf0e10cSrcweir             addWindowListener( xWL );
232*cdf0e10cSrcweir             mbWindowListener = true;
233*cdf0e10cSrcweir         }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir         if ( maTopWindowListeners.getLength() )
236*cdf0e10cSrcweir 		    xTW->addTopWindowListener( &maTopWindowListeners );
237*cdf0e10cSrcweir     }
238*cdf0e10cSrcweir }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir void UnoDialogControl::PrepareWindowDescriptor( ::com::sun::star::awt::WindowDescriptor& rDesc )
241*cdf0e10cSrcweir {
242*cdf0e10cSrcweir     sal_Bool bDecoration( sal_True );
243*cdf0e10cSrcweir     ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_DECORATION )) >>= bDecoration;
244*cdf0e10cSrcweir     if ( !bDecoration )
245*cdf0e10cSrcweir     {
246*cdf0e10cSrcweir         // Now we have to manipulate the WindowDescriptor
247*cdf0e10cSrcweir         rDesc.WindowAttributes = rDesc.WindowAttributes | ::com::sun::star::awt::WindowAttribute::NODECORATION;
248*cdf0e10cSrcweir     }
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir     // We have to set the graphic property before the peer
251*cdf0e10cSrcweir     // will be created. Otherwise the properties will be copied
252*cdf0e10cSrcweir     // into the peer via propertiesChangeEvents. As the order of
253*cdf0e10cSrcweir     // can lead to overwrites we have to set the graphic property
254*cdf0e10cSrcweir     // before the propertiesChangeEvents are sent!
255*cdf0e10cSrcweir     ::rtl::OUString aImageURL;
256*cdf0e10cSrcweir     Reference< graphic::XGraphic > xGraphic;
257*cdf0e10cSrcweir     if (( ImplGetPropertyValue( PROPERTY_IMAGEURL ) >>= aImageURL ) &&
258*cdf0e10cSrcweir         ( aImageURL.getLength() > 0 ))
259*cdf0e10cSrcweir     {
260*cdf0e10cSrcweir         ::rtl::OUString absoluteUrl =
261*cdf0e10cSrcweir             getPhysicalLocation( ImplGetPropertyValue( PROPERTY_DIALOGSOURCEURL ),
262*cdf0e10cSrcweir                                  ImplGetPropertyValue( PROPERTY_IMAGEURL ));
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 		xGraphic = ControlContainerBase::Impl_getGraphicFromURL_nothrow( absoluteUrl );
265*cdf0e10cSrcweir         ImplSetPropertyValue( PROPERTY_GRAPHIC, uno::makeAny( xGraphic ), sal_True );
266*cdf0e10cSrcweir     }
267*cdf0e10cSrcweir }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir void UnoDialogControl::addTopWindowListener( const Reference< XTopWindowListener >& rxListener ) throw (RuntimeException)
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir 	maTopWindowListeners.addInterface( rxListener );
272*cdf0e10cSrcweir 	if( getPeer().is() && maTopWindowListeners.getLength() == 1 )
273*cdf0e10cSrcweir 	{
274*cdf0e10cSrcweir 		Reference < XTopWindow >  xTW( getPeer(), UNO_QUERY );
275*cdf0e10cSrcweir 		xTW->addTopWindowListener( &maTopWindowListeners );
276*cdf0e10cSrcweir 	}
277*cdf0e10cSrcweir }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir void UnoDialogControl::removeTopWindowListener( const Reference< XTopWindowListener >& rxListener ) throw (RuntimeException)
280*cdf0e10cSrcweir {
281*cdf0e10cSrcweir 	if( getPeer().is() && maTopWindowListeners.getLength() == 1 )
282*cdf0e10cSrcweir 	{
283*cdf0e10cSrcweir 		Reference < XTopWindow >  xTW( getPeer(), UNO_QUERY );
284*cdf0e10cSrcweir 		xTW->removeTopWindowListener( &maTopWindowListeners );
285*cdf0e10cSrcweir 	}
286*cdf0e10cSrcweir 	maTopWindowListeners.removeInterface( rxListener );
287*cdf0e10cSrcweir }
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir void UnoDialogControl::toFront(  ) throw (RuntimeException)
290*cdf0e10cSrcweir {
291*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
292*cdf0e10cSrcweir 	if ( getPeer().is() )
293*cdf0e10cSrcweir 	{
294*cdf0e10cSrcweir 		Reference< XTopWindow > xTW( getPeer(), UNO_QUERY );
295*cdf0e10cSrcweir 		if( xTW.is() )
296*cdf0e10cSrcweir 			xTW->toFront();
297*cdf0e10cSrcweir 	}
298*cdf0e10cSrcweir }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir void UnoDialogControl::toBack(  ) throw (RuntimeException)
301*cdf0e10cSrcweir {
302*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
303*cdf0e10cSrcweir 	if ( getPeer().is() )
304*cdf0e10cSrcweir 	{
305*cdf0e10cSrcweir 		Reference< XTopWindow > xTW( getPeer(), UNO_QUERY );
306*cdf0e10cSrcweir 		if( xTW.is() )
307*cdf0e10cSrcweir 			xTW->toBack();
308*cdf0e10cSrcweir 	}
309*cdf0e10cSrcweir }
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir void UnoDialogControl::setMenuBar( const Reference< XMenuBar >& rxMenuBar ) throw (RuntimeException)
312*cdf0e10cSrcweir {
313*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
314*cdf0e10cSrcweir 	mxMenuBar = rxMenuBar;
315*cdf0e10cSrcweir 	if ( getPeer().is() )
316*cdf0e10cSrcweir 	{
317*cdf0e10cSrcweir 		Reference< XTopWindow > xTW( getPeer(), UNO_QUERY );
318*cdf0e10cSrcweir 		if( xTW.is() )
319*cdf0e10cSrcweir 			xTW->setMenuBar( mxMenuBar );
320*cdf0e10cSrcweir 	}
321*cdf0e10cSrcweir }
322*cdf0e10cSrcweir static ::Size ImplMapPixelToAppFont( OutputDevice* pOutDev, const ::Size& aSize )
323*cdf0e10cSrcweir {
324*cdf0e10cSrcweir     ::Size aTmp = pOutDev->PixelToLogic( aSize, MAP_APPFONT );
325*cdf0e10cSrcweir     return aTmp;
326*cdf0e10cSrcweir }
327*cdf0e10cSrcweir // ::com::sun::star::awt::XWindowListener
328*cdf0e10cSrcweir void SAL_CALL UnoDialogControl::windowResized( const ::com::sun::star::awt::WindowEvent& e )
329*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
330*cdf0e10cSrcweir {
331*cdf0e10cSrcweir     OutputDevice*pOutDev = Application::GetDefaultDevice();
332*cdf0e10cSrcweir 	DBG_ASSERT( pOutDev, "Missing Default Device!" );
333*cdf0e10cSrcweir 	if ( pOutDev && !mbSizeModified )
334*cdf0e10cSrcweir 	{
335*cdf0e10cSrcweir         // Currentley we are simply using MAP_APPFONT
336*cdf0e10cSrcweir 		::Size aAppFontSize( e.Width, e.Height );
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir         Reference< XControl > xDialogControl( *this, UNO_QUERY_THROW );
339*cdf0e10cSrcweir         Reference< XDevice > xDialogDevice( xDialogControl->getPeer(), UNO_QUERY );
340*cdf0e10cSrcweir         OSL_ENSURE( xDialogDevice.is(), "UnoDialogControl::windowResized: no peer, but a windowResized event?" );
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir         // #i87592 In design mode the drawing layer works with sizes with decoration.
343*cdf0e10cSrcweir         // Therefore we have to substract them before writing back to the properties (model).
344*cdf0e10cSrcweir 		if ( xDialogDevice.is() && mbDesignMode )
345*cdf0e10cSrcweir         {
346*cdf0e10cSrcweir             DeviceInfo aDeviceInfo( xDialogDevice->getInfo() );
347*cdf0e10cSrcweir             aAppFontSize.Width() -= aDeviceInfo.LeftInset + aDeviceInfo.RightInset;
348*cdf0e10cSrcweir             aAppFontSize.Height() -= aDeviceInfo.TopInset + aDeviceInfo.BottomInset;
349*cdf0e10cSrcweir         }
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir         aAppFontSize = ImplMapPixelToAppFont( pOutDev, aAppFontSize );
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir         // Remember that changes have been done by listener. No need to
354*cdf0e10cSrcweir         // update the position because of property change event.
355*cdf0e10cSrcweir         mbSizeModified = true;
356*cdf0e10cSrcweir         Sequence< rtl::OUString > aProps( 2 );
357*cdf0e10cSrcweir         Sequence< Any > aValues( 2 );
358*cdf0e10cSrcweir         // Properties in a sequence must be sorted!
359*cdf0e10cSrcweir         aProps[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" ));
360*cdf0e10cSrcweir         aProps[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width"  ));
361*cdf0e10cSrcweir         aValues[0] <<= aAppFontSize.Height();
362*cdf0e10cSrcweir         aValues[1] <<= aAppFontSize.Width();
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir 	    ImplSetPropertyValues( aProps, aValues, true );
365*cdf0e10cSrcweir         mbSizeModified = false;
366*cdf0e10cSrcweir 	}
367*cdf0e10cSrcweir }
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir void SAL_CALL UnoDialogControl::windowMoved( const ::com::sun::star::awt::WindowEvent& e )
370*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
371*cdf0e10cSrcweir {
372*cdf0e10cSrcweir 	OutputDevice*pOutDev = Application::GetDefaultDevice();
373*cdf0e10cSrcweir 	DBG_ASSERT( pOutDev, "Missing Default Device!" );
374*cdf0e10cSrcweir 	if ( pOutDev && !mbPosModified )
375*cdf0e10cSrcweir 	{
376*cdf0e10cSrcweir         // Currentley we are simply using MAP_APPFONT
377*cdf0e10cSrcweir         Any    aAny;
378*cdf0e10cSrcweir 		::Size aTmp( e.X, e.Y );
379*cdf0e10cSrcweir         aTmp = ImplMapPixelToAppFont( pOutDev, aTmp );
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir         // Remember that changes have been done by listener. No need to
382*cdf0e10cSrcweir         // update the position because of property change event.
383*cdf0e10cSrcweir         mbPosModified = true;
384*cdf0e10cSrcweir         Sequence< rtl::OUString > aProps( 2 );
385*cdf0e10cSrcweir         Sequence< Any > aValues( 2 );
386*cdf0e10cSrcweir         aProps[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionX"  ));
387*cdf0e10cSrcweir         aProps[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionY" ));
388*cdf0e10cSrcweir         aValues[0] <<= aTmp.Width();
389*cdf0e10cSrcweir         aValues[1] <<= aTmp.Height();
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir 	    ImplSetPropertyValues( aProps, aValues, true );
392*cdf0e10cSrcweir         mbPosModified = false;
393*cdf0e10cSrcweir 	}
394*cdf0e10cSrcweir }
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir void SAL_CALL UnoDialogControl::windowShown( const EventObject& e ) throw (RuntimeException)
397*cdf0e10cSrcweir {
398*cdf0e10cSrcweir     (void)e;
399*cdf0e10cSrcweir }
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir void SAL_CALL UnoDialogControl::windowHidden( const EventObject& e ) throw (RuntimeException)
402*cdf0e10cSrcweir {
403*cdf0e10cSrcweir     (void)e;
404*cdf0e10cSrcweir }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir void SAL_CALL UnoDialogControl::endDialog( ::sal_Int32 i_result ) throw (RuntimeException)
407*cdf0e10cSrcweir {
408*cdf0e10cSrcweir     Reference< XDialog2 > xPeerDialog( getPeer(), UNO_QUERY );
409*cdf0e10cSrcweir     if ( xPeerDialog.is() )
410*cdf0e10cSrcweir         xPeerDialog->endDialog( i_result );
411*cdf0e10cSrcweir }
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir void SAL_CALL UnoDialogControl::setHelpId( const rtl::OUString& i_id ) throw (RuntimeException)
414*cdf0e10cSrcweir {
415*cdf0e10cSrcweir     Reference< XDialog2 > xPeerDialog( getPeer(), UNO_QUERY );
416*cdf0e10cSrcweir     if ( xPeerDialog.is() )
417*cdf0e10cSrcweir         xPeerDialog->setHelpId( i_id );
418*cdf0e10cSrcweir }
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir void UnoDialogControl::setTitle( const ::rtl::OUString& Title ) throw(RuntimeException)
421*cdf0e10cSrcweir {
422*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
423*cdf0e10cSrcweir 	Any aAny;
424*cdf0e10cSrcweir 	aAny <<= Title;
425*cdf0e10cSrcweir 	ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_TITLE ), aAny, sal_True );
426*cdf0e10cSrcweir }
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir ::rtl::OUString UnoDialogControl::getTitle() throw(RuntimeException)
429*cdf0e10cSrcweir {
430*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
431*cdf0e10cSrcweir 	return ImplGetPropertyValue_UString( BASEPROPERTY_TITLE );
432*cdf0e10cSrcweir }
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir sal_Int16 UnoDialogControl::execute() throw(RuntimeException)
435*cdf0e10cSrcweir {
436*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
437*cdf0e10cSrcweir 	sal_Int16 nDone = -1;
438*cdf0e10cSrcweir 	if ( getPeer().is() )
439*cdf0e10cSrcweir 	{
440*cdf0e10cSrcweir 		Reference< XDialog > xDlg( getPeer(), UNO_QUERY );
441*cdf0e10cSrcweir 		if( xDlg.is() )
442*cdf0e10cSrcweir 		{
443*cdf0e10cSrcweir 			GetComponentInfos().bVisible = sal_True;
444*cdf0e10cSrcweir 			nDone = xDlg->execute();
445*cdf0e10cSrcweir 			GetComponentInfos().bVisible = sal_False;
446*cdf0e10cSrcweir 		}
447*cdf0e10cSrcweir 	}
448*cdf0e10cSrcweir 	return nDone;
449*cdf0e10cSrcweir }
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir void UnoDialogControl::endExecute() throw(RuntimeException)
452*cdf0e10cSrcweir {
453*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
454*cdf0e10cSrcweir 	if ( getPeer().is() )
455*cdf0e10cSrcweir 	{
456*cdf0e10cSrcweir 		Reference< XDialog > xDlg( getPeer(), UNO_QUERY );
457*cdf0e10cSrcweir 		if( xDlg.is() )
458*cdf0e10cSrcweir 		{
459*cdf0e10cSrcweir 			xDlg->endExecute();
460*cdf0e10cSrcweir 			GetComponentInfos().bVisible = sal_False;
461*cdf0e10cSrcweir 		}
462*cdf0e10cSrcweir 	}
463*cdf0e10cSrcweir }
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir // XModifyListener
466*cdf0e10cSrcweir void SAL_CALL UnoDialogControl::modified(
467*cdf0e10cSrcweir     const lang::EventObject& /*rEvent*/ )
468*cdf0e10cSrcweir throw (RuntimeException)
469*cdf0e10cSrcweir {
470*cdf0e10cSrcweir     ImplUpdateResourceResolver();
471*cdf0e10cSrcweir }
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir void UnoDialogControl::ImplModelPropertiesChanged( const Sequence< PropertyChangeEvent >& rEvents ) throw(RuntimeException)
474*cdf0e10cSrcweir {
475*cdf0e10cSrcweir     sal_Int32 nLen = rEvents.getLength();
476*cdf0e10cSrcweir 	for( sal_Int32 i = 0; i < nLen; i++ )
477*cdf0e10cSrcweir 	{
478*cdf0e10cSrcweir 		const PropertyChangeEvent& rEvt = rEvents.getConstArray()[i];
479*cdf0e10cSrcweir 		Reference< XControlModel > xModel( rEvt.Source, UNO_QUERY );
480*cdf0e10cSrcweir 		sal_Bool bOwnModel = (XControlModel*)xModel.get() == (XControlModel*)getModel().get();
481*cdf0e10cSrcweir         if ( bOwnModel && rEvt.PropertyName.equalsAsciiL( "ImageURL", 8 ))
482*cdf0e10cSrcweir         {
483*cdf0e10cSrcweir             ::rtl::OUString aImageURL;
484*cdf0e10cSrcweir             Reference< graphic::XGraphic > xGraphic;
485*cdf0e10cSrcweir             if (( ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_IMAGEURL ) ) >>= aImageURL ) &&
486*cdf0e10cSrcweir                 ( aImageURL.getLength() > 0 ))
487*cdf0e10cSrcweir             {
488*cdf0e10cSrcweir                 ::rtl::OUString absoluteUrl =
489*cdf0e10cSrcweir                     getPhysicalLocation( ImplGetPropertyValue( GetPropertyName( BASEPROPERTY_DIALOGSOURCEURL )),
490*cdf0e10cSrcweir                                          uno::makeAny(aImageURL));
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir                 xGraphic = Impl_getGraphicFromURL_nothrow( absoluteUrl );
493*cdf0e10cSrcweir             }
494*cdf0e10cSrcweir             ImplSetPropertyValue(  GetPropertyName( BASEPROPERTY_GRAPHIC), uno::makeAny( xGraphic ), sal_True );
495*cdf0e10cSrcweir             break;
496*cdf0e10cSrcweir         }
497*cdf0e10cSrcweir     }
498*cdf0e10cSrcweir     ControlContainerBase::ImplModelPropertiesChanged(rEvents);
499*cdf0e10cSrcweir }
500