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/cxfa_gecolor.h" 13 #include "xfa/fxgraphics/cxfa_gepath.h" 14 15 CFWL_ListBoxTP::CFWL_ListBoxTP() {} 16 17 CFWL_ListBoxTP::~CFWL_ListBoxTP() {} 18 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::Check: { 43 uint32_t color = 0xFF000000; 44 if (pParams->m_dwStates == CFWL_PartState_Checked) { 45 color = 0xFFFF0000; 46 } else if (pParams->m_dwStates == CFWL_PartState_Normal) { 47 color = 0xFF0000FF; 48 } 49 FillSoildRect(pParams->m_pGraphics, color, &pParams->m_rtPart, 50 &pParams->m_matrix); 51 } 52 default: 53 break; 54 } 55 } 56 57 void CFWL_ListBoxTP::DrawListBoxItem(CXFA_Graphics* pGraphics, 58 uint32_t dwStates, 59 const CFX_RectF* prtItem, 60 void* pData, 61 CFX_Matrix* pMatrix) { 62 if (dwStates & CFWL_PartState_Selected) { 63 pGraphics->SaveGraphState(); 64 pGraphics->SetFillColor(CXFA_GEColor(FWLTHEME_COLOR_BKSelected)); 65 CFX_RectF rt(*prtItem); 66 CXFA_GEPath path; 67 #if (_FX_OS_ == _FX_OS_MACOSX_) 68 path.AddRectangle(rt.left, rt.top, rt.width - 1, rt.height - 1); 69 #else 70 path.AddRectangle(rt.left, rt.top, rt.width, rt.height); 71 #endif 72 pGraphics->FillPath(&path, FXFILL_WINDING, pMatrix); 73 pGraphics->RestoreGraphState(); 74 } 75 if (dwStates & CFWL_PartState_Focused && pData) 76 DrawFocus(pGraphics, (CFX_RectF*)pData, pMatrix); 77 } 78