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