soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
STabCtrl.h
Go to the documentation of this file.
1/**
2 * @file STabCtrl.h
3 * @brief Definition of the STabCtrl and related classes.
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 __STABCTRL__H__
13#define __STABCTRL__H__
14
15#include <core/SWnd.h>
16#include <helper/SplitString.h>
17#include <proxy/SWindowProxy.h>
18#include <interface/SCtrl-i.h>
19
20SNSBEGIN
21
22/**
23 * @class STabPage
24 * @brief A tab page within a tab control.
25 *
26 * This class represents a tab page within an STabCtrl, which can have a title and an icon.
27 */
28class SOUI_EXP STabPage : public TWindowProxy<ITabPage> {
29 DEF_SOBJECT(SWindow, L"page")
30 friend class STabCtrl;
31
32 public:
33 /**
34 * @brief Constructor for STabPage.
35 */
37 : m_iIcon(-1)
38 , m_strTitle(this)
39 {
40 m_bVisible = FALSE;
41 }
42
43 /**
44 * @brief Destructor for STabPage.
45 */
46 virtual ~STabPage()
47 {
48 }
49
50 public:
51 /**
52 * @brief Gets the title of the tab page.
53 * @return The title of the tab page.
54 */
55 STDMETHOD_(LPCTSTR, GetTitle)(CTHIS) SCONST OVERRIDE
56 {
57 return m_strTitle.GetText(FALSE);
58 }
59
60 /**
61 * @brief Sets the title of the tab page.
62 * @param lpszTitle The new title for the tab page.
63 */
64 STDMETHOD_(void, SetTitle)(THIS_ LPCTSTR lpszTitle) OVERRIDE
65 {
66 m_strTitle.SetText(lpszTitle, false);
67 }
68
69 /**
70 * @brief Gets the icon index of the tab page.
71 * @return The icon index of the tab page.
72 */
73 STDMETHOD_(int, GetIconIndex)(CTHIS) SCONST OVERRIDE
74 {
75 return m_iIcon;
76 }
77
78 /**
79 * @brief Sets the icon index of the tab page.
80 * @param iIcon The new icon index for the tab page.
81 */
82 STDMETHOD_(void, SetIconIndex)(THIS_ int iIcon) OVERRIDE
83 {
84 m_iIcon = iIcon;
85 }
86
87 protected:
88 /**
89 * @brief Handles tooltip updates.
90 * @param pt The mouse position.
91 * @param tipInfo Tooltip information.
92 * @return Always returns FALSE to disable tooltips on the page.
93 */
94 virtual BOOL UpdateToolTip(CPoint pt, SwndToolTipInfo &tipInfo)
95 {
96 return FALSE;
97 }
98
99 SOUI_ATTRS_BEGIN()
100 ATTR_I18NSTRT(L"title", m_strTitle, FALSE) /**< Title of the tab page. */
101 ATTR_INT(L"iconIndex", m_iIcon, FALSE) /**< Icon index of the tab page. */
102 SOUI_ATTRS_END()
103
104 protected:
105 STrText m_strTitle; /**< Title of the tab page. */
106 int m_iIcon; /**< Icon index of the tab page. */
107};
108
109class STabSlider;
110
111/**
112 * @class STabCtrl
113 * @brief A tab control for managing multiple tab pages.
114 *
115 * This class represents a tab control that can manage multiple tab pages with various customization options.
116 */
117class SOUI_EXP STabCtrl : public TWindowProxy<ITabCtrl> {
118 friend class STabSlider;
119 DEF_SOBJECT(SWindow, L"tabctrl")
120
121 protected:
122 int m_nHoverTabItem; /**< Index of the tab item under the hover state. */
123 int m_nCurrentPage; /**< Index of the currently selected page. */
124 SLayoutSize m_nTabInterSize; /**< Spacing between tab pages. */
125 SLayoutSize m_szTab[2]; /**< Size of the tab pages. */
126 SLayoutSize m_nTabPos; /**< Position of the tabs. */
127 SAutoRefPtr<ISkinObj> m_pSkinTab; /**< Skin object for the tabs. */
128 SAutoRefPtr<ISkinObj> m_pSkinIcon; /**< Skin object for the icons. */
129 SAutoRefPtr<ISkinObj> m_pSkinTabInter; /**< Skin object for the tab spacing. */
130 SAutoRefPtr<ISkinObj> m_pSkinFrame; /**< Skin object for the frame. */
131 SLayoutSize m_ptIcon[2]; /**< Position of the icons. */
132 SLayoutSize m_ptText[2]; /**< Position of the text. */
133 int m_nTabAlign; /**< Alignment of the tabs. */
134
135 SArray<STabPage *> m_lstPages; /**< List of tab pages. */
136 STabSlider *m_tabSlider;
137 enum
138 {
139 AlignTop,
140 AlignLeft,
141 AlignBottom,
142 AlignRight,
143 };
144
145 enum TEXTDIR
146 {
147 Text_Horz,
148 Text_Vert,
149 } m_txtDir;
150 int m_nAnimateSteps; /**< Number of animation steps. */
151 int m_nAniamteType; /**< Animation style. */
152 SAutoRefPtr<IInterpolator> m_aniInterpolator;
153
154 public:
155 /**
156 * @brief Constructor for STabCtrl.
157 */
158 STabCtrl();
159
160 /**
161 * @brief Destructor for STabCtrl.
162 */
163 virtual ~STabCtrl()
164 {
165 }
166
167 public:
168 /**
169 * @brief Gets the index of the currently selected tab page.
170 * @return Index of the currently selected tab page.
171 */
172 STDMETHOD_(int, GetCurSel)(THIS) SCONST OVERRIDE;
173
174 /**
175 * @brief Sets the currently selected tab page.
176 * @param nIndex Index of the tab page to select.
177 * @return TRUE if successful, otherwise FALSE.
178 */
179 STDMETHOD_(BOOL, SetCurSel)(THIS_ int nIndex) OVERRIDE;
180
181 /**
182 * @brief Sets the title of a tab page.
183 * @param nIndex Index of the tab page.
184 * @param lpszTitle New title for the tab page.
185 * @return TRUE if successful, otherwise FALSE.
186 */
187 STDMETHOD_(BOOL, SetItemTitle)(THIS_ int nIndex, LPCTSTR lpszTitle) OVERRIDE;
188
189 /**
190 * @brief Inserts a new tab page.
191 * @param lpContent XML description of the page.
192 * @param iInsert Position to insert the page.
193 * @return Index of the inserted page.
194 */
195 STDMETHOD_(int, InsertItem)(THIS_ LPCWSTR lpContent, int iInsert = -1) OVERRIDE;
196
197 /**
198 * @brief Gets the number of tab pages.
199 * @return Number of tab pages.
200 */
201 STDMETHOD_(int, GetItemCount)(THIS) SCONST OVERRIDE;
202
203 /**
204 * @brief Gets a tab page by index.
205 * @param nIndex Index of the tab page.
206 * @return Pointer to the tab page.
207 */
208 STDMETHOD_(IWindow *, GetPage)(THIS_ int nIndex) OVERRIDE;
209
210 /**
211 * @brief Removes a tab page by index.
212 * @param nIndex Index of the tab page to remove.
213 * @param iSelPage Index of the page to select after removal.
214 * @return TRUE if successful, otherwise FALSE.
215 */
216 STDMETHOD_(BOOL, RemoveItem)(THIS_ int nIndex, int iSelPage = 0) OVERRIDE;
217
218 /**
219 * @brief Removes all tab pages.
220 */
221 STDMETHOD_(void, RemoveAllItems)(THIS) OVERRIDE;
222
223 /**
224 * @brief Gets the index of a tab page by name or title.
225 * @param pszName Name or title of the page.
226 * @param bTitle TRUE if pszName is a title, FALSE if it is a name.
227 * @return Index of the found page.
228 */
229 STDMETHOD_(int, GetPageIndex)(THIS_ LPCTSTR pszName, BOOL bTitle) OVERRIDE;
230
231 public:
232 /**
233 * @brief Gets a tab page by index.
234 * @param iPage Index of the tab page.
235 * @return Pointer to the tab page.
236 */
237 STabPage *GetItem(int iPage);
238
239 /**
240 * @brief Gets a tab page by name or title.
241 * @param pszName Name or title of the page.
242 * @param bTitle TRUE if pszName is a title, FALSE if it is a name.
243 * @return Pointer to the tab page.
244 */
245 STabPage *GetPage(LPCTSTR pszName, BOOL bTitle = TRUE);
246
247 /**
248 * @brief Sets the currently selected tab page by name or title.
249 * @param pszName Name or title of the page.
250 * @param bTitle TRUE if pszName is a title, FALSE if it is a name.
251 * @return TRUE if successful, otherwise FALSE.
252 */
253 BOOL SetCurSel(LPCTSTR pszName, BOOL bTitle = TRUE);
254
255 protected:
256 /**
257 * @brief Creates tab pages from an XML node.
258 * @param xmlNode XML node containing the tab page definitions.
259 * @return TRUE if successful, otherwise FALSE.
260 */
261 BOOL CreateChildren(SXmlNode xmlNode);
262
263 /**
264 * @brief Inserts a new tab page from an XML node.
265 * @param xmlNode XML node containing the tab page definition.
266 * @param iInsert Position to insert the page.
267 * @param bLoading TRUE if the page is being loaded.
268 * @return Index of the inserted page.
269 */
270 virtual int InsertItem(SXmlNode xmlNode, int iInsert = -1, BOOL bLoading = FALSE);
271
272 /**
273 * @brief Handles the insertion of a tab page.
274 * @param pItem Pointer to the inserted tab page.
275 */
276 virtual void OnItemInserted(STabPage *pItem)
277 {
278 }
279
280 /**
281 * @brief Handles the removal of a tab page.
282 * @param pItem Pointer to the removed tab page.
283 */
284 virtual void OnItemRemoved(STabPage *pItem)
285 {
286 }
287
288 /**
289 * @brief Prepares the rendering target for painting the current window.
290 * @param pRT Pointer to the rendering target.
291 * @param painter Painter object.
292 */
293 virtual void BeforePaint(IRenderTarget *pRT, SPainter &painter);
294
295 /**
296 * @brief Gets the layout rectangle for child windows.
297 * @param prc Pointer to the rectangle to receive the layout rectangle.
298 */
299 STDMETHOD_(void, GetChildrenLayoutRect)(THIS_ RECT *prc) SCONST OVERRIDE;
300
301 /**
302 * @brief Gets the rectangle of the tab header.
303 * @return Rectangle of the tab header.
304 */
305 virtual CRect GetTitleRect();
306
307 /**
308 * @brief Gets the rectangle of a specified tab item.
309 * @param nIndex Index of the tab item.
310 * @param rcItem Rectangle to receive the item position.
311 * @return TRUE if successful, otherwise FALSE.
312 */
313 virtual BOOL GetItemRect(int nIndex, CRect &rcItem);
314
315 /**
316 * @brief Draws a tab item.
317 * @param pRT Pointer to the rendering target.
318 * @param rcItem Rectangle of the item to draw.
319 * @param iItem Index of the item.
320 * @param dwState State of the item.
321 */
322 virtual void DrawItem(IRenderTarget *pRT, const CRect &rcItem, int iItem, DWORD dwState);
323
324 virtual STabPage *CreatePageFromXml(SXmlNode xmlPage);
325
326 /**
327 * @brief Gets the dialog code for the window.
328 * @return Dialog code.
329 */
330 virtual UINT WINAPI OnGetDlgCode() const
331 {
332 return SC_WANTARROWS;
333 }
334
335 virtual BOOL UpdateToolTip(CPoint pt, SwndToolTipInfo &tipInfo);
336
337 /**
338 * @brief Updates the positions of child windows.
339 */
340 STDMETHOD_(void, UpdateChildrenPosition)(THIS) OVERRIDE;
341
342 STDMETHOD_(void, OnInitFinished)(THIS_ IXmlNode *xmlNode) OVERRIDE;
343
344 virtual void OnColorize(COLORREF cr);
345 virtual void OnScaleChanged(int nScale);
346
347 virtual HRESULT OnLanguageChanged();
348
349 protected:
350 /**
351 * @brief Performs a hit test on the tab control.
352 * @param pt Mouse position.
353 * @return Index of the tab item under the mouse, or -1 if none.
354 */
355 int HitTest(CPoint pt);
356
357 void OnSliderFinish();
358
359 protected:
360 /**
361 * @brief Outputs text vertically.
362 * @param pRT Pointer to the rendering target.
363 * @param x X-coordinate of the text.
364 * @param y Y-coordinate of the text.
365 * @param strText Text to output.
366 */
367 void TextOutV(IRenderTarget *pRT, int x, int y, const SStringT &strText);
368
369 /**
370 * @brief Draws text vertically.
371 * @param pRT Pointer to the rendering target.
372 * @param rcText Rectangle for the text.
373 * @param strText Text to draw.
374 */
375 void DrawTextV(IRenderTarget *pRT, CRect rcText, const SStringT &strText);
376
377 /**
378 * @brief Measures text vertically.
379 * @param pRT Pointer to the rendering target.
380 * @param strText Text to measure.
381 * @return Size of the text.
382 */
383 SIZE MeasureTextV(IRenderTarget *pRT, const SStringT &strText);
384
385 protected:
386 /**
387 * @brief Handles the paint event.
388 * @param pRT Pointer to the rendering target.
389 */
390 void OnPaint(IRenderTarget *pRT);
391
392 /**
393 * @brief Handles the left mouse button down event.
394 * @param nFlags Flags associated with the mouse event.
395 * @param point Mouse position.
396 */
397 void OnLButtonDown(UINT nFlags, CPoint point);
398
399 /**
400 * @brief Handles the mouse move event.
401 * @param nFlags Flags associated with the mouse event.
402 * @param point Mouse position.
403 */
404 void OnMouseMove(UINT nFlags, CPoint point);
405
406 /**
407 * @brief Handles the mouse leave event.
408 */
410 {
411 OnMouseMove(0, CPoint(-1, -1));
412 }
413
414 /**
415 * @brief Handles the key down event.
416 * @param nChar Virtual key code of the key.
417 * @param nRepCnt Repeat count for the key.
418 * @param nFlags Flags associated with the key event.
419 */
420 void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
421
422 /**
423 * @brief Handles the destroy event.
424 */
425 void OnDestroy();
426
427 SOUI_MSG_MAP_BEGIN()
428 MSG_WM_PAINT_EX(OnPaint)
429 MSG_WM_DESTROY(OnDestroy)
430 MSG_WM_LBUTTONDOWN(OnLButtonDown)
431 MSG_WM_MOUSEMOVE(OnMouseMove)
432 MSG_WM_MOUSELEAVE(OnMouseLeave)
433 MSG_WM_KEYDOWN(OnKeyDown)
434 SOUI_MSG_MAP_END()
435
436 SOUI_ATTRS_BEGIN()
437 ATTR_INT(L"curSel", m_nCurrentPage, FALSE) /**< Index of the currently selected page. */
438 ATTR_LAYOUTSIZE2(L"tabSize", m_szTab, TRUE) /**< Size of the tab pages. */
439 ATTR_LAYOUTSIZE(L"tabWidth", m_szTab[0], FALSE) /**< Width of the tab pages. */
440 ATTR_LAYOUTSIZE(L"tabHeight", m_szTab[1], FALSE) /**< Height of the tab pages. */
441 ATTR_LAYOUTSIZE(L"tabPos", m_nTabPos, FALSE) /**< Position of the tabs. */
442 ATTR_LAYOUTSIZE(L"tabInterSize", m_nTabInterSize, FALSE) /**< Spacing between tab pages. */
443 ATTR_SKIN(L"tabInterSkin", m_pSkinTabInter, FALSE) /**< Skin object for the tab spacing. */
444 ATTR_SKIN(L"tabSkin", m_pSkinTab, FALSE) /**< Skin object for the tabs. */
445 ATTR_SKIN(L"iconSkin", m_pSkinIcon, FALSE) /**< Skin object for the icons. */
446 ATTR_SKIN(L"frameSkin", m_pSkinFrame, FALSE) /**< Skin object for the frame. */
447 ATTR_LAYOUTSIZE(L"icon-x", m_ptIcon[0], FALSE) /**< X-coordinate of the icons. */
448 ATTR_LAYOUTSIZE(L"icon-y", m_ptIcon[1], FALSE) /**< Y-coordinate of the icons. */
449 ATTR_LAYOUTSIZE(L"text-x", m_ptText[0], FALSE) /**< X-coordinate of the text. */
450 ATTR_LAYOUTSIZE(L"text-y", m_ptText[1], FALSE) /**< Y-coordinate of the text. */
451 ATTR_ENUM_BEGIN(L"tabAlign", int, TRUE)
452 ATTR_ENUM_VALUE(L"top", AlignTop) /**< Align tabs at the top. */
453 ATTR_ENUM_VALUE(L"left", AlignLeft) /**< Align tabs on the left. */
454 ATTR_ENUM_VALUE(L"right", AlignRight) /**< Align tabs on the right. */
455 ATTR_ENUM_VALUE(L"bottom", AlignBottom) /**< Align tabs at the bottom. */
456 ATTR_ENUM_END(m_nTabAlign)
457 ATTR_ENUM_BEGIN(L"textDir", TEXTDIR, TRUE)
458 ATTR_ENUM_VALUE(L"hori", Text_Horz) /**< Horizontal text direction. */
459 ATTR_ENUM_VALUE(L"horizontal", Text_Horz) /**< Horizontal text direction. */
460 ATTR_ENUM_VALUE(L"vert", Text_Vert) /**< Vertical text direction. */
461 ATTR_ENUM_VALUE(L"vertical", Text_Vert) /**< Vertical text direction. */
462 ATTR_ENUM_END(m_txtDir)
463 ATTR_INT(L"animateSteps", m_nAnimateSteps, FALSE) /**< Number of animation steps. */
464 ATTR_INT(L"animateType", m_nAniamteType, FALSE) /**< Animation style. */
465 ATTR_INTERPOLATOR(L"interpolator", m_aniInterpolator, FALSE) /**< Interpolator for animations. */
466 ATTR_CHAIN_PTR(m_aniInterpolator, 0) /**< Chain attributes to interpolator. */
467 SOUI_ATTRS_END()
468};
469
470SNSEND
471
472#endif // __STABCTRL__H__
SOUI基础DUI窗口模块
Smart pointer class for managing COM-style reference-counted objects.
布局大小类
Definition SLayoutSize.h:10
Helper class for painting.
Definition SWnd.h:178
int m_nAniamteType
Definition STabCtrl.h:151
SAutoRefPtr< ISkinObj > m_pSkinTabInter
Definition STabCtrl.h:129
SLayoutSize m_szTab[2]
Definition STabCtrl.h:125
virtual void OnItemInserted(STabPage *pItem)
Handles the insertion of a tab page.
Definition STabCtrl.h:276
virtual void OnItemRemoved(STabPage *pItem)
Handles the removal of a tab page.
Definition STabCtrl.h:284
int m_nAnimateSteps
Definition STabCtrl.h:150
int m_nCurrentPage
Definition STabCtrl.h:123
SAutoRefPtr< ISkinObj > m_pSkinFrame
Definition STabCtrl.h:130
int m_nHoverTabItem
Definition STabCtrl.h:122
SArray< STabPage * > m_lstPages
Definition STabCtrl.h:135
STabCtrl()
Constructor for STabCtrl.
Definition STabCtrl.cpp:286
SAutoRefPtr< ISkinObj > m_pSkinIcon
Definition STabCtrl.h:128
void OnMouseLeave()
Handles the mouse leave event.
Definition STabCtrl.h:409
virtual UINT WINAPI OnGetDlgCode() const
Gets the dialog code for the window.
Definition STabCtrl.h:330
SLayoutSize m_nTabInterSize
Definition STabCtrl.h:124
SLayoutSize m_ptText[2]
Definition STabCtrl.h:132
SLayoutSize m_nTabPos
Definition STabCtrl.h:126
virtual ~STabCtrl()
Destructor for STabCtrl.
Definition STabCtrl.h:163
SAutoRefPtr< ISkinObj > m_pSkinTab
Definition STabCtrl.h:127
int m_nTabAlign
Definition STabCtrl.h:133
SLayoutSize m_ptIcon[2]
Definition STabCtrl.h:131
A tab page within a tab control.
Definition STabCtrl.h:28
virtual BOOL UpdateToolTip(CPoint pt, SwndToolTipInfo &tipInfo)
Handles tooltip updates.
Definition STabCtrl.h:94
STrText m_strTitle
Definition STabCtrl.h:105
LPCTSTR GetTitle() SCONST OVERRIDE
Gets the title of the tab page.
Definition STabCtrl.h:55
STabPage()
Constructor for STabPage.
Definition STabCtrl.h:36
virtual ~STabPage()
Destructor for STabPage.
Definition STabCtrl.h:46
void SetTitle(LPCTSTR lpszTitle) OVERRIDE
Sets the title of the tab page.
Definition STabCtrl.h:64
int GetIconIndex() SCONST OVERRIDE
Gets the icon index of the tab page.
Definition STabCtrl.h:73
int m_iIcon
Definition STabCtrl.h:106
void SetIconIndex(int iIcon) OVERRIDE
Sets the icon index of the tab page.
Definition STabCtrl.h:82
Class for handling text with translation support.
Definition SWnd.h:230
virtual BOOL UpdateToolTip(CPoint pt, SwndToolTipInfo &tipInfo)
Handle tooltip updates.
Definition Swnd.cpp:277
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 OnPaint(IRenderTarget *pRT)
Handles the painting of the window.
Definition Swnd.cpp:1785
virtual void OnScaleChanged(int scale)
Called when the scale of the window changes.
Definition Swnd.cpp:3271
virtual HRESULT OnLanguageChanged()
Called when the language of the window changes.
Definition Swnd.cpp:3229
virtual void BeforePaint(IRenderTarget *pRT, SPainter &painter)
Prepare rendering environment.
Definition Swnd.cpp:1755
SWindow()
Constructor.
Definition Swnd.cpp:104
void OnLButtonDown(UINT nFlags, CPoint pt)
Handles the left mouse button down event.
Definition Swnd.cpp:2092
virtual void OnColorize(COLORREF cr)
Adjusts the color tone of the window.
Definition Swnd.cpp:3154
virtual BOOL CreateChildren(SXmlNode xmlNode)
Create child windows from XML node.
Definition Swnd.cpp:823
BOOL m_bVisible
Definition SWnd.h:2604
Class representing an XML node.
Definition SXml.h:352
Interface for rendering target objects.
Definition SRender-i.h:1440
Interface for XML nodes.
Definition sxml-i.h:128
Information for window tooltips.
Definition SWnd.h:208