Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fwl / src / theme / datetimepickertp.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../../foxitlib.h"\r
8 CFWL_DateTimePickerTP::CFWL_DateTimePickerTP()\r
9 {\r
10     m_pThemeData = FX_NEW DTPThemeData;\r
11     initThemeData();\r
12 }\r
13 CFWL_DateTimePickerTP::~CFWL_DateTimePickerTP()\r
14 {\r
15     delete m_pThemeData;\r
16 }\r
17 FX_BOOL CFWL_DateTimePickerTP::IsValidWidget(IFWL_Widget *pWidget)\r
18 {\r
19     _FWL_RETURN_VALUE_IF_FAIL(pWidget, FALSE);\r
20     return pWidget->GetClassID() == FWL_CLASSHASH_DateTimePicker;\r
21 }\r
22 FX_BOOL CFWL_DateTimePickerTP::DrawBackground(CFWL_ThemeBackground *pParams)\r
23 {\r
24     _FWL_RETURN_VALUE_IF_FAIL(pParams, FALSE);\r
25     switch(pParams->m_iPart) {\r
26         case FWL_PART_DTP_Border: {\r
27                 DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix);\r
28                 break;\r
29             }\r
30         case FWL_PART_DTP_Edge: {\r
31                 DrawEdge(pParams->m_pGraphics, pParams->m_pWidget->GetStyles(), &pParams->m_rtPart, &pParams->m_matrix);\r
32                 break;\r
33             }\r
34         case FWL_PART_DTP_DropDownButton: {\r
35                 DrawDropDownButton(pParams, &pParams->m_matrix);\r
36                 break;\r
37             }\r
38         default: {\r
39             }\r
40     }\r
41     return TRUE;\r
42 }\r
43 #ifdef THEME_XPSimilar\r
44 void CFWL_DateTimePickerTP::DrawDropDownButton(CFWL_ThemeBackground *pParams, CFX_Matrix *pMatrix)\r
45 {\r
46     FX_DWORD dwStates = pParams->m_dwStates;\r
47     dwStates &= 0x03;\r
48     FWLTHEME_STATE eState = FWLTHEME_STATE_Normal;\r
49     switch (eState & dwStates) {\r
50         case FWL_PARTSTATE_DTP_Normal: {\r
51                 eState = FWLTHEME_STATE_Normal;\r
52                 break;\r
53             }\r
54         case FWL_PARTSTATE_DTP_Hovered: {\r
55                 eState = FWLTHEME_STATE_Hover;\r
56                 break;\r
57             }\r
58         case FWL_PARTSTATE_DTP_Pressed: {\r
59                 eState = FWLTHEME_STATE_Pressed;\r
60                 break;\r
61             }\r
62         case FWL_PARTSTATE_DTP_Disabled: {\r
63                 eState = FWLTHEME_STATE_Disabale;\r
64                 break;\r
65             }\r
66         default: {\r
67             }\r
68     }\r
69     DrawArrowBtn(pParams->m_pGraphics, &pParams->m_rtPart, FWLTHEME_DIRECTION_Down, eState, pMatrix);\r
70 }\r
71 #else\r
72 void CFWL_DateTimePickerTP::DrawDropDownButton(CFWL_ThemeBackground *pParams, CFX_Matrix *pMatrix)\r
73 {\r
74     FX_BOOL bPressed = ((pParams->m_dwStates & FWL_PARTSTATE_DTP_Pressed) == FWL_PARTSTATE_DTP_Pressed);\r
75     FX_FLOAT fWidth =  bPressed ? 1.0f : 2.0f;\r
76     FWLTHEME_EDGE eType = bPressed ? FWLTHEME_EDGE_Flat : FWLTHEME_EDGE_Raised;\r
77     Draw3DRect(pParams->m_pGraphics, eType, fWidth, &pParams->m_rtPart, FWLTHEME_COLOR_EDGELT1, FWLTHEME_COLOR_EDGELT2, FWLTHEME_COLOR_EDGERB1, FWLTHEME_COLOR_EDGERB2, pMatrix);\r
78     CFX_Path path;\r
79     path.Create();\r
80     path.AddRectangle(pParams->m_rtPart.left + fWidth, pParams->m_rtPart.top + fWidth, pParams->m_rtPart.width - 2 * fWidth, pParams->m_rtPart.height - 2 * fWidth);\r
81     pParams->m_pGraphics->SaveGraphState();\r
82     CFX_Color crFill(FWLTHEME_COLOR_Background);\r
83     pParams->m_pGraphics->SetFillColor(&crFill);\r
84     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);\r
85     pParams->m_pGraphics->RestoreGraphState();\r
86     FX_ARGB argbFill = ArgbEncode(255, 77, 97, 133);\r
87     switch(pParams->m_dwStates & 0x03) {\r
88         case FWL_PARTSTATE_DTP_Normal: {\r
89             }\r
90         case FWL_PARTSTATE_DTP_Hovered: {\r
91             }\r
92         case FWL_PARTSTATE_DTP_Pressed: {\r
93                 argbFill = 0xFF000000;\r
94                 break;\r
95             }\r
96         case FWL_PARTSTATE_DTP_Disabled: {\r
97                 argbFill = 0xFFF0F0F0;\r
98                 break;\r
99             }\r
100     }\r
101     DrawArrow(pParams->m_pGraphics, &pParams->m_rtPart, FWLTHEME_DIRECTION_Down, argbFill, bPressed, pMatrix);\r
102 }\r
103 #endif\r
104 void CFWL_DateTimePickerTP::initThemeData()\r
105 {\r
106     FX_DWORD *pData = (FX_DWORD*)&m_pThemeData->BoxBkColor;\r
107     *pData++ = 0, *pData++ = 0, \\r
108                              *pData++ = ArgbEncode(255, 220, 220, 215), *pData++ = ArgbEncode(255, 255, 255, 255), \\r
109                                         *pData++ = ArgbEncode(255, 255, 240, 207), *pData++ = ArgbEncode(255, 248, 179, 48), \\r
110                                                 *pData++ = ArgbEncode(255, 176, 176, 167), *pData++ = ArgbEncode(255, 241, 239, 239), \\r
111                                                         *pData++ = ArgbEncode(255, 255, 255, 255), *pData++ = ArgbEncode(255, 255, 255, 255), \\r
112                                                                 *pData++ = ArgbEncode(255, 220, 220, 215), *pData++ = ArgbEncode(255, 255, 255, 255), \\r
113                                                                         *pData++ = ArgbEncode(255, 255, 240, 207), *pData++ = ArgbEncode(255, 248, 179, 48), \\r
114                                                                                 *pData++ = ArgbEncode(255, 176, 176, 167), *pData++ = ArgbEncode(255, 241, 239, 239), \\r
115                                                                                         *pData++ = ArgbEncode(255, 255, 255, 255), *pData++ = ArgbEncode(255, 255, 255, 255), \\r
116                                                                                                 *pData++ = ArgbEncode(255, 220, 220, 215), *pData++ = ArgbEncode(255, 255, 255, 255), \\r
117                                                                                                         *pData++ = ArgbEncode(255, 255, 240, 207), *pData++ = ArgbEncode(255, 248, 179, 48), \\r
118                                                                                                                 *pData++ = ArgbEncode(255, 176, 176, 167), *pData++ = ArgbEncode(255, 241, 239, 239), \\r
119                                                                                                                         *pData++ = ArgbEncode(255, 255, 255, 255), *pData++ = ArgbEncode(255, 255, 255, 255);\r
120 }\r