1c142477cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3c142477cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4c142477cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5c142477cSAndrew Rist  * distributed with this work for additional information
6c142477cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7c142477cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8c142477cSAndrew Rist  * "License"); you may not use this file except in compliance
9c142477cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10c142477cSAndrew Rist  *
11c142477cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12c142477cSAndrew Rist  *
13c142477cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14c142477cSAndrew Rist  * software distributed under the License is distributed on an
15c142477cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16c142477cSAndrew Rist  * KIND, either express or implied.  See the License for the
17c142477cSAndrew Rist  * specific language governing permissions and limitations
18c142477cSAndrew Rist  * under the License.
19c142477cSAndrew Rist  *
20c142477cSAndrew Rist  *************************************************************/
21c142477cSAndrew Rist 
22c142477cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sdext.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "unodialog.hxx"
28e4a7f284SAriel Constenla-Haile #include <com/sun/star/text/XTextRange.hpp>
29*880c69c6SAriel Constenla-Haile #include <com/sun/star/drawing/XShapes.hpp>
30*880c69c6SAriel Constenla-Haile #include <com/sun/star/container/XIndexAccess.hpp>
31e4a7f284SAriel Constenla-Haile #include <com/sun/star/view/XSelectionSupplier.hpp>
32*880c69c6SAriel Constenla-Haile #include <com/sun/star/view/XControlAccess.hpp>
33*880c69c6SAriel Constenla-Haile #include <com/sun/star/frame/XDispatch.hpp>
34*880c69c6SAriel Constenla-Haile #include <com/sun/star/awt/XMessageBoxFactory.hpp>
35*880c69c6SAriel Constenla-Haile #include <com/sun/star/awt/MessageBoxButtons.hpp>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir // -------------
38cdf0e10cSrcweir // - UnoDialog -
39cdf0e10cSrcweir // -------------
40cdf0e10cSrcweir 
41*880c69c6SAriel Constenla-Haile using namespace ::rtl;
42cdf0e10cSrcweir using namespace ::com::sun::star::awt;
43cdf0e10cSrcweir using namespace ::com::sun::star::uno;
44cdf0e10cSrcweir using namespace ::com::sun::star::util;
45cdf0e10cSrcweir using namespace ::com::sun::star::lang;
46cdf0e10cSrcweir using namespace ::com::sun::star::view;
47cdf0e10cSrcweir using namespace ::com::sun::star::frame;
48cdf0e10cSrcweir using namespace ::com::sun::star::beans;
49cdf0e10cSrcweir using namespace ::com::sun::star::script;
50cdf0e10cSrcweir 
51*880c69c6SAriel Constenla-Haile UnoDialog::UnoDialog( const Reference< XComponentContext > &rxMSF, Reference< XFrame >& rxFrame ) :
52*880c69c6SAriel Constenla-Haile 	mxMSF( rxMSF ),
53*880c69c6SAriel Constenla-Haile 	mxController( rxFrame->getController() ),
54*880c69c6SAriel Constenla-Haile 	mxDialogModel( mxMSF->getServiceManager()->createInstanceWithContext( OUString( RTL_CONSTASCII_USTRINGPARAM(
55*880c69c6SAriel Constenla-Haile 		"com.sun.star.awt.UnoControlDialogModel" ) ), mxMSF ), UNO_QUERY_THROW ),
56cdf0e10cSrcweir 	mxDialogModelMultiPropertySet( mxDialogModel, UNO_QUERY_THROW ),
57cdf0e10cSrcweir 	mxDialogModelPropertySet( mxDialogModel, UNO_QUERY_THROW ),
58cdf0e10cSrcweir 	mxDialogModelMSF( mxDialogModel, UNO_QUERY_THROW ),
59cdf0e10cSrcweir 	mxDialogModelNameContainer( mxDialogModel, UNO_QUERY_THROW ),
60cdf0e10cSrcweir 	mxDialogModelNameAccess( mxDialogModel, UNO_QUERY_THROW ),
61cdf0e10cSrcweir 	mxControlModel( mxDialogModel, UNO_QUERY_THROW ),
62*880c69c6SAriel Constenla-Haile 	mxDialog( mxMSF->getServiceManager()->createInstanceWithContext( OUString( RTL_CONSTASCII_USTRINGPARAM(
63*880c69c6SAriel Constenla-Haile 		"com.sun.star.awt.UnoControlDialog" ) ), mxMSF ), UNO_QUERY_THROW ),
64cdf0e10cSrcweir 	mxControl( mxDialog, UNO_QUERY_THROW ),
65cdf0e10cSrcweir 	mbStatus( sal_False )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	mxControl->setModel( mxControlModel );
68cdf0e10cSrcweir 	mxDialogControlContainer = Reference< XControlContainer >( mxDialog, UNO_QUERY_THROW );
69*880c69c6SAriel Constenla-Haile 	mxDialogComponent = Reference< XComponent >( mxDialog, UNO_QUERY_THROW );
70*880c69c6SAriel Constenla-Haile 	mxDialogWindow = Reference< XWindow >( mxDialog, UNO_QUERY_THROW );
71*880c69c6SAriel Constenla-Haile 
72*880c69c6SAriel Constenla-Haile 	Reference< XFrame > xFrame( mxController->getFrame() );
73*880c69c6SAriel Constenla-Haile 	Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() );
74*880c69c6SAriel Constenla-Haile 	mxWindowPeer = Reference< XWindowPeer >( xContainerWindow, UNO_QUERY_THROW );
75*880c69c6SAriel Constenla-Haile 	createWindowPeer( mxWindowPeer );
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir // -----------------------------------------------------------------------------
79cdf0e10cSrcweir 
80cdf0e10cSrcweir UnoDialog::~UnoDialog()
81cdf0e10cSrcweir {
82*880c69c6SAriel Constenla-Haile 
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir // -----------------------------------------------------------------------------
86cdf0e10cSrcweir 
87cdf0e10cSrcweir void UnoDialog::execute()
88cdf0e10cSrcweir {
89cdf0e10cSrcweir 	mxDialogWindow->setEnable( sal_True );
90cdf0e10cSrcweir 	mxDialogWindow->setVisible( sal_True );
91cdf0e10cSrcweir 	mxDialog->execute();
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir void UnoDialog::endExecute( sal_Bool bStatus )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	mbStatus = bStatus;
97cdf0e10cSrcweir 	mxDialog->endExecute();
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir // -----------------------------------------------------------------------------
101cdf0e10cSrcweir 
102*880c69c6SAriel Constenla-Haile Reference< XWindowPeer > UnoDialog::createWindowPeer( Reference< XWindowPeer > xParentPeer )
103cdf0e10cSrcweir 	throw ( Exception )
104cdf0e10cSrcweir {
105*880c69c6SAriel Constenla-Haile 	mxDialogWindow->setVisible( sal_False );
106*880c69c6SAriel Constenla-Haile 	Reference< XToolkit > xToolkit( mxMSF->getServiceManager()->createInstanceWithContext( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ), mxMSF ), UNO_QUERY_THROW  );
107*880c69c6SAriel Constenla-Haile 	if ( !xParentPeer.is() )
108*880c69c6SAriel Constenla-Haile 		xParentPeer = xToolkit->getDesktopWindow();
109cdf0e10cSrcweir 	mxReschedule = Reference< XReschedule >( xToolkit, UNO_QUERY );
110*880c69c6SAriel Constenla-Haile 	mxControl->createPeer( xToolkit, xParentPeer );
111*880c69c6SAriel Constenla-Haile //	xWindowPeer = xControl.getPeer();
112cdf0e10cSrcweir 	return mxControl->getPeer();
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir // -----------------------------------------------------------------------------
116cdf0e10cSrcweir 
117cdf0e10cSrcweir Reference< XInterface > UnoDialog::insertControlModel( const OUString& rServiceName, const OUString& rName,
118cdf0e10cSrcweir 														const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir 	Reference< XInterface > xControlModel;
121cdf0e10cSrcweir 	try
122cdf0e10cSrcweir 	{
123cdf0e10cSrcweir         xControlModel = mxDialogModelMSF->createInstance( rServiceName );
124cdf0e10cSrcweir 		Reference< XMultiPropertySet > xMultiPropSet( xControlModel, UNO_QUERY_THROW );
125cdf0e10cSrcweir 		xMultiPropSet->setPropertyValues( rPropertyNames, rPropertyValues );
126cdf0e10cSrcweir         mxDialogModelNameContainer->insertByName( rName, Any( xControlModel ) );
127cdf0e10cSrcweir     }
128cdf0e10cSrcweir 	catch( Exception& )
129cdf0e10cSrcweir 	{
130cdf0e10cSrcweir     }
131cdf0e10cSrcweir 	return xControlModel;
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir // -----------------------------------------------------------------------------
135cdf0e10cSrcweir 
136cdf0e10cSrcweir void UnoDialog::setVisible( const OUString& rName, sal_Bool bVisible )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir 	try
139cdf0e10cSrcweir 	{
140cdf0e10cSrcweir 		Reference< XInterface > xControl( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
141cdf0e10cSrcweir 		Reference< XWindow > xWindow( xControl, UNO_QUERY_THROW );
142cdf0e10cSrcweir 		xWindow->setVisible( bVisible );
143cdf0e10cSrcweir 	}
144cdf0e10cSrcweir 	catch ( Exception& )
145cdf0e10cSrcweir 	{
146cdf0e10cSrcweir 	}
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir // -----------------------------------------------------------------------------
150cdf0e10cSrcweir 
151cdf0e10cSrcweir sal_Bool UnoDialog::isHighContrast()
152cdf0e10cSrcweir {
153cdf0e10cSrcweir 	sal_Bool bHighContrast = sal_False;
154cdf0e10cSrcweir 	try
155cdf0e10cSrcweir 	{
156*880c69c6SAriel Constenla-Haile 		sal_Int32 nBackgroundColor = 0;
157*880c69c6SAriel Constenla-Haile 		if ( mxDialogModelPropertySet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "BackgroundColor" ) ) ) >>= nBackgroundColor )
158*880c69c6SAriel Constenla-Haile 		{
159*880c69c6SAriel Constenla-Haile 			sal_uInt8 nLum( static_cast< sal_uInt8 >( ( static_cast< sal_uInt8 >( nBackgroundColor >> 16 ) * 28 +
160*880c69c6SAriel Constenla-Haile 														static_cast< sal_uInt8 >( nBackgroundColor >> 8 ) * 151 +
161*880c69c6SAriel Constenla-Haile 														static_cast< sal_uInt8 >( nBackgroundColor ) * 77 ) >> 8 ) );
162*880c69c6SAriel Constenla-Haile 			bHighContrast = nLum <= 38;
163*880c69c6SAriel Constenla-Haile 		}
164cdf0e10cSrcweir 	}
165cdf0e10cSrcweir 	catch( Exception& )
166cdf0e10cSrcweir 	{
167cdf0e10cSrcweir 	}
168cdf0e10cSrcweir 	return bHighContrast;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir // -----------------------------------------------------------------------------
172cdf0e10cSrcweir 
173cdf0e10cSrcweir Reference< XButton > UnoDialog::insertButton( const OUString& rName, Reference< XActionListener > xActionListener,
174cdf0e10cSrcweir 			const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
175cdf0e10cSrcweir {
176cdf0e10cSrcweir 	Reference< XButton > xButton;
177cdf0e10cSrcweir 	try
178cdf0e10cSrcweir 	{
179cdf0e10cSrcweir         Reference< XInterface > xButtonModel( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlButtonModel" ) ),
180cdf0e10cSrcweir 			rName, rPropertyNames, rPropertyValues ) );
181cdf0e10cSrcweir 		Reference< XPropertySet > xPropertySet( xButtonModel, UNO_QUERY_THROW );
182cdf0e10cSrcweir 		xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
183cdf0e10cSrcweir 		xButton = Reference< XButton >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 		if ( xActionListener.is() )
186cdf0e10cSrcweir 		{
187cdf0e10cSrcweir             xButton->addActionListener( xActionListener );
188cdf0e10cSrcweir 			xButton->setActionCommand( rName );
189cdf0e10cSrcweir 		}
190cdf0e10cSrcweir 		return xButton;
191cdf0e10cSrcweir 	}
192cdf0e10cSrcweir 	catch( Exception& )
193cdf0e10cSrcweir 	{
194cdf0e10cSrcweir 	}
195cdf0e10cSrcweir 	return xButton;
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir // -----------------------------------------------------------------------------
199cdf0e10cSrcweir 
200cdf0e10cSrcweir Reference< XFixedText > UnoDialog::insertFixedText( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir 	Reference< XFixedText > xFixedText;
203cdf0e10cSrcweir 	try
204cdf0e10cSrcweir 	{
205cdf0e10cSrcweir 		Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlFixedTextModel" ) ),
206cdf0e10cSrcweir 			rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
207cdf0e10cSrcweir         xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
208cdf0e10cSrcweir 		xFixedText = Reference< XFixedText >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
209cdf0e10cSrcweir 	}
210cdf0e10cSrcweir 	catch ( Exception& )
211cdf0e10cSrcweir 	{
212cdf0e10cSrcweir     }
213cdf0e10cSrcweir 	return xFixedText;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir // -----------------------------------------------------------------------------
217cdf0e10cSrcweir 
218cdf0e10cSrcweir Reference< XCheckBox > UnoDialog::insertCheckBox( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir 	Reference< XCheckBox > xCheckBox;
221cdf0e10cSrcweir 	try
222cdf0e10cSrcweir 	{
223cdf0e10cSrcweir 		Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlCheckBoxModel" ) ),
224cdf0e10cSrcweir 			rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
225cdf0e10cSrcweir         xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
226cdf0e10cSrcweir 		xCheckBox = Reference< XCheckBox >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
227cdf0e10cSrcweir 	}
228cdf0e10cSrcweir 	catch ( Exception& )
229cdf0e10cSrcweir 	{
230cdf0e10cSrcweir     }
231cdf0e10cSrcweir 	return xCheckBox;
232cdf0e10cSrcweir }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir // -----------------------------------------------------------------------------
235cdf0e10cSrcweir 
236cdf0e10cSrcweir Reference< XControl > UnoDialog::insertFormattedField( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
237cdf0e10cSrcweir {
238cdf0e10cSrcweir 	Reference< XControl > xControl;
239cdf0e10cSrcweir 	try
240cdf0e10cSrcweir 	{
241cdf0e10cSrcweir 		Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlFormattedFieldModel" ) ),
242cdf0e10cSrcweir 			rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
243cdf0e10cSrcweir         xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
244cdf0e10cSrcweir 		xControl = Reference< XControl >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
245cdf0e10cSrcweir 	}
246cdf0e10cSrcweir 	catch ( Exception& )
247cdf0e10cSrcweir 	{
248cdf0e10cSrcweir     }
249cdf0e10cSrcweir 	return xControl;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir // -----------------------------------------------------------------------------
253cdf0e10cSrcweir 
254cdf0e10cSrcweir Reference< XComboBox > UnoDialog::insertComboBox( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
255cdf0e10cSrcweir {
256cdf0e10cSrcweir 	Reference< XComboBox > xControl;
257cdf0e10cSrcweir 	try
258cdf0e10cSrcweir 	{
259cdf0e10cSrcweir 		Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlComboBoxModel" ) ),
260cdf0e10cSrcweir 			rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
261cdf0e10cSrcweir         xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
262cdf0e10cSrcweir 		xControl = Reference< XComboBox >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
263cdf0e10cSrcweir 	}
264cdf0e10cSrcweir 	catch ( Exception& )
265cdf0e10cSrcweir 	{
266cdf0e10cSrcweir 	}
267cdf0e10cSrcweir 	return xControl;
268cdf0e10cSrcweir }
269cdf0e10cSrcweir 
270cdf0e10cSrcweir // -----------------------------------------------------------------------------
271cdf0e10cSrcweir 
272cdf0e10cSrcweir Reference< XRadioButton > UnoDialog::insertRadioButton( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir 	Reference< XRadioButton > xControl;
275cdf0e10cSrcweir 	try
276cdf0e10cSrcweir 	{
277cdf0e10cSrcweir 		Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlRadioButtonModel" ) ),
278cdf0e10cSrcweir 			rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
279cdf0e10cSrcweir         xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
280cdf0e10cSrcweir 		xControl = Reference< XRadioButton >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
281cdf0e10cSrcweir 	}
282cdf0e10cSrcweir 	catch ( Exception& )
283cdf0e10cSrcweir 	{
284cdf0e10cSrcweir 	}
285cdf0e10cSrcweir 	return xControl;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir 
288cdf0e10cSrcweir // -----------------------------------------------------------------------------
289cdf0e10cSrcweir 
290cdf0e10cSrcweir Reference< XListBox > UnoDialog::insertListBox( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
291cdf0e10cSrcweir {
292cdf0e10cSrcweir 	Reference< XListBox > xControl;
293cdf0e10cSrcweir 	try
294cdf0e10cSrcweir 	{
295cdf0e10cSrcweir 		Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlListBoxModel" ) ),
296cdf0e10cSrcweir 			rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
297cdf0e10cSrcweir         xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
298cdf0e10cSrcweir 		xControl = Reference< XListBox >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
299cdf0e10cSrcweir 	}
300cdf0e10cSrcweir 	catch ( Exception& )
301cdf0e10cSrcweir 	{
302cdf0e10cSrcweir 	}
303cdf0e10cSrcweir 	return xControl;
304cdf0e10cSrcweir }
305cdf0e10cSrcweir 
306cdf0e10cSrcweir // -----------------------------------------------------------------------------
307cdf0e10cSrcweir 
308cdf0e10cSrcweir Reference< XControl > UnoDialog::insertImage( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
309cdf0e10cSrcweir {
310cdf0e10cSrcweir 	Reference< XControl > xControl;
311cdf0e10cSrcweir 	try
312cdf0e10cSrcweir 	{
313cdf0e10cSrcweir 		Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlImageControlModel" ) ),
314cdf0e10cSrcweir 			rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
315cdf0e10cSrcweir         xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
316cdf0e10cSrcweir 		xControl = Reference< XControl >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
317cdf0e10cSrcweir 	}
318cdf0e10cSrcweir 	catch ( Exception& )
319cdf0e10cSrcweir 	{
320cdf0e10cSrcweir     }
321cdf0e10cSrcweir 	return xControl;
322cdf0e10cSrcweir }
323cdf0e10cSrcweir 
324cdf0e10cSrcweir // -----------------------------------------------------------------------------
325cdf0e10cSrcweir 
326cdf0e10cSrcweir void UnoDialog::setControlProperty( const OUString& rControlName, const OUString& rPropertyName, const Any& rPropertyValue )
327cdf0e10cSrcweir {
328cdf0e10cSrcweir     try
329cdf0e10cSrcweir 	{
330cdf0e10cSrcweir 		if ( mxDialogModelNameAccess->hasByName( rControlName ) )
331cdf0e10cSrcweir 		{
332cdf0e10cSrcweir 			Reference< XPropertySet > xPropertySet( mxDialogModelNameAccess->getByName( rControlName ), UNO_QUERY_THROW );
333cdf0e10cSrcweir 			xPropertySet->setPropertyValue( rPropertyName, rPropertyValue );
334cdf0e10cSrcweir 		}
335cdf0e10cSrcweir     }
336cdf0e10cSrcweir 	catch ( Exception& )
337cdf0e10cSrcweir 	{
338cdf0e10cSrcweir     }
339cdf0e10cSrcweir }
340cdf0e10cSrcweir 
341cdf0e10cSrcweir // -----------------------------------------------------------------------------
342cdf0e10cSrcweir 
343cdf0e10cSrcweir sal_Int32 UnoDialog::getMapsFromPixels( sal_Int32 nPixels ) const
344cdf0e10cSrcweir {
345cdf0e10cSrcweir 	double dMaps = 0;
346cdf0e10cSrcweir 	try
347cdf0e10cSrcweir 	{
348cdf0e10cSrcweir 		sal_Int32 nMapWidth = 0;
349cdf0e10cSrcweir 		const OUString sWidth( RTL_CONSTASCII_USTRINGPARAM( "Width" ) );
350cdf0e10cSrcweir 		if ( mxDialogModelPropertySet->getPropertyValue( sWidth  ) >>= nMapWidth )
351cdf0e10cSrcweir 		{
352cdf0e10cSrcweir 			Reference< XWindow > xWindow( mxDialog, UNO_QUERY_THROW );
353cdf0e10cSrcweir 			double pxWidth = xWindow->getPosSize().Width;
354cdf0e10cSrcweir 			double mapRatio = ( pxWidth / nMapWidth );
355cdf0e10cSrcweir 			dMaps = nPixels / mapRatio;
356cdf0e10cSrcweir 		}
357cdf0e10cSrcweir 	}
358cdf0e10cSrcweir 	catch ( Exception& )
359cdf0e10cSrcweir 	{
360cdf0e10cSrcweir 	}
361cdf0e10cSrcweir 	return static_cast< sal_Int32 >( dMaps );
362cdf0e10cSrcweir }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir // -----------------------------------------------------------------------------
365cdf0e10cSrcweir 
366cdf0e10cSrcweir Any UnoDialog::getControlProperty( const OUString& rControlName, const OUString& rPropertyName )
367cdf0e10cSrcweir {
368cdf0e10cSrcweir 	Any aRet;
369cdf0e10cSrcweir     try
370cdf0e10cSrcweir 	{
371cdf0e10cSrcweir 		if ( mxDialogModelNameAccess->hasByName( rControlName ) )
372cdf0e10cSrcweir 		{
373cdf0e10cSrcweir 			Reference< XPropertySet > xPropertySet( mxDialogModelNameAccess->getByName( rControlName ), UNO_QUERY_THROW );
374cdf0e10cSrcweir 			aRet = xPropertySet->getPropertyValue( rPropertyName );
375cdf0e10cSrcweir 		}
376cdf0e10cSrcweir     }
377cdf0e10cSrcweir 	catch ( Exception& )
378cdf0e10cSrcweir 	{
379cdf0e10cSrcweir     }
380cdf0e10cSrcweir 	return aRet;
381cdf0e10cSrcweir }
382cdf0e10cSrcweir 
383cdf0e10cSrcweir // -----------------------------------------------------------------------------
384cdf0e10cSrcweir 
385cdf0e10cSrcweir void UnoDialog::enableControl( const OUString& rControlName )
386cdf0e10cSrcweir {
387cdf0e10cSrcweir 	const OUString sEnabled( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) );
388cdf0e10cSrcweir 	setControlProperty( rControlName, sEnabled, Any( sal_True ) );
389cdf0e10cSrcweir }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir // -----------------------------------------------------------------------------
392cdf0e10cSrcweir 
393cdf0e10cSrcweir void UnoDialog::disableControl( const OUString& rControlName )
394cdf0e10cSrcweir {
395cdf0e10cSrcweir 	const OUString sEnabled( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) );
396cdf0e10cSrcweir 	setControlProperty( rControlName, sEnabled, Any( sal_False ) );
397cdf0e10cSrcweir }
398cdf0e10cSrcweir 
399cdf0e10cSrcweir // -----------------------------------------------------------------------------
400