Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: xfa/fwl/core/ifwl_checkbox.cpp

Issue 2501033005: Continue fwl/core nit cleanup. (Closed)
Patch Set: Rebase to master Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fwl/core/ifwl_checkbox.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fwl/core/ifwl_checkbox.h" 7 #include "xfa/fwl/core/ifwl_checkbox.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 26 matching lines...) Expand all
37 m_rtFocus.Reset(); 37 m_rtFocus.Reset();
38 } 38 }
39 39
40 IFWL_CheckBox::~IFWL_CheckBox() {} 40 IFWL_CheckBox::~IFWL_CheckBox() {}
41 41
42 FWL_Type IFWL_CheckBox::GetClassID() const { 42 FWL_Type IFWL_CheckBox::GetClassID() const {
43 return FWL_Type::CheckBox; 43 return FWL_Type::CheckBox;
44 } 44 }
45 45
46 void IFWL_CheckBox::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { 46 void IFWL_CheckBox::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) {
47 if (bAutoSize) { 47 if (!bAutoSize) {
48 rect.Set(0, 0, 0, 0);
49 if (!m_pProperties->m_pThemeProvider)
50 m_pProperties->m_pThemeProvider = GetAvailableTheme();
51 if (!m_pProperties->m_pThemeProvider)
52 return;
53 if (!m_pProperties->m_pDataProvider)
54 return;
55 CFX_WideString wsCaption;
56 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption);
57 if (wsCaption.GetLength() > 0) {
58 CFX_SizeF sz = CalcTextSize(
59 wsCaption, m_pProperties->m_pThemeProvider,
60 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine));
61 rect.Set(0, 0, sz.x, sz.y);
62 }
63 rect.Inflate(kCaptionMargin, kCaptionMargin);
64 IFWL_CheckBoxDP* pData =
65 static_cast<IFWL_CheckBoxDP*>(m_pProperties->m_pDataProvider);
66 FX_FLOAT fCheckBox = pData->GetBoxSize(this);
67 rect.width += fCheckBox;
68 if (rect.height < fCheckBox) {
69 rect.height = fCheckBox;
70 }
71 IFWL_Widget::GetWidgetRect(rect, true);
72 } else {
73 rect = m_pProperties->m_rtWidget; 48 rect = m_pProperties->m_rtWidget;
49 return;
74 } 50 }
51
52 rect.Set(0, 0, 0, 0);
53 if (!m_pProperties->m_pThemeProvider)
54 m_pProperties->m_pThemeProvider = GetAvailableTheme();
55 if (!m_pProperties->m_pThemeProvider)
56 return;
57 if (!m_pProperties->m_pDataProvider)
58 return;
59
60 CFX_WideString wsCaption;
61 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption);
62 if (wsCaption.GetLength() > 0) {
63 CFX_SizeF sz = CalcTextSize(
64 wsCaption, m_pProperties->m_pThemeProvider,
65 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine));
66 rect.Set(0, 0, sz.x, sz.y);
67 }
68 rect.Inflate(kCaptionMargin, kCaptionMargin);
69
70 IFWL_CheckBoxDP* pData =
71 static_cast<IFWL_CheckBoxDP*>(m_pProperties->m_pDataProvider);
72 FX_FLOAT fCheckBox = pData->GetBoxSize(this);
73 rect.width += fCheckBox;
74 rect.height = std::max(rect.height, fCheckBox);
75 IFWL_Widget::GetWidgetRect(rect, true);
75 } 76 }
76 77
77 void IFWL_CheckBox::Update() { 78 void IFWL_CheckBox::Update() {
78 if (IsLocked()) { 79 if (IsLocked())
79 return; 80 return;
80 } 81 if (!m_pProperties->m_pThemeProvider)
81 if (!m_pProperties->m_pThemeProvider) {
82 m_pProperties->m_pThemeProvider = GetAvailableTheme(); 82 m_pProperties->m_pThemeProvider = GetAvailableTheme();
83 } 83
84 UpdateTextOutStyles(); 84 UpdateTextOutStyles();
85 Layout(); 85 Layout();
86 } 86 }
87 87
88 void IFWL_CheckBox::DrawWidget(CFX_Graphics* pGraphics, 88 void IFWL_CheckBox::DrawWidget(CFX_Graphics* pGraphics,
89 const CFX_Matrix* pMatrix) { 89 const CFX_Matrix* pMatrix) {
90 if (!pGraphics) 90 if (!pGraphics)
91 return; 91 return;
92 if (!m_pProperties->m_pThemeProvider) 92 if (!m_pProperties->m_pThemeProvider)
93 return; 93 return;
94
94 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; 95 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
95 if (HasBorder()) { 96 if (HasBorder()) {
96 DrawBorder(pGraphics, CFWL_Part::Border, m_pProperties->m_pThemeProvider, 97 DrawBorder(pGraphics, CFWL_Part::Border, m_pProperties->m_pThemeProvider,
97 pMatrix); 98 pMatrix);
98 } 99 }
99 if (HasEdge()) { 100 if (HasEdge())
100 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); 101 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix);
101 } 102
102 int32_t dwStates = GetPartStates(); 103 int32_t dwStates = GetPartStates();
103 { 104
104 CFWL_ThemeBackground param; 105 CFWL_ThemeBackground param;
105 param.m_pWidget = this; 106 param.m_pWidget = this;
106 param.m_iPart = CFWL_Part::Background; 107 param.m_iPart = CFWL_Part::Background;
107 param.m_dwStates = dwStates; 108 param.m_dwStates = dwStates;
108 param.m_pGraphics = pGraphics; 109 param.m_pGraphics = pGraphics;
109 if (pMatrix) { 110 if (pMatrix)
110 param.m_matrix.Concat(*pMatrix); 111 param.m_matrix.Concat(*pMatrix);
111 } 112 param.m_rtPart = m_rtClient;
112 param.m_rtPart = m_rtClient; 113 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)
113 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) { 114 param.m_pData = &m_rtFocus;
114 param.m_pData = &m_rtFocus; 115 pTheme->DrawBackground(&param);
115 } 116
116 pTheme->DrawBackground(&param); 117 param.m_iPart = CFWL_Part::CheckBox;
117 param.m_iPart = CFWL_Part::CheckBox; 118 param.m_rtPart = m_rtBox;
118 param.m_rtPart = m_rtBox; 119 pTheme->DrawBackground(&param);
119 pTheme->DrawBackground(&param); 120
120 }
121 if (!m_pProperties->m_pDataProvider) 121 if (!m_pProperties->m_pDataProvider)
122 return; 122 return;
123 123
124 { 124 CFX_WideString wsCaption;
125 CFX_WideString wsCaption; 125 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption);
126 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); 126 if (wsCaption.GetLength() <= 0)
127 int32_t iLen = wsCaption.GetLength(); 127 return;
128 if (iLen <= 0) 128
129 return; 129 CFWL_ThemeText textParam;
130 CFWL_ThemeText textParam; 130 textParam.m_pWidget = this;
131 textParam.m_pWidget = this; 131 textParam.m_iPart = CFWL_Part::Caption;
132 textParam.m_iPart = CFWL_Part::Caption; 132 textParam.m_dwStates = dwStates;
133 textParam.m_dwStates = dwStates; 133 textParam.m_pGraphics = pGraphics;
134 textParam.m_pGraphics = pGraphics; 134 if (pMatrix)
135 if (pMatrix) { 135 textParam.m_matrix.Concat(*pMatrix);
136 textParam.m_matrix.Concat(*pMatrix); 136 textParam.m_rtPart = m_rtCaption;
137 } 137 textParam.m_wsText = wsCaption;
138 textParam.m_rtPart = m_rtCaption; 138 textParam.m_dwTTOStyles = m_dwTTOStyles;
139 textParam.m_wsText = wsCaption; 139 textParam.m_iTTOAlign = m_iTTOAlign;
140 textParam.m_dwTTOStyles = m_dwTTOStyles; 140 pTheme->DrawText(&textParam);
141 textParam.m_iTTOAlign = m_iTTOAlign;
142 pTheme->DrawText(&textParam);
143 }
144 } 141 }
145 142
146 void IFWL_CheckBox::SetCheckState(int32_t iCheck) { 143 void IFWL_CheckBox::SetCheckState(int32_t iCheck) {
147 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; 144 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask;
148 switch (iCheck) { 145 switch (iCheck) {
149 case 1: 146 case 1:
150 m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; 147 m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked;
151 break; 148 break;
152 case 2: 149 case 2:
153 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) 150 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State)
154 m_pProperties->m_dwStates |= FWL_STATE_CKB_Neutral; 151 m_pProperties->m_dwStates |= FWL_STATE_CKB_Neutral;
155 break; 152 break;
156 default: 153 default:
157 break; 154 break;
158 } 155 }
159 Repaint(&m_rtClient); 156 Repaint(&m_rtClient);
160 } 157 }
161 158
162 void IFWL_CheckBox::Layout() { 159 void IFWL_CheckBox::Layout() {
163 int32_t width = int32_t(m_pProperties->m_rtWidget.width + 0.5f); 160 m_pProperties->m_rtWidget.width =
164 int32_t height = int32_t(m_pProperties->m_rtWidget.height + 0.5f); 161 FXSYS_round(m_pProperties->m_rtWidget.width);
165 m_pProperties->m_rtWidget.width = (FX_FLOAT)width; 162 m_pProperties->m_rtWidget.height =
166 m_pProperties->m_rtWidget.height = (FX_FLOAT)height; 163 FXSYS_round(m_pProperties->m_rtWidget.height);
167 GetClientRect(m_rtClient); 164 GetClientRect(m_rtClient);
168 FX_FLOAT fBoxTop = m_rtClient.top; 165
169 FX_FLOAT fBoxLeft = m_rtClient.left;
170 FX_FLOAT fTextLeft = 0.0, fTextRight = 0.0;
171 FX_FLOAT fClientRight = m_rtClient.right();
172 FX_FLOAT fClientBottom = m_rtClient.bottom();
173 if (!m_pProperties->m_pDataProvider) 166 if (!m_pProperties->m_pDataProvider)
174 return; 167 return;
168
169 FX_FLOAT fBoxTop = m_rtClient.top;
170 FX_FLOAT fClientBottom = m_rtClient.bottom();
171
175 IFWL_CheckBoxDP* pData = 172 IFWL_CheckBoxDP* pData =
176 static_cast<IFWL_CheckBoxDP*>(m_pProperties->m_pDataProvider); 173 static_cast<IFWL_CheckBoxDP*>(m_pProperties->m_pDataProvider);
177 FX_FLOAT fCheckBox = pData->GetBoxSize(this); 174 FX_FLOAT fCheckBox = pData->GetBoxSize(this);
178 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) { 175 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) {
179 case FWL_STYLEEXT_CKB_Top: { 176 case FWL_STYLEEXT_CKB_Top:
180 fBoxTop = m_rtClient.top;
181 break; 177 break;
182 }
183 case FWL_STYLEEXT_CKB_Bottom: { 178 case FWL_STYLEEXT_CKB_Bottom: {
184 fBoxTop = fClientBottom - fCheckBox; 179 fBoxTop = fClientBottom - fCheckBox;
185 break; 180 break;
186 } 181 }
187 case FWL_STYLEEXT_CKB_VCenter: 182 case FWL_STYLEEXT_CKB_VCenter:
188 default: { 183 default: {
189 fBoxTop = m_rtClient.top + (m_rtClient.height - fCheckBox) / 2; 184 fBoxTop = m_rtClient.top + (m_rtClient.height - fCheckBox) / 2;
190 fBoxTop = FXSYS_floor(fBoxTop); 185 fBoxTop = FXSYS_floor(fBoxTop);
186 break;
191 } 187 }
192 } 188 }
189
190 FX_FLOAT fBoxLeft = m_rtClient.left;
191 FX_FLOAT fTextLeft = 0.0;
192 FX_FLOAT fTextRight = 0.0;
193 FX_FLOAT fClientRight = m_rtClient.right();
193 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_LeftText) { 194 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_LeftText) {
194 fBoxLeft = fClientRight - fCheckBox; 195 fBoxLeft = fClientRight - fCheckBox;
195 fTextLeft = m_rtClient.left; 196 fTextLeft = m_rtClient.left;
196 fTextRight = fBoxLeft; 197 fTextRight = fBoxLeft;
197 } else { 198 } else {
198 fTextLeft = fBoxLeft + fCheckBox; 199 fTextLeft = fBoxLeft + fCheckBox;
199 fTextRight = fClientRight; 200 fTextRight = fClientRight;
200 } 201 }
201 m_rtBox.Set(fBoxLeft, fBoxTop, fCheckBox, fCheckBox); 202 m_rtBox.Set(fBoxLeft, fBoxTop, fCheckBox, fCheckBox);
202 m_rtCaption.Set(fTextLeft, m_rtClient.top, fTextRight - fTextLeft, 203 m_rtCaption.Set(fTextLeft, m_rtClient.top, fTextRight - fTextLeft,
203 m_rtClient.height); 204 m_rtClient.height);
204 m_rtCaption.Inflate(-kCaptionMargin, -kCaptionMargin); 205 m_rtCaption.Inflate(-kCaptionMargin, -kCaptionMargin);
206
205 CFX_RectF rtFocus; 207 CFX_RectF rtFocus;
206 rtFocus.Set(m_rtCaption.left, m_rtCaption.top, m_rtCaption.width, 208 rtFocus.Set(m_rtCaption.left, m_rtCaption.top, m_rtCaption.width,
207 m_rtCaption.height); 209 m_rtCaption.height);
210
208 CFX_WideString wsCaption; 211 CFX_WideString wsCaption;
209 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); 212 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption);
210 if (wsCaption.IsEmpty()) { 213 if (wsCaption.IsEmpty()) {
211 m_rtFocus.Set(0, 0, 0, 0); 214 m_rtFocus.Set(0, 0, 0, 0);
215 return;
216 }
217
218 CalcTextRect(wsCaption, m_pProperties->m_pThemeProvider, m_dwTTOStyles,
219 m_iTTOAlign, rtFocus);
220 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) == 0) {
221 FX_FLOAT fWidth = std::max(m_rtCaption.width, rtFocus.width);
222 FX_FLOAT fHeight = std::min(m_rtCaption.height, rtFocus.height);
223 FX_FLOAT fLeft = m_rtCaption.left;
224 FX_FLOAT fTop = m_rtCaption.top;
225 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) ==
226 FWL_STYLEEXT_CKB_Center) {
227 fLeft = m_rtCaption.left + (m_rtCaption.width - fWidth) / 2;
228 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) ==
229 FWL_STYLEEXT_CKB_Right) {
230 fLeft = m_rtCaption.right() - fWidth;
231 }
232 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) ==
233 FWL_STYLEEXT_CKB_VCenter) {
234 fTop = m_rtCaption.top + (m_rtCaption.height - fHeight) / 2;
235 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) ==
236 FWL_STYLEEXT_CKB_Bottom) {
237 fTop = m_rtCaption.bottom() - fHeight;
238 }
239 m_rtFocus.Set(fLeft, fTop, fWidth, fHeight);
212 } else { 240 } else {
213 CalcTextRect(wsCaption, m_pProperties->m_pThemeProvider, m_dwTTOStyles, 241 m_rtFocus.Set(rtFocus.left, rtFocus.top, rtFocus.width, rtFocus.height);
214 m_iTTOAlign, rtFocus);
215 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) == 0) {
216 FX_FLOAT fWidth = std::max(m_rtCaption.width, rtFocus.width);
217 FX_FLOAT fHeight = std::min(m_rtCaption.height, rtFocus.height);
218 FX_FLOAT fLeft = m_rtCaption.left;
219 FX_FLOAT fTop = m_rtCaption.top;
220 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) ==
221 FWL_STYLEEXT_CKB_Center) {
222 fLeft = m_rtCaption.left + (m_rtCaption.width - fWidth) / 2;
223 } else if ((m_pProperties->m_dwStyleExes &
224 FWL_STYLEEXT_CKB_HLayoutMask) == FWL_STYLEEXT_CKB_Right) {
225 fLeft = m_rtCaption.right() - fWidth;
226 }
227 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) ==
228 FWL_STYLEEXT_CKB_VCenter) {
229 fTop = m_rtCaption.top + (m_rtCaption.height - fHeight) / 2;
230 } else if ((m_pProperties->m_dwStyleExes &
231 FWL_STYLEEXT_CKB_VLayoutMask) == FWL_STYLEEXT_CKB_Bottom) {
232 fTop = m_rtCaption.bottom() - fHeight;
233 }
234 m_rtFocus.Set(fLeft, fTop, fWidth, fHeight);
235 } else {
236 m_rtFocus.Set(rtFocus.left, rtFocus.top, rtFocus.width, rtFocus.height);
237 }
238 m_rtFocus.Inflate(1, 1);
239 } 242 }
243 m_rtFocus.Inflate(1, 1);
240 } 244 }
241 245
242 uint32_t IFWL_CheckBox::GetPartStates() { 246 uint32_t IFWL_CheckBox::GetPartStates() const {
243 int32_t dwStates = CFWL_PartState_Normal; 247 int32_t dwStates = CFWL_PartState_Normal;
244 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == 248 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) ==
245 FWL_STATE_CKB_Neutral) { 249 FWL_STATE_CKB_Neutral) {
246 dwStates = CFWL_PartState_Neutral; 250 dwStates = CFWL_PartState_Neutral;
247 } else if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == 251 } else if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) ==
248 FWL_STATE_CKB_Checked) { 252 FWL_STATE_CKB_Checked) {
249 dwStates = CFWL_PartState_Checked; 253 dwStates = CFWL_PartState_Checked;
250 } 254 }
251 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { 255 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
252 dwStates |= CFWL_PartState_Disabled; 256 dwStates |= CFWL_PartState_Disabled;
253 } else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) { 257 else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered)
254 dwStates |= CFWL_PartState_Hovered; 258 dwStates |= CFWL_PartState_Hovered;
255 } else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) { 259 else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed)
256 dwStates |= CFWL_PartState_Pressed; 260 dwStates |= CFWL_PartState_Pressed;
257 } else { 261 else
258 dwStates |= CFWL_PartState_Normal; 262 dwStates |= CFWL_PartState_Normal;
259 } 263 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)
260 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) {
261 dwStates |= CFWL_PartState_Focused; 264 dwStates |= CFWL_PartState_Focused;
262 }
263 return dwStates; 265 return dwStates;
264 } 266 }
265 267
266 void IFWL_CheckBox::UpdateTextOutStyles() { 268 void IFWL_CheckBox::UpdateTextOutStyles() {
267 m_iTTOAlign = FDE_TTOALIGNMENT_Center;
268 switch (m_pProperties->m_dwStyleExes & 269 switch (m_pProperties->m_dwStyleExes &
269 (FWL_STYLEEXT_CKB_HLayoutMask | FWL_STYLEEXT_CKB_VLayoutMask)) { 270 (FWL_STYLEEXT_CKB_HLayoutMask | FWL_STYLEEXT_CKB_VLayoutMask)) {
270 case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_Top: { 271 case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_Top: {
271 m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; 272 m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft;
272 break; 273 break;
273 } 274 }
274 case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_Top: { 275 case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_Top: {
275 m_iTTOAlign = FDE_TTOALIGNMENT_TopCenter; 276 m_iTTOAlign = FDE_TTOALIGNMENT_TopCenter;
276 break; 277 break;
277 } 278 }
278 case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_Top: { 279 case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_Top: {
279 m_iTTOAlign = FDE_TTOALIGNMENT_TopRight; 280 m_iTTOAlign = FDE_TTOALIGNMENT_TopRight;
280 break; 281 break;
281 } 282 }
282 case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_VCenter: { 283 case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_VCenter: {
283 m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; 284 m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft;
284 break; 285 break;
285 } 286 }
286 case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_VCenter: {
287 m_iTTOAlign = FDE_TTOALIGNMENT_Center;
288 break;
289 }
290 case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_VCenter: { 287 case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_VCenter: {
291 m_iTTOAlign = FDE_TTOALIGNMENT_CenterRight; 288 m_iTTOAlign = FDE_TTOALIGNMENT_CenterRight;
292 break; 289 break;
293 } 290 }
294 case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_Bottom: { 291 case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_Bottom: {
295 m_iTTOAlign = FDE_TTOALIGNMENT_BottomLeft; 292 m_iTTOAlign = FDE_TTOALIGNMENT_BottomLeft;
296 break; 293 break;
297 } 294 }
298 case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_Bottom: { 295 case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_Bottom: {
299 m_iTTOAlign = FDE_TTOALIGNMENT_BottomCenter; 296 m_iTTOAlign = FDE_TTOALIGNMENT_BottomCenter;
300 break; 297 break;
301 } 298 }
302 case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_Bottom: { 299 case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_Bottom: {
303 m_iTTOAlign = FDE_TTOALIGNMENT_BottomRight; 300 m_iTTOAlign = FDE_TTOALIGNMENT_BottomRight;
304 break; 301 break;
305 } 302 }
306 default: {} 303 case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_VCenter:
304 default: {
305 m_iTTOAlign = FDE_TTOALIGNMENT_Center;
306 break;
307 }
307 } 308 }
308 m_dwTTOStyles = 0; 309 m_dwTTOStyles = 0;
309 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) { 310 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading)
310 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; 311 m_dwTTOStyles |= FDE_TTOSTYLE_RTL;
311 } 312 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine)
312 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) {
313 m_dwTTOStyles |= FDE_TTOSTYLE_LineWrap; 313 m_dwTTOStyles |= FDE_TTOSTYLE_LineWrap;
314 } else { 314 else
315 m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine; 315 m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine;
316 }
317 } 316 }
318 317
319 void IFWL_CheckBox::NextStates() { 318 void IFWL_CheckBox::NextStates() {
320 uint32_t dwFirststate = m_pProperties->m_dwStates; 319 uint32_t dwFirststate = m_pProperties->m_dwStates;
321 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_RadioButton) { 320 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_RadioButton) {
322 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == 321 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) ==
323 FWL_STATE_CKB_Unchecked) { 322 FWL_STATE_CKB_Unchecked) {
324 CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr(); 323 CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr();
325 if (!pWidgetMgr->IsFormDisabled()) { 324 if (!pWidgetMgr->IsFormDisabled()) {
326 CFX_ArrayTemplate<IFWL_Widget*> radioarr; 325 CFX_ArrayTemplate<IFWL_Widget*> radioarr;
(...skipping 12 matching lines...) Expand all
339 break; 338 break;
340 } 339 }
341 } 340 }
342 } 341 }
343 m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; 342 m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked;
344 } 343 }
345 } else { 344 } else {
346 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == 345 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) ==
347 FWL_STATE_CKB_Neutral) { 346 FWL_STATE_CKB_Neutral) {
348 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; 347 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask;
349 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) { 348 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State)
350 m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; 349 m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked;
351 }
352 } else if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == 350 } else if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) ==
353 FWL_STATE_CKB_Checked) { 351 FWL_STATE_CKB_Checked) {
354 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; 352 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask;
355 } else { 353 } else {
356 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) { 354 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State)
357 m_pProperties->m_dwStates |= FWL_STATE_CKB_Neutral; 355 m_pProperties->m_dwStates |= FWL_STATE_CKB_Neutral;
358 } else { 356 else
359 m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; 357 m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked;
360 }
361 } 358 }
362 } 359 }
360
363 Repaint(&m_rtClient); 361 Repaint(&m_rtClient);
364 uint32_t dwLaststate = m_pProperties->m_dwStates; 362 if (dwFirststate != m_pProperties->m_dwStates) {
365 if (dwFirststate != dwLaststate) {
366 CFWL_EvtCkbCheckStateChanged wmCheckBoxState; 363 CFWL_EvtCkbCheckStateChanged wmCheckBoxState;
367 wmCheckBoxState.m_pSrcTarget = this; 364 wmCheckBoxState.m_pSrcTarget = this;
368 DispatchEvent(&wmCheckBoxState); 365 DispatchEvent(&wmCheckBoxState);
369 } 366 }
370 } 367 }
371 368
372 void IFWL_CheckBox::OnProcessMessage(CFWL_Message* pMessage) { 369 void IFWL_CheckBox::OnProcessMessage(CFWL_Message* pMessage) {
373 if (!pMessage) 370 if (!pMessage)
374 return; 371 return;
375 372
376 switch (pMessage->GetClassID()) { 373 switch (pMessage->GetClassID()) {
377 case CFWL_MessageType::SetFocus: 374 case CFWL_MessageType::SetFocus:
378 OnFocusChanged(pMessage, true); 375 OnFocusChanged(true);
379 break; 376 break;
380 case CFWL_MessageType::KillFocus: 377 case CFWL_MessageType::KillFocus:
381 OnFocusChanged(pMessage, false); 378 OnFocusChanged(false);
382 break; 379 break;
383 case CFWL_MessageType::Mouse: { 380 case CFWL_MessageType::Mouse: {
384 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); 381 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage);
385 switch (pMsg->m_dwCmd) { 382 switch (pMsg->m_dwCmd) {
386 case FWL_MouseCommand::LeftButtonDown: 383 case FWL_MouseCommand::LeftButtonDown:
387 OnLButtonDown(pMsg); 384 OnLButtonDown();
388 break; 385 break;
389 case FWL_MouseCommand::LeftButtonUp: 386 case FWL_MouseCommand::LeftButtonUp:
390 OnLButtonUp(pMsg); 387 OnLButtonUp(pMsg);
391 break; 388 break;
392 case FWL_MouseCommand::Move: 389 case FWL_MouseCommand::Move:
393 OnMouseMove(pMsg); 390 OnMouseMove(pMsg);
394 break; 391 break;
395 case FWL_MouseCommand::Leave: 392 case FWL_MouseCommand::Leave:
396 OnMouseLeave(pMsg); 393 OnMouseLeave();
397 break; 394 break;
398 default: 395 default:
399 break; 396 break;
400 } 397 }
401 break; 398 break;
402 } 399 }
403 case CFWL_MessageType::Key: { 400 case CFWL_MessageType::Key: {
404 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); 401 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage);
405 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) 402 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown)
406 OnKeyDown(pKey); 403 OnKeyDown(pKey);
407 break; 404 break;
408 } 405 }
409 default: 406 default:
410 break; 407 break;
411 } 408 }
412 409
413 IFWL_Widget::OnProcessMessage(pMessage); 410 IFWL_Widget::OnProcessMessage(pMessage);
414 } 411 }
415 412
416 void IFWL_CheckBox::OnDrawWidget(CFX_Graphics* pGraphics, 413 void IFWL_CheckBox::OnDrawWidget(CFX_Graphics* pGraphics,
417 const CFX_Matrix* pMatrix) { 414 const CFX_Matrix* pMatrix) {
418 DrawWidget(pGraphics, pMatrix); 415 DrawWidget(pGraphics, pMatrix);
419 } 416 }
420 417
421 void IFWL_CheckBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { 418 void IFWL_CheckBox::OnFocusChanged(bool bSet) {
422 if (bSet) 419 if (bSet)
423 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; 420 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
424 else 421 else
425 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; 422 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
426 423
427 Repaint(&(m_rtClient)); 424 Repaint(&m_rtClient);
428 } 425 }
429 426
430 void IFWL_CheckBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { 427 void IFWL_CheckBox::OnLButtonDown() {
431 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) 428 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
432 return; 429 return;
433 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) 430 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0)
434 SetFocus(true); 431 SetFocus(true);
435 432
436 m_bBtnDown = true; 433 m_bBtnDown = true;
437 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; 434 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered;
438 m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; 435 m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed;
439 Repaint(&(m_rtClient)); 436 Repaint(&m_rtClient);
440 } 437 }
441 438
442 void IFWL_CheckBox::OnLButtonUp(CFWL_MsgMouse* pMsg) { 439 void IFWL_CheckBox::OnLButtonUp(CFWL_MsgMouse* pMsg) {
443 if (!m_bBtnDown) 440 if (!m_bBtnDown)
444 return; 441 return;
445 442
446 m_bBtnDown = false; 443 m_bBtnDown = false;
447 if (!m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) 444 if (!m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy))
448 return; 445 return;
449 446
(...skipping 28 matching lines...) Expand all
478 } 475 }
479 } 476 }
480 } else { 477 } else {
481 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { 478 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) {
482 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) { 479 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) {
483 bRepaint = true; 480 bRepaint = true;
484 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; 481 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered;
485 } 482 }
486 } 483 }
487 } 484 }
488 if (bRepaint) { 485 if (bRepaint)
489 Repaint(&(m_rtBox)); 486 Repaint(&m_rtBox);
490 }
491 } 487 }
492 488
493 void IFWL_CheckBox::OnMouseLeave(CFWL_MsgMouse* pMsg) { 489 void IFWL_CheckBox::OnMouseLeave() {
494 if (m_bBtnDown) 490 if (m_bBtnDown)
495 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; 491 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered;
496 else 492 else
497 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; 493 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered;
498 494
499 Repaint(&(m_rtBox)); 495 Repaint(&m_rtBox);
500 } 496 }
501 497
502 void IFWL_CheckBox::OnKeyDown(CFWL_MsgKey* pMsg) { 498 void IFWL_CheckBox::OnKeyDown(CFWL_MsgKey* pMsg) {
503 if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) { 499 if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) {
504 DispatchKeyEvent(pMsg); 500 DispatchKeyEvent(pMsg);
505 return; 501 return;
506 } 502 }
507 if (pMsg->m_dwKeyCode == FWL_VKEY_Return || 503 if (pMsg->m_dwKeyCode == FWL_VKEY_Return ||
508 pMsg->m_dwKeyCode == FWL_VKEY_Space) { 504 pMsg->m_dwKeyCode == FWL_VKEY_Space) {
509 NextStates(); 505 NextStates();
510 } 506 }
511 } 507 }
OLDNEW
« no previous file with comments | « xfa/fwl/core/ifwl_checkbox.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698