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_svtools.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 32*cdf0e10cSrcweir // switches 33*cdf0e10cSrcweir // use it to enable test szenarios 34*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #define TEST_DYNAMICMENUOPTIONS 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 39*cdf0e10cSrcweir // my own includes 40*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include <unotools/dynamicmenuoptions.hxx> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 45*cdf0e10cSrcweir // interface includes 46*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 47*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx> 48*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp> 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 53*cdf0e10cSrcweir // other includes 54*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #ifndef _COMPHELPER_PROCESSFACTORY_HXX_ 57*cdf0e10cSrcweir #include <comphelper/regpathhelper.hxx> 58*cdf0e10cSrcweir #endif 59*cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx> 60*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx> 61*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 62*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h> 63*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.h> 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir #ifndef _RTL_USTRING_ 66*cdf0e10cSrcweir #include <rtl/ustring> 67*cdf0e10cSrcweir #endif 68*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 69*cdf0e10cSrcweir #include <osl/diagnose.h> 70*cdf0e10cSrcweir #include <osl/mutex.hxx> 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir /* 73*cdf0e10cSrcweir #include <svtools/unoiface.hxx> 74*cdf0e10cSrcweir #include <tools/urlobj.hxx> 75*cdf0e10cSrcweir */ 76*cdf0e10cSrcweir #include <vcl/event.hxx> 77*cdf0e10cSrcweir #include <vcl/svapp.hxx> 78*cdf0e10cSrcweir #include <vcl/wrkwin.hxx> 79*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 80*cdf0e10cSrcweir #include <stdio.h> 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 83*cdf0e10cSrcweir // const 84*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 87*cdf0e10cSrcweir // namespace 88*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir using namespace ::rtl ; 91*cdf0e10cSrcweir using namespace ::osl ; 92*cdf0e10cSrcweir using namespace ::comphelper ; 93*cdf0e10cSrcweir using namespace ::com::sun::star::uno ; 94*cdf0e10cSrcweir using namespace ::com::sun::star::lang ; 95*cdf0e10cSrcweir using namespace ::com::sun::star::beans ; 96*cdf0e10cSrcweir using namespace ::com::sun::star::registry ; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 99*cdf0e10cSrcweir // defines 100*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir #define ASCII( STEXT ) OUString( RTL_CONSTASCII_USTRINGPARAM( STEXT )) 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir #define SERVICENAME_SIMPLEREGISTRY OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.registry.SimpleRegistry" )) 105*cdf0e10cSrcweir #define SERVICENAME_NESTEDREGISTRY OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.registry.NestedRegistry" )) 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 108*cdf0e10cSrcweir // declarations 109*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir class TestApplication : public Application 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir //************************************************************************************************************* 114*cdf0e10cSrcweir // interface 115*cdf0e10cSrcweir //************************************************************************************************************* 116*cdf0e10cSrcweir public: 117*cdf0e10cSrcweir void Main(); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir //************************************************************************************************************* 120*cdf0e10cSrcweir // test methods 121*cdf0e10cSrcweir //************************************************************************************************************* 122*cdf0e10cSrcweir private: 123*cdf0e10cSrcweir void impl_testDynamicMenuOptions(); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir //************************************************************************************************************* 126*cdf0e10cSrcweir // helper methods 127*cdf0e10cSrcweir //************************************************************************************************************* 128*cdf0e10cSrcweir private: 129*cdf0e10cSrcweir static Reference< XMultiServiceFactory > getUNOServiceManager(); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir //************************************************************************************************************* 132*cdf0e10cSrcweir // member 133*cdf0e10cSrcweir //************************************************************************************************************* 134*cdf0e10cSrcweir private: 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir }; // class TestApplication 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 139*cdf0e10cSrcweir // global variables 140*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir TestApplication aTestApplication ; 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 145*cdf0e10cSrcweir // main 146*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir void TestApplication::Main() 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir /**-*********************************************************************************************************** 151*cdf0e10cSrcweir initialize program 152*cdf0e10cSrcweir **************************************************************************************************************/ 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir // Init global servicemanager and set it for external services. 155*cdf0e10cSrcweir ::comphelper::setProcessServiceFactory( TestApplication::getUNOServiceManager() ); 156*cdf0e10cSrcweir // Control sucess of operation. 157*cdf0e10cSrcweir OSL_ENSURE( !(::comphelper::getProcessServiceFactory()!=TestApplication::getUNOServiceManager()), "TestApplication::Main()\nGlobal servicemanager not right initialized.\n" ); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir /**-*********************************************************************************************************** 160*cdf0e10cSrcweir test area 161*cdf0e10cSrcweir **************************************************************************************************************/ 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir #ifdef TEST_DYNAMICMENUOPTIONS 164*cdf0e10cSrcweir impl_testDynamicMenuOptions(); 165*cdf0e10cSrcweir #endif 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir // Execute(); 168*cdf0e10cSrcweir OSL_ENSURE( sal_False, "Test was successful!\n" ); 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir //***************************************************************************************************************** 172*cdf0e10cSrcweir // test configuration of dynamic menus "New" and "Wizard" 173*cdf0e10cSrcweir //***************************************************************************************************************** 174*cdf0e10cSrcweir void TestApplication::impl_testDynamicMenuOptions() 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir SvtDynamicMenuOptions aCFG; 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir // Test: 179*cdf0e10cSrcweir // read menus 180*cdf0e10cSrcweir // if( menus == empty ) 181*cdf0e10cSrcweir // { 182*cdf0e10cSrcweir // fill it with samples 183*cdf0e10cSrcweir // read it again 184*cdf0e10cSrcweir // } 185*cdf0e10cSrcweir // output content 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > lNewMenu = aCFG.GetMenu( E_NEWMENU ); 188*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > lWizardMenu = aCFG.GetMenu( E_WIZARDMENU ); 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir if( lNewMenu.getLength() < 1 ) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir aCFG.AppendItem( E_NEWMENU, ASCII("private:factory/swriter"), ASCII("new writer"), ASCII("icon_writer"), ASCII("_blank") ); 193*cdf0e10cSrcweir aCFG.AppendItem( E_NEWMENU, ASCII("private:factory/scalc" ), ASCII("new calc" ), ASCII("icon_calc" ), ASCII("_blank") ); 194*cdf0e10cSrcweir aCFG.AppendItem( E_NEWMENU, ASCII("private:factory/sdraw" ), ASCII("new draw" ), ASCII("icon_draw" ), ASCII("_blank") ); 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir lNewMenu = aCFG.GetMenu( E_NEWMENU ); 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir if( lWizardMenu.getLength() < 1 ) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir aCFG.AppendItem( E_WIZARDMENU, ASCII("file://a"), ASCII("system file"), ASCII("icon_file"), ASCII("_self") ); 202*cdf0e10cSrcweir aCFG.AppendItem( E_WIZARDMENU, ASCII("ftp://b" ), ASCII("ftp host" ), ASCII("icon_ftp" ), ASCII("_self") ); 203*cdf0e10cSrcweir aCFG.AppendItem( E_WIZARDMENU, ASCII("http://c"), ASCII("www" ), ASCII("icon_www" ), ASCII("_self") ); 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir lWizardMenu = aCFG.GetMenu( E_WIZARDMENU ); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir sal_uInt32 nItemCount ; 209*cdf0e10cSrcweir sal_uInt32 nItem ; 210*cdf0e10cSrcweir sal_uInt32 nPropertyCount; 211*cdf0e10cSrcweir sal_uInt32 nProperty ; 212*cdf0e10cSrcweir OUString sPropertyValue; 213*cdf0e10cSrcweir OUStringBuffer sOut( 5000 ) ; 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir nItemCount = lNewMenu.getLength(); 216*cdf0e10cSrcweir for( nItem=0; nItem<nItemCount; ++nItem ) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir nPropertyCount = lNewMenu[nItem].getLength(); 219*cdf0e10cSrcweir for( nProperty=0; nProperty<nPropertyCount; ++nProperty ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir lNewMenu[nItem][nProperty].Value >>= sPropertyValue; 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir sOut.appendAscii ( "New/" ); 224*cdf0e10cSrcweir sOut.append ( (sal_Int32)nItem ); 225*cdf0e10cSrcweir sOut.appendAscii ( "/" ); 226*cdf0e10cSrcweir sOut.append ( lNewMenu[nItem][nProperty].Name ); 227*cdf0e10cSrcweir sOut.appendAscii ( " = " ); 228*cdf0e10cSrcweir sOut.append ( sPropertyValue ); 229*cdf0e10cSrcweir sOut.appendAscii ( "\n" ); 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir sOut.appendAscii("\n--------------------------------------\n"); 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir nItemCount = lWizardMenu.getLength(); 236*cdf0e10cSrcweir for( nItem=0; nItem<nItemCount; ++nItem ) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir nPropertyCount = lNewMenu[nItem].getLength(); 239*cdf0e10cSrcweir for( nProperty=0; nProperty<nPropertyCount; ++nProperty ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir lWizardMenu[nItem][nProperty].Value >>= sPropertyValue; 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir sOut.appendAscii ( "Wizard/" ); 244*cdf0e10cSrcweir sOut.append ( (sal_Int32)nItem ); 245*cdf0e10cSrcweir sOut.appendAscii ( "/" ); 246*cdf0e10cSrcweir sOut.append ( lNewMenu[nItem][nProperty].Name ); 247*cdf0e10cSrcweir sOut.appendAscii ( " = " ); 248*cdf0e10cSrcweir sOut.append ( sPropertyValue ); 249*cdf0e10cSrcweir sOut.appendAscii ( "\n" ); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir OSL_ENSURE( sal_False, OUStringToOString( sOut.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ).getStr() ); 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir //***************************************************************************************************************** 257*cdf0e10cSrcweir // create new uno servicemanager by using normall applicat.rdb and user.rdb of an office installation! 258*cdf0e10cSrcweir // Don't use this application at same time like the office! 259*cdf0e10cSrcweir //***************************************************************************************************************** 260*cdf0e10cSrcweir Reference< XMultiServiceFactory > TestApplication::getUNOServiceManager() 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir static Reference< XMultiServiceFactory > smgr; 263*cdf0e10cSrcweir if( ! smgr.is() ) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir Reference< XComponentContext > rCtx = 266*cdf0e10cSrcweir cppu::defaultBootstrap_InitialComponentContext(); 267*cdf0e10cSrcweir smgr = Reference< XMultiServiceFactory > ( rCtx->getServiceManager() , UNO_QUERY ); 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir return smgr; 270*cdf0e10cSrcweir } 271