soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SWndStyle.h
Go to the documentation of this file.
1/**
2 * Copyright (C) 2014-2050
3 * All rights reserved.
4 *
5 * @file SwndStyle.h
6 * @brief SOUI窗口风格管理
7 * @version v1.0
8 * @author SOUI group
9 * @date 2014/08/02
10 *
11 * Description: This file defines the SwndStyle class, which manages the style attributes of SOUI windows.
12 */
13
14#ifndef __SWNDSTYLE__H__
15#define __SWNDSTYLE__H__
16
17#include "res.mgr/SDpiAwareFont.h"
18
19SNSBEGIN
20
21/**
22 * @class SwndStyle
23 * @brief Manages the style attributes of SOUI windows.
24 *
25 * This class provides functionality to manage various style attributes of SOUI windows, including
26 * text alignment, background and border colors, cursor, text colors, fonts, margins, and padding.
27 */
28class SOUI_EXP SwndStyle {
29 public:
30 /**
31 * @brief Alignment constants for horizontal alignment.
32 */
33 enum
34 {
35 Align_Left = 0x000U, // valign = top
36 Align_Center = 0x100U, // valign = middle
37 Align_Right = 0x200U, // valign = bottom
38 Align_MaskX = 0x300U,
39 };
40
41 /**
42 * @brief Alignment constants for vertical alignment.
43 */
44 enum
45 {
46 VAlign_Top = 0x0000U, // valign = top
47 VAlign_Middle = 0x1000U, // valign = middle
48 VAlign_Bottom = 0x2000U, // valign = bottom
49 Align_MaskY = 0x3000U,
50 };
51
52 public:
53 /**
54 * @brief Constructor.
55 */
56 SwndStyle();
57
58 COLORREF m_crBg; /**< Background color */
59 COLORREF m_crBorder; /**< Border color */
60
61 SStringT m_strCursor; /**< Cursor name */
62
63 DWORD m_bDotted : 1; /**< Support ellipsis for text */
64 DWORD m_bTrackMouseEvent : 1; /**< Monitor mouse enter and leave messages */
65 DWORD m_bVideoCanvas : 1; /**< Video rendering canvas */
66
67 /**
68 * @brief Retrieves the text alignment.
69 * @return Text alignment flags.
70 */
71 UINT GetTextAlign() const;
72
73 /**
74 * @brief Retrieves the alignment (horizontal and vertical).
75 * @return Alignment flags.
76 */
77 UINT GetAlign() const;
78
79 /**
80 * @brief Retrieves the number of states.
81 * @return Number of states.
82 */
83 int GetStates();
84
85 /**
86 * @brief Retrieves the text color for a specific state.
87 * @param iState State index.
88 * @return Text color for the specified state.
89 */
90 COLORREF GetTextColor(int iState);
91
92 /**
93 * @brief Retrieves the text font for a specific state.
94 * @param iState State index.
95 * @return Text font for the specified state.
96 */
97 IFontPtr GetTextFont(int iState);
98
99 /**
100 * @brief Retrieves the margin rectangle.
101 * @return Margin rectangle.
102 */
103 CRect GetMargin() const;
104
105 /**
106 * @brief Retrieves the padding rectangle.
107 * @return Padding rectangle.
108 */
109 CRect GetPadding() const;
110
111 /**
112 * @brief Sets the text color for a specific state.
113 * @param iState State index.
114 * @param cr Text color to set.
115 */
116 void SetTextColor(int iState, COLORREF cr)
117 {
118 m_crText[iState] = cr;
119 }
120
121 /**
122 * @brief Sets the scale factor.
123 * @param nScale Scale factor to set.
124 */
125 void SetScale(int nScale);
126
127 /**
128 * @brief Retrieves the scale factor.
129 * @return Scale factor.
130 */
131 int GetScale() const;
132
133 /**
134 * @brief Sets the horizontal alignment.
135 * @param uAlign Horizontal alignment flags.
136 */
137 void SetAlign(UINT uAlign);
138
139 /**
140 * @brief Sets the vertical alignment.
141 * @param uAlign Vertical alignment flags.
142 */
143 void SetVAlign(UINT uAlign);
144
145 /**
146 * @brief Retrieves the multi-line flag.
147 * @return TRUE if multi-lines are enabled, FALSE otherwise.
148 */
149 BOOL GetMultiLines() const
150 {
151 return m_bMultiLines;
152 }
153
154 /**
155 * @brief Sets the multi-line flag.
156 * @param bMultiLines TRUE to enable multi-lines, FALSE to disable.
157 */
158 void SetMultiLines(BOOL bMultiLines)
159 {
160 m_bMultiLines = bMultiLines;
161 }
162
163 /**
164 * @brief Updates the font based on the current scale.
165 */
166 void UpdateFont();
167
168 protected:
169 SLayoutSize m_rcMargin[4]; /**< 4-week non-client area size */
170 SLayoutSize m_rcInset[4]; /**< Text area 4-directional inner padding */
171 BOOL m_bMultiLines; /**< Multiple lines flag */
172 UINT m_nTextAlign; /**< Text alignment */
173 UINT m_uAlign, m_uVAlign; /**< Horizontal and vertical alignment */
174 COLORREF m_crText[4]; /**< Text color for 4 states */
175 SDpiAwareFont m_ftText[4]; /**< Text font for 4 states */
176
177 int m_nScale;
178
179 /**
180 * @brief Handles the 'padding' attribute.
181 * @param strValue Attribute value.
182 * @param bLoading TRUE if loading, FALSE otherwise.
183 * @return HRESULT indicating success or failure.
184 */
185 HRESULT OnAttrPadding(const SStringW &strValue, BOOL bLoading);
186
187 /**
188 * @brief Handles the 'margin' attribute.
189 * @param strValue Attribute value.
190 * @param bLoading TRUE if loading, FALSE otherwise.
191 * @return HRESULT indicating success or failure.
192 */
193 HRESULT OnAttrMargin(const SStringW &strValue, BOOL bLoading);
194
195 /**
196 * @brief Handles the 'margin-x' attribute.
197 * @param strValue Attribute value.
198 * @param bLoading TRUE if loading, FALSE otherwise.
199 * @return HRESULT indicating success or failure.
200 */
201 HRESULT OnAttrMarginX(const SStringW &strValue, BOOL bLoading);
202
203 /**
204 * @brief Handles the 'margin-y' attribute.
205 * @param strValue Attribute value.
206 * @param bLoading TRUE if loading, FALSE otherwise.
207 * @return HRESULT indicating success or failure.
208 */
209 HRESULT OnAttrMarginY(const SStringW &strValue, BOOL bLoading);
210
211 /**
212 * @brief Parses a string into an array of layout sizes.
213 * @param strValue String containing layout sizes.
214 * @param layoutSizes Array to store parsed layout sizes.
215 */
216 void _ParseLayoutSize4(const SStringW &strValue, SLayoutSize layoutSizes[]);
217
218 SOUI_ATTRS_BEGIN()
219 ATTR_HEX(L"textMode", m_nTextAlign, TRUE)
220 ATTR_BOOL(L"multiLines", m_bMultiLines, TRUE)
221 ATTR_ENUM_BEGIN(L"align", UINT, TRUE)
222 ATTR_ENUM_VALUE(L"left", Align_Left)
223 ATTR_ENUM_VALUE(L"center", Align_Center)
224 ATTR_ENUM_VALUE(L"right", Align_Right)
225 ATTR_ENUM_END(m_uAlign)
226 ATTR_ENUM_BEGIN(L"valign", UINT, TRUE)
227 ATTR_ENUM_VALUE(L"top", VAlign_Top)
228 ATTR_ENUM_VALUE(L"middle", VAlign_Middle)
229 ATTR_ENUM_VALUE(L"bottom", VAlign_Bottom)
230 ATTR_ENUM_END(m_uVAlign)
231
232 ATTR_COLOR(L"colorBkgnd", m_crBg, TRUE)
233 ATTR_COLOR(L"colorBorder", m_crBorder, TRUE)
234
235 ATTR_FONT(L"font", m_ftText[0], TRUE)
236 ATTR_FONT(L"fontHover", m_ftText[1], TRUE)
237 ATTR_FONT(L"fontPush", m_ftText[2], TRUE)
238 ATTR_FONT(L"fontDisable", m_ftText[3], TRUE)
239
240 ATTR_COLOR(L"colorText", m_crText[0], TRUE)
241 ATTR_COLOR(L"colorTextHover", m_crText[1], TRUE)
242 ATTR_COLOR(L"colorTextPush", m_crText[2], TRUE)
243 ATTR_COLOR(L"colorTextDisable", m_crText[3], TRUE)
244
245 ATTR_CUSTOM(L"margin-x", OnAttrMarginX)
246 ATTR_CUSTOM(L"margin-y", OnAttrMarginY)
247 ATTR_CUSTOM(L"margin", OnAttrMargin)
248 ATTR_CUSTOM(L"inset", OnAttrPadding)
249 ATTR_CUSTOM(L"padding", OnAttrPadding)
250 ATTR_LAYOUTSIZE(L"padding_left", m_rcInset[0], TRUE)
251 ATTR_LAYOUTSIZE(L"padding_top", m_rcInset[1], TRUE)
252 ATTR_LAYOUTSIZE(L"padding_right", m_rcInset[2], TRUE)
253 ATTR_LAYOUTSIZE(L"padding_bottom", m_rcInset[3], TRUE)
254 ATTR_STRINGT(L"cursor", m_strCursor, FALSE)
255 ATTR_INT(L"dotted", m_bDotted, FALSE)
256 SOUI_ATTRS_BREAK()
257};
258
259SNSEND
260#endif // __SWNDSTYLE__H__
Class for managing DPI-aware fonts. This class provides functionality to handle font scaling based on...
布局大小类
Definition SLayoutSize.h:10
A class representing an ASCII string.
Definition sstringw.h:96
SwndStyle()
Constructor.
Definition SwndStyle.cpp:12
UINT GetTextAlign() const
Retrieves the text alignment.
Definition SwndStyle.cpp:36
SLayoutSize m_rcInset[4]
Definition SWndStyle.h:170
SDpiAwareFont m_ftText[4]
Definition SWndStyle.h:175
UINT GetAlign() const
Retrieves the alignment (horizontal and vertical).
Definition SwndStyle.cpp:31
IFontPtr GetTextFont(int iState)
Retrieves the text font for a specific state.
Definition SwndStyle.cpp:87
BOOL GetMultiLines() const
Retrieves the multi-line flag.
Definition SWndStyle.h:149
COLORREF m_crText[4]
Definition SWndStyle.h:174
BOOL m_bMultiLines
Definition SWndStyle.h:171
void _ParseLayoutSize4(const SStringW &strValue, SLayoutSize layoutSizes[])
Parses a string into an array of layout sizes.
void SetMultiLines(BOOL bMultiLines)
Sets the multi-line flag.
Definition SWndStyle.h:158
HRESULT OnAttrPadding(const SStringW &strValue, BOOL bLoading)
Handles the 'padding' attribute.
UINT m_nTextAlign
Definition SWndStyle.h:172
SStringT m_strCursor
Definition SWndStyle.h:61
COLORREF m_crBorder
Definition SWndStyle.h:59
DWORD m_bTrackMouseEvent
Definition SWndStyle.h:64
HRESULT OnAttrMarginX(const SStringW &strValue, BOOL bLoading)
Handles the 'margin-x' attribute.
SLayoutSize m_rcMargin[4]
Definition SWndStyle.h:169
DWORD m_bDotted
Definition SWndStyle.h:63
HRESULT OnAttrMarginY(const SStringW &strValue, BOOL bLoading)
Handles the 'margin-y' attribute.
UINT m_uVAlign
Definition SWndStyle.h:173
HRESULT OnAttrMargin(const SStringW &strValue, BOOL bLoading)
Handles the 'margin' attribute.
Definition SwndStyle.cpp:95
int GetStates()
Retrieves the number of states.
Definition SwndStyle.cpp:66
COLORREF m_crBg
Definition SWndStyle.h:58
COLORREF GetTextColor(int iState)
Retrieves the text color for a specific state.
Definition SwndStyle.cpp:79
DWORD m_bVideoCanvas
Definition SWndStyle.h:65
void SetTextColor(int iState, COLORREF cr)
Sets the text color for a specific state.
Definition SWndStyle.h:116
CRect GetMargin() const
Retrieves the margin rectangle.
CRect GetPadding() const
Retrieves the padding rectangle.