Merge to XFA: Use stdint.h types throughout PDFium.
[pdfium.git] / xfa / src / fxfa / src / app / xfa_ffbarcode.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4 \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../../foxitlib.h"\r
8 #include "../common/xfa_common.h"\r
9 #include "xfa_fwladapter.h"\r
10 #include "xfa_ffwidget.h"\r
11 #include "xfa_fffield.h"\r
12 #include "xfa_ffpageview.h"\r
13 #include "xfa_fftextedit.h"\r
14 #include "xfa_ffbarcode.h"\r
15 static XFA_LPCBARCODETYPEENUMINFO XFA_GetBarcodeTypeByName(FX_WSTR wsName);\r
16 CXFA_FFBarcode::CXFA_FFBarcode(CXFA_FFPageView* pPageView, CXFA_WidgetAcc* pDataAcc)\r
17     : CXFA_FFTextEdit(pPageView, pDataAcc)\r
18 {\r
19 }\r
20 CXFA_FFBarcode::~CXFA_FFBarcode()\r
21 {\r
22 }\r
23 FX_BOOL CXFA_FFBarcode::LoadWidget()\r
24 {\r
25     CFWL_Barcode* pFWLBarcode = CFWL_Barcode::Create();\r
26     if(pFWLBarcode)     {\r
27         pFWLBarcode->Initialize();\r
28     }\r
29     m_pNormalWidget = pFWLBarcode;\r
30     IFWL_Widget* pWidget = m_pNormalWidget->GetWidget();\r
31     m_pNormalWidget->SetPrivateData(pWidget, this, NULL);\r
32     IFWL_NoteDriver *pNoteDriver = FWL_GetApp()->GetNoteDriver();\r
33     pNoteDriver->RegisterEventTarget(pWidget, pWidget);\r
34     m_pOldDelegate = m_pNormalWidget->SetDelegate(this);\r
35     m_pNormalWidget->LockUpdate();\r
36     CFX_WideString wsText;\r
37     m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display);\r
38     pFWLBarcode->SetText(wsText);\r
39     UpdateWidgetProperty();\r
40     m_pNormalWidget->UnlockUpdate();\r
41     return CXFA_FFField::LoadWidget();\r
42 }\r
43 void CXFA_FFBarcode::RenderWidget(CFX_Graphics* pGS, CFX_Matrix* pMatrix , FX_DWORD dwStatus , int32_t iRotate )\r
44 {\r
45     if (!IsMatchVisibleStatus(dwStatus)) {\r
46         return;\r
47     }\r
48     CFX_Matrix mtRotate;\r
49     GetRotateMatrix(mtRotate);\r
50     if (pMatrix) {\r
51         mtRotate.Concat(*pMatrix);\r
52     }\r
53     CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus);\r
54     CXFA_Border borderUI = m_pDataAcc->GetUIBorder();\r
55     DrawBorder(pGS, borderUI, m_rtUI, &mtRotate);\r
56     RenderCaption(pGS, &mtRotate);\r
57     CFX_RectF rtWidget;\r
58     m_pNormalWidget->GetWidgetRect(rtWidget);\r
59     CFX_Matrix mt;\r
60     mt.Set(1, 0, 0, 1, rtWidget.left, rtWidget.top);\r
61     mt.Concat(mtRotate);\r
62     m_pNormalWidget->DrawWidget(pGS, &mt);\r
63 }\r
64 void CXFA_FFBarcode::UpdateWidgetProperty()\r
65 {\r
66     CXFA_FFTextEdit::UpdateWidgetProperty();\r
67     CFWL_Barcode* pBarCodeWidget = (CFWL_Barcode*)m_pNormalWidget;\r
68     CFX_WideString wsType = GetDataAcc()->GetBarcodeType();\r
69     XFA_LPCBARCODETYPEENUMINFO pBarcodeTypeInfo = XFA_GetBarcodeTypeByName(wsType);\r
70     pBarCodeWidget->SetType(pBarcodeTypeInfo->eBCType);\r
71     CXFA_WidgetAcc *pAcc = GetDataAcc();\r
72     int32_t intVal;\r
73     FX_CHAR  charVal;\r
74     FX_BOOL  boolVal;\r
75     FX_FLOAT floatVal;\r
76     if (pAcc->GetBarcodeAttribute_CharEncoding(intVal)) {\r
77         pBarCodeWidget->SetCharEncoding((BC_CHAR_ENCODING)intVal);\r
78     }\r
79     if (pAcc->GetBarcodeAttribute_Checksum(intVal)) {\r
80         pBarCodeWidget->SetCalChecksum(intVal);\r
81     }\r
82     if (pAcc->GetBarcodeAttribute_DataLength(intVal)) {\r
83         pBarCodeWidget->SetDataLength(intVal);\r
84     }\r
85     if (pAcc->GetBarcodeAttribute_StartChar(charVal)) {\r
86         pBarCodeWidget->SetStartChar(charVal);\r
87     }\r
88     if (pAcc->GetBarcodeAttribute_EndChar(charVal)) {\r
89         pBarCodeWidget->SetEndChar(charVal);\r
90     }\r
91     if (pAcc->GetBarcodeAttribute_ECLevel(intVal)) {\r
92         pBarCodeWidget->SetErrorCorrectionLevel(intVal);\r
93     }\r
94     if (pAcc->GetBarcodeAttribute_ModuleWidth(intVal)) {\r
95         pBarCodeWidget->SetModuleWidth(intVal);\r
96     }\r
97     if (pAcc->GetBarcodeAttribute_ModuleHeight(intVal)) {\r
98         pBarCodeWidget->SetModuleHeight(intVal);\r
99     }\r
100     if (pAcc->GetBarcodeAttribute_PrintChecksum(boolVal)) {\r
101         pBarCodeWidget->SetPrintChecksum(boolVal);\r
102     }\r
103     if (pAcc->GetBarcodeAttribute_TextLocation(intVal)) {\r
104         pBarCodeWidget->SetTextLocation((BC_TEXT_LOC)intVal);\r
105     }\r
106     if (pAcc->GetBarcodeAttribute_Truncate(boolVal)) {\r
107         pBarCodeWidget->SetTruncated(boolVal);\r
108     }\r
109     if (pAcc->GetBarcodeAttribute_WideNarrowRatio(floatVal))    {\r
110         pBarCodeWidget->SetWideNarrowRatio((int32_t)floatVal);\r
111     }\r
112     if (pBarcodeTypeInfo->eName == XFA_BARCODETYPE_code3Of9\r
113             || pBarcodeTypeInfo->eName == XFA_BARCODETYPE_ean8\r
114             || pBarcodeTypeInfo->eName == XFA_BARCODETYPE_ean13\r
115             || pBarcodeTypeInfo->eName == XFA_BARCODETYPE_upcA) {\r
116         pBarCodeWidget->SetPrintChecksum(TRUE);\r
117     }\r
118 }\r
119 FX_BOOL CXFA_FFBarcode::OnLButtonDown(FX_DWORD dwFlags, FX_FLOAT fx, FX_FLOAT fy)\r
120 {\r
121     CFWL_Barcode* pBarCodeWidget = (CFWL_Barcode*)m_pNormalWidget;\r
122     if (!pBarCodeWidget || pBarCodeWidget->IsProtectedType()) {\r
123         return FALSE;\r
124     }\r
125     if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) {\r
126         return FALSE;\r
127     }\r
128     return CXFA_FFTextEdit::OnLButtonDown(dwFlags, fx, fy);\r
129 }\r
130 FX_BOOL CXFA_FFBarcode::OnRButtonDown(FX_DWORD dwFlags, FX_FLOAT fx, FX_FLOAT fy)\r
131 {\r
132     CFWL_Barcode* pBarCodeWidget = (CFWL_Barcode*)m_pNormalWidget;\r
133     if (!pBarCodeWidget || pBarCodeWidget->IsProtectedType()) {\r
134         return FALSE;\r
135     }\r
136     return CXFA_FFTextEdit::OnRButtonDown(dwFlags, fx, fy);\r
137 }\r
138 extern const XFA_BARCODETYPEENUMINFO g_XFABarCodeTypeEnumData[] = {\r
139     {0x7fb4a18, L"ean13", XFA_BARCODETYPE_ean13, BC_EAN13},\r
140     {0x8d13a3d, L"code11", XFA_BARCODETYPE_code11, BC_UNKNOWN},\r
141     {0x8d149a8, L"code49", XFA_BARCODETYPE_code49, BC_UNKNOWN},\r
142     {0x8d16347, L"code93", XFA_BARCODETYPE_code93, BC_UNKNOWN},\r
143     {0x91a92e2, L"upsMaxicode", XFA_BARCODETYPE_upsMaxicode, BC_UNKNOWN},\r
144     {0xa7d48dc, L"fim", XFA_BARCODETYPE_fim, BC_UNKNOWN},\r
145     {0xb359fe9, L"msi", XFA_BARCODETYPE_msi, BC_UNKNOWN},\r
146     {0x121f738c, L"code2Of5Matrix", XFA_BARCODETYPE_code2Of5Matrix, BC_UNKNOWN},\r
147     {0x15358616, L"ucc128", XFA_BARCODETYPE_ucc128, BC_UNKNOWN},\r
148     {0x1f4bfa05, L"rfid", XFA_BARCODETYPE_rfid, BC_UNKNOWN},\r
149     {0x1fda71bc, L"rss14Stacked", XFA_BARCODETYPE_rss14Stacked, BC_UNKNOWN},\r
150     {0x22065087, L"ean8add2", XFA_BARCODETYPE_ean8add2, BC_UNKNOWN},\r
151     {0x2206508a, L"ean8add5", XFA_BARCODETYPE_ean8add5, BC_UNKNOWN},\r
152     {0x2278366c, L"codabar", XFA_BARCODETYPE_codabar, BC_CODABAR},\r
153     {0x2a039a8d, L"telepen", XFA_BARCODETYPE_telepen, BC_UNKNOWN},\r
154     {0x323ed337, L"upcApwcd", XFA_BARCODETYPE_upcApwcd, BC_UNKNOWN},\r
155     {0x347a1846, L"postUSIMB", XFA_BARCODETYPE_postUSIMB, BC_UNKNOWN},\r
156     {0x391bb836, L"code128", XFA_BARCODETYPE_code128, BC_CODE128},\r
157     {0x398eddaf, L"dataMatrix", XFA_BARCODETYPE_dataMatrix, BC_DATAMATRIX},\r
158     {0x3cff60a8, L"upcEadd2", XFA_BARCODETYPE_upcEadd2, BC_UNKNOWN},\r
159     {0x3cff60ab, L"upcEadd5", XFA_BARCODETYPE_upcEadd5, BC_UNKNOWN},\r
160     {0x402cb188, L"code2Of5Standard", XFA_BARCODETYPE_code2Of5Standard, BC_UNKNOWN},\r
161     {0x411764f7, L"aztec", XFA_BARCODETYPE_aztec, BC_UNKNOWN},\r
162     {0x44d4e84c, L"ean8", XFA_BARCODETYPE_ean8, BC_EAN8},\r
163     {0x48468902, L"ucc128sscc", XFA_BARCODETYPE_ucc128sscc, BC_UNKNOWN},\r
164     {0x4880aea4, L"upcAadd2", XFA_BARCODETYPE_upcAadd2, BC_UNKNOWN},\r
165     {0x4880aea7, L"upcAadd5", XFA_BARCODETYPE_upcAadd5, BC_UNKNOWN},\r
166     {0x54f18256, L"code2Of5Industrial", XFA_BARCODETYPE_code2Of5Industrial, BC_UNKNOWN},\r
167     {0x58e15f25, L"rss14Limited", XFA_BARCODETYPE_rss14Limited, BC_UNKNOWN},\r
168     {0x5c08d1b9, L"postAUSReplyPaid", XFA_BARCODETYPE_postAUSReplyPaid, BC_UNKNOWN},\r
169     {0x5fa700bd, L"rss14", XFA_BARCODETYPE_rss14, BC_UNKNOWN},\r
170     {0x631a7e35, L"logmars", XFA_BARCODETYPE_logmars, BC_UNKNOWN},\r
171     {0x6a236236, L"pdf417", XFA_BARCODETYPE_pdf417, BC_PDF417},\r
172     {0x6d098ece, L"upcean2", XFA_BARCODETYPE_upcean2, BC_UNKNOWN},\r
173     {0x6d098ed1, L"upcean5", XFA_BARCODETYPE_upcean5, BC_UNKNOWN},\r
174     {0x76b04eed, L"code3Of9extended", XFA_BARCODETYPE_code3Of9extended, BC_UNKNOWN},\r
175     {0x7c7db84a, L"maxicode", XFA_BARCODETYPE_maxicode, BC_UNKNOWN},\r
176     {0x8266f7f7, L"ucc128random", XFA_BARCODETYPE_ucc128random, BC_UNKNOWN},\r
177     {0x83eca147, L"postUSDPBC", XFA_BARCODETYPE_postUSDPBC, BC_UNKNOWN},\r
178     {0x8dd71de0, L"postAUSStandard", XFA_BARCODETYPE_postAUSStandard, BC_UNKNOWN},\r
179     {0x98adad85, L"plessey", XFA_BARCODETYPE_plessey, BC_UNKNOWN},\r
180     {0x9f84cce6, L"ean13pwcd", XFA_BARCODETYPE_ean13pwcd, BC_UNKNOWN},\r
181     {0xb514fbe9, L"upcA", XFA_BARCODETYPE_upcA, BC_UPCA},\r
182     {0xb514fbed, L"upcE", XFA_BARCODETYPE_upcE, BC_UNKNOWN},\r
183     {0xb5c6a853, L"ean13add2", XFA_BARCODETYPE_ean13add2, BC_UNKNOWN},\r
184     {0xb5c6a856, L"ean13add5", XFA_BARCODETYPE_ean13add5, BC_UNKNOWN},\r
185     {0xb81fc512, L"postUKRM4SCC", XFA_BARCODETYPE_postUKRM4SCC, BC_UNKNOWN},\r
186     {0xbad34b22, L"code128SSCC", XFA_BARCODETYPE_code128SSCC, BC_UNKNOWN},\r
187     {0xbfbe0cf6, L"postUS5Zip", XFA_BARCODETYPE_postUS5Zip, BC_UNKNOWN},\r
188     {0xc56618e8, L"pdf417macro", XFA_BARCODETYPE_pdf417macro, BC_UNKNOWN},\r
189     {0xca730f8a, L"code2Of5Interleaved", XFA_BARCODETYPE_code2Of5Interleaved, BC_UNKNOWN},\r
190     {0xd0097ac6, L"rss14Expanded", XFA_BARCODETYPE_rss14Expanded, BC_UNKNOWN},\r
191     {0xd25a0240, L"postAUSCust2", XFA_BARCODETYPE_postAUSCust2, BC_UNKNOWN},\r
192     {0xd25a0241, L"postAUSCust3", XFA_BARCODETYPE_postAUSCust3, BC_UNKNOWN},\r
193     {0xd53ed3e7, L"rss14Truncated", XFA_BARCODETYPE_rss14Truncated, BC_UNKNOWN},\r
194     {0xe72bcd57, L"code128A", XFA_BARCODETYPE_code128A, BC_UNKNOWN},\r
195     {0xe72bcd58, L"code128B", XFA_BARCODETYPE_code128B, BC_CODE128_B},\r
196     {0xe72bcd59, L"code128C", XFA_BARCODETYPE_code128C, BC_CODE128_C},\r
197     {0xee83c50f, L"rss14StackedOmni", XFA_BARCODETYPE_rss14StackedOmni, BC_UNKNOWN},\r
198     {0xf2a18f7e, L"QRCode", XFA_BARCODETYPE_QRCode, BC_QR_CODE},\r
199     {0xfaeaf37f, L"postUSStandard", XFA_BARCODETYPE_postUSStandard, BC_UNKNOWN},\r
200     {0xfb48155c, L"code3Of9", XFA_BARCODETYPE_code3Of9, BC_CODE39},\r
201 };\r
202 extern const int32_t g_iXFABarcodeTypeCount = sizeof(g_XFABarCodeTypeEnumData) / sizeof(XFA_BARCODETYPEENUMINFO);\r
203 static XFA_LPCBARCODETYPEENUMINFO XFA_GetBarcodeTypeByName(FX_WSTR wsName)\r
204 {\r
205     int32_t iLength = wsName.GetLength();\r
206     if (iLength == 0) {\r
207         return NULL;\r
208     }\r
209     uint32_t uHash = FX_HashCode_String_GetW(wsName.GetPtr(), iLength, TRUE);\r
210     int32_t iStart = 0, iEnd = g_iXFABarcodeTypeCount - 1;\r
211     do {\r
212         int32_t iMid = (iStart + iEnd) / 2;\r
213         XFA_LPCBARCODETYPEENUMINFO pInfo = g_XFABarCodeTypeEnumData + iMid;\r
214         if (uHash == pInfo->uHash) {\r
215             return pInfo;\r
216         } else if (uHash < pInfo->uHash) {\r
217             iEnd = iMid - 1;\r
218         } else {\r
219             iStart = iMid + 1;\r
220         }\r
221     } while (iStart <= iEnd);\r
222     return NULL;\r
223 }\r