Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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 "xfa/fxfa/app/xfa_ffwidgetacc.h" |
| 8 | |
| 9 | #include <algorithm> |
tsepez | f74ad99 | 2016-05-11 10:26:05 -0700 | [diff] [blame] | 10 | #include <memory> |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 11 | |
| 12 | #include "xfa/fde/tto/fde_textout.h" |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 13 | #include "xfa/fde/xml/fde_xml_imp.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 14 | #include "xfa/fxfa/app/xfa_ffcheckbutton.h" |
| 15 | #include "xfa/fxfa/app/xfa_ffchoicelist.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 16 | #include "xfa/fxfa/app/xfa_fffield.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 17 | #include "xfa/fxfa/app/xfa_fwladapter.h" |
| 18 | #include "xfa/fxfa/app/xfa_textlayout.h" |
dsinclair | 7222ea6 | 2016-04-06 14:33:07 -0700 | [diff] [blame] | 19 | #include "xfa/fxfa/include/xfa_ffapp.h" |
| 20 | #include "xfa/fxfa/include/xfa_ffdoc.h" |
| 21 | #include "xfa/fxfa/include/xfa_ffdocview.h" |
| 22 | #include "xfa/fxfa/include/xfa_ffpageview.h" |
| 23 | #include "xfa/fxfa/include/xfa_ffwidget.h" |
| 24 | #include "xfa/fxfa/include/xfa_fontmgr.h" |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 25 | #include "xfa/fxfa/parser/xfa_document_layout_imp.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 26 | #include "xfa/fxfa/parser/xfa_localevalue.h" |
| 27 | #include "xfa/fxfa/parser/xfa_script.h" |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 28 | #include "xfa/fxfa/parser/xfa_script_imp.h" |
dsinclair | 86fad99 | 2016-05-31 11:34:04 -0700 | [diff] [blame] | 29 | #include "xfa/fxjse/value.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 30 | |
| 31 | static void XFA_FFDeleteCalcData(void* pData) { |
| 32 | if (pData) { |
| 33 | delete ((CXFA_CalcData*)pData); |
| 34 | } |
| 35 | } |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 36 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 37 | static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADeleteCalcData = { |
| 38 | XFA_FFDeleteCalcData, NULL}; |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 39 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 40 | class CXFA_WidgetLayoutData { |
| 41 | public: |
| 42 | CXFA_WidgetLayoutData() : m_fWidgetHeight(-1) {} |
| 43 | virtual ~CXFA_WidgetLayoutData() {} |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 44 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 45 | FX_FLOAT m_fWidgetHeight; |
| 46 | }; |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 47 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 48 | class CXFA_TextLayoutData : public CXFA_WidgetLayoutData { |
| 49 | public: |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 50 | CXFA_TextLayoutData() {} |
| 51 | ~CXFA_TextLayoutData() override {} |
| 52 | |
| 53 | CXFA_TextLayout* GetTextLayout() const { return m_pTextLayout.get(); } |
| 54 | CXFA_TextProvider* GetTextProvider() const { return m_pTextProvider.get(); } |
| 55 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 56 | void LoadText(CXFA_WidgetAcc* pAcc) { |
| 57 | if (m_pTextLayout) |
| 58 | return; |
| 59 | |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 60 | m_pTextProvider.reset( |
| 61 | new CXFA_TextProvider(pAcc, XFA_TEXTPROVIDERTYPE_Text)); |
| 62 | m_pTextLayout.reset(new CXFA_TextLayout(m_pTextProvider.get())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 63 | } |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 64 | |
| 65 | private: |
| 66 | std::unique_ptr<CXFA_TextLayout> m_pTextLayout; |
| 67 | std::unique_ptr<CXFA_TextProvider> m_pTextProvider; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 68 | }; |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 69 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 70 | class CXFA_ImageLayoutData : public CXFA_WidgetLayoutData { |
| 71 | public: |
| 72 | CXFA_ImageLayoutData() |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 73 | : m_pDIBitmap(nullptr), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 74 | m_bNamedImage(FALSE), |
| 75 | m_iImageXDpi(0), |
| 76 | m_iImageYDpi(0) {} |
| 77 | |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 78 | ~CXFA_ImageLayoutData() override { |
| 79 | if (m_pDIBitmap && !m_bNamedImage) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 80 | delete m_pDIBitmap; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | FX_BOOL LoadImageData(CXFA_WidgetAcc* pAcc) { |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 84 | if (m_pDIBitmap) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 85 | return TRUE; |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 86 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 87 | CXFA_Value value = pAcc->GetFormValue(); |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 88 | if (!value) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 89 | return FALSE; |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 90 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 91 | CXFA_Image imageObj = value.GetImage(); |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 92 | if (!imageObj) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 93 | return FALSE; |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 94 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 95 | CXFA_FFDoc* pFFDoc = pAcc->GetDoc(); |
| 96 | pAcc->SetImageImage(XFA_LoadImageData(pFFDoc, &imageObj, m_bNamedImage, |
| 97 | m_iImageXDpi, m_iImageYDpi)); |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 98 | return !!m_pDIBitmap; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | CFX_DIBitmap* m_pDIBitmap; |
| 102 | FX_BOOL m_bNamedImage; |
| 103 | int32_t m_iImageXDpi; |
| 104 | int32_t m_iImageYDpi; |
| 105 | }; |
tsepez | f74ad99 | 2016-05-11 10:26:05 -0700 | [diff] [blame] | 106 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 107 | class CXFA_FieldLayoutData : public CXFA_WidgetLayoutData { |
| 108 | public: |
tsepez | f74ad99 | 2016-05-11 10:26:05 -0700 | [diff] [blame] | 109 | CXFA_FieldLayoutData() {} |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 110 | ~CXFA_FieldLayoutData() override {} |
tsepez | f74ad99 | 2016-05-11 10:26:05 -0700 | [diff] [blame] | 111 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 112 | FX_BOOL LoadCaption(CXFA_WidgetAcc* pAcc) { |
tsepez | f74ad99 | 2016-05-11 10:26:05 -0700 | [diff] [blame] | 113 | if (m_pCapTextLayout) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 114 | return TRUE; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 115 | CXFA_Caption caption = pAcc->GetCaption(); |
tsepez | f74ad99 | 2016-05-11 10:26:05 -0700 | [diff] [blame] | 116 | if (!caption || caption.GetPresence() == XFA_ATTRIBUTEENUM_Hidden) |
| 117 | return FALSE; |
| 118 | m_pCapTextProvider.reset( |
| 119 | new CXFA_TextProvider(pAcc, XFA_TEXTPROVIDERTYPE_Caption)); |
| 120 | m_pCapTextLayout.reset(new CXFA_TextLayout(m_pCapTextProvider.get())); |
| 121 | return TRUE; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 122 | } |
tsepez | f74ad99 | 2016-05-11 10:26:05 -0700 | [diff] [blame] | 123 | |
| 124 | std::unique_ptr<CXFA_TextLayout> m_pCapTextLayout; |
| 125 | std::unique_ptr<CXFA_TextProvider> m_pCapTextProvider; |
| 126 | std::unique_ptr<CFDE_TextOut> m_pTextOut; |
| 127 | std::unique_ptr<CFX_FloatArray> m_pFieldSplitArray; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 128 | }; |
tsepez | f74ad99 | 2016-05-11 10:26:05 -0700 | [diff] [blame] | 129 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 130 | class CXFA_TextEditData : public CXFA_FieldLayoutData { |
| 131 | public: |
| 132 | }; |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 133 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 134 | class CXFA_ImageEditData : public CXFA_FieldLayoutData { |
| 135 | public: |
| 136 | CXFA_ImageEditData() |
| 137 | : m_pDIBitmap(NULL), |
| 138 | m_bNamedImage(FALSE), |
| 139 | m_iImageXDpi(0), |
| 140 | m_iImageYDpi(0) {} |
| 141 | |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 142 | ~CXFA_ImageEditData() override { |
| 143 | if (m_pDIBitmap && !m_bNamedImage) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 144 | delete m_pDIBitmap; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 145 | } |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 146 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 147 | FX_BOOL LoadImageData(CXFA_WidgetAcc* pAcc) { |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 148 | if (m_pDIBitmap) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 149 | return TRUE; |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 150 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 151 | CXFA_Value value = pAcc->GetFormValue(); |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 152 | if (!value) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 153 | return FALSE; |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 154 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 155 | CXFA_Image imageObj = value.GetImage(); |
| 156 | CXFA_FFDoc* pFFDoc = pAcc->GetDoc(); |
| 157 | pAcc->SetImageEditImage(XFA_LoadImageData(pFFDoc, &imageObj, m_bNamedImage, |
| 158 | m_iImageXDpi, m_iImageYDpi)); |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 159 | return !!m_pDIBitmap; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 160 | } |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 161 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 162 | CFX_DIBitmap* m_pDIBitmap; |
| 163 | FX_BOOL m_bNamedImage; |
| 164 | int32_t m_iImageXDpi; |
| 165 | int32_t m_iImageYDpi; |
| 166 | }; |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 167 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 168 | CXFA_WidgetAcc::CXFA_WidgetAcc(CXFA_FFDocView* pDocView, CXFA_Node* pNode) |
| 169 | : CXFA_WidgetData(pNode), |
| 170 | m_pDocView(pDocView), |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 171 | m_nRecursionDepth(0) {} |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 172 | |
| 173 | CXFA_WidgetAcc::~CXFA_WidgetAcc() {} |
| 174 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 175 | FX_BOOL CXFA_WidgetAcc::GetName(CFX_WideString& wsName, int32_t iNameType) { |
| 176 | if (iNameType == 0) { |
| 177 | m_pNode->TryCData(XFA_ATTRIBUTE_Name, wsName); |
| 178 | return !wsName.IsEmpty(); |
| 179 | } |
| 180 | m_pNode->GetSOMExpression(wsName); |
| 181 | if (iNameType == 2 && wsName.GetLength() >= 15) { |
| 182 | CFX_WideStringC wsPre = FX_WSTRC(L"xfa[0].form[0]."); |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 183 | if (wsPre == CFX_WideStringC(wsName.c_str(), wsPre.GetLength())) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 184 | wsName.Delete(0, wsPre.GetLength()); |
| 185 | } |
| 186 | } |
| 187 | return TRUE; |
| 188 | } |
| 189 | CXFA_Node* CXFA_WidgetAcc::GetDatasets() { |
| 190 | return m_pNode->GetBindData(); |
| 191 | } |
| 192 | FX_BOOL CXFA_WidgetAcc::ProcessValueChanged() { |
| 193 | m_pDocView->AddValidateWidget(this); |
| 194 | m_pDocView->AddCalculateWidgetAcc(this); |
| 195 | m_pDocView->RunCalculateWidgets(); |
| 196 | m_pDocView->RunValidate(); |
| 197 | return TRUE; |
| 198 | } |
| 199 | void CXFA_WidgetAcc::ResetData() { |
| 200 | CFX_WideString wsValue; |
| 201 | XFA_ELEMENT eUIType = (XFA_ELEMENT)GetUIType(); |
| 202 | switch (eUIType) { |
| 203 | case XFA_ELEMENT_ImageEdit: { |
| 204 | CXFA_Value imageValue = GetDefaultValue(); |
| 205 | CXFA_Image image = imageValue.GetImage(); |
| 206 | CFX_WideString wsContentType, wsHref; |
| 207 | if (image) { |
| 208 | image.GetContent(wsValue); |
| 209 | image.GetContentType(wsContentType); |
| 210 | image.GetHref(wsHref); |
| 211 | } |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 212 | SetImageEdit(wsContentType, wsHref, wsValue); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 213 | } break; |
| 214 | case XFA_ELEMENT_ExclGroup: { |
| 215 | CXFA_Node* pNextChild = m_pNode->GetNodeItem( |
| 216 | XFA_NODEITEM_FirstChild, XFA_OBJECTTYPE_ContainerNode); |
| 217 | while (pNextChild) { |
| 218 | CXFA_Node* pChild = pNextChild; |
| 219 | CXFA_WidgetAcc* pAcc = (CXFA_WidgetAcc*)pChild->GetWidgetData(); |
| 220 | if (!pAcc) { |
| 221 | continue; |
| 222 | } |
| 223 | CXFA_Value defValue(NULL); |
| 224 | if (wsValue.IsEmpty() && (defValue = pAcc->GetDefaultValue())) { |
| 225 | defValue.GetChildValueContent(wsValue); |
| 226 | SetValue(wsValue, XFA_VALUEPICTURE_Raw); |
| 227 | pAcc->SetValue(wsValue, XFA_VALUEPICTURE_Raw); |
| 228 | } else { |
| 229 | CXFA_Node* pItems = pChild->GetChild(0, XFA_ELEMENT_Items); |
| 230 | if (!pItems) { |
| 231 | continue; |
| 232 | } |
| 233 | CFX_WideString itemText; |
| 234 | if (pItems->CountChildren(XFA_ELEMENT_UNKNOWN) > 1) { |
| 235 | itemText = pItems->GetChild(1, XFA_ELEMENT_UNKNOWN)->GetContent(); |
| 236 | } |
| 237 | pAcc->SetValue(itemText, XFA_VALUEPICTURE_Raw); |
| 238 | } |
| 239 | pNextChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling, |
| 240 | XFA_OBJECTTYPE_ContainerNode); |
| 241 | } |
| 242 | } break; |
| 243 | case XFA_ELEMENT_ChoiceList: |
| 244 | ClearAllSelections(); |
| 245 | default: |
| 246 | if (CXFA_Value defValue = GetDefaultValue()) { |
| 247 | defValue.GetChildValueContent(wsValue); |
| 248 | } |
| 249 | SetValue(wsValue, XFA_VALUEPICTURE_Raw); |
| 250 | break; |
| 251 | } |
| 252 | } |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 253 | void CXFA_WidgetAcc::SetImageEdit(const CFX_WideString& wsContentType, |
| 254 | const CFX_WideString& wsHref, |
| 255 | const CFX_WideString& wsData) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 256 | CXFA_Image image = GetFormValue().GetImage(); |
| 257 | if (image) { |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 258 | image.SetContentType(CFX_WideString(wsContentType)); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 259 | image.SetHref(wsHref); |
| 260 | } |
| 261 | CFX_WideString wsFormatValue(wsData); |
| 262 | GetFormatDataValue(wsData, wsFormatValue); |
| 263 | m_pNode->SetContent(wsData, wsFormatValue, TRUE); |
| 264 | CXFA_Node* pBind = GetDatasets(); |
| 265 | if (!pBind) { |
| 266 | image.SetTransferEncoding(XFA_ATTRIBUTEENUM_Base64); |
| 267 | return; |
| 268 | } |
| 269 | pBind->SetCData(XFA_ATTRIBUTE_ContentType, wsContentType); |
| 270 | CXFA_Node* pHrefNode = pBind->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 271 | if (pHrefNode) { |
| 272 | pHrefNode->SetCData(XFA_ATTRIBUTE_Value, wsHref); |
| 273 | } else { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 274 | CFDE_XMLNode* pXMLNode = pBind->GetXMLMappingNode(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 275 | ASSERT(pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element); |
tsepez | afe9430 | 2016-05-13 17:21:31 -0700 | [diff] [blame] | 276 | static_cast<CFDE_XMLElement*>(pXMLNode)->SetString(L"href", wsHref); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
| 280 | CXFA_WidgetAcc* CXFA_WidgetAcc::GetExclGroup() { |
| 281 | CXFA_Node* pExcl = m_pNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 282 | if (!pExcl || pExcl->GetClassID() != XFA_ELEMENT_ExclGroup) { |
| 283 | return NULL; |
| 284 | } |
| 285 | return (CXFA_WidgetAcc*)pExcl->GetWidgetData(); |
| 286 | } |
| 287 | CXFA_FFDocView* CXFA_WidgetAcc::GetDocView() { |
| 288 | return m_pDocView; |
| 289 | } |
| 290 | CXFA_FFDoc* CXFA_WidgetAcc::GetDoc() { |
| 291 | return (CXFA_FFDoc*)m_pDocView->GetDoc(); |
| 292 | } |
| 293 | CXFA_FFApp* CXFA_WidgetAcc::GetApp() { |
| 294 | return GetDoc()->GetApp(); |
| 295 | } |
| 296 | IXFA_AppProvider* CXFA_WidgetAcc::GetAppProvider() { |
| 297 | return GetApp()->GetAppProvider(); |
| 298 | } |
| 299 | int32_t CXFA_WidgetAcc::ProcessEvent(int32_t iActivity, |
| 300 | CXFA_EventParam* pEventParam) { |
| 301 | if (GetClassID() == XFA_ELEMENT_Draw) { |
| 302 | return XFA_EVENTERROR_NotExist; |
| 303 | } |
| 304 | int32_t iRet = XFA_EVENTERROR_NotExist; |
| 305 | CXFA_NodeArray eventArray; |
| 306 | int32_t iCounts = |
| 307 | GetEventByActivity(iActivity, eventArray, pEventParam->m_bIsFormReady); |
| 308 | for (int32_t i = 0; i < iCounts; i++) { |
| 309 | CXFA_Event event(eventArray[i]); |
| 310 | int32_t result = ProcessEvent(event, pEventParam); |
| 311 | if (i == 0) { |
| 312 | iRet = result; |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 313 | } else if (result == XFA_EVENTERROR_Success) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 314 | iRet = result; |
| 315 | } |
| 316 | } |
| 317 | return iRet; |
| 318 | } |
| 319 | int32_t CXFA_WidgetAcc::ProcessEvent(CXFA_Event& event, |
| 320 | CXFA_EventParam* pEventParam) { |
| 321 | if (!event) { |
| 322 | return XFA_EVENTERROR_NotExist; |
| 323 | } |
| 324 | switch (event.GetEventType()) { |
| 325 | case XFA_ELEMENT_Execute: |
| 326 | break; |
| 327 | case XFA_ELEMENT_Script: { |
| 328 | CXFA_Script script = event.GetScript(); |
| 329 | return ExecuteScript(script, pEventParam); |
| 330 | } break; |
| 331 | case XFA_ELEMENT_SignData: |
| 332 | break; |
| 333 | case XFA_ELEMENT_Submit: { |
| 334 | CXFA_Submit submit = event.GetSubmit(); |
| 335 | return GetDoc()->GetDocProvider()->SubmitData(GetDoc(), submit); |
| 336 | } |
| 337 | default: |
| 338 | break; |
| 339 | } |
| 340 | return XFA_EVENTERROR_NotExist; |
| 341 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 342 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 343 | int32_t CXFA_WidgetAcc::ProcessCalculate() { |
| 344 | if (GetClassID() == XFA_ELEMENT_Draw) { |
| 345 | return XFA_EVENTERROR_NotExist; |
| 346 | } |
| 347 | CXFA_Calculate calc = GetCalculate(); |
| 348 | if (!calc) { |
| 349 | return XFA_EVENTERROR_NotExist; |
| 350 | } |
| 351 | if (GetNode()->HasFlag(XFA_NODEFLAG_UserInteractive)) { |
| 352 | return XFA_EVENTERROR_Disabled; |
| 353 | } |
| 354 | CXFA_EventParam EventParam; |
| 355 | EventParam.m_eType = XFA_EVENT_Calculate; |
| 356 | CXFA_Script script = calc.GetScript(); |
| 357 | int32_t iRet = ExecuteScript(script, &EventParam); |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 358 | if (iRet != XFA_EVENTERROR_Success) |
| 359 | return iRet; |
| 360 | |
| 361 | if (GetRawValue() != EventParam.m_wsResult) { |
| 362 | SetValue(EventParam.m_wsResult, XFA_VALUEPICTURE_Raw); |
| 363 | UpdateUIDisplay(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 364 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 365 | return XFA_EVENTERROR_Success; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 366 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 367 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 368 | void CXFA_WidgetAcc::ProcessScriptTestValidate(CXFA_Validate validate, |
| 369 | int32_t iRet, |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 370 | CFXJSE_Value* pRetValue, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 371 | FX_BOOL bVersionFlag) { |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 372 | if (iRet == XFA_EVENTERROR_Success && pRetValue) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame^] | 373 | if (pRetValue->IsBoolean() && !pRetValue->ToBoolean()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 374 | IXFA_AppProvider* pAppProvider = GetAppProvider(); |
| 375 | if (!pAppProvider) { |
| 376 | return; |
| 377 | } |
| 378 | CFX_WideString wsTitle; |
| 379 | pAppProvider->LoadString(XFA_IDS_AppName, wsTitle); |
| 380 | CFX_WideString wsScriptMsg; |
| 381 | validate.GetScriptMessageText(wsScriptMsg); |
| 382 | int32_t eScriptTest = validate.GetScriptTest(); |
| 383 | if (eScriptTest == XFA_ATTRIBUTEENUM_Warning) { |
| 384 | if (GetNode()->HasFlag(XFA_NODEFLAG_UserInteractive)) { |
| 385 | return; |
| 386 | } |
| 387 | if (wsScriptMsg.IsEmpty()) { |
| 388 | GetValidateMessage(pAppProvider, wsScriptMsg, FALSE, bVersionFlag); |
| 389 | } |
| 390 | if (bVersionFlag) { |
tsepez | 3f80c86 | 2016-05-16 12:03:24 -0700 | [diff] [blame] | 391 | pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Warning, |
| 392 | XFA_MB_OK); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 393 | return; |
| 394 | } |
tsepez | 3f80c86 | 2016-05-16 12:03:24 -0700 | [diff] [blame] | 395 | if (pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Warning, |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 396 | XFA_MB_YesNo) == XFA_IDYes) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 397 | GetNode()->SetFlag(XFA_NODEFLAG_UserInteractive, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 398 | } |
| 399 | } else { |
| 400 | if (wsScriptMsg.IsEmpty()) { |
| 401 | GetValidateMessage(pAppProvider, wsScriptMsg, TRUE, bVersionFlag); |
| 402 | } |
tsepez | 3f80c86 | 2016-05-16 12:03:24 -0700 | [diff] [blame] | 403 | pAppProvider->MsgBox(wsScriptMsg, wsTitle, XFA_MBICON_Error, XFA_MB_OK); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | int32_t CXFA_WidgetAcc::ProcessFormatTestValidate(CXFA_Validate validate, |
| 409 | FX_BOOL bVersionFlag) { |
| 410 | CFX_WideString wsRawValue = GetRawValue(); |
| 411 | if (!wsRawValue.IsEmpty()) { |
| 412 | CFX_WideString wsPicture; |
| 413 | validate.GetPicture(wsPicture); |
| 414 | if (wsPicture.IsEmpty()) { |
| 415 | return XFA_EVENTERROR_NotExist; |
| 416 | } |
| 417 | IFX_Locale* pLocale = GetLocal(); |
| 418 | if (!pLocale) { |
| 419 | return XFA_EVENTERROR_NotExist; |
| 420 | } |
| 421 | CXFA_LocaleValue lcValue = XFA_GetLocaleValue(this); |
| 422 | if (!lcValue.ValidateValue(lcValue.GetValue(), wsPicture, pLocale)) { |
| 423 | IXFA_AppProvider* pAppProvider = GetAppProvider(); |
| 424 | if (!pAppProvider) { |
| 425 | return XFA_EVENTERROR_NotExist; |
| 426 | } |
| 427 | CFX_WideString wsFormatMsg; |
| 428 | validate.GetFormatMessageText(wsFormatMsg); |
| 429 | CFX_WideString wsTitle; |
| 430 | pAppProvider->LoadString(XFA_IDS_AppName, wsTitle); |
| 431 | int32_t eFormatTest = validate.GetFormatTest(); |
| 432 | if (eFormatTest == XFA_ATTRIBUTEENUM_Error) { |
| 433 | if (wsFormatMsg.IsEmpty()) { |
| 434 | GetValidateMessage(pAppProvider, wsFormatMsg, TRUE, bVersionFlag); |
| 435 | } |
tsepez | 3f80c86 | 2016-05-16 12:03:24 -0700 | [diff] [blame] | 436 | pAppProvider->MsgBox(wsFormatMsg, wsTitle, XFA_MBICON_Error, XFA_MB_OK); |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 437 | return XFA_EVENTERROR_Success; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 438 | } |
| 439 | if (GetNode()->HasFlag(XFA_NODEFLAG_UserInteractive)) { |
| 440 | return XFA_EVENTERROR_NotExist; |
| 441 | } |
| 442 | if (wsFormatMsg.IsEmpty()) { |
| 443 | GetValidateMessage(pAppProvider, wsFormatMsg, FALSE, bVersionFlag); |
| 444 | } |
| 445 | if (bVersionFlag) { |
tsepez | 3f80c86 | 2016-05-16 12:03:24 -0700 | [diff] [blame] | 446 | pAppProvider->MsgBox(wsFormatMsg, wsTitle, XFA_MBICON_Warning, |
| 447 | XFA_MB_OK); |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 448 | return XFA_EVENTERROR_Success; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 449 | } |
tsepez | 3f80c86 | 2016-05-16 12:03:24 -0700 | [diff] [blame] | 450 | if (pAppProvider->MsgBox(wsFormatMsg, wsTitle, XFA_MBICON_Warning, |
| 451 | XFA_MB_YesNo) == XFA_IDYes) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 452 | GetNode()->SetFlag(XFA_NODEFLAG_UserInteractive, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 453 | } |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 454 | return XFA_EVENTERROR_Success; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | return XFA_EVENTERROR_NotExist; |
| 458 | } |
| 459 | int32_t CXFA_WidgetAcc::ProcessNullTestValidate(CXFA_Validate validate, |
| 460 | int32_t iFlags, |
| 461 | FX_BOOL bVersionFlag) { |
| 462 | CFX_WideString wsValue; |
| 463 | GetValue(wsValue, XFA_VALUEPICTURE_Raw); |
| 464 | if (!wsValue.IsEmpty()) { |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 465 | return XFA_EVENTERROR_Success; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 466 | } |
| 467 | if (m_bIsNull && (m_bPreNull == m_bIsNull)) { |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 468 | return XFA_EVENTERROR_Success; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 469 | } |
| 470 | int32_t eNullTest = validate.GetNullTest(); |
| 471 | CFX_WideString wsNullMsg; |
| 472 | validate.GetNullMessageText(wsNullMsg); |
| 473 | if (iFlags & 0x01) { |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 474 | int32_t iRet = XFA_EVENTERROR_Success; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 475 | if (eNullTest != XFA_ATTRIBUTEENUM_Disabled) { |
| 476 | iRet = XFA_EVENTERROR_Error; |
| 477 | } |
| 478 | if (!wsNullMsg.IsEmpty()) { |
| 479 | if (eNullTest != XFA_ATTRIBUTEENUM_Disabled) { |
| 480 | m_pDocView->m_arrNullTestMsg.Add(wsNullMsg); |
| 481 | return XFA_EVENTERROR_Error; |
| 482 | } |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 483 | return XFA_EVENTERROR_Success; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 484 | } |
| 485 | return iRet; |
| 486 | } |
| 487 | if (wsNullMsg.IsEmpty() && bVersionFlag && |
| 488 | eNullTest != XFA_ATTRIBUTEENUM_Disabled) { |
| 489 | return XFA_EVENTERROR_Error; |
| 490 | } |
| 491 | IXFA_AppProvider* pAppProvider = GetAppProvider(); |
| 492 | if (!pAppProvider) { |
| 493 | return XFA_EVENTERROR_NotExist; |
| 494 | } |
| 495 | CFX_WideString wsCaptionName; |
| 496 | CFX_WideString wsTitle; |
| 497 | pAppProvider->LoadString(XFA_IDS_AppName, wsTitle); |
| 498 | switch (eNullTest) { |
| 499 | case XFA_ATTRIBUTEENUM_Error: { |
| 500 | if (wsNullMsg.IsEmpty()) { |
| 501 | GetValidateCaptionName(wsCaptionName, bVersionFlag); |
| 502 | CFX_WideString wsError; |
| 503 | pAppProvider->LoadString(XFA_IDS_ValidateNullError, wsError); |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 504 | wsNullMsg.Format(wsError.c_str(), wsCaptionName.c_str()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 505 | } |
tsepez | 3f80c86 | 2016-05-16 12:03:24 -0700 | [diff] [blame] | 506 | pAppProvider->MsgBox(wsNullMsg, wsTitle, XFA_MBICON_Status, XFA_MB_OK); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 507 | return XFA_EVENTERROR_Error; |
| 508 | } |
| 509 | case XFA_ATTRIBUTEENUM_Warning: { |
| 510 | if (GetNode()->HasFlag(XFA_NODEFLAG_UserInteractive)) { |
| 511 | return TRUE; |
| 512 | } |
| 513 | if (wsNullMsg.IsEmpty()) { |
| 514 | GetValidateCaptionName(wsCaptionName, bVersionFlag); |
| 515 | CFX_WideString wsWarning; |
| 516 | pAppProvider->LoadString(XFA_IDS_ValidateNullWarning, wsWarning); |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 517 | wsNullMsg.Format(wsWarning.c_str(), wsCaptionName.c_str(), |
| 518 | wsCaptionName.c_str()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 519 | } |
tsepez | 3f80c86 | 2016-05-16 12:03:24 -0700 | [diff] [blame] | 520 | if (pAppProvider->MsgBox(wsNullMsg, wsTitle, XFA_MBICON_Warning, |
| 521 | XFA_MB_YesNo) == XFA_IDYes) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 522 | GetNode()->SetFlag(XFA_NODEFLAG_UserInteractive, false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 523 | } |
| 524 | return XFA_EVENTERROR_Error; |
| 525 | } |
| 526 | case XFA_ATTRIBUTEENUM_Disabled: |
| 527 | default: |
| 528 | break; |
| 529 | } |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 530 | return XFA_EVENTERROR_Success; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 531 | } |
| 532 | void CXFA_WidgetAcc::GetValidateCaptionName(CFX_WideString& wsCaptionName, |
| 533 | FX_BOOL bVersionFlag) { |
| 534 | if (!bVersionFlag) { |
| 535 | CXFA_Caption caption = GetCaption(); |
| 536 | if (caption) { |
| 537 | CXFA_Value capValue = caption.GetValue(); |
| 538 | if (capValue) { |
| 539 | CXFA_Text capText = capValue.GetText(); |
| 540 | if (capText) { |
| 541 | capText.GetContent(wsCaptionName); |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | if (wsCaptionName.IsEmpty()) { |
| 547 | GetName(wsCaptionName); |
| 548 | } |
| 549 | } |
| 550 | void CXFA_WidgetAcc::GetValidateMessage(IXFA_AppProvider* pAppProvider, |
| 551 | CFX_WideString& wsMessage, |
| 552 | FX_BOOL bError, |
| 553 | FX_BOOL bVersionFlag) { |
| 554 | CFX_WideString wsCaptionName; |
| 555 | GetValidateCaptionName(wsCaptionName, bVersionFlag); |
| 556 | CFX_WideString wsError; |
| 557 | if (bVersionFlag) { |
| 558 | pAppProvider->LoadString(XFA_IDS_ValidateFailed, wsError); |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 559 | wsMessage.Format(wsError.c_str(), wsCaptionName.c_str()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 560 | return; |
| 561 | } |
| 562 | if (bError) { |
| 563 | pAppProvider->LoadString(XFA_IDS_ValidateError, wsError); |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 564 | wsMessage.Format(wsError.c_str(), wsCaptionName.c_str()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 565 | return; |
| 566 | } |
| 567 | CFX_WideString wsWarning; |
| 568 | pAppProvider->LoadString(XFA_IDS_ValidateWarning, wsWarning); |
tsepez | bd9748d | 2016-04-13 21:40:19 -0700 | [diff] [blame] | 569 | wsMessage.Format(wsWarning.c_str(), wsCaptionName.c_str(), |
| 570 | wsCaptionName.c_str()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 571 | } |
| 572 | int32_t CXFA_WidgetAcc::ProcessValidate(int32_t iFlags) { |
| 573 | if (GetClassID() == XFA_ELEMENT_Draw) { |
| 574 | return XFA_EVENTERROR_NotExist; |
| 575 | } |
| 576 | CXFA_Validate validate = GetValidate(); |
| 577 | if (!validate) { |
| 578 | return XFA_EVENTERROR_NotExist; |
| 579 | } |
| 580 | FX_BOOL bInitDoc = validate.GetNode()->HasFlag(XFA_NODEFLAG_NeedsInitApp); |
| 581 | FX_BOOL bStatus = |
| 582 | m_pDocView->GetLayoutStatus() < XFA_DOCVIEW_LAYOUTSTATUS_End; |
| 583 | int32_t iFormat = 0; |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 584 | CFXJSE_Value* pRetValue = nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 585 | int32_t iRet = XFA_EVENTERROR_NotExist; |
| 586 | CXFA_Script script = validate.GetScript(); |
| 587 | if (script) { |
| 588 | CXFA_EventParam eParam; |
| 589 | eParam.m_eType = XFA_EVENT_Validate; |
| 590 | eParam.m_pTarget = this; |
| 591 | iRet = ExecuteScript(script, &eParam, |
| 592 | ((bInitDoc || bStatus) && GetRawValue().IsEmpty()) |
| 593 | ? nullptr |
| 594 | : &pRetValue); |
| 595 | } |
| 596 | XFA_VERSION version = GetDoc()->GetXFADoc()->GetCurVersionMode(); |
| 597 | FX_BOOL bVersionFlag = FALSE; |
| 598 | if (version < XFA_VERSION_208) { |
| 599 | bVersionFlag = TRUE; |
| 600 | } |
| 601 | if (bInitDoc) { |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 602 | validate.GetNode()->ClearFlag(XFA_NODEFLAG_NeedsInitApp); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 603 | } else { |
| 604 | iFormat = ProcessFormatTestValidate(validate, bVersionFlag); |
| 605 | if (!bVersionFlag) { |
| 606 | bVersionFlag = GetDoc()->GetXFADoc()->HasFlag(XFA_DOCFLAG_Scripting); |
| 607 | } |
| 608 | iRet |= ProcessNullTestValidate(validate, iFlags, bVersionFlag); |
| 609 | } |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 610 | if (iFormat != XFA_EVENTERROR_Success) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 611 | ProcessScriptTestValidate(validate, iRet, pRetValue, bVersionFlag); |
| 612 | } |
dsinclair | 86fad99 | 2016-05-31 11:34:04 -0700 | [diff] [blame] | 613 | delete pRetValue; |
| 614 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 615 | return iRet | iFormat; |
| 616 | } |
| 617 | int32_t CXFA_WidgetAcc::ExecuteScript(CXFA_Script script, |
| 618 | CXFA_EventParam* pEventParam, |
dsinclair | 12a6b0c | 2016-05-26 11:14:08 -0700 | [diff] [blame] | 619 | CFXJSE_Value** pRetValue) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 620 | static const uint32_t MAX_RECURSION_DEPTH = 2; |
| 621 | if (m_nRecursionDepth > MAX_RECURSION_DEPTH) |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 622 | return XFA_EVENTERROR_Success; |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 623 | ASSERT(pEventParam); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 624 | if (!script) { |
| 625 | return XFA_EVENTERROR_NotExist; |
| 626 | } |
| 627 | if (script.GetRunAt() == XFA_ATTRIBUTEENUM_Server) { |
| 628 | return XFA_EVENTERROR_Disabled; |
| 629 | } |
| 630 | CFX_WideString wsExpression; |
| 631 | script.GetExpression(wsExpression); |
| 632 | if (wsExpression.IsEmpty()) { |
| 633 | return XFA_EVENTERROR_NotExist; |
| 634 | } |
| 635 | XFA_SCRIPTTYPE eScriptType = script.GetContentType(); |
| 636 | if (eScriptType == XFA_SCRIPTTYPE_Unkown) { |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 637 | return XFA_EVENTERROR_Success; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 638 | } |
| 639 | CXFA_FFDoc* pDoc = GetDoc(); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 640 | CXFA_ScriptContext* pContext = pDoc->GetXFADoc()->GetScriptContext(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 641 | pContext->SetEventParam(*pEventParam); |
| 642 | pContext->SetRunAtType((XFA_ATTRIBUTEENUM)script.GetRunAt()); |
| 643 | CXFA_NodeArray refNodes; |
| 644 | if (pEventParam->m_eType == XFA_EVENT_InitCalculate || |
| 645 | pEventParam->m_eType == XFA_EVENT_Calculate) { |
| 646 | pContext->SetNodesOfRunScript(&refNodes); |
| 647 | } |
dsinclair | 86fad99 | 2016-05-31 11:34:04 -0700 | [diff] [blame] | 648 | std::unique_ptr<CFXJSE_Value> pTmpRetValue( |
| 649 | new CFXJSE_Value(pContext->GetRuntime())); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 650 | ++m_nRecursionDepth; |
dsinclair | 86fad99 | 2016-05-31 11:34:04 -0700 | [diff] [blame] | 651 | FX_BOOL bRet = pContext->RunScript((XFA_SCRIPTLANGTYPE)eScriptType, |
| 652 | wsExpression.AsStringC(), |
| 653 | pTmpRetValue.get(), m_pNode); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 654 | --m_nRecursionDepth; |
| 655 | int32_t iRet = XFA_EVENTERROR_Error; |
| 656 | if (bRet) { |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 657 | iRet = XFA_EVENTERROR_Success; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 658 | if (pEventParam->m_eType == XFA_EVENT_Calculate || |
| 659 | pEventParam->m_eType == XFA_EVENT_InitCalculate) { |
dsinclair | 769b137 | 2016-06-08 13:12:41 -0700 | [diff] [blame^] | 660 | if (!pTmpRetValue->IsUndefined()) { |
| 661 | if (!pTmpRetValue->IsNull()) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 662 | CFX_ByteString bsString; |
dsinclair | f27aeec | 2016-06-07 19:36:18 -0700 | [diff] [blame] | 663 | pTmpRetValue->ToString(bsString); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 664 | pEventParam->m_wsResult = |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 665 | CFX_WideString::FromUTF8(bsString.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 666 | } |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 667 | iRet = XFA_EVENTERROR_Success; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 668 | } else { |
| 669 | iRet = XFA_EVENTERROR_Error; |
| 670 | } |
| 671 | if (pEventParam->m_eType == XFA_EVENT_InitCalculate) { |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 672 | if ((iRet == XFA_EVENTERROR_Success) && |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 673 | (GetRawValue() != pEventParam->m_wsResult)) { |
| 674 | SetValue(pEventParam->m_wsResult, XFA_VALUEPICTURE_Raw); |
| 675 | m_pDocView->AddValidateWidget(this); |
| 676 | } |
| 677 | } |
| 678 | int32_t iRefs = refNodes.GetSize(); |
| 679 | for (int32_t r = 0; r < iRefs; r++) { |
| 680 | CXFA_WidgetAcc* pRefAcc = (CXFA_WidgetAcc*)refNodes[r]->GetWidgetData(); |
| 681 | if (pRefAcc && pRefAcc == this) { |
| 682 | continue; |
| 683 | } |
| 684 | CXFA_Node* pRefNode = refNodes[r]; |
| 685 | CXFA_CalcData* pGlobalData = |
| 686 | (CXFA_CalcData*)pRefNode->GetUserData(XFA_CalcData); |
| 687 | if (!pGlobalData) { |
| 688 | pGlobalData = new CXFA_CalcData; |
| 689 | pRefNode->SetUserData(XFA_CalcData, pGlobalData, |
| 690 | &gs_XFADeleteCalcData); |
| 691 | } |
| 692 | if (pGlobalData->m_Globals.Find(this) < 0) { |
| 693 | pGlobalData->m_Globals.Add(this); |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | } |
dsinclair | 86fad99 | 2016-05-31 11:34:04 -0700 | [diff] [blame] | 698 | if (pRetValue) |
| 699 | *pRetValue = pTmpRetValue.release(); |
| 700 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 701 | pContext->SetNodesOfRunScript(NULL); |
| 702 | return iRet; |
| 703 | } |
| 704 | CXFA_FFWidget* CXFA_WidgetAcc::GetNextWidget(CXFA_FFWidget* pWidget) { |
| 705 | CXFA_LayoutItem* pLayout = nullptr; |
| 706 | if (pWidget) { |
| 707 | pLayout = pWidget->GetNext(); |
| 708 | } else { |
| 709 | pLayout = m_pDocView->GetXFALayout()->GetLayoutItem(m_pNode); |
| 710 | } |
| 711 | return static_cast<CXFA_FFWidget*>(pLayout); |
| 712 | } |
| 713 | void CXFA_WidgetAcc::UpdateUIDisplay(CXFA_FFWidget* pExcept) { |
| 714 | CXFA_FFWidget* pWidget = NULL; |
weili | 038aa53 | 2016-05-20 15:38:29 -0700 | [diff] [blame] | 715 | while ((pWidget = GetNextWidget(pWidget)) != nullptr) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 716 | if (pWidget == pExcept || !pWidget->IsLoaded() || |
| 717 | (GetUIType() != XFA_ELEMENT_CheckButton && pWidget->IsFocused())) { |
| 718 | continue; |
| 719 | } |
| 720 | pWidget->UpdateFWLData(); |
| 721 | pWidget->AddInvalidateRect(); |
| 722 | } |
| 723 | } |
thestig | b1a5959 | 2016-04-14 18:29:56 -0700 | [diff] [blame] | 724 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 725 | void CXFA_WidgetAcc::CalcCaptionSize(CFX_SizeF& szCap) { |
| 726 | CXFA_Caption caption = GetCaption(); |
| 727 | if (!caption || caption.GetPresence() != XFA_ATTRIBUTEENUM_Visible) { |
| 728 | return; |
| 729 | } |
| 730 | LoadCaption(); |
| 731 | XFA_ELEMENT eUIType = (XFA_ELEMENT)GetUIType(); |
| 732 | int32_t iCapPlacement = caption.GetPlacementType(); |
| 733 | FX_FLOAT fCapReserve = caption.GetReserve(); |
| 734 | const bool bVert = iCapPlacement == XFA_ATTRIBUTEENUM_Top || |
| 735 | iCapPlacement == XFA_ATTRIBUTEENUM_Bottom; |
| 736 | const bool bReserveExit = fCapReserve > 0.01; |
| 737 | CXFA_TextLayout* pCapTextLayout = |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 738 | static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()) |
| 739 | ->m_pCapTextLayout.get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 740 | if (pCapTextLayout) { |
| 741 | if (!bVert && eUIType != XFA_ELEMENT_Button) { |
| 742 | szCap.x = fCapReserve; |
| 743 | } |
| 744 | CFX_SizeF minSize; |
| 745 | pCapTextLayout->CalcSize(minSize, szCap, szCap); |
| 746 | if (bReserveExit) { |
| 747 | bVert ? szCap.y = fCapReserve : szCap.x = fCapReserve; |
| 748 | } |
| 749 | } else { |
| 750 | FX_FLOAT fFontSize = 10.0f; |
| 751 | if (CXFA_Font font = caption.GetFont()) { |
| 752 | fFontSize = font.GetFontSize(); |
| 753 | } else if (CXFA_Font widgetfont = GetFont()) { |
| 754 | fFontSize = widgetfont.GetFontSize(); |
| 755 | } |
| 756 | if (bVert) { |
| 757 | szCap.y = fCapReserve > 0 ? fCapReserve : fFontSize; |
| 758 | } else { |
| 759 | szCap.x = fCapReserve > 0 ? fCapReserve : 0; |
| 760 | szCap.y = fFontSize; |
| 761 | } |
| 762 | } |
| 763 | if (CXFA_Margin mgCap = caption.GetMargin()) { |
| 764 | FX_FLOAT fLeftInset, fTopInset, fRightInset, fBottomInset; |
| 765 | mgCap.GetLeftInset(fLeftInset); |
| 766 | mgCap.GetTopInset(fTopInset); |
| 767 | mgCap.GetRightInset(fRightInset); |
| 768 | mgCap.GetBottomInset(fBottomInset); |
| 769 | if (bReserveExit) { |
| 770 | bVert ? (szCap.x += fLeftInset + fRightInset) |
| 771 | : (szCap.y += fTopInset + fBottomInset); |
| 772 | } else { |
| 773 | szCap.x += fLeftInset + fRightInset; |
| 774 | szCap.y += fTopInset + fBottomInset; |
| 775 | } |
| 776 | } |
| 777 | } |
| 778 | FX_BOOL CXFA_WidgetAcc::CalculateFieldAutoSize(CFX_SizeF& size) { |
| 779 | CFX_SizeF szCap; |
| 780 | CalcCaptionSize(szCap); |
| 781 | CFX_RectF rtUIMargin; |
| 782 | GetUIMargin(rtUIMargin); |
| 783 | size.x += rtUIMargin.left + rtUIMargin.width; |
| 784 | size.y += rtUIMargin.top + rtUIMargin.height; |
| 785 | if (szCap.x > 0 && szCap.y > 0) { |
| 786 | int32_t iCapPlacement = GetCaption().GetPlacementType(); |
| 787 | switch (iCapPlacement) { |
| 788 | case XFA_ATTRIBUTEENUM_Left: |
| 789 | case XFA_ATTRIBUTEENUM_Right: |
| 790 | case XFA_ATTRIBUTEENUM_Inline: { |
| 791 | size.x += szCap.x; |
| 792 | size.y = std::max(size.y, szCap.y); |
| 793 | } break; |
| 794 | case XFA_ATTRIBUTEENUM_Top: |
| 795 | case XFA_ATTRIBUTEENUM_Bottom: { |
| 796 | size.y += szCap.y; |
| 797 | size.x = std::max(size.x, szCap.x); |
| 798 | } |
| 799 | default: |
| 800 | break; |
| 801 | } |
| 802 | } |
| 803 | return CalculateWidgetAutoSize(size); |
| 804 | } |
| 805 | FX_BOOL CXFA_WidgetAcc::CalculateWidgetAutoSize(CFX_SizeF& size) { |
| 806 | CXFA_Margin mgWidget = GetMargin(); |
| 807 | if (mgWidget) { |
| 808 | FX_FLOAT fLeftInset, fTopInset, fRightInset, fBottomInset; |
| 809 | mgWidget.GetLeftInset(fLeftInset); |
| 810 | mgWidget.GetTopInset(fTopInset); |
| 811 | mgWidget.GetRightInset(fRightInset); |
| 812 | mgWidget.GetBottomInset(fBottomInset); |
| 813 | size.x += fLeftInset + fRightInset; |
| 814 | size.y += fTopInset + fBottomInset; |
| 815 | } |
| 816 | CXFA_Para para = GetPara(); |
| 817 | if (para) { |
| 818 | size.x += para.GetMarginLeft(); |
| 819 | size.x += para.GetTextIndent(); |
| 820 | } |
| 821 | FX_FLOAT fVal = 0, fMin = 0, fMax = 0; |
| 822 | if (GetWidth(fVal)) { |
| 823 | size.x = fVal; |
| 824 | } else { |
| 825 | if (GetMinWidth(fMin)) { |
| 826 | size.x = std::max(size.x, fMin); |
| 827 | } |
| 828 | if (GetMaxWidth(fMax) && fMax > 0) { |
| 829 | size.x = std::min(size.x, fMax); |
| 830 | } |
| 831 | } |
| 832 | fVal = 0, fMin = 0, fMax = 0; |
| 833 | if (GetHeight(fVal)) { |
| 834 | size.y = fVal; |
| 835 | } else { |
| 836 | if (GetMinHeight(fMin)) { |
| 837 | size.y = std::max(size.y, fMin); |
| 838 | } |
| 839 | if (GetMaxHeight(fMax) && fMax > 0) { |
| 840 | size.y = std::min(size.y, fMax); |
| 841 | } |
| 842 | } |
| 843 | return TRUE; |
| 844 | } |
| 845 | void CXFA_WidgetAcc::CalculateTextContentSize(CFX_SizeF& size) { |
| 846 | FX_FLOAT fFontSize = GetFontSize(); |
| 847 | CFX_WideString wsText; |
| 848 | GetValue(wsText, XFA_VALUEPICTURE_Display); |
| 849 | if (wsText.IsEmpty()) { |
| 850 | size.y += fFontSize; |
| 851 | return; |
| 852 | } |
| 853 | FX_WCHAR wcEnter = '\n'; |
| 854 | FX_WCHAR wsLast = wsText.GetAt(wsText.GetLength() - 1); |
| 855 | if (wsLast == wcEnter) { |
| 856 | wsText = wsText + wcEnter; |
| 857 | } |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 858 | |
| 859 | CXFA_FieldLayoutData* layoutData = |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 860 | static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()); |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 861 | if (!layoutData->m_pTextOut) { |
tsepez | f74ad99 | 2016-05-11 10:26:05 -0700 | [diff] [blame] | 862 | layoutData->m_pTextOut.reset(new CFDE_TextOut); |
| 863 | CFDE_TextOut* pTextOut = layoutData->m_pTextOut.get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 864 | pTextOut->SetFont(GetFDEFont()); |
| 865 | pTextOut->SetFontSize(fFontSize); |
| 866 | pTextOut->SetLineBreakTolerance(fFontSize * 0.2f); |
| 867 | pTextOut->SetLineSpace(GetLineHeight()); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 868 | uint32_t dwStyles = FDE_TTOSTYLE_LastLineHeight; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 869 | if (GetUIType() == XFA_ELEMENT_TextEdit && IsMultiLine()) { |
| 870 | dwStyles |= FDE_TTOSTYLE_LineWrap; |
| 871 | } |
| 872 | pTextOut->SetStyles(dwStyles); |
| 873 | } |
dsinclair | acd0d59 | 2016-04-21 11:06:27 -0700 | [diff] [blame] | 874 | layoutData->m_pTextOut->CalcLogicSize(wsText.c_str(), wsText.GetLength(), |
| 875 | size); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 876 | } |
| 877 | FX_BOOL CXFA_WidgetAcc::CalculateTextEditAutoSize(CFX_SizeF& size) { |
| 878 | if (size.x > 0) { |
| 879 | CFX_SizeF szOrz = size; |
| 880 | CFX_SizeF szCap; |
| 881 | CalcCaptionSize(szCap); |
| 882 | FX_BOOL bCapExit = szCap.x > 0.01 && szCap.y > 0.01; |
| 883 | int32_t iCapPlacement = XFA_ATTRIBUTEENUM_Unknown; |
| 884 | if (bCapExit) { |
| 885 | iCapPlacement = GetCaption().GetPlacementType(); |
| 886 | switch (iCapPlacement) { |
| 887 | case XFA_ATTRIBUTEENUM_Left: |
| 888 | case XFA_ATTRIBUTEENUM_Right: |
| 889 | case XFA_ATTRIBUTEENUM_Inline: { |
| 890 | size.x -= szCap.x; |
| 891 | } |
| 892 | default: |
| 893 | break; |
| 894 | } |
| 895 | } |
| 896 | CFX_RectF rtUIMargin; |
| 897 | GetUIMargin(rtUIMargin); |
| 898 | size.x -= rtUIMargin.left + rtUIMargin.width; |
| 899 | CXFA_Margin mgWidget = GetMargin(); |
| 900 | if (mgWidget) { |
| 901 | FX_FLOAT fLeftInset, fRightInset; |
| 902 | mgWidget.GetLeftInset(fLeftInset); |
| 903 | mgWidget.GetRightInset(fRightInset); |
| 904 | size.x -= fLeftInset + fRightInset; |
| 905 | } |
| 906 | CalculateTextContentSize(size); |
| 907 | size.y += rtUIMargin.top + rtUIMargin.height; |
| 908 | if (bCapExit) { |
| 909 | switch (iCapPlacement) { |
| 910 | case XFA_ATTRIBUTEENUM_Left: |
| 911 | case XFA_ATTRIBUTEENUM_Right: |
| 912 | case XFA_ATTRIBUTEENUM_Inline: { |
| 913 | size.y = std::max(size.y, szCap.y); |
| 914 | } break; |
| 915 | case XFA_ATTRIBUTEENUM_Top: |
| 916 | case XFA_ATTRIBUTEENUM_Bottom: { |
| 917 | size.y += szCap.y; |
| 918 | } |
| 919 | default: |
| 920 | break; |
| 921 | } |
| 922 | } |
| 923 | size.x = szOrz.x; |
| 924 | return CalculateWidgetAutoSize(size); |
| 925 | } |
| 926 | CalculateTextContentSize(size); |
| 927 | return CalculateFieldAutoSize(size); |
| 928 | } |
| 929 | FX_BOOL CXFA_WidgetAcc::CalculateCheckButtonAutoSize(CFX_SizeF& size) { |
| 930 | FX_FLOAT fCheckSize = GetCheckButtonSize(); |
| 931 | size.x = size.y = fCheckSize; |
| 932 | return CalculateFieldAutoSize(size); |
| 933 | } |
| 934 | FX_BOOL CXFA_WidgetAcc::CalculatePushButtonAutoSize(CFX_SizeF& size) { |
| 935 | CalcCaptionSize(size); |
| 936 | return CalculateWidgetAutoSize(size); |
| 937 | } |
| 938 | FX_BOOL CXFA_WidgetAcc::CalculateImageAutoSize(CFX_SizeF& size) { |
| 939 | if (!GetImageImage()) { |
| 940 | LoadImageImage(); |
| 941 | } |
| 942 | size.clear(); |
| 943 | if (CFX_DIBitmap* pBitmap = GetImageImage()) { |
| 944 | CFX_RectF rtImage, rtFit; |
| 945 | rtImage.Set(0, 0, 0, 0); |
| 946 | rtFit.Set(0, 0, 0, 0); |
| 947 | int32_t iImageXDpi = 0; |
| 948 | int32_t iImageYDpi = 0; |
| 949 | GetImageDpi(iImageXDpi, iImageYDpi); |
| 950 | rtImage.width = |
| 951 | XFA_UnitPx2Pt((FX_FLOAT)pBitmap->GetWidth(), (FX_FLOAT)iImageXDpi); |
| 952 | rtImage.height = |
| 953 | XFA_UnitPx2Pt((FX_FLOAT)pBitmap->GetHeight(), (FX_FLOAT)iImageYDpi); |
| 954 | if (GetWidth(rtFit.width)) { |
| 955 | GetWidthWithoutMargin(rtFit.width); |
| 956 | } else { |
| 957 | rtFit.width = rtImage.width; |
| 958 | } |
| 959 | if (GetHeight(rtFit.height)) { |
| 960 | GetHeightWithoutMargin(rtFit.height); |
| 961 | } else { |
| 962 | rtFit.height = rtImage.height; |
| 963 | } |
| 964 | size.x = rtFit.width; |
| 965 | size.y = rtFit.height; |
| 966 | } |
| 967 | return CalculateWidgetAutoSize(size); |
| 968 | } |
| 969 | FX_BOOL CXFA_WidgetAcc::CalculateImageEditAutoSize(CFX_SizeF& size) { |
| 970 | if (!GetImageEditImage()) { |
| 971 | LoadImageEditImage(); |
| 972 | } |
| 973 | size.clear(); |
| 974 | if (CFX_DIBitmap* pBitmap = GetImageEditImage()) { |
| 975 | CFX_RectF rtImage, rtFit; |
| 976 | rtImage.Set(0, 0, 0, 0); |
| 977 | rtFit.Set(0, 0, 0, 0); |
| 978 | int32_t iImageXDpi = 0; |
| 979 | int32_t iImageYDpi = 0; |
| 980 | GetImageEditDpi(iImageXDpi, iImageYDpi); |
| 981 | rtImage.width = |
| 982 | XFA_UnitPx2Pt((FX_FLOAT)pBitmap->GetWidth(), (FX_FLOAT)iImageXDpi); |
| 983 | rtImage.height = |
| 984 | XFA_UnitPx2Pt((FX_FLOAT)pBitmap->GetHeight(), (FX_FLOAT)iImageYDpi); |
| 985 | if (GetWidth(rtFit.width)) { |
| 986 | GetWidthWithoutMargin(rtFit.width); |
| 987 | } else { |
| 988 | rtFit.width = rtImage.width; |
| 989 | } |
| 990 | if (GetHeight(rtFit.height)) { |
| 991 | GetHeightWithoutMargin(rtFit.height); |
| 992 | } else { |
| 993 | rtFit.height = rtImage.height; |
| 994 | } |
| 995 | size.x = rtFit.width; |
| 996 | size.y = rtFit.height; |
| 997 | } |
| 998 | return CalculateFieldAutoSize(size); |
| 999 | } |
| 1000 | FX_BOOL CXFA_WidgetAcc::LoadImageImage() { |
| 1001 | InitLayoutData(); |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1002 | return static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get()) |
| 1003 | ->LoadImageData(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1004 | } |
| 1005 | FX_BOOL CXFA_WidgetAcc::LoadImageEditImage() { |
| 1006 | InitLayoutData(); |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1007 | return static_cast<CXFA_ImageEditData*>(m_pLayoutData.get()) |
| 1008 | ->LoadImageData(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1009 | } |
| 1010 | void CXFA_WidgetAcc::GetImageDpi(int32_t& iImageXDpi, int32_t& iImageYDpi) { |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1011 | CXFA_ImageLayoutData* pData = |
| 1012 | static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get()); |
| 1013 | iImageXDpi = pData->m_iImageXDpi; |
| 1014 | iImageYDpi = pData->m_iImageYDpi; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1015 | } |
| 1016 | void CXFA_WidgetAcc::GetImageEditDpi(int32_t& iImageXDpi, int32_t& iImageYDpi) { |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1017 | CXFA_ImageEditData* pData = |
| 1018 | static_cast<CXFA_ImageEditData*>(m_pLayoutData.get()); |
| 1019 | iImageXDpi = pData->m_iImageXDpi; |
| 1020 | iImageYDpi = pData->m_iImageYDpi; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1021 | } |
| 1022 | FX_BOOL CXFA_WidgetAcc::CalculateTextAutoSize(CFX_SizeF& size) { |
| 1023 | LoadText(); |
| 1024 | CXFA_TextLayout* pTextLayout = |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1025 | static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get())->GetTextLayout(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1026 | if (pTextLayout) { |
| 1027 | size.x = pTextLayout->StartLayout(size.x); |
| 1028 | size.y = pTextLayout->GetLayoutHeight(); |
| 1029 | } |
| 1030 | return CalculateWidgetAutoSize(size); |
| 1031 | } |
| 1032 | void CXFA_WidgetAcc::LoadText() { |
| 1033 | InitLayoutData(); |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1034 | static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get())->LoadText(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1035 | } |
| 1036 | FX_FLOAT CXFA_WidgetAcc::CalculateWidgetAutoWidth(FX_FLOAT fWidthCalc) { |
| 1037 | CXFA_Margin mgWidget = GetMargin(); |
| 1038 | if (mgWidget) { |
| 1039 | FX_FLOAT fLeftInset, fRightInset; |
| 1040 | mgWidget.GetLeftInset(fLeftInset); |
| 1041 | mgWidget.GetRightInset(fRightInset); |
| 1042 | fWidthCalc += fLeftInset + fRightInset; |
| 1043 | } |
| 1044 | FX_FLOAT fMin = 0, fMax = 0; |
| 1045 | if (GetMinWidth(fMin)) { |
| 1046 | fWidthCalc = std::max(fWidthCalc, fMin); |
| 1047 | } |
| 1048 | if (GetMaxWidth(fMax) && fMax > 0) { |
| 1049 | fWidthCalc = std::min(fWidthCalc, fMax); |
| 1050 | } |
| 1051 | return fWidthCalc; |
| 1052 | } |
| 1053 | FX_FLOAT CXFA_WidgetAcc::GetWidthWithoutMargin(FX_FLOAT fWidthCalc) { |
| 1054 | CXFA_Margin mgWidget = GetMargin(); |
| 1055 | if (mgWidget) { |
| 1056 | FX_FLOAT fLeftInset, fRightInset; |
| 1057 | mgWidget.GetLeftInset(fLeftInset); |
| 1058 | mgWidget.GetRightInset(fRightInset); |
| 1059 | fWidthCalc -= fLeftInset + fRightInset; |
| 1060 | } |
| 1061 | return fWidthCalc; |
| 1062 | } |
| 1063 | FX_FLOAT CXFA_WidgetAcc::CalculateWidgetAutoHeight(FX_FLOAT fHeightCalc) { |
| 1064 | CXFA_Margin mgWidget = GetMargin(); |
| 1065 | if (mgWidget) { |
| 1066 | FX_FLOAT fTopInset, fBottomInset; |
| 1067 | mgWidget.GetTopInset(fTopInset); |
| 1068 | mgWidget.GetBottomInset(fBottomInset); |
| 1069 | fHeightCalc += fTopInset + fBottomInset; |
| 1070 | } |
| 1071 | FX_FLOAT fMin = 0, fMax = 0; |
| 1072 | if (GetMinHeight(fMin)) { |
| 1073 | fHeightCalc = std::max(fHeightCalc, fMin); |
| 1074 | } |
| 1075 | if (GetMaxHeight(fMax) && fMax > 0) { |
| 1076 | fHeightCalc = std::min(fHeightCalc, fMax); |
| 1077 | } |
| 1078 | return fHeightCalc; |
| 1079 | } |
| 1080 | FX_FLOAT CXFA_WidgetAcc::GetHeightWithoutMargin(FX_FLOAT fHeightCalc) { |
| 1081 | CXFA_Margin mgWidget = GetMargin(); |
| 1082 | if (mgWidget) { |
| 1083 | FX_FLOAT fTopInset, fBottomInset; |
| 1084 | mgWidget.GetTopInset(fTopInset); |
| 1085 | mgWidget.GetBottomInset(fBottomInset); |
| 1086 | fHeightCalc -= fTopInset + fBottomInset; |
| 1087 | } |
| 1088 | return fHeightCalc; |
| 1089 | } |
| 1090 | void CXFA_WidgetAcc::StartWidgetLayout(FX_FLOAT& fCalcWidth, |
| 1091 | FX_FLOAT& fCalcHeight) { |
| 1092 | InitLayoutData(); |
| 1093 | XFA_ELEMENT eUIType = GetUIType(); |
| 1094 | if (eUIType == XFA_ELEMENT_Text) { |
| 1095 | m_pLayoutData->m_fWidgetHeight = -1; |
| 1096 | GetHeight(m_pLayoutData->m_fWidgetHeight); |
| 1097 | StartTextLayout(fCalcWidth, fCalcHeight); |
| 1098 | return; |
| 1099 | } |
| 1100 | if (fCalcWidth > 0 && fCalcHeight > 0) { |
| 1101 | return; |
| 1102 | } |
| 1103 | m_pLayoutData->m_fWidgetHeight = -1; |
| 1104 | FX_FLOAT fWidth = 0; |
| 1105 | if (fCalcWidth > 0 && fCalcHeight < 0) { |
| 1106 | if (!GetHeight(fCalcHeight)) { |
| 1107 | CalculateAccWidthAndHeight(eUIType, fCalcWidth, fCalcHeight); |
| 1108 | } |
| 1109 | m_pLayoutData->m_fWidgetHeight = fCalcHeight; |
| 1110 | return; |
| 1111 | } |
| 1112 | if (fCalcWidth < 0 && fCalcHeight < 0) { |
| 1113 | if (!GetWidth(fWidth) || !GetHeight(fCalcHeight)) { |
| 1114 | CalculateAccWidthAndHeight(eUIType, fWidth, fCalcHeight); |
| 1115 | } |
| 1116 | fCalcWidth = fWidth; |
| 1117 | } |
| 1118 | m_pLayoutData->m_fWidgetHeight = fCalcHeight; |
| 1119 | } |
| 1120 | void CXFA_WidgetAcc::CalculateAccWidthAndHeight(XFA_ELEMENT eUIType, |
| 1121 | FX_FLOAT& fWidth, |
| 1122 | FX_FLOAT& fCalcHeight) { |
| 1123 | CFX_SizeF sz(fWidth, m_pLayoutData->m_fWidgetHeight); |
| 1124 | switch (eUIType) { |
| 1125 | case XFA_ELEMENT_Barcode: |
| 1126 | case XFA_ELEMENT_ChoiceList: |
| 1127 | case XFA_ELEMENT_Signature: |
| 1128 | CalculateFieldAutoSize(sz); |
| 1129 | break; |
| 1130 | case XFA_ELEMENT_ImageEdit: |
| 1131 | CalculateImageEditAutoSize(sz); |
| 1132 | break; |
| 1133 | case XFA_ELEMENT_Button: |
| 1134 | CalculatePushButtonAutoSize(sz); |
| 1135 | break; |
| 1136 | case XFA_ELEMENT_CheckButton: |
| 1137 | CalculateCheckButtonAutoSize(sz); |
| 1138 | break; |
| 1139 | case XFA_ELEMENT_DateTimeEdit: |
| 1140 | case XFA_ELEMENT_NumericEdit: |
| 1141 | case XFA_ELEMENT_PasswordEdit: |
| 1142 | case XFA_ELEMENT_TextEdit: |
| 1143 | CalculateTextEditAutoSize(sz); |
| 1144 | break; |
| 1145 | case XFA_ELEMENT_Image: |
| 1146 | CalculateImageAutoSize(sz); |
| 1147 | break; |
| 1148 | case XFA_ELEMENT_Arc: |
| 1149 | case XFA_ELEMENT_Line: |
| 1150 | case XFA_ELEMENT_Rectangle: |
| 1151 | case XFA_ELEMENT_Subform: |
| 1152 | case XFA_ELEMENT_ExclGroup: |
| 1153 | CalculateWidgetAutoSize(sz); |
| 1154 | break; |
| 1155 | default: |
| 1156 | break; |
| 1157 | } |
| 1158 | fWidth = sz.x; |
| 1159 | m_pLayoutData->m_fWidgetHeight = sz.y; |
| 1160 | fCalcHeight = sz.y; |
| 1161 | } |
| 1162 | FX_BOOL CXFA_WidgetAcc::FindSplitPos(int32_t iBlockIndex, |
| 1163 | FX_FLOAT& fCalcHeight) { |
| 1164 | XFA_ELEMENT eUIType = (XFA_ELEMENT)GetUIType(); |
| 1165 | if (eUIType == XFA_ELEMENT_Subform) { |
| 1166 | return FALSE; |
| 1167 | } |
| 1168 | if (eUIType != XFA_ELEMENT_Text && eUIType != XFA_ELEMENT_TextEdit && |
| 1169 | eUIType != XFA_ELEMENT_NumericEdit && |
| 1170 | eUIType != XFA_ELEMENT_PasswordEdit) { |
| 1171 | fCalcHeight = 0; |
| 1172 | return TRUE; |
| 1173 | } |
| 1174 | FX_FLOAT fTopInset = 0; |
| 1175 | FX_FLOAT fBottomInset = 0; |
| 1176 | if (iBlockIndex == 0) { |
| 1177 | CXFA_Margin mgWidget = GetMargin(); |
| 1178 | if (mgWidget) { |
| 1179 | mgWidget.GetTopInset(fTopInset); |
| 1180 | mgWidget.GetBottomInset(fBottomInset); |
| 1181 | } |
| 1182 | CFX_RectF rtUIMargin; |
| 1183 | GetUIMargin(rtUIMargin); |
| 1184 | fTopInset += rtUIMargin.top; |
| 1185 | fBottomInset += rtUIMargin.width; |
| 1186 | } |
| 1187 | if (eUIType == XFA_ELEMENT_Text) { |
| 1188 | FX_FLOAT fHeight = fCalcHeight; |
| 1189 | if (iBlockIndex == 0) { |
| 1190 | fCalcHeight = fCalcHeight - fTopInset; |
| 1191 | if (fCalcHeight < 0) { |
| 1192 | fCalcHeight = 0; |
| 1193 | } |
| 1194 | } |
| 1195 | CXFA_TextLayout* pTextLayout = |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1196 | static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get())->GetTextLayout(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1197 | pTextLayout->DoLayout(iBlockIndex, fCalcHeight, fCalcHeight, |
| 1198 | m_pLayoutData->m_fWidgetHeight - fTopInset); |
| 1199 | if (fCalcHeight != 0) { |
| 1200 | if (iBlockIndex == 0) { |
| 1201 | fCalcHeight = fCalcHeight + fTopInset; |
| 1202 | } |
| 1203 | if (fabs(fHeight - fCalcHeight) < XFA_FLOAT_PERCISION) { |
| 1204 | return FALSE; |
| 1205 | } |
| 1206 | } |
| 1207 | return TRUE; |
| 1208 | } |
| 1209 | XFA_ATTRIBUTEENUM iCapPlacement = XFA_ATTRIBUTEENUM_Unknown; |
| 1210 | FX_FLOAT fCapReserve = 0; |
| 1211 | if (iBlockIndex == 0) { |
| 1212 | CXFA_Caption caption = GetCaption(); |
| 1213 | if (caption && caption.GetPresence() != XFA_ATTRIBUTEENUM_Hidden) { |
| 1214 | iCapPlacement = (XFA_ATTRIBUTEENUM)caption.GetPlacementType(); |
| 1215 | fCapReserve = caption.GetReserve(); |
| 1216 | } |
| 1217 | if (iCapPlacement == XFA_ATTRIBUTEENUM_Top && |
| 1218 | fCalcHeight < fCapReserve + fTopInset) { |
| 1219 | fCalcHeight = 0; |
| 1220 | return TRUE; |
| 1221 | } |
| 1222 | if (iCapPlacement == XFA_ATTRIBUTEENUM_Bottom && |
| 1223 | m_pLayoutData->m_fWidgetHeight - fCapReserve - fBottomInset) { |
| 1224 | fCalcHeight = 0; |
| 1225 | return TRUE; |
| 1226 | } |
| 1227 | if (iCapPlacement != XFA_ATTRIBUTEENUM_Top) { |
| 1228 | fCapReserve = 0; |
| 1229 | } |
| 1230 | } |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1231 | CXFA_FieldLayoutData* pFieldData = |
| 1232 | static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1233 | int32_t iLinesCount = 0; |
| 1234 | FX_FLOAT fHeight = m_pLayoutData->m_fWidgetHeight; |
| 1235 | CFX_WideString wsText; |
| 1236 | GetValue(wsText, XFA_VALUEPICTURE_Display); |
| 1237 | if (wsText.IsEmpty()) { |
| 1238 | iLinesCount = 1; |
| 1239 | } else { |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1240 | if (!pFieldData->m_pTextOut) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1241 | FX_FLOAT fWidth = 0; |
| 1242 | GetWidth(fWidth); |
| 1243 | CalculateAccWidthAndHeight(eUIType, fWidth, fHeight); |
| 1244 | } |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1245 | iLinesCount = pFieldData->m_pTextOut->GetTotalLines(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1246 | } |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1247 | if (!pFieldData->m_pFieldSplitArray) { |
| 1248 | pFieldData->m_pFieldSplitArray.reset(new CFX_FloatArray); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1249 | } |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1250 | CFX_FloatArray* pFieldArray = pFieldData->m_pFieldSplitArray.get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1251 | int32_t iFieldSplitCount = pFieldArray->GetSize(); |
| 1252 | for (int32_t i = 0; i < iBlockIndex * 3; i += 3) { |
| 1253 | iLinesCount -= (int32_t)pFieldArray->GetAt(i + 1); |
| 1254 | fHeight -= pFieldArray->GetAt(i + 2); |
| 1255 | } |
| 1256 | if (iLinesCount == 0) { |
| 1257 | return FALSE; |
| 1258 | } |
| 1259 | FX_FLOAT fLineHeight = GetLineHeight(); |
| 1260 | FX_FLOAT fFontSize = GetFontSize(); |
| 1261 | FX_FLOAT fTextHeight = iLinesCount * fLineHeight - fLineHeight + fFontSize; |
| 1262 | FX_FLOAT fSpaceAbove = 0; |
| 1263 | FX_FLOAT fStartOffset = 0; |
| 1264 | if (fHeight > 0.1f && iBlockIndex == 0) { |
| 1265 | fStartOffset = fTopInset; |
| 1266 | fHeight -= (fTopInset + fBottomInset); |
| 1267 | if (CXFA_Para para = GetPara()) { |
| 1268 | fSpaceAbove = para.GetSpaceAbove(); |
| 1269 | FX_FLOAT fSpaceBelow = para.GetSpaceBelow(); |
| 1270 | fHeight -= (fSpaceAbove + fSpaceBelow); |
| 1271 | switch (para.GetVerticalAlign()) { |
| 1272 | case XFA_ATTRIBUTEENUM_Top: |
| 1273 | fStartOffset += fSpaceAbove; |
| 1274 | break; |
| 1275 | case XFA_ATTRIBUTEENUM_Middle: |
| 1276 | fStartOffset += ((fHeight - fTextHeight) / 2 + fSpaceAbove); |
| 1277 | break; |
| 1278 | case XFA_ATTRIBUTEENUM_Bottom: |
| 1279 | fStartOffset += (fHeight - fTextHeight + fSpaceAbove); |
| 1280 | break; |
| 1281 | } |
| 1282 | } |
| 1283 | if (fStartOffset < 0.1f) { |
| 1284 | fStartOffset = 0; |
| 1285 | } |
| 1286 | } |
| 1287 | for (int32_t i = iBlockIndex - 1; iBlockIndex > 0 && i < iBlockIndex; i++) { |
| 1288 | fStartOffset = pFieldArray->GetAt(i * 3) - pFieldArray->GetAt(i * 3 + 2); |
| 1289 | if (fStartOffset < 0.1f) { |
| 1290 | fStartOffset = 0; |
| 1291 | } |
| 1292 | } |
| 1293 | if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { |
| 1294 | pFieldArray->SetAt(0, fStartOffset); |
| 1295 | } else { |
| 1296 | pFieldArray->Add(fStartOffset); |
| 1297 | } |
| 1298 | XFA_VERSION version = GetDoc()->GetXFADoc()->GetCurVersionMode(); |
| 1299 | FX_BOOL bCanSplitNoContent = FALSE; |
| 1300 | XFA_ATTRIBUTEENUM eLayoutMode; |
| 1301 | GetNode() |
| 1302 | ->GetNodeItem(XFA_NODEITEM_Parent) |
| 1303 | ->TryEnum(XFA_ATTRIBUTE_Layout, eLayoutMode, TRUE); |
| 1304 | if ((eLayoutMode == XFA_ATTRIBUTEENUM_Position || |
| 1305 | eLayoutMode == XFA_ATTRIBUTEENUM_Tb || |
| 1306 | eLayoutMode == XFA_ATTRIBUTEENUM_Row || |
| 1307 | eLayoutMode == XFA_ATTRIBUTEENUM_Table) && |
| 1308 | version > XFA_VERSION_208) { |
| 1309 | bCanSplitNoContent = TRUE; |
| 1310 | } |
| 1311 | if ((eLayoutMode == XFA_ATTRIBUTEENUM_Tb || |
| 1312 | eLayoutMode == XFA_ATTRIBUTEENUM_Row || |
| 1313 | eLayoutMode == XFA_ATTRIBUTEENUM_Table) && |
| 1314 | version <= XFA_VERSION_208) { |
| 1315 | if (fStartOffset < fCalcHeight) { |
| 1316 | bCanSplitNoContent = TRUE; |
| 1317 | } else { |
| 1318 | fCalcHeight = 0; |
| 1319 | return TRUE; |
| 1320 | } |
| 1321 | } |
| 1322 | if (bCanSplitNoContent) { |
| 1323 | if ((fCalcHeight - fTopInset - fSpaceAbove < fLineHeight)) { |
| 1324 | fCalcHeight = 0; |
| 1325 | return TRUE; |
| 1326 | } |
| 1327 | if (fStartOffset + XFA_FLOAT_PERCISION >= fCalcHeight) { |
| 1328 | if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { |
| 1329 | pFieldArray->SetAt(iBlockIndex * 3 + 1, 0); |
| 1330 | pFieldArray->SetAt(iBlockIndex * 3 + 2, fCalcHeight); |
| 1331 | } else { |
| 1332 | pFieldArray->Add(0); |
| 1333 | pFieldArray->Add(fCalcHeight); |
| 1334 | } |
| 1335 | return FALSE; |
| 1336 | } |
| 1337 | if (fCalcHeight - fStartOffset < fLineHeight) { |
| 1338 | fCalcHeight = fStartOffset; |
| 1339 | if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { |
| 1340 | pFieldArray->SetAt(iBlockIndex * 3 + 1, 0); |
| 1341 | pFieldArray->SetAt(iBlockIndex * 3 + 2, fCalcHeight); |
| 1342 | } else { |
| 1343 | pFieldArray->Add(0); |
| 1344 | pFieldArray->Add(fCalcHeight); |
| 1345 | } |
| 1346 | return TRUE; |
| 1347 | } |
| 1348 | FX_FLOAT fTextNum = |
| 1349 | fCalcHeight + XFA_FLOAT_PERCISION - fCapReserve - fStartOffset; |
| 1350 | int32_t iLineNum = |
| 1351 | (int32_t)((fTextNum + (fLineHeight - fFontSize)) / fLineHeight); |
| 1352 | if (iLineNum >= iLinesCount) { |
| 1353 | if (fCalcHeight - fStartOffset - fTextHeight >= fFontSize) { |
| 1354 | if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { |
| 1355 | pFieldArray->SetAt(iBlockIndex * 3 + 1, (FX_FLOAT)iLinesCount); |
| 1356 | pFieldArray->SetAt(iBlockIndex * 3 + 2, fCalcHeight); |
| 1357 | } else { |
| 1358 | pFieldArray->Add((FX_FLOAT)iLinesCount); |
| 1359 | pFieldArray->Add(fCalcHeight); |
| 1360 | } |
| 1361 | return FALSE; |
| 1362 | } |
| 1363 | if (fHeight - fStartOffset - fTextHeight < fFontSize) { |
| 1364 | iLineNum -= 1; |
| 1365 | if (iLineNum == 0) { |
| 1366 | fCalcHeight = 0; |
| 1367 | return TRUE; |
| 1368 | } |
| 1369 | } else { |
| 1370 | iLineNum = (int32_t)(fTextNum / fLineHeight); |
| 1371 | } |
| 1372 | } |
| 1373 | if (iLineNum > 0) { |
| 1374 | FX_FLOAT fSplitHeight = |
| 1375 | iLineNum * fLineHeight + fCapReserve + fStartOffset; |
| 1376 | if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { |
| 1377 | pFieldArray->SetAt(iBlockIndex * 3 + 1, (FX_FLOAT)iLineNum); |
| 1378 | pFieldArray->SetAt(iBlockIndex * 3 + 2, fSplitHeight); |
| 1379 | } else { |
| 1380 | pFieldArray->Add((FX_FLOAT)iLineNum); |
| 1381 | pFieldArray->Add(fSplitHeight); |
| 1382 | } |
| 1383 | if (fabs(fSplitHeight - fCalcHeight) < XFA_FLOAT_PERCISION) { |
| 1384 | return FALSE; |
| 1385 | } |
| 1386 | fCalcHeight = fSplitHeight; |
| 1387 | return TRUE; |
| 1388 | } |
| 1389 | } |
| 1390 | fCalcHeight = 0; |
| 1391 | return TRUE; |
| 1392 | } |
| 1393 | void CXFA_WidgetAcc::InitLayoutData() { |
| 1394 | if (m_pLayoutData) { |
| 1395 | return; |
| 1396 | } |
| 1397 | switch (GetUIType()) { |
| 1398 | case XFA_ELEMENT_Text: |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1399 | m_pLayoutData.reset(new CXFA_TextLayoutData); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1400 | return; |
| 1401 | case XFA_ELEMENT_TextEdit: |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1402 | m_pLayoutData.reset(new CXFA_TextEditData); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1403 | return; |
| 1404 | case XFA_ELEMENT_Image: |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1405 | m_pLayoutData.reset(new CXFA_ImageLayoutData); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1406 | return; |
| 1407 | case XFA_ELEMENT_ImageEdit: |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1408 | m_pLayoutData.reset(new CXFA_ImageEditData); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1409 | return; |
| 1410 | default: |
| 1411 | break; |
| 1412 | } |
| 1413 | if (GetClassID() == XFA_ELEMENT_Field) { |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1414 | m_pLayoutData.reset(new CXFA_FieldLayoutData); |
| 1415 | return; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1416 | } |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1417 | m_pLayoutData.reset(new CXFA_WidgetLayoutData); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1418 | } |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1419 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1420 | void CXFA_WidgetAcc::StartTextLayout(FX_FLOAT& fCalcWidth, |
| 1421 | FX_FLOAT& fCalcHeight) { |
| 1422 | LoadText(); |
| 1423 | CXFA_TextLayout* pTextLayout = |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1424 | static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get())->GetTextLayout(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1425 | FX_FLOAT fTextHeight = 0; |
| 1426 | if (fCalcWidth > 0 && fCalcHeight > 0) { |
| 1427 | FX_FLOAT fWidth = GetWidthWithoutMargin(fCalcWidth); |
| 1428 | pTextLayout->StartLayout(fWidth); |
| 1429 | fTextHeight = fCalcHeight; |
| 1430 | fTextHeight = GetHeightWithoutMargin(fTextHeight); |
| 1431 | pTextLayout->DoLayout(0, fTextHeight, -1, fTextHeight); |
| 1432 | return; |
| 1433 | } |
| 1434 | if (fCalcWidth > 0 && fCalcHeight < 0) { |
| 1435 | FX_FLOAT fWidth = GetWidthWithoutMargin(fCalcWidth); |
| 1436 | pTextLayout->StartLayout(fWidth); |
| 1437 | } |
| 1438 | if (fCalcWidth < 0 && fCalcHeight < 0) { |
| 1439 | FX_FLOAT fMaxWidth = -1; |
| 1440 | FX_BOOL bRet = GetWidth(fMaxWidth); |
| 1441 | if (bRet) { |
| 1442 | FX_FLOAT fWidth = GetWidthWithoutMargin(fMaxWidth); |
| 1443 | pTextLayout->StartLayout(fWidth); |
| 1444 | } else { |
| 1445 | FX_FLOAT fWidth = pTextLayout->StartLayout(fMaxWidth); |
| 1446 | fMaxWidth = CalculateWidgetAutoWidth(fWidth); |
| 1447 | fWidth = GetWidthWithoutMargin(fMaxWidth); |
| 1448 | pTextLayout->StartLayout(fWidth); |
| 1449 | } |
| 1450 | fCalcWidth = fMaxWidth; |
| 1451 | } |
| 1452 | if (m_pLayoutData->m_fWidgetHeight < 0) { |
| 1453 | m_pLayoutData->m_fWidgetHeight = pTextLayout->GetLayoutHeight(); |
| 1454 | m_pLayoutData->m_fWidgetHeight = |
| 1455 | CalculateWidgetAutoHeight(m_pLayoutData->m_fWidgetHeight); |
| 1456 | } |
| 1457 | fTextHeight = m_pLayoutData->m_fWidgetHeight; |
| 1458 | fTextHeight = GetHeightWithoutMargin(fTextHeight); |
| 1459 | pTextLayout->DoLayout(0, fTextHeight, -1, fTextHeight); |
| 1460 | fCalcHeight = m_pLayoutData->m_fWidgetHeight; |
| 1461 | } |
| 1462 | FX_BOOL CXFA_WidgetAcc::LoadCaption() { |
| 1463 | InitLayoutData(); |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1464 | return static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()) |
| 1465 | ->LoadCaption(this); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1466 | } |
| 1467 | CXFA_TextLayout* CXFA_WidgetAcc::GetCaptionTextLayout() { |
| 1468 | return m_pLayoutData |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1469 | ? static_cast<CXFA_FieldLayoutData*>(m_pLayoutData.get()) |
tsepez | f74ad99 | 2016-05-11 10:26:05 -0700 | [diff] [blame] | 1470 | ->m_pCapTextLayout.get() |
| 1471 | : nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1472 | } |
| 1473 | CXFA_TextLayout* CXFA_WidgetAcc::GetTextLayout() { |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1474 | return m_pLayoutData |
| 1475 | ? static_cast<CXFA_TextLayoutData*>(m_pLayoutData.get()) |
| 1476 | ->GetTextLayout() |
| 1477 | : NULL; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1478 | } |
| 1479 | CFX_DIBitmap* CXFA_WidgetAcc::GetImageImage() { |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1480 | return m_pLayoutData |
| 1481 | ? static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get()) |
| 1482 | ->m_pDIBitmap |
| 1483 | : NULL; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1484 | } |
| 1485 | CFX_DIBitmap* CXFA_WidgetAcc::GetImageEditImage() { |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1486 | return m_pLayoutData |
| 1487 | ? static_cast<CXFA_ImageEditData*>(m_pLayoutData.get()) |
| 1488 | ->m_pDIBitmap |
| 1489 | : NULL; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1490 | } |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1491 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1492 | void CXFA_WidgetAcc::SetImageImage(CFX_DIBitmap* newImage) { |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1493 | CXFA_ImageLayoutData* pData = |
| 1494 | static_cast<CXFA_ImageLayoutData*>(m_pLayoutData.get()); |
| 1495 | if (pData->m_pDIBitmap == newImage) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1496 | return; |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1497 | |
| 1498 | if (pData->m_pDIBitmap && !pData->m_bNamedImage) |
| 1499 | delete pData->m_pDIBitmap; |
| 1500 | |
| 1501 | pData->m_pDIBitmap = newImage; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1502 | } |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1503 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1504 | void CXFA_WidgetAcc::SetImageEditImage(CFX_DIBitmap* newImage) { |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1505 | CXFA_ImageEditData* pData = |
| 1506 | static_cast<CXFA_ImageEditData*>(m_pLayoutData.get()); |
| 1507 | if (pData->m_pDIBitmap == newImage) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1508 | return; |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1509 | |
| 1510 | if (pData->m_pDIBitmap && !pData->m_bNamedImage) |
| 1511 | delete pData->m_pDIBitmap; |
| 1512 | |
| 1513 | pData->m_pDIBitmap = newImage; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1514 | } |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1515 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1516 | CXFA_WidgetLayoutData* CXFA_WidgetAcc::GetWidgetLayoutData() { |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1517 | return m_pLayoutData.get(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1518 | } |
tsepez | 2346793 | 2016-05-19 09:30:58 -0700 | [diff] [blame] | 1519 | |
thestig | a4fdfc5 | 2016-06-07 17:33:37 -0700 | [diff] [blame] | 1520 | CFGAS_GEFont* CXFA_WidgetAcc::GetFDEFont() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1521 | CFX_WideStringC wsFontName = FX_WSTRC(L"Courier"); |
tsepez | 736f28a | 2016-03-25 14:19:51 -0700 | [diff] [blame] | 1522 | uint32_t dwFontStyle = 0; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1523 | if (CXFA_Font font = GetFont()) { |
| 1524 | if (font.IsBold()) { |
| 1525 | dwFontStyle |= FX_FONTSTYLE_Bold; |
| 1526 | } |
| 1527 | if (font.IsItalic()) { |
| 1528 | dwFontStyle |= FX_FONTSTYLE_Italic; |
| 1529 | } |
| 1530 | font.GetTypeface(wsFontName); |
| 1531 | } |
| 1532 | CXFA_FFDoc* pDoc = GetDoc(); |
| 1533 | return pDoc->GetApp()->GetXFAFontMgr()->GetFont(pDoc, wsFontName, |
| 1534 | dwFontStyle); |
| 1535 | } |
| 1536 | FX_FLOAT CXFA_WidgetAcc::GetFontSize() { |
| 1537 | FX_FLOAT fFontSize = 10.0f; |
| 1538 | if (CXFA_Font font = GetFont()) { |
| 1539 | fFontSize = font.GetFontSize(); |
| 1540 | } |
| 1541 | return fFontSize < 0.1f ? 10.0f : fFontSize; |
| 1542 | } |
| 1543 | FX_FLOAT CXFA_WidgetAcc::GetLineHeight() { |
| 1544 | FX_FLOAT fLineHeight = 0; |
| 1545 | if (CXFA_Para para = GetPara()) { |
| 1546 | fLineHeight = para.GetLineHeight(); |
| 1547 | } |
| 1548 | if (fLineHeight < 1) { |
| 1549 | fLineHeight = GetFontSize() * 1.2f; |
| 1550 | } |
| 1551 | return fLineHeight; |
| 1552 | } |
| 1553 | FX_ARGB CXFA_WidgetAcc::GetTextColor() { |
| 1554 | if (CXFA_Font font = GetFont()) { |
| 1555 | return font.GetColor(); |
| 1556 | } |
| 1557 | return 0xFF000000; |
| 1558 | } |
| 1559 | CXFA_Node* CXFA_TextProvider::GetTextNode(FX_BOOL& bRichText) { |
| 1560 | bRichText = FALSE; |
| 1561 | if (m_pTextNode) { |
| 1562 | if (m_pTextNode->GetClassID() == XFA_ELEMENT_ExData) { |
| 1563 | CFX_WideString wsContentType; |
| 1564 | m_pTextNode->GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, |
| 1565 | FALSE); |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 1566 | if (wsContentType == FX_WSTRC(L"text/html")) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1567 | bRichText = TRUE; |
| 1568 | } |
| 1569 | } |
| 1570 | return m_pTextNode; |
| 1571 | } |
| 1572 | if (m_eType == XFA_TEXTPROVIDERTYPE_Text) { |
| 1573 | CXFA_Node* pElementNode = m_pWidgetAcc->GetNode(); |
| 1574 | CXFA_Node* pValueNode = pElementNode->GetChild(0, XFA_ELEMENT_Value); |
| 1575 | if (!pValueNode) { |
| 1576 | return NULL; |
| 1577 | } |
| 1578 | CXFA_Node* pChildNode = pValueNode->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1579 | if (pChildNode && pChildNode->GetClassID() == XFA_ELEMENT_ExData) { |
| 1580 | CFX_WideString wsContentType; |
| 1581 | pChildNode->GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, FALSE); |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 1582 | if (wsContentType == FX_WSTRC(L"text/html")) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1583 | bRichText = TRUE; |
| 1584 | } |
| 1585 | } |
| 1586 | return pChildNode; |
| 1587 | } else if (m_eType == XFA_TEXTPROVIDERTYPE_Datasets) { |
| 1588 | CXFA_Node* pBind = m_pWidgetAcc->GetDatasets(); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1589 | CFDE_XMLNode* pXMLNode = pBind->GetXMLMappingNode(); |
dsinclair | 43854a5 | 2016-04-27 12:26:00 -0700 | [diff] [blame] | 1590 | ASSERT(pXMLNode); |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1591 | for (CFDE_XMLNode* pXMLChild = |
| 1592 | pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1593 | pXMLChild; |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1594 | pXMLChild = pXMLChild->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1595 | if (pXMLChild->GetType() == FDE_XMLNODE_Element) { |
dsinclair | ae95f76 | 2016-03-29 16:58:29 -0700 | [diff] [blame] | 1596 | CFDE_XMLElement* pElement = static_cast<CFDE_XMLElement*>(pXMLChild); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1597 | if (XFA_RecognizeRichText(pElement)) { |
| 1598 | bRichText = TRUE; |
| 1599 | } |
| 1600 | } |
| 1601 | } |
| 1602 | return pBind; |
| 1603 | } else if (m_eType == XFA_TEXTPROVIDERTYPE_Caption) { |
| 1604 | CXFA_Node* pCaptionNode = |
| 1605 | m_pWidgetAcc->GetNode()->GetChild(0, XFA_ELEMENT_Caption); |
| 1606 | if (pCaptionNode == NULL) { |
| 1607 | return NULL; |
| 1608 | } |
| 1609 | CXFA_Node* pValueNode = pCaptionNode->GetChild(0, XFA_ELEMENT_Value); |
| 1610 | if (pValueNode == NULL) { |
| 1611 | return NULL; |
| 1612 | } |
| 1613 | CXFA_Node* pChildNode = pValueNode->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1614 | if (pChildNode && pChildNode->GetClassID() == XFA_ELEMENT_ExData) { |
| 1615 | CFX_WideString wsContentType; |
| 1616 | pChildNode->GetAttribute(XFA_ATTRIBUTE_ContentType, wsContentType, FALSE); |
tsepez | 9f2970c | 2016-04-01 10:23:04 -0700 | [diff] [blame] | 1617 | if (wsContentType == FX_WSTRC(L"text/html")) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1618 | bRichText = TRUE; |
| 1619 | } |
| 1620 | } |
| 1621 | return pChildNode; |
| 1622 | } |
| 1623 | CXFA_Node* pItemNode = |
| 1624 | m_pWidgetAcc->GetNode()->GetChild(0, XFA_ELEMENT_Items); |
| 1625 | if (pItemNode == NULL) { |
| 1626 | return NULL; |
| 1627 | } |
| 1628 | CXFA_Node* pNode = pItemNode->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 1629 | while (pNode) { |
| 1630 | CFX_WideStringC wsName; |
| 1631 | pNode->TryCData(XFA_ATTRIBUTE_Name, wsName); |
| 1632 | if (m_eType == XFA_TEXTPROVIDERTYPE_Rollover && |
| 1633 | wsName == FX_WSTRC(L"rollover")) { |
| 1634 | return pNode; |
| 1635 | } |
| 1636 | if (m_eType == XFA_TEXTPROVIDERTYPE_Down && wsName == FX_WSTRC(L"down")) { |
| 1637 | return pNode; |
| 1638 | } |
| 1639 | pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling); |
| 1640 | } |
| 1641 | return NULL; |
| 1642 | } |
| 1643 | CXFA_Para CXFA_TextProvider::GetParaNode() { |
| 1644 | if (m_eType == XFA_TEXTPROVIDERTYPE_Text) { |
| 1645 | return m_pWidgetAcc->GetPara(); |
| 1646 | } |
| 1647 | CXFA_Node* pNode = m_pWidgetAcc->GetNode()->GetChild(0, XFA_ELEMENT_Caption); |
| 1648 | return CXFA_Para(pNode->GetChild(0, XFA_ELEMENT_Para)); |
| 1649 | } |
| 1650 | CXFA_Font CXFA_TextProvider::GetFontNode() { |
| 1651 | if (m_eType == XFA_TEXTPROVIDERTYPE_Text) { |
| 1652 | return m_pWidgetAcc->GetFont(); |
| 1653 | } |
| 1654 | CXFA_Node* pNode = m_pWidgetAcc->GetNode()->GetChild(0, XFA_ELEMENT_Caption); |
| 1655 | pNode = pNode->GetChild(0, XFA_ELEMENT_Font); |
| 1656 | if (pNode) { |
| 1657 | return CXFA_Font(pNode); |
| 1658 | } |
| 1659 | return m_pWidgetAcc->GetFont(); |
| 1660 | } |
| 1661 | FX_BOOL CXFA_TextProvider::IsCheckButtonAndAutoWidth() { |
| 1662 | XFA_ELEMENT eType = m_pWidgetAcc->GetUIType(); |
| 1663 | if (eType == XFA_ELEMENT_CheckButton) { |
| 1664 | FX_FLOAT fWidth = 0; |
| 1665 | return !m_pWidgetAcc->GetWidth(fWidth); |
| 1666 | } |
| 1667 | return FALSE; |
| 1668 | } |
| 1669 | FX_BOOL CXFA_TextProvider::GetEmbbedObj(FX_BOOL bURI, |
| 1670 | FX_BOOL bRaw, |
| 1671 | const CFX_WideString& wsAttr, |
| 1672 | CFX_WideString& wsValue) { |
| 1673 | if (m_eType != XFA_TEXTPROVIDERTYPE_Text) { |
| 1674 | return FALSE; |
| 1675 | } |
| 1676 | if (bURI) { |
| 1677 | CXFA_Node* pWidgetNode = m_pWidgetAcc->GetNode(); |
| 1678 | CXFA_Node* pParent = pWidgetNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 1679 | CXFA_Document* pDocument = pWidgetNode->GetDocument(); |
| 1680 | CXFA_Node* pIDNode = NULL; |
| 1681 | CXFA_WidgetAcc* pEmbAcc = NULL; |
| 1682 | if (pParent) { |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1683 | pIDNode = pDocument->GetNodeByID(pParent, wsAttr.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1684 | } |
| 1685 | if (!pIDNode) { |
| 1686 | pIDNode = pDocument->GetNodeByID( |
tsepez | fc58ad1 | 2016-04-05 12:22:15 -0700 | [diff] [blame] | 1687 | ToNode(pDocument->GetXFAObject(XFA_HASHCODE_Form)), |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 1688 | wsAttr.AsStringC()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 1689 | } |
| 1690 | if (pIDNode) { |
| 1691 | pEmbAcc = (CXFA_WidgetAcc*)pIDNode->GetWidgetData(); |
| 1692 | } |
| 1693 | if (pEmbAcc) { |
| 1694 | pEmbAcc->GetValue(wsValue, XFA_VALUEPICTURE_Display); |
| 1695 | return TRUE; |
| 1696 | } |
| 1697 | } |
| 1698 | return FALSE; |
| 1699 | } |