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/widgettp.h" | |
8 | |
9 #include <algorithm> | |
10 | |
11 #include "xfa/fde/tto/fde_textout.h" | |
12 #include "xfa/fwl/core/cfwl_themebackground.h" | |
13 #include "xfa/fwl/core/cfwl_themepart.h" | |
14 #include "xfa/fwl/core/cfwl_themetext.h" | |
15 #include "xfa/fwl/core/ifwl_themeprovider.h" | |
16 #include "xfa/fwl/core/ifwl_widgetmgr.h" | |
17 #include "xfa/fxgraphics/cfx_color.h" | |
18 #include "xfa/fxgraphics/cfx_path.h" | |
19 #include "xfa/fxgraphics/cfx_shading.h" | |
20 | |
21 static void FWL_SetChildThemeID(IFWL_Widget* pParent, uint32_t dwThemeID) { | |
22 IFWL_WidgetMgr* pWidgetMgr = FWL_GetWidgetMgr(); | |
23 IFWL_Widget* pChild = | |
24 pWidgetMgr->GetWidget(pParent, FWL_WGTRELATION_FirstChild); | |
25 while (pChild) { | |
26 IFWL_ThemeProvider* pTheme = pChild->GetThemeProvider(); | |
27 if (pTheme) { | |
28 pTheme->SetThemeID(pChild, dwThemeID, FALSE); | |
29 } | |
30 FWL_SetChildThemeID(pChild, dwThemeID); | |
31 pChild = pWidgetMgr->GetWidget(pChild, FWL_WGTRELATION_NextSibling); | |
32 } | |
33 } | |
34 FX_BOOL CFWL_WidgetTP::IsValidWidget(IFWL_Widget* pWidget) { | |
35 return FALSE; | |
36 } | |
37 uint32_t CFWL_WidgetTP::GetThemeID(IFWL_Widget* pWidget) { | |
38 return m_dwThemeID; | |
39 } | |
40 uint32_t CFWL_WidgetTP::SetThemeID(IFWL_Widget* pWidget, | |
41 uint32_t dwThemeID, | |
42 FX_BOOL bChildren) { | |
43 uint32_t dwOld = m_dwThemeID; | |
44 m_dwThemeID = dwThemeID; | |
45 if (CFWL_ArrowData::IsInstance()) { | |
46 CFWL_ArrowData::GetInstance()->SetColorData(FWL_GetThemeColor(dwThemeID)); | |
47 } | |
48 if (bChildren) { | |
49 FWL_SetChildThemeID(pWidget, dwThemeID); | |
50 } | |
51 return dwOld; | |
52 } | |
53 FWL_ERR CFWL_WidgetTP::GetThemeMatrix(IFWL_Widget* pWidget, | |
54 CFX_Matrix& matrix) { | |
55 matrix.Set(_ctm.a, _ctm.b, _ctm.c, _ctm.d, _ctm.e, _ctm.f); | |
56 return FWL_ERR_Succeeded; | |
57 } | |
58 FWL_ERR CFWL_WidgetTP::SetThemeMatrix(IFWL_Widget* pWidget, | |
59 const CFX_Matrix& matrix) { | |
60 _ctm.Set(matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f); | |
61 return FWL_ERR_Succeeded; | |
62 } | |
63 FX_BOOL CFWL_WidgetTP::DrawBackground(CFWL_ThemeBackground* pParams) { | |
64 return TRUE; | |
65 } | |
66 FX_BOOL CFWL_WidgetTP::DrawText(CFWL_ThemeText* pParams) { | |
67 if (!m_pTextOut) { | |
68 InitTTO(); | |
69 } | |
70 int32_t iLen = pParams->m_wsText.GetLength(); | |
71 if (iLen <= 0) | |
72 return FALSE; | |
73 CFX_Graphics* pGraphics = pParams->m_pGraphics; | |
74 m_pTextOut->SetRenderDevice(pGraphics->GetRenderDevice()); | |
75 m_pTextOut->SetStyles(pParams->m_dwTTOStyles); | |
76 m_pTextOut->SetAlignment(pParams->m_iTTOAlign); | |
77 CFX_Matrix* pMatrix = &pParams->m_matrix; | |
78 pMatrix->Concat(*pGraphics->GetMatrix()); | |
79 m_pTextOut->SetMatrix(*pMatrix); | |
80 m_pTextOut->DrawLogicText(pParams->m_wsText, iLen, pParams->m_rtPart); | |
81 return TRUE; | |
82 } | |
83 void* CFWL_WidgetTP::GetCapacity(CFWL_ThemePart* pThemePart, | |
84 uint32_t dwCapacity) { | |
85 switch (dwCapacity) { | |
86 case FWL_WGTCAPACITY_CXBorder: { | |
87 m_fValue = FWLTHEME_CAPACITY_CXBorder; | |
88 break; | |
89 } | |
90 case FWL_WGTCAPACITY_CYBorder: { | |
91 m_fValue = FWLTHEME_CAPACITY_CYBorder; | |
92 break; | |
93 } | |
94 case FWL_WGTCAPACITY_EdgeFlat: { | |
95 m_fValue = FWLTHEME_CAPACITY_EdgeFlat; | |
96 break; | |
97 } | |
98 case FWL_WGTCAPACITY_EdgeRaised: { | |
99 m_fValue = FWLTHEME_CAPACITY_EdgeRaised; | |
100 break; | |
101 } | |
102 case FWL_WGTCAPACITY_EdgeSunken: { | |
103 m_fValue = FWLTHEME_CAPACITY_EdgeSunken; | |
104 break; | |
105 } | |
106 case FWL_WGTCAPACITY_FontSize: { | |
107 m_fValue = FWLTHEME_CAPACITY_FontSize; | |
108 break; | |
109 } | |
110 case FWL_WGTCAPACITY_TextColor: { | |
111 m_dwValue = FWLTHEME_CAPACITY_TextColor; | |
112 return &m_dwValue; | |
113 } | |
114 case FWL_WGTCAPACITY_ScrollBarWidth: { | |
115 m_fValue = FWLTHEME_CAPACITY_ScrollBarWidth; | |
116 break; | |
117 } | |
118 case FWL_WGTCAPACITY_Font: { | |
119 return m_pFDEFont; | |
120 } | |
121 case FWL_WGTCAPACITY_TextSelColor: { | |
122 m_dwValue = (m_dwThemeID == 0) ? FWLTHEME_CAPACITY_TextSelColor | |
123 : FWLTHEME_COLOR_Green_BKSelected; | |
124 return &m_dwValue; | |
125 } | |
126 case FWL_WGTCAPACITY_LineHeight: { | |
127 m_fValue = FWLTHEME_CAPACITY_LineHeight; | |
128 break; | |
129 } | |
130 case FWL_WGTCAPACITY_UIMargin: { | |
131 m_rtMargin.Set(0, 0, 0, 0); | |
132 return &m_rtMargin; | |
133 } | |
134 default: { return NULL; } | |
135 } | |
136 return &m_fValue; | |
137 } | |
138 FX_BOOL CFWL_WidgetTP::IsCustomizedLayout(IFWL_Widget* pWidget) { | |
139 return FWL_GetThemeLayout(m_dwThemeID); | |
140 } | |
141 FWL_ERR CFWL_WidgetTP::GetPartRect(CFWL_ThemePart* pThemePart, | |
142 CFX_RectF& rect) { | |
143 return FWL_ERR_Succeeded; | |
144 } | |
145 FX_BOOL CFWL_WidgetTP::IsInPart(CFWL_ThemePart* pThemePart, | |
146 FX_FLOAT fx, | |
147 FX_FLOAT fy) { | |
148 return TRUE; | |
149 } | |
150 FX_BOOL CFWL_WidgetTP::CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect) { | |
151 if (!pParams) | |
152 return FALSE; | |
153 if (!m_pTextOut) | |
154 return FALSE; | |
155 m_pTextOut->SetAlignment(pParams->m_iTTOAlign); | |
156 m_pTextOut->SetStyles(pParams->m_dwTTOStyles | FDE_TTOSTYLE_ArabicContext); | |
157 m_pTextOut->CalcLogicSize(pParams->m_wsText, pParams->m_wsText.GetLength(), | |
158 rect); | |
159 return TRUE; | |
160 } | |
161 FWL_ERR CFWL_WidgetTP::Initialize() { | |
162 m_dwThemeID = 0; | |
163 _ctm.SetIdentity(); | |
164 return FWL_ERR_Succeeded; | |
165 } | |
166 FWL_ERR CFWL_WidgetTP::Finalize() { | |
167 if (!m_pTextOut) { | |
168 FinalizeTTO(); | |
169 } | |
170 return FWL_ERR_Succeeded; | |
171 } | |
172 CFWL_WidgetTP::~CFWL_WidgetTP() {} | |
173 FWL_ERR CFWL_WidgetTP::SetFont(IFWL_Widget* pWidget, | |
174 const FX_WCHAR* strFont, | |
175 FX_FLOAT fFontSize, | |
176 FX_ARGB rgbFont) { | |
177 if (!m_pTextOut) { | |
178 return FWL_ERR_Succeeded; | |
179 } | |
180 m_pFDEFont = CFWL_FontManager::GetInstance()->FindFont(strFont, 0, 0); | |
181 m_pTextOut->SetFont(m_pFDEFont); | |
182 m_pTextOut->SetFontSize(fFontSize); | |
183 m_pTextOut->SetTextColor(rgbFont); | |
184 return FWL_ERR_Succeeded; | |
185 } | |
186 FWL_ERR CFWL_WidgetTP::SetFont(IFWL_Widget* pWidget, | |
187 IFX_Font* pFont, | |
188 FX_FLOAT fFontSize, | |
189 FX_ARGB rgbFont) { | |
190 if (!m_pTextOut) { | |
191 return FWL_ERR_Succeeded; | |
192 } | |
193 m_pTextOut->SetFont(pFont); | |
194 m_pTextOut->SetFontSize(fFontSize); | |
195 m_pTextOut->SetTextColor(rgbFont); | |
196 return FWL_ERR_Succeeded; | |
197 } | |
198 IFX_Font* CFWL_WidgetTP::GetFont(IFWL_Widget* pWidget) { | |
199 return m_pFDEFont; | |
200 } | |
201 CFWL_WidgetTP::CFWL_WidgetTP() | |
202 : m_dwRefCount(1), m_pTextOut(NULL), m_pFDEFont(NULL), m_dwThemeID(0) {} | |
203 FX_ERR CFWL_WidgetTP::InitTTO() { | |
204 if (m_pTextOut) { | |
205 return FWL_ERR_Succeeded; | |
206 } | |
207 m_pFDEFont = | |
208 CFWL_FontManager::GetInstance()->FindFont(FX_WSTRC(L"Helvetica"), 0, 0); | |
209 m_pTextOut = IFDE_TextOut::Create(); | |
210 m_pTextOut->SetFont(m_pFDEFont); | |
211 m_pTextOut->SetFontSize(FWLTHEME_CAPACITY_FontSize); | |
212 m_pTextOut->SetTextColor(FWLTHEME_CAPACITY_TextColor); | |
213 m_pTextOut->SetEllipsisString(L"..."); | |
214 return FWL_ERR_Succeeded; | |
215 } | |
216 FX_ERR CFWL_WidgetTP::FinalizeTTO() { | |
217 if (m_pTextOut) { | |
218 m_pTextOut->Release(); | |
219 m_pTextOut = NULL; | |
220 } | |
221 return FWL_ERR_Succeeded; | |
222 } | |
223 #ifdef THEME_XPSimilar | |
224 void CFWL_WidgetTP::DrawEdge(CFX_Graphics* pGraphics, | |
225 uint32_t dwStyles, | |
226 const CFX_RectF* pRect, | |
227 CFX_Matrix* pMatrix) { | |
228 if (!pGraphics) | |
229 return; | |
230 if (!pRect) | |
231 return; | |
232 pGraphics->SaveGraphState(); | |
233 CFX_Color crStroke(FWL_GetThemeColor(m_dwThemeID) == 0 | |
234 ? ArgbEncode(255, 127, 157, 185) | |
235 : FWLTHEME_COLOR_Green_BKSelected); | |
236 pGraphics->SetStrokeColor(&crStroke); | |
237 CFX_Path path; | |
238 path.Create(); | |
239 path.AddRectangle(pRect->left, pRect->top, pRect->width - 1, | |
240 pRect->height - 1); | |
241 pGraphics->StrokePath(&path, pMatrix); | |
242 path.Clear(); | |
243 crStroke = ArgbEncode(255, 255, 255, 255); | |
244 pGraphics->SetStrokeColor(&crStroke); | |
245 path.AddRectangle(pRect->left + 1, pRect->top + 1, pRect->width - 3, | |
246 pRect->height - 3); | |
247 pGraphics->StrokePath(&path, pMatrix); | |
248 pGraphics->RestoreGraphState(); | |
249 } | |
250 #else | |
251 void CFWL_WidgetTP::DrawEdge(CFX_Graphics* pGraphics, | |
252 uint32_t dwStyles, | |
253 const CFX_RectF* pRect, | |
254 CFX_Matrix* pMatrix) { | |
255 if (!pGraphics) | |
256 return; | |
257 if (!pRect) | |
258 return; | |
259 FWLTHEME_EDGE eType; | |
260 FX_FLOAT fWidth; | |
261 switch (dwStyles & FWL_WGTSTYLE_EdgeMask) { | |
262 case FWL_WGTSTYLE_EdgeRaised: { | |
263 eType = FWLTHEME_EDGE_Raised, fWidth = FWLTHEME_CAPACITY_EdgeRaised; | |
264 break; | |
265 } | |
266 case FWL_WGTSTYLE_EdgeSunken: { | |
267 eType = FWLTHEME_EDGE_Sunken, fWidth = FWLTHEME_CAPACITY_EdgeSunken; | |
268 break; | |
269 } | |
270 case FWL_WGTSTYLE_EdgeFlat: | |
271 default: { return; } | |
272 } | |
273 Draw3DRect(pGraphics, eType, fWidth, pRect, FWLTHEME_COLOR_EDGELT1, | |
274 FWLTHEME_COLOR_EDGELT2, FWLTHEME_COLOR_EDGERB1, | |
275 FWLTHEME_COLOR_EDGERB2, pMatrix); | |
276 } | |
277 #endif | |
278 void CFWL_WidgetTP::Draw3DRect(CFX_Graphics* pGraphics, | |
279 FWLTHEME_EDGE eType, | |
280 FX_FLOAT fWidth, | |
281 const CFX_RectF* pRect, | |
282 FX_ARGB cr1, | |
283 FX_ARGB cr2, | |
284 FX_ARGB cr3, | |
285 FX_ARGB cr4, | |
286 CFX_Matrix* pMatrix) { | |
287 if (!pGraphics) | |
288 return; | |
289 if (!pRect) | |
290 return; | |
291 pGraphics->SaveGraphState(); | |
292 if (eType == FWLTHEME_EDGE_Flat) { | |
293 CFX_Path path; | |
294 path.Create(); | |
295 path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height); | |
296 path.AddRectangle(pRect->left + 1, pRect->top + 1, pRect->width - 2, | |
297 pRect->height - 2); | |
298 CFX_Color cr(ArgbEncode(255, 100, 100, 100)); | |
299 pGraphics->SetFillColor(&cr); | |
300 pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); | |
301 path.Clear(); | |
302 path.AddRectangle(pRect->left + 1, pRect->top + 1, pRect->width - 2, | |
303 pRect->height - 2); | |
304 path.AddRectangle(pRect->left + 2, pRect->top + 2, pRect->width - 4, | |
305 pRect->height - 4); | |
306 cr.Set(0xFFFFFFFF); | |
307 pGraphics->SetFillColor(&cr); | |
308 pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); | |
309 } else { | |
310 FX_FLOAT fLeft = pRect->left; | |
311 FX_FLOAT fRight = pRect->right(); | |
312 FX_FLOAT fTop = pRect->top; | |
313 FX_FLOAT fBottom = pRect->bottom(); | |
314 FX_FLOAT fHalfWidth = fWidth / 2.0f; | |
315 CFX_Color crLT(eType == FWLTHEME_EDGE_Raised ? cr4 : cr1); | |
316 pGraphics->SetFillColor(&crLT); | |
317 CFX_Path pathLT; | |
318 pathLT.Create(); | |
319 pathLT.MoveTo(fLeft, fBottom - fHalfWidth); | |
320 pathLT.LineTo(fLeft, fTop); | |
321 pathLT.LineTo(fRight - fHalfWidth, fTop); | |
322 pathLT.LineTo(fRight - fHalfWidth, fTop + fHalfWidth); | |
323 pathLT.LineTo(fLeft + fHalfWidth, fTop + fHalfWidth); | |
324 pathLT.LineTo(fLeft + fHalfWidth, fBottom - fHalfWidth); | |
325 pathLT.LineTo(fLeft, fBottom - fHalfWidth); | |
326 pGraphics->FillPath(&pathLT, FXFILL_WINDING, pMatrix); | |
327 crLT = CFX_Color(eType == FWLTHEME_EDGE_Raised ? cr3 : cr2); | |
328 pGraphics->SetFillColor(&crLT); | |
329 pathLT.Clear(); | |
330 pathLT.MoveTo(fLeft + fHalfWidth, fBottom - fWidth); | |
331 pathLT.LineTo(fLeft + fHalfWidth, fTop + fHalfWidth); | |
332 pathLT.LineTo(fRight - fWidth, fTop + fHalfWidth); | |
333 pathLT.LineTo(fRight - fWidth, fTop + fWidth); | |
334 pathLT.LineTo(fLeft + fWidth, fTop + fWidth); | |
335 pathLT.LineTo(fLeft + fWidth, fBottom - fWidth); | |
336 pathLT.LineTo(fLeft + fHalfWidth, fBottom - fWidth); | |
337 pGraphics->FillPath(&pathLT, FXFILL_WINDING, pMatrix); | |
338 CFX_Color crRB(eType == FWLTHEME_EDGE_Raised ? cr1 : cr3); | |
339 pGraphics->SetFillColor(&crRB); | |
340 CFX_Path pathRB; | |
341 pathRB.Create(); | |
342 pathRB.MoveTo(fRight - fHalfWidth, fTop + fHalfWidth); | |
343 pathRB.LineTo(fRight - fHalfWidth, fBottom - fHalfWidth); | |
344 pathRB.LineTo(fLeft + fHalfWidth, fBottom - fHalfWidth); | |
345 pathRB.LineTo(fLeft + fHalfWidth, fBottom - fWidth); | |
346 pathRB.LineTo(fRight - fWidth, fBottom - fWidth); | |
347 pathRB.LineTo(fRight - fWidth, fTop + fHalfWidth); | |
348 pathRB.LineTo(fRight - fHalfWidth, fTop + fHalfWidth); | |
349 pGraphics->FillPath(&pathRB, FXFILL_WINDING, pMatrix); | |
350 crRB = CFX_Color(eType == FWLTHEME_EDGE_Raised ? cr2 : cr4); | |
351 pGraphics->SetFillColor(&crRB); | |
352 pathRB.Clear(); | |
353 pathRB.MoveTo(fRight, fTop); | |
354 pathRB.LineTo(fRight, fBottom); | |
355 pathRB.LineTo(fLeft, fBottom); | |
356 pathRB.LineTo(fLeft, fBottom - fHalfWidth); | |
357 pathRB.LineTo(fRight - fHalfWidth, fBottom - fHalfWidth); | |
358 pathRB.LineTo(fRight - fHalfWidth, fTop); | |
359 pathRB.LineTo(fRight, fTop); | |
360 pGraphics->FillPath(&pathRB, FXFILL_WINDING, pMatrix); | |
361 } | |
362 pGraphics->RestoreGraphState(); | |
363 } | |
364 void CFWL_WidgetTP::Draw3DCircle(CFX_Graphics* pGraphics, | |
365 FWLTHEME_EDGE eType, | |
366 FX_FLOAT fWidth, | |
367 const CFX_RectF* pRect, | |
368 FX_ARGB cr1, | |
369 FX_ARGB cr2, | |
370 FX_ARGB cr3, | |
371 FX_ARGB cr4, | |
372 CFX_Matrix* pMatrix) { | |
373 if (!pGraphics) | |
374 return; | |
375 if (!pRect) | |
376 return; | |
377 pGraphics->SaveGraphState(); | |
378 CFX_Path path; | |
379 path.Create(); | |
380 path.AddArc(pRect->left, pRect->top, pRect->width, pRect->height, | |
381 FWLTHEME_PI * 3 / 4, FWLTHEME_PI); | |
382 CFX_Color crFill1(eType == FWLTHEME_EDGE_Raised ? cr4 : cr1); | |
383 pGraphics->SetStrokeColor(&crFill1); | |
384 pGraphics->StrokePath(&path, pMatrix); | |
385 CFX_RectF rtInner(*pRect); | |
386 rtInner.Deflate(pRect->width / 4, pRect->height / 4); | |
387 path.Clear(); | |
388 path.AddArc(rtInner.left, rtInner.top, rtInner.width, rtInner.height, | |
389 FWLTHEME_PI * 3 / 4, FWLTHEME_PI); | |
390 CFX_Color crFill2(eType == FWLTHEME_EDGE_Raised ? cr3 : cr2); | |
391 pGraphics->SetStrokeColor(&crFill2); | |
392 pGraphics->StrokePath(&path, pMatrix); | |
393 path.Clear(); | |
394 path.AddArc(pRect->left, pRect->top, pRect->width, pRect->height, | |
395 FWLTHEME_PI * 7 / 4, FWLTHEME_PI); | |
396 CFX_Color crFill3(eType == FWLTHEME_EDGE_Raised ? cr1 : cr3); | |
397 pGraphics->SetStrokeColor(&crFill3); | |
398 pGraphics->StrokePath(&path, pMatrix); | |
399 path.AddArc(rtInner.left, rtInner.top, rtInner.width, rtInner.height, | |
400 FWLTHEME_PI * 7 / 4, FWLTHEME_PI); | |
401 CFX_Color crFill4(eType == FWLTHEME_EDGE_Raised ? cr2 : cr4); | |
402 pGraphics->SetStrokeColor(&crFill4); | |
403 pGraphics->StrokePath(&path, pMatrix); | |
404 pGraphics->RestoreGraphState(); | |
405 } | |
406 void CFWL_WidgetTP::DrawBorder(CFX_Graphics* pGraphics, | |
407 const CFX_RectF* pRect, | |
408 CFX_Matrix* pMatrix) { | |
409 if (!pGraphics) | |
410 return; | |
411 if (!pRect) | |
412 return; | |
413 CFX_Path path; | |
414 path.Create(); | |
415 path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height); | |
416 path.AddRectangle(pRect->left + 1, pRect->top + 1, pRect->width - 2, | |
417 pRect->height - 2); | |
418 pGraphics->SaveGraphState(); | |
419 CFX_Color crFill(ArgbEncode(255, 0, 0, 0)); | |
420 pGraphics->SetFillColor(&crFill); | |
421 pGraphics->FillPath(&path, FXFILL_ALTERNATE, pMatrix); | |
422 pGraphics->RestoreGraphState(); | |
423 } | |
424 void CFWL_WidgetTP::FillBackground(CFX_Graphics* pGraphics, | |
425 const CFX_RectF* pRect, | |
426 CFX_Matrix* pMatrix) { | |
427 FillSoildRect(pGraphics, FWLTHEME_COLOR_Background, pRect, pMatrix); | |
428 } | |
429 void CFWL_WidgetTP::FillSoildRect(CFX_Graphics* pGraphics, | |
430 FX_ARGB fillColor, | |
431 const CFX_RectF* pRect, | |
432 CFX_Matrix* pMatrix) { | |
433 if (!pGraphics) | |
434 return; | |
435 if (!pRect) | |
436 return; | |
437 pGraphics->SaveGraphState(); | |
438 CFX_Color crFill(fillColor); | |
439 pGraphics->SetFillColor(&crFill); | |
440 CFX_Path path; | |
441 path.Create(); | |
442 path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height); | |
443 pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); | |
444 pGraphics->RestoreGraphState(); | |
445 } | |
446 void CFWL_WidgetTP::DrawAxialShading(CFX_Graphics* pGraphics, | |
447 FX_FLOAT fx1, | |
448 FX_FLOAT fy1, | |
449 FX_FLOAT fx2, | |
450 FX_FLOAT fy2, | |
451 FX_ARGB beginColor, | |
452 FX_ARGB endColor, | |
453 CFX_Path* path, | |
454 int32_t fillMode, | |
455 CFX_Matrix* pMatrix) { | |
456 if (!pGraphics || !path) | |
457 return; | |
458 | |
459 CFX_PointF begPoint(fx1, fy1); | |
460 CFX_PointF endPoint(fx2, fy2); | |
461 CFX_Shading shading(begPoint, endPoint, FALSE, FALSE, beginColor, endColor); | |
462 pGraphics->SaveGraphState(); | |
463 CFX_Color color1(&shading); | |
464 pGraphics->SetFillColor(&color1); | |
465 pGraphics->FillPath(path, fillMode, pMatrix); | |
466 pGraphics->RestoreGraphState(); | |
467 } | |
468 void CFWL_WidgetTP::DrawAnnulusRect(CFX_Graphics* pGraphics, | |
469 FX_ARGB fillColor, | |
470 const CFX_RectF* pRect, | |
471 FX_FLOAT fRingWidth, | |
472 CFX_Matrix* pMatrix) { | |
473 if (!pGraphics) | |
474 return; | |
475 if (!pRect) | |
476 return; | |
477 pGraphics->SaveGraphState(); | |
478 CFX_Color cr(fillColor); | |
479 pGraphics->SetFillColor(&cr); | |
480 CFX_Path path; | |
481 path.Create(); | |
482 CFX_RectF rtInner(*pRect); | |
483 rtInner.Deflate(fRingWidth, fRingWidth); | |
484 path.AddRectangle(rtInner.left, rtInner.top, rtInner.width, rtInner.height); | |
485 path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height); | |
486 pGraphics->FillPath(&path, FXFILL_ALTERNATE, pMatrix); | |
487 pGraphics->RestoreGraphState(); | |
488 } | |
489 void CFWL_WidgetTP::DrawAnnulusCircle(CFX_Graphics* pGraphics, | |
490 FX_ARGB fillColor, | |
491 const CFX_RectF* pRect, | |
492 FX_FLOAT fWidth, | |
493 CFX_Matrix* pMatrix) { | |
494 if (!pGraphics) | |
495 return; | |
496 if (!pRect) | |
497 return; | |
498 if (fWidth > pRect->width / 2) { | |
499 return; | |
500 } | |
501 pGraphics->SaveGraphState(); | |
502 CFX_Color cr(fillColor); | |
503 pGraphics->SetFillColor(&cr); | |
504 CFX_Path path; | |
505 path.Create(); | |
506 path.AddEllipse(*pRect); | |
507 CFX_RectF rtIn(*pRect); | |
508 rtIn.Inflate(-fWidth, -fWidth); | |
509 path.AddEllipse(rtIn); | |
510 pGraphics->FillPath(&path, FXFILL_ALTERNATE, pMatrix); | |
511 pGraphics->RestoreGraphState(); | |
512 } | |
513 void CFWL_WidgetTP::DrawFocus(CFX_Graphics* pGraphics, | |
514 const CFX_RectF* pRect, | |
515 CFX_Matrix* pMatrix) { | |
516 if (!pGraphics) | |
517 return; | |
518 if (!pRect) | |
519 return; | |
520 pGraphics->SaveGraphState(); | |
521 CFX_Color cr(0xFF000000); | |
522 pGraphics->SetStrokeColor(&cr); | |
523 FX_FLOAT DashPattern[2] = {1, 1}; | |
524 pGraphics->SetLineDash(0.0f, DashPattern, 2); | |
525 CFX_Path path; | |
526 path.Create(); | |
527 path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height); | |
528 pGraphics->StrokePath(&path, pMatrix); | |
529 pGraphics->RestoreGraphState(); | |
530 } | |
531 #define FWLTHEME_ARROW_Denominator 3 | |
532 void CFWL_WidgetTP::DrawArrow(CFX_Graphics* pGraphics, | |
533 const CFX_RectF* pRect, | |
534 FWLTHEME_DIRECTION eDict, | |
535 FX_ARGB argbFill, | |
536 FX_BOOL bPressed, | |
537 CFX_Matrix* pMatrix) { | |
538 CFX_RectF rtArrow(*pRect); | |
539 CFX_Path path; | |
540 path.Create(); | |
541 FX_FLOAT fBtn = | |
542 std::min(pRect->width, pRect->height) / FWLTHEME_ARROW_Denominator; | |
543 rtArrow.left = pRect->left + (pRect->width - fBtn) / 2; | |
544 rtArrow.top = pRect->top + (pRect->height - fBtn) / 2; | |
545 rtArrow.width = fBtn; | |
546 rtArrow.height = fBtn; | |
547 if (bPressed) { | |
548 rtArrow.Offset(1, 1); | |
549 } | |
550 switch (eDict) { | |
551 case FWLTHEME_DIRECTION_Up: { | |
552 path.MoveTo(rtArrow.left, rtArrow.bottom()); | |
553 path.LineTo(rtArrow.right(), rtArrow.bottom()); | |
554 path.LineTo(rtArrow.left + fBtn / 2, rtArrow.top); | |
555 path.LineTo(rtArrow.left, rtArrow.bottom()); | |
556 break; | |
557 } | |
558 case FWLTHEME_DIRECTION_Left: { | |
559 path.MoveTo(rtArrow.right(), rtArrow.top); | |
560 path.LineTo(rtArrow.right(), rtArrow.bottom()); | |
561 path.LineTo(rtArrow.left, rtArrow.top + fBtn / 2); | |
562 path.LineTo(rtArrow.right(), rtArrow.top); | |
563 break; | |
564 } | |
565 case FWLTHEME_DIRECTION_Right: { | |
566 path.MoveTo(rtArrow.left, rtArrow.top); | |
567 path.LineTo(rtArrow.left, rtArrow.bottom()); | |
568 path.LineTo(rtArrow.right(), rtArrow.top + fBtn / 2); | |
569 path.LineTo(rtArrow.left, rtArrow.top); | |
570 break; | |
571 } | |
572 case FWLTHEME_DIRECTION_Down: | |
573 default: { | |
574 path.MoveTo(rtArrow.left, rtArrow.top); | |
575 path.LineTo(rtArrow.right(), rtArrow.top); | |
576 path.LineTo(rtArrow.left + fBtn / 2, rtArrow.bottom()); | |
577 path.LineTo(rtArrow.left, rtArrow.top); | |
578 } | |
579 } | |
580 pGraphics->SaveGraphState(); | |
581 CFX_Color cr(argbFill); | |
582 pGraphics->SetFillColor(&cr); | |
583 pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); | |
584 pGraphics->RestoreGraphState(); | |
585 } | |
586 void CFWL_WidgetTP::DrawArrow(CFX_Graphics* pGraphics, | |
587 const CFX_RectF* pRect, | |
588 FWLTHEME_DIRECTION eDict, | |
589 FX_ARGB argSign, | |
590 CFX_Matrix* pMatrix) { | |
591 FX_BOOL bVert = | |
592 (eDict == FWLTHEME_DIRECTION_Up || eDict == FWLTHEME_DIRECTION_Down); | |
593 FX_FLOAT fLeft = | |
594 (FX_FLOAT)(((pRect->width - (bVert ? 9 : 6)) / 2 + pRect->left) + 0.5); | |
595 FX_FLOAT fTop = | |
596 (FX_FLOAT)(((pRect->height - (bVert ? 6 : 9)) / 2 + pRect->top) + 0.5); | |
597 CFX_Path path; | |
598 path.Create(); | |
599 switch (eDict) { | |
600 case FWLTHEME_DIRECTION_Down: { | |
601 path.MoveTo(fLeft, fTop + 1); | |
602 path.LineTo(fLeft + 4, fTop + 5); | |
603 path.LineTo(fLeft + 8, fTop + 1); | |
604 path.LineTo(fLeft + 7, fTop); | |
605 path.LineTo(fLeft + 4, fTop + 3); | |
606 path.LineTo(fLeft + 1, fTop); | |
607 break; | |
608 } | |
609 case FWLTHEME_DIRECTION_Up: { | |
610 path.MoveTo(fLeft, fTop + 4); | |
611 path.LineTo(fLeft + 4, fTop); | |
612 path.LineTo(fLeft + 8, fTop + 4); | |
613 path.LineTo(fLeft + 7, fTop + 5); | |
614 path.LineTo(fLeft + 4, fTop + 2); | |
615 path.LineTo(fLeft + 1, fTop + 5); | |
616 break; | |
617 } | |
618 case FWLTHEME_DIRECTION_Right: { | |
619 path.MoveTo(fLeft + 1, fTop); | |
620 path.LineTo(fLeft + 5, fTop + 4); | |
621 path.LineTo(fLeft + 1, fTop + 8); | |
622 path.LineTo(fLeft, fTop + 7); | |
623 path.LineTo(fLeft + 3, fTop + 4); | |
624 path.LineTo(fLeft, fTop + 1); | |
625 break; | |
626 } | |
627 case FWLTHEME_DIRECTION_Left: { | |
628 path.MoveTo(fLeft, fTop + 4); | |
629 path.LineTo(fLeft + 4, fTop); | |
630 path.LineTo(fLeft + 5, fTop + 1); | |
631 path.LineTo(fLeft + 2, fTop + 4); | |
632 path.LineTo(fLeft + 5, fTop + 7); | |
633 path.LineTo(fLeft + 4, fTop + 8); | |
634 break; | |
635 } | |
636 } | |
637 CFX_Color cr(argSign); | |
638 pGraphics->SetFillColor(&cr); | |
639 pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); | |
640 } | |
641 void CFWL_WidgetTP::DrawBtn(CFX_Graphics* pGraphics, | |
642 const CFX_RectF* pRect, | |
643 FWLTHEME_STATE eState, | |
644 CFX_Matrix* pMatrix) { | |
645 CFX_Path path; | |
646 path.Create(); | |
647 if (!CFWL_ArrowData::IsInstance()) { | |
648 CFWL_ArrowData::GetInstance()->SetColorData(FWL_GetThemeColor(m_dwThemeID)); | |
649 } | |
650 CFWL_ArrowData::CColorData* pColorData = | |
651 CFWL_ArrowData::GetInstance()->m_pColorData; | |
652 FX_FLOAT fRight = pRect->right(); | |
653 FX_FLOAT fBottom = pRect->bottom(); | |
654 path.AddRectangle(pRect->left, pRect->top, pRect->width, pRect->height); | |
655 DrawAxialShading(pGraphics, pRect->left, pRect->top, fRight, fBottom, | |
656 pColorData->clrStart[eState - 1], | |
657 pColorData->clrEnd[eState - 1], &path, FXFILL_WINDING, | |
658 pMatrix); | |
659 CFX_Color rcStroke; | |
660 rcStroke.Set(pColorData->clrBorder[eState - 1]); | |
661 pGraphics->SetStrokeColor(&rcStroke); | |
662 pGraphics->StrokePath(&path, pMatrix); | |
663 } | |
664 void CFWL_WidgetTP::DrawArrowBtn(CFX_Graphics* pGraphics, | |
665 const CFX_RectF* pRect, | |
666 FWLTHEME_DIRECTION eDict, | |
667 FWLTHEME_STATE eState, | |
668 CFX_Matrix* pMatrix) { | |
669 DrawBtn(pGraphics, pRect, eState, pMatrix); | |
670 if (!CFWL_ArrowData::IsInstance()) { | |
671 CFWL_ArrowData::GetInstance()->SetColorData(FWL_GetThemeColor(m_dwThemeID)); | |
672 } | |
673 CFWL_ArrowData::CColorData* pColorData = | |
674 CFWL_ArrowData::GetInstance()->m_pColorData; | |
675 DrawArrow(pGraphics, pRect, eDict, pColorData->clrSign[eState - 1], pMatrix); | |
676 } | |
677 FWLCOLOR CFWL_WidgetTP::BlendColor(FWLCOLOR srcColor, | |
678 FWLCOLOR renderColor, | |
679 uint8_t scale) { | |
680 FWLCOLOR dstColor; | |
681 uint8_t n = 255 - scale; | |
682 dstColor.a = (uint8_t)( | |
683 ((uint16_t)srcColor.a * n + (uint16_t)renderColor.a * scale) >> 8); | |
684 dstColor.r = (uint8_t)( | |
685 ((uint16_t)srcColor.r * n + (uint16_t)renderColor.r * scale) >> 8); | |
686 dstColor.g = (uint8_t)( | |
687 ((uint16_t)srcColor.g * n + (uint16_t)renderColor.g * scale) >> 8); | |
688 dstColor.b = (uint8_t)( | |
689 ((uint16_t)srcColor.b * n + (uint16_t)renderColor.b * scale) >> 8); | |
690 return dstColor; | |
691 } | |
692 CFWL_ArrowData::CFWL_ArrowData() : m_pColorData(NULL) { | |
693 SetColorData(0); | |
694 } | |
695 CFWL_FontData::CFWL_FontData() | |
696 : m_dwStyles(0), | |
697 m_dwCodePage(0), | |
698 m_pFont(0), | |
699 m_pFontMgr(NULL) | |
700 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | |
701 , | |
702 m_pFontSource(NULL) | |
703 #endif | |
704 { | |
705 } | |
706 CFWL_FontData::~CFWL_FontData() { | |
707 if (m_pFont) { | |
708 m_pFont->Release(); | |
709 } | |
710 if (m_pFontMgr) { | |
711 m_pFontMgr->Release(); | |
712 } | |
713 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | |
714 if (m_pFontSource != NULL) { | |
715 m_pFontSource->Release(); | |
716 } | |
717 #endif | |
718 } | |
719 FX_BOOL CFWL_FontData::Equal(const CFX_WideStringC& wsFontFamily, | |
720 uint32_t dwFontStyles, | |
721 uint16_t wCodePage) { | |
722 return m_wsFamily == wsFontFamily && m_dwStyles == dwFontStyles && | |
723 m_dwCodePage == wCodePage; | |
724 } | |
725 FX_BOOL CFWL_FontData::LoadFont(const CFX_WideStringC& wsFontFamily, | |
726 uint32_t dwFontStyles, | |
727 uint16_t dwCodePage) { | |
728 m_wsFamily = wsFontFamily; | |
729 m_dwStyles = dwFontStyles; | |
730 m_dwCodePage = dwCodePage; | |
731 if (!m_pFontMgr) { | |
732 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | |
733 m_pFontMgr = IFX_FontMgr::Create(FX_GetDefFontEnumerator()); | |
734 #else | |
735 m_pFontSource = FX_CreateDefaultFontSourceEnum(); | |
736 m_pFontMgr = IFX_FontMgr::Create(m_pFontSource); | |
737 #endif | |
738 } | |
739 m_pFont = IFX_Font::LoadFont(wsFontFamily.GetPtr(), dwFontStyles, dwCodePage, | |
740 m_pFontMgr); | |
741 return m_pFont != NULL; | |
742 } | |
743 | |
744 CFWL_FontManager* CFWL_FontManager::s_FontManager = nullptr; | |
745 CFWL_FontManager* CFWL_FontManager::GetInstance() { | |
746 if (!s_FontManager) | |
747 s_FontManager = new CFWL_FontManager; | |
748 return s_FontManager; | |
749 } | |
750 void CFWL_FontManager::DestroyInstance() { | |
751 delete s_FontManager; | |
752 s_FontManager = nullptr; | |
753 } | |
754 CFWL_FontManager::CFWL_FontManager() {} | |
755 CFWL_FontManager::~CFWL_FontManager() {} | |
756 IFX_Font* CFWL_FontManager::FindFont(const CFX_WideStringC& wsFontFamily, | |
757 uint32_t dwFontStyles, | |
758 uint16_t wCodePage) { | |
759 for (const auto& pData : m_FontsArray) { | |
760 if (pData->Equal(wsFontFamily, dwFontStyles, wCodePage)) | |
761 return pData->GetFont(); | |
762 } | |
763 std::unique_ptr<CFWL_FontData> pFontData(new CFWL_FontData); | |
764 if (!pFontData->LoadFont(wsFontFamily, dwFontStyles, wCodePage)) | |
765 return nullptr; | |
766 m_FontsArray.push_back(std::move(pFontData)); | |
767 return m_FontsArray.back()->GetFont(); | |
768 } | |
769 FX_BOOL FWLTHEME_Init() { | |
770 return TRUE; | |
771 } | |
772 void FWLTHEME_Release() { | |
773 CFWL_ArrowData::DestroyInstance(); | |
774 CFWL_FontManager::DestroyInstance(); | |
775 } | |
776 uint32_t FWL_GetThemeLayout(uint32_t dwThemeID) { | |
777 return 0xffff0000 & dwThemeID; | |
778 } | |
779 uint32_t FWL_GetThemeColor(uint32_t dwThemeID) { | |
780 return 0x0000ffff & dwThemeID; | |
781 } | |
782 uint32_t FWL_MakeThemeID(uint32_t dwLayout, uint32_t dwColor) { | |
783 return (dwLayout << 16) | (0x0000FFFF & dwColor); | |
784 } | |
785 CFWL_ArrowData* CFWL_ArrowData::m_pInstance = NULL; | |
786 CFWL_ArrowData* CFWL_ArrowData::GetInstance() { | |
787 if (!m_pInstance) { | |
788 m_pInstance = new CFWL_ArrowData; | |
789 } | |
790 return m_pInstance; | |
791 } | |
792 FX_BOOL CFWL_ArrowData::IsInstance() { | |
793 return (m_pInstance != NULL); | |
794 } | |
795 void CFWL_ArrowData::DestroyInstance() { | |
796 if (m_pInstance) { | |
797 delete m_pInstance; | |
798 m_pInstance = NULL; | |
799 } | |
800 } | |
801 CFWL_ArrowData::~CFWL_ArrowData() { | |
802 if (m_pColorData) { | |
803 delete m_pColorData; | |
804 m_pColorData = NULL; | |
805 } | |
806 } | |
807 void CFWL_ArrowData::SetColorData(uint32_t dwID) { | |
808 if (!m_pColorData) { | |
809 m_pColorData = new CColorData; | |
810 } | |
811 if (dwID) { | |
812 m_pColorData->clrBorder[0] = ArgbEncode(255, 142, 153, 125); | |
813 m_pColorData->clrBorder[1] = ArgbEncode(255, 157, 171, 119); | |
814 m_pColorData->clrBorder[2] = ArgbEncode(255, 118, 131, 97); | |
815 m_pColorData->clrBorder[3] = ArgbEncode(255, 172, 168, 153); | |
816 m_pColorData->clrStart[0] = ArgbEncode(255, 203, 215, 186); | |
817 m_pColorData->clrStart[1] = ArgbEncode(255, 218, 232, 185); | |
818 m_pColorData->clrStart[2] = ArgbEncode(255, 203, 215, 186); | |
819 m_pColorData->clrStart[3] = ArgbEncode(255, 254, 254, 251); | |
820 m_pColorData->clrEnd[0] = ArgbEncode(255, 149, 167, 117); | |
821 m_pColorData->clrEnd[1] = ArgbEncode(255, 198, 211, 155); | |
822 m_pColorData->clrEnd[2] = ArgbEncode(255, 149, 167, 117); | |
823 m_pColorData->clrEnd[3] = ArgbEncode(255, 243, 241, 236); | |
824 m_pColorData->clrSign[0] = ArgbEncode(255, 255, 255, 255); | |
825 m_pColorData->clrSign[1] = ArgbEncode(255, 255, 255, 255); | |
826 m_pColorData->clrSign[2] = ArgbEncode(255, 255, 255, 255); | |
827 m_pColorData->clrSign[3] = ArgbEncode(255, 128, 128, 128); | |
828 } else { | |
829 m_pColorData->clrBorder[0] = ArgbEncode(255, 202, 216, 249); | |
830 m_pColorData->clrBorder[1] = ArgbEncode(255, 171, 190, 233); | |
831 m_pColorData->clrBorder[2] = ArgbEncode(255, 135, 147, 219); | |
832 m_pColorData->clrBorder[3] = ArgbEncode(255, 172, 168, 153); | |
833 m_pColorData->clrStart[0] = ArgbEncode(255, 225, 234, 254); | |
834 m_pColorData->clrStart[1] = ArgbEncode(255, 253, 255, 255); | |
835 m_pColorData->clrStart[2] = ArgbEncode(255, 110, 142, 241); | |
836 m_pColorData->clrStart[3] = ArgbEncode(255, 254, 254, 251); | |
837 m_pColorData->clrEnd[0] = ArgbEncode(255, 175, 204, 251); | |
838 m_pColorData->clrEnd[1] = ArgbEncode(255, 185, 218, 251); | |
839 m_pColorData->clrEnd[2] = ArgbEncode(255, 210, 222, 235); | |
840 m_pColorData->clrEnd[3] = ArgbEncode(255, 243, 241, 236); | |
841 m_pColorData->clrSign[0] = ArgbEncode(255, 77, 97, 133); | |
842 m_pColorData->clrSign[1] = ArgbEncode(255, 77, 97, 133); | |
843 m_pColorData->clrSign[2] = ArgbEncode(255, 77, 97, 133); | |
844 m_pColorData->clrSign[3] = ArgbEncode(255, 128, 128, 128); | |
845 } | |
846 } | |
OLD | NEW |