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