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