• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/cfx_color.h"
14 #include "xfa/fxgraphics/cfx_path.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       FX_FLOAT fRight = rect.right();
33       FX_FLOAT fBottom = rect.bottom();
34 
35       CFX_Path 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       CFX_Path fillPath;
52       fillPath.AddSubpath(&strokePath);
53 
54       CFX_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       CFX_Color crStroke(m_pThemeData->clrBorder[iColor]);
71       pGraphics->SetStrokeColor(&crStroke);
72       pGraphics->StrokePath(&strokePath, &pParams->m_matrix);
73 
74       fillPath.Clear();
75       fillPath.AddRectangle(rtInner.left, rtInner.top, rtInner.width,
76                             rtInner.height);
77 
78       CFX_Color crFill(m_pThemeData->clrFill[iColor]);
79       pGraphics->SetFillColor(&crFill);
80       pGraphics->FillPath(&fillPath, FXFILL_WINDING, &pParams->m_matrix);
81       if (pParams->m_dwStates & CFWL_PartState_Focused) {
82         rtInner.Inflate(1, 1, 0, 0);
83         DrawFocus(pGraphics, &rtInner, &pParams->m_matrix);
84       }
85       pGraphics->RestoreGraphState();
86       break;
87     }
88     default:
89       break;
90   }
91 }
92 
SetThemeData()93 void CFWL_PushButtonTP::SetThemeData() {
94   m_pThemeData->clrBorder[0] = ArgbEncode(255, 0, 60, 116);
95   m_pThemeData->clrBorder[1] = ArgbEncode(255, 0, 60, 116);
96   m_pThemeData->clrBorder[2] = ArgbEncode(255, 0, 60, 116);
97   m_pThemeData->clrBorder[3] = ArgbEncode(255, 0, 60, 116);
98   m_pThemeData->clrBorder[4] = ArgbEncode(255, 201, 199, 186);
99   m_pThemeData->clrStart[0] = ArgbEncode(255, 255, 255, 255);
100   m_pThemeData->clrStart[1] = ArgbEncode(255, 209, 204, 193);
101   m_pThemeData->clrStart[2] = ArgbEncode(255, 255, 240, 207);
102   m_pThemeData->clrStart[3] = ArgbEncode(255, 206, 231, 255);
103   m_pThemeData->clrStart[4] = ArgbEncode(255, 245, 244, 234);
104   m_pThemeData->clrEnd[0] = ArgbEncode(255, 214, 208, 197);
105   m_pThemeData->clrEnd[1] = ArgbEncode(255, 242, 241, 238);
106   m_pThemeData->clrEnd[2] = ArgbEncode(255, 229, 151, 0);
107   m_pThemeData->clrEnd[3] = ArgbEncode(255, 105, 130, 238);
108   m_pThemeData->clrEnd[4] = ArgbEncode(255, 245, 244, 234);
109   m_pThemeData->clrFill[0] = ArgbEncode(255, 255, 255, 255);
110   m_pThemeData->clrFill[1] = ArgbEncode(255, 226, 225, 218);
111   m_pThemeData->clrFill[2] = ArgbEncode(255, 255, 255, 255);
112   m_pThemeData->clrFill[3] = ArgbEncode(255, 255, 255, 255);
113   m_pThemeData->clrFill[4] = ArgbEncode(255, 245, 244, 234);
114 }
115 
GetColorID(uint32_t dwStates) const116 int32_t CFWL_PushButtonTP::GetColorID(uint32_t dwStates) const {
117   int32_t color = 0;
118   if (dwStates & CFWL_PartState_Disabled)
119     color += 4;
120   if (dwStates & CFWL_PartState_Default) {
121     color += 3;
122   } else {
123     if (dwStates & CFWL_PartState_Hovered)
124       color += 2;
125     if (dwStates & CFWL_PartState_Pressed)
126       color += 1;
127   }
128   return color;
129 }
130