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

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

Issue 2506083002: Continue formatting fwl/core (Closed)
Patch Set: format 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_datetimepicker.h ('k') | xfa/fxfa/app/xfa_ffchoicelist.h » ('j') | 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_datetimepicker.h" 7 #include "xfa/fwl/core/ifwl_datetimepicker.h"
8 8
9 #include "third_party/base/ptr_util.h" 9 #include "third_party/base/ptr_util.h"
10 #include "xfa/fwl/core/cfwl_message.h" 10 #include "xfa/fwl/core/cfwl_message.h"
11 #include "xfa/fwl/core/cfwl_themebackground.h" 11 #include "xfa/fwl/core/cfwl_themebackground.h"
12 #include "xfa/fwl/core/cfwl_widgetmgr.h" 12 #include "xfa/fwl/core/cfwl_widgetmgr.h"
13 #include "xfa/fwl/core/fwl_noteimp.h" 13 #include "xfa/fwl/core/fwl_noteimp.h"
14 #include "xfa/fwl/core/ifwl_datetimeedit.h"
15 #include "xfa/fwl/core/ifwl_formproxy.h" 14 #include "xfa/fwl/core/ifwl_formproxy.h"
16 #include "xfa/fwl/core/ifwl_spinbutton.h" 15 #include "xfa/fwl/core/ifwl_spinbutton.h"
17 #include "xfa/fwl/core/ifwl_themeprovider.h" 16 #include "xfa/fwl/core/ifwl_themeprovider.h"
18 17
19 namespace { 18 namespace {
20 19
21 const int kDateTimePickerWidth = 100; 20 const int kDateTimePickerWidth = 100;
22 const int kDateTimePickerHeight = 20; 21 const int kDateTimePickerHeight = 20;
23 22
24 } // namespace 23 } // namespace
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 66
68 FWL_Type IFWL_DateTimePicker::GetClassID() const { 67 FWL_Type IFWL_DateTimePicker::GetClassID() const {
69 return FWL_Type::DateTimePicker; 68 return FWL_Type::DateTimePicker;
70 } 69 }
71 70
72 void IFWL_DateTimePicker::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { 71 void IFWL_DateTimePicker::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) {
73 if (m_pWidgetMgr->IsFormDisabled()) { 72 if (m_pWidgetMgr->IsFormDisabled()) {
74 DisForm_GetWidgetRect(rect, bAutoSize); 73 DisForm_GetWidgetRect(rect, bAutoSize);
75 return; 74 return;
76 } 75 }
77 if (bAutoSize) { 76 if (!bAutoSize) {
78 rect.Set(0, 0, kDateTimePickerWidth, kDateTimePickerHeight);
79 IFWL_Widget::GetWidgetRect(rect, true);
80 } else {
81 rect = m_pProperties->m_rtWidget; 77 rect = m_pProperties->m_rtWidget;
78 return;
82 } 79 }
80
81 rect.Set(0, 0, kDateTimePickerWidth, kDateTimePickerHeight);
82 IFWL_Widget::GetWidgetRect(rect, true);
83 } 83 }
84 84
85 void IFWL_DateTimePicker::Update() { 85 void IFWL_DateTimePicker::Update() {
86 if (m_pWidgetMgr->IsFormDisabled()) { 86 if (m_pWidgetMgr->IsFormDisabled()) {
87 DisForm_Update(); 87 DisForm_Update();
88 return; 88 return;
89 } 89 }
90 if (m_iLock) { 90 if (m_iLock)
91 return; 91 return;
92 } 92 if (!m_pProperties->m_pThemeProvider)
93 if (!m_pProperties->m_pThemeProvider) {
94 m_pProperties->m_pThemeProvider = GetAvailableTheme(); 93 m_pProperties->m_pThemeProvider = GetAvailableTheme();
95 } 94
96 m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider); 95 m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider);
97 GetClientRect(m_rtClient); 96 GetClientRect(m_rtClient);
98 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( 97 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>(
99 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); 98 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth));
100 if (!pFWidth) 99 if (!pFWidth)
101 return; 100 return;
101
102 FX_FLOAT fBtn = *pFWidth; 102 FX_FLOAT fBtn = *pFWidth;
103 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn - 1, 103 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn - 1,
104 m_rtClient.height - 1); 104 m_rtClient.height - 1);
105
105 CFX_RectF rtEdit; 106 CFX_RectF rtEdit;
106 rtEdit.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn, 107 rtEdit.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn,
107 m_rtClient.height); 108 m_rtClient.height);
108 m_pEdit->SetWidgetRect(rtEdit); 109 m_pEdit->SetWidgetRect(rtEdit);
109 ResetEditAlignment(); 110 ResetEditAlignment();
110 m_pEdit->Update(); 111 m_pEdit->Update();
111 if (!(m_pMonthCal->GetThemeProvider())) { 112 if (!(m_pMonthCal->GetThemeProvider()))
112 m_pMonthCal->SetThemeProvider(m_pProperties->m_pThemeProvider); 113 m_pMonthCal->SetThemeProvider(m_pProperties->m_pThemeProvider);
113 }
114 if (m_pProperties->m_pDataProvider) { 114 if (m_pProperties->m_pDataProvider) {
115 IFWL_DateTimePickerDP* pData = 115 IFWL_DateTimePickerDP* pData =
116 static_cast<IFWL_DateTimePickerDP*>(m_pProperties->m_pDataProvider); 116 static_cast<IFWL_DateTimePickerDP*>(m_pProperties->m_pDataProvider);
117 pData->GetToday(this, m_iCurYear, m_iCurMonth, m_iCurDay); 117 pData->GetToday(this, m_iCurYear, m_iCurMonth, m_iCurDay);
118 } 118 }
119
119 CFX_RectF rtMonthCal; 120 CFX_RectF rtMonthCal;
120 m_pMonthCal->GetWidgetRect(rtMonthCal, true); 121 m_pMonthCal->GetWidgetRect(rtMonthCal, true);
121 CFX_RectF rtPopUp; 122 CFX_RectF rtPopUp;
122 rtPopUp.Set(rtMonthCal.left, rtMonthCal.top + kDateTimePickerHeight, 123 rtPopUp.Set(rtMonthCal.left, rtMonthCal.top + kDateTimePickerHeight,
123 rtMonthCal.width, rtMonthCal.height); 124 rtMonthCal.width, rtMonthCal.height);
124 m_pMonthCal->SetWidgetRect(rtPopUp); 125 m_pMonthCal->SetWidgetRect(rtPopUp);
125 m_pMonthCal->Update(); 126 m_pMonthCal->Update();
126 return; 127 return;
127 } 128 }
128 129
129 int32_t IFWL_DateTimePicker::CountSelRanges() {
130 return m_pEdit->CountSelRanges();
131 }
132
133 int32_t IFWL_DateTimePicker::GetSelRange(int32_t nIndex, int32_t& nStart) {
134 return m_pEdit->GetSelRange(nIndex, nStart);
135 }
136
137 FWL_WidgetHit IFWL_DateTimePicker::HitTest(FX_FLOAT fx, FX_FLOAT fy) { 130 FWL_WidgetHit IFWL_DateTimePicker::HitTest(FX_FLOAT fx, FX_FLOAT fy) {
138 if (m_pWidgetMgr->IsFormDisabled()) 131 if (m_pWidgetMgr->IsFormDisabled())
139 return DisForm_HitTest(fx, fy); 132 return DisForm_HitTest(fx, fy);
140 if (m_rtClient.Contains(fx, fy)) 133 if (m_rtClient.Contains(fx, fy))
141 return FWL_WidgetHit::Client; 134 return FWL_WidgetHit::Client;
142 if (IsMonthCalendarVisible()) { 135 if (IsMonthCalendarVisible()) {
143 CFX_RectF rect; 136 CFX_RectF rect;
144 m_pMonthCal->GetWidgetRect(rect); 137 m_pMonthCal->GetWidgetRect(rect);
145 if (rect.Contains(fx, fy)) 138 if (rect.Contains(fx, fy))
146 return FWL_WidgetHit::Client; 139 return FWL_WidgetHit::Client;
147 } 140 }
148 return FWL_WidgetHit::Unknown; 141 return FWL_WidgetHit::Unknown;
149 } 142 }
150 143
151 void IFWL_DateTimePicker::DrawWidget(CFX_Graphics* pGraphics, 144 void IFWL_DateTimePicker::DrawWidget(CFX_Graphics* pGraphics,
152 const CFX_Matrix* pMatrix) { 145 const CFX_Matrix* pMatrix) {
153 if (!pGraphics) 146 if (!pGraphics)
154 return; 147 return;
155 if (!m_pProperties->m_pThemeProvider) 148 if (!m_pProperties->m_pThemeProvider)
156 return; 149 return;
150
157 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; 151 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
158 if (HasBorder()) { 152 if (HasBorder())
159 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); 153 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix);
160 } 154 if (HasEdge())
161 if (HasEdge()) {
162 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); 155 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix);
163 } 156 if (!m_rtBtn.IsEmpty())
164 if (!m_rtBtn.IsEmpty()) {
165 DrawDropDownButton(pGraphics, pTheme, pMatrix); 157 DrawDropDownButton(pGraphics, pTheme, pMatrix);
166 }
167 if (m_pWidgetMgr->IsFormDisabled()) { 158 if (m_pWidgetMgr->IsFormDisabled()) {
168 DisForm_DrawWidget(pGraphics, pMatrix); 159 DisForm_DrawWidget(pGraphics, pMatrix);
169 return; 160 return;
170 } 161 }
171 } 162 }
172 163
173 void IFWL_DateTimePicker::SetThemeProvider(IFWL_ThemeProvider* pTP) { 164 void IFWL_DateTimePicker::SetThemeProvider(IFWL_ThemeProvider* pTP) {
174 m_pProperties->m_pThemeProvider = pTP; 165 m_pProperties->m_pThemeProvider = pTP;
175 m_pMonthCal->SetThemeProvider(pTP); 166 m_pMonthCal->SetThemeProvider(pTP);
176 } 167 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 DispatchEvent(&ev); 201 DispatchEvent(&ev);
211 } 202 }
212 203
213 void IFWL_DateTimePicker::GetEditText(CFX_WideString& wsText, 204 void IFWL_DateTimePicker::GetEditText(CFX_WideString& wsText,
214 int32_t nStart, 205 int32_t nStart,
215 int32_t nCount) const { 206 int32_t nCount) const {
216 if (m_pEdit) 207 if (m_pEdit)
217 m_pEdit->GetText(wsText, nStart, nCount); 208 m_pEdit->GetText(wsText, nStart, nCount);
218 } 209 }
219 210
220 void IFWL_DateTimePicker::GetBBox(CFX_RectF& rect) { 211 void IFWL_DateTimePicker::GetBBox(CFX_RectF& rect) const {
221 if (m_pWidgetMgr->IsFormDisabled()) { 212 if (m_pWidgetMgr->IsFormDisabled()) {
222 DisForm_GetBBox(rect); 213 DisForm_GetBBox(rect);
223 return; 214 return;
224 } 215 }
216
225 rect = m_pProperties->m_rtWidget; 217 rect = m_pProperties->m_rtWidget;
226 if (IsMonthCalendarVisible()) { 218 if (IsMonthCalendarVisible()) {
227 CFX_RectF rtMonth; 219 CFX_RectF rtMonth;
228 m_pMonthCal->GetWidgetRect(rtMonth); 220 m_pMonthCal->GetWidgetRect(rtMonth);
229 rtMonth.Offset(m_pProperties->m_rtWidget.left, 221 rtMonth.Offset(m_pProperties->m_rtWidget.left,
230 m_pProperties->m_rtWidget.top); 222 m_pProperties->m_rtWidget.top);
231 rect.Union(rtMonth); 223 rect.Union(rtMonth);
232 } 224 }
233 } 225 }
234 226
235 void IFWL_DateTimePicker::SetEditLimit(int32_t nLimit) {
236 m_pEdit->SetLimit(nLimit);
237 }
238
239 void IFWL_DateTimePicker::ModifyEditStylesEx(uint32_t dwStylesExAdded, 227 void IFWL_DateTimePicker::ModifyEditStylesEx(uint32_t dwStylesExAdded,
240 uint32_t dwStylesExRemoved) { 228 uint32_t dwStylesExRemoved) {
241 m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); 229 m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved);
242 } 230 }
243 231
244 void IFWL_DateTimePicker::DrawDropDownButton(CFX_Graphics* pGraphics, 232 void IFWL_DateTimePicker::DrawDropDownButton(CFX_Graphics* pGraphics,
245 IFWL_ThemeProvider* pTheme, 233 IFWL_ThemeProvider* pTheme,
246 const CFX_Matrix* pMatrix) { 234 const CFX_Matrix* pMatrix) {
247 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_Spin) == 235 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_Spin) ==
248 FWL_STYLEEXT_DTP_Spin) { 236 FWL_STYLEEXT_DTP_Spin) {
249 return; 237 return;
250 } 238 }
251 239
252 CFWL_ThemeBackground param; 240 CFWL_ThemeBackground param;
253 param.m_pWidget = this; 241 param.m_pWidget = this;
254 param.m_iPart = CFWL_Part::DropDownButton; 242 param.m_iPart = CFWL_Part::DropDownButton;
255 param.m_dwStates = m_iBtnState; 243 param.m_dwStates = m_iBtnState;
256 param.m_pGraphics = pGraphics; 244 param.m_pGraphics = pGraphics;
257 param.m_rtPart = m_rtBtn; 245 param.m_rtPart = m_rtBtn;
258 if (pMatrix) 246 if (pMatrix)
259 param.m_matrix.Concat(*pMatrix); 247 param.m_matrix.Concat(*pMatrix);
260
261 pTheme->DrawBackground(&param); 248 pTheme->DrawBackground(&param);
262 } 249 }
263 250
264 void IFWL_DateTimePicker::FormatDateString(int32_t iYear, 251 void IFWL_DateTimePicker::FormatDateString(int32_t iYear,
265 int32_t iMonth, 252 int32_t iMonth,
266 int32_t iDay, 253 int32_t iDay,
267 CFX_WideString& wsText) { 254 CFX_WideString& wsText) {
268 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_ShortDateFormat) == 255 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_ShortDateFormat) ==
269 FWL_STYLEEXT_DTP_ShortDateFormat) { 256 FWL_STYLEEXT_DTP_ShortDateFormat) {
270 wsText.Format(L"%d-%d-%d", iYear, iMonth, iDay); 257 wsText.Format(L"%d-%d-%d", iYear, iMonth, iDay);
271 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_LongDateFormat) == 258 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_LongDateFormat) ==
272 FWL_STYLEEXT_DTP_LongDateFormat) { 259 FWL_STYLEEXT_DTP_LongDateFormat) {
273 wsText.Format(L"%d Year %d Month %d Day", iYear, iMonth, iDay); 260 wsText.Format(L"%d Year %d Month %d Day", iYear, iMonth, iDay);
274 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_TimeFormat) ==
275 FWL_STYLEEXT_DTP_TimeFormat) {
276 } 261 }
277 } 262 }
278 263
279 void IFWL_DateTimePicker::ShowMonthCalendar(bool bActivate) { 264 void IFWL_DateTimePicker::ShowMonthCalendar(bool bActivate) {
280 if (m_pWidgetMgr->IsFormDisabled()) { 265 if (m_pWidgetMgr->IsFormDisabled())
281 return DisForm_ShowMonthCalendar(bActivate); 266 return DisForm_ShowMonthCalendar(bActivate);
282 } 267 if (IsMonthCalendarVisible() == bActivate)
283 if (IsMonthCalendarVisible() == bActivate) { 268 return;
269 if (!m_pForm)
270 InitProxyForm();
271
272 if (!bActivate) {
273 m_pForm->EndDoModal();
284 return; 274 return;
285 } 275 }
286 if (!m_pForm) { 276
287 InitProxyForm(); 277 CFX_RectF rtMonth;
288 } 278 m_pMonthCal->GetWidgetRect(rtMonth);
289 if (bActivate) { 279
290 CFX_RectF rtMonth; 280 CFX_RectF rtAnchor;
291 m_pMonthCal->GetWidgetRect(rtMonth); 281 rtAnchor.Set(0, 0, m_pProperties->m_rtWidget.width,
292 CFX_RectF rtAnchor; 282 m_pProperties->m_rtWidget.height);
293 rtAnchor.Set(0, 0, m_pProperties->m_rtWidget.width, 283 GetPopupPos(0, rtMonth.height, rtAnchor, rtMonth);
294 m_pProperties->m_rtWidget.height); 284 m_pForm->SetWidgetRect(rtMonth);
295 GetPopupPos(0, rtMonth.height, rtAnchor, rtMonth); 285
296 m_pForm->SetWidgetRect(rtMonth); 286 rtMonth.left = rtMonth.top = 0;
297 rtMonth.left = rtMonth.top = 0; 287 m_pMonthCal->SetStates(FWL_WGTSTATE_Invisible, !bActivate);
298 m_pMonthCal->SetStates(FWL_WGTSTATE_Invisible, !bActivate); 288 m_pMonthCal->SetWidgetRect(rtMonth);
299 m_pMonthCal->SetWidgetRect(rtMonth); 289 m_pMonthCal->Update();
300 m_pMonthCal->Update(); 290 m_pForm->DoModal();
301 m_pForm->DoModal();
302 } else {
303 m_pForm->EndDoModal();
304 }
305 } 291 }
306 292
307 bool IFWL_DateTimePicker::IsMonthCalendarVisible() { 293 bool IFWL_DateTimePicker::IsMonthCalendarVisible() const {
308 if (m_pWidgetMgr->IsFormDisabled()) { 294 if (m_pWidgetMgr->IsFormDisabled())
309 return DisForm_IsMonthCalendarVisible(); 295 return DisForm_IsMonthCalendarVisible();
310 }
311 if (!m_pForm) 296 if (!m_pForm)
312 return false; 297 return false;
313 return !(m_pForm->GetStates() & FWL_WGTSTATE_Invisible); 298 return !(m_pForm->GetStates() & FWL_WGTSTATE_Invisible);
314 } 299 }
315 300
316 void IFWL_DateTimePicker::ResetEditAlignment() { 301 void IFWL_DateTimePicker::ResetEditAlignment() {
317 if (!m_pEdit) 302 if (!m_pEdit)
318 return; 303 return;
319 uint32_t dwStylExes = m_pProperties->m_dwStyleExes; 304
320 uint32_t dwAdd = 0; 305 uint32_t dwAdd = 0;
321 switch (dwStylExes & FWL_STYLEEXT_DTP_EditHAlignMask) { 306 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditHAlignMask) {
322 case FWL_STYLEEXT_DTP_EditHCenter: { 307 case FWL_STYLEEXT_DTP_EditHCenter: {
323 dwAdd |= FWL_STYLEEXT_EDT_HCenter; 308 dwAdd |= FWL_STYLEEXT_EDT_HCenter;
324 break; 309 break;
325 } 310 }
326 case FWL_STYLEEXT_DTP_EditHFar: { 311 case FWL_STYLEEXT_DTP_EditHFar: {
327 dwAdd |= FWL_STYLEEXT_EDT_HFar; 312 dwAdd |= FWL_STYLEEXT_EDT_HFar;
328 break; 313 break;
329 } 314 }
330 default: { dwAdd |= FWL_STYLEEXT_EDT_HNear; } 315 default: {
316 dwAdd |= FWL_STYLEEXT_EDT_HNear;
317 break;
318 }
331 } 319 }
332 switch (dwStylExes & FWL_STYLEEXT_DTP_EditVAlignMask) { 320 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditVAlignMask) {
333 case FWL_STYLEEXT_DTP_EditVCenter: { 321 case FWL_STYLEEXT_DTP_EditVCenter: {
334 dwAdd |= FWL_STYLEEXT_EDT_VCenter; 322 dwAdd |= FWL_STYLEEXT_EDT_VCenter;
335 break; 323 break;
336 } 324 }
337 case FWL_STYLEEXT_DTP_EditVFar: { 325 case FWL_STYLEEXT_DTP_EditVFar: {
338 dwAdd |= FWL_STYLEEXT_EDT_VFar; 326 dwAdd |= FWL_STYLEEXT_EDT_VFar;
339 break; 327 break;
340 } 328 }
341 default: { dwAdd |= FWL_STYLEEXT_EDT_VNear; } 329 default: {
330 dwAdd |= FWL_STYLEEXT_EDT_VNear;
331 break;
332 }
342 } 333 }
343 if (dwStylExes & FWL_STYLEEXT_DTP_EditJustified) { 334 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditJustified)
344 dwAdd |= FWL_STYLEEXT_EDT_Justified; 335 dwAdd |= FWL_STYLEEXT_EDT_Justified;
345 } 336 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditDistributed)
346 if (dwStylExes & FWL_STYLEEXT_DTP_EditDistributed) {
347 dwAdd |= FWL_STYLEEXT_EDT_Distributed; 337 dwAdd |= FWL_STYLEEXT_EDT_Distributed;
348 } 338
349 m_pEdit->ModifyStylesEx(dwAdd, FWL_STYLEEXT_EDT_HAlignMask | 339 m_pEdit->ModifyStylesEx(dwAdd, FWL_STYLEEXT_EDT_HAlignMask |
350 FWL_STYLEEXT_EDT_HAlignModeMask | 340 FWL_STYLEEXT_EDT_HAlignModeMask |
351 FWL_STYLEEXT_EDT_VAlignMask); 341 FWL_STYLEEXT_EDT_VAlignMask);
352 } 342 }
353 343
354 void IFWL_DateTimePicker::ProcessSelChanged(int32_t iYear, 344 void IFWL_DateTimePicker::ProcessSelChanged(int32_t iYear,
355 int32_t iMonth, 345 int32_t iMonth,
356 int32_t iDay) { 346 int32_t iDay) {
357 m_iYear = iYear; 347 m_iYear = iYear;
358 m_iMonth = iMonth; 348 m_iMonth = iMonth;
359 m_iDay = iDay; 349 m_iDay = iDay;
350
360 CFX_WideString wsText; 351 CFX_WideString wsText;
361 FormatDateString(m_iYear, m_iMonth, m_iDay, wsText); 352 FormatDateString(m_iYear, m_iMonth, m_iDay, wsText);
362 m_pEdit->SetText(wsText); 353 m_pEdit->SetText(wsText);
363 m_pEdit->Update(); 354 m_pEdit->Update();
364 Repaint(&m_rtClient); 355 Repaint(&m_rtClient);
356
365 CFWL_Event_DtpSelectChanged ev; 357 CFWL_Event_DtpSelectChanged ev;
366 ev.m_pSrcTarget = this; 358 ev.m_pSrcTarget = this;
367 ev.iYear = m_iYear; 359 ev.iYear = m_iYear;
368 ev.iMonth = m_iMonth; 360 ev.iMonth = m_iMonth;
369 ev.iDay = m_iDay; 361 ev.iDay = m_iDay;
370 DispatchEvent(&ev); 362 DispatchEvent(&ev);
371 } 363 }
372 364
373 void IFWL_DateTimePicker::InitProxyForm() { 365 void IFWL_DateTimePicker::InitProxyForm() {
374 if (m_pForm) 366 if (m_pForm)
375 return; 367 return;
376 if (!m_pMonthCal) 368 if (!m_pMonthCal)
377 return; 369 return;
378 370
379 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); 371 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>();
380 prop->m_dwStyles = FWL_WGTSTYLE_Popup; 372 prop->m_dwStyles = FWL_WGTSTYLE_Popup;
381 prop->m_dwStates = FWL_WGTSTATE_Invisible; 373 prop->m_dwStates = FWL_WGTSTATE_Invisible;
382 prop->m_pOwner = this; 374 prop->m_pOwner = this;
383 375
384 m_pForm.reset( 376 m_pForm = pdfium::MakeUnique<IFWL_FormProxy>(m_pOwnerApp, std::move(prop),
385 new IFWL_FormProxy(m_pOwnerApp, std::move(prop), m_pMonthCal.get())); 377 m_pMonthCal.get());
386 m_pMonthCal->SetParent(m_pForm.get()); 378 m_pMonthCal->SetParent(m_pForm.get());
387 } 379 }
388 380
389 bool IFWL_DateTimePicker::DisForm_IsMonthCalendarVisible() { 381 bool IFWL_DateTimePicker::DisForm_IsMonthCalendarVisible() const {
390 if (!m_pMonthCal) 382 if (!m_pMonthCal)
391 return false; 383 return false;
392 return !(m_pMonthCal->GetStates() & FWL_WGTSTATE_Invisible); 384 return !(m_pMonthCal->GetStates() & FWL_WGTSTATE_Invisible);
393 } 385 }
394 386
395 void IFWL_DateTimePicker::DisForm_ShowMonthCalendar(bool bActivate) { 387 void IFWL_DateTimePicker::DisForm_ShowMonthCalendar(bool bActivate) {
396 bool bShowed = IsMonthCalendarVisible(); 388 if (IsMonthCalendarVisible() == bActivate)
397 if (bShowed == bActivate) {
398 return; 389 return;
399 } 390
400 if (bActivate) { 391 if (bActivate) {
401 CFX_RectF rtMonthCal; 392 CFX_RectF rtMonthCal;
402 m_pMonthCal->GetWidgetRect(rtMonthCal, true); 393 m_pMonthCal->GetWidgetRect(rtMonthCal, true);
403 FX_FLOAT fPopupMin = rtMonthCal.height; 394 FX_FLOAT fPopupMin = rtMonthCal.height;
404 FX_FLOAT fPopupMax = rtMonthCal.height; 395 FX_FLOAT fPopupMax = rtMonthCal.height;
405 CFX_RectF rtAnchor(m_pProperties->m_rtWidget); 396 CFX_RectF rtAnchor(m_pProperties->m_rtWidget);
406 rtAnchor.width = rtMonthCal.width; 397 rtAnchor.width = rtMonthCal.width;
407 rtMonthCal.left = m_rtClient.left; 398 rtMonthCal.left = m_rtClient.left;
408 rtMonthCal.top = rtAnchor.Height(); 399 rtMonthCal.top = rtAnchor.Height();
409 GetPopupPos(fPopupMin, fPopupMax, rtAnchor, rtMonthCal); 400 GetPopupPos(fPopupMin, fPopupMax, rtAnchor, rtMonthCal);
410 m_pMonthCal->SetWidgetRect(rtMonthCal); 401 m_pMonthCal->SetWidgetRect(rtMonthCal);
411 if (m_iYear > 0 && m_iMonth > 0 && m_iDay > 0) { 402 if (m_iYear > 0 && m_iMonth > 0 && m_iDay > 0)
412 m_pMonthCal->SetSelect(m_iYear, m_iMonth, m_iDay); 403 m_pMonthCal->SetSelect(m_iYear, m_iMonth, m_iDay);
413 }
414 m_pMonthCal->Update(); 404 m_pMonthCal->Update();
415 } 405 }
416 m_pMonthCal->SetStates(FWL_WGTSTATE_Invisible, !bActivate); 406 m_pMonthCal->SetStates(FWL_WGTSTATE_Invisible, !bActivate);
407
417 if (bActivate) { 408 if (bActivate) {
418 CFWL_MsgSetFocus msg; 409 CFWL_MsgSetFocus msg;
419 msg.m_pDstTarget = m_pMonthCal.get(); 410 msg.m_pDstTarget = m_pMonthCal.get();
420 msg.m_pSrcTarget = m_pEdit.get(); 411 msg.m_pSrcTarget = m_pEdit.get();
421 m_pEdit->GetDelegate()->OnProcessMessage(&msg); 412 m_pEdit->GetDelegate()->OnProcessMessage(&msg);
422 } 413 }
414
423 CFX_RectF rtInvalidate, rtCal; 415 CFX_RectF rtInvalidate, rtCal;
424 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, 416 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width,
425 m_pProperties->m_rtWidget.height); 417 m_pProperties->m_rtWidget.height);
426 m_pMonthCal->GetWidgetRect(rtCal); 418 m_pMonthCal->GetWidgetRect(rtCal);
427 rtInvalidate.Union(rtCal); 419 rtInvalidate.Union(rtCal);
428 rtInvalidate.Inflate(2, 2); 420 rtInvalidate.Inflate(2, 2);
429 Repaint(&rtInvalidate); 421 Repaint(&rtInvalidate);
430 } 422 }
431 423
432 FWL_WidgetHit IFWL_DateTimePicker::DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy) { 424 FWL_WidgetHit IFWL_DateTimePicker::DisForm_HitTest(FX_FLOAT fx,
425 FX_FLOAT fy) const {
433 CFX_RectF rect; 426 CFX_RectF rect;
434 rect.Set(0, 0, m_pProperties->m_rtWidget.width, 427 rect.Set(0, 0, m_pProperties->m_rtWidget.width,
435 m_pProperties->m_rtWidget.height); 428 m_pProperties->m_rtWidget.height);
436 if (rect.Contains(fx, fy)) 429 if (rect.Contains(fx, fy))
437 return FWL_WidgetHit::Edit; 430 return FWL_WidgetHit::Edit;
438 if (DisForm_IsNeedShowButton()) 431 if (DisForm_IsNeedShowButton())
439 rect.width += m_fBtn; 432 rect.width += m_fBtn;
440 if (rect.Contains(fx, fy)) 433 if (rect.Contains(fx, fy))
441 return FWL_WidgetHit::Client; 434 return FWL_WidgetHit::Client;
442 if (IsMonthCalendarVisible()) { 435 if (IsMonthCalendarVisible()) {
443 m_pMonthCal->GetWidgetRect(rect); 436 m_pMonthCal->GetWidgetRect(rect);
444 if (rect.Contains(fx, fy)) 437 if (rect.Contains(fx, fy))
445 return FWL_WidgetHit::Client; 438 return FWL_WidgetHit::Client;
446 } 439 }
447 return FWL_WidgetHit::Unknown; 440 return FWL_WidgetHit::Unknown;
448 } 441 }
449 442
450 bool IFWL_DateTimePicker::DisForm_IsNeedShowButton() { 443 bool IFWL_DateTimePicker::DisForm_IsNeedShowButton() const {
451 bool bFocus = m_pProperties->m_dwStates & FWL_WGTSTATE_Focused || 444 return m_pProperties->m_dwStates & FWL_WGTSTATE_Focused ||
452 m_pMonthCal->GetStates() & FWL_WGTSTATE_Focused || 445 m_pMonthCal->GetStates() & FWL_WGTSTATE_Focused ||
453 m_pEdit->GetStates() & FWL_WGTSTATE_Focused; 446 m_pEdit->GetStates() & FWL_WGTSTATE_Focused;
454 return bFocus;
455 } 447 }
456 448
457 void IFWL_DateTimePicker::DisForm_Update() { 449 void IFWL_DateTimePicker::DisForm_Update() {
458 if (m_iLock) 450 if (m_iLock)
459 return; 451 return;
460 if (!m_pProperties->m_pThemeProvider) 452 if (!m_pProperties->m_pThemeProvider)
461 m_pProperties->m_pThemeProvider = GetAvailableTheme(); 453 m_pProperties->m_pThemeProvider = GetAvailableTheme();
462 454
463 m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider); 455 m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider);
464 GetClientRect(m_rtClient); 456 GetClientRect(m_rtClient);
465 m_pEdit->SetWidgetRect(m_rtClient); 457 m_pEdit->SetWidgetRect(m_rtClient);
466 ResetEditAlignment(); 458 ResetEditAlignment();
467 m_pEdit->Update(); 459 m_pEdit->Update();
460
468 if (!m_pMonthCal->GetThemeProvider()) 461 if (!m_pMonthCal->GetThemeProvider())
469 m_pMonthCal->SetThemeProvider(m_pProperties->m_pThemeProvider); 462 m_pMonthCal->SetThemeProvider(m_pProperties->m_pThemeProvider);
470
471 if (m_pProperties->m_pDataProvider) { 463 if (m_pProperties->m_pDataProvider) {
472 IFWL_DateTimePickerDP* pData = 464 IFWL_DateTimePickerDP* pData =
473 static_cast<IFWL_DateTimePickerDP*>(m_pProperties->m_pDataProvider); 465 static_cast<IFWL_DateTimePickerDP*>(m_pProperties->m_pDataProvider);
474 pData->GetToday(this, m_iCurYear, m_iCurMonth, m_iCurDay); 466 pData->GetToday(this, m_iCurYear, m_iCurMonth, m_iCurDay);
475 } 467 }
468
476 FX_FLOAT* pWidth = static_cast<FX_FLOAT*>( 469 FX_FLOAT* pWidth = static_cast<FX_FLOAT*>(
477 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); 470 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth));
478 if (!pWidth) 471 if (!pWidth)
479 return; 472 return;
480 473
481 m_fBtn = *pWidth; 474 m_fBtn = *pWidth;
482 CFX_RectF rtMonthCal; 475 CFX_RectF rtMonthCal;
483 m_pMonthCal->GetWidgetRect(rtMonthCal, true); 476 m_pMonthCal->GetWidgetRect(rtMonthCal, true);
477
484 CFX_RectF rtPopUp; 478 CFX_RectF rtPopUp;
485 rtPopUp.Set(rtMonthCal.left, rtMonthCal.top + kDateTimePickerHeight, 479 rtPopUp.Set(rtMonthCal.left, rtMonthCal.top + kDateTimePickerHeight,
486 rtMonthCal.width, rtMonthCal.height); 480 rtMonthCal.width, rtMonthCal.height);
487 m_pMonthCal->SetWidgetRect(rtPopUp); 481 m_pMonthCal->SetWidgetRect(rtPopUp);
488 m_pMonthCal->Update(); 482 m_pMonthCal->Update();
489 } 483 }
490 484
491 void IFWL_DateTimePicker::DisForm_GetWidgetRect(CFX_RectF& rect, 485 void IFWL_DateTimePicker::DisForm_GetWidgetRect(CFX_RectF& rect,
492 bool bAutoSize) { 486 bool bAutoSize) {
493 rect = m_pProperties->m_rtWidget; 487 rect = m_pProperties->m_rtWidget;
494 if (DisForm_IsNeedShowButton()) { 488 if (DisForm_IsNeedShowButton())
495 rect.width += m_fBtn; 489 rect.width += m_fBtn;
496 }
497 } 490 }
498 491
499 void IFWL_DateTimePicker::DisForm_GetBBox(CFX_RectF& rect) { 492 void IFWL_DateTimePicker::DisForm_GetBBox(CFX_RectF& rect) const {
500 rect = m_pProperties->m_rtWidget; 493 rect = m_pProperties->m_rtWidget;
501 if (DisForm_IsNeedShowButton()) { 494 if (DisForm_IsNeedShowButton())
502 rect.width += m_fBtn; 495 rect.width += m_fBtn;
503 } 496 if (!IsMonthCalendarVisible())
504 if (IsMonthCalendarVisible()) { 497 return;
505 CFX_RectF rtMonth; 498
506 m_pMonthCal->GetWidgetRect(rtMonth); 499 CFX_RectF rtMonth;
507 rtMonth.Offset(m_pProperties->m_rtWidget.left, 500 m_pMonthCal->GetWidgetRect(rtMonth);
508 m_pProperties->m_rtWidget.top); 501 rtMonth.Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top);
509 rect.Union(rtMonth); 502 rect.Union(rtMonth);
510 }
511 } 503 }
512 504
513 void IFWL_DateTimePicker::DisForm_DrawWidget(CFX_Graphics* pGraphics, 505 void IFWL_DateTimePicker::DisForm_DrawWidget(CFX_Graphics* pGraphics,
514 const CFX_Matrix* pMatrix) { 506 const CFX_Matrix* pMatrix) {
515 if (!pGraphics) 507 if (!pGraphics)
516 return; 508 return;
517 if (m_pEdit) { 509 if (m_pEdit) {
518 CFX_RectF rtEdit; 510 CFX_RectF rtEdit;
519 m_pEdit->GetWidgetRect(rtEdit); 511 m_pEdit->GetWidgetRect(rtEdit);
512
520 CFX_Matrix mt; 513 CFX_Matrix mt;
521 mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top); 514 mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top);
522 if (pMatrix) { 515 if (pMatrix)
523 mt.Concat(*pMatrix); 516 mt.Concat(*pMatrix);
524 }
525 m_pEdit->DrawWidget(pGraphics, &mt); 517 m_pEdit->DrawWidget(pGraphics, &mt);
526 } 518 }
527 if (IsMonthCalendarVisible()) { 519 if (!IsMonthCalendarVisible())
528 CFX_RectF rtMonth; 520 return;
529 m_pMonthCal->GetWidgetRect(rtMonth); 521
530 CFX_Matrix mt; 522 CFX_RectF rtMonth;
531 mt.Set(1, 0, 0, 1, rtMonth.left, rtMonth.top); 523 m_pMonthCal->GetWidgetRect(rtMonth);
532 if (pMatrix) { 524 CFX_Matrix mt;
533 mt.Concat(*pMatrix); 525 mt.Set(1, 0, 0, 1, rtMonth.left, rtMonth.top);
534 } 526 if (pMatrix)
535 m_pMonthCal->DrawWidget(pGraphics, &mt); 527 mt.Concat(*pMatrix);
536 } 528 m_pMonthCal->DrawWidget(pGraphics, &mt);
537 return;
538 } 529 }
539 530
540 void IFWL_DateTimePicker::OnProcessMessage(CFWL_Message* pMessage) { 531 void IFWL_DateTimePicker::OnProcessMessage(CFWL_Message* pMessage) {
541 if (!pMessage) 532 if (!pMessage)
542 return; 533 return;
543 534
544 switch (pMessage->GetClassID()) { 535 switch (pMessage->GetClassID()) {
545 case CFWL_MessageType::SetFocus: 536 case CFWL_MessageType::SetFocus:
546 OnFocusChanged(pMessage, true); 537 OnFocusChanged(pMessage, true);
547 break; 538 break;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 ShowMonthCalendar(false); 595 ShowMonthCalendar(false);
605 } 596 }
606 Repaint(&m_rtClient); 597 Repaint(&m_rtClient);
607 } 598 }
608 599
609 void IFWL_DateTimePicker::OnLButtonDown(CFWL_MsgMouse* pMsg) { 600 void IFWL_DateTimePicker::OnLButtonDown(CFWL_MsgMouse* pMsg) {
610 if (!pMsg) 601 if (!pMsg)
611 return; 602 return;
612 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) 603 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0)
613 SetFocus(true); 604 SetFocus(true);
614 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { 605 if (!m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy))
615 if (IsMonthCalendarVisible()) { 606 return;
616 ShowMonthCalendar(false); 607
617 CFWL_Event_DtpCloseUp ev; 608 if (IsMonthCalendarVisible()) {
618 DispatchEvent(&ev); 609 ShowMonthCalendar(false);
619 } else { 610 CFWL_Event_DtpCloseUp ev;
620 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_TimeFormat)) { 611 DispatchEvent(&ev);
621 ShowMonthCalendar(true); 612 return;
622 CFWL_Event_DtpDropDown ev;
623 DispatchEvent(&ev);
624 }
625 m_bLBtnDown = true;
626 Repaint(&m_rtClient);
627 }
628 } 613 }
614
615 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_TimeFormat)) {
616 ShowMonthCalendar(true);
617 CFWL_Event_DtpDropDown ev;
618 DispatchEvent(&ev);
619 }
620 m_bLBtnDown = true;
621 Repaint(&m_rtClient);
629 } 622 }
630 623
631 void IFWL_DateTimePicker::OnLButtonUp(CFWL_MsgMouse* pMsg) { 624 void IFWL_DateTimePicker::OnLButtonUp(CFWL_MsgMouse* pMsg) {
632 if (!pMsg) 625 if (!pMsg)
633 return; 626 return;
634 627
635 m_bLBtnDown = false; 628 m_bLBtnDown = false;
636 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) 629 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy))
637 m_iBtnState = CFWL_PartState_Hovered; 630 m_iBtnState = CFWL_PartState_Hovered;
638 else 631 else
639 m_iBtnState = CFWL_PartState_Normal; 632 m_iBtnState = CFWL_PartState_Normal;
640 Repaint(&m_rtBtn); 633 Repaint(&m_rtBtn);
641 } 634 }
642 635
643 void IFWL_DateTimePicker::OnMouseMove(CFWL_MsgMouse* pMsg) { 636 void IFWL_DateTimePicker::OnMouseMove(CFWL_MsgMouse* pMsg) {
644 if (!m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) 637 if (!m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy))
645 m_iBtnState = CFWL_PartState_Normal; 638 m_iBtnState = CFWL_PartState_Normal;
646
647 Repaint(&m_rtBtn); 639 Repaint(&m_rtBtn);
648 } 640 }
649 641
650 void IFWL_DateTimePicker::OnMouseLeave(CFWL_MsgMouse* pMsg) { 642 void IFWL_DateTimePicker::OnMouseLeave(CFWL_MsgMouse* pMsg) {
651 if (!pMsg) 643 if (!pMsg)
652 return; 644 return;
653 m_iBtnState = CFWL_PartState_Normal; 645 m_iBtnState = CFWL_PartState_Normal;
654 Repaint(&m_rtBtn); 646 Repaint(&m_rtBtn);
655 } 647 }
656 648
(...skipping 30 matching lines...) Expand all
687 return m_iCurDay; 679 return m_iCurDay;
688 } 680 }
689 681
690 int32_t IFWL_DateTimePicker::GetCurMonth(IFWL_Widget* pWidget) { 682 int32_t IFWL_DateTimePicker::GetCurMonth(IFWL_Widget* pWidget) {
691 return m_iCurMonth; 683 return m_iCurMonth;
692 } 684 }
693 685
694 int32_t IFWL_DateTimePicker::GetCurYear(IFWL_Widget* pWidget) { 686 int32_t IFWL_DateTimePicker::GetCurYear(IFWL_Widget* pWidget) {
695 return m_iCurYear; 687 return m_iCurYear;
696 } 688 }
OLDNEW
« no previous file with comments | « xfa/fwl/core/ifwl_datetimepicker.h ('k') | xfa/fxfa/app/xfa_ffchoicelist.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698