| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "core/fxcrt/include/fx_ext.h" | |
| 8 #include "xfa/fxbarcode/include/BC_Library.h" | |
| 9 #include "xfa/fxfa/app/xfa_ffnotify.h" | |
| 10 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" | |
| 11 #include "xfa/fxfa/parser/xfa_docdata.h" | |
| 12 #include "xfa/fxfa/parser/xfa_doclayout.h" | |
| 13 #include "xfa/fxfa/parser/xfa_document.h" | |
| 14 #include "xfa/fxfa/parser/xfa_localemgr.h" | |
| 15 #include "xfa/fxfa/parser/xfa_localevalue.h" | |
| 16 #include "xfa/fxfa/parser/xfa_object.h" | |
| 17 #include "xfa/fxfa/parser/xfa_parser.h" | |
| 18 #include "xfa/fxfa/parser/xfa_script.h" | |
| 19 #include "xfa/fxfa/parser/xfa_utils.h" | |
| 20 | |
| 21 static FX_ARGB XFA_WStringToColor(const CFX_WideStringC& wsValue) { | |
| 22 uint8_t r = 0, g = 0, b = 0; | |
| 23 if (wsValue.GetLength() == 0) { | |
| 24 return 0xff000000; | |
| 25 } | |
| 26 int cc = 0; | |
| 27 const FX_WCHAR* str = wsValue.c_str(); | |
| 28 int len = wsValue.GetLength(); | |
| 29 while (XFA_IsSpace(str[cc]) && cc < len) { | |
| 30 cc++; | |
| 31 } | |
| 32 if (cc >= len) { | |
| 33 return 0xff000000; | |
| 34 } | |
| 35 while (cc < len) { | |
| 36 if (str[cc] == ',' || !XFA_IsDigit(str[cc])) { | |
| 37 break; | |
| 38 } | |
| 39 r = r * 10 + str[cc] - '0'; | |
| 40 cc++; | |
| 41 } | |
| 42 if (cc < len && str[cc] == ',') { | |
| 43 cc++; | |
| 44 while (XFA_IsSpace(str[cc]) && cc < len) { | |
| 45 cc++; | |
| 46 } | |
| 47 while (cc < len) { | |
| 48 if (str[cc] == ',' || !XFA_IsDigit(str[cc])) { | |
| 49 break; | |
| 50 } | |
| 51 g = g * 10 + str[cc] - '0'; | |
| 52 cc++; | |
| 53 } | |
| 54 if (cc < len && str[cc] == ',') { | |
| 55 cc++; | |
| 56 while (XFA_IsSpace(str[cc]) && cc < len) { | |
| 57 cc++; | |
| 58 } | |
| 59 while (cc < len) { | |
| 60 if (str[cc] == ',' || !XFA_IsDigit(str[cc])) { | |
| 61 break; | |
| 62 } | |
| 63 b = b * 10 + str[cc] - '0'; | |
| 64 cc++; | |
| 65 } | |
| 66 } | |
| 67 } | |
| 68 return (0xff << 24) | (r << 16) | (g << 8) | b; | |
| 69 } | |
| 70 XFA_ELEMENT CXFA_Data::GetClassID() const { | |
| 71 return m_pNode ? m_pNode->GetClassID() : XFA_ELEMENT_UNKNOWN; | |
| 72 } | |
| 73 FX_BOOL CXFA_Data::TryMeasure(XFA_ATTRIBUTE eAttr, | |
| 74 FX_FLOAT& fValue, | |
| 75 FX_BOOL bUseDefault) const { | |
| 76 CXFA_Measurement ms; | |
| 77 if (m_pNode->TryMeasure(eAttr, ms, bUseDefault)) { | |
| 78 fValue = ms.ToUnit(XFA_UNIT_Pt); | |
| 79 return TRUE; | |
| 80 } | |
| 81 return FALSE; | |
| 82 } | |
| 83 FX_BOOL CXFA_Data::SetMeasure(XFA_ATTRIBUTE eAttr, FX_FLOAT fValue) { | |
| 84 CXFA_Measurement ms(fValue, XFA_UNIT_Pt); | |
| 85 return m_pNode->SetMeasure(eAttr, ms); | |
| 86 } | |
| 87 CXFA_Fill::CXFA_Fill(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 88 CXFA_Fill::~CXFA_Fill() {} | |
| 89 int32_t CXFA_Fill::GetPresence() { | |
| 90 return m_pNode->GetEnum(XFA_ATTRIBUTE_Presence); | |
| 91 } | |
| 92 void CXFA_Fill::SetColor(FX_ARGB color) { | |
| 93 CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_ELEMENT_Color); | |
| 94 CFX_WideString wsColor; | |
| 95 int a, r, g, b; | |
| 96 ArgbDecode(color, a, r, g, b); | |
| 97 wsColor.Format(L"%d,%d,%d", r, g, b); | |
| 98 pNode->SetCData(XFA_ATTRIBUTE_Value, wsColor); | |
| 99 } | |
| 100 FX_ARGB CXFA_Fill::GetColor(FX_BOOL bText) { | |
| 101 if (CXFA_Node* pNode = m_pNode->GetChild(0, XFA_ELEMENT_Color)) { | |
| 102 CFX_WideStringC wsColor; | |
| 103 if (pNode->TryCData(XFA_ATTRIBUTE_Value, wsColor, FALSE)) { | |
| 104 return XFA_WStringToColor(wsColor); | |
| 105 } | |
| 106 } | |
| 107 if (bText) { | |
| 108 return 0xFF000000; | |
| 109 } | |
| 110 return 0xFFFFFFFF; | |
| 111 } | |
| 112 int32_t CXFA_Fill::GetFillType() { | |
| 113 CXFA_Node* pChild = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 114 while (pChild) { | |
| 115 int32_t eType = pChild->GetClassID(); | |
| 116 if (eType != XFA_ELEMENT_Color && eType != XFA_ELEMENT_Extras) { | |
| 117 return eType; | |
| 118 } | |
| 119 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); | |
| 120 } | |
| 121 return XFA_ELEMENT_Solid; | |
| 122 } | |
| 123 int32_t CXFA_Fill::GetPattern(FX_ARGB& foreColor) { | |
| 124 CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_ELEMENT_Pattern); | |
| 125 if (CXFA_Node* pColor = pNode->GetChild(0, XFA_ELEMENT_Color)) { | |
| 126 CFX_WideStringC wsColor; | |
| 127 pColor->TryCData(XFA_ATTRIBUTE_Value, wsColor, FALSE); | |
| 128 foreColor = XFA_WStringToColor(wsColor); | |
| 129 } else { | |
| 130 foreColor = 0xFF000000; | |
| 131 } | |
| 132 return pNode->GetEnum(XFA_ATTRIBUTE_Type); | |
| 133 } | |
| 134 int32_t CXFA_Fill::GetStipple(FX_ARGB& stippleColor) { | |
| 135 CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_ELEMENT_Stipple); | |
| 136 int32_t eAttr = 50; | |
| 137 pNode->TryInteger(XFA_ATTRIBUTE_Rate, eAttr); | |
| 138 if (CXFA_Node* pColor = pNode->GetChild(0, XFA_ELEMENT_Color)) { | |
| 139 CFX_WideStringC wsColor; | |
| 140 pColor->TryCData(XFA_ATTRIBUTE_Value, wsColor, FALSE); | |
| 141 stippleColor = XFA_WStringToColor(wsColor); | |
| 142 } else { | |
| 143 stippleColor = 0xFF000000; | |
| 144 } | |
| 145 return eAttr; | |
| 146 } | |
| 147 int32_t CXFA_Fill::GetLinear(FX_ARGB& endColor) { | |
| 148 CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_ELEMENT_Linear); | |
| 149 XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_ToRight; | |
| 150 pNode->TryEnum(XFA_ATTRIBUTE_Type, eAttr); | |
| 151 if (CXFA_Node* pColor = pNode->GetChild(0, XFA_ELEMENT_Color)) { | |
| 152 CFX_WideStringC wsColor; | |
| 153 pColor->TryCData(XFA_ATTRIBUTE_Value, wsColor, FALSE); | |
| 154 endColor = XFA_WStringToColor(wsColor); | |
| 155 } else { | |
| 156 endColor = 0xFF000000; | |
| 157 } | |
| 158 return eAttr; | |
| 159 } | |
| 160 int32_t CXFA_Fill::GetRadial(FX_ARGB& endColor) { | |
| 161 CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_ELEMENT_Radial); | |
| 162 XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_ToEdge; | |
| 163 pNode->TryEnum(XFA_ATTRIBUTE_Type, eAttr); | |
| 164 if (CXFA_Node* pColor = pNode->GetChild(0, XFA_ELEMENT_Color)) { | |
| 165 CFX_WideStringC wsColor; | |
| 166 pColor->TryCData(XFA_ATTRIBUTE_Value, wsColor, FALSE); | |
| 167 endColor = XFA_WStringToColor(wsColor); | |
| 168 } else { | |
| 169 endColor = 0xFF000000; | |
| 170 } | |
| 171 return eAttr; | |
| 172 } | |
| 173 CXFA_Margin::CXFA_Margin(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 174 FX_BOOL CXFA_Margin::GetLeftInset(FX_FLOAT& fInset, FX_FLOAT fDefInset) const { | |
| 175 fInset = fDefInset; | |
| 176 return TryMeasure(XFA_ATTRIBUTE_LeftInset, fInset); | |
| 177 } | |
| 178 FX_BOOL CXFA_Margin::GetTopInset(FX_FLOAT& fInset, FX_FLOAT fDefInset) const { | |
| 179 fInset = fDefInset; | |
| 180 return TryMeasure(XFA_ATTRIBUTE_TopInset, fInset); | |
| 181 } | |
| 182 FX_BOOL CXFA_Margin::GetRightInset(FX_FLOAT& fInset, FX_FLOAT fDefInset) const { | |
| 183 fInset = fDefInset; | |
| 184 return TryMeasure(XFA_ATTRIBUTE_RightInset, fInset); | |
| 185 } | |
| 186 FX_BOOL CXFA_Margin::GetBottomInset(FX_FLOAT& fInset, | |
| 187 FX_FLOAT fDefInset) const { | |
| 188 fInset = fDefInset; | |
| 189 return TryMeasure(XFA_ATTRIBUTE_BottomInset, fInset); | |
| 190 } | |
| 191 CXFA_Font::CXFA_Font(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 192 FX_FLOAT CXFA_Font::GetBaselineShift() { | |
| 193 return m_pNode->GetMeasure(XFA_ATTRIBUTE_BaselineShift).ToUnit(XFA_UNIT_Pt); | |
| 194 } | |
| 195 FX_FLOAT CXFA_Font::GetHorizontalScale() { | |
| 196 CFX_WideString wsValue; | |
| 197 m_pNode->TryCData(XFA_ATTRIBUTE_FontHorizontalScale, wsValue); | |
| 198 int32_t iScale = FXSYS_wtoi((const FX_WCHAR*)wsValue); | |
| 199 return iScale > 0 ? (FX_FLOAT)iScale : 100.0f; | |
| 200 } | |
| 201 FX_FLOAT CXFA_Font::GetVerticalScale() { | |
| 202 CFX_WideString wsValue; | |
| 203 m_pNode->TryCData(XFA_ATTRIBUTE_FontVerticalScale, wsValue); | |
| 204 int32_t iScale = FXSYS_wtoi((const FX_WCHAR*)wsValue); | |
| 205 return iScale > 0 ? (FX_FLOAT)iScale : 100.0f; | |
| 206 } | |
| 207 FX_FLOAT CXFA_Font::GetLetterSpacing() { | |
| 208 CFX_WideStringC wsValue; | |
| 209 if (!m_pNode->TryCData(XFA_ATTRIBUTE_LetterSpacing, wsValue)) { | |
| 210 return 0; | |
| 211 } | |
| 212 CXFA_Measurement ms(wsValue); | |
| 213 if (ms.GetUnit() == XFA_UNIT_Em) { | |
| 214 return ms.GetValue() * GetFontSize(); | |
| 215 } | |
| 216 return ms.ToUnit(XFA_UNIT_Pt); | |
| 217 } | |
| 218 int32_t CXFA_Font::GetLineThrough() { | |
| 219 int32_t iValue = 0; | |
| 220 m_pNode->TryInteger(XFA_ATTRIBUTE_LineThrough, iValue); | |
| 221 return iValue; | |
| 222 } | |
| 223 int32_t CXFA_Font::GetUnderline() { | |
| 224 int32_t iValue = 0; | |
| 225 m_pNode->TryInteger(XFA_ATTRIBUTE_Underline, iValue); | |
| 226 return iValue; | |
| 227 } | |
| 228 int32_t CXFA_Font::GetUnderlinePeriod() { | |
| 229 XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_All; | |
| 230 m_pNode->TryEnum(XFA_ATTRIBUTE_UnderlinePeriod, eAttr); | |
| 231 return eAttr; | |
| 232 } | |
| 233 FX_FLOAT CXFA_Font::GetFontSize() { | |
| 234 CXFA_Measurement ms; | |
| 235 m_pNode->TryMeasure(XFA_ATTRIBUTE_Size, ms); | |
| 236 return ms.ToUnit(XFA_UNIT_Pt); | |
| 237 } | |
| 238 void CXFA_Font::GetTypeface(CFX_WideStringC& wsTypeFace) { | |
| 239 m_pNode->TryCData(XFA_ATTRIBUTE_Typeface, wsTypeFace); | |
| 240 } | |
| 241 FX_BOOL CXFA_Font::IsBold() { | |
| 242 XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_Normal; | |
| 243 m_pNode->TryEnum(XFA_ATTRIBUTE_Weight, eAttr); | |
| 244 return eAttr == XFA_ATTRIBUTEENUM_Bold; | |
| 245 } | |
| 246 FX_BOOL CXFA_Font::IsItalic() { | |
| 247 XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_Normal; | |
| 248 m_pNode->TryEnum(XFA_ATTRIBUTE_Posture, eAttr); | |
| 249 return eAttr == XFA_ATTRIBUTEENUM_Italic; | |
| 250 } | |
| 251 void CXFA_Font::SetColor(FX_ARGB color) { | |
| 252 CXFA_Fill fill(m_pNode->GetProperty(0, XFA_ELEMENT_Fill)); | |
| 253 fill.SetColor(color); | |
| 254 } | |
| 255 FX_ARGB CXFA_Font::GetColor() { | |
| 256 CXFA_Fill fill(m_pNode->GetChild(0, XFA_ELEMENT_Fill)); | |
| 257 return fill ? fill.GetColor(TRUE) : 0xFF000000; | |
| 258 } | |
| 259 CXFA_Caption::CXFA_Caption(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 260 int32_t CXFA_Caption::GetPresence() { | |
| 261 XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_Visible; | |
| 262 m_pNode->TryEnum(XFA_ATTRIBUTE_Presence, eAttr); | |
| 263 return eAttr; | |
| 264 } | |
| 265 int32_t CXFA_Caption::GetPlacementType() { | |
| 266 XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_Left; | |
| 267 m_pNode->TryEnum(XFA_ATTRIBUTE_Placement, eAttr); | |
| 268 return eAttr; | |
| 269 } | |
| 270 FX_FLOAT CXFA_Caption::GetReserve() { | |
| 271 CXFA_Measurement ms; | |
| 272 m_pNode->TryMeasure(XFA_ATTRIBUTE_Reserve, ms); | |
| 273 return ms.ToUnit(XFA_UNIT_Pt); | |
| 274 } | |
| 275 CXFA_Margin CXFA_Caption::GetMargin() { | |
| 276 return CXFA_Margin(m_pNode ? m_pNode->GetChild(0, XFA_ELEMENT_Margin) : NULL); | |
| 277 } | |
| 278 CXFA_Font CXFA_Caption::GetFont() { | |
| 279 return CXFA_Font(m_pNode ? m_pNode->GetChild(0, XFA_ELEMENT_Font) : NULL); | |
| 280 } | |
| 281 CXFA_Value CXFA_Caption::GetValue() { | |
| 282 return CXFA_Value(m_pNode ? m_pNode->GetChild(0, XFA_ELEMENT_Value) : NULL); | |
| 283 } | |
| 284 CXFA_Para::CXFA_Para(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 285 int32_t CXFA_Para::GetHorizontalAlign() { | |
| 286 XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_Left; | |
| 287 m_pNode->TryEnum(XFA_ATTRIBUTE_HAlign, eAttr); | |
| 288 return eAttr; | |
| 289 } | |
| 290 int32_t CXFA_Para::GetVerticalAlign() { | |
| 291 XFA_ATTRIBUTEENUM eAttr = XFA_ATTRIBUTEENUM_Top; | |
| 292 m_pNode->TryEnum(XFA_ATTRIBUTE_VAlign, eAttr); | |
| 293 return eAttr; | |
| 294 } | |
| 295 FX_FLOAT CXFA_Para::GetLineHeight() { | |
| 296 CXFA_Measurement ms; | |
| 297 m_pNode->TryMeasure(XFA_ATTRIBUTE_LineHeight, ms); | |
| 298 return ms.ToUnit(XFA_UNIT_Pt); | |
| 299 } | |
| 300 FX_FLOAT CXFA_Para::GetMarginLeft() { | |
| 301 CXFA_Measurement ms; | |
| 302 m_pNode->TryMeasure(XFA_ATTRIBUTE_MarginLeft, ms); | |
| 303 return ms.ToUnit(XFA_UNIT_Pt); | |
| 304 } | |
| 305 FX_FLOAT CXFA_Para::GetMarginRight() { | |
| 306 CXFA_Measurement ms; | |
| 307 m_pNode->TryMeasure(XFA_ATTRIBUTE_MarginRight, ms); | |
| 308 return ms.ToUnit(XFA_UNIT_Pt); | |
| 309 } | |
| 310 FX_FLOAT CXFA_Para::GetSpaceAbove() { | |
| 311 CXFA_Measurement ms; | |
| 312 m_pNode->TryMeasure(XFA_ATTRIBUTE_SpaceAbove, ms); | |
| 313 return ms.ToUnit(XFA_UNIT_Pt); | |
| 314 } | |
| 315 FX_FLOAT CXFA_Para::GetSpaceBelow() { | |
| 316 CXFA_Measurement ms; | |
| 317 m_pNode->TryMeasure(XFA_ATTRIBUTE_SpaceBelow, ms); | |
| 318 return ms.ToUnit(XFA_UNIT_Pt); | |
| 319 } | |
| 320 FX_FLOAT CXFA_Para::GetTextIndent() { | |
| 321 CXFA_Measurement ms; | |
| 322 m_pNode->TryMeasure(XFA_ATTRIBUTE_TextIndent, ms); | |
| 323 return ms.ToUnit(XFA_UNIT_Pt); | |
| 324 } | |
| 325 CXFA_Event::CXFA_Event(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 326 int32_t CXFA_Event::GetActivity() { | |
| 327 return m_pNode->GetEnum(XFA_ATTRIBUTE_Activity); | |
| 328 } | |
| 329 int32_t CXFA_Event::GetEventType() { | |
| 330 CXFA_Node* pChild = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 331 while (pChild) { | |
| 332 int32_t eType = pChild->GetClassID(); | |
| 333 if (eType != XFA_ELEMENT_Extras) { | |
| 334 return eType; | |
| 335 } | |
| 336 pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); | |
| 337 } | |
| 338 return XFA_ELEMENT_UNKNOWN; | |
| 339 } | |
| 340 void CXFA_Event::GetRef(CFX_WideStringC& wsRef) { | |
| 341 m_pNode->TryCData(XFA_ATTRIBUTE_Ref, wsRef); | |
| 342 } | |
| 343 CXFA_Script CXFA_Event::GetScript() { | |
| 344 return CXFA_Script(m_pNode->GetChild(0, XFA_ELEMENT_Script)); | |
| 345 } | |
| 346 CXFA_Submit CXFA_Event::GetSubmit() { | |
| 347 return CXFA_Submit(m_pNode->GetChild(0, XFA_ELEMENT_Submit)); | |
| 348 } | |
| 349 void CXFA_Event::GetSignDataTarget(CFX_WideString& wsTarget) { | |
| 350 if (CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_ELEMENT_SignData)) { | |
| 351 CFX_WideStringC wsCData; | |
| 352 pNode->TryCData(XFA_ATTRIBUTE_Target, wsCData); | |
| 353 wsTarget = wsCData; | |
| 354 } | |
| 355 } | |
| 356 CXFA_Script::CXFA_Script(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 357 XFA_SCRIPTTYPE CXFA_Script::GetContentType() { | |
| 358 CFX_WideStringC cData; | |
| 359 if (m_pNode->TryCData(XFA_ATTRIBUTE_ContentType, cData, FALSE)) { | |
| 360 if (cData == FX_WSTRC(L"application/x-javascript")) { | |
| 361 return XFA_SCRIPTTYPE_Javascript; | |
| 362 } else if (cData == FX_WSTRC(L"application/x-formcalc")) { | |
| 363 return XFA_SCRIPTTYPE_Formcalc; | |
| 364 } else { | |
| 365 return XFA_SCRIPTTYPE_Unkown; | |
| 366 } | |
| 367 } | |
| 368 return XFA_SCRIPTTYPE_Formcalc; | |
| 369 } | |
| 370 int32_t CXFA_Script::GetRunAt() { | |
| 371 return m_pNode->GetEnum(XFA_ATTRIBUTE_RunAt); | |
| 372 } | |
| 373 void CXFA_Script::GetExpression(CFX_WideString& wsExpression) { | |
| 374 m_pNode->TryContent(wsExpression); | |
| 375 } | |
| 376 CXFA_Submit::CXFA_Submit(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 377 FX_BOOL CXFA_Submit::IsSubmitEmbedPDF() { | |
| 378 return m_pNode->GetBoolean(XFA_ATTRIBUTE_EmbedPDF); | |
| 379 } | |
| 380 int32_t CXFA_Submit::GetSubmitFormat() { | |
| 381 return m_pNode->GetEnum(XFA_ATTRIBUTE_Format); | |
| 382 } | |
| 383 void CXFA_Submit::GetSubmitTarget(CFX_WideStringC& wsTarget) { | |
| 384 m_pNode->TryCData(XFA_ATTRIBUTE_Target, wsTarget); | |
| 385 } | |
| 386 void CXFA_Submit::GetSubmitXDPContent(CFX_WideStringC& wsContent) { | |
| 387 m_pNode->TryCData(XFA_ATTRIBUTE_XdpContent, wsContent); | |
| 388 } | |
| 389 XFA_ELEMENT CXFA_Value::GetChildValueClassID() { | |
| 390 if (!m_pNode) { | |
| 391 return XFA_ELEMENT_UNKNOWN; | |
| 392 } | |
| 393 if (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild)) { | |
| 394 return pNode->GetClassID(); | |
| 395 } | |
| 396 return XFA_ELEMENT_UNKNOWN; | |
| 397 } | |
| 398 FX_BOOL CXFA_Value::GetChildValueContent(CFX_WideString& wsContent) { | |
| 399 if (!m_pNode) { | |
| 400 return FALSE; | |
| 401 } | |
| 402 if (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild)) { | |
| 403 return pNode->TryContent(wsContent); | |
| 404 } | |
| 405 return FALSE; | |
| 406 } | |
| 407 CXFA_Arc CXFA_Value::GetArc() { | |
| 408 return CXFA_Arc(m_pNode ? m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild) | |
| 409 : nullptr); | |
| 410 } | |
| 411 CXFA_Line CXFA_Value::GetLine() { | |
| 412 return CXFA_Line(m_pNode ? m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild) | |
| 413 : nullptr); | |
| 414 } | |
| 415 CXFA_Rectangle CXFA_Value::GetRectangle() { | |
| 416 return CXFA_Rectangle(m_pNode ? m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild) | |
| 417 : nullptr); | |
| 418 } | |
| 419 CXFA_Text CXFA_Value::GetText() { | |
| 420 return CXFA_Text(m_pNode ? m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild) | |
| 421 : nullptr); | |
| 422 } | |
| 423 CXFA_ExData CXFA_Value::GetExData() { | |
| 424 return CXFA_ExData(m_pNode ? m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild) | |
| 425 : nullptr); | |
| 426 } | |
| 427 CXFA_Image CXFA_Value::GetImage() { | |
| 428 return CXFA_Image( | |
| 429 m_pNode ? (m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild)) : nullptr, | |
| 430 TRUE); | |
| 431 } | |
| 432 int32_t CXFA_Line::GetHand() { | |
| 433 return m_pNode->GetEnum(XFA_ATTRIBUTE_Hand); | |
| 434 } | |
| 435 FX_BOOL CXFA_Line::GetSlop() { | |
| 436 XFA_ATTRIBUTEENUM eSlop = m_pNode->GetEnum(XFA_ATTRIBUTE_Slope); | |
| 437 return eSlop == XFA_ATTRIBUTEENUM_Slash; | |
| 438 } | |
| 439 CXFA_Edge CXFA_Line::GetEdge() { | |
| 440 return CXFA_Edge(m_pNode->GetChild(0, XFA_ELEMENT_Edge)); | |
| 441 } | |
| 442 CXFA_Text::CXFA_Text(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 443 void CXFA_Text::GetContent(CFX_WideString& wsText) { | |
| 444 m_pNode->TryContent(wsText); | |
| 445 } | |
| 446 CXFA_ExData::CXFA_ExData(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 447 FX_BOOL CXFA_ExData::SetContentType(const CFX_WideString& wsContentType) { | |
| 448 return m_pNode->SetCData(XFA_ATTRIBUTE_ContentType, wsContentType); | |
| 449 } | |
| 450 CXFA_Image::CXFA_Image(CXFA_Node* pNode, FX_BOOL bDefValue) | |
| 451 : CXFA_Data(pNode), m_bDefValue(bDefValue) {} | |
| 452 int32_t CXFA_Image::GetAspect() { | |
| 453 return m_pNode->GetEnum(XFA_ATTRIBUTE_Aspect); | |
| 454 } | |
| 455 FX_BOOL CXFA_Image::GetContentType(CFX_WideString& wsContentType) { | |
| 456 return m_pNode->TryCData(XFA_ATTRIBUTE_ContentType, wsContentType); | |
| 457 } | |
| 458 FX_BOOL CXFA_Image::GetHref(CFX_WideString& wsHref) { | |
| 459 if (m_bDefValue) { | |
| 460 return m_pNode->TryCData(XFA_ATTRIBUTE_Href, wsHref); | |
| 461 } | |
| 462 return m_pNode->GetAttribute(FX_WSTRC(L"href"), wsHref); | |
| 463 } | |
| 464 int32_t CXFA_Image::GetTransferEncoding() { | |
| 465 if (m_bDefValue) { | |
| 466 return m_pNode->GetEnum(XFA_ATTRIBUTE_TransferEncoding); | |
| 467 } | |
| 468 return XFA_ATTRIBUTEENUM_Base64; | |
| 469 } | |
| 470 FX_BOOL CXFA_Image::GetContent(CFX_WideString& wsText) { | |
| 471 return m_pNode->TryContent(wsText); | |
| 472 } | |
| 473 FX_BOOL CXFA_Image::SetContentType(const CFX_WideString& wsContentType) { | |
| 474 return m_pNode->SetCData(XFA_ATTRIBUTE_ContentType, wsContentType); | |
| 475 } | |
| 476 FX_BOOL CXFA_Image::SetHref(const CFX_WideString& wsHref) { | |
| 477 if (m_bDefValue) { | |
| 478 return m_pNode->SetCData(XFA_ATTRIBUTE_Href, wsHref); | |
| 479 } | |
| 480 return m_pNode->SetAttribute(XFA_ATTRIBUTE_Href, wsHref.AsWideStringC()); | |
| 481 } | |
| 482 FX_BOOL CXFA_Image::SetTransferEncoding(int32_t iTransferEncoding) { | |
| 483 if (m_bDefValue) { | |
| 484 return m_pNode->SetEnum(XFA_ATTRIBUTE_TransferEncoding, | |
| 485 (XFA_ATTRIBUTEENUM)iTransferEncoding); | |
| 486 } | |
| 487 return TRUE; | |
| 488 } | |
| 489 CXFA_Calculate::CXFA_Calculate(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 490 int32_t CXFA_Calculate::GetOverride() { | |
| 491 XFA_ATTRIBUTEENUM eAtt = XFA_ATTRIBUTEENUM_Error; | |
| 492 m_pNode->TryEnum(XFA_ATTRIBUTE_Override, eAtt, FALSE); | |
| 493 return eAtt; | |
| 494 } | |
| 495 CXFA_Script CXFA_Calculate::GetScript() { | |
| 496 return CXFA_Script(m_pNode->GetChild(0, XFA_ELEMENT_Script)); | |
| 497 } | |
| 498 void CXFA_Calculate::GetMessageText(CFX_WideString& wsMessage) { | |
| 499 if (CXFA_Node* pNode = m_pNode->GetChild(0, XFA_ELEMENT_Message)) { | |
| 500 CXFA_Text text(pNode->GetChild(0, XFA_ELEMENT_Text)); | |
| 501 if (text) { | |
| 502 text.GetContent(wsMessage); | |
| 503 } | |
| 504 } | |
| 505 } | |
| 506 CXFA_Validate::CXFA_Validate(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 507 int32_t CXFA_Validate::GetFormatTest() { | |
| 508 return m_pNode->GetEnum(XFA_ATTRIBUTE_FormatTest); | |
| 509 } | |
| 510 FX_BOOL CXFA_Validate::SetTestValue(int32_t iType, | |
| 511 CFX_WideString& wsValue, | |
| 512 XFA_ATTRIBUTEENUM eName) { | |
| 513 const XFA_ATTRIBUTEENUMINFO* pInfo = | |
| 514 XFA_GetAttributeEnumByName(wsValue.AsWideStringC()); | |
| 515 if (pInfo) { | |
| 516 eName = pInfo->eName; | |
| 517 } | |
| 518 m_pNode->SetEnum((XFA_ATTRIBUTE)iType, eName, FALSE); | |
| 519 return TRUE; | |
| 520 } | |
| 521 FX_BOOL CXFA_Validate::SetNullTest(CFX_WideString wsValue) { | |
| 522 return SetTestValue(XFA_ATTRIBUTE_NullTest, wsValue, | |
| 523 XFA_ATTRIBUTEENUM_Disabled); | |
| 524 } | |
| 525 int32_t CXFA_Validate::GetNullTest() { | |
| 526 return m_pNode->GetEnum(XFA_ATTRIBUTE_NullTest); | |
| 527 } | |
| 528 int32_t CXFA_Validate::GetScriptTest() { | |
| 529 return m_pNode->GetEnum(XFA_ATTRIBUTE_ScriptTest); | |
| 530 } | |
| 531 void CXFA_Validate::GetMessageText(CFX_WideString& wsMessage, | |
| 532 const CFX_WideStringC& wsMessageType) { | |
| 533 if (CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_ELEMENT_Message, FALSE)) { | |
| 534 CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 535 for (; pItemNode; | |
| 536 pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 537 if (pItemNode->GetClassID() != XFA_ELEMENT_Text) { | |
| 538 continue; | |
| 539 } | |
| 540 CFX_WideStringC wsName; | |
| 541 pItemNode->TryCData(XFA_ATTRIBUTE_Name, wsName); | |
| 542 if (wsName.IsEmpty() || wsName == wsMessageType) { | |
| 543 pItemNode->TryContent(wsMessage); | |
| 544 return; | |
| 545 } | |
| 546 } | |
| 547 } | |
| 548 } | |
| 549 void CXFA_Validate::SetFormatMessageText(CFX_WideString wsMessage) { | |
| 550 SetMessageText(wsMessage, FX_WSTRC(L"formatTest")); | |
| 551 } | |
| 552 void CXFA_Validate::GetFormatMessageText(CFX_WideString& wsMessage) { | |
| 553 GetMessageText(wsMessage, FX_WSTRC(L"formatTest")); | |
| 554 } | |
| 555 void CXFA_Validate::SetNullMessageText(CFX_WideString wsMessage) { | |
| 556 SetMessageText(wsMessage, FX_WSTRC(L"nullTest")); | |
| 557 } | |
| 558 void CXFA_Validate::GetNullMessageText(CFX_WideString& wsMessage) { | |
| 559 GetMessageText(wsMessage, FX_WSTRC(L"nullTest")); | |
| 560 } | |
| 561 void CXFA_Validate::SetMessageText(CFX_WideString& wsMessage, | |
| 562 const CFX_WideStringC& wsMessageType) { | |
| 563 if (CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_ELEMENT_Message, TRUE)) { | |
| 564 CXFA_Node* pItemNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 565 for (; pItemNode; | |
| 566 pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 567 if (pItemNode->GetClassID() != XFA_ELEMENT_Text) { | |
| 568 continue; | |
| 569 } | |
| 570 CFX_WideStringC wsName; | |
| 571 pItemNode->TryCData(XFA_ATTRIBUTE_Name, wsName); | |
| 572 if (wsName.IsEmpty() || wsName == wsMessageType) { | |
| 573 pItemNode->SetContent(wsMessage, wsMessage, FALSE); | |
| 574 return; | |
| 575 } | |
| 576 } | |
| 577 CXFA_Node* pTextNode = pNode->CreateSamePacketNode(XFA_ELEMENT_Text); | |
| 578 pNode->InsertChild(pTextNode); | |
| 579 pTextNode->SetCData(XFA_ATTRIBUTE_Name, wsMessageType, FALSE); | |
| 580 pTextNode->SetContent(wsMessage, wsMessage, FALSE); | |
| 581 } | |
| 582 } | |
| 583 void CXFA_Validate::GetScriptMessageText(CFX_WideString& wsMessage) { | |
| 584 GetMessageText(wsMessage, FX_WSTRC(L"scriptTest")); | |
| 585 } | |
| 586 void CXFA_Validate::SetScriptMessageText(CFX_WideString wsMessage) { | |
| 587 SetMessageText(wsMessage, FX_WSTRC(L"scriptTest")); | |
| 588 } | |
| 589 void CXFA_Validate::GetPicture(CFX_WideString& wsPicture) { | |
| 590 if (CXFA_Node* pNode = m_pNode->GetChild(0, XFA_ELEMENT_Picture)) { | |
| 591 pNode->TryContent(wsPicture); | |
| 592 } | |
| 593 } | |
| 594 CXFA_Script CXFA_Validate::GetScript() { | |
| 595 return CXFA_Script(m_pNode->GetChild(0, XFA_ELEMENT_Script)); | |
| 596 } | |
| 597 CXFA_Bind::CXFA_Bind(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 598 void CXFA_Bind::GetPicture(CFX_WideString& wsPicture) { | |
| 599 if (CXFA_Node* pPicture = m_pNode->GetChild(0, XFA_ELEMENT_Picture)) { | |
| 600 pPicture->TryContent(wsPicture); | |
| 601 } | |
| 602 } | |
| 603 CXFA_Assist::CXFA_Assist(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 604 CXFA_ToolTip CXFA_Assist::GetToolTip() { | |
| 605 return CXFA_ToolTip(m_pNode->GetChild(0, XFA_ELEMENT_ToolTip)); | |
| 606 } | |
| 607 CXFA_ToolTip::CXFA_ToolTip(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 608 FX_BOOL CXFA_ToolTip::GetTip(CFX_WideString& wsTip) { | |
| 609 return m_pNode->TryContent(wsTip); | |
| 610 } | |
| 611 CXFA_BindItems::CXFA_BindItems(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 612 void CXFA_BindItems::GetLabelRef(CFX_WideStringC& wsLabelRef) { | |
| 613 m_pNode->TryCData(XFA_ATTRIBUTE_LabelRef, wsLabelRef); | |
| 614 } | |
| 615 void CXFA_BindItems::GetValueRef(CFX_WideStringC& wsValueRef) { | |
| 616 m_pNode->TryCData(XFA_ATTRIBUTE_ValueRef, wsValueRef); | |
| 617 } | |
| 618 void CXFA_BindItems::GetRef(CFX_WideStringC& wsRef) { | |
| 619 m_pNode->TryCData(XFA_ATTRIBUTE_Ref, wsRef); | |
| 620 } | |
| 621 FX_BOOL CXFA_BindItems::SetConnection(const CFX_WideString& wsConnection) { | |
| 622 return m_pNode->SetCData(XFA_ATTRIBUTE_Connection, wsConnection); | |
| 623 } | |
| 624 int32_t CXFA_Box::GetHand() const { | |
| 625 if (!m_pNode) { | |
| 626 return XFA_ATTRIBUTEENUM_Even; | |
| 627 } | |
| 628 return m_pNode->GetEnum(XFA_ATTRIBUTE_Hand); | |
| 629 } | |
| 630 int32_t CXFA_Box::GetPresence() const { | |
| 631 if (!m_pNode) { | |
| 632 return XFA_ATTRIBUTEENUM_Hidden; | |
| 633 } | |
| 634 return m_pNode->GetEnum(XFA_ATTRIBUTE_Presence); | |
| 635 } | |
| 636 int32_t CXFA_Box::CountEdges() const { | |
| 637 if (!m_pNode) { | |
| 638 return 0; | |
| 639 } | |
| 640 return m_pNode->CountChildren(XFA_ELEMENT_Edge); | |
| 641 } | |
| 642 CXFA_Edge CXFA_Box::GetEdge(int32_t nIndex) const { | |
| 643 return CXFA_Edge( | |
| 644 m_pNode ? m_pNode->GetProperty(nIndex, XFA_ELEMENT_Edge, nIndex == 0) | |
| 645 : nullptr); | |
| 646 } | |
| 647 static void XFA_BOX_GetStrokes(CXFA_Node* pNode, | |
| 648 CXFA_StrokeArray& strokes, | |
| 649 FX_BOOL bNULL) { | |
| 650 strokes.RemoveAll(); | |
| 651 if (!pNode) { | |
| 652 return; | |
| 653 } | |
| 654 strokes.SetSize(8); | |
| 655 int32_t i, j; | |
| 656 for (i = 0, j = 0; i < 4; i++) { | |
| 657 CXFA_Corner corner = | |
| 658 CXFA_Corner(pNode->GetProperty(i, XFA_ELEMENT_Corner, i == 0)); | |
| 659 if (corner || i == 0) { | |
| 660 strokes.SetAt(j, corner); | |
| 661 } else if (bNULL) { | |
| 662 strokes.SetAt(j, CXFA_Stroke(nullptr)); | |
| 663 } else if (i == 1) { | |
| 664 strokes.SetAt(j, strokes[0]); | |
| 665 } else if (i == 2) { | |
| 666 strokes.SetAt(j, strokes[0]); | |
| 667 } else { | |
| 668 strokes.SetAt(j, strokes[2]); | |
| 669 } | |
| 670 j++; | |
| 671 CXFA_Edge edge = CXFA_Edge(pNode->GetProperty(i, XFA_ELEMENT_Edge, i == 0)); | |
| 672 if (edge || i == 0) { | |
| 673 strokes.SetAt(j, edge); | |
| 674 } else if (bNULL) { | |
| 675 strokes.SetAt(j, CXFA_Stroke(nullptr)); | |
| 676 } else if (i == 1) { | |
| 677 strokes.SetAt(j, strokes[1]); | |
| 678 } else if (i == 2) { | |
| 679 strokes.SetAt(j, strokes[1]); | |
| 680 } else { | |
| 681 strokes.SetAt(j, strokes[3]); | |
| 682 } | |
| 683 j++; | |
| 684 } | |
| 685 } | |
| 686 void CXFA_Box::GetStrokes(CXFA_StrokeArray& strokes) const { | |
| 687 XFA_BOX_GetStrokes(m_pNode, strokes, FALSE); | |
| 688 } | |
| 689 FX_BOOL CXFA_Box::IsCircular() const { | |
| 690 if (!m_pNode) { | |
| 691 return FALSE; | |
| 692 } | |
| 693 return m_pNode->GetBoolean(XFA_ATTRIBUTE_Circular); | |
| 694 } | |
| 695 FX_BOOL CXFA_Box::GetStartAngle(FX_FLOAT& fStartAngle) const { | |
| 696 fStartAngle = 0; | |
| 697 if (!m_pNode) { | |
| 698 return FALSE; | |
| 699 } | |
| 700 CXFA_Measurement ms; | |
| 701 FX_BOOL bRet = m_pNode->TryMeasure(XFA_ATTRIBUTE_StartAngle, ms, FALSE); | |
| 702 if (bRet) { | |
| 703 fStartAngle = ms.GetValue(); | |
| 704 } | |
| 705 return bRet; | |
| 706 } | |
| 707 FX_BOOL CXFA_Box::GetSweepAngle(FX_FLOAT& fSweepAngle) const { | |
| 708 fSweepAngle = 360; | |
| 709 if (!m_pNode) { | |
| 710 return FALSE; | |
| 711 } | |
| 712 CXFA_Measurement ms; | |
| 713 FX_BOOL bRet = m_pNode->TryMeasure(XFA_ATTRIBUTE_SweepAngle, ms, FALSE); | |
| 714 if (bRet) { | |
| 715 fSweepAngle = ms.GetValue(); | |
| 716 } | |
| 717 return bRet; | |
| 718 } | |
| 719 CXFA_Fill CXFA_Box::GetFill(FX_BOOL bModified) const { | |
| 720 if (!m_pNode) { | |
| 721 return CXFA_Fill(nullptr); | |
| 722 } | |
| 723 CXFA_Node* pFillNode = m_pNode->GetProperty(0, XFA_ELEMENT_Fill, bModified); | |
| 724 return CXFA_Fill(pFillNode); | |
| 725 } | |
| 726 CXFA_Margin CXFA_Box::GetMargin() const { | |
| 727 return CXFA_Margin(m_pNode ? m_pNode->GetChild(0, XFA_ELEMENT_Margin) | |
| 728 : nullptr); | |
| 729 } | |
| 730 static int32_t XFA_BOX_3DStyle(const CXFA_StrokeArray& strokes, | |
| 731 CXFA_Stroke& stroke) { | |
| 732 int32_t iCount = strokes.GetSize(); | |
| 733 if (iCount < 1) { | |
| 734 return 0; | |
| 735 } | |
| 736 stroke = strokes[0]; | |
| 737 for (int32_t i = 1; i < iCount; i++) { | |
| 738 CXFA_Stroke find = strokes[i]; | |
| 739 if (!find) { | |
| 740 continue; | |
| 741 } | |
| 742 if (!stroke) { | |
| 743 stroke = find; | |
| 744 } else if (stroke.GetStrokeType() != find.GetStrokeType()) { | |
| 745 stroke = find; | |
| 746 break; | |
| 747 } | |
| 748 } | |
| 749 int32_t iType = stroke.GetStrokeType(); | |
| 750 if (iType == XFA_ATTRIBUTEENUM_Lowered || iType == XFA_ATTRIBUTEENUM_Raised || | |
| 751 iType == XFA_ATTRIBUTEENUM_Etched || | |
| 752 iType == XFA_ATTRIBUTEENUM_Embossed) { | |
| 753 return iType; | |
| 754 } | |
| 755 return 0; | |
| 756 } | |
| 757 int32_t CXFA_Box::Get3DStyle(FX_BOOL& bVisible, FX_FLOAT& fThickness) const { | |
| 758 if (IsArc()) { | |
| 759 return 0; | |
| 760 } | |
| 761 CXFA_StrokeArray strokes; | |
| 762 XFA_BOX_GetStrokes(m_pNode, strokes, TRUE); | |
| 763 CXFA_Stroke stroke(NULL); | |
| 764 int32_t iType = XFA_BOX_3DStyle(strokes, stroke); | |
| 765 if (iType) { | |
| 766 bVisible = stroke.IsVisible(); | |
| 767 fThickness = stroke.GetThickness(); | |
| 768 } | |
| 769 return iType; | |
| 770 } | |
| 771 int32_t CXFA_Stroke::GetPresence() const { | |
| 772 return m_pNode ? m_pNode->GetEnum(XFA_ATTRIBUTE_Presence) | |
| 773 : XFA_ATTRIBUTEENUM_Invisible; | |
| 774 } | |
| 775 int32_t CXFA_Stroke::GetCapType() const { | |
| 776 if (!m_pNode) { | |
| 777 return XFA_ATTRIBUTEENUM_Square; | |
| 778 } | |
| 779 return m_pNode->GetEnum(XFA_ATTRIBUTE_Cap); | |
| 780 } | |
| 781 int32_t CXFA_Stroke::GetStrokeType() const { | |
| 782 return m_pNode ? m_pNode->GetEnum(XFA_ATTRIBUTE_Stroke) | |
| 783 : XFA_ATTRIBUTEENUM_Solid; | |
| 784 } | |
| 785 FX_FLOAT CXFA_Stroke::GetThickness() const { | |
| 786 return GetMSThickness().ToUnit(XFA_UNIT_Pt); | |
| 787 } | |
| 788 CXFA_Measurement CXFA_Stroke::GetMSThickness() const { | |
| 789 return m_pNode ? m_pNode->GetMeasure(XFA_ATTRIBUTE_Thickness) | |
| 790 : XFA_GetAttributeDefaultValue_Measure(XFA_ELEMENT_Edge, | |
| 791 XFA_ATTRIBUTE_Thickness, | |
| 792 XFA_XDPPACKET_Form); | |
| 793 } | |
| 794 void CXFA_Stroke::SetMSThickness(CXFA_Measurement msThinkness) { | |
| 795 if (!m_pNode) { | |
| 796 return; | |
| 797 } | |
| 798 m_pNode->SetMeasure(XFA_ATTRIBUTE_Thickness, msThinkness); | |
| 799 } | |
| 800 FX_ARGB CXFA_Stroke::GetColor() const { | |
| 801 if (!m_pNode) { | |
| 802 return 0xFF000000; | |
| 803 } | |
| 804 CXFA_Node* pNode = m_pNode->GetChild(0, XFA_ELEMENT_Color); | |
| 805 if (!pNode) { | |
| 806 return 0xFF000000; | |
| 807 } | |
| 808 CFX_WideStringC wsColor; | |
| 809 pNode->TryCData(XFA_ATTRIBUTE_Value, wsColor); | |
| 810 return XFA_WStringToColor(wsColor); | |
| 811 } | |
| 812 void CXFA_Stroke::SetColor(FX_ARGB argb) { | |
| 813 if (!m_pNode) { | |
| 814 return; | |
| 815 } | |
| 816 CXFA_Node* pNode = m_pNode->GetProperty(0, XFA_ELEMENT_Color); | |
| 817 CFX_WideString wsColor; | |
| 818 int a, r, g, b; | |
| 819 ArgbDecode(argb, a, r, g, b); | |
| 820 wsColor.Format(L"%d,%d,%d", r, g, b); | |
| 821 pNode->SetCData(XFA_ATTRIBUTE_Value, wsColor); | |
| 822 } | |
| 823 int32_t CXFA_Stroke::GetJoinType() const { | |
| 824 return m_pNode ? m_pNode->GetEnum(XFA_ATTRIBUTE_Join) | |
| 825 : XFA_ATTRIBUTEENUM_Square; | |
| 826 } | |
| 827 FX_BOOL CXFA_Stroke::IsInverted() const { | |
| 828 return m_pNode ? m_pNode->GetBoolean(XFA_ATTRIBUTE_Inverted) : FALSE; | |
| 829 } | |
| 830 FX_FLOAT CXFA_Stroke::GetRadius() const { | |
| 831 return m_pNode ? m_pNode->GetMeasure(XFA_ATTRIBUTE_Radius).ToUnit(XFA_UNIT_Pt) | |
| 832 : 0; | |
| 833 } | |
| 834 FX_BOOL CXFA_Stroke::SameStyles(CXFA_Stroke stroke, uint32_t dwFlags) const { | |
| 835 if (m_pNode == stroke.GetNode()) { | |
| 836 return TRUE; | |
| 837 } | |
| 838 if (FXSYS_fabs(GetThickness() - stroke.GetThickness()) >= 0.01f) { | |
| 839 return FALSE; | |
| 840 } | |
| 841 if ((dwFlags & XFA_STROKE_SAMESTYLE_NoPresence) == 0 && | |
| 842 IsVisible() != stroke.IsVisible()) { | |
| 843 return FALSE; | |
| 844 } | |
| 845 if (GetStrokeType() != stroke.GetStrokeType()) { | |
| 846 return FALSE; | |
| 847 } | |
| 848 if (GetColor() != stroke.GetColor()) { | |
| 849 return FALSE; | |
| 850 } | |
| 851 if ((dwFlags & XFA_STROKE_SAMESTYLE_Corner) != 0 && | |
| 852 FXSYS_fabs(GetRadius() - stroke.GetRadius()) >= 0.01f) { | |
| 853 return FALSE; | |
| 854 } | |
| 855 return TRUE; | |
| 856 } | |
| 857 FX_FLOAT XFA_GetEdgeThickness(const CXFA_StrokeArray& strokes, | |
| 858 FX_BOOL b3DStyle, | |
| 859 int32_t nIndex) { | |
| 860 FX_FLOAT fThickness = 0; | |
| 861 { | |
| 862 if (strokes[nIndex * 2 + 1].GetPresence() == XFA_ATTRIBUTEENUM_Visible) { | |
| 863 if (nIndex == 0) { | |
| 864 fThickness += 2.5f; | |
| 865 } | |
| 866 fThickness += strokes[nIndex * 2 + 1].GetThickness() * (b3DStyle ? 4 : 2); | |
| 867 } | |
| 868 } | |
| 869 return fThickness; | |
| 870 } | |
| 871 CXFA_WidgetData::CXFA_WidgetData(CXFA_Node* pNode) | |
| 872 : CXFA_Data(pNode), | |
| 873 m_bIsNull(TRUE), | |
| 874 m_bPreNull(TRUE), | |
| 875 m_pUiChildNode(NULL), | |
| 876 m_eUIType(XFA_ELEMENT_UNKNOWN) {} | |
| 877 CXFA_Node* CXFA_WidgetData::GetUIChild() { | |
| 878 if (m_eUIType == XFA_ELEMENT_UNKNOWN) { | |
| 879 m_pUiChildNode = XFA_CreateUIChild(m_pNode, m_eUIType); | |
| 880 } | |
| 881 return m_pUiChildNode; | |
| 882 } | |
| 883 XFA_ELEMENT CXFA_WidgetData::GetUIType() { | |
| 884 GetUIChild(); | |
| 885 return m_eUIType; | |
| 886 } | |
| 887 CFX_WideString CXFA_WidgetData::GetRawValue() { | |
| 888 return m_pNode->GetContent(); | |
| 889 } | |
| 890 int32_t CXFA_WidgetData::GetAccess(FX_BOOL bTemplate) { | |
| 891 if (bTemplate) { | |
| 892 CXFA_Node* pNode = m_pNode->GetTemplateNode(); | |
| 893 if (pNode) { | |
| 894 return pNode->GetEnum(XFA_ATTRIBUTE_Access); | |
| 895 } | |
| 896 return XFA_ATTRIBUTEENUM_Open; | |
| 897 } | |
| 898 CXFA_Node* pNode = m_pNode; | |
| 899 while (pNode) { | |
| 900 int32_t iAcc = pNode->GetEnum(XFA_ATTRIBUTE_Access); | |
| 901 if (iAcc != XFA_ATTRIBUTEENUM_Open) { | |
| 902 return iAcc; | |
| 903 } | |
| 904 pNode = | |
| 905 pNode->GetNodeItem(XFA_NODEITEM_Parent, XFA_OBJECTTYPE_ContainerNode); | |
| 906 } | |
| 907 return XFA_ATTRIBUTEENUM_Open; | |
| 908 } | |
| 909 int32_t CXFA_WidgetData::GetRotate() { | |
| 910 CXFA_Measurement ms; | |
| 911 if (!m_pNode->TryMeasure(XFA_ATTRIBUTE_Rotate, ms, FALSE)) { | |
| 912 return 0; | |
| 913 } | |
| 914 int32_t iRotate = FXSYS_round(ms.GetValue()); | |
| 915 iRotate = XFA_MapRotation(iRotate); | |
| 916 return iRotate / 90 * 90; | |
| 917 } | |
| 918 CXFA_Border CXFA_WidgetData::GetBorder(FX_BOOL bModified) { | |
| 919 return CXFA_Border(m_pNode->GetProperty(0, XFA_ELEMENT_Border, bModified)); | |
| 920 } | |
| 921 CXFA_Caption CXFA_WidgetData::GetCaption(FX_BOOL bModified) { | |
| 922 return CXFA_Caption(m_pNode->GetProperty(0, XFA_ELEMENT_Caption, bModified)); | |
| 923 } | |
| 924 CXFA_Font CXFA_WidgetData::GetFont(FX_BOOL bModified) { | |
| 925 return CXFA_Font(m_pNode->GetProperty(0, XFA_ELEMENT_Font, bModified)); | |
| 926 } | |
| 927 CXFA_Margin CXFA_WidgetData::GetMargin(FX_BOOL bModified) { | |
| 928 return CXFA_Margin(m_pNode->GetProperty(0, XFA_ELEMENT_Margin, bModified)); | |
| 929 } | |
| 930 CXFA_Para CXFA_WidgetData::GetPara(FX_BOOL bModified) { | |
| 931 return CXFA_Para(m_pNode->GetProperty(0, XFA_ELEMENT_Para, bModified)); | |
| 932 } | |
| 933 void CXFA_WidgetData::GetEventList(CXFA_NodeArray& events) { | |
| 934 m_pNode->GetNodeList(events, 0, XFA_ELEMENT_Event); | |
| 935 } | |
| 936 int32_t CXFA_WidgetData::GetEventByActivity(int32_t iActivity, | |
| 937 CXFA_NodeArray& events, | |
| 938 FX_BOOL bIsFormReady) { | |
| 939 CXFA_NodeArray allEvents; | |
| 940 GetEventList(allEvents); | |
| 941 int32_t iCount = allEvents.GetSize(); | |
| 942 for (int32_t i = 0; i < iCount; i++) { | |
| 943 CXFA_Event event(allEvents[i]); | |
| 944 if (event.GetActivity() == iActivity) { | |
| 945 if (iActivity == XFA_ATTRIBUTEENUM_Ready) { | |
| 946 CFX_WideStringC wsRef; | |
| 947 event.GetRef(wsRef); | |
| 948 if (bIsFormReady) { | |
| 949 if (wsRef == CFX_WideStringC(L"$form")) { | |
| 950 events.Add(allEvents[i]); | |
| 951 } | |
| 952 } else { | |
| 953 if (wsRef == CFX_WideStringC(L"$layout")) { | |
| 954 events.Add(allEvents[i]); | |
| 955 } | |
| 956 } | |
| 957 } else { | |
| 958 events.Add(allEvents[i]); | |
| 959 } | |
| 960 } | |
| 961 } | |
| 962 return events.GetSize(); | |
| 963 } | |
| 964 CXFA_Value CXFA_WidgetData::GetDefaultValue(FX_BOOL bModified) { | |
| 965 CXFA_Node* pTemNode = m_pNode->GetTemplateNode(); | |
| 966 return CXFA_Value(pTemNode | |
| 967 ? pTemNode->GetProperty(0, XFA_ELEMENT_Value, bModified) | |
| 968 : nullptr); | |
| 969 } | |
| 970 CXFA_Value CXFA_WidgetData::GetFormValue(FX_BOOL bModified) { | |
| 971 return CXFA_Value(m_pNode->GetProperty(0, XFA_ELEMENT_Value, bModified)); | |
| 972 } | |
| 973 CXFA_Calculate CXFA_WidgetData::GetCalculate(FX_BOOL bModified) { | |
| 974 return CXFA_Calculate( | |
| 975 m_pNode->GetProperty(0, XFA_ELEMENT_Calculate, bModified)); | |
| 976 } | |
| 977 CXFA_Validate CXFA_WidgetData::GetValidate(FX_BOOL bModified) { | |
| 978 return CXFA_Validate( | |
| 979 m_pNode->GetProperty(0, XFA_ELEMENT_Validate, bModified)); | |
| 980 } | |
| 981 CXFA_Bind CXFA_WidgetData::GetBind(FX_BOOL bModified) { | |
| 982 return CXFA_Bind(m_pNode->GetProperty(0, XFA_ELEMENT_Bind, bModified)); | |
| 983 } | |
| 984 CXFA_Assist CXFA_WidgetData::GetAssist(FX_BOOL bModified) { | |
| 985 return CXFA_Assist(m_pNode->GetProperty(0, XFA_ELEMENT_Assist, bModified)); | |
| 986 } | |
| 987 FX_BOOL CXFA_WidgetData::GetWidth(FX_FLOAT& fWidth) { | |
| 988 return TryMeasure(XFA_ATTRIBUTE_W, fWidth); | |
| 989 } | |
| 990 FX_BOOL CXFA_WidgetData::GetHeight(FX_FLOAT& fHeight) { | |
| 991 return TryMeasure(XFA_ATTRIBUTE_H, fHeight); | |
| 992 } | |
| 993 FX_BOOL CXFA_WidgetData::GetMinWidth(FX_FLOAT& fMinWidth) { | |
| 994 return TryMeasure(XFA_ATTRIBUTE_MinW, fMinWidth); | |
| 995 } | |
| 996 FX_BOOL CXFA_WidgetData::GetMinHeight(FX_FLOAT& fMinHeight) { | |
| 997 return TryMeasure(XFA_ATTRIBUTE_MinH, fMinHeight); | |
| 998 } | |
| 999 FX_BOOL CXFA_WidgetData::GetMaxWidth(FX_FLOAT& fMaxWidth) { | |
| 1000 return TryMeasure(XFA_ATTRIBUTE_MaxW, fMaxWidth); | |
| 1001 } | |
| 1002 FX_BOOL CXFA_WidgetData::GetMaxHeight(FX_FLOAT& fMaxHeight) { | |
| 1003 return TryMeasure(XFA_ATTRIBUTE_MaxH, fMaxHeight); | |
| 1004 } | |
| 1005 CXFA_Border CXFA_WidgetData::GetUIBorder(FX_BOOL bModified) { | |
| 1006 CXFA_Node* pUIChild = GetUIChild(); | |
| 1007 return CXFA_Border( | |
| 1008 pUIChild ? pUIChild->GetProperty(0, XFA_ELEMENT_Border, bModified) | |
| 1009 : nullptr); | |
| 1010 } | |
| 1011 CXFA_Margin CXFA_WidgetData::GetUIMargin(FX_BOOL bModified) { | |
| 1012 CXFA_Node* pUIChild = GetUIChild(); | |
| 1013 return CXFA_Margin( | |
| 1014 pUIChild ? pUIChild->GetProperty(0, XFA_ELEMENT_Margin, bModified) | |
| 1015 : nullptr); | |
| 1016 } | |
| 1017 void CXFA_WidgetData::GetUIMargin(CFX_RectF& rtUIMargin) { | |
| 1018 rtUIMargin.Reset(); | |
| 1019 CXFA_Margin mgUI = GetUIMargin(); | |
| 1020 if (!mgUI) { | |
| 1021 return; | |
| 1022 } | |
| 1023 CXFA_Border border = GetUIBorder(); | |
| 1024 if (border && border.GetPresence() != XFA_ATTRIBUTEENUM_Visible) { | |
| 1025 return; | |
| 1026 } | |
| 1027 FX_FLOAT fLeftInset, fTopInset, fRightInset, fBottomInset; | |
| 1028 FX_BOOL bLeft = mgUI.GetLeftInset(fLeftInset); | |
| 1029 FX_BOOL bTop = mgUI.GetTopInset(fTopInset); | |
| 1030 FX_BOOL bRight = mgUI.GetRightInset(fRightInset); | |
| 1031 FX_BOOL bBottom = mgUI.GetBottomInset(fBottomInset); | |
| 1032 if (border) { | |
| 1033 FX_BOOL bVisible = FALSE; | |
| 1034 FX_FLOAT fThickness = 0; | |
| 1035 border.Get3DStyle(bVisible, fThickness); | |
| 1036 if (!bLeft || !bTop || !bRight || !bBottom) { | |
| 1037 CXFA_StrokeArray strokes; | |
| 1038 border.GetStrokes(strokes); | |
| 1039 if (!bTop) { | |
| 1040 fTopInset = XFA_GetEdgeThickness(strokes, bVisible, 0); | |
| 1041 } | |
| 1042 if (!bRight) { | |
| 1043 fRightInset = XFA_GetEdgeThickness(strokes, bVisible, 1); | |
| 1044 } | |
| 1045 if (!bBottom) { | |
| 1046 fBottomInset = XFA_GetEdgeThickness(strokes, bVisible, 2); | |
| 1047 } | |
| 1048 if (!bLeft) { | |
| 1049 fLeftInset = XFA_GetEdgeThickness(strokes, bVisible, 3); | |
| 1050 } | |
| 1051 } | |
| 1052 } | |
| 1053 rtUIMargin.Set(fLeftInset, fTopInset, fRightInset, fBottomInset); | |
| 1054 } | |
| 1055 int32_t CXFA_WidgetData::GetButtonHighlight() { | |
| 1056 CXFA_Node* pUIChild = GetUIChild(); | |
| 1057 if (pUIChild) { | |
| 1058 return pUIChild->GetEnum(XFA_ATTRIBUTE_Highlight); | |
| 1059 } | |
| 1060 return XFA_GetAttributeDefaultValue_Enum( | |
| 1061 XFA_ELEMENT_Button, XFA_ATTRIBUTE_Highlight, XFA_XDPPACKET_Form); | |
| 1062 } | |
| 1063 FX_BOOL CXFA_WidgetData::GetButtonRollover(CFX_WideString& wsRollover, | |
| 1064 FX_BOOL& bRichText) { | |
| 1065 if (CXFA_Node* pItems = m_pNode->GetChild(0, XFA_ELEMENT_Items)) { | |
| 1066 CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1067 while (pText) { | |
| 1068 CFX_WideStringC wsName; | |
| 1069 pText->TryCData(XFA_ATTRIBUTE_Name, wsName); | |
| 1070 if (wsName == FX_WSTRC(L"rollover")) { | |
| 1071 pText->TryContent(wsRollover); | |
| 1072 bRichText = pText->GetClassID() == XFA_ELEMENT_ExData; | |
| 1073 return !wsRollover.IsEmpty(); | |
| 1074 } | |
| 1075 pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling); | |
| 1076 } | |
| 1077 } | |
| 1078 return FALSE; | |
| 1079 } | |
| 1080 FX_BOOL CXFA_WidgetData::GetButtonDown(CFX_WideString& wsDown, | |
| 1081 FX_BOOL& bRichText) { | |
| 1082 if (CXFA_Node* pItems = m_pNode->GetChild(0, XFA_ELEMENT_Items)) { | |
| 1083 CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1084 while (pText) { | |
| 1085 CFX_WideStringC wsName; | |
| 1086 pText->TryCData(XFA_ATTRIBUTE_Name, wsName); | |
| 1087 if (wsName == FX_WSTRC(L"down")) { | |
| 1088 pText->TryContent(wsDown); | |
| 1089 bRichText = pText->GetClassID() == XFA_ELEMENT_ExData; | |
| 1090 return !wsDown.IsEmpty(); | |
| 1091 } | |
| 1092 pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling); | |
| 1093 } | |
| 1094 } | |
| 1095 return FALSE; | |
| 1096 } | |
| 1097 int32_t CXFA_WidgetData::GetCheckButtonShape() { | |
| 1098 CXFA_Node* pUIChild = GetUIChild(); | |
| 1099 if (pUIChild) { | |
| 1100 return pUIChild->GetEnum(XFA_ATTRIBUTE_Shape); | |
| 1101 } | |
| 1102 return XFA_GetAttributeDefaultValue_Enum( | |
| 1103 XFA_ELEMENT_CheckButton, XFA_ATTRIBUTE_Shape, XFA_XDPPACKET_Form); | |
| 1104 } | |
| 1105 int32_t CXFA_WidgetData::GetCheckButtonMark() { | |
| 1106 CXFA_Node* pUIChild = GetUIChild(); | |
| 1107 if (pUIChild) { | |
| 1108 return pUIChild->GetEnum(XFA_ATTRIBUTE_Mark); | |
| 1109 } | |
| 1110 return XFA_GetAttributeDefaultValue_Enum( | |
| 1111 XFA_ELEMENT_CheckButton, XFA_ATTRIBUTE_Mark, XFA_XDPPACKET_Form); | |
| 1112 } | |
| 1113 FX_BOOL CXFA_WidgetData::IsRadioButton() { | |
| 1114 if (CXFA_Node* pParent = m_pNode->GetNodeItem(XFA_NODEITEM_Parent)) { | |
| 1115 return pParent->GetClassID() == XFA_ELEMENT_ExclGroup; | |
| 1116 } | |
| 1117 return FALSE; | |
| 1118 } | |
| 1119 FX_FLOAT CXFA_WidgetData::GetCheckButtonSize() { | |
| 1120 CXFA_Node* pUIChild = GetUIChild(); | |
| 1121 if (pUIChild) { | |
| 1122 return pUIChild->GetMeasure(XFA_ATTRIBUTE_Size).ToUnit(XFA_UNIT_Pt); | |
| 1123 } | |
| 1124 return XFA_GetAttributeDefaultValue_Measure( | |
| 1125 XFA_ELEMENT_CheckButton, XFA_ATTRIBUTE_Size, XFA_XDPPACKET_Form) | |
| 1126 .ToUnit(XFA_UNIT_Pt); | |
| 1127 } | |
| 1128 FX_BOOL CXFA_WidgetData::IsAllowNeutral() { | |
| 1129 CXFA_Node* pUIChild = GetUIChild(); | |
| 1130 if (pUIChild) { | |
| 1131 return pUIChild->GetBoolean(XFA_ATTRIBUTE_AllowNeutral); | |
| 1132 } | |
| 1133 return XFA_GetAttributeDefaultValue_Boolean( | |
| 1134 XFA_ELEMENT_CheckButton, XFA_ATTRIBUTE_AllowNeutral, XFA_XDPPACKET_Form); | |
| 1135 } | |
| 1136 XFA_CHECKSTATE CXFA_WidgetData::GetCheckState() { | |
| 1137 CFX_WideString wsValue = GetRawValue(); | |
| 1138 if (wsValue.IsEmpty()) { | |
| 1139 return XFA_CHECKSTATE_Off; | |
| 1140 } | |
| 1141 if (CXFA_Node* pItems = m_pNode->GetChild(0, XFA_ELEMENT_Items)) { | |
| 1142 CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1143 int32_t i = 0; | |
| 1144 while (pText) { | |
| 1145 CFX_WideString wsContent; | |
| 1146 if (pText->TryContent(wsContent) && (wsContent == wsValue)) { | |
| 1147 return (XFA_CHECKSTATE)i; | |
| 1148 } | |
| 1149 i++; | |
| 1150 pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling); | |
| 1151 } | |
| 1152 } | |
| 1153 return XFA_CHECKSTATE_Off; | |
| 1154 } | |
| 1155 void CXFA_WidgetData::SetCheckState(XFA_CHECKSTATE eCheckState, | |
| 1156 FX_BOOL bNotify) { | |
| 1157 CXFA_WidgetData exclGroup(GetExclGroupNode()); | |
| 1158 if (exclGroup) { | |
| 1159 CFX_WideString wsValue; | |
| 1160 if (eCheckState != XFA_CHECKSTATE_Off) { | |
| 1161 if (CXFA_Node* pItems = m_pNode->GetChild(0, XFA_ELEMENT_Items)) { | |
| 1162 CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1163 if (pText) { | |
| 1164 pText->TryContent(wsValue); | |
| 1165 } | |
| 1166 } | |
| 1167 } | |
| 1168 CXFA_Node* pChild = | |
| 1169 exclGroup.GetNode()->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1170 for (; pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 1171 if (pChild->GetClassID() != XFA_ELEMENT_Field) { | |
| 1172 continue; | |
| 1173 } | |
| 1174 CXFA_Node* pItem = pChild->GetChild(0, XFA_ELEMENT_Items); | |
| 1175 if (!pItem) { | |
| 1176 continue; | |
| 1177 } | |
| 1178 CXFA_Node* pItemchild = pItem->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1179 if (!pItemchild) { | |
| 1180 continue; | |
| 1181 } | |
| 1182 CFX_WideString text = pItemchild->GetContent(); | |
| 1183 CFX_WideString wsChildValue = text; | |
| 1184 if (wsValue != text) { | |
| 1185 pItemchild = pItemchild->GetNodeItem(XFA_NODEITEM_NextSibling); | |
| 1186 if (pItemchild) { | |
| 1187 wsChildValue = pItemchild->GetContent(); | |
| 1188 } else { | |
| 1189 wsChildValue.Empty(); | |
| 1190 } | |
| 1191 } | |
| 1192 CXFA_WidgetData ch(pChild); | |
| 1193 ch.SyncValue(wsChildValue, bNotify); | |
| 1194 } | |
| 1195 exclGroup.SyncValue(wsValue, bNotify); | |
| 1196 } else { | |
| 1197 CXFA_Node* pItems = m_pNode->GetChild(0, XFA_ELEMENT_Items); | |
| 1198 if (!pItems) { | |
| 1199 return; | |
| 1200 } | |
| 1201 int32_t i = -1; | |
| 1202 CXFA_Node* pText = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1203 CFX_WideString wsContent; | |
| 1204 while (pText) { | |
| 1205 i++; | |
| 1206 if (i == eCheckState) { | |
| 1207 pText->TryContent(wsContent); | |
| 1208 break; | |
| 1209 } | |
| 1210 pText = pText->GetNodeItem(XFA_NODEITEM_NextSibling); | |
| 1211 } | |
| 1212 SyncValue(wsContent, bNotify); | |
| 1213 } | |
| 1214 } | |
| 1215 CXFA_Node* CXFA_WidgetData::GetExclGroupNode() { | |
| 1216 CXFA_Node* pExcl = ToNode(m_pNode->GetNodeItem(XFA_NODEITEM_Parent)); | |
| 1217 if (!pExcl || pExcl->GetClassID() != XFA_ELEMENT_ExclGroup) { | |
| 1218 return NULL; | |
| 1219 } | |
| 1220 return pExcl; | |
| 1221 } | |
| 1222 CXFA_Node* CXFA_WidgetData::GetSelectedMember() { | |
| 1223 CXFA_Node* pSelectedMember = NULL; | |
| 1224 CFX_WideString wsState = GetRawValue(); | |
| 1225 if (wsState.IsEmpty()) { | |
| 1226 return pSelectedMember; | |
| 1227 } | |
| 1228 for (CXFA_Node* pNode = ToNode(m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild)); | |
| 1229 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 1230 CXFA_WidgetData widgetData(pNode); | |
| 1231 if (widgetData.GetCheckState() == XFA_CHECKSTATE_On) { | |
| 1232 pSelectedMember = pNode; | |
| 1233 break; | |
| 1234 } | |
| 1235 } | |
| 1236 return pSelectedMember; | |
| 1237 } | |
| 1238 CXFA_Node* CXFA_WidgetData::SetSelectedMember(const CFX_WideStringC& wsName, | |
| 1239 FX_BOOL bNotify) { | |
| 1240 CXFA_Node* pSelectedMember = NULL; | |
| 1241 uint32_t nameHash = | |
| 1242 FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength()); | |
| 1243 for (CXFA_Node* pNode = ToNode(m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild)); | |
| 1244 pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 1245 if (pNode->GetNameHash() == nameHash) { | |
| 1246 CXFA_WidgetData widgetData(pNode); | |
| 1247 widgetData.SetCheckState(XFA_CHECKSTATE_On, bNotify); | |
| 1248 pSelectedMember = pNode; | |
| 1249 break; | |
| 1250 } | |
| 1251 } | |
| 1252 return pSelectedMember; | |
| 1253 } | |
| 1254 void CXFA_WidgetData::SetSelectedMemberByValue(const CFX_WideStringC& wsValue, | |
| 1255 FX_BOOL bNotify, | |
| 1256 FX_BOOL bScriptModify, | |
| 1257 FX_BOOL bSyncData) { | |
| 1258 CFX_WideString wsExclGroup; | |
| 1259 for (CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); pNode; | |
| 1260 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 1261 if (pNode->GetClassID() != XFA_ELEMENT_Field) { | |
| 1262 continue; | |
| 1263 } | |
| 1264 CXFA_Node* pItem = pNode->GetChild(0, XFA_ELEMENT_Items); | |
| 1265 if (!pItem) { | |
| 1266 continue; | |
| 1267 } | |
| 1268 CXFA_Node* pItemchild = pItem->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1269 if (!pItemchild) { | |
| 1270 continue; | |
| 1271 } | |
| 1272 CFX_WideString wsChildValue = pItemchild->GetContent(); | |
| 1273 if (wsValue != wsChildValue) { | |
| 1274 pItemchild = pItemchild->GetNodeItem(XFA_NODEITEM_NextSibling); | |
| 1275 if (pItemchild) { | |
| 1276 wsChildValue = pItemchild->GetContent(); | |
| 1277 } else { | |
| 1278 wsChildValue.Empty(); | |
| 1279 } | |
| 1280 } else { | |
| 1281 wsExclGroup = wsValue; | |
| 1282 } | |
| 1283 pNode->SetContent(wsChildValue, wsChildValue, bNotify, bScriptModify, | |
| 1284 FALSE); | |
| 1285 } | |
| 1286 if (m_pNode) { | |
| 1287 m_pNode->SetContent(wsExclGroup, wsExclGroup, bNotify, bScriptModify, | |
| 1288 bSyncData); | |
| 1289 } | |
| 1290 } | |
| 1291 CXFA_Node* CXFA_WidgetData::GetExclGroupFirstMember() { | |
| 1292 CXFA_Node* pExcl = GetNode(); | |
| 1293 if (!pExcl) { | |
| 1294 return NULL; | |
| 1295 } | |
| 1296 CXFA_Node* pNode = pExcl->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1297 while (pNode) { | |
| 1298 if (pNode->GetClassID() == XFA_ELEMENT_Field) { | |
| 1299 return pNode; | |
| 1300 } | |
| 1301 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); | |
| 1302 } | |
| 1303 return NULL; | |
| 1304 } | |
| 1305 CXFA_Node* CXFA_WidgetData::GetExclGroupNextMember(CXFA_Node* pNode) { | |
| 1306 if (!pNode) { | |
| 1307 return NULL; | |
| 1308 } | |
| 1309 CXFA_Node* pNodeField = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); | |
| 1310 while (pNodeField) { | |
| 1311 if (pNodeField->GetClassID() == XFA_ELEMENT_Field) { | |
| 1312 return pNodeField; | |
| 1313 } | |
| 1314 pNodeField = pNodeField->GetNodeItem(XFA_NODEITEM_NextSibling); | |
| 1315 } | |
| 1316 return NULL; | |
| 1317 } | |
| 1318 int32_t CXFA_WidgetData::GetChoiceListCommitOn() { | |
| 1319 CXFA_Node* pUIChild = GetUIChild(); | |
| 1320 if (pUIChild) { | |
| 1321 return pUIChild->GetEnum(XFA_ATTRIBUTE_CommitOn); | |
| 1322 } | |
| 1323 return XFA_GetAttributeDefaultValue_Enum( | |
| 1324 XFA_ELEMENT_ChoiceList, XFA_ATTRIBUTE_CommitOn, XFA_XDPPACKET_Form); | |
| 1325 } | |
| 1326 FX_BOOL CXFA_WidgetData::IsChoiceListAllowTextEntry() { | |
| 1327 CXFA_Node* pUIChild = GetUIChild(); | |
| 1328 if (pUIChild) { | |
| 1329 return pUIChild->GetBoolean(XFA_ATTRIBUTE_TextEntry); | |
| 1330 } | |
| 1331 return XFA_GetAttributeDefaultValue_Boolean( | |
| 1332 XFA_ELEMENT_ChoiceList, XFA_ATTRIBUTE_TextEntry, XFA_XDPPACKET_Form); | |
| 1333 } | |
| 1334 int32_t CXFA_WidgetData::GetChoiceListOpen() { | |
| 1335 CXFA_Node* pUIChild = GetUIChild(); | |
| 1336 if (pUIChild) { | |
| 1337 return pUIChild->GetEnum(XFA_ATTRIBUTE_Open); | |
| 1338 } | |
| 1339 return XFA_GetAttributeDefaultValue_Enum( | |
| 1340 XFA_ELEMENT_ChoiceList, XFA_ATTRIBUTE_Open, XFA_XDPPACKET_Form); | |
| 1341 } | |
| 1342 FX_BOOL CXFA_WidgetData::IsListBox() { | |
| 1343 int32_t iOpenMode = GetChoiceListOpen(); | |
| 1344 return (iOpenMode == XFA_ATTRIBUTEENUM_Always || | |
| 1345 iOpenMode == XFA_ATTRIBUTEENUM_MultiSelect); | |
| 1346 } | |
| 1347 int32_t CXFA_WidgetData::CountChoiceListItems(FX_BOOL bSaveValue) { | |
| 1348 CXFA_NodeArray pItems; | |
| 1349 CXFA_Node* pItem = NULL; | |
| 1350 int32_t iCount = 0; | |
| 1351 CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1352 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 1353 if (pNode->GetClassID() != XFA_ELEMENT_Items) { | |
| 1354 continue; | |
| 1355 } | |
| 1356 iCount++; | |
| 1357 pItems.Add(pNode); | |
| 1358 if (iCount == 2) { | |
| 1359 break; | |
| 1360 } | |
| 1361 } | |
| 1362 if (iCount == 0) { | |
| 1363 return 0; | |
| 1364 } | |
| 1365 pItem = pItems[0]; | |
| 1366 if (iCount > 1) { | |
| 1367 FX_BOOL bItemOneHasSave = pItems[0]->GetBoolean(XFA_ATTRIBUTE_Save); | |
| 1368 FX_BOOL bItemTwoHasSave = pItems[1]->GetBoolean(XFA_ATTRIBUTE_Save); | |
| 1369 if (bItemOneHasSave != bItemTwoHasSave && bSaveValue == bItemTwoHasSave) { | |
| 1370 pItem = pItems[1]; | |
| 1371 } | |
| 1372 } | |
| 1373 pItems.RemoveAll(); | |
| 1374 return pItem->CountChildren(XFA_ELEMENT_UNKNOWN); | |
| 1375 } | |
| 1376 FX_BOOL CXFA_WidgetData::GetChoiceListItem(CFX_WideString& wsText, | |
| 1377 int32_t nIndex, | |
| 1378 FX_BOOL bSaveValue) { | |
| 1379 wsText.Empty(); | |
| 1380 CXFA_NodeArray pItemsArray; | |
| 1381 CXFA_Node* pItems = NULL; | |
| 1382 int32_t iCount = 0; | |
| 1383 CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1384 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 1385 if (pNode->GetClassID() != XFA_ELEMENT_Items) { | |
| 1386 continue; | |
| 1387 } | |
| 1388 iCount++; | |
| 1389 pItemsArray.Add(pNode); | |
| 1390 if (iCount == 2) { | |
| 1391 break; | |
| 1392 } | |
| 1393 } | |
| 1394 if (iCount == 0) { | |
| 1395 return FALSE; | |
| 1396 } | |
| 1397 pItems = pItemsArray[0]; | |
| 1398 if (iCount > 1) { | |
| 1399 FX_BOOL bItemOneHasSave = pItemsArray[0]->GetBoolean(XFA_ATTRIBUTE_Save); | |
| 1400 FX_BOOL bItemTwoHasSave = pItemsArray[1]->GetBoolean(XFA_ATTRIBUTE_Save); | |
| 1401 if (bItemOneHasSave != bItemTwoHasSave && bSaveValue == bItemTwoHasSave) { | |
| 1402 pItems = pItemsArray[1]; | |
| 1403 } | |
| 1404 } | |
| 1405 if (pItems) { | |
| 1406 CXFA_Node* pItem = pItems->GetChild(nIndex, XFA_ELEMENT_UNKNOWN); | |
| 1407 if (pItem) { | |
| 1408 pItem->TryContent(wsText); | |
| 1409 return TRUE; | |
| 1410 } | |
| 1411 } | |
| 1412 return FALSE; | |
| 1413 } | |
| 1414 void CXFA_WidgetData::GetChoiceListItems(CFX_WideStringArray& wsTextArray, | |
| 1415 FX_BOOL bSaveValue) { | |
| 1416 CXFA_NodeArray pItems; | |
| 1417 CXFA_Node* pItem = NULL; | |
| 1418 int32_t iCount = 0; | |
| 1419 CXFA_Node* pNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1420 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 1421 if (pNode->GetClassID() != XFA_ELEMENT_Items) { | |
| 1422 continue; | |
| 1423 } | |
| 1424 iCount++; | |
| 1425 pItems.Add(pNode); | |
| 1426 if (iCount == 2) { | |
| 1427 break; | |
| 1428 } | |
| 1429 } | |
| 1430 if (iCount == 0) { | |
| 1431 return; | |
| 1432 } | |
| 1433 pItem = pItems[0]; | |
| 1434 if (iCount > 1) { | |
| 1435 FX_BOOL bItemOneHasSave = pItems[0]->GetBoolean(XFA_ATTRIBUTE_Save); | |
| 1436 FX_BOOL bItemTwoHasSave = pItems[1]->GetBoolean(XFA_ATTRIBUTE_Save); | |
| 1437 if (bItemOneHasSave != bItemTwoHasSave && bSaveValue == bItemTwoHasSave) { | |
| 1438 pItem = pItems[1]; | |
| 1439 } | |
| 1440 } | |
| 1441 pItems.RemoveAll(); | |
| 1442 pNode = pItem->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1443 for (; pNode; pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 1444 pNode->TryContent(wsTextArray.Add()); | |
| 1445 } | |
| 1446 } | |
| 1447 int32_t CXFA_WidgetData::CountSelectedItems() { | |
| 1448 CFX_WideStringArray wsValueArray; | |
| 1449 GetSelectedItemsValue(wsValueArray); | |
| 1450 if (IsListBox() || !IsChoiceListAllowTextEntry()) { | |
| 1451 return wsValueArray.GetSize(); | |
| 1452 } | |
| 1453 int32_t iSelected = 0; | |
| 1454 CFX_WideStringArray wsSaveTextArray; | |
| 1455 GetChoiceListItems(wsSaveTextArray, TRUE); | |
| 1456 int32_t iValues = wsValueArray.GetSize(); | |
| 1457 for (int32_t i = 0; i < iValues; i++) { | |
| 1458 int32_t iSaves = wsSaveTextArray.GetSize(); | |
| 1459 for (int32_t j = 0; j < iSaves; j++) { | |
| 1460 if (wsValueArray[i] == wsSaveTextArray[j]) { | |
| 1461 iSelected++; | |
| 1462 break; | |
| 1463 } | |
| 1464 } | |
| 1465 } | |
| 1466 return iSelected; | |
| 1467 } | |
| 1468 int32_t CXFA_WidgetData::GetSelectedItem(int32_t nIndex) { | |
| 1469 CFX_WideStringArray wsValueArray; | |
| 1470 GetSelectedItemsValue(wsValueArray); | |
| 1471 CFX_WideStringArray wsSaveTextArray; | |
| 1472 GetChoiceListItems(wsSaveTextArray, TRUE); | |
| 1473 int32_t iSaves = wsSaveTextArray.GetSize(); | |
| 1474 for (int32_t j = 0; j < iSaves; j++) { | |
| 1475 if (wsValueArray[nIndex] == wsSaveTextArray[j]) { | |
| 1476 return j; | |
| 1477 } | |
| 1478 } | |
| 1479 return -1; | |
| 1480 } | |
| 1481 void CXFA_WidgetData::GetSelectedItems(CFX_Int32Array& iSelArray) { | |
| 1482 CFX_WideStringArray wsValueArray; | |
| 1483 GetSelectedItemsValue(wsValueArray); | |
| 1484 int32_t iValues = wsValueArray.GetSize(); | |
| 1485 if (iValues < 1) { | |
| 1486 return; | |
| 1487 } | |
| 1488 CFX_WideStringArray wsSaveTextArray; | |
| 1489 GetChoiceListItems(wsSaveTextArray, TRUE); | |
| 1490 int32_t iSaves = wsSaveTextArray.GetSize(); | |
| 1491 for (int32_t i = 0; i < iValues; i++) { | |
| 1492 for (int32_t j = 0; j < iSaves; j++) { | |
| 1493 if (wsValueArray[i] == wsSaveTextArray[j]) { | |
| 1494 iSelArray.Add(j); | |
| 1495 break; | |
| 1496 } | |
| 1497 } | |
| 1498 } | |
| 1499 } | |
| 1500 void CXFA_WidgetData::GetSelectedItemsValue( | |
| 1501 CFX_WideStringArray& wsSelTextArray) { | |
| 1502 CFX_WideString wsValue = GetRawValue(); | |
| 1503 if (GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { | |
| 1504 if (!wsValue.IsEmpty()) { | |
| 1505 int32_t iStart = 0; | |
| 1506 int32_t iLength = wsValue.GetLength(); | |
| 1507 int32_t iEnd = wsValue.Find(L'\n', iStart); | |
| 1508 iEnd = (iEnd == -1) ? iLength : iEnd; | |
| 1509 while (iEnd >= iStart) { | |
| 1510 wsSelTextArray.Add(wsValue.Mid(iStart, iEnd - iStart)); | |
| 1511 iStart = iEnd + 1; | |
| 1512 if (iStart >= iLength) { | |
| 1513 break; | |
| 1514 } | |
| 1515 iEnd = wsValue.Find(L'\n', iStart); | |
| 1516 if (iEnd < 0) { | |
| 1517 wsSelTextArray.Add(wsValue.Mid(iStart, iLength - iStart)); | |
| 1518 } | |
| 1519 } | |
| 1520 } | |
| 1521 } else { | |
| 1522 wsSelTextArray.Add(wsValue); | |
| 1523 } | |
| 1524 } | |
| 1525 FX_BOOL CXFA_WidgetData::GetItemState(int32_t nIndex) { | |
| 1526 if (nIndex < 0) { | |
| 1527 return FALSE; | |
| 1528 } | |
| 1529 CFX_WideStringArray wsSaveTextArray; | |
| 1530 GetChoiceListItems(wsSaveTextArray, TRUE); | |
| 1531 if (wsSaveTextArray.GetSize() <= nIndex) { | |
| 1532 return FALSE; | |
| 1533 } | |
| 1534 CFX_WideStringArray wsValueArray; | |
| 1535 GetSelectedItemsValue(wsValueArray); | |
| 1536 int32_t iValues = wsValueArray.GetSize(); | |
| 1537 for (int32_t j = 0; j < iValues; j++) { | |
| 1538 if (wsValueArray[j] == wsSaveTextArray[nIndex]) { | |
| 1539 return TRUE; | |
| 1540 } | |
| 1541 } | |
| 1542 return FALSE; | |
| 1543 } | |
| 1544 void CXFA_WidgetData::SetItemState(int32_t nIndex, | |
| 1545 FX_BOOL bSelected, | |
| 1546 FX_BOOL bNotify, | |
| 1547 FX_BOOL bScriptModify, | |
| 1548 FX_BOOL bSyncData) { | |
| 1549 if (nIndex < 0) { | |
| 1550 return; | |
| 1551 } | |
| 1552 CFX_WideStringArray wsSaveTextArray; | |
| 1553 GetChoiceListItems(wsSaveTextArray, TRUE); | |
| 1554 if (wsSaveTextArray.GetSize() <= nIndex) { | |
| 1555 return; | |
| 1556 } | |
| 1557 int32_t iSel = -1; | |
| 1558 CFX_WideStringArray wsValueArray; | |
| 1559 GetSelectedItemsValue(wsValueArray); | |
| 1560 int32_t iValues = wsValueArray.GetSize(); | |
| 1561 for (int32_t j = 0; j < iValues; j++) { | |
| 1562 if (wsValueArray[j] == wsSaveTextArray[nIndex]) { | |
| 1563 iSel = j; | |
| 1564 break; | |
| 1565 } | |
| 1566 } | |
| 1567 if (GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { | |
| 1568 if (bSelected) { | |
| 1569 if (iSel < 0) { | |
| 1570 CFX_WideString wsValue = GetRawValue(); | |
| 1571 if (!wsValue.IsEmpty()) { | |
| 1572 wsValue += L"\n"; | |
| 1573 } | |
| 1574 wsValue += wsSaveTextArray[nIndex]; | |
| 1575 m_pNode->SetContent(wsValue, wsValue, bNotify, bScriptModify, | |
| 1576 bSyncData); | |
| 1577 } | |
| 1578 } else if (iSel >= 0) { | |
| 1579 CFX_Int32Array iSelArray; | |
| 1580 GetSelectedItems(iSelArray); | |
| 1581 for (int32_t i = 0; i < iSelArray.GetSize(); i++) { | |
| 1582 if (iSelArray[i] == nIndex) { | |
| 1583 iSelArray.RemoveAt(i); | |
| 1584 break; | |
| 1585 } | |
| 1586 } | |
| 1587 SetSelectdItems(iSelArray, bNotify, bScriptModify, bSyncData); | |
| 1588 } | |
| 1589 } else { | |
| 1590 if (bSelected) { | |
| 1591 if (iSel < 0) { | |
| 1592 CFX_WideString wsSaveText = wsSaveTextArray[nIndex]; | |
| 1593 CFX_WideString wsFormatText(wsSaveText); | |
| 1594 GetFormatDataValue(wsSaveText.AsWideStringC(), wsFormatText); | |
| 1595 m_pNode->SetContent(wsSaveText, wsFormatText, bNotify, bScriptModify, | |
| 1596 bSyncData); | |
| 1597 } | |
| 1598 } else if (iSel >= 0) { | |
| 1599 m_pNode->SetContent(CFX_WideString(), CFX_WideString(), bNotify, | |
| 1600 bScriptModify, bSyncData); | |
| 1601 } | |
| 1602 } | |
| 1603 } | |
| 1604 void CXFA_WidgetData::SetSelectdItems(CFX_Int32Array& iSelArray, | |
| 1605 FX_BOOL bNotify, | |
| 1606 FX_BOOL bScriptModify, | |
| 1607 FX_BOOL bSyncData) { | |
| 1608 CFX_WideString wsValue; | |
| 1609 int32_t iSize = iSelArray.GetSize(); | |
| 1610 if (iSize >= 1) { | |
| 1611 CFX_WideStringArray wsSaveTextArray; | |
| 1612 GetChoiceListItems(wsSaveTextArray, TRUE); | |
| 1613 CFX_WideString wsItemValue; | |
| 1614 for (int32_t i = 0; i < iSize; i++) { | |
| 1615 wsItemValue = (iSize == 1) | |
| 1616 ? wsSaveTextArray[iSelArray[i]] | |
| 1617 : wsSaveTextArray[iSelArray[i]] + FX_WSTRC(L"\n"); | |
| 1618 wsValue += wsItemValue; | |
| 1619 } | |
| 1620 } | |
| 1621 CFX_WideString wsFormat(wsValue); | |
| 1622 if (GetChoiceListOpen() != XFA_ATTRIBUTEENUM_MultiSelect) { | |
| 1623 GetFormatDataValue(wsValue.AsWideStringC(), wsFormat); | |
| 1624 } | |
| 1625 m_pNode->SetContent(wsValue, wsFormat, bNotify, bScriptModify, bSyncData); | |
| 1626 } | |
| 1627 void CXFA_WidgetData::ClearAllSelections() { | |
| 1628 CXFA_Node* pBind = m_pNode->GetBindData(); | |
| 1629 if (pBind && GetChoiceListOpen() == XFA_ATTRIBUTEENUM_MultiSelect) { | |
| 1630 while (CXFA_Node* pChildNode = | |
| 1631 pBind->GetNodeItem(XFA_NODEITEM_FirstChild)) { | |
| 1632 pBind->RemoveChild(pChildNode); | |
| 1633 } | |
| 1634 } else { | |
| 1635 SyncValue(CFX_WideString(), FALSE); | |
| 1636 } | |
| 1637 } | |
| 1638 void CXFA_WidgetData::InsertItem(const CFX_WideString& wsLabel, | |
| 1639 const CFX_WideString& wsValue, | |
| 1640 int32_t nIndex, | |
| 1641 FX_BOOL bNotify) { | |
| 1642 CFX_WideString wsNewValue(wsValue); | |
| 1643 if (wsNewValue.IsEmpty()) { | |
| 1644 wsNewValue = wsLabel; | |
| 1645 } | |
| 1646 CXFA_NodeArray listitems; | |
| 1647 int32_t iCount = 0; | |
| 1648 CXFA_Node* pItemNode = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1649 for (; pItemNode; | |
| 1650 pItemNode = pItemNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 1651 if (pItemNode->GetClassID() != XFA_ELEMENT_Items) { | |
| 1652 continue; | |
| 1653 } | |
| 1654 listitems.Add(pItemNode); | |
| 1655 iCount++; | |
| 1656 } | |
| 1657 if (iCount < 1) { | |
| 1658 CXFA_Node* pItems = m_pNode->CreateSamePacketNode(XFA_ELEMENT_Items); | |
| 1659 m_pNode->InsertChild(-1, pItems); | |
| 1660 InsertListTextItem(pItems, wsLabel.AsWideStringC(), nIndex); | |
| 1661 CXFA_Node* pSaveItems = m_pNode->CreateSamePacketNode(XFA_ELEMENT_Items); | |
| 1662 m_pNode->InsertChild(-1, pSaveItems); | |
| 1663 pSaveItems->SetBoolean(XFA_ATTRIBUTE_Save, TRUE); | |
| 1664 InsertListTextItem(pSaveItems, wsNewValue.AsWideStringC(), nIndex); | |
| 1665 } else if (iCount > 1) { | |
| 1666 for (int32_t i = 0; i < 2; i++) { | |
| 1667 CXFA_Node* pNode = listitems[i]; | |
| 1668 FX_BOOL bHasSave = pNode->GetBoolean(XFA_ATTRIBUTE_Save); | |
| 1669 if (bHasSave) { | |
| 1670 InsertListTextItem(pNode, wsNewValue.AsWideStringC(), nIndex); | |
| 1671 } else { | |
| 1672 InsertListTextItem(pNode, wsLabel.AsWideStringC(), nIndex); | |
| 1673 } | |
| 1674 } | |
| 1675 } else { | |
| 1676 CXFA_Node* pNode = listitems[0]; | |
| 1677 pNode->SetBoolean(XFA_ATTRIBUTE_Save, FALSE); | |
| 1678 pNode->SetEnum(XFA_ATTRIBUTE_Presence, XFA_ATTRIBUTEENUM_Visible); | |
| 1679 CXFA_Node* pSaveItems = m_pNode->CreateSamePacketNode(XFA_ELEMENT_Items); | |
| 1680 m_pNode->InsertChild(-1, pSaveItems); | |
| 1681 pSaveItems->SetBoolean(XFA_ATTRIBUTE_Save, TRUE); | |
| 1682 pSaveItems->SetEnum(XFA_ATTRIBUTE_Presence, XFA_ATTRIBUTEENUM_Hidden); | |
| 1683 listitems.RemoveAll(); | |
| 1684 CXFA_Node* pListNode = pNode->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1685 int32_t i = 0; | |
| 1686 while (pListNode) { | |
| 1687 CFX_WideString wsOldValue; | |
| 1688 pListNode->TryContent(wsOldValue); | |
| 1689 InsertListTextItem(pSaveItems, wsOldValue.AsWideStringC(), i); | |
| 1690 i++; | |
| 1691 pListNode = pListNode->GetNodeItem(XFA_NODEITEM_NextSibling); | |
| 1692 } | |
| 1693 InsertListTextItem(pNode, wsLabel.AsWideStringC(), nIndex); | |
| 1694 InsertListTextItem(pSaveItems, wsNewValue.AsWideStringC(), nIndex); | |
| 1695 } | |
| 1696 if (!bNotify) { | |
| 1697 return; | |
| 1698 } | |
| 1699 m_pNode->GetDocument()->GetNotify()->OnWidgetDataEvent( | |
| 1700 this, XFA_WIDGETEVENT_ListItemAdded, (void*)(const FX_WCHAR*)wsLabel, | |
| 1701 (void*)(const FX_WCHAR*)wsValue, (void*)(uintptr_t)nIndex); | |
| 1702 } | |
| 1703 void CXFA_WidgetData::GetItemLabel(const CFX_WideStringC& wsValue, | |
| 1704 CFX_WideString& wsLabel) { | |
| 1705 int32_t iCount = 0; | |
| 1706 CXFA_NodeArray listitems; | |
| 1707 CXFA_Node* pItems = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1708 for (; pItems; pItems = pItems->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 1709 if (pItems->GetClassID() != XFA_ELEMENT_Items) { | |
| 1710 continue; | |
| 1711 } | |
| 1712 iCount++; | |
| 1713 listitems.Add(pItems); | |
| 1714 } | |
| 1715 if (iCount <= 1) { | |
| 1716 wsLabel = wsValue; | |
| 1717 } else { | |
| 1718 CXFA_Node* pLabelItems = listitems[0]; | |
| 1719 FX_BOOL bSave = pLabelItems->GetBoolean(XFA_ATTRIBUTE_Save); | |
| 1720 CXFA_Node* pSaveItems = NULL; | |
| 1721 if (bSave) { | |
| 1722 pSaveItems = pLabelItems; | |
| 1723 pLabelItems = listitems[1]; | |
| 1724 } else { | |
| 1725 pSaveItems = listitems[1]; | |
| 1726 } | |
| 1727 iCount = 0; | |
| 1728 int32_t iSearch = -1; | |
| 1729 CFX_WideString wsContent; | |
| 1730 CXFA_Node* pChildItem = pSaveItems->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1731 for (; pChildItem; | |
| 1732 pChildItem = pChildItem->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 1733 pChildItem->TryContent(wsContent); | |
| 1734 if (wsContent == wsValue) { | |
| 1735 iSearch = iCount; | |
| 1736 break; | |
| 1737 } | |
| 1738 iCount++; | |
| 1739 } | |
| 1740 if (iSearch < 0) { | |
| 1741 return; | |
| 1742 } | |
| 1743 if (CXFA_Node* pText = | |
| 1744 pLabelItems->GetChild(iSearch, XFA_ELEMENT_UNKNOWN)) { | |
| 1745 pText->TryContent(wsLabel); | |
| 1746 } | |
| 1747 } | |
| 1748 } | |
| 1749 void CXFA_WidgetData::GetItemValue(const CFX_WideStringC& wsLabel, | |
| 1750 CFX_WideString& wsValue) { | |
| 1751 int32_t iCount = 0; | |
| 1752 CXFA_NodeArray listitems; | |
| 1753 CXFA_Node* pItems = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1754 for (; pItems; pItems = pItems->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 1755 if (pItems->GetClassID() != XFA_ELEMENT_Items) { | |
| 1756 continue; | |
| 1757 } | |
| 1758 iCount++; | |
| 1759 listitems.Add(pItems); | |
| 1760 } | |
| 1761 if (iCount <= 1) { | |
| 1762 wsValue = wsLabel; | |
| 1763 } else { | |
| 1764 CXFA_Node* pLabelItems = listitems[0]; | |
| 1765 FX_BOOL bSave = pLabelItems->GetBoolean(XFA_ATTRIBUTE_Save); | |
| 1766 CXFA_Node* pSaveItems = NULL; | |
| 1767 if (bSave) { | |
| 1768 pSaveItems = pLabelItems; | |
| 1769 pLabelItems = listitems[1]; | |
| 1770 } else { | |
| 1771 pSaveItems = listitems[1]; | |
| 1772 } | |
| 1773 iCount = 0; | |
| 1774 int32_t iSearch = -1; | |
| 1775 CFX_WideString wsContent; | |
| 1776 CXFA_Node* pChildItem = pLabelItems->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1777 for (; pChildItem; | |
| 1778 pChildItem = pChildItem->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 1779 pChildItem->TryContent(wsContent); | |
| 1780 if (wsContent == wsLabel) { | |
| 1781 iSearch = iCount; | |
| 1782 break; | |
| 1783 } | |
| 1784 iCount++; | |
| 1785 } | |
| 1786 if (iSearch < 0) { | |
| 1787 return; | |
| 1788 } | |
| 1789 if (CXFA_Node* pText = pSaveItems->GetChild(iSearch, XFA_ELEMENT_UNKNOWN)) { | |
| 1790 pText->TryContent(wsValue); | |
| 1791 } | |
| 1792 } | |
| 1793 } | |
| 1794 FX_BOOL CXFA_WidgetData::DeleteItem(int32_t nIndex, | |
| 1795 FX_BOOL bNotify, | |
| 1796 FX_BOOL bScriptModify, | |
| 1797 FX_BOOL bSyncData) { | |
| 1798 FX_BOOL bSetValue = FALSE; | |
| 1799 CXFA_Node* pItems = m_pNode->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1800 for (; pItems; pItems = pItems->GetNodeItem(XFA_NODEITEM_NextSibling)) { | |
| 1801 if (pItems->GetClassID() != XFA_ELEMENT_Items) { | |
| 1802 continue; | |
| 1803 } | |
| 1804 if (nIndex < 0) { | |
| 1805 while (CXFA_Node* pNode = pItems->GetNodeItem(XFA_NODEITEM_FirstChild)) { | |
| 1806 pItems->RemoveChild(pNode); | |
| 1807 } | |
| 1808 } else { | |
| 1809 if (!bSetValue && pItems->GetBoolean(XFA_ATTRIBUTE_Save)) { | |
| 1810 SetItemState(nIndex, FALSE, TRUE, bScriptModify, bSyncData); | |
| 1811 bSetValue = TRUE; | |
| 1812 } | |
| 1813 int32_t i = 0; | |
| 1814 CXFA_Node* pNode = pItems->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 1815 while (pNode) { | |
| 1816 if (i == nIndex) { | |
| 1817 pItems->RemoveChild(pNode); | |
| 1818 break; | |
| 1819 } | |
| 1820 i++; | |
| 1821 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); | |
| 1822 } | |
| 1823 } | |
| 1824 } | |
| 1825 if (!bNotify) { | |
| 1826 return TRUE; | |
| 1827 } | |
| 1828 m_pNode->GetDocument()->GetNotify()->OnWidgetDataEvent( | |
| 1829 this, XFA_WIDGETEVENT_ListItemRemoved, (void*)(uintptr_t)nIndex); | |
| 1830 return TRUE; | |
| 1831 } | |
| 1832 int32_t CXFA_WidgetData::GetHorizontalScrollPolicy() { | |
| 1833 CXFA_Node* pUIChild = GetUIChild(); | |
| 1834 if (pUIChild) { | |
| 1835 return pUIChild->GetEnum(XFA_ATTRIBUTE_HScrollPolicy); | |
| 1836 } | |
| 1837 return XFA_ATTRIBUTEENUM_Auto; | |
| 1838 } | |
| 1839 int32_t CXFA_WidgetData::GetNumberOfCells() { | |
| 1840 CXFA_Node* pUIChild = GetUIChild(); | |
| 1841 if (!pUIChild) { | |
| 1842 return -1; | |
| 1843 } | |
| 1844 if (CXFA_Node* pNode = pUIChild->GetChild(0, XFA_ELEMENT_Comb)) { | |
| 1845 return pNode->GetInteger(XFA_ATTRIBUTE_NumberOfCells); | |
| 1846 } | |
| 1847 return -1; | |
| 1848 } | |
| 1849 CFX_WideString CXFA_WidgetData::GetBarcodeType() { | |
| 1850 CXFA_Node* pUIChild = GetUIChild(); | |
| 1851 return pUIChild ? pUIChild->GetCData(XFA_ATTRIBUTE_Type) : NULL; | |
| 1852 } | |
| 1853 FX_BOOL CXFA_WidgetData::GetBarcodeAttribute_CharEncoding(int32_t& val) { | |
| 1854 CXFA_Node* pUIChild = GetUIChild(); | |
| 1855 CFX_WideString wsCharEncoding; | |
| 1856 if (pUIChild->TryCData(XFA_ATTRIBUTE_CharEncoding, wsCharEncoding)) { | |
| 1857 if (wsCharEncoding.CompareNoCase(L"UTF-16")) { | |
| 1858 val = CHAR_ENCODING_UNICODE; | |
| 1859 return TRUE; | |
| 1860 } else if (wsCharEncoding.CompareNoCase(L"UTF-8")) { | |
| 1861 val = CHAR_ENCODING_UTF8; | |
| 1862 return TRUE; | |
| 1863 } | |
| 1864 } | |
| 1865 return FALSE; | |
| 1866 } | |
| 1867 FX_BOOL CXFA_WidgetData::GetBarcodeAttribute_Checksum(int32_t& val) { | |
| 1868 CXFA_Node* pUIChild = GetUIChild(); | |
| 1869 XFA_ATTRIBUTEENUM eChecksum; | |
| 1870 if (pUIChild->TryEnum(XFA_ATTRIBUTE_Checksum, eChecksum)) { | |
| 1871 switch (eChecksum) { | |
| 1872 case XFA_ATTRIBUTEENUM_None: | |
| 1873 val = 0; | |
| 1874 return TRUE; | |
| 1875 case XFA_ATTRIBUTEENUM_Auto: | |
| 1876 val = 1; | |
| 1877 return TRUE; | |
| 1878 case XFA_ATTRIBUTEENUM_1mod10: | |
| 1879 break; | |
| 1880 case XFA_ATTRIBUTEENUM_1mod10_1mod11: | |
| 1881 break; | |
| 1882 case XFA_ATTRIBUTEENUM_2mod10: | |
| 1883 break; | |
| 1884 default: | |
| 1885 break; | |
| 1886 } | |
| 1887 } | |
| 1888 return FALSE; | |
| 1889 } | |
| 1890 FX_BOOL CXFA_WidgetData::GetBarcodeAttribute_DataLength(int32_t& val) { | |
| 1891 CXFA_Node* pUIChild = GetUIChild(); | |
| 1892 CFX_WideString wsDataLength; | |
| 1893 if (pUIChild->TryCData(XFA_ATTRIBUTE_DataLength, wsDataLength)) { | |
| 1894 val = FXSYS_wtoi(wsDataLength); | |
| 1895 return TRUE; | |
| 1896 } | |
| 1897 return FALSE; | |
| 1898 } | |
| 1899 FX_BOOL CXFA_WidgetData::GetBarcodeAttribute_StartChar(FX_CHAR& val) { | |
| 1900 CXFA_Node* pUIChild = GetUIChild(); | |
| 1901 CFX_WideStringC wsStartEndChar; | |
| 1902 if (pUIChild->TryCData(XFA_ATTRIBUTE_StartChar, wsStartEndChar)) { | |
| 1903 if (wsStartEndChar.GetLength()) { | |
| 1904 val = (FX_CHAR)wsStartEndChar.GetAt(0); | |
| 1905 return TRUE; | |
| 1906 } | |
| 1907 } | |
| 1908 return FALSE; | |
| 1909 } | |
| 1910 FX_BOOL CXFA_WidgetData::GetBarcodeAttribute_EndChar(FX_CHAR& val) { | |
| 1911 CXFA_Node* pUIChild = GetUIChild(); | |
| 1912 CFX_WideStringC wsStartEndChar; | |
| 1913 if (pUIChild->TryCData(XFA_ATTRIBUTE_EndChar, wsStartEndChar)) { | |
| 1914 if (wsStartEndChar.GetLength()) { | |
| 1915 val = (FX_CHAR)wsStartEndChar.GetAt(0); | |
| 1916 return TRUE; | |
| 1917 } | |
| 1918 } | |
| 1919 return FALSE; | |
| 1920 } | |
| 1921 FX_BOOL CXFA_WidgetData::GetBarcodeAttribute_ECLevel(int32_t& val) { | |
| 1922 CXFA_Node* pUIChild = GetUIChild(); | |
| 1923 CFX_WideString wsECLevel; | |
| 1924 if (pUIChild->TryCData(XFA_ATTRIBUTE_ErrorCorrectionLevel, wsECLevel)) { | |
| 1925 val = FXSYS_wtoi(wsECLevel); | |
| 1926 return TRUE; | |
| 1927 } | |
| 1928 return FALSE; | |
| 1929 } | |
| 1930 FX_BOOL CXFA_WidgetData::GetBarcodeAttribute_ModuleWidth(int32_t& val) { | |
| 1931 CXFA_Node* pUIChild = GetUIChild(); | |
| 1932 CXFA_Measurement mModuleWidthHeight; | |
| 1933 if (pUIChild->TryMeasure(XFA_ATTRIBUTE_ModuleWidth, mModuleWidthHeight)) { | |
| 1934 val = (int32_t)mModuleWidthHeight.ToUnit(XFA_UNIT_Pt); | |
| 1935 return TRUE; | |
| 1936 } | |
| 1937 return FALSE; | |
| 1938 } | |
| 1939 FX_BOOL CXFA_WidgetData::GetBarcodeAttribute_ModuleHeight(int32_t& val) { | |
| 1940 CXFA_Node* pUIChild = GetUIChild(); | |
| 1941 CXFA_Measurement mModuleWidthHeight; | |
| 1942 if (pUIChild->TryMeasure(XFA_ATTRIBUTE_ModuleHeight, mModuleWidthHeight)) { | |
| 1943 val = (int32_t)mModuleWidthHeight.ToUnit(XFA_UNIT_Pt); | |
| 1944 return TRUE; | |
| 1945 } | |
| 1946 return FALSE; | |
| 1947 } | |
| 1948 FX_BOOL CXFA_WidgetData::GetBarcodeAttribute_PrintChecksum(FX_BOOL& val) { | |
| 1949 CXFA_Node* pUIChild = GetUIChild(); | |
| 1950 FX_BOOL bPrintCheckDigit; | |
| 1951 if (pUIChild->TryBoolean(XFA_ATTRIBUTE_PrintCheckDigit, bPrintCheckDigit)) { | |
| 1952 val = bPrintCheckDigit; | |
| 1953 return TRUE; | |
| 1954 } | |
| 1955 return FALSE; | |
| 1956 } | |
| 1957 FX_BOOL CXFA_WidgetData::GetBarcodeAttribute_TextLocation(int32_t& val) { | |
| 1958 CXFA_Node* pUIChild = GetUIChild(); | |
| 1959 XFA_ATTRIBUTEENUM eTextLocation; | |
| 1960 if (pUIChild->TryEnum(XFA_ATTRIBUTE_TextLocation, eTextLocation)) { | |
| 1961 switch (eTextLocation) { | |
| 1962 case XFA_ATTRIBUTEENUM_None: | |
| 1963 val = BC_TEXT_LOC_NONE; | |
| 1964 return TRUE; | |
| 1965 case XFA_ATTRIBUTEENUM_Above: | |
| 1966 val = BC_TEXT_LOC_ABOVE; | |
| 1967 return TRUE; | |
| 1968 case XFA_ATTRIBUTEENUM_Below: | |
| 1969 val = BC_TEXT_LOC_BELOW; | |
| 1970 return TRUE; | |
| 1971 case XFA_ATTRIBUTEENUM_AboveEmbedded: | |
| 1972 val = BC_TEXT_LOC_ABOVEEMBED; | |
| 1973 return TRUE; | |
| 1974 case XFA_ATTRIBUTEENUM_BelowEmbedded: | |
| 1975 val = BC_TEXT_LOC_BELOWEMBED; | |
| 1976 return TRUE; | |
| 1977 default: | |
| 1978 break; | |
| 1979 } | |
| 1980 } | |
| 1981 return FALSE; | |
| 1982 } | |
| 1983 FX_BOOL CXFA_WidgetData::GetBarcodeAttribute_Truncate(FX_BOOL& val) { | |
| 1984 CXFA_Node* pUIChild = GetUIChild(); | |
| 1985 FX_BOOL bTruncate; | |
| 1986 if (pUIChild->TryBoolean(XFA_ATTRIBUTE_Truncate, bTruncate)) { | |
| 1987 val = bTruncate; | |
| 1988 return TRUE; | |
| 1989 } | |
| 1990 return FALSE; | |
| 1991 } | |
| 1992 FX_BOOL CXFA_WidgetData::GetBarcodeAttribute_WideNarrowRatio(FX_FLOAT& val) { | |
| 1993 CXFA_Node* pUIChild = GetUIChild(); | |
| 1994 CFX_WideString wsWideNarrowRatio; | |
| 1995 if (pUIChild->TryCData(XFA_ATTRIBUTE_WideNarrowRatio, wsWideNarrowRatio)) { | |
| 1996 FX_STRSIZE ptPos = wsWideNarrowRatio.Find(':'); | |
| 1997 FX_FLOAT fRatio = 0; | |
| 1998 if (ptPos >= 0) { | |
| 1999 fRatio = (FX_FLOAT)FXSYS_wtoi(wsWideNarrowRatio); | |
| 2000 } else { | |
| 2001 int32_t fA, fB; | |
| 2002 fA = FXSYS_wtoi(wsWideNarrowRatio.Left(ptPos)); | |
| 2003 fB = FXSYS_wtoi(wsWideNarrowRatio.Mid(ptPos + 1)); | |
| 2004 if (fB) { | |
| 2005 fRatio = (FX_FLOAT)fA / fB; | |
| 2006 } | |
| 2007 } | |
| 2008 val = fRatio; | |
| 2009 return TRUE; | |
| 2010 } | |
| 2011 return FALSE; | |
| 2012 } | |
| 2013 void CXFA_WidgetData::GetPasswordChar(CFX_WideString& wsPassWord) { | |
| 2014 CXFA_Node* pUIChild = GetUIChild(); | |
| 2015 if (pUIChild) { | |
| 2016 pUIChild->TryCData(XFA_ATTRIBUTE_PasswordChar, wsPassWord); | |
| 2017 } else { | |
| 2018 wsPassWord = XFA_GetAttributeDefaultValue_Cdata(XFA_ELEMENT_PasswordEdit, | |
| 2019 XFA_ATTRIBUTE_PasswordChar, | |
| 2020 XFA_XDPPACKET_Form); | |
| 2021 } | |
| 2022 } | |
| 2023 FX_BOOL CXFA_WidgetData::IsMultiLine() { | |
| 2024 CXFA_Node* pUIChild = GetUIChild(); | |
| 2025 if (pUIChild) { | |
| 2026 return pUIChild->GetBoolean(XFA_ATTRIBUTE_MultiLine); | |
| 2027 } | |
| 2028 return XFA_GetAttributeDefaultValue_Boolean( | |
| 2029 XFA_ELEMENT_TextEdit, XFA_ATTRIBUTE_MultiLine, XFA_XDPPACKET_Form); | |
| 2030 } | |
| 2031 int32_t CXFA_WidgetData::GetVerticalScrollPolicy() { | |
| 2032 CXFA_Node* pUIChild = GetUIChild(); | |
| 2033 if (pUIChild) { | |
| 2034 return pUIChild->GetEnum(XFA_ATTRIBUTE_VScrollPolicy); | |
| 2035 } | |
| 2036 return XFA_GetAttributeDefaultValue_Enum( | |
| 2037 XFA_ELEMENT_TextEdit, XFA_ATTRIBUTE_VScrollPolicy, XFA_XDPPACKET_Form); | |
| 2038 } | |
| 2039 int32_t CXFA_WidgetData::GetMaxChars(XFA_ELEMENT& eType) { | |
| 2040 if (CXFA_Node* pNode = m_pNode->GetChild(0, XFA_ELEMENT_Value)) { | |
| 2041 if (CXFA_Node* pChild = pNode->GetNodeItem(XFA_NODEITEM_FirstChild)) { | |
| 2042 switch (pChild->GetClassID()) { | |
| 2043 case XFA_ELEMENT_Text: | |
| 2044 eType = XFA_ELEMENT_Text; | |
| 2045 return pChild->GetInteger(XFA_ATTRIBUTE_MaxChars); | |
| 2046 case XFA_ELEMENT_ExData: { | |
| 2047 eType = XFA_ELEMENT_ExData; | |
| 2048 int32_t iMax = pChild->GetInteger(XFA_ATTRIBUTE_MaxLength); | |
| 2049 return iMax < 0 ? 0 : iMax; | |
| 2050 } | |
| 2051 default: | |
| 2052 break; | |
| 2053 } | |
| 2054 } | |
| 2055 } | |
| 2056 return 0; | |
| 2057 } | |
| 2058 FX_BOOL CXFA_WidgetData::GetFracDigits(int32_t& iFracDigits) { | |
| 2059 if (CXFA_Node* pNode = m_pNode->GetChild(0, XFA_ELEMENT_Value)) { | |
| 2060 if (CXFA_Node* pChild = pNode->GetChild(0, XFA_ELEMENT_Decimal)) { | |
| 2061 return pChild->TryInteger(XFA_ATTRIBUTE_FracDigits, iFracDigits); | |
| 2062 } | |
| 2063 } | |
| 2064 iFracDigits = -1; | |
| 2065 return FALSE; | |
| 2066 } | |
| 2067 FX_BOOL CXFA_WidgetData::GetLeadDigits(int32_t& iLeadDigits) { | |
| 2068 if (CXFA_Node* pNode = m_pNode->GetChild(0, XFA_ELEMENT_Value)) { | |
| 2069 if (CXFA_Node* pChild = pNode->GetChild(0, XFA_ELEMENT_Decimal)) { | |
| 2070 return pChild->TryInteger(XFA_ATTRIBUTE_LeadDigits, iLeadDigits); | |
| 2071 } | |
| 2072 } | |
| 2073 iLeadDigits = -1; | |
| 2074 return FALSE; | |
| 2075 } | |
| 2076 CFX_WideString XFA_NumericLimit(const CFX_WideString& wsValue, | |
| 2077 int32_t iLead, | |
| 2078 int32_t iTread) { | |
| 2079 if ((iLead == -1) && (iTread == -1)) { | |
| 2080 return wsValue; | |
| 2081 } | |
| 2082 CFX_WideString wsRet; | |
| 2083 int32_t iLead_ = 0, iTread_ = -1; | |
| 2084 int32_t iCount = wsValue.GetLength(); | |
| 2085 if (iCount == 0) { | |
| 2086 return wsValue; | |
| 2087 } | |
| 2088 int32_t i = 0; | |
| 2089 if (wsValue[i] == L'-') { | |
| 2090 wsRet += L'-'; | |
| 2091 i++; | |
| 2092 } | |
| 2093 for (; i < iCount; i++) { | |
| 2094 FX_WCHAR wc = wsValue[i]; | |
| 2095 if (XFA_IsDigit(wc)) { | |
| 2096 if (iLead >= 0) { | |
| 2097 iLead_++; | |
| 2098 if (iLead_ > iLead) { | |
| 2099 return L"0"; | |
| 2100 } | |
| 2101 } else if (iTread_ >= 0) { | |
| 2102 iTread_++; | |
| 2103 if (iTread_ > iTread) { | |
| 2104 if (iTread != -1) { | |
| 2105 CFX_Decimal wsDeci = CFX_Decimal(wsValue.AsWideStringC()); | |
| 2106 wsDeci.SetScale(iTread); | |
| 2107 wsRet = wsDeci; | |
| 2108 } | |
| 2109 return wsRet; | |
| 2110 } | |
| 2111 } | |
| 2112 } else if (wc == L'.') { | |
| 2113 iTread_ = 0; | |
| 2114 iLead = -1; | |
| 2115 } | |
| 2116 wsRet += wc; | |
| 2117 } | |
| 2118 return wsRet; | |
| 2119 } | |
| 2120 FX_BOOL CXFA_WidgetData::SetValue(const CFX_WideString& wsValue, | |
| 2121 XFA_VALUEPICTURE eValueType) { | |
| 2122 if (wsValue.IsEmpty()) { | |
| 2123 SyncValue(wsValue, TRUE); | |
| 2124 return TRUE; | |
| 2125 } | |
| 2126 m_bPreNull = m_bIsNull; | |
| 2127 m_bIsNull = FALSE; | |
| 2128 CFX_WideString wsNewText(wsValue); | |
| 2129 CFX_WideString wsPicture; | |
| 2130 GetPictureContent(wsPicture, eValueType); | |
| 2131 FX_BOOL bValidate = TRUE; | |
| 2132 FX_BOOL bSyncData = FALSE; | |
| 2133 CXFA_Node* pNode = GetUIChild(); | |
| 2134 if (!pNode) { | |
| 2135 return TRUE; | |
| 2136 } | |
| 2137 XFA_ELEMENT uiType = pNode->GetClassID(); | |
| 2138 if (!wsPicture.IsEmpty()) { | |
| 2139 CXFA_LocaleMgr* pLocalMgr = m_pNode->GetDocument()->GetLocalMgr(); | |
| 2140 IFX_Locale* pLocale = GetLocal(); | |
| 2141 CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); | |
| 2142 bValidate = | |
| 2143 widgetValue.ValidateValue(wsValue, wsPicture, pLocale, &wsPicture); | |
| 2144 if (bValidate) { | |
| 2145 widgetValue = CXFA_LocaleValue(widgetValue.GetType(), wsNewText, | |
| 2146 wsPicture, pLocale, pLocalMgr); | |
| 2147 wsNewText = widgetValue.GetValue(); | |
| 2148 if (uiType == XFA_ELEMENT_NumericEdit) { | |
| 2149 int32_t iLeadDigits = 0; | |
| 2150 int32_t iFracDigits = 0; | |
| 2151 GetLeadDigits(iLeadDigits); | |
| 2152 GetFracDigits(iFracDigits); | |
| 2153 wsNewText = XFA_NumericLimit(wsNewText, iLeadDigits, iFracDigits); | |
| 2154 } | |
| 2155 bSyncData = TRUE; | |
| 2156 } | |
| 2157 } else { | |
| 2158 if (uiType == XFA_ELEMENT_NumericEdit) { | |
| 2159 if (wsNewText != FX_WSTRC(L"0")) { | |
| 2160 int32_t iLeadDigits = 0; | |
| 2161 int32_t iFracDigits = 0; | |
| 2162 GetLeadDigits(iLeadDigits); | |
| 2163 GetFracDigits(iFracDigits); | |
| 2164 wsNewText = XFA_NumericLimit(wsNewText, iLeadDigits, iFracDigits); | |
| 2165 } | |
| 2166 bSyncData = TRUE; | |
| 2167 } | |
| 2168 } | |
| 2169 if (uiType != XFA_ELEMENT_NumericEdit || bSyncData) { | |
| 2170 SyncValue(wsNewText, TRUE); | |
| 2171 } | |
| 2172 return bValidate; | |
| 2173 } | |
| 2174 FX_BOOL CXFA_WidgetData::GetPictureContent(CFX_WideString& wsPicture, | |
| 2175 XFA_VALUEPICTURE ePicture) { | |
| 2176 if (ePicture == XFA_VALUEPICTURE_Raw) { | |
| 2177 return FALSE; | |
| 2178 } | |
| 2179 CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); | |
| 2180 switch (ePicture) { | |
| 2181 case XFA_VALUEPICTURE_Display: { | |
| 2182 if (CXFA_Node* pFormat = m_pNode->GetChild(0, XFA_ELEMENT_Format)) { | |
| 2183 if (CXFA_Node* pPicture = pFormat->GetChild(0, XFA_ELEMENT_Picture)) { | |
| 2184 if (pPicture->TryContent(wsPicture)) { | |
| 2185 return TRUE; | |
| 2186 } | |
| 2187 } | |
| 2188 } | |
| 2189 CFX_WideString wsDataPicture, wsTimePicture; | |
| 2190 IFX_Locale* pLocale = GetLocal(); | |
| 2191 if (!pLocale) { | |
| 2192 return FALSE; | |
| 2193 } | |
| 2194 uint32_t dwType = widgetValue.GetType(); | |
| 2195 switch (dwType) { | |
| 2196 case XFA_VT_DATE: | |
| 2197 pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium, | |
| 2198 wsPicture); | |
| 2199 break; | |
| 2200 case XFA_VT_TIME: | |
| 2201 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium, | |
| 2202 wsPicture); | |
| 2203 break; | |
| 2204 case XFA_VT_DATETIME: | |
| 2205 pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium, | |
| 2206 wsDataPicture); | |
| 2207 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Medium, | |
| 2208 wsTimePicture); | |
| 2209 wsPicture = wsDataPicture + FX_WSTRC(L"T") + wsTimePicture; | |
| 2210 break; | |
| 2211 case XFA_VT_DECIMAL: | |
| 2212 case XFA_VT_FLOAT: | |
| 2213 break; | |
| 2214 default: | |
| 2215 break; | |
| 2216 } | |
| 2217 } | |
| 2218 return TRUE; | |
| 2219 case XFA_VALUEPICTURE_Edit: { | |
| 2220 CXFA_Node* pUI = m_pNode->GetChild(0, XFA_ELEMENT_Ui); | |
| 2221 if (pUI) { | |
| 2222 if (CXFA_Node* pPicture = pUI->GetChild(0, XFA_ELEMENT_Picture)) { | |
| 2223 if (pPicture->TryContent(wsPicture)) { | |
| 2224 return TRUE; | |
| 2225 } | |
| 2226 } | |
| 2227 } | |
| 2228 { | |
| 2229 CFX_WideString wsDataPicture, wsTimePicture; | |
| 2230 IFX_Locale* pLocale = GetLocal(); | |
| 2231 if (!pLocale) { | |
| 2232 return FALSE; | |
| 2233 } | |
| 2234 uint32_t dwType = widgetValue.GetType(); | |
| 2235 switch (dwType) { | |
| 2236 case XFA_VT_DATE: | |
| 2237 pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Short, | |
| 2238 wsPicture); | |
| 2239 break; | |
| 2240 case XFA_VT_TIME: | |
| 2241 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Short, | |
| 2242 wsPicture); | |
| 2243 break; | |
| 2244 case XFA_VT_DATETIME: | |
| 2245 pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Short, | |
| 2246 wsDataPicture); | |
| 2247 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Short, | |
| 2248 wsTimePicture); | |
| 2249 wsPicture = wsDataPicture + L"T" + wsTimePicture; | |
| 2250 break; | |
| 2251 default: | |
| 2252 break; | |
| 2253 } | |
| 2254 } | |
| 2255 } | |
| 2256 return TRUE; | |
| 2257 case XFA_VALUEPICTURE_DataBind: { | |
| 2258 if (CXFA_Bind bind = GetBind()) { | |
| 2259 bind.GetPicture(wsPicture); | |
| 2260 return TRUE; | |
| 2261 } | |
| 2262 } break; | |
| 2263 default: | |
| 2264 break; | |
| 2265 } | |
| 2266 return FALSE; | |
| 2267 } | |
| 2268 IFX_Locale* CXFA_WidgetData::GetLocal() { | |
| 2269 IFX_Locale* pLocale = NULL; | |
| 2270 if (!m_pNode) { | |
| 2271 return pLocale; | |
| 2272 } | |
| 2273 FX_BOOL bLocale = FALSE; | |
| 2274 CFX_WideString wsLocaleName; | |
| 2275 bLocale = m_pNode->GetLocaleName(wsLocaleName); | |
| 2276 if (bLocale) { | |
| 2277 if (wsLocaleName == FX_WSTRC(L"ambient")) { | |
| 2278 pLocale = m_pNode->GetDocument()->GetLocalMgr()->GetDefLocale(); | |
| 2279 } else { | |
| 2280 pLocale = m_pNode->GetDocument()->GetLocalMgr()->GetLocaleByName( | |
| 2281 wsLocaleName.AsWideStringC()); | |
| 2282 } | |
| 2283 } | |
| 2284 return pLocale; | |
| 2285 } | |
| 2286 static FX_BOOL XFA_SplitDateTime(const CFX_WideString& wsDateTime, | |
| 2287 CFX_WideString& wsDate, | |
| 2288 CFX_WideString& wsTime) { | |
| 2289 wsDate = L""; | |
| 2290 wsTime = L""; | |
| 2291 if (wsDateTime.IsEmpty()) { | |
| 2292 return FALSE; | |
| 2293 } | |
| 2294 int nSplitIndex = -1; | |
| 2295 nSplitIndex = wsDateTime.Find('T'); | |
| 2296 if (nSplitIndex < 0) { | |
| 2297 nSplitIndex = wsDateTime.Find(' '); | |
| 2298 } | |
| 2299 if (nSplitIndex < 0) { | |
| 2300 return FALSE; | |
| 2301 } | |
| 2302 wsDate = wsDateTime.Left(nSplitIndex); | |
| 2303 if (!wsDate.IsEmpty()) { | |
| 2304 int32_t iCount = wsDate.GetLength(); | |
| 2305 int32_t i = 0; | |
| 2306 for (i = 0; i < iCount; i++) { | |
| 2307 if (wsDate[i] >= '0' && wsDate[i] <= '9') { | |
| 2308 break; | |
| 2309 } | |
| 2310 } | |
| 2311 if (i == iCount) { | |
| 2312 return FALSE; | |
| 2313 } | |
| 2314 } | |
| 2315 wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1); | |
| 2316 if (!wsTime.IsEmpty()) { | |
| 2317 int32_t iCount = wsTime.GetLength(); | |
| 2318 int32_t i = 0; | |
| 2319 for (i = 0; i < iCount; i++) { | |
| 2320 if (wsTime[i] >= '0' && wsTime[i] <= '9') { | |
| 2321 break; | |
| 2322 } | |
| 2323 } | |
| 2324 if (i == iCount) { | |
| 2325 return FALSE; | |
| 2326 } | |
| 2327 } | |
| 2328 return TRUE; | |
| 2329 } | |
| 2330 | |
| 2331 FX_BOOL CXFA_WidgetData::GetValue(CFX_WideString& wsValue, | |
| 2332 XFA_VALUEPICTURE eValueType) { | |
| 2333 wsValue = m_pNode->GetContent(); | |
| 2334 | |
| 2335 if (eValueType == XFA_VALUEPICTURE_Display) | |
| 2336 GetItemLabel(wsValue.AsWideStringC(), wsValue); | |
| 2337 | |
| 2338 CFX_WideString wsPicture; | |
| 2339 GetPictureContent(wsPicture, eValueType); | |
| 2340 CXFA_Node* pNode = GetUIChild(); | |
| 2341 if (!pNode) | |
| 2342 return TRUE; | |
| 2343 | |
| 2344 XFA_ELEMENT uiType = GetUIChild()->GetClassID(); | |
| 2345 switch (uiType) { | |
| 2346 case XFA_ELEMENT_ChoiceList: { | |
| 2347 if (eValueType == XFA_VALUEPICTURE_Display) { | |
| 2348 int32_t iSelItemIndex = GetSelectedItem(0); | |
| 2349 if (iSelItemIndex >= 0) { | |
| 2350 GetChoiceListItem(wsValue, iSelItemIndex); | |
| 2351 wsPicture.Empty(); | |
| 2352 } | |
| 2353 } | |
| 2354 } break; | |
| 2355 case XFA_ELEMENT_NumericEdit: | |
| 2356 if (eValueType != XFA_VALUEPICTURE_Raw && wsPicture.IsEmpty()) { | |
| 2357 IFX_Locale* pLocale = GetLocal(); | |
| 2358 if (eValueType == XFA_VALUEPICTURE_Display && pLocale) { | |
| 2359 CFX_WideString wsOutput; | |
| 2360 NormalizeNumStr(wsValue, wsOutput); | |
| 2361 FormatNumStr(wsOutput, pLocale, wsOutput); | |
| 2362 wsValue = wsOutput; | |
| 2363 } | |
| 2364 } | |
| 2365 break; | |
| 2366 default: | |
| 2367 break; | |
| 2368 } | |
| 2369 if (wsPicture.IsEmpty()) | |
| 2370 return TRUE; | |
| 2371 | |
| 2372 if (IFX_Locale* pLocale = GetLocal()) { | |
| 2373 CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); | |
| 2374 CXFA_LocaleMgr* pLocalMgr = m_pNode->GetDocument()->GetLocalMgr(); | |
| 2375 switch (widgetValue.GetType()) { | |
| 2376 case XFA_VT_DATE: { | |
| 2377 CFX_WideString wsDate, wsTime; | |
| 2378 if (XFA_SplitDateTime(wsValue, wsDate, wsTime)) { | |
| 2379 CXFA_LocaleValue date(XFA_VT_DATE, wsDate, pLocalMgr); | |
| 2380 if (date.FormatPatterns(wsValue, wsPicture, pLocale, eValueType)) | |
| 2381 return TRUE; | |
| 2382 } | |
| 2383 break; | |
| 2384 } | |
| 2385 case XFA_VT_TIME: { | |
| 2386 CFX_WideString wsDate, wsTime; | |
| 2387 if (XFA_SplitDateTime(wsValue, wsDate, wsTime)) { | |
| 2388 CXFA_LocaleValue time(XFA_VT_TIME, wsTime, pLocalMgr); | |
| 2389 if (time.FormatPatterns(wsValue, wsPicture, pLocale, eValueType)) | |
| 2390 return TRUE; | |
| 2391 } | |
| 2392 break; | |
| 2393 } | |
| 2394 default: | |
| 2395 break; | |
| 2396 } | |
| 2397 widgetValue.FormatPatterns(wsValue, wsPicture, pLocale, eValueType); | |
| 2398 } | |
| 2399 return TRUE; | |
| 2400 } | |
| 2401 | |
| 2402 FX_BOOL CXFA_WidgetData::GetNormalizeDataValue( | |
| 2403 const CFX_WideStringC& wsValue, | |
| 2404 CFX_WideString& wsNormalizeValue) { | |
| 2405 wsNormalizeValue = wsValue; | |
| 2406 if (wsValue.IsEmpty()) { | |
| 2407 return TRUE; | |
| 2408 } | |
| 2409 CFX_WideString wsPicture; | |
| 2410 GetPictureContent(wsPicture, XFA_VALUEPICTURE_DataBind); | |
| 2411 if (wsPicture.IsEmpty()) { | |
| 2412 return TRUE; | |
| 2413 } | |
| 2414 FXSYS_assert(GetNode()); | |
| 2415 CXFA_LocaleMgr* pLocalMgr = GetNode()->GetDocument()->GetLocalMgr(); | |
| 2416 IFX_Locale* pLocale = GetLocal(); | |
| 2417 CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(this); | |
| 2418 if (widgetValue.ValidateValue(wsValue, wsPicture, pLocale, &wsPicture)) { | |
| 2419 widgetValue = CXFA_LocaleValue(widgetValue.GetType(), wsNormalizeValue, | |
| 2420 wsPicture, pLocale, pLocalMgr); | |
| 2421 wsNormalizeValue = widgetValue.GetValue(); | |
| 2422 return TRUE; | |
| 2423 } | |
| 2424 return FALSE; | |
| 2425 } | |
| 2426 FX_BOOL CXFA_WidgetData::GetFormatDataValue(const CFX_WideStringC& wsValue, | |
| 2427 CFX_WideString& wsFormatedValue) { | |
| 2428 wsFormatedValue = wsValue; | |
| 2429 if (wsValue.IsEmpty()) { | |
| 2430 return TRUE; | |
| 2431 } | |
| 2432 CFX_WideString wsPicture; | |
| 2433 GetPictureContent(wsPicture, XFA_VALUEPICTURE_DataBind); | |
| 2434 if (wsPicture.IsEmpty()) { | |
| 2435 return TRUE; | |
| 2436 } | |
| 2437 if (IFX_Locale* pLocale = GetLocal()) { | |
| 2438 FXSYS_assert(GetNode()); | |
| 2439 CXFA_Node* pNodeValue = GetNode()->GetChild(0, XFA_ELEMENT_Value); | |
| 2440 if (!pNodeValue) { | |
| 2441 return FALSE; | |
| 2442 } | |
| 2443 CXFA_Node* pValueChild = pNodeValue->GetNodeItem(XFA_NODEITEM_FirstChild); | |
| 2444 if (!pValueChild) { | |
| 2445 return FALSE; | |
| 2446 } | |
| 2447 int32_t iVTType = XFA_VT_NULL; | |
| 2448 XFA_ELEMENT eType = pValueChild->GetClassID(); | |
| 2449 switch (eType) { | |
| 2450 case XFA_ELEMENT_Decimal: | |
| 2451 iVTType = XFA_VT_DECIMAL; | |
| 2452 break; | |
| 2453 case XFA_ELEMENT_Float: | |
| 2454 iVTType = XFA_VT_FLOAT; | |
| 2455 break; | |
| 2456 case XFA_ELEMENT_Date: | |
| 2457 iVTType = XFA_VT_DATE; | |
| 2458 break; | |
| 2459 case XFA_ELEMENT_Time: | |
| 2460 iVTType = XFA_VT_TIME; | |
| 2461 break; | |
| 2462 case XFA_ELEMENT_DateTime: | |
| 2463 iVTType = XFA_VT_DATETIME; | |
| 2464 break; | |
| 2465 case XFA_ELEMENT_Boolean: | |
| 2466 iVTType = XFA_VT_BOOLEAN; | |
| 2467 break; | |
| 2468 case XFA_ELEMENT_Integer: | |
| 2469 iVTType = XFA_VT_INTEGER; | |
| 2470 break; | |
| 2471 case XFA_ELEMENT_Text: | |
| 2472 iVTType = XFA_VT_TEXT; | |
| 2473 break; | |
| 2474 default: | |
| 2475 iVTType = XFA_VT_NULL; | |
| 2476 break; | |
| 2477 } | |
| 2478 CXFA_LocaleMgr* pLocalMgr = GetNode()->GetDocument()->GetLocalMgr(); | |
| 2479 CXFA_LocaleValue widgetValue(iVTType, wsValue, pLocalMgr); | |
| 2480 switch (widgetValue.GetType()) { | |
| 2481 case XFA_VT_DATE: { | |
| 2482 CFX_WideString wsDate, wsTime; | |
| 2483 if (XFA_SplitDateTime(wsValue, wsDate, wsTime)) { | |
| 2484 CXFA_LocaleValue date(XFA_VT_DATE, wsDate, pLocalMgr); | |
| 2485 if (date.FormatPatterns(wsFormatedValue, wsPicture, pLocale, | |
| 2486 XFA_VALUEPICTURE_DataBind)) { | |
| 2487 return TRUE; | |
| 2488 } | |
| 2489 } | |
| 2490 break; | |
| 2491 } | |
| 2492 case XFA_VT_TIME: { | |
| 2493 CFX_WideString wsDate, wsTime; | |
| 2494 if (XFA_SplitDateTime(wsValue, wsDate, wsTime)) { | |
| 2495 CXFA_LocaleValue time(XFA_VT_TIME, wsTime, pLocalMgr); | |
| 2496 if (time.FormatPatterns(wsFormatedValue, wsPicture, pLocale, | |
| 2497 XFA_VALUEPICTURE_DataBind)) { | |
| 2498 return TRUE; | |
| 2499 } | |
| 2500 } | |
| 2501 break; | |
| 2502 } | |
| 2503 default: | |
| 2504 break; | |
| 2505 } | |
| 2506 widgetValue.FormatPatterns(wsFormatedValue, wsPicture, pLocale, | |
| 2507 XFA_VALUEPICTURE_DataBind); | |
| 2508 } | |
| 2509 return FALSE; | |
| 2510 } | |
| 2511 void CXFA_WidgetData::NormalizeNumStr(const CFX_WideString& wsValue, | |
| 2512 CFX_WideString& wsOutput) { | |
| 2513 if (wsValue.IsEmpty()) { | |
| 2514 return; | |
| 2515 } | |
| 2516 wsOutput = wsValue; | |
| 2517 wsOutput.TrimLeft('0'); | |
| 2518 int32_t dot_index = wsOutput.Find('.'); | |
| 2519 int32_t iFracDigits = 0; | |
| 2520 if (!wsOutput.IsEmpty() && dot_index >= 0 && | |
| 2521 (!GetFracDigits(iFracDigits) || iFracDigits != -1)) { | |
| 2522 wsOutput.TrimRight(L"0"); | |
| 2523 wsOutput.TrimRight(L"."); | |
| 2524 } | |
| 2525 if (wsOutput.IsEmpty() || wsOutput[0] == '.') { | |
| 2526 wsOutput.Insert(0, '0'); | |
| 2527 } | |
| 2528 } | |
| 2529 void CXFA_WidgetData::FormatNumStr(const CFX_WideString& wsValue, | |
| 2530 IFX_Locale* pLocale, | |
| 2531 CFX_WideString& wsOutput) { | |
| 2532 if (wsValue.IsEmpty()) { | |
| 2533 return; | |
| 2534 } | |
| 2535 CFX_WideString wsSrcNum = wsValue; | |
| 2536 CFX_WideString wsGroupSymbol; | |
| 2537 pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Grouping, wsGroupSymbol); | |
| 2538 FX_BOOL bNeg = FALSE; | |
| 2539 if (wsSrcNum[0] == '-') { | |
| 2540 bNeg = TRUE; | |
| 2541 wsSrcNum.Delete(0, 1); | |
| 2542 } | |
| 2543 int32_t len = wsSrcNum.GetLength(); | |
| 2544 int32_t dot_index = wsSrcNum.Find('.'); | |
| 2545 if (dot_index == -1) { | |
| 2546 dot_index = len; | |
| 2547 } | |
| 2548 int32_t cc = dot_index - 1; | |
| 2549 if (cc >= 0) { | |
| 2550 int nPos = dot_index % 3; | |
| 2551 wsOutput.Empty(); | |
| 2552 for (int32_t i = 0; i < dot_index; i++) { | |
| 2553 if (i % 3 == nPos && i != 0) { | |
| 2554 wsOutput += wsGroupSymbol; | |
| 2555 } | |
| 2556 wsOutput += wsSrcNum[i]; | |
| 2557 } | |
| 2558 if (dot_index < len) { | |
| 2559 CFX_WideString wsSymbol; | |
| 2560 pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal, wsSymbol); | |
| 2561 wsOutput += wsSymbol; | |
| 2562 wsOutput += wsSrcNum.Right(len - dot_index - 1); | |
| 2563 } | |
| 2564 if (bNeg) { | |
| 2565 CFX_WideString wsMinusymbol; | |
| 2566 pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus, wsMinusymbol); | |
| 2567 wsOutput = wsMinusymbol + wsOutput; | |
| 2568 } | |
| 2569 } | |
| 2570 } | |
| 2571 void CXFA_WidgetData::SyncValue(const CFX_WideString& wsValue, | |
| 2572 FX_BOOL bNotify) { | |
| 2573 if (!m_pNode) { | |
| 2574 return; | |
| 2575 } | |
| 2576 CFX_WideString wsFormatValue(wsValue); | |
| 2577 CXFA_WidgetData* pContainerWidgetData = m_pNode->GetContainerWidgetData(); | |
| 2578 if (pContainerWidgetData) { | |
| 2579 pContainerWidgetData->GetFormatDataValue(wsValue.AsWideStringC(), | |
| 2580 wsFormatValue); | |
| 2581 } | |
| 2582 m_pNode->SetContent(wsValue, wsFormatValue, bNotify); | |
| 2583 } | |
| 2584 void CXFA_WidgetData::InsertListTextItem(CXFA_Node* pItems, | |
| 2585 const CFX_WideStringC& wsText, | |
| 2586 int32_t nIndex) { | |
| 2587 CXFA_Node* pText = pItems->CreateSamePacketNode(XFA_ELEMENT_Text); | |
| 2588 pItems->InsertChild(nIndex, pText); | |
| 2589 pText->SetContent(wsText, wsText, FALSE, FALSE, FALSE); | |
| 2590 } | |
| 2591 CXFA_Occur::CXFA_Occur(CXFA_Node* pNode) : CXFA_Data(pNode) {} | |
| 2592 int32_t CXFA_Occur::GetMax() { | |
| 2593 int32_t iMax = 1; | |
| 2594 if (m_pNode) { | |
| 2595 if (!m_pNode->TryInteger(XFA_ATTRIBUTE_Max, iMax, TRUE)) { | |
| 2596 iMax = GetMin(); | |
| 2597 } | |
| 2598 } | |
| 2599 return iMax; | |
| 2600 } | |
| 2601 int32_t CXFA_Occur::GetMin() { | |
| 2602 int32_t iMin = 1; | |
| 2603 if (m_pNode) { | |
| 2604 if (!m_pNode->TryInteger(XFA_ATTRIBUTE_Min, iMin, TRUE) || iMin < 0) { | |
| 2605 iMin = 1; | |
| 2606 } | |
| 2607 } | |
| 2608 return iMin; | |
| 2609 } | |
| 2610 FX_BOOL CXFA_Occur::GetOccurInfo(int32_t& iMin, int32_t& iMax, int32_t& iInit) { | |
| 2611 if (!m_pNode) { | |
| 2612 return FALSE; | |
| 2613 } | |
| 2614 if (!m_pNode->TryInteger(XFA_ATTRIBUTE_Min, iMin, FALSE) || iMin < 0) { | |
| 2615 iMin = 1; | |
| 2616 } | |
| 2617 if (!m_pNode->TryInteger(XFA_ATTRIBUTE_Max, iMax, FALSE)) { | |
| 2618 if (iMin == 0) { | |
| 2619 iMax = 1; | |
| 2620 } else { | |
| 2621 iMax = iMin; | |
| 2622 } | |
| 2623 } | |
| 2624 if (!m_pNode->TryInteger(XFA_ATTRIBUTE_Initial, iInit, FALSE) || | |
| 2625 iInit < iMin) { | |
| 2626 iInit = iMin; | |
| 2627 } | |
| 2628 return TRUE; | |
| 2629 } | |
| 2630 void CXFA_Occur::SetMax(int32_t iMax) { | |
| 2631 iMax = (iMax != -1 && iMax < 1) ? 1 : iMax; | |
| 2632 m_pNode->SetInteger(XFA_ATTRIBUTE_Max, iMax, FALSE); | |
| 2633 int32_t iMin = GetMin(); | |
| 2634 if (iMax != -1 && iMax < iMin) { | |
| 2635 iMin = iMax; | |
| 2636 m_pNode->SetInteger(XFA_ATTRIBUTE_Min, iMin, FALSE); | |
| 2637 } | |
| 2638 } | |
| 2639 void CXFA_Occur::SetMin(int32_t iMin) { | |
| 2640 iMin = (iMin < 0) ? 1 : iMin; | |
| 2641 m_pNode->SetInteger(XFA_ATTRIBUTE_Min, iMin, FALSE); | |
| 2642 int32_t iMax = GetMax(); | |
| 2643 if (iMax > 0 && iMax < iMin) { | |
| 2644 iMax = iMin; | |
| 2645 m_pNode->SetInteger(XFA_ATTRIBUTE_Max, iMax, FALSE); | |
| 2646 } | |
| 2647 } | |
| 2648 XFA_ATTRIBUTEENUM XFA_GetEnumTypeAttribute( | |
| 2649 CXFA_Node* pNode, | |
| 2650 XFA_ATTRIBUTE attributeValue = XFA_ATTRIBUTE_Type, | |
| 2651 XFA_ATTRIBUTEENUM eDefaultValue = XFA_ATTRIBUTEENUM_Optional) { | |
| 2652 XFA_ATTRIBUTEENUM eType = eDefaultValue; | |
| 2653 if (pNode) { | |
| 2654 if (!pNode->TryEnum(attributeValue, eType, TRUE)) { | |
| 2655 eType = eDefaultValue; | |
| 2656 } | |
| 2657 } | |
| 2658 return eType; | |
| 2659 } | |
| OLD | NEW |