fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sdext / source / minimizer / unodialog.cxx
blobb213a271e2f43c5b734b4e80b7ab9c85a88361e1
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/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>
34 // - UnoDialog -
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 > &rxContext, Reference< XFrame >& rxFrame ) :
47 mxContext( rxContext ),
48 mxController( rxFrame->getController() ),
49 mxDialogModel( mxContext->getServiceManager()->createInstanceWithContext( OUString(
50 "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 mbStatus( false )
61 mxControl->setModel( mxControlModel );
63 Reference< XFrame > xFrame( mxController->getFrame() );
64 Reference< XWindow > xContainerWindow( xFrame->getContainerWindow() );
65 mxWindowPeer = Reference< XWindowPeer >( xContainerWindow, UNO_QUERY_THROW );
66 createWindowPeer( mxWindowPeer );
71 UnoDialog::~UnoDialog()
78 void UnoDialog::execute()
80 mxDialog->setEnable( sal_True );
81 mxDialog->setVisible( sal_True );
82 mxDialog->execute();
85 void UnoDialog::endExecute( bool bStatus )
87 mbStatus = bStatus;
88 mxDialog->endExecute();
93 Reference< XWindowPeer > UnoDialog::createWindowPeer( Reference< XWindowPeer > xParentPeer )
94 throw ( Exception )
96 mxDialog->setVisible( sal_False );
97 Reference< XToolkit > xToolkit( Toolkit::create( mxContext ), UNO_QUERY_THROW );
98 if ( !xParentPeer.is() )
99 xParentPeer = xToolkit->getDesktopWindow();
100 mxReschedule = Reference< XReschedule >( xToolkit, UNO_QUERY );
101 mxDialog->createPeer( xToolkit, xParentPeer );
102 // xWindowPeer = xControl.getPeer();
103 return mxDialog->getPeer();
108 Reference< XInterface > UnoDialog::insertControlModel( const OUString& rServiceName, const OUString& rName,
109 const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
111 Reference< XInterface > xControlModel;
114 xControlModel = mxDialogModelMSF->createInstance( rServiceName );
115 Reference< XMultiPropertySet > xMultiPropSet( xControlModel, UNO_QUERY_THROW );
116 xMultiPropSet->setPropertyValues( rPropertyNames, rPropertyValues );
117 mxDialogModelNameContainer->insertByName( rName, Any( xControlModel ) );
119 catch( Exception& )
122 return xControlModel;
127 void UnoDialog::setVisible( const OUString& rName, bool bVisible )
131 Reference< XInterface > xControl( mxDialog->getControl( rName ), UNO_QUERY_THROW );
132 Reference< XWindow > xWindow( xControl, UNO_QUERY_THROW );
133 xWindow->setVisible( bVisible );
135 catch ( Exception& )
142 Reference< XButton > UnoDialog::insertButton( const OUString& rName, Reference< XActionListener > xActionListener,
143 const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
145 Reference< XButton > xButton;
148 Reference< XInterface > xButtonModel( insertControlModel( OUString( "com.sun.star.awt.UnoControlButtonModel" ),
149 rName, rPropertyNames, rPropertyValues ) );
150 Reference< XPropertySet > xPropertySet( xButtonModel, UNO_QUERY_THROW );
151 xPropertySet->setPropertyValue("Name", Any( rName ) );
152 xButton = Reference< XButton >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
154 if ( xActionListener.is() )
156 xButton->addActionListener( xActionListener );
157 xButton->setActionCommand( rName );
159 return xButton;
161 catch( Exception& )
164 return xButton;
169 Reference< XFixedText > UnoDialog::insertFixedText( const OUString& rName, const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
171 Reference< XFixedText > xFixedText;
174 Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlFixedTextModel" ),
175 rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
176 xPropertySet->setPropertyValue("Name", Any( rName ) );
177 xFixedText = Reference< XFixedText >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
179 catch ( Exception& )
182 return xFixedText;
187 Reference< XCheckBox > UnoDialog::insertCheckBox( const OUString& rName, const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
189 Reference< XCheckBox > xCheckBox;
192 Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlCheckBoxModel" ),
193 rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
194 xPropertySet->setPropertyValue("Name", Any( rName ) );
195 xCheckBox = Reference< XCheckBox >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
197 catch ( Exception& )
200 return xCheckBox;
205 Reference< XControl > UnoDialog::insertFormattedField( const OUString& rName, const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
207 Reference< XControl > xControl;
210 Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlFormattedFieldModel" ),
211 rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
212 xPropertySet->setPropertyValue("Name", Any( rName ) );
213 xControl = Reference< XControl >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
215 catch ( Exception& )
218 return xControl;
223 Reference< XComboBox > UnoDialog::insertComboBox( const OUString& rName, const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
225 Reference< XComboBox > xControl;
228 Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlComboBoxModel" ),
229 rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
230 xPropertySet->setPropertyValue("Name", Any( rName ) );
231 xControl = Reference< XComboBox >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
233 catch ( Exception& )
236 return xControl;
241 Reference< XRadioButton > UnoDialog::insertRadioButton( const OUString& rName, const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
243 Reference< XRadioButton > xControl;
246 Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlRadioButtonModel" ),
247 rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
248 xPropertySet->setPropertyValue("Name", Any( rName ) );
249 xControl = Reference< XRadioButton >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
251 catch ( Exception& )
254 return xControl;
259 Reference< XListBox > UnoDialog::insertListBox( const OUString& rName, const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
261 Reference< XListBox > xControl;
264 Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlListBoxModel" ),
265 rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
266 xPropertySet->setPropertyValue("Name", Any( rName ) );
267 xControl = Reference< XListBox >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
269 catch ( Exception& )
272 return xControl;
277 Reference< XControl > UnoDialog::insertImage( const OUString& rName, const Sequence< OUString >& rPropertyNames, const Sequence< Any >& rPropertyValues )
279 Reference< XControl > xControl;
282 Reference< XPropertySet > xPropertySet( insertControlModel( OUString( "com.sun.star.awt.UnoControlImageControlModel" ),
283 rName, rPropertyNames, rPropertyValues ), UNO_QUERY_THROW );
284 xPropertySet->setPropertyValue("Name", Any( rName ) );
285 xControl = Reference< XControl >( mxDialog->getControl( rName ), UNO_QUERY_THROW );
287 catch ( Exception& )
290 return xControl;
295 void UnoDialog::setControlProperty( const OUString& rControlName, const OUString& rPropertyName, const Any& rPropertyValue )
299 if ( mxDialogModelNameAccess->hasByName( rControlName ) )
301 Reference< XPropertySet > xPropertySet( mxDialogModelNameAccess->getByName( rControlName ), UNO_QUERY_THROW );
302 xPropertySet->setPropertyValue( rPropertyName, rPropertyValue );
305 catch ( Exception& )
312 Any UnoDialog::getControlProperty( const OUString& rControlName, const OUString& rPropertyName )
314 Any aRet;
317 if ( mxDialogModelNameAccess->hasByName( rControlName ) )
319 Reference< XPropertySet > xPropertySet( mxDialogModelNameAccess->getByName( rControlName ), UNO_QUERY_THROW );
320 aRet = xPropertySet->getPropertyValue( rPropertyName );
323 catch ( Exception& )
326 return aRet;
331 void UnoDialog::enableControl( const OUString& rControlName )
333 const OUString sEnabled( "Enabled" );
334 setControlProperty( rControlName, sEnabled, Any( sal_True ) );
339 void UnoDialog::disableControl( const OUString& rControlName )
341 const OUString sEnabled( "Enabled" );
342 setControlProperty( rControlName, sEnabled, Any( sal_False ) );
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */