1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
23 #include <com/sun/star/awt/Toolkit.hpp>
24 #include <com/sun/star/awt/UnoControlDialog.hpp>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/view/XSelectionSupplier.hpp>
29 using namespace ::com::sun::star::awt
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::util
;
32 using namespace ::com::sun::star::lang
;
33 using namespace ::com::sun::star::view
;
34 using namespace ::com::sun::star::frame
;
35 using namespace ::com::sun::star::beans
;
37 UnoDialog::UnoDialog( const Reference
< XComponentContext
> &rxContext
, Reference
< XFrame
> const & rxFrame
) :
38 mxContext( rxContext
),
39 mxController( rxFrame
->getController() ),
40 mxDialogModel( mxContext
->getServiceManager()->createInstanceWithContext(
41 "com.sun.star.awt.UnoControlDialogModel", mxContext
), UNO_SET_THROW
),
42 mxDialogModelMultiPropertySet( mxDialogModel
, UNO_QUERY_THROW
),
43 mxDialogModelMSF( mxDialogModel
, UNO_QUERY_THROW
),
44 mxDialogModelNameContainer( mxDialogModel
, UNO_QUERY_THROW
),
45 mxDialogModelNameAccess( mxDialogModel
, UNO_QUERY_THROW
),
46 mxControlModel( mxDialogModel
, UNO_QUERY_THROW
),
47 mxDialog( UnoControlDialog::create(rxContext
) ),
48 mxControl( mxDialog
, UNO_QUERY_THROW
),
51 mxControl
->setModel( mxControlModel
);
53 Reference
< XFrame
> xFrame( mxController
->getFrame() );
54 Reference
< XWindow
> xContainerWindow( xFrame
->getContainerWindow() );
55 Reference
< XWindowPeer
> xWindowPeer( xContainerWindow
, UNO_QUERY_THROW
);
57 // set the main loop handle to update GUI while busy
58 Reference
< XToolkit
> xToolkit( Toolkit::create( mxContext
), UNO_QUERY_THROW
);
59 mxReschedule
.set( xToolkit
, UNO_QUERY
);
61 // allocate the real window resources
62 mxDialog
->createPeer(xToolkit
,
63 xWindowPeer
.is() ? xWindowPeer
: xToolkit
->getDesktopWindow());
66 UnoDialog::~UnoDialog()
69 Reference
<XComponent
> xDialogComponent(mxDialog
, UNO_QUERY_THROW
);
70 xDialogComponent
->dispose();
73 void UnoDialog::execute()
75 mxDialog
->setEnable( true );
76 mxDialog
->setVisible( true );
80 void UnoDialog::endExecute( bool bStatus
)
83 mxDialog
->endExecute();
86 Reference
< XInterface
> UnoDialog::insertControlModel( const OUString
& rServiceName
, const OUString
& rName
,
87 const Sequence
< OUString
>& rPropertyNames
, const Sequence
< Any
>& rPropertyValues
)
89 Reference
< XInterface
> xControlModel
;
92 xControlModel
= mxDialogModelMSF
->createInstance( rServiceName
);
93 Reference
< XMultiPropertySet
> xMultiPropSet( xControlModel
, UNO_QUERY_THROW
);
94 xMultiPropSet
->setPropertyValues( rPropertyNames
, rPropertyValues
);
95 mxDialogModelNameContainer
->insertByName( rName
, Any( xControlModel
) );
100 return xControlModel
;
104 void UnoDialog::setVisible( const OUString
& rName
, bool bVisible
)
108 Reference
< XInterface
> xControl( mxDialog
->getControl( rName
), UNO_QUERY_THROW
);
109 Reference
< XWindow
> xWindow( xControl
, UNO_QUERY_THROW
);
110 xWindow
->setVisible( bVisible
);
118 Reference
< XButton
> UnoDialog::insertButton( const OUString
& rName
, const Reference
< XActionListener
>& xActionListener
,
119 const Sequence
< OUString
>& rPropertyNames
, const Sequence
< Any
>& rPropertyValues
)
121 Reference
< XButton
> xButton
;
124 Reference
< XInterface
> xButtonModel( insertControlModel( "com.sun.star.awt.UnoControlButtonModel",
125 rName
, rPropertyNames
, rPropertyValues
) );
126 Reference
< XPropertySet
> xPropertySet( xButtonModel
, UNO_QUERY_THROW
);
127 xPropertySet
->setPropertyValue("Name", Any( rName
) );
128 xButton
.set( mxDialog
->getControl( rName
), UNO_QUERY_THROW
);
130 if ( xActionListener
.is() )
132 xButton
->addActionListener( xActionListener
);
133 xButton
->setActionCommand( rName
);
144 Reference
< XFixedText
> UnoDialog::insertFixedText( const OUString
& rName
, const Sequence
< OUString
>& rPropertyNames
, const Sequence
< Any
>& rPropertyValues
)
146 Reference
< XFixedText
> xFixedText
;
149 Reference
< XPropertySet
> xPropertySet( insertControlModel( "com.sun.star.awt.UnoControlFixedTextModel",
150 rName
, rPropertyNames
, rPropertyValues
), UNO_QUERY_THROW
);
151 xPropertySet
->setPropertyValue("Name", Any( rName
) );
152 xFixedText
.set( mxDialog
->getControl( rName
), UNO_QUERY_THROW
);
161 Reference
< XCheckBox
> UnoDialog::insertCheckBox( const OUString
& rName
, const Sequence
< OUString
>& rPropertyNames
, const Sequence
< Any
>& rPropertyValues
)
163 Reference
< XCheckBox
> xCheckBox
;
166 Reference
< XPropertySet
> xPropertySet( insertControlModel( "com.sun.star.awt.UnoControlCheckBoxModel",
167 rName
, rPropertyNames
, rPropertyValues
), UNO_QUERY_THROW
);
168 xPropertySet
->setPropertyValue("Name", Any( rName
) );
169 xCheckBox
.set( mxDialog
->getControl( rName
), UNO_QUERY_THROW
);
178 Reference
< XControl
> UnoDialog::insertFormattedField( const OUString
& rName
, const Sequence
< OUString
>& rPropertyNames
, const Sequence
< Any
>& rPropertyValues
)
180 Reference
< XControl
> xControl
;
183 Reference
< XPropertySet
> xPropertySet( insertControlModel( "com.sun.star.awt.UnoControlFormattedFieldModel",
184 rName
, rPropertyNames
, rPropertyValues
), UNO_QUERY_THROW
);
185 xPropertySet
->setPropertyValue("Name", Any( rName
) );
186 xControl
.set( mxDialog
->getControl( rName
), UNO_SET_THROW
);
195 Reference
< XComboBox
> UnoDialog::insertComboBox( const OUString
& rName
, const Sequence
< OUString
>& rPropertyNames
, const Sequence
< Any
>& rPropertyValues
)
197 Reference
< XComboBox
> xControl
;
200 Reference
< XPropertySet
> xPropertySet( insertControlModel( "com.sun.star.awt.UnoControlComboBoxModel",
201 rName
, rPropertyNames
, rPropertyValues
), UNO_QUERY_THROW
);
202 xPropertySet
->setPropertyValue("Name", Any( rName
) );
203 xControl
.set( mxDialog
->getControl( rName
), UNO_QUERY_THROW
);
212 Reference
< XRadioButton
> UnoDialog::insertRadioButton( const OUString
& rName
, const Sequence
< OUString
>& rPropertyNames
, const Sequence
< Any
>& rPropertyValues
)
214 Reference
< XRadioButton
> xControl
;
217 Reference
< XPropertySet
> xPropertySet( insertControlModel( "com.sun.star.awt.UnoControlRadioButtonModel",
218 rName
, rPropertyNames
, rPropertyValues
), UNO_QUERY_THROW
);
219 xPropertySet
->setPropertyValue("Name", Any( rName
) );
220 xControl
.set( mxDialog
->getControl( rName
), UNO_QUERY_THROW
);
229 Reference
< XListBox
> UnoDialog::insertListBox( const OUString
& rName
, const Sequence
< OUString
>& rPropertyNames
, const Sequence
< Any
>& rPropertyValues
)
231 Reference
< XListBox
> xControl
;
234 Reference
< XPropertySet
> xPropertySet( insertControlModel( "com.sun.star.awt.UnoControlListBoxModel",
235 rName
, rPropertyNames
, rPropertyValues
), UNO_QUERY_THROW
);
236 xPropertySet
->setPropertyValue("Name", Any( rName
) );
237 xControl
.set( mxDialog
->getControl( rName
), UNO_QUERY_THROW
);
246 Reference
< XControl
> UnoDialog::insertImage( const OUString
& rName
, const Sequence
< OUString
>& rPropertyNames
, const Sequence
< Any
>& rPropertyValues
)
248 Reference
< XControl
> xControl
;
251 Reference
< XPropertySet
> xPropertySet( insertControlModel( "com.sun.star.awt.UnoControlImageControlModel",
252 rName
, rPropertyNames
, rPropertyValues
), UNO_QUERY_THROW
);
253 xPropertySet
->setPropertyValue("Name", Any( rName
) );
254 xControl
.set( mxDialog
->getControl( rName
), UNO_SET_THROW
);
263 void UnoDialog::setControlProperty( const OUString
& rControlName
, const OUString
& rPropertyName
, const Any
& rPropertyValue
)
267 if ( mxDialogModelNameAccess
->hasByName( rControlName
) )
269 Reference
< XPropertySet
> xPropertySet( mxDialogModelNameAccess
->getByName( rControlName
), UNO_QUERY_THROW
);
270 xPropertySet
->setPropertyValue( rPropertyName
, rPropertyValue
);
279 Any
UnoDialog::getControlProperty( const OUString
& rControlName
, const OUString
& rPropertyName
)
284 if ( mxDialogModelNameAccess
->hasByName( rControlName
) )
286 Reference
< XPropertySet
> xPropertySet( mxDialogModelNameAccess
->getByName( rControlName
), UNO_QUERY_THROW
);
287 aRet
= xPropertySet
->getPropertyValue( rPropertyName
);
297 void UnoDialog::enableControl( const OUString
& rControlName
)
299 const OUString
sEnabled( "Enabled" );
300 setControlProperty( rControlName
, sEnabled
, Any( true ) );
304 void UnoDialog::disableControl( const OUString
& rControlName
)
306 const OUString
sEnabled( "Enabled" );
307 setControlProperty( rControlName
, sEnabled
, Any( false ) );
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */