• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef XFA_FXFA_CXFA_WIDGETACC_H_
8 #define XFA_FXFA_CXFA_WIDGETACC_H_
9 
10 #include <memory>
11 #include <utility>
12 #include <vector>
13 
14 #include "core/fxcrt/fx_coordinates.h"
15 #include "core/fxcrt/fx_string.h"
16 #include "core/fxcrt/fx_system.h"
17 #include "core/fxcrt/retain_ptr.h"
18 #include "core/fxge/dib/cfx_dibitmap.h"
19 #include "core/fxge/fx_dib.h"
20 #include "xfa/fxfa/fxfa_basic.h"
21 
22 enum XFA_CHECKSTATE {
23   XFA_CHECKSTATE_On = 0,
24   XFA_CHECKSTATE_Off = 1,
25   XFA_CHECKSTATE_Neutral = 2,
26 };
27 
28 enum XFA_VALUEPICTURE {
29   XFA_VALUEPICTURE_Raw = 0,
30   XFA_VALUEPICTURE_Display,
31   XFA_VALUEPICTURE_Edit,
32   XFA_VALUEPICTURE_DataBind,
33 };
34 
35 class CFGAS_GEFont;
36 class CXFA_Bind;
37 class CXFA_Border;
38 class CXFA_Calculate;
39 class CXFA_Caption;
40 class CXFA_Event;
41 class CXFA_EventParam;
42 class CXFA_FFApp;
43 class CXFA_FFDoc;
44 class CXFA_FFDocView;
45 class CXFA_FFWidget;
46 class CXFA_Font;
47 class CXFA_Margin;
48 class CXFA_Node;
49 class CXFA_Script;
50 class CXFA_Para;
51 class CXFA_TextLayout;
52 class CXFA_Value;
53 class CXFA_Validate;
54 class CXFA_WidgetLayoutData;
55 class IFX_Locale;
56 
57 class CXFA_WidgetAcc {
58  public:
59   explicit CXFA_WidgetAcc(CXFA_Node* pNode);
60   ~CXFA_WidgetAcc();
61 
62   void ResetData();
63 
64   CXFA_FFWidget* GetNextWidget(CXFA_FFWidget* pWidget);
65   void StartWidgetLayout(CXFA_FFDoc* doc,
66                          float& fCalcWidth,
67                          float& fCalcHeight);
68   bool FindSplitPos(CXFA_FFDocView* docView,
69                     int32_t iBlockIndex,
70                     float& fCalcHeight);
71 
72   bool LoadCaption(CXFA_FFDoc* doc);
73   CXFA_TextLayout* GetCaptionTextLayout();
74 
75   void LoadText(CXFA_FFDoc* doc);
76   CXFA_TextLayout* GetTextLayout();
77 
78   bool LoadImageImage(CXFA_FFDoc* doc);
79   bool LoadImageEditImage(CXFA_FFDoc* doc);
80   void GetImageDpi(int32_t& iImageXDpi, int32_t& iImageYDpi);
81   void GetImageEditDpi(int32_t& iImageXDpi, int32_t& iImageYDpi);
82 
83   RetainPtr<CFX_DIBitmap> GetImageImage();
84   RetainPtr<CFX_DIBitmap> GetImageEditImage();
85   void SetImageEdit(const WideString& wsContentType,
86                     const WideString& wsHref,
87                     const WideString& wsData);
88   void SetImageImage(const RetainPtr<CFX_DIBitmap>& newImage);
89   void SetImageEditImage(const RetainPtr<CFX_DIBitmap>& newImage);
90   void UpdateUIDisplay(CXFA_FFDocView* docView, CXFA_FFWidget* pExcept);
91 
92   RetainPtr<CFGAS_GEFont> GetFDEFont(CXFA_FFDoc* doc);
93 
GetNode()94   CXFA_Node* GetNode() const { return m_pNode; }
95 
96   CXFA_Node* GetUIChild();
97   XFA_Element GetUIType();
98   CFX_RectF GetUIMargin();
99 
100   bool IsOpenAccess() const;
101   bool IsListBox();
102   bool IsAllowNeutral();
103   bool IsRadioButton();
104   bool IsChoiceListAllowTextEntry();
105   bool IsMultiLine();
106 
107   CXFA_Border* GetUIBorder();
108 
109   std::vector<CXFA_Event*> GetEventByActivity(XFA_AttributeEnum iActivity,
110                                               bool bIsFormReady);
111 
112   XFA_AttributeEnum GetButtonHighlight();
113   bool HasButtonRollover() const;
114   bool HasButtonDown() const;
115 
116   bool IsCheckButtonRound();
117   XFA_AttributeEnum GetCheckButtonMark();
118   float GetCheckButtonSize();
119 
120   XFA_CHECKSTATE GetCheckState();
121   void SetCheckState(XFA_CHECKSTATE eCheckState, bool bNotify);
122 
123   CXFA_Node* GetSelectedMember();
124   CXFA_Node* SetSelectedMember(const WideStringView& wsName, bool bNotify);
125   void SetSelectedMemberByValue(const WideStringView& wsValue,
126                                 bool bNotify,
127                                 bool bScriptModify,
128                                 bool bSyncData);
129 
130   CXFA_Node* GetExclGroupFirstMember();
131   CXFA_Node* GetExclGroupNextMember(CXFA_Node* pNode);
132 
133   int32_t CountChoiceListItems(bool bSaveValue);
134   Optional<WideString> GetChoiceListItem(int32_t nIndex, bool bSaveValue);
135   bool IsChoiceListMultiSelect();
136   bool IsChoiceListCommitOnSelect();
137   std::vector<WideString> GetChoiceListItems(bool bSaveValue);
138 
139   int32_t CountSelectedItems();
140   int32_t GetSelectedItem(int32_t nIndex);
141   std::vector<int32_t> GetSelectedItems();
142   std::vector<WideString> GetSelectedItemsValue();
143   void SetSelectedItems(const std::vector<int32_t>& iSelArray,
144                         bool bNotify,
145                         bool bScriptModify,
146                         bool bSyncData);
147   void InsertItem(const WideString& wsLabel,
148                   const WideString& wsValue,
149                   bool bNotify);
150   bool DeleteItem(int32_t nIndex, bool bNotify, bool bScriptModify);
151   void ClearAllSelections();
152 
153   bool GetItemState(int32_t nIndex);
154   void SetItemState(int32_t nIndex,
155                     bool bSelected,
156                     bool bNotify,
157                     bool bScriptModify,
158                     bool bSyncData);
159 
160   WideString GetItemValue(const WideStringView& wsLabel);
161 
162   bool IsHorizontalScrollPolicyOff();
163   bool IsVerticalScrollPolicyOff();
164   Optional<int32_t> GetNumberOfCells();
165 
166   bool SetValue(XFA_VALUEPICTURE eValueType, const WideString& wsValue);
167   WideString GetValue(XFA_VALUEPICTURE eValueType);
168 
169   WideString GetPictureContent(XFA_VALUEPICTURE ePicture);
170   IFX_Locale* GetLocale();
171 
172   WideString GetNormalizeDataValue(const WideString& wsValue);
173   WideString GetFormatDataValue(const WideString& wsValue);
174   WideString NormalizeNumStr(const WideString& wsValue);
175 
176   WideString GetPasswordChar();
177   std::pair<XFA_Element, int32_t> GetMaxChars();
178   int32_t GetFracDigits();
179   int32_t GetLeadDigits();
180 
181   WideString NumericLimit(const WideString& wsValue,
182                           int32_t iLead,
183                           int32_t iTread) const;
184 
IsPreNull()185   bool IsPreNull() const { return m_bPreNull; }
SetPreNull(bool val)186   void SetPreNull(bool val) { m_bPreNull = val; }
IsNull()187   bool IsNull() const { return m_bIsNull; }
SetIsNull(bool val)188   void SetIsNull(bool val) { m_bIsNull = val; }
189 
190  private:
191   void CalcCaptionSize(CXFA_FFDoc* doc, CFX_SizeF& szCap);
192   bool CalculateFieldAutoSize(CXFA_FFDoc* doc, CFX_SizeF& size);
193   bool CalculateWidgetAutoSize(CFX_SizeF& size);
194   bool CalculateTextEditAutoSize(CXFA_FFDoc* doc, CFX_SizeF& size);
195   bool CalculateCheckButtonAutoSize(CXFA_FFDoc* doc, CFX_SizeF& size);
196   bool CalculatePushButtonAutoSize(CXFA_FFDoc* doc, CFX_SizeF& size);
197   CFX_SizeF CalculateImageSize(float img_width,
198                                float img_height,
199                                float dpi_x,
200                                float dpi_y);
201   bool CalculateImageEditAutoSize(CXFA_FFDoc* doc, CFX_SizeF& size);
202   bool CalculateImageAutoSize(CXFA_FFDoc* doc, CFX_SizeF& size);
203   float CalculateWidgetAutoHeight(float fHeightCalc);
204   float CalculateWidgetAutoWidth(float fWidthCalc);
205   float GetWidthWithoutMargin(float fWidthCalc);
206   float GetHeightWithoutMargin(float fHeightCalc);
207   void CalculateTextContentSize(CXFA_FFDoc* doc, CFX_SizeF& size);
208   void CalculateAccWidthAndHeight(CXFA_FFDoc* doc,
209                                   XFA_Element eUIType,
210                                   float& fWidth,
211                                   float& fCalcHeight);
212   void InitLayoutData();
213   void StartTextLayout(CXFA_FFDoc* doc, float& fCalcWidth, float& fCalcHeight);
214 
215   void InsertListTextItem(CXFA_Node* pItems,
216                           const WideString& wsText,
217                           int32_t nIndex);
218   WideString FormatNumStr(const WideString& wsValue, IFX_Locale* pLocale);
219   void GetItemLabel(const WideStringView& wsValue, WideString& wsLabel);
220 
221   std::unique_ptr<CXFA_WidgetLayoutData> m_pLayoutData;
222   bool m_bIsNull;
223   bool m_bPreNull;
224   CXFA_Node* m_pUiChildNode;
225   XFA_Element m_eUIType;
226   CXFA_Node* m_pNode;
227 };
228 
229 #endif  // XFA_FXFA_CXFA_WIDGETACC_H_
230