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