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/src/foxitlib.h"
8 #include "xfa/src/fwl/src/core/include/fwl_targetimp.h"
9 #include "xfa/src/fwl/src/core/include/fwl_noteimp.h"
10 #include "xfa/src/fwl/src/core/include/fwl_widgetimp.h"
11 #include "xfa/src/fwl/src/basewidget/include/fwl_pictureboximp.h"
12
13 // static
Create(const CFWL_WidgetImpProperties & properties,IFWL_Widget * pOuter)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 }
IFWL_PictureBox()24 IFWL_PictureBox::IFWL_PictureBox() {}
25
CFWL_PictureBoxImp(const CFWL_WidgetImpProperties & properties,IFWL_Widget * pOuter)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 }
~CFWL_PictureBoxImp()37 CFWL_PictureBoxImp::~CFWL_PictureBoxImp() {}
GetClassName(CFX_WideString & wsClass) const38 FWL_ERR CFWL_PictureBoxImp::GetClassName(CFX_WideString& wsClass) const {
39 wsClass = FWL_CLASS_PictureBox;
40 return FWL_ERR_Succeeded;
41 }
GetClassID() const42 FX_DWORD CFWL_PictureBoxImp::GetClassID() const {
43 return FWL_CLASSHASH_PictureBox;
44 }
Initialize()45 FWL_ERR CFWL_PictureBoxImp::Initialize() {
46 if (CFWL_WidgetImp::Initialize() != FWL_ERR_Succeeded)
47 return FWL_ERR_Indefinite;
48 m_pDelegate = new CFWL_PictureBoxImpDelegate(this);
49 return FWL_ERR_Succeeded;
50 }
Finalize()51 FWL_ERR CFWL_PictureBoxImp::Finalize() {
52 delete m_pDelegate;
53 m_pDelegate = nullptr;
54 return CFWL_WidgetImp::Finalize();
55 }
GetWidgetRect(CFX_RectF & rect,FX_BOOL bAutoSize)56 FWL_ERR CFWL_PictureBoxImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) {
57 if (bAutoSize) {
58 rect.Set(0, 0, 0, 0);
59 if (!m_pProperties->m_pDataProvider)
60 return FWL_ERR_Indefinite;
61 CFX_DIBitmap* pBitmap =
62 static_cast<IFWL_PictureBoxDP*>(m_pProperties->m_pDataProvider)
63 ->GetPicture(m_pInterface);
64 if (pBitmap) {
65 rect.Set(0, 0, (FX_FLOAT)pBitmap->GetWidth(),
66 (FX_FLOAT)pBitmap->GetHeight());
67 }
68 CFWL_WidgetImp::GetWidgetRect(rect, TRUE);
69 } else {
70 rect = m_pProperties->m_rtWidget;
71 }
72 return FWL_ERR_Succeeded;
73 }
Update()74 FWL_ERR CFWL_PictureBoxImp::Update() {
75 if (IsLocked()) {
76 return FWL_ERR_Succeeded;
77 }
78 if (!m_pProperties->m_pThemeProvider) {
79 m_pProperties->m_pThemeProvider = GetAvailableTheme();
80 }
81 GetClientRect(m_rtClient);
82 return FWL_ERR_Succeeded;
83 }
DrawWidget(CFX_Graphics * pGraphics,const CFX_Matrix * pMatrix)84 FWL_ERR CFWL_PictureBoxImp::DrawWidget(CFX_Graphics* pGraphics,
85 const CFX_Matrix* pMatrix) {
86 if (!pGraphics)
87 return FWL_ERR_Indefinite;
88 if (!m_pProperties->m_pThemeProvider)
89 return FWL_ERR_Indefinite;
90 IFWL_ThemeProvider* pTheme = GetAvailableTheme();
91 if (HasBorder()) {
92 DrawBorder(pGraphics, FWL_PART_PTB_Border, pTheme, pMatrix);
93 }
94 if (HasEdge()) {
95 DrawEdge(pGraphics, FWL_PART_PTB_Edge, pTheme, pMatrix);
96 }
97 DrawBkground(pGraphics, pTheme, pMatrix);
98 return FWL_ERR_Succeeded;
99 }
DrawBkground(CFX_Graphics * pGraphics,IFWL_ThemeProvider * pTheme,const CFX_Matrix * pMatrix)100 void CFWL_PictureBoxImp::DrawBkground(CFX_Graphics* pGraphics,
101 IFWL_ThemeProvider* pTheme,
102 const CFX_Matrix* pMatrix) {
103 IFWL_PictureBoxDP* pPictureDP =
104 static_cast<IFWL_PictureBoxDP*>(m_pProperties->m_pDataProvider);
105 if (!pPictureDP)
106 return;
107
108 CFX_DIBitmap* pPicture = pPictureDP->GetPicture(m_pInterface);
109 CFX_Matrix matrix;
110 pPictureDP->GetMatrix(m_pInterface, matrix);
111 if (!pPicture)
112 return;
113
114 matrix.Concat(*pMatrix);
115 FX_FLOAT fx = (FX_FLOAT)pPicture->GetWidth();
116 FX_FLOAT fy = (FX_FLOAT)pPicture->GetHeight();
117 if (fx > m_rtClient.width) {
118 fx = m_rtClient.width;
119 }
120 if (fy > m_rtClient.height) {
121 fy = m_rtClient.height;
122 }
123 CFX_PointF pt;
124 pt.Set((m_rtClient.width - fx) / 2, (m_rtClient.height - fy) / 2);
125 pGraphics->DrawImage(pPicture, pt, &matrix);
126 }
VStyle(FX_BOOL dwStyle)127 FX_BOOL CFWL_PictureBoxImp::VStyle(FX_BOOL dwStyle) {
128 switch (dwStyle & FWL_STYLEEXT_PTB_VAlignMask) {
129 case FWL_STYLEEXT_PTB_Top: {
130 return m_bTop = TRUE;
131 break;
132 }
133 case FWL_STYLEEXT_PTB_Vcenter: {
134 return m_bVCenter = TRUE;
135 break;
136 }
137 case FWL_STYLEEXT_PTB_Bottom: {
138 return m_bButton = TRUE;
139 break;
140 }
141 }
142 return FALSE;
143 }
CFWL_PictureBoxImpDelegate(CFWL_PictureBoxImp * pOwner)144 CFWL_PictureBoxImpDelegate::CFWL_PictureBoxImpDelegate(
145 CFWL_PictureBoxImp* pOwner)
146 : m_pOwner(pOwner) {}
OnDrawWidget(CFX_Graphics * pGraphics,const CFX_Matrix * pMatrix)147 FWL_ERR CFWL_PictureBoxImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics,
148 const CFX_Matrix* pMatrix) {
149 return m_pOwner->DrawWidget(pGraphics, pMatrix);
150 }
151