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