soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SResProvider.h
1#ifndef __SRESPROVIDER__H__
2#define __SRESPROVIDER__H__
3
5#include <helper/SResID.h>
6#include <helper/obj-ref-impl.hpp>
7
8SNSBEGIN
9
10// Define system resource types
11extern const TCHAR KTypeBitmap[];
12extern const TCHAR KTypeCursor[];
13extern const TCHAR KTypeIcon[];
14extern const TCHAR KTypeHtml[];
15
16/**
17 * @class SResLoadFromMemory
18 * @brief Utility class for loading resources from memory.
19 */
20class SOUI_EXP SResLoadFromMemory {
21 public:
22 /**
23 * @brief Loads an image from a memory buffer.
24 * @param pBuf Pointer to the memory buffer containing the image data.
25 * @param size Size of the memory buffer.
26 * @return Pointer to the loaded IBitmapS object, or nullptr if loading fails.
27 */
28 static IBitmapS *LoadImage(LPVOID pBuf, size_t size);
29
30 /**
31 * @brief Loads an image from a memory buffer as an IImgX object.
32 * @param pBuf Pointer to the memory buffer containing the image data.
33 * @param size Size of the memory buffer.
34 * @return Pointer to the loaded IImgX object, or nullptr if loading fails.
35 */
36 static IImgX *LoadImgX(LPVOID pBuf, size_t size);
37};
38
39#ifdef _WIN32
40
41/**
42 * @class SResProviderPE
43 * @brief Resource provider for resources embedded in a PE file (Windows-specific).
44 */
45class SOUI_EXP SResProviderPE : public TObjRefImpl<IResProvider> {
46 public:
47 /**
48 * @brief Constructor.
49 */
50 SResProviderPE();
51
52 /**
53 * @brief Destructor.
54 */
55 ~SResProviderPE();
56
57 public:
58 /**
59 * @brief Initializes the resource provider.
60 * @param wParam Additional initialization parameter (wParam).
61 * @param lParam Additional initialization parameter (lParam).
62 * @return TRUE if initialization is successful, FALSE otherwise.
63 */
64 STDMETHOD_(BOOL, Init)(THIS_ WPARAM wParam, LPARAM lParam);
65
66 /**
67 * @brief Checks if a resource exists.
68 * @param pszType Type of the resource.
69 * @param pszResName Name of the resource.
70 * @return TRUE if the resource exists, FALSE otherwise.
71 */
72 STDMETHOD_(BOOL, HasResource)(THIS_ LPCTSTR pszType, LPCTSTR pszResName);
73
74 /**
75 * @brief Loads an icon resource.
76 * @param pszResName Name of the icon resource.
77 * @param cx Desired width of the icon.
78 * @param cy Desired height of the icon.
79 * @return Handle to the loaded icon, or nullptr if loading fails.
80 */
81 STDMETHOD_(HICON, LoadIcon)(THIS_ LPCTSTR pszResName, int cx, int cy);
82
83 /**
84 * @brief Loads a bitmap resource.
85 * @param pszResName Name of the bitmap resource.
86 * @return Handle to the loaded bitmap, or nullptr if loading fails.
87 */
88 STDMETHOD_(HBITMAP, LoadBitmap)(THIS_ LPCTSTR pszResName);
89
90 /**
91 * @brief Loads a cursor resource.
92 * @param pszResName Name of the cursor resource.
93 * @return Handle to the loaded cursor, or nullptr if loading fails.
94 */
95 STDMETHOD_(HCURSOR, LoadCursor)(THIS_ LPCTSTR pszResName);
96
97 /**
98 * @brief Loads an image resource as an IBitmapS object.
99 * @param pszType Type of the resource.
100 * @param pszResName Name of the resource.
101 * @return Pointer to the loaded IBitmapS object, or nullptr if loading fails.
102 */
103 STDMETHOD_(IBitmapS *, LoadImage)(THIS_ LPCTSTR pszType, LPCTSTR pszResName);
104
105 /**
106 * @brief Loads an image resource as an IImgX object.
107 * @param pszType Type of the resource.
108 * @param pszResName Name of the resource.
109 * @return Pointer to the loaded IImgX object, or nullptr if loading fails.
110 */
111 STDMETHOD_(IImgX *, LoadImgX)(THIS_ LPCTSTR pszType, LPCTSTR pszResName);
112
113 /**
114 * @brief Retrieves the size of the raw buffer for a resource.
115 * @param pszType Type of the resource.
116 * @param pszResName Name of the resource.
117 * @return Size of the raw buffer, or 0 if the resource does not exist.
118 */
119 STDMETHOD_(size_t, GetRawBufferSize)(THIS_ LPCTSTR pszType, LPCTSTR pszResName);
120
121 /**
122 * @brief Retrieves the raw buffer for a resource.
123 * @param pszType Type of the resource.
124 * @param pszResName Name of the resource.
125 * @param pBuf Buffer to store the raw data.
126 * @param size Size of the buffer.
127 * @return TRUE if the raw buffer is successfully retrieved, FALSE otherwise.
128 */
129 STDMETHOD_(BOOL, GetRawBuffer)(THIS_ LPCTSTR pszType, LPCTSTR pszResName, LPVOID pBuf, size_t size);
130
131 /**
132 * @brief Enumerates resources of a specific type.
133 * @param funEnumCB Callback function to process each resource.
134 * @param lp User-defined parameter passed to the callback function.
135 */
136 STDMETHOD_(void, EnumResource)(THIS_ EnumResCallback funEnumCB, LPARAM lp);
137
138 /**
139 * @brief Enumerates files in the resource provider.
140 * @param funEnumCB Callback function to process each file.
141 * @param lp User-defined parameter passed to the callback function.
142 */
143 STDMETHOD_(void, EnumFile)(THIS_ EnumFileCallback funEnumCB, LPARAM lp);
144
145 protected:
146 /**
147 * @brief Retrieves a pointer to the raw buffer for a resource.
148 * @param strType Type of the resource.
149 * @param pszResName Name of the resource.
150 * @return Pointer to the raw buffer, or nullptr if the resource does not exist.
151 */
152 LPVOID GetRawBufferPtr(LPCTSTR strType, LPCTSTR pszResName);
153
154 /**
155 * @brief Finds a resource in the PE file.
156 * @param strType Type of the resource.
157 * @param pszResName Name of the resource.
158 * @return Handle to the resource, or nullptr if not found.
159 */
160 HRSRC MyFindResource(LPCTSTR strType, LPCTSTR pszResName);
161
162 HINSTANCE m_hResInst; // Handle to the resource instance
163 BOOL m_bOwner; // Flag indicating if the instance is owned
164};
165
166#endif // _WIN32
167
168/**
169 * @class SResLoadFromFile
170 * @brief Utility class for loading resources from files.
171 */
172class SOUI_EXP SResLoadFromFile {
173 public:
174 /**
175 * @brief Loads a bitmap from a file.
176 * @param pszFileName Name of the file containing the bitmap.
177 * @return Handle to the loaded bitmap, or nullptr if loading fails.
178 */
179 static HBITMAP LoadBitmap(LPCTSTR pszFileName);
180
181 /**
182 * @brief Loads an icon from a file.
183 * @param pszFileName Name of the file containing the icon.
184 * @param cx Desired width of the icon.
185 * @param cy Desired height of the icon.
186 * @return Handle to the loaded icon, or nullptr if loading fails.
187 */
188 static HICON LoadIcon(LPCTSTR pszFileName, int cx = 0, int cy = 0);
189
190 /**
191 * @brief Loads a cursor from a file.
192 * @param pszFileName Name of the file containing the cursor.
193 * @return Handle to the loaded cursor, or nullptr if loading fails.
194 */
195 static HCURSOR LoadCursor(LPCTSTR pszFileName);
196
197 /**
198 * @brief Loads an image from a file as an IBitmapS object.
199 * @param pszFileName Name of the file containing the image.
200 * @return Pointer to the loaded IBitmapS object, or nullptr if loading fails.
201 */
202 static IBitmapS *LoadImage(LPCTSTR pszFileName);
203
204 /**
205 * @brief Loads an image from a file as an IImgX object.
206 * @param pszFileName Name of the file containing the image.
207 * @return Pointer to the loaded IImgX object, or nullptr if loading fails.
208 */
209 static IImgX *LoadImgX(LPCTSTR pszFileName);
210
211 /**
212 * @brief Retrieves the size of the raw buffer for a file.
213 * @param pszFileName Name of the file.
214 * @return Size of the raw buffer, or 0 if the file does not exist.
215 */
216 static size_t GetRawBufferSize(LPCTSTR pszFileName);
217
218 /**
219 * @brief Retrieves the raw buffer for a file.
220 * @param pszFileName Name of the file.
221 * @param pBuf Buffer to store the raw data.
222 * @param size Size of the buffer.
223 * @return TRUE if the raw buffer is successfully retrieved, FALSE otherwise.
224 */
225 static BOOL GetRawBuffer(LPCTSTR pszFileName, LPVOID pBuf, size_t size);
226};
227
228/**
229 * @class SResProviderFiles
230 * @brief Resource provider for resources stored in files.
231 */
232class SOUI_EXP SResProviderFiles : public TObjRefImpl<IResProvider> {
233 public:
234 /**
235 * @brief Constructor.
236 */
238
239 /**
240 * @brief Initializes the resource provider.
241 * @param wParam Additional initialization parameter (wParam).
242 * @param lParam Additional initialization parameter (lParam).
243 * @return TRUE if initialization is successful, FALSE otherwise.
244 */
245 STDMETHOD_(BOOL, Init)(THIS_ WPARAM wParam, LPARAM lParam) OVERRIDE;
246
247 /**
248 * @brief Checks if a resource exists.
249 * @param pszType Type of the resource.
250 * @param pszResName Name of the resource.
251 * @return TRUE if the resource exists, FALSE otherwise.
252 */
253 STDMETHOD_(BOOL, HasResource)(THIS_ LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE;
254
255 /**
256 * @brief Loads an icon resource.
257 * @param pszResName Name of the icon resource.
258 * @param cx Desired width of the icon.
259 * @param cy Desired height of the icon.
260 * @return Handle to the loaded icon, or nullptr if loading fails.
261 */
262 STDMETHOD_(HICON, LoadIcon)(THIS_ LPCTSTR pszResName, int cx, int cy) OVERRIDE;
263
264 /**
265 * @brief Loads a bitmap resource.
266 * @param pszResName Name of the bitmap resource.
267 * @return Handle to the loaded bitmap, or nullptr if loading fails.
268 */
269 STDMETHOD_(HBITMAP, LoadBitmap)(THIS_ LPCTSTR pszResName) OVERRIDE;
270
271 /**
272 * @brief Loads a cursor resource.
273 * @param pszResName Name of the cursor resource.
274 * @return Handle to the loaded cursor, or nullptr if loading fails.
275 */
276 STDMETHOD_(HCURSOR, LoadCursor)(THIS_ LPCTSTR pszResName) OVERRIDE;
277
278 /**
279 * @brief Loads an image resource as an IBitmapS object.
280 * @param pszType Type of the resource.
281 * @param pszResName Name of the resource.
282 * @return Pointer to the loaded IBitmapS object, or nullptr if loading fails.
283 */
284 STDMETHOD_(IBitmapS *, LoadImage)(THIS_ LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE;
285
286 /**
287 * @brief Loads an image resource as an IImgX object.
288 * @param pszType Type of the resource.
289 * @param pszResName Name of the resource.
290 * @return Pointer to the loaded IImgX object, or nullptr if loading fails.
291 */
292 STDMETHOD_(IImgX *, LoadImgX)(THIS_ LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE;
293
294 /**
295 * @brief Retrieves the size of the raw buffer for a resource.
296 * @param pszType Type of the resource.
297 * @param pszResName Name of the resource.
298 * @return Size of the raw buffer, or 0 if the resource does not exist.
299 */
300 STDMETHOD_(size_t, GetRawBufferSize)(THIS_ LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE;
301
302 /**
303 * @brief Retrieves the raw buffer for a resource.
304 * @param pszType Type of the resource.
305 * @param pszResName Name of the resource.
306 * @param pBuf Buffer to store the raw data.
307 * @param size Size of the buffer.
308 * @return TRUE if the raw buffer is successfully retrieved, FALSE otherwise.
309 */
310 STDMETHOD_(BOOL, GetRawBuffer)(THIS_ LPCTSTR pszType, LPCTSTR pszResName, LPVOID pBuf, size_t size) OVERRIDE;
311
312 /**
313 * @brief Enumerates resources of a specific type.
314 * @param funEnumCB Callback function to process each resource.
315 * @param lp User-defined parameter passed to the callback function.
316 */
317 STDMETHOD_(void, EnumResource)(THIS_ EnumResCallback funEnumCB, LPARAM lp) OVERRIDE;
318
319 /**
320 * @brief Enumerates files in the resource provider.
321 * @param funEnumCB Callback function to process each file.
322 * @param lp User-defined parameter passed to the callback function.
323 */
324 STDMETHOD_(void, EnumFile)(THIS_ EnumFileCallback funEnumCB, LPARAM lp) OVERRIDE;
325
326 protected:
327 /**
328 * @brief Enumerates files in a specified path.
329 * @param pszPath Path to the directory containing the files.
330 * @param funEnumCB Callback function to process each file.
331 * @param lp User-defined parameter passed to the callback function.
332 */
333 void _EnumFile(LPCTSTR pszPath, EnumFileCallback funEnumCB, LPARAM lp);
334
335 /**
336 * @brief Retrieves the resource path for a given type and name.
337 * @param strType Type of the resource.
338 * @param pszResName Name of the resource.
339 * @return Full path to the resource file, or an empty string if not found.
340 */
341 SStringT GetRes(LPCTSTR strType, LPCTSTR pszResName);
342
343 SStringT m_strPath; // Base path for resource files
344 SMap<SResID, SStringT> m_mapFiles; // Map of resource IDs to file paths
345};
346
347SNSEND
348
349#endif // __SRESPROVIDER__H__
Utility class for loading resources from files.
static HBITMAP LoadBitmap(LPCTSTR pszFileName)
Loads a bitmap from a file.
static size_t GetRawBufferSize(LPCTSTR pszFileName)
Retrieves the size of the raw buffer for a file.
static BOOL GetRawBuffer(LPCTSTR pszFileName, LPVOID pBuf, size_t size)
Retrieves the raw buffer for a file.
static IBitmapS * LoadImage(LPCTSTR pszFileName)
Loads an image from a file as an IBitmapS object.
static IImgX * LoadImgX(LPCTSTR pszFileName)
Loads an image from a file as an IImgX object.
static HICON LoadIcon(LPCTSTR pszFileName, int cx=0, int cy=0)
Loads an icon from a file.
static HCURSOR LoadCursor(LPCTSTR pszFileName)
Loads a cursor from a file.
Utility class for loading resources from memory.
static IImgX * LoadImgX(LPVOID pBuf, size_t size)
Loads an image from a memory buffer as an IImgX object.
static IBitmapS * LoadImage(LPVOID pBuf, size_t size)
Loads an image from a memory buffer.
HBITMAP LoadBitmap(LPCTSTR pszResName) OVERRIDE
Loads a bitmap resource.
BOOL HasResource(LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE
Checks if a resource exists.
HICON LoadIcon(LPCTSTR pszResName, int cx, int cy) OVERRIDE
Loads an icon resource.
SResProviderFiles()
Constructor.
IBitmapS * LoadImage(LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE
Loads an image resource as an IBitmapS object.
void EnumFile(EnumFileCallback funEnumCB, LPARAM lp) OVERRIDE
Enumerates files in the resource provider.
BOOL GetRawBuffer(LPCTSTR pszType, LPCTSTR pszResName, LPVOID pBuf, size_t size) OVERRIDE
Retrieves the raw buffer for a resource.
IImgX * LoadImgX(LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE
Loads an image resource as an IImgX object.
HCURSOR LoadCursor(LPCTSTR pszResName) OVERRIDE
Loads a cursor resource.
SStringT GetRes(LPCTSTR strType, LPCTSTR pszResName)
Retrieves the resource path for a given type and name.
void _EnumFile(LPCTSTR pszPath, EnumFileCallback funEnumCB, LPARAM lp)
Enumerates files in a specified path.
size_t GetRawBufferSize(LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE
Retrieves the size of the raw buffer for a resource.
void EnumResource(EnumResCallback funEnumCB, LPARAM lp) OVERRIDE
Enumerates resources of a specific type.
BOOL Init(WPARAM wParam, LPARAM lParam) OVERRIDE
Initializes the resource provider.
Template class implementing the IObjRef interface.
Bitmap object interface.
Definition SRender-i.h:420
Interface for image data.