• 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/cfde_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/cxfa_gecolor.h"
16 #include "xfa/fxgraphics/cxfa_gepath.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   CXFA_GEPath 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   pParams->m_pGraphics->SetFillColor(CXFA_GEColor(m_pThemeData->clrBK));
112   pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
113   pParams->m_pGraphics->RestoreGraphState();
114 }
115 
DrawHeadBk(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)116 void CFWL_MonthCalendarTP::DrawHeadBk(CFWL_ThemeBackground* pParams,
117                                       CFX_Matrix* pMatrix) {
118   CXFA_GEPath path;
119   CFX_RectF rtHead = pParams->m_rtPart;
120   path.AddRectangle(rtHead.left, rtHead.top, rtHead.width, rtHead.height);
121   pParams->m_pGraphics->SaveGraphState();
122   pParams->m_pGraphics->SetFillColor(CXFA_GEColor(m_pThemeData->clrBK));
123   pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
124   pParams->m_pGraphics->RestoreGraphState();
125 }
126 
DrawLButton(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)127 void CFWL_MonthCalendarTP::DrawLButton(CFWL_ThemeBackground* pParams,
128                                        CFX_Matrix* pMatrix) {
129   CXFA_GEPath path;
130   CFX_RectF rtLBtn = pParams->m_rtPart;
131   path.AddRectangle(rtLBtn.left, rtLBtn.top, rtLBtn.width, rtLBtn.height);
132   pParams->m_pGraphics->SaveGraphState();
133   pParams->m_pGraphics->SetStrokeColor(
134       CXFA_GEColor(ArgbEncode(0xff, 205, 219, 243)));
135   pParams->m_pGraphics->StrokePath(&path, pMatrix);
136   if (pParams->m_dwStates & CFWL_PartState_Pressed) {
137     pParams->m_pGraphics->SetFillColor(
138         CXFA_GEColor(ArgbEncode(0xff, 174, 198, 242)));
139     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
140   } else {
141     pParams->m_pGraphics->SetFillColor(
142         CXFA_GEColor(ArgbEncode(0xff, 227, 235, 249)));
143     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
144   }
145 
146   path.Clear();
147   path.MoveTo(CFX_PointF(rtLBtn.left + rtLBtn.Width() / 3 * 2,
148                          rtLBtn.top + rtLBtn.height / 4));
149   path.LineTo(CFX_PointF(rtLBtn.left + rtLBtn.Width() / 3,
150                          rtLBtn.top + rtLBtn.height / 2));
151   path.LineTo(CFX_PointF(rtLBtn.left + rtLBtn.Width() / 3 * 2,
152                          rtLBtn.bottom() - rtLBtn.height / 4));
153 
154   pParams->m_pGraphics->SetStrokeColor(
155       CXFA_GEColor(ArgbEncode(0xff, 50, 104, 205)));
156   pParams->m_pGraphics->StrokePath(&path, pMatrix);
157   pParams->m_pGraphics->RestoreGraphState();
158 }
159 
DrawRButton(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)160 void CFWL_MonthCalendarTP::DrawRButton(CFWL_ThemeBackground* pParams,
161                                        CFX_Matrix* pMatrix) {
162   CXFA_GEPath path;
163   CFX_RectF rtRBtn = pParams->m_rtPart;
164   path.AddRectangle(rtRBtn.left, rtRBtn.top, rtRBtn.width, rtRBtn.height);
165   pParams->m_pGraphics->SaveGraphState();
166   pParams->m_pGraphics->SetStrokeColor(
167       CXFA_GEColor(ArgbEncode(0xff, 205, 219, 243)));
168   pParams->m_pGraphics->StrokePath(&path, pMatrix);
169   if (pParams->m_dwStates & CFWL_PartState_Pressed) {
170     pParams->m_pGraphics->SetFillColor(
171         CXFA_GEColor(ArgbEncode(0xff, 174, 198, 242)));
172     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
173   } else {
174     pParams->m_pGraphics->SetFillColor(
175         CXFA_GEColor(ArgbEncode(0xff, 227, 235, 249)));
176     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
177   }
178 
179   path.Clear();
180   path.MoveTo(CFX_PointF(rtRBtn.left + rtRBtn.Width() / 3,
181                          rtRBtn.top + rtRBtn.height / 4));
182   path.LineTo(CFX_PointF(rtRBtn.left + rtRBtn.Width() / 3 * 2,
183                          rtRBtn.top + rtRBtn.height / 2));
184   path.LineTo(CFX_PointF(rtRBtn.left + rtRBtn.Width() / 3,
185                          rtRBtn.bottom() - rtRBtn.height / 4));
186 
187   pParams->m_pGraphics->SetStrokeColor(
188       CXFA_GEColor(ArgbEncode(0xff, 50, 104, 205)));
189   pParams->m_pGraphics->StrokePath(&path, pMatrix);
190   pParams->m_pGraphics->RestoreGraphState();
191 }
192 
DrawHSeperator(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)193 void CFWL_MonthCalendarTP::DrawHSeperator(CFWL_ThemeBackground* pParams,
194                                           CFX_Matrix* pMatrix) {
195   CXFA_GEPath path;
196   CFX_RectF rtHSep = pParams->m_rtPart;
197   path.MoveTo(CFX_PointF(rtHSep.left, rtHSep.top + rtHSep.height / 2));
198   path.LineTo(CFX_PointF(rtHSep.right(), rtHSep.top + rtHSep.height / 2));
199   pParams->m_pGraphics->SaveGraphState();
200   pParams->m_pGraphics->SetStrokeColor(
201       CXFA_GEColor(m_pThemeData->clrSeperator));
202   pParams->m_pGraphics->StrokePath(&path, pMatrix);
203   pParams->m_pGraphics->RestoreGraphState();
204 }
205 
DrawWeekNumSep(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)206 void CFWL_MonthCalendarTP::DrawWeekNumSep(CFWL_ThemeBackground* pParams,
207                                           CFX_Matrix* pMatrix) {
208   CXFA_GEPath path;
209   CFX_RectF rtWeekSep = pParams->m_rtPart;
210   path.MoveTo(rtWeekSep.TopLeft());
211   path.LineTo(rtWeekSep.BottomLeft());
212   pParams->m_pGraphics->SaveGraphState();
213   pParams->m_pGraphics->SetStrokeColor(
214       CXFA_GEColor(m_pThemeData->clrSeperator));
215   pParams->m_pGraphics->StrokePath(&path, pMatrix);
216   pParams->m_pGraphics->RestoreGraphState();
217 }
218 
DrawDatesInBK(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)219 void CFWL_MonthCalendarTP::DrawDatesInBK(CFWL_ThemeBackground* pParams,
220                                          CFX_Matrix* pMatrix) {
221   pParams->m_pGraphics->SaveGraphState();
222   if (pParams->m_dwStates & CFWL_PartState_Selected) {
223     CXFA_GEPath path;
224     CFX_RectF rtSelDay = pParams->m_rtPart;
225     path.AddRectangle(rtSelDay.left, rtSelDay.top, rtSelDay.width,
226                       rtSelDay.height);
227     pParams->m_pGraphics->SetFillColor(
228         CXFA_GEColor(m_pThemeData->clrDatesSelectedBK));
229     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
230   } else if (pParams->m_dwStates & CFWL_PartState_Hovered) {
231     CXFA_GEPath path;
232     CFX_RectF rtSelDay = pParams->m_rtPart;
233     path.AddRectangle(rtSelDay.left, rtSelDay.top, rtSelDay.width,
234                       rtSelDay.height);
235     pParams->m_pGraphics->SetFillColor(
236         CXFA_GEColor(m_pThemeData->clrDatesHoverBK));
237     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
238   }
239   pParams->m_pGraphics->RestoreGraphState();
240 }
241 
DrawDatesInCircle(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)242 void CFWL_MonthCalendarTP::DrawDatesInCircle(CFWL_ThemeBackground* pParams,
243                                              CFX_Matrix* pMatrix) {
244   CXFA_GEPath path;
245   CFX_RectF rtSelDay = pParams->m_rtPart;
246   path.AddRectangle(rtSelDay.left, rtSelDay.top, rtSelDay.width,
247                     rtSelDay.height);
248   pParams->m_pGraphics->SaveGraphState();
249   pParams->m_pGraphics->SetStrokeColor(
250       CXFA_GEColor(m_pThemeData->clrDatesCircle));
251   pParams->m_pGraphics->StrokePath(&path, pMatrix);
252   pParams->m_pGraphics->RestoreGraphState();
253 }
254 
DrawTodayCircle(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)255 void CFWL_MonthCalendarTP::DrawTodayCircle(CFWL_ThemeBackground* pParams,
256                                            CFX_Matrix* pMatrix) {
257   CXFA_GEPath path;
258   CFX_RectF rtTodayCircle = pParams->m_rtPart;
259   path.AddRectangle(rtTodayCircle.left, rtTodayCircle.top, rtTodayCircle.width,
260                     rtTodayCircle.height);
261   pParams->m_pGraphics->SaveGraphState();
262   pParams->m_pGraphics->SetStrokeColor(
263       CXFA_GEColor(m_pThemeData->clrDatesCircle));
264   pParams->m_pGraphics->StrokePath(&path, pMatrix);
265   pParams->m_pGraphics->RestoreGraphState();
266 }
267 
GetState(uint32_t dwFWLStates)268 FWLTHEME_STATE CFWL_MonthCalendarTP::GetState(uint32_t dwFWLStates) {
269   if (dwFWLStates & CFWL_PartState_Hovered)
270     return FWLTHEME_STATE_Hover;
271   if (dwFWLStates & CFWL_PartState_Pressed)
272     return FWLTHEME_STATE_Pressed;
273   return FWLTHEME_STATE_Normal;
274 }
275 
SetThemeData()276 void CFWL_MonthCalendarTP::SetThemeData() {
277   m_pThemeData->clrCaption = ArgbEncode(0xff, 0, 153, 255);
278   m_pThemeData->clrSeperator = ArgbEncode(0xff, 141, 161, 239);
279   m_pThemeData->clrDatesHoverBK = ArgbEncode(0xff, 193, 211, 251);
280   m_pThemeData->clrDatesSelectedBK = ArgbEncode(0xff, 173, 188, 239);
281   m_pThemeData->clrDatesCircle = ArgbEncode(0xff, 103, 144, 209);
282   m_pThemeData->clrToday = ArgbEncode(0xff, 0, 0, 0);
283   m_pThemeData->clrBK = ArgbEncode(0xff, 255, 255, 255);
284 }
285