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 _TOOLS_RESID_HXX 25 #define _TOOLS_RESID_HXX 26 27 #include <tools/solar.h> 28 #include <osl/diagnose.h> 29 30 struct RSHEADER_TYPE; 31 typedef sal_uInt32 RESOURCE_TYPE; 32 #define RSC_NOTYPE 0x100 33 #define RSC_DONTRELEASE (sal_uInt32(1 << 31)) 34 35 class ResMgr; 36 37 //--------- 38 //- ResId - 39 //--------- 40 41 class ResId 42 { 43 /* 44 consider two cases: either m_pResource is valid and points 45 two a resource data buffer; then m_nResId and m_pResMgr are 46 not used and may be 0 resp. NULL 47 or m_pResource is NULL, the m_nResId and m_pResMgr must be valid. 48 In this case the highest bit if set decides whether to 49 not to release the Resource context after loading this id 50 */ 51 RSHEADER_TYPE* m_pResource; 52 53 mutable sal_uInt32 m_nResId; // Resource Identifier 54 mutable RESOURCE_TYPE m_nRT; // type for loading (mutable to be set later) 55 mutable ResMgr * m_pResMgr; // load from this ResMgr (mutable for setting on demand) 56 mutable RESOURCE_TYPE m_nRT2; // type for loading (supercedes m_nRT) 57 mutable sal_uInt32 m_nWinBits; // container for original style bits on a window in a resource 58 ImplInit(sal_uInt32 nId,ResMgr & rMgr,RSHEADER_TYPE * pRes)59 void ImplInit( sal_uInt32 nId, ResMgr& rMgr, RSHEADER_TYPE* pRes ) 60 { 61 m_pResource = pRes; m_nResId = nId; m_nRT = RSC_NOTYPE; m_pResMgr = &rMgr; m_nRT2 = RSC_NOTYPE; m_nWinBits = 0; 62 OSL_ENSURE( m_pResMgr != NULL, "ResId without ResMgr created" ); 63 } 64 public: ResId(RSHEADER_TYPE * pRc,ResMgr & rMgr)65 ResId( RSHEADER_TYPE * pRc, ResMgr& rMgr ) 66 { 67 ImplInit( 0, rMgr, pRc ); 68 } ResId(sal_uInt32 nId,ResMgr & rMgr)69 ResId( sal_uInt32 nId, ResMgr& rMgr ) 70 { 71 ImplInit( nId, rMgr, NULL ); 72 } 73 // backwards compatibility; avoid ambiguities ResId(sal_uInt16 nId,ResMgr & rMgr)74 ResId( sal_uInt16 nId, ResMgr& rMgr ) 75 { 76 ImplInit( sal_uInt32(nId), rMgr, NULL ); 77 } ResId(int nId,ResMgr & rMgr)78 ResId( int nId, ResMgr& rMgr ) 79 { 80 ImplInit( sal_uInt32(nId), rMgr, NULL ); 81 } ResId(long nId,ResMgr & rMgr)82 ResId( long nId, ResMgr& rMgr ) 83 { 84 ImplInit( sal_uInt32(nId), rMgr, NULL ); 85 } 86 GetWinBits() const87 sal_uInt32 GetWinBits() const 88 { return m_nWinBits; } SetWinBits(sal_uInt32 nBits) const89 void SetWinBits( sal_uInt32 nBits ) const 90 { m_nWinBits = nBits; } 91 GetRT() const92 RESOURCE_TYPE GetRT() const { return( m_nRT ); } SetRT(RESOURCE_TYPE nType) const93 const ResId & SetRT( RESOURCE_TYPE nType ) const 94 /* 95 Set the type if not already set. Ask for tye with GetRT() 96 97 [Example] 98 ResId aId( 1000 ); 99 aId.SetRT( RSC_WINDOW ); // settype window Window 100 aId.SetRT( RSC_BUTTON ); // will not set type Button 101 //aId.GetRT() == RSC_WINDOW is true 102 103 @see 104 ResId::GetRT2(), ResId::GetRT() 105 */ 106 { 107 if( RSC_NOTYPE == m_nRT ) 108 m_nRT = nType; 109 return *this; 110 } GetRT2() const111 RESOURCE_TYPE GetRT2() const 112 /* 113 Get the effective type (m_nRT2 or m_nRT1) 114 115 A second resource type is used to supercede settings 116 of the base class ( e.g. Window ) 117 */ 118 { 119 return (RSC_NOTYPE == m_nRT2) ? m_nRT : m_nRT2; 120 } SetRT2(RESOURCE_TYPE nTyp) const121 const ResId & SetRT2( RESOURCE_TYPE nTyp ) const 122 /* 123 Set the superceding type. Ask spcifically for it with GetRT2() 124 125 SetRT2() may only be called if no derived class calls SetRT in its 126 Resource constructor. 127 */ 128 { 129 if( RSC_NOTYPE == m_nRT2 ) 130 m_nRT2 = nTyp; 131 return *this; 132 } 133 GetResMgr() const134 ResMgr * GetResMgr() const { return m_pResMgr; } SetResMgr(ResMgr * pMgr) const135 const ResId & SetResMgr( ResMgr * pMgr ) const 136 { 137 m_pResMgr = pMgr; 138 OSL_ENSURE( m_pResMgr != NULL, "invalid ResMgr set on ResId" ); 139 return *this; 140 } 141 SetAutoRelease(sal_Bool bRelease) const142 const ResId & SetAutoRelease(sal_Bool bRelease) const 143 { 144 if( bRelease ) 145 m_nResId &= ~RSC_DONTRELEASE; 146 else 147 m_nResId |= RSC_DONTRELEASE; 148 return *this; 149 } 150 IsAutoRelease() const151 sal_Bool IsAutoRelease() const 152 { return !(m_nResId & RSC_DONTRELEASE); } 153 GetId() const154 sal_uInt32 GetId() const { return m_nResId & ~RSC_DONTRELEASE; } GetpResource() const155 RSHEADER_TYPE* GetpResource() const { return m_pResource; } 156 }; 157 158 #endif // _RESID_HXX 159