Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fwl / src / theme / edittp.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 CFWL_EditTP::CFWL_EditTP()\r
9 {\r
10 }\r
11 CFWL_EditTP::~CFWL_EditTP()\r
12 {\r
13 }\r
14 FX_BOOL CFWL_EditTP::IsValidWidget(IFWL_Widget *pWidget)\r
15 {\r
16     _FWL_RETURN_VALUE_IF_FAIL(pWidget, FALSE);\r
17     return pWidget->GetClassID() == FWL_CLASSHASH_Edit;\r
18 }\r
19 FX_BOOL CFWL_EditTP::DrawBackground(CFWL_ThemeBackground *pParams)\r
20 {\r
21     switch(pParams->m_iPart) {\r
22         case FWL_PART_EDT_Border: {\r
23                 DrawBorder(pParams->m_pGraphics, & pParams->m_rtPart, &pParams->m_matrix);\r
24                 break;\r
25             }\r
26         case FWL_PART_EDT_Edge: {\r
27                 DrawEdge(pParams->m_pGraphics, pParams->m_pWidget->GetStyles(), &pParams->m_rtPart, &pParams->m_matrix);\r
28                 break;\r
29             }\r
30         case FWL_PART_EDT_Background: {\r
31                 if (pParams->m_pPath) {\r
32                     CFX_Graphics *pGraphics = pParams->m_pGraphics;\r
33                     pGraphics->SaveGraphState();\r
34                     CFX_Color crSelected(FWL_GetThemeColor(m_dwThemeID) == 0 ? FWLTHEME_COLOR_BKSelected : FWLTHEME_COLOR_Green_BKSelected);\r
35                     pGraphics->SetFillColor(&crSelected);\r
36                     pGraphics->FillPath(pParams->m_pPath, FXFILL_WINDING, &pParams->m_matrix);\r
37                     pGraphics->RestoreGraphState();\r
38                 } else {\r
39                     FX_BOOL bStatic = pParams->m_dwData == FWL_PARTDATA_EDT_StaticBackground;\r
40                     CFX_Path path;\r
41                     path.Create();\r
42                     path.AddRectangle(pParams->m_rtPart.left, pParams->m_rtPart.top, pParams->m_rtPart.width, pParams->m_rtPart.height);\r
43                     CFX_Color cr(FWLTHEME_COLOR_Background);\r
44                     if (!bStatic) {\r
45                         if ((pParams->m_dwStates & FWL_PARTSTATE_EDT_Disable) == FWL_PARTSTATE_EDT_Disable) {\r
46                             cr.Set(FWLTHEME_COLOR_EDGERB1);\r
47                         } else if((pParams->m_dwStates & FWL_PARTSTATE_EDT_ReadOnly) == FWL_PARTSTATE_EDT_ReadOnly) {\r
48                             cr.Set(ArgbEncode(255, 236, 233, 216));\r
49                         } else {\r
50                             cr.Set(0xFFFFFFFF);\r
51                         }\r
52                     }\r
53                     pParams->m_pGraphics->SaveGraphState();\r
54                     pParams->m_pGraphics->SetFillColor(&cr);\r
55                     pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, &pParams->m_matrix);\r
56                     pParams->m_pGraphics->RestoreGraphState();\r
57                 }\r
58                 break;\r
59             }\r
60         case FWL_PART_EDT_CombTextLine: {\r
61                 FX_ARGB cr = 0xFF000000;\r
62                 FX_FLOAT fWidth = 1.0f;\r
63                 CFX_Color crLine(cr);\r
64                 pParams->m_pGraphics->SetStrokeColor(&crLine);\r
65                 pParams->m_pGraphics->SetLineWidth(fWidth);\r
66                 pParams->m_pGraphics->StrokePath(pParams->m_pPath, &pParams->m_matrix);\r
67                 break;\r
68             }\r
69         default: {\r
70                 break;\r
71             }\r
72     }\r
73     return TRUE;\r
74 }\r
75 FWL_ERR CFWL_EditTP::Initialize()\r
76 {\r
77     InitTTO();\r
78     return CFWL_WidgetTP::Initialize();\r
79 }\r
80 FWL_ERR CFWL_EditTP::Finalize()\r
81 {\r
82     FinalizeTTO();\r
83     return CFWL_WidgetTP::Finalize();\r
84 }\r