soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SListbox.h
1#ifndef __SLISTBOX__H__
2#define __SLISTBOX__H__
3
4#include <core/SPanel.h>
5#include <proxy/SPanelProxy.h>
6#include <interface/SCtrl-i.h>
7
8SNSBEGIN
9
10/**
11 * @struct tagLBITEM
12 * @brief List Box Item Structure
13 * @details Structure representing an item in the list box.
14 */
15typedef struct tagLBITEM
16{
17 STrText strText; /**< Text of the item */
18 int nImage; /**< Icon index */
19 LPARAM lParam; /**< Additional parameter */
20
21 /**
22 * @brief Constructor
23 * @param pOwner Owner window pointer
24 */
26 : strText(pOwner)
27 {
28 nImage = -1;
29 lParam = 0;
30 }
31} LBITEM, *LPLBITEM;
32
33/**
34 * @class SListBox
35 * @brief List Box Control
36 * @details A control that displays a list of items from which the user can select one or more.
37 */
38class SOUI_EXP SListBox : public TPanelProxy<IListBox> {
39 public:
40 DEF_SOBJECT(SPanel, L"listbox")
41
42 /**
43 * @brief Constructor
44 */
45 SListBox();
46
47 /**
48 * @brief Destructor
49 */
50 virtual ~SListBox();
51
52 public:
53 /**
54 * @brief Get the number of items in the list box
55 * @return Number of items
56 */
57 STDMETHOD_(int, GetCount)(THIS) SCONST OVERRIDE;
58
59 /**
60 * @brief Get the index of the currently selected item
61 * @return Index of the selected item
62 */
63 STDMETHOD_(int, GetCurSel)(THIS) SCONST OVERRIDE;
64
65 /**
66 * @brief Set the currently selected item
67 * @param nIndex Index of the item to select
68 * @param bNotifyChange Whether to notify of the change
69 * @return TRUE if successful, FALSE otherwise
70 */
71 STDMETHOD_(BOOL, SetCurSel)(THIS_ int nIndex, BOOL bNotifyChange = FALSE) OVERRIDE;
72
73 /**
74 * @brief Get the index of the top visible item
75 * @return Index of the top visible item
76 */
77 STDMETHOD_(int, GetTopIndex)(THIS) SCONST OVERRIDE;
78
79 /**
80 * @brief Set the index of the top visible item
81 * @param nIndex Index of the top visible item
82 * @return TRUE if successful, FALSE otherwise
83 */
84 STDMETHOD_(BOOL, SetTopIndex)(THIS_ int nIndex) OVERRIDE;
85
86 /**
87 * @brief Get the height of the items
88 * @return Height of the items
89 */
90 STDMETHOD_(int, GetItemHeight)(THIS) SCONST OVERRIDE;
91
92 /**
93 * @brief Set the height of the items
94 * @param nItemHeight Height of the items
95 */
96 STDMETHOD_(void, SetItemHeight)(THIS_ int nItemHeight) OVERRIDE;
97
98 /**
99 * @brief Get the data associated with an item
100 * @param nIndex Index of the item
101 * @return Data associated with the item
102 */
103 STDMETHOD_(LPARAM, GetItemData)(THIS_ int nIndex) SCONST OVERRIDE;
104
105 /**
106 * @brief Set the data associated with an item
107 * @param nIndex Index of the item
108 * @param lParam Data to associate with the item
109 * @return TRUE if successful, FALSE otherwise
110 */
111 STDMETHOD_(BOOL, SetItemData)(THIS_ int nIndex, LPARAM lParam) OVERRIDE;
112
113 /**
114 * @brief Get the text of an item
115 * @param nIndex Index of the item
116 * @param bRawText Whether to get raw text
117 * @param str Output string for the item text
118 * @return TRUE if successful, FALSE otherwise
119 */
120 STDMETHOD_(BOOL, GetIText)(THIS_ int nIndex, BOOL bRawText, IStringT *str) SCONST OVERRIDE;
121
122 /**
123 * @brief Delete all items in the list box
124 */
125 STDMETHOD_(void, DeleteAll)(THIS) OVERRIDE;
126
127 /**
128 * @brief Delete a specific item
129 * @param nIndex Index of the item to delete
130 * @return TRUE if successful, FALSE otherwise
131 */
132 STDMETHOD_(BOOL, DeleteString)(THIS_ int nIndex) OVERRIDE;
133
134 /**
135 * @brief Add a string to the list box
136 * @param lpszItem Text of the item
137 * @param nImage Icon index
138 * @param lParam Additional parameter
139 * @return Index of the added item
140 */
141 STDMETHOD_(int, AddString)(THIS_ LPCTSTR lpszItem, int nImage = -1, LPARAM lParam = 0) OVERRIDE;
142
143 /**
144 * @brief Insert a string into the list box
145 * @param nIndex Index at which to insert the item
146 * @param lpszItem Text of the item
147 * @param nImage Icon index
148 * @param lParam Additional parameter
149 * @return Index of the inserted item
150 */
151 STDMETHOD_(int, InsertString)
152 (THIS_ int nIndex, LPCTSTR lpszItem, int nImage = -1, LPARAM lParam = 0) OVERRIDE;
153
154 /**
155 * @brief Ensure an item is visible
156 * @param nIndex Index of the item to ensure visible
157 */
158 STDMETHOD_(void, EnsureVisible)(THIS_ int nIndex) OVERRIDE;
159
160 /**
161 * @brief Find a string in the list box
162 * @param iFindAfter Index after which to start searching
163 * @param pszText String to find
164 * @return Index of the found item or -1 if not found
165 */
166 STDMETHOD_(int, FindString)(THIS_ int iFindAfter, LPCTSTR pszText) SCONST OVERRIDE;
167
168 /**
169 * @brief Get the desired size of the control
170 * @param psz Output size
171 * @param nParentWid Parent container width
172 * @param nParentHei Parent container height
173 */
174 STDMETHOD_(void, GetDesiredSize)(THIS_ SIZE *psz, int nParentWid, int nParentHei) OVERRIDE;
175
176 /**
177 * @brief Set the image of an item
178 * @param nIndex Index of the item
179 * @param iImage Icon index
180 * @return TRUE if successful, FALSE otherwise
181 */
182 STDMETHOD_(BOOL, SetItemImage)(THIS_ int nIndex, int iImage) OVERRIDE;
183
184 /**
185 * @brief Get the image of an item
186 * @param nIndex Index of the item
187 * @return Icon index
188 */
189 STDMETHOD_(int, GetItemImage)(THIS_ int nIndex) OVERRIDE;
190
191 public:
192 /**
193 * @brief Get the text of an item
194 * @param nIndex Index of the item
195 * @param bRawText Whether to get raw text
196 * @return Text of the item
197 */
198 SStringT GetText(int nIndex, BOOL bRawText = FALSE) const
199 {
200 SStringT strRet;
201 GetIText(nIndex, bRawText, &strRet);
202 return strRet;
203 }
204
205 protected:
206 /**
207 * @brief Redraw a specific item
208 * @param iItem Index of the item to redraw
209 */
210 void RedrawItem(int iItem);
211
212 /**
213 * @brief Hit test to determine the item under the mouse
214 * @param pt Mouse coordinates
215 * @return Index of the item or -1 if no item
216 */
217 int HitTest(CPoint &pt);
218
219 /**
220 * @brief Update the scroll bar
221 */
222 void UpdateScrollBar();
223
224 /**
225 * @brief Handle language change event
226 * @return HRESULT
227 */
228 virtual HRESULT OnLanguageChanged();
229
230 /**
231 * @brief Handle scale change event
232 * @param nScale Scale factor
233 */
234 void OnScaleChanged(int nScale) override;
235
236 /**
237 * @brief Create child items from XML configuration
238 * @param xmlNode XML node for the child items
239 * @return TRUE if successful, FALSE otherwise
240 */
241 virtual BOOL CreateChildren(SXmlNode xmlNode);
242
243 /**
244 * @brief Load attributes for an item from XML
245 * @param xmlNode XML node for the item
246 * @param pItem Pointer to the item structure
247 */
248 void LoadItemAttribute(SXmlNode xmlNode, LPLBITEM pItem);
249
250 /**
251 * @brief Insert a new item
252 * @param nIndex Index at which to insert the item
253 * @param pItem Pointer to the item structure
254 * @return Index of the inserted item
255 */
256 int InsertItem(int nIndex, LPLBITEM pItem);
257
258 /**
259 * @brief Draw an item
260 * @param pRT Rendering target handle
261 * @param rc Rectangle for the item
262 * @param iItem Index of the item
263 */
264 virtual void DrawItem(IRenderTarget *pRT, CRect &rc, int iItem);
265
266 /**
267 * @brief Notify of selection change
268 * @param nOldSel Old selected index
269 * @param nNewSel New selected index
270 */
271 void NotifySelChange(int nOldSel, int nNewSel);
272
273 /**
274 * @brief Get the dialog code
275 * @return Dialog code
276 */
277 virtual UINT WINAPI OnGetDlgCode() const;
278
279 protected:
280 /**
281 * @brief Handle size change event
282 * @param nType Size change type
283 * @param size New size
284 */
285 void OnSize(UINT nType, CSize size);
286
287 /**
288 * @brief Paint the control
289 * @param pRT Rendering target handle
290 */
291 void OnPaint(IRenderTarget *pRT);
292
293 /**
294 * @brief Handle left mouse button down event
295 * @param nFlags Flags
296 * @param pt Mouse coordinates
297 */
298 void OnLButtonDown(UINT nFlags, CPoint pt);
299
300 /**
301 * @brief Handle left mouse button double-click event
302 * @param nFlags Flags
303 * @param pt Mouse coordinates
304 */
305 void OnLButtonDbClick(UINT nFlags, CPoint pt);
306
307 /**
308 * @brief Handle left mouse button up event
309 * @param nFlags Flags
310 * @param pt Mouse coordinates
311 */
312 void OnLButtonUp(UINT nFlags, CPoint pt);
313
314 /**
315 * @brief Handle mouse move event
316 * @param nFlags Flags
317 * @param pt Mouse coordinates
318 */
319 void OnMouseMove(UINT nFlags, CPoint pt);
320
321 /**
322 * @brief Handle key down event
323 * @param nChar Key code
324 * @param nRepCnt Repeat count
325 * @param nFlags Flags
326 */
327 void OnKeyDown(TCHAR nChar, UINT nRepCnt, UINT nFlags);
328
329 /**
330 * @brief Handle character input event
331 * @param nChar Character code
332 * @param nRepCnt Repeat count
333 * @param nFlags Flags
334 */
335 void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
336
337 /**
338 * @brief Handle destroy event
339 */
340 void OnDestroy();
341
342 /**
343 * @brief Handle show window event
344 * @param bShow Show flag
345 * @param nStatus Status code
346 */
347 void OnShowWindow(BOOL bShow, UINT nStatus);
348
349 /**
350 * @brief Handle mouse leave event
351 */
352 void OnMouseLeave();
353
354 protected:
355 SArray<LPLBITEM> m_arrItems; /**< Array of items */
356
357 SLayoutSize m_itemHeight; /**< Height of the items */
358 int m_iSelItem; /**< Index of the selected item */
359 int m_iHoverItem; /**< Index of the item under the mouse */
360 int m_iScrollSpeed; /**< Scroll speed */
361 BOOL m_bHotTrack; /**< Hot tracking flag */
362
363 SLayoutSize m_ptIcon[2]; /**< Icon coordinates */
364 SLayoutSize m_ptText[2]; /**< Text coordinates */
365
366 COLORREF m_crItemBg; /**< Background color */
367 COLORREF m_crItemBg2; /**< Background color for even rows */
368 COLORREF m_crItemSelBg; /**< Selected item background color */
369 COLORREF m_crItemHotBg; /**< Hot item background color */
370 COLORREF m_crText; /**< Text color */
371 COLORREF m_crSelText; /**< Selected text color */
372 SAutoRefPtr<ISkinObj> m_pItemSkin, m_pIconSkin;
373
374 public:
375 SOUI_ATTRS_BEGIN()
376 ATTR_LAYOUTSIZE(L"itemHeight", m_itemHeight, FALSE)
377 ATTR_SKIN(L"itemSkin", m_pItemSkin, TRUE)
378 ATTR_SKIN(L"iconSkin", m_pIconSkin, TRUE)
379 ATTR_COLOR(L"colorItemBkgnd", m_crItemBg, FALSE)
380 ATTR_COLOR(L"colorItemBkgnd2", m_crItemBg2, FALSE)
381 ATTR_COLOR(L"colorItemSelBkgnd", m_crItemSelBg, FALSE)
382 ATTR_COLOR(L"colorItemHotBkgnd", m_crItemHotBg, FALSE)
383 ATTR_COLOR(L"colorText", m_crText, FALSE)
384 ATTR_COLOR(L"colorSelText", m_crSelText, FALSE)
385 ATTR_LAYOUTSIZE(L"icon-x", m_ptIcon[0], FALSE)
386 ATTR_LAYOUTSIZE(L"icon-y", m_ptIcon[1], FALSE)
387 ATTR_LAYOUTSIZE(L"text-x", m_ptText[0], FALSE)
388 ATTR_LAYOUTSIZE(L"text-y", m_ptText[1], FALSE)
389 ATTR_INT(L"hotTrack", m_bHotTrack, FALSE)
390 SOUI_ATTRS_END()
391
392 SOUI_MSG_MAP_BEGIN()
393 MSG_WM_DESTROY(OnDestroy)
394 MSG_WM_SIZE(OnSize)
395 MSG_WM_PAINT_EX(OnPaint)
396 MSG_WM_LBUTTONDOWN(OnLButtonDown)
397 MSG_WM_LBUTTONDBLCLK(OnLButtonDbClick)
398 MSG_WM_LBUTTONUP(OnLButtonUp)
399 MSG_WM_MOUSEMOVE(OnMouseMove)
400 MSG_WM_KEYDOWN(OnKeyDown)
401 MSG_WM_CHAR(OnChar)
402 MSG_WM_SHOWWINDOW(OnShowWindow)
403 MSG_WM_MOUSELEAVE(OnMouseLeave)
404 SOUI_MSG_MAP_END()
405};
406
407SNSEND
408
409#endif // __SLISTBOX__H__
SOUI Panel with Scrollbar Support.
Smart pointer class for managing COM-style reference-counted objects.
布局大小类
Definition SLayoutSize.h:10
BOOL GetIText(int nIndex, BOOL bRawText, IStringT *str) SCONST OVERRIDE
Get the text of an item.
Definition SListbox.cpp:127
void EnsureVisible(int nIndex) OVERRIDE
Ensure an item is visible.
Definition SListbox.cpp:204
int GetItemImage(int nIndex) OVERRIDE
Get the image of an item.
Definition SListbox.cpp:119
void OnPaint(IRenderTarget *pRT)
Paint the control.
Definition SListbox.cpp:451
COLORREF m_crItemSelBg
Definition SListbox.h:368
SLayoutSize m_ptText[2]
Definition SListbox.h:364
BOOL DeleteString(int nIndex) OVERRIDE
Delete a specific item.
Definition SListbox.cpp:164
COLORREF m_crItemBg2
Definition SListbox.h:367
int GetCount() SCONST OVERRIDE
Get the number of items in the list box.
Definition SListbox.cpp:42
COLORREF m_crSelText
Definition SListbox.h:371
SListBox()
Constructor.
Definition SListbox.cpp:15
COLORREF m_crItemHotBg
Definition SListbox.h:369
int GetTopIndex() SCONST OVERRIDE
Get the index of the top visible item.
Definition SListbox.cpp:79
void SetItemHeight(int nItemHeight) OVERRIDE
Set the height of the items.
Definition SListbox.cpp:142
int GetItemHeight() SCONST OVERRIDE
Get the height of the items.
Definition SListbox.cpp:137
void OnMouseMove(UINT nFlags, CPoint pt)
Handle mouse move event.
Definition SListbox.cpp:512
BOOL SetItemData(int nIndex, LPARAM lParam) OVERRIDE
Set the data associated with an item.
Definition SListbox.cpp:101
COLORREF m_crItemBg
Definition SListbox.h:366
int FindString(int iFindAfter, LPCTSTR pszText) SCONST OVERRIDE
Find a string in the list box.
Definition SListbox.cpp:250
LPARAM GetItemData(int nIndex) SCONST OVERRIDE
Get the data associated with an item.
Definition SListbox.cpp:93
SStringT GetText(int nIndex, BOOL bRawText=FALSE) const
Get the text of an item.
Definition SListbox.h:198
BOOL SetTopIndex(int nIndex) OVERRIDE
Set the index of the top visible item.
Definition SListbox.cpp:84
SLayoutSize m_ptIcon[2]
Definition SListbox.h:363
int m_iHoverItem
Definition SListbox.h:359
void OnLButtonDown(UINT nFlags, CPoint pt)
Handle left mouse button down event.
Definition SListbox.cpp:477
void OnSize(UINT nType, CSize size)
Handle size change event.
Definition SListbox.cpp:471
void OnMouseLeave()
Handle mouse leave event.
Definition SListbox.cpp:578
void OnKeyDown(TCHAR nChar, UINT nRepCnt, UINT nFlags)
Handle key down event.
Definition SListbox.cpp:528
SArray< LPLBITEM > m_arrItems
Definition SListbox.h:355
void DeleteAll() OVERRIDE
Delete all items in the list box.
Definition SListbox.cpp:148
int AddString(LPCTSTR lpszItem, int nImage=-1, LPARAM lParam=0) OVERRIDE
Add a string to the list box.
Definition SListbox.cpp:187
BOOL m_bHotTrack
Definition SListbox.h:361
int GetCurSel() SCONST OVERRIDE
Get the index of the currently selected item.
Definition SListbox.cpp:47
void GetDesiredSize(SIZE *psz, int nParentWid, int nParentHei) OVERRIDE
Get the desired size of the control.
Definition SListbox.cpp:644
void OnLButtonUp(UINT nFlags, CPoint pt)
Handle left mouse button up event.
Definition SListbox.cpp:488
void OnShowWindow(BOOL bShow, UINT nStatus)
Handle show window event.
Definition SListbox.cpp:569
int m_iScrollSpeed
Definition SListbox.h:360
COLORREF m_crText
Definition SListbox.h:370
int m_iSelItem
Definition SListbox.h:358
SLayoutSize m_itemHeight
Definition SListbox.h:357
int InsertString(int nIndex, LPCTSTR lpszItem, int nImage=-1, LPARAM lParam=0) OVERRIDE
Insert a string into the list box.
Definition SListbox.cpp:192
void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
Handle character input event.
Definition SListbox.cpp:551
BOOL SetItemImage(int nIndex, int iImage) OVERRIDE
Set the image of an item.
Definition SListbox.cpp:110
void OnLButtonDbClick(UINT nFlags, CPoint pt)
Handle left mouse button double-click event.
Definition SListbox.cpp:500
BOOL SetCurSel(int nIndex, BOOL bNotifyChange=FALSE) OVERRIDE
Set the currently selected item.
Definition SListbox.cpp:52
void OnDestroy()
Handle destroy event.
Definition SListbox.cpp:563
virtual void OnScaleChanged(int nScale)
Handles scale change events.
Definition SPanel.cpp:638
SPanel()
Constructor for SPanel.
Definition SPanel.cpp:165
void OnShowWindow(BOOL bShow, UINT nStatus)
Handles the WM_SHOWWINDOW message.
Definition SPanel.cpp:589
void OnDestroy()
Handles the WM_DESTROY message.
Definition SPanel.cpp:326
Class for handling text with translation support.
Definition SWnd.h:230
Base class for SOUI DUI windows.
Definition SWnd.h:286
UINT OnGetDlgCode() SCONST OVERRIDE
Retrieves the dialog code for the window.
Definition Swnd.cpp:1991
void OnMouseMove(UINT nFlags, CPoint pt)
Handles the mouse move event.
Definition Swnd.cpp:2131
void OnPaint(IRenderTarget *pRT)
Handles the painting of the window.
Definition Swnd.cpp:1785
void OnLButtonDbClick(UINT nFlags, CPoint point)
Handles the left mouse button double-click event.
Definition Swnd.cpp:2100
void OnMouseLeave()
Handles the mouse leave event.
Definition Swnd.cpp:2147
virtual HRESULT OnLanguageChanged()
Called when the language of the window changes.
Definition Swnd.cpp:3229
void OnSize(UINT nType, CSize size)
Handles the resizing of the window.
Definition Swnd.cpp:2844
void OnLButtonUp(UINT nFlags, CPoint pt)
Handles the left mouse button up event.
Definition Swnd.cpp:2105
void OnLButtonDown(UINT nFlags, CPoint pt)
Handles the left mouse button down event.
Definition Swnd.cpp:2092
virtual BOOL CreateChildren(SXmlNode xmlNode)
Create child windows from XML node.
Definition Swnd.cpp:823
Class representing an XML node.
Definition SXml.h:352
Interface for rendering target objects.
Definition SRender-i.h:1440
int nImage
Definition SListbox.h:18
tagLBITEM(SWindow *pOwner)
Constructor.
Definition SListbox.h:25
STrText strText
Definition SListbox.h:17
LPARAM lParam
Definition SListbox.h:19