blob: b1c3379ac9a7660f3b9e18c1073180a39817ac58 [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
dsinclair114e46a2016-09-29 17:18:21 -07007#include "fpdfsdk/cpdfsdk_widget.h"
Lei Zhangc2fb35f2016-01-05 16:46:58 -08008
Lei Zhangaa8bf7e2015-12-24 19:13:32 -08009#include <memory>
10
dsinclair488b7ad2016-10-04 11:55:50 -070011#include "core/fpdfapi/parser/cpdf_dictionary.h"
12#include "core/fpdfapi/parser/cpdf_document.h"
13#include "core/fpdfapi/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"
dsinclair735606d2016-10-05 15:47:02 -070022#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070023#include "fpdfsdk/cpdfsdk_interform.h"
24#include "fpdfsdk/cpdfsdk_pageview.h"
jaepark611adb82016-08-17 11:34:36 -070025#include "fpdfsdk/formfiller/cba_fontmap.h"
dsinclair114e46a2016-09-29 17:18:21 -070026#include "fpdfsdk/fsdk_actionhandler.h"
27#include "fpdfsdk/fsdk_define.h"
dsinclair0bb385b2016-09-29 17:03:59 -070028#include "fpdfsdk/fxedit/fxet_edit.h"
jaepark611adb82016-08-17 11:34:36 -070029#include "fpdfsdk/pdfwindow/PWL_Edit.h"
dan sinclair89e904b2016-03-23 19:29:15 -040030#include "fpdfsdk/pdfwindow/PWL_Utils.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031
Tom Sepez40e9ff32015-11-30 12:39:54 -080032#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -070033#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
dsinclair5b493092016-09-29 20:20:24 -070034#include "xfa/fxfa/cxfa_eventparam.h"
35#include "xfa/fxfa/fxfa_widget.h"
36#include "xfa/fxfa/xfa_ffdocview.h"
37#include "xfa/fxfa/xfa_ffwidget.h"
38#include "xfa/fxfa/xfa_ffwidgethandler.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080039#endif // PDF_ENABLE_XFA
40
dsinclair72177da2016-09-15 12:07:23 -070041namespace {
42
43// Convert a FX_ARGB to a FX_COLORREF.
44FX_COLORREF ARGBToColorRef(FX_ARGB argb) {
45 return (((static_cast<uint32_t>(argb) & 0x00FF0000) >> 16) |
46 (static_cast<uint32_t>(argb) & 0x0000FF00) |
47 ((static_cast<uint32_t>(argb) & 0x000000FF) << 16));
48}
49
50} // namespace
51
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
53 CPDFSDK_PageView* pPageView,
54 CPDFSDK_InterForm* pInterForm)
55 : CPDFSDK_BAAnnot(pAnnot, pPageView),
56 m_pInterForm(pInterForm),
57 m_nAppAge(0),
Tom Sepez40e9ff32015-11-30 12:39:54 -080058 m_nValueAge(0)
59#ifdef PDF_ENABLE_XFA
60 ,
thestig1cd352e2016-06-07 17:53:06 -070061 m_hMixXFAWidget(nullptr),
62 m_pWidgetHandler(nullptr)
Tom Sepez40e9ff32015-11-30 12:39:54 -080063#endif // PDF_ENABLE_XFA
64{
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065}
66
dsinclairce04a452016-09-07 05:46:55 -070067CPDFSDK_Widget::~CPDFSDK_Widget() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070068
Tom Sepez51da0932015-11-25 16:05:49 -080069#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -070070CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const {
dsinclair521b7502016-11-02 13:02:28 -070071 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
72 if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070073 if (!m_hMixXFAWidget) {
dsinclair521b7502016-11-02 13:02:28 -070074 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075 CFX_WideString sName;
Lei Zhang99766722016-02-23 11:21:48 -080076 if (GetFieldType() == FIELDTYPE_RADIOBUTTON) {
77 sName = GetAnnotName();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078 if (sName.IsEmpty())
79 sName = GetName();
Dan Sinclair738b08c2016-03-01 14:45:20 -050080 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081 sName = GetName();
Dan Sinclair738b08c2016-03-01 14:45:20 -050082 }
Bo Xufdc00a72014-10-28 23:03:33 -070083
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084 if (!sName.IsEmpty())
weilib4d1b572016-08-10 14:50:48 -070085 m_hMixXFAWidget = pDocView->GetWidgetByName(sName, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070086 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -070087 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088 return m_hMixXFAWidget;
89 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070090
thestig1cd352e2016-06-07 17:53:06 -070091 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070092}
93
dsinclairdf4bc592016-03-31 20:34:43 -070094CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() {
dsinclair521b7502016-11-02 13:02:28 -070095 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
96 if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) {
97 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070098 CFX_WideString sName = GetName();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099 if (!sName.IsEmpty())
weilib4d1b572016-08-10 14:50:48 -0700100 return pDocView->GetWidgetByName(sName, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101 }
102 }
103
Tom Sepez50d12ad2015-11-24 09:50:51 -0800104 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700105}
106
dsinclairdf4bc592016-03-31 20:34:43 -0700107CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const {
dsinclair521b7502016-11-02 13:02:28 -0700108 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
109 if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110 if (!m_pWidgetHandler) {
dsinclair521b7502016-11-02 13:02:28 -0700111 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112 m_pWidgetHandler = pDocView->GetWidgetHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113 }
114 return m_pWidgetHandler;
115 }
116
thestig1cd352e2016-06-07 17:53:06 -0700117 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700118}
119
120static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) {
121 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
122
123 switch (eXFAAAT) {
124 case PDFSDK_XFA_Click:
125 eEventType = XFA_EVENT_Click;
126 break;
127 case PDFSDK_XFA_Full:
128 eEventType = XFA_EVENT_Full;
129 break;
130 case PDFSDK_XFA_PreOpen:
131 eEventType = XFA_EVENT_PreOpen;
132 break;
133 case PDFSDK_XFA_PostOpen:
134 eEventType = XFA_EVENT_PostOpen;
135 break;
136 }
137
138 return eEventType;
139}
140
141static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT,
tsepez4cf55152016-11-02 14:37:54 -0700142 bool bWillCommit) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700143 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
144
145 switch (eAAT) {
146 case CPDF_AAction::CursorEnter:
147 eEventType = XFA_EVENT_MouseEnter;
148 break;
149 case CPDF_AAction::CursorExit:
150 eEventType = XFA_EVENT_MouseExit;
151 break;
152 case CPDF_AAction::ButtonDown:
153 eEventType = XFA_EVENT_MouseDown;
154 break;
155 case CPDF_AAction::ButtonUp:
156 eEventType = XFA_EVENT_MouseUp;
157 break;
158 case CPDF_AAction::GetFocus:
159 eEventType = XFA_EVENT_Enter;
160 break;
161 case CPDF_AAction::LoseFocus:
162 eEventType = XFA_EVENT_Exit;
163 break;
164 case CPDF_AAction::PageOpen:
165 break;
166 case CPDF_AAction::PageClose:
167 break;
168 case CPDF_AAction::PageVisible:
169 break;
170 case CPDF_AAction::PageInvisible:
171 break;
172 case CPDF_AAction::KeyStroke:
jaepark611adb82016-08-17 11:34:36 -0700173 if (!bWillCommit)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700174 eEventType = XFA_EVENT_Change;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700175 break;
176 case CPDF_AAction::Validate:
177 eEventType = XFA_EVENT_Validate;
178 break;
179 case CPDF_AAction::OpenPage:
180 case CPDF_AAction::ClosePage:
181 case CPDF_AAction::Format:
182 case CPDF_AAction::Calculate:
183 case CPDF_AAction::CloseDocument:
184 case CPDF_AAction::SaveDocument:
185 case CPDF_AAction::DocumentSaved:
186 case CPDF_AAction::PrintDocument:
187 case CPDF_AAction::DocumentPrinted:
188 break;
189 }
190
191 return eEventType;
192}
193
tsepez4cf55152016-11-02 14:37:54 -0700194bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) {
jaepark611adb82016-08-17 11:34:36 -0700195 CXFA_FFWidget* hWidget = GetMixXFAWidget();
196 if (!hWidget)
tsepez4cf55152016-11-02 14:37:54 -0700197 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198
jaepark611adb82016-08-17 11:34:36 -0700199 CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
200 if (!pXFAWidgetHandler)
tsepez4cf55152016-11-02 14:37:54 -0700201 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202
jaepark611adb82016-08-17 11:34:36 -0700203 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
204
205 CXFA_WidgetAcc* pAcc;
206 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
207 GetFieldType() == FIELDTYPE_RADIOBUTTON) {
208 if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) {
209 pAcc = hGroupWidget->GetDataAcc();
210 if (pXFAWidgetHandler->HasEvent(pAcc, eEventType))
tsepez4cf55152016-11-02 14:37:54 -0700211 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 }
213 }
214
jaepark611adb82016-08-17 11:34:36 -0700215 pAcc = hWidget->GetDataAcc();
216 return pXFAWidgetHandler->HasEvent(pAcc, eEventType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700217}
218
tsepez4cf55152016-11-02 14:37:54 -0700219bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
220 PDFSDK_FieldAction& data,
221 CPDFSDK_PageView* pPageView) {
dsinclair521b7502016-11-02 13:02:28 -0700222 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223
jaepark611adb82016-08-17 11:34:36 -0700224 CXFA_FFWidget* hWidget = GetMixXFAWidget();
225 if (!hWidget)
tsepez4cf55152016-11-02 14:37:54 -0700226 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227
jaepark611adb82016-08-17 11:34:36 -0700228 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
229 if (eEventType == XFA_EVENT_Unknown)
tsepez4cf55152016-11-02 14:37:54 -0700230 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231
jaepark611adb82016-08-17 11:34:36 -0700232 CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
233 if (!pXFAWidgetHandler)
tsepez4cf55152016-11-02 14:37:54 -0700234 return false;
jaepark611adb82016-08-17 11:34:36 -0700235
236 CXFA_EventParam param;
237 param.m_eType = eEventType;
238 param.m_wsChange = data.sChange;
239 param.m_iCommitKey = data.nCommitKey;
240 param.m_bShift = data.bShift;
241 param.m_iSelStart = data.nSelStart;
242 param.m_iSelEnd = data.nSelEnd;
243 param.m_wsFullText = data.sValue;
244 param.m_bKeyDown = data.bKeyDown;
245 param.m_bModifier = data.bModifier;
246 param.m_wsNewText = data.sValue;
247 if (data.nSelEnd > data.nSelStart)
248 param.m_wsNewText.Delete(data.nSelStart, data.nSelEnd - data.nSelStart);
249
250 for (int i = 0; i < data.sChange.GetLength(); i++)
251 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
252 param.m_wsPrevText = data.sValue;
253
254 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
255 GetFieldType() == FIELDTYPE_RADIOBUTTON) {
256 if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) {
257 CXFA_WidgetAcc* pAcc = hGroupWidget->GetDataAcc();
258 param.m_pTarget = pAcc;
259 if (pXFAWidgetHandler->ProcessEvent(pAcc, &param) !=
260 XFA_EVENTERROR_Success) {
tsepez4cf55152016-11-02 14:37:54 -0700261 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262 }
263 }
264 }
jaepark611adb82016-08-17 11:34:36 -0700265 CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc();
266 param.m_pTarget = pAcc;
267 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700268
dsinclair521b7502016-11-02 13:02:28 -0700269 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
jaepark611adb82016-08-17 11:34:36 -0700270 pDocView->UpdateDocView();
271
272 return nRet == XFA_EVENTERROR_Success;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700273}
274
tsepez4cf55152016-11-02 14:37:54 -0700275void CPDFSDK_Widget::Synchronize(bool bSynchronizeElse) {
jaepark611adb82016-08-17 11:34:36 -0700276 CXFA_FFWidget* hWidget = GetMixXFAWidget();
277 if (!hWidget)
278 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700279
jaepark611adb82016-08-17 11:34:36 -0700280 CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc();
281 if (!pWidgetAcc)
282 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283
jaepark611adb82016-08-17 11:34:36 -0700284 CPDF_FormField* pFormField = GetFormField();
285 switch (GetFieldType()) {
286 case FIELDTYPE_CHECKBOX:
287 case FIELDTYPE_RADIOBUTTON: {
288 CPDF_FormControl* pFormCtrl = GetFormControl();
289 XFA_CHECKSTATE eCheckState =
290 pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off;
291 pWidgetAcc->SetCheckState(eCheckState, true);
292 break;
293 }
294 case FIELDTYPE_TEXTFIELD:
295 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
296 break;
297 case FIELDTYPE_LISTBOX: {
298 pWidgetAcc->ClearAllSelections();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700299
jaepark611adb82016-08-17 11:34:36 -0700300 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
301 int nIndex = pFormField->GetSelectedIndex(i);
302 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
tsepez4cf55152016-11-02 14:37:54 -0700303 pWidgetAcc->SetItemState(nIndex, true, false, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700304 }
jaepark611adb82016-08-17 11:34:36 -0700305 break;
306 }
307 case FIELDTYPE_COMBOBOX: {
308 pWidgetAcc->ClearAllSelections();
dsinclair221caf62016-04-04 12:08:40 -0700309
jaepark611adb82016-08-17 11:34:36 -0700310 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
311 int nIndex = pFormField->GetSelectedIndex(i);
312 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
tsepez4cf55152016-11-02 14:37:54 -0700313 pWidgetAcc->SetItemState(nIndex, true, false, false, true);
jaepark611adb82016-08-17 11:34:36 -0700314 }
315 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
316 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317 }
318 }
jaepark611adb82016-08-17 11:34:36 -0700319
320 if (bSynchronizeElse)
321 pWidgetAcc->ProcessValueChanged();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700322}
323
324void CPDFSDK_Widget::SynchronizeXFAValue() {
dsinclair521b7502016-11-02 13:02:28 -0700325 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
326 CXFA_FFDocView* pXFADocView = pContext->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327 if (!pXFADocView)
328 return;
329
dsinclairdf4bc592016-03-31 20:34:43 -0700330 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700331 if (GetXFAWidgetHandler()) {
332 CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(),
333 GetFormControl());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700334 }
335 }
336}
337
338void CPDFSDK_Widget::SynchronizeXFAItems() {
dsinclair521b7502016-11-02 13:02:28 -0700339 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
340 CXFA_FFDocView* pXFADocView = pContext->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700341 if (!pXFADocView)
342 return;
343
dsinclairdf4bc592016-03-31 20:34:43 -0700344 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700345 if (GetXFAWidgetHandler())
346 SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700347 }
348}
349
dsinclairdf4bc592016-03-31 20:34:43 -0700350void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView,
351 CXFA_FFWidget* hWidget,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700352 CPDF_FormField* pFormField,
353 CPDF_FormControl* pFormControl) {
Lei Zhang5eca3052016-02-22 20:32:21 -0800354 ASSERT(hWidget);
dsinclair221caf62016-04-04 12:08:40 -0700355 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700356
dsinclair221caf62016-04-04 12:08:40 -0700357 switch (pFormField->GetFieldType()) {
358 case FIELDTYPE_CHECKBOX: {
359 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
360 pFormField->CheckControl(
361 pFormField->GetControlIndex(pFormControl),
362 pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true);
363 }
jaepark611adb82016-08-17 11:34:36 -0700364 break;
365 }
dsinclair221caf62016-04-04 12:08:40 -0700366 case FIELDTYPE_RADIOBUTTON: {
367 // TODO(weili): Check whether we need to handle checkbox and radio
368 // button differently, otherwise, merge these two cases.
369 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
370 pFormField->CheckControl(
371 pFormField->GetControlIndex(pFormControl),
372 pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true);
373 }
jaepark611adb82016-08-17 11:34:36 -0700374 break;
375 }
dsinclair221caf62016-04-04 12:08:40 -0700376 case FIELDTYPE_TEXTFIELD: {
377 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
378 CFX_WideString sValue;
379 pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
tsepez4cf55152016-11-02 14:37:54 -0700380 pFormField->SetValue(sValue, true);
dsinclair221caf62016-04-04 12:08:40 -0700381 }
jaepark611adb82016-08-17 11:34:36 -0700382 break;
383 }
dsinclair221caf62016-04-04 12:08:40 -0700384 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700385 pFormField->ClearSelection(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700386
dsinclair221caf62016-04-04 12:08:40 -0700387 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
388 for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
389 int nIndex = pWidgetAcc->GetSelectedItem(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700390
dsinclair221caf62016-04-04 12:08:40 -0700391 if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
tsepez4cf55152016-11-02 14:37:54 -0700392 pFormField->SetItemSelection(nIndex, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700393 }
394 }
dsinclair221caf62016-04-04 12:08:40 -0700395 }
jaepark611adb82016-08-17 11:34:36 -0700396 break;
397 }
dsinclair221caf62016-04-04 12:08:40 -0700398 case FIELDTYPE_COMBOBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700399 pFormField->ClearSelection(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700400
dsinclair221caf62016-04-04 12:08:40 -0700401 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
402 for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
403 int nIndex = pWidgetAcc->GetSelectedItem(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700404
dsinclair221caf62016-04-04 12:08:40 -0700405 if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
tsepez4cf55152016-11-02 14:37:54 -0700406 pFormField->SetItemSelection(nIndex, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700408 }
dsinclair221caf62016-04-04 12:08:40 -0700409
410 CFX_WideString sValue;
411 pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
tsepez4cf55152016-11-02 14:37:54 -0700412 pFormField->SetValue(sValue, true);
dsinclair221caf62016-04-04 12:08:40 -0700413 }
jaepark611adb82016-08-17 11:34:36 -0700414 break;
415 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416 }
417}
418
dsinclairdf4bc592016-03-31 20:34:43 -0700419void CPDFSDK_Widget::SynchronizeXFAItems(CXFA_FFDocView* pXFADocView,
420 CXFA_FFWidget* hWidget,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700421 CPDF_FormField* pFormField,
422 CPDF_FormControl* pFormControl) {
Lei Zhang5eca3052016-02-22 20:32:21 -0800423 ASSERT(hWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700424
dsinclair221caf62016-04-04 12:08:40 -0700425 switch (pFormField->GetFieldType()) {
426 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700427 pFormField->ClearSelection(false);
428 pFormField->ClearOptions(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429
dsinclair221caf62016-04-04 12:08:40 -0700430 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
431 for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz; i++) {
432 CFX_WideString swText;
433 pWidgetAcc->GetChoiceListItem(swText, i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700434
tsepez4cf55152016-11-02 14:37:54 -0700435 pFormField->InsertOption(swText, i, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436 }
dsinclair221caf62016-04-04 12:08:40 -0700437 }
jaepark611adb82016-08-17 11:34:36 -0700438 break;
439 }
dsinclair221caf62016-04-04 12:08:40 -0700440 case FIELDTYPE_COMBOBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700441 pFormField->ClearSelection(false);
442 pFormField->ClearOptions(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700443
dsinclair221caf62016-04-04 12:08:40 -0700444 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
445 for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz; i++) {
446 CFX_WideString swText;
447 pWidgetAcc->GetChoiceListItem(swText, i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448
tsepez4cf55152016-11-02 14:37:54 -0700449 pFormField->InsertOption(swText, i, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450 }
dsinclair221caf62016-04-04 12:08:40 -0700451 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452
tsepez4cf55152016-11-02 14:37:54 -0700453 pFormField->SetValue(L"", true);
jaepark611adb82016-08-17 11:34:36 -0700454 break;
455 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 }
457}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800458#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700459
tsepez4cf55152016-11-02 14:37:54 -0700460bool CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode) {
dsinclair38fd8442016-09-15 10:15:32 -0700461 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462 if (!pAP)
tsepez4cf55152016-11-02 14:37:54 -0700463 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700464
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465 // Choose the right sub-ap
466 const FX_CHAR* ap_entry = "N";
467 if (mode == CPDF_Annot::Down)
468 ap_entry = "D";
469 else if (mode == CPDF_Annot::Rollover)
470 ap_entry = "R";
471 if (!pAP->KeyExist(ap_entry))
472 ap_entry = "N";
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700473
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700474 // Get the AP stream or subdirectory
dsinclair38fd8442016-09-15 10:15:32 -0700475 CPDF_Object* psub = pAP->GetDirectObjectFor(ap_entry);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700476 if (!psub)
tsepez4cf55152016-11-02 14:37:54 -0700477 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700478
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 int nFieldType = GetFieldType();
480 switch (nFieldType) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700481 case FIELDTYPE_PUSHBUTTON:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700482 case FIELDTYPE_COMBOBOX:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700483 case FIELDTYPE_LISTBOX:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700484 case FIELDTYPE_TEXTFIELD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485 case FIELDTYPE_SIGNATURE:
Dan Sinclairaa435ba2015-10-22 16:45:48 -0400486 return psub->IsStream();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700487 case FIELDTYPE_CHECKBOX:
488 case FIELDTYPE_RADIOBUTTON:
Dan Sinclairf1251c12015-10-20 16:24:45 -0400489 if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) {
dsinclair38fd8442016-09-15 10:15:32 -0700490 return !!pSubDict->GetStreamFor(GetAppState());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700491 }
tsepez4cf55152016-11-02 14:37:54 -0700492 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493 }
tsepez4cf55152016-11-02 14:37:54 -0700494 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495}
496
497int CPDFSDK_Widget::GetFieldType() const {
dsinclair92828192016-08-17 13:28:51 -0700498 CPDF_FormField* pField = GetFormField();
499 return pField ? pField->GetFieldType() : FIELDTYPE_UNKNOWN;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500}
501
tsepez4cf55152016-11-02 14:37:54 -0700502bool CPDFSDK_Widget::IsAppearanceValid() {
Tom Sepez51da0932015-11-25 16:05:49 -0800503#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -0700504 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
505 int nDocType = pContext->GetDocType();
Tom Sepez540c4362015-11-24 13:33:57 -0800506 if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA)
tsepez4cf55152016-11-02 14:37:54 -0700507 return true;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800508#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800509 return CPDFSDK_BAAnnot::IsAppearanceValid();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700510}
511
weili625ad662016-06-15 11:21:33 -0700512int CPDFSDK_Widget::GetLayoutOrder() const {
513 return 2;
514}
515
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516int CPDFSDK_Widget::GetFieldFlags() const {
517 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518 CPDF_FormControl* pFormControl =
519 pPDFInterForm->GetControlByDict(m_pAnnot->GetAnnotDict());
520 CPDF_FormField* pFormField = pFormControl->GetField();
521 return pFormField->GetFieldFlags();
522}
523
jaepark9ed91372016-08-26 16:16:10 -0700524bool CPDFSDK_Widget::IsSignatureWidget() const {
525 return GetFieldType() == FIELDTYPE_SIGNATURE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526}
527
528CPDF_FormField* CPDFSDK_Widget::GetFormField() const {
dsinclair92828192016-08-17 13:28:51 -0700529 CPDF_FormControl* pControl = GetFormControl();
530 return pControl ? pControl->GetField() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700531}
532
533CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535 return pPDFInterForm->GetControlByDict(GetAnnotDict());
536}
537
Lei Zhang1b700c32015-10-30 23:55:35 -0700538CPDF_FormControl* CPDFSDK_Widget::GetFormControl(
539 CPDF_InterForm* pInterForm,
540 const CPDF_Dictionary* pAnnotDict) {
Lei Zhang96660d62015-12-14 18:27:25 -0800541 ASSERT(pAnnotDict);
Lei Zhang1b700c32015-10-30 23:55:35 -0700542 return pInterForm->GetControlByDict(pAnnotDict);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700543}
544
545int CPDFSDK_Widget::GetRotate() const {
546 CPDF_FormControl* pCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 return pCtrl->GetRotation() % 360;
548}
549
Tom Sepez51da0932015-11-25 16:05:49 -0800550#ifdef PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700551CFX_WideString CPDFSDK_Widget::GetName() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700553 return pFormField->GetFullName();
554}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800555#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700556
tsepez4cf55152016-11-02 14:37:54 -0700557bool CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559 int iColorType = 0;
dsinclair72177da2016-09-15 12:07:23 -0700560 color = ARGBToColorRef(pFormCtrl->GetBackgroundColor(iColorType));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561 return iColorType != COLORTYPE_TRANSPARENT;
562}
563
tsepez4cf55152016-11-02 14:37:54 -0700564bool CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566 int iColorType = 0;
dsinclair72177da2016-09-15 12:07:23 -0700567 color = ARGBToColorRef(pFormCtrl->GetBorderColor(iColorType));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700568 return iColorType != COLORTYPE_TRANSPARENT;
569}
570
tsepez4cf55152016-11-02 14:37:54 -0700571bool CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
jaepark611adb82016-08-17 11:34:36 -0700574 if (!da.HasColor())
tsepez4cf55152016-11-02 14:37:54 -0700575 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576
jaepark611adb82016-08-17 11:34:36 -0700577 FX_ARGB argb;
578 int iColorType = COLORTYPE_TRANSPARENT;
579 da.GetColor(argb, iColorType);
dsinclair72177da2016-09-15 12:07:23 -0700580 color = ARGBToColorRef(argb);
jaepark611adb82016-08-17 11:34:36 -0700581 return iColorType != COLORTYPE_TRANSPARENT;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700582}
583
584FX_FLOAT CPDFSDK_Widget::GetFontSize() const {
585 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586 CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
587 CFX_ByteString csFont = "";
588 FX_FLOAT fFontSize = 0.0f;
589 pDa.GetFont(csFont, fFontSize);
590
591 return fFontSize;
592}
593
Tom Sepezbf59a072015-10-21 14:07:23 -0700594int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700595#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700596 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700597 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
598 if (nIndex < pWidgetAcc->CountSelectedItems())
599 return pWidgetAcc->GetSelectedItem(nIndex);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700600 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700602#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700603 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700604 return pFormField->GetSelectedIndex(nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700605}
606
Tom Sepeza8a39e22015-10-12 15:47:07 -0700607#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700608CFX_WideString CPDFSDK_Widget::GetValue(bool bDisplay) const {
dsinclairdf4bc592016-03-31 20:34:43 -0700609 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700610 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
611 CFX_WideString sValue;
612 pWidgetAcc->GetValue(
613 sValue, bDisplay ? XFA_VALUEPICTURE_Display : XFA_VALUEPICTURE_Edit);
614 return sValue;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700615 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800617#else
618CFX_WideString CPDFSDK_Widget::GetValue() const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700619#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700621 return pFormField->GetValue();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700622}
623
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624CFX_WideString CPDFSDK_Widget::GetDefaultValue() const {
625 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700626 return pFormField->GetDefaultValue();
627}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700628
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700629CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const {
630 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700631 return pFormField->GetOptionLabel(nIndex);
632}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700633
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700634int CPDFSDK_Widget::CountOptions() const {
635 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636 return pFormField->CountOptions();
637}
638
tsepez4cf55152016-11-02 14:37:54 -0700639bool CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700640#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700641 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700642 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
643 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
644 return pWidgetAcc->GetItemState(nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700645
tsepez4cf55152016-11-02 14:37:54 -0700646 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700647 }
648 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700649#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650 CPDF_FormField* pFormField = GetFormField();
651 return pFormField->IsItemSelected(nIndex);
652}
653
654int CPDFSDK_Widget::GetTopVisibleIndex() const {
655 CPDF_FormField* pFormField = GetFormField();
656 return pFormField->GetTopVisibleIndex();
657}
658
Wei Li97da9762016-03-11 17:00:48 -0800659bool CPDFSDK_Widget::IsChecked() const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700660#ifdef PDF_ENABLE_XFA
dsinclair221caf62016-04-04 12:08:40 -0700661 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
662 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc())
663 return pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700664 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700665#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700666 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667 return pFormCtrl->IsChecked();
668}
669
670int CPDFSDK_Widget::GetAlignment() const {
671 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700672 return pFormCtrl->GetControlAlignment();
673}
674
675int CPDFSDK_Widget::GetMaxLen() const {
676 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700677 return pFormField->GetMaxLen();
678}
679
Wei Li97da9762016-03-11 17:00:48 -0800680void CPDFSDK_Widget::SetCheck(bool bChecked, bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700682 CPDF_FormField* pFormField = pFormCtrl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700683 pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
684 bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800685#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686 if (!IsWidgetAppearanceValid(CPDF_Annot::Normal))
tsepez4cf55152016-11-02 14:37:54 -0700687 ResetAppearance(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700688 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700689 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800690#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691}
692
tsepez4cf55152016-11-02 14:37:54 -0700693void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700694 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700695 pFormField->SetValue(sValue, bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800696#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700698 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::SetDefaultValue(const CFX_WideString& sValue) {}
703void CPDFSDK_Widget::SetOptionSelection(int index,
tsepez4cf55152016-11-02 14:37:54 -0700704 bool bSelected,
705 bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700706 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707 pFormField->SetItemSelection(index, bSelected, bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800708#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700710 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800711#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700712}
713
tsepez4cf55152016-11-02 14:37:54 -0700714void CPDFSDK_Widget::ClearSelection(bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700715 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700716 pFormField->ClearSelection(bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800717#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700719 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::SetTopVisibleIndex(int index) {}
724
725void CPDFSDK_Widget::SetAppModified() {
tsepez4cf55152016-11-02 14:37:54 -0700726 m_bAppModified = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700727}
728
729void CPDFSDK_Widget::ClearAppModified() {
tsepez4cf55152016-11-02 14:37:54 -0700730 m_bAppModified = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731}
732
tsepez4cf55152016-11-02 14:37:54 -0700733bool CPDFSDK_Widget::IsAppModified() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734 return m_bAppModified;
735}
736
Tom Sepez51da0932015-11-25 16:05:49 -0800737#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700738void CPDFSDK_Widget::ResetAppearance(bool bValueChanged) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739 switch (GetFieldType()) {
740 case FIELDTYPE_TEXTFIELD:
741 case FIELDTYPE_COMBOBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700742 bool bFormatted = false;
tsepez8c2a8cd2016-09-07 15:29:11 -0700743 CFX_WideString sValue = OnFormat(bFormatted);
tsepez4cf55152016-11-02 14:37:54 -0700744 ResetAppearance(bFormatted ? &sValue : nullptr, true);
jaepark611adb82016-08-17 11:34:36 -0700745 break;
746 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747 default:
tsepez4cf55152016-11-02 14:37:54 -0700748 ResetAppearance(nullptr, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700749 break;
750 }
751}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800752#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700753
tsepeza31da742016-09-08 11:28:14 -0700754void CPDFSDK_Widget::ResetAppearance(const CFX_WideString* sValue,
tsepez4cf55152016-11-02 14:37:54 -0700755 bool bValueChanged) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700756 SetAppModified();
757
758 m_nAppAge++;
759 if (m_nAppAge > 999999)
760 m_nAppAge = 0;
761 if (bValueChanged)
762 m_nValueAge++;
763
764 int nFieldType = GetFieldType();
765
766 switch (nFieldType) {
767 case FIELDTYPE_PUSHBUTTON:
768 ResetAppearance_PushButton();
769 break;
770 case FIELDTYPE_CHECKBOX:
771 ResetAppearance_CheckBox();
772 break;
773 case FIELDTYPE_RADIOBUTTON:
774 ResetAppearance_RadioButton();
775 break;
776 case FIELDTYPE_COMBOBOX:
777 ResetAppearance_ComboBox(sValue);
778 break;
779 case FIELDTYPE_LISTBOX:
780 ResetAppearance_ListBox();
781 break;
782 case FIELDTYPE_TEXTFIELD:
783 ResetAppearance_TextField(sValue);
784 break;
785 }
786
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700787 m_pAnnot->ClearCachedAP();
788}
789
tsepez4cf55152016-11-02 14:37:54 -0700790CFX_WideString CPDFSDK_Widget::OnFormat(bool& bFormatted) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700791 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800792 ASSERT(pFormField);
tsepez8c2a8cd2016-09-07 15:29:11 -0700793 return m_pInterForm->OnFormat(pFormField, bFormatted);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700794}
795
tsepez4cf55152016-11-02 14:37:54 -0700796void CPDFSDK_Widget::ResetFieldAppearance(bool bValueChanged) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700797 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800798 ASSERT(pFormField);
thestig1cd352e2016-06-07 17:53:06 -0700799 m_pInterForm->ResetFieldAppearance(pFormField, nullptr, bValueChanged);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700800}
801
802void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800803 const CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700804 CPDF_Annot::AppearanceMode mode,
805 const CPDF_RenderOptions* pOptions) {
806 int nFieldType = GetFieldType();
807
808 if ((nFieldType == FIELDTYPE_CHECKBOX ||
809 nFieldType == FIELDTYPE_RADIOBUTTON) &&
810 mode == CPDF_Annot::Normal &&
811 !IsWidgetAppearanceValid(CPDF_Annot::Normal)) {
812 CFX_PathData pathData;
813
Tom Sepez281a9ea2016-02-26 14:24:28 -0800814 CFX_FloatRect rcAnnot = GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700815
816 pathData.AppendRect(rcAnnot.left, rcAnnot.bottom, rcAnnot.right,
817 rcAnnot.top);
818
819 CFX_GraphStateData gsd;
820 gsd.m_LineWidth = 0.0f;
821
822 pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA,
823 FXFILL_ALTERNATE);
824 } else {
825 CPDFSDK_BAAnnot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);
826 }
827}
828
829void CPDFSDK_Widget::UpdateField() {
830 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800831 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700832 m_pInterForm->UpdateField(pFormField);
833}
834
835void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
836 CPDFSDK_PageView* pPageView) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700837 int nFieldType = GetFieldType();
jaepark611adb82016-08-17 11:34:36 -0700838 if (!m_pInterForm->IsNeedHighLight(nFieldType))
839 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700840
jaepark611adb82016-08-17 11:34:36 -0700841 CFX_FloatRect rc = GetRect();
842 FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);
843 uint8_t alpha = m_pInterForm->GetHighlightAlpha();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700844
jaepark611adb82016-08-17 11:34:36 -0700845 CFX_FloatRect rcDevice;
jaepark611adb82016-08-17 11:34:36 -0700846 CFX_Matrix page2device;
847 pPageView->GetCurrentMatrix(page2device);
848 page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom),
849 rcDevice.left, rcDevice.bottom);
850 page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top),
851 rcDevice.right, rcDevice.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700852
jaepark611adb82016-08-17 11:34:36 -0700853 rcDevice.Normalize();
854
855 FX_ARGB argb = ArgbEncode((int)alpha, color);
856 FX_RECT rcDev((int)rcDevice.left, (int)rcDevice.top, (int)rcDevice.right,
857 (int)rcDevice.bottom);
858 pDevice->FillRect(&rcDev, argb);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700859}
860
861void CPDFSDK_Widget::ResetAppearance_PushButton() {
862 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800863 CFX_FloatRect rcWindow = GetRotatedRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700864 int32_t nLayout = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700865 switch (pControl->GetTextPosition()) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700866 case TEXTPOS_ICON:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700867 nLayout = PPBL_ICON;
868 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700869 case TEXTPOS_BELOW:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700870 nLayout = PPBL_ICONTOPLABELBOTTOM;
871 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700872 case TEXTPOS_ABOVE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700873 nLayout = PPBL_LABELTOPICONBOTTOM;
874 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700875 case TEXTPOS_RIGHT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700876 nLayout = PPBL_ICONLEFTLABELRIGHT;
877 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700878 case TEXTPOS_LEFT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700879 nLayout = PPBL_LABELLEFTICONRIGHT;
880 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700881 case TEXTPOS_OVERLAID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700882 nLayout = PPBL_LABELOVERICON;
883 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700884 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700885 nLayout = PPBL_LABEL;
886 break;
887 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700888
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700889 CPWL_Color crBackground, crBorder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700890
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700891 int iColorType;
892 FX_FLOAT fc[4];
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700893
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700894 pControl->GetOriginalBackgroundColor(iColorType, fc);
895 if (iColorType > 0)
896 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700897
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700898 pControl->GetOriginalBorderColor(iColorType, fc);
899 if (iColorType > 0)
900 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700901
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700902 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700903 CPWL_Dash dsBorder(3, 0, 0);
904 CPWL_Color crLeftTop, crRightBottom;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700905
dsinclair92cb5e52016-05-16 11:38:28 -0700906 BorderStyle nBorderStyle = GetBorderStyle();
907 switch (nBorderStyle) {
908 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700909 dsBorder = CPWL_Dash(3, 3, 0);
910 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700911 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700912 fBorderWidth *= 2;
913 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
914 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
915 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700916 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700917 fBorderWidth *= 2;
918 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
919 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
920 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700921 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700922 break;
923 }
924
Tom Sepez281a9ea2016-02-26 14:24:28 -0800925 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700926
927 CPWL_Color crText(COLORTYPE_GRAY, 0);
928
929 FX_FLOAT fFontSize = 12.0f;
930 CFX_ByteString csNameTag;
931
932 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
933 if (da.HasColor()) {
934 da.GetColor(iColorType, fc);
935 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
936 }
937
938 if (da.HasFont())
939 da.GetFont(csNameTag, fFontSize);
940
941 CFX_WideString csWCaption;
942 CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption;
943
jaepark611adb82016-08-17 11:34:36 -0700944 if (pControl->HasMKEntry("CA"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700945 csNormalCaption = pControl->GetNormalCaption();
jaepark611adb82016-08-17 11:34:36 -0700946
947 if (pControl->HasMKEntry("RC"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700948 csRolloverCaption = pControl->GetRolloverCaption();
jaepark611adb82016-08-17 11:34:36 -0700949
950 if (pControl->HasMKEntry("AC"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700951 csDownCaption = pControl->GetDownCaption();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700952
thestig1cd352e2016-06-07 17:53:06 -0700953 CPDF_Stream* pNormalIcon = nullptr;
954 CPDF_Stream* pRolloverIcon = nullptr;
955 CPDF_Stream* pDownIcon = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700956
jaepark611adb82016-08-17 11:34:36 -0700957 if (pControl->HasMKEntry("I"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700958 pNormalIcon = pControl->GetNormalIcon();
jaepark611adb82016-08-17 11:34:36 -0700959
960 if (pControl->HasMKEntry("RI"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700961 pRolloverIcon = pControl->GetRolloverIcon();
jaepark611adb82016-08-17 11:34:36 -0700962
963 if (pControl->HasMKEntry("IX"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700964 pDownIcon = pControl->GetDownIcon();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700965
966 if (pNormalIcon) {
967 if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -0700968 if (pImageDict->GetStringFor("Name").IsEmpty())
969 pImageDict->SetStringFor("Name", "ImgA");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700970 }
971 }
972
973 if (pRolloverIcon) {
974 if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -0700975 if (pImageDict->GetStringFor("Name").IsEmpty())
976 pImageDict->SetStringFor("Name", "ImgB");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700977 }
978 }
979
980 if (pDownIcon) {
981 if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -0700982 if (pImageDict->GetStringFor("Name").IsEmpty())
983 pImageDict->SetStringFor("Name", "ImgC");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700984 }
985 }
986
987 CPDF_IconFit iconFit = pControl->GetIconFit();
988
dsinclair690c0332016-10-11 09:13:01 -0700989 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
Lei Zhangfcfa3b82015-12-24 21:07:28 -0800990 font_map.SetAPType("N");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700991
992 CFX_ByteString csAP =
993 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
994 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
995 crLeftTop, crRightBottom, nBorderStyle,
996 dsBorder) +
997 CPWL_Utils::GetPushButtonAppStream(
Lei Zhangfcfa3b82015-12-24 21:07:28 -0800998 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700999 pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout);
1000
1001 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP);
1002 if (pNormalIcon)
1003 AddImageToAppearance("N", pNormalIcon);
1004
1005 CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode();
1006 if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) {
1007 if (csRolloverCaption.IsEmpty() && !pRolloverIcon) {
1008 csRolloverCaption = csNormalCaption;
1009 pRolloverIcon = pNormalIcon;
1010 }
1011
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001012 font_map.SetAPType("R");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001013
1014 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1015 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1016 crLeftTop, crRightBottom,
1017 nBorderStyle, dsBorder) +
1018 CPWL_Utils::GetPushButtonAppStream(
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001019 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001020 pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize,
1021 nLayout);
1022
1023 WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP);
1024 if (pRolloverIcon)
1025 AddImageToAppearance("R", pRolloverIcon);
1026
1027 if (csDownCaption.IsEmpty() && !pDownIcon) {
1028 csDownCaption = csNormalCaption;
1029 pDownIcon = pNormalIcon;
1030 }
1031
1032 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -07001033 case BorderStyle::BEVELED: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001034 CPWL_Color crTemp = crLeftTop;
1035 crLeftTop = crRightBottom;
1036 crRightBottom = crTemp;
dsinclair92cb5e52016-05-16 11:38:28 -07001037 break;
1038 }
1039 case BorderStyle::INSET: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001040 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1041 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001042 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001043 }
1044 default:
1045 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001046 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001047
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001048 font_map.SetAPType("D");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001049
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001050 csAP = CPWL_Utils::GetRectFillAppStream(
1051 rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) +
1052 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1053 crLeftTop, crRightBottom,
1054 nBorderStyle, dsBorder) +
1055 CPWL_Utils::GetPushButtonAppStream(
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001056 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001057 pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001058
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001059 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001060 if (pDownIcon)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001061 AddImageToAppearance("D", pDownIcon);
1062 } else {
1063 RemoveAppearance("D");
1064 RemoveAppearance("R");
1065 }
1066}
1067
1068void CPDFSDK_Widget::ResetAppearance_CheckBox() {
1069 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001070 CPWL_Color crBackground, crBorder, crText;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001071 int iColorType;
1072 FX_FLOAT fc[4];
1073
1074 pControl->GetOriginalBackgroundColor(iColorType, fc);
1075 if (iColorType > 0)
1076 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1077
1078 pControl->GetOriginalBorderColor(iColorType, fc);
1079 if (iColorType > 0)
1080 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1081
1082 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001083 CPWL_Dash dsBorder(3, 0, 0);
1084 CPWL_Color crLeftTop, crRightBottom;
1085
dsinclair92cb5e52016-05-16 11:38:28 -07001086 BorderStyle nBorderStyle = GetBorderStyle();
1087 switch (nBorderStyle) {
1088 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001089 dsBorder = CPWL_Dash(3, 3, 0);
1090 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001091 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001092 fBorderWidth *= 2;
1093 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1094 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
1095 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001096 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001097 fBorderWidth *= 2;
1098 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1099 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1100 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001101 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001102 break;
1103 }
1104
Tom Sepez281a9ea2016-02-26 14:24:28 -08001105 CFX_FloatRect rcWindow = GetRotatedRect();
1106 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001107
1108 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
1109 if (da.HasColor()) {
1110 da.GetColor(iColorType, fc);
1111 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1112 }
1113
1114 int32_t nStyle = 0;
1115
1116 CFX_WideString csWCaption = pControl->GetNormalCaption();
1117 if (csWCaption.GetLength() > 0) {
1118 switch (csWCaption[0]) {
1119 case L'l':
1120 nStyle = PCS_CIRCLE;
1121 break;
1122 case L'8':
1123 nStyle = PCS_CROSS;
1124 break;
1125 case L'u':
1126 nStyle = PCS_DIAMOND;
1127 break;
1128 case L'n':
1129 nStyle = PCS_SQUARE;
1130 break;
1131 case L'H':
1132 nStyle = PCS_STAR;
1133 break;
1134 default: // L'4'
1135 nStyle = PCS_CHECK;
1136 break;
1137 }
1138 } else {
1139 nStyle = PCS_CHECK;
1140 }
1141
1142 CFX_ByteString csAP_N_ON =
1143 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1144 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1145 crLeftTop, crRightBottom, nBorderStyle,
1146 dsBorder);
1147
1148 CFX_ByteString csAP_N_OFF = csAP_N_ON;
1149
1150 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -07001151 case BorderStyle::BEVELED: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001152 CPWL_Color crTemp = crLeftTop;
1153 crLeftTop = crRightBottom;
1154 crRightBottom = crTemp;
dsinclair92cb5e52016-05-16 11:38:28 -07001155 break;
1156 }
1157 case BorderStyle::INSET: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001158 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1159 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1160 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001161 }
1162 default:
1163 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001164 }
1165
1166 CFX_ByteString csAP_D_ON =
1167 CPWL_Utils::GetRectFillAppStream(
1168 rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) +
1169 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1170 crLeftTop, crRightBottom, nBorderStyle,
1171 dsBorder);
1172
1173 CFX_ByteString csAP_D_OFF = csAP_D_ON;
1174
1175 csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
1176 csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
1177
1178 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
1179 pControl->GetCheckedAPState());
1180 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
1181
1182 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
1183 pControl->GetCheckedAPState());
1184 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
1185
1186 CFX_ByteString csAS = GetAppState();
1187 if (csAS.IsEmpty())
1188 SetAppState("Off");
1189}
1190
1191void CPDFSDK_Widget::ResetAppearance_RadioButton() {
1192 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001193 CPWL_Color crBackground, crBorder, crText;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001194 int iColorType;
1195 FX_FLOAT fc[4];
1196
1197 pControl->GetOriginalBackgroundColor(iColorType, fc);
1198 if (iColorType > 0)
1199 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1200
1201 pControl->GetOriginalBorderColor(iColorType, fc);
1202 if (iColorType > 0)
1203 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1204
1205 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001206 CPWL_Dash dsBorder(3, 0, 0);
1207 CPWL_Color crLeftTop, crRightBottom;
1208
dsinclair92cb5e52016-05-16 11:38:28 -07001209 BorderStyle nBorderStyle = GetBorderStyle();
1210 switch (nBorderStyle) {
1211 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001212 dsBorder = CPWL_Dash(3, 3, 0);
1213 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001214 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001215 fBorderWidth *= 2;
1216 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1217 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
1218 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001219 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001220 fBorderWidth *= 2;
1221 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1222 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1223 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001224 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001225 break;
1226 }
1227
Tom Sepez281a9ea2016-02-26 14:24:28 -08001228 CFX_FloatRect rcWindow = GetRotatedRect();
1229 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001230
1231 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
1232 if (da.HasColor()) {
1233 da.GetColor(iColorType, fc);
1234 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1235 }
1236
1237 int32_t nStyle = 0;
1238
1239 CFX_WideString csWCaption = pControl->GetNormalCaption();
1240 if (csWCaption.GetLength() > 0) {
1241 switch (csWCaption[0]) {
1242 default: // L'l':
1243 nStyle = PCS_CIRCLE;
1244 break;
1245 case L'8':
1246 nStyle = PCS_CROSS;
1247 break;
1248 case L'u':
1249 nStyle = PCS_DIAMOND;
1250 break;
1251 case L'n':
1252 nStyle = PCS_SQUARE;
1253 break;
1254 case L'H':
1255 nStyle = PCS_STAR;
1256 break;
1257 case L'4':
1258 nStyle = PCS_CHECK;
1259 break;
1260 }
1261 } else {
1262 nStyle = PCS_CIRCLE;
1263 }
1264
1265 CFX_ByteString csAP_N_ON;
1266
Tom Sepez281a9ea2016-02-26 14:24:28 -08001267 CFX_FloatRect rcCenter =
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001268 CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f);
1269
1270 if (nStyle == PCS_CIRCLE) {
dsinclair92cb5e52016-05-16 11:38:28 -07001271 if (nBorderStyle == BorderStyle::BEVELED) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001272 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1273 crRightBottom = CPWL_Utils::SubstractColor(crBackground, 0.25f);
dsinclair92cb5e52016-05-16 11:38:28 -07001274 } else if (nBorderStyle == BorderStyle::INSET) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001275 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5f);
1276 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75f);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001277 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001278
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001279 csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBackground) +
1280 CPWL_Utils::GetCircleBorderAppStream(
1281 rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
1282 nBorderStyle, dsBorder);
1283 } else {
1284 csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1285 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1286 crLeftTop, crRightBottom,
1287 nBorderStyle, dsBorder);
1288 }
1289
1290 CFX_ByteString csAP_N_OFF = csAP_N_ON;
1291
1292 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -07001293 case BorderStyle::BEVELED: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001294 CPWL_Color crTemp = crLeftTop;
1295 crLeftTop = crRightBottom;
1296 crRightBottom = crTemp;
dsinclair92cb5e52016-05-16 11:38:28 -07001297 break;
1298 }
1299 case BorderStyle::INSET: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001300 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1301 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1302 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001303 }
1304 default:
1305 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001306 }
1307
1308 CFX_ByteString csAP_D_ON;
1309
1310 if (nStyle == PCS_CIRCLE) {
1311 CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground, 0.25f);
dsinclair92cb5e52016-05-16 11:38:28 -07001312 if (nBorderStyle == BorderStyle::BEVELED) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001313 crLeftTop = CPWL_Utils::SubstractColor(crBackground, 0.25f);
1314 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1315 crBK = crBackground;
dsinclair92cb5e52016-05-16 11:38:28 -07001316 } else if (nBorderStyle == BorderStyle::INSET) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001317 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1318 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1319 }
1320
1321 csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBK) +
1322 CPWL_Utils::GetCircleBorderAppStream(
1323 rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
1324 nBorderStyle, dsBorder);
1325 } else {
1326 csAP_D_ON = CPWL_Utils::GetRectFillAppStream(
1327 rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) +
1328 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1329 crLeftTop, crRightBottom,
1330 nBorderStyle, dsBorder);
1331 }
1332
1333 CFX_ByteString csAP_D_OFF = csAP_D_ON;
1334
1335 csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
1336 csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
1337
1338 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
1339 pControl->GetCheckedAPState());
1340 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
1341
1342 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
1343 pControl->GetCheckedAPState());
1344 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
1345
1346 CFX_ByteString csAS = GetAppState();
1347 if (csAS.IsEmpty())
1348 SetAppState("Off");
1349}
1350
tsepeza31da742016-09-08 11:28:14 -07001351void CPDFSDK_Widget::ResetAppearance_ComboBox(const CFX_WideString* sValue) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001352 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001353 CPDF_FormField* pField = pControl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001354 CFX_ByteTextBuf sBody, sLines;
1355
Tom Sepez281a9ea2016-02-26 14:24:28 -08001356 CFX_FloatRect rcClient = GetClientRect();
1357 CFX_FloatRect rcButton = rcClient;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001358 rcButton.left = rcButton.right - 13;
1359 rcButton.Normalize();
1360
dsinclaire35af1e2016-07-13 11:26:20 -07001361 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit);
tsepez4cf55152016-11-02 14:37:54 -07001362 pEdit->EnableRefresh(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001363
dsinclair690c0332016-10-11 09:13:01 -07001364 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
thestig732f6a02016-05-12 10:41:56 -07001365 pEdit->SetFontMap(&font_map);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001366
thestig732f6a02016-05-12 10:41:56 -07001367 CFX_FloatRect rcEdit = rcClient;
1368 rcEdit.right = rcButton.left;
1369 rcEdit.Normalize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001370
thestig732f6a02016-05-12 10:41:56 -07001371 pEdit->SetPlateRect(rcEdit);
tsepez4cf55152016-11-02 14:37:54 -07001372 pEdit->SetAlignmentV(1, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001373
thestig732f6a02016-05-12 10:41:56 -07001374 FX_FLOAT fFontSize = GetFontSize();
1375 if (IsFloatZero(fFontSize))
tsepez4cf55152016-11-02 14:37:54 -07001376 pEdit->SetAutoFontSize(true, true);
thestig732f6a02016-05-12 10:41:56 -07001377 else
1378 pEdit->SetFontSize(fFontSize);
1379
1380 pEdit->Initialize();
1381
1382 if (sValue) {
tsepeza31da742016-09-08 11:28:14 -07001383 pEdit->SetText(*sValue);
thestig732f6a02016-05-12 10:41:56 -07001384 } else {
1385 int32_t nCurSel = pField->GetSelectedIndex(0);
thestig732f6a02016-05-12 10:41:56 -07001386 if (nCurSel < 0)
tsepez067990c2016-09-13 06:46:40 -07001387 pEdit->SetText(pField->GetValue());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001388 else
tsepez067990c2016-09-13 06:46:40 -07001389 pEdit->SetText(pField->GetOptionLabel(nCurSel));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001390 }
1391
thestig732f6a02016-05-12 10:41:56 -07001392 CFX_FloatRect rcContent = pEdit->GetContentRect();
1393
1394 CFX_ByteString sEdit =
tsepez63f545c2016-09-13 16:08:49 -07001395 CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_FloatPoint());
thestig732f6a02016-05-12 10:41:56 -07001396 if (sEdit.GetLength() > 0) {
1397 sBody << "/Tx BMC\n"
1398 << "q\n";
1399 if (rcContent.Width() > rcEdit.Width() ||
1400 rcContent.Height() > rcEdit.Height()) {
1401 sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width()
1402 << " " << rcEdit.Height() << " re\nW\nn\n";
1403 }
1404
1405 CPWL_Color crText = GetTextPWLColor();
1406 sBody << "BT\n"
1407 << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"
1408 << "Q\nEMC\n";
1409 }
1410
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001411 sBody << CPWL_Utils::GetDropButtonAppStream(rcButton);
1412
1413 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
tsepez8e4c5052016-04-14 13:42:44 -07001414 sLines.AsStringC() + sBody.AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001415
1416 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1417}
1418
1419void CPDFSDK_Widget::ResetAppearance_ListBox() {
1420 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001421 CPDF_FormField* pField = pControl->GetField();
Tom Sepez281a9ea2016-02-26 14:24:28 -08001422 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001423 CFX_ByteTextBuf sBody, sLines;
1424
dsinclaire35af1e2016-07-13 11:26:20 -07001425 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit);
tsepez4cf55152016-11-02 14:37:54 -07001426 pEdit->EnableRefresh(false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001427
dsinclair690c0332016-10-11 09:13:01 -07001428 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
thestig732f6a02016-05-12 10:41:56 -07001429 pEdit->SetFontMap(&font_map);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001430
thestig732f6a02016-05-12 10:41:56 -07001431 pEdit->SetPlateRect(CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001432
thestig732f6a02016-05-12 10:41:56 -07001433 FX_FLOAT fFontSize = GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001434
thestig594b20b2016-05-12 21:56:43 -07001435 pEdit->SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001436
thestig732f6a02016-05-12 10:41:56 -07001437 pEdit->Initialize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001438
thestig732f6a02016-05-12 10:41:56 -07001439 CFX_ByteTextBuf sList;
1440 FX_FLOAT fy = rcClient.top;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001441
thestig732f6a02016-05-12 10:41:56 -07001442 int32_t nTop = pField->GetTopVisibleIndex();
1443 int32_t nCount = pField->CountOptions();
1444 int32_t nSelCount = pField->CountSelectedItems();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001445
thestig594b20b2016-05-12 21:56:43 -07001446 for (int32_t i = nTop; i < nCount; ++i) {
1447 bool bSelected = false;
1448 for (int32_t j = 0; j < nSelCount; ++j) {
thestig732f6a02016-05-12 10:41:56 -07001449 if (pField->GetSelectedIndex(j) == i) {
thestig594b20b2016-05-12 21:56:43 -07001450 bSelected = true;
thestig732f6a02016-05-12 10:41:56 -07001451 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001452 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001453 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001454
tsepez067990c2016-09-13 06:46:40 -07001455 pEdit->SetText(pField->GetOptionLabel(i));
thestig732f6a02016-05-12 10:41:56 -07001456
1457 CFX_FloatRect rcContent = pEdit->GetContentRect();
1458 FX_FLOAT fItemHeight = rcContent.Height();
1459
1460 if (bSelected) {
1461 CFX_FloatRect rcItem =
1462 CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy);
1463 sList << "q\n"
1464 << CPWL_Utils::GetColorAppStream(
1465 CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f,
1466 113.0f / 255.0f),
tsepez4cf55152016-11-02 14:37:54 -07001467 true)
thestig732f6a02016-05-12 10:41:56 -07001468 << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width()
1469 << " " << rcItem.Height() << " re f\n"
1470 << "Q\n";
1471
1472 sList << "BT\n"
1473 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1),
tsepez4cf55152016-11-02 14:37:54 -07001474 true)
dsinclaire35af1e2016-07-13 11:26:20 -07001475 << CPWL_Utils::GetEditAppStream(pEdit.get(),
1476 CFX_FloatPoint(0.0f, fy))
thestig732f6a02016-05-12 10:41:56 -07001477 << "ET\n";
1478 } else {
1479 CPWL_Color crText = GetTextPWLColor();
1480 sList << "BT\n"
tsepez4cf55152016-11-02 14:37:54 -07001481 << CPWL_Utils::GetColorAppStream(crText, true)
dsinclaire35af1e2016-07-13 11:26:20 -07001482 << CPWL_Utils::GetEditAppStream(pEdit.get(),
1483 CFX_FloatPoint(0.0f, fy))
thestig732f6a02016-05-12 10:41:56 -07001484 << "ET\n";
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001485 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001486
thestig732f6a02016-05-12 10:41:56 -07001487 fy -= fItemHeight;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001488 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001489
thestig732f6a02016-05-12 10:41:56 -07001490 if (sList.GetSize() > 0) {
1491 sBody << "/Tx BMC\n"
1492 << "q\n"
1493 << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width()
1494 << " " << rcClient.Height() << " re\nW\nn\n";
1495 sBody << sList << "Q\nEMC\n";
1496 }
1497
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001498 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
tsepez8e4c5052016-04-14 13:42:44 -07001499 sLines.AsStringC() + sBody.AsStringC();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001500
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001501 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001502}
1503
tsepeza31da742016-09-08 11:28:14 -07001504void CPDFSDK_Widget::ResetAppearance_TextField(const CFX_WideString* sValue) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001505 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001506 CPDF_FormField* pField = pControl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001507 CFX_ByteTextBuf sBody, sLines;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001508
dsinclaire35af1e2016-07-13 11:26:20 -07001509 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit);
tsepez4cf55152016-11-02 14:37:54 -07001510 pEdit->EnableRefresh(false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001511
dsinclair690c0332016-10-11 09:13:01 -07001512 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
thestig732f6a02016-05-12 10:41:56 -07001513 pEdit->SetFontMap(&font_map);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001514
thestig732f6a02016-05-12 10:41:56 -07001515 CFX_FloatRect rcClient = GetClientRect();
1516 pEdit->SetPlateRect(rcClient);
tsepez4cf55152016-11-02 14:37:54 -07001517 pEdit->SetAlignmentH(pControl->GetControlAlignment(), true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001518
thestig732f6a02016-05-12 10:41:56 -07001519 uint32_t dwFieldFlags = pField->GetFieldFlags();
tsepez4cf55152016-11-02 14:37:54 -07001520 bool bMultiLine = (dwFieldFlags >> 12) & 1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001521
thestig732f6a02016-05-12 10:41:56 -07001522 if (bMultiLine) {
tsepez4cf55152016-11-02 14:37:54 -07001523 pEdit->SetMultiLine(true, true);
1524 pEdit->SetAutoReturn(true, true);
thestig732f6a02016-05-12 10:41:56 -07001525 } else {
tsepez4cf55152016-11-02 14:37:54 -07001526 pEdit->SetAlignmentV(1, true);
thestig732f6a02016-05-12 10:41:56 -07001527 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001528
thestig732f6a02016-05-12 10:41:56 -07001529 uint16_t subWord = 0;
1530 if ((dwFieldFlags >> 13) & 1) {
1531 subWord = '*';
tsepez4cf55152016-11-02 14:37:54 -07001532 pEdit->SetPasswordChar(subWord, true);
thestig732f6a02016-05-12 10:41:56 -07001533 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001534
thestig732f6a02016-05-12 10:41:56 -07001535 int nMaxLen = pField->GetMaxLen();
tsepez4cf55152016-11-02 14:37:54 -07001536 bool bCharArray = (dwFieldFlags >> 24) & 1;
thestig732f6a02016-05-12 10:41:56 -07001537 FX_FLOAT fFontSize = GetFontSize();
Bo Xufdc00a72014-10-28 23:03:33 -07001538
Tom Sepez51da0932015-11-25 16:05:49 -08001539#ifdef PDF_ENABLE_XFA
thestig732f6a02016-05-12 10:41:56 -07001540 CFX_WideString sValueTmp;
1541 if (!sValue && GetMixXFAWidget()) {
tsepez4cf55152016-11-02 14:37:54 -07001542 sValueTmp = GetValue(true);
tsepeza31da742016-09-08 11:28:14 -07001543 sValue = &sValueTmp;
thestig732f6a02016-05-12 10:41:56 -07001544 }
Tom Sepez40e9ff32015-11-30 12:39:54 -08001545#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001546
thestig732f6a02016-05-12 10:41:56 -07001547 if (nMaxLen > 0) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001548 if (bCharArray) {
thestig732f6a02016-05-12 10:41:56 -07001549 pEdit->SetCharArray(nMaxLen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001550
thestig732f6a02016-05-12 10:41:56 -07001551 if (IsFloatZero(fFontSize)) {
1552 fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0),
1553 rcClient, nMaxLen);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001554 }
thestig732f6a02016-05-12 10:41:56 -07001555 } else {
1556 if (sValue)
tsepeza31da742016-09-08 11:28:14 -07001557 nMaxLen = sValue->GetLength();
thestig732f6a02016-05-12 10:41:56 -07001558 pEdit->SetLimitChar(nMaxLen);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001559 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001560 }
1561
thestig732f6a02016-05-12 10:41:56 -07001562 if (IsFloatZero(fFontSize))
tsepez4cf55152016-11-02 14:37:54 -07001563 pEdit->SetAutoFontSize(true, true);
thestig732f6a02016-05-12 10:41:56 -07001564 else
1565 pEdit->SetFontSize(fFontSize);
1566
1567 pEdit->Initialize();
tsepez067990c2016-09-13 06:46:40 -07001568 pEdit->SetText(sValue ? *sValue : pField->GetValue());
thestig732f6a02016-05-12 10:41:56 -07001569
1570 CFX_FloatRect rcContent = pEdit->GetContentRect();
thestig732f6a02016-05-12 10:41:56 -07001571 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(
tsepez63f545c2016-09-13 16:08:49 -07001572 pEdit.get(), CFX_FloatPoint(), nullptr, !bCharArray, subWord);
thestig732f6a02016-05-12 10:41:56 -07001573
1574 if (sEdit.GetLength() > 0) {
1575 sBody << "/Tx BMC\n"
1576 << "q\n";
1577 if (rcContent.Width() > rcClient.Width() ||
1578 rcContent.Height() > rcClient.Height()) {
1579 sBody << rcClient.left << " " << rcClient.bottom << " "
1580 << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
1581 }
1582 CPWL_Color crText = GetTextPWLColor();
1583 sBody << "BT\n"
1584 << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"
1585 << "Q\nEMC\n";
1586 }
1587
1588 if (bCharArray) {
1589 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -07001590 case BorderStyle::SOLID: {
thestig732f6a02016-05-12 10:41:56 -07001591 CFX_ByteString sColor =
tsepez4cf55152016-11-02 14:37:54 -07001592 CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false);
thestig732f6a02016-05-12 10:41:56 -07001593 if (sColor.GetLength() > 0) {
1594 sLines << "q\n"
1595 << GetBorderWidth() << " w\n"
tsepez4cf55152016-11-02 14:37:54 -07001596 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false)
thestig732f6a02016-05-12 10:41:56 -07001597 << " 2 J 0 j\n";
1598
thestig594b20b2016-05-12 21:56:43 -07001599 for (int32_t i = 1; i < nMaxLen; ++i) {
thestig732f6a02016-05-12 10:41:56 -07001600 sLines << rcClient.left +
1601 ((rcClient.right - rcClient.left) / nMaxLen) * i
1602 << " " << rcClient.bottom << " m\n"
1603 << rcClient.left +
1604 ((rcClient.right - rcClient.left) / nMaxLen) * i
1605 << " " << rcClient.top << " l S\n";
1606 }
1607
1608 sLines << "Q\n";
1609 }
dsinclair92cb5e52016-05-16 11:38:28 -07001610 break;
1611 }
1612 case BorderStyle::DASH: {
thestig732f6a02016-05-12 10:41:56 -07001613 CFX_ByteString sColor =
tsepez4cf55152016-11-02 14:37:54 -07001614 CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false);
thestig732f6a02016-05-12 10:41:56 -07001615 if (sColor.GetLength() > 0) {
1616 CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0);
1617
1618 sLines << "q\n"
1619 << GetBorderWidth() << " w\n"
tsepez4cf55152016-11-02 14:37:54 -07001620 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false)
thestig732f6a02016-05-12 10:41:56 -07001621 << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] "
1622 << dsBorder.nPhase << " d\n";
1623
thestig594b20b2016-05-12 21:56:43 -07001624 for (int32_t i = 1; i < nMaxLen; ++i) {
thestig732f6a02016-05-12 10:41:56 -07001625 sLines << rcClient.left +
1626 ((rcClient.right - rcClient.left) / nMaxLen) * i
1627 << " " << rcClient.bottom << " m\n"
1628 << rcClient.left +
1629 ((rcClient.right - rcClient.left) / nMaxLen) * i
1630 << " " << rcClient.top << " l S\n";
1631 }
1632
1633 sLines << "Q\n";
1634 }
dsinclair92cb5e52016-05-16 11:38:28 -07001635 break;
1636 }
1637 default:
1638 break;
thestig732f6a02016-05-12 10:41:56 -07001639 }
1640 }
1641
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001642 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
tsepez8e4c5052016-04-14 13:42:44 -07001643 sLines.AsStringC() + sBody.AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001644 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001645}
1646
Tom Sepez281a9ea2016-02-26 14:24:28 -08001647CFX_FloatRect CPDFSDK_Widget::GetClientRect() const {
1648 CFX_FloatRect rcWindow = GetRotatedRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001649 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
1650 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -07001651 case BorderStyle::BEVELED:
1652 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001653 fBorderWidth *= 2.0f;
1654 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001655 default:
1656 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001657 }
1658
1659 return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001660}
1661
Tom Sepez281a9ea2016-02-26 14:24:28 -08001662CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const {
1663 CFX_FloatRect rectAnnot = GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001664 FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left;
1665 FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;
1666
1667 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -08001668 CFX_FloatRect rcPDFWindow;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001669 switch (abs(pControl->GetRotation() % 360)) {
1670 case 0:
1671 case 180:
1672 default:
Tom Sepez281a9ea2016-02-26 14:24:28 -08001673 rcPDFWindow = CFX_FloatRect(0, 0, fWidth, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001674 break;
1675 case 90:
1676 case 270:
Tom Sepez281a9ea2016-02-26 14:24:28 -08001677 rcPDFWindow = CFX_FloatRect(0, 0, fHeight, fWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001678 break;
1679 }
1680
1681 return rcPDFWindow;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001682}
1683
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001684CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const {
1685 CPWL_Color crBackground = GetFillPWLColor();
jaepark611adb82016-08-17 11:34:36 -07001686 if (crBackground.nColorType != COLORTYPE_TRANSPARENT)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001687 return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);
jaepark611adb82016-08-17 11:34:36 -07001688
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001689 return "";
Bo Xufdc00a72014-10-28 23:03:33 -07001690}
1691
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001692CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001693 CFX_FloatRect rcWindow = GetRotatedRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001694 CPWL_Color crBorder = GetBorderPWLColor();
1695 CPWL_Color crBackground = GetFillPWLColor();
1696 CPWL_Color crLeftTop, crRightBottom;
1697
1698 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001699 CPWL_Dash dsBorder(3, 0, 0);
1700
dsinclair92cb5e52016-05-16 11:38:28 -07001701 BorderStyle nBorderStyle = GetBorderStyle();
1702 switch (nBorderStyle) {
1703 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001704 dsBorder = CPWL_Dash(3, 3, 0);
1705 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001706 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001707 fBorderWidth *= 2;
1708 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1709 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
1710 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001711 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001712 fBorderWidth *= 2;
1713 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1714 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1715 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001716 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001717 break;
1718 }
1719
1720 return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1721 crLeftTop, crRightBottom, nBorderStyle,
1722 dsBorder);
Bo Xufdc00a72014-10-28 23:03:33 -07001723}
1724
Tom Sepez60d909e2015-12-10 15:34:55 -08001725CFX_Matrix CPDFSDK_Widget::GetMatrix() const {
1726 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001727 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -08001728 CFX_FloatRect rcAnnot = GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001729 FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left;
1730 FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom;
1731
1732 switch (abs(pControl->GetRotation() % 360)) {
1733 case 0:
1734 default:
Tom Sepez60d909e2015-12-10 15:34:55 -08001735 mt = CFX_Matrix(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001736 break;
1737 case 90:
Tom Sepez60d909e2015-12-10 15:34:55 -08001738 mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001739 break;
1740 case 180:
Tom Sepez60d909e2015-12-10 15:34:55 -08001741 mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001742 break;
1743 case 270:
Tom Sepez60d909e2015-12-10 15:34:55 -08001744 mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001745 break;
1746 }
1747
1748 return mt;
Bo Xufdc00a72014-10-28 23:03:33 -07001749}
1750
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001751CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const {
1752 CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0);
1753
1754 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001755 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
1756 if (da.HasColor()) {
1757 int32_t iColorType;
1758 FX_FLOAT fc[4];
1759 da.GetColor(iColorType, fc);
1760 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1761 }
1762
1763 return crText;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001764}
1765
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001766CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const {
1767 CPWL_Color crBorder;
1768
1769 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001770 int32_t iColorType;
1771 FX_FLOAT fc[4];
1772 pFormCtrl->GetOriginalBorderColor(iColorType, fc);
1773 if (iColorType > 0)
1774 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1775
1776 return crBorder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001777}
1778
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001779CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const {
1780 CPWL_Color crFill;
1781
1782 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001783 int32_t iColorType;
1784 FX_FLOAT fc[4];
1785 pFormCtrl->GetOriginalBackgroundColor(iColorType, fc);
1786 if (iColorType > 0)
1787 crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1788
1789 return crFill;
Bo Xufdc00a72014-10-28 23:03:33 -07001790}
1791
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001792void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType,
1793 CPDF_Stream* pImage) {
dsinclair38fd8442016-09-15 10:15:32 -07001794 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
1795 CPDF_Stream* pStream = pAPDict->GetStreamFor(sAPType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001796 CPDF_Dictionary* pStreamDict = pStream->GetDict();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001797 CFX_ByteString sImageAlias = "IMG";
1798
1799 if (CPDF_Dictionary* pImageDict = pImage->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -07001800 sImageAlias = pImageDict->GetStringFor("Name");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001801 if (sImageAlias.IsEmpty())
1802 sImageAlias = "IMG";
1803 }
1804
tsepez698c5712016-09-28 16:47:07 -07001805 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
dsinclair38fd8442016-09-15 10:15:32 -07001806 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001807 if (!pStreamResList) {
tsepez698c5712016-09-28 16:47:07 -07001808 pStreamResList = new CPDF_Dictionary(pDoc->GetByteStringPool());
dsinclair38fd8442016-09-15 10:15:32 -07001809 pStreamDict->SetFor("Resources", pStreamResList);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001810 }
1811
tsepez698c5712016-09-28 16:47:07 -07001812 CPDF_Dictionary* pXObject = new CPDF_Dictionary(pDoc->GetByteStringPool());
Tom Sepezc25a4212016-10-14 17:45:56 -07001813 pXObject->SetReferenceFor(sImageAlias, pDoc, pImage->GetObjNum());
tsepezbb577af2016-09-21 19:10:19 -07001814 pStreamResList->SetFor("XObject", pXObject);
Bo Xufdc00a72014-10-28 23:03:33 -07001815}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001816
1817void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) {
dsinclair38fd8442016-09-15 10:15:32 -07001818 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"))
1819 pAPDict->RemoveFor(sAPType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001820}
1821
tsepez4cf55152016-11-02 14:37:54 -07001822bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
1823 PDFSDK_FieldAction& data,
1824 CPDFSDK_PageView* pPageView) {
dsinclairb402b172016-10-11 09:26:32 -07001825 CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001826
Tom Sepez40e9ff32015-11-30 12:39:54 -08001827#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -07001828 CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext();
dsinclairdf4bc592016-03-31 20:34:43 -07001829 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001830 XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit);
1831
1832 if (eEventType != XFA_EVENT_Unknown) {
dsinclairdf4bc592016-03-31 20:34:43 -07001833 if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001834 CXFA_EventParam param;
1835 param.m_eType = eEventType;
1836 param.m_wsChange = data.sChange;
1837 param.m_iCommitKey = data.nCommitKey;
1838 param.m_bShift = data.bShift;
1839 param.m_iSelStart = data.nSelStart;
1840 param.m_iSelEnd = data.nSelEnd;
1841 param.m_wsFullText = data.sValue;
1842 param.m_bKeyDown = data.bKeyDown;
1843 param.m_bModifier = data.bModifier;
1844 param.m_wsNewText = data.sValue;
1845 if (data.nSelEnd > data.nSelStart)
1846 param.m_wsNewText.Delete(data.nSelStart,
1847 data.nSelEnd - data.nSelStart);
1848 for (int i = data.sChange.GetLength() - 1; i >= 0; i--)
1849 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
1850 param.m_wsPrevText = data.sValue;
1851
dsinclair221caf62016-04-04 12:08:40 -07001852 CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001853 param.m_pTarget = pAcc;
1854 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
1855
dsinclair521b7502016-11-02 13:02:28 -07001856 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001857 pDocView->UpdateDocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001858
Wei Lie98ac2e2016-03-18 15:43:04 -07001859 if (nRet == XFA_EVENTERROR_Success)
tsepez4cf55152016-11-02 14:37:54 -07001860 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001861 }
1862 }
1863 }
Tom Sepez40e9ff32015-11-30 12:39:54 -08001864#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001865
1866 CPDF_Action action = GetAAction(type);
Wei Li0fc6b252016-03-01 16:29:41 -08001867 if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) {
dsinclairb402b172016-10-11 09:26:32 -07001868 CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander();
dsinclair19c198b2016-10-11 12:51:37 -07001869 return pActionHandler->DoAction_Field(action, type, pFormFillEnv,
1870 GetFormField(), data);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001871 }
tsepez4cf55152016-11-02 14:37:54 -07001872 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001873}
1874
1875CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) {
1876 switch (eAAT) {
1877 case CPDF_AAction::CursorEnter:
1878 case CPDF_AAction::CursorExit:
1879 case CPDF_AAction::ButtonDown:
1880 case CPDF_AAction::ButtonUp:
1881 case CPDF_AAction::GetFocus:
1882 case CPDF_AAction::LoseFocus:
1883 case CPDF_AAction::PageOpen:
1884 case CPDF_AAction::PageClose:
1885 case CPDF_AAction::PageVisible:
1886 case CPDF_AAction::PageInvisible:
1887 return CPDFSDK_BAAnnot::GetAAction(eAAT);
1888
1889 case CPDF_AAction::KeyStroke:
1890 case CPDF_AAction::Format:
1891 case CPDF_AAction::Validate:
1892 case CPDF_AAction::Calculate: {
1893 CPDF_FormField* pField = GetFormField();
Wei Li0fc6b252016-03-01 16:29:41 -08001894 if (pField->GetAdditionalAction().GetDict())
1895 return pField->GetAdditionalAction().GetAction(eAAT);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001896 return CPDFSDK_BAAnnot::GetAAction(eAAT);
1897 }
1898 default:
1899 break;
1900 }
1901
1902 return CPDF_Action();
1903}
1904
1905CFX_WideString CPDFSDK_Widget::GetAlternateName() const {
1906 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001907 return pFormField->GetAlternateName();
1908}
1909
1910int32_t CPDFSDK_Widget::GetAppearanceAge() const {
1911 return m_nAppAge;
1912}
1913
1914int32_t CPDFSDK_Widget::GetValueAge() const {
1915 return m_nValueAge;
1916}
1917
tsepez4cf55152016-11-02 14:37:54 -07001918bool CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001919 CPDF_Annot* pAnnot = GetPDFAnnot();
jaeparka1d21112016-08-25 13:33:34 -07001920 CFX_FloatRect annotRect = pAnnot->GetRect();
jaepark611adb82016-08-17 11:34:36 -07001921 if (!annotRect.Contains(pageX, pageY))
tsepez4cf55152016-11-02 14:37:54 -07001922 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001923
jaepark611adb82016-08-17 11:34:36 -07001924 if (!IsVisible())
tsepez4cf55152016-11-02 14:37:54 -07001925 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001926
jaepark611adb82016-08-17 11:34:36 -07001927 if ((GetFieldFlags() & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
tsepez4cf55152016-11-02 14:37:54 -07001928 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001929
tsepez4cf55152016-11-02 14:37:54 -07001930 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001931}