• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/theme/cfwl_monthcalendartp.h"
8 
9 #include "xfa/fde/tto/fde_textout.h"
10 #include "xfa/fwl/cfwl_monthcalendar.h"
11 #include "xfa/fwl/cfwl_themebackground.h"
12 #include "xfa/fwl/cfwl_themetext.h"
13 #include "xfa/fwl/cfwl_widget.h"
14 #include "xfa/fwl/ifwl_themeprovider.h"
15 #include "xfa/fxgraphics/cfx_color.h"
16 #include "xfa/fxgraphics/cfx_path.h"
17 
CFWL_MonthCalendarTP()18 CFWL_MonthCalendarTP::CFWL_MonthCalendarTP() : m_pThemeData(new MCThemeData) {
19   SetThemeData();
20 }
21 
~CFWL_MonthCalendarTP()22 CFWL_MonthCalendarTP::~CFWL_MonthCalendarTP() {}
23 
Initialize()24 void CFWL_MonthCalendarTP::Initialize() {
25   CFWL_WidgetTP::Initialize();
26   InitTTO();
27 }
28 
Finalize()29 void CFWL_MonthCalendarTP::Finalize() {
30   FinalizeTTO();
31   CFWL_WidgetTP::Finalize();
32 }
33 
DrawBackground(CFWL_ThemeBackground * pParams)34 void CFWL_MonthCalendarTP::DrawBackground(CFWL_ThemeBackground* pParams) {
35   if (!pParams)
36     return;
37 
38   switch (pParams->m_iPart) {
39     case CFWL_Part::Border: {
40       DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix);
41       break;
42     }
43     case CFWL_Part::Background: {
44       DrawTotalBK(pParams, &pParams->m_matrix);
45       break;
46     }
47     case CFWL_Part::Header: {
48       DrawHeadBk(pParams, &pParams->m_matrix);
49       break;
50     }
51     case CFWL_Part::LBtn: {
52       FWLTHEME_STATE eState = GetState(pParams->m_dwStates);
53       DrawArrowBtn(pParams->m_pGraphics, &pParams->m_rtPart,
54                    FWLTHEME_DIRECTION_Left, eState, &pParams->m_matrix);
55       break;
56     }
57     case CFWL_Part::RBtn: {
58       FWLTHEME_STATE eState = GetState(pParams->m_dwStates);
59       DrawArrowBtn(pParams->m_pGraphics, &pParams->m_rtPart,
60                    FWLTHEME_DIRECTION_Right, eState, &pParams->m_matrix);
61       break;
62     }
63     case CFWL_Part::HSeparator: {
64       DrawHSeperator(pParams, &pParams->m_matrix);
65       break;
66     }
67     case CFWL_Part::DatesIn: {
68       DrawDatesInBK(pParams, &pParams->m_matrix);
69       break;
70     }
71     case CFWL_Part::TodayCircle: {
72       DrawTodayCircle(pParams, &pParams->m_matrix);
73       break;
74     }
75     case CFWL_Part::DateInCircle: {
76       DrawDatesInCircle(pParams, &pParams->m_matrix);
77       break;
78     }
79     case CFWL_Part::WeekNumSep: {
80       DrawWeekNumSep(pParams, &pParams->m_matrix);
81       break;
82     }
83     default:
84       break;
85   }
86 }
87 
DrawText(CFWL_ThemeText * pParams)88 void CFWL_MonthCalendarTP::DrawText(CFWL_ThemeText* pParams) {
89   if (!m_pTextOut)
90     return;
91 
92   if ((pParams->m_iPart == CFWL_Part::DatesIn) &&
93       !(pParams->m_dwStates & FWL_ITEMSTATE_MCD_Flag) &&
94       (pParams->m_dwStates &
95        (CFWL_PartState_Hovered | CFWL_PartState_Selected))) {
96     m_pTextOut->SetTextColor(0xFFFFFFFF);
97   } else if (pParams->m_iPart == CFWL_Part::Caption) {
98     m_pTextOut->SetTextColor(m_pThemeData->clrCaption);
99   } else {
100     m_pTextOut->SetTextColor(0xFF000000);
101   }
102   CFWL_WidgetTP::DrawText(pParams);
103 }
104 
DrawTotalBK(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)105 void CFWL_MonthCalendarTP::DrawTotalBK(CFWL_ThemeBackground* pParams,
106                                        CFX_Matrix* pMatrix) {
107   CFX_Path path;
108   CFX_RectF rtTotal(pParams->m_rtPart);
109   path.AddRectangle(rtTotal.left, rtTotal.top, rtTotal.width, rtTotal.height);
110   pParams->m_pGraphics->SaveGraphState();
111 
112   CFX_Color clrBK(m_pThemeData->clrBK);
113   pParams->m_pGraphics->SetFillColor(&clrBK);
114   pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
115   pParams->m_pGraphics->RestoreGraphState();
116 }
117 
DrawHeadBk(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)118 void CFWL_MonthCalendarTP::DrawHeadBk(CFWL_ThemeBackground* pParams,
119                                       CFX_Matrix* pMatrix) {
120   CFX_Path path;
121   CFX_RectF rtHead = pParams->m_rtPart;
122   path.AddRectangle(rtHead.left, rtHead.top, rtHead.width, rtHead.height);
123   pParams->m_pGraphics->SaveGraphState();
124 
125   CFX_Color clrHeadBK(m_pThemeData->clrBK);
126   pParams->m_pGraphics->SetFillColor(&clrHeadBK);
127   pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
128   pParams->m_pGraphics->RestoreGraphState();
129 }
130 
DrawLButton(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)131 void CFWL_MonthCalendarTP::DrawLButton(CFWL_ThemeBackground* pParams,
132                                        CFX_Matrix* pMatrix) {
133   CFX_Path path;
134   CFX_RectF rtLBtn = pParams->m_rtPart;
135   path.AddRectangle(rtLBtn.left, rtLBtn.top, rtLBtn.width, rtLBtn.height);
136   pParams->m_pGraphics->SaveGraphState();
137 
138   CFX_Color clrLBtnEdge(ArgbEncode(0xff, 205, 219, 243));
139   pParams->m_pGraphics->SetStrokeColor(&clrLBtnEdge);
140   pParams->m_pGraphics->StrokePath(&path, pMatrix);
141   if (pParams->m_dwStates & CFWL_PartState_Pressed) {
142     CFX_Color clrLBtnFill(ArgbEncode(0xff, 174, 198, 242));
143     pParams->m_pGraphics->SetFillColor(&clrLBtnFill);
144     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
145   } else {
146     CFX_Color clrLBtnFill(ArgbEncode(0xff, 227, 235, 249));
147     pParams->m_pGraphics->SetFillColor(&clrLBtnFill);
148     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
149   }
150 
151   path.Clear();
152   path.MoveTo(CFX_PointF(rtLBtn.left + rtLBtn.Width() / 3 * 2,
153                          rtLBtn.top + rtLBtn.height / 4));
154   path.LineTo(CFX_PointF(rtLBtn.left + rtLBtn.Width() / 3,
155                          rtLBtn.top + rtLBtn.height / 2));
156   path.LineTo(CFX_PointF(rtLBtn.left + rtLBtn.Width() / 3 * 2,
157                          rtLBtn.bottom() - rtLBtn.height / 4));
158 
159   CFX_Color clrFlag(ArgbEncode(0xff, 50, 104, 205));
160   pParams->m_pGraphics->SetStrokeColor(&clrFlag);
161   pParams->m_pGraphics->StrokePath(&path, pMatrix);
162   pParams->m_pGraphics->RestoreGraphState();
163 }
164 
DrawRButton(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)165 void CFWL_MonthCalendarTP::DrawRButton(CFWL_ThemeBackground* pParams,
166                                        CFX_Matrix* pMatrix) {
167   CFX_Path path;
168   CFX_RectF rtRBtn = pParams->m_rtPart;
169   path.AddRectangle(rtRBtn.left, rtRBtn.top, rtRBtn.width, rtRBtn.height);
170   pParams->m_pGraphics->SaveGraphState();
171 
172   CFX_Color clrRBtnEdge(ArgbEncode(0xff, 205, 219, 243));
173   pParams->m_pGraphics->SetStrokeColor(&clrRBtnEdge);
174   pParams->m_pGraphics->StrokePath(&path, pMatrix);
175   if (pParams->m_dwStates & CFWL_PartState_Pressed) {
176     CFX_Color clrRBtnFill(ArgbEncode(0xff, 174, 198, 242));
177     pParams->m_pGraphics->SetFillColor(&clrRBtnFill);
178     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
179   } else {
180     CFX_Color clrRBtnFill(ArgbEncode(0xff, 227, 235, 249));
181     pParams->m_pGraphics->SetFillColor(&clrRBtnFill);
182     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
183   }
184 
185   path.Clear();
186   path.MoveTo(CFX_PointF(rtRBtn.left + rtRBtn.Width() / 3,
187                          rtRBtn.top + rtRBtn.height / 4));
188   path.LineTo(CFX_PointF(rtRBtn.left + rtRBtn.Width() / 3 * 2,
189                          rtRBtn.top + rtRBtn.height / 2));
190   path.LineTo(CFX_PointF(rtRBtn.left + rtRBtn.Width() / 3,
191                          rtRBtn.bottom() - rtRBtn.height / 4));
192 
193   CFX_Color clrFlag(ArgbEncode(0xff, 50, 104, 205));
194   pParams->m_pGraphics->SetStrokeColor(&clrFlag);
195   pParams->m_pGraphics->StrokePath(&path, pMatrix);
196   pParams->m_pGraphics->RestoreGraphState();
197 }
198 
DrawHSeperator(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)199 void CFWL_MonthCalendarTP::DrawHSeperator(CFWL_ThemeBackground* pParams,
200                                           CFX_Matrix* pMatrix) {
201   CFX_Path path;
202   CFX_RectF rtHSep = pParams->m_rtPart;
203   path.MoveTo(CFX_PointF(rtHSep.left, rtHSep.top + rtHSep.height / 2));
204   path.LineTo(CFX_PointF(rtHSep.right(), rtHSep.top + rtHSep.height / 2));
205   pParams->m_pGraphics->SaveGraphState();
206 
207   CFX_Color clrHSep(m_pThemeData->clrSeperator);
208   pParams->m_pGraphics->SetStrokeColor(&clrHSep);
209   pParams->m_pGraphics->StrokePath(&path, pMatrix);
210   pParams->m_pGraphics->RestoreGraphState();
211 }
212 
DrawWeekNumSep(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)213 void CFWL_MonthCalendarTP::DrawWeekNumSep(CFWL_ThemeBackground* pParams,
214                                           CFX_Matrix* pMatrix) {
215   CFX_Path path;
216   CFX_RectF rtWeekSep = pParams->m_rtPart;
217   path.MoveTo(rtWeekSep.TopLeft());
218   path.LineTo(rtWeekSep.BottomLeft());
219   pParams->m_pGraphics->SaveGraphState();
220 
221   CFX_Color clrHSep(m_pThemeData->clrSeperator);
222   pParams->m_pGraphics->SetStrokeColor(&clrHSep);
223   pParams->m_pGraphics->StrokePath(&path, pMatrix);
224   pParams->m_pGraphics->RestoreGraphState();
225 }
226 
DrawDatesInBK(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)227 void CFWL_MonthCalendarTP::DrawDatesInBK(CFWL_ThemeBackground* pParams,
228                                          CFX_Matrix* pMatrix) {
229   pParams->m_pGraphics->SaveGraphState();
230   if (pParams->m_dwStates & CFWL_PartState_Selected) {
231     CFX_Path path;
232     CFX_RectF rtSelDay = pParams->m_rtPart;
233     path.AddRectangle(rtSelDay.left, rtSelDay.top, rtSelDay.width,
234                       rtSelDay.height);
235     CFX_Color clrSelDayBK(m_pThemeData->clrDatesSelectedBK);
236     pParams->m_pGraphics->SetFillColor(&clrSelDayBK);
237     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
238   } else if (pParams->m_dwStates & CFWL_PartState_Hovered) {
239     CFX_Path path;
240     CFX_RectF rtSelDay = pParams->m_rtPart;
241     path.AddRectangle(rtSelDay.left, rtSelDay.top, rtSelDay.width,
242                       rtSelDay.height);
243     CFX_Color clrSelDayBK(m_pThemeData->clrDatesHoverBK);
244     pParams->m_pGraphics->SetFillColor(&clrSelDayBK);
245     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
246   }
247   pParams->m_pGraphics->RestoreGraphState();
248 }
249 
DrawDatesInCircle(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)250 void CFWL_MonthCalendarTP::DrawDatesInCircle(CFWL_ThemeBackground* pParams,
251                                              CFX_Matrix* pMatrix) {
252   CFX_Path path;
253   CFX_RectF rtSelDay = pParams->m_rtPart;
254   path.AddRectangle(rtSelDay.left, rtSelDay.top, rtSelDay.width,
255                     rtSelDay.height);
256   pParams->m_pGraphics->SaveGraphState();
257   CFX_Color clrSelDayBK(m_pThemeData->clrDatesCircle);
258   pParams->m_pGraphics->SetStrokeColor(&clrSelDayBK);
259   pParams->m_pGraphics->StrokePath(&path, pMatrix);
260   pParams->m_pGraphics->RestoreGraphState();
261 }
262 
DrawTodayCircle(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)263 void CFWL_MonthCalendarTP::DrawTodayCircle(CFWL_ThemeBackground* pParams,
264                                            CFX_Matrix* pMatrix) {
265   CFX_Path path;
266   CFX_RectF rtTodayCircle = pParams->m_rtPart;
267   path.AddRectangle(rtTodayCircle.left, rtTodayCircle.top, rtTodayCircle.width,
268                     rtTodayCircle.height);
269   pParams->m_pGraphics->SaveGraphState();
270   CFX_Color clrTodayCircle(m_pThemeData->clrDatesCircle);
271   pParams->m_pGraphics->SetStrokeColor(&clrTodayCircle);
272   pParams->m_pGraphics->StrokePath(&path, pMatrix);
273   pParams->m_pGraphics->RestoreGraphState();
274 }
275 
GetState(uint32_t dwFWLStates)276 FWLTHEME_STATE CFWL_MonthCalendarTP::GetState(uint32_t dwFWLStates) {
277   if (dwFWLStates & CFWL_PartState_Hovered)
278     return FWLTHEME_STATE_Hover;
279   if (dwFWLStates & CFWL_PartState_Pressed)
280     return FWLTHEME_STATE_Pressed;
281   return FWLTHEME_STATE_Normal;
282 }
283 
SetThemeData()284 void CFWL_MonthCalendarTP::SetThemeData() {
285   m_pThemeData->clrCaption = ArgbEncode(0xff, 0, 153, 255);
286   m_pThemeData->clrSeperator = ArgbEncode(0xff, 141, 161, 239);
287   m_pThemeData->clrDatesHoverBK = ArgbEncode(0xff, 193, 211, 251);
288   m_pThemeData->clrDatesSelectedBK = ArgbEncode(0xff, 173, 188, 239);
289   m_pThemeData->clrDatesCircle = ArgbEncode(0xff, 103, 144, 209);
290   m_pThemeData->clrToday = ArgbEncode(0xff, 0, 0, 0);
291   m_pThemeData->clrBK = ArgbEncode(0xff, 255, 255, 255);
292 }
293