soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
STileView.h
Go to the documentation of this file.
1/**
2 * @file STileView.h
3 * @brief Definition of the STileView class.
4 * @version v1.0
5 * @author soui
6 * @date 2014-07-06
7 *
8 * @copyright Copyright (C) 2014-2050 SOUI团队
9 * All rights reserved.
10 */
11
12#ifndef __STILEVIEW__H__
13#define __STILEVIEW__H__
14
15#include <core/SWnd.h>
16#include <core/SPanel.h>
17#include <core/SItemPanel.h>
18#include <interface/SAdapter-i.h>
19#include <helper/STileViewItemLocator.h>
20#include <proxy/SPanelProxy.h>
21
22SNSBEGIN
23
24/**
25 * @class STileView
26 * @brief A tile view control for displaying items in a grid layout.
27 *
28 * This class represents a tile view control that can display items in a grid layout with various customization options.
29 */
30class SOUI_EXP STileView
31 : public TPanelProxy<ITileView>
32 , protected SHostProxy
33 , protected IItemContainer {
34 DEF_SOBJECT(SPanel, L"tileview")
35
36 friend class STileViewDataSetObserver;
37
38 public:
39 /**
40 * @brief Constructor for STileView.
41 */
42 STileView();
43
44 /**
45 * @brief Destructor for STileView.
46 */
47 ~STileView();
48
49 public:
50 /**
51 * @brief Sets the adapter for the tile view.
52 * @param adapter Pointer to the adapter.
53 * @return TRUE if successful, otherwise FALSE.
54 */
55 STDMETHOD_(BOOL, SetAdapter)(THIS_ ILvAdapter *adapter) OVERRIDE;
56
57 /**
58 * @brief Gets the adapter for the tile view.
59 * @return Pointer to the adapter.
60 */
61 STDMETHOD_(ILvAdapter *, GetAdapter)(THIS) SCONST OVERRIDE;
62
63 /**
64 * @brief Sets the item locator for the tile view.
65 * @param pItemLocator Pointer to the item locator.
66 */
67 STDMETHOD_(void, SetItemLocator)(THIS_ ITileViewItemLocator *pItemLocator) OVERRIDE;
68
69 /**
70 * @brief Gets the item locator for the tile view.
71 * @return Pointer to the item locator.
72 */
73 STDMETHOD_(ITileViewItemLocator *, GetItemLocator)(THIS) SCONST OVERRIDE;
74
75 /**
76 * @brief Sets the selected item.
77 * @param iItem Index of the item to select.
78 * @param bNotify Flag indicating if a notification should be sent.
79 */
80 STDMETHOD_(void, SetSel)(THIS_ int iItem, BOOL bNotify = FALSE) OVERRIDE;
81
82 /**
83 * @brief Gets the selected item.
84 * @return Index of the selected item.
85 */
86 STDMETHOD_(int, GetSel)(THIS) SCONST OVERRIDE;
87
88 /**
89 * @brief Ensures the specified item is visible.
90 * @param iItem Index of the item to make visible.
91 */
92 STDMETHOD_(void, EnsureVisible)(THIS_ int iItem) OVERRIDE;
93
94 /**
95 * @brief Performs a hit test on the tile view.
96 * @param pt Pointer to the point to test.
97 * @return Pointer to the item panel at the specified point.
98 */
99 STDMETHOD_(IItemPanel *, HitTest)(THIS_ const POINT *pt) SCONST OVERRIDE;
100
101 public:
102 /**
103 * @brief Performs a hit test on the tile view.
104 * @param pt The point to test.
105 * @return Pointer to the item panel at the specified point.
106 */
107 SItemPanel *HitTest(CPoint &pt) const;
108
109 protected:
110 /**
111 * @brief Handles the capture of an item.
112 * @param pItem Pointer to the item panel.
113 * @param bCapture Flag indicating if the item should be captured.
114 */
115 virtual void OnItemSetCapture(SOsrPanel *pItem, BOOL bCapture);
116
117 /**
118 * @brief Gets the rectangle of an item.
119 * @param pItem Pointer to the item panel.
120 * @param rcItem Rectangle to receive the item position.
121 * @return TRUE if successful, otherwise FALSE.
122 */
123 virtual BOOL OnItemGetRect(const SOsrPanel *pItem, CRect &rcItem) const;
124
125 /**
126 * @brief Checks if item redraw is delayed.
127 * @return TRUE if item redraw is delayed, otherwise FALSE.
128 */
129 virtual BOOL IsItemRedrawDelay() const;
130
131 protected:
132 /**
133 * @brief Handles data set changes.
134 */
135 void onDataSetChanged();
136
137 /**
138 * @brief Handles data set invalidation.
139 */
141
142 /**
143 * @brief Handles data changes for a specific item.
144 * @param iItem Index of the item.
145 */
146 void onItemDataChanged(int iItem);
147
148 protected:
149 /**
150 * @brief Handles item click events.
151 * @param pEvt Pointer to the event arguments.
152 * @return TRUE if the event was handled, otherwise FALSE.
153 */
154 BOOL OnItemClick(IEvtArgs *pEvt);
155
156 protected:
157 /**
158 * @brief Handles scroll events.
159 * @param bVertical Flag indicating if the scroll is vertical.
160 * @param uCode Scroll code.
161 * @param nPos Scroll position.
162 * @return TRUE if the event was handled, otherwise FALSE.
163 */
164 virtual BOOL OnScroll(BOOL bVertical, UINT uCode, int nPos);
165
166 /**
167 * @brief Gets the scroll line size.
168 * @param bVertical Flag indicating if the scroll is vertical.
169 * @return Scroll line size.
170 */
171 virtual int GetScrollLineSize(BOOL bVertical);
172
173 /**
174 * @brief Creates child windows from an XML node.
175 * @param xmlNode XML node containing the child window definitions.
176 * @return TRUE if successful, otherwise FALSE.
177 */
178 virtual BOOL CreateChildren(SXmlNode xmlNode);
179
180 /**
181 * @brief Updates the tooltip.
182 * @param pt Mouse position.
183 * @param tipInfo Tooltip information.
184 * @return TRUE if the tooltip was updated, otherwise FALSE.
185 */
186 virtual BOOL UpdateToolTip(CPoint pt, SwndToolTipInfo &tipInfo);
187
188 /**
189 * @brief Gets the dialog code for the window.
190 * @return Dialog code.
191 */
192 virtual UINT WINAPI OnGetDlgCode() const;
193
194 /**
195 * @brief Sets the cursor.
196 * @param pt Mouse position.
197 * @return TRUE if the cursor was set, otherwise FALSE.
198 */
199 virtual BOOL OnSetCursor(const CPoint &pt);
200
201 /**
202 * @brief Handles colorization.
203 * @param cr Color reference.
204 */
205 virtual void OnColorize(COLORREF cr);
206
207 /**
208 * @brief Handles scale changes.
209 * @param nScale New scale value.
210 */
211 virtual void OnScaleChanged(int nScale);
212
213 /**
214 * @brief Handles language changes.
215 * @return Result of the language change handling.
216 */
217 virtual HRESULT OnLanguageChanged();
218
219 /**
220 * @brief Rebuilds the font.
221 */
222 virtual void OnRebuildFont();
223
224 protected:
225 /**
226 * @brief Dispatches messages to items.
227 * @param uMsg Message identifier.
228 * @param wParam Additional message-specific information.
229 * @param lParam Additional message-specific information.
230 */
231 void DispatchMessage2Items(UINT uMsg, WPARAM wParam, LPARAM lParam);
232
233 /**
234 * @brief Updates the scroll bars.
235 */
236 void UpdateScrollBar();
237
238 /**
239 * @brief Redraws a specific item.
240 * @param pItem Pointer to the item panel.
241 */
242 void RedrawItem(SOsrPanel *pItem);
243
244 /**
245 * @brief Gets the item panel by index.
246 * @param iItem Index of the item.
247 * @return Pointer to the item panel.
248 */
249 SItemPanel *GetItemPanel(int iItem);
250
251 /**
252 * @brief Calculates the drawing rectangle for an item.
253 * @param iItem Index of the item.
254 * @return Drawing rectangle of the item.
255 */
256 CRect CalcItemDrawRect(int iItem) const; // 计算item实际绘制的位置
257
258 /**
259 * @brief Updates the visible items.
260 */
261 void UpdateVisibleItems();
262
263 /**
264 * @brief Updates a specific visible item.
265 * @param iItem Index of the item.
266 */
267 void UpdateVisibleItem(int iItem);
268
269 /**
270 * @brief Handles the paint event.
271 * @param pRT Pointer to the rendering target.
272 */
273 void OnPaint(IRenderTarget *pRT);
274
275 /**
276 * @brief Handles the size event.
277 * @param nType Type of size change.
278 * @param size New size.
279 */
280 void OnSize(UINT nType, CSize size);
281
282 /**
283 * @brief Handles the destroy event.
284 */
285 void OnDestroy();
286
287 /**
288 * @brief Handles mouse events.
289 * @param uMsg Message identifier.
290 * @param wParam Additional message-specific information.
291 * @param lParam Additional message-specific information.
292 * @return Result of the message handling.
293 */
294 LRESULT OnMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam);
295
296 /**
297 * @brief Handles key events.
298 * @param uMsg Message identifier.
299 * @param wParam Additional message-specific information.
300 * @param lParam Additional message-specific information.
301 * @return Result of the message handling.
302 */
303 LRESULT OnKeyEvent(UINT uMsg, WPARAM wParam, LPARAM lParam);
304
305 /**
306 * @brief Handles the key down event.
307 * @param nChar Virtual key code of the key.
308 * @param nRepCnt Repeat count for the key.
309 * @param nFlags Flags associated with the key event.
310 */
311 void OnKeyDown(TCHAR nChar, UINT nRepCnt, UINT nFlags);
312
313 /**
314 * @brief Handles the mouse leave event.
315 */
316 void OnMouseLeave();
317
318 /**
319 * @brief Handles the mouse wheel event.
320 * @param nFlags Flags associated with the mouse event.
321 * @param zDelta Wheel delta.
322 * @param pt Mouse position.
323 * @return TRUE if the event was handled, otherwise FALSE.
324 */
325 BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
326
327 /**
328 * @brief Handles the kill focus event.
329 * @param wndFocus Handle to the window receiving focus.
330 */
331 void OnKillFocus(SWND wndFocus);
332
333 /**
334 * @brief Handles the set focus event.
335 * @param wndOld Handle to the window losing focus.
336 */
337 void OnSetFocus(SWND wndOld);
338
339 /**
340 * @brief Handles the set scale event.
341 * @param uMsg Message identifier.
342 * @param wParam Additional message-specific information.
343 * @param lParam Additional message-specific information.
344 * @return Result of the message handling.
345 */
346 LRESULT OnSetScale(UINT uMsg, WPARAM wParam, LPARAM lParam);
347
348 /**
349 * @brief Handles the show window event.
350 * @param bShow Flag indicating if the window is being shown.
351 * @param nStatus Status of the window.
352 */
353 void OnShowWindow(BOOL bShow, UINT nStatus);
354
355 SOUI_MSG_MAP_BEGIN()
356 MSG_WM_PAINT_EX(OnPaint) /**< Paint event. */
357 MSG_WM_SIZE(OnSize) /**< Size event. */
358 MSG_WM_DESTROY(OnDestroy) /**< Destroy event. */
359 MSG_WM_MOUSEWHEEL(OnMouseWheel) /**< Mouse wheel event. */
360 MSG_WM_MOUSELEAVE(OnMouseLeave) /**< Mouse leave event. */
361 MSG_WM_KEYDOWN(OnKeyDown) /**< Key down event. */
362 MSG_WM_KILLFOCUS_EX(OnKillFocus) /**< Kill focus event. */
363 MSG_WM_SETFOCUS_EX(OnSetFocus) /**< Set focus event. */
364 MESSAGE_HANDLER_EX(UM_SETSCALE, OnSetScale) /**< Set scale event. */
365 MSG_WM_SHOWWINDOW(OnShowWindow) /**< Show window event. */
366 MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseEvent) /**< Mouse event range. */
367 MESSAGE_RANGE_HANDLER_EX(WM_KEYFIRST, WM_KEYLAST, OnKeyEvent) /**< Key event range. */
368 MESSAGE_RANGE_HANDLER_EX(WM_IME_STARTCOMPOSITION, WM_IME_KEYLAST, OnKeyEvent) /**< IME key event range. */
369 MESSAGE_HANDLER_EX(WM_IME_CHAR, OnKeyEvent) /**< IME character event. */
370 MESSAGE_HANDLER_EX(WM_IME_REQUEST, OnKeyEvent) /**< IME request event. */
371 SOUI_MSG_MAP_END()
372
373 SOUI_ATTRS_BEGIN()
374 ATTR_LAYOUTSIZE(L"marginSize", m_nMarginSize, FALSE) /**< Margin size for items. */
375 ATTR_BOOL(L"wantTab", m_bWantTab, FALSE) /**< Flag indicating if tabbing is wanted. */
376 SOUI_ATTRS_END()
377
378 protected:
379 SAutoRefPtr<ILvAdapter> m_adapter; /**< Adapter for the tile view. */
380 SAutoRefPtr<ILvDataSetObserver> m_observer; /**< Data set observer. */
381 SAutoRefPtr<ITileViewItemLocator> m_tvItemLocator; /**< Item locator for the tile view. */
382
383 /**
384 * @struct ItemInfo
385 * @brief Information about an item in the tile view.
386 */
387 struct ItemInfo
388 {
389 SItemPanel *pItem; /**< Pointer to the item panel. */
390 int nType; /**< Type of the item. */
391 };
392
393 bool m_bPendingUpdate; /**< Flag indicating if an update is pending due to data set changes. */
394 int m_iPendingUpdateItem; /**< Index of the item to update, -1 for all, -2 for nothing. */
395 int m_iPendingViewItem; /**< Index of the item to view, -1 for initialization. */
396
397 int m_iFirstVisible; /**< Index of the first visible item. */
398 SList<ItemInfo> m_lstItems; // List of currently visible items.
399
400 SOsrPanel *m_itemCapture; /**< Item panel that has been set capture. */
401
402 int m_iSelItem; /**< Index of the selected item. */
403 SOsrPanel *m_pHoverItem; /**< Item panel under the hover state. */
404
405 SArray<SList<SItemPanel *> *> m_itemRecycle; // Recycle bin for item panels, one list per style for reuse.
406
407 SXmlDoc m_xmlTemplate; /**< XML template for item panels. */
408 SLayoutSize m_nMarginSize; /**< Margin size for items. */
409 BOOL m_bWantTab; /**< Flag indicating if tabbing is wanted. */
410 BOOL m_bDatasetInvalidated; /**< Flag indicating if the data set is invalidated. */
411};
412
413SNSEND
414
415#endif // __STILEVIEW__H__
SOUI Panel with Scrollbar Support.
SOUI基础DUI窗口模块
Smart pointer class for managing COM-style reference-counted objects.
布局大小类
Definition SLayoutSize.h:10
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
SAutoRefPtr< ILvDataSetObserver > m_observer
Definition STileView.h:380
void OnKeyDown(TCHAR nChar, UINT nRepCnt, UINT nFlags)
Handles the key down event.
SXmlDoc m_xmlTemplate
Definition STileView.h:407
BOOL m_bDatasetInvalidated
Definition STileView.h:410
void UpdateScrollBar()
Updates the scroll bars.
void onDataSetInvalidated()
Handles data set invalidation.
void OnPaint(IRenderTarget *pRT)
Handles the paint event.
virtual BOOL IsItemRedrawDelay() const
Checks if item redraw is delayed.
BOOL m_bWantTab
Definition STileView.h:409
SAutoRefPtr< ILvAdapter > m_adapter
Definition STileView.h:379
int m_iSelItem
Definition STileView.h:402
ILvAdapter * GetAdapter() SCONST OVERRIDE
Gets the adapter for the tile view.
SItemPanel * GetItemPanel(int iItem)
Gets the item panel by index.
void UpdateVisibleItems()
Updates the visible items.
SOsrPanel * m_pHoverItem
Definition STileView.h:403
void EnsureVisible(int iItem) OVERRIDE
Ensures the specified item is visible.
LRESULT OnSetScale(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handles the set scale event.
IItemPanel * HitTest(const POINT *pt) SCONST OVERRIDE
Performs a hit test on the tile view.
void OnSize(UINT nType, CSize size)
Handles the size event.
void SetSel(int iItem, BOOL bNotify=FALSE) OVERRIDE
Sets the selected item.
void SetItemLocator(ITileViewItemLocator *pItemLocator) OVERRIDE
Sets the item locator for the tile view.
int m_iPendingUpdateItem
Definition STileView.h:394
void OnMouseLeave()
Handles the mouse leave event.
void UpdateVisibleItem(int iItem)
Updates a specific visible item.
void OnDestroy()
Handles the destroy event.
BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
Handles the mouse wheel event.
void onDataSetChanged()
Handles data set changes.
SOsrPanel * m_itemCapture
Definition STileView.h:400
int GetSel() SCONST OVERRIDE
Gets the selected item.
void onItemDataChanged(int iItem)
Handles data changes for a specific item.
ITileViewItemLocator * GetItemLocator() SCONST OVERRIDE
Gets the item locator for the tile view.
void OnShowWindow(BOOL bShow, UINT nStatus)
Handles the show window event.
CRect CalcItemDrawRect(int iItem) const
Calculates the drawing rectangle for an item.
void OnSetFocus(SWND wndOld)
Handles the set focus event.
LRESULT OnKeyEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handles key events.
SAutoRefPtr< ITileViewItemLocator > m_tvItemLocator
Definition STileView.h:381
STileView()
Constructor for STileView.
Definition STileView.cpp:39
BOOL OnItemClick(IEvtArgs *pEvt)
Handles item click events.
void OnKillFocus(SWND wndFocus)
Handles the kill focus event.
BOOL SetAdapter(ILvAdapter *adapter) OVERRIDE
Sets the adapter for the tile view.
Definition STileView.cpp:66
bool m_bPendingUpdate
Definition STileView.h:393
int m_iFirstVisible
Definition STileView.h:397
SLayoutSize m_nMarginSize
Definition STileView.h:408
LRESULT OnMouseEvent(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handles mouse events.
void DispatchMessage2Items(UINT uMsg, WPARAM wParam, LPARAM lParam)
Dispatches messages to items.
virtual BOOL OnItemGetRect(const SOsrPanel *pItem, CRect &rcItem) const
Gets the rectangle of an item.
int m_iPendingViewItem
Definition STileView.h:395
void RedrawItem(SOsrPanel *pItem)
Redraws a specific item.
virtual void OnItemSetCapture(SOsrPanel *pItem, BOOL bCapture)
Handles the capture of an item.
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
LRESULT OnSetScale(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handles setting the scale of the window.
Definition Swnd.cpp:2282
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 about an item in the tile view.
Definition STileView.h:388
SItemPanel * pItem
Definition STileView.h:389
Information for window tooltips.
Definition SWnd.h:208