• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "build/build_config.h"
10 #include "core/fxge/render_defines.h"
11 #include "xfa/fwl/cfwl_listbox.h"
12 #include "xfa/fwl/cfwl_themebackground.h"
13 #include "xfa/fwl/cfwl_widget.h"
14 #include "xfa/fxgraphics/cxfa_gecolor.h"
15 #include "xfa/fxgraphics/cxfa_gepath.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.m_iPart) {
23     case CFWL_Part::Border: {
24       DrawBorder(pParams.m_pGraphics.Get(), pParams.m_rtPart, pParams.m_matrix);
25       break;
26     }
27     case CFWL_Part::Background: {
28       FillSolidRect(pParams.m_pGraphics.Get(), ArgbEncode(255, 255, 255, 255),
29                     pParams.m_rtPart, pParams.m_matrix);
30       if (pParams.m_pRtData) {
31         FillSolidRect(pParams.m_pGraphics.Get(), FWLTHEME_COLOR_Background,
32                       *pParams.m_pRtData, pParams.m_matrix);
33       }
34       break;
35     }
36     case CFWL_Part::ListItem: {
37       DrawListBoxItem(pParams.m_pGraphics.Get(), pParams.m_dwStates,
38                       pParams.m_rtPart, pParams.m_pRtData, pParams.m_matrix);
39       break;
40     }
41     case CFWL_Part::Check: {
42       uint32_t color = 0xFF000000;
43       if (pParams.m_dwStates == CFWL_PartState_Checked) {
44         color = 0xFFFF0000;
45       } else if (pParams.m_dwStates == CFWL_PartState_Normal) {
46         color = 0xFF0000FF;
47       }
48       FillSolidRect(pParams.m_pGraphics.Get(), color, pParams.m_rtPart,
49                     pParams.m_matrix);
50       break;
51     }
52     default:
53       break;
54   }
55 }
56 
DrawListBoxItem(CXFA_Graphics * pGraphics,uint32_t dwStates,const CFX_RectF & rtItem,const CFX_RectF * pData,const CFX_Matrix & matrix)57 void CFWL_ListBoxTP::DrawListBoxItem(CXFA_Graphics* pGraphics,
58                                      uint32_t dwStates,
59                                      const CFX_RectF& rtItem,
60                                      const CFX_RectF* pData,
61                                      const CFX_Matrix& matrix) {
62   if (dwStates & CFWL_PartState_Selected) {
63     pGraphics->SaveGraphState();
64     pGraphics->SetFillColor(CXFA_GEColor(FWLTHEME_COLOR_BKSelected));
65     CXFA_GEPath path;
66 #if defined(OS_MACOSX)
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, FXFILL_WINDING, &matrix);
73     pGraphics->RestoreGraphState();
74   }
75   if ((dwStates & CFWL_PartState_Focused) && pData)
76     DrawFocus(pGraphics, *pData, matrix);
77 }
78