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_listboxtp.h"
8
9 #include "xfa/fwl/cfwl_listbox.h"
10 #include "xfa/fwl/cfwl_themebackground.h"
11 #include "xfa/fwl/cfwl_widget.h"
12 #include "xfa/fxgraphics/cfx_color.h"
13 #include "xfa/fxgraphics/cfx_path.h"
14
CFWL_ListBoxTP()15 CFWL_ListBoxTP::CFWL_ListBoxTP() {}
16
~CFWL_ListBoxTP()17 CFWL_ListBoxTP::~CFWL_ListBoxTP() {}
18
DrawBackground(CFWL_ThemeBackground * pParams)19 void CFWL_ListBoxTP::DrawBackground(CFWL_ThemeBackground* pParams) {
20 if (!pParams)
21 return;
22
23 switch (pParams->m_iPart) {
24 case CFWL_Part::Border: {
25 DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix);
26 break;
27 }
28 case CFWL_Part::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 CFWL_Part::ListItem: {
38 DrawListBoxItem(pParams->m_pGraphics, pParams->m_dwStates,
39 &pParams->m_rtPart, pParams->m_pData, &pParams->m_matrix);
40 break;
41 }
42 case CFWL_Part::Icon: {
43 pParams->m_pGraphics->StretchImage(pParams->m_pImage, pParams->m_rtPart,
44 &pParams->m_matrix);
45 break;
46 }
47 case CFWL_Part::Check: {
48 uint32_t color = 0xFF000000;
49 if (pParams->m_dwStates == CFWL_PartState_Checked) {
50 color = 0xFFFF0000;
51 } else if (pParams->m_dwStates == CFWL_PartState_Normal) {
52 color = 0xFF0000FF;
53 }
54 FillSoildRect(pParams->m_pGraphics, color, &pParams->m_rtPart,
55 &pParams->m_matrix);
56 }
57 default:
58 break;
59 }
60 }
61
DrawListBoxItem(CFX_Graphics * pGraphics,uint32_t dwStates,const CFX_RectF * prtItem,void * pData,CFX_Matrix * pMatrix)62 void CFWL_ListBoxTP::DrawListBoxItem(CFX_Graphics* pGraphics,
63 uint32_t dwStates,
64 const CFX_RectF* prtItem,
65 void* pData,
66 CFX_Matrix* pMatrix) {
67 if (dwStates & CFWL_PartState_Selected) {
68 pGraphics->SaveGraphState();
69 CFX_Color crFill(FWLTHEME_COLOR_BKSelected);
70 pGraphics->SetFillColor(&crFill);
71 CFX_RectF rt(*prtItem);
72 CFX_Path path;
73 #if (_FX_OS_ == _FX_MACOSX_)
74 path.AddRectangle(rt.left, rt.top, rt.width - 1, rt.height - 1);
75 #else
76 path.AddRectangle(rt.left, rt.top, rt.width, rt.height);
77 #endif
78 pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix);
79 pGraphics->RestoreGraphState();
80 }
81 if (dwStates & CFWL_PartState_Focused && pData)
82 DrawFocus(pGraphics, (CFX_RectF*)pData, pMatrix);
83 }
84