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