| 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/core/cfwl_barcode.h" | 7 #include "xfa/fwl/core/cfwl_barcode.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "third_party/base/ptr_util.h" | 11 #include "third_party/base/ptr_util.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 IFWL_Barcode* ToBarcode(IFWL_Widget* widget) { | 15 IFWL_Barcode* ToBarcode(IFWL_Widget* widget) { |
| 16 return static_cast<IFWL_Barcode*>(widget); | 16 return static_cast<IFWL_Barcode*>(widget); |
| 17 } | 17 } |
| 18 | 18 |
| 19 } // namespace | 19 } // namespace |
| 20 | 20 |
| 21 CFWL_Barcode::CFWL_Barcode(const IFWL_App* app) : CFWL_Edit(app) {} | 21 CFWL_Barcode::CFWL_Barcode(const IFWL_App* app) |
| 22 : CFWL_Edit(app), m_dwAttributeMask(FWL_BCDATTRIBUTE_NONE) {} |
| 22 | 23 |
| 23 CFWL_Barcode::~CFWL_Barcode() {} | 24 CFWL_Barcode::~CFWL_Barcode() {} |
| 24 | 25 |
| 25 void CFWL_Barcode::Initialize() { | 26 void CFWL_Barcode::Initialize() { |
| 26 ASSERT(!m_pIface); | 27 ASSERT(!m_pIface); |
| 27 | 28 |
| 28 m_pIface = pdfium::MakeUnique<IFWL_Barcode>( | 29 m_pIface = pdfium::MakeUnique<IFWL_Barcode>( |
| 29 m_pApp, pdfium::MakeUnique<CFWL_WidgetProperties>(&m_barcodeData)); | 30 m_pApp, pdfium::MakeUnique<CFWL_WidgetProperties>(this)); |
| 30 | 31 |
| 31 CFWL_Widget::Initialize(); | 32 CFWL_Widget::Initialize(); |
| 32 } | 33 } |
| 33 | 34 |
| 34 void CFWL_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) { | 35 void CFWL_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) { |
| 35 m_barcodeData.m_dwAttributeMask |= FWL_BCDATTRIBUTE_CHARENCODING; | 36 m_dwAttributeMask |= FWL_BCDATTRIBUTE_CHARENCODING; |
| 36 m_barcodeData.m_eCharEncoding = encoding; | 37 m_eCharEncoding = encoding; |
| 37 } | 38 } |
| 39 |
| 38 void CFWL_Barcode::SetModuleHeight(int32_t height) { | 40 void CFWL_Barcode::SetModuleHeight(int32_t height) { |
| 39 m_barcodeData.m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEHEIGHT; | 41 m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEHEIGHT; |
| 40 m_barcodeData.m_nModuleHeight = height; | 42 m_nModuleHeight = height; |
| 41 } | 43 } |
| 44 |
| 42 void CFWL_Barcode::SetModuleWidth(int32_t width) { | 45 void CFWL_Barcode::SetModuleWidth(int32_t width) { |
| 43 m_barcodeData.m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEWIDTH; | 46 m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEWIDTH; |
| 44 m_barcodeData.m_nModuleWidth = width; | 47 m_nModuleWidth = width; |
| 45 } | 48 } |
| 49 |
| 46 void CFWL_Barcode::SetDataLength(int32_t dataLength) { | 50 void CFWL_Barcode::SetDataLength(int32_t dataLength) { |
| 47 m_barcodeData.m_dwAttributeMask |= FWL_BCDATTRIBUTE_DATALENGTH; | 51 m_dwAttributeMask |= FWL_BCDATTRIBUTE_DATALENGTH; |
| 48 m_barcodeData.m_nDataLength = dataLength; | 52 m_nDataLength = dataLength; |
| 49 ToBarcode(GetWidget())->SetLimit(dataLength); | 53 ToBarcode(GetWidget())->SetLimit(dataLength); |
| 50 } | 54 } |
| 55 |
| 51 void CFWL_Barcode::SetCalChecksum(bool calChecksum) { | 56 void CFWL_Barcode::SetCalChecksum(bool calChecksum) { |
| 52 m_barcodeData.m_dwAttributeMask |= FWL_BCDATTRIBUTE_CALCHECKSUM; | 57 m_dwAttributeMask |= FWL_BCDATTRIBUTE_CALCHECKSUM; |
| 53 m_barcodeData.m_bCalChecksum = calChecksum; | 58 m_bCalChecksum = calChecksum; |
| 54 } | 59 } |
| 60 |
| 55 void CFWL_Barcode::SetPrintChecksum(bool printChecksum) { | 61 void CFWL_Barcode::SetPrintChecksum(bool printChecksum) { |
| 56 m_barcodeData.m_dwAttributeMask |= FWL_BCDATTRIBUTE_PRINTCHECKSUM; | 62 m_dwAttributeMask |= FWL_BCDATTRIBUTE_PRINTCHECKSUM; |
| 57 m_barcodeData.m_bPrintChecksum = printChecksum; | 63 m_bPrintChecksum = printChecksum; |
| 58 } | 64 } |
| 65 |
| 59 void CFWL_Barcode::SetTextLocation(BC_TEXT_LOC location) { | 66 void CFWL_Barcode::SetTextLocation(BC_TEXT_LOC location) { |
| 60 m_barcodeData.m_dwAttributeMask |= FWL_BCDATTRIBUTE_TEXTLOCATION; | 67 m_dwAttributeMask |= FWL_BCDATTRIBUTE_TEXTLOCATION; |
| 61 m_barcodeData.m_eTextLocation = location; | 68 m_eTextLocation = location; |
| 62 } | 69 } |
| 70 |
| 63 void CFWL_Barcode::SetWideNarrowRatio(int32_t ratio) { | 71 void CFWL_Barcode::SetWideNarrowRatio(int32_t ratio) { |
| 64 m_barcodeData.m_dwAttributeMask |= FWL_BCDATTRIBUTE_WIDENARROWRATIO; | 72 m_dwAttributeMask |= FWL_BCDATTRIBUTE_WIDENARROWRATIO; |
| 65 m_barcodeData.m_nWideNarrowRatio = ratio; | 73 m_nWideNarrowRatio = ratio; |
| 66 } | 74 } |
| 75 |
| 67 void CFWL_Barcode::SetStartChar(FX_CHAR startChar) { | 76 void CFWL_Barcode::SetStartChar(FX_CHAR startChar) { |
| 68 m_barcodeData.m_dwAttributeMask |= FWL_BCDATTRIBUTE_STARTCHAR; | 77 m_dwAttributeMask |= FWL_BCDATTRIBUTE_STARTCHAR; |
| 69 m_barcodeData.m_cStartChar = startChar; | 78 m_cStartChar = startChar; |
| 70 } | 79 } |
| 80 |
| 71 void CFWL_Barcode::SetEndChar(FX_CHAR endChar) { | 81 void CFWL_Barcode::SetEndChar(FX_CHAR endChar) { |
| 72 m_barcodeData.m_dwAttributeMask |= FWL_BCDATTRIBUTE_ENDCHAR; | 82 m_dwAttributeMask |= FWL_BCDATTRIBUTE_ENDCHAR; |
| 73 m_barcodeData.m_cEndChar = endChar; | 83 m_cEndChar = endChar; |
| 74 } | 84 } |
| 85 |
| 75 void CFWL_Barcode::SetVersion(int32_t version) { | 86 void CFWL_Barcode::SetVersion(int32_t version) { |
| 76 m_barcodeData.m_dwAttributeMask |= FWL_BCDATTRIBUTE_VERSION; | 87 m_dwAttributeMask |= FWL_BCDATTRIBUTE_VERSION; |
| 77 m_barcodeData.m_nVersion = version; | 88 m_nVersion = version; |
| 78 } | 89 } |
| 90 |
| 79 void CFWL_Barcode::SetErrorCorrectionLevel(int32_t ecLevel) { | 91 void CFWL_Barcode::SetErrorCorrectionLevel(int32_t ecLevel) { |
| 80 m_barcodeData.m_dwAttributeMask |= FWL_BCDATTRIBUTE_ECLEVEL; | 92 m_dwAttributeMask |= FWL_BCDATTRIBUTE_ECLEVEL; |
| 81 m_barcodeData.m_nECLevel = ecLevel; | 93 m_nECLevel = ecLevel; |
| 82 } | 94 } |
| 95 |
| 83 void CFWL_Barcode::SetTruncated(bool truncated) { | 96 void CFWL_Barcode::SetTruncated(bool truncated) { |
| 84 m_barcodeData.m_dwAttributeMask |= FWL_BCDATTRIBUTE_TRUNCATED; | 97 m_dwAttributeMask |= FWL_BCDATTRIBUTE_TRUNCATED; |
| 85 m_barcodeData.m_bTruncated = truncated; | 98 m_bTruncated = truncated; |
| 86 } | 99 } |
| 100 |
| 87 void CFWL_Barcode::ResetBarcodeAttributes() { | 101 void CFWL_Barcode::ResetBarcodeAttributes() { |
| 88 m_barcodeData.m_dwAttributeMask = FWL_BCDATTRIBUTE_NONE; | 102 m_dwAttributeMask = FWL_BCDATTRIBUTE_NONE; |
| 89 } | 103 } |
| 90 | 104 |
| 91 void CFWL_Barcode::SetType(BC_TYPE type) { | 105 void CFWL_Barcode::SetType(BC_TYPE type) { |
| 92 if (GetWidget()) | 106 if (GetWidget()) |
| 93 ToBarcode(GetWidget())->SetType(type); | 107 ToBarcode(GetWidget())->SetType(type); |
| 94 } | 108 } |
| 95 | 109 |
| 96 bool CFWL_Barcode::IsProtectedType() { | 110 bool CFWL_Barcode::IsProtectedType() { |
| 97 return GetWidget() ? ToBarcode(GetWidget())->IsProtectedType() : false; | 111 return GetWidget() ? ToBarcode(GetWidget())->IsProtectedType() : false; |
| 98 } | 112 } |
| 99 | 113 |
| 100 CFWL_Barcode::CFWL_BarcodeDP::CFWL_BarcodeDP() | 114 FWL_Error CFWL_Barcode::GetCaption(IFWL_Widget* pWidget, |
| 101 : m_dwAttributeMask(FWL_BCDATTRIBUTE_NONE) {} | 115 CFX_WideString& wsCaption) { |
| 102 | |
| 103 FWL_Error CFWL_Barcode::CFWL_BarcodeDP::GetCaption(IFWL_Widget* pWidget, | |
| 104 CFX_WideString& wsCaption) { | |
| 105 return FWL_Error::Succeeded; | 116 return FWL_Error::Succeeded; |
| 106 } | 117 } |
| 107 | 118 |
| 108 BC_CHAR_ENCODING CFWL_Barcode::CFWL_BarcodeDP::GetCharEncoding() const { | 119 BC_CHAR_ENCODING CFWL_Barcode::GetCharEncoding() const { |
| 109 return m_eCharEncoding; | 120 return m_eCharEncoding; |
| 110 } | 121 } |
| 111 | 122 |
| 112 int32_t CFWL_Barcode::CFWL_BarcodeDP::GetModuleHeight() const { | 123 int32_t CFWL_Barcode::GetModuleHeight() const { |
| 113 return m_nModuleHeight; | 124 return m_nModuleHeight; |
| 114 } | 125 } |
| 115 | 126 |
| 116 int32_t CFWL_Barcode::CFWL_BarcodeDP::GetModuleWidth() const { | 127 int32_t CFWL_Barcode::GetModuleWidth() const { |
| 117 return m_nModuleWidth; | 128 return m_nModuleWidth; |
| 118 } | 129 } |
| 119 | 130 |
| 120 int32_t CFWL_Barcode::CFWL_BarcodeDP::GetDataLength() const { | 131 int32_t CFWL_Barcode::GetDataLength() const { |
| 121 return m_nDataLength; | 132 return m_nDataLength; |
| 122 } | 133 } |
| 123 | 134 |
| 124 bool CFWL_Barcode::CFWL_BarcodeDP::GetCalChecksum() const { | 135 bool CFWL_Barcode::GetCalChecksum() const { |
| 125 return m_bCalChecksum; | 136 return m_bCalChecksum; |
| 126 } | 137 } |
| 127 | 138 |
| 128 bool CFWL_Barcode::CFWL_BarcodeDP::GetPrintChecksum() const { | 139 bool CFWL_Barcode::GetPrintChecksum() const { |
| 129 return m_bPrintChecksum; | 140 return m_bPrintChecksum; |
| 130 } | 141 } |
| 131 | 142 |
| 132 BC_TEXT_LOC CFWL_Barcode::CFWL_BarcodeDP::GetTextLocation() const { | 143 BC_TEXT_LOC CFWL_Barcode::GetTextLocation() const { |
| 133 return m_eTextLocation; | 144 return m_eTextLocation; |
| 134 } | 145 } |
| 135 | 146 |
| 136 int32_t CFWL_Barcode::CFWL_BarcodeDP::GetWideNarrowRatio() const { | 147 int32_t CFWL_Barcode::GetWideNarrowRatio() const { |
| 137 return m_nWideNarrowRatio; | 148 return m_nWideNarrowRatio; |
| 138 } | 149 } |
| 139 | 150 |
| 140 FX_CHAR CFWL_Barcode::CFWL_BarcodeDP::GetStartChar() const { | 151 FX_CHAR CFWL_Barcode::GetStartChar() const { |
| 141 return m_cStartChar; | 152 return m_cStartChar; |
| 142 } | 153 } |
| 143 | 154 |
| 144 FX_CHAR CFWL_Barcode::CFWL_BarcodeDP::GetEndChar() const { | 155 FX_CHAR CFWL_Barcode::GetEndChar() const { |
| 145 return m_cEndChar; | 156 return m_cEndChar; |
| 146 } | 157 } |
| 147 | 158 |
| 148 int32_t CFWL_Barcode::CFWL_BarcodeDP::GetVersion() const { | 159 int32_t CFWL_Barcode::GetVersion() const { |
| 149 return m_nVersion; | 160 return m_nVersion; |
| 150 } | 161 } |
| 151 | 162 |
| 152 int32_t CFWL_Barcode::CFWL_BarcodeDP::GetErrorCorrectionLevel() const { | 163 int32_t CFWL_Barcode::GetErrorCorrectionLevel() const { |
| 153 return m_nECLevel; | 164 return m_nECLevel; |
| 154 } | 165 } |
| 155 | 166 |
| 156 bool CFWL_Barcode::CFWL_BarcodeDP::GetTruncated() const { | 167 bool CFWL_Barcode::GetTruncated() const { |
| 157 return m_bTruncated; | 168 return m_bTruncated; |
| 158 } | 169 } |
| 159 | 170 |
| 160 uint32_t CFWL_Barcode::CFWL_BarcodeDP::GetBarcodeAttributeMask() const { | 171 uint32_t CFWL_Barcode::GetBarcodeAttributeMask() const { |
| 161 return m_dwAttributeMask; | 172 return m_dwAttributeMask; |
| 162 } | 173 } |
| OLD | NEW |