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