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