1*b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b0724fc6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b0724fc6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b0724fc6SAndrew Rist * distributed with this work for additional information
6*b0724fc6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b0724fc6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b0724fc6SAndrew Rist * "License"); you may not use this file except in compliance
9*b0724fc6SAndrew Rist * with the License. You may obtain a copy of the License at
10*b0724fc6SAndrew Rist *
11*b0724fc6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b0724fc6SAndrew Rist *
13*b0724fc6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b0724fc6SAndrew Rist * software distributed under the License is distributed on an
15*b0724fc6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b0724fc6SAndrew Rist * KIND, either express or implied. See the License for the
17*b0724fc6SAndrew Rist * specific language governing permissions and limitations
18*b0724fc6SAndrew Rist * under the License.
19*b0724fc6SAndrew Rist *
20*b0724fc6SAndrew Rist *************************************************************/
21*b0724fc6SAndrew Rist
22*b0724fc6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_toolkit.hxx"
26cdf0e10cSrcweir #include <tools/svwin.h>
27cdf0e10cSrcweir #include <sal/main.h>
28cdf0e10cSrcweir #include <com/sun/star/awt/XToolkit.hpp>
29cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
31cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
32cdf0e10cSrcweir #include <com/sun/star/awt/XControlModel.hpp>
33cdf0e10cSrcweir #include <com/sun/star/awt/XControlContainer.hpp>
34cdf0e10cSrcweir #include <com/sun/star/awt/XControl.hpp>
35cdf0e10cSrcweir #include <com/sun/star/awt/XDialog.hpp>
36cdf0e10cSrcweir
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include <tools/debug.hxx>
39cdf0e10cSrcweir #include <vcl/svapp.hxx>
40cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
41cdf0e10cSrcweir
42cdf0e10cSrcweir #include <svtools/unoiface.hxx> // InitExtToolkit
43cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
44cdf0e10cSrcweir
45cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
46cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
47cdf0e10cSrcweir #include <comphelper/regpathhelper.hxx>
48cdf0e10cSrcweir
49cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
50cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp>
51cdf0e10cSrcweir
52cdf0e10cSrcweir
53cdf0e10cSrcweir using namespace ::com::sun::star;
54cdf0e10cSrcweir using namespace ::com::sun::star::connection;
55cdf0e10cSrcweir using namespace ::vos;
56cdf0e10cSrcweir using namespace ::rtl;
57cdf0e10cSrcweir using namespace ::com::sun::star::uno;
58cdf0e10cSrcweir using namespace ::com::sun::star::registry;
59cdf0e10cSrcweir using namespace ::com::sun::star::lang;
60cdf0e10cSrcweir
61cdf0e10cSrcweir
62cdf0e10cSrcweir
createApplicationServiceManager()63cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > createApplicationServiceManager()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir try
66cdf0e10cSrcweir {
67cdf0e10cSrcweir ::rtl::OUString localRegistry = ::comphelper::getPathToUserRegistry();
68cdf0e10cSrcweir ::rtl::OUString systemRegistry = ::comphelper::getPathToSystemRegistry();
69cdf0e10cSrcweir
70cdf0e10cSrcweir Reference< XSimpleRegistry > xLocalRegistry( ::cppu::createSimpleRegistry() );
71cdf0e10cSrcweir Reference< XSimpleRegistry > xSystemRegistry( ::cppu::createSimpleRegistry() );
72cdf0e10cSrcweir if ( xLocalRegistry.is() && (localRegistry.getLength() > 0) )
73cdf0e10cSrcweir {
74cdf0e10cSrcweir try
75cdf0e10cSrcweir {
76cdf0e10cSrcweir xLocalRegistry->open( localRegistry, sal_False, sal_True);
77cdf0e10cSrcweir }
78cdf0e10cSrcweir catch ( InvalidRegistryException& )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
82cdf0e10cSrcweir if ( !xLocalRegistry->isValid() )
83cdf0e10cSrcweir xLocalRegistry->open(localRegistry, sal_True, sal_True);
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
86cdf0e10cSrcweir if ( xSystemRegistry.is() && (systemRegistry.getLength() > 0) )
87cdf0e10cSrcweir xSystemRegistry->open( systemRegistry, sal_True, sal_False);
88cdf0e10cSrcweir
89cdf0e10cSrcweir if ( (xLocalRegistry.is() && xLocalRegistry->isValid()) &&
90cdf0e10cSrcweir (xSystemRegistry.is() && xSystemRegistry->isValid()) )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir Reference < XSimpleRegistry > xReg( ::cppu::createNestedRegistry() );
93cdf0e10cSrcweir Sequence< Any > seqAnys(2);
94cdf0e10cSrcweir seqAnys[0] <<= xLocalRegistry ;
95cdf0e10cSrcweir seqAnys[1] <<= xSystemRegistry ;
96cdf0e10cSrcweir Reference< XInitialization > xInit( xReg, UNO_QUERY );
97cdf0e10cSrcweir xInit->initialize( seqAnys );
98cdf0e10cSrcweir
99cdf0e10cSrcweir Reference< XComponentContext > xContext( ::cppu::bootstrap_InitialComponentContext( xReg ) );
100cdf0e10cSrcweir return Reference< XMultiServiceFactory >( xContext->getServiceManager(), UNO_QUERY );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir }
103cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir }
106cdf0e10cSrcweir
107cdf0e10cSrcweir return ::cppu::createServiceFactory();
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir
111cdf0e10cSrcweir // -----------------------------------------------------------------------
112cdf0e10cSrcweir void Main( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & );
113cdf0e10cSrcweir
SAL_IMPLEMENT_MAIN()114cdf0e10cSrcweir SAL_IMPLEMENT_MAIN()
115cdf0e10cSrcweir {
116cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMSF = createApplicationServiceManager();
117cdf0e10cSrcweir //SVInit( xMSF );
118cdf0e10cSrcweir ::Main( xMSF );
119cdf0e10cSrcweir //SVDeinit();
120cdf0e10cSrcweir return NULL;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir
123cdf0e10cSrcweir /*
124cdf0e10cSrcweir class MyApp : public Application
125cdf0e10cSrcweir {
126cdf0e10cSrcweir public:
127cdf0e10cSrcweir void Main()
128cdf0e10cSrcweir {
129cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMSF = createApplicationServiceManager();
130cdf0e10cSrcweir ::Main( xMSF );
131cdf0e10cSrcweir }
132cdf0e10cSrcweir };
133cdf0e10cSrcweir
134cdf0e10cSrcweir MyApp aMyApp;
135cdf0e10cSrcweir */
136cdf0e10cSrcweir
137cdf0e10cSrcweir
138cdf0e10cSrcweir class MyWin : public WorkWindow
139cdf0e10cSrcweir {
140cdf0e10cSrcweir private:
141cdf0e10cSrcweir uno::Reference< awt::XView > mxView;
142cdf0e10cSrcweir
143cdf0e10cSrcweir public:
MyWin()144cdf0e10cSrcweir MyWin() : WorkWindow( NULL, WB_APP|WB_STDWORK ) {;}
145cdf0e10cSrcweir void Paint( const Rectangle& r );
SetXView(uno::Reference<awt::XView> xV)146cdf0e10cSrcweir void SetXView( uno::Reference< awt::XView > xV ) { mxView = xV; }
147cdf0e10cSrcweir };
148cdf0e10cSrcweir
149cdf0e10cSrcweir
150cdf0e10cSrcweir // -----------------------------------------------------------------------
151cdf0e10cSrcweir
Main(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xMSF)152cdf0e10cSrcweir void Main( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xMSF )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir ::comphelper::setProcessServiceFactory( xMSF );
155cdf0e10cSrcweir
156cdf0e10cSrcweir //uno::Reference< awt::XToolkit> xToolkit( xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.ExtToolkit" ) ) ), uno::UNO_QUERY );
157cdf0e10cSrcweir uno::Reference< awt::XToolkit> xToolkit( xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ) ), uno::UNO_QUERY );
158cdf0e10cSrcweir
159cdf0e10cSrcweir // Create a DialogModel
160cdf0e10cSrcweir uno::Reference< container::XNameContainer > xC( xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), uno::UNO_QUERY );
161cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xModFact( xC, uno::UNO_QUERY );
162cdf0e10cSrcweir
163cdf0e10cSrcweir // Create a ButtonModel
164cdf0e10cSrcweir uno::Reference< awt::XControlModel > xCtrl1( xModFact->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlButtonModel" ) ) ), uno::UNO_QUERY );
165cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPSet( xCtrl1, uno::UNO_QUERY );
166cdf0e10cSrcweir uno::Any aValue;
167cdf0e10cSrcweir aValue <<= (sal_Int32) 10;
168cdf0e10cSrcweir xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ), aValue );
169cdf0e10cSrcweir aValue <<= (sal_Int32) 10;
170cdf0e10cSrcweir xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) ), aValue );
171cdf0e10cSrcweir aValue <<= (sal_Int32) 40;
172cdf0e10cSrcweir xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Width" ) ), aValue );
173cdf0e10cSrcweir aValue <<= (sal_Int32) 12;
174cdf0e10cSrcweir xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Height" ) ), aValue );
175cdf0e10cSrcweir aValue <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Test!" ) );
176cdf0e10cSrcweir xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Label" ) ), aValue );
177cdf0e10cSrcweir uno::Any aAny;
178cdf0e10cSrcweir aAny <<= xCtrl1;
179cdf0e10cSrcweir xC->insertByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Control1" ) ), aAny );
180cdf0e10cSrcweir
181cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xDlgPSet( xC, uno::UNO_QUERY );
182cdf0e10cSrcweir aValue <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Test-Dialog" ) );
183cdf0e10cSrcweir xDlgPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Title" ) ), aValue );
184cdf0e10cSrcweir aValue <<= (sal_Int32) 200;
185cdf0e10cSrcweir xDlgPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Width" ) ), aValue );
186cdf0e10cSrcweir aValue <<= (sal_Int32) 200;
187cdf0e10cSrcweir xDlgPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Height" ) ), aValue );
188cdf0e10cSrcweir
189cdf0e10cSrcweir // Create a Dialog
190cdf0e10cSrcweir uno::Reference< awt::XControl > xDlg( xMSF->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialog" ) ) ), uno::UNO_QUERY );
191cdf0e10cSrcweir uno::Reference< awt::XControlModel > xDlgMod( xC, uno::UNO_QUERY );
192cdf0e10cSrcweir xDlg->setModel( xDlgMod );
193cdf0e10cSrcweir
194cdf0e10cSrcweir // Create a EditModel
195cdf0e10cSrcweir uno::Reference< awt::XControlModel > xCtrl2( xModFact->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlEditModel" ) ) ), uno::UNO_QUERY );
196cdf0e10cSrcweir xPSet = uno::Reference< beans::XPropertySet >( xCtrl2, uno::UNO_QUERY );
197cdf0e10cSrcweir aValue <<= (sal_Int32) 10;
198cdf0e10cSrcweir xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ), aValue );
199cdf0e10cSrcweir aValue <<= (sal_Int32) 40;
200cdf0e10cSrcweir xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) ), aValue );
201cdf0e10cSrcweir aValue <<= (sal_Int32) 80;
202cdf0e10cSrcweir xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Width" ) ), aValue );
203cdf0e10cSrcweir aValue <<= (sal_Int32) 12;
204cdf0e10cSrcweir xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Height" ) ), aValue );
205cdf0e10cSrcweir aValue <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Text..." ) );
206cdf0e10cSrcweir xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Text" ) ), aValue );
207cdf0e10cSrcweir aAny <<= xCtrl2;
208cdf0e10cSrcweir xC->insertByName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Control2" ) ), aAny );
209cdf0e10cSrcweir
210cdf0e10cSrcweir // test if listener works...
211cdf0e10cSrcweir aValue <<= (sal_Int32) 20;
212cdf0e10cSrcweir xPSet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ), aValue );
213cdf0e10cSrcweir
214cdf0e10cSrcweir MyWin * pWindow;
215cdf0e10cSrcweir ::osl::Guard< vos::IMutex > aVclGuard( Application::GetSolarMutex() );
216cdf0e10cSrcweir pWindow = new MyWin();
217cdf0e10cSrcweir pWindow->Show();
218cdf0e10cSrcweir
219cdf0e10cSrcweir xDlg->setDesignMode( sal_True );
220cdf0e10cSrcweir
221cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow( xDlg, uno::UNO_QUERY );
222cdf0e10cSrcweir xWindow->setVisible( sal_False );
223cdf0e10cSrcweir
224cdf0e10cSrcweir xDlg->createPeer( xToolkit, pWindow->GetComponentInterface() );
225cdf0e10cSrcweir
226cdf0e10cSrcweir uno::Reference< awt::XView > xView( xDlg, uno::UNO_QUERY );
227cdf0e10cSrcweir pWindow->SetXView( xView );
228cdf0e10cSrcweir
229cdf0e10cSrcweir uno::Reference< awt::XDialog > xD( xDlg, uno::UNO_QUERY );
230cdf0e10cSrcweir
231cdf0e10cSrcweir //static BOOL bExecute = FALSE;
232cdf0e10cSrcweir //if ( bExecute )
233cdf0e10cSrcweir xD->execute();
234cdf0e10cSrcweir //Execute();
235cdf0e10cSrcweir Reference< XComponent > xDT( xD, uno::UNO_QUERY );
236cdf0e10cSrcweir xDT->dispose();
237cdf0e10cSrcweir delete pWindow;
238cdf0e10cSrcweir
239cdf0e10cSrcweir Reference< XComponent > xT( xToolkit, uno::UNO_QUERY );
240cdf0e10cSrcweir xT->dispose();
241cdf0e10cSrcweir
242cdf0e10cSrcweir Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY );
243cdf0e10cSrcweir if (xProps.is())
244cdf0e10cSrcweir {
245cdf0e10cSrcweir try
246cdf0e10cSrcweir {
247cdf0e10cSrcweir Reference< lang::XComponent > xComp;
248cdf0e10cSrcweir if (xProps->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xComp)
249cdf0e10cSrcweir {
250cdf0e10cSrcweir xComp->dispose();
251cdf0e10cSrcweir }
252cdf0e10cSrcweir }
253cdf0e10cSrcweir catch (beans::UnknownPropertyException &)
254cdf0e10cSrcweir {
255cdf0e10cSrcweir }
256cdf0e10cSrcweir }
257cdf0e10cSrcweir }
258cdf0e10cSrcweir
Paint(const Rectangle & r)259cdf0e10cSrcweir void MyWin::Paint( const Rectangle& r )
260cdf0e10cSrcweir {
261cdf0e10cSrcweir static BOOL bDraw = TRUE;
262cdf0e10cSrcweir if ( bDraw && mxView.is() )
263cdf0e10cSrcweir mxView->draw( 50, 50 );
264cdf0e10cSrcweir }
265cdf0e10cSrcweir
266