soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SHeaderCtrl.h
1#ifndef __SHEADERCTRL__H__
2#define __SHEADERCTRL__H__
3
4#include <core/SWnd.h>
5#include <interface/SCtrl-i.h>
6#include <proxy/SWindowProxy.h>
7
8SNSBEGIN
9
10#define SORT_MASK (HDF_SORTDOWN | HDF_SORTUP)
11#define ALIGN_MASK (HDF_LEFT | HDF_RIGHT | HDF_CENTER)
12
13/**
14 * @class SHeaderCtrl
15 * @brief Header Control
16 * @details A header control that manages columns with titles and sorting indicators.
17 */
18class SOUI_EXP SHeaderCtrl : public TWindowProxy<IHeaderCtrl> {
19 DEF_SOBJECT(SWindow, L"header")
20
21 enum
22 {
23 MARGIN_ADJUST_ENABLE = 4,
24 MARGIN_ADJUST_DISABLE = 2,
25 };
26
27 typedef struct SHDITEMEX : public SHDITEM
28 {
29 STrText strText;
30 } * LPSHDITEMEX;
31
32 public:
33 /**
34 * @brief Constructor
35 */
36 SHeaderCtrl(void);
37
38 /**
39 * @brief Destructor
40 */
41 ~SHeaderCtrl(void);
42
43 public:
44 /**
45 * @brief Insert a new item
46 * @param iItem Index of the new item
47 * @param pszText Title of the new item
48 * @param nWidth Width of the new item
49 * @param fmt Format flag
50 * @param lParam Additional parameter
51 * @param bDpiAware DPI awareness flag
52 * @param fWeight Font weight
53 * @return Index of the inserted item
54 */
55 STDMETHOD_(int, InsertItem)
56 (THIS_ int iItem, LPCTSTR pszText, int nWidth, UINT fmt, LPARAM lParam, BOOL bDpiAware = FALSE, float fWeight = 0.0f) OVERRIDE;
57
58 /**
59 * @brief Insert a new item (ANSI version)
60 * @param iItem Index of the new item
61 * @param pszText Title of the new item
62 * @param nWidth Width of the new item
63 * @param fmt Format flag
64 * @param lParam Additional parameter
65 * @param bDpiAware DPI awareness flag
66 * @param fWeight Font weight
67 * @return Index of the inserted item
68 */
69 STDMETHOD_(int, InsertItemA)
70 (THIS_ int iItem, LPCSTR pszText, int nWidth, UINT fmt, LPARAM lParam, BOOL bDpiAware = FALSE, float fWeight = 0.0f) OVERRIDE
71 {
72 SStringT str = S_CA2T(pszText, CP_UTF8);
73 return InsertItem(iItem, str, nWidth, fmt, lParam, bDpiAware, fWeight);
74 }
75
76 /**
77 * @brief Get an item
78 * @param iItem Index of the item
79 * @param pItem Output structure for the item
80 * @return TRUE if successful, FALSE otherwise
81 */
82 STDMETHOD_(BOOL, GetItem)(THIS_ int iItem, SHDITEM *pItem) SCONST OVERRIDE;
83
84 /**
85 * @brief Set an item
86 * @param iItem Index of the item
87 * @param pItem Structure for the item
88 * @return TRUE if successful, FALSE otherwise
89 */
90 STDMETHOD_(BOOL, SetItem)(THIS_ int iItem, const SHDITEM *pItem) OVERRIDE;
91
92 /**
93 * @brief Get the number of items
94 * @return Number of items
95 */
96 STDMETHOD_(UINT, GetItemCount)(THIS) SCONST OVERRIDE;
97
98 /**
99 * @brief Get the total width of all items
100 * @param bMinWid Whether to get the minimum width
101 * @return Total width
102 */
103 STDMETHOD_(int, GetTotalWidth)(THIS_ BOOL bMinWid = FALSE) SCONST OVERRIDE;
104
105 /**
106 * @brief Check if auto-resize is enabled
107 * @return TRUE if auto-resize is enabled, FALSE otherwise
108 */
109 STDMETHOD_(BOOL, IsAutoResize)(THIS) SCONST OVERRIDE;
110
111 /**
112 * @brief Get the width of a specific item
113 * @param iItem Index of the item
114 * @return Width of the item
115 */
116 STDMETHOD_(int, GetItemWidth)(THIS_ int iItem) SCONST OVERRIDE;
117
118 /**
119 * @brief Delete a specific item
120 * @param iItem Index of the item to delete
121 * @return TRUE if successful, FALSE otherwise
122 */
123 STDMETHOD_(BOOL, DeleteItem)(THIS_ int iItem) OVERRIDE;
124
125 /**
126 * @brief Delete all items
127 */
128 STDMETHOD_(void, DeleteAllItems)(THIS) OVERRIDE;
129
130 /**
131 * @brief Set the sort flag for an item
132 * @param iItem Index of the item
133 * @param sortFlag Sort flag
134 */
135 STDMETHOD_(void, SetItemSort)(THIS_ int iItem, UINT sortFlag) OVERRIDE;
136
137 /**
138 * @brief Set the visibility of an item
139 * @param iItem Index of the item
140 * @param visible Visibility flag
141 */
142 STDMETHOD_(void, SetItemVisible)(THIS_ int iItem, BOOL visible) OVERRIDE;
143
144 /**
145 * @brief Check if an item is visible
146 * @param iItem Index of the item
147 * @return TRUE if visible, FALSE otherwise
148 */
149 STDMETHOD_(BOOL, IsItemVisible)(THIS_ int iItem) SCONST OVERRIDE;
150
151 /**
152 * @brief Get the original item index from the order
153 * @param iOrder Order index
154 * @return Original item index
155 */
156 STDMETHOD_(int, GetOriItemIndex)(CTHIS_ int iOrder) SCONST OVERRIDE;
157
158 /**
159 * @brief Get the rectangle of an item
160 * @param iItem Index of the item
161 * @param prc Output rectangle
162 */
163 STDMETHOD_(void, GetItemRect)(CTHIS_ int iItem, LPRECT prc) SCONST OVERRIDE;
164
165 public:
166 /**
167 * @brief Get the rectangle of an item
168 * @param iItem Index of the item
169 * @return Rectangle of the item
170 */
171 CRect GetItemRect(int iItem) const;
172
173 SOUI_ATTRS_BEGIN()
174 ATTR_SKIN(L"itemSkin", m_pSkinItem, FALSE)
175 ATTR_SKIN(L"sortSkin", m_pSkinSort, FALSE)
176 ATTR_INT(L"fixWidth", m_bFixWidth, FALSE)
177 ATTR_INT(L"itemSwapEnable", m_bItemSwapEnable, FALSE)
178 ATTR_INT(L"sortHeader", m_bSortHeader, FALSE)
179 SOUI_ATTRS_END()
180
181 protected:
182 /**
183 * @brief Create child items from XML configuration
184 * @param xmlNode XML node for the child items
185 * @return TRUE if successful, FALSE otherwise
186 */
187 virtual BOOL CreateChildren(SXmlNode xmlNode);
188
189 /**
190 * @brief Set the cursor based on the mouse position
191 * @param pt Mouse coordinates
192 * @return TRUE if successful, FALSE otherwise
193 */
194 virtual BOOL OnSetCursor(const CPoint &pt);
195
196 /**
197 * @brief Paint the control
198 * @param pRT Rendering target handle
199 */
200 void OnPaint(IRenderTarget *pRT);
201
202 /**
203 * @brief Draw an item
204 * @param pRT Rendering target handle
205 * @param rcItem Rectangle for the item
206 * @param pItem Pointer to the item structure
207 */
208 virtual void DrawItem(IRenderTarget *pRT, CRect rcItem, const LPSHDITEMEX pItem);
209
210 /**
211 * @brief Handle colorization event
212 * @param cr Color reference
213 */
214 virtual void OnColorize(COLORREF cr);
215
216 /**
217 * @brief Handle language change event
218 * @return HRESULT
219 */
220 virtual HRESULT OnLanguageChanged();
221
222 /**
223 * @brief Handle scale change event
224 * @param nScale Scale factor
225 */
226 virtual void OnScaleChanged(int nScale);
227
228 /**
229 * @brief Handle relayout event
230 * @param rcWnd Window rectangle
231 * @return TRUE if successful, FALSE otherwise
232 */
233 virtual BOOL OnRelayout(const CRect &rcWnd);
234
235 /**
236 * @brief Hit test to determine the item under the mouse
237 * @param pt Mouse coordinates
238 * @return Hit test result (DWORD)
239 */
240 DWORD HitTest(CPoint pt);
241
242 /**
243 * @brief Redraw a specific item
244 * @param iItem Index of the item to redraw
245 */
246 void RedrawItem(int iItem);
247
248 /**
249 * @brief Draw the dragging state
250 * @param dwDragTo Drag target
251 */
252 void DrawDraggingState(DWORD dwDragTo);
253
254 /**
255 * @brief Check if an item is in hover state
256 * @param dwHitTest Hit test result
257 * @return TRUE if in hover state, FALSE otherwise
258 */
259 BOOL IsItemHover(DWORD dwHitTest)
260 {
261 return dwHitTest != -1 && LOWORD(dwHitTest) == HIWORD(dwHitTest);
262 }
263
264 /**
265 * @brief Create a drag image for an item
266 * @param iItem Index of the item
267 * @return Handle to the drag image
268 */
269 HBITMAP CreateDragImage(UINT iItem);
270
271 /**
272 * @brief Handle left mouse button down event
273 * @param nFlags Flags
274 * @param pt Mouse coordinates
275 */
276 void OnLButtonDown(UINT nFlags, CPoint pt);
277
278 /**
279 * @brief Handle left mouse button up event
280 * @param nFlags Flags
281 * @param pt Mouse coordinates
282 */
283 void OnLButtonUp(UINT nFlags, CPoint pt);
284
285 /**
286 * @brief Handle mouse move event
287 * @param nFlags Flags
288 * @param pt Mouse coordinates
289 */
290 void OnMouseMove(UINT nFlags, CPoint pt);
291
292 /**
293 * @brief Handle mouse leave event
294 */
295 void OnMouseLeave();
296
297 /**
298 * @brief Handle destroy event
299 */
300 void OnDestroy();
301
302 /**
303 * @brief Handle activate application event
304 * @param bActive Activation flag
305 * @param dwThreadID Thread ID
306 */
307 void OnActivateApp(BOOL bActive, DWORD dwThreadID);
308
309 SOUI_MSG_MAP_BEGIN()
310 MSG_WM_PAINT_EX(OnPaint)
311 MSG_WM_LBUTTONDOWN(OnLButtonDown)
312 MSG_WM_LBUTTONUP(OnLButtonUp)
313 MSG_WM_MOUSEMOVE(OnMouseMove)
314 MSG_WM_MOUSELEAVE(OnMouseLeave)
315 MSG_WM_ACTIVATEAPP(OnActivateApp)
316 MSG_WM_DESTROY(OnDestroy)
317 SOUI_MSG_MAP_END()
318
319 protected:
320 SAutoRefPtr<ISkinObj> m_pSkinItem; /**< Skin for drawing header items */
321 SAutoRefPtr<ISkinObj> m_pSkinSort; /**< Skin for sorting indicators */
322 BOOL m_bSortHeader; /**< Whether header can be clicked to sort */
323 BOOL m_bFixWidth; /**< Whether item widths are fixed */
324 BOOL m_bItemSwapEnable; /**< Whether item swapping is enabled */
325
326 BOOL m_bDragging; /**< Dragging flag */
327 HBITMAP m_hDragImg; /**< Bitmap for drag image */
328 CPoint m_ptClick; /**< Click point */
329 DWORD m_dwHitTest; /**< Hit test result */
330 DWORD m_dwDragTo; /**< Drag target */
331 int m_nAdjItemOldWidth; /**< Original width of the dragged item */
332 SArray<SHDITEMEX> m_arrItems; /**< Array of header items */
333 int m_nScale; /**< Current scale factor */
334};
335
336SNSEND
337
338#endif // __SHEADERCTRL__H__
SOUI基础DUI窗口模块
Smart pointer class for managing COM-style reference-counted objects.
BOOL IsItemHover(DWORD dwHitTest)
Check if an item is in hover state.
int InsertItem(int iItem, LPCTSTR pszText, int nWidth, UINT fmt, LPARAM lParam, BOOL bDpiAware=FALSE, float fWeight=0.0f) OVERRIDE
Insert a new item.
HBITMAP m_hDragImg
CPoint m_ptClick
BOOL m_bItemSwapEnable
DWORD m_dwHitTest
SArray< SHDITEMEX > m_arrItems
DWORD m_dwDragTo
SHeaderCtrl(void)
Constructor.
int m_nAdjItemOldWidth
SAutoRefPtr< ISkinObj > m_pSkinSort
SAutoRefPtr< ISkinObj > m_pSkinItem
BOOL m_bSortHeader
int InsertItemA(int iItem, LPCSTR pszText, int nWidth, UINT fmt, LPARAM lParam, BOOL bDpiAware=FALSE, float fWeight=0.0f) OVERRIDE
Insert a new item (ANSI version)
Definition SHeaderCtrl.h:70
Class for handling text with translation support.
Definition SWnd.h:230
void OnMouseMove(UINT nFlags, CPoint pt)
Handles the mouse move event.
Definition Swnd.cpp:2131
void OnDestroy()
Handles the destruction of the window.
Definition Swnd.cpp:1701
void OnMouseLeave()
Handles the mouse leave event.
Definition Swnd.cpp:2147
void OnLButtonUp(UINT nFlags, CPoint pt)
Handles the left mouse button up event.
Definition Swnd.cpp:2105
SWindow()
Constructor.
Definition Swnd.cpp:104
void OnLButtonDown(UINT nFlags, CPoint pt)
Handles the left mouse button down event.
Definition Swnd.cpp:2092
Class representing an XML node.
Definition SXml.h:352
Interface for rendering target objects.
Definition SRender-i.h:1440
Interface for Skin Objects.
Definition SSkinobj-i.h:29