soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SResProviderMgr.h
1#ifndef __SRESPROVIDERMGR__H__
2#define __SRESPROVIDERMGR__H__
3
4#include <windows.h>
5#include <interface/SResProviderMgr-i.h>
6#include <layout/SLayoutSize.h>
8#include <helper/SAutoBuf.h>
9
10SNSBEGIN
11
12/**
13 * @class SResProviderMgr
14 * @brief Resource Provider Manager
15 *
16 * @details Manages multiple resource providers and provides methods to load and manage resources.
17 */
18class SOUI_EXP SResProviderMgr : public IResProviderMgr {
19 public:
20 /**
21 * @brief Constructor.
22 */
23 SResProviderMgr(void);
24
25 /**
26 * @brief Destructor.
27 */
28 ~SResProviderMgr(void);
29
30 public:
31 /**
32 * @brief Adds a resource provider with a specified UI definition.
33 * @param pResProvider Pointer to the resource provider to add.
34 * @param pszUidef UI definition string (default is "uidef:xml_init").
35 */
36 STDMETHOD_(void, AddResProvider)(THIS_ IResProvider *pResProvider, LPCTSTR pszUidef DEF_VAL(_T("uidef:xml_init"))) OVERRIDE;
37
38 /**
39 * @brief Adds a resource provider with a specified UI definition (ANSI version).
40 * @param pResProvider Pointer to the resource provider to add.
41 * @param pszUidef UI definition string (default is "uidef:xml_init").
42 */
43 STDMETHOD_(void, AddResProviderA)(THIS_ IResProvider *pResProvider, LPCSTR pszUidef DEF_VAL("uidef:xml_init")) OVERRIDE;
44
45 /**
46 * @brief Removes a resource provider.
47 * @param pResProvider Pointer to the resource provider to remove.
48 */
49 STDMETHOD_(void, RemoveResProvider)(THIS_ IResProvider *pResProvider) OVERRIDE;
50
51 /**
52 * @brief Removes all resource providers.
53 */
54 STDMETHOD_(void, RemoveAll)(THIS) OVERRIDE;
55
56 /**
57 * @brief Retrieves the first resource provider in the list.
58 * @return Pointer to the first resource provider, or nullptr if the list is empty.
59 */
60 STDMETHOD_(IResProvider *, GetHeadResProvider)(THIS) SCONST OVERRIDE;
61
62 /**
63 * @brief Retrieves the last resource provider in the list.
64 * @return Pointer to the last resource provider, or nullptr if the list is empty.
65 */
66 STDMETHOD_(IResProvider *, GetTailResProvider)(THIS) SCONST OVERRIDE;
67
68 /**
69 * @brief Sets the file prefix for resource paths.
70 * @param pszFilePrefix File prefix to set.
71 */
72 STDMETHOD_(void, SetFilePrefix)(THIS_ LPCTSTR pszFilePrefix) OVERRIDE;
73
74 //////////////////////////////////////////////////////////////////////////
75 /**
76 * @brief Checks if a resource exists.
77 * @param pszType Type of the resource.
78 * @param pszResName Name of the resource.
79 * @return TRUE if the resource exists, FALSE otherwise.
80 */
81 STDMETHOD_(BOOL, HasResource)(THIS_ LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE;
82
83 /**
84 * @brief Loads an icon resource.
85 * @param pszResName Name of the icon resource.
86 * @param cx Desired width of the icon (default is 0).
87 * @param cy Desired height of the icon (default is 0).
88 * @param bFromFile TRUE if the resource should be loaded from a file, FALSE otherwise (default is FALSE).
89 * @return Handle to the loaded icon, or nullptr if loading fails.
90 */
91 STDMETHOD_(HICON, LoadIcon)(THIS_ LPCTSTR pszResName, int cx = 0, int cy = 0, BOOL bFromFile = FALSE) OVERRIDE;
92
93 /**
94 * @brief Loads a cursor resource.
95 * @param pszResName Name of the cursor resource.
96 * @param bFromFile TRUE if the resource should be loaded from a file, FALSE otherwise (default is FALSE).
97 * @return Handle to the loaded cursor, or nullptr if loading fails.
98 */
99 STDMETHOD_(HCURSOR, LoadCursor)(THIS_ LPCTSTR pszResName, BOOL bFromFile = FALSE) OVERRIDE;
100
101 /**
102 * @brief Loads a bitmap resource.
103 * @param pszResName Name of the bitmap resource.
104 * @param bFromFile TRUE if the resource should be loaded from a file, FALSE otherwise (default is FALSE).
105 * @return Handle to the loaded bitmap, or nullptr if loading fails.
106 */
107 STDMETHOD_(HBITMAP, LoadBitmap)(THIS_ LPCTSTR pszResName, BOOL bFromFile = FALSE) OVERRIDE;
108
109 /**
110 * @brief Loads an image resource as an IBitmapS object.
111 * @param pszType Type of the resource.
112 * @param pszResName Name of the resource.
113 * @return Pointer to the loaded IBitmapS object, or nullptr if loading fails.
114 */
115 STDMETHOD_(IBitmapS *, LoadImage)(THIS_ LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE;
116
117 /**
118 * @brief Loads an image resource as an IImgX object.
119 * @param pszType Type of the resource.
120 * @param pszResName Name of the resource.
121 * @return Pointer to the loaded IImgX object, or nullptr if loading fails.
122 */
123 STDMETHOD_(IImgX *, LoadImgX)(THIS_ LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE;
124
125 /**
126 * @brief Retrieves the size of the raw buffer for a resource.
127 * @param pszType Type of the resource.
128 * @param pszResName Name of the resource.
129 * @return Size of the raw buffer, or 0 if the resource does not exist.
130 */
131 STDMETHOD_(size_t, GetRawBufferSize)(THIS_ LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE;
132
133 /**
134 * @brief Retrieves the raw buffer for a resource.
135 * @param pszType Type of the resource.
136 * @param pszResName Name of the resource.
137 * @param pBuf Buffer to store the raw data.
138 * @param size Size of the buffer.
139 * @return TRUE if the raw buffer is successfully retrieved, FALSE otherwise.
140 */
141 STDMETHOD_(BOOL, GetRawBuffer)(THIS_ LPCTSTR pszType, LPCTSTR pszResName, LPVOID pBuf, size_t size) OVERRIDE;
142
143 public:
144 // Helper methods
145
146 /**
147 * @brief Finds the resource provider that contains the specified resource type and name.
148 * @param pszType Type of the resource.
149 * @param pszResName Name of the resource.
150 * @return Pointer to the resource provider, or nullptr if not found.
151 */
152 IResProvider *GetMatchResProvider(LPCTSTR pszType, LPCTSTR pszResName);
153
154 /**
155 * @brief Loads an image using a type:name formatted string.
156 * @param strImgID Type:name formatted string.
157 * @return Pointer to the loaded IBitmapS object, or nullptr if loading fails.
158 */
159 IBitmapS *LoadImage2(const SStringW &strImgID);
160
161 /**
162 * @brief Loads an icon using a name:size formatted string.
163 * @param strIconID Name:size formatted string.
164 * @return Handle to the loaded icon, or nullptr if loading fails.
165 */
166 HICON LoadIcon2(const SStringW &strIconID);
167
168 /**
169 * @brief Loads the raw buffer for a resource using a specified resource provider.
170 * @param pszType Type of the resource.
171 * @param pszResName Name of the resource.
172 * @param pResProvider Pointer to the resource provider.
173 * @param buf Buffer to store the raw data.
174 * @return TRUE if the raw buffer is successfully loaded, FALSE otherwise.
175 */
176 BOOL LoadRawBuffer(LPCTSTR pszType, LPCTSTR pszResName, IResProvider *pResProvider, SAutoBuf &buf);
177
178 protected:
179#ifdef _DEBUG
180 /**
181 * @brief Callback function to check resource usage (debug only).
182 * @param pszName Name of the resource.
183 * @param pszType Type of the resource.
184 * @param lp User-defined parameter.
185 * @return TRUE if the resource is in use, FALSE otherwise.
186 */
187 static BOOL CALLBACK CheckUsage(LPCTSTR pszName, LPCTSTR pszType, LPARAM lp);
188#endif
189
190 /**
191 * @brief Converts a system cursor name to its corresponding ID.
192 * @param pszCursorName Name of the system cursor.
193 * @return ID of the system cursor.
194 */
195 LPCTSTR SysCursorName2ID(LPCTSTR pszCursorName);
196
197 /**
198 * @brief Checks if the resource type is an external file.
199 * @param pszType Type of the resource.
200 * @return TRUE if the resource type is an external file, FALSE otherwise.
201 */
202 BOOL IsFileType(LPCTSTR pszType);
203
204 SStringT m_strFilePrefix; // File prefix for resource paths
205 SList<IResProvider *> m_lstResPackage; // List of resource providers
206
207 typedef SMap<SStringT, HCURSOR> CURSORMAP;
208 CURSORMAP m_mapCachedCursor; // Map of cached cursors
209
210 SCriticalSection m_cs; // Critical section for thread safety
211
212#ifdef _DEBUG
213 // Resource usage count map (debug only)
214 SMap<SStringT, int> m_mapResUsageCount;
215#endif
216};
217
218SNSEND
219
220#endif // __SRESPROVIDERMGR__H__
Header file for the SAutoBuf class, a smart buffer management class.
Header file for SCriticalSection and SAutoLock classes.
A smart buffer management class that automatically handles memory allocation and deallocation.
Definition SAutoBuf.h:18
Wrapper class for a critical section.
IResProvider * GetHeadResProvider() SCONST OVERRIDE
Retrieves the first resource provider in the list.
void RemoveResProvider(IResProvider *pResProvider) OVERRIDE
Removes a resource provider.
void AddResProviderA(IResProvider *pResProvider, LPCSTR pszUidef="uidef:xml_init") OVERRIDE
Adds a resource provider with a specified UI definition (ANSI version).
IBitmapS * LoadImage2(const SStringW &strImgID)
Loads an image using a type:name formatted string.
void SetFilePrefix(LPCTSTR pszFilePrefix) OVERRIDE
Sets the file prefix for resource paths.
IResProvider * GetMatchResProvider(LPCTSTR pszType, LPCTSTR pszResName)
Finds the resource provider that contains the specified resource type and name.
LPCTSTR SysCursorName2ID(LPCTSTR pszCursorName)
Converts a system cursor name to its corresponding ID.
BOOL IsFileType(LPCTSTR pszType)
Checks if the resource type is an external file.
void AddResProvider(IResProvider *pResProvider, LPCTSTR pszUidef=_T("uidef:xml_init")) OVERRIDE
Adds a resource provider with a specified UI definition.
void RemoveAll() OVERRIDE
Removes all resource providers.
IResProvider * GetTailResProvider() SCONST OVERRIDE
Retrieves the last resource provider in the list.
HICON LoadIcon2(const SStringW &strIconID)
Loads an icon using a name:size formatted string.
SResProviderMgr(void)
Constructor.
BOOL LoadRawBuffer(LPCTSTR pszType, LPCTSTR pszResName, IResProvider *pResProvider, SAutoBuf &buf)
Loads the raw buffer for a resource using a specified resource provider.
size_t GetRawBufferSize(LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE
Retrieves the size of the raw buffer for a resource.
HICON LoadIcon(LPCTSTR pszResName, int cx=0, int cy=0, BOOL bFromFile=FALSE) OVERRIDE
Loads an icon resource.
BOOL HasResource(LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE
Checks if a resource exists.
IBitmapS * LoadImage(LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE
Loads an image resource as an IBitmapS object.
HCURSOR LoadCursor(LPCTSTR pszResName, BOOL bFromFile=FALSE) OVERRIDE
Loads a cursor resource.
IImgX * LoadImgX(LPCTSTR pszType, LPCTSTR pszResName) OVERRIDE
Loads an image resource as an IImgX object.
HBITMAP LoadBitmap(LPCTSTR pszResName, BOOL bFromFile=FALSE) OVERRIDE
Loads a bitmap resource.
BOOL GetRawBuffer(LPCTSTR pszType, LPCTSTR pszResName, LPVOID pBuf, size_t size) OVERRIDE
Retrieves the raw buffer for a resource.
A class representing an ASCII string.
Definition sstringw.h:96
Bitmap object interface.
Definition SRender-i.h:420
Interface for image data.
ResProvider对象