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 "unodialog.hxx"
22 : #include <com/sun/star/awt/MessageBoxButtons.hpp>
23 : #include <com/sun/star/awt/Toolkit.hpp>
24 : #include <com/sun/star/awt/UnoControlDialog.hpp>
25 : #include <com/sun/star/awt/XMessageBoxFactory.hpp>
26 : #include <com/sun/star/container/XIndexAccess.hpp>
27 : #include <com/sun/star/drawing/XShapes.hpp>
28 : #include <com/sun/star/frame/XDispatch.hpp>
29 : #include <com/sun/star/text/XTextRange.hpp>
30 : #include <com/sun/star/view/XSelectionSupplier.hpp>
31 : #include <com/sun/star/view/XControlAccess.hpp>
32 :
33 :
34 : // - UnoDialog -
35 :
36 :
37 : using namespace ::rtl;
38 : using namespace ::com::sun::star::awt;
39 : using namespace ::com::sun::star::uno;
40 : using namespace ::com::sun::star::util;
41 : using namespace ::com::sun::star::lang;
42 : using namespace ::com::sun::star::view;
43 : using namespace ::com::sun::star::frame;
44 : using namespace ::com::sun::star::beans;
45 : using namespace ::com::sun::star::script;
46 :
47 0 : UnoDialog::UnoDialog( const Reference< XComponentContext > &rxContext, Reference< XFrame >& rxFrame ) :
48 : mxContext( rxContext ),
49 0 : mxController( rxFrame->getController() ),
50 0 : mxDialogModel( mxContext->getServiceManager()->createInstanceWithContext( OUString(
51 0 : "com.sun.star.awt.UnoControlDialogModel" ), mxContext ), UNO_QUERY_THROW ),
52 : mxDialogModelMultiPropertySet( mxDialogModel, UNO_QUERY_THROW ),
53 : mxDialogModelPropertySet( mxDialogModel, UNO_QUERY_THROW ),
54 : mxDialogModelMSF( mxDialogModel, UNO_QUERY_THROW ),
55 : mxDialogModelNameContainer( mxDialogModel, UNO_QUERY_THROW ),
56 : mxDialogModelNameAccess( mxDialogModel, UNO_QUERY_THROW ),
57 : mxControlModel( mxDialogModel, UNO_QUERY_THROW ),
58 : mxDialog( UnoControlDialog::create(rxContext) ),
59 : mxControl( mxDialog, UNO_QUERY_THROW ),
60 0 : mbStatus( sal_False )
61 : {
62 0 : mxControl->setModel( mxControlModel );
63 :
64 0 : Reference< XFrame > xFrame( mxController->getFrame() );
65 0 : Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() );
66 0 : mxWindowPeer = Reference< XWindowPeer >( xContainerWindow, UNO_QUERY_THROW );
67 0 : createWindowPeer( mxWindowPeer );
68 0 : }
69 :
70 :
71 :
72 0 : UnoDialog::~UnoDialog()
73 : {
74 :
75 0 : }
76 :
77 :
78 :
79 0 : void UnoDialog::execute()
80 : {
81 0 : mxDialog->setEnable( sal_True );
82 0 : mxDialog->setVisible( sal_True );
83 0 : mxDialog->execute();
84 0 : }
85 :
86 0 : void UnoDialog::endExecute( sal_Bool bStatus )
87 : {
88 0 : mbStatus = bStatus;
89 0 : mxDialog->endExecute();
90 0 : }
91 :
92 :
93 :
94 0 : Reference< XWindowPeer > UnoDialog::createWindowPeer( Reference< XWindowPeer > xParentPeer )
95 : throw ( Exception )
96 : {
97 0 : mxDialog->setVisible( sal_False );
98 0 : Reference< XToolkit > xToolkit( Toolkit::create( mxContext ), UNO_QUERY_THROW );
99 0 : if ( !xParentPeer.is() )
100 0 : xParentPeer = xToolkit->getDesktopWindow();
101 0 : mxReschedule = Reference< XReschedule >( xToolkit, UNO_QUERY );
102 0 : mxDialog->createPeer( xToolkit, xParentPeer );
103 : // xWindowPeer = xControl.getPeer();
104 0 : return mxDialog->getPeer();
105 : }
106 :
107 :
108 :
109 0 : Reference< XInterface > UnoDialog::insertControlModel( const OUString& rServiceName, const OUString& rName,
110 : const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
111 : {
112 0 : Reference< XInterface > xControlModel;
113 : try
114 : {
115 0 : xControlModel = mxDialogModelMSF->createInstance( rServiceName );
116 0 : Reference< XMultiPropertySet > xMultiPropSet( xControlModel, UNO_QUERY_THROW );
117 0 : xMultiPropSet->setPropertyValues( rPropertyNames, rPropertyValues );
118 0 : mxDialogModelNameContainer->insertByName( rName, Any( xControlModel ) );
119 : }
120 0 : catch( Exception& )
121 : {
122 : }
123 0 : return xControlModel;
124 : }
125 :
126 :
127 :
128 0 : void UnoDialog::setVisible( const OUString& rName, sal_Bool bVisible )
129 : {
130 : try
131 : {
132 0 : Reference< XInterface > xControl( mxDialog->getControl( rName ), UNO_QUERY_THROW );
133 0 : Reference< XWindow > xWindow( xControl, UNO_QUERY_THROW );
134 0 : xWindow->setVisible( bVisible );
135 : }
136 0 : catch ( Exception& )
137 : {
138 : }
139 0 : }
140 :
141 :
142 :
143 0 : Reference< XButton > UnoDialog::insertButton( const OUString& rName, Reference< XActionListener > xActionListener,
144 : const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
145 : {
146 0 : Reference< XButton > xButton;
147 : try
148 : {
149 : Reference< XInterface > xButtonModel( insertControlModel( OUString( "com.sun.star.awt.UnoControlButtonModel" ),
150 0 : rName, rPropertyNames, rPropertyValues ) );
151 0 : Reference< XPropertySet > xPropertySet( xButtonModel, UNO_QUERY_THROW );
152 0 : xPropertySet->setPropertyValue("Name", Any( rName ) );
153 0 : xButton = Reference< XButton >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
154 :
155 0 : if ( xActionListener.is() )
156 : {
157 0 : xButton->addActionListener( xActionListener );
158 0 : xButton->setActionCommand( rName );
159 : }
160 0 : return xButton;
161 : }
162 0 : catch( Exception& )
163 : {
164 : }
165 0 : return xButton;
166 : }
167 :
168 :
169 :
170 0 : Reference< XFixedText > UnoDialog::insertFixedText( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
171 : {
172 0 : Reference< XFixedText > xFixedText;
173 : try
174 : {
175 : Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlFixedTextModel" ),
176 0 : rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
177 0 : xPropertySet->setPropertyValue("Name", Any( rName ) );
178 0 : xFixedText = Reference< XFixedText >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
179 : }
180 0 : catch ( Exception& )
181 : {
182 : }
183 0 : return xFixedText;
184 : }
185 :
186 :
187 :
188 0 : Reference< XCheckBox > UnoDialog::insertCheckBox( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
189 : {
190 0 : Reference< XCheckBox > xCheckBox;
191 : try
192 : {
193 : Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlCheckBoxModel" ),
194 0 : rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
195 0 : xPropertySet->setPropertyValue("Name", Any( rName ) );
196 0 : xCheckBox = Reference< XCheckBox >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
197 : }
198 0 : catch ( Exception& )
199 : {
200 : }
201 0 : return xCheckBox;
202 : }
203 :
204 :
205 :
206 0 : Reference< XControl > UnoDialog::insertFormattedField( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
207 : {
208 0 : Reference< XControl > xControl;
209 : try
210 : {
211 : Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlFormattedFieldModel" ),
212 0 : rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
213 0 : xPropertySet->setPropertyValue("Name", Any( rName ) );
214 0 : xControl = Reference< XControl >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
215 : }
216 0 : catch ( Exception& )
217 : {
218 : }
219 0 : return xControl;
220 : }
221 :
222 :
223 :
224 0 : Reference< XComboBox > UnoDialog::insertComboBox( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
225 : {
226 0 : Reference< XComboBox > xControl;
227 : try
228 : {
229 : Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlComboBoxModel" ),
230 0 : rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
231 0 : xPropertySet->setPropertyValue("Name", Any( rName ) );
232 0 : xControl = Reference< XComboBox >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
233 : }
234 0 : catch ( Exception& )
235 : {
236 : }
237 0 : return xControl;
238 : }
239 :
240 :
241 :
242 0 : Reference< XRadioButton > UnoDialog::insertRadioButton( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
243 : {
244 0 : Reference< XRadioButton > xControl;
245 : try
246 : {
247 : Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlRadioButtonModel" ),
248 0 : rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
249 0 : xPropertySet->setPropertyValue("Name", Any( rName ) );
250 0 : xControl = Reference< XRadioButton >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
251 : }
252 0 : catch ( Exception& )
253 : {
254 : }
255 0 : return xControl;
256 : }
257 :
258 :
259 :
260 0 : Reference< XListBox > UnoDialog::insertListBox( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
261 : {
262 0 : Reference< XListBox > xControl;
263 : try
264 : {
265 : Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlListBoxModel" ),
266 0 : rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
267 0 : xPropertySet->setPropertyValue("Name", Any( rName ) );
268 0 : xControl = Reference< XListBox >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
269 : }
270 0 : catch ( Exception& )
271 : {
272 : }
273 0 : return xControl;
274 : }
275 :
276 :
277 :
278 0 : Reference< XControl > UnoDialog::insertImage( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
279 : {
280 0 : Reference< XControl > xControl;
281 : try
282 : {
283 : Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlImageControlModel" ),
284 0 : rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
285 0 : xPropertySet->setPropertyValue("Name", Any( rName ) );
286 0 : xControl = Reference< XControl >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
287 : }
288 0 : catch ( Exception& )
289 : {
290 : }
291 0 : return xControl;
292 : }
293 :
294 :
295 :
296 0 : void UnoDialog::setControlProperty( const OUString& rControlName, const OUString& rPropertyName, const Any& rPropertyValue )
297 : {
298 : try
299 : {
300 0 : if ( mxDialogModelNameAccess->hasByName( rControlName ) )
301 : {
302 0 : Reference< XPropertySet > xPropertySet( mxDialogModelNameAccess->getByName( rControlName ), UNO_QUERY_THROW );
303 0 : xPropertySet->setPropertyValue( rPropertyName, rPropertyValue );
304 : }
305 : }
306 0 : catch ( Exception& )
307 : {
308 : }
309 0 : }
310 :
311 :
312 :
313 0 : Any UnoDialog::getControlProperty( const OUString& rControlName, const OUString& rPropertyName )
314 : {
315 0 : Any aRet;
316 : try
317 : {
318 0 : if ( mxDialogModelNameAccess->hasByName( rControlName ) )
319 : {
320 0 : Reference< XPropertySet > xPropertySet( mxDialogModelNameAccess->getByName( rControlName ), UNO_QUERY_THROW );
321 0 : aRet = xPropertySet->getPropertyValue( rPropertyName );
322 : }
323 : }
324 0 : catch ( Exception& )
325 : {
326 : }
327 0 : return aRet;
328 : }
329 :
330 :
331 :
332 0 : void UnoDialog::enableControl( const OUString& rControlName )
333 : {
334 0 : const OUString sEnabled( "Enabled" );
335 0 : setControlProperty( rControlName, sEnabled, Any( sal_True ) );
336 0 : }
337 :
338 :
339 :
340 0 : void UnoDialog::disableControl( const OUString& rControlName )
341 : {
342 0 : const OUString sEnabled( "Enabled" );
343 0 : setControlProperty( rControlName, sEnabled, Any( sal_False ) );
344 0 : }
345 :
346 :
347 :
348 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|