Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fwl / src / theme / pushbuttontp.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../../foxitlib.h"\r
8 #define PUSHBUTTON_SIZE_Corner          2\r
9 CFWL_PushButtonTP::CFWL_PushButtonTP()\r
10 {\r
11     m_pThemeData = FX_NEW PBThemeData;\r
12     SetThemeData(0);\r
13 }\r
14 CFWL_PushButtonTP::~CFWL_PushButtonTP()\r
15 {\r
16     if (m_pThemeData) {\r
17         delete m_pThemeData;\r
18     }\r
19 }\r
20 FX_BOOL CFWL_PushButtonTP::IsValidWidget(IFWL_Widget *pWidget)\r
21 {\r
22     return pWidget->GetClassID() == FWL_CLASSHASH_PushButton;\r
23 }\r
24 FX_DWORD CFWL_PushButtonTP::SetThemeID(IFWL_Widget *pWidget, FX_DWORD dwThemeID, FX_BOOL bChildren )\r
25 {\r
26     SetThemeData(FWL_GetThemeColor(dwThemeID));\r
27     return CFWL_WidgetTP::SetThemeID(pWidget, dwThemeID, bChildren);\r
28 }\r
29 FX_BOOL CFWL_PushButtonTP::DrawBackground(CFWL_ThemeBackground *pParams)\r
30 {\r
31     switch(pParams->m_iPart) {\r
32         case FWL_PART_PSB_Border: {\r
33                 DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix);\r
34                 break;\r
35             }\r
36         case FWL_PART_PSB_Edge: {\r
37                 DrawEdge(pParams->m_pGraphics, pParams->m_pWidget->GetStyles(), &pParams->m_rtPart, &pParams->m_matrix);\r
38                 break;\r
39             }\r
40         case FWL_PART_PSB_Background: {\r
41                 CFX_RectF &rect = pParams->m_rtPart;\r
42                 FX_FLOAT fRight = rect.right();\r
43                 FX_FLOAT fBottom = rect.bottom();\r
44                 CFX_Path strokePath;\r
45                 strokePath.Create();\r
46                 strokePath.MoveTo(rect.left + PUSHBUTTON_SIZE_Corner, rect.top);\r
47                 strokePath.LineTo(fRight - PUSHBUTTON_SIZE_Corner, rect.top);\r
48                 strokePath.LineTo(fRight, rect.top + PUSHBUTTON_SIZE_Corner);\r
49                 strokePath.LineTo(fRight, fBottom - PUSHBUTTON_SIZE_Corner);\r
50                 strokePath.LineTo(fRight - PUSHBUTTON_SIZE_Corner, fBottom);\r
51                 strokePath.LineTo(rect.left + PUSHBUTTON_SIZE_Corner, fBottom);\r
52                 strokePath.LineTo(rect.left, fBottom - PUSHBUTTON_SIZE_Corner);\r
53                 strokePath.LineTo(rect.left, rect.top + PUSHBUTTON_SIZE_Corner);\r
54                 strokePath.LineTo(rect.left + PUSHBUTTON_SIZE_Corner, rect.top);\r
55                 CFX_Path fillPath;\r
56                 fillPath.Create();\r
57                 fillPath.AddSubpath(&strokePath);\r
58                 CFX_Graphics *pGraphics = pParams->m_pGraphics;\r
59                 pGraphics->SaveGraphState();\r
60                 CFX_RectF rtInner(rect);\r
61                 rtInner.Deflate(PUSHBUTTON_SIZE_Corner + 1,\r
62                                 PUSHBUTTON_SIZE_Corner + 1,\r
63                                 PUSHBUTTON_SIZE_Corner,\r
64                                 PUSHBUTTON_SIZE_Corner);\r
65                 fillPath.AddRectangle(rtInner.left, rtInner.top, rtInner.width, rtInner.height);\r
66                 FX_INT32 iColor = GetColorID(pParams->m_dwStates);\r
67                 DrawAxialShading(pGraphics,\r
68                                  rect.left + PUSHBUTTON_SIZE_Corner,\r
69                                  rect.top,\r
70                                  rect.left + PUSHBUTTON_SIZE_Corner,\r
71                                  rect.bottom(),\r
72                                  m_pThemeData->clrStart[iColor],\r
73                                  m_pThemeData->clrEnd[iColor],\r
74                                  &fillPath,\r
75                                  FXFILL_ALTERNATE,\r
76                                  &pParams->m_matrix);\r
77                 CFX_Color crStroke(m_pThemeData->clrBorder[iColor]);\r
78                 pGraphics->SetStrokeColor(&crStroke);\r
79                 pGraphics->StrokePath(&strokePath, &pParams->m_matrix);\r
80                 fillPath.Clear();\r
81                 fillPath.AddRectangle(rtInner.left, rtInner.top, rtInner.width, rtInner.height);\r
82                 CFX_Color crFill(m_pThemeData->clrFill[iColor]);\r
83                 pGraphics->SetFillColor(&crFill);\r
84                 pGraphics->FillPath(&fillPath, FXFILL_WINDING, &pParams->m_matrix);\r
85                 if (pParams->m_dwStates & FWL_PARTSTATE_PSB_Focused) {\r
86                     rtInner.Inflate(1, 1, 0, 0);\r
87                     DrawFocus(pGraphics, &rtInner, &pParams->m_matrix);\r
88                 }\r
89                 pGraphics->RestoreGraphState();\r
90                 break;\r
91             }\r
92         default: {\r
93             }\r
94     }\r
95     return TRUE;\r
96 }\r
97 FX_LPVOID CFWL_PushButtonTP::GetCapacity(CFWL_ThemePart *pThemePart, FX_DWORD dwCapacity)\r
98 {\r
99     if (dwCapacity == FWL_WGTCAPACITY_PSB_Margin) {\r
100         m_fValue = 0;\r
101         return &m_fValue;\r
102     }\r
103     return CFWL_WidgetTP::GetCapacity(pThemePart, dwCapacity);\r
104 }\r
105 FWL_ERR CFWL_PushButtonTP::Initialize()\r
106 {\r
107     InitTTO();\r
108     return CFWL_WidgetTP::Initialize();\r
109 }\r
110 FWL_ERR CFWL_PushButtonTP::Finalize()\r
111 {\r
112     FinalizeTTO();\r
113     return CFWL_WidgetTP::Finalize();\r
114 }\r
115 void CFWL_PushButtonTP::SetThemeData(FX_DWORD dwID)\r
116 {\r
117     FX_ARGB *pData = (FX_ARGB*)&*m_pThemeData;\r
118     if (dwID) {\r
119         m_pThemeData->clrBorder[0] = ArgbEncode(255, 55, 98, 6);\r
120         m_pThemeData->clrBorder[1] = ArgbEncode(255, 55, 98, 6);\r
121         m_pThemeData->clrBorder[2] = ArgbEncode(255, 55, 98, 6);\r
122         m_pThemeData->clrBorder[3] = ArgbEncode(255, 55, 98, 6);\r
123         m_pThemeData->clrBorder[4] = ArgbEncode(255, 172, 168, 153);\r
124         m_pThemeData->clrStart[0] = ArgbEncode(255, 255, 255, 246);\r
125         m_pThemeData->clrStart[1] = ArgbEncode(255, 223, 205, 180);\r
126         m_pThemeData->clrStart[2] = ArgbEncode(255, 252, 197, 149);\r
127         m_pThemeData->clrStart[3] = ArgbEncode(255, 194, 209, 143);\r
128         m_pThemeData->clrStart[4] = ArgbEncode(255, 216, 216, 216);\r
129         m_pThemeData->clrEnd[0] = ArgbEncode(255, 227, 209, 184);\r
130         m_pThemeData->clrEnd[1] = ArgbEncode(255, 248, 244, 228);\r
131         m_pThemeData->clrEnd[2] = ArgbEncode(255, 207, 114, 37);\r
132         m_pThemeData->clrEnd[3] = ArgbEncode(255, 144, 193, 84);\r
133         m_pThemeData->clrEnd[4] = ArgbEncode(255, 172, 168, 153);\r
134         m_pThemeData->clrFill[0] = ArgbEncode(255, 255, 255, 255);\r
135         m_pThemeData->clrFill[1] = ArgbEncode(255, 226, 225, 218);\r
136         m_pThemeData->clrFill[2] = ArgbEncode(255, 255, 255, 255);\r
137         m_pThemeData->clrFill[3] = ArgbEncode(255, 255, 255, 255);\r
138         m_pThemeData->clrFill[4] = ArgbEncode(255, 245, 244, 234);\r
139     } else {\r
140         m_pThemeData->clrBorder[0] = ArgbEncode(255, 0, 60, 116);\r
141         m_pThemeData->clrBorder[1] = ArgbEncode(255, 0, 60, 116);\r
142         m_pThemeData->clrBorder[2] = ArgbEncode(255, 0, 60, 116);\r
143         m_pThemeData->clrBorder[3] = ArgbEncode(255, 0, 60, 116);\r
144         m_pThemeData->clrBorder[4] = ArgbEncode(255, 201, 199, 186);\r
145         m_pThemeData->clrStart[0] = ArgbEncode(255, 255, 255, 255);\r
146         m_pThemeData->clrStart[1] = ArgbEncode(255, 209, 204, 193);\r
147         m_pThemeData->clrStart[2] = ArgbEncode(255, 255, 240, 207);\r
148         m_pThemeData->clrStart[3] = ArgbEncode(255, 206, 231, 255);\r
149         m_pThemeData->clrStart[4] = ArgbEncode(255, 245, 244, 234);\r
150         m_pThemeData->clrEnd[0] = ArgbEncode(255, 214, 208, 197);\r
151         m_pThemeData->clrEnd[1] = ArgbEncode(255, 242, 241, 238);\r
152         m_pThemeData->clrEnd[2] = ArgbEncode(255, 229, 151, 0);\r
153         m_pThemeData->clrEnd[3] = ArgbEncode(255, 105, 130, 238);\r
154         m_pThemeData->clrEnd[4] = ArgbEncode(255, 245, 244, 234);\r
155         m_pThemeData->clrFill[0] = ArgbEncode(255, 255, 255, 255);\r
156         m_pThemeData->clrFill[1] = ArgbEncode(255, 226, 225, 218);\r
157         m_pThemeData->clrFill[2] = ArgbEncode(255, 255, 255, 255);\r
158         m_pThemeData->clrFill[3] = ArgbEncode(255, 255, 255, 255);\r
159         m_pThemeData->clrFill[4] = ArgbEncode(255, 245, 244, 234);\r
160     }\r
161 }\r
162 FX_INT32 CFWL_PushButtonTP::GetColorID(FX_DWORD dwStates)\r
163 {\r
164     return dwStates &= FWL_PARTSTATE_PSB_Mask;\r
165 }\r