xref: /AOO41X/main/tools/inc/tools/rc.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _TOOLS_RC_HXX
28 #define _TOOLS_RC_HXX
29 
30 #include "tools/toolsdllapi.h"
31 #include <i18npool/lang.h>
32 #include <tools/string.hxx>
33 #include <tools/resmgr.hxx>
34 
35 // ------------
36 // - Resource -
37 // ------------
38 
39 class TOOLS_DLLPUBLIC Resource
40 {
41 	protected:
42 	ResMgr* m_pResMgr;
43 
44 	// check availability of Resource
45 	sal_Bool				IsAvailableRes( const ResId& rId ) const
46 	{ return m_pResMgr->IsAvailable( rId, this ); }
47 
48 	// Load a Resource
49 	void				GetRes( const ResId& rResId );
50 
51 	// check Resource state
52 	void				TestRes();
53 
54 	// Get a pointer to the Resource's data
55 	void* GetClassRes()
56 	{ return m_pResMgr->GetClass(); }
57 
58 	// read a string from the resource
59 	static sal_uInt32	GetStringRes( UniString& rStr, const sal_uInt8* pStr )
60 	{ return ResMgr::GetString( rStr, pStr ); }
61 
62 	// increase the memory pointer gotten by GetClassRes()
63 	void* IncrementRes( sal_uInt32 nBytes )
64 	{ return m_pResMgr->Increment( nBytes ); }
65 
66 	// return the memory size of a Resource data block
67 	static sal_uInt32	GetObjSizeRes( RSHEADER_TYPE * pHT )
68 	{ return ResMgr::GetObjSize( pHT ); }
69 
70 	// return the remaining size of this Resource's data
71 	sal_uInt32 GetRemainSizeRes()
72 	{ return m_pResMgr->GetRemainSize(); }
73 
74 	// get a 32bit value from Resource data
75 	static sal_Int32	GetLongRes( void * pLong )
76 	{ return ResMgr::GetLong( pLong ); }
77 	// get a 16bit value from Resource data
78 	static sal_Int16	GetShortRes( void * pShort )
79 	{ return ResMgr::GetShort( pShort ); }
80 
81 	// read a 32bit value from resource data and increment pointer
82 	sal_Int32 ReadLongRes()
83 	{ return m_pResMgr->ReadLong(); }
84 	// read a 16bit value from resource data and increment pointer
85 	sal_Int16 ReadShortRes()
86 	{ return m_pResMgr->ReadShort(); }
87 	// read a string from resource data and increment pointer
88 	UniString ReadStringRes()
89 	{ return m_pResMgr->ReadString(); }
90 	// read a byte string from resource data and increment pointer
91 	rtl::OString ReadByteStringRes()
92 	{ return m_pResMgr->ReadByteString(); }
93 
94 	// Gibt die Resource frei (this-Zeiger fuer Fehlerueberpruefung)
95 	// free the resource from m_pResMgr's stack (pass this ptr for validation)
96 	void FreeResource()
97 	{ m_pResMgr->PopContext( this ); }
98 
99 	// constructors
100 	Resource() : m_pResMgr( NULL ) {}
101 	Resource( const ResId& rResId );
102 
103 	public:
104 	#ifdef DBG_UTIL
105 	~Resource() { TestRes(); }
106 	#else
107 	~Resource() {}
108 	#endif
109 };
110 
111 #endif // _SV_RC_HXX
112