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_comboboxtp.h" 8 9 #include "xfa/fwl/cfwl_combobox.h" 10 #include "xfa/fwl/cfwl_themebackground.h" 11 #include "xfa/fwl/cfwl_widget.h" 12 #include "xfa/fwl/ifwl_themeprovider.h" 13 #include "xfa/fxgraphics/cfx_color.h" 14 #include "xfa/fxgraphics/cfx_path.h" 15 16 CFWL_ComboBoxTP::CFWL_ComboBoxTP() {} 17 18 CFWL_ComboBoxTP::~CFWL_ComboBoxTP() {} 19 20 void CFWL_ComboBoxTP::DrawBackground(CFWL_ThemeBackground* pParams) { 21 if (!pParams) 22 return; 23 24 switch (pParams->m_iPart) { 25 case CFWL_Part::Border: { 26 DrawBorder(pParams->m_pGraphics, &pParams->m_rtPart, &pParams->m_matrix); 27 break; 28 } 29 case CFWL_Part::Background: { 30 CFX_Path path; 31 CFX_RectF& rect = pParams->m_rtPart; 32 path.AddRectangle(rect.left, rect.top, rect.width, rect.height); 33 FX_ARGB argb_color; 34 switch (pParams->m_dwStates) { 35 case CFWL_PartState_Selected: 36 argb_color = FWLTHEME_COLOR_BKSelected; 37 break; 38 case CFWL_PartState_Disabled: 39 argb_color = FWLTHEME_COLOR_EDGERB1; 40 break; 41 default: 42 argb_color = 0xFFFFFFFF; 43 } 44 pParams->m_pGraphics->SaveGraphState(); 45 CFX_Color cr(argb_color); 46 pParams->m_pGraphics->SetFillColor(&cr); 47 pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, &pParams->m_matrix); 48 pParams->m_pGraphics->RestoreGraphState(); 49 break; 50 } 51 case CFWL_Part::DropDownButton: { 52 DrawDropDownButton(pParams, pParams->m_dwStates, &pParams->m_matrix); 53 break; 54 } 55 case CFWL_Part::StretchHandler: { 56 DrawStrethHandler(pParams, 0, &pParams->m_matrix); 57 break; 58 } 59 default: 60 break; 61 } 62 } 63 64 void CFWL_ComboBoxTP::DrawStrethHandler(CFWL_ThemeBackground* pParams, 65 uint32_t dwStates, 66 CFX_Matrix* pMatrix) { 67 CFX_Path path; 68 path.AddRectangle(pParams->m_rtPart.left, pParams->m_rtPart.top, 69 pParams->m_rtPart.width - 1, pParams->m_rtPart.height); 70 CFX_Color cr(ArgbEncode(0xff, 0xff, 0, 0)); 71 pParams->m_pGraphics->SetFillColor(&cr); 72 pParams->m_pGraphics->FillPath(&path, FXFILL_WINDING, &pParams->m_matrix); 73 } 74 75 void CFWL_ComboBoxTP::DrawDropDownButton(CFWL_ThemeBackground* pParams, 76 uint32_t dwStates, 77 CFX_Matrix* pMatrix) { 78 FWLTHEME_STATE eState = FWLTHEME_STATE_Normal; 79 switch (dwStates) { 80 case CFWL_PartState_Normal: { 81 eState = FWLTHEME_STATE_Normal; 82 break; 83 } 84 case CFWL_PartState_Hovered: { 85 eState = FWLTHEME_STATE_Hover; 86 break; 87 } 88 case CFWL_PartState_Pressed: { 89 eState = FWLTHEME_STATE_Pressed; 90 break; 91 } 92 case CFWL_PartState_Disabled: { 93 eState = FWLTHEME_STATE_Disable; 94 break; 95 } 96 default: 97 break; 98 } 99 DrawArrowBtn(pParams->m_pGraphics, &pParams->m_rtPart, 100 FWLTHEME_DIRECTION_Down, eState, &pParams->m_matrix); 101 } 102