soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SSplitWnd.h
Go to the documentation of this file.
1/**
2 * @file SSplitWnd.h
3 * @brief Definition of the SSplitWnd and related classes.
4 * @version v1.0
5 * @author soui
6 * @date 2014-07-08
7 *
8 * @copyright Copyright (C) 2014-2050 SOUI团队
9 * All rights reserved.
10 */
11
12#ifndef __SSPLITWND__H__
13#define __SSPLITWND__H__
14
15#include <core/SWnd.h>
16#include <layout/SLayoutSize.h>
17
18SNSBEGIN
19
20/**
21 * @class SSplitPane
22 * @brief A pane within a split window.
23 *
24 * This class represents a pane within a split window, which can have ideal, minimum, and maximum sizes.
25 */
26class SOUI_EXP SSplitPane : public SWindow {
27 friend class SSplitWnd;
28 DEF_SOBJECT(SWindow, L"pane")
29
30 public:
31 /**
32 * @brief Constructor for SSplitPane.
33 */
34 SSplitPane();
35
36 /**
37 * @brief Destructor for SSplitPane.
38 */
39 virtual ~SSplitPane()
40 {
41 }
42
43 /**
44 * @brief Moves the pane to a new position.
45 * @param rc The new rectangle position.
46 */
47 void Move(CRect rc);
48
49 SOUI_ATTRS_BEGIN()
50 ATTR_LAYOUTSIZE(L"idealSize", m_nSizeIdeal, FALSE) /**< Ideal size of the pane. */
51 ATTR_LAYOUTSIZE(L"minSize", m_nSizeMin, FALSE) /**< Minimum size of the pane. */
52 ATTR_LAYOUTSIZE(L"maxSize", m_nSizeMax, FALSE) /**< Maximum size of the pane. */
53 ATTR_INT(L"priority", m_nPriority, FALSE) /**< Priority of the pane. Higher priority means the pane will reach its ideal size first. */
54 SOUI_ATTRS_END()
55
56 protected:
57 SLayoutSize m_nSizeIdeal; /**< Ideal size of the pane. */
58 SLayoutSize m_nSizeMin; /**< Minimum size of the pane. */
59 SLayoutSize m_nSizeMax; /**< Maximum size of the pane. */
60 int m_nPriority; /**< Priority of the pane. Higher priority means the pane will reach its ideal size first. */
61};
62
63/**
64 * @class SSplitWnd
65 * @brief A split window that can contain multiple panes.
66 *
67 * This class represents a split window that can be divided into multiple panes, which can be adjusted in size.
68 */
69class SOUI_EXP SSplitWnd : public SWindow {
70 DEF_SOBJECT(SWindow, L"splitwnd")
71
72 /**
73 * @enum SPLIT_ORINTATION
74 * @brief Orientation of the split window.
75 */
76 enum SPLIT_ORINTATION
77 {
78 Horizontal = 0, /**< Horizontal orientation. */
79 Vertical, /**< Vertical orientation. */
80 };
81
82 /**
83 * @struct PANESIZE
84 * @brief Size information for a pane.
85 */
86 struct PANESIZE
87 {
88 int actural; /**< Actual size of the pane. */
89 int preferred; /**< Preferred size of the pane. */
90 int minimum; /**< Minimum size of the pane. */
91 int maximum; /**< Maximum size of the pane. */
92 };
93
94 typedef SArray<PANESIZE> PANESIZELIST; /**< List of pane sizes. */
95
96 protected:
97 typedef SArray<SSplitPane *> SplitPaneList;
98 SplitPaneList m_lstPane; /**< List of panes sorted by display order. */
99 SplitPaneList m_lstPriority; /**< List of panes sorted by priority. */
100 int m_spliterSize; /**< Size of the splitter bar. */
101 int m_orintation; /**< Orientation of the split window, see SPLIT_ORINTATION. */
102
103 BOOL m_bAdjustable; /**< Flag indicating if the panes are adjustable in size. */
104 SAutoRefPtr<ISkinObj> m_pSkinSep; /**< Skin object for the splitter bar. */
105
106 CPoint m_ptDragPrev; /**< Previous position during dragging. */
107 int m_iDragSep; /**< Index of the splitter bar being dragged, -1 if no dragging. */
108
109 public:
110 /**
111 * @brief Constructor for SSplitWnd.
112 */
113 SSplitWnd(void);
114
115 /**
116 * @brief Destructor for SSplitWnd.
117 */
118 virtual ~SSplitWnd(void);
119
120 /**
121 * @brief Retrieves a pane by index.
122 * @param iPane The index of the pane.
123 * @return Pointer to the SSplitPane object.
124 */
125 SSplitPane *GetPane(UINT iPane);
126
127 /**
128 * @brief Shows a pane.
129 * @param iPane The index of the pane to show.
130 * @return TRUE if successful, otherwise FALSE.
131 */
132 BOOL ShowPane(UINT iPane);
133
134 /**
135 * @brief Hides a pane.
136 * @param iPane The index of the pane to hide.
137 * @return TRUE if successful, otherwise FALSE.
138 */
139 BOOL HidePane(UINT iPane);
140
141 /**
142 * @brief Retrieves the index of a pane by its name.
143 * @param strName The name of the pane.
144 * @return Index of the pane, or -1 if not found.
145 */
146 int PaneIndex(const SStringW &strName) const;
147
148 /**
149 * @brief Inserts a new pane.
150 * @param pane Pointer to the SSplitPane object to insert.
151 * @param index The index at which to insert the pane, default is -1 (end).
152 * @return Index of the inserted pane.
153 */
154 int InsertItem(SSplitPane *pane, int index = -1);
155
156 /**
157 * @brief Removes a pane.
158 * @param pane Pointer to the SSplitPane object to remove.
159 */
160 void RemoveItem(SSplitPane *pane);
161
162 protected:
163 /**
164 * @brief Retrieves the layout rectangle for child windows.
165 * @param prc Pointer to the rectangle to receive the layout rectangle.
166 */
167 STDMETHOD_(void, GetChildrenLayoutRect)(THIS_ RECT *prc) SCONST OVERRIDE;
168
169 /**
170 * @brief Updates the positions of child windows.
171 */
172 STDMETHOD_(void, UpdateChildrenPosition)(THIS) OVERRIDE;
173
174 /**
175 * @brief Creates child windows from an XML node.
176 * @param xmlNode The XML node containing the child window definitions.
177 * @return TRUE if successful, otherwise FALSE.
178 */
179 virtual BOOL CreateChildren(SXmlNode xmlNode);
180
181 /**
182 * @brief Sets the cursor.
183 * @param pt The mouse position.
184 * @return TRUE if the cursor was set, otherwise FALSE.
185 */
186 virtual BOOL OnSetCursor(const CPoint &pt);
187
188 /**
189 * @brief Paints the window.
190 * @param pRT Pointer to the render target.
191 */
192 void OnPaint(IRenderTarget *pRT);
193
194 /**
195 * @brief Handles left mouse button down events.
196 * @param nFlags Flags associated with the mouse event.
197 * @param pt The mouse position.
198 */
199 void OnLButtonDown(UINT nFlags, CPoint pt);
200
201 /**
202 * @brief Handles left mouse button up events.
203 * @param nFlags Flags associated with the mouse event.
204 * @param pt The mouse position.
205 */
206 void OnLButtonUp(UINT nFlags, CPoint pt);
207
208 /**
209 * @brief Handles mouse move events.
210 * @param nFlags Flags associated with the mouse event.
211 * @param pt The mouse position.
212 */
213 void OnMouseMove(UINT nFlags, CPoint pt);
214
215 protected:
216 /**
217 * @brief Comparison function for qsort.
218 * @param p1 Pointer to the first element.
219 * @param p2 Pointer to the second element.
220 * @return Comparison result.
221 */
222 static int FunComp(const void *p1, const void *p2);
223
224 /**
225 * @brief Sorts the pane list by priority.
226 * @param lstPane The list of panes to sort.
227 */
228 void SortPriorityList(SplitPaneList &lstPane);
229
230 /**
231 * @brief Fetches size information for the panes.
232 * @param lstPane The list of panes.
233 * @param lstPaneSize The list to store the size information.
234 */
235 void FatchPaneSizeInfo(const SplitPaneList &lstPane, PANESIZELIST &lstPaneSize);
236
237 /**
238 * @brief Resets the positions of the panes based on size information.
239 * @param lstPane The list of panes.
240 * @param lstPanePriority The list of panes sorted by priority.
241 * @param lstPaneSize The list of pane size information.
242 * @param offset The offset to apply.
243 * @return The remaining space after resetting positions.
244 */
245 int ResetPanesPostion(SplitPaneList &lstPane, SplitPaneList &lstPanePriority, PANESIZELIST &lstPaneSize, int offset);
246
247 /**
248 * @brief Adjusts the sizes of the panes.
249 * @param lstPriority The list of panes sorted by priority.
250 * @param remain The remaining space to distribute.
251 * @return The remaining space after adjustment.
252 */
253 int AdjustPanesSize(PANESIZELIST &lstPriority, int remain);
254
255 /**
256 * @brief Relayouts the panes within the window.
257 * @param rc The new rectangle for the window.
258 * @param lstPaneSize The list of pane size information.
259 */
260 void Relayout(const CRect &rc, PANESIZELIST lstPaneSize = PANESIZELIST());
261
262 public:
263 SOUI_ATTRS_BEGIN()
264 ATTR_INT(L"sepSize", m_spliterSize, TRUE) /**< Size of the splitter bar. */
265 ATTR_SKIN(L"sepSkin", m_pSkinSep, TRUE) /**< Skin object for the splitter bar. */
266 ATTR_BOOL(L"adjustable", m_bAdjustable, TRUE) /**< Flag indicating if the panes are adjustable in size. */
267 ATTR_INT(L"vertical", m_orintation, TRUE) /**< Orientation of the split window, see SPLIT_ORINTATION. */
268 SOUI_ATTRS_END()
269
270 SOUI_MSG_MAP_BEGIN()
271 MSG_WM_PAINT_EX(OnPaint)
272 MSG_WM_LBUTTONDOWN(OnLButtonDown)
273 MSG_WM_LBUTTONUP(OnLButtonUp)
274 MSG_WM_MOUSEMOVE(OnMouseMove)
275 SOUI_MSG_MAP_END()
276};
277
278/**
279 * @class SSplitWnd_Col
280 * @brief A vertical split window.
281 *
282 * This class represents a vertical split window, where panes are stacked vertically.
283 */
284class SOUI_EXP SSplitWnd_Col : public SSplitWnd {
285 DEF_SOBJECT(SSplitWnd, L"splitcol")
286
287 public:
288 /**
289 * @brief Constructor for SSplitWnd_Col.
290 */
292 {
293 m_pSkinSep = GETBUILTINSKIN(SKIN_SYS_SPLIT_VERT);
294 m_orintation = Vertical;
295 }
296};
297
298/**
299 * @class SSplitWnd_Row
300 * @brief A horizontal split window.
301 *
302 * This class represents a horizontal split window, where panes are arranged horizontally.
303 */
304class SOUI_EXP SSplitWnd_Row : public SSplitWnd {
305 DEF_SOBJECT(SSplitWnd, L"splitrow")
306
307 public:
308 /**
309 * @brief Constructor for SSplitWnd_Row.
310 */
312 {
313 m_pSkinSep = GETBUILTINSKIN(SKIN_SYS_SPLIT_HORZ);
314 m_orintation = Horizontal;
315 }
316};
317
318SNSEND
319
320#endif // __SSPLITWND__H__
SOUI基础DUI窗口模块
Smart pointer class for managing COM-style reference-counted objects.
布局大小类
Definition SLayoutSize.h:10
A pane within a split window.
Definition SSplitWnd.h:26
SLayoutSize m_nSizeIdeal
Definition SSplitWnd.h:57
SSplitPane()
Constructor for SSplitPane.
Definition SSplitWnd.cpp:8
SLayoutSize m_nSizeMin
Definition SSplitWnd.h:58
SLayoutSize m_nSizeMax
Definition SSplitWnd.h:59
virtual ~SSplitPane()
Destructor for SSplitPane.
Definition SSplitWnd.h:39
int m_nPriority
Definition SSplitWnd.h:60
SSplitWnd_Col()
Constructor for SSplitWnd_Col.
Definition SSplitWnd.h:291
SSplitWnd_Row()
Constructor for SSplitWnd_Row.
Definition SSplitWnd.h:311
void Relayout(const CRect &rc, PANESIZELIST lstPaneSize=PANESIZELIST())
Relayouts the panes within the window.
static int FunComp(const void *p1, const void *p2)
Comparison function for qsort.
int m_orintation
Definition SSplitWnd.h:101
void OnLButtonUp(UINT nFlags, CPoint pt)
Handles left mouse button up events.
SplitPaneList m_lstPane
Definition SSplitWnd.h:98
SAutoRefPtr< ISkinObj > m_pSkinSep
Definition SSplitWnd.h:104
SSplitWnd(void)
Constructor for SSplitWnd.
Definition SSplitWnd.cpp:26
void UpdateChildrenPosition() OVERRIDE
Updates the positions of child windows.
void OnLButtonDown(UINT nFlags, CPoint pt)
Handles left mouse button down events.
int InsertItem(SSplitPane *pane, int index=-1)
Inserts a new pane.
void OnMouseMove(UINT nFlags, CPoint pt)
Handles mouse move events.
void RemoveItem(SSplitPane *pane)
Removes a pane.
void GetChildrenLayoutRect(RECT *prc) SCONST OVERRIDE
Retrieves the layout rectangle for child windows.
int m_spliterSize
Definition SSplitWnd.h:100
BOOL HidePane(UINT iPane)
Hides a pane.
Definition SSplitWnd.cpp:49
int ResetPanesPostion(SplitPaneList &lstPane, SplitPaneList &lstPanePriority, PANESIZELIST &lstPaneSize, int offset)
Resets the positions of the panes based on size information.
SSplitPane * GetPane(UINT iPane)
Retrieves a pane by index.
int m_iDragSep
Definition SSplitWnd.h:107
void FatchPaneSizeInfo(const SplitPaneList &lstPane, PANESIZELIST &lstPaneSize)
Fetches size information for the panes.
CPoint m_ptDragPrev
Definition SSplitWnd.h:106
int AdjustPanesSize(PANESIZELIST &lstPriority, int remain)
Adjusts the sizes of the panes.
BOOL m_bAdjustable
Definition SSplitWnd.h:103
int PaneIndex(const SStringW &strName) const
Retrieves the index of a pane by its name.
void SortPriorityList(SplitPaneList &lstPane)
Sorts the pane list by priority.
SplitPaneList m_lstPriority
Definition SSplitWnd.h:99
BOOL ShowPane(UINT iPane)
Shows a pane.
Definition SSplitWnd.cpp:39
void OnPaint(IRenderTarget *pRT)
Paints the window.
Definition SSplitWnd.cpp:86
A class representing an ASCII string.
Definition sstringw.h:96
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 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
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 Move(LPCRECT prect) OVERRIDE
Moves the window to a new position and size.
Definition Swnd.cpp:399
Class representing an XML node.
Definition SXml.h:352
Interface for rendering target objects.
Definition SRender-i.h:1440