merge the formfield patch from ooo-build
[ooovba.git] / framework / source / inc / accelerators / presethandler.hxx
blob4b226b106b9ddc6e7f524a74ec3059d04a9a1912
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: presethandler.hxx,v $
10 * $Revision: 1.9.82.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __FRAMEWORK_ACCELERATORS_PRESETHANDLER_HXX_
32 #define __FRAMEWORK_ACCELERATORS_PRESETHANDLER_HXX_
34 //__________________________________________
35 // own includes
37 #include <accelerators/storageholder.hxx>
38 #include <threadhelp/threadhelpbase.hxx>
39 #include <general.h>
40 #include <stdtypes.h>
42 //__________________________________________
43 // interface includes
45 #ifndef __COM_SUN_STAR_EMBED_XSTORAGE_HPP_
46 #include <com/sun/star/embed/XStorage.hpp>
47 #endif
49 #ifndef __COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 #endif
53 //__________________________________________
54 // other includes
55 #include <comphelper/processfactory.hxx>
56 #include <salhelper/singletonref.hxx>
57 #include <comphelper/locale.hxx>
59 //__________________________________________
60 // definition
62 namespace framework
65 //__________________________________________
66 /**
67 TODO document me
69 <layer>/global/<resourcetype>/<preset>.xml
70 <layer>/modules/<moduleid>/<resourcetype>/<preset>.xml
72 RESOURCETYPE PRESET TARGET
73 (share) (user)
74 "accelerator" "default" "current"
75 "word"
76 "excel"
78 "menubar" "default" "menubar"
81 class PresetHandler : private ThreadHelpBase // attention! Must be the first base class to guarentee right initialize lock ...
83 //-------------------------------------------
84 // const
86 public:
88 static ::rtl::OUString PRESET_DEFAULT();
89 static ::rtl::OUString TARGET_CURRENT();
91 static ::rtl::OUString RESOURCETYPE_MENUBAR();
92 static ::rtl::OUString RESOURCETYPE_TOOLBAR();
93 static ::rtl::OUString RESOURCETYPE_ACCELERATOR();
94 static ::rtl::OUString RESOURCETYPE_STATUSBAR();
96 //-------------------------------------------
97 // types
99 public:
101 //---------------------------------------
102 /** @short this handler can provide different
103 types of configuration.
105 @descr Means: a global or a module dependend
106 or ... configuration.
108 enum EConfigType
110 E_GLOBAL,
111 E_MODULES,
112 E_DOCUMENT
115 private:
117 //---------------------------------------
118 /** @short because a concurrent access to the same storage from different implementations
119 isnt supported, we have to share it with others.
121 @descr This struct makes it possible to use any shared storage
122 in combination with a SingletonRef<> template ...
124 Attention: Because these struct is shared it must be
125 used within a synchronized section. Thats why this struct
126 uses a base class ThreadHelpBase and can be locked
127 from outside doing so!
129 struct TSharedStorages : public ThreadHelpBase
131 public:
133 StorageHolder m_lStoragesShare;
134 StorageHolder m_lStoragesUser;
136 TSharedStorages()
137 : m_lStoragesShare(::comphelper::getProcessServiceFactory())
138 , m_lStoragesUser (::comphelper::getProcessServiceFactory())
141 virtual ~TSharedStorages() {};
144 //-------------------------------------------
145 // member
147 private:
149 //---------------------------------------
150 /** @short can be used to create on needed uno resources. */
151 css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
153 //---------------------------------------
154 /** @short knows the type of provided configuration.
156 @descr e.g. global, modules, ...
158 EConfigType m_eConfigType;
160 //---------------------------------------
161 /** @short specify the type of resource, which configuration sets
162 must be provided here.
164 @descr e.g. menubars, toolbars, accelerators
166 ::rtl::OUString m_sResourceType;
168 //---------------------------------------
169 /** @short specify the application module for a module
170 dependend configuration.
172 @descr Will be used only, if m_sResourceType is set to
173 "module". Further it must be a valid module identifier
174 then ...
176 ::rtl::OUString m_sModule;
178 //---------------------------------------
179 /** @short provides access to the:
180 a) shared root storages
181 b) shared "inbetween" storages
182 of the share and user layer. */
183 ::salhelper::SingletonRef< TSharedStorages > m_aSharedStorages;
185 //---------------------------------------
186 /** @short if we run in document mode, we cant use the global root storages!
187 We have to use a special document storage explicitly. */
188 StorageHolder m_lDocumentStorages;
190 //---------------------------------------
191 /** @short holds the folder storage of the share layer alive,
192 where the current configuration set exists.
194 @descr Note: If this preset handler works in document mode
195 this member is meaned relative to the document root ...
196 not to the share layer root!
198 Further is defined, that m_xWorkingStorageUser
199 is equals to m_xWorkingStorageShare then!
201 css::uno::Reference< css::embed::XStorage > m_xWorkingStorageShare;
203 //---------------------------------------
204 /** @short global language-independent storage
206 css::uno::Reference< css::embed::XStorage > m_xWorkingStorageNoLang;
208 //---------------------------------------
209 /** @short holds the folder storage of the user layer alive,
210 where the current configuration set exists.
212 @descr Note: If this preset handler works in document mode
213 this member is meaned relative to the document root ...
214 not to the user layer root!
216 Further is defined, that m_xWorkingStorageUser
217 is equals to m_xWorkingStorageShare then!
219 css::uno::Reference< css::embed::XStorage > m_xWorkingStorageUser;
221 //---------------------------------------
222 /** @short knows the names of all presets inside the current
223 working storage of the share layer. */
224 OUStringList m_lPresets;
226 //---------------------------------------
227 /** @short knows the names of all targets inside the current
228 working storage of the user layer. */
229 OUStringList m_lTargets;
231 //---------------------------------------
232 /** @short its the current office locale and will be used
233 to handle localized presets.
235 @descr Default is "x-notranslate" which disable any
236 localized handling inside this class! */
237 ::comphelper::Locale m_aLocale;
239 //---------------------------------------
240 /** @short knows the relative path from the root. */
241 ::rtl::OUString m_sRelPathShare;
242 ::rtl::OUString m_sRelPathNoLang;
243 ::rtl::OUString m_sRelPathUser;
245 //-------------------------------------------
246 // native interface
248 public:
250 //---------------------------------------
251 /** @short does nothing real.
253 @descr Because this class should be useable in combination
254 with ::salhelper::SingletonRef template this ctor
255 cant have any special parameters!
257 @param xSMGR
258 points to an uno service manager, which is used internaly
259 to create own needed uno resources.
261 PresetHandler(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
263 //---------------------------------------
264 /** @short copy ctor */
265 PresetHandler(const PresetHandler& rCopy);
267 //---------------------------------------
268 /** @short closes all open storages ... if user forgot that .-) */
269 virtual ~PresetHandler();
271 //---------------------------------------
272 /** @short free all currently cache(!) storages. */
273 void forgetCachedStorages();
275 //---------------------------------------
276 /** @short return access to the internaly used and cached root storage.
278 @descr These root storages are the base of all further opened
279 presets and targets. They are provided here only, to support
280 older implementations, which base on them ...
282 getOrCreate...() - What does it mean?
283 Such root storage will be created one times only and
284 cached then internaly till the last instance of such PresetHandler
285 dies.
287 @return com::sun::star::embed::XStorage
288 which represent a root storage.
290 css::uno::Reference< css::embed::XStorage > getOrCreateRootStorageShare();
291 css::uno::Reference< css::embed::XStorage > getOrCreateRootStorageUser();
293 //---------------------------------------
294 /** @short provides access to the current working storages.
296 @descr Working storages are the "lowest" storages, where the
297 preset and target files exists.
299 @return com::sun::star::embed::XStorage
300 which the current working storage.
302 css::uno::Reference< css::embed::XStorage > getWorkingStorageShare();
303 css::uno::Reference< css::embed::XStorage > getWorkingStorageUser();
305 //---------------------------------------
306 /** @short check if there is a parent storage well known for
307 the specified child storage and return it.
309 @param xChild
310 the child storage where a paranet storage should be searched for.
312 @return com::sun::star::embed::XStorage
313 A valid storage if a paranet exists. NULL otherwise.
315 css::uno::Reference< css::embed::XStorage > getParentStorageShare(const css::uno::Reference< css::embed::XStorage >& xChild);
316 css::uno::Reference< css::embed::XStorage > getParentStorageUser (const css::uno::Reference< css::embed::XStorage >& xChild);
318 //---------------------------------------
319 /** @short free all internal structures and let this handler
320 work on a new type of configuration sets.
322 @param eConfigType
323 differ between global or module dependend configuration.
325 @param sResourceType
326 differ between menubar/toolbar/accelerator/... configuration.
328 @param sModule
329 if sResourceType is set to a module dependend configuration,
330 it address the current application module.
332 @param xDocumentRoot
333 if sResourceType is set to E_DOCUMENT, this value points to the
334 root storage inside the document, where we can save our
335 configuration files. Note: Thats not the real root of the document ...
336 its only a sub storage. But we interpret it as our root storage.
338 @param aLocale
339 in case this configuration supports localized entries,
340 the current locale must be set.
342 Localzation will be represented as directory structure
343 of provided presets. Means: you call us with a preset name "default";
344 and we use e.g. "/en-US/default.xml" internaly.
346 If no localization exists for this preset set, this class
347 will work in default mode - means "no locale" - automaticly.
348 e.g. "/default.xml"
350 @throw com::sun::star::uno::RuntimeException(!)
351 if the specified resource couldn't be located.
353 void connectToResource( EConfigType eConfigType ,
354 const ::rtl::OUString& sResourceType ,
355 const ::rtl::OUString& sModule ,
356 const css::uno::Reference< css::embed::XStorage >& xDocumentRoot ,
357 const ::comphelper::Locale& aLocale = ::comphelper::Locale(::comphelper::Locale::X_NOTRANSLATE()));
359 //---------------------------------------
360 /** @short try to copy the specified preset from the share
361 layer to the user layer and establish it as the
362 specified target.
364 @descr Means: copy share/.../<preset>.xml user/.../<target>.xml
365 Note: The target will be overwritten completly or
366 created as new by this operation!
368 @param sPreset
369 the ALIAS name of an existing preset.
371 @param sTarget
372 the ALIAS name of the target.
374 @throw com::sun::star::container::NoSuchElementException
375 if the specified preset does not exists.
377 @throw com::sun::star::io::IOException
378 if copying failed.
380 void copyPresetToTarget(const ::rtl::OUString& sPreset,
381 const ::rtl::OUString& sTarget);
383 //---------------------------------------
384 /** @short open the specified preset as stream object
385 and return it.
387 @descr Note: Because presets resist inside the share
388 layer, they will be opened readonly everytimes.
390 @param sPreset
391 the ALIAS name of an existing preset.
393 @param bNoLangGlobal
394 access the global language-independent storage instead of the preset storage
396 @return The opened preset stream ... or NULL if the preset does not exists.
398 css::uno::Reference< css::io::XStream > openPreset(const ::rtl::OUString& sPreset,
399 sal_Bool bUseNoLangGlobal = sal_False);
401 //---------------------------------------
402 /** @short open the specified target as stream object
403 and return it.
405 @descr Note: Targets resist inside the user
406 layer. Normaly they are opened in read/write mode.
407 But it will be opened readonly automaticly if that isnt possible
408 (may be the file is write protected on the system ...).
410 @param sTarget
411 the ALIAS name of the target.
413 @param bCreateIfMissing
414 create target file, if it does not still exists.
415 Note: That does not means reseting of an existing file!
417 @return The opened target stream ... or NULL if the target does not exists
418 or couldnt be created as new one.
420 css::uno::Reference< css::io::XStream > openTarget(const ::rtl::OUString& sTarget ,
421 sal_Bool bCreateIfMissing);
423 //---------------------------------------
424 /** @short do anything which is neccessary to flush all changes
425 back to disk.
427 @descr We have to call commit on all cached sub storages on the
428 path from the root storage upside down to the working storage
429 (which are not realy used, but required to be holded alive!).
431 void commitUserChanges();
433 //---------------------------------------
434 /** TODO */
435 void addStorageListener(IStorageListener* pListener);
436 void removeStorageListener(IStorageListener* pListener);
438 //-------------------------------------------
439 // helper
441 private:
443 //---------------------------------------
444 /** @short open a config path ignoring errors (catching exceptions).
446 @descr We catch only normal exceptions here - no runtime exceptions.
448 @param sPath
449 the configuration path, which should be opened.
451 @param eMode
452 the open mode (READ/READWRITE)
454 @param bShare
455 force using of the share layer instead of the user layer.
457 @return An opened storage in case method was successfully - null otherwise.
459 css::uno::Reference< css::embed::XStorage > impl_openPathIgnoringErrors(const ::rtl::OUString& sPath ,
460 sal_Int32 eMode ,
461 sal_Bool bShare);
463 //---------------------------------------
464 /** @short try to find the specified locale inside list of possible ones.
466 @descr The lits of possible locale values was e.g. retrieved from the system
467 (configuration, directory listing etcpp). The locale normaly represent
468 the current office locale. This method search for a suitable item by using
469 different algorithm.
470 a) exact search
471 b) search with using fallbacks
473 @param lLocalizedValues
474 list of ISO locale codes
476 @param aLocale
477 [IN ] the current office locale, which should be searched inside lLocalizedValues.
478 [OUT] in case fallbacks was allowed, it contains afterwards the fallback locale.
480 @param bAllowFallbacks
481 enable/disable using of fallbacks
483 @return An iterator, which points directly into lLocalizedValue list.
484 As a negative result the special iterator lLocalizedValues.end() will be returned.
486 ::std::vector< ::rtl::OUString >::const_iterator impl_findMatchingLocalizedValue(const ::std::vector< ::rtl::OUString >& lLocalizedValues,
487 ::comphelper::Locale& aLocale ,
488 sal_Bool bAllowFallbacks );
490 //---------------------------------------
491 /** @short open a config path ignoring errors (catching exceptions).
493 @descr We catch only normal exceptions here - no runtime exceptions.
494 Further the path itself is tries in different versions (using locale
495 specific attributes).
496 e.g. "path/e-US" => "path/en" => "path/de"
498 @param sPath
499 the configuration path, which should be opened.
500 Its further used as out parameter too, so we can return the localized
501 path to the calli!
503 @param eMode
504 the open mode (READ/READWRITE)
506 @param bShare
507 force using of the share layer instead of the user layer.
509 @param aLocale
510 [IN ] contains the start locale for searching localized sub dirs.
511 [OUT] contains the locale of a found localized sub dir
513 @param bAllowFallback
514 enable/disable fallback handling for locales
516 @return An opened storage in case method was successfully - null otherwise.
518 css::uno::Reference< css::embed::XStorage > impl_openLocalizedPathIgnoringErrors(::rtl::OUString& sPath ,
519 sal_Int32 eMode ,
520 sal_Bool bShare ,
521 ::comphelper::Locale& aLocale ,
522 sal_Bool bAllowFallback);
524 //---------------------------------------
525 /** @short returns the names of all sub storages of specified storage.
527 @param xFolder
528 the base storage for this operation.
530 @return [vector< string >]
531 a list of folder names.
533 ::std::vector< ::rtl::OUString > impl_getSubFolderNames(const css::uno::Reference< css::embed::XStorage >& xFolder);
536 } // namespace framework
538 #endif // __FRAMEWORK_ACCELERATORS_PRESETHANDLER_HXX_