Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "unodialog.hxx"
31 : : #include <com/sun/star/text/XTextRange.hpp>
32 : : #include <com/sun/star/drawing/XShapes.hpp>
33 : : #include <com/sun/star/container/XIndexAccess.hpp>
34 : : #include <com/sun/star/view/XSelectionSupplier.hpp>
35 : : #include <com/sun/star/view/XControlAccess.hpp>
36 : : #include <com/sun/star/frame/XDispatch.hpp>
37 : : #include <com/sun/star/awt/XMessageBoxFactory.hpp>
38 : : #include <com/sun/star/awt/MessageBoxButtons.hpp>
39 : :
40 : : // -------------
41 : : // - UnoDialog -
42 : : // -------------
43 : :
44 : : using namespace ::rtl;
45 : : using namespace ::com::sun::star::awt;
46 : : using namespace ::com::sun::star::uno;
47 : : using namespace ::com::sun::star::util;
48 : : using namespace ::com::sun::star::lang;
49 : : using namespace ::com::sun::star::view;
50 : : using namespace ::com::sun::star::frame;
51 : : using namespace ::com::sun::star::beans;
52 : : using namespace ::com::sun::star::script;
53 : :
54 : 0 : UnoDialog::UnoDialog( const Reference< XComponentContext > &rxMSF, Reference< XFrame >& rxFrame ) :
55 : : mxMSF( rxMSF ),
56 : 0 : mxController( rxFrame->getController() ),
57 : 0 : mxDialogModel( mxMSF->getServiceManager()->createInstanceWithContext( OUString( RTL_CONSTASCII_USTRINGPARAM(
58 : 0 : "com.sun.star.awt.UnoControlDialogModel" ) ), mxMSF ), UNO_QUERY_THROW ),
59 : : mxDialogModelMultiPropertySet( mxDialogModel, UNO_QUERY_THROW ),
60 : : mxDialogModelPropertySet( mxDialogModel, UNO_QUERY_THROW ),
61 : : mxDialogModelMSF( mxDialogModel, UNO_QUERY_THROW ),
62 : : mxDialogModelNameContainer( mxDialogModel, UNO_QUERY_THROW ),
63 : : mxDialogModelNameAccess( mxDialogModel, UNO_QUERY_THROW ),
64 : : mxControlModel( mxDialogModel, UNO_QUERY_THROW ),
65 : 0 : mxDialog( mxMSF->getServiceManager()->createInstanceWithContext( OUString( RTL_CONSTASCII_USTRINGPARAM(
66 : 0 : "com.sun.star.awt.UnoControlDialog" ) ), mxMSF ), UNO_QUERY_THROW ),
67 : : mxControl( mxDialog, UNO_QUERY_THROW ),
68 : 0 : mbStatus( sal_False )
69 : : {
70 : 0 : mxControl->setModel( mxControlModel );
71 : 0 : mxDialogControlContainer = Reference< XControlContainer >( mxDialog, UNO_QUERY_THROW );
72 : 0 : mxDialogComponent = Reference< XComponent >( mxDialog, UNO_QUERY_THROW );
73 : 0 : mxDialogWindow = Reference< XWindow >( mxDialog, UNO_QUERY_THROW );
74 : :
75 : 0 : Reference< XFrame > xFrame( mxController->getFrame() );
76 : 0 : Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() );
77 : 0 : mxWindowPeer = Reference< XWindowPeer >( xContainerWindow, UNO_QUERY_THROW );
78 : 0 : createWindowPeer( mxWindowPeer );
79 : 0 : }
80 : :
81 : : // -----------------------------------------------------------------------------
82 : :
83 : 0 : UnoDialog::~UnoDialog()
84 : : {
85 : :
86 : 0 : }
87 : :
88 : : // -----------------------------------------------------------------------------
89 : :
90 : 0 : void UnoDialog::execute()
91 : : {
92 : 0 : mxDialogWindow->setEnable( sal_True );
93 : 0 : mxDialogWindow->setVisible( sal_True );
94 : 0 : mxDialog->execute();
95 : 0 : }
96 : :
97 : 0 : void UnoDialog::endExecute( sal_Bool bStatus )
98 : : {
99 : 0 : mbStatus = bStatus;
100 : 0 : mxDialog->endExecute();
101 : 0 : }
102 : :
103 : : // -----------------------------------------------------------------------------
104 : :
105 : 0 : Reference< XWindowPeer > UnoDialog::createWindowPeer( Reference< XWindowPeer > xParentPeer )
106 : : throw ( Exception )
107 : : {
108 : 0 : mxDialogWindow->setVisible( sal_False );
109 : 0 : Reference< XToolkit > xToolkit( mxMSF->getServiceManager()->createInstanceWithContext( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ), mxMSF ), UNO_QUERY_THROW );
110 : 0 : if ( !xParentPeer.is() )
111 : 0 : xParentPeer = xToolkit->getDesktopWindow();
112 : 0 : mxReschedule = Reference< XReschedule >( xToolkit, UNO_QUERY );
113 : 0 : mxControl->createPeer( xToolkit, xParentPeer );
114 : : // xWindowPeer = xControl.getPeer();
115 : 0 : return mxControl->getPeer();
116 : : }
117 : :
118 : : // -----------------------------------------------------------------------------
119 : :
120 : 0 : Reference< XInterface > UnoDialog::insertControlModel( const OUString& rServiceName, const OUString& rName,
121 : : const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
122 : : {
123 : 0 : Reference< XInterface > xControlModel;
124 : : try
125 : : {
126 : 0 : xControlModel = mxDialogModelMSF->createInstance( rServiceName );
127 : 0 : Reference< XMultiPropertySet > xMultiPropSet( xControlModel, UNO_QUERY_THROW );
128 : 0 : xMultiPropSet->setPropertyValues( rPropertyNames, rPropertyValues );
129 : 0 : mxDialogModelNameContainer->insertByName( rName, Any( xControlModel ) );
130 : : }
131 : 0 : catch( Exception& )
132 : : {
133 : : }
134 : 0 : return xControlModel;
135 : : }
136 : :
137 : : // -----------------------------------------------------------------------------
138 : :
139 : 0 : void UnoDialog::setVisible( const OUString& rName, sal_Bool bVisible )
140 : : {
141 : : try
142 : : {
143 : 0 : Reference< XInterface > xControl( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
144 : 0 : Reference< XWindow > xWindow( xControl, UNO_QUERY_THROW );
145 : 0 : xWindow->setVisible( bVisible );
146 : : }
147 : 0 : catch ( Exception& )
148 : : {
149 : : }
150 : 0 : }
151 : :
152 : : // -----------------------------------------------------------------------------
153 : :
154 : 0 : Reference< XButton > UnoDialog::insertButton( const OUString& rName, Reference< XActionListener > xActionListener,
155 : : const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
156 : : {
157 : 0 : Reference< XButton > xButton;
158 : : try
159 : : {
160 : : Reference< XInterface > xButtonModel( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlButtonModel" ) ),
161 : 0 : rName, rPropertyNames, rPropertyValues ) );
162 : 0 : Reference< XPropertySet > xPropertySet( xButtonModel, UNO_QUERY_THROW );
163 : 0 : xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
164 : 0 : xButton = Reference< XButton >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
165 : :
166 : 0 : if ( xActionListener.is() )
167 : : {
168 : 0 : xButton->addActionListener( xActionListener );
169 : 0 : xButton->setActionCommand( rName );
170 : : }
171 : 0 : return xButton;
172 : : }
173 : 0 : catch( Exception& )
174 : : {
175 : : }
176 : 0 : return xButton;
177 : : }
178 : :
179 : : // -----------------------------------------------------------------------------
180 : :
181 : 0 : Reference< XFixedText > UnoDialog::insertFixedText( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
182 : : {
183 : 0 : Reference< XFixedText > xFixedText;
184 : : try
185 : : {
186 : : Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlFixedTextModel" ) ),
187 : 0 : rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
188 : 0 : xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
189 : 0 : xFixedText = Reference< XFixedText >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
190 : : }
191 : 0 : catch ( Exception& )
192 : : {
193 : : }
194 : 0 : return xFixedText;
195 : : }
196 : :
197 : : // -----------------------------------------------------------------------------
198 : :
199 : 0 : Reference< XCheckBox > UnoDialog::insertCheckBox( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
200 : : {
201 : 0 : Reference< XCheckBox > xCheckBox;
202 : : try
203 : : {
204 : : Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlCheckBoxModel" ) ),
205 : 0 : rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
206 : 0 : xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
207 : 0 : xCheckBox = Reference< XCheckBox >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
208 : : }
209 : 0 : catch ( Exception& )
210 : : {
211 : : }
212 : 0 : return xCheckBox;
213 : : }
214 : :
215 : : // -----------------------------------------------------------------------------
216 : :
217 : 0 : Reference< XControl > UnoDialog::insertFormattedField( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
218 : : {
219 : 0 : Reference< XControl > xControl;
220 : : try
221 : : {
222 : : Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlFormattedFieldModel" ) ),
223 : 0 : rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
224 : 0 : xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
225 : 0 : xControl = Reference< XControl >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
226 : : }
227 : 0 : catch ( Exception& )
228 : : {
229 : : }
230 : 0 : return xControl;
231 : : }
232 : :
233 : : // -----------------------------------------------------------------------------
234 : :
235 : 0 : Reference< XComboBox > UnoDialog::insertComboBox( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
236 : : {
237 : 0 : Reference< XComboBox > xControl;
238 : : try
239 : : {
240 : : Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlComboBoxModel" ) ),
241 : 0 : rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
242 : 0 : xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
243 : 0 : xControl = Reference< XComboBox >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
244 : : }
245 : 0 : catch ( Exception& )
246 : : {
247 : : }
248 : 0 : return xControl;
249 : : }
250 : :
251 : : // -----------------------------------------------------------------------------
252 : :
253 : 0 : Reference< XRadioButton > UnoDialog::insertRadioButton( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
254 : : {
255 : 0 : Reference< XRadioButton > xControl;
256 : : try
257 : : {
258 : : Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlRadioButtonModel" ) ),
259 : 0 : rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
260 : 0 : xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
261 : 0 : xControl = Reference< XRadioButton >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
262 : : }
263 : 0 : catch ( Exception& )
264 : : {
265 : : }
266 : 0 : return xControl;
267 : : }
268 : :
269 : : // -----------------------------------------------------------------------------
270 : :
271 : 0 : Reference< XListBox > UnoDialog::insertListBox( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
272 : : {
273 : 0 : Reference< XListBox > xControl;
274 : : try
275 : : {
276 : : Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlListBoxModel" ) ),
277 : 0 : rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
278 : 0 : xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
279 : 0 : xControl = Reference< XListBox >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
280 : : }
281 : 0 : catch ( Exception& )
282 : : {
283 : : }
284 : 0 : return xControl;
285 : : }
286 : :
287 : : // -----------------------------------------------------------------------------
288 : :
289 : 0 : Reference< XControl > UnoDialog::insertImage( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
290 : : {
291 : 0 : Reference< XControl > xControl;
292 : : try
293 : : {
294 : : Reference< XPropertySet > xPropertySet( insertControlModel( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlImageControlModel" ) ),
295 : 0 : rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
296 : 0 : xPropertySet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( rName ) );
297 : 0 : xControl = Reference< XControl >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
298 : : }
299 : 0 : catch ( Exception& )
300 : : {
301 : : }
302 : 0 : return xControl;
303 : : }
304 : :
305 : : // -----------------------------------------------------------------------------
306 : :
307 : 0 : void UnoDialog::setControlProperty( const OUString& rControlName, const OUString& rPropertyName, const Any& rPropertyValue )
308 : : {
309 : : try
310 : : {
311 : 0 : if ( mxDialogModelNameAccess->hasByName( rControlName ) )
312 : : {
313 : 0 : Reference< XPropertySet > xPropertySet( mxDialogModelNameAccess->getByName( rControlName ), UNO_QUERY_THROW );
314 : 0 : xPropertySet->setPropertyValue( rPropertyName, rPropertyValue );
315 : : }
316 : : }
317 : 0 : catch ( Exception& )
318 : : {
319 : : }
320 : 0 : }
321 : :
322 : : // -----------------------------------------------------------------------------
323 : :
324 : 0 : Any UnoDialog::getControlProperty( const OUString& rControlName, const OUString& rPropertyName )
325 : : {
326 : 0 : Any aRet;
327 : : try
328 : : {
329 : 0 : if ( mxDialogModelNameAccess->hasByName( rControlName ) )
330 : : {
331 : 0 : Reference< XPropertySet > xPropertySet( mxDialogModelNameAccess->getByName( rControlName ), UNO_QUERY_THROW );
332 : 0 : aRet = xPropertySet->getPropertyValue( rPropertyName );
333 : : }
334 : : }
335 : 0 : catch ( Exception& )
336 : : {
337 : : }
338 : 0 : return aRet;
339 : : }
340 : :
341 : : // -----------------------------------------------------------------------------
342 : :
343 : 0 : void UnoDialog::enableControl( const OUString& rControlName )
344 : : {
345 : 0 : const OUString sEnabled( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) );
346 : 0 : setControlProperty( rControlName, sEnabled, Any( sal_True ) );
347 : 0 : }
348 : :
349 : : // -----------------------------------------------------------------------------
350 : :
351 : 0 : void UnoDialog::disableControl( const OUString& rControlName )
352 : : {
353 : 0 : const OUString sEnabled( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) );
354 : 0 : setControlProperty( rControlName, sEnabled, Any( sal_False ) );
355 : 0 : }
356 : :
357 : : // -----------------------------------------------------------------------------
358 : :
359 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|