OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #include "xfa/fwl/core/cfwl_monthcalendar.h" | |
8 | |
9 #include <algorithm> | |
10 #include <memory> | |
11 #include <utility> | |
12 | |
13 #include "third_party/base/ptr_util.h" | |
14 #include "xfa/fde/tto/fde_textout.h" | |
15 #include "xfa/fwl/core/cfwl_datetimepicker.h" | |
16 #include "xfa/fwl/core/cfwl_formproxy.h" | |
17 #include "xfa/fwl/core/cfwl_msgmouse.h" | |
18 #include "xfa/fwl/core/cfwl_notedriver.h" | |
19 #include "xfa/fwl/core/cfwl_themebackground.h" | |
20 #include "xfa/fwl/core/cfwl_themetext.h" | |
21 #include "xfa/fwl/core/ifwl_themeprovider.h" | |
22 | |
23 #define MONTHCAL_HSEP_HEIGHT 1 | |
24 #define MONTHCAL_VSEP_WIDTH 1 | |
25 #define MONTHCAL_HMARGIN 3 | |
26 #define MONTHCAL_VMARGIN 2 | |
27 #define MONTHCAL_ROWS 9 | |
28 #define MONTHCAL_COLUMNS 7 | |
29 #define MONTHCAL_HEADER_BTN_VMARGIN 7 | |
30 #define MONTHCAL_HEADER_BTN_HMARGIN 5 | |
31 | |
32 namespace { | |
33 | |
34 CFX_WideString* GetCapacityForDay(IFWL_ThemeProvider* pTheme, | |
35 CFWL_ThemePart& params, | |
36 uint32_t day) { | |
37 ASSERT(day < 7); | |
38 | |
39 if (day == 0) { | |
40 return static_cast<CFX_WideString*>( | |
41 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Sun)); | |
42 } | |
43 if (day == 1) { | |
44 return static_cast<CFX_WideString*>( | |
45 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Mon)); | |
46 } | |
47 if (day == 2) { | |
48 return static_cast<CFX_WideString*>( | |
49 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Tue)); | |
50 } | |
51 if (day == 3) { | |
52 return static_cast<CFX_WideString*>( | |
53 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Wed)); | |
54 } | |
55 if (day == 4) { | |
56 return static_cast<CFX_WideString*>( | |
57 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Thu)); | |
58 } | |
59 if (day == 5) { | |
60 return static_cast<CFX_WideString*>( | |
61 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Fri)); | |
62 } | |
63 | |
64 return static_cast<CFX_WideString*>( | |
65 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Sat)); | |
66 } | |
67 | |
68 CFX_WideString* GetCapacityForMonth(IFWL_ThemeProvider* pTheme, | |
69 CFWL_ThemePart& params, | |
70 uint32_t month) { | |
71 ASSERT(month < 12); | |
72 | |
73 if (month == 0) { | |
74 return static_cast<CFX_WideString*>( | |
75 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::January)); | |
76 } | |
77 if (month == 1) { | |
78 return static_cast<CFX_WideString*>( | |
79 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::February)); | |
80 } | |
81 if (month == 2) { | |
82 return static_cast<CFX_WideString*>( | |
83 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::March)); | |
84 } | |
85 if (month == 3) { | |
86 return static_cast<CFX_WideString*>( | |
87 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::April)); | |
88 } | |
89 if (month == 4) { | |
90 return static_cast<CFX_WideString*>( | |
91 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::May)); | |
92 } | |
93 if (month == 5) { | |
94 return static_cast<CFX_WideString*>( | |
95 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::June)); | |
96 } | |
97 if (month == 6) { | |
98 return static_cast<CFX_WideString*>( | |
99 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::July)); | |
100 } | |
101 if (month == 7) { | |
102 return static_cast<CFX_WideString*>( | |
103 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::August)); | |
104 } | |
105 if (month == 8) { | |
106 return static_cast<CFX_WideString*>( | |
107 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::September)); | |
108 } | |
109 if (month == 9) { | |
110 return static_cast<CFX_WideString*>( | |
111 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::October)); | |
112 } | |
113 if (month == 10) { | |
114 return static_cast<CFX_WideString*>( | |
115 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::November)); | |
116 } | |
117 | |
118 return static_cast<CFX_WideString*>( | |
119 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::December)); | |
120 } | |
121 | |
122 } // namespace | |
123 | |
124 CFWL_MonthCalendar::CFWL_MonthCalendar( | |
125 const CFWL_App* app, | |
126 std::unique_ptr<CFWL_WidgetProperties> properties, | |
127 CFWL_Widget* pOuter) | |
128 : CFWL_Widget(app, std::move(properties), pOuter), | |
129 m_bInitialized(false), | |
130 m_pDateTime(new CFX_DateTime), | |
131 m_iCurYear(2011), | |
132 m_iCurMonth(1), | |
133 m_iYear(2011), | |
134 m_iMonth(1), | |
135 m_iDay(1), | |
136 m_iHovered(-1), | |
137 m_iLBtnPartStates(CFWL_PartState_Normal), | |
138 m_iRBtnPartStates(CFWL_PartState_Normal), | |
139 m_bFlag(false) { | |
140 m_rtHead.Reset(); | |
141 m_rtWeek.Reset(); | |
142 m_rtLBtn.Reset(); | |
143 m_rtRBtn.Reset(); | |
144 m_rtDates.Reset(); | |
145 m_rtHSep.Reset(); | |
146 m_rtHeadText.Reset(); | |
147 m_rtToday.Reset(); | |
148 m_rtTodayFlag.Reset(); | |
149 m_rtClient.Reset(); | |
150 m_rtWeekNum.Reset(); | |
151 m_rtWeekNumSep.Reset(); | |
152 } | |
153 | |
154 CFWL_MonthCalendar::~CFWL_MonthCalendar() { | |
155 ClearDateItem(); | |
156 m_arrSelDays.RemoveAll(); | |
157 } | |
158 | |
159 FWL_Type CFWL_MonthCalendar::GetClassID() const { | |
160 return FWL_Type::MonthCalendar; | |
161 } | |
162 | |
163 CFX_RectF CFWL_MonthCalendar::GetAutosizedWidgetRect() { | |
164 CFX_SizeF fs = CalcSize(); | |
165 CFX_RectF rect; | |
166 rect.Set(0, 0, fs.x, fs.y); | |
167 InflateWidgetRect(rect); | |
168 return rect; | |
169 } | |
170 | |
171 void CFWL_MonthCalendar::Update() { | |
172 if (IsLocked()) | |
173 return; | |
174 if (!m_pProperties->m_pThemeProvider) | |
175 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
176 | |
177 GetCapValue(); | |
178 if (!m_bInitialized) { | |
179 InitDate(); | |
180 m_bInitialized = true; | |
181 } | |
182 | |
183 ClearDateItem(); | |
184 ResetDateItem(); | |
185 Layout(); | |
186 } | |
187 | |
188 void CFWL_MonthCalendar::DrawWidget(CFX_Graphics* pGraphics, | |
189 const CFX_Matrix* pMatrix) { | |
190 if (!pGraphics) | |
191 return; | |
192 if (!m_pProperties->m_pThemeProvider) | |
193 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
194 | |
195 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
196 if (HasBorder()) | |
197 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | |
198 if (HasEdge()) | |
199 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | |
200 | |
201 DrawBackground(pGraphics, pTheme, pMatrix); | |
202 DrawHeadBK(pGraphics, pTheme, pMatrix); | |
203 DrawLButton(pGraphics, pTheme, pMatrix); | |
204 DrawRButton(pGraphics, pTheme, pMatrix); | |
205 DrawSeperator(pGraphics, pTheme, pMatrix); | |
206 DrawDatesInBK(pGraphics, pTheme, pMatrix); | |
207 DrawDatesInCircle(pGraphics, pTheme, pMatrix); | |
208 DrawCaption(pGraphics, pTheme, pMatrix); | |
209 DrawWeek(pGraphics, pTheme, pMatrix); | |
210 DrawDatesIn(pGraphics, pTheme, pMatrix); | |
211 DrawDatesOut(pGraphics, pTheme, pMatrix); | |
212 DrawToday(pGraphics, pTheme, pMatrix); | |
213 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) { | |
214 DrawWeekNumberSep(pGraphics, pTheme, pMatrix); | |
215 DrawWeekNumber(pGraphics, pTheme, pMatrix); | |
216 } | |
217 } | |
218 | |
219 void CFWL_MonthCalendar::SetSelect(int32_t iYear, | |
220 int32_t iMonth, | |
221 int32_t iDay) { | |
222 ChangeToMonth(iYear, iMonth); | |
223 AddSelDay(iDay); | |
224 } | |
225 | |
226 void CFWL_MonthCalendar::DrawBackground(CFX_Graphics* pGraphics, | |
227 IFWL_ThemeProvider* pTheme, | |
228 const CFX_Matrix* pMatrix) { | |
229 CFWL_ThemeBackground params; | |
230 params.m_pWidget = this; | |
231 params.m_iPart = CFWL_Part::Background; | |
232 params.m_pGraphics = pGraphics; | |
233 params.m_dwStates = CFWL_PartState_Normal; | |
234 params.m_rtPart = m_rtClient; | |
235 if (pMatrix) | |
236 params.m_matrix.Concat(*pMatrix); | |
237 pTheme->DrawBackground(¶ms); | |
238 } | |
239 | |
240 void CFWL_MonthCalendar::DrawHeadBK(CFX_Graphics* pGraphics, | |
241 IFWL_ThemeProvider* pTheme, | |
242 const CFX_Matrix* pMatrix) { | |
243 CFWL_ThemeBackground params; | |
244 params.m_pWidget = this; | |
245 params.m_iPart = CFWL_Part::Header; | |
246 params.m_pGraphics = pGraphics; | |
247 params.m_dwStates = CFWL_PartState_Normal; | |
248 params.m_rtPart = m_rtHead; | |
249 if (pMatrix) | |
250 params.m_matrix.Concat(*pMatrix); | |
251 pTheme->DrawBackground(¶ms); | |
252 } | |
253 | |
254 void CFWL_MonthCalendar::DrawLButton(CFX_Graphics* pGraphics, | |
255 IFWL_ThemeProvider* pTheme, | |
256 const CFX_Matrix* pMatrix) { | |
257 CFWL_ThemeBackground params; | |
258 params.m_pWidget = this; | |
259 params.m_iPart = CFWL_Part::LBtn; | |
260 params.m_pGraphics = pGraphics; | |
261 params.m_dwStates = m_iLBtnPartStates; | |
262 params.m_rtPart = m_rtLBtn; | |
263 if (pMatrix) | |
264 params.m_matrix.Concat(*pMatrix); | |
265 pTheme->DrawBackground(¶ms); | |
266 } | |
267 | |
268 void CFWL_MonthCalendar::DrawRButton(CFX_Graphics* pGraphics, | |
269 IFWL_ThemeProvider* pTheme, | |
270 const CFX_Matrix* pMatrix) { | |
271 CFWL_ThemeBackground params; | |
272 params.m_pWidget = this; | |
273 params.m_iPart = CFWL_Part::RBtn; | |
274 params.m_pGraphics = pGraphics; | |
275 params.m_dwStates = m_iRBtnPartStates; | |
276 params.m_rtPart = m_rtRBtn; | |
277 if (pMatrix) | |
278 params.m_matrix.Concat(*pMatrix); | |
279 pTheme->DrawBackground(¶ms); | |
280 } | |
281 | |
282 void CFWL_MonthCalendar::DrawCaption(CFX_Graphics* pGraphics, | |
283 IFWL_ThemeProvider* pTheme, | |
284 const CFX_Matrix* pMatrix) { | |
285 CFWL_ThemeText textParam; | |
286 textParam.m_pWidget = this; | |
287 textParam.m_iPart = CFWL_Part::Caption; | |
288 textParam.m_dwStates = CFWL_PartState_Normal; | |
289 textParam.m_pGraphics = pGraphics; | |
290 int32_t iYear; | |
291 int32_t iMonth; | |
292 iYear = m_iCurYear; | |
293 iMonth = m_iCurMonth; | |
294 CFX_WideString wsCation; | |
295 GetHeadText(iYear, iMonth, wsCation); | |
296 textParam.m_wsText = wsCation; | |
297 m_szHead = | |
298 CalcTextSize(textParam.m_wsText, m_pProperties->m_pThemeProvider, false); | |
299 CalcHeadSize(); | |
300 textParam.m_rtPart = m_rtHeadText; | |
301 textParam.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; | |
302 textParam.m_iTTOAlign = FDE_TTOALIGNMENT_Center; | |
303 if (pMatrix) | |
304 textParam.m_matrix.Concat(*pMatrix); | |
305 pTheme->DrawText(&textParam); | |
306 } | |
307 | |
308 void CFWL_MonthCalendar::DrawSeperator(CFX_Graphics* pGraphics, | |
309 IFWL_ThemeProvider* pTheme, | |
310 const CFX_Matrix* pMatrix) { | |
311 CFWL_ThemeBackground params; | |
312 params.m_pWidget = this; | |
313 params.m_iPart = CFWL_Part::HSeparator; | |
314 params.m_pGraphics = pGraphics; | |
315 params.m_dwStates = CFWL_PartState_Normal; | |
316 params.m_rtPart = m_rtHSep; | |
317 if (pMatrix) | |
318 params.m_matrix.Concat(*pMatrix); | |
319 pTheme->DrawBackground(¶ms); | |
320 } | |
321 | |
322 void CFWL_MonthCalendar::DrawDatesInBK(CFX_Graphics* pGraphics, | |
323 IFWL_ThemeProvider* pTheme, | |
324 const CFX_Matrix* pMatrix) { | |
325 CFWL_ThemeBackground params; | |
326 params.m_pWidget = this; | |
327 params.m_iPart = CFWL_Part::DateInBK; | |
328 params.m_pGraphics = pGraphics; | |
329 if (pMatrix) | |
330 params.m_matrix.Concat(*pMatrix); | |
331 | |
332 int32_t iCount = m_arrDates.GetSize(); | |
333 for (int32_t j = 0; j < iCount; j++) { | |
334 DATEINFO* pDataInfo = m_arrDates.GetAt(j); | |
335 if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Selected) { | |
336 params.m_dwStates |= CFWL_PartState_Selected; | |
337 if (((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) == | |
338 0) && | |
339 pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) { | |
340 params.m_dwStates |= CFWL_PartState_Flagged; | |
341 } | |
342 if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Focused) | |
343 params.m_dwStates |= CFWL_PartState_Focused; | |
344 } else if (j == m_iHovered - 1) { | |
345 params.m_dwStates |= CFWL_PartState_Hovered; | |
346 } else if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) { | |
347 params.m_dwStates = CFWL_PartState_Flagged; | |
348 pTheme->DrawBackground(¶ms); | |
349 } | |
350 params.m_rtPart = pDataInfo->rect; | |
351 pTheme->DrawBackground(¶ms); | |
352 params.m_dwStates = 0; | |
353 } | |
354 } | |
355 | |
356 void CFWL_MonthCalendar::DrawWeek(CFX_Graphics* pGraphics, | |
357 IFWL_ThemeProvider* pTheme, | |
358 const CFX_Matrix* pMatrix) { | |
359 CFWL_ThemeText params; | |
360 params.m_pWidget = this; | |
361 params.m_iPart = CFWL_Part::Week; | |
362 params.m_pGraphics = pGraphics; | |
363 params.m_dwStates = CFWL_PartState_Normal; | |
364 params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; | |
365 CFX_RectF rtDayOfWeek; | |
366 if (pMatrix) | |
367 params.m_matrix.Concat(*pMatrix); | |
368 | |
369 for (int32_t i = 0; i < 7; i++) { | |
370 rtDayOfWeek.Set(m_rtWeek.left + i * (m_szCell.x + MONTHCAL_HMARGIN * 2), | |
371 m_rtWeek.top, m_szCell.x, m_szCell.y); | |
372 params.m_rtPart = rtDayOfWeek; | |
373 params.m_wsText = *GetCapacityForDay(pTheme, params, i); | |
374 params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; | |
375 pTheme->DrawText(¶ms); | |
376 } | |
377 } | |
378 | |
379 void CFWL_MonthCalendar::DrawWeekNumber(CFX_Graphics* pGraphics, | |
380 IFWL_ThemeProvider* pTheme, | |
381 const CFX_Matrix* pMatrix) { | |
382 CFWL_ThemeText params; | |
383 params.m_pWidget = this; | |
384 params.m_iPart = CFWL_Part::WeekNum; | |
385 params.m_pGraphics = pGraphics; | |
386 params.m_dwStates = CFWL_PartState_Normal; | |
387 params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; | |
388 CFX_WideString wsWeekNum; | |
389 params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; | |
390 params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; | |
391 if (pMatrix) | |
392 params.m_matrix.Concat(*pMatrix); | |
393 | |
394 int32_t iMonthNum = m_pDateTime->GetMonth(); | |
395 int32_t iDayNum = FX_DaysInMonth(m_iCurYear, iMonthNum); | |
396 int32_t iTemp = 0; | |
397 FX_FLOAT fVStartPos = m_rtClient.top + m_fHeadHei + m_fHSepHei; | |
398 FX_FLOAT fHStartPos = m_rtClient.left; | |
399 for (int32_t i = 1; i <= iDayNum; i += 7) { | |
400 iTemp++; | |
401 m_rtWeekNum.Set(fHStartPos, fVStartPos + m_fDateCellHei * iTemp, | |
402 m_fWeekNumWid, m_fDateCellHei); | |
403 wsWeekNum.Format(L"0"); | |
404 params.m_wsText = wsWeekNum; | |
405 params.m_rtPart = m_rtWeekNum; | |
406 pTheme->DrawText(¶ms); | |
407 } | |
408 } | |
409 | |
410 void CFWL_MonthCalendar::DrawWeekNumberSep(CFX_Graphics* pGraphics, | |
411 IFWL_ThemeProvider* pTheme, | |
412 const CFX_Matrix* pMatrix) { | |
413 CFWL_ThemeBackground params; | |
414 params.m_pWidget = this; | |
415 params.m_iPart = CFWL_Part::WeekNumSep; | |
416 params.m_pGraphics = pGraphics; | |
417 params.m_dwStates = CFWL_PartState_Normal; | |
418 params.m_rtPart = m_rtWeekNumSep; | |
419 if (pMatrix) | |
420 params.m_matrix.Concat(*pMatrix); | |
421 pTheme->DrawBackground(¶ms); | |
422 } | |
423 | |
424 void CFWL_MonthCalendar::DrawToday(CFX_Graphics* pGraphics, | |
425 IFWL_ThemeProvider* pTheme, | |
426 const CFX_Matrix* pMatrix) { | |
427 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) | |
428 return; | |
429 | |
430 CFWL_ThemeText params; | |
431 params.m_pWidget = this; | |
432 params.m_iPart = CFWL_Part::Today; | |
433 params.m_pGraphics = pGraphics; | |
434 params.m_dwStates = CFWL_PartState_Normal; | |
435 params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; | |
436 | |
437 CFX_WideString* wsDay = static_cast<CFX_WideString*>( | |
438 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Today)); | |
439 CFX_WideString wsText; | |
440 GetTodayText(m_iYear, m_iMonth, m_iDay, wsText); | |
441 params.m_wsText = *wsDay + wsText; | |
442 | |
443 m_szToday = | |
444 CalcTextSize(params.m_wsText, m_pProperties->m_pThemeProvider, false); | |
445 CalcTodaySize(); | |
446 params.m_rtPart = m_rtToday; | |
447 params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; | |
448 if (pMatrix) | |
449 params.m_matrix.Concat(*pMatrix); | |
450 pTheme->DrawText(¶ms); | |
451 } | |
452 | |
453 void CFWL_MonthCalendar::DrawDatesIn(CFX_Graphics* pGraphics, | |
454 IFWL_ThemeProvider* pTheme, | |
455 const CFX_Matrix* pMatrix) { | |
456 CFWL_ThemeText params; | |
457 params.m_pWidget = this; | |
458 params.m_iPart = CFWL_Part::DatesIn; | |
459 params.m_pGraphics = pGraphics; | |
460 params.m_dwStates = CFWL_PartState_Normal; | |
461 params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; | |
462 if (pMatrix) | |
463 params.m_matrix.Concat(*pMatrix); | |
464 | |
465 int32_t iCount = m_arrDates.GetSize(); | |
466 for (int32_t j = 0; j < iCount; j++) { | |
467 DATEINFO* pDataInfo = m_arrDates.GetAt(j); | |
468 params.m_wsText = pDataInfo->wsDay; | |
469 params.m_rtPart = pDataInfo->rect; | |
470 params.m_dwStates = pDataInfo->dwStates; | |
471 if (j + 1 == m_iHovered) | |
472 params.m_dwStates |= CFWL_PartState_Hovered; | |
473 params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; | |
474 pTheme->DrawText(¶ms); | |
475 } | |
476 } | |
477 | |
478 void CFWL_MonthCalendar::DrawDatesOut(CFX_Graphics* pGraphics, | |
479 IFWL_ThemeProvider* pTheme, | |
480 const CFX_Matrix* pMatrix) { | |
481 CFWL_ThemeText params; | |
482 params.m_pWidget = this; | |
483 params.m_iPart = CFWL_Part::DatesOut; | |
484 params.m_pGraphics = pGraphics; | |
485 params.m_dwStates = CFWL_PartState_Normal; | |
486 params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; | |
487 if (pMatrix) | |
488 params.m_matrix.Concat(*pMatrix); | |
489 pTheme->DrawText(¶ms); | |
490 } | |
491 | |
492 void CFWL_MonthCalendar::DrawDatesInCircle(CFX_Graphics* pGraphics, | |
493 IFWL_ThemeProvider* pTheme, | |
494 const CFX_Matrix* pMatrix) { | |
495 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) | |
496 return; | |
497 if (m_iMonth != m_iCurMonth || m_iYear != m_iCurYear) | |
498 return; | |
499 if (m_iDay < 1 || m_iDay > m_arrDates.GetSize()) | |
500 return; | |
501 | |
502 DATEINFO* pDate = m_arrDates[m_iDay - 1]; | |
503 if (!pDate) | |
504 return; | |
505 | |
506 CFWL_ThemeBackground params; | |
507 params.m_pWidget = this; | |
508 params.m_iPart = CFWL_Part::DateInCircle; | |
509 params.m_pGraphics = pGraphics; | |
510 params.m_rtPart = pDate->rect; | |
511 params.m_dwStates = CFWL_PartState_Normal; | |
512 if (pMatrix) | |
513 params.m_matrix.Concat(*pMatrix); | |
514 pTheme->DrawBackground(¶ms); | |
515 } | |
516 | |
517 CFX_SizeF CFWL_MonthCalendar::CalcSize() { | |
518 if (!m_pProperties->m_pThemeProvider) | |
519 return CFX_SizeF(); | |
520 | |
521 CFX_SizeF fs; | |
522 CFWL_ThemePart params; | |
523 params.m_pWidget = this; | |
524 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
525 FX_FLOAT fMaxWeekW = 0.0f; | |
526 FX_FLOAT fMaxWeekH = 0.0f; | |
527 | |
528 for (uint32_t i = 0; i < 7; ++i) { | |
529 CFX_SizeF sz = CalcTextSize(*GetCapacityForDay(pTheme, params, i), | |
530 m_pProperties->m_pThemeProvider, false); | |
531 fMaxWeekW = (fMaxWeekW >= sz.x) ? fMaxWeekW : sz.x; | |
532 fMaxWeekH = (fMaxWeekH >= sz.y) ? fMaxWeekH : sz.y; | |
533 } | |
534 | |
535 FX_FLOAT fDayMaxW = 0.0f; | |
536 FX_FLOAT fDayMaxH = 0.0f; | |
537 for (int day = 10; day <= 31; day++) { | |
538 CFX_WideString wsDay; | |
539 wsDay.Format(L"%d", day); | |
540 CFX_SizeF sz = CalcTextSize(wsDay, m_pProperties->m_pThemeProvider, false); | |
541 fDayMaxW = (fDayMaxW >= sz.x) ? fDayMaxW : sz.x; | |
542 fDayMaxH = (fDayMaxH >= sz.y) ? fDayMaxH : sz.y; | |
543 } | |
544 m_szCell.x = FX_FLOAT((fMaxWeekW >= fDayMaxW) ? (int)(fMaxWeekW + 0.5) | |
545 : (int)(fDayMaxW + 0.5)); | |
546 m_szCell.y = (fMaxWeekH >= fDayMaxH) ? fMaxWeekH : fDayMaxH; | |
547 fs.x = m_szCell.x * MONTHCAL_COLUMNS + | |
548 MONTHCAL_HMARGIN * MONTHCAL_COLUMNS * 2 + | |
549 MONTHCAL_HEADER_BTN_HMARGIN * 2; | |
550 FX_FLOAT fMonthMaxW = 0.0f; | |
551 FX_FLOAT fMonthMaxH = 0.0f; | |
552 | |
553 for (uint32_t i = 0; i < 12; ++i) { | |
554 CFX_SizeF sz = CalcTextSize(*GetCapacityForMonth(pTheme, params, i), | |
555 m_pProperties->m_pThemeProvider, false); | |
556 fMonthMaxW = (fMonthMaxW >= sz.x) ? fMonthMaxW : sz.x; | |
557 fMonthMaxH = (fMonthMaxH >= sz.y) ? fMonthMaxH : sz.y; | |
558 } | |
559 | |
560 CFX_WideString wsYear; | |
561 GetHeadText(m_iYear, m_iMonth, wsYear); | |
562 | |
563 CFX_SizeF szYear = | |
564 CalcTextSize(wsYear, m_pProperties->m_pThemeProvider, false); | |
565 fMonthMaxH = std::max(fMonthMaxH, szYear.y); | |
566 m_szHead = CFX_SizeF(fMonthMaxW + szYear.x, fMonthMaxH); | |
567 fMonthMaxW = m_szHead.x + MONTHCAL_HEADER_BTN_HMARGIN * 2 + m_szCell.x * 2; | |
568 fs.x = std::max(fs.x, fMonthMaxW); | |
569 | |
570 CFX_WideString wsToday; | |
571 GetTodayText(m_iYear, m_iMonth, m_iDay, wsToday); | |
572 CFX_WideString* wsText = static_cast<CFX_WideString*>( | |
573 pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Today)); | |
574 m_wsToday = *wsText + wsToday; | |
575 m_szToday = CalcTextSize(wsToday, m_pProperties->m_pThemeProvider, false); | |
576 m_szToday.y = (m_szToday.y >= m_szCell.y) ? m_szToday.y : m_szCell.y; | |
577 fs.y = m_szCell.x + m_szCell.y * (MONTHCAL_ROWS - 2) + m_szToday.y + | |
578 MONTHCAL_VMARGIN * MONTHCAL_ROWS * 2 + MONTHCAL_HEADER_BTN_VMARGIN * 4; | |
579 return fs; | |
580 } | |
581 | |
582 void CFWL_MonthCalendar::CalcHeadSize() { | |
583 FX_FLOAT fHeadHMargin = (m_rtClient.width - m_szHead.x) / 2; | |
584 FX_FLOAT fHeadVMargin = (m_szCell.x - m_szHead.y) / 2; | |
585 m_rtHeadText.Set(m_rtClient.left + fHeadHMargin, | |
586 m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN + | |
587 MONTHCAL_VMARGIN + fHeadVMargin, | |
588 m_szHead.x, m_szHead.y); | |
589 } | |
590 | |
591 void CFWL_MonthCalendar::CalcTodaySize() { | |
592 m_rtTodayFlag.Set( | |
593 m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN, | |
594 m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN, | |
595 m_szCell.x, m_szToday.y); | |
596 m_rtToday.Set( | |
597 m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + m_szCell.x + | |
598 MONTHCAL_HMARGIN * 2, | |
599 m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN, | |
600 m_szToday.x, m_szToday.y); | |
601 } | |
602 | |
603 void CFWL_MonthCalendar::Layout() { | |
604 GetClientRect(m_rtClient); | |
605 | |
606 m_rtHead.Set( | |
607 m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, m_rtClient.top, | |
608 m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, | |
609 m_szCell.x + (MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN) * 2); | |
610 m_rtWeek.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, m_rtHead.bottom(), | |
611 m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, | |
612 m_szCell.y + MONTHCAL_VMARGIN * 2); | |
613 m_rtLBtn.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, | |
614 m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN, m_szCell.x, | |
615 m_szCell.x); | |
616 m_rtRBtn.Set(m_rtClient.left + m_rtClient.width - | |
617 MONTHCAL_HEADER_BTN_HMARGIN - m_szCell.x, | |
618 m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN, m_szCell.x, | |
619 m_szCell.x); | |
620 m_rtHSep.Set( | |
621 m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN, | |
622 m_rtWeek.bottom() - MONTHCAL_VMARGIN, | |
623 m_rtClient.width - (MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN) * 2, | |
624 MONTHCAL_HSEP_HEIGHT); | |
625 m_rtDates.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, | |
626 m_rtWeek.bottom(), | |
627 m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, | |
628 m_szCell.y * (MONTHCAL_ROWS - 3) + | |
629 MONTHCAL_VMARGIN * (MONTHCAL_ROWS - 3) * 2); | |
630 | |
631 CalDateItem(); | |
632 } | |
633 | |
634 void CFWL_MonthCalendar::CalDateItem() { | |
635 bool bNewWeek = false; | |
636 int32_t iWeekOfMonth = 0; | |
637 FX_FLOAT fLeft = m_rtDates.left; | |
638 FX_FLOAT fTop = m_rtDates.top; | |
639 int32_t iCount = m_arrDates.GetSize(); | |
640 for (int32_t i = 0; i < iCount; i++) { | |
641 DATEINFO* pDateInfo = m_arrDates.GetAt(i); | |
642 if (bNewWeek) { | |
643 iWeekOfMonth++; | |
644 bNewWeek = false; | |
645 } | |
646 pDateInfo->rect.Set( | |
647 fLeft + pDateInfo->iDayOfWeek * (m_szCell.x + (MONTHCAL_HMARGIN * 2)), | |
648 fTop + iWeekOfMonth * (m_szCell.y + (MONTHCAL_VMARGIN * 2)), | |
649 m_szCell.x + (MONTHCAL_HMARGIN * 2), | |
650 m_szCell.y + (MONTHCAL_VMARGIN * 2)); | |
651 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) | |
652 pDateInfo->rect.Offset(m_fWeekNumWid, 0); | |
653 if (pDateInfo->iDayOfWeek >= 6) | |
654 bNewWeek = true; | |
655 } | |
656 } | |
657 | |
658 void CFWL_MonthCalendar::GetCapValue() { | |
659 if (!m_pProperties->m_pThemeProvider) | |
660 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
661 | |
662 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
663 CFWL_ThemePart part; | |
664 part.m_pWidget = this; | |
665 m_fHeadWid = *static_cast<FX_FLOAT*>( | |
666 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderWidth)); | |
667 m_fHeadHei = *static_cast<FX_FLOAT*>( | |
668 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderHeight)); | |
669 m_fHeadBtnWid = *static_cast<FX_FLOAT*>( | |
670 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnWidth)); | |
671 m_fHeadBtnHei = *static_cast<FX_FLOAT*>( | |
672 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnHeight)); | |
673 m_fHeadBtnHMargin = *static_cast<FX_FLOAT*>( | |
674 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnHMargin)); | |
675 m_fHeadBtnVMargin = *static_cast<FX_FLOAT*>( | |
676 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnVMargin)); | |
677 m_fHeadTextWid = *static_cast<FX_FLOAT*>( | |
678 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextWidth)); | |
679 m_fHeadTextHei = *static_cast<FX_FLOAT*>( | |
680 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextHeight)); | |
681 m_fHeadTextHMargin = *static_cast<FX_FLOAT*>( | |
682 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextHMargin)); | |
683 m_fHeadTextVMargin = *static_cast<FX_FLOAT*>( | |
684 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextVMargin)); | |
685 m_fHSepWid = *static_cast<FX_FLOAT*>( | |
686 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HSepWidth)); | |
687 m_fHSepHei = *static_cast<FX_FLOAT*>( | |
688 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HSepHeight)); | |
689 m_fWeekNumWid = *static_cast<FX_FLOAT*>( | |
690 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekNumWidth)); | |
691 m_fSepDOffset = *static_cast<FX_FLOAT*>( | |
692 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepDOffset)); | |
693 m_fSepX = *static_cast<FX_FLOAT*>( | |
694 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepX)); | |
695 m_fSepY = *static_cast<FX_FLOAT*>( | |
696 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepY)); | |
697 m_fWeekNumHeigh = *static_cast<FX_FLOAT*>( | |
698 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekNumHeight)); | |
699 m_fWeekWid = *static_cast<FX_FLOAT*>( | |
700 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekWidth)); | |
701 m_fWeekHei = *static_cast<FX_FLOAT*>( | |
702 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekHeight)); | |
703 m_fDateCellWid = *static_cast<FX_FLOAT*>( | |
704 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::DatesCellWidth)); | |
705 m_fDateCellHei = *static_cast<FX_FLOAT*>( | |
706 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::DatesCellHeight)); | |
707 m_fTodayWid = *static_cast<FX_FLOAT*>( | |
708 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayWidth)); | |
709 m_fTodayHei = *static_cast<FX_FLOAT*>( | |
710 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayHeight)); | |
711 m_fTodayFlagWid = *static_cast<FX_FLOAT*>( | |
712 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayFlagWidth)); | |
713 m_fMCWid = *static_cast<FX_FLOAT*>( | |
714 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Width)); | |
715 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) | |
716 m_fMCWid += m_fWeekNumWid; | |
717 | |
718 m_fMCHei = *static_cast<FX_FLOAT*>( | |
719 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Height)); | |
720 } | |
721 | |
722 void CFWL_MonthCalendar::InitDate() { | |
723 // TODO(dsinclair): These should pull the real today values instead of | |
724 // pretending it's 2011-01-01. | |
725 m_iYear = 2011; | |
726 m_iMonth = 1; | |
727 m_iDay = 1; | |
728 m_iCurYear = m_iYear; | |
729 m_iCurMonth = m_iMonth; | |
730 | |
731 GetTodayText(m_iYear, m_iMonth, m_iDay, m_wsToday); | |
732 GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead); | |
733 m_dtMin = DATE(1500, 12, 1); | |
734 m_dtMax = DATE(2200, 1, 1); | |
735 } | |
736 | |
737 void CFWL_MonthCalendar::ClearDateItem() { | |
738 for (int32_t i = 0; i < m_arrDates.GetSize(); i++) | |
739 delete m_arrDates.GetAt(i); | |
740 m_arrDates.RemoveAll(); | |
741 } | |
742 | |
743 void CFWL_MonthCalendar::ResetDateItem() { | |
744 m_pDateTime->Set(m_iCurYear, m_iCurMonth, 1); | |
745 int32_t iDays = FX_DaysInMonth(m_iCurYear, m_iCurMonth); | |
746 int32_t iDayOfWeek = m_pDateTime->GetDayOfWeek(); | |
747 for (int32_t i = 0; i < iDays; i++) { | |
748 if (iDayOfWeek >= 7) | |
749 iDayOfWeek = 0; | |
750 | |
751 CFX_WideString wsDay; | |
752 wsDay.Format(L"%d", i + 1); | |
753 uint32_t dwStates = 0; | |
754 if (m_iYear == m_iCurYear && m_iMonth == m_iCurMonth && m_iDay == (i + 1)) | |
755 dwStates |= FWL_ITEMSTATE_MCD_Flag; | |
756 if (m_arrSelDays.Find(i + 1) != -1) | |
757 dwStates |= FWL_ITEMSTATE_MCD_Selected; | |
758 | |
759 CFX_RectF rtDate; | |
760 rtDate.Set(0, 0, 0, 0); | |
761 m_arrDates.Add(new DATEINFO(i + 1, iDayOfWeek, dwStates, rtDate, wsDay)); | |
762 iDayOfWeek++; | |
763 } | |
764 } | |
765 | |
766 void CFWL_MonthCalendar::NextMonth() { | |
767 int32_t iYear = m_iCurYear, iMonth = m_iCurMonth; | |
768 if (iMonth >= 12) { | |
769 iMonth = 1; | |
770 iYear++; | |
771 } else { | |
772 iMonth++; | |
773 } | |
774 DATE dt(m_iCurYear, m_iCurMonth, 1); | |
775 if (!(dt < m_dtMax)) | |
776 return; | |
777 | |
778 m_iCurYear = iYear, m_iCurMonth = iMonth; | |
779 ChangeToMonth(m_iCurYear, m_iCurMonth); | |
780 } | |
781 | |
782 void CFWL_MonthCalendar::PrevMonth() { | |
783 int32_t iYear = m_iCurYear, iMonth = m_iCurMonth; | |
784 if (iMonth <= 1) { | |
785 iMonth = 12; | |
786 iYear--; | |
787 } else { | |
788 iMonth--; | |
789 } | |
790 | |
791 DATE dt(m_iCurYear, m_iCurMonth, 1); | |
792 if (!(dt > m_dtMin)) | |
793 return; | |
794 | |
795 m_iCurYear = iYear, m_iCurMonth = iMonth; | |
796 ChangeToMonth(m_iCurYear, m_iCurMonth); | |
797 } | |
798 | |
799 void CFWL_MonthCalendar::ChangeToMonth(int32_t iYear, int32_t iMonth) { | |
800 m_iCurYear = iYear; | |
801 m_iCurMonth = iMonth; | |
802 m_iHovered = -1; | |
803 | |
804 ClearDateItem(); | |
805 ResetDateItem(); | |
806 CalDateItem(); | |
807 GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead); | |
808 } | |
809 | |
810 void CFWL_MonthCalendar::RemoveSelDay() { | |
811 int32_t iCount = m_arrSelDays.GetSize(); | |
812 int32_t iDatesCount = m_arrDates.GetSize(); | |
813 for (int32_t i = 0; i < iCount; i++) { | |
814 int32_t iSelDay = m_arrSelDays.GetAt(i); | |
815 if (iSelDay <= iDatesCount) { | |
816 DATEINFO* pDateInfo = m_arrDates.GetAt(iSelDay - 1); | |
817 pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected; | |
818 } | |
819 } | |
820 m_arrSelDays.RemoveAll(); | |
821 return; | |
822 } | |
823 | |
824 void CFWL_MonthCalendar::AddSelDay(int32_t iDay) { | |
825 ASSERT(iDay > 0); | |
826 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) | |
827 return; | |
828 | |
829 if (m_arrSelDays.Find(iDay) != -1) | |
830 return; | |
831 | |
832 RemoveSelDay(); | |
833 if (iDay <= m_arrDates.GetSize()) { | |
834 DATEINFO* pDateInfo = m_arrDates.GetAt(iDay - 1); | |
835 pDateInfo->dwStates |= FWL_ITEMSTATE_MCD_Selected; | |
836 } | |
837 m_arrSelDays.Add(iDay); | |
838 } | |
839 | |
840 void CFWL_MonthCalendar::JumpToToday() { | |
841 if (m_iYear != m_iCurYear || m_iMonth != m_iCurMonth) { | |
842 m_iCurYear = m_iYear; | |
843 m_iCurMonth = m_iMonth; | |
844 ChangeToMonth(m_iYear, m_iMonth); | |
845 AddSelDay(m_iDay); | |
846 return; | |
847 } | |
848 | |
849 if (m_arrSelDays.Find(m_iDay) == -1) | |
850 AddSelDay(m_iDay); | |
851 } | |
852 | |
853 void CFWL_MonthCalendar::GetHeadText(int32_t iYear, | |
854 int32_t iMonth, | |
855 CFX_WideString& wsHead) { | |
856 ASSERT(iMonth > 0 && iMonth < 13); | |
857 static const FX_WCHAR* const pMonth[] = { | |
858 L"January", L"February", L"March", L"April", | |
859 L"May", L"June", L"July", L"August", | |
860 L"September", L"October", L"November", L"December"}; | |
861 wsHead.Format(L"%s, %d", pMonth[iMonth - 1], iYear); | |
862 } | |
863 | |
864 void CFWL_MonthCalendar::GetTodayText(int32_t iYear, | |
865 int32_t iMonth, | |
866 int32_t iDay, | |
867 CFX_WideString& wsToday) { | |
868 wsToday.Format(L", %d/%d/%d", iDay, iMonth, iYear); | |
869 } | |
870 | |
871 int32_t CFWL_MonthCalendar::GetDayAtPoint(FX_FLOAT x, FX_FLOAT y) { | |
872 int32_t iCount = m_arrDates.GetSize(); | |
873 for (int32_t i = 0; i < iCount; i++) { | |
874 DATEINFO* pDateInfo = m_arrDates.GetAt(i); | |
875 if (pDateInfo->rect.Contains(x, y)) | |
876 return ++i; | |
877 } | |
878 return -1; | |
879 } | |
880 | |
881 void CFWL_MonthCalendar::GetDayRect(int32_t iDay, CFX_RectF& rtDay) { | |
882 if (iDay <= 0 || iDay > m_arrDates.GetSize()) | |
883 return; | |
884 | |
885 DATEINFO* pDateInfo = m_arrDates[iDay - 1]; | |
886 if (!pDateInfo) | |
887 return; | |
888 rtDay = pDateInfo->rect; | |
889 } | |
890 | |
891 void CFWL_MonthCalendar::OnProcessMessage(CFWL_Message* pMessage) { | |
892 if (!pMessage) | |
893 return; | |
894 | |
895 switch (pMessage->GetType()) { | |
896 case CFWL_Message::Type::SetFocus: | |
897 case CFWL_Message::Type::KillFocus: | |
898 GetOuter()->GetDelegate()->OnProcessMessage(pMessage); | |
899 break; | |
900 case CFWL_Message::Type::Key: | |
901 break; | |
902 case CFWL_Message::Type::Mouse: { | |
903 CFWL_MsgMouse* pMouse = static_cast<CFWL_MsgMouse*>(pMessage); | |
904 switch (pMouse->m_dwCmd) { | |
905 case FWL_MouseCommand::LeftButtonDown: | |
906 OnLButtonDown(pMouse); | |
907 break; | |
908 case FWL_MouseCommand::LeftButtonUp: | |
909 OnLButtonUp(pMouse); | |
910 break; | |
911 case FWL_MouseCommand::Move: | |
912 OnMouseMove(pMouse); | |
913 break; | |
914 case FWL_MouseCommand::Leave: | |
915 OnMouseLeave(pMouse); | |
916 break; | |
917 default: | |
918 break; | |
919 } | |
920 break; | |
921 } | |
922 default: | |
923 break; | |
924 } | |
925 CFWL_Widget::OnProcessMessage(pMessage); | |
926 } | |
927 | |
928 void CFWL_MonthCalendar::OnDrawWidget(CFX_Graphics* pGraphics, | |
929 const CFX_Matrix* pMatrix) { | |
930 DrawWidget(pGraphics, pMatrix); | |
931 } | |
932 | |
933 void CFWL_MonthCalendar::OnLButtonDown(CFWL_MsgMouse* pMsg) { | |
934 if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
935 m_iLBtnPartStates = CFWL_PartState_Pressed; | |
936 PrevMonth(); | |
937 Repaint(&m_rtClient); | |
938 } else if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
939 m_iRBtnPartStates |= CFWL_PartState_Pressed; | |
940 NextMonth(); | |
941 Repaint(&m_rtClient); | |
942 } else if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
943 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) == 0) { | |
944 JumpToToday(); | |
945 Repaint(&m_rtClient); | |
946 } | |
947 } else { | |
948 CFWL_DateTimePicker* pIPicker = static_cast<CFWL_DateTimePicker*>(m_pOuter); | |
949 if (pIPicker->IsMonthCalendarVisible()) | |
950 m_bFlag = 1; | |
951 } | |
952 } | |
953 | |
954 void CFWL_MonthCalendar::OnLButtonUp(CFWL_MsgMouse* pMsg) { | |
955 if (m_pWidgetMgr->IsFormDisabled()) | |
956 return DisForm_OnLButtonUp(pMsg); | |
957 | |
958 if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
959 m_iLBtnPartStates = 0; | |
960 Repaint(&m_rtLBtn); | |
961 return; | |
962 } | |
963 if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
964 m_iRBtnPartStates = 0; | |
965 Repaint(&m_rtRBtn); | |
966 return; | |
967 } | |
968 if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) | |
969 return; | |
970 | |
971 int32_t iOldSel = 0; | |
972 if (m_arrSelDays.GetSize() > 0) | |
973 iOldSel = m_arrSelDays[0]; | |
974 | |
975 int32_t iCurSel = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); | |
976 CFWL_DateTimePicker* pIPicker = static_cast<CFWL_DateTimePicker*>(m_pOuter); | |
977 CFX_RectF rt = pIPicker->GetFormProxy()->GetWidgetRect(); | |
978 rt.Set(0, 0, rt.width, rt.height); | |
979 if (iCurSel > 0) { | |
980 DATEINFO* lpDatesInfo = m_arrDates.GetAt(iCurSel - 1); | |
981 CFX_RectF rtInvalidate(lpDatesInfo->rect); | |
982 if (iOldSel > 0 && iOldSel <= m_arrDates.GetSize()) { | |
983 lpDatesInfo = m_arrDates.GetAt(iOldSel - 1); | |
984 rtInvalidate.Union(lpDatesInfo->rect); | |
985 } | |
986 AddSelDay(iCurSel); | |
987 if (!m_pOuter) | |
988 return; | |
989 | |
990 pIPicker->ProcessSelChanged(m_iCurYear, m_iCurMonth, iCurSel); | |
991 pIPicker->ShowMonthCalendar(false); | |
992 } else if (m_bFlag && (!rt.Contains(pMsg->m_fx, pMsg->m_fy))) { | |
993 pIPicker->ShowMonthCalendar(false); | |
994 } | |
995 m_bFlag = 0; | |
996 } | |
997 | |
998 void CFWL_MonthCalendar::DisForm_OnLButtonUp(CFWL_MsgMouse* pMsg) { | |
999 if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
1000 m_iLBtnPartStates = 0; | |
1001 Repaint(&(m_rtLBtn)); | |
1002 return; | |
1003 } | |
1004 if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
1005 m_iRBtnPartStates = 0; | |
1006 Repaint(&(m_rtRBtn)); | |
1007 return; | |
1008 } | |
1009 if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) | |
1010 return; | |
1011 | |
1012 int32_t iOldSel = 0; | |
1013 if (m_arrSelDays.GetSize() > 0) | |
1014 iOldSel = m_arrSelDays[0]; | |
1015 | |
1016 int32_t iCurSel = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); | |
1017 if (iCurSel > 0) { | |
1018 DATEINFO* lpDatesInfo = m_arrDates.GetAt(iCurSel - 1); | |
1019 CFX_RectF rtInvalidate(lpDatesInfo->rect); | |
1020 if (iOldSel > 0 && iOldSel <= m_arrDates.GetSize()) { | |
1021 lpDatesInfo = m_arrDates.GetAt(iOldSel - 1); | |
1022 rtInvalidate.Union(lpDatesInfo->rect); | |
1023 } | |
1024 AddSelDay(iCurSel); | |
1025 CFWL_DateTimePicker* pDateTime = | |
1026 static_cast<CFWL_DateTimePicker*>(m_pOuter); | |
1027 pDateTime->ProcessSelChanged(m_iCurYear, m_iCurMonth, iCurSel); | |
1028 pDateTime->ShowMonthCalendar(false); | |
1029 } | |
1030 } | |
1031 | |
1032 void CFWL_MonthCalendar::OnMouseMove(CFWL_MsgMouse* pMsg) { | |
1033 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) | |
1034 return; | |
1035 | |
1036 bool bRepaint = false; | |
1037 CFX_RectF rtInvalidate; | |
1038 rtInvalidate.Set(0, 0, 0, 0); | |
1039 if (m_rtDates.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
1040 int32_t iHover = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); | |
1041 bRepaint = m_iHovered != iHover; | |
1042 if (bRepaint) { | |
1043 if (m_iHovered > 0) | |
1044 GetDayRect(m_iHovered, rtInvalidate); | |
1045 if (iHover > 0) { | |
1046 CFX_RectF rtDay; | |
1047 GetDayRect(iHover, rtDay); | |
1048 if (rtInvalidate.IsEmpty()) | |
1049 rtInvalidate = rtDay; | |
1050 else | |
1051 rtInvalidate.Union(rtDay); | |
1052 } | |
1053 } | |
1054 m_iHovered = iHover; | |
1055 } else { | |
1056 bRepaint = m_iHovered > 0; | |
1057 if (bRepaint) | |
1058 GetDayRect(m_iHovered, rtInvalidate); | |
1059 | |
1060 m_iHovered = -1; | |
1061 } | |
1062 if (bRepaint && !rtInvalidate.IsEmpty()) | |
1063 Repaint(&rtInvalidate); | |
1064 } | |
1065 | |
1066 void CFWL_MonthCalendar::OnMouseLeave(CFWL_MsgMouse* pMsg) { | |
1067 if (m_iHovered <= 0) | |
1068 return; | |
1069 | |
1070 CFX_RectF rtInvalidate; | |
1071 rtInvalidate.Set(0, 0, 0, 0); | |
1072 GetDayRect(m_iHovered, rtInvalidate); | |
1073 m_iHovered = -1; | |
1074 if (!rtInvalidate.IsEmpty()) | |
1075 Repaint(&rtInvalidate); | |
1076 } | |
1077 | |
1078 CFWL_MonthCalendar::DATEINFO::DATEINFO(int32_t day, | |
1079 int32_t dayofweek, | |
1080 uint32_t dwSt, | |
1081 CFX_RectF rc, | |
1082 CFX_WideString& wsday) | |
1083 : iDay(day), | |
1084 iDayOfWeek(dayofweek), | |
1085 dwStates(dwSt), | |
1086 rect(rc), | |
1087 wsDay(wsday) {} | |
1088 | |
1089 CFWL_MonthCalendar::DATEINFO::~DATEINFO() {} | |
OLD | NEW |