blob: d41f8927d7d49dff981eb952e77c22c10d03dcb8 [file] [log] [blame]
jaepark611adb82016-08-17 11:34:36 -07001// Copyright 2016 PDFium Authors. All rights reserved.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
jaepark611adb82016-08-17 11:34:36 -07007#include "fpdfsdk/include/cpdfsdk_widget.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -08008
Lei Zhangaa8bf7e2015-12-24 19:13:32 -08009#include <memory>
10
dsinclairc6c425a2016-09-29 12:01:30 -070011#include "core/fpdfapi/fpdf_parser/cpdf_dictionary.h"
12#include "core/fpdfapi/fpdf_parser/cpdf_document.h"
13#include "core/fpdfapi/fpdf_parser/cpdf_stream.h"
dsinclair1727aee2016-09-29 13:12:56 -070014#include "core/fpdfdoc/cpdf_defaultappearance.h"
15#include "core/fpdfdoc/cpdf_formcontrol.h"
16#include "core/fpdfdoc/cpdf_formfield.h"
17#include "core/fpdfdoc/cpdf_iconfit.h"
18#include "core/fpdfdoc/cpdf_interform.h"
dsinclair74a34fc2016-09-29 16:41:42 -070019#include "core/fxge/cfx_graphstatedata.h"
20#include "core/fxge/cfx_pathdata.h"
21#include "core/fxge/cfx_renderdevice.h"
jaepark611adb82016-08-17 11:34:36 -070022#include "fpdfsdk/formfiller/cba_fontmap.h"
dsinclaire35af1e2016-07-13 11:26:20 -070023#include "fpdfsdk/fxedit/include/fxet_edit.h"
dsinclairf34518b2016-09-13 12:03:48 -070024#include "fpdfsdk/include/cpdfsdk_document.h"
dsinclair79db6092016-09-14 07:27:21 -070025#include "fpdfsdk/include/cpdfsdk_environment.h"
jaepark611adb82016-08-17 11:34:36 -070026#include "fpdfsdk/include/cpdfsdk_interform.h"
dsinclairf34518b2016-09-13 12:03:48 -070027#include "fpdfsdk/include/cpdfsdk_pageview.h"
28#include "fpdfsdk/include/fsdk_actionhandler.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080029#include "fpdfsdk/include/fsdk_define.h"
jaepark611adb82016-08-17 11:34:36 -070030#include "fpdfsdk/pdfwindow/PWL_Edit.h"
dan sinclair89e904b2016-03-23 19:29:15 -040031#include "fpdfsdk/pdfwindow/PWL_Utils.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070032
Tom Sepez40e9ff32015-11-30 12:39:54 -080033#ifdef PDF_ENABLE_XFA
dsinclair89bdd082016-04-06 10:47:54 -070034#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
weili625ad662016-06-15 11:21:33 -070035#include "xfa/fxfa/include/cxfa_eventparam.h"
jaepark611adb82016-08-17 11:34:36 -070036#include "xfa/fxfa/include/fxfa_widget.h"
weili625ad662016-06-15 11:21:33 -070037#include "xfa/fxfa/include/xfa_ffdocview.h"
dsinclair7222ea62016-04-06 14:33:07 -070038#include "xfa/fxfa/include/xfa_ffwidget.h"
weili625ad662016-06-15 11:21:33 -070039#include "xfa/fxfa/include/xfa_ffwidgethandler.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080040#endif // PDF_ENABLE_XFA
41
dsinclair72177da2016-09-15 12:07:23 -070042namespace {
43
44// Convert a FX_ARGB to a FX_COLORREF.
45FX_COLORREF ARGBToColorRef(FX_ARGB argb) {
46 return (((static_cast<uint32_t>(argb) & 0x00FF0000) >> 16) |
47 (static_cast<uint32_t>(argb) & 0x0000FF00) |
48 ((static_cast<uint32_t>(argb) & 0x000000FF) << 16));
49}
50
51} // namespace
52
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
54 CPDFSDK_PageView* pPageView,
55 CPDFSDK_InterForm* pInterForm)
56 : CPDFSDK_BAAnnot(pAnnot, pPageView),
57 m_pInterForm(pInterForm),
58 m_nAppAge(0),
Tom Sepez40e9ff32015-11-30 12:39:54 -080059 m_nValueAge(0)
60#ifdef PDF_ENABLE_XFA
61 ,
thestig1cd352e2016-06-07 17:53:06 -070062 m_hMixXFAWidget(nullptr),
63 m_pWidgetHandler(nullptr)
Tom Sepez40e9ff32015-11-30 12:39:54 -080064#endif // PDF_ENABLE_XFA
65{
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070066}
67
dsinclairce04a452016-09-07 05:46:55 -070068CPDFSDK_Widget::~CPDFSDK_Widget() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070069
Tom Sepez51da0932015-11-25 16:05:49 -080070#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -070071CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
Tom Sepez50d12ad2015-11-24 09:50:51 -080073 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
75 if (!m_hMixXFAWidget) {
dsinclairdf4bc592016-03-31 20:34:43 -070076 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070077 CFX_WideString sName;
Lei Zhang99766722016-02-23 11:21:48 -080078 if (GetFieldType() == FIELDTYPE_RADIOBUTTON) {
79 sName = GetAnnotName();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080 if (sName.IsEmpty())
81 sName = GetName();
Dan Sinclair738b08c2016-03-01 14:45:20 -050082 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083 sName = GetName();
Dan Sinclair738b08c2016-03-01 14:45:20 -050084 }
Bo Xufdc00a72014-10-28 23:03:33 -070085
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086 if (!sName.IsEmpty())
weilib4d1b572016-08-10 14:50:48 -070087 m_hMixXFAWidget = pDocView->GetWidgetByName(sName, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -070089 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070090 return m_hMixXFAWidget;
91 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070092
thestig1cd352e2016-06-07 17:53:06 -070093 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094}
95
dsinclairdf4bc592016-03-31 20:34:43 -070096CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
Tom Sepez50d12ad2015-11-24 09:50:51 -080098 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
dsinclairdf4bc592016-03-31 20:34:43 -0700100 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101 CFX_WideString sName = GetName();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102 if (!sName.IsEmpty())
weilib4d1b572016-08-10 14:50:48 -0700103 return pDocView->GetWidgetByName(sName, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 }
105 }
106
Tom Sepez50d12ad2015-11-24 09:50:51 -0800107 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108}
109
dsinclairdf4bc592016-03-31 20:34:43 -0700110CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700111 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800112 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113 if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) {
114 if (!m_pWidgetHandler) {
jaepark611adb82016-08-17 11:34:36 -0700115 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116 m_pWidgetHandler = pDocView->GetWidgetHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 }
118 return m_pWidgetHandler;
119 }
120
thestig1cd352e2016-06-07 17:53:06 -0700121 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700122}
123
124static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) {
125 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
126
127 switch (eXFAAAT) {
128 case PDFSDK_XFA_Click:
129 eEventType = XFA_EVENT_Click;
130 break;
131 case PDFSDK_XFA_Full:
132 eEventType = XFA_EVENT_Full;
133 break;
134 case PDFSDK_XFA_PreOpen:
135 eEventType = XFA_EVENT_PreOpen;
136 break;
137 case PDFSDK_XFA_PostOpen:
138 eEventType = XFA_EVENT_PostOpen;
139 break;
140 }
141
142 return eEventType;
143}
144
145static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT,
146 FX_BOOL bWillCommit) {
147 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
148
149 switch (eAAT) {
150 case CPDF_AAction::CursorEnter:
151 eEventType = XFA_EVENT_MouseEnter;
152 break;
153 case CPDF_AAction::CursorExit:
154 eEventType = XFA_EVENT_MouseExit;
155 break;
156 case CPDF_AAction::ButtonDown:
157 eEventType = XFA_EVENT_MouseDown;
158 break;
159 case CPDF_AAction::ButtonUp:
160 eEventType = XFA_EVENT_MouseUp;
161 break;
162 case CPDF_AAction::GetFocus:
163 eEventType = XFA_EVENT_Enter;
164 break;
165 case CPDF_AAction::LoseFocus:
166 eEventType = XFA_EVENT_Exit;
167 break;
168 case CPDF_AAction::PageOpen:
169 break;
170 case CPDF_AAction::PageClose:
171 break;
172 case CPDF_AAction::PageVisible:
173 break;
174 case CPDF_AAction::PageInvisible:
175 break;
176 case CPDF_AAction::KeyStroke:
jaepark611adb82016-08-17 11:34:36 -0700177 if (!bWillCommit)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 eEventType = XFA_EVENT_Change;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700179 break;
180 case CPDF_AAction::Validate:
181 eEventType = XFA_EVENT_Validate;
182 break;
183 case CPDF_AAction::OpenPage:
184 case CPDF_AAction::ClosePage:
185 case CPDF_AAction::Format:
186 case CPDF_AAction::Calculate:
187 case CPDF_AAction::CloseDocument:
188 case CPDF_AAction::SaveDocument:
189 case CPDF_AAction::DocumentSaved:
190 case CPDF_AAction::PrintDocument:
191 case CPDF_AAction::DocumentPrinted:
192 break;
193 }
194
195 return eEventType;
196}
197
198FX_BOOL CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) {
jaepark611adb82016-08-17 11:34:36 -0700199 CXFA_FFWidget* hWidget = GetMixXFAWidget();
200 if (!hWidget)
201 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202
jaepark611adb82016-08-17 11:34:36 -0700203 CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
204 if (!pXFAWidgetHandler)
205 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206
jaepark611adb82016-08-17 11:34:36 -0700207 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
208
209 CXFA_WidgetAcc* pAcc;
210 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
211 GetFieldType() == FIELDTYPE_RADIOBUTTON) {
212 if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) {
213 pAcc = hGroupWidget->GetDataAcc();
214 if (pXFAWidgetHandler->HasEvent(pAcc, eEventType))
215 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216 }
217 }
218
jaepark611adb82016-08-17 11:34:36 -0700219 pAcc = hWidget->GetDataAcc();
220 return pXFAWidgetHandler->HasEvent(pAcc, eEventType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221}
222
223FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
224 PDFSDK_FieldAction& data,
225 CPDFSDK_PageView* pPageView) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700226 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800227 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228
jaepark611adb82016-08-17 11:34:36 -0700229 CXFA_FFWidget* hWidget = GetMixXFAWidget();
230 if (!hWidget)
231 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700232
jaepark611adb82016-08-17 11:34:36 -0700233 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
234 if (eEventType == XFA_EVENT_Unknown)
235 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236
jaepark611adb82016-08-17 11:34:36 -0700237 CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
238 if (!pXFAWidgetHandler)
239 return FALSE;
240
241 CXFA_EventParam param;
242 param.m_eType = eEventType;
243 param.m_wsChange = data.sChange;
244 param.m_iCommitKey = data.nCommitKey;
245 param.m_bShift = data.bShift;
246 param.m_iSelStart = data.nSelStart;
247 param.m_iSelEnd = data.nSelEnd;
248 param.m_wsFullText = data.sValue;
249 param.m_bKeyDown = data.bKeyDown;
250 param.m_bModifier = data.bModifier;
251 param.m_wsNewText = data.sValue;
252 if (data.nSelEnd > data.nSelStart)
253 param.m_wsNewText.Delete(data.nSelStart, data.nSelEnd - data.nSelStart);
254
255 for (int i = 0; i < data.sChange.GetLength(); i++)
256 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
257 param.m_wsPrevText = data.sValue;
258
259 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
260 GetFieldType() == FIELDTYPE_RADIOBUTTON) {
261 if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) {
262 CXFA_WidgetAcc* pAcc = hGroupWidget->GetDataAcc();
263 param.m_pTarget = pAcc;
264 if (pXFAWidgetHandler->ProcessEvent(pAcc, &param) !=
265 XFA_EVENTERROR_Success) {
266 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700267 }
268 }
269 }
jaepark611adb82016-08-17 11:34:36 -0700270 CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc();
271 param.m_pTarget = pAcc;
272 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700273
jaepark611adb82016-08-17 11:34:36 -0700274 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView())
275 pDocView->UpdateDocView();
276
277 return nRet == XFA_EVENTERROR_Success;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700278}
279
280void CPDFSDK_Widget::Synchronize(FX_BOOL bSynchronizeElse) {
jaepark611adb82016-08-17 11:34:36 -0700281 CXFA_FFWidget* hWidget = GetMixXFAWidget();
282 if (!hWidget)
283 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700284
jaepark611adb82016-08-17 11:34:36 -0700285 CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc();
286 if (!pWidgetAcc)
287 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288
jaepark611adb82016-08-17 11:34:36 -0700289 CPDF_FormField* pFormField = GetFormField();
290 switch (GetFieldType()) {
291 case FIELDTYPE_CHECKBOX:
292 case FIELDTYPE_RADIOBUTTON: {
293 CPDF_FormControl* pFormCtrl = GetFormControl();
294 XFA_CHECKSTATE eCheckState =
295 pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off;
296 pWidgetAcc->SetCheckState(eCheckState, true);
297 break;
298 }
299 case FIELDTYPE_TEXTFIELD:
300 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
301 break;
302 case FIELDTYPE_LISTBOX: {
303 pWidgetAcc->ClearAllSelections();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700304
jaepark611adb82016-08-17 11:34:36 -0700305 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
306 int nIndex = pFormField->GetSelectedIndex(i);
307 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
308 pWidgetAcc->SetItemState(nIndex, TRUE, false, FALSE, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 }
jaepark611adb82016-08-17 11:34:36 -0700310 break;
311 }
312 case FIELDTYPE_COMBOBOX: {
313 pWidgetAcc->ClearAllSelections();
dsinclair221caf62016-04-04 12:08:40 -0700314
jaepark611adb82016-08-17 11:34:36 -0700315 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
316 int nIndex = pFormField->GetSelectedIndex(i);
317 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
318 pWidgetAcc->SetItemState(nIndex, TRUE, false, FALSE, TRUE);
319 }
320 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
321 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700322 }
323 }
jaepark611adb82016-08-17 11:34:36 -0700324
325 if (bSynchronizeElse)
326 pWidgetAcc->ProcessValueChanged();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327}
328
329void CPDFSDK_Widget::SynchronizeXFAValue() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700330 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800331 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
dsinclairdf4bc592016-03-31 20:34:43 -0700332 CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333 if (!pXFADocView)
334 return;
335
dsinclairdf4bc592016-03-31 20:34:43 -0700336 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700337 if (GetXFAWidgetHandler()) {
338 CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(),
339 GetFormControl());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700340 }
341 }
342}
343
344void CPDFSDK_Widget::SynchronizeXFAItems() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700345 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800346 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
dsinclairdf4bc592016-03-31 20:34:43 -0700347 CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700348 if (!pXFADocView)
349 return;
350
dsinclairdf4bc592016-03-31 20:34:43 -0700351 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700352 if (GetXFAWidgetHandler())
353 SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 }
355}
356
dsinclairdf4bc592016-03-31 20:34:43 -0700357void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView,
358 CXFA_FFWidget* hWidget,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359 CPDF_FormField* pFormField,
360 CPDF_FormControl* pFormControl) {
Lei Zhang5eca3052016-02-22 20:32:21 -0800361 ASSERT(hWidget);
dsinclair221caf62016-04-04 12:08:40 -0700362 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700363
dsinclair221caf62016-04-04 12:08:40 -0700364 switch (pFormField->GetFieldType()) {
365 case FIELDTYPE_CHECKBOX: {
366 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
367 pFormField->CheckControl(
368 pFormField->GetControlIndex(pFormControl),
369 pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true);
370 }
jaepark611adb82016-08-17 11:34:36 -0700371 break;
372 }
dsinclair221caf62016-04-04 12:08:40 -0700373 case FIELDTYPE_RADIOBUTTON: {
374 // TODO(weili): Check whether we need to handle checkbox and radio
375 // button differently, otherwise, merge these two cases.
376 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
377 pFormField->CheckControl(
378 pFormField->GetControlIndex(pFormControl),
379 pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true);
380 }
jaepark611adb82016-08-17 11:34:36 -0700381 break;
382 }
dsinclair221caf62016-04-04 12:08:40 -0700383 case FIELDTYPE_TEXTFIELD: {
384 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
385 CFX_WideString sValue;
386 pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
387 pFormField->SetValue(sValue, TRUE);
388 }
jaepark611adb82016-08-17 11:34:36 -0700389 break;
390 }
dsinclair221caf62016-04-04 12:08:40 -0700391 case FIELDTYPE_LISTBOX: {
392 pFormField->ClearSelection(FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700393
dsinclair221caf62016-04-04 12:08:40 -0700394 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
395 for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
396 int nIndex = pWidgetAcc->GetSelectedItem(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700397
dsinclair221caf62016-04-04 12:08:40 -0700398 if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
399 pFormField->SetItemSelection(nIndex, TRUE, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700400 }
401 }
dsinclair221caf62016-04-04 12:08:40 -0700402 }
jaepark611adb82016-08-17 11:34:36 -0700403 break;
404 }
dsinclair221caf62016-04-04 12:08:40 -0700405 case FIELDTYPE_COMBOBOX: {
406 pFormField->ClearSelection(FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407
dsinclair221caf62016-04-04 12:08:40 -0700408 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
409 for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
410 int nIndex = pWidgetAcc->GetSelectedItem(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700411
dsinclair221caf62016-04-04 12:08:40 -0700412 if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
413 pFormField->SetItemSelection(nIndex, TRUE, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415 }
dsinclair221caf62016-04-04 12:08:40 -0700416
417 CFX_WideString sValue;
418 pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
419 pFormField->SetValue(sValue, TRUE);
420 }
jaepark611adb82016-08-17 11:34:36 -0700421 break;
422 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423 }
424}
425
dsinclairdf4bc592016-03-31 20:34:43 -0700426void CPDFSDK_Widget::SynchronizeXFAItems(CXFA_FFDocView* pXFADocView,
427 CXFA_FFWidget* hWidget,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428 CPDF_FormField* pFormField,
429 CPDF_FormControl* pFormControl) {
Lei Zhang5eca3052016-02-22 20:32:21 -0800430 ASSERT(hWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431
dsinclair221caf62016-04-04 12:08:40 -0700432 switch (pFormField->GetFieldType()) {
433 case FIELDTYPE_LISTBOX: {
434 pFormField->ClearSelection(FALSE);
435 pFormField->ClearOptions(TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436
dsinclair221caf62016-04-04 12:08:40 -0700437 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
438 for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz; i++) {
439 CFX_WideString swText;
440 pWidgetAcc->GetChoiceListItem(swText, i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700441
dsinclair221caf62016-04-04 12:08:40 -0700442 pFormField->InsertOption(swText, i, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443 }
dsinclair221caf62016-04-04 12:08:40 -0700444 }
jaepark611adb82016-08-17 11:34:36 -0700445 break;
446 }
dsinclair221caf62016-04-04 12:08:40 -0700447 case FIELDTYPE_COMBOBOX: {
448 pFormField->ClearSelection(FALSE);
449 pFormField->ClearOptions(FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450
dsinclair221caf62016-04-04 12:08:40 -0700451 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
452 for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz; i++) {
453 CFX_WideString swText;
454 pWidgetAcc->GetChoiceListItem(swText, i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455
dsinclair221caf62016-04-04 12:08:40 -0700456 pFormField->InsertOption(swText, i, FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700457 }
dsinclair221caf62016-04-04 12:08:40 -0700458 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700459
dsinclair221caf62016-04-04 12:08:40 -0700460 pFormField->SetValue(L"", TRUE);
jaepark611adb82016-08-17 11:34:36 -0700461 break;
462 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463 }
464}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800465#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466
467FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(
468 CPDF_Annot::AppearanceMode mode) {
dsinclair38fd8442016-09-15 10:15:32 -0700469 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700470 if (!pAP)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700471 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700472
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473 // Choose the right sub-ap
474 const FX_CHAR* ap_entry = "N";
475 if (mode == CPDF_Annot::Down)
476 ap_entry = "D";
477 else if (mode == CPDF_Annot::Rollover)
478 ap_entry = "R";
479 if (!pAP->KeyExist(ap_entry))
480 ap_entry = "N";
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700481
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482 // Get the AP stream or subdirectory
dsinclair38fd8442016-09-15 10:15:32 -0700483 CPDF_Object* psub = pAP->GetDirectObjectFor(ap_entry);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700484 if (!psub)
485 return FALSE;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700486
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700487 int nFieldType = GetFieldType();
488 switch (nFieldType) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700489 case FIELDTYPE_PUSHBUTTON:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700490 case FIELDTYPE_COMBOBOX:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700491 case FIELDTYPE_LISTBOX:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700492 case FIELDTYPE_TEXTFIELD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493 case FIELDTYPE_SIGNATURE:
Dan Sinclairaa435ba2015-10-22 16:45:48 -0400494 return psub->IsStream();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495 case FIELDTYPE_CHECKBOX:
496 case FIELDTYPE_RADIOBUTTON:
Dan Sinclairf1251c12015-10-20 16:24:45 -0400497 if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) {
dsinclair38fd8442016-09-15 10:15:32 -0700498 return !!pSubDict->GetStreamFor(GetAppState());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499 }
500 return FALSE;
501 }
502 return TRUE;
503}
504
505int CPDFSDK_Widget::GetFieldType() const {
dsinclair92828192016-08-17 13:28:51 -0700506 CPDF_FormField* pField = GetFormField();
507 return pField ? pField->GetFieldType() : FIELDTYPE_UNKNOWN;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508}
509
510FX_BOOL CPDFSDK_Widget::IsAppearanceValid() {
Tom Sepez51da0932015-11-25 16:05:49 -0800511#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700512 CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800513 CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514 int nDocType = pDoc->GetDocType();
Tom Sepez540c4362015-11-24 13:33:57 -0800515 if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA)
516 return TRUE;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800517#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800518 return CPDFSDK_BAAnnot::IsAppearanceValid();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700519}
520
weili625ad662016-06-15 11:21:33 -0700521int CPDFSDK_Widget::GetLayoutOrder() const {
522 return 2;
523}
524
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525int CPDFSDK_Widget::GetFieldFlags() const {
526 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 CPDF_FormControl* pFormControl =
528 pPDFInterForm->GetControlByDict(m_pAnnot->GetAnnotDict());
529 CPDF_FormField* pFormField = pFormControl->GetField();
530 return pFormField->GetFieldFlags();
531}
532
jaepark9ed91372016-08-26 16:16:10 -0700533bool CPDFSDK_Widget::IsSignatureWidget() const {
534 return GetFieldType() == FIELDTYPE_SIGNATURE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535}
536
537CPDF_FormField* CPDFSDK_Widget::GetFormField() const {
dsinclair92828192016-08-17 13:28:51 -0700538 CPDF_FormControl* pControl = GetFormControl();
539 return pControl ? pControl->GetField() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540}
541
542CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700543 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544 return pPDFInterForm->GetControlByDict(GetAnnotDict());
545}
546
Lei Zhang1b700c32015-10-30 23:55:35 -0700547CPDF_FormControl* CPDFSDK_Widget::GetFormControl(
548 CPDF_InterForm* pInterForm,
549 const CPDF_Dictionary* pAnnotDict) {
Lei Zhang96660d62015-12-14 18:27:25 -0800550 ASSERT(pAnnotDict);
Lei Zhang1b700c32015-10-30 23:55:35 -0700551 return pInterForm->GetControlByDict(pAnnotDict);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552}
553
554int CPDFSDK_Widget::GetRotate() const {
555 CPDF_FormControl* pCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700556 return pCtrl->GetRotation() % 360;
557}
558
Tom Sepez51da0932015-11-25 16:05:49 -0800559#ifdef PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700560CFX_WideString CPDFSDK_Widget::GetName() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562 return pFormField->GetFullName();
563}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800564#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565
566FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const {
567 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700568 int iColorType = 0;
dsinclair72177da2016-09-15 12:07:23 -0700569 color = ARGBToColorRef(pFormCtrl->GetBackgroundColor(iColorType));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570 return iColorType != COLORTYPE_TRANSPARENT;
571}
572
573FX_BOOL CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const {
574 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575 int iColorType = 0;
dsinclair72177da2016-09-15 12:07:23 -0700576 color = ARGBToColorRef(pFormCtrl->GetBorderColor(iColorType));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700577 return iColorType != COLORTYPE_TRANSPARENT;
578}
579
580FX_BOOL CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const {
581 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700582 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
jaepark611adb82016-08-17 11:34:36 -0700583 if (!da.HasColor())
584 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585
jaepark611adb82016-08-17 11:34:36 -0700586 FX_ARGB argb;
587 int iColorType = COLORTYPE_TRANSPARENT;
588 da.GetColor(argb, iColorType);
dsinclair72177da2016-09-15 12:07:23 -0700589 color = ARGBToColorRef(argb);
jaepark611adb82016-08-17 11:34:36 -0700590 return iColorType != COLORTYPE_TRANSPARENT;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591}
592
593FX_FLOAT CPDFSDK_Widget::GetFontSize() const {
594 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700595 CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
596 CFX_ByteString csFont = "";
597 FX_FLOAT fFontSize = 0.0f;
598 pDa.GetFont(csFont, fFontSize);
599
600 return fFontSize;
601}
602
Tom Sepezbf59a072015-10-21 14:07:23 -0700603int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700604#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700605 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700606 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
607 if (nIndex < pWidgetAcc->CountSelectedItems())
608 return pWidgetAcc->GetSelectedItem(nIndex);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700609 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700610 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700611#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700613 return pFormField->GetSelectedIndex(nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700614}
615
Tom Sepeza8a39e22015-10-12 15:47:07 -0700616#ifdef PDF_ENABLE_XFA
Tom Sepez40e9ff32015-11-30 12:39:54 -0800617CFX_WideString CPDFSDK_Widget::GetValue(FX_BOOL bDisplay) const {
dsinclairdf4bc592016-03-31 20:34:43 -0700618 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700619 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
620 CFX_WideString sValue;
621 pWidgetAcc->GetValue(
622 sValue, bDisplay ? XFA_VALUEPICTURE_Display : XFA_VALUEPICTURE_Edit);
623 return sValue;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700624 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700625 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800626#else
627CFX_WideString CPDFSDK_Widget::GetValue() const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700628#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700629 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630 return pFormField->GetValue();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700631}
632
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633CFX_WideString CPDFSDK_Widget::GetDefaultValue() const {
634 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700635 return pFormField->GetDefaultValue();
636}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700637
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700638CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const {
639 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700640 return pFormField->GetOptionLabel(nIndex);
641}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700642
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700643int CPDFSDK_Widget::CountOptions() const {
644 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700645 return pFormField->CountOptions();
646}
647
Tom Sepezbf59a072015-10-21 14:07:23 -0700648FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700649#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700650 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700651 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
652 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
653 return pWidgetAcc->GetItemState(nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700654
dsinclair221caf62016-04-04 12:08:40 -0700655 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700656 }
657 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700658#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700659 CPDF_FormField* pFormField = GetFormField();
660 return pFormField->IsItemSelected(nIndex);
661}
662
663int CPDFSDK_Widget::GetTopVisibleIndex() const {
664 CPDF_FormField* pFormField = GetFormField();
665 return pFormField->GetTopVisibleIndex();
666}
667
Wei Li97da9762016-03-11 17:00:48 -0800668bool CPDFSDK_Widget::IsChecked() const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700669#ifdef PDF_ENABLE_XFA
dsinclair221caf62016-04-04 12:08:40 -0700670 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
671 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc())
672 return pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700673 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700674#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700676 return pFormCtrl->IsChecked();
677}
678
679int CPDFSDK_Widget::GetAlignment() const {
680 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681 return pFormCtrl->GetControlAlignment();
682}
683
684int CPDFSDK_Widget::GetMaxLen() const {
685 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686 return pFormField->GetMaxLen();
687}
688
Wei Li97da9762016-03-11 17:00:48 -0800689void CPDFSDK_Widget::SetCheck(bool bChecked, bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691 CPDF_FormField* pFormField = pFormCtrl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692 pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
693 bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800694#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700695 if (!IsWidgetAppearanceValid(CPDF_Annot::Normal))
696 ResetAppearance(TRUE);
697 if (!bNotify)
698 Synchronize(TRUE);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800699#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700700}
701
702void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify) {
703 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700704 pFormField->SetValue(sValue, bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800705#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700706 if (!bNotify)
707 Synchronize(TRUE);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800708#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709}
710
711void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {}
712void CPDFSDK_Widget::SetOptionSelection(int index,
713 FX_BOOL bSelected,
714 FX_BOOL bNotify) {
715 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700716 pFormField->SetItemSelection(index, bSelected, bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800717#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 if (!bNotify)
719 Synchronize(TRUE);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800720#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721}
722
723void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify) {
724 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725 pFormField->ClearSelection(bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800726#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700727 if (!bNotify)
728 Synchronize(TRUE);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800729#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700730}
731
732void CPDFSDK_Widget::SetTopVisibleIndex(int index) {}
733
734void CPDFSDK_Widget::SetAppModified() {
735 m_bAppModified = TRUE;
736}
737
738void CPDFSDK_Widget::ClearAppModified() {
739 m_bAppModified = FALSE;
740}
741
742FX_BOOL CPDFSDK_Widget::IsAppModified() const {
743 return m_bAppModified;
744}
745
Tom Sepez51da0932015-11-25 16:05:49 -0800746#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) {
748 switch (GetFieldType()) {
749 case FIELDTYPE_TEXTFIELD:
750 case FIELDTYPE_COMBOBOX: {
tsepez8c2a8cd2016-09-07 15:29:11 -0700751 FX_BOOL bFormatted = FALSE;
752 CFX_WideString sValue = OnFormat(bFormatted);
tsepeza31da742016-09-08 11:28:14 -0700753 ResetAppearance(bFormatted ? &sValue : nullptr, TRUE);
jaepark611adb82016-08-17 11:34:36 -0700754 break;
755 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700756 default:
Lei Zhang99766722016-02-23 11:21:48 -0800757 ResetAppearance(nullptr, FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758 break;
759 }
760}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800761#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700762
tsepeza31da742016-09-08 11:28:14 -0700763void CPDFSDK_Widget::ResetAppearance(const CFX_WideString* sValue,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700764 FX_BOOL bValueChanged) {
765 SetAppModified();
766
767 m_nAppAge++;
768 if (m_nAppAge > 999999)
769 m_nAppAge = 0;
770 if (bValueChanged)
771 m_nValueAge++;
772
773 int nFieldType = GetFieldType();
774
775 switch (nFieldType) {
776 case FIELDTYPE_PUSHBUTTON:
777 ResetAppearance_PushButton();
778 break;
779 case FIELDTYPE_CHECKBOX:
780 ResetAppearance_CheckBox();
781 break;
782 case FIELDTYPE_RADIOBUTTON:
783 ResetAppearance_RadioButton();
784 break;
785 case FIELDTYPE_COMBOBOX:
786 ResetAppearance_ComboBox(sValue);
787 break;
788 case FIELDTYPE_LISTBOX:
789 ResetAppearance_ListBox();
790 break;
791 case FIELDTYPE_TEXTFIELD:
792 ResetAppearance_TextField(sValue);
793 break;
794 }
795
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700796 m_pAnnot->ClearCachedAP();
797}
798
tsepez8c2a8cd2016-09-07 15:29:11 -0700799CFX_WideString CPDFSDK_Widget::OnFormat(FX_BOOL& bFormatted) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700800 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800801 ASSERT(pFormField);
tsepez8c2a8cd2016-09-07 15:29:11 -0700802 return m_pInterForm->OnFormat(pFormField, bFormatted);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700803}
804
805void CPDFSDK_Widget::ResetFieldAppearance(FX_BOOL bValueChanged) {
806 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800807 ASSERT(pFormField);
thestig1cd352e2016-06-07 17:53:06 -0700808 m_pInterForm->ResetFieldAppearance(pFormField, nullptr, bValueChanged);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700809}
810
811void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800812 const CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700813 CPDF_Annot::AppearanceMode mode,
814 const CPDF_RenderOptions* pOptions) {
815 int nFieldType = GetFieldType();
816
817 if ((nFieldType == FIELDTYPE_CHECKBOX ||
818 nFieldType == FIELDTYPE_RADIOBUTTON) &&
819 mode == CPDF_Annot::Normal &&
820 !IsWidgetAppearanceValid(CPDF_Annot::Normal)) {
821 CFX_PathData pathData;
822
Tom Sepez281a9ea2016-02-26 14:24:28 -0800823 CFX_FloatRect rcAnnot = GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700824
825 pathData.AppendRect(rcAnnot.left, rcAnnot.bottom, rcAnnot.right,
826 rcAnnot.top);
827
828 CFX_GraphStateData gsd;
829 gsd.m_LineWidth = 0.0f;
830
831 pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA,
832 FXFILL_ALTERNATE);
833 } else {
834 CPDFSDK_BAAnnot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);
835 }
836}
837
838void CPDFSDK_Widget::UpdateField() {
839 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800840 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700841 m_pInterForm->UpdateField(pFormField);
842}
843
844void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
845 CPDFSDK_PageView* pPageView) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700846 int nFieldType = GetFieldType();
jaepark611adb82016-08-17 11:34:36 -0700847 if (!m_pInterForm->IsNeedHighLight(nFieldType))
848 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700849
jaepark611adb82016-08-17 11:34:36 -0700850 CFX_FloatRect rc = GetRect();
851 FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);
852 uint8_t alpha = m_pInterForm->GetHighlightAlpha();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700853
jaepark611adb82016-08-17 11:34:36 -0700854 CFX_FloatRect rcDevice;
855 ASSERT(m_pInterForm->GetDocument());
dsinclair79db6092016-09-14 07:27:21 -0700856 CPDFSDK_Environment* pEnv = m_pInterForm->GetDocument()->GetEnv();
jaepark611adb82016-08-17 11:34:36 -0700857 if (!pEnv)
858 return;
859 CFX_Matrix page2device;
860 pPageView->GetCurrentMatrix(page2device);
861 page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom),
862 rcDevice.left, rcDevice.bottom);
863 page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top),
864 rcDevice.right, rcDevice.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700865
jaepark611adb82016-08-17 11:34:36 -0700866 rcDevice.Normalize();
867
868 FX_ARGB argb = ArgbEncode((int)alpha, color);
869 FX_RECT rcDev((int)rcDevice.left, (int)rcDevice.top, (int)rcDevice.right,
870 (int)rcDevice.bottom);
871 pDevice->FillRect(&rcDev, argb);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700872}
873
874void CPDFSDK_Widget::ResetAppearance_PushButton() {
875 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800876 CFX_FloatRect rcWindow = GetRotatedRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700877 int32_t nLayout = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700878 switch (pControl->GetTextPosition()) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700879 case TEXTPOS_ICON:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700880 nLayout = PPBL_ICON;
881 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700882 case TEXTPOS_BELOW:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700883 nLayout = PPBL_ICONTOPLABELBOTTOM;
884 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700885 case TEXTPOS_ABOVE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700886 nLayout = PPBL_LABELTOPICONBOTTOM;
887 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700888 case TEXTPOS_RIGHT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700889 nLayout = PPBL_ICONLEFTLABELRIGHT;
890 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700891 case TEXTPOS_LEFT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700892 nLayout = PPBL_LABELLEFTICONRIGHT;
893 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700894 case TEXTPOS_OVERLAID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700895 nLayout = PPBL_LABELOVERICON;
896 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700897 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700898 nLayout = PPBL_LABEL;
899 break;
900 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700901
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700902 CPWL_Color crBackground, crBorder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700903
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700904 int iColorType;
905 FX_FLOAT fc[4];
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700906
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700907 pControl->GetOriginalBackgroundColor(iColorType, fc);
908 if (iColorType > 0)
909 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700910
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700911 pControl->GetOriginalBorderColor(iColorType, fc);
912 if (iColorType > 0)
913 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700914
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700915 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700916 CPWL_Dash dsBorder(3, 0, 0);
917 CPWL_Color crLeftTop, crRightBottom;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700918
dsinclair92cb5e52016-05-16 11:38:28 -0700919 BorderStyle nBorderStyle = GetBorderStyle();
920 switch (nBorderStyle) {
921 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700922 dsBorder = CPWL_Dash(3, 3, 0);
923 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700924 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700925 fBorderWidth *= 2;
926 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
927 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
928 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700929 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700930 fBorderWidth *= 2;
931 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
932 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
933 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700934 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700935 break;
936 }
937
Tom Sepez281a9ea2016-02-26 14:24:28 -0800938 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700939
940 CPWL_Color crText(COLORTYPE_GRAY, 0);
941
942 FX_FLOAT fFontSize = 12.0f;
943 CFX_ByteString csNameTag;
944
945 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
946 if (da.HasColor()) {
947 da.GetColor(iColorType, fc);
948 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
949 }
950
951 if (da.HasFont())
952 da.GetFont(csNameTag, fFontSize);
953
954 CFX_WideString csWCaption;
955 CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption;
956
jaepark611adb82016-08-17 11:34:36 -0700957 if (pControl->HasMKEntry("CA"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700958 csNormalCaption = pControl->GetNormalCaption();
jaepark611adb82016-08-17 11:34:36 -0700959
960 if (pControl->HasMKEntry("RC"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700961 csRolloverCaption = pControl->GetRolloverCaption();
jaepark611adb82016-08-17 11:34:36 -0700962
963 if (pControl->HasMKEntry("AC"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700964 csDownCaption = pControl->GetDownCaption();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700965
thestig1cd352e2016-06-07 17:53:06 -0700966 CPDF_Stream* pNormalIcon = nullptr;
967 CPDF_Stream* pRolloverIcon = nullptr;
968 CPDF_Stream* pDownIcon = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700969
jaepark611adb82016-08-17 11:34:36 -0700970 if (pControl->HasMKEntry("I"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700971 pNormalIcon = pControl->GetNormalIcon();
jaepark611adb82016-08-17 11:34:36 -0700972
973 if (pControl->HasMKEntry("RI"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700974 pRolloverIcon = pControl->GetRolloverIcon();
jaepark611adb82016-08-17 11:34:36 -0700975
976 if (pControl->HasMKEntry("IX"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700977 pDownIcon = pControl->GetDownIcon();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700978
979 if (pNormalIcon) {
980 if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -0700981 if (pImageDict->GetStringFor("Name").IsEmpty())
982 pImageDict->SetStringFor("Name", "ImgA");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700983 }
984 }
985
986 if (pRolloverIcon) {
987 if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -0700988 if (pImageDict->GetStringFor("Name").IsEmpty())
989 pImageDict->SetStringFor("Name", "ImgB");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700990 }
991 }
992
993 if (pDownIcon) {
994 if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -0700995 if (pImageDict->GetStringFor("Name").IsEmpty())
996 pImageDict->SetStringFor("Name", "ImgC");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700997 }
998 }
999
1000 CPDF_IconFit iconFit = pControl->GetIconFit();
1001
1002 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
dsinclair79db6092016-09-14 07:27:21 -07001003 CPDFSDK_Environment* pEnv = pDoc->GetEnv();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001004
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001005 CBA_FontMap font_map(this, pEnv->GetSysHandler());
1006 font_map.SetAPType("N");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001007
1008 CFX_ByteString csAP =
1009 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1010 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1011 crLeftTop, crRightBottom, nBorderStyle,
1012 dsBorder) +
1013 CPWL_Utils::GetPushButtonAppStream(
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001014 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001015 pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout);
1016
1017 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP);
1018 if (pNormalIcon)
1019 AddImageToAppearance("N", pNormalIcon);
1020
1021 CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode();
1022 if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) {
1023 if (csRolloverCaption.IsEmpty() && !pRolloverIcon) {
1024 csRolloverCaption = csNormalCaption;
1025 pRolloverIcon = pNormalIcon;
1026 }
1027
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001028 font_map.SetAPType("R");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001029
1030 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1031 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1032 crLeftTop, crRightBottom,
1033 nBorderStyle, dsBorder) +
1034 CPWL_Utils::GetPushButtonAppStream(
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001035 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001036 pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize,
1037 nLayout);
1038
1039 WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP);
1040 if (pRolloverIcon)
1041 AddImageToAppearance("R", pRolloverIcon);
1042
1043 if (csDownCaption.IsEmpty() && !pDownIcon) {
1044 csDownCaption = csNormalCaption;
1045 pDownIcon = pNormalIcon;
1046 }
1047
1048 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -07001049 case BorderStyle::BEVELED: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001050 CPWL_Color crTemp = crLeftTop;
1051 crLeftTop = crRightBottom;
1052 crRightBottom = crTemp;
dsinclair92cb5e52016-05-16 11:38:28 -07001053 break;
1054 }
1055 case BorderStyle::INSET: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001056 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1057 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001058 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001059 }
1060 default:
1061 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001062 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001063
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001064 font_map.SetAPType("D");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001065
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001066 csAP = CPWL_Utils::GetRectFillAppStream(
1067 rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) +
1068 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1069 crLeftTop, crRightBottom,
1070 nBorderStyle, dsBorder) +
1071 CPWL_Utils::GetPushButtonAppStream(
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001072 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001073 pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001074
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001075 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001076 if (pDownIcon)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001077 AddImageToAppearance("D", pDownIcon);
1078 } else {
1079 RemoveAppearance("D");
1080 RemoveAppearance("R");
1081 }
1082}
1083
1084void CPDFSDK_Widget::ResetAppearance_CheckBox() {
1085 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001086 CPWL_Color crBackground, crBorder, crText;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001087 int iColorType;
1088 FX_FLOAT fc[4];
1089
1090 pControl->GetOriginalBackgroundColor(iColorType, fc);
1091 if (iColorType > 0)
1092 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1093
1094 pControl->GetOriginalBorderColor(iColorType, fc);
1095 if (iColorType > 0)
1096 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1097
1098 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001099 CPWL_Dash dsBorder(3, 0, 0);
1100 CPWL_Color crLeftTop, crRightBottom;
1101
dsinclair92cb5e52016-05-16 11:38:28 -07001102 BorderStyle nBorderStyle = GetBorderStyle();
1103 switch (nBorderStyle) {
1104 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001105 dsBorder = CPWL_Dash(3, 3, 0);
1106 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001107 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001108 fBorderWidth *= 2;
1109 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1110 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
1111 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001112 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001113 fBorderWidth *= 2;
1114 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1115 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1116 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001117 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001118 break;
1119 }
1120
Tom Sepez281a9ea2016-02-26 14:24:28 -08001121 CFX_FloatRect rcWindow = GetRotatedRect();
1122 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001123
1124 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
1125 if (da.HasColor()) {
1126 da.GetColor(iColorType, fc);
1127 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1128 }
1129
1130 int32_t nStyle = 0;
1131
1132 CFX_WideString csWCaption = pControl->GetNormalCaption();
1133 if (csWCaption.GetLength() > 0) {
1134 switch (csWCaption[0]) {
1135 case L'l':
1136 nStyle = PCS_CIRCLE;
1137 break;
1138 case L'8':
1139 nStyle = PCS_CROSS;
1140 break;
1141 case L'u':
1142 nStyle = PCS_DIAMOND;
1143 break;
1144 case L'n':
1145 nStyle = PCS_SQUARE;
1146 break;
1147 case L'H':
1148 nStyle = PCS_STAR;
1149 break;
1150 default: // L'4'
1151 nStyle = PCS_CHECK;
1152 break;
1153 }
1154 } else {
1155 nStyle = PCS_CHECK;
1156 }
1157
1158 CFX_ByteString csAP_N_ON =
1159 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1160 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1161 crLeftTop, crRightBottom, nBorderStyle,
1162 dsBorder);
1163
1164 CFX_ByteString csAP_N_OFF = csAP_N_ON;
1165
1166 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -07001167 case BorderStyle::BEVELED: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001168 CPWL_Color crTemp = crLeftTop;
1169 crLeftTop = crRightBottom;
1170 crRightBottom = crTemp;
dsinclair92cb5e52016-05-16 11:38:28 -07001171 break;
1172 }
1173 case BorderStyle::INSET: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001174 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1175 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1176 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001177 }
1178 default:
1179 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001180 }
1181
1182 CFX_ByteString csAP_D_ON =
1183 CPWL_Utils::GetRectFillAppStream(
1184 rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) +
1185 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1186 crLeftTop, crRightBottom, nBorderStyle,
1187 dsBorder);
1188
1189 CFX_ByteString csAP_D_OFF = csAP_D_ON;
1190
1191 csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
1192 csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
1193
1194 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
1195 pControl->GetCheckedAPState());
1196 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
1197
1198 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
1199 pControl->GetCheckedAPState());
1200 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
1201
1202 CFX_ByteString csAS = GetAppState();
1203 if (csAS.IsEmpty())
1204 SetAppState("Off");
1205}
1206
1207void CPDFSDK_Widget::ResetAppearance_RadioButton() {
1208 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001209 CPWL_Color crBackground, crBorder, crText;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001210 int iColorType;
1211 FX_FLOAT fc[4];
1212
1213 pControl->GetOriginalBackgroundColor(iColorType, fc);
1214 if (iColorType > 0)
1215 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1216
1217 pControl->GetOriginalBorderColor(iColorType, fc);
1218 if (iColorType > 0)
1219 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1220
1221 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001222 CPWL_Dash dsBorder(3, 0, 0);
1223 CPWL_Color crLeftTop, crRightBottom;
1224
dsinclair92cb5e52016-05-16 11:38:28 -07001225 BorderStyle nBorderStyle = GetBorderStyle();
1226 switch (nBorderStyle) {
1227 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001228 dsBorder = CPWL_Dash(3, 3, 0);
1229 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001230 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001231 fBorderWidth *= 2;
1232 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1233 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
1234 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001235 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001236 fBorderWidth *= 2;
1237 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1238 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1239 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001240 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001241 break;
1242 }
1243
Tom Sepez281a9ea2016-02-26 14:24:28 -08001244 CFX_FloatRect rcWindow = GetRotatedRect();
1245 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001246
1247 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
1248 if (da.HasColor()) {
1249 da.GetColor(iColorType, fc);
1250 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1251 }
1252
1253 int32_t nStyle = 0;
1254
1255 CFX_WideString csWCaption = pControl->GetNormalCaption();
1256 if (csWCaption.GetLength() > 0) {
1257 switch (csWCaption[0]) {
1258 default: // L'l':
1259 nStyle = PCS_CIRCLE;
1260 break;
1261 case L'8':
1262 nStyle = PCS_CROSS;
1263 break;
1264 case L'u':
1265 nStyle = PCS_DIAMOND;
1266 break;
1267 case L'n':
1268 nStyle = PCS_SQUARE;
1269 break;
1270 case L'H':
1271 nStyle = PCS_STAR;
1272 break;
1273 case L'4':
1274 nStyle = PCS_CHECK;
1275 break;
1276 }
1277 } else {
1278 nStyle = PCS_CIRCLE;
1279 }
1280
1281 CFX_ByteString csAP_N_ON;
1282
Tom Sepez281a9ea2016-02-26 14:24:28 -08001283 CFX_FloatRect rcCenter =
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001284 CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f);
1285
1286 if (nStyle == PCS_CIRCLE) {
dsinclair92cb5e52016-05-16 11:38:28 -07001287 if (nBorderStyle == BorderStyle::BEVELED) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001288 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1289 crRightBottom = CPWL_Utils::SubstractColor(crBackground, 0.25f);
dsinclair92cb5e52016-05-16 11:38:28 -07001290 } else if (nBorderStyle == BorderStyle::INSET) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001291 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5f);
1292 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75f);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001293 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001294
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001295 csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBackground) +
1296 CPWL_Utils::GetCircleBorderAppStream(
1297 rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
1298 nBorderStyle, dsBorder);
1299 } else {
1300 csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1301 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1302 crLeftTop, crRightBottom,
1303 nBorderStyle, dsBorder);
1304 }
1305
1306 CFX_ByteString csAP_N_OFF = csAP_N_ON;
1307
1308 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -07001309 case BorderStyle::BEVELED: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001310 CPWL_Color crTemp = crLeftTop;
1311 crLeftTop = crRightBottom;
1312 crRightBottom = crTemp;
dsinclair92cb5e52016-05-16 11:38:28 -07001313 break;
1314 }
1315 case BorderStyle::INSET: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001316 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1317 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1318 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001319 }
1320 default:
1321 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001322 }
1323
1324 CFX_ByteString csAP_D_ON;
1325
1326 if (nStyle == PCS_CIRCLE) {
1327 CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground, 0.25f);
dsinclair92cb5e52016-05-16 11:38:28 -07001328 if (nBorderStyle == BorderStyle::BEVELED) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001329 crLeftTop = CPWL_Utils::SubstractColor(crBackground, 0.25f);
1330 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1331 crBK = crBackground;
dsinclair92cb5e52016-05-16 11:38:28 -07001332 } else if (nBorderStyle == BorderStyle::INSET) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001333 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1334 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1335 }
1336
1337 csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBK) +
1338 CPWL_Utils::GetCircleBorderAppStream(
1339 rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
1340 nBorderStyle, dsBorder);
1341 } else {
1342 csAP_D_ON = CPWL_Utils::GetRectFillAppStream(
1343 rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) +
1344 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1345 crLeftTop, crRightBottom,
1346 nBorderStyle, dsBorder);
1347 }
1348
1349 CFX_ByteString csAP_D_OFF = csAP_D_ON;
1350
1351 csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
1352 csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
1353
1354 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
1355 pControl->GetCheckedAPState());
1356 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
1357
1358 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
1359 pControl->GetCheckedAPState());
1360 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
1361
1362 CFX_ByteString csAS = GetAppState();
1363 if (csAS.IsEmpty())
1364 SetAppState("Off");
1365}
1366
tsepeza31da742016-09-08 11:28:14 -07001367void CPDFSDK_Widget::ResetAppearance_ComboBox(const CFX_WideString* sValue) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001368 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001369 CPDF_FormField* pField = pControl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001370 CFX_ByteTextBuf sBody, sLines;
1371
Tom Sepez281a9ea2016-02-26 14:24:28 -08001372 CFX_FloatRect rcClient = GetClientRect();
1373 CFX_FloatRect rcButton = rcClient;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001374 rcButton.left = rcButton.right - 13;
1375 rcButton.Normalize();
1376
dsinclaire35af1e2016-07-13 11:26:20 -07001377 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit);
thestig732f6a02016-05-12 10:41:56 -07001378 pEdit->EnableRefresh(FALSE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001379
thestig732f6a02016-05-12 10:41:56 -07001380 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
dsinclair79db6092016-09-14 07:27:21 -07001381 CPDFSDK_Environment* pEnv = pDoc->GetEnv();
thestig732f6a02016-05-12 10:41:56 -07001382 CBA_FontMap font_map(this, pEnv->GetSysHandler());
1383 pEdit->SetFontMap(&font_map);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001384
thestig732f6a02016-05-12 10:41:56 -07001385 CFX_FloatRect rcEdit = rcClient;
1386 rcEdit.right = rcButton.left;
1387 rcEdit.Normalize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001388
thestig732f6a02016-05-12 10:41:56 -07001389 pEdit->SetPlateRect(rcEdit);
dsinclairefd5a992016-07-18 10:04:07 -07001390 pEdit->SetAlignmentV(1, TRUE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001391
thestig732f6a02016-05-12 10:41:56 -07001392 FX_FLOAT fFontSize = GetFontSize();
1393 if (IsFloatZero(fFontSize))
dsinclairefd5a992016-07-18 10:04:07 -07001394 pEdit->SetAutoFontSize(TRUE, TRUE);
thestig732f6a02016-05-12 10:41:56 -07001395 else
1396 pEdit->SetFontSize(fFontSize);
1397
1398 pEdit->Initialize();
1399
1400 if (sValue) {
tsepeza31da742016-09-08 11:28:14 -07001401 pEdit->SetText(*sValue);
thestig732f6a02016-05-12 10:41:56 -07001402 } else {
1403 int32_t nCurSel = pField->GetSelectedIndex(0);
thestig732f6a02016-05-12 10:41:56 -07001404 if (nCurSel < 0)
tsepez067990c2016-09-13 06:46:40 -07001405 pEdit->SetText(pField->GetValue());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001406 else
tsepez067990c2016-09-13 06:46:40 -07001407 pEdit->SetText(pField->GetOptionLabel(nCurSel));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001408 }
1409
thestig732f6a02016-05-12 10:41:56 -07001410 CFX_FloatRect rcContent = pEdit->GetContentRect();
1411
1412 CFX_ByteString sEdit =
tsepez63f545c2016-09-13 16:08:49 -07001413 CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_FloatPoint());
thestig732f6a02016-05-12 10:41:56 -07001414 if (sEdit.GetLength() > 0) {
1415 sBody << "/Tx BMC\n"
1416 << "q\n";
1417 if (rcContent.Width() > rcEdit.Width() ||
1418 rcContent.Height() > rcEdit.Height()) {
1419 sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width()
1420 << " " << rcEdit.Height() << " re\nW\nn\n";
1421 }
1422
1423 CPWL_Color crText = GetTextPWLColor();
1424 sBody << "BT\n"
1425 << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"
1426 << "Q\nEMC\n";
1427 }
1428
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001429 sBody << CPWL_Utils::GetDropButtonAppStream(rcButton);
1430
1431 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
tsepez8e4c5052016-04-14 13:42:44 -07001432 sLines.AsStringC() + sBody.AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001433
1434 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1435}
1436
1437void CPDFSDK_Widget::ResetAppearance_ListBox() {
1438 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001439 CPDF_FormField* pField = pControl->GetField();
Tom Sepez281a9ea2016-02-26 14:24:28 -08001440 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001441 CFX_ByteTextBuf sBody, sLines;
1442
dsinclaire35af1e2016-07-13 11:26:20 -07001443 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit);
thestig732f6a02016-05-12 10:41:56 -07001444 pEdit->EnableRefresh(FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001445
thestig732f6a02016-05-12 10:41:56 -07001446 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
dsinclair79db6092016-09-14 07:27:21 -07001447 CPDFSDK_Environment* pEnv = pDoc->GetEnv();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001448
thestig732f6a02016-05-12 10:41:56 -07001449 CBA_FontMap font_map(this, pEnv->GetSysHandler());
1450 pEdit->SetFontMap(&font_map);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001451
thestig732f6a02016-05-12 10:41:56 -07001452 pEdit->SetPlateRect(CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001453
thestig732f6a02016-05-12 10:41:56 -07001454 FX_FLOAT fFontSize = GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001455
thestig594b20b2016-05-12 21:56:43 -07001456 pEdit->SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001457
thestig732f6a02016-05-12 10:41:56 -07001458 pEdit->Initialize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001459
thestig732f6a02016-05-12 10:41:56 -07001460 CFX_ByteTextBuf sList;
1461 FX_FLOAT fy = rcClient.top;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001462
thestig732f6a02016-05-12 10:41:56 -07001463 int32_t nTop = pField->GetTopVisibleIndex();
1464 int32_t nCount = pField->CountOptions();
1465 int32_t nSelCount = pField->CountSelectedItems();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001466
thestig594b20b2016-05-12 21:56:43 -07001467 for (int32_t i = nTop; i < nCount; ++i) {
1468 bool bSelected = false;
1469 for (int32_t j = 0; j < nSelCount; ++j) {
thestig732f6a02016-05-12 10:41:56 -07001470 if (pField->GetSelectedIndex(j) == i) {
thestig594b20b2016-05-12 21:56:43 -07001471 bSelected = true;
thestig732f6a02016-05-12 10:41:56 -07001472 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001473 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001474 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001475
tsepez067990c2016-09-13 06:46:40 -07001476 pEdit->SetText(pField->GetOptionLabel(i));
thestig732f6a02016-05-12 10:41:56 -07001477
1478 CFX_FloatRect rcContent = pEdit->GetContentRect();
1479 FX_FLOAT fItemHeight = rcContent.Height();
1480
1481 if (bSelected) {
1482 CFX_FloatRect rcItem =
1483 CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy);
1484 sList << "q\n"
1485 << CPWL_Utils::GetColorAppStream(
1486 CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f,
1487 113.0f / 255.0f),
1488 TRUE)
1489 << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width()
1490 << " " << rcItem.Height() << " re f\n"
1491 << "Q\n";
1492
1493 sList << "BT\n"
1494 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1),
1495 TRUE)
dsinclaire35af1e2016-07-13 11:26:20 -07001496 << CPWL_Utils::GetEditAppStream(pEdit.get(),
1497 CFX_FloatPoint(0.0f, fy))
thestig732f6a02016-05-12 10:41:56 -07001498 << "ET\n";
1499 } else {
1500 CPWL_Color crText = GetTextPWLColor();
1501 sList << "BT\n"
1502 << CPWL_Utils::GetColorAppStream(crText, TRUE)
dsinclaire35af1e2016-07-13 11:26:20 -07001503 << CPWL_Utils::GetEditAppStream(pEdit.get(),
1504 CFX_FloatPoint(0.0f, fy))
thestig732f6a02016-05-12 10:41:56 -07001505 << "ET\n";
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001506 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001507
thestig732f6a02016-05-12 10:41:56 -07001508 fy -= fItemHeight;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001509 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001510
thestig732f6a02016-05-12 10:41:56 -07001511 if (sList.GetSize() > 0) {
1512 sBody << "/Tx BMC\n"
1513 << "q\n"
1514 << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width()
1515 << " " << rcClient.Height() << " re\nW\nn\n";
1516 sBody << sList << "Q\nEMC\n";
1517 }
1518
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001519 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
tsepez8e4c5052016-04-14 13:42:44 -07001520 sLines.AsStringC() + sBody.AsStringC();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001521
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001522 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001523}
1524
tsepeza31da742016-09-08 11:28:14 -07001525void CPDFSDK_Widget::ResetAppearance_TextField(const CFX_WideString* sValue) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001526 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001527 CPDF_FormField* pField = pControl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001528 CFX_ByteTextBuf sBody, sLines;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001529
dsinclaire35af1e2016-07-13 11:26:20 -07001530 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit);
thestig732f6a02016-05-12 10:41:56 -07001531 pEdit->EnableRefresh(FALSE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001532
thestig732f6a02016-05-12 10:41:56 -07001533 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
dsinclair79db6092016-09-14 07:27:21 -07001534 CPDFSDK_Environment* pEnv = pDoc->GetEnv();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001535
thestig732f6a02016-05-12 10:41:56 -07001536 CBA_FontMap font_map(this, pEnv->GetSysHandler());
1537 pEdit->SetFontMap(&font_map);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001538
thestig732f6a02016-05-12 10:41:56 -07001539 CFX_FloatRect rcClient = GetClientRect();
1540 pEdit->SetPlateRect(rcClient);
dsinclairefd5a992016-07-18 10:04:07 -07001541 pEdit->SetAlignmentH(pControl->GetControlAlignment(), TRUE);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001542
thestig732f6a02016-05-12 10:41:56 -07001543 uint32_t dwFieldFlags = pField->GetFieldFlags();
1544 FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001545
thestig732f6a02016-05-12 10:41:56 -07001546 if (bMultiLine) {
dsinclairefd5a992016-07-18 10:04:07 -07001547 pEdit->SetMultiLine(TRUE, TRUE);
1548 pEdit->SetAutoReturn(TRUE, TRUE);
thestig732f6a02016-05-12 10:41:56 -07001549 } else {
dsinclairefd5a992016-07-18 10:04:07 -07001550 pEdit->SetAlignmentV(1, TRUE);
thestig732f6a02016-05-12 10:41:56 -07001551 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001552
thestig732f6a02016-05-12 10:41:56 -07001553 uint16_t subWord = 0;
1554 if ((dwFieldFlags >> 13) & 1) {
1555 subWord = '*';
dsinclairefd5a992016-07-18 10:04:07 -07001556 pEdit->SetPasswordChar(subWord, TRUE);
thestig732f6a02016-05-12 10:41:56 -07001557 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001558
thestig732f6a02016-05-12 10:41:56 -07001559 int nMaxLen = pField->GetMaxLen();
1560 FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1;
1561 FX_FLOAT fFontSize = GetFontSize();
Bo Xufdc00a72014-10-28 23:03:33 -07001562
Tom Sepez51da0932015-11-25 16:05:49 -08001563#ifdef PDF_ENABLE_XFA
thestig732f6a02016-05-12 10:41:56 -07001564 CFX_WideString sValueTmp;
1565 if (!sValue && GetMixXFAWidget()) {
1566 sValueTmp = GetValue(TRUE);
tsepeza31da742016-09-08 11:28:14 -07001567 sValue = &sValueTmp;
thestig732f6a02016-05-12 10:41:56 -07001568 }
Tom Sepez40e9ff32015-11-30 12:39:54 -08001569#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001570
thestig732f6a02016-05-12 10:41:56 -07001571 if (nMaxLen > 0) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001572 if (bCharArray) {
thestig732f6a02016-05-12 10:41:56 -07001573 pEdit->SetCharArray(nMaxLen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001574
thestig732f6a02016-05-12 10:41:56 -07001575 if (IsFloatZero(fFontSize)) {
1576 fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0),
1577 rcClient, nMaxLen);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001578 }
thestig732f6a02016-05-12 10:41:56 -07001579 } else {
1580 if (sValue)
tsepeza31da742016-09-08 11:28:14 -07001581 nMaxLen = sValue->GetLength();
thestig732f6a02016-05-12 10:41:56 -07001582 pEdit->SetLimitChar(nMaxLen);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001583 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001584 }
1585
thestig732f6a02016-05-12 10:41:56 -07001586 if (IsFloatZero(fFontSize))
dsinclairefd5a992016-07-18 10:04:07 -07001587 pEdit->SetAutoFontSize(TRUE, TRUE);
thestig732f6a02016-05-12 10:41:56 -07001588 else
1589 pEdit->SetFontSize(fFontSize);
1590
1591 pEdit->Initialize();
tsepez067990c2016-09-13 06:46:40 -07001592 pEdit->SetText(sValue ? *sValue : pField->GetValue());
thestig732f6a02016-05-12 10:41:56 -07001593
1594 CFX_FloatRect rcContent = pEdit->GetContentRect();
thestig732f6a02016-05-12 10:41:56 -07001595 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(
tsepez63f545c2016-09-13 16:08:49 -07001596 pEdit.get(), CFX_FloatPoint(), nullptr, !bCharArray, subWord);
thestig732f6a02016-05-12 10:41:56 -07001597
1598 if (sEdit.GetLength() > 0) {
1599 sBody << "/Tx BMC\n"
1600 << "q\n";
1601 if (rcContent.Width() > rcClient.Width() ||
1602 rcContent.Height() > rcClient.Height()) {
1603 sBody << rcClient.left << " " << rcClient.bottom << " "
1604 << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
1605 }
1606 CPWL_Color crText = GetTextPWLColor();
1607 sBody << "BT\n"
1608 << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"
1609 << "Q\nEMC\n";
1610 }
1611
1612 if (bCharArray) {
1613 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -07001614 case BorderStyle::SOLID: {
thestig732f6a02016-05-12 10:41:56 -07001615 CFX_ByteString sColor =
1616 CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE);
1617 if (sColor.GetLength() > 0) {
1618 sLines << "q\n"
1619 << GetBorderWidth() << " w\n"
1620 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE)
1621 << " 2 J 0 j\n";
1622
thestig594b20b2016-05-12 21:56:43 -07001623 for (int32_t i = 1; i < nMaxLen; ++i) {
thestig732f6a02016-05-12 10:41:56 -07001624 sLines << rcClient.left +
1625 ((rcClient.right - rcClient.left) / nMaxLen) * i
1626 << " " << rcClient.bottom << " m\n"
1627 << rcClient.left +
1628 ((rcClient.right - rcClient.left) / nMaxLen) * i
1629 << " " << rcClient.top << " l S\n";
1630 }
1631
1632 sLines << "Q\n";
1633 }
dsinclair92cb5e52016-05-16 11:38:28 -07001634 break;
1635 }
1636 case BorderStyle::DASH: {
thestig732f6a02016-05-12 10:41:56 -07001637 CFX_ByteString sColor =
1638 CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE);
1639 if (sColor.GetLength() > 0) {
1640 CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0);
1641
1642 sLines << "q\n"
1643 << GetBorderWidth() << " w\n"
1644 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE)
1645 << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] "
1646 << dsBorder.nPhase << " d\n";
1647
thestig594b20b2016-05-12 21:56:43 -07001648 for (int32_t i = 1; i < nMaxLen; ++i) {
thestig732f6a02016-05-12 10:41:56 -07001649 sLines << rcClient.left +
1650 ((rcClient.right - rcClient.left) / nMaxLen) * i
1651 << " " << rcClient.bottom << " m\n"
1652 << rcClient.left +
1653 ((rcClient.right - rcClient.left) / nMaxLen) * i
1654 << " " << rcClient.top << " l S\n";
1655 }
1656
1657 sLines << "Q\n";
1658 }
dsinclair92cb5e52016-05-16 11:38:28 -07001659 break;
1660 }
1661 default:
1662 break;
thestig732f6a02016-05-12 10:41:56 -07001663 }
1664 }
1665
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001666 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
tsepez8e4c5052016-04-14 13:42:44 -07001667 sLines.AsStringC() + sBody.AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001668 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001669}
1670
Tom Sepez281a9ea2016-02-26 14:24:28 -08001671CFX_FloatRect CPDFSDK_Widget::GetClientRect() const {
1672 CFX_FloatRect rcWindow = GetRotatedRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001673 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
1674 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -07001675 case BorderStyle::BEVELED:
1676 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001677 fBorderWidth *= 2.0f;
1678 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001679 default:
1680 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001681 }
1682
1683 return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001684}
1685
Tom Sepez281a9ea2016-02-26 14:24:28 -08001686CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const {
1687 CFX_FloatRect rectAnnot = GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001688 FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left;
1689 FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;
1690
1691 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -08001692 CFX_FloatRect rcPDFWindow;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001693 switch (abs(pControl->GetRotation() % 360)) {
1694 case 0:
1695 case 180:
1696 default:
Tom Sepez281a9ea2016-02-26 14:24:28 -08001697 rcPDFWindow = CFX_FloatRect(0, 0, fWidth, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001698 break;
1699 case 90:
1700 case 270:
Tom Sepez281a9ea2016-02-26 14:24:28 -08001701 rcPDFWindow = CFX_FloatRect(0, 0, fHeight, fWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001702 break;
1703 }
1704
1705 return rcPDFWindow;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001706}
1707
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001708CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const {
1709 CPWL_Color crBackground = GetFillPWLColor();
jaepark611adb82016-08-17 11:34:36 -07001710 if (crBackground.nColorType != COLORTYPE_TRANSPARENT)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001711 return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);
jaepark611adb82016-08-17 11:34:36 -07001712
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001713 return "";
Bo Xufdc00a72014-10-28 23:03:33 -07001714}
1715
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001716CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001717 CFX_FloatRect rcWindow = GetRotatedRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001718 CPWL_Color crBorder = GetBorderPWLColor();
1719 CPWL_Color crBackground = GetFillPWLColor();
1720 CPWL_Color crLeftTop, crRightBottom;
1721
1722 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001723 CPWL_Dash dsBorder(3, 0, 0);
1724
dsinclair92cb5e52016-05-16 11:38:28 -07001725 BorderStyle nBorderStyle = GetBorderStyle();
1726 switch (nBorderStyle) {
1727 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001728 dsBorder = CPWL_Dash(3, 3, 0);
1729 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001730 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001731 fBorderWidth *= 2;
1732 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1733 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
1734 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001735 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001736 fBorderWidth *= 2;
1737 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1738 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1739 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001740 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001741 break;
1742 }
1743
1744 return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1745 crLeftTop, crRightBottom, nBorderStyle,
1746 dsBorder);
Bo Xufdc00a72014-10-28 23:03:33 -07001747}
1748
Tom Sepez60d909e2015-12-10 15:34:55 -08001749CFX_Matrix CPDFSDK_Widget::GetMatrix() const {
1750 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001751 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -08001752 CFX_FloatRect rcAnnot = GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001753 FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left;
1754 FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom;
1755
1756 switch (abs(pControl->GetRotation() % 360)) {
1757 case 0:
1758 default:
Tom Sepez60d909e2015-12-10 15:34:55 -08001759 mt = CFX_Matrix(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001760 break;
1761 case 90:
Tom Sepez60d909e2015-12-10 15:34:55 -08001762 mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001763 break;
1764 case 180:
Tom Sepez60d909e2015-12-10 15:34:55 -08001765 mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001766 break;
1767 case 270:
Tom Sepez60d909e2015-12-10 15:34:55 -08001768 mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001769 break;
1770 }
1771
1772 return mt;
Bo Xufdc00a72014-10-28 23:03:33 -07001773}
1774
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001775CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const {
1776 CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0);
1777
1778 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001779 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
1780 if (da.HasColor()) {
1781 int32_t iColorType;
1782 FX_FLOAT fc[4];
1783 da.GetColor(iColorType, fc);
1784 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1785 }
1786
1787 return crText;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001788}
1789
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001790CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const {
1791 CPWL_Color crBorder;
1792
1793 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001794 int32_t iColorType;
1795 FX_FLOAT fc[4];
1796 pFormCtrl->GetOriginalBorderColor(iColorType, fc);
1797 if (iColorType > 0)
1798 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1799
1800 return crBorder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001801}
1802
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001803CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const {
1804 CPWL_Color crFill;
1805
1806 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001807 int32_t iColorType;
1808 FX_FLOAT fc[4];
1809 pFormCtrl->GetOriginalBackgroundColor(iColorType, fc);
1810 if (iColorType > 0)
1811 crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1812
1813 return crFill;
Bo Xufdc00a72014-10-28 23:03:33 -07001814}
1815
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001816void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType,
1817 CPDF_Stream* pImage) {
dsinclair38fd8442016-09-15 10:15:32 -07001818 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
1819 CPDF_Stream* pStream = pAPDict->GetStreamFor(sAPType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001820 CPDF_Dictionary* pStreamDict = pStream->GetDict();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001821 CFX_ByteString sImageAlias = "IMG";
1822
1823 if (CPDF_Dictionary* pImageDict = pImage->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -07001824 sImageAlias = pImageDict->GetStringFor("Name");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001825 if (sImageAlias.IsEmpty())
1826 sImageAlias = "IMG";
1827 }
1828
tsepez698c5712016-09-28 16:47:07 -07001829 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
dsinclair38fd8442016-09-15 10:15:32 -07001830 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001831 if (!pStreamResList) {
tsepez698c5712016-09-28 16:47:07 -07001832 pStreamResList = new CPDF_Dictionary(pDoc->GetByteStringPool());
dsinclair38fd8442016-09-15 10:15:32 -07001833 pStreamDict->SetFor("Resources", pStreamResList);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001834 }
1835
tsepez698c5712016-09-28 16:47:07 -07001836 CPDF_Dictionary* pXObject = new CPDF_Dictionary(pDoc->GetByteStringPool());
tsepezbb577af2016-09-21 19:10:19 -07001837 pXObject->SetReferenceFor(sImageAlias, pDoc, pImage->GetObjNum());
1838 pStreamResList->SetFor("XObject", pXObject);
Bo Xufdc00a72014-10-28 23:03:33 -07001839}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001840
1841void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) {
dsinclair38fd8442016-09-15 10:15:32 -07001842 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"))
1843 pAPDict->RemoveFor(sAPType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001844}
1845
1846FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
1847 PDFSDK_FieldAction& data,
1848 CPDFSDK_PageView* pPageView) {
1849 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
dsinclair79db6092016-09-14 07:27:21 -07001850 CPDFSDK_Environment* pEnv = pDocument->GetEnv();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001851
Tom Sepez40e9ff32015-11-30 12:39:54 -08001852#ifdef PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -08001853 CPDFXFA_Document* pDoc = pDocument->GetXFADocument();
dsinclairdf4bc592016-03-31 20:34:43 -07001854 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001855 XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit);
1856
1857 if (eEventType != XFA_EVENT_Unknown) {
dsinclairdf4bc592016-03-31 20:34:43 -07001858 if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001859 CXFA_EventParam param;
1860 param.m_eType = eEventType;
1861 param.m_wsChange = data.sChange;
1862 param.m_iCommitKey = data.nCommitKey;
1863 param.m_bShift = data.bShift;
1864 param.m_iSelStart = data.nSelStart;
1865 param.m_iSelEnd = data.nSelEnd;
1866 param.m_wsFullText = data.sValue;
1867 param.m_bKeyDown = data.bKeyDown;
1868 param.m_bModifier = data.bModifier;
1869 param.m_wsNewText = data.sValue;
1870 if (data.nSelEnd > data.nSelStart)
1871 param.m_wsNewText.Delete(data.nSelStart,
1872 data.nSelEnd - data.nSelStart);
1873 for (int i = data.sChange.GetLength() - 1; i >= 0; i--)
1874 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
1875 param.m_wsPrevText = data.sValue;
1876
dsinclair221caf62016-04-04 12:08:40 -07001877 CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001878 param.m_pTarget = pAcc;
1879 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
1880
jaepark611adb82016-08-17 11:34:36 -07001881 if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001882 pDocView->UpdateDocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001883
Wei Lie98ac2e2016-03-18 15:43:04 -07001884 if (nRet == XFA_EVENTERROR_Success)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001885 return TRUE;
1886 }
1887 }
1888 }
Tom Sepez40e9ff32015-11-30 12:39:54 -08001889#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001890
1891 CPDF_Action action = GetAAction(type);
Wei Li0fc6b252016-03-01 16:29:41 -08001892 if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001893 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
1894 return pActionHandler->DoAction_Field(action, type, pDocument,
1895 GetFormField(), data);
1896 }
1897 return FALSE;
1898}
1899
1900CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) {
1901 switch (eAAT) {
1902 case CPDF_AAction::CursorEnter:
1903 case CPDF_AAction::CursorExit:
1904 case CPDF_AAction::ButtonDown:
1905 case CPDF_AAction::ButtonUp:
1906 case CPDF_AAction::GetFocus:
1907 case CPDF_AAction::LoseFocus:
1908 case CPDF_AAction::PageOpen:
1909 case CPDF_AAction::PageClose:
1910 case CPDF_AAction::PageVisible:
1911 case CPDF_AAction::PageInvisible:
1912 return CPDFSDK_BAAnnot::GetAAction(eAAT);
1913
1914 case CPDF_AAction::KeyStroke:
1915 case CPDF_AAction::Format:
1916 case CPDF_AAction::Validate:
1917 case CPDF_AAction::Calculate: {
1918 CPDF_FormField* pField = GetFormField();
Wei Li0fc6b252016-03-01 16:29:41 -08001919 if (pField->GetAdditionalAction().GetDict())
1920 return pField->GetAdditionalAction().GetAction(eAAT);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001921 return CPDFSDK_BAAnnot::GetAAction(eAAT);
1922 }
1923 default:
1924 break;
1925 }
1926
1927 return CPDF_Action();
1928}
1929
1930CFX_WideString CPDFSDK_Widget::GetAlternateName() const {
1931 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001932 return pFormField->GetAlternateName();
1933}
1934
1935int32_t CPDFSDK_Widget::GetAppearanceAge() const {
1936 return m_nAppAge;
1937}
1938
1939int32_t CPDFSDK_Widget::GetValueAge() const {
1940 return m_nValueAge;
1941}
1942
1943FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY) {
1944 CPDF_Annot* pAnnot = GetPDFAnnot();
jaeparka1d21112016-08-25 13:33:34 -07001945 CFX_FloatRect annotRect = pAnnot->GetRect();
jaepark611adb82016-08-17 11:34:36 -07001946 if (!annotRect.Contains(pageX, pageY))
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001947 return FALSE;
1948
jaepark611adb82016-08-17 11:34:36 -07001949 if (!IsVisible())
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001950 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001951
jaepark611adb82016-08-17 11:34:36 -07001952 if ((GetFieldFlags() & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
Lei Zhangd88a3642015-11-10 09:38:57 -08001953 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001954
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001955 return TRUE;
1956}