Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Side by Side Diff: xfa/src/fxfa/app/xfa_fwltheme.cpp

Issue 1803723002: Move xfa/src up to xfa/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/src/fxfa/app/xfa_fwltheme.h ('k') | xfa/src/fxfa/app/xfa_rendercontext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/src/fxfa/app/xfa_fwltheme.h"
8
9 #include "xfa/include/fwl/basewidget/fwl_barcode.h"
10 #include "xfa/include/fwl/basewidget/fwl_caret.h"
11 #include "xfa/include/fwl/basewidget/fwl_checkbox.h"
12 #include "xfa/include/fwl/basewidget/fwl_combobox.h"
13 #include "xfa/include/fwl/basewidget/fwl_datetimepicker.h"
14 #include "xfa/include/fwl/basewidget/fwl_edit.h"
15 #include "xfa/include/fwl/basewidget/fwl_listbox.h"
16 #include "xfa/include/fwl/basewidget/fwl_monthcalendar.h"
17 #include "xfa/include/fwl/basewidget/fwl_picturebox.h"
18 #include "xfa/include/fwl/basewidget/fwl_pushbutton.h"
19 #include "xfa/include/fwl/basewidget/fwl_scrollbar.h"
20 #include "xfa/src/fde/tto/fde_textout.h"
21 #include "xfa/src/fgas/crt/fgas_codepage.h"
22 #include "xfa/src/fxfa/app/xfa_ffapp.h"
23 #include "xfa/src/fxfa/app/xfa_ffwidget.h"
24
25 CXFA_FFWidget* XFA_ThemeGetOuterWidget(IFWL_Widget* pWidget) {
26 IFWL_Widget* pOuter = pWidget;
27 while (pOuter->GetOuter()) {
28 pOuter = pOuter->GetOuter();
29 }
30 if (pOuter) {
31 return (CXFA_FFWidget*)pOuter->GetPrivateData(pOuter);
32 }
33 return NULL;
34 }
35 CXFA_FWLTheme::CXFA_FWLTheme(CXFA_FFApp* pApp) : m_pApp(pApp) {
36 m_pTextOut = NULL;
37 m_dwCapacity = 0;
38 m_fCapacity = 0;
39 m_pCalendarFont = NULL;
40 m_Rect.Set(0, 0, 0, 0);
41 m_pCheckBoxTP = new CXFA_FWLCheckBoxTP;
42 m_pListBoxTP = new CFWL_ListBoxTP;
43 m_pPictureBoxTP = new CFWL_PictureBoxTP;
44 m_pSrollBarTP = new CFWL_ScrollBarTP;
45 m_pEditTP = new CXFA_FWLEditTP;
46 m_pComboBoxTP = new CFWL_ComboBoxTP;
47 m_pMonthCalendarTP = new CFWL_MonthCalendarTP;
48 m_pDateTimePickerTP = new CFWL_DateTimePickerTP;
49 m_pPushButtonTP = new CFWL_PushButtonTP;
50 m_pCaretTP = new CFWL_CaretTP;
51 m_pBarcodeTP = new CFWL_BarcodeTP;
52 Initialize();
53 }
54 CXFA_FWLTheme::~CXFA_FWLTheme() {
55 Finalize();
56 delete m_pCheckBoxTP;
57 delete m_pListBoxTP;
58 delete m_pPictureBoxTP;
59 delete m_pSrollBarTP;
60 delete m_pEditTP;
61 delete m_pComboBoxTP;
62 delete m_pMonthCalendarTP;
63 delete m_pDateTimePickerTP;
64 delete m_pPushButtonTP;
65 delete m_pCaretTP;
66 delete m_pBarcodeTP;
67 }
68 static const FX_WCHAR* g_FWLTheme_CalFonts[] = {
69 L"Arial", L"Courier New", L"DejaVu Sans",
70 };
71 FWL_ERR CXFA_FWLTheme::Initialize() {
72 m_pTextOut = IFDE_TextOut::Create();
73 for (size_t i = 0; !m_pCalendarFont && i < FX_ArraySize(g_FWLTheme_CalFonts);
74 ++i) {
75 m_pCalendarFont = IFX_Font::LoadFont(g_FWLTheme_CalFonts[i], 0, 0,
76 m_pApp->GetFDEFontMgr());
77 }
78 if (!m_pCalendarFont) {
79 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
80 m_pCalendarFont = m_pApp->GetFDEFontMgr()->GetDefFontByCodePage(
81 FX_CODEPAGE_MSWin_WesternEuropean, 0, NULL);
82 #else
83 m_pCalendarFont = m_pApp->GetFDEFontMgr()->GetFontByCodePage(
84 FX_CODEPAGE_MSWin_WesternEuropean, 0, NULL);
85 #endif
86 }
87
88 FXSYS_assert(NULL != m_pCalendarFont);
89 FWLTHEME_Init();
90 return FWL_ERR_Succeeded;
91 }
92 FWL_ERR CXFA_FWLTheme::Finalize() {
93 if (m_pTextOut) {
94 m_pTextOut->Release();
95 m_pTextOut = NULL;
96 }
97 if (m_pCalendarFont) {
98 m_pCalendarFont->Release();
99 m_pCalendarFont = NULL;
100 }
101 FWLTHEME_Release();
102 return FWL_ERR_Succeeded;
103 }
104 FX_BOOL CXFA_FWLTheme::IsValidWidget(IFWL_Widget* pWidget) {
105 return TRUE;
106 }
107 FX_DWORD CXFA_FWLTheme::GetThemeID(IFWL_Widget* pWidget) {
108 return 0;
109 }
110 FX_DWORD CXFA_FWLTheme::SetThemeID(IFWL_Widget* pWidget,
111 FX_DWORD dwThemeID,
112 FX_BOOL bChildren) {
113 return 0;
114 }
115 FX_BOOL CXFA_FWLTheme::DrawBackground(CFWL_ThemeBackground* pParams) {
116 return GetTheme(pParams->m_pWidget)->DrawBackground(pParams);
117 }
118 FX_BOOL CXFA_FWLTheme::DrawText(CFWL_ThemeText* pParams) {
119 if (pParams->m_wsText.IsEmpty()) {
120 return FWL_ERR_Indefinite;
121 }
122 if (pParams->m_pWidget->GetClassID() == FWL_CLASSHASH_MonthCalendar) {
123 CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget);
124 if (!pWidget) {
125 return FWL_ERR_Indefinite;
126 }
127 m_pTextOut->SetStyles(pParams->m_dwTTOStyles);
128 m_pTextOut->SetAlignment(pParams->m_iTTOAlign);
129 m_pTextOut->SetFont(m_pCalendarFont);
130 m_pTextOut->SetFontSize(FWLTHEME_CAPACITY_FontSize);
131 m_pTextOut->SetTextColor(FWLTHEME_CAPACITY_TextColor);
132 if ((pParams->m_iPart == FWL_PART_MCD_DatesIn) &&
133 !(pParams->m_dwStates & FWL_ITEMSTATE_MCD_Flag) &&
134 (pParams->m_dwStates &
135 (FWL_PARTSTATE_MCD_Hovered | FWL_PARTSTATE_MCD_Selected))) {
136 m_pTextOut->SetTextColor(0xFFFFFFFF);
137 }
138 if (pParams->m_iPart == FWL_PART_MCD_Caption) {
139 if (m_pMonthCalendarTP->GetThemeID(pParams->m_pWidget) == 0) {
140 m_pTextOut->SetTextColor(ArgbEncode(0xff, 0, 153, 255));
141 } else {
142 m_pTextOut->SetTextColor(ArgbEncode(0xff, 128, 128, 0));
143 }
144 }
145 CFX_Graphics* pGraphics = pParams->m_pGraphics;
146 CFX_RenderDevice* pRenderDevice = pGraphics->GetRenderDevice();
147 if (!pRenderDevice)
148 return FALSE;
149 m_pTextOut->SetRenderDevice(pRenderDevice);
150 CFX_Matrix mtPart = pParams->m_matrix;
151 CFX_Matrix* pMatrix = pGraphics->GetMatrix();
152 if (pMatrix) {
153 mtPart.Concat(*pMatrix);
154 }
155 m_pTextOut->SetMatrix(mtPart);
156 m_pTextOut->DrawLogicText(pParams->m_wsText, pParams->m_wsText.GetLength(),
157 pParams->m_rtPart);
158 return TRUE;
159 }
160 CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget);
161 if (!pWidget) {
162 return FWL_ERR_Indefinite;
163 }
164 CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc();
165 CFX_Graphics* pGraphics = pParams->m_pGraphics;
166 CFX_RenderDevice* pRenderDevice = pGraphics->GetRenderDevice();
167 if (!pRenderDevice)
168 return FALSE;
169 m_pTextOut->SetRenderDevice(pRenderDevice);
170 m_pTextOut->SetStyles(pParams->m_dwTTOStyles);
171 m_pTextOut->SetAlignment(pParams->m_iTTOAlign);
172 m_pTextOut->SetFont(pAcc->GetFDEFont());
173 m_pTextOut->SetFontSize(pAcc->GetFontSize());
174 m_pTextOut->SetTextColor(pAcc->GetTextColor());
175 CFX_Matrix mtPart = pParams->m_matrix;
176 CFX_Matrix* pMatrix = pGraphics->GetMatrix();
177 if (pMatrix) {
178 mtPart.Concat(*pMatrix);
179 }
180 m_pTextOut->SetMatrix(mtPart);
181 m_pTextOut->DrawLogicText(pParams->m_wsText, pParams->m_wsText.GetLength(),
182 pParams->m_rtPart);
183 return TRUE;
184 }
185 void* CXFA_FWLTheme::GetCapacity(CFWL_ThemePart* pThemePart,
186 FX_DWORD dwCapacity) {
187 switch (dwCapacity) {
188 case FWL_WGTCAPACITY_Font: {
189 if (CXFA_FFWidget* pWidget =
190 XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) {
191 return pWidget->GetDataAcc()->GetFDEFont();
192 }
193 } break;
194 case FWL_WGTCAPACITY_FontSize: {
195 if (CXFA_FFWidget* pWidget =
196 XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) {
197 m_fCapacity = pWidget->GetDataAcc()->GetFontSize();
198 return &m_fCapacity;
199 }
200 } break;
201 case FWL_WGTCAPACITY_TextColor: {
202 if (CXFA_FFWidget* pWidget =
203 XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) {
204 m_dwCapacity = pWidget->GetDataAcc()->GetTextColor();
205 return &m_dwCapacity;
206 }
207 } break;
208 case FWL_WGTCAPACITY_LineHeight: {
209 if (CXFA_FFWidget* pWidget =
210 XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) {
211 m_fCapacity = pWidget->GetDataAcc()->GetLineHeight();
212 return &m_fCapacity;
213 }
214 } break;
215 case FWL_WGTCAPACITY_ScrollBarWidth: {
216 m_fCapacity = 9;
217 return &m_fCapacity;
218 } break;
219 case FWL_WGTCAPACITY_UIMargin: {
220 CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget);
221 if (pWidget) {
222 CXFA_LayoutItem* pItem = pWidget;
223 CXFA_WidgetAcc* pWidgetAcc = pWidget->GetDataAcc();
224 pWidgetAcc->GetUIMargin(m_Rect);
225 if (CXFA_Para para = pWidgetAcc->GetPara()) {
226 m_Rect.left += para.GetMarginLeft();
227 if (pWidgetAcc->IsMultiLine()) {
228 m_Rect.width += para.GetMarginRight();
229 }
230 }
231 if (pItem->GetPrev() == NULL) {
232 if (pItem->GetNext()) {
233 m_Rect.height = 0;
234 }
235 } else if (pItem->GetNext() == NULL) {
236 m_Rect.top = 0;
237 } else {
238 m_Rect.top = 0;
239 m_Rect.height = 0;
240 }
241 }
242 return &m_Rect;
243 } break;
244 case FWL_WGTCAPACITY_SpaceAboveBelow: {
245 CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pThemePart->m_pWidget);
246 if (pWidget) {
247 CXFA_WidgetAcc* pWidgetAcc = pWidget->GetDataAcc();
248 if (CXFA_Para para = pWidgetAcc->GetPara()) {
249 m_SizeAboveBelow.x = para.GetSpaceAbove();
250 m_SizeAboveBelow.y = para.GetSpaceBelow();
251 }
252 }
253 return &m_SizeAboveBelow;
254 } break;
255 default:
256 break;
257 }
258 if (pThemePart->m_pWidget->GetClassID() == FWL_CLASSHASH_MonthCalendar &&
259 dwCapacity >= FWL_MCCAPACITY_Sun && dwCapacity <= FWL_MCCAPACITY_Today) {
260 if (CXFA_FFWidget* pWidget =
261 XFA_ThemeGetOuterWidget(pThemePart->m_pWidget)) {
262 IXFA_AppProvider* pAppProvider = pWidget->GetAppProvider();
263 m_wsResource.Empty();
264 pAppProvider->LoadString(
265 XFA_IDS_StringWeekDay_Sun + dwCapacity - FWL_WGTCAPACITY_MAX - 5,
266 m_wsResource);
267 if (!m_wsResource.IsEmpty()) {
268 return &m_wsResource;
269 }
270 }
271 }
272 return GetTheme(pThemePart->m_pWidget)->GetCapacity(pThemePart, dwCapacity);
273 }
274 FX_BOOL CXFA_FWLTheme::IsCustomizedLayout(IFWL_Widget* pWidget) {
275 return GetTheme(pWidget)->IsCustomizedLayout(pWidget);
276 }
277 FWL_ERR CXFA_FWLTheme::GetPartRect(CFWL_ThemePart* pThemePart) {
278 CFX_RectF rect;
279 return GetTheme(pThemePart->m_pWidget)->GetPartRect(pThemePart, rect);
280 }
281 FX_BOOL CXFA_FWLTheme::IsInPart(CFWL_ThemePart* pThemePart,
282 FX_FLOAT fx,
283 FX_FLOAT fy) {
284 return GetTheme(pThemePart->m_pWidget)->IsInPart(pThemePart, fx, fy);
285 }
286 FX_BOOL CXFA_FWLTheme::CalcTextRect(CFWL_ThemeText* pParams, CFX_RectF& rect) {
287 if (pParams->m_pWidget->GetClassID() == FWL_CLASSHASH_MonthCalendar) {
288 CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget);
289 if (!pWidget) {
290 return FWL_ERR_Indefinite;
291 }
292 if (!pParams)
293 return FALSE;
294 if (!m_pTextOut)
295 return FALSE;
296 m_pTextOut->SetFont(m_pCalendarFont);
297 m_pTextOut->SetFontSize(FWLTHEME_CAPACITY_FontSize);
298 m_pTextOut->SetTextColor(FWLTHEME_CAPACITY_TextColor);
299 m_pTextOut->SetAlignment(pParams->m_iTTOAlign);
300 m_pTextOut->SetStyles(pParams->m_dwTTOStyles);
301 m_pTextOut->CalcLogicSize(pParams->m_wsText, pParams->m_wsText.GetLength(),
302 rect);
303 return TRUE;
304 }
305 CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget);
306 if (!pWidget) {
307 return FWL_ERR_Indefinite;
308 }
309 CXFA_WidgetAcc* pAcc = pWidget->GetDataAcc();
310 m_pTextOut->SetFont(pAcc->GetFDEFont());
311 m_pTextOut->SetFontSize(pAcc->GetFontSize());
312 m_pTextOut->SetTextColor(pAcc->GetTextColor());
313 if (!pParams)
314 return FALSE;
315 if (!m_pTextOut)
316 return FALSE;
317 m_pTextOut->SetAlignment(pParams->m_iTTOAlign);
318 m_pTextOut->SetStyles(pParams->m_dwTTOStyles);
319 m_pTextOut->CalcLogicSize(pParams->m_wsText, pParams->m_wsText.GetLength(),
320 rect);
321 return TRUE;
322 }
323 CFWL_WidgetTP* CXFA_FWLTheme::GetTheme(IFWL_Widget* pWidget) {
324 switch (pWidget->GetClassID()) {
325 case FWL_CLASSHASH_CheckBox:
326 return m_pCheckBoxTP;
327 case FWL_CLASSHASH_ListBox:
328 return m_pListBoxTP;
329 case FWL_CLASSHASH_PictureBox:
330 return m_pPictureBoxTP;
331 case FWL_CLASSHASH_ScrollBar:
332 return m_pSrollBarTP;
333 case FWL_CLASSHASH_Edit:
334 return m_pEditTP;
335 case FWL_CLASSHASH_ComboBox:
336 return m_pComboBoxTP;
337 case FWL_CLASSHASH_MonthCalendar:
338 return m_pMonthCalendarTP;
339 case FWL_CLASSHASH_DateTimePicker:
340 return m_pDateTimePickerTP;
341 case FWL_CLASSHASH_PushButton:
342 return m_pPushButtonTP;
343 case FWL_CLASSHASH_Caret:
344 return m_pCaretTP;
345 case FWL_CLASSHASH_Barcode:
346 return m_pBarcodeTP;
347 default:
348 break;
349 }
350 return NULL;
351 }
352 CXFA_FWLCheckBoxTP::CXFA_FWLCheckBoxTP() {}
353 FX_BOOL CXFA_FWLCheckBoxTP::DrawBackground(CFWL_ThemeBackground* pParams) {
354 if (pParams->m_iPart != FWL_PART_CKB_CheckBox) {
355 return TRUE;
356 }
357 if (((pParams->m_dwStates & FWL_PARTSTATE_CKB_Mask2) ==
358 FWL_PARTSTATE_CKB_Checked) ||
359 ((pParams->m_dwStates & FWL_PARTSTATE_CKB_Mask2) ==
360 FWL_PARTSTATE_CKB_Neutral)) {
361 DrawCheckSign(pParams->m_pWidget, pParams->m_pGraphics, &pParams->m_rtPart,
362 pParams->m_dwStates, &pParams->m_matrix);
363 }
364 return TRUE;
365 }
366 void CXFA_FWLCheckBoxTP::DrawCheckSign(IFWL_Widget* pWidget,
367 CFX_Graphics* pGraphics,
368 const CFX_RectF* pRtBox,
369 int32_t iState,
370 CFX_Matrix* pMatrix) {
371 CFX_RectF rtSign(*pRtBox);
372 FX_DWORD dwColor = 0xFF000000;
373 if ((iState & FWL_PARTSTATE_CKB_Mask2) == FWL_PARTSTATE_CKB_Neutral) {
374 dwColor = 0xFFA9A9A9;
375 }
376 {
377 FX_DWORD dwStyle = pWidget->GetStylesEx();
378 rtSign.Deflate(rtSign.width / 4, rtSign.height / 4);
379 switch (dwStyle & FWL_STYLEEXT_CKB_SignShapeMask) {
380 case FWL_STYLEEXT_CKB_SignShapeCheck:
381 DrawSignCheck(pGraphics, &rtSign, dwColor, pMatrix);
382 break;
383 case FWL_STYLEEXT_CKB_SignShapeCircle:
384 DrawSignCircle(pGraphics, &rtSign, dwColor, pMatrix);
385 break;
386 case FWL_STYLEEXT_CKB_SignShapeCross:
387 DrawSignCross(pGraphics, &rtSign, dwColor, pMatrix);
388 break;
389 case FWL_STYLEEXT_CKB_SignShapeDiamond:
390 DrawSignDiamond(pGraphics, &rtSign, dwColor, pMatrix);
391 break;
392 case FWL_STYLEEXT_CKB_SignShapeSquare:
393 DrawSignSquare(pGraphics, &rtSign, dwColor, pMatrix);
394 break;
395 case FWL_STYLEEXT_CKB_SignShapeStar:
396 DrawSignStar(pGraphics, &rtSign, dwColor, pMatrix);
397 break;
398 default:
399 break;
400 }
401 }
402 }
403 CXFA_FWLEditTP::CXFA_FWLEditTP() {}
404 CXFA_FWLEditTP::~CXFA_FWLEditTP() {}
405 FX_BOOL CXFA_FWLEditTP::DrawBackground(CFWL_ThemeBackground* pParams) {
406 if (FWL_PART_EDT_CombTextLine == pParams->m_iPart) {
407 CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget);
408 FX_ARGB cr = 0xFF000000;
409 FX_FLOAT fWidth = 1.0f;
410 if (CXFA_Border borderUI = pWidget->GetDataAcc()->GetUIBorder()) {
411 CXFA_Edge edge = borderUI.GetEdge(0);
412 if (edge) {
413 cr = edge.GetColor();
414 fWidth = edge.GetThickness();
415 }
416 }
417 CFX_Color crLine(cr);
418 pParams->m_pGraphics->SetStrokeColor(&crLine);
419 pParams->m_pGraphics->SetLineWidth(fWidth);
420 pParams->m_pGraphics->StrokePath(pParams->m_pPath, &pParams->m_matrix);
421 return TRUE;
422 }
423 return CFWL_EditTP::DrawBackground(pParams);
424 }
OLDNEW
« no previous file with comments | « xfa/src/fxfa/app/xfa_fwltheme.h ('k') | xfa/src/fxfa/app/xfa_rendercontext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698