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_pushbuttontp.h"
8
9 #include "xfa/fwl/cfwl_pushbutton.h"
10 #include "xfa/fwl/cfwl_themebackground.h"
11 #include "xfa/fwl/cfwl_widget.h"
12 #include "xfa/fwl/ifwl_themeprovider.h"
13 #include "xfa/fxgraphics/cxfa_gecolor.h"
14 #include "xfa/fxgraphics/cxfa_gepath.h"
15
16 #define PUSHBUTTON_SIZE_Corner 2
17
CFWL_PushButtonTP()18 CFWL_PushButtonTP::CFWL_PushButtonTP() : m_pThemeData(new PBThemeData) {
19 SetThemeData();
20 }
21
~CFWL_PushButtonTP()22 CFWL_PushButtonTP::~CFWL_PushButtonTP() {}
23
DrawBackground(CFWL_ThemeBackground * pParams)24 void CFWL_PushButtonTP::DrawBackground(CFWL_ThemeBackground* pParams) {
25 switch (pParams->m_iPart) {
26 case CFWL_Part::Border: {
27 DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix);
28 break;
29 }
30 case CFWL_Part::Background: {
31 CFX_RectF& rect = pParams->m_rtPart;
32 float fRight = rect.right();
33 float fBottom = rect.bottom();
34
35 CXFA_GEPath strokePath;
36 strokePath.MoveTo(
37 CFX_PointF(rect.left + PUSHBUTTON_SIZE_Corner, rect.top));
38 strokePath.LineTo(CFX_PointF(fRight - PUSHBUTTON_SIZE_Corner, rect.top));
39 strokePath.LineTo(CFX_PointF(fRight, rect.top + PUSHBUTTON_SIZE_Corner));
40 strokePath.LineTo(CFX_PointF(fRight, fBottom - PUSHBUTTON_SIZE_Corner));
41 strokePath.LineTo(CFX_PointF(fRight - PUSHBUTTON_SIZE_Corner, fBottom));
42 strokePath.LineTo(
43 CFX_PointF(rect.left + PUSHBUTTON_SIZE_Corner, fBottom));
44 strokePath.LineTo(
45 CFX_PointF(rect.left, fBottom - PUSHBUTTON_SIZE_Corner));
46 strokePath.LineTo(
47 CFX_PointF(rect.left, rect.top + PUSHBUTTON_SIZE_Corner));
48 strokePath.LineTo(
49 CFX_PointF(rect.left + PUSHBUTTON_SIZE_Corner, rect.top));
50
51 CXFA_GEPath fillPath;
52 fillPath.AddSubpath(&strokePath);
53
54 CXFA_Graphics* pGraphics = pParams->m_pGraphics;
55 pGraphics->SaveGraphState();
56
57 CFX_RectF rtInner(rect);
58 rtInner.Deflate(PUSHBUTTON_SIZE_Corner + 1, PUSHBUTTON_SIZE_Corner + 1,
59 PUSHBUTTON_SIZE_Corner, PUSHBUTTON_SIZE_Corner);
60 fillPath.AddRectangle(rtInner.left, rtInner.top, rtInner.width,
61 rtInner.height);
62
63 int32_t iColor = GetColorID(pParams->m_dwStates);
64 DrawAxialShading(pGraphics, rect.left + PUSHBUTTON_SIZE_Corner, rect.top,
65 rect.left + PUSHBUTTON_SIZE_Corner, rect.bottom(),
66 m_pThemeData->clrStart[iColor],
67 m_pThemeData->clrEnd[iColor], &fillPath,
68 FXFILL_ALTERNATE, &pParams->m_matrix);
69
70 pGraphics->SetStrokeColor(CXFA_GEColor(m_pThemeData->clrBorder[iColor]));
71 pGraphics->StrokePath(&strokePath, &pParams->m_matrix);
72
73 fillPath.Clear();
74 fillPath.AddRectangle(rtInner.left, rtInner.top, rtInner.width,
75 rtInner.height);
76
77 pGraphics->SetFillColor(CXFA_GEColor(m_pThemeData->clrFill[iColor]));
78 pGraphics->FillPath(&fillPath, FXFILL_WINDING, &pParams->m_matrix);
79 if (pParams->m_dwStates & CFWL_PartState_Focused) {
80 rtInner.Inflate(1, 1, 0, 0);
81 DrawFocus(pGraphics, &rtInner, &pParams->m_matrix);
82 }
83 pGraphics->RestoreGraphState();
84 break;
85 }
86 default:
87 break;
88 }
89 }
90
SetThemeData()91 void CFWL_PushButtonTP::SetThemeData() {
92 m_pThemeData->clrBorder[0] = ArgbEncode(255, 0, 60, 116);
93 m_pThemeData->clrBorder[1] = ArgbEncode(255, 0, 60, 116);
94 m_pThemeData->clrBorder[2] = ArgbEncode(255, 0, 60, 116);
95 m_pThemeData->clrBorder[3] = ArgbEncode(255, 0, 60, 116);
96 m_pThemeData->clrBorder[4] = ArgbEncode(255, 201, 199, 186);
97 m_pThemeData->clrStart[0] = ArgbEncode(255, 255, 255, 255);
98 m_pThemeData->clrStart[1] = ArgbEncode(255, 209, 204, 193);
99 m_pThemeData->clrStart[2] = ArgbEncode(255, 255, 240, 207);
100 m_pThemeData->clrStart[3] = ArgbEncode(255, 206, 231, 255);
101 m_pThemeData->clrStart[4] = ArgbEncode(255, 245, 244, 234);
102 m_pThemeData->clrEnd[0] = ArgbEncode(255, 214, 208, 197);
103 m_pThemeData->clrEnd[1] = ArgbEncode(255, 242, 241, 238);
104 m_pThemeData->clrEnd[2] = ArgbEncode(255, 229, 151, 0);
105 m_pThemeData->clrEnd[3] = ArgbEncode(255, 105, 130, 238);
106 m_pThemeData->clrEnd[4] = ArgbEncode(255, 245, 244, 234);
107 m_pThemeData->clrFill[0] = ArgbEncode(255, 255, 255, 255);
108 m_pThemeData->clrFill[1] = ArgbEncode(255, 226, 225, 218);
109 m_pThemeData->clrFill[2] = ArgbEncode(255, 255, 255, 255);
110 m_pThemeData->clrFill[3] = ArgbEncode(255, 255, 255, 255);
111 m_pThemeData->clrFill[4] = ArgbEncode(255, 245, 244, 234);
112 }
113
GetColorID(uint32_t dwStates) const114 int32_t CFWL_PushButtonTP::GetColorID(uint32_t dwStates) const {
115 int32_t color = 0;
116 if (dwStates & CFWL_PartState_Disabled)
117 color += 4;
118 if (dwStates & CFWL_PartState_Default) {
119 color += 3;
120 } else {
121 if (dwStates & CFWL_PartState_Hovered)
122 color += 2;
123 if (dwStates & CFWL_PartState_Pressed)
124 color += 1;
125 }
126 return color;
127 }
128