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