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