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