Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[pdfium.git] / xfa / src / fwl / src / theme / listboxtp.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_ListBoxTP::CFWL_ListBoxTP()\r
9 {\r
10 }\r
11 CFWL_ListBoxTP::~CFWL_ListBoxTP()\r
12 {\r
13 }\r
14 FX_BOOL CFWL_ListBoxTP::IsValidWidget(IFWL_Widget *pWidget)\r
15 {\r
16     _FWL_RETURN_VALUE_IF_FAIL(pWidget, FALSE);\r
17     return pWidget->GetClassID() == FWL_CLASSHASH_ListBox;\r
18 }\r
19 FX_BOOL CFWL_ListBoxTP::DrawBackground(CFWL_ThemeBackground *pParams)\r
20 {\r
21     _FWL_RETURN_VALUE_IF_FAIL(pParams, FALSE);\r
22     switch(pParams->m_iPart) {\r
23         case FWL_PART_LTB_Border: {\r
24                 DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix);\r
25                 break;\r
26             }\r
27         case FWL_PART_LTB_Edge: {\r
28                 DrawEdge(pParams->m_pGraphics, pParams->m_pWidget->GetStyles(), &pParams->m_rtPart, &pParams->m_matrix);\r
29                 break;\r
30             }\r
31         case FWL_PART_LTB_Background: {\r
32                 FillSoildRect(pParams->m_pGraphics, ArgbEncode(255, 255, 255, 255), &pParams->m_rtPart, &pParams->m_matrix);\r
33                 if (pParams->m_pData) {\r
34                     FillSoildRect(pParams->m_pGraphics, FWLTHEME_COLOR_Background, (CFX_RectF*)pParams->m_pData, &pParams->m_matrix);\r
35                 }\r
36                 break;\r
37             }\r
38         case FWL_PART_LTB_ListItem: {\r
39                 DrawListBoxItem(pParams->m_pGraphics, pParams->m_dwStates, &pParams->m_rtPart, pParams->m_pData, &pParams->m_matrix);\r
40                 break;\r
41             }\r
42         case FWL_PART_LTB_Icon: {\r
43                 pParams->m_pGraphics->StretchImage(pParams->m_pImage, pParams->m_rtPart, &pParams->m_matrix);\r
44                 break;\r
45             }\r
46         case FWL_PART_LTB_Check: {\r
47                 FX_DWORD color = 0xFF000000;\r
48                 if (pParams->m_dwStates == FWL_PARTSTATE_LTB_Checked) {\r
49                     color = 0xFFFF0000;\r
50                 } else if (pParams->m_dwStates == FWL_PARTSTATE_LTB_UnChecked) {\r
51                     color = 0xFF0000FF;\r
52                 }\r
53                 FillSoildRect(pParams->m_pGraphics, color, &pParams->m_rtPart, &pParams->m_matrix);\r
54             }\r
55         default: {\r
56             }\r
57     }\r
58     return TRUE;\r
59 }\r
60 FWL_ERR CFWL_ListBoxTP::Initialize()\r
61 {\r
62     InitTTO();\r
63     return CFWL_WidgetTP::Initialize();\r
64 }\r
65 FWL_ERR CFWL_ListBoxTP::Finalize()\r
66 {\r
67     FinalizeTTO();\r
68     return CFWL_WidgetTP::Finalize();\r
69 }\r
70 void CFWL_ListBoxTP::DrawListBoxItem(CFX_Graphics *pGraphics, FX_DWORD dwStates, const CFX_RectF *prtItem, FX_LPVOID pData , CFX_Matrix *pMatrix )\r
71 {\r
72     if (dwStates & FWL_PARTSTATE_LTB_Selected) {\r
73         pGraphics->SaveGraphState();\r
74         CFX_Color crFill(FWL_GetThemeColor(m_dwThemeID) == 0 ? FWLTHEME_COLOR_BKSelected : FWLTHEME_COLOR_Green_BKSelected);\r
75         pGraphics->SetFillColor(&crFill);\r
76         CFX_RectF rt(*prtItem);\r
77         CFX_Path path;\r
78         path.Create();\r
79 #if (_FX_OS_==_FX_MACOSX_)\r
80         path.AddRectangle(rt.left, rt.top, rt.width - 1, rt.height - 1);\r
81 #else\r
82         path.AddRectangle(rt.left, rt.top, rt.width, rt.height);\r
83 #endif\r
84         pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);\r
85         pGraphics->RestoreGraphState();\r
86     }\r
87     if (dwStates & FWL_PARTSTATE_LTB_Focused) {\r
88         if (pData) {\r
89             DrawFocus(pGraphics, (CFX_RectF*)pData, pMatrix);\r
90         }\r
91     }\r
92 }\r