soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SMCListView.h
1#ifndef __SMCLISTVIEW__H__
2#define __SMCLISTVIEW__H__
3
4#include "core/SPanel.h"
5#include "core/SItemPanel.h"
6#include "SHeaderCtrl.h"
7
8SNSBEGIN
9
10/**
11 * @class SMCListView
12 * @brief Multi-Column List View Control
13 * @details A control that displays a list of items with multiple columns.
14 */
15class SOUI_EXP SMCListView
16 : public TPanelProxy<IMcListView>
17 , protected SHostProxy
18 , protected IItemContainer {
19 DEF_SOBJECT(SPanel, L"mclistview")
20
21 friend class SMCListViewDataSetObserver;
22
23 public:
24 /**
25 * @brief Constructor
26 */
28
29 /**
30 * @brief Destructor
31 */
32 virtual ~SMCListView();
33
34 public:
35 /**
36 * @brief Set the adapter for the list view
37 * @param adapter Pointer to the multi-column adapter
38 * @return TRUE if successful, FALSE otherwise
39 */
40 STDMETHOD_(BOOL, SetAdapter)(THIS_ IMcAdapter *adapter) OVERRIDE;
41
42 /**
43 * @brief Get the adapter for the list view
44 * @return Pointer to the multi-column adapter
45 */
46 STDMETHOD_(IMcAdapter *, GetAdapter)(THIS) SCONST OVERRIDE;
47
48 /**
49 * @brief Get the item locator for the list view
50 * @return Pointer to the item locator
51 */
52 STDMETHOD_(IListViewItemLocator *, GetItemLocator)(THIS) SCONST OVERRIDE;
53
54 /**
55 * @brief Set the item locator for the list view
56 * @param pItemLocator Pointer to the item locator
57 */
58 STDMETHOD_(void, SetItemLocator)(THIS_ IListViewItemLocator *pItemLocator) OVERRIDE;
59
60 /**
61 * @brief Ensure an item is visible
62 * @param iItem Index of the item to ensure visible
63 */
64 STDMETHOD_(void, EnsureVisible)(THIS_ int iItem) OVERRIDE;
65
66 /**
67 * @brief Set the selected item
68 * @param iItem Index of the item to select
69 * @param bNotify Whether to notify of the change
70 */
71 STDMETHOD_(void, SetSel)(THIS_ int iItem, BOOL bNotify = FALSE) OVERRIDE;
72
73 /**
74 * @brief Get the selected item
75 * @return Index of the selected item
76 */
77 STDMETHOD_(int, GetSel)(THIS) SCONST OVERRIDE;
78
79 /**
80 * @brief Hit test to determine the item under the mouse
81 * @param pt Pointer to the mouse coordinates
82 * @return Pointer to the item panel if found, NULL otherwise
83 */
84 STDMETHOD_(IItemPanel *, HitTest)(THIS_ const POINT *pt) SCONST OVERRIDE;
85
86 /**
87 * @brief Get the header control
88 * @return Pointer to the header control
89 */
90 STDMETHOD_(IHeaderCtrl *, GetIHeaderCtrl)(THIS) SCONST OVERRIDE;
91
92 /**
93 * @brief Insert a column
94 * @param nIndex Index at which to insert the column
95 * @param pszText Column title
96 * @param nWidth Column width
97 * @param fmt Format flags
98 * @param lParam Additional parameter
99 * @param bDpiAware DPI awareness flag
100 * @param fWeight Font weight
101 * @return Index of the inserted column
102 */
103 STDMETHOD_(int, InsertColumn)
104 (THIS_ int nIndex, LPCTSTR pszText, int nWidth, UINT fmt, LPARAM lParam = 0, BOOL bDpiAware = TRUE, float fWeight = 0.0f) OVERRIDE;
105
106 /**
107 * @brief Delete a specific column
108 * @param iCol Index of the column to delete
109 */
110 STDMETHOD_(void, DeleteColumn)(THIS_ int iCol) OVERRIDE;
111
112 /**
113 * @brief Get the total number of columns
114 * @return Number of columns
115 */
116 STDMETHOD_(int, GetColumnCount)(THIS) SCONST OVERRIDE;
117
118 /**
119 * @brief Get the desired size of the control
120 * @param psz Output size
121 * @param nParentWid Parent container width
122 * @param nParentHei Parent container height
123 */
124 STDMETHOD_(void, GetDesiredSize)(THIS_ SIZE *psz, int nParentWid, int nParentHei) OVERRIDE;
125
126 public:
127 /**
128 * @brief Hit test to determine the item under the mouse
129 * @param pt Mouse coordinates
130 * @return Pointer to the item panel if found, NULL otherwise
131 */
132 SItemPanel *HitTest(CPoint &pt) const;
133
134 /**
135 * @brief Get the header control
136 * @return Pointer to the header control
137 */
138 SHeaderCtrl *GetHeaderCtrl() const;
139
140 /**
141 * @brief Update visible items
142 */
143 void UpdateVisibleItems();
144
145 /**
146 * @brief Update a specific visible item
147 * @param iItem Index of the item
148 */
149 void UpdateVisibleItem(int iItem);
150
151 protected:
152 /**
153 * @brief Handle item capture
154 * @param pItem Pointer to the item panel
155 * @param bCapture Capture flag
156 */
157 virtual void OnItemSetCapture(SOsrPanel *pItem, BOOL bCapture);
158
159 /**
160 * @brief Get the rectangle of an item
161 * @param pItem Pointer to the item panel
162 * @param rcItem Output rectangle
163 * @return TRUE if successful, FALSE otherwise
164 */
165 virtual BOOL OnItemGetRect(const SOsrPanel *pItem, CRect &rcItem) const;
166
167 /**
168 * @brief Check if item redraw is delayed
169 * @return TRUE if redraw is delayed, FALSE otherwise
170 */
171 virtual BOOL IsItemRedrawDelay() const;
172
173 protected:
174 /**
175 * @brief Handle data set changed event
176 */
177 void onDataSetChanged();
178
179 /**
180 * @brief Handle data set invalidated event
181 */
183
184 /**
185 * @brief Handle item data changed event
186 * @param iItem Index of the item
187 */
188 void onItemDataChanged(int iItem);
189
190 protected:
191 /**
192 * @brief Handle item click event
193 * @param pEvt Event arguments
194 * @return TRUE if handled, FALSE otherwise
195 */
196 BOOL OnItemClick(IEvtArgs *pEvt);
197
198 protected:
199 /**
200 * @brief Handle scroll event
201 * @param bVertical Whether the scroll is vertical
202 * @param uCode Scroll type
203 * @param nPos Scroll position
204 * @return TRUE if handled, FALSE otherwise
205 */
206 virtual BOOL OnScroll(BOOL bVertical, UINT uCode, int nPos);
207
208 /**
209 * @brief Get the scroll line size
210 * @param bVertical Whether the scroll is vertical
211 * @return Scroll line size
212 */
213 virtual int GetScrollLineSize(BOOL bVertical);
214
215 /**
216 * @brief Create child items from XML configuration
217 * @param xmlNode XML node for the child items
218 * @return TRUE if successful, FALSE otherwise
219 */
220 virtual BOOL CreateChildren(SXmlNode xmlNode);
221
222 /**
223 * @brief Update tooltip information
224 * @param pt Mouse coordinates
225 * @param tipInfo Tooltip information
226 * @return TRUE if handled, FALSE otherwise
227 */
228 virtual BOOL UpdateToolTip(CPoint pt, SwndToolTipInfo &tipInfo);
229
230 /**
231 * @brief Get the dialog code
232 * @return Dialog code
233 */
234 virtual UINT WINAPI OnGetDlgCode() const;
235
236 /**
237 * @brief Handle set cursor event
238 * @param pt Mouse coordinates
239 * @return TRUE if handled, FALSE otherwise
240 */
241 virtual BOOL OnSetCursor(const CPoint &pt);
242
243 /**
244 * @brief Handle colorization event
245 * @param cr Color reference
246 */
247 virtual void OnColorize(COLORREF cr);
248
249 /**
250 * @brief Handle scale change event
251 * @param nScale Scale factor
252 */
253 virtual void OnScaleChanged(int nScale);
254
255 /**
256 * @brief Handle language change event
257 * @return HRESULT
258 */
259 virtual HRESULT OnLanguageChanged();
260
261 /**
262 * @brief Handle rebuild font event
263 */
264 virtual void OnRebuildFont();
265
266 protected:
267 /**
268 * @brief Dispatch messages to items
269 * @param uMsg Message identifier
270 * @param wParam Additional message-specific information
271 * @param lParam Additional message-specific information
272 */
273 void DispatchMessage2Items(UINT uMsg, WPARAM wParam, LPARAM lParam);
274
275 /**
276 * @brief Update the scroll bar
277 */
278 void UpdateScrollBar();
279
280 /**
281 * @brief Redraw a specific item
282 * @param pItem Pointer to the item panel
283 */
284 void RedrawItem(SOsrPanel *pItem);
285
286 /**
287 * @brief Get the item panel for a specific item
288 * @param iItem Index of the item
289 * @return Pointer to the item panel
290 */
291 SItemPanel *GetItemPanel(int iItem);
292
293 /**
294 * @brief Paint the control
295 * @param pRT Rendering target handle
296 */
297 void OnPaint(IRenderTarget *pRT);
298
299 /**
300 * @brief Handle size change event
301 * @param nType Size change type
302 * @param size New size
303 */
304 void OnSize(UINT nType, CSize size);
305
306 /**
307 * @brief Handle destroy event
308 */
309 void OnDestroy();
310
311 /**
312 * @brief Handle mouse event
313 * @param uMsg Message identifier
314 * @param wParam Additional message-specific information
315 * @param lParam Additional message-specific information
316 * @return Result of the message processing
317 */
318 LRESULT OnMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam);
319
320 /**
321 * @brief Handle key event
322 * @param uMsg Message identifier
323 * @param wParam Additional message-specific information
324 * @param lParam Additional message-specific information
325 * @return Result of the message processing
326 */
327 LRESULT OnKeyEvent(UINT uMsg, WPARAM wParam, LPARAM lParam);
328
329 /**
330 * @brief Handle key down event
331 * @param nChar Key code
332 * @param nRepCnt Repeat count
333 * @param nFlags Flags
334 */
335 void OnKeyDown(TCHAR nChar, UINT nRepCnt, UINT nFlags);
336
337 /**
338 * @brief Handle mouse leave event
339 */
340 void OnMouseLeave();
341
342 /**
343 * @brief Handle mouse wheel event
344 * @param nFlags Flags
345 * @param zDelta Delta value
346 * @param pt Mouse coordinates
347 * @return TRUE if handled, FALSE otherwise
348 */
349 BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
350
351 /**
352 * @brief Handle kill focus event
353 * @param wndFocus New focus window handle
354 */
355 void OnKillFocus(SWND wndFocus);
356
357 /**
358 * @brief Handle set focus event
359 * @param wndOld Previous focus window handle
360 */
361 void OnSetFocus(SWND wndOld);
362
363 /**
364 * @brief Handle show window event
365 * @param bShow Show flag
366 * @param nStatus Status code
367 */
368 void OnShowWindow(BOOL bShow, UINT nStatus);
369
370 SOUI_MSG_MAP_BEGIN()
371 MSG_WM_PAINT_EX(OnPaint)
372 MSG_WM_SIZE(OnSize)
373 MSG_WM_DESTROY(OnDestroy)
374 MSG_WM_MOUSEWHEEL(OnMouseWheel)
375 MSG_WM_MOUSELEAVE(OnMouseLeave)
376 MSG_WM_KEYDOWN(OnKeyDown)
377 MSG_WM_SETFOCUS_EX(OnSetFocus)
378 MSG_WM_KILLFOCUS_EX(OnKillFocus)
379 MSG_WM_SHOWWINDOW(OnShowWindow)
380 MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseEvent)
381 MESSAGE_RANGE_HANDLER_EX(WM_KEYFIRST, WM_KEYLAST, OnKeyEvent)
382 MESSAGE_RANGE_HANDLER_EX(WM_IME_STARTCOMPOSITION, WM_IME_KEYLAST, OnKeyEvent)
383 MESSAGE_HANDLER_EX(WM_IME_CHAR, OnKeyEvent)
384 MESSAGE_HANDLER_EX(WM_IME_REQUEST, OnKeyEvent)
385 SOUI_MSG_MAP_END()
386
387 SOUI_ATTRS_BEGIN()
388 ATTR_LAYOUTSIZE(L"headerHeight", m_nHeaderHeight, FALSE)
389 ATTR_INT(L"hotTrack", m_bHotTrack, FALSE)
390 ATTR_SKIN(L"dividerSkin", m_pSkinDivider, TRUE)
391 ATTR_LAYOUTSIZE(L"dividerSize", m_nDividerSize, FALSE)
392 ATTR_INT(L"wantTab", m_bWantTab, FALSE)
393 ATTR_COLOR(L"colorGrid", m_crGrid, TRUE)
394 SOUI_ATTRS_END()
395
396 protected:
397 SAutoRefPtr<IMcAdapter> m_adapter; /**< Pointer to the multi-column adapter */
398 SAutoRefPtr<ILvDataSetObserver> m_observer; /**< Pointer to the data set observer */
399 SAutoRefPtr<IListViewItemLocator> m_lvItemLocator; /**< Pointer to the item locator */
400
401 struct ItemInfo
402 {
403 SItemPanel *pItem; /**< Pointer to the item panel */
404 int nType; /**< Type of the item */
405 };
406
407 bool m_bPendingUpdate; /**< Flag indicating pending update */
408 int m_iPendingUpdateItem; /**< Index of the item to update, -1 for all, -2 for nothing */
409 int m_iPendingViewItem; /**< Index of the item to view, -1 for init */
410
411 int m_iFirstVisible; /**< Index of the first visible item */
412 SList<ItemInfo> m_lstItems; /**< List of currently visible items */
413 SOsrPanel *m_itemCapture; /**< Item panel that has been set capture */
414
415 int m_iSelItem; /**< Index of the selected item */
416 SOsrPanel *m_pHoverItem; /**< Item panel under the mouse */
417
418 SArray<SList<SItemPanel *> *> m_itemRecycle; /**< Recycle bin for item panels */
419
420 SXmlDoc m_xmlTemplate; /**< XML template for items */
421 SAutoRefPtr<ISkinObj> m_pSkinDivider; /**< Skin for dividers */
422 SLayoutSize m_nDividerSize; /**< Size of dividers */
423 BOOL m_bWantTab; /**< Flag indicating whether to want tab */
424 BOOL m_bDatasetInvalidated; /**< Flag indicating data set is invalidated */
425 COLORREF m_crGrid; /**< Grid color */
426
427 protected:
428 /**
429 * @brief Handle header click event
430 * @param pEvt Event arguments
431 * @return TRUE if handled, FALSE otherwise
432 */
433 BOOL OnHeaderClick(IEvtArgs *pEvt);
434
435 /**
436 * @brief Handle header size changing event
437 * @param pEvt Event arguments
438 * @return TRUE if handled, FALSE otherwise
439 */
440 BOOL OnHeaderSizeChanging(IEvtArgs *pEvt);
441
442 /**
443 * @brief Handle header swap event
444 * @param pEvt Event arguments
445 * @return TRUE if handled, FALSE otherwise
446 */
447 BOOL OnHeaderSwap(IEvtArgs *pEvt);
448
449 /**
450 * @brief Get the rectangle of the list
451 * @return Rectangle of the list
452 */
453 CRect GetListRect();
454
455 /**
456 * @brief Update the header control
457 */
458 void UpdateHeaderCtrl();
459
460 /**
461 * @brief Update the position of child items
462 */
463 STDMETHOD_(void, UpdateChildrenPosition)(THIS) OVERRIDE;
464
465 /**
466 * @brief Get the height of the header
467 * @return Height of the header
468 */
469 int GetHeaderHeight() const;
470
471 protected:
472 /**
473 * @brief Get the rectangle of an item by position
474 * @param iPosition Position of the item
475 * @return Rectangle of the item
476 */
477 CRect _OnItemGetRect(int iPosition) const;
478
479 /**
480 * @brief Update the column widths in the adapter
481 */
482 void _UpdateAdapterColumnsWidth() const;
483
484 protected:
485 SHeaderCtrl *m_pHeader; /**< Pointer to the header control */
486 SLayoutSize m_nHeaderHeight; /**< Height of the header */
487 BOOL m_bHotTrack; /**< Hot tracking flag */
488};
489
490SNSEND
491
492#endif // __SMCLISTVIEW__H__
SOUI Panel with Scrollbar Support.
Smart pointer class for managing COM-style reference-counted objects.
Header Control.
Definition SHeaderCtrl.h:18
布局大小类
Definition SLayoutSize.h:10
int m_iPendingViewItem
void GetDesiredSize(SIZE *psz, int nParentWid, int nParentHei) OVERRIDE
Get the desired size of the control.
void UpdateVisibleItems()
Update visible items.
SHeaderCtrl * GetHeaderCtrl() const
Get the header control.
SList< ItemInfo > m_lstItems
BOOL OnItemClick(IEvtArgs *pEvt)
Handle item click event.
SArray< SList< SItemPanel * > * > m_itemRecycle
virtual BOOL OnItemGetRect(const SOsrPanel *pItem, CRect &rcItem) const
Get the rectangle of an item.
IHeaderCtrl * GetIHeaderCtrl() SCONST OVERRIDE
Get the header control.
SItemPanel * GetItemPanel(int iItem)
Get the item panel for a specific item.
void UpdateChildrenPosition() OVERRIDE
Update the position of child items.
void onDataSetChanged()
Handle data set changed event.
int GetSel() SCONST OVERRIDE
Get the selected item.
SXmlDoc m_xmlTemplate
SAutoRefPtr< IListViewItemLocator > m_lvItemLocator
void SetSel(int iItem, BOOL bNotify=FALSE) OVERRIDE
Set the selected item.
SOsrPanel * m_pHoverItem
CRect GetListRect()
Get the rectangle of the list.
int m_iFirstVisible
void OnShowWindow(BOOL bShow, UINT nStatus)
Handle show window event.
void OnKillFocus(SWND wndFocus)
Handle kill focus event.
LRESULT OnKeyEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handle key event.
int GetColumnCount() SCONST OVERRIDE
Get the total number of columns.
BOOL m_bDatasetInvalidated
void DispatchMessage2Items(UINT uMsg, WPARAM wParam, LPARAM lParam)
Dispatch messages to items.
void _UpdateAdapterColumnsWidth() const
Update the column widths in the adapter.
void UpdateHeaderCtrl()
Update the header control.
BOOL OnHeaderClick(IEvtArgs *pEvt)
Handle header click event.
SLayoutSize m_nHeaderHeight
virtual BOOL IsItemRedrawDelay() const
Check if item redraw is delayed.
int GetHeaderHeight() const
Get the height of the header.
BOOL SetAdapter(IMcAdapter *adapter) OVERRIDE
Set the adapter for the list view.
bool m_bPendingUpdate
void UpdateScrollBar()
Update the scroll bar.
SHeaderCtrl * m_pHeader
void UpdateVisibleItem(int iItem)
Update a specific visible item.
BOOL OnHeaderSizeChanging(IEvtArgs *pEvt)
Handle header size changing event.
virtual void OnItemSetCapture(SOsrPanel *pItem, BOOL bCapture)
Handle item capture.
void onDataSetInvalidated()
Handle data set invalidated event.
SAutoRefPtr< IMcAdapter > m_adapter
void OnSize(UINT nType, CSize size)
Handle size change event.
void RedrawItem(SOsrPanel *pItem)
Redraw a specific item.
BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
Handle mouse wheel event.
void OnPaint(IRenderTarget *pRT)
Paint the control.
int InsertColumn(int nIndex, LPCTSTR pszText, int nWidth, UINT fmt, LPARAM lParam=0, BOOL bDpiAware=TRUE, float fWeight=0.0f) OVERRIDE
Insert a column.
COLORREF m_crGrid
SMCListView()
Constructor.
void DeleteColumn(int iCol) OVERRIDE
Delete a specific column.
CRect _OnItemGetRect(int iPosition) const
Get the rectangle of an item by position.
void OnSetFocus(SWND wndOld)
Handle set focus event.
void EnsureVisible(int iItem) OVERRIDE
Ensure an item is visible.
void SetItemLocator(IListViewItemLocator *pItemLocator) OVERRIDE
Set the item locator for the list view.
void OnMouseLeave()
Handle mouse leave event.
SAutoRefPtr< ISkinObj > m_pSkinDivider
void onItemDataChanged(int iItem)
Handle item data changed event.
int m_iPendingUpdateItem
IItemPanel * HitTest(const POINT *pt) SCONST OVERRIDE
Hit test to determine the item under the mouse.
BOOL OnHeaderSwap(IEvtArgs *pEvt)
Handle header swap event.
void OnDestroy()
Handle destroy event.
IMcAdapter * GetAdapter() SCONST OVERRIDE
Get the adapter for the list view.
IListViewItemLocator * GetItemLocator() SCONST OVERRIDE
Get the item locator for the list view.
SOsrPanel * m_itemCapture
SLayoutSize m_nDividerSize
LRESULT OnMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handle mouse event.
SAutoRefPtr< ILvDataSetObserver > m_observer
void OnKeyDown(TCHAR nChar, UINT nRepCnt, UINT nFlags)
Handle key down event.
virtual int GetScrollLineSize(BOOL bVertical)
Gets the line size for scrolling.
Definition SPanel.cpp:616
virtual void OnColorize(COLORREF cr)
Handles colorization events.
Definition SPanel.cpp:631
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
BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
Handles the WM_MOUSEWHEEL message.
Definition SPanel.cpp:484
virtual BOOL OnScroll(BOOL bVertical, UINT uCode, int nPos)
Handles scroll events.
Definition SPanel.cpp:517
void OnDestroy()
Handles the WM_DESTROY message.
Definition SPanel.cpp:326
UINT OnGetDlgCode() SCONST OVERRIDE
Retrieves the dialog code for the window.
Definition Swnd.cpp:1991
virtual BOOL UpdateToolTip(CPoint pt, SwndToolTipInfo &tipInfo)
Handle tooltip updates.
Definition Swnd.cpp:277
void OnKillFocus(SWND wndFocus)
Handles losing focus.
Definition Swnd.cpp:2274
void OnPaint(IRenderTarget *pRT)
Handles the painting of the window.
Definition Swnd.cpp:1785
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
virtual void OnRebuildFont()
Called when the font of the window needs to be rebuilt.
Definition Swnd.cpp:3303
virtual BOOL OnSetCursor(const CPoint &pt)
Sets the cursor when the mouse hovers over the window.
Definition Swnd.cpp:429
virtual BOOL CreateChildren(SXmlNode xmlNode)
Create child windows from XML node.
Definition Swnd.cpp:823
void OnSetFocus(SWND wndOld)
Handles gaining focus.
Definition Swnd.cpp:2265
Implementation of IXmlDoc.
Definition SXml.h:912
Class representing an XML node.
Definition SXml.h:352
Interface for rendering target objects.
Definition SRender-i.h:1440
Information for window tooltips.
Definition SWnd.h:208