soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SwndStyle.cpp
1//////////////////////////////////////////////////////////////////////////
2// File Name: SwndStyle.h
3//////////////////////////////////////////////////////////////////////////
4
5#include "souistd.h"
6#include "core/SWndStyle.h"
7#include "core/SWnd.h"
8#include "helper/SplitString.h"
9
10SNSBEGIN
11
13 : m_uAlign(Align_Center)
14 , m_uVAlign(VAlign_Middle)
15 , m_nTextAlign(0)
16 , m_crBg(CR_INVALID)
17 , m_crBorder(CR_INVALID)
18 , m_strCursor(_T("arrow"))
19 , m_bDotted(0)
22 , m_nScale(100)
23 , m_bMultiLines(FALSE)
24{
25 for (int i = 0; i < 4; i++)
26 {
27 m_crText[i] = CR_INVALID;
28 }
29}
30
32{
33 return m_uAlign | m_uVAlign;
34}
35
37{
38 if (m_nTextAlign)
39 return m_nTextAlign;
40 UINT uRet = 0;
41 switch (m_uAlign)
42 {
43 case Align_Center:
44 uRet |= DT_CENTER;
45 break;
46 case Align_Right:
47 uRet |= DT_RIGHT;
48 break;
49 }
50 switch (m_uVAlign)
51 {
52 case VAlign_Middle:
53 uRet |= DT_VCENTER;
54 break;
55 case VAlign_Bottom:
56 uRet |= DT_BOTTOM;
57 break;
58 }
59 if (!m_bMultiLines)
60 uRet |= DT_SINGLELINE;
61 if (m_bDotted)
62 uRet |= DT_END_ELLIPSIS;
63 return uRet;
64}
65
67{
68 int fonts = 1, colors = 1;
69 for (int i = 1; i < 4; i++)
70 {
71 if (m_ftText[i].GetFontPtr() != NULL)
72 fonts++;
73 if (m_crText[i] != CR_INVALID)
74 colors++;
75 }
76 return smax(fonts, colors);
77}
78
79COLORREF SwndStyle::GetTextColor(int iState)
80{
81 iState %= 4;
82 if (m_crText[iState] == CR_INVALID)
83 iState = 0;
84 return m_crText[iState];
85}
86
87IFontPtr SwndStyle::GetTextFont(int iState)
88{
89 iState %= 4;
90 if (!m_ftText[iState].GetFontPtr())
91 iState = 0;
92 return m_ftText[iState].GetFontPtr();
93}
94
95HRESULT SwndStyle::OnAttrMargin(const SStringW &strValue, BOOL bLoading)
96{
98 return !bLoading ? S_OK : S_FALSE;
99}
100
101HRESULT SwndStyle::OnAttrMarginX(const SStringW &strValue, BOOL bLoading)
102{
103 m_rcMargin[0] = m_rcMargin[2] = GETLAYOUTSIZE(strValue);
104 return !bLoading ? S_OK : S_FALSE;
105}
106
107HRESULT SwndStyle::OnAttrMarginY(const SStringW &strValue, BOOL bLoading)
108{
109 m_rcMargin[1] = m_rcMargin[3] = GETLAYOUTSIZE(strValue);
110
111 return !bLoading ? S_OK : S_FALSE;
112}
113
114void SwndStyle::_ParseLayoutSize4(const SStringW &strValue, SLayoutSize layoutSizes[])
115{
116 SStringWList values;
117 size_t nValues = SplitString(strValue, L',', values);
118 if (nValues == 1)
119 {
120 layoutSizes[0] = layoutSizes[1] = layoutSizes[2] = layoutSizes[3] = GETLAYOUTSIZE(values[0]);
121 }
122 else if (nValues == 2)
123 {
124 layoutSizes[0] = layoutSizes[2] = GETLAYOUTSIZE(values[0]);
125 layoutSizes[1] = layoutSizes[3] = GETLAYOUTSIZE(values[1]);
126 }
127 else if (nValues == 4)
128 {
129 layoutSizes[0] = GETLAYOUTSIZE(values[0]);
130 layoutSizes[1] = GETLAYOUTSIZE(values[1]);
131 layoutSizes[2] = GETLAYOUTSIZE(values[2]);
132 layoutSizes[3] = GETLAYOUTSIZE(values[3]);
133 }
134}
135
136HRESULT SwndStyle::OnAttrPadding(const SStringW &strValue, BOOL bLoading)
137{
138 _ParseLayoutSize4(strValue, m_rcInset);
139 return bLoading ? S_FALSE : S_OK;
140}
141
142void SwndStyle::SetScale(int nScale)
143{
144 m_nScale = nScale;
145 for (int i = 0; i < 4; i++)
146 {
147 m_ftText[i].UpdateFont(nScale);
148 }
149}
150
152{
153 return m_nScale;
154}
155
157{
158 CRect rcRet;
159 rcRet.left = m_rcMargin[0].toPixelSize(GetScale());
160 rcRet.top = m_rcMargin[1].toPixelSize(GetScale());
161 rcRet.right = m_rcMargin[2].toPixelSize(GetScale());
162 rcRet.bottom = m_rcMargin[3].toPixelSize(GetScale());
163 return rcRet;
164}
165
167{
168 CRect rcRet;
169 rcRet.left = m_rcInset[0].toPixelSize(GetScale());
170 rcRet.top = m_rcInset[1].toPixelSize(GetScale());
171 rcRet.right = m_rcInset[2].toPixelSize(GetScale());
172 rcRet.bottom = m_rcInset[3].toPixelSize(GetScale());
173 return rcRet;
174}
175
176void SwndStyle::SetAlign(UINT uAlign)
177{
178 m_uAlign = uAlign;
179}
180
181void SwndStyle::SetVAlign(UINT uAlign)
182{
183 m_uVAlign = uAlign;
184}
185
187{
188 for (int i = 0; i < 4; i++)
189 {
190 m_ftText[i].UpdateFont(m_nScale);
191 }
192}
193
194SNSEND
SOUI基础DUI窗口模块
SOUI窗口风格管理
布局大小类
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
void UpdateFont()
Updates the font based on the current scale.
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
COLORREF m_crText[4]
Definition SWndStyle.h:174
int GetScale() const
Retrieves the scale factor.
BOOL m_bMultiLines
Definition SWndStyle.h:171
void _ParseLayoutSize4(const SStringW &strValue, SLayoutSize layoutSizes[])
Parses a string into an array of layout sizes.
HRESULT OnAttrPadding(const SStringW &strValue, BOOL bLoading)
Handles the 'padding' attribute.
UINT m_nTextAlign
Definition SWndStyle.h:172
void SetScale(int nScale)
Sets the scale factor.
SStringT m_strCursor
Definition SWndStyle.h:61
void SetVAlign(UINT uAlign)
Sets the vertical alignment.
COLORREF m_crBorder
Definition SWndStyle.h:59
void SetAlign(UINT uAlign)
Sets the horizontal alignment.
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
CRect GetMargin() const
Retrieves the margin rectangle.
CRect GetPadding() const
Retrieves the padding rectangle.