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