| 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_barcodeimp.h" | 7 #include "xfa/fwl/basewidget/fwl_barcodeimp.h" |
| 8 | 8 |
| 9 #include "xfa/fwl/basewidget/fwl_editimp.h" | 9 #include "xfa/fwl/basewidget/fwl_editimp.h" |
| 10 #include "xfa/fwl/basewidget/fxmath_barcodeimp.h" | 10 #include "xfa/fwl/basewidget/fxmath_barcodeimp.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 CFWL_BarcodeImp::CFWL_BarcodeImp(const CFWL_WidgetImpProperties& properties, | 32 CFWL_BarcodeImp::CFWL_BarcodeImp(const CFWL_WidgetImpProperties& properties, |
| 33 IFWL_Widget* pOuter) | 33 IFWL_Widget* pOuter) |
| 34 : CFWL_EditImp(properties, pOuter), | 34 : CFWL_EditImp(properties, pOuter), |
| 35 m_pBarcodeEngine(NULL), | 35 m_pBarcodeEngine(NULL), |
| 36 m_dwStatus(0), | 36 m_dwStatus(0), |
| 37 m_type(BC_UNKNOWN) {} | 37 m_type(BC_UNKNOWN) {} |
| 38 CFWL_BarcodeImp::~CFWL_BarcodeImp() { | 38 CFWL_BarcodeImp::~CFWL_BarcodeImp() { |
| 39 ReleaseBarcodeEngine(); | 39 ReleaseBarcodeEngine(); |
| 40 } | 40 } |
| 41 FWL_ERR CFWL_BarcodeImp::GetClassName(CFX_WideString& wsClass) const { | 41 FWL_Error CFWL_BarcodeImp::GetClassName(CFX_WideString& wsClass) const { |
| 42 wsClass = FWL_CLASS_Barcode; | 42 wsClass = FWL_CLASS_Barcode; |
| 43 return FWL_ERR_Succeeded; | 43 return FWL_Error::Succeeded; |
| 44 } | 44 } |
| 45 uint32_t CFWL_BarcodeImp::GetClassID() const { | 45 uint32_t CFWL_BarcodeImp::GetClassID() const { |
| 46 return FWL_CLASSHASH_Barcode; | 46 return FWL_CLASSHASH_Barcode; |
| 47 } | 47 } |
| 48 FWL_ERR CFWL_BarcodeImp::Initialize() { | 48 FWL_Error CFWL_BarcodeImp::Initialize() { |
| 49 if (!m_pDelegate) { | 49 if (!m_pDelegate) { |
| 50 m_pDelegate = new CFWL_BarcodeImpDelegate(this); | 50 m_pDelegate = new CFWL_BarcodeImpDelegate(this); |
| 51 } | 51 } |
| 52 if (CFWL_EditImp::Initialize() != FWL_ERR_Succeeded) | 52 if (CFWL_EditImp::Initialize() != FWL_Error::Succeeded) |
| 53 return FWL_ERR_Indefinite; | 53 return FWL_Error::Indefinite; |
| 54 return FWL_ERR_Succeeded; | 54 return FWL_Error::Succeeded; |
| 55 } | 55 } |
| 56 FWL_ERR CFWL_BarcodeImp::Finalize() { | 56 FWL_Error CFWL_BarcodeImp::Finalize() { |
| 57 delete m_pDelegate; | 57 delete m_pDelegate; |
| 58 m_pDelegate = nullptr; | 58 m_pDelegate = nullptr; |
| 59 ReleaseBarcodeEngine(); | 59 ReleaseBarcodeEngine(); |
| 60 return CFWL_EditImp::Finalize(); | 60 return CFWL_EditImp::Finalize(); |
| 61 } | 61 } |
| 62 FWL_ERR CFWL_BarcodeImp::Update() { | 62 FWL_Error CFWL_BarcodeImp::Update() { |
| 63 if (IsLocked()) { | 63 if (IsLocked()) { |
| 64 return FWL_ERR_Indefinite; | 64 return FWL_Error::Indefinite; |
| 65 } | 65 } |
| 66 FWL_ERR ret = CFWL_EditImp::Update(); | 66 FWL_Error ret = CFWL_EditImp::Update(); |
| 67 GenerateBarcodeImageCache(); | 67 GenerateBarcodeImageCache(); |
| 68 return ret; | 68 return ret; |
| 69 } | 69 } |
| 70 FWL_ERR CFWL_BarcodeImp::DrawWidget(CFX_Graphics* pGraphics, | 70 FWL_Error CFWL_BarcodeImp::DrawWidget(CFX_Graphics* pGraphics, |
| 71 const CFX_Matrix* pMatrix) { | 71 const CFX_Matrix* pMatrix) { |
| 72 if (!pGraphics) | 72 if (!pGraphics) |
| 73 return FWL_ERR_Indefinite; | 73 return FWL_Error::Indefinite; |
| 74 if (!m_pProperties->m_pThemeProvider) | 74 if (!m_pProperties->m_pThemeProvider) |
| 75 return FWL_ERR_Indefinite; | 75 return FWL_Error::Indefinite; |
| 76 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { | 76 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { |
| 77 GenerateBarcodeImageCache(); | 77 GenerateBarcodeImageCache(); |
| 78 if (!m_pBarcodeEngine || (m_dwStatus & XFA_BCS_EncodeSuccess) == 0) { | 78 if (!m_pBarcodeEngine || (m_dwStatus & XFA_BCS_EncodeSuccess) == 0) { |
| 79 return FWL_ERR_Succeeded; | 79 return FWL_Error::Succeeded; |
| 80 } | 80 } |
| 81 CFX_Matrix mt; | 81 CFX_Matrix mt; |
| 82 mt.e = m_rtClient.left; | 82 mt.e = m_rtClient.left; |
| 83 mt.f = m_rtClient.top; | 83 mt.f = m_rtClient.top; |
| 84 if (pMatrix) { | 84 if (pMatrix) { |
| 85 mt.Concat(*pMatrix); | 85 mt.Concat(*pMatrix); |
| 86 } | 86 } |
| 87 int32_t errorCode = 0; | 87 int32_t errorCode = 0; |
| 88 if (!m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), pMatrix, | 88 if (!m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), pMatrix, |
| 89 errorCode)) { | 89 errorCode)) { |
| 90 return FWL_ERR_Indefinite; | 90 return FWL_Error::Indefinite; |
| 91 } | 91 } |
| 92 return FWL_ERR_Succeeded; | 92 return FWL_Error::Succeeded; |
| 93 } | 93 } |
| 94 return CFWL_EditImp::DrawWidget(pGraphics, pMatrix); | 94 return CFWL_EditImp::DrawWidget(pGraphics, pMatrix); |
| 95 } | 95 } |
| 96 void CFWL_BarcodeImp::GenerateBarcodeImageCache() { | 96 void CFWL_BarcodeImp::GenerateBarcodeImageCache() { |
| 97 if ((m_dwStatus & XFA_BCS_NeedUpdate) == 0) | 97 if ((m_dwStatus & XFA_BCS_NeedUpdate) == 0) |
| 98 return; | 98 return; |
| 99 m_dwStatus = 0; | 99 m_dwStatus = 0; |
| 100 CreateBarcodeEngine(); | 100 CreateBarcodeEngine(); |
| 101 IFWL_BarcodeDP* pData = | 101 IFWL_BarcodeDP* pData = |
| 102 static_cast<IFWL_BarcodeDP*>(m_pProperties->m_pDataProvider); | 102 static_cast<IFWL_BarcodeDP*>(m_pProperties->m_pDataProvider); |
| 103 if (!pData) | 103 if (!pData) |
| 104 return; | 104 return; |
| 105 if (!m_pBarcodeEngine) | 105 if (!m_pBarcodeEngine) |
| 106 return; | 106 return; |
| 107 CFX_WideString wsText; | 107 CFX_WideString wsText; |
| 108 if (GetText(wsText) != FWL_ERR_Succeeded) | 108 if (GetText(wsText) != FWL_Error::Succeeded) |
| 109 return; | 109 return; |
| 110 CFWL_ThemePart part; | 110 CFWL_ThemePart part; |
| 111 part.m_pWidget = m_pInterface; | 111 part.m_pWidget = m_pInterface; |
| 112 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); | 112 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); |
| 113 IFX_Font* pFont = static_cast<IFX_Font*>( | 113 IFX_Font* pFont = static_cast<IFX_Font*>( |
| 114 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Font)); | 114 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Font)); |
| 115 CFX_Font* pCXFont = | 115 CFX_Font* pCXFont = |
| 116 pFont ? static_cast<CFX_Font*>(pFont->GetDevFont()) : nullptr; | 116 pFont ? static_cast<CFX_Font*>(pFont->GetDevFont()) : nullptr; |
| 117 if (pCXFont) { | 117 if (pCXFont) { |
| 118 m_pBarcodeEngine->SetFont(pCXFont); | 118 m_pBarcodeEngine->SetFont(pCXFont); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 void CFWL_BarcodeImp::SetType(BC_TYPE type) { | 195 void CFWL_BarcodeImp::SetType(BC_TYPE type) { |
| 196 if (m_type == type) { | 196 if (m_type == type) { |
| 197 return; | 197 return; |
| 198 } | 198 } |
| 199 ReleaseBarcodeEngine(); | 199 ReleaseBarcodeEngine(); |
| 200 m_type = type; | 200 m_type = type; |
| 201 m_dwStatus = XFA_BCS_NeedUpdate; | 201 m_dwStatus = XFA_BCS_NeedUpdate; |
| 202 } | 202 } |
| 203 FWL_ERR CFWL_BarcodeImp::SetText(const CFX_WideString& wsText) { | 203 FWL_Error CFWL_BarcodeImp::SetText(const CFX_WideString& wsText) { |
| 204 ReleaseBarcodeEngine(); | 204 ReleaseBarcodeEngine(); |
| 205 m_dwStatus = XFA_BCS_NeedUpdate; | 205 m_dwStatus = XFA_BCS_NeedUpdate; |
| 206 return CFWL_EditImp::SetText(wsText); | 206 return CFWL_EditImp::SetText(wsText); |
| 207 } | 207 } |
| 208 FX_BOOL CFWL_BarcodeImp::IsProtectedType() { | 208 FX_BOOL CFWL_BarcodeImp::IsProtectedType() { |
| 209 if (!m_pBarcodeEngine) { | 209 if (!m_pBarcodeEngine) { |
| 210 return TRUE; | 210 return TRUE; |
| 211 } | 211 } |
| 212 BC_TYPE tEngineType = m_pBarcodeEngine->GetType(); | 212 BC_TYPE tEngineType = m_pBarcodeEngine->GetType(); |
| 213 if (tEngineType == BC_QR_CODE || tEngineType == BC_PDF417 || | 213 if (tEngineType == BC_QR_CODE || tEngineType == BC_PDF417 || |
| 214 tEngineType == BC_DATAMATRIX) { | 214 tEngineType == BC_DATAMATRIX) { |
| 215 return TRUE; | 215 return TRUE; |
| 216 } | 216 } |
| 217 return FALSE; | 217 return FALSE; |
| 218 } | 218 } |
| 219 | 219 |
| 220 CFWL_BarcodeImpDelegate::CFWL_BarcodeImpDelegate(CFWL_BarcodeImp* pOwner) | 220 CFWL_BarcodeImpDelegate::CFWL_BarcodeImpDelegate(CFWL_BarcodeImp* pOwner) |
| 221 : CFWL_EditImpDelegate(pOwner) {} | 221 : CFWL_EditImpDelegate(pOwner) {} |
| 222 | 222 |
| 223 FWL_ERR CFWL_BarcodeImpDelegate::OnProcessEvent(CFWL_Event* pEvent) { | 223 void CFWL_BarcodeImpDelegate::OnProcessEvent(CFWL_Event* pEvent) { |
| 224 if (pEvent->GetClassID() == CFWL_EventType::TextChanged) { | 224 if (pEvent->GetClassID() == CFWL_EventType::TextChanged) { |
| 225 CFWL_BarcodeImp* pOwner = static_cast<CFWL_BarcodeImp*>(m_pOwner); | 225 CFWL_BarcodeImp* pOwner = static_cast<CFWL_BarcodeImp*>(m_pOwner); |
| 226 pOwner->ReleaseBarcodeEngine(); | 226 pOwner->ReleaseBarcodeEngine(); |
| 227 pOwner->m_dwStatus = XFA_BCS_NeedUpdate; | 227 pOwner->m_dwStatus = XFA_BCS_NeedUpdate; |
| 228 } | 228 } |
| 229 return CFWL_EditImpDelegate::OnProcessEvent(pEvent); | 229 CFWL_EditImpDelegate::OnProcessEvent(pEvent); |
| 230 } | 230 } |
| OLD | NEW |