fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sdext / source / minimizer / unodialog.cxx
blob922527e2a88d7bf595e0b6285d65f5a8c2b97478
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "unodialog.hxx"
22 #include <com/sun/star/text/XTextRange.hpp>
23 #include <com/sun/star/drawing/XShapes.hpp>
24 #include <com/sun/star/container/XIndexAccess.hpp>
25 #include <com/sun/star/view/XSelectionSupplier.hpp>
26 #include <com/sun/star/view/XControlAccess.hpp>
27 #include <com/sun/star/frame/XDispatch.hpp>
28 #include <com/sun/star/awt/Toolkit.hpp>
29 #include <com/sun/star/awt/XMessageBoxFactory.hpp>
30 #include <com/sun/star/awt/MessageBoxButtons.hpp>
32 // -------------
33 // - UnoDialog -
34 // -------------
36 using namespace ::rtl;
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;
46 UnoDialog::UnoDialog( const Reference< XComponentContext > &rxMSF, Reference< XFrame >& rxFrame ) :
47 mxMSF( rxMSF ),
48 mxController( rxFrame->getController() ),
49 mxDialogModel( mxMSF->getServiceManager()->createInstanceWithContext( OUString(
50 "com.sun.star.awt.UnoControlDialogModel" ), mxMSF ), 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( mxMSF->getServiceManager()->createInstanceWithContext( OUString(
58 "com.sun.star.awt.UnoControlDialog" ), mxMSF ), UNO_QUERY_THROW ),
59 mxControl( mxDialog, UNO_QUERY_THROW ),
60 mbStatus( sal_False )
62 mxControl->setModel( mxControlModel );
63 mxDialogControlContainer = Reference< XControlContainer >( mxDialog, UNO_QUERY_THROW );
64 mxDialogComponent = Reference< XComponent >( mxDialog, UNO_QUERY_THROW );
65 mxDialogWindow = Reference< XWindow >( mxDialog, UNO_QUERY_THROW );
67 Reference< XFrame > xFrame( mxController->getFrame() );
68 Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() );
69 mxWindowPeer = Reference< XWindowPeer >( xContainerWindow, UNO_QUERY_THROW );
70 createWindowPeer( mxWindowPeer );
73 // -----------------------------------------------------------------------------
75 UnoDialog::~UnoDialog()
80 // -----------------------------------------------------------------------------
82 void UnoDialog::execute()
84 mxDialogWindow->setEnable( sal_True );
85 mxDialogWindow->setVisible( sal_True );
86 mxDialog->execute();
89 void UnoDialog::endExecute( sal_Bool bStatus )
91 mbStatus = bStatus;
92 mxDialog->endExecute();
95 // -----------------------------------------------------------------------------
97 Reference< XWindowPeer > UnoDialog::createWindowPeer( Reference< XWindowPeer > xParentPeer )
98 throw ( Exception )
100 mxDialogWindow->setVisible( sal_False );
101 Reference< XToolkit > xToolkit( Toolkit::create( mxMSF ), UNO_QUERY_THROW );
102 if ( !xParentPeer.is() )
103 xParentPeer = xToolkit->getDesktopWindow();
104 mxReschedule = Reference< XReschedule >( xToolkit, UNO_QUERY );
105 mxControl->createPeer( xToolkit, xParentPeer );
106 // xWindowPeer = xControl.getPeer();
107 return mxControl->getPeer();
110 // -----------------------------------------------------------------------------
112 Reference< XInterface > UnoDialog::insertControlModel( const OUString& rServiceName, const OUString& rName,
113 const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
115 Reference< XInterface > xControlModel;
118 xControlModel = mxDialogModelMSF->createInstance( rServiceName );
119 Reference< XMultiPropertySet > xMultiPropSet( xControlModel, UNO_QUERY_THROW );
120 xMultiPropSet->setPropertyValues( rPropertyNames, rPropertyValues );
121 mxDialogModelNameContainer->insertByName( rName, Any( xControlModel ) );
123 catch( Exception& )
126 return xControlModel;
129 // -----------------------------------------------------------------------------
131 void UnoDialog::setVisible( const OUString& rName, sal_Bool bVisible )
135 Reference< XInterface > xControl( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
136 Reference< XWindow > xWindow( xControl, UNO_QUERY_THROW );
137 xWindow->setVisible( bVisible );
139 catch ( Exception& )
144 // -----------------------------------------------------------------------------
146 Reference< XButton > UnoDialog::insertButton( const OUString& rName, Reference< XActionListener > xActionListener,
147 const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
149 Reference< XButton > xButton;
152 Reference< XInterface > xButtonModel( insertControlModel( OUString( "com.sun.star.awt.UnoControlButtonModel" ),
153 rName, rPropertyNames, rPropertyValues ) );
154 Reference< XPropertySet > xPropertySet( xButtonModel, UNO_QUERY_THROW );
155 xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) );
156 xButton = Reference< XButton >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
158 if ( xActionListener.is() )
160 xButton->addActionListener( xActionListener );
161 xButton->setActionCommand( rName );
163 return xButton;
165 catch( Exception& )
168 return xButton;
171 // -----------------------------------------------------------------------------
173 Reference< XFixedText > UnoDialog::insertFixedText( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
175 Reference< XFixedText > xFixedText;
178 Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlFixedTextModel" ),
179 rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
180 xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) );
181 xFixedText = Reference< XFixedText >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
183 catch ( Exception& )
186 return xFixedText;
189 // -----------------------------------------------------------------------------
191 Reference< XCheckBox > UnoDialog::insertCheckBox( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
193 Reference< XCheckBox > xCheckBox;
196 Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlCheckBoxModel" ),
197 rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
198 xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) );
199 xCheckBox = Reference< XCheckBox >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
201 catch ( Exception& )
204 return xCheckBox;
207 // -----------------------------------------------------------------------------
209 Reference< XControl > UnoDialog::insertFormattedField( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
211 Reference< XControl > xControl;
214 Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlFormattedFieldModel" ),
215 rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
216 xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) );
217 xControl = Reference< XControl >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
219 catch ( Exception& )
222 return xControl;
225 // -----------------------------------------------------------------------------
227 Reference< XComboBox > UnoDialog::insertComboBox( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
229 Reference< XComboBox > xControl;
232 Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlComboBoxModel" ),
233 rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
234 xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) );
235 xControl = Reference< XComboBox >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
237 catch ( Exception& )
240 return xControl;
243 // -----------------------------------------------------------------------------
245 Reference< XRadioButton > UnoDialog::insertRadioButton( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
247 Reference< XRadioButton > xControl;
250 Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlRadioButtonModel" ),
251 rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
252 xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) );
253 xControl = Reference< XRadioButton >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
255 catch ( Exception& )
258 return xControl;
261 // -----------------------------------------------------------------------------
263 Reference< XListBox > UnoDialog::insertListBox( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
265 Reference< XListBox > xControl;
268 Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlListBoxModel" ),
269 rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
270 xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) );
271 xControl = Reference< XListBox >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
273 catch ( Exception& )
276 return xControl;
279 // -----------------------------------------------------------------------------
281 Reference< XControl > UnoDialog::insertImage( const OUString& rName, const Sequence< OUString > rPropertyNames, const Sequence< Any > rPropertyValues )
283 Reference< XControl > xControl;
286 Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlImageControlModel" ),
287 rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
288 xPropertySet->setPropertyValue( OUString( "Name" ), Any( rName ) );
289 xControl = Reference< XControl >( mxDialogControlContainer->getControl( rName ), UNO_QUERY_THROW );
291 catch ( Exception& )
294 return xControl;
297 // -----------------------------------------------------------------------------
299 void UnoDialog::setControlProperty( const OUString& rControlName, const OUString& rPropertyName, const Any& rPropertyValue )
303 if ( mxDialogModelNameAccess->hasByName( rControlName ) )
305 Reference< XPropertySet > xPropertySet( mxDialogModelNameAccess->getByName( rControlName ), UNO_QUERY_THROW );
306 xPropertySet->setPropertyValue( rPropertyName, rPropertyValue );
309 catch ( Exception& )
314 // -----------------------------------------------------------------------------
316 Any UnoDialog::getControlProperty( const OUString& rControlName, const OUString& rPropertyName )
318 Any aRet;
321 if ( mxDialogModelNameAccess->hasByName( rControlName ) )
323 Reference< XPropertySet > xPropertySet( mxDialogModelNameAccess->getByName( rControlName ), UNO_QUERY_THROW );
324 aRet = xPropertySet->getPropertyValue( rPropertyName );
327 catch ( Exception& )
330 return aRet;
333 // -----------------------------------------------------------------------------
335 void UnoDialog::enableControl( const OUString& rControlName )
337 const OUString sEnabled( "Enabled" );
338 setControlProperty( rControlName, sEnabled, Any( sal_True ) );
341 // -----------------------------------------------------------------------------
343 void UnoDialog::disableControl( const OUString& rControlName )
345 const OUString sEnabled( "Enabled" );
346 setControlProperty( rControlName, sEnabled, Any( sal_False ) );
349 // -----------------------------------------------------------------------------
351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */