xref: /trunk/main/tools/inc/tools/rc.hxx (revision 8b851043)
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 #ifndef _TOOLS_RC_HXX
24 #define _TOOLS_RC_HXX
25 
26 #include "tools/toolsdllapi.h"
27 #include <i18npool/lang.h>
28 #include <tools/string.hxx>
29 #include <tools/resmgr.hxx>
30 
31 // ------------
32 // - Resource -
33 // ------------
34 
35 class TOOLS_DLLPUBLIC Resource
36 {
37 	protected:
38 	ResMgr* m_pResMgr;
39 
40 	// check availability of Resource
IsAvailableRes(const ResId & rId) const41 	sal_Bool				IsAvailableRes( const ResId& rId ) const
42 	{ return m_pResMgr->IsAvailable( rId, this ); }
43 
44 	// Load a Resource
45 	void				GetRes( const ResId& rResId );
46 
47 	// check Resource state
48 	void				TestRes();
49 
50 	// Get a pointer to the Resource's data
GetClassRes()51 	void* GetClassRes()
52 	{ return m_pResMgr->GetClass(); }
53 
54 	// read a string from the resource
GetStringRes(UniString & rStr,const sal_uInt8 * pStr)55 	static sal_uInt32	GetStringRes( UniString& rStr, const sal_uInt8* pStr )
56 	{ return ResMgr::GetString( rStr, pStr ); }
57 
58 	// increase the memory pointer gotten by GetClassRes()
IncrementRes(sal_uInt32 nBytes)59 	void* IncrementRes( sal_uInt32 nBytes )
60 	{ return m_pResMgr->Increment( nBytes ); }
61 
62 	// return the memory size of a Resource data block
GetObjSizeRes(RSHEADER_TYPE * pHT)63 	static sal_uInt32	GetObjSizeRes( RSHEADER_TYPE * pHT )
64 	{ return ResMgr::GetObjSize( pHT ); }
65 
66 	// return the remaining size of this Resource's data
GetRemainSizeRes()67 	sal_uInt32 GetRemainSizeRes()
68 	{ return m_pResMgr->GetRemainSize(); }
69 
70 	// get a 32bit value from Resource data
GetLongRes(void * pLong)71 	static sal_Int32	GetLongRes( void * pLong )
72 	{ return ResMgr::GetLong( pLong ); }
73 	// get a 16bit value from Resource data
GetShortRes(void * pShort)74 	static sal_Int16	GetShortRes( void * pShort )
75 	{ return ResMgr::GetShort( pShort ); }
76 
77 	// read a 32bit value from resource data and increment pointer
ReadLongRes()78 	sal_Int32 ReadLongRes()
79 	{ return m_pResMgr->ReadLong(); }
80 	// read a 16bit value from resource data and increment pointer
ReadShortRes()81 	sal_Int16 ReadShortRes()
82 	{ return m_pResMgr->ReadShort(); }
83 	// read a string from resource data and increment pointer
ReadStringRes()84 	UniString ReadStringRes()
85 	{ return m_pResMgr->ReadString(); }
86 	// read a byte string from resource data and increment pointer
ReadByteStringRes()87 	rtl::OString ReadByteStringRes()
88 	{ return m_pResMgr->ReadByteString(); }
89 
90 	// Gibt die Resource frei (this-Zeiger fuer Fehlerueberpruefung)
91 	// free the resource from m_pResMgr's stack (pass this ptr for validation)
FreeResource()92 	void FreeResource()
93 	{ m_pResMgr->PopContext( this ); }
94 
95 	// constructors
Resource()96 	Resource() : m_pResMgr( NULL ) {}
97 	Resource( const ResId& rResId );
98 
99 	public:
100 	#ifdef DBG_UTIL
~Resource()101 	~Resource() { TestRes(); }
102 	#else
103 	~Resource() {}
104 	#endif
105 };
106 
107 #endif // _SV_RC_HXX
108