merged tag ooo/DEV300_m102
[LibreOffice.git] / toolkit / workben / unodialog.cxx
blob052ece9ac7fd827d8317a07a535bd41a8f5fa4f4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_toolkit.hxx"
30 #include <tools/svwin.h>
31 #include <sal/main.h>
32 #include <com/sun/star/awt/XToolkit.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/container/XNameContainer.hpp>
36 #include <com/sun/star/awt/XControlModel.hpp>
37 #include <com/sun/star/awt/XControlContainer.hpp>
38 #include <com/sun/star/awt/XControl.hpp>
39 #include <com/sun/star/awt/XDialog.hpp>
42 #include <tools/debug.hxx>
43 #include <vcl/svapp.hxx>
44 #include <vcl/wrkwin.hxx>
46 #include <svtools/unoiface.hxx> // InitExtToolkit
47 #include <comphelper/processfactory.hxx>
49 #include <cppuhelper/servicefactory.hxx>
50 #include <cppuhelper/bootstrap.hxx>
51 #include <comphelper/regpathhelper.hxx>
53 #include <com/sun/star/lang/XInitialization.hpp>
54 #include <com/sun/star/registry/XSimpleRegistry.hpp>
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::connection;
59 using namespace ::vos;
60 using namespace ::rtl;
61 using namespace ::com::sun::star::uno;
62 using namespace ::com::sun::star::registry;
63 using namespace ::com::sun::star::lang;
67 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > createApplicationServiceManager()
69 try
71 ::rtl::OUString localRegistry = ::comphelper::getPathToUserRegistry();
72 ::rtl::OUString systemRegistry = ::comphelper::getPathToSystemRegistry();
74 Reference< XSimpleRegistry > xLocalRegistry( ::cppu::createSimpleRegistry() );
75 Reference< XSimpleRegistry > xSystemRegistry( ::cppu::createSimpleRegistry() );
76 if ( xLocalRegistry.is() && (localRegistry.getLength() > 0) )
78 try
80 xLocalRegistry->open( localRegistry, sal_False, sal_True);
82 catch ( InvalidRegistryException& )
86 if ( !xLocalRegistry->isValid() )
87 xLocalRegistry->open(localRegistry, sal_True, sal_True);
90 if ( xSystemRegistry.is() && (systemRegistry.getLength() > 0) )
91 xSystemRegistry->open( systemRegistry, sal_True, sal_False);
93 if ( (xLocalRegistry.is() && xLocalRegistry->isValid()) &&
94 (xSystemRegistry.is() && xSystemRegistry->isValid()) )
96 Reference < XSimpleRegistry > xReg( ::cppu::createNestedRegistry() );
97 Sequence< Any > seqAnys(2);
98 seqAnys[0] <<= xLocalRegistry ;
99 seqAnys[1] <<= xSystemRegistry ;
100 Reference< XInitialization > xInit( xReg, UNO_QUERY );
101 xInit->initialize( seqAnys );
103 Reference< XComponentContext > xContext( ::cppu::bootstrap_InitialComponentContext( xReg ) );
104 return Reference< XMultiServiceFactory >( xContext->getServiceManager(), UNO_QUERY );
107 catch( ::com::sun::star::uno::Exception& )
111 return ::cppu::createServiceFactory();
115 // -----------------------------------------------------------------------
116 void Main( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & );
118 SAL_IMPLEMENT_MAIN()
120 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMSF = createApplicationServiceManager();
121 //SVInit( xMSF );
122 ::Main( xMSF );
123 //SVDeinit();
124 return NULL;
128 class MyApp : public Application
130 public:
131 void Main()
133 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMSF = createApplicationServiceManager();
134 ::Main( xMSF );
138 MyApp aMyApp;
142 class MyWin : public WorkWindow
144 private:
145 uno::Reference< awt::XView > mxView;
147 public:
148 MyWin() : WorkWindow( NULL, WB_APP|WB_STDWORK ) {;}
149 void Paint( const Rectangle& r );
150 void SetXView( uno::Reference< awt::XView > xV ) { mxView = xV; }
154 // -----------------------------------------------------------------------
156 void Main( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xMSF )
158 ::comphelper::setProcessServiceFactory( xMSF );
160 //uno::Reference< awt::XToolkit> xToolkit( xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.ExtToolkit" ) ) ), uno::UNO_QUERY );
161 uno::Reference< awt::XToolkit> xToolkit( xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ) ), uno::UNO_QUERY );
163 // Create a DialogModel
164 uno::Reference< container::XNameContainer > xC( xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), uno::UNO_QUERY );
165 uno::Reference< lang::XMultiServiceFactory > xModFact( xC, uno::UNO_QUERY );
167 // Create a ButtonModel
168 uno::Reference< awt::XControlModel > xCtrl1( xModFact->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlButtonModel" ) ) ), uno::UNO_QUERY );
169 uno::Reference< beans::XPropertySet > xPSet( xCtrl1, uno::UNO_QUERY );
170 uno::Any aValue;
171 aValue <<= (sal_Int32) 10;
172 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ), aValue );
173 aValue <<= (sal_Int32) 10;
174 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) ), aValue );
175 aValue <<= (sal_Int32) 40;
176 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Width" ) ), aValue );
177 aValue <<= (sal_Int32) 12;
178 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Height" ) ), aValue );
179 aValue <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Test!" ) );
180 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Label" ) ), aValue );
181 uno::Any aAny;
182 aAny <<= xCtrl1;
183 xC->insertByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Control1" ) ), aAny );
185 uno::Reference< beans::XPropertySet > xDlgPSet( xC, uno::UNO_QUERY );
186 aValue <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Test-Dialog" ) );
187 xDlgPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Title" ) ), aValue );
188 aValue <<= (sal_Int32) 200;
189 xDlgPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Width" ) ), aValue );
190 aValue <<= (sal_Int32) 200;
191 xDlgPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Height" ) ), aValue );
193 // Create a Dialog
194 uno::Reference< awt::XControl > xDlg( xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialog" ) ) ), uno::UNO_QUERY );
195 uno::Reference< awt::XControlModel > xDlgMod( xC, uno::UNO_QUERY );
196 xDlg->setModel( xDlgMod );
198 // Create a EditModel
199 uno::Reference< awt::XControlModel > xCtrl2( xModFact->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlEditModel" ) ) ), uno::UNO_QUERY );
200 xPSet = uno::Reference< beans::XPropertySet >( xCtrl2, uno::UNO_QUERY );
201 aValue <<= (sal_Int32) 10;
202 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ), aValue );
203 aValue <<= (sal_Int32) 40;
204 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) ), aValue );
205 aValue <<= (sal_Int32) 80;
206 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Width" ) ), aValue );
207 aValue <<= (sal_Int32) 12;
208 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Height" ) ), aValue );
209 aValue <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Text..." ) );
210 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Text" ) ), aValue );
211 aAny <<= xCtrl2;
212 xC->insertByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Control2" ) ), aAny );
214 // test if listener works...
215 aValue <<= (sal_Int32) 20;
216 xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ), aValue );
218 MyWin * pWindow;
219 ::osl::Guard< vos::IMutex > aVclGuard( Application::GetSolarMutex() );
220 pWindow = new MyWin();
221 pWindow->Show();
223 xDlg->setDesignMode( sal_True );
225 uno::Reference< awt::XWindow > xWindow( xDlg, uno::UNO_QUERY );
226 xWindow->setVisible( sal_False );
228 xDlg->createPeer( xToolkit, pWindow->GetComponentInterface() );
230 uno::Reference< awt::XView > xView( xDlg, uno::UNO_QUERY );
231 pWindow->SetXView( xView );
233 uno::Reference< awt::XDialog > xD( xDlg, uno::UNO_QUERY );
235 //static BOOL bExecute = FALSE;
236 //if ( bExecute )
237 xD->execute();
238 //Execute();
239 Reference< XComponent > xDT( xD, uno::UNO_QUERY );
240 xDT->dispose();
241 delete pWindow;
243 Reference< XComponent > xT( xToolkit, uno::UNO_QUERY );
244 xT->dispose();
246 Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY );
247 if (xProps.is())
251 Reference< lang::XComponent > xComp;
252 if (xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xComp)
254 xComp->dispose();
257 catch (beans::UnknownPropertyException &)
263 void MyWin::Paint( const Rectangle& r )
265 static BOOL bDraw = TRUE;
266 if ( bDraw && mxView.is() )
267 mxView->draw( 50, 50 );