Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fwl / src / theme / comboboxtp.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 #define FWLTHEME_CAPACITY_ComboFormHandler      8.0f\r
9 CFWL_ComboBoxTP::CFWL_ComboBoxTP()\r
10 {\r
11     m_dwThemeID = 0;\r
12 }\r
13 CFWL_ComboBoxTP::~CFWL_ComboBoxTP()\r
14 {\r
15 }\r
16 FX_BOOL CFWL_ComboBoxTP::IsValidWidget(IFWL_Widget *pWidget)\r
17 {\r
18     _FWL_RETURN_VALUE_IF_FAIL(pWidget, FALSE);\r
19     return pWidget->GetClassID() == FWL_CLASSHASH_ComboBox;\r
20 }\r
21 FX_BOOL CFWL_ComboBoxTP::DrawBackground(CFWL_ThemeBackground *pParams)\r
22 {\r
23     _FWL_RETURN_VALUE_IF_FAIL(pParams, FALSE);\r
24     switch(pParams->m_iPart) {\r
25         case FWL_PART_CMB_Border: {\r
26                 DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix);\r
27                 break;\r
28             }\r
29         case FWL_PART_CMB_Edge: {\r
30                 DrawEdge(pParams->m_pGraphics, pParams->m_pWidget->GetStyles(), &pParams->m_rtPart, &pParams->m_matrix);\r
31                 break;\r
32             }\r
33         case FWL_PART_CMB_Background: {\r
34                 CFX_Path path;\r
35                 path.Create();\r
36                 CFX_RectF & rect = pParams->m_rtPart;\r
37                 path.AddRectangle(rect.left, rect.top, rect.width, rect.height);\r
38                 CFX_Color cr;\r
39                 switch(pParams->m_dwStates) {\r
40                     case FWL_PARTSTATE_CMB_Selected:\r
41                         cr = FWLTHEME_COLOR_BKSelected;\r
42                         break;\r
43                     case FWL_PARTSTATE_CMB_Disabled:\r
44                         cr = FWLTHEME_COLOR_EDGERB1;\r
45                         break;\r
46                     default:\r
47                         cr = 0xFFFFFFFF;\r
48                 }\r
49                 pParams->m_pGraphics->SaveGraphState();\r
50                 pParams->m_pGraphics->SetFillColor(&cr);\r
51                 pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, &pParams->m_matrix);\r
52                 pParams->m_pGraphics->RestoreGraphState();\r
53                 break;\r
54             }\r
55         case FWL_PART_CMB_DropDownButton: {\r
56                 DrawDropDownButton(pParams, pParams->m_dwStates, &pParams->m_matrix);\r
57                 break;\r
58             }\r
59         case FWL_PART_CMB_StretcgHandler: {\r
60                 DrawStrethHandler(pParams, 0, &pParams->m_matrix);\r
61                 break;\r
62             }\r
63         default: {\r
64                 return FALSE;\r
65             }\r
66     }\r
67     return TRUE;\r
68 }\r
69 void CFWL_ComboBoxTP::DrawStrethHandler(CFWL_ThemeBackground *pParams, FX_DWORD dwStates, CFX_Matrix *pMatrix)\r
70 {\r
71     CFX_Path path;\r
72     path.Create();\r
73     path.AddRectangle(pParams->m_rtPart.left,\r
74                       pParams->m_rtPart.top,\r
75                       pParams->m_rtPart.width - 1,\r
76                       pParams->m_rtPart.height);\r
77     CFX_Color cr(ArgbEncode(0xff, 0xff, 0, 0));\r
78     pParams->m_pGraphics->SetFillColor(&cr);\r
79     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, &pParams->m_matrix);\r
80 }\r
81 FX_LPVOID CFWL_ComboBoxTP::GetCapacity(CFWL_ThemePart *pThemePart, FX_DWORD dwCapacity)\r
82 {\r
83     if (dwCapacity == FWL_WGTCAPACITY_CMB_ComboFormHandler) {\r
84         m_fValue = FWLTHEME_CAPACITY_ComboFormHandler;\r
85         return &m_fValue;\r
86     }\r
87     return CFWL_WidgetTP::GetCapacity(pThemePart, dwCapacity);\r
88 }\r
89 #ifdef THEME_XPSimilar\r
90 void CFWL_ComboBoxTP::DrawDropDownButton(CFWL_ThemeBackground *pParams, FX_DWORD dwStates, CFX_Matrix *pMatrix)\r
91 {\r
92     FWLTHEME_STATE eState = FWLTHEME_STATE_Normal;\r
93     switch ( dwStates) {\r
94         case FWL_PARTSTATE_CMB_Normal: {\r
95                 eState = FWLTHEME_STATE_Normal;\r
96                 break;\r
97             }\r
98         case FWL_PARTSTATE_CMB_Hovered: {\r
99                 eState = FWLTHEME_STATE_Hover;\r
100                 break;\r
101             }\r
102         case FWL_PARTSTATE_CMB_Pressed: {\r
103                 eState = FWLTHEME_STATE_Pressed;\r
104                 break;\r
105             }\r
106         case FWL_PARTSTATE_CMB_Disabled: {\r
107                 eState = FWLTHEME_STATE_Disabale;\r
108                 break;\r
109             }\r
110         default: {\r
111             }\r
112     }\r
113     DrawArrowBtn(pParams->m_pGraphics, &pParams->m_rtPart, FWLTHEME_DIRECTION_Down, eState, &pParams->m_matrix);\r
114 }\r
115 #else\r
116 void CFWL_ComboBoxTP::DrawDropDownButton(CFWL_ThemeBackground *pParams, FX_DWORD dwStates, CFX_Matrix *pMatrix)\r
117 {\r
118     FX_BOOL bPressed = ((pParams->m_dwStates & FWL_CMBPARTSTATE_Pressed) == FWL_CMBPARTSTATE_Pressed);\r
119     FX_FLOAT fWidth =  bPressed ? 1.0f : 2.0f;\r
120     FWLTHEME_EDGE eType = bPressed ? FWLTHEME_EDGE_Flat : FWLTHEME_EDGE_Raised;\r
121     Draw3DRect(pParams->m_pGraphics, eType, fWidth, &pParams->m_rtPart, FWLTHEME_COLOR_EDGELT1, FWLTHEME_COLOR_EDGELT2, FWLTHEME_COLOR_EDGERB1, FWLTHEME_COLOR_EDGERB2, pMatrix);\r
122     CFX_Path path;\r
123     path.Create();\r
124     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
125     pParams->m_pGraphics->SaveGraphState();\r
126     CFX_Color crFill(FWLTHEME_COLOR_Background);\r
127     pParams->m_pGraphics->SetFillColor(&crFill);\r
128     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, &pParams->m_matrix);\r
129     pParams->m_pGraphics->RestoreGraphState();\r
130     FX_ARGB argbFill = ArgbEncode(255, 77, 97, 133);\r
131     switch(pParams->m_dwStates & 0x03) {\r
132         case FWL_CMBPARTSTATE_Normal: {\r
133             }\r
134         case FWL_CMBPARTSTATE_Hovered: {\r
135             }\r
136         case FWL_CMBPARTSTATE_Pressed: {\r
137                 argbFill = 0xFF000000;\r
138                 break;\r
139             }\r
140         case FWL_CMBPARTSTATE_Disabled: {\r
141                 argbFill = 0xFFF0F0F0;\r
142                 break;\r
143             }\r
144     }\r
145     DrawArrow(pParams->m_pGraphics, &pParams->m_rtPart, FWLTHEME_DIRECTION_Down, argbFill, bPressed, &pParams->m_matrix);\r
146 }\r
147 #endif\r