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/fwl/theme/cfwl_edittp.h"
8 
9 #include "xfa/fwl/cfwl_edit.h"
10 #include "xfa/fwl/cfwl_themebackground.h"
11 #include "xfa/fwl/cfwl_widget.h"
12 #include "xfa/fxfa/cxfa_ffwidget.h"
13 #include "xfa/fxfa/cxfa_fwltheme.h"
14 #include "xfa/fxfa/parser/cxfa_border.h"
15 #include "xfa/fxfa/parser/cxfa_edge.h"
16 #include "xfa/fxgraphics/cxfa_gecolor.h"
17 #include "xfa/fxgraphics/cxfa_gepath.h"
18 
CFWL_EditTP()19 CFWL_EditTP::CFWL_EditTP() {}
20 
~CFWL_EditTP()21 CFWL_EditTP::~CFWL_EditTP() {}
22 
DrawBackground(CFWL_ThemeBackground * pParams)23 void CFWL_EditTP::DrawBackground(CFWL_ThemeBackground* pParams) {
24   if (CFWL_Part::CombTextLine == pParams->m_iPart) {
25     CXFA_FFWidget* pWidget = XFA_ThemeGetOuterWidget(pParams->m_pWidget);
26     CXFA_Border* borderUI = pWidget->GetNode()->GetWidgetAcc()->GetUIBorder();
27     FX_ARGB cr = 0xFF000000;
28     float fWidth = 1.0f;
29     if (borderUI) {
30       CXFA_Edge* edge = borderUI->GetEdgeIfExists(0);
31       if (edge) {
32         cr = edge->GetColor();
33         fWidth = edge->GetThickness();
34       }
35     }
36     pParams->m_pGraphics->SetStrokeColor(CXFA_GEColor(cr));
37     pParams->m_pGraphics->SetLineWidth(fWidth);
38     pParams->m_pGraphics->StrokePath(pParams->m_pPath, &pParams->m_matrix);
39     return;
40   }
41 
42   switch (pParams->m_iPart) {
43     case CFWL_Part::Border: {
44       DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix);
45       break;
46     }
47     case CFWL_Part::Background: {
48       if (pParams->m_pPath) {
49         CXFA_Graphics* pGraphics = pParams->m_pGraphics;
50         pGraphics->SaveGraphState();
51         pGraphics->SetFillColor(CXFA_GEColor(FWLTHEME_COLOR_BKSelected));
52         pGraphics->FillPath(pParams->m_pPath, FXFILL_WINDING,
53                             &pParams->m_matrix);
54         pGraphics->RestoreGraphState();
55       } else {
56         CXFA_GEPath path;
57         path.AddRectangle(pParams->m_rtPart.left, pParams->m_rtPart.top,
58                           pParams->m_rtPart.width, pParams->m_rtPart.height);
59         CXFA_GEColor cr(FWLTHEME_COLOR_Background);
60         if (!pParams->m_bStaticBackground) {
61           if (pParams->m_dwStates & CFWL_PartState_Disabled)
62             cr = CXFA_GEColor(FWLTHEME_COLOR_EDGERB1);
63           else if (pParams->m_dwStates & CFWL_PartState_ReadOnly)
64             cr = CXFA_GEColor(ArgbEncode(255, 236, 233, 216));
65           else
66             cr = CXFA_GEColor(0xFFFFFFFF);
67         }
68         pParams->m_pGraphics->SaveGraphState();
69         pParams->m_pGraphics->SetFillColor(cr);
70         pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING,
71                                        &pParams->m_matrix);
72         pParams->m_pGraphics->RestoreGraphState();
73       }
74       break;
75     }
76     case CFWL_Part::CombTextLine: {
77       pParams->m_pGraphics->SetStrokeColor(CXFA_GEColor(0xFF000000));
78       pParams->m_pGraphics->SetLineWidth(1.0f);
79       pParams->m_pGraphics->StrokePath(pParams->m_pPath, &pParams->m_matrix);
80       break;
81     }
82     default:
83       break;
84   }
85 }
86