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