Make CFWL_Barcode's status an enum.
Fix some nits along the way.
Change-Id: Iee52addeaf3e360e5f7296edec567cd34a1c579d
Reviewed-on: https://pdfium-review.googlesource.com/c/49011
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/xfa/fwl/cfwl_barcode.cpp b/xfa/fwl/cfwl_barcode.cpp
index f59b441..9cc2918 100644
--- a/xfa/fwl/cfwl_barcode.cpp
+++ b/xfa/fwl/cfwl_barcode.cpp
@@ -17,12 +17,9 @@
#include "xfa/fwl/theme/cfwl_utils.h"
CFWL_Barcode::CFWL_Barcode(const CFWL_App* app)
- : CFWL_Edit(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr),
- m_dwStatus(0),
- m_type(BC_UNKNOWN),
- m_dwAttributeMask(FWL_BCDATTRIBUTE_NONE) {}
+ : CFWL_Edit(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr) {}
-CFWL_Barcode::~CFWL_Barcode() {}
+CFWL_Barcode::~CFWL_Barcode() = default;
FWL_Type CFWL_Barcode::GetClassID() const {
return FWL_Type::Barcode;
@@ -44,7 +41,7 @@
return;
if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) {
GenerateBarcodeImageCache();
- if (!m_pBarcodeEngine || (m_dwStatus & XFA_BCS_EncodeSuccess) == 0)
+ if (!m_pBarcodeEngine || m_eStatus != Status::kEncodeSuccess)
return;
CFX_Matrix mt;
@@ -64,13 +61,13 @@
m_pBarcodeEngine.reset();
m_type = type;
- m_dwStatus = XFA_BCS_NeedUpdate;
+ m_eStatus = Status::kNeedUpdate;
}
void CFWL_Barcode::SetText(const WideString& wsText,
CFDE_TextEditEngine::RecordOperation op) {
m_pBarcodeEngine.reset();
- m_dwStatus = XFA_BCS_NeedUpdate;
+ m_eStatus = Status::kNeedUpdate;
CFWL_Edit::SetText(wsText, op);
}
@@ -79,17 +76,14 @@
return true;
BC_TYPE tEngineType = m_pBarcodeEngine->GetType();
- if (tEngineType == BC_QR_CODE || tEngineType == BC_PDF417 ||
- tEngineType == BC_DATAMATRIX) {
- return true;
- }
- return false;
+ return tEngineType == BC_QR_CODE || tEngineType == BC_PDF417 ||
+ tEngineType == BC_DATAMATRIX;
}
void CFWL_Barcode::OnProcessEvent(CFWL_Event* pEvent) {
if (pEvent->GetType() == CFWL_Event::Type::TextWillChange) {
m_pBarcodeEngine.reset();
- m_dwStatus = XFA_BCS_NeedUpdate;
+ m_eStatus = Status::kNeedUpdate;
}
CFWL_Edit::OnProcessEvent(pEvent);
}
@@ -151,10 +145,10 @@
}
void CFWL_Barcode::GenerateBarcodeImageCache() {
- if ((m_dwStatus & XFA_BCS_NeedUpdate) == 0)
+ if (m_eStatus != Status::kNeedUpdate)
return;
- m_dwStatus = 0;
+ m_eStatus = Status::kNormal;
CreateBarcodeEngine();
if (!m_pBarcodeEngine)
return;
@@ -198,9 +192,9 @@
if (m_dwAttributeMask & FWL_BCDATTRIBUTE_ECLEVEL)
m_pBarcodeEngine->SetErrorCorrectionLevel(m_nECLevel);
- m_dwStatus = m_pBarcodeEngine->Encode(GetText().AsStringView())
- ? XFA_BCS_EncodeSuccess
- : 0;
+ m_eStatus = m_pBarcodeEngine->Encode(GetText().AsStringView())
+ ? Status::kEncodeSuccess
+ : Status::kNormal;
}
void CFWL_Barcode::CreateBarcodeEngine() {
diff --git a/xfa/fwl/cfwl_barcode.h b/xfa/fwl/cfwl_barcode.h
index cd36cc3..759d048 100644
--- a/xfa/fwl/cfwl_barcode.h
+++ b/xfa/fwl/cfwl_barcode.h
@@ -11,15 +11,8 @@
#include "fxbarcode/BC_Library.h"
#include "xfa/fwl/cfwl_edit.h"
-#include "xfa/fwl/cfwl_scrollbar.h"
-#include "xfa/fwl/cfwl_widget.h"
-class CFWL_WidgetProperties;
class CFX_Barcode;
-class CFWL_Widget;
-
-#define XFA_BCS_NeedUpdate 0x0001
-#define XFA_BCS_EncodeSuccess 0x0002
enum FWL_BCDAttribute {
FWL_BCDATTRIBUTE_NONE = 0,
@@ -69,12 +62,18 @@
void SetErrorCorrectionLevel(int32_t ecLevel);
private:
+ enum class Status : uint8_t {
+ kNormal,
+ kNeedUpdate,
+ kEncodeSuccess,
+ };
+
void GenerateBarcodeImageCache();
void CreateBarcodeEngine();
std::unique_ptr<CFX_Barcode> m_pBarcodeEngine;
- uint32_t m_dwStatus;
- BC_TYPE m_type;
+ Status m_eStatus = Status::kNormal;
+ BC_TYPE m_type = BC_UNKNOWN;
BC_CHAR_ENCODING m_eCharEncoding;
int32_t m_nModuleHeight;
int32_t m_nModuleWidth;
@@ -86,7 +85,7 @@
char m_cStartChar;
char m_cEndChar;
int32_t m_nECLevel;
- uint32_t m_dwAttributeMask;
+ uint32_t m_dwAttributeMask = 0;
};
#endif // XFA_FWL_CFWL_BARCODE_H_