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