soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SouiLayout.h
1#ifndef __SOUILAYOUT__H__
2#define __SOUILAYOUT__H__
3
4#include <interface/slayout-i.h>
5#include <layout/SouiLayoutParamStruct.h>
6#include <sobject/Sobject.hpp>
7
8SNSBEGIN
9
10/**
11 * @class SouiLayoutParam
12 * @brief Soui布局参数类
13 */
15 : public TObjRefImpl<SObjectImpl<ILayoutParam>>
16 , protected SouiLayoutParamStruct {
17 DEF_SOBJECT(SObjectImpl<ILayoutParam>, L"SouiLayoutParam")
18
19 friend class SouiLayout;
20
21 public:
22 /**
23 * @brief 构造函数
24 */
26
27 /**
28 * @brief 清除布局参数
29 */
30 STDMETHOD_(void, Clear)(THIS) OVERRIDE;
31
32 /**
33 * @brief 检查是否匹配父容器大小
34 * @param orientation 方向(水平或垂直)
35 * @return 如果匹配父容器大小返回TRUE,否则返回FALSE
36 */
37 STDMETHOD_(BOOL, IsMatchParent)(THIS_ ORIENTATION orientation) SCONST OVERRIDE;
38
39 /**
40 * @brief 检查是否包裹内容大小
41 * @param orientation 方向(水平或垂直)
42 * @return 如果包裹内容大小返回TRUE,否则返回FALSE
43 */
44 STDMETHOD_(BOOL, IsWrapContent)(THIS_ ORIENTATION orientation) SCONST OVERRIDE;
45
46 /**
47 * @brief 检查是否指定大小
48 * @param orientation 方向(水平或垂直)
49 * @return 如果指定大小返回TRUE,否则返回FALSE
50 */
51 STDMETHOD_(BOOL, IsSpecifiedSize)(THIS_ ORIENTATION orientation) SCONST OVERRIDE;
52
53 /**
54 * @brief 获取指定大小
55 * @param orientation 方向(水平或垂直)
56 * @return 指定大小
57 */
58 STDMETHOD_(SLayoutSize, GetSpecifiedSize)(THIS_ ORIENTATION orientation) SCONST OVERRIDE;
59
60 /**
61 * @brief 设置匹配父容器大小
62 * @param orientation 方向(水平或垂直)
63 */
64 STDMETHOD_(void, SetMatchParent)(THIS_ ORIENTATION orientation) OVERRIDE;
65
66 /**
67 * @brief 设置包裹内容大小
68 * @param orientation 方向(水平或垂直)
69 */
70 STDMETHOD_(void, SetWrapContent)(THIS_ ORIENTATION orientation) OVERRIDE;
71
72 /**
73 * @brief 设置指定大小
74 * @param orientation 方向(水平或垂直)
75 * @param layoutSize 指定大小
76 */
77 STDMETHOD_(void, SetSpecifiedSize)
78 (THIS_ ORIENTATION orientation, const SLayoutSize &layoutSize) OVERRIDE;
79
80 /**
81 * @brief 获取原始数据指针
82 * @return 原始数据指针
83 */
84 STDMETHOD_(void *, GetRawData)(THIS) OVERRIDE;
85
86 /**
87 * @brief 克隆布局参数
88 * @return 克隆的布局参数对象指针
89 */
90 STDMETHOD_(ILayoutParam *, Clone)(THIS) SCONST OVERRIDE;
91
92 public:
93 /**
94 * @brief 检查是否需要偏移
95 * @param orientation 方向(水平或垂直)
96 * @return 如果需要偏移返回TRUE,否则返回FALSE
97 */
98 bool IsOffsetRequired(ORIENTATION orientation) const;
99
100 /**
101 * @brief 获取额外大小
102 * @param orientation 方向(水平或垂直)
103 * @param nScale 缩放比例
104 * @return 额外大小
105 */
106 int GetExtraSize(ORIENTATION orientation, int nScale) const;
107
108 protected:
109 /**
110 * @brief 处理宽度属性
111 * @param strValue 属性值字符串
112 * @param bLoading 是否正在加载
113 * @return 处理结果
114 */
115 HRESULT OnAttrWidth(const SStringW &strValue, BOOL bLoading);
116
117 /**
118 * @brief 处理高度属性
119 * @param strValue 属性值字符串
120 * @param bLoading 是否正在加载
121 * @return 处理结果
122 */
123 HRESULT OnAttrHeight(const SStringW &strValue, BOOL bLoading);
124
125 /**
126 * @brief 处理大小属性
127 * @param strValue 属性值字符串
128 * @param bLoading 是否正在加载
129 * @return 处理结果
130 */
131 HRESULT OnAttrSize(const SStringW &strValue, BOOL bLoading);
132
133 /**
134 * @brief 处理位置属性
135 * @param strValue 属性值字符串
136 * @param bLoading 是否正在加载
137 * @return 处理结果
138 */
139 HRESULT OnAttrPos(const SStringW &strValue, BOOL bLoading);
140
141 /**
142 * @brief 处理偏移属性
143 * @param strValue 属性值字符串
144 * @param bLoading 是否正在加载
145 * @return 处理结果
146 */
147 HRESULT OnAttrOffset(const SStringW &strValue, BOOL bLoading);
148
149 SOUI_ATTRS_BEGIN()
150 ATTR_CUSTOM(L"width", OnAttrWidth) // 宽度
151 ATTR_CUSTOM(L"height", OnAttrHeight) // 高度
152 ATTR_CUSTOM(L"pos", OnAttrPos) // 位置
153 ATTR_CUSTOM(L"size", OnAttrSize) // 大小
154 ATTR_CUSTOM(L"offset", OnAttrOffset) // 偏移
155 SOUI_ATTRS_BREAK()
156
157 protected:
158 /**
159 * @brief 将字符串描述的坐标转换成POSITION_ITEM
160 * @param strPos 坐标字符串
161 * @param posItem 位置信息结构体引用
162 * @return 如果成功转换返回TRUE,否则返回FALSE
163 */
164 BOOL StrPos2ItemPos(const SStringW &strPos, POS_INFO &posItem);
165
166 /**
167 * @brief 解析在pos中定义的前两个位置
168 * @param pos1 第一个位置字符串
169 * @param pos2 第二个位置字符串
170 * @return 如果成功解析返回TRUE,否则返回FALSE
171 */
172 BOOL ParsePosition12(const SStringW &pos1, const SStringW &pos2);
173
174 /**
175 * @brief 解析在pos中定义的后两个位置
176 * @param pos3 第三个位置字符串
177 * @param pos4 第四个位置字符串
178 * @return 如果成功解析返回TRUE,否则返回FALSE
179 */
180 BOOL ParsePosition34(const SStringW &pos3, const SStringW &pos4);
181};
182
183/**
184 * @class SouiLayout
185 * @brief Soui布局类
186 */
187class SOUI_EXP SouiLayout : public TObjRefImpl<SObjectImpl<ILayout>> {
188 DEF_SOBJECT(SObjectImpl<ILayout>, L"SouiLayout")
189
190 public:
191 /**
192 * @brief 构造函数
193 */
194 SouiLayout(void);
195
196 /**
197 * @brief 析构函数
198 */
199 ~SouiLayout(void);
200
201 /**
202 * @brief 检查布局参数是否可接受
203 * @param pLayoutParam 布局参数对象指针
204 * @return 如果可接受返回TRUE,否则返回FALSE
205 */
206 STDMETHOD_(BOOL, IsParamAcceptable)(THIS_ const ILayoutParam *pLayoutParam) SCONST OVERRIDE;
207
208 /**
209 * @brief 布局子窗口
210 * @param pParent 父窗口指针
211 */
212 STDMETHOD_(void, LayoutChildren)(THIS_ IWindow *pParent) OVERRIDE;
213
214 /**
215 * @brief 创建布局参数对象
216 * @return 布局参数对象指针
217 */
218 STDMETHOD_(ILayoutParam *, CreateLayoutParam)(THIS) SCONST OVERRIDE;
219
220 /**
221 * @brief 测量子窗口大小
222 * @param pParent 父窗口指针
223 * @param nWidth 宽度
224 * @param nHeight 高度
225 * @return 测量结果大小
226 */
227 STDMETHOD_(SIZE, MeasureChildren)
228 (THIS_ const IWindow *pParent, int nWidth, int nHeight) SCONST OVERRIDE;
229
230 protected:
231 /**
232 * @struct WndPos
233 * @brief 窗口位置结构体
234 */
235 struct WndPos
236 {
237 SWindow *pWnd; // 窗口指针
238 CRect rc; // 窗口矩形区域
239 bool bWaitOffsetX; // 是否等待X方向偏移
240 bool bWaitOffsetY; // 是否等待Y方向偏移
241 };
242
243 /**
244 * @brief 计算扩展位置
245 * @param pListChildren 子窗口列表指针
246 * @param nWidth 宽度
247 * @param nHeight 高度
248 */
249 void CalcPositionEx(SList<WndPos> *pListChildren, int nWidth, int nHeight) const;
250
251 /**
252 * @brief 计算位置
253 * @param pListChildren 子窗口列表指针
254 * @param nWidth 宽度
255 * @param nHeight 高度
256 * @return 计算结果
257 */
258 int CalcPostion(SList<WndPos> *pListChildren, int nWidth, int nHeight) const;
259
260 /**
261 * @brief 将位置项转换为值
262 * @param pLstChilds 子窗口列表指针
263 * @param position 位置指针
264 * @param pos 位置信息结构体
265 * @param nMax 最大值
266 * @param bX 是否为X方向
267 * @param nScale 缩放比例
268 * @return 计算的值
269 */
270 int PositionItem2Value(SList<WndPos> *pLstChilds, SPOSITION position, const POS_INFO &pos, int nMax, BOOL bX, int nScale) const;
271
272 /**
273 * @brief 计算子窗口左侧位置
274 * @param pWindow 窗口指针
275 * @param pParam 布局参数对象指针
276 * @return 计算的左侧位置
277 */
278 int CalcChildLeft(SWindow *pWindow, SouiLayoutParam *pParam);
279
280 /**
281 * @brief 计算子窗口右侧位置
282 * @param pWindow 窗口指针
283 * @param pParam 布局参数对象指针
284 * @return 计算的右侧位置
285 */
286 int CalcChildRight(SWindow *pWindow, SouiLayoutParam *pParam);
287
288 /**
289 * @brief 计算子窗口顶部位置
290 * @param pWindow 窗口指针
291 * @param pParam 布局参数对象指针
292 * @return 计算的顶部位置
293 */
294 int CalcChildTop(SWindow *pWindow, SouiLayoutParam *pParam);
295
296 /**
297 * @brief 计算子窗口底部位置
298 * @param pWindow 窗口指针
299 * @param pParam 布局参数对象指针
300 * @return 计算的底部位置
301 */
303
304 /**
305 * @brief 检查位置是否等待
306 * @param nPos 位置值
307 * @return 如果等待返回TRUE,否则返回FALSE
308 */
309 BOOL IsWaitingPos(int nPos) const;
310
311 /**
312 * @brief 获取参考兄弟窗口
313 * @param pCurWnd 当前窗口指针
314 * @param uCode 代码
315 * @return 参考兄弟窗口指针
316 */
317 SWindow *GetRefSibling(SWindow *pCurWnd, int uCode);
318
319 /**
320 * @brief 获取窗口布局矩形区域
321 * @param pWindow 窗口指针
322 * @return 窗口布局矩形区域
323 */
325};
326
327SNSEND
328
329#endif // __SOUILAYOUT__H__
布局大小类
Definition SLayoutSize.h:10
A class representing an ASCII string.
Definition sstringw.h:96
Base class for SOUI DUI windows.
Definition SWnd.h:286
SWindow * GetRefSibling(SWindow *pCurWnd, int uCode)
获取参考兄弟窗口
int CalcChildBottom(SWindow *pWindow, SouiLayoutParam *pParam)
计算子窗口底部位置
void CalcPositionEx(SList< WndPos > *pListChildren, int nWidth, int nHeight) const
计算扩展位置
BOOL IsParamAcceptable(const ILayoutParam *pLayoutParam) SCONST OVERRIDE
检查布局参数是否可接受
CRect GetWindowLayoutRect(SWindow *pWindow)
获取窗口布局矩形区域
int PositionItem2Value(SList< WndPos > *pLstChilds, SPOSITION position, const POS_INFO &pos, int nMax, BOOL bX, int nScale) const
将位置项转换为值
SIZE MeasureChildren(const IWindow *pParent, int nWidth, int nHeight) SCONST OVERRIDE
测量子窗口大小
SouiLayout(void)
构造函数
int CalcPostion(SList< WndPos > *pListChildren, int nWidth, int nHeight) const
计算位置
ILayoutParam * CreateLayoutParam() SCONST OVERRIDE
创建布局参数对象
BOOL IsWaitingPos(int nPos) const
检查位置是否等待
void LayoutChildren(IWindow *pParent) OVERRIDE
布局子窗口
int CalcChildRight(SWindow *pWindow, SouiLayoutParam *pParam)
计算子窗口右侧位置
int CalcChildTop(SWindow *pWindow, SouiLayoutParam *pParam)
计算子窗口顶部位置
int CalcChildLeft(SWindow *pWindow, SouiLayoutParam *pParam)
计算子窗口左侧位置
Soui布局参数类
Definition SouiLayout.h:16
ILayoutParam * Clone() SCONST OVERRIDE
克隆布局参数
BOOL IsSpecifiedSize(ORIENTATION orientation) SCONST OVERRIDE
检查是否指定大小
SouiLayoutParam()
构造函数
BOOL ParsePosition12(const SStringW &pos1, const SStringW &pos2)
解析在pos中定义的前两个位置
void SetSpecifiedSize(ORIENTATION orientation, const SLayoutSize &layoutSize) OVERRIDE
设置指定大小
HRESULT OnAttrPos(const SStringW &strValue, BOOL bLoading)
处理位置属性
HRESULT OnAttrSize(const SStringW &strValue, BOOL bLoading)
处理大小属性
BOOL StrPos2ItemPos(const SStringW &strPos, POS_INFO &posItem)
将字符串描述的坐标转换成POSITION_ITEM
HRESULT OnAttrWidth(const SStringW &strValue, BOOL bLoading)
处理宽度属性
void Clear() OVERRIDE
清除布局参数
void * GetRawData() OVERRIDE
获取原始数据指针
SLayoutSize GetSpecifiedSize(ORIENTATION orientation) SCONST OVERRIDE
获取指定大小
int GetExtraSize(ORIENTATION orientation, int nScale) const
获取额外大小
HRESULT OnAttrHeight(const SStringW &strValue, BOOL bLoading)
处理高度属性
BOOL IsWrapContent(ORIENTATION orientation) SCONST OVERRIDE
检查是否包裹内容大小
void SetMatchParent(ORIENTATION orientation) OVERRIDE
设置匹配父容器大小
bool IsOffsetRequired(ORIENTATION orientation) const
检查是否需要偏移
BOOL ParsePosition34(const SStringW &pos3, const SStringW &pos4)
解析在pos中定义的后两个位置
HRESULT OnAttrOffset(const SStringW &strValue, BOOL bLoading)
处理偏移属性
void SetWrapContent(ORIENTATION orientation) OVERRIDE
设置包裹内容大小
BOOL IsMatchParent(ORIENTATION orientation) SCONST OVERRIDE
检查是否匹配父容器大小
窗口位置结构体
Definition SouiLayout.h:236