Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: xfa/fwl/core/ifwl_barcode.cpp

Issue 2432423002: Merge the CFWL_*Imp classes into the IFWL_* classes. (Closed)
Patch Set: Review feedback Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fwl/core/ifwl_barcode.h ('k') | xfa/fwl/core/ifwl_caret.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_barcodeimp.h" 7 #include "xfa/fwl/core/ifwl_barcode.h"
8 8
9 #include "xfa/fgas/font/fgas_gefont.h" 9 #include "xfa/fgas/font/fgas_gefont.h"
10 #include "xfa/fwl/basewidget/cfx_barcode.h"
11 #include "xfa/fwl/basewidget/fwl_editimp.h"
12 #include "xfa/fwl/core/cfwl_themepart.h" 10 #include "xfa/fwl/core/cfwl_themepart.h"
11 #include "xfa/fwl/core/cfx_barcode.h"
13 #include "xfa/fwl/core/fwl_noteimp.h" 12 #include "xfa/fwl/core/fwl_noteimp.h"
14 #include "xfa/fwl/core/fwl_widgetimp.h"
15 #include "xfa/fwl/core/ifwl_themeprovider.h" 13 #include "xfa/fwl/core/ifwl_themeprovider.h"
16 14
17 // static 15 // static
18 IFWL_Barcode* IFWL_Barcode::Create(const CFWL_WidgetImpProperties& properties) { 16 IFWL_Barcode* IFWL_Barcode::Create(const CFWL_WidgetImpProperties& properties) {
19 IFWL_Barcode* pBarcode = new IFWL_Barcode; 17 return new IFWL_Barcode(properties, nullptr);
20 CFWL_BarcodeImp* pBarcodeImpl = new CFWL_BarcodeImp(properties, nullptr);
21 pBarcode->SetImpl(pBarcodeImpl);
22 pBarcodeImpl->SetInterface(pBarcode);
23 return pBarcode;
24 }
25 IFWL_Barcode::IFWL_Barcode() {}
26 void IFWL_Barcode::SetType(BC_TYPE type) {
27 static_cast<CFWL_BarcodeImp*>(GetImpl())->SetType(type);
28 }
29 FX_BOOL IFWL_Barcode::IsProtectedType() {
30 return static_cast<CFWL_BarcodeImp*>(GetImpl())->IsProtectedType();
31 } 18 }
32 19
33 CFWL_BarcodeImp::CFWL_BarcodeImp(const CFWL_WidgetImpProperties& properties, 20 IFWL_Barcode::IFWL_Barcode(const CFWL_WidgetImpProperties& properties,
34 IFWL_Widget* pOuter) 21 IFWL_Widget* pOuter)
35 : CFWL_EditImp(properties, pOuter), 22 : IFWL_Edit(properties, pOuter), m_dwStatus(0), m_type(BC_UNKNOWN) {}
36 m_dwStatus(0),
37 m_type(BC_UNKNOWN) {}
38 23
39 CFWL_BarcodeImp::~CFWL_BarcodeImp() {} 24 IFWL_Barcode::~IFWL_Barcode() {}
40 25
41 FWL_Error CFWL_BarcodeImp::GetClassName(CFX_WideString& wsClass) const { 26 FWL_Error IFWL_Barcode::GetClassName(CFX_WideString& wsClass) const {
42 wsClass = FWL_CLASS_Barcode; 27 wsClass = FWL_CLASS_Barcode;
43 return FWL_Error::Succeeded; 28 return FWL_Error::Succeeded;
44 } 29 }
45 30
46 FWL_Type CFWL_BarcodeImp::GetClassID() const { 31 FWL_Type IFWL_Barcode::GetClassID() const {
47 return FWL_Type::Barcode; 32 return FWL_Type::Barcode;
48 } 33 }
49 34
50 FWL_Error CFWL_BarcodeImp::Initialize() { 35 FWL_Error IFWL_Barcode::Initialize() {
51 if (!m_pDelegate) { 36 if (!m_pDelegate) {
52 m_pDelegate = new CFWL_BarcodeImpDelegate(this); 37 m_pDelegate = new CFWL_BarcodeImpDelegate(this);
53 } 38 }
54 if (CFWL_EditImp::Initialize() != FWL_Error::Succeeded) 39 if (IFWL_Edit::Initialize() != FWL_Error::Succeeded)
55 return FWL_Error::Indefinite; 40 return FWL_Error::Indefinite;
56 return FWL_Error::Succeeded; 41 return FWL_Error::Succeeded;
57 } 42 }
58 FWL_Error CFWL_BarcodeImp::Finalize() { 43 FWL_Error IFWL_Barcode::Finalize() {
59 delete m_pDelegate; 44 delete m_pDelegate;
60 m_pDelegate = nullptr; 45 m_pDelegate = nullptr;
61 m_pBarcodeEngine.reset(); 46 m_pBarcodeEngine.reset();
62 return CFWL_EditImp::Finalize(); 47 return IFWL_Edit::Finalize();
63 } 48 }
64 FWL_Error CFWL_BarcodeImp::Update() { 49 FWL_Error IFWL_Barcode::Update() {
65 if (IsLocked()) { 50 if (IsLocked()) {
66 return FWL_Error::Indefinite; 51 return FWL_Error::Indefinite;
67 } 52 }
68 FWL_Error ret = CFWL_EditImp::Update(); 53 FWL_Error ret = IFWL_Edit::Update();
69 GenerateBarcodeImageCache(); 54 GenerateBarcodeImageCache();
70 return ret; 55 return ret;
71 } 56 }
72 FWL_Error CFWL_BarcodeImp::DrawWidget(CFX_Graphics* pGraphics, 57 FWL_Error IFWL_Barcode::DrawWidget(CFX_Graphics* pGraphics,
73 const CFX_Matrix* pMatrix) { 58 const CFX_Matrix* pMatrix) {
74 if (!pGraphics) 59 if (!pGraphics)
75 return FWL_Error::Indefinite; 60 return FWL_Error::Indefinite;
76 if (!m_pProperties->m_pThemeProvider) 61 if (!m_pProperties->m_pThemeProvider)
77 return FWL_Error::Indefinite; 62 return FWL_Error::Indefinite;
78 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { 63 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) {
79 GenerateBarcodeImageCache(); 64 GenerateBarcodeImageCache();
80 if (!m_pBarcodeEngine || (m_dwStatus & XFA_BCS_EncodeSuccess) == 0) { 65 if (!m_pBarcodeEngine || (m_dwStatus & XFA_BCS_EncodeSuccess) == 0) {
81 return FWL_Error::Succeeded; 66 return FWL_Error::Succeeded;
82 } 67 }
83 CFX_Matrix mt; 68 CFX_Matrix mt;
84 mt.e = m_rtClient.left; 69 mt.e = m_rtClient.left;
85 mt.f = m_rtClient.top; 70 mt.f = m_rtClient.top;
86 if (pMatrix) { 71 if (pMatrix) {
87 mt.Concat(*pMatrix); 72 mt.Concat(*pMatrix);
88 } 73 }
89 int32_t errorCode = 0; 74 int32_t errorCode = 0;
90 if (!m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), pMatrix, 75 if (!m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), pMatrix,
91 errorCode)) { 76 errorCode)) {
92 return FWL_Error::Indefinite; 77 return FWL_Error::Indefinite;
93 } 78 }
94 return FWL_Error::Succeeded; 79 return FWL_Error::Succeeded;
95 } 80 }
96 return CFWL_EditImp::DrawWidget(pGraphics, pMatrix); 81 return IFWL_Edit::DrawWidget(pGraphics, pMatrix);
97 } 82 }
98 void CFWL_BarcodeImp::GenerateBarcodeImageCache() { 83 void IFWL_Barcode::GenerateBarcodeImageCache() {
99 if ((m_dwStatus & XFA_BCS_NeedUpdate) == 0) 84 if ((m_dwStatus & XFA_BCS_NeedUpdate) == 0)
100 return; 85 return;
101 m_dwStatus = 0; 86 m_dwStatus = 0;
102 CreateBarcodeEngine(); 87 CreateBarcodeEngine();
103 IFWL_BarcodeDP* pData = 88 IFWL_BarcodeDP* pData =
104 static_cast<IFWL_BarcodeDP*>(m_pProperties->m_pDataProvider); 89 static_cast<IFWL_BarcodeDP*>(m_pProperties->m_pDataProvider);
105 if (!pData) 90 if (!pData)
106 return; 91 return;
107 if (!m_pBarcodeEngine) 92 if (!m_pBarcodeEngine)
108 return; 93 return;
109 CFX_WideString wsText; 94 CFX_WideString wsText;
110 if (GetText(wsText) != FWL_Error::Succeeded) 95 if (GetText(wsText) != FWL_Error::Succeeded)
111 return; 96 return;
112 CFWL_ThemePart part; 97 CFWL_ThemePart part;
113 part.m_pWidget = m_pInterface; 98 part.m_pWidget = this;
114 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); 99 IFWL_ThemeProvider* pTheme = GetAvailableTheme();
115 CFGAS_GEFont* pFont = static_cast<CFGAS_GEFont*>( 100 CFGAS_GEFont* pFont = static_cast<CFGAS_GEFont*>(
116 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Font)); 101 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Font));
117 CFX_Font* pCXFont = pFont ? pFont->GetDevFont() : nullptr; 102 CFX_Font* pCXFont = pFont ? pFont->GetDevFont() : nullptr;
118 if (pCXFont) { 103 if (pCXFont) {
119 m_pBarcodeEngine->SetFont(pCXFont); 104 m_pBarcodeEngine->SetFont(pCXFont);
120 } 105 }
121 FX_FLOAT* pFontSize = static_cast<FX_FLOAT*>( 106 FX_FLOAT* pFontSize = static_cast<FX_FLOAT*>(
122 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::FontSize)); 107 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::FontSize));
123 if (pFontSize) { 108 if (pFontSize) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 } 154 }
170 if (dwAttributeMask & FWL_BCDATTRIBUTE_TRUNCATED) { 155 if (dwAttributeMask & FWL_BCDATTRIBUTE_TRUNCATED) {
171 m_pBarcodeEngine->SetTruncated(pData->GetTruncated()); 156 m_pBarcodeEngine->SetTruncated(pData->GetTruncated());
172 } 157 }
173 int32_t errorCode = 0; 158 int32_t errorCode = 0;
174 m_dwStatus = m_pBarcodeEngine->Encode(wsText.AsStringC(), TRUE, errorCode) 159 m_dwStatus = m_pBarcodeEngine->Encode(wsText.AsStringC(), TRUE, errorCode)
175 ? XFA_BCS_EncodeSuccess 160 ? XFA_BCS_EncodeSuccess
176 : 0; 161 : 0;
177 } 162 }
178 163
179 void CFWL_BarcodeImp::CreateBarcodeEngine() { 164 void IFWL_Barcode::CreateBarcodeEngine() {
180 if (m_pBarcodeEngine || m_type == BC_UNKNOWN) 165 if (m_pBarcodeEngine || m_type == BC_UNKNOWN)
181 return; 166 return;
182 167
183 std::unique_ptr<CFX_Barcode> pBarcode(new CFX_Barcode); 168 std::unique_ptr<CFX_Barcode> pBarcode(new CFX_Barcode);
184 if (pBarcode->Create(m_type)) 169 if (pBarcode->Create(m_type))
185 m_pBarcodeEngine = std::move(pBarcode); 170 m_pBarcodeEngine = std::move(pBarcode);
186 } 171 }
187 172
188 void CFWL_BarcodeImp::SetType(BC_TYPE type) { 173 void IFWL_Barcode::SetType(BC_TYPE type) {
189 if (m_type == type) 174 if (m_type == type)
190 return; 175 return;
191 176
192 m_pBarcodeEngine.reset(); 177 m_pBarcodeEngine.reset();
193 m_type = type; 178 m_type = type;
194 m_dwStatus = XFA_BCS_NeedUpdate; 179 m_dwStatus = XFA_BCS_NeedUpdate;
195 } 180 }
196 FWL_Error CFWL_BarcodeImp::SetText(const CFX_WideString& wsText) { 181 FWL_Error IFWL_Barcode::SetText(const CFX_WideString& wsText) {
197 m_pBarcodeEngine.reset(); 182 m_pBarcodeEngine.reset();
198 m_dwStatus = XFA_BCS_NeedUpdate; 183 m_dwStatus = XFA_BCS_NeedUpdate;
199 return CFWL_EditImp::SetText(wsText); 184 return IFWL_Edit::SetText(wsText);
200 } 185 }
201 FX_BOOL CFWL_BarcodeImp::IsProtectedType() { 186 FX_BOOL IFWL_Barcode::IsProtectedType() {
202 if (!m_pBarcodeEngine) { 187 if (!m_pBarcodeEngine) {
203 return TRUE; 188 return TRUE;
204 } 189 }
205 BC_TYPE tEngineType = m_pBarcodeEngine->GetType(); 190 BC_TYPE tEngineType = m_pBarcodeEngine->GetType();
206 if (tEngineType == BC_QR_CODE || tEngineType == BC_PDF417 || 191 if (tEngineType == BC_QR_CODE || tEngineType == BC_PDF417 ||
207 tEngineType == BC_DATAMATRIX) { 192 tEngineType == BC_DATAMATRIX) {
208 return TRUE; 193 return TRUE;
209 } 194 }
210 return FALSE; 195 return FALSE;
211 } 196 }
212 197
213 CFWL_BarcodeImpDelegate::CFWL_BarcodeImpDelegate(CFWL_BarcodeImp* pOwner) 198 CFWL_BarcodeImpDelegate::CFWL_BarcodeImpDelegate(IFWL_Barcode* pOwner)
214 : CFWL_EditImpDelegate(pOwner) {} 199 : CFWL_EditImpDelegate(pOwner) {}
215 200
216 void CFWL_BarcodeImpDelegate::OnProcessEvent(CFWL_Event* pEvent) { 201 void CFWL_BarcodeImpDelegate::OnProcessEvent(CFWL_Event* pEvent) {
217 if (pEvent->GetClassID() == CFWL_EventType::TextChanged) { 202 if (pEvent->GetClassID() == CFWL_EventType::TextChanged) {
218 CFWL_BarcodeImp* pOwner = static_cast<CFWL_BarcodeImp*>(m_pOwner); 203 IFWL_Barcode* pOwner = static_cast<IFWL_Barcode*>(m_pOwner);
219 pOwner->m_pBarcodeEngine.reset(); 204 pOwner->m_pBarcodeEngine.reset();
220 pOwner->m_dwStatus = XFA_BCS_NeedUpdate; 205 pOwner->m_dwStatus = XFA_BCS_NeedUpdate;
221 } 206 }
222 CFWL_EditImpDelegate::OnProcessEvent(pEvent); 207 CFWL_EditImpDelegate::OnProcessEvent(pEvent);
223 } 208 }
OLDNEW
« no previous file with comments | « xfa/fwl/core/ifwl_barcode.h ('k') | xfa/fwl/core/ifwl_caret.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698