1 // Copyright 2014 The PDFium Authors
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 "build/build_config.h"
10 #include "xfa/fgas/graphics/cfgas_gecolor.h"
11 #include "xfa/fgas/graphics/cfgas_gegraphics.h"
12 #include "xfa/fgas/graphics/cfgas_gepath.h"
13 #include "xfa/fwl/cfwl_listbox.h"
14 #include "xfa/fwl/cfwl_themebackground.h"
15 #include "xfa/fwl/cfwl_widget.h"
16
17 CFWL_ListBoxTP::CFWL_ListBoxTP() = default;
18
19 CFWL_ListBoxTP::~CFWL_ListBoxTP() = default;
20
DrawBackground(const CFWL_ThemeBackground & pParams)21 void CFWL_ListBoxTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
22 switch (pParams.GetPart()) {
23 case CFWL_ThemePart::Part::kBorder: {
24 DrawBorder(pParams.GetGraphics(), pParams.m_PartRect, pParams.m_matrix);
25 break;
26 }
27 case CFWL_ThemePart::Part::kBackground: {
28 FillSolidRect(pParams.GetGraphics(), ArgbEncode(255, 255, 255, 255),
29 pParams.m_PartRect, pParams.m_matrix);
30 if (pParams.m_pRtData) {
31 FillSolidRect(pParams.GetGraphics(), FWLTHEME_COLOR_Background,
32 *pParams.m_pRtData, pParams.m_matrix);
33 }
34 break;
35 }
36 case CFWL_ThemePart::Part::kListItem: {
37 DrawListBoxItem(pParams.GetGraphics(), pParams.m_dwStates,
38 pParams.m_PartRect, pParams.m_pRtData, pParams.m_matrix);
39 break;
40 }
41 case CFWL_ThemePart::Part::kCheck: {
42 uint32_t color = 0xFF000000;
43 if (pParams.m_dwStates == CFWL_PartState::kChecked) {
44 color = 0xFFFF0000;
45 } else if (pParams.m_dwStates == CFWL_PartState::kNormal) {
46 color = 0xFF0000FF;
47 }
48 FillSolidRect(pParams.GetGraphics(), color, pParams.m_PartRect,
49 pParams.m_matrix);
50 break;
51 }
52 default:
53 break;
54 }
55 }
56
DrawListBoxItem(CFGAS_GEGraphics * pGraphics,Mask<CFWL_PartState> dwStates,const CFX_RectF & rtItem,const CFX_RectF * pData,const CFX_Matrix & matrix)57 void CFWL_ListBoxTP::DrawListBoxItem(CFGAS_GEGraphics* pGraphics,
58 Mask<CFWL_PartState> dwStates,
59 const CFX_RectF& rtItem,
60 const CFX_RectF* pData,
61 const CFX_Matrix& matrix) {
62 if (dwStates & CFWL_PartState::kSelected) {
63 CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
64 pGraphics->SetFillColor(CFGAS_GEColor(FWLTHEME_COLOR_BKSelected));
65 CFGAS_GEPath path;
66 #if BUILDFLAG(IS_APPLE)
67 path.AddRectangle(rtItem.left, rtItem.top, rtItem.width - 1,
68 rtItem.height - 1);
69 #else
70 path.AddRectangle(rtItem.left, rtItem.top, rtItem.width, rtItem.height);
71 #endif
72 pGraphics->FillPath(path, CFX_FillRenderOptions::FillType::kWinding,
73 matrix);
74 }
75 if ((dwStates & CFWL_PartState::kFocused) && pData)
76 DrawFocus(pGraphics, *pData, matrix);
77 }
78