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