1*b5088357SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b5088357SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b5088357SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b5088357SAndrew Rist  * distributed with this work for additional information
6*b5088357SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b5088357SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b5088357SAndrew Rist  * "License"); you may not use this file except in compliance
9*b5088357SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b5088357SAndrew Rist  *
11*b5088357SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b5088357SAndrew Rist  *
13*b5088357SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b5088357SAndrew Rist  * software distributed under the License is distributed on an
15*b5088357SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b5088357SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b5088357SAndrew Rist  * specific language governing permissions and limitations
18*b5088357SAndrew Rist  * under the License.
19*b5088357SAndrew Rist  *
20*b5088357SAndrew Rist  *************************************************************/
21*b5088357SAndrew Rist 
22*b5088357SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_unotools.hxx"
26cdf0e10cSrcweir #ifndef GCC
27cdf0e10cSrcweir #endif
28cdf0e10cSrcweir 
29cdf0e10cSrcweir //_________________________________________________________________________________________________________________
30cdf0e10cSrcweir //	includes
31cdf0e10cSrcweir //_________________________________________________________________________________________________________________
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <unotools/dynamicmenuoptions.hxx>
34cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
35cdf0e10cSrcweir #include <unotools/configmgr.hxx>
36cdf0e10cSrcweir #include <unotools/configitem.hxx>
37cdf0e10cSrcweir #include <tools/debug.hxx>
38cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
39cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #ifndef __SGI_STL_VECTOR
42cdf0e10cSrcweir #include <vector>
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include <itemholder1.hxx>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #include <algorithm>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir //_________________________________________________________________________________________________________________
50cdf0e10cSrcweir //	namespaces
51cdf0e10cSrcweir //_________________________________________________________________________________________________________________
52cdf0e10cSrcweir 
53cdf0e10cSrcweir using namespace ::std					;
54cdf0e10cSrcweir using namespace ::utl					;
55cdf0e10cSrcweir using namespace ::rtl					;
56cdf0e10cSrcweir using namespace ::osl					;
57cdf0e10cSrcweir using namespace ::com::sun::star::uno	;
58cdf0e10cSrcweir using namespace ::com::sun::star::beans	;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir //_________________________________________________________________________________________________________________
61cdf0e10cSrcweir //	const
62cdf0e10cSrcweir //_________________________________________________________________________________________________________________
63cdf0e10cSrcweir 
64cdf0e10cSrcweir #define ROOTNODE_MENUS                                  OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/Menus/"     ))
65cdf0e10cSrcweir #define PATHDELIMITER                                   OUString(RTL_CONSTASCII_USTRINGPARAM("/"                        ))
66cdf0e10cSrcweir 
67cdf0e10cSrcweir #define SETNODE_NEWMENU                                 OUString(RTL_CONSTASCII_USTRINGPARAM("New"                      ))
68cdf0e10cSrcweir #define SETNODE_WIZARDMENU                              OUString(RTL_CONSTASCII_USTRINGPARAM("Wizard"                   ))
69cdf0e10cSrcweir #define SETNODE_HELPBOOKMARKS                           OUString(RTL_CONSTASCII_USTRINGPARAM("HelpBookmarks"            ))
70cdf0e10cSrcweir 
71cdf0e10cSrcweir #define PROPERTYNAME_URL                                DYNAMICMENU_PROPERTYNAME_URL
72cdf0e10cSrcweir #define PROPERTYNAME_TITLE                              DYNAMICMENU_PROPERTYNAME_TITLE
73cdf0e10cSrcweir #define PROPERTYNAME_IMAGEIDENTIFIER                    DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER
74cdf0e10cSrcweir #define PROPERTYNAME_TARGETNAME                         DYNAMICMENU_PROPERTYNAME_TARGETNAME
75cdf0e10cSrcweir 
76cdf0e10cSrcweir #define PROPERTYCOUNT                                   4
77cdf0e10cSrcweir 
78cdf0e10cSrcweir #define OFFSET_URL                                      0
79cdf0e10cSrcweir #define OFFSET_TITLE                                    1
80cdf0e10cSrcweir #define OFFSET_IMAGEIDENTIFIER                          2
81cdf0e10cSrcweir #define OFFSET_TARGETNAME                               3
82cdf0e10cSrcweir 
83cdf0e10cSrcweir #define PATHPREFIX_SETUP                                OUString(RTL_CONSTASCII_USTRINGPARAM("m"                        ))
84cdf0e10cSrcweir #define PATHPREFIX_USER                                 OUString(RTL_CONSTASCII_USTRINGPARAM("u"                        ))
85cdf0e10cSrcweir 
86cdf0e10cSrcweir //_________________________________________________________________________________________________________________
87cdf0e10cSrcweir //	private declarations!
88cdf0e10cSrcweir //_________________________________________________________________________________________________________________
89cdf0e10cSrcweir 
90cdf0e10cSrcweir /*-****************************************************************************************************************
91cdf0e10cSrcweir     @descr  struct to hold information about one menu entry.
92cdf0e10cSrcweir ****************************************************************************************************************-*/
93cdf0e10cSrcweir struct SvtDynMenuEntry
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     public:
SvtDynMenuEntrySvtDynMenuEntry96cdf0e10cSrcweir         SvtDynMenuEntry() {};
97cdf0e10cSrcweir 
SvtDynMenuEntrySvtDynMenuEntry98cdf0e10cSrcweir         SvtDynMenuEntry(  const OUString& sNewURL             ,
99cdf0e10cSrcweir                     const OUString& sNewTitle           ,
100cdf0e10cSrcweir                     const OUString& sNewImageIdentifier ,
101cdf0e10cSrcweir                     const OUString& sNewTargetName      )
102cdf0e10cSrcweir         {
103cdf0e10cSrcweir             sURL                = sNewURL               ;
104cdf0e10cSrcweir             sTitle              = sNewTitle             ;
105cdf0e10cSrcweir             sImageIdentifier    = sNewImageIdentifier   ;
106cdf0e10cSrcweir             sTargetName         = sNewTargetName        ;
107cdf0e10cSrcweir         }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     public:
110cdf0e10cSrcweir         OUString    sName               ;
111cdf0e10cSrcweir         OUString    sURL                ;
112cdf0e10cSrcweir         OUString    sTitle              ;
113cdf0e10cSrcweir         OUString    sImageIdentifier    ;
114cdf0e10cSrcweir         OUString    sTargetName         ;
115cdf0e10cSrcweir };
116cdf0e10cSrcweir 
117cdf0e10cSrcweir /*-****************************************************************************************************************
118cdf0e10cSrcweir     @descr  support simple menu structures and operations on it
119cdf0e10cSrcweir ****************************************************************************************************************-*/
120cdf0e10cSrcweir class SvtDynMenu
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     public:
123cdf0e10cSrcweir         //---------------------------------------------------------------------------------------------------------
124cdf0e10cSrcweir         // append setup written menu entry
125cdf0e10cSrcweir         // Don't touch name of entry. It was defined by setup and must be the same everytime!
126cdf0e10cSrcweir         // Look for double menu entries here too ... may be some seperator items are supeflous ...
AppendSetupEntry(const SvtDynMenuEntry & rEntry)127cdf0e10cSrcweir         void AppendSetupEntry( const SvtDynMenuEntry& rEntry )
128cdf0e10cSrcweir         {
129cdf0e10cSrcweir             if(
130cdf0e10cSrcweir                 ( lSetupEntries.size()         <  1           )  ||
131cdf0e10cSrcweir                 ( lSetupEntries.rbegin()->sURL != rEntry.sURL )
132cdf0e10cSrcweir               )
133cdf0e10cSrcweir             {
134cdf0e10cSrcweir                 lSetupEntries.push_back( rEntry );
135cdf0e10cSrcweir             }
136cdf0e10cSrcweir         }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         //---------------------------------------------------------------------------------------------------------
139cdf0e10cSrcweir         // append user specific menu entry
140cdf0e10cSrcweir         // We must find unique name for it by using special prefix
141cdf0e10cSrcweir         // and next count of user setted entries!
142cdf0e10cSrcweir         // Look for double menu entries here too ... may be some seperator items are supeflous ...
AppendUserEntry(SvtDynMenuEntry & rEntry)143cdf0e10cSrcweir         void AppendUserEntry( SvtDynMenuEntry& rEntry )
144cdf0e10cSrcweir         {
145cdf0e10cSrcweir             if(
146cdf0e10cSrcweir                 ( lUserEntries.size()         <  1           )  ||
147cdf0e10cSrcweir                 ( lUserEntries.rbegin()->sURL != rEntry.sURL )
148cdf0e10cSrcweir               )
149cdf0e10cSrcweir             {
150cdf0e10cSrcweir                 rEntry.sName  = PATHPREFIX_USER;
151cdf0e10cSrcweir                 rEntry.sName += OUString::valueOf( (sal_Int32)impl_getNextUserEntryNr() );
152cdf0e10cSrcweir                 lUserEntries.push_back( rEntry );
153cdf0e10cSrcweir             }
154cdf0e10cSrcweir         }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         //---------------------------------------------------------------------------------------------------------
157cdf0e10cSrcweir         // the only way to free memory!
Clear()158cdf0e10cSrcweir         void Clear()
159cdf0e10cSrcweir         {
160cdf0e10cSrcweir             lSetupEntries.clear();
161cdf0e10cSrcweir             lUserEntries.clear();
162cdf0e10cSrcweir         }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir         //---------------------------------------------------------------------------------------------------------
165cdf0e10cSrcweir         // convert internal list to external format
166cdf0e10cSrcweir         // for using it on right menus realy
167cdf0e10cSrcweir         // Notice:   We build a property list with 4 entries and set it on result list then.
168cdf0e10cSrcweir         //           The while-loop starts with pointer on internal member list lSetupEntries, change to
169cdf0e10cSrcweir         //           lUserEntries then and stop after that with NULL!
170cdf0e10cSrcweir         //           Separator entries will be packed in another way then normal entries! We define
171cdf0e10cSrcweir         //           special strings "sEmpty" and "sSeperator" to perform too ...
GetList() const172cdf0e10cSrcweir         Sequence< Sequence< PropertyValue > > GetList() const
173cdf0e10cSrcweir         {
174cdf0e10cSrcweir             sal_Int32                             nSetupCount = (sal_Int32)lSetupEntries.size();
175cdf0e10cSrcweir             sal_Int32                             nUserCount  = (sal_Int32)lUserEntries.size();
176cdf0e10cSrcweir             sal_Int32                             nStep       = 0;
177cdf0e10cSrcweir             Sequence< PropertyValue >             lProperties ( PROPERTYCOUNT );
178cdf0e10cSrcweir             Sequence< Sequence< PropertyValue > > lResult     ( nSetupCount+nUserCount );
179cdf0e10cSrcweir             OUString                              sSeperator  ( RTL_CONSTASCII_USTRINGPARAM("private:separator") );
180cdf0e10cSrcweir             OUString                              sEmpty      ;
181cdf0e10cSrcweir             const vector< SvtDynMenuEntry >*            pList       = &lSetupEntries;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir             lProperties[OFFSET_URL            ].Name = PROPERTYNAME_URL             ;
184cdf0e10cSrcweir             lProperties[OFFSET_TITLE          ].Name = PROPERTYNAME_TITLE           ;
185cdf0e10cSrcweir             lProperties[OFFSET_IMAGEIDENTIFIER].Name = PROPERTYNAME_IMAGEIDENTIFIER ;
186cdf0e10cSrcweir             lProperties[OFFSET_TARGETNAME     ].Name = PROPERTYNAME_TARGETNAME      ;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir             while( pList != NULL )
189cdf0e10cSrcweir             {
190cdf0e10cSrcweir                 for( vector< SvtDynMenuEntry >::const_iterator pItem =pList->begin();
191cdf0e10cSrcweir                                                          pItem!=pList->end()  ;
192cdf0e10cSrcweir                                                          ++pItem              )
193cdf0e10cSrcweir                 {
194cdf0e10cSrcweir                     if( pItem->sURL == sSeperator )
195cdf0e10cSrcweir                     {
196cdf0e10cSrcweir                         lProperties[OFFSET_URL              ].Value <<= sSeperator  ;
197cdf0e10cSrcweir                         lProperties[OFFSET_TITLE            ].Value <<= sEmpty      ;
198cdf0e10cSrcweir                         lProperties[OFFSET_IMAGEIDENTIFIER  ].Value <<= sEmpty      ;
199cdf0e10cSrcweir                         lProperties[OFFSET_TARGETNAME       ].Value <<= sEmpty      ;
200cdf0e10cSrcweir                     }
201cdf0e10cSrcweir                     else
202cdf0e10cSrcweir                     {
203cdf0e10cSrcweir                         lProperties[OFFSET_URL              ].Value <<= pItem->sURL            ;
204cdf0e10cSrcweir                         lProperties[OFFSET_TITLE            ].Value <<= pItem->sTitle          ;
205cdf0e10cSrcweir                         lProperties[OFFSET_IMAGEIDENTIFIER  ].Value <<= pItem->sImageIdentifier;
206cdf0e10cSrcweir                         lProperties[OFFSET_TARGETNAME       ].Value <<= pItem->sTargetName     ;
207cdf0e10cSrcweir                     }
208cdf0e10cSrcweir                     lResult[nStep] = lProperties;
209cdf0e10cSrcweir                     ++nStep;
210cdf0e10cSrcweir                 }
211cdf0e10cSrcweir                 if( pList == &lSetupEntries )
212cdf0e10cSrcweir                     pList = &lUserEntries;
213cdf0e10cSrcweir                 else
214cdf0e10cSrcweir                     pList = NULL;
215cdf0e10cSrcweir             }
216cdf0e10cSrcweir             return lResult;
217cdf0e10cSrcweir         }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir     private:
220cdf0e10cSrcweir         //---------------------------------------------------------------------------------------------------------
221cdf0e10cSrcweir         // search for an entry named "ux" with x=[0..i] inside our menu
222cdf0e10cSrcweir         // which has set highest number x. So we can add another user entry.
impl_getNextUserEntryNr() const223cdf0e10cSrcweir         sal_Int32 impl_getNextUserEntryNr() const
224cdf0e10cSrcweir         {
225cdf0e10cSrcweir             sal_Int32 nNr = 0;
226cdf0e10cSrcweir             for( vector< SvtDynMenuEntry >::const_iterator pItem =lUserEntries.begin();
227cdf0e10cSrcweir                                                      pItem!=lUserEntries.end()  ;
228cdf0e10cSrcweir                                                      ++pItem                    )
229cdf0e10cSrcweir             {
230cdf0e10cSrcweir                 if( pItem->sName.compareTo( PATHPREFIX_USER, 1 ) == 0 )
231cdf0e10cSrcweir                 {
232cdf0e10cSrcweir                     OUString  sNr      = pItem->sName.copy( 1, pItem->sName.getLength()-1 );
233cdf0e10cSrcweir                     sal_Int32 nCheckNr = sNr.toInt32();
234cdf0e10cSrcweir                     if( nCheckNr > nNr )
235cdf0e10cSrcweir                         nNr = nCheckNr;
236cdf0e10cSrcweir                 }
237cdf0e10cSrcweir             }
238cdf0e10cSrcweir             // Attention: Code isn't prepared for recyling of unused fragmented numbers!
239cdf0e10cSrcweir             // If we reach end of sal_Int32 range ... we must stop further working ...
240cdf0e10cSrcweir             // But I think nobody expand a menu to more then 1000 ... 100000 ... entries ... or?
241cdf0e10cSrcweir             DBG_ASSERT( !(nNr>0x7fffffff), "Menu::impl_getNextUserEntryNr()\nUser count can be out of range next time ...\n" );
242cdf0e10cSrcweir             return nNr;
243cdf0e10cSrcweir         }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     private:
246cdf0e10cSrcweir         vector< SvtDynMenuEntry > lSetupEntries;
247cdf0e10cSrcweir         vector< SvtDynMenuEntry > lUserEntries ;
248cdf0e10cSrcweir };
249cdf0e10cSrcweir 
250cdf0e10cSrcweir class SvtDynamicMenuOptions_Impl : public ConfigItem
251cdf0e10cSrcweir {
252cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
253cdf0e10cSrcweir 	//	public methods
254cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 	public:
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 		//---------------------------------------------------------------------------------------------------------
259cdf0e10cSrcweir 		//	constructor / destructor
260cdf0e10cSrcweir 		//---------------------------------------------------------------------------------------------------------
261cdf0e10cSrcweir 
262cdf0e10cSrcweir          SvtDynamicMenuOptions_Impl();
263cdf0e10cSrcweir         ~SvtDynamicMenuOptions_Impl();
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 		//---------------------------------------------------------------------------------------------------------
266cdf0e10cSrcweir 		//	overloaded methods of baseclass
267cdf0e10cSrcweir 		//---------------------------------------------------------------------------------------------------------
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 		/*-****************************************************************************************************//**
270cdf0e10cSrcweir 			@short		called for notify of configmanager
271cdf0e10cSrcweir 			@descr		These method is called from the ConfigManager before application ends or from the
272cdf0e10cSrcweir 			 			PropertyChangeListener if the sub tree broadcasts changes. You must update your
273cdf0e10cSrcweir 						internal values.
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 			@seealso	baseclass ConfigItem
276cdf0e10cSrcweir 
277cdf0e10cSrcweir             @param      "lPropertyNames" is the list of properties which should be updated.
278cdf0e10cSrcweir 			@return		-
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 			@onerror	-
281cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
282cdf0e10cSrcweir 
283cdf0e10cSrcweir         virtual void Notify( const Sequence< OUString >& lPropertyNames );
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 		/*-****************************************************************************************************//**
286cdf0e10cSrcweir 			@short		write changes to configuration
287cdf0e10cSrcweir 			@descr		These method writes the changed values into the sub tree
288cdf0e10cSrcweir 						and should always called in our destructor to guarantee consistency of config data.
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 			@seealso	baseclass ConfigItem
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 			@param		-
293cdf0e10cSrcweir 			@return		-
294cdf0e10cSrcweir 
295cdf0e10cSrcweir 			@onerror	-
296cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     	virtual void Commit();
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 		//---------------------------------------------------------------------------------------------------------
301cdf0e10cSrcweir 		//	public interface
302cdf0e10cSrcweir 		//---------------------------------------------------------------------------------------------------------
303cdf0e10cSrcweir 
304cdf0e10cSrcweir 		/*-****************************************************************************************************//**
305cdf0e10cSrcweir             @short      base implementation of public interface for "SvtDynamicMenuOptions"!
306cdf0e10cSrcweir             @descr      These class is used as static member of "SvtDynamicMenuOptions" ...
307cdf0e10cSrcweir 						=> The code exist only for one time and isn't duplicated for every instance!
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 			@seealso	-
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 			@param		-
312cdf0e10cSrcweir 			@return		-
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 			@onerror	-
315cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
316cdf0e10cSrcweir 
317cdf0e10cSrcweir         void                                    Clear       (           EDynamicMenuType    eMenu           );
318cdf0e10cSrcweir         Sequence< Sequence< PropertyValue > >   GetMenu     (           EDynamicMenuType    eMenu           ) const ;
319cdf0e10cSrcweir         void                                    AppendItem  (           EDynamicMenuType    eMenu           ,
320cdf0e10cSrcweir                                                                 const   OUString&           sURL            ,
321cdf0e10cSrcweir                                                                 const   OUString&           sTitle          ,
322cdf0e10cSrcweir                                                                 const   OUString&           sImageIdentifier,
323cdf0e10cSrcweir                                                                 const   OUString&           sTargetName     );
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
326cdf0e10cSrcweir 	//	private methods
327cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
328cdf0e10cSrcweir 
329cdf0e10cSrcweir 	private:
330cdf0e10cSrcweir 
331cdf0e10cSrcweir 		/*-****************************************************************************************************//**
332cdf0e10cSrcweir             @short      return list of key names of our configuration management which represent oue module tree
333cdf0e10cSrcweir 			@descr		These methods return the current list of key names! We need it to get needed values from our
334cdf0e10cSrcweir                         configuration management and support dynamical menu item lists!
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 			@seealso	-
337cdf0e10cSrcweir 
338cdf0e10cSrcweir             @param      "nNewCount"     ,   returns count of menu entries for "new"
339cdf0e10cSrcweir             @param      "nWizardCount"  ,   returns count of menu entries for "wizard"
340cdf0e10cSrcweir 			@return		A list of configuration key names is returned.
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 			@onerror	-
343cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
344cdf0e10cSrcweir 
345cdf0e10cSrcweir         Sequence< OUString > impl_GetPropertyNames( sal_uInt32& nNewCount, sal_uInt32& nWizardCount, sal_uInt32& nHelpBookmarksCount );
346cdf0e10cSrcweir 
347cdf0e10cSrcweir         /*-****************************************************************************************************//**
348cdf0e10cSrcweir             @short      sort given source list and expand it for all well known properties to destination
349cdf0e10cSrcweir             @descr      We must support sets of entries with count inside the name .. but some of them could be missing!
350cdf0e10cSrcweir                         e.g. s1-s2-s3-s0-u1-s6-u5-u7
351cdf0e10cSrcweir                         Then we must sort it by name and expand it to the follow one:
352cdf0e10cSrcweir                             sSetNode/s0/URL
353cdf0e10cSrcweir                             sSetNode/s0/Title
354cdf0e10cSrcweir                             sSetNode/s0/...
355cdf0e10cSrcweir                             sSetNode/s1/URL
356cdf0e10cSrcweir                             sSetNode/s1/Title
357cdf0e10cSrcweir                             sSetNode/s1/...
358cdf0e10cSrcweir                             ...
359cdf0e10cSrcweir                             sSetNode/s6/URL
360cdf0e10cSrcweir                             sSetNode/s6/Title
361cdf0e10cSrcweir                             sSetNode/s6/...
362cdf0e10cSrcweir                             sSetNode/u1/URL
363cdf0e10cSrcweir                             sSetNode/u1/Title
364cdf0e10cSrcweir                             sSetNode/u1/...
365cdf0e10cSrcweir                             ...
366cdf0e10cSrcweir                             sSetNode/u7/URL
367cdf0e10cSrcweir                             sSetNode/u7/Title
368cdf0e10cSrcweir                             sSetNode/u7/...
369cdf0e10cSrcweir                         Rules: We start with all setup written entries names "sx" and x=[0..n].
370cdf0e10cSrcweir                         Then we handle all "ux" items. Inside these blocks we sort it ascending by number.
371cdf0e10cSrcweir 
372cdf0e10cSrcweir             @attention  We add these expanded list to the end of given "lDestination" list!
373cdf0e10cSrcweir                         So we must start on "lDestination.getLength()".
374cdf0e10cSrcweir                         Reallocation of memory of destination list is done by us!
375cdf0e10cSrcweir 
376cdf0e10cSrcweir             @seealso    method impl_GetPropertyNames()
377cdf0e10cSrcweir 
378cdf0e10cSrcweir             @param      "lSource"      ,   original list (e.g. [m1-m2-m3-m6-m0] )
379cdf0e10cSrcweir             @param      "lDestination" ,   destination of operation
380cdf0e10cSrcweir             @param      "sSetNode"     ,   name of configuration set to build complete path
381cdf0e10cSrcweir 			@return		A list of configuration key names is returned.
382cdf0e10cSrcweir 
383cdf0e10cSrcweir 			@onerror	-
384cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
385cdf0e10cSrcweir 
386cdf0e10cSrcweir         void impl_SortAndExpandPropertyNames( const Sequence< OUString >& lSource      ,
387cdf0e10cSrcweir                                                     Sequence< OUString >& lDestination ,
388cdf0e10cSrcweir                                               const OUString&             sSetNode     );
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
391cdf0e10cSrcweir 	//	private member
392cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
393cdf0e10cSrcweir 
394cdf0e10cSrcweir 	private:
395cdf0e10cSrcweir 
396cdf0e10cSrcweir         SvtDynMenu  m_aNewMenu              ;
397cdf0e10cSrcweir         SvtDynMenu  m_aWizardMenu           ;
398cdf0e10cSrcweir         SvtDynMenu  m_aHelpBookmarksMenu    ;
399cdf0e10cSrcweir };
400cdf0e10cSrcweir 
401cdf0e10cSrcweir //_________________________________________________________________________________________________________________
402cdf0e10cSrcweir //	definitions
403cdf0e10cSrcweir //_________________________________________________________________________________________________________________
404cdf0e10cSrcweir 
405cdf0e10cSrcweir //*****************************************************************************************************************
406cdf0e10cSrcweir //	constructor
407cdf0e10cSrcweir //*****************************************************************************************************************
SvtDynamicMenuOptions_Impl()408cdf0e10cSrcweir SvtDynamicMenuOptions_Impl::SvtDynamicMenuOptions_Impl()
409cdf0e10cSrcweir 	// Init baseclasses first
410cdf0e10cSrcweir     :   ConfigItem( ROOTNODE_MENUS )
411cdf0e10cSrcweir 	// Init member then...
412cdf0e10cSrcweir {
413cdf0e10cSrcweir     // Get names and values of all accessable menu entries and fill internal structures.
414cdf0e10cSrcweir 	// See impl_GetPropertyNames() for further informations.
415cdf0e10cSrcweir     sal_uInt32              nNewCount           = 0;
416cdf0e10cSrcweir     sal_uInt32              nWizardCount        = 0;
417cdf0e10cSrcweir     sal_uInt32              nHelpBookmarksCount = 0;
418cdf0e10cSrcweir     Sequence< OUString >    lNames              = impl_GetPropertyNames ( nNewCount           ,
419cdf0e10cSrcweir                                                                           nWizardCount        ,
420cdf0e10cSrcweir                                                                           nHelpBookmarksCount );
421cdf0e10cSrcweir     Sequence< Any >         lValues             = GetProperties         ( lNames              );
422cdf0e10cSrcweir 
423cdf0e10cSrcweir 	// Safe impossible cases.
424cdf0e10cSrcweir 	// We need values from ALL configuration keys.
425cdf0e10cSrcweir 	// Follow assignment use order of values in relation to our list of key names!
426cdf0e10cSrcweir     DBG_ASSERT( !(lNames.getLength()!=lValues.getLength()), "SvtDynamicMenuOptions_Impl::SvtDynamicMenuOptions_Impl()\nI miss some values of configuration keys!\n" );
427cdf0e10cSrcweir 
428cdf0e10cSrcweir 	// Copy values from list in right order to ouer internal member.
429cdf0e10cSrcweir 	// Attention: List for names and values have an internal construction pattern!
430cdf0e10cSrcweir     //
431cdf0e10cSrcweir     // first "New" menu ...
432cdf0e10cSrcweir     //      Name                            Value
433cdf0e10cSrcweir     //      /New/1/URL                      "private:factory/swriter"
434cdf0e10cSrcweir     //      /New/1/Title                    "Neues Writer Dokument"
435cdf0e10cSrcweir     //      /New/1/ImageIdentifier          "icon_writer"
436cdf0e10cSrcweir     //      /New/1/TargetName               "_blank"
437cdf0e10cSrcweir     //
438cdf0e10cSrcweir     //      /New/2/URL                      "private:factory/scalc"
439cdf0e10cSrcweir     //      /New/2/Title                    "Neues Calc Dokument"
440cdf0e10cSrcweir     //      /New/2/ImageIdentifier          "icon_calc"
441cdf0e10cSrcweir     //      /New/2/TargetName               "_blank"
442cdf0e10cSrcweir     //
443cdf0e10cSrcweir     // second "Wizard" menu ...
444cdf0e10cSrcweir     //      /Wizard/1/URL                   "file://b"
445cdf0e10cSrcweir     //      /Wizard/1/Title                 "MalWas"
446cdf0e10cSrcweir     //      /Wizard/1/ImageIdentifier       "icon_?"
447cdf0e10cSrcweir     //      /Wizard/1/TargetName            "_self"
448cdf0e10cSrcweir     //
449cdf0e10cSrcweir     //      ... and so on ...
450cdf0e10cSrcweir 
451cdf0e10cSrcweir     sal_uInt32  nItem     = 0 ;
452cdf0e10cSrcweir     sal_uInt32  nPosition = 0 ;
453cdf0e10cSrcweir     OUString    sName         ;
454cdf0e10cSrcweir 
455cdf0e10cSrcweir     // We must use these one instance object(!) to get information about installed modules.
456cdf0e10cSrcweir     // These information are used to filter menu entries wich need not installed modules ...
457cdf0e10cSrcweir     // Such entries shouldnt be available then!
458cdf0e10cSrcweir     // see impl_IsEntrySupported() too
459cdf0e10cSrcweir     SvtModuleOptions aModuleOptions;
460cdf0e10cSrcweir 
461cdf0e10cSrcweir     // Get names/values for new menu.
462cdf0e10cSrcweir 	// 4 subkeys for every item!
463cdf0e10cSrcweir     for( nItem=0; nItem<nNewCount; ++nItem )
464cdf0e10cSrcweir 	{
465cdf0e10cSrcweir         SvtDynMenuEntry   aItem                       ;
466cdf0e10cSrcweir         lValues[nPosition] >>= aItem.sURL             ;
467cdf0e10cSrcweir 		++nPosition;
468cdf0e10cSrcweir         lValues[nPosition] >>= aItem.sTitle           ;
469cdf0e10cSrcweir 		++nPosition;
470cdf0e10cSrcweir         lValues[nPosition] >>= aItem.sImageIdentifier ;
471cdf0e10cSrcweir 		++nPosition;
472cdf0e10cSrcweir         lValues[nPosition] >>= aItem.sTargetName      ;
473cdf0e10cSrcweir 		++nPosition;
474cdf0e10cSrcweir         m_aNewMenu.AppendSetupEntry( aItem );
475cdf0e10cSrcweir 	}
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 	// Attention: Don't reset nPosition here!
478cdf0e10cSrcweir 
479cdf0e10cSrcweir     // Get names/values for wizard menu.
480cdf0e10cSrcweir 	// 4 subkeys for every item!
481cdf0e10cSrcweir     for( nItem=0; nItem<nWizardCount; ++nItem )
482cdf0e10cSrcweir 	{
483cdf0e10cSrcweir         SvtDynMenuEntry   aItem                       ;
484cdf0e10cSrcweir         lValues[nPosition] >>= aItem.sURL             ;
485cdf0e10cSrcweir 		++nPosition;
486cdf0e10cSrcweir         lValues[nPosition] >>= aItem.sTitle           ;
487cdf0e10cSrcweir 		++nPosition;
488cdf0e10cSrcweir         lValues[nPosition] >>= aItem.sImageIdentifier ;
489cdf0e10cSrcweir 		++nPosition;
490cdf0e10cSrcweir         lValues[nPosition] >>= aItem.sTargetName      ;
491cdf0e10cSrcweir 		++nPosition;
492cdf0e10cSrcweir         m_aWizardMenu.AppendSetupEntry( aItem );
493cdf0e10cSrcweir 	}
494cdf0e10cSrcweir 
495cdf0e10cSrcweir 	// Attention: Don't reset nPosition here!
496cdf0e10cSrcweir 
497cdf0e10cSrcweir 	// Get names/values for wizard menu.
498cdf0e10cSrcweir 	// 4 subkeys for every item!
499cdf0e10cSrcweir     for( nItem=0; nItem<nHelpBookmarksCount; ++nItem )
500cdf0e10cSrcweir 	{
501cdf0e10cSrcweir         SvtDynMenuEntry   aItem                       ;
502cdf0e10cSrcweir         lValues[nPosition] >>= aItem.sURL             ;
503cdf0e10cSrcweir 		++nPosition;
504cdf0e10cSrcweir         lValues[nPosition] >>= aItem.sTitle           ;
505cdf0e10cSrcweir 		++nPosition;
506cdf0e10cSrcweir         lValues[nPosition] >>= aItem.sImageIdentifier ;
507cdf0e10cSrcweir 		++nPosition;
508cdf0e10cSrcweir         lValues[nPosition] >>= aItem.sTargetName      ;
509cdf0e10cSrcweir 		++nPosition;
510cdf0e10cSrcweir         m_aHelpBookmarksMenu.AppendSetupEntry( aItem );
511cdf0e10cSrcweir 	}
512cdf0e10cSrcweir 
513cdf0e10cSrcweir /*TODO: Not used in the moment! see Notify() ...
514cdf0e10cSrcweir 	// Enable notification mechanism of ouer baseclass.
515cdf0e10cSrcweir 	// We need it to get information about changes outside these class on ouer used configuration keys!
516cdf0e10cSrcweir     EnableNotification( lNames );
517cdf0e10cSrcweir */
518cdf0e10cSrcweir }
519cdf0e10cSrcweir 
520cdf0e10cSrcweir //*****************************************************************************************************************
521cdf0e10cSrcweir //	destructor
522cdf0e10cSrcweir //*****************************************************************************************************************
~SvtDynamicMenuOptions_Impl()523cdf0e10cSrcweir SvtDynamicMenuOptions_Impl::~SvtDynamicMenuOptions_Impl()
524cdf0e10cSrcweir {
525cdf0e10cSrcweir 	// We must save our current values .. if user forget it!
526cdf0e10cSrcweir 	if( IsModified() == sal_True )
527cdf0e10cSrcweir 	{
528cdf0e10cSrcweir 		Commit();
529cdf0e10cSrcweir 	}
530cdf0e10cSrcweir }
531cdf0e10cSrcweir 
532cdf0e10cSrcweir //*****************************************************************************************************************
533cdf0e10cSrcweir //	public method
534cdf0e10cSrcweir //*****************************************************************************************************************
Notify(const Sequence<OUString> &)535cdf0e10cSrcweir void SvtDynamicMenuOptions_Impl::Notify( const Sequence< OUString >& )
536cdf0e10cSrcweir {
537cdf0e10cSrcweir     DBG_ASSERT( sal_False, "SvtDynamicMenuOptions_Impl::Notify()\nNot implemented yet! I don't know how I can handle a dynamical list of unknown properties ...\n" );
538cdf0e10cSrcweir }
539cdf0e10cSrcweir 
540cdf0e10cSrcweir //*****************************************************************************************************************
541cdf0e10cSrcweir //	public method
542cdf0e10cSrcweir //*****************************************************************************************************************
Commit()543cdf0e10cSrcweir void SvtDynamicMenuOptions_Impl::Commit()
544cdf0e10cSrcweir {
545cdf0e10cSrcweir     DBG_ERROR( "SvtDynamicMenuOptions_Impl::Commit()\nNot implemented yet!\n" );
546cdf0e10cSrcweir     /*
547cdf0e10cSrcweir     // Write all properties!
548cdf0e10cSrcweir     // Delete complete sets first.
549cdf0e10cSrcweir     ClearNodeSet( SETNODE_NEWMENU    );
550cdf0e10cSrcweir     ClearNodeSet( SETNODE_WIZARDMENU );
551cdf0e10cSrcweir     ClearNodeSet( SETNODE_HELPBOOKMARKS );
552cdf0e10cSrcweir 
553cdf0e10cSrcweir     MenuEntry                    aItem                           ;
554cdf0e10cSrcweir     OUString                    sNode                           ;
555cdf0e10cSrcweir     Sequence< PropertyValue >   lPropertyValues( PROPERTYCOUNT );
556cdf0e10cSrcweir     sal_uInt32                  nItem          = 0              ;
557cdf0e10cSrcweir 
558cdf0e10cSrcweir     // Copy "new" menu entries to save-list!
559cdf0e10cSrcweir     sal_uInt32 nNewCount = m_aNewMenu.size();
560cdf0e10cSrcweir     for( nItem=0; nItem<nNewCount; ++nItem )
561cdf0e10cSrcweir 	{
562cdf0e10cSrcweir         aItem = m_aNewMenu[nItem];
563cdf0e10cSrcweir         // Format:  "New/1/URL"
564cdf0e10cSrcweir         //          "New/1/Title"
565cdf0e10cSrcweir         //          ...
566cdf0e10cSrcweir         sNode = SETNODE_NEWMENU + PATHDELIMITER + PATHPREFIX + OUString::valueOf( (sal_Int32)nItem ) + PATHDELIMITER;
567cdf0e10cSrcweir 
568cdf0e10cSrcweir         lPropertyValues[OFFSET_URL             ].Name  =   sNode + PROPERTYNAME_URL             ;
569cdf0e10cSrcweir         lPropertyValues[OFFSET_TITLE           ].Name  =   sNode + PROPERTYNAME_TITLE           ;
570cdf0e10cSrcweir         lPropertyValues[OFFSET_IMAGEIDENTIFIER ].Name  =   sNode + PROPERTYNAME_IMAGEIDENTIFIER ;
571cdf0e10cSrcweir         lPropertyValues[OFFSET_TARGETNAME      ].Name  =   sNode + PROPERTYNAME_TARGETNAME      ;
572cdf0e10cSrcweir 
573cdf0e10cSrcweir         lPropertyValues[OFFSET_URL             ].Value <<= aItem.sURL                           ;
574cdf0e10cSrcweir         lPropertyValues[OFFSET_TITLE           ].Value <<= aItem.sTitle                         ;
575cdf0e10cSrcweir         lPropertyValues[OFFSET_IMAGEIDENTIFIER ].Value <<= aItem.sImageIdentifier               ;
576cdf0e10cSrcweir         lPropertyValues[OFFSET_TARGETNAME      ].Value <<= aItem.sTargetName                    ;
577cdf0e10cSrcweir 
578cdf0e10cSrcweir         SetSetProperties( SETNODE_NEWMENU, lPropertyValues );
579cdf0e10cSrcweir 	}
580cdf0e10cSrcweir 
581cdf0e10cSrcweir     // Copy "wizard" menu entries to save-list!
582cdf0e10cSrcweir     sal_uInt32 nWizardCount = m_aWizardMenu.size();
583cdf0e10cSrcweir     for( nItem=0; nItem<nWizardCount; ++nItem )
584cdf0e10cSrcweir 	{
585cdf0e10cSrcweir         aItem = m_aWizardMenu[nItem];
586cdf0e10cSrcweir         // Format:  "Wizard/1/URL"
587cdf0e10cSrcweir         //          "Wizard/1/Title"
588cdf0e10cSrcweir         //          ...
589cdf0e10cSrcweir         sNode = SETNODE_WIZARDMENU + PATHDELIMITER + PATHPREFIX + OUString::valueOf( (sal_Int32)nItem ) + PATHDELIMITER;
590cdf0e10cSrcweir 
591cdf0e10cSrcweir         lPropertyValues[OFFSET_URL             ].Name  =   sNode + PROPERTYNAME_URL             ;
592cdf0e10cSrcweir         lPropertyValues[OFFSET_TITLE           ].Name  =   sNode + PROPERTYNAME_TITLE           ;
593cdf0e10cSrcweir         lPropertyValues[OFFSET_IMAGEIDENTIFIER ].Name  =   sNode + PROPERTYNAME_IMAGEIDENTIFIER ;
594cdf0e10cSrcweir         lPropertyValues[OFFSET_TARGETNAME      ].Name  =   sNode + PROPERTYNAME_TARGETNAME      ;
595cdf0e10cSrcweir 
596cdf0e10cSrcweir         lPropertyValues[OFFSET_URL             ].Value <<= aItem.sURL                           ;
597cdf0e10cSrcweir         lPropertyValues[OFFSET_TITLE           ].Value <<= aItem.sTitle                         ;
598cdf0e10cSrcweir         lPropertyValues[OFFSET_IMAGEIDENTIFIER ].Value <<= aItem.sImageIdentifier               ;
599cdf0e10cSrcweir         lPropertyValues[OFFSET_TARGETNAME      ].Value <<= aItem.sTargetName                    ;
600cdf0e10cSrcweir 
601cdf0e10cSrcweir         SetSetProperties( SETNODE_WIZARDMENU, lPropertyValues );
602cdf0e10cSrcweir 	}
603cdf0e10cSrcweir 
604cdf0e10cSrcweir 	// Copy help bookmarks entries to save-list!
605cdf0e10cSrcweir     sal_uInt32 nHelpBookmarksCount = m_aHelpBookmarksMenu.size();
606cdf0e10cSrcweir     for( nItem=0; nItem<nHelpBookmarksCount; ++nItem )
607cdf0e10cSrcweir 	{
608cdf0e10cSrcweir         aItem = m_aHelpBookmarksMenu[nItem];
609cdf0e10cSrcweir         // Format:  "HelpBookmarks/1/URL"
610cdf0e10cSrcweir         //          "HelpBookmarks/1/Title"
611cdf0e10cSrcweir         //          ...
612cdf0e10cSrcweir         sNode = SETNODE_HELPBOOKMARKS + PATHDELIMITER + PATHPREFIX + OUString::valueOf( (sal_Int32)nItem ) + PATHDELIMITER;
613cdf0e10cSrcweir 
614cdf0e10cSrcweir         lPropertyValues[OFFSET_URL             ].Name  =   sNode + PROPERTYNAME_URL             ;
615cdf0e10cSrcweir         lPropertyValues[OFFSET_TITLE           ].Name  =   sNode + PROPERTYNAME_TITLE           ;
616cdf0e10cSrcweir         lPropertyValues[OFFSET_IMAGEIDENTIFIER ].Name  =   sNode + PROPERTYNAME_IMAGEIDENTIFIER ;
617cdf0e10cSrcweir         lPropertyValues[OFFSET_TARGETNAME      ].Name  =   sNode + PROPERTYNAME_TARGETNAME      ;
618cdf0e10cSrcweir 
619cdf0e10cSrcweir         lPropertyValues[OFFSET_URL             ].Value <<= aItem.sURL                           ;
620cdf0e10cSrcweir         lPropertyValues[OFFSET_TITLE           ].Value <<= aItem.sTitle                         ;
621cdf0e10cSrcweir         lPropertyValues[OFFSET_IMAGEIDENTIFIER ].Value <<= aItem.sImageIdentifier               ;
622cdf0e10cSrcweir         lPropertyValues[OFFSET_TARGETNAME      ].Value <<= aItem.sTargetName                    ;
623cdf0e10cSrcweir 
624cdf0e10cSrcweir         SetSetProperties( SETNODE_HELPBOOKMARKS, lPropertyValues );
625cdf0e10cSrcweir 	}
626cdf0e10cSrcweir     */
627cdf0e10cSrcweir }
628cdf0e10cSrcweir 
629cdf0e10cSrcweir //*****************************************************************************************************************
630cdf0e10cSrcweir //	public method
631cdf0e10cSrcweir //*****************************************************************************************************************
Clear(EDynamicMenuType eMenu)632cdf0e10cSrcweir void SvtDynamicMenuOptions_Impl::Clear( EDynamicMenuType eMenu )
633cdf0e10cSrcweir {
634cdf0e10cSrcweir     switch( eMenu )
635cdf0e10cSrcweir 	{
636cdf0e10cSrcweir         case E_NEWMENU      :   {
637cdf0e10cSrcweir                                     m_aNewMenu.Clear();
638cdf0e10cSrcweir                                     SetModified();
639cdf0e10cSrcweir                                 }
640cdf0e10cSrcweir                                 break;
641cdf0e10cSrcweir 
642cdf0e10cSrcweir         case E_WIZARDMENU   :   {
643cdf0e10cSrcweir                                     m_aWizardMenu.Clear();
644cdf0e10cSrcweir                                     SetModified();
645cdf0e10cSrcweir                                 }
646cdf0e10cSrcweir                                 break;
647cdf0e10cSrcweir 
648cdf0e10cSrcweir         case E_HELPBOOKMARKS :  {
649cdf0e10cSrcweir                                     m_aHelpBookmarksMenu.Clear();
650cdf0e10cSrcweir                                     SetModified();
651cdf0e10cSrcweir                                 }
652cdf0e10cSrcweir                                 break;
653cdf0e10cSrcweir 	}
654cdf0e10cSrcweir }
655cdf0e10cSrcweir 
656cdf0e10cSrcweir //*****************************************************************************************************************
657cdf0e10cSrcweir //	public method
658cdf0e10cSrcweir //*****************************************************************************************************************
GetMenu(EDynamicMenuType eMenu) const659cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > SvtDynamicMenuOptions_Impl::GetMenu( EDynamicMenuType eMenu ) const
660cdf0e10cSrcweir {
661cdf0e10cSrcweir     Sequence< Sequence< PropertyValue > > lReturn;
662cdf0e10cSrcweir     switch( eMenu )
663cdf0e10cSrcweir 	{
664cdf0e10cSrcweir         case E_NEWMENU      :   {
665cdf0e10cSrcweir                                     lReturn = m_aNewMenu.GetList();
666cdf0e10cSrcweir                                 }
667cdf0e10cSrcweir                                 break;
668cdf0e10cSrcweir 
669cdf0e10cSrcweir         case E_WIZARDMENU   :   {
670cdf0e10cSrcweir                                     lReturn = m_aWizardMenu.GetList();
671cdf0e10cSrcweir                                 }
672cdf0e10cSrcweir                                 break;
673cdf0e10cSrcweir 
674cdf0e10cSrcweir         case E_HELPBOOKMARKS :  {
675cdf0e10cSrcweir                                     lReturn = m_aHelpBookmarksMenu.GetList();
676cdf0e10cSrcweir                                 }
677cdf0e10cSrcweir                                 break;
678cdf0e10cSrcweir 	}
679cdf0e10cSrcweir     return lReturn;
680cdf0e10cSrcweir }
681cdf0e10cSrcweir 
682cdf0e10cSrcweir //*****************************************************************************************************************
683cdf0e10cSrcweir //	public method
684cdf0e10cSrcweir //*****************************************************************************************************************
AppendItem(EDynamicMenuType eMenu,const OUString & sURL,const OUString & sTitle,const OUString & sImageIdentifier,const OUString & sTargetName)685cdf0e10cSrcweir void SvtDynamicMenuOptions_Impl::AppendItem(            EDynamicMenuType    eMenu           ,
686cdf0e10cSrcweir                                                 const   OUString&           sURL            ,
687cdf0e10cSrcweir                                                 const   OUString&           sTitle          ,
688cdf0e10cSrcweir                                                 const   OUString&           sImageIdentifier,
689cdf0e10cSrcweir                                                 const   OUString&           sTargetName     )
690cdf0e10cSrcweir {
691cdf0e10cSrcweir     SvtDynMenuEntry aItem( sURL, sTitle, sImageIdentifier, sTargetName );
692cdf0e10cSrcweir 
693cdf0e10cSrcweir     switch( eMenu )
694cdf0e10cSrcweir 	{
695cdf0e10cSrcweir         case E_NEWMENU  :   {
696cdf0e10cSrcweir                                 m_aNewMenu.AppendUserEntry( aItem );
697cdf0e10cSrcweir 								SetModified();
698cdf0e10cSrcweir 							}
699cdf0e10cSrcweir 							break;
700cdf0e10cSrcweir 
701cdf0e10cSrcweir         case E_WIZARDMENU   :   {
702cdf0e10cSrcweir                                 m_aWizardMenu.AppendUserEntry( aItem );
703cdf0e10cSrcweir 								SetModified();
704cdf0e10cSrcweir 							}
705cdf0e10cSrcweir 							break;
706cdf0e10cSrcweir 
707cdf0e10cSrcweir         case E_HELPBOOKMARKS :  {
708cdf0e10cSrcweir                                 m_aHelpBookmarksMenu.AppendUserEntry( aItem );
709cdf0e10cSrcweir 								SetModified();
710cdf0e10cSrcweir 							}
711cdf0e10cSrcweir 							break;
712cdf0e10cSrcweir 	}
713cdf0e10cSrcweir }
714cdf0e10cSrcweir 
715cdf0e10cSrcweir //*****************************************************************************************************************
716cdf0e10cSrcweir //	private method
717cdf0e10cSrcweir //*****************************************************************************************************************
impl_GetPropertyNames(sal_uInt32 & nNewCount,sal_uInt32 & nWizardCount,sal_uInt32 & nHelpBookmarksCount)718cdf0e10cSrcweir Sequence< OUString > SvtDynamicMenuOptions_Impl::impl_GetPropertyNames( sal_uInt32& nNewCount, sal_uInt32& nWizardCount, sal_uInt32& nHelpBookmarksCount )
719cdf0e10cSrcweir {
720cdf0e10cSrcweir 	// First get ALL names of current existing list items in configuration!
721cdf0e10cSrcweir     Sequence< OUString > lNewItems           = GetNodeNames( SETNODE_NEWMENU       );
722cdf0e10cSrcweir     Sequence< OUString > lWizardItems        = GetNodeNames( SETNODE_WIZARDMENU    );
723cdf0e10cSrcweir     Sequence< OUString > lHelpBookmarksItems = GetNodeNames( SETNODE_HELPBOOKMARKS );
724cdf0e10cSrcweir 
725cdf0e10cSrcweir 	// Get information about list counts ...
726cdf0e10cSrcweir     nNewCount           = lNewItems.getLength          ();
727cdf0e10cSrcweir     nWizardCount        = lWizardItems.getLength       ();
728cdf0e10cSrcweir     nHelpBookmarksCount = lHelpBookmarksItems.getLength();
729cdf0e10cSrcweir 
730cdf0e10cSrcweir     // Sort and expand all three list to result list ...
731cdf0e10cSrcweir     Sequence< OUString > lProperties;
732cdf0e10cSrcweir     impl_SortAndExpandPropertyNames( lNewItems          , lProperties, SETNODE_NEWMENU       );
733cdf0e10cSrcweir     impl_SortAndExpandPropertyNames( lWizardItems       , lProperties, SETNODE_WIZARDMENU    );
734cdf0e10cSrcweir     impl_SortAndExpandPropertyNames( lHelpBookmarksItems, lProperties, SETNODE_HELPBOOKMARKS );
735cdf0e10cSrcweir 
736cdf0e10cSrcweir 	// Return result.
737cdf0e10cSrcweir     return lProperties;
738cdf0e10cSrcweir }
739cdf0e10cSrcweir 
740cdf0e10cSrcweir //*****************************************************************************************************************
741cdf0e10cSrcweir //  private helper
742cdf0e10cSrcweir //*****************************************************************************************************************
743cdf0e10cSrcweir class CountWithPrefixSort
744cdf0e10cSrcweir {
745cdf0e10cSrcweir     public:
operator ()(const OUString & s1,const OUString & s2) const746cdf0e10cSrcweir         int operator() ( const OUString& s1 ,
747cdf0e10cSrcweir                          const OUString& s2 ) const
748cdf0e10cSrcweir         {
749cdf0e10cSrcweir             // Get order numbers from entry name without prefix.
750cdf0e10cSrcweir             // e.g. "m10" => 10
751cdf0e10cSrcweir             //      "m5"  => 5
752cdf0e10cSrcweir             sal_Int32 n1 = s1.copy( 1, s1.getLength()-1 ).toInt32();
753cdf0e10cSrcweir             sal_Int32 n2 = s2.copy( 1, s2.getLength()-1 ).toInt32();
754cdf0e10cSrcweir             // MUST be in [0,1] ... because it's a difference between
755cdf0e10cSrcweir             // insert-positions of given entries in sorted list!
756cdf0e10cSrcweir             return( n1<n2 );
757cdf0e10cSrcweir         }
758cdf0e10cSrcweir };
759cdf0e10cSrcweir 
760cdf0e10cSrcweir class SelectByPrefix
761cdf0e10cSrcweir {
762cdf0e10cSrcweir     public:
operator ()(const OUString & s) const763cdf0e10cSrcweir         bool operator() ( const OUString& s ) const
764cdf0e10cSrcweir         {
765cdf0e10cSrcweir             // Prefer setup written entries by check first letter of given string. It must be a "s".
766cdf0e10cSrcweir             return( s.indexOf( PATHPREFIX_SETUP ) == 0 );
767cdf0e10cSrcweir         }
768cdf0e10cSrcweir };
769cdf0e10cSrcweir 
770cdf0e10cSrcweir //*****************************************************************************************************************
771cdf0e10cSrcweir //	private method
772cdf0e10cSrcweir //*****************************************************************************************************************
impl_SortAndExpandPropertyNames(const Sequence<OUString> & lSource,Sequence<OUString> & lDestination,const OUString & sSetNode)773cdf0e10cSrcweir void SvtDynamicMenuOptions_Impl::impl_SortAndExpandPropertyNames( const Sequence< OUString >& lSource      ,
774cdf0e10cSrcweir                                                                         Sequence< OUString >& lDestination ,
775cdf0e10cSrcweir                                                                   const OUString&             sSetNode     )
776cdf0e10cSrcweir {
777cdf0e10cSrcweir     OUString            sFixPath                                    ;
778cdf0e10cSrcweir     vector< OUString >  lTemp                                       ;
779cdf0e10cSrcweir     sal_Int32           nSourceCount     = lSource.getLength()      ;
780cdf0e10cSrcweir     sal_Int32           nDestinationStep = lDestination.getLength() ; // start on end of current list ...!
781cdf0e10cSrcweir 
782cdf0e10cSrcweir     lDestination.realloc( (nSourceCount*PROPERTYCOUNT)+nDestinationStep ); // get enough memory for copy operations after nDestination ...
783cdf0e10cSrcweir 
784cdf0e10cSrcweir     // Copy all items to temp. vector to use fast sort operations :-)
785cdf0e10cSrcweir     for( sal_Int32 nSourceStep=0; nSourceStep<nSourceCount; ++nSourceStep )
786cdf0e10cSrcweir         lTemp.push_back( lSource[nSourceStep] );
787cdf0e10cSrcweir 
788cdf0e10cSrcweir     // Sort all entries by number ...
789cdf0e10cSrcweir     stable_sort( lTemp.begin(), lTemp.end(), CountWithPrefixSort() );
790cdf0e10cSrcweir     // and split into setup & user written entries!
791cdf0e10cSrcweir     stable_partition( lTemp.begin(), lTemp.end(), SelectByPrefix() );
792cdf0e10cSrcweir 
793cdf0e10cSrcweir     // Copy sorted entries to destination and expand every item with
794cdf0e10cSrcweir     // 4 supported sub properties.
795cdf0e10cSrcweir     for( vector< OUString >::const_iterator pItem =lTemp.begin() ;
796cdf0e10cSrcweir                                             pItem!=lTemp.end()   ;
797cdf0e10cSrcweir                                             ++pItem              )
798cdf0e10cSrcweir     {
799cdf0e10cSrcweir         sFixPath  = sSetNode       ;
800cdf0e10cSrcweir         sFixPath += PATHDELIMITER  ;
801cdf0e10cSrcweir         sFixPath += *pItem         ;
802cdf0e10cSrcweir         sFixPath += PATHDELIMITER  ;
803cdf0e10cSrcweir 
804cdf0e10cSrcweir         lDestination[nDestinationStep]  = sFixPath                      ;
805cdf0e10cSrcweir         lDestination[nDestinationStep] += PROPERTYNAME_URL              ;
806cdf0e10cSrcweir         ++nDestinationStep;
807cdf0e10cSrcweir         lDestination[nDestinationStep]  = sFixPath                      ;
808cdf0e10cSrcweir         lDestination[nDestinationStep] += PROPERTYNAME_TITLE            ;
809cdf0e10cSrcweir         ++nDestinationStep;
810cdf0e10cSrcweir         lDestination[nDestinationStep]  = sFixPath                      ;
811cdf0e10cSrcweir         lDestination[nDestinationStep] += PROPERTYNAME_IMAGEIDENTIFIER  ;
812cdf0e10cSrcweir         ++nDestinationStep;
813cdf0e10cSrcweir         lDestination[nDestinationStep]  = sFixPath                      ;
814cdf0e10cSrcweir         lDestination[nDestinationStep] += PROPERTYNAME_TARGETNAME       ;
815cdf0e10cSrcweir         ++nDestinationStep;
816cdf0e10cSrcweir     }
817cdf0e10cSrcweir }
818cdf0e10cSrcweir 
819cdf0e10cSrcweir //*****************************************************************************************************************
820cdf0e10cSrcweir //	initialize static member
821cdf0e10cSrcweir //	DON'T DO IT IN YOUR HEADER!
822cdf0e10cSrcweir //	see definition for further informations
823cdf0e10cSrcweir //*****************************************************************************************************************
824cdf0e10cSrcweir SvtDynamicMenuOptions_Impl*     SvtDynamicMenuOptions::m_pDataContainer = NULL  ;
825cdf0e10cSrcweir sal_Int32                       SvtDynamicMenuOptions::m_nRefCount      = 0     ;
826cdf0e10cSrcweir 
827cdf0e10cSrcweir //*****************************************************************************************************************
828cdf0e10cSrcweir //	constructor
829cdf0e10cSrcweir //*****************************************************************************************************************
SvtDynamicMenuOptions()830cdf0e10cSrcweir SvtDynamicMenuOptions::SvtDynamicMenuOptions()
831cdf0e10cSrcweir {
832cdf0e10cSrcweir     // Global access, must be guarded (multithreading!).
833cdf0e10cSrcweir     MutexGuard aGuard( GetOwnStaticMutex() );
834cdf0e10cSrcweir 	// Increase ouer refcount ...
835cdf0e10cSrcweir 	++m_nRefCount;
836cdf0e10cSrcweir 	// ... and initialize ouer data container only if it not already exist!
837cdf0e10cSrcweir     if( m_pDataContainer == NULL )
838cdf0e10cSrcweir 	{
839cdf0e10cSrcweir         m_pDataContainer = new SvtDynamicMenuOptions_Impl;
840cdf0e10cSrcweir         ItemHolder1::holdConfigItem(E_DYNAMICMENUOPTIONS);
841cdf0e10cSrcweir 	}
842cdf0e10cSrcweir }
843cdf0e10cSrcweir 
844cdf0e10cSrcweir //*****************************************************************************************************************
845cdf0e10cSrcweir //	destructor
846cdf0e10cSrcweir //*****************************************************************************************************************
~SvtDynamicMenuOptions()847cdf0e10cSrcweir SvtDynamicMenuOptions::~SvtDynamicMenuOptions()
848cdf0e10cSrcweir {
849cdf0e10cSrcweir     // Global access, must be guarded (multithreading!)
850cdf0e10cSrcweir     MutexGuard aGuard( GetOwnStaticMutex() );
851cdf0e10cSrcweir 	// Decrease ouer refcount.
852cdf0e10cSrcweir 	--m_nRefCount;
853cdf0e10cSrcweir 	// If last instance was deleted ...
854cdf0e10cSrcweir 	// we must destroy ouer static data container!
855cdf0e10cSrcweir     if( m_nRefCount <= 0 )
856cdf0e10cSrcweir 	{
857cdf0e10cSrcweir 		delete m_pDataContainer;
858cdf0e10cSrcweir 		m_pDataContainer = NULL;
859cdf0e10cSrcweir 	}
860cdf0e10cSrcweir }
861cdf0e10cSrcweir 
862cdf0e10cSrcweir //*****************************************************************************************************************
863cdf0e10cSrcweir //	public method
864cdf0e10cSrcweir //*****************************************************************************************************************
Clear(EDynamicMenuType eMenu)865cdf0e10cSrcweir void SvtDynamicMenuOptions::Clear( EDynamicMenuType eMenu )
866cdf0e10cSrcweir {
867cdf0e10cSrcweir     MutexGuard aGuard( GetOwnStaticMutex() );
868cdf0e10cSrcweir     m_pDataContainer->Clear( eMenu );
869cdf0e10cSrcweir }
870cdf0e10cSrcweir 
871cdf0e10cSrcweir //*****************************************************************************************************************
872cdf0e10cSrcweir //	public method
873cdf0e10cSrcweir //*****************************************************************************************************************
GetMenu(EDynamicMenuType eMenu) const874cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > SvtDynamicMenuOptions::GetMenu( EDynamicMenuType eMenu ) const
875cdf0e10cSrcweir {
876cdf0e10cSrcweir     MutexGuard aGuard( GetOwnStaticMutex() );
877cdf0e10cSrcweir     return m_pDataContainer->GetMenu( eMenu );
878cdf0e10cSrcweir }
879cdf0e10cSrcweir 
880cdf0e10cSrcweir //*****************************************************************************************************************
881cdf0e10cSrcweir //	public method
882cdf0e10cSrcweir //*****************************************************************************************************************
AppendItem(EDynamicMenuType eMenu,const OUString & sURL,const OUString & sTitle,const OUString & sImageIdentifier,const OUString & sTargetName)883cdf0e10cSrcweir void SvtDynamicMenuOptions::AppendItem(         EDynamicMenuType    eMenu           ,
884cdf0e10cSrcweir                                         const   OUString&           sURL            ,
885cdf0e10cSrcweir                                         const   OUString&           sTitle          ,
886cdf0e10cSrcweir                                         const   OUString&           sImageIdentifier,
887cdf0e10cSrcweir                                         const   OUString&           sTargetName     )
888cdf0e10cSrcweir {
889cdf0e10cSrcweir     MutexGuard aGuard( GetOwnStaticMutex() );
890cdf0e10cSrcweir     m_pDataContainer->AppendItem( eMenu, sURL, sTitle, sImageIdentifier, sTargetName );
891cdf0e10cSrcweir }
892cdf0e10cSrcweir 
893cdf0e10cSrcweir //*****************************************************************************************************************
894cdf0e10cSrcweir //	private method
895cdf0e10cSrcweir //*****************************************************************************************************************
GetOwnStaticMutex()896cdf0e10cSrcweir Mutex& SvtDynamicMenuOptions::GetOwnStaticMutex()
897cdf0e10cSrcweir {
898cdf0e10cSrcweir 	// Initialize static mutex only for one time!
899cdf0e10cSrcweir     static Mutex* pMutex = NULL;
900cdf0e10cSrcweir 	// If these method first called (Mutex not already exist!) ...
901cdf0e10cSrcweir     if( pMutex == NULL )
902cdf0e10cSrcweir     {
903cdf0e10cSrcweir 		// ... we must create a new one. Protect follow code with the global mutex -
904cdf0e10cSrcweir 		// It must be - we create a static variable!
905cdf0e10cSrcweir         MutexGuard aGuard( Mutex::getGlobalMutex() );
906cdf0e10cSrcweir 		// We must check our pointer again - because it can be that another instance of ouer class will be fastr then these!
907cdf0e10cSrcweir         if( pMutex == NULL )
908cdf0e10cSrcweir         {
909cdf0e10cSrcweir 			// Create the new mutex and set it for return on static variable.
910cdf0e10cSrcweir             static Mutex aMutex;
911cdf0e10cSrcweir             pMutex = &aMutex;
912cdf0e10cSrcweir         }
913cdf0e10cSrcweir     }
914cdf0e10cSrcweir 	// Return new created or already existing mutex object.
915cdf0e10cSrcweir     return *pMutex;
916cdf0e10cSrcweir }
917