| OLD | NEW |
| (Empty) |
| 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/basewidget/fwl_pictureboximp.h" | |
| 8 | |
| 9 #include "xfa/fwl/core/fwl_noteimp.h" | |
| 10 #include "xfa/fwl/core/fwl_widgetimp.h" | |
| 11 #include "xfa/fwl/lightwidget/cfwl_picturebox.h" | |
| 12 | |
| 13 // static | |
| 14 IFWL_PictureBox* IFWL_PictureBox::Create( | |
| 15 const CFWL_WidgetImpProperties& properties, | |
| 16 IFWL_Widget* pOuter) { | |
| 17 IFWL_PictureBox* pPictureBox = new IFWL_PictureBox; | |
| 18 CFWL_PictureBoxImp* pPictureBoxImpl = | |
| 19 new CFWL_PictureBoxImp(properties, pOuter); | |
| 20 pPictureBox->SetImpl(pPictureBoxImpl); | |
| 21 pPictureBoxImpl->SetInterface(pPictureBox); | |
| 22 return pPictureBox; | |
| 23 } | |
| 24 IFWL_PictureBox::IFWL_PictureBox() {} | |
| 25 | |
| 26 CFWL_PictureBoxImp::CFWL_PictureBoxImp( | |
| 27 const CFWL_WidgetImpProperties& properties, | |
| 28 IFWL_Widget* pOuter) | |
| 29 : CFWL_WidgetImp(properties, pOuter), | |
| 30 m_bTop(FALSE), | |
| 31 m_bVCenter(FALSE), | |
| 32 m_bButton(FALSE) { | |
| 33 m_rtClient.Reset(); | |
| 34 m_rtImage.Reset(); | |
| 35 m_matrix.SetIdentity(); | |
| 36 } | |
| 37 | |
| 38 CFWL_PictureBoxImp::~CFWL_PictureBoxImp() {} | |
| 39 | |
| 40 FWL_Error CFWL_PictureBoxImp::GetClassName(CFX_WideString& wsClass) const { | |
| 41 wsClass = FWL_CLASS_PictureBox; | |
| 42 return FWL_Error::Succeeded; | |
| 43 } | |
| 44 | |
| 45 FWL_Type CFWL_PictureBoxImp::GetClassID() const { | |
| 46 return FWL_Type::PictureBox; | |
| 47 } | |
| 48 | |
| 49 FWL_Error CFWL_PictureBoxImp::Initialize() { | |
| 50 if (CFWL_WidgetImp::Initialize() != FWL_Error::Succeeded) | |
| 51 return FWL_Error::Indefinite; | |
| 52 | |
| 53 m_pDelegate = new CFWL_PictureBoxImpDelegate(this); | |
| 54 return FWL_Error::Succeeded; | |
| 55 } | |
| 56 | |
| 57 FWL_Error CFWL_PictureBoxImp::Finalize() { | |
| 58 delete m_pDelegate; | |
| 59 m_pDelegate = nullptr; | |
| 60 return CFWL_WidgetImp::Finalize(); | |
| 61 } | |
| 62 FWL_Error CFWL_PictureBoxImp::GetWidgetRect(CFX_RectF& rect, | |
| 63 FX_BOOL bAutoSize) { | |
| 64 if (bAutoSize) { | |
| 65 rect.Set(0, 0, 0, 0); | |
| 66 if (!m_pProperties->m_pDataProvider) | |
| 67 return FWL_Error::Indefinite; | |
| 68 CFX_DIBitmap* pBitmap = | |
| 69 static_cast<IFWL_PictureBoxDP*>(m_pProperties->m_pDataProvider) | |
| 70 ->GetPicture(m_pInterface); | |
| 71 if (pBitmap) { | |
| 72 rect.Set(0, 0, (FX_FLOAT)pBitmap->GetWidth(), | |
| 73 (FX_FLOAT)pBitmap->GetHeight()); | |
| 74 } | |
| 75 CFWL_WidgetImp::GetWidgetRect(rect, TRUE); | |
| 76 } else { | |
| 77 rect = m_pProperties->m_rtWidget; | |
| 78 } | |
| 79 return FWL_Error::Succeeded; | |
| 80 } | |
| 81 FWL_Error CFWL_PictureBoxImp::Update() { | |
| 82 if (IsLocked()) { | |
| 83 return FWL_Error::Succeeded; | |
| 84 } | |
| 85 if (!m_pProperties->m_pThemeProvider) { | |
| 86 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
| 87 } | |
| 88 GetClientRect(m_rtClient); | |
| 89 return FWL_Error::Succeeded; | |
| 90 } | |
| 91 FWL_Error CFWL_PictureBoxImp::DrawWidget(CFX_Graphics* pGraphics, | |
| 92 const CFX_Matrix* pMatrix) { | |
| 93 if (!pGraphics) | |
| 94 return FWL_Error::Indefinite; | |
| 95 if (!m_pProperties->m_pThemeProvider) | |
| 96 return FWL_Error::Indefinite; | |
| 97 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); | |
| 98 if (HasBorder()) { | |
| 99 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | |
| 100 } | |
| 101 if (HasEdge()) { | |
| 102 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | |
| 103 } | |
| 104 DrawBkground(pGraphics, pTheme, pMatrix); | |
| 105 return FWL_Error::Succeeded; | |
| 106 } | |
| 107 void CFWL_PictureBoxImp::DrawBkground(CFX_Graphics* pGraphics, | |
| 108 IFWL_ThemeProvider* pTheme, | |
| 109 const CFX_Matrix* pMatrix) { | |
| 110 IFWL_PictureBoxDP* pPictureDP = | |
| 111 static_cast<IFWL_PictureBoxDP*>(m_pProperties->m_pDataProvider); | |
| 112 if (!pPictureDP) | |
| 113 return; | |
| 114 | |
| 115 CFX_DIBitmap* pPicture = pPictureDP->GetPicture(m_pInterface); | |
| 116 CFX_Matrix matrix; | |
| 117 pPictureDP->GetMatrix(m_pInterface, matrix); | |
| 118 if (!pPicture) | |
| 119 return; | |
| 120 | |
| 121 matrix.Concat(*pMatrix); | |
| 122 FX_FLOAT fx = (FX_FLOAT)pPicture->GetWidth(); | |
| 123 FX_FLOAT fy = (FX_FLOAT)pPicture->GetHeight(); | |
| 124 if (fx > m_rtClient.width) { | |
| 125 fx = m_rtClient.width; | |
| 126 } | |
| 127 if (fy > m_rtClient.height) { | |
| 128 fy = m_rtClient.height; | |
| 129 } | |
| 130 pGraphics->DrawImage(pPicture, CFX_PointF((m_rtClient.width - fx) / 2, | |
| 131 (m_rtClient.height - fy) / 2), | |
| 132 &matrix); | |
| 133 } | |
| 134 FX_BOOL CFWL_PictureBoxImp::VStyle(FX_BOOL dwStyle) { | |
| 135 switch (dwStyle & FWL_STYLEEXT_PTB_VAlignMask) { | |
| 136 case FWL_STYLEEXT_PTB_Top: { | |
| 137 return m_bTop = TRUE; | |
| 138 break; | |
| 139 } | |
| 140 case FWL_STYLEEXT_PTB_Vcenter: { | |
| 141 return m_bVCenter = TRUE; | |
| 142 break; | |
| 143 } | |
| 144 case FWL_STYLEEXT_PTB_Bottom: { | |
| 145 return m_bButton = TRUE; | |
| 146 break; | |
| 147 } | |
| 148 } | |
| 149 return FALSE; | |
| 150 } | |
| 151 | |
| 152 CFWL_PictureBoxImpDelegate::CFWL_PictureBoxImpDelegate( | |
| 153 CFWL_PictureBoxImp* pOwner) | |
| 154 : m_pOwner(pOwner) {} | |
| 155 | |
| 156 void CFWL_PictureBoxImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | |
| 157 const CFX_Matrix* pMatrix) { | |
| 158 m_pOwner->DrawWidget(pGraphics, pMatrix); | |
| 159 } | |
| OLD | NEW |