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/foxitlib.h"
CFWL_DateTimePickerTP()8 CFWL_DateTimePickerTP::CFWL_DateTimePickerTP() {
9 m_pThemeData = new DTPThemeData;
10 initThemeData();
11 }
~CFWL_DateTimePickerTP()12 CFWL_DateTimePickerTP::~CFWL_DateTimePickerTP() {
13 delete m_pThemeData;
14 }
IsValidWidget(IFWL_Widget * pWidget)15 FX_BOOL CFWL_DateTimePickerTP::IsValidWidget(IFWL_Widget* pWidget) {
16 if (!pWidget)
17 return FALSE;
18 return pWidget->GetClassID() == FWL_CLASSHASH_DateTimePicker;
19 }
DrawBackground(CFWL_ThemeBackground * pParams)20 FX_BOOL CFWL_DateTimePickerTP::DrawBackground(CFWL_ThemeBackground* pParams) {
21 if (!pParams)
22 return FALSE;
23 switch (pParams->m_iPart) {
24 case FWL_PART_DTP_Border: {
25 DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix);
26 break;
27 }
28 case FWL_PART_DTP_Edge: {
29 DrawEdge(pParams->m_pGraphics, pParams->m_pWidget->GetStyles(),
30 &pParams->m_rtPart, &pParams->m_matrix);
31 break;
32 }
33 case FWL_PART_DTP_DropDownButton: {
34 DrawDropDownButton(pParams, &pParams->m_matrix);
35 break;
36 }
37 default: {}
38 }
39 return TRUE;
40 }
41 #ifdef THEME_XPSimilar
DrawDropDownButton(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)42 void CFWL_DateTimePickerTP::DrawDropDownButton(CFWL_ThemeBackground* pParams,
43 CFX_Matrix* pMatrix) {
44 FX_DWORD dwStates = pParams->m_dwStates;
45 dwStates &= 0x03;
46 FWLTHEME_STATE eState = FWLTHEME_STATE_Normal;
47 switch (eState & dwStates) {
48 case FWL_PARTSTATE_DTP_Normal: {
49 eState = FWLTHEME_STATE_Normal;
50 break;
51 }
52 case FWL_PARTSTATE_DTP_Hovered: {
53 eState = FWLTHEME_STATE_Hover;
54 break;
55 }
56 case FWL_PARTSTATE_DTP_Pressed: {
57 eState = FWLTHEME_STATE_Pressed;
58 break;
59 }
60 case FWL_PARTSTATE_DTP_Disabled: {
61 eState = FWLTHEME_STATE_Disabale;
62 break;
63 }
64 default: {}
65 }
66 DrawArrowBtn(pParams->m_pGraphics, &pParams->m_rtPart,
67 FWLTHEME_DIRECTION_Down, eState, pMatrix);
68 }
69 #else
DrawDropDownButton(CFWL_ThemeBackground * pParams,CFX_Matrix * pMatrix)70 void CFWL_DateTimePickerTP::DrawDropDownButton(CFWL_ThemeBackground* pParams,
71 CFX_Matrix* pMatrix) {
72 FX_BOOL bPressed = ((pParams->m_dwStates & FWL_PARTSTATE_DTP_Pressed) ==
73 FWL_PARTSTATE_DTP_Pressed);
74 FX_FLOAT fWidth = bPressed ? 1.0f : 2.0f;
75 FWLTHEME_EDGE eType = bPressed ? FWLTHEME_EDGE_Flat : FWLTHEME_EDGE_Raised;
76 Draw3DRect(pParams->m_pGraphics, eType, fWidth, &pParams->m_rtPart,
77 FWLTHEME_COLOR_EDGELT1, FWLTHEME_COLOR_EDGELT2,
78 FWLTHEME_COLOR_EDGERB1, FWLTHEME_COLOR_EDGERB2, pMatrix);
79 CFX_Path path;
80 path.Create();
81 path.AddRectangle(pParams->m_rtPart.left + fWidth,
82 pParams->m_rtPart.top + fWidth,
83 pParams->m_rtPart.width - 2 * fWidth,
84 pParams->m_rtPart.height - 2 * fWidth);
85 pParams->m_pGraphics->SaveGraphState();
86 CFX_Color crFill(FWLTHEME_COLOR_Background);
87 pParams->m_pGraphics->SetFillColor(&crFill);
88 pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
89 pParams->m_pGraphics->RestoreGraphState();
90 FX_ARGB argbFill = ArgbEncode(255, 77, 97, 133);
91 switch (pParams->m_dwStates & 0x03) {
92 case FWL_PARTSTATE_DTP_Normal: {
93 }
94 case FWL_PARTSTATE_DTP_Hovered: {
95 }
96 case FWL_PARTSTATE_DTP_Pressed: {
97 argbFill = 0xFF000000;
98 break;
99 }
100 case FWL_PARTSTATE_DTP_Disabled: {
101 argbFill = 0xFFF0F0F0;
102 break;
103 }
104 }
105 DrawArrow(pParams->m_pGraphics, &pParams->m_rtPart, FWLTHEME_DIRECTION_Down,
106 argbFill, bPressed, pMatrix);
107 }
108 #endif
initThemeData()109 void CFWL_DateTimePickerTP::initThemeData() {
110 FX_DWORD* pData = (FX_DWORD*)&m_pThemeData->BoxBkColor;
111 *pData++ = 0, *pData++ = 0, *pData++ = ArgbEncode(255, 220, 220, 215),
112 *pData++ = ArgbEncode(255, 255, 255, 255),
113 *pData++ = ArgbEncode(255, 255, 240, 207),
114 *pData++ = ArgbEncode(255, 248, 179, 48),
115 *pData++ = ArgbEncode(255, 176, 176, 167),
116 *pData++ = ArgbEncode(255, 241, 239, 239),
117 *pData++ = ArgbEncode(255, 255, 255, 255),
118 *pData++ = ArgbEncode(255, 255, 255, 255),
119 *pData++ = ArgbEncode(255, 220, 220, 215),
120 *pData++ = ArgbEncode(255, 255, 255, 255),
121 *pData++ = ArgbEncode(255, 255, 240, 207),
122 *pData++ = ArgbEncode(255, 248, 179, 48),
123 *pData++ = ArgbEncode(255, 176, 176, 167),
124 *pData++ = ArgbEncode(255, 241, 239, 239),
125 *pData++ = ArgbEncode(255, 255, 255, 255),
126 *pData++ = ArgbEncode(255, 255, 255, 255),
127 *pData++ = ArgbEncode(255, 220, 220, 215),
128 *pData++ = ArgbEncode(255, 255, 255, 255),
129 *pData++ = ArgbEncode(255, 255, 240, 207),
130 *pData++ = ArgbEncode(255, 248, 179, 48),
131 *pData++ = ArgbEncode(255, 176, 176, 167),
132 *pData++ = ArgbEncode(255, 241, 239, 239),
133 *pData++ = ArgbEncode(255, 255, 255, 255),
134 *pData++ = ArgbEncode(255, 255, 255, 255);
135 }
136