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/scrollbartp.h" | |
8 | |
9 #include "xfa/fwl/basewidget/ifwl_scrollbar.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 FWL_SCROLL_PawLen 12.5f | |
17 | |
18 CFWL_ScrollBarTP::CFWL_ScrollBarTP() { | |
19 m_pThemeData = new SBThemeData; | |
20 SetThemeData(0); | |
21 } | |
22 CFWL_ScrollBarTP::~CFWL_ScrollBarTP() { | |
23 if (m_pThemeData) { | |
24 delete m_pThemeData; | |
25 m_pThemeData = NULL; | |
26 } | |
27 } | |
28 FX_BOOL CFWL_ScrollBarTP::IsValidWidget(IFWL_Widget* pWidget) { | |
29 if (!pWidget) | |
30 return FALSE; | |
31 return pWidget->GetClassID() == FWL_CLASSHASH_ScrollBar; | |
32 } | |
33 void* CFWL_ScrollBarTP::GetCapacity(CFWL_ThemePart* pThemePart, | |
34 uint32_t dwCapacity) { | |
35 if (dwCapacity == FWL_CAPACITY_SCB_Size) { | |
36 m_fValue = 5; | |
37 return &m_fValue; | |
38 } | |
39 return CFWL_WidgetTP::GetCapacity(pThemePart, dwCapacity); | |
40 } | |
41 uint32_t CFWL_ScrollBarTP::SetThemeID(IFWL_Widget* pWidget, | |
42 uint32_t dwThemeID, | |
43 FX_BOOL bChildren) { | |
44 if (m_pThemeData) { | |
45 SetThemeData(FWL_GetThemeColor(dwThemeID)); | |
46 } | |
47 return CFWL_WidgetTP::SetThemeID(pWidget, dwThemeID, bChildren); | |
48 } | |
49 FX_BOOL CFWL_ScrollBarTP::DrawBackground(CFWL_ThemeBackground* pParams) { | |
50 if (!pParams) | |
51 return FALSE; | |
52 IFWL_Widget* pWidget = pParams->m_pWidget; | |
53 FWLTHEME_STATE eState = FWLTHEME_STATE_Normal; | |
54 switch (pParams->m_dwStates & 0x03) { | |
55 case FWL_PARTSTATE_SCB_Hovered: { | |
56 eState = FWLTHEME_STATE_Hover; | |
57 break; | |
58 } | |
59 case FWL_PARTSTATE_SCB_Pressed: { | |
60 eState = FWLTHEME_STATE_Pressed; | |
61 break; | |
62 } | |
63 case FWL_PARTSTATE_SCB_Disabled: { | |
64 eState = FWLTHEME_STATE_Disabale; | |
65 break; | |
66 } | |
67 } | |
68 CFX_Graphics* pGraphics = pParams->m_pGraphics; | |
69 CFX_RectF* pRect = &pParams->m_rtPart; | |
70 FX_BOOL bVert = pWidget->GetStylesEx(); | |
71 switch (pParams->m_iPart) { | |
72 case FWL_PART_SCB_ForeArrow: { | |
73 DrawMaxMinBtn(pGraphics, pRect, | |
74 bVert ? FWLTHEME_DIRECTION_Up : FWLTHEME_DIRECTION_Left, | |
75 eState, &pParams->m_matrix); | |
76 break; | |
77 } | |
78 case FWL_PART_SCB_BackArrow: { | |
79 DrawMaxMinBtn(pGraphics, pRect, | |
80 bVert ? FWLTHEME_DIRECTION_Down : FWLTHEME_DIRECTION_Right, | |
81 eState, &pParams->m_matrix); | |
82 break; | |
83 } | |
84 case FWL_PART_SCB_Thumb: { | |
85 DrawThumbBtn(pGraphics, pRect, bVert, eState, TRUE, &pParams->m_matrix); | |
86 break; | |
87 } | |
88 case FWL_PART_SCB_LowerTrack: { | |
89 DrawTrack(pGraphics, pRect, bVert, eState, TRUE, &pParams->m_matrix); | |
90 break; | |
91 } | |
92 case FWL_PART_SCB_UpperTrack: { | |
93 DrawTrack(pGraphics, pRect, bVert, eState, FALSE, &pParams->m_matrix); | |
94 break; | |
95 } | |
96 default: {} | |
97 } | |
98 return TRUE; | |
99 } | |
100 #ifdef THEME_XPSimilar | |
101 void CFWL_ScrollBarTP::DrawThumbBtn(CFX_Graphics* pGraphics, | |
102 const CFX_RectF* pRect, | |
103 FX_BOOL bVert, | |
104 FWLTHEME_STATE eState, | |
105 FX_BOOL bPawButton, | |
106 CFX_Matrix* pMatrix) { | |
107 if (eState < FWLTHEME_STATE_Normal || eState > FWLTHEME_STATE_Disabale) { | |
108 return; | |
109 } | |
110 CFX_Path path; | |
111 path.Create(); | |
112 CFX_RectF rect(*pRect); | |
113 if (bVert) { | |
114 rect.Deflate(1, 0); | |
115 if (rect.IsEmpty(0.1f)) { | |
116 return; | |
117 } | |
118 path.AddRectangle(rect.left, rect.top, rect.width, rect.height); | |
119 DrawAxialShading(pGraphics, rect.left, rect.top, rect.right(), rect.top, | |
120 m_pThemeData->clrBtnBK[eState - 1][0], | |
121 m_pThemeData->clrBtnBK[eState - 1][1], &path, | |
122 FXFILL_WINDING, pMatrix); | |
123 CFX_Color rcStroke; | |
124 rcStroke.Set(m_pThemeData->clrBtnBorder[eState - 1]); | |
125 pGraphics->SaveGraphState(); | |
126 pGraphics->SetStrokeColor(&rcStroke); | |
127 pGraphics->StrokePath(&path, pMatrix); | |
128 pGraphics->RestoreGraphState(); | |
129 } else { | |
130 rect.Deflate(0, 1); | |
131 if (rect.IsEmpty(0.1f)) { | |
132 return; | |
133 } | |
134 path.AddRectangle(rect.left, rect.top, rect.width, rect.height); | |
135 DrawAxialShading(pGraphics, rect.left, rect.top, rect.left, rect.bottom(), | |
136 m_pThemeData->clrBtnBK[eState - 1][0], | |
137 m_pThemeData->clrBtnBK[eState - 1][1], &path, | |
138 FXFILL_WINDING, pMatrix); | |
139 CFX_Color rcStroke; | |
140 rcStroke.Set(m_pThemeData->clrBtnBorder[eState - 1]); | |
141 pGraphics->SaveGraphState(); | |
142 pGraphics->SetStrokeColor(&rcStroke); | |
143 pGraphics->StrokePath(&path, pMatrix); | |
144 pGraphics->RestoreGraphState(); | |
145 } | |
146 } | |
147 void CFWL_ScrollBarTP::DrawPaw(CFX_Graphics* pGraphics, | |
148 const CFX_RectF* pRect, | |
149 FX_BOOL bVert, | |
150 FWLTHEME_STATE eState, | |
151 CFX_Matrix* pMatrix) { | |
152 CFX_Path path; | |
153 path.Create(); | |
154 if (bVert) { | |
155 FX_FLOAT fPawLen = FWL_SCROLL_PawLen; | |
156 if (pRect->width / 2 <= fPawLen) { | |
157 fPawLen = (pRect->width - 6) / 2; | |
158 } | |
159 FX_FLOAT fX = pRect->left + pRect->width / 4; | |
160 FX_FLOAT fY = pRect->top + pRect->height / 2; | |
161 path.MoveTo(fX, fY - 4); | |
162 path.LineTo(fX + fPawLen, fY - 4); | |
163 path.MoveTo(fX, fY - 2); | |
164 path.LineTo(fX + fPawLen, fY - 2); | |
165 path.MoveTo(fX, fY); | |
166 path.LineTo(fX + fPawLen, fY); | |
167 path.MoveTo(fX, fY + 2); | |
168 path.LineTo(fX + fPawLen, fY + 2); | |
169 CFX_Color clrLight(m_pThemeData->clrPawColorLight[eState - 1]); | |
170 pGraphics->SetLineWidth(1); | |
171 pGraphics->SetStrokeColor(&clrLight); | |
172 pGraphics->StrokePath(&path); | |
173 fX++; | |
174 path.Clear(); | |
175 path.MoveTo(fX, fY - 3); | |
176 path.LineTo(fX + fPawLen, fY - 3); | |
177 path.MoveTo(fX, fY - 1); | |
178 path.LineTo(fX + fPawLen, fY - 1); | |
179 path.MoveTo(fX, fY + 1); | |
180 path.LineTo(fX + fPawLen, fY + 1); | |
181 path.MoveTo(fX, fY + 3); | |
182 path.LineTo(fX + fPawLen, fY + 3); | |
183 CFX_Color clrDark(m_pThemeData->clrPawColorDark[eState - 1]); | |
184 pGraphics->SetLineWidth(1); | |
185 pGraphics->SetStrokeColor(&clrDark); | |
186 pGraphics->StrokePath(&path, pMatrix); | |
187 } else { | |
188 FX_FLOAT fPawLen = FWL_SCROLL_PawLen; | |
189 if (pRect->height / 2 <= fPawLen) { | |
190 fPawLen = (pRect->height - 6) / 2; | |
191 } | |
192 FX_FLOAT fX = pRect->left + pRect->width / 2; | |
193 FX_FLOAT fY = pRect->top + pRect->height / 4; | |
194 path.MoveTo(fX - 4, fY); | |
195 path.LineTo(fX - 4, fY + fPawLen); | |
196 path.MoveTo(fX - 2, fY); | |
197 path.LineTo(fX - 2, fY + fPawLen); | |
198 path.MoveTo(fX, fY); | |
199 path.LineTo(fX, fY + fPawLen); | |
200 path.MoveTo(fX + 2, fY); | |
201 path.LineTo(fX + 2, fY + fPawLen); | |
202 CFX_Color clrLight(m_pThemeData->clrPawColorLight[eState - 1]); | |
203 pGraphics->SetLineWidth(1); | |
204 pGraphics->SetStrokeColor(&clrLight); | |
205 pGraphics->StrokePath(&path, pMatrix); | |
206 fY++; | |
207 path.Clear(); | |
208 path.MoveTo(fX - 3, fY); | |
209 path.LineTo(fX - 3, fY + fPawLen); | |
210 path.MoveTo(fX - 1, fY); | |
211 path.LineTo(fX - 1, fY + fPawLen); | |
212 path.MoveTo(fX + 1, fY); | |
213 path.LineTo(fX + 1, fY + fPawLen); | |
214 path.MoveTo(fX + 3, fY); | |
215 path.LineTo(fX + 3, fY + fPawLen); | |
216 CFX_Color clrDark(m_pThemeData->clrPawColorDark[eState - 1]); | |
217 pGraphics->SetLineWidth(1); | |
218 pGraphics->SetStrokeColor(&clrDark); | |
219 pGraphics->StrokePath(&path, pMatrix); | |
220 } | |
221 } | |
222 void CFWL_ScrollBarTP::DrawTrack(CFX_Graphics* pGraphics, | |
223 const CFX_RectF* pRect, | |
224 FX_BOOL bVert, | |
225 FWLTHEME_STATE eState, | |
226 FX_BOOL bLowerTrack, | |
227 CFX_Matrix* pMatrix) { | |
228 if (eState < FWLTHEME_STATE_Normal || eState > FWLTHEME_STATE_Disabale) { | |
229 return; | |
230 } | |
231 pGraphics->SaveGraphState(); | |
232 CFX_Color colorLine(ArgbEncode(255, 238, 237, 229)); | |
233 CFX_Path path; | |
234 path.Create(); | |
235 FX_FLOAT fRight = pRect->right(); | |
236 FX_FLOAT fBottom = pRect->bottom(); | |
237 if (bVert) { | |
238 path.AddRectangle(pRect->left, pRect->top, 1, pRect->height); | |
239 path.AddRectangle(fRight - 1, pRect->top, 1, pRect->height); | |
240 } else { | |
241 path.AddRectangle(pRect->left, pRect->top, pRect->width, 1); | |
242 path.AddRectangle(pRect->left, fBottom - 1, pRect->width, 1); | |
243 } | |
244 pGraphics->SetFillColor(&colorLine); | |
245 pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); | |
246 path.Clear(); | |
247 path.AddRectangle(pRect->left + 1, pRect->top, pRect->width - 2, | |
248 pRect->height); | |
249 FX_FLOAT x1 = bVert ? pRect->left + 1 : pRect->left; | |
250 FX_FLOAT y1 = bVert ? pRect->top : pRect->top + 1; | |
251 FX_FLOAT x2 = bVert ? fRight - 1 : pRect->left; | |
252 FX_FLOAT y2 = bVert ? pRect->top : fBottom - 1; | |
253 pGraphics->RestoreGraphState(); | |
254 DrawAxialShading(pGraphics, x1, y1, x2, y2, m_pThemeData->clrTrackBKStart, | |
255 m_pThemeData->clrTrackBKEnd, &path, FXFILL_WINDING, pMatrix); | |
256 } | |
257 void CFWL_ScrollBarTP::DrawMaxMinBtn(CFX_Graphics* pGraphics, | |
258 const CFX_RectF* pRect, | |
259 FWLTHEME_DIRECTION eDict, | |
260 FWLTHEME_STATE eState, | |
261 CFX_Matrix* pMatrix) { | |
262 DrawTrack(pGraphics, pRect, | |
263 eDict == FWLTHEME_DIRECTION_Up || eDict == FWLTHEME_DIRECTION_Down, | |
264 eState, TRUE, pMatrix); | |
265 CFX_RectF rtArrowBtn(*pRect); | |
266 rtArrowBtn.Deflate(1, 1, 1, 1); | |
267 DrawArrowBtn(pGraphics, &rtArrowBtn, eDict, eState, pMatrix); | |
268 } | |
269 #else | |
270 void CFWL_ScrollBarTP::DrawThumbBtn(CFX_Graphics* pGraphics, | |
271 const CFX_RectF* pRect, | |
272 FX_BOOL bVert, | |
273 FWLTHEME_STATE eState, | |
274 FX_BOOL bPawButton, | |
275 CFX_Matrix* pMatrix) { | |
276 if (pRect->IsEmpty()) { | |
277 return; | |
278 } | |
279 CFX_RectF rtThumb(*pRect); | |
280 FX_FLOAT fWidth = 2; | |
281 Draw3DRect(pGraphics, FWLTHEME_EDGE_Raised, fWidth, pRect, | |
282 FWLTHEME_COLOR_EDGELT1, FWLTHEME_COLOR_EDGELT2, | |
283 FWLTHEME_COLOR_EDGERB1, FWLTHEME_COLOR_EDGERB2, pMatrix); | |
284 CFX_Path path; | |
285 path.Create(); | |
286 path.AddRectangle(pRect->left + fWidth, pRect->top + fWidth, | |
287 pRect->width - 2 * fWidth, pRect->height - 2 * fWidth); | |
288 pGraphics->SaveGraphState(); | |
289 CFX_Color crFill(FWLTHEME_COLOR_Background); | |
290 pGraphics->SetFillColor(&crFill); | |
291 pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); | |
292 pGraphics->RestoreGraphState(); | |
293 } | |
294 void CFWL_ScrollBarTP::DrawTrack(CFX_Graphics* pGraphics, | |
295 const CFX_RectF* pRect, | |
296 FX_BOOL bVert, | |
297 FWLTHEME_STATE eState, | |
298 FX_BOOL bLowerTrack, | |
299 CFX_Matrix* pMatrix) { | |
300 if (pRect->IsEmpty()) { | |
301 return; | |
302 } | |
303 CFX_Path path; | |
304 path.Create(); | |
305 path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height); | |
306 pGraphics->SaveGraphState(); | |
307 CFX_Color clrFill(0xFFF0F0F0); | |
308 pGraphics->SetFillColor(&clrFill); | |
309 pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); | |
310 pGraphics->RestoreGraphState(); | |
311 } | |
312 void CFWL_ScrollBarTP::DrawMaxMinBtn(CFX_Graphics* pGraphics, | |
313 const CFX_RectF* pRect, | |
314 FWLTHEME_DIRECTION eDict, | |
315 FWLTHEME_STATE eState, | |
316 CFX_Matrix* pMatrix) { | |
317 CFX_RectF rtThumb(*pRect); | |
318 FX_FLOAT fWidth = eState == FWLTHEME_STATE_Pressed ? 1.0f : 2.0f; | |
319 FWLTHEME_EDGE eType = eState == FWLTHEME_STATE_Pressed ? FWLTHEME_EDGE_Flat | |
320 : FWLTHEME_EDGE_Raised; | |
321 Draw3DRect(pGraphics, eType, fWidth, pRect, FWLTHEME_COLOR_EDGELT1, | |
322 FWLTHEME_COLOR_EDGELT2, FWLTHEME_COLOR_EDGERB1, | |
323 FWLTHEME_COLOR_EDGERB2, pMatrix); | |
324 CFX_Path path; | |
325 path.Create(); | |
326 path.AddRectangle(pRect->left + fWidth, pRect->top + fWidth, | |
327 pRect->width - 2 * fWidth, pRect->height - 2 * fWidth); | |
328 pGraphics->SaveGraphState(); | |
329 CFX_Color crFill(FWLTHEME_COLOR_Background); | |
330 pGraphics->SetFillColor(&crFill); | |
331 pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); | |
332 pGraphics->RestoreGraphState(); | |
333 DrawArrow(pGraphics, pRect, eDict, | |
334 eState == FWLTHEME_STATE_Disabale ? 0xFFA0A0A0 : 0xFF000000, | |
335 eState == FWLTHEME_STATE_Pressed, pMatrix); | |
336 } | |
337 #endif | |
338 void CFWL_ScrollBarTP::SetThemeData(uint32_t dwID) { | |
339 m_pThemeData->clrPawColorLight[3] = ArgbEncode(0xff, 208, 223, 172); | |
340 m_pThemeData->clrPawColorDark[3] = ArgbEncode(0xff, 140, 157, 115); | |
341 m_pThemeData->clrBtnBK[3][0] = ArgbEncode(0xff, 164, 180, 139); | |
342 m_pThemeData->clrBtnBK[3][1] = ArgbEncode(0xff, 141, 157, 115); | |
343 m_pThemeData->clrBtnBorder[3] = ArgbEncode(0xff, 236, 233, 216); | |
344 if (dwID) { | |
345 m_pThemeData->clrPawColorLight[0] = ArgbEncode(0xff, 208, 223, 172); | |
346 m_pThemeData->clrPawColorDark[0] = ArgbEncode(0xff, 140, 157, 115); | |
347 m_pThemeData->clrBtnBK[0][0] = ArgbEncode(0xff, 162, 179, 141); | |
348 m_pThemeData->clrBtnBK[0][1] = ArgbEncode(0xff, 149, 167, 117); | |
349 m_pThemeData->clrBtnBorder[0] = ArgbEncode(0xff, 142, 153, 125); | |
350 m_pThemeData->clrPawColorLight[1] = ArgbEncode(0xff, 235, 245, 212); | |
351 m_pThemeData->clrPawColorDark[1] = ArgbEncode(0xff, 182, 198, 142); | |
352 m_pThemeData->clrBtnBK[1][0] = ArgbEncode(0xff, 200, 213, 170); | |
353 m_pThemeData->clrBtnBK[1][1] = ArgbEncode(0xff, 195, 208, 150); | |
354 m_pThemeData->clrBtnBorder[1] = ArgbEncode(0xff, 189, 203, 150); | |
355 m_pThemeData->clrPawColorLight[2] = ArgbEncode(0xff, 208, 223, 172); | |
356 m_pThemeData->clrPawColorDark[2] = ArgbEncode(0xff, 140, 157, 115); | |
357 m_pThemeData->clrBtnBK[2][0] = ArgbEncode(0xff, 164, 180, 139); | |
358 m_pThemeData->clrBtnBK[2][1] = ArgbEncode(0xff, 141, 157, 115); | |
359 m_pThemeData->clrBtnBorder[2] = ArgbEncode(0xff, 128, 146, 102); | |
360 m_pThemeData->clrTrackBKStart = ArgbEncode(0xff, 243, 241, 236); | |
361 m_pThemeData->clrTrackBKEnd = ArgbEncode(0xff, 254, 254, 251); | |
362 } else { | |
363 m_pThemeData->clrPawColorLight[0] = ArgbEncode(0xff, 238, 244, 254); | |
364 m_pThemeData->clrPawColorDark[0] = ArgbEncode(0xff, 140, 176, 248); | |
365 m_pThemeData->clrBtnBK[0][0] = ArgbEncode(0xff, 197, 213, 252); | |
366 m_pThemeData->clrBtnBK[0][1] = ArgbEncode(0xff, 182, 205, 251); | |
367 m_pThemeData->clrBtnBorder[0] = ArgbEncode(0xff, 148, 176, 221); | |
368 m_pThemeData->clrPawColorLight[1] = ArgbEncode(0xff, 252, 253, 255); | |
369 m_pThemeData->clrPawColorDark[1] = ArgbEncode(0xff, 156, 197, 255); | |
370 m_pThemeData->clrBtnBK[1][0] = ArgbEncode(0xff, 216, 232, 255); | |
371 m_pThemeData->clrBtnBK[1][1] = ArgbEncode(0xff, 204, 225, 255); | |
372 m_pThemeData->clrBtnBorder[1] = ArgbEncode(0xff, 218, 230, 254); | |
373 m_pThemeData->clrPawColorLight[2] = ArgbEncode(0xff, 207, 221, 253); | |
374 m_pThemeData->clrPawColorDark[2] = ArgbEncode(0xff, 131, 158, 216); | |
375 m_pThemeData->clrBtnBK[2][0] = ArgbEncode(0xff, 167, 190, 245); | |
376 m_pThemeData->clrBtnBK[2][1] = ArgbEncode(0xff, 146, 179, 249); | |
377 m_pThemeData->clrBtnBorder[2] = ArgbEncode(0xff, 124, 159, 211); | |
378 m_pThemeData->clrTrackBKStart = ArgbEncode(0xff, 243, 241, 236); | |
379 m_pThemeData->clrTrackBKEnd = ArgbEncode(0xff, 254, 254, 251); | |
380 } | |
381 } | |
OLD | NEW |