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