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

Side by Side Diff: xfa/src/fwl/basewidget/fwl_monthcalendarimp.cpp

Issue 1803723002: Move xfa/src up to xfa/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 months 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
OLDNEW
(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/src/fwl/basewidget/fwl_monthcalendarimp.h"
8
9 #include <algorithm>
10
11 #include "xfa/include/fwl/basewidget/fwl_monthcalendar.h"
12 #include "xfa/include/fwl/core/fwl_theme.h"
13 #include "xfa/src/fde/tto/fde_textout.h"
14 #include "xfa/src/fwl/core/fwl_noteimp.h"
15 #include "xfa/src/fwl/core/fwl_targetimp.h"
16 #include "xfa/src/fwl/core/fwl_widgetimp.h"
17
18 #define MONTHCAL_HSEP_HEIGHT 1
19 #define MONTHCAL_VSEP_WIDTH 1
20 #define MONTHCAL_HMARGIN 3
21 #define MONTHCAL_VMARGIN 2
22 #define MONTHCAL_ROWS 9
23 #define MONTHCAL_COLUMNS 7
24 #define MONTHCAL_HEADER_BTN_VMARGIN 7
25 #define MONTHCAL_HEADER_BTN_HMARGIN 5
26
27 // static
28 IFWL_MonthCalendar* IFWL_MonthCalendar::Create(
29 const CFWL_WidgetImpProperties& properties,
30 IFWL_Widget* pOuter) {
31 IFWL_MonthCalendar* pMonthCalendar = new IFWL_MonthCalendar;
32 CFWL_MonthCalendarImp* pMonthCalendarImpl =
33 new CFWL_MonthCalendarImp(properties, pOuter);
34 pMonthCalendar->SetImpl(pMonthCalendarImpl);
35 pMonthCalendarImpl->SetInterface(pMonthCalendar);
36 return pMonthCalendar;
37 }
38 IFWL_MonthCalendar::IFWL_MonthCalendar() {}
39 int32_t IFWL_MonthCalendar::CountSelect() {
40 return static_cast<CFWL_MonthCalendarImp*>(GetImpl())->CountSelect();
41 }
42 FX_BOOL IFWL_MonthCalendar::GetSelect(int32_t& iYear,
43 int32_t& iMonth,
44 int32_t& iDay,
45 int32_t nIndex) {
46 return static_cast<CFWL_MonthCalendarImp*>(GetImpl())
47 ->GetSelect(iYear, iMonth, iDay, nIndex);
48 }
49 FX_BOOL IFWL_MonthCalendar::SetSelect(int32_t iYear,
50 int32_t iMonth,
51 int32_t iDay) {
52 return static_cast<CFWL_MonthCalendarImp*>(GetImpl())
53 ->SetSelect(iYear, iMonth, iDay);
54 }
55
56 CFWL_MonthCalendarImp::CFWL_MonthCalendarImp(
57 const CFWL_WidgetImpProperties& properties,
58 IFWL_Widget* pOuter)
59 : CFWL_WidgetImp(properties, pOuter),
60 m_iCurYear(2011),
61 m_iCurMonth(1),
62 m_iYear(2011),
63 m_iMonth(1),
64 m_iDay(1),
65 m_iHovered(-1),
66 m_iLBtnPartStates(FWL_PARTSTATE_MCD_Normal),
67 m_iRBtnPartStates(FWL_PARTSTATE_MCD_Normal) {
68 m_rtHead.Reset();
69 m_rtWeek.Reset();
70 m_rtLBtn.Reset();
71 m_rtRBtn.Reset();
72 m_rtDates.Reset();
73 m_rtHSep.Reset();
74 m_rtHeadText.Reset();
75 m_rtToday.Reset();
76 m_rtTodayFlag.Reset();
77 m_rtClient.Reset();
78 m_rtWeekNum.Reset();
79 m_rtWeekNumSep.Reset();
80 m_pDateTime = new CFX_DateTime;
81 m_bInit = FALSE;
82 m_iMaxSel = 1;
83 }
84 CFWL_MonthCalendarImp::~CFWL_MonthCalendarImp() {
85 ClearDateItem();
86 delete m_pDateTime;
87 m_arrSelDays.RemoveAll();
88 }
89 FWL_ERR CFWL_MonthCalendarImp::GetClassName(CFX_WideString& wsClass) const {
90 wsClass = FWL_CLASS_MonthCalendar;
91 return FWL_ERR_Succeeded;
92 }
93 FX_DWORD CFWL_MonthCalendarImp::GetClassID() const {
94 return FWL_CLASSHASH_MonthCalendar;
95 }
96 FWL_ERR CFWL_MonthCalendarImp::Initialize() {
97 if (CFWL_WidgetImp::Initialize() != FWL_ERR_Succeeded)
98 return FWL_ERR_Indefinite;
99 m_pDelegate = new CFWL_MonthCalendarImpDelegate(this);
100 return FWL_ERR_Succeeded;
101 }
102 FWL_ERR CFWL_MonthCalendarImp::Finalize() {
103 delete m_pDelegate;
104 m_pDelegate = nullptr;
105 return CFWL_WidgetImp::Finalize();
106 }
107 FWL_ERR CFWL_MonthCalendarImp::GetWidgetRect(CFX_RectF& rect,
108 FX_BOOL bAutoSize) {
109 if (bAutoSize) {
110 CFX_SizeF fs = CalcSize(TRUE);
111 rect.Set(0, 0, fs.x, fs.y);
112 CFWL_WidgetImp::GetWidgetRect(rect, TRUE);
113 } else {
114 rect = m_pProperties->m_rtWidget;
115 }
116 return FWL_ERR_Succeeded;
117 }
118 FWL_ERR CFWL_MonthCalendarImp::Update() {
119 if (IsLocked()) {
120 return FWL_ERR_Indefinite;
121 }
122 if (!m_pProperties->m_pThemeProvider) {
123 m_pProperties->m_pThemeProvider = GetAvailableTheme();
124 }
125 GetCapValue();
126 if (!m_bInit) {
127 m_bInit = InitDate();
128 }
129 ClearDateItem();
130 ReSetDateItem();
131 LayOut();
132 return FWL_ERR_Succeeded;
133 }
134 FWL_ERR CFWL_MonthCalendarImp::DrawWidget(CFX_Graphics* pGraphics,
135 const CFX_Matrix* pMatrix) {
136 if (!pGraphics)
137 return FWL_ERR_Indefinite;
138 if (m_pProperties->m_pThemeProvider == NULL) {
139 m_pProperties->m_pThemeProvider = GetAvailableTheme();
140 }
141 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
142 if (HasBorder()) {
143 DrawBorder(pGraphics, FWL_PART_MCD_Border, pTheme, pMatrix);
144 }
145 if (HasEdge()) {
146 DrawEdge(pGraphics, FWL_PART_MCD_Edge, pTheme, pMatrix);
147 }
148 DrawBkground(pGraphics, pTheme, pMatrix);
149 DrawHeadBK(pGraphics, pTheme, pMatrix);
150 DrawLButton(pGraphics, pTheme, pMatrix);
151 DrawRButton(pGraphics, pTheme, pMatrix);
152 DrawSeperator(pGraphics, pTheme, pMatrix);
153 DrawDatesInBK(pGraphics, pTheme, pMatrix);
154 DrawDatesInCircle(pGraphics, pTheme, pMatrix);
155 DrawCaption(pGraphics, pTheme, pMatrix);
156 DrawWeek(pGraphics, pTheme, pMatrix);
157 DrawDatesIn(pGraphics, pTheme, pMatrix);
158 DrawDatesOut(pGraphics, pTheme, pMatrix);
159 DrawToday(pGraphics, pTheme, pMatrix);
160 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) {
161 DrawWeekNumberSep(pGraphics, pTheme, pMatrix);
162 DrawWeekNumber(pGraphics, pTheme, pMatrix);
163 }
164 return FWL_ERR_Succeeded;
165 }
166 int32_t CFWL_MonthCalendarImp::CountSelect() {
167 return m_arrSelDays.GetSize();
168 }
169 FX_BOOL CFWL_MonthCalendarImp::GetSelect(int32_t& iYear,
170 int32_t& iMonth,
171 int32_t& iDay,
172 int32_t nIndex) {
173 if (nIndex >= m_arrSelDays.GetSize()) {
174 return FALSE;
175 }
176 iYear = m_iCurYear;
177 iMonth = m_iCurMonth;
178 iDay = m_arrSelDays[nIndex];
179 return TRUE;
180 }
181 FX_BOOL CFWL_MonthCalendarImp::SetSelect(int32_t iYear,
182 int32_t iMonth,
183 int32_t iDay) {
184 ChangeToMonth(iYear, iMonth);
185 return AddSelDay(iDay);
186 }
187 void CFWL_MonthCalendarImp::DrawBkground(CFX_Graphics* pGraphics,
188 IFWL_ThemeProvider* pTheme,
189 const CFX_Matrix* pMatrix) {
190 CFWL_ThemeBackground params;
191 params.m_pWidget = m_pInterface;
192 params.m_iPart = FWL_PART_MCD_Background;
193 params.m_pGraphics = pGraphics;
194 params.m_dwStates = FWL_PARTSTATE_MCD_Normal;
195 params.m_rtPart = m_rtClient;
196 if (pMatrix) {
197 params.m_matrix.Concat(*pMatrix);
198 }
199 pTheme->DrawBackground(&params);
200 }
201 void CFWL_MonthCalendarImp::DrawHeadBK(CFX_Graphics* pGraphics,
202 IFWL_ThemeProvider* pTheme,
203 const CFX_Matrix* pMatrix) {
204 CFWL_ThemeBackground params;
205 params.m_pWidget = m_pInterface;
206 params.m_iPart = FWL_PART_MCD_Header;
207 params.m_pGraphics = pGraphics;
208 params.m_dwStates = FWL_PARTSTATE_MCD_Normal;
209 params.m_rtPart = m_rtHead;
210 if (pMatrix) {
211 params.m_matrix.Concat(*pMatrix);
212 }
213 pTheme->DrawBackground(&params);
214 }
215 void CFWL_MonthCalendarImp::DrawLButton(CFX_Graphics* pGraphics,
216 IFWL_ThemeProvider* pTheme,
217 const CFX_Matrix* pMatrix) {
218 CFWL_ThemeBackground params;
219 params.m_pWidget = m_pInterface;
220 params.m_iPart = FWL_PART_MCD_LBtn;
221 params.m_pGraphics = pGraphics;
222 params.m_dwStates = m_iLBtnPartStates;
223 params.m_rtPart = m_rtLBtn;
224 if (pMatrix) {
225 params.m_matrix.Concat(*pMatrix);
226 }
227 pTheme->DrawBackground(&params);
228 }
229 void CFWL_MonthCalendarImp::DrawRButton(CFX_Graphics* pGraphics,
230 IFWL_ThemeProvider* pTheme,
231 const CFX_Matrix* pMatrix) {
232 CFWL_ThemeBackground params;
233 params.m_pWidget = m_pInterface;
234 params.m_iPart = FWL_PART_MCD_RBtn;
235 params.m_pGraphics = pGraphics;
236 params.m_dwStates = m_iRBtnPartStates;
237 params.m_rtPart = m_rtRBtn;
238 if (pMatrix) {
239 params.m_matrix.Concat(*pMatrix);
240 }
241 pTheme->DrawBackground(&params);
242 }
243 void CFWL_MonthCalendarImp::DrawCaption(CFX_Graphics* pGraphics,
244 IFWL_ThemeProvider* pTheme,
245 const CFX_Matrix* pMatrix) {
246 CFWL_ThemeText textParam;
247 textParam.m_pWidget = m_pInterface;
248 textParam.m_iPart = FWL_PART_MCD_Caption;
249 textParam.m_dwStates = FWL_PARTSTATE_MCD_Normal;
250 textParam.m_pGraphics = pGraphics;
251 int32_t iYear;
252 int32_t iMonth;
253 iYear = m_iCurYear;
254 iMonth = m_iCurMonth;
255 CFX_WideString wsCation;
256 GetHeadText(iYear, iMonth, wsCation);
257 textParam.m_wsText = wsCation;
258 m_szHead = CalcTextSize(textParam.m_wsText, m_pProperties->m_pThemeProvider);
259 CalcHeadSize();
260 textParam.m_rtPart = m_rtHeadText;
261 textParam.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine;
262 textParam.m_iTTOAlign = FDE_TTOALIGNMENT_Center;
263 if (pMatrix) {
264 textParam.m_matrix.Concat(*pMatrix);
265 }
266 pTheme->DrawText(&textParam);
267 }
268 void CFWL_MonthCalendarImp::DrawSeperator(CFX_Graphics* pGraphics,
269 IFWL_ThemeProvider* pTheme,
270 const CFX_Matrix* pMatrix) {
271 CFWL_ThemeBackground params;
272 params.m_pWidget = m_pInterface;
273 params.m_iPart = FWL_PART_MCD_HSeparator;
274 params.m_pGraphics = pGraphics;
275 params.m_dwStates = FWL_PARTSTATE_MCD_Normal;
276 params.m_rtPart = m_rtHSep;
277 if (pMatrix) {
278 params.m_matrix.Concat(*pMatrix);
279 }
280 pTheme->DrawBackground(&params);
281 }
282 void CFWL_MonthCalendarImp::DrawDatesInBK(CFX_Graphics* pGraphics,
283 IFWL_ThemeProvider* pTheme,
284 const CFX_Matrix* pMatrix) {
285 CFWL_ThemeBackground params;
286 params.m_pWidget = m_pInterface;
287 params.m_iPart = FWL_PART_MCD_DateInBK;
288 params.m_pGraphics = pGraphics;
289 if (pMatrix) {
290 params.m_matrix.Concat(*pMatrix);
291 }
292 int32_t iCount = m_arrDates.GetSize();
293 for (int32_t j = 0; j < iCount; j++) {
294 FWL_DATEINFO* pDataInfo = (FWL_DATEINFO*)m_arrDates.GetAt(j);
295 if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Selected) {
296 params.m_dwStates |= FWL_PARTSTATE_MCD_Selected;
297 if (((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) ==
298 0) &&
299 pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) {
300 params.m_dwStates |= FWL_PARTSTATE_MCD_Flagged;
301 }
302 if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Focused) {
303 params.m_dwStates |= FWL_PARTSTATE_MCD_Focused;
304 }
305 } else if (j == m_iHovered - 1) {
306 params.m_dwStates |= FWL_PARTSTATE_MCD_Hovered;
307 } else if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) {
308 params.m_dwStates = FWL_PARTSTATE_MCD_Flagged;
309 pTheme->DrawBackground(&params);
310 }
311 params.m_rtPart = pDataInfo->rect;
312 pTheme->DrawBackground(&params);
313 params.m_dwStates = 0;
314 }
315 }
316 void CFWL_MonthCalendarImp::DrawWeek(CFX_Graphics* pGraphics,
317 IFWL_ThemeProvider* pTheme,
318 const CFX_Matrix* pMatrix) {
319 CFWL_ThemeText params;
320 params.m_pWidget = m_pInterface;
321 params.m_iPart = FWL_PART_MCD_Week;
322 params.m_pGraphics = pGraphics;
323 params.m_dwStates = FWL_PARTSTATE_MCD_Normal;
324 params.m_iTTOAlign = FDE_TTOALIGNMENT_Center;
325 CFX_RectF rtDayOfWeek;
326 if (pMatrix) {
327 params.m_matrix.Concat(*pMatrix);
328 }
329 for (int32_t i = 0; i < 7; i++) {
330 rtDayOfWeek.Set(m_rtWeek.left + i * (m_szCell.x + MONTHCAL_HMARGIN * 2),
331 m_rtWeek.top, m_szCell.x, m_szCell.y);
332 CFX_WideString* wsWeekDay = static_cast<CFX_WideString*>(
333 pTheme->GetCapacity(&params, i + FWL_MCCAPACITY_Sun));
334 params.m_rtPart = rtDayOfWeek;
335 params.m_wsText = *wsWeekDay;
336 params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine;
337 pTheme->DrawText(&params);
338 }
339 }
340 void CFWL_MonthCalendarImp::DrawWeekNumber(CFX_Graphics* pGraphics,
341 IFWL_ThemeProvider* pTheme,
342 const CFX_Matrix* pMatrix) {
343 CFWL_ThemeText params;
344 params.m_pWidget = m_pInterface;
345 params.m_iPart = FWL_PART_MCD_WeekNum;
346 params.m_pGraphics = pGraphics;
347 params.m_dwStates = FWL_PARTSTATE_MCD_Normal;
348 params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft;
349 CFX_WideString wsWeekNum;
350 params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine;
351 params.m_iTTOAlign = FDE_TTOALIGNMENT_Center;
352 if (pMatrix) {
353 params.m_matrix.Concat(*pMatrix);
354 }
355 int32_t iWeekNum = 0;
356 int32_t iMonthNum = m_pDateTime->GetMonth();
357 int32_t iDayNum = FX_DaysInMonth(m_iCurYear, iMonthNum);
358 int32_t iTemp = 0;
359 FX_FLOAT fVStartPos = m_rtClient.top + m_fHeadHei + m_fHSepHei;
360 FX_FLOAT fHStartPos = m_rtClient.left;
361 for (int32_t i = 1; i <= iDayNum; i += 7) {
362 iTemp++;
363 iWeekNum = CalWeekNumber(m_iCurYear, iMonthNum, i);
364 m_rtWeekNum.Set(fHStartPos, fVStartPos + m_fDateCellHei * iTemp,
365 m_fWeekNumWid, m_fDateCellHei);
366 wsWeekNum.Format(L"%d", iWeekNum);
367 params.m_wsText = wsWeekNum;
368 params.m_rtPart = m_rtWeekNum;
369 pTheme->DrawText(&params);
370 }
371 }
372 void CFWL_MonthCalendarImp::DrawWeekNumberSep(CFX_Graphics* pGraphics,
373 IFWL_ThemeProvider* pTheme,
374 const CFX_Matrix* pMatrix) {
375 CFWL_ThemeBackground params;
376 params.m_pWidget = m_pInterface;
377 params.m_iPart = FWL_PART_MCD_WeekNumSep;
378 params.m_pGraphics = pGraphics;
379 params.m_dwStates = FWL_PARTSTATE_MCD_Normal;
380 params.m_rtPart = m_rtWeekNumSep;
381 if (pMatrix) {
382 params.m_matrix.Concat(*pMatrix);
383 }
384 pTheme->DrawBackground(&params);
385 }
386 void CFWL_MonthCalendarImp::DrawToday(CFX_Graphics* pGraphics,
387 IFWL_ThemeProvider* pTheme,
388 const CFX_Matrix* pMatrix) {
389 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) {
390 return;
391 }
392 CFWL_ThemeText params;
393 params.m_pWidget = m_pInterface;
394 params.m_iPart = FWL_PART_MCD_Today;
395 params.m_pGraphics = pGraphics;
396 params.m_dwStates = FWL_PARTSTATE_MCD_Normal;
397 params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft;
398 CFX_WideString* wsDay = static_cast<CFX_WideString*>(
399 pTheme->GetCapacity(&params, FWL_MCCAPACITY_Today));
400 CFX_WideString wsText;
401 GetTodayText(m_iYear, m_iMonth, m_iDay, wsText);
402 params.m_wsText = *wsDay + wsText;
403 m_szToday = CalcTextSize(params.m_wsText, m_pProperties->m_pThemeProvider);
404 CalcTodaySize();
405 params.m_rtPart = m_rtToday;
406 params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine;
407 if (pMatrix) {
408 params.m_matrix.Concat(*pMatrix);
409 }
410 pTheme->DrawText(&params);
411 }
412 void CFWL_MonthCalendarImp::DrawDatesIn(CFX_Graphics* pGraphics,
413 IFWL_ThemeProvider* pTheme,
414 const CFX_Matrix* pMatrix) {
415 CFWL_ThemeText params;
416 params.m_pWidget = m_pInterface;
417 params.m_iPart = FWL_PART_MCD_DatesIn;
418 params.m_pGraphics = pGraphics;
419 params.m_dwStates = FWL_PARTSTATE_MCD_Normal;
420 params.m_iTTOAlign = FDE_TTOALIGNMENT_Center;
421 if (pMatrix) {
422 params.m_matrix.Concat(*pMatrix);
423 }
424 int32_t iCount = m_arrDates.GetSize();
425 for (int32_t j = 0; j < iCount; j++) {
426 FWL_DATEINFO* pDataInfo = (FWL_DATEINFO*)m_arrDates.GetAt(j);
427 params.m_wsText = pDataInfo->wsDay;
428 params.m_rtPart = pDataInfo->rect;
429 params.m_dwStates = pDataInfo->dwStates;
430 if (j + 1 == m_iHovered) {
431 params.m_dwStates |= FWL_PARTSTATE_MCD_Hovered;
432 }
433 params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine;
434 pTheme->DrawText(&params);
435 }
436 }
437 void CFWL_MonthCalendarImp::DrawDatesOut(CFX_Graphics* pGraphics,
438 IFWL_ThemeProvider* pTheme,
439 const CFX_Matrix* pMatrix) {
440 CFWL_ThemeText params;
441 params.m_pWidget = m_pInterface;
442 params.m_iPart = FWL_PART_MCD_DatesOut;
443 params.m_pGraphics = pGraphics;
444 params.m_dwStates = FWL_PARTSTATE_MCD_Normal;
445 params.m_iTTOAlign = FDE_TTOALIGNMENT_Center;
446 if (pMatrix) {
447 params.m_matrix.Concat(*pMatrix);
448 }
449 pTheme->DrawText(&params);
450 }
451 void CFWL_MonthCalendarImp::DrawDatesInCircle(CFX_Graphics* pGraphics,
452 IFWL_ThemeProvider* pTheme,
453 const CFX_Matrix* pMatrix) {
454 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) {
455 return;
456 }
457 if (m_iMonth != m_iCurMonth || m_iYear != m_iCurYear) {
458 return;
459 }
460 if (m_iDay < 1 || m_iDay > m_arrDates.GetSize()) {
461 return;
462 }
463 FWL_DATEINFO* pDate = (FWL_DATEINFO*)m_arrDates[m_iDay - 1];
464 if (!pDate)
465 return;
466 CFWL_ThemeBackground params;
467 params.m_pWidget = m_pInterface;
468 params.m_iPart = FWL_PART_MCD_DateInCircle;
469 params.m_pGraphics = pGraphics;
470 params.m_rtPart = pDate->rect;
471 params.m_dwStates = FWL_PARTSTATE_MCD_Normal;
472 if (pMatrix) {
473 params.m_matrix.Concat(*pMatrix);
474 }
475 pTheme->DrawBackground(&params);
476 }
477 void CFWL_MonthCalendarImp::DrawTodayCircle(CFX_Graphics* pGraphics,
478 IFWL_ThemeProvider* pTheme,
479 const CFX_Matrix* pMatrix) {
480 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) {
481 return;
482 }
483 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) {
484 return;
485 }
486 CFWL_ThemeBackground params;
487 params.m_pWidget = m_pInterface;
488 params.m_iPart = FWL_PART_MCD_TodayCircle;
489 params.m_pGraphics = pGraphics;
490 params.m_dwStates = FWL_PARTSTATE_MCD_Normal;
491 params.m_rtPart = m_rtTodayFlag;
492 if (pMatrix) {
493 params.m_matrix.Concat(*pMatrix);
494 }
495 pTheme->DrawBackground(&params);
496 }
497 CFX_SizeF CFWL_MonthCalendarImp::CalcSize(FX_BOOL bAutoSize) {
498 if (!m_pProperties->m_pThemeProvider)
499 return CFX_SizeF();
500
501 if (!bAutoSize) {
502 GetClientRect(m_rtClient);
503 return CFX_SizeF(m_rtClient.width, m_rtClient.height);
504 }
505
506 CFX_SizeF fs;
507 CFWL_ThemePart params;
508 params.m_pWidget = m_pInterface;
509 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
510 CFX_WideString* wsText = NULL;
511 FX_FLOAT fMaxWeekW = 0.0f;
512 FX_FLOAT fMaxWeekH = 0.0f;
513 for (FX_DWORD week = FWL_MCCAPACITY_Sun; week <= FWL_MCCAPACITY_Sat; week++) {
514 wsText = static_cast<CFX_WideString*>(pTheme->GetCapacity(&params, week));
515 CFX_SizeF sz = CalcTextSize(*wsText, m_pProperties->m_pThemeProvider);
516 fMaxWeekW = (fMaxWeekW >= sz.x) ? fMaxWeekW : sz.x;
517 fMaxWeekH = (fMaxWeekH >= sz.y) ? fMaxWeekH : sz.y;
518 }
519 FX_FLOAT fDayMaxW = 0.0f;
520 FX_FLOAT fDayMaxH = 0.0f;
521 for (int day = 10; day <= 31; day++) {
522 CFX_WideString wsDay;
523 wsDay.Format(L"%d", day);
524 CFX_SizeF sz = CalcTextSize(wsDay, m_pProperties->m_pThemeProvider);
525 fDayMaxW = (fDayMaxW >= sz.x) ? fDayMaxW : sz.x;
526 fDayMaxH = (fDayMaxH >= sz.y) ? fDayMaxH : sz.y;
527 }
528 m_szCell.x = FX_FLOAT((fMaxWeekW >= fDayMaxW) ? (int)(fMaxWeekW + 0.5)
529 : (int)(fDayMaxW + 0.5));
530 m_szCell.y = (fMaxWeekH >= fDayMaxH) ? fMaxWeekH : fDayMaxH;
531 fs.x = m_szCell.x * MONTHCAL_COLUMNS +
532 MONTHCAL_HMARGIN * MONTHCAL_COLUMNS * 2 +
533 MONTHCAL_HEADER_BTN_HMARGIN * 2;
534 FX_FLOAT fMonthMaxW = 0.0f;
535 FX_FLOAT fMonthMaxH = 0.0f;
536 for (FX_DWORD month = FWL_MCCAPACITY_January;
537 month <= FWL_MCCAPACITY_December; month++) {
538 wsText = static_cast<CFX_WideString*>(pTheme->GetCapacity(&params, month));
539 CFX_SizeF sz = CalcTextSize(*wsText, m_pProperties->m_pThemeProvider);
540 fMonthMaxW = (fMonthMaxW >= sz.x) ? fMonthMaxW : sz.x;
541 fMonthMaxH = (fMonthMaxH >= sz.y) ? fMonthMaxH : sz.y;
542 }
543 CFX_WideString wsYear;
544 GetHeadText(m_iYear, m_iMonth, wsYear);
545 CFX_SizeF szYear = CalcTextSize(wsYear, m_pProperties->m_pThemeProvider);
546 fMonthMaxH = std::max(fMonthMaxH, szYear.y);
547 m_szHead = CFX_SizeF(fMonthMaxW + szYear.x, fMonthMaxH);
548 fMonthMaxW = m_szHead.x + MONTHCAL_HEADER_BTN_HMARGIN * 2 + m_szCell.x * 2;
549 fs.x = std::max(fs.x, fMonthMaxW);
550 CFX_WideString wsToday;
551 GetTodayText(m_iYear, m_iMonth, m_iDay, wsToday);
552 wsText = static_cast<CFX_WideString*>(
553 pTheme->GetCapacity(&params, FWL_MCCAPACITY_Today));
554 m_wsToday = *wsText + wsToday;
555 m_szToday = CalcTextSize(wsToday, m_pProperties->m_pThemeProvider);
556 m_szToday.y = (m_szToday.y >= m_szCell.y) ? m_szToday.y : m_szCell.y;
557 fs.y = m_szCell.x + m_szCell.y * (MONTHCAL_ROWS - 2) + m_szToday.y +
558 MONTHCAL_VMARGIN * MONTHCAL_ROWS * 2 + MONTHCAL_HEADER_BTN_VMARGIN * 4;
559 return fs;
560 }
561
562 void CFWL_MonthCalendarImp::CalcHeadSize() {
563 FX_FLOAT fHeadHMargin = (m_rtClient.width - m_szHead.x) / 2;
564 FX_FLOAT fHeadVMargin = (m_szCell.x - m_szHead.y) / 2;
565 m_rtHeadText.Set(m_rtClient.left + fHeadHMargin,
566 m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN +
567 MONTHCAL_VMARGIN + fHeadVMargin,
568 m_szHead.x, m_szHead.y);
569 }
570 void CFWL_MonthCalendarImp::CalcTodaySize() {
571 m_rtTodayFlag.Set(
572 m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN,
573 m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN,
574 m_szCell.x, m_szToday.y);
575 m_rtToday.Set(
576 m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + m_szCell.x +
577 MONTHCAL_HMARGIN * 2,
578 m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN,
579 m_szToday.x, m_szToday.y);
580 }
581 void CFWL_MonthCalendarImp::LayOut() {
582 GetClientRect(m_rtClient);
583 {
584 m_rtHead.Set(
585 m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, m_rtClient.top,
586 m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2,
587 m_szCell.x + (MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN) * 2);
588 m_rtWeek.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN,
589 m_rtHead.bottom(),
590 m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2,
591 m_szCell.y + MONTHCAL_VMARGIN * 2);
592 m_rtLBtn.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN,
593 m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN, m_szCell.x,
594 m_szCell.x);
595 m_rtRBtn.Set(m_rtClient.left + m_rtClient.width -
596 MONTHCAL_HEADER_BTN_HMARGIN - m_szCell.x,
597 m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN, m_szCell.x,
598 m_szCell.x);
599 m_rtHSep.Set(
600 m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN,
601 m_rtWeek.bottom() - MONTHCAL_VMARGIN,
602 m_rtClient.width - (MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN) * 2,
603 MONTHCAL_HSEP_HEIGHT);
604 m_rtDates.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN,
605 m_rtWeek.bottom(),
606 m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2,
607 m_szCell.y * (MONTHCAL_ROWS - 3) +
608 MONTHCAL_VMARGIN * (MONTHCAL_ROWS - 3) * 2);
609 }
610 CalDateItem();
611 }
612 void CFWL_MonthCalendarImp::CalDateItem() {
613 FX_BOOL bNewWeek = FALSE;
614 int32_t iWeekOfMonth = 0;
615 FX_FLOAT fLeft = m_rtDates.left;
616 FX_FLOAT fTop = m_rtDates.top;
617 int32_t iCount = m_arrDates.GetSize();
618 for (int32_t i = 0; i < iCount; i++) {
619 FWL_DATEINFO* pDateInfo = (FWL_DATEINFO*)m_arrDates.GetAt(i);
620 if (bNewWeek) {
621 iWeekOfMonth++;
622 bNewWeek = FALSE;
623 }
624 pDateInfo->rect.Set(
625 fLeft + pDateInfo->iDayOfWeek * (m_szCell.x + (MONTHCAL_HMARGIN * 2)),
626 fTop + iWeekOfMonth * (m_szCell.y + (MONTHCAL_VMARGIN * 2)),
627 m_szCell.x + (MONTHCAL_HMARGIN * 2),
628 m_szCell.y + (MONTHCAL_VMARGIN * 2));
629 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) {
630 pDateInfo->rect.Offset(m_fWeekNumWid, 0);
631 }
632 if (pDateInfo->iDayOfWeek >= 6) {
633 bNewWeek = TRUE;
634 }
635 }
636 }
637 void CFWL_MonthCalendarImp::GetCapValue() {
638 if (!m_pProperties->m_pThemeProvider) {
639 m_pProperties->m_pThemeProvider = GetAvailableTheme();
640 }
641 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
642 CFWL_ThemePart part;
643 part.m_pWidget = m_pInterface;
644 m_fHeadWid = *static_cast<FX_FLOAT*>(
645 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_HEADER_WIDTH));
646 m_fHeadHei = *static_cast<FX_FLOAT*>(
647 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_HEADER_Height));
648 m_fHeadBtnWid = *static_cast<FX_FLOAT*>(
649 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_HEADER_BTN_WIDTH));
650 m_fHeadBtnHei = *static_cast<FX_FLOAT*>(
651 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_HEADER_BTN_HEIGHT));
652 m_fHeadBtnHMargin = *static_cast<FX_FLOAT*>(
653 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_HEADER_BTN_HMARGIN));
654 m_fHeadBtnVMargin = *static_cast<FX_FLOAT*>(
655 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_HEADER_BTN_VMARGIN));
656 m_fHeadTextWid = *static_cast<FX_FLOAT*>(
657 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_HEADER_TEXTWIDHT));
658 m_fHeadTextHei = *static_cast<FX_FLOAT*>(
659 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_HEADER_TEXTHEIGHT));
660 m_fHeadTextHMargin = *static_cast<FX_FLOAT*>(
661 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_HEADER_TEXT_HMARGIN));
662 m_fHeadTextVMargin = *static_cast<FX_FLOAT*>(
663 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_HEADER_TEXT_VMARGIN));
664 m_fHSepWid = *static_cast<FX_FLOAT*>(
665 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_HSEP_WIDTH));
666 m_fHSepHei = *static_cast<FX_FLOAT*>(
667 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_HSEP_HEIGHT));
668 m_fWeekNumWid = *static_cast<FX_FLOAT*>(
669 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_WEEKNUM_WIDTH));
670 m_fSepDOffset = *static_cast<FX_FLOAT*>(
671 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_SEP_DOFFSET));
672 m_fSepX = *static_cast<FX_FLOAT*>(
673 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_SEP_X));
674 m_fSepY = *static_cast<FX_FLOAT*>(
675 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_SEP_Y));
676 m_fWeekNumHeigh = *static_cast<FX_FLOAT*>(
677 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_WEEKNUM_HEIGHT));
678 m_fWeekWid = *static_cast<FX_FLOAT*>(
679 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_WEEK_WIDTH));
680 m_fWeekHei = *static_cast<FX_FLOAT*>(
681 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_WEEK_HEIGHT));
682 m_fDateCellWid = *static_cast<FX_FLOAT*>(
683 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_DATES_CELL_WIDTH));
684 m_fDateCellHei = *static_cast<FX_FLOAT*>(
685 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_DATES_CELL_HEIGHT));
686 m_fTodayWid = *static_cast<FX_FLOAT*>(
687 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_TODAY_WIDHT));
688 m_fTodayHei = *static_cast<FX_FLOAT*>(
689 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_TODAY_HEIGHT));
690 m_fTodayFlagWid = *static_cast<FX_FLOAT*>(
691 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_TODAY_FLAG_WIDHT));
692 m_fMCWid = *static_cast<FX_FLOAT*>(
693 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_WIDTH));
694 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) {
695 m_fMCWid += m_fWeekNumWid;
696 }
697 m_fMCHei = *static_cast<FX_FLOAT*>(
698 pTheme->GetCapacity(&part, FWL_WGTCAPACITY_MC_HEIGHT));
699 }
700 int32_t CFWL_MonthCalendarImp::CalWeekNumber(int32_t iYear,
701 int32_t iMonth,
702 int32_t iDay) {
703 return 0;
704 }
705 FX_BOOL CFWL_MonthCalendarImp::GetMinDate(int32_t& iYear,
706 int32_t& iMonth,
707 int32_t& iDay) {
708 iYear = m_dtMin.iYear;
709 iMonth = m_dtMin.iMonth;
710 iDay = m_dtMin.iDay;
711 return TRUE;
712 }
713 FX_BOOL CFWL_MonthCalendarImp::SetMinDate(int32_t iYear,
714 int32_t iMonth,
715 int32_t iDay) {
716 m_dtMin = DATE(iYear, iMonth, iDay);
717 return TRUE;
718 }
719 FX_BOOL CFWL_MonthCalendarImp::GetMaxDate(int32_t& iYear,
720 int32_t& iMonth,
721 int32_t& iDay) {
722 iYear = m_dtMax.iYear;
723 iMonth = m_dtMax.iMonth;
724 iDay = m_dtMax.iDay;
725 return TRUE;
726 }
727 FX_BOOL CFWL_MonthCalendarImp::SetMaxDate(int32_t iYear,
728 int32_t iMonth,
729 int32_t iDay) {
730 m_dtMax = DATE(iYear, iMonth, iDay);
731 return TRUE;
732 }
733 FX_BOOL CFWL_MonthCalendarImp::InitDate() {
734 if (m_pProperties->m_pDataProvider) {
735 IFWL_MonthCalendarDP* pDateProv =
736 static_cast<IFWL_MonthCalendarDP*>(m_pProperties->m_pDataProvider);
737 m_iYear = pDateProv->GetCurYear(m_pInterface);
738 m_iMonth = pDateProv->GetCurMonth(m_pInterface);
739 m_iDay = pDateProv->GetCurDay(m_pInterface);
740 m_iCurYear = m_iYear;
741 m_iCurMonth = m_iMonth;
742 } else {
743 m_iDay = 1;
744 m_iMonth = 1;
745 m_iYear = 1;
746 m_iCurYear = m_iYear;
747 m_iCurMonth = m_iMonth;
748 }
749 GetTodayText(m_iYear, m_iMonth, m_iDay, m_wsToday);
750 GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead);
751 m_dtMin = DATE(1500, 12, 1);
752 m_dtMax = DATE(2200, 1, 1);
753 return TRUE;
754 }
755 void CFWL_MonthCalendarImp::ClearDateItem() {
756 int32_t iCount = m_arrDates.GetSize();
757 for (int32_t i = 0; i < iCount; i++) {
758 FWL_DATEINFO* pData = (FWL_DATEINFO*)m_arrDates.GetAt(i);
759 delete pData;
760 }
761 m_arrDates.RemoveAll();
762 }
763 void CFWL_MonthCalendarImp::ReSetDateItem() {
764 m_pDateTime->Set(m_iCurYear, m_iCurMonth, 1);
765 int32_t iDays = FX_DaysInMonth(m_iCurYear, m_iCurMonth);
766 int32_t iDayOfWeek = m_pDateTime->GetDayOfWeek();
767 for (int32_t i = 0; i < iDays; i++) {
768 if (iDayOfWeek >= 7) {
769 iDayOfWeek = 0;
770 }
771 CFX_WideString wsDay;
772 wsDay.Format(L"%d", i + 1);
773 FX_DWORD dwStates = 0;
774 if (m_iYear == m_iCurYear && m_iMonth == m_iCurMonth && m_iDay == (i + 1)) {
775 dwStates |= FWL_ITEMSTATE_MCD_Flag;
776 }
777 if (m_arrSelDays.Find(i + 1) != -1) {
778 dwStates |= FWL_ITEMSTATE_MCD_Selected;
779 }
780 CFX_RectF rtDate;
781 rtDate.Set(0, 0, 0, 0);
782 m_arrDates.Add(
783 new FWL_DATEINFO(i + 1, iDayOfWeek, dwStates, rtDate, wsDay));
784 iDayOfWeek++;
785 }
786 }
787 FX_BOOL CFWL_MonthCalendarImp::NextMonth() {
788 int32_t iYear = m_iCurYear, iMonth = m_iCurMonth;
789 if (iMonth >= 12) {
790 iMonth = 1;
791 iYear++;
792 } else {
793 iMonth++;
794 }
795 DATE dt(m_iCurYear, m_iCurMonth, 1);
796 if (!(dt < m_dtMax)) {
797 return FALSE;
798 }
799 m_iCurYear = iYear, m_iCurMonth = iMonth;
800 ChangeToMonth(m_iCurYear, m_iCurMonth);
801 return TRUE;
802 }
803 FX_BOOL CFWL_MonthCalendarImp::PrevMonth() {
804 int32_t iYear = m_iCurYear, iMonth = m_iCurMonth;
805 if (iMonth <= 1) {
806 iMonth = 12;
807 iYear--;
808 } else {
809 iMonth--;
810 }
811 DATE dt(m_iCurYear, m_iCurMonth, 1);
812 if (!(dt > m_dtMin)) {
813 return FALSE;
814 }
815 m_iCurYear = iYear, m_iCurMonth = iMonth;
816 ChangeToMonth(m_iCurYear, m_iCurMonth);
817 return TRUE;
818 }
819 void CFWL_MonthCalendarImp::ChangeToMonth(int32_t iYear, int32_t iMonth) {
820 m_iCurYear = iYear;
821 m_iCurMonth = iMonth;
822 m_iHovered = -1;
823 ClearDateItem();
824 ReSetDateItem();
825 CalDateItem();
826 GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead);
827 }
828 FX_BOOL CFWL_MonthCalendarImp::RemoveSelDay(int32_t iDay, FX_BOOL bAll) {
829 if (iDay == -1 && !bAll) {
830 return FALSE;
831 }
832 if (bAll) {
833 int32_t iCount = m_arrSelDays.GetSize();
834 int32_t iDatesCount = m_arrDates.GetSize();
835 for (int32_t i = 0; i < iCount; i++) {
836 int32_t iSelDay = m_arrSelDays.GetAt(i);
837 if (iSelDay <= iDatesCount) {
838 FWL_DATEINFO* pDateInfo = (FWL_DATEINFO*)m_arrDates.GetAt(iSelDay - 1);
839 pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected;
840 }
841 }
842 m_arrSelDays.RemoveAll();
843 } else {
844 int32_t index = m_arrSelDays.Find(iDay);
845 if (index == -1) {
846 return FALSE;
847 }
848 int32_t iSelDay = m_arrSelDays.GetAt(iDay);
849 int32_t iDatesCount = m_arrDates.GetSize();
850 if (iSelDay <= iDatesCount) {
851 FWL_DATEINFO* pDateInfo = (FWL_DATEINFO*)m_arrDates.GetAt(iSelDay - 1);
852 pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected;
853 }
854 m_arrSelDays.RemoveAt(index);
855 }
856 return TRUE;
857 }
858 FX_BOOL CFWL_MonthCalendarImp::AddSelDay(int32_t iDay) {
859 FXSYS_assert(iDay > 0);
860 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) {
861 } else {
862 if (m_arrSelDays.Find(iDay) == -1) {
863 RemoveSelDay(-1, TRUE);
864 if (iDay <= m_arrDates.GetSize()) {
865 FWL_DATEINFO* pDateInfo = (FWL_DATEINFO*)m_arrDates.GetAt(iDay - 1);
866 pDateInfo->dwStates |= FWL_ITEMSTATE_MCD_Selected;
867 }
868 m_arrSelDays.Add(iDay);
869 }
870 }
871 return TRUE;
872 }
873 FX_BOOL CFWL_MonthCalendarImp::JumpToToday() {
874 if (m_iYear != m_iCurYear || m_iMonth != m_iCurMonth) {
875 m_iCurYear = m_iYear;
876 m_iCurMonth = m_iMonth;
877 ChangeToMonth(m_iYear, m_iMonth);
878 AddSelDay(m_iDay);
879 } else {
880 if (m_arrSelDays.Find(m_iDay) == -1) {
881 AddSelDay(m_iDay);
882 }
883 }
884 return TRUE;
885 }
886 void CFWL_MonthCalendarImp::GetHeadText(int32_t iYear,
887 int32_t iMonth,
888 CFX_WideString& wsHead) {
889 FXSYS_assert(iMonth > 0 && iMonth < 13);
890 static const FX_WCHAR* const pMonth[] = {
891 L"January", L"February", L"March", L"April",
892 L"May", L"June", L"July", L"August",
893 L"September", L"October", L"November", L"December"};
894 wsHead.Format(L"%s, %d", pMonth[iMonth - 1], iYear);
895 }
896 void CFWL_MonthCalendarImp::GetTodayText(int32_t iYear,
897 int32_t iMonth,
898 int32_t iDay,
899 CFX_WideString& wsToday) {
900 wsToday.Format(L", %d/%d/%d", iDay, iMonth, iYear);
901 }
902 int32_t CFWL_MonthCalendarImp::GetDayAtPoint(FX_FLOAT x, FX_FLOAT y) {
903 int32_t iCount = m_arrDates.GetSize();
904 for (int32_t i = 0; i < iCount; i++) {
905 FWL_DATEINFO* pDateInfo = (FWL_DATEINFO*)m_arrDates.GetAt(i);
906 if (pDateInfo->rect.Contains(x, y)) {
907 return ++i;
908 }
909 }
910 return -1;
911 }
912 FX_BOOL CFWL_MonthCalendarImp::GetDayRect(int32_t iDay, CFX_RectF& rtDay) {
913 if (iDay <= 0 || iDay > m_arrDates.GetSize()) {
914 return FALSE;
915 }
916 FWL_DATEINFO* pDateInfo = (FWL_DATEINFO*)m_arrDates[iDay - 1];
917 if (!pDateInfo)
918 return FALSE;
919 rtDay = pDateInfo->rect;
920 return TRUE;
921 }
922 CFWL_MonthCalendarImpDelegate::CFWL_MonthCalendarImpDelegate(
923 CFWL_MonthCalendarImp* pOwner)
924 : m_pOwner(pOwner) {}
925 int32_t CFWL_MonthCalendarImpDelegate::OnProcessMessage(
926 CFWL_Message* pMessage) {
927 if (!pMessage)
928 return 0;
929 FX_DWORD dwMsgCode = pMessage->GetClassID();
930 int32_t iRet = 1;
931 switch (dwMsgCode) {
932 case FWL_MSGHASH_SetFocus:
933 case FWL_MSGHASH_KillFocus: {
934 OnFocusChanged(pMessage, dwMsgCode == FWL_MSGHASH_SetFocus);
935 break;
936 }
937 case FWL_MSGHASH_Key: {
938 break;
939 }
940 case FWL_MSGHASH_Mouse: {
941 CFWL_MsgMouse* pMouse = static_cast<CFWL_MsgMouse*>(pMessage);
942 FX_DWORD dwCmd = pMouse->m_dwCmd;
943 switch (dwCmd) {
944 case FWL_MSGMOUSECMD_LButtonDown: {
945 OnLButtonDown(pMouse);
946 break;
947 }
948 case FWL_MSGMOUSECMD_LButtonUp: {
949 OnLButtonUp(pMouse);
950 break;
951 }
952 case FWL_MSGMOUSECMD_MouseMove: {
953 OnMouseMove(pMouse);
954 break;
955 }
956 case FWL_MSGMOUSECMD_MouseLeave: {
957 OnMouseLeave(pMouse);
958 break;
959 }
960 default: { break; }
961 }
962 break;
963 }
964 default: {
965 iRet = 0;
966 break;
967 }
968 }
969 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage);
970 return iRet;
971 }
972 FWL_ERR CFWL_MonthCalendarImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics,
973 const CFX_Matrix* pMatrix) {
974 return m_pOwner->DrawWidget(pGraphics, pMatrix);
975 }
976
977 void CFWL_MonthCalendarImpDelegate::OnActivate(CFWL_Message* pMsg) {}
978
979 void CFWL_MonthCalendarImpDelegate::OnFocusChanged(CFWL_Message* pMsg,
980 FX_BOOL bSet) {
981 if (bSet) {
982 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
983 } else {
984 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
985 }
986 m_pOwner->Repaint(&m_pOwner->m_rtClient);
987 }
988 void CFWL_MonthCalendarImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) {
989 if (m_pOwner->m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) {
990 m_pOwner->m_iLBtnPartStates = FWL_PARTSTATE_MCD_Pressed;
991 m_pOwner->PrevMonth();
992 m_pOwner->Repaint(&m_pOwner->m_rtClient);
993 } else if (m_pOwner->m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) {
994 m_pOwner->m_iRBtnPartStates |= FWL_PARTSTATE_MCD_Pressed;
995 m_pOwner->NextMonth();
996 m_pOwner->Repaint(&m_pOwner->m_rtClient);
997 } else if (m_pOwner->m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) {
998 if ((m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) ==
999 0) {
1000 m_pOwner->JumpToToday();
1001 m_pOwner->Repaint(&m_pOwner->m_rtClient);
1002 }
1003 } else {
1004 if (m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) {
1005 } else {
1006 int32_t iOldSel = 0;
1007 if (m_pOwner->m_arrSelDays.GetSize() > 0) {
1008 iOldSel = m_pOwner->m_arrSelDays[0];
1009 } else {
1010 return;
1011 }
1012 int32_t iCurSel = m_pOwner->GetDayAtPoint(pMsg->m_fx, pMsg->m_fy);
1013 FX_BOOL bSelChanged = iCurSel > 0 && iCurSel != iOldSel;
1014 if (bSelChanged) {
1015 FWL_DATEINFO* lpDatesInfo =
1016 (FWL_DATEINFO*)m_pOwner->m_arrDates.GetAt(iCurSel - 1);
1017 CFX_RectF rtInvalidate(lpDatesInfo->rect);
1018 if (iOldSel > 0) {
1019 lpDatesInfo = (FWL_DATEINFO*)m_pOwner->m_arrDates.GetAt(iOldSel - 1);
1020 rtInvalidate.Union(lpDatesInfo->rect);
1021 }
1022 m_pOwner->AddSelDay(iCurSel);
1023 CFWL_EvtClick wmClick;
1024 wmClick.m_pSrcTarget = m_pOwner->m_pInterface;
1025 m_pOwner->DispatchEvent(&wmClick);
1026 CFWL_EventMcdDateChanged wmDateSelected;
1027 wmDateSelected.m_iStartDay = iCurSel;
1028 wmDateSelected.m_iEndDay = iCurSel;
1029 wmDateSelected.m_iOldMonth = m_pOwner->m_iCurMonth;
1030 wmDateSelected.m_iOldYear = m_pOwner->m_iCurYear;
1031 wmDateSelected.m_pSrcTarget = m_pOwner->m_pInterface;
1032 m_pOwner->DispatchEvent(&wmDateSelected);
1033 m_pOwner->Repaint(&rtInvalidate);
1034 }
1035 }
1036 }
1037 }
1038 void CFWL_MonthCalendarImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) {
1039 if (m_pOwner->m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) {
1040 m_pOwner->m_iLBtnPartStates = 0;
1041 m_pOwner->Repaint(&m_pOwner->m_rtLBtn);
1042 } else if (m_pOwner->m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) {
1043 m_pOwner->m_iRBtnPartStates = 0;
1044 m_pOwner->Repaint(&m_pOwner->m_rtRBtn);
1045 } else if (m_pOwner->m_rtDates.Contains(pMsg->m_fx, pMsg->m_fy)) {
1046 int32_t iDay = m_pOwner->GetDayAtPoint(pMsg->m_fx, pMsg->m_fy);
1047 if (iDay != -1) {
1048 m_pOwner->AddSelDay(iDay);
1049 }
1050 }
1051 }
1052 void CFWL_MonthCalendarImpDelegate::OnMouseMove(CFWL_MsgMouse* pMsg) {
1053 if (m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) {
1054 return;
1055 }
1056 FX_BOOL bRepaint = FALSE;
1057 CFX_RectF rtInvalidate;
1058 rtInvalidate.Set(0, 0, 0, 0);
1059 if (m_pOwner->m_rtDates.Contains(pMsg->m_fx, pMsg->m_fy)) {
1060 int32_t iHover = m_pOwner->GetDayAtPoint(pMsg->m_fx, pMsg->m_fy);
1061 bRepaint = m_pOwner->m_iHovered != iHover;
1062 if (bRepaint) {
1063 if (m_pOwner->m_iHovered > 0) {
1064 m_pOwner->GetDayRect(m_pOwner->m_iHovered, rtInvalidate);
1065 }
1066 if (iHover > 0) {
1067 CFX_RectF rtDay;
1068 m_pOwner->GetDayRect(iHover, rtDay);
1069 if (rtInvalidate.IsEmpty()) {
1070 rtInvalidate = rtDay;
1071 } else {
1072 rtInvalidate.Union(rtDay);
1073 }
1074 }
1075 }
1076 m_pOwner->m_iHovered = iHover;
1077 } else {
1078 bRepaint = m_pOwner->m_iHovered > 0;
1079 if (bRepaint) {
1080 m_pOwner->GetDayRect(m_pOwner->m_iHovered, rtInvalidate);
1081 }
1082 m_pOwner->m_iHovered = -1;
1083 }
1084 if (bRepaint && !rtInvalidate.IsEmpty()) {
1085 m_pOwner->Repaint(&rtInvalidate);
1086 }
1087 }
1088 void CFWL_MonthCalendarImpDelegate::OnMouseLeave(CFWL_MsgMouse* pMsg) {
1089 if (m_pOwner->m_iHovered > 0) {
1090 CFX_RectF rtInvalidate;
1091 rtInvalidate.Set(0, 0, 0, 0);
1092 m_pOwner->GetDayRect(m_pOwner->m_iHovered, rtInvalidate);
1093 m_pOwner->m_iHovered = -1;
1094 if (!rtInvalidate.IsEmpty()) {
1095 m_pOwner->Repaint(&rtInvalidate);
1096 }
1097 }
1098 }
OLDNEW
« no previous file with comments | « xfa/src/fwl/basewidget/fwl_monthcalendarimp.h ('k') | xfa/src/fwl/basewidget/fwl_pictureboximp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698