1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _FORMULA_CORE_RESOURCE_HXX_ 25 #define _FORMULA_CORE_RESOURCE_HXX_ 26 27 #ifndef _RTL_USTRING_HXX_ 28 #include <rtl/ustring.hxx> 29 #endif 30 #include <osl/mutex.hxx> 31 32 class ResMgr; 33 //......................................................................... 34 namespace formula 35 { 36 37 #define FORMULA_RES( id ) ResourceManager::loadString( id ) 38 #define FORMULA_RES_PARAM( id, ascii, replace ) ResourceManager::loadString( id, ascii, replace ) 39 40 #define FORMULACORE_RESSTRING( id ) FORMULA_RES( id ) 41 // (compatibility) 42 43 //================================================================== 44 //= ResourceManager 45 //= handling ressources within the FORMULA-Core library 46 //================================================================== 47 class ResourceManager 48 { 49 friend class OModuleClient; 50 static ::osl::Mutex s_aMutex; /// access safety 51 static sal_Int32 s_nClients; /// number of registered clients 52 static ResMgr* m_pImpl; 53 54 private: 55 // no instantiation allowed ResourceManager()56 ResourceManager() { } ~ResourceManager()57 ~ResourceManager() { } 58 59 protected: 60 static void ensureImplExists(); 61 /// register a client for the module 62 static void registerClient(); 63 /// revoke a client for the module 64 static void revokeClient(); 65 66 public: 67 /** loads the string with the specified resource id 68 */ 69 static ::rtl::OUString loadString(sal_uInt16 _nResId); 70 71 /** loads a string from the resource file, substituting a placeholder with a given string 72 73 @param _nResId 74 the resource ID of the string to loAD 75 @param _pPlaceholderAscii 76 the ASCII representation of the placeholder string 77 @param _rReplace 78 the string which should substutite the placeholder 79 */ 80 static ::rtl::OUString loadString( 81 sal_uInt16 _nResId, 82 const sal_Char* _pPlaceholderAscii, 83 const ::rtl::OUString& _rReplace 84 ); 85 86 static ResMgr* getResManager(); 87 }; 88 89 //========================================================================= 90 //= OModuleClient 91 //========================================================================= 92 /** base class for objects which uses any global module-specific ressources 93 */ 94 class OModuleClient 95 { 96 public: OModuleClient()97 OModuleClient() { ResourceManager::registerClient(); } ~OModuleClient()98 ~OModuleClient() { ResourceManager::revokeClient(); } 99 }; 100 101 102 //......................................................................... 103 } // formula 104 //......................................................................... 105 106 #endif // _FORMULA_CORE_RESOURCE_HXX_ 107 108