merge the formfield patch from ooo-build
[ooovba.git] / toolkit / workben / unodialog.cxx
blob1f23b5d90282ffb5ab9bf5dde957cdbc20092032
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unodialog.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_toolkit.hxx"
33 #include <tools/svwin.h>
34 #include <sal/main.h>
35 #include <com/sun/star/awt/XToolkit.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <com/sun/star/container/XNameContainer.hpp>
39 #include <com/sun/star/awt/XControlModel.hpp>
40 #include <com/sun/star/awt/XControlContainer.hpp>
41 #include <com/sun/star/awt/XControl.hpp>
42 #include <com/sun/star/awt/XDialog.hpp>
45 #include <tools/debug.hxx>
46 #include <vcl/svapp.hxx>
47 #include <vcl/wrkwin.hxx>
49 #include <svtools/unoiface.hxx> // InitExtToolkit
50 #include <comphelper/processfactory.hxx>
52 #include <cppuhelper/servicefactory.hxx>
53 #include <cppuhelper/bootstrap.hxx>
54 #include <comphelper/regpathhelper.hxx>
56 #include <com/sun/star/lang/XInitialization.hpp>
57 #include <com/sun/star/registry/XSimpleRegistry.hpp>
60 using namespace ::com::sun::star;
61 using namespace ::com::sun::star::connection;
62 using namespace ::vos;
63 using namespace ::rtl;
64 using namespace ::com::sun::star::uno;
65 using namespace ::com::sun::star::registry;
66 using namespace ::com::sun::star::lang;
70 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > createApplicationServiceManager()
72 try
74 ::rtl::OUString localRegistry = ::comphelper::getPathToUserRegistry();
75 ::rtl::OUString systemRegistry = ::comphelper::getPathToSystemRegistry();
77 Reference< XSimpleRegistry > xLocalRegistry( ::cppu::createSimpleRegistry() );
78 Reference< XSimpleRegistry > xSystemRegistry( ::cppu::createSimpleRegistry() );
79 if ( xLocalRegistry.is() && (localRegistry.getLength() > 0) )
81 try
83 xLocalRegistry->open( localRegistry, sal_False, sal_True);
85 catch ( InvalidRegistryException& )
89 if ( !xLocalRegistry->isValid() )
90 xLocalRegistry->open(localRegistry, sal_True, sal_True);
93 if ( xSystemRegistry.is() && (systemRegistry.getLength() > 0) )
94 xSystemRegistry->open( systemRegistry, sal_True, sal_False);
96 if ( (xLocalRegistry.is() && xLocalRegistry->isValid()) &&
97 (xSystemRegistry.is() && xSystemRegistry->isValid()) )
99 Reference < XSimpleRegistry > xReg( ::cppu::createNestedRegistry() );
100 Sequence< Any > seqAnys(2);
101 seqAnys[0] <<= xLocalRegistry ;
102 seqAnys[1] <<= xSystemRegistry ;
103 Reference< XInitialization > xInit( xReg, UNO_QUERY );
104 xInit->initialize( seqAnys );
106 Reference< XComponentContext > xContext( ::cppu::bootstrap_InitialComponentContext( xReg ) );
107 return Reference< XMultiServiceFactory >( xContext->getServiceManager(), UNO_QUERY );
110 catch( ::com::sun::star::uno::Exception& )
114 return ::cppu::createServiceFactory();
118 // -----------------------------------------------------------------------
119 void Main( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & );
121 SAL_IMPLEMENT_MAIN()
123 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMSF = createApplicationServiceManager();
124 //SVInit( xMSF );
125 ::Main( xMSF );
126 //SVDeinit();
127 return NULL;
131 class MyApp : public Application
133 public:
134 void Main()
136 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMSF = createApplicationServiceManager();
137 ::Main( xMSF );
141 MyApp aMyApp;
145 class MyWin : public WorkWindow
147 private:
148 uno::Reference< awt::XView > mxView;
150 public:
151 MyWin() : WorkWindow( NULL, WB_APP|WB_STDWORK ) {;}
152 void Paint( const Rectangle& r );
153 void SetXView( uno::Reference< awt::XView > xV ) { mxView = xV; }
157 // -----------------------------------------------------------------------
159 void Main( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xMSF )
161 ::comphelper::setProcessServiceFactory( xMSF );
163 //uno::Reference< awt::XToolkit> xToolkit( xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.ExtToolkit" ) ) ), uno::UNO_QUERY );
164 uno::Reference< awt::XToolkit> xToolkit( xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ) ), uno::UNO_QUERY );
166 // Create a DialogModel
167 uno::Reference< container::XNameContainer > xC( xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), uno::UNO_QUERY );
168 uno::Reference< lang::XMultiServiceFactory > xModFact( xC, uno::UNO_QUERY );
170 // Create a ButtonModel
171 uno::Reference< awt::XControlModel > xCtrl1( xModFact->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlButtonModel" ) ) ), uno::UNO_QUERY );
172 uno::Reference< beans::XPropertySet > xPSet( xCtrl1, uno::UNO_QUERY );
173 uno::Any aValue;
174 aValue <<= (sal_Int32) 10;
175 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ), aValue );
176 aValue <<= (sal_Int32) 10;
177 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) ), aValue );
178 aValue <<= (sal_Int32) 40;
179 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Width" ) ), aValue );
180 aValue <<= (sal_Int32) 12;
181 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Height" ) ), aValue );
182 aValue <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Test!" ) );
183 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Label" ) ), aValue );
184 uno::Any aAny;
185 aAny <<= xCtrl1;
186 xC->insertByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Control1" ) ), aAny );
188 uno::Reference< beans::XPropertySet > xDlgPSet( xC, uno::UNO_QUERY );
189 aValue <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Test-Dialog" ) );
190 xDlgPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Title" ) ), aValue );
191 aValue <<= (sal_Int32) 200;
192 xDlgPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Width" ) ), aValue );
193 aValue <<= (sal_Int32) 200;
194 xDlgPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Height" ) ), aValue );
196 // Create a Dialog
197 uno::Reference< awt::XControl > xDlg( xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialog" ) ) ), uno::UNO_QUERY );
198 uno::Reference< awt::XControlModel > xDlgMod( xC, uno::UNO_QUERY );
199 xDlg->setModel( xDlgMod );
201 // Create a EditModel
202 uno::Reference< awt::XControlModel > xCtrl2( xModFact->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlEditModel" ) ) ), uno::UNO_QUERY );
203 xPSet = uno::Reference< beans::XPropertySet >( xCtrl2, uno::UNO_QUERY );
204 aValue <<= (sal_Int32) 10;
205 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ), aValue );
206 aValue <<= (sal_Int32) 40;
207 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) ), aValue );
208 aValue <<= (sal_Int32) 80;
209 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Width" ) ), aValue );
210 aValue <<= (sal_Int32) 12;
211 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Height" ) ), aValue );
212 aValue <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Text..." ) );
213 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Text" ) ), aValue );
214 aAny <<= xCtrl2;
215 xC->insertByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Control2" ) ), aAny );
217 // test if listener works...
218 aValue <<= (sal_Int32) 20;
219 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ), aValue );
221 MyWin * pWindow;
222 ::osl::Guard< vos::IMutex > aVclGuard( Application::GetSolarMutex() );
223 pWindow = new MyWin();
224 pWindow->Show();
226 xDlg->setDesignMode( sal_True );
228 uno::Reference< awt::XWindow > xWindow( xDlg, uno::UNO_QUERY );
229 xWindow->setVisible( sal_False );
231 xDlg->createPeer( xToolkit, pWindow->GetComponentInterface() );
233 uno::Reference< awt::XView > xView( xDlg, uno::UNO_QUERY );
234 pWindow->SetXView( xView );
236 uno::Reference< awt::XDialog > xD( xDlg, uno::UNO_QUERY );
238 //static BOOL bExecute = FALSE;
239 //if ( bExecute )
240 xD->execute();
241 //Execute();
242 Reference< XComponent > xDT( xD, uno::UNO_QUERY );
243 xDT->dispose();
244 delete pWindow;
246 Reference< XComponent > xT( xToolkit, uno::UNO_QUERY );
247 xT->dispose();
249 Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY );
250 if (xProps.is())
254 Reference< lang::XComponent > xComp;
255 if (xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xComp)
257 xComp->dispose();
260 catch (beans::UnknownPropertyException &)
266 void MyWin::Paint( const Rectangle& r )
268 static BOOL bDraw = TRUE;
269 if ( bDraw && mxView.is() )
270 mxView->draw( 50, 50 );