blob: 108690665c95cb3d5510530b1f4edeab1d5743be [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
tsepez0e606b52016-11-18 16:22:41 -080011#include "core/fpdfapi/parser/cpdf_array.h"
dsinclair488b7ad2016-10-04 11:55:50 -070012#include "core/fpdfapi/parser/cpdf_dictionary.h"
13#include "core/fpdfapi/parser/cpdf_document.h"
tsepez0e606b52016-11-18 16:22:41 -080014#include "core/fpdfapi/parser/cpdf_reference.h"
dsinclair488b7ad2016-10-04 11:55:50 -070015#include "core/fpdfapi/parser/cpdf_stream.h"
tsepez0e606b52016-11-18 16:22:41 -080016#include "core/fpdfapi/parser/cpdf_string.h"
dsinclair1727aee2016-09-29 13:12:56 -070017#include "core/fpdfdoc/cpdf_defaultappearance.h"
18#include "core/fpdfdoc/cpdf_formcontrol.h"
19#include "core/fpdfdoc/cpdf_formfield.h"
20#include "core/fpdfdoc/cpdf_iconfit.h"
21#include "core/fpdfdoc/cpdf_interform.h"
dsinclair74a34fc2016-09-29 16:41:42 -070022#include "core/fxge/cfx_graphstatedata.h"
23#include "core/fxge/cfx_pathdata.h"
24#include "core/fxge/cfx_renderdevice.h"
dsinclair735606d2016-10-05 15:47:02 -070025#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070026#include "fpdfsdk/cpdfsdk_interform.h"
27#include "fpdfsdk/cpdfsdk_pageview.h"
jaepark611adb82016-08-17 11:34:36 -070028#include "fpdfsdk/formfiller/cba_fontmap.h"
dsinclair114e46a2016-09-29 17:18:21 -070029#include "fpdfsdk/fsdk_actionhandler.h"
30#include "fpdfsdk/fsdk_define.h"
dsinclair0bb385b2016-09-29 17:03:59 -070031#include "fpdfsdk/fxedit/fxet_edit.h"
jaepark611adb82016-08-17 11:34:36 -070032#include "fpdfsdk/pdfwindow/PWL_Edit.h"
dan sinclair89e904b2016-03-23 19:29:15 -040033#include "fpdfsdk/pdfwindow/PWL_Utils.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070034
Tom Sepez40e9ff32015-11-30 12:39:54 -080035#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -070036#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
dsinclair5b493092016-09-29 20:20:24 -070037#include "xfa/fxfa/cxfa_eventparam.h"
38#include "xfa/fxfa/fxfa_widget.h"
39#include "xfa/fxfa/xfa_ffdocview.h"
40#include "xfa/fxfa/xfa_ffwidget.h"
41#include "xfa/fxfa/xfa_ffwidgethandler.h"
Tom Sepez40e9ff32015-11-30 12:39:54 -080042#endif // PDF_ENABLE_XFA
43
dsinclair72177da2016-09-15 12:07:23 -070044namespace {
45
46// Convert a FX_ARGB to a FX_COLORREF.
47FX_COLORREF ARGBToColorRef(FX_ARGB argb) {
48 return (((static_cast<uint32_t>(argb) & 0x00FF0000) >> 16) |
49 (static_cast<uint32_t>(argb) & 0x0000FF00) |
50 ((static_cast<uint32_t>(argb) & 0x000000FF) << 16));
51}
52
53} // namespace
54
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
56 CPDFSDK_PageView* pPageView,
57 CPDFSDK_InterForm* pInterForm)
58 : CPDFSDK_BAAnnot(pAnnot, pPageView),
59 m_pInterForm(pInterForm),
60 m_nAppAge(0),
Tom Sepez40e9ff32015-11-30 12:39:54 -080061 m_nValueAge(0)
62#ifdef PDF_ENABLE_XFA
63 ,
thestig1cd352e2016-06-07 17:53:06 -070064 m_hMixXFAWidget(nullptr),
65 m_pWidgetHandler(nullptr)
Tom Sepez40e9ff32015-11-30 12:39:54 -080066#endif // PDF_ENABLE_XFA
67{
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070068}
69
dsinclairce04a452016-09-07 05:46:55 -070070CPDFSDK_Widget::~CPDFSDK_Widget() {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071
Tom Sepez51da0932015-11-25 16:05:49 -080072#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -070073CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const {
dsinclair521b7502016-11-02 13:02:28 -070074 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
75 if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076 if (!m_hMixXFAWidget) {
dsinclair521b7502016-11-02 13:02:28 -070077 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078 CFX_WideString sName;
Lei Zhang99766722016-02-23 11:21:48 -080079 if (GetFieldType() == FIELDTYPE_RADIOBUTTON) {
80 sName = GetAnnotName();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070081 if (sName.IsEmpty())
82 sName = GetName();
Dan Sinclair738b08c2016-03-01 14:45:20 -050083 } else {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070084 sName = GetName();
Dan Sinclair738b08c2016-03-01 14:45:20 -050085 }
Bo Xufdc00a72014-10-28 23:03:33 -070086
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 if (!sName.IsEmpty())
weilib4d1b572016-08-10 14:50:48 -070088 m_hMixXFAWidget = pDocView->GetWidgetByName(sName, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -070089 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -070090 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091 return m_hMixXFAWidget;
92 }
Lei Zhanga6d9f0e2015-06-13 00:48:38 -070093
thestig1cd352e2016-06-07 17:53:06 -070094 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070095}
96
dsinclairdf4bc592016-03-31 20:34:43 -070097CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() {
dsinclair521b7502016-11-02 13:02:28 -070098 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
99 if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) {
100 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101 CFX_WideString sName = GetName();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700102 if (!sName.IsEmpty())
weilib4d1b572016-08-10 14:50:48 -0700103 return pDocView->GetWidgetByName(sName, nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700104 }
105 }
106
Tom Sepez50d12ad2015-11-24 09:50:51 -0800107 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700108}
109
dsinclairdf4bc592016-03-31 20:34:43 -0700110CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const {
dsinclair521b7502016-11-02 13:02:28 -0700111 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
112 if (pContext->GetDocType() == DOCTYPE_STATIC_XFA) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113 if (!m_pWidgetHandler) {
dsinclair521b7502016-11-02 13:02:28 -0700114 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700115 m_pWidgetHandler = pDocView->GetWidgetHandler();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700116 }
117 return m_pWidgetHandler;
118 }
119
thestig1cd352e2016-06-07 17:53:06 -0700120 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700121}
122
123static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) {
124 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
125
126 switch (eXFAAAT) {
127 case PDFSDK_XFA_Click:
128 eEventType = XFA_EVENT_Click;
129 break;
130 case PDFSDK_XFA_Full:
131 eEventType = XFA_EVENT_Full;
132 break;
133 case PDFSDK_XFA_PreOpen:
134 eEventType = XFA_EVENT_PreOpen;
135 break;
136 case PDFSDK_XFA_PostOpen:
137 eEventType = XFA_EVENT_PostOpen;
138 break;
139 }
140
141 return eEventType;
142}
143
144static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT,
tsepez4cf55152016-11-02 14:37:54 -0700145 bool bWillCommit) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
147
148 switch (eAAT) {
149 case CPDF_AAction::CursorEnter:
150 eEventType = XFA_EVENT_MouseEnter;
151 break;
152 case CPDF_AAction::CursorExit:
153 eEventType = XFA_EVENT_MouseExit;
154 break;
155 case CPDF_AAction::ButtonDown:
156 eEventType = XFA_EVENT_MouseDown;
157 break;
158 case CPDF_AAction::ButtonUp:
159 eEventType = XFA_EVENT_MouseUp;
160 break;
161 case CPDF_AAction::GetFocus:
162 eEventType = XFA_EVENT_Enter;
163 break;
164 case CPDF_AAction::LoseFocus:
165 eEventType = XFA_EVENT_Exit;
166 break;
167 case CPDF_AAction::PageOpen:
168 break;
169 case CPDF_AAction::PageClose:
170 break;
171 case CPDF_AAction::PageVisible:
172 break;
173 case CPDF_AAction::PageInvisible:
174 break;
175 case CPDF_AAction::KeyStroke:
jaepark611adb82016-08-17 11:34:36 -0700176 if (!bWillCommit)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 eEventType = XFA_EVENT_Change;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 break;
179 case CPDF_AAction::Validate:
180 eEventType = XFA_EVENT_Validate;
181 break;
182 case CPDF_AAction::OpenPage:
183 case CPDF_AAction::ClosePage:
184 case CPDF_AAction::Format:
185 case CPDF_AAction::Calculate:
186 case CPDF_AAction::CloseDocument:
187 case CPDF_AAction::SaveDocument:
188 case CPDF_AAction::DocumentSaved:
189 case CPDF_AAction::PrintDocument:
190 case CPDF_AAction::DocumentPrinted:
191 break;
192 }
193
194 return eEventType;
195}
196
tsepez4cf55152016-11-02 14:37:54 -0700197bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) {
jaepark611adb82016-08-17 11:34:36 -0700198 CXFA_FFWidget* hWidget = GetMixXFAWidget();
199 if (!hWidget)
tsepez4cf55152016-11-02 14:37:54 -0700200 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700201
jaepark611adb82016-08-17 11:34:36 -0700202 CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
203 if (!pXFAWidgetHandler)
tsepez4cf55152016-11-02 14:37:54 -0700204 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205
jaepark611adb82016-08-17 11:34:36 -0700206 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
207
208 CXFA_WidgetAcc* pAcc;
209 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
210 GetFieldType() == FIELDTYPE_RADIOBUTTON) {
211 if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) {
212 pAcc = hGroupWidget->GetDataAcc();
213 if (pXFAWidgetHandler->HasEvent(pAcc, eEventType))
tsepez4cf55152016-11-02 14:37:54 -0700214 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215 }
216 }
217
jaepark611adb82016-08-17 11:34:36 -0700218 pAcc = hWidget->GetDataAcc();
219 return pXFAWidgetHandler->HasEvent(pAcc, eEventType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700220}
221
tsepez4cf55152016-11-02 14:37:54 -0700222bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
223 PDFSDK_FieldAction& data,
224 CPDFSDK_PageView* pPageView) {
dsinclair521b7502016-11-02 13:02:28 -0700225 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700226
jaepark611adb82016-08-17 11:34:36 -0700227 CXFA_FFWidget* hWidget = GetMixXFAWidget();
228 if (!hWidget)
tsepez4cf55152016-11-02 14:37:54 -0700229 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230
jaepark611adb82016-08-17 11:34:36 -0700231 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
232 if (eEventType == XFA_EVENT_Unknown)
tsepez4cf55152016-11-02 14:37:54 -0700233 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234
jaepark611adb82016-08-17 11:34:36 -0700235 CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
236 if (!pXFAWidgetHandler)
tsepez4cf55152016-11-02 14:37:54 -0700237 return false;
jaepark611adb82016-08-17 11:34:36 -0700238
239 CXFA_EventParam param;
240 param.m_eType = eEventType;
241 param.m_wsChange = data.sChange;
242 param.m_iCommitKey = data.nCommitKey;
243 param.m_bShift = data.bShift;
244 param.m_iSelStart = data.nSelStart;
245 param.m_iSelEnd = data.nSelEnd;
246 param.m_wsFullText = data.sValue;
247 param.m_bKeyDown = data.bKeyDown;
248 param.m_bModifier = data.bModifier;
249 param.m_wsNewText = data.sValue;
250 if (data.nSelEnd > data.nSelStart)
251 param.m_wsNewText.Delete(data.nSelStart, data.nSelEnd - data.nSelStart);
252
253 for (int i = 0; i < data.sChange.GetLength(); i++)
254 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
255 param.m_wsPrevText = data.sValue;
256
257 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
258 GetFieldType() == FIELDTYPE_RADIOBUTTON) {
259 if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) {
260 CXFA_WidgetAcc* pAcc = hGroupWidget->GetDataAcc();
261 param.m_pTarget = pAcc;
262 if (pXFAWidgetHandler->ProcessEvent(pAcc, &param) !=
263 XFA_EVENTERROR_Success) {
tsepez4cf55152016-11-02 14:37:54 -0700264 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700265 }
266 }
267 }
jaepark611adb82016-08-17 11:34:36 -0700268 CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc();
269 param.m_pTarget = pAcc;
270 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700271
dsinclair521b7502016-11-02 13:02:28 -0700272 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
jaepark611adb82016-08-17 11:34:36 -0700273 pDocView->UpdateDocView();
274
275 return nRet == XFA_EVENTERROR_Success;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700276}
277
tsepez4cf55152016-11-02 14:37:54 -0700278void CPDFSDK_Widget::Synchronize(bool bSynchronizeElse) {
jaepark611adb82016-08-17 11:34:36 -0700279 CXFA_FFWidget* hWidget = GetMixXFAWidget();
280 if (!hWidget)
281 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282
jaepark611adb82016-08-17 11:34:36 -0700283 CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc();
284 if (!pWidgetAcc)
285 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700286
jaepark611adb82016-08-17 11:34:36 -0700287 CPDF_FormField* pFormField = GetFormField();
288 switch (GetFieldType()) {
289 case FIELDTYPE_CHECKBOX:
290 case FIELDTYPE_RADIOBUTTON: {
291 CPDF_FormControl* pFormCtrl = GetFormControl();
292 XFA_CHECKSTATE eCheckState =
293 pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off;
294 pWidgetAcc->SetCheckState(eCheckState, true);
295 break;
296 }
297 case FIELDTYPE_TEXTFIELD:
298 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
299 break;
300 case FIELDTYPE_LISTBOX: {
301 pWidgetAcc->ClearAllSelections();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302
jaepark611adb82016-08-17 11:34:36 -0700303 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
304 int nIndex = pFormField->GetSelectedIndex(i);
305 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
tsepez4cf55152016-11-02 14:37:54 -0700306 pWidgetAcc->SetItemState(nIndex, true, false, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307 }
jaepark611adb82016-08-17 11:34:36 -0700308 break;
309 }
310 case FIELDTYPE_COMBOBOX: {
311 pWidgetAcc->ClearAllSelections();
dsinclair221caf62016-04-04 12:08:40 -0700312
jaepark611adb82016-08-17 11:34:36 -0700313 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
314 int nIndex = pFormField->GetSelectedIndex(i);
315 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
tsepez4cf55152016-11-02 14:37:54 -0700316 pWidgetAcc->SetItemState(nIndex, true, false, false, true);
jaepark611adb82016-08-17 11:34:36 -0700317 }
318 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
319 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700320 }
321 }
jaepark611adb82016-08-17 11:34:36 -0700322
323 if (bSynchronizeElse)
324 pWidgetAcc->ProcessValueChanged();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700325}
326
327void CPDFSDK_Widget::SynchronizeXFAValue() {
dsinclair521b7502016-11-02 13:02:28 -0700328 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
329 CXFA_FFDocView* pXFADocView = pContext->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700330 if (!pXFADocView)
331 return;
332
dsinclairdf4bc592016-03-31 20:34:43 -0700333 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700334 if (GetXFAWidgetHandler()) {
335 CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(),
336 GetFormControl());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700337 }
338 }
339}
340
341void CPDFSDK_Widget::SynchronizeXFAItems() {
dsinclair521b7502016-11-02 13:02:28 -0700342 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
343 CXFA_FFDocView* pXFADocView = pContext->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700344 if (!pXFADocView)
345 return;
346
dsinclairdf4bc592016-03-31 20:34:43 -0700347 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700348 if (GetXFAWidgetHandler())
349 SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350 }
351}
352
dsinclairdf4bc592016-03-31 20:34:43 -0700353void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView,
354 CXFA_FFWidget* hWidget,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355 CPDF_FormField* pFormField,
356 CPDF_FormControl* pFormControl) {
Lei Zhang5eca3052016-02-22 20:32:21 -0800357 ASSERT(hWidget);
dsinclair221caf62016-04-04 12:08:40 -0700358 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359
dsinclair221caf62016-04-04 12:08:40 -0700360 switch (pFormField->GetFieldType()) {
361 case FIELDTYPE_CHECKBOX: {
362 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
363 pFormField->CheckControl(
364 pFormField->GetControlIndex(pFormControl),
365 pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true);
366 }
jaepark611adb82016-08-17 11:34:36 -0700367 break;
368 }
dsinclair221caf62016-04-04 12:08:40 -0700369 case FIELDTYPE_RADIOBUTTON: {
370 // TODO(weili): Check whether we need to handle checkbox and radio
371 // button differently, otherwise, merge these two cases.
372 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
373 pFormField->CheckControl(
374 pFormField->GetControlIndex(pFormControl),
375 pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true);
376 }
jaepark611adb82016-08-17 11:34:36 -0700377 break;
378 }
dsinclair221caf62016-04-04 12:08:40 -0700379 case FIELDTYPE_TEXTFIELD: {
380 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
381 CFX_WideString sValue;
382 pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
tsepez4cf55152016-11-02 14:37:54 -0700383 pFormField->SetValue(sValue, true);
dsinclair221caf62016-04-04 12:08:40 -0700384 }
jaepark611adb82016-08-17 11:34:36 -0700385 break;
386 }
dsinclair221caf62016-04-04 12:08:40 -0700387 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700388 pFormField->ClearSelection(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700389
dsinclair221caf62016-04-04 12:08:40 -0700390 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
391 for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
392 int nIndex = pWidgetAcc->GetSelectedItem(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700393
dsinclair221caf62016-04-04 12:08:40 -0700394 if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
tsepez4cf55152016-11-02 14:37:54 -0700395 pFormField->SetItemSelection(nIndex, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700396 }
397 }
dsinclair221caf62016-04-04 12:08:40 -0700398 }
jaepark611adb82016-08-17 11:34:36 -0700399 break;
400 }
dsinclair221caf62016-04-04 12:08:40 -0700401 case FIELDTYPE_COMBOBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700402 pFormField->ClearSelection(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700403
dsinclair221caf62016-04-04 12:08:40 -0700404 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
405 for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
406 int nIndex = pWidgetAcc->GetSelectedItem(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407
dsinclair221caf62016-04-04 12:08:40 -0700408 if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
tsepez4cf55152016-11-02 14:37:54 -0700409 pFormField->SetItemSelection(nIndex, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700411 }
dsinclair221caf62016-04-04 12:08:40 -0700412
413 CFX_WideString sValue;
414 pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
tsepez4cf55152016-11-02 14:37:54 -0700415 pFormField->SetValue(sValue, true);
dsinclair221caf62016-04-04 12:08:40 -0700416 }
jaepark611adb82016-08-17 11:34:36 -0700417 break;
418 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419 }
420}
421
dsinclairdf4bc592016-03-31 20:34:43 -0700422void CPDFSDK_Widget::SynchronizeXFAItems(CXFA_FFDocView* pXFADocView,
423 CXFA_FFWidget* hWidget,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700424 CPDF_FormField* pFormField,
425 CPDF_FormControl* pFormControl) {
Lei Zhang5eca3052016-02-22 20:32:21 -0800426 ASSERT(hWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427
dsinclair221caf62016-04-04 12:08:40 -0700428 switch (pFormField->GetFieldType()) {
429 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700430 pFormField->ClearSelection(false);
431 pFormField->ClearOptions(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432
dsinclair221caf62016-04-04 12:08:40 -0700433 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
434 for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz; i++) {
435 CFX_WideString swText;
436 pWidgetAcc->GetChoiceListItem(swText, i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437
tsepez4cf55152016-11-02 14:37:54 -0700438 pFormField->InsertOption(swText, i, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439 }
dsinclair221caf62016-04-04 12:08:40 -0700440 }
jaepark611adb82016-08-17 11:34:36 -0700441 break;
442 }
dsinclair221caf62016-04-04 12:08:40 -0700443 case FIELDTYPE_COMBOBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700444 pFormField->ClearSelection(false);
445 pFormField->ClearOptions(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446
dsinclair221caf62016-04-04 12:08:40 -0700447 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
448 for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz; i++) {
449 CFX_WideString swText;
450 pWidgetAcc->GetChoiceListItem(swText, i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451
tsepez4cf55152016-11-02 14:37:54 -0700452 pFormField->InsertOption(swText, i, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 }
dsinclair221caf62016-04-04 12:08:40 -0700454 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455
tsepez4cf55152016-11-02 14:37:54 -0700456 pFormField->SetValue(L"", true);
jaepark611adb82016-08-17 11:34:36 -0700457 break;
458 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700459 }
460}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800461#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700462
tsepez4cf55152016-11-02 14:37:54 -0700463bool CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode) {
dsinclair38fd8442016-09-15 10:15:32 -0700464 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465 if (!pAP)
tsepez4cf55152016-11-02 14:37:54 -0700466 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700467
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700468 // Choose the right sub-ap
469 const FX_CHAR* ap_entry = "N";
470 if (mode == CPDF_Annot::Down)
471 ap_entry = "D";
472 else if (mode == CPDF_Annot::Rollover)
473 ap_entry = "R";
474 if (!pAP->KeyExist(ap_entry))
475 ap_entry = "N";
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700476
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700477 // Get the AP stream or subdirectory
dsinclair38fd8442016-09-15 10:15:32 -0700478 CPDF_Object* psub = pAP->GetDirectObjectFor(ap_entry);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 if (!psub)
tsepez4cf55152016-11-02 14:37:54 -0700480 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700481
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482 int nFieldType = GetFieldType();
483 switch (nFieldType) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700484 case FIELDTYPE_PUSHBUTTON:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700485 case FIELDTYPE_COMBOBOX:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700486 case FIELDTYPE_LISTBOX:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700487 case FIELDTYPE_TEXTFIELD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488 case FIELDTYPE_SIGNATURE:
Dan Sinclairaa435ba2015-10-22 16:45:48 -0400489 return psub->IsStream();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490 case FIELDTYPE_CHECKBOX:
491 case FIELDTYPE_RADIOBUTTON:
Dan Sinclairf1251c12015-10-20 16:24:45 -0400492 if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) {
dsinclair38fd8442016-09-15 10:15:32 -0700493 return !!pSubDict->GetStreamFor(GetAppState());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 }
tsepez4cf55152016-11-02 14:37:54 -0700495 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 }
tsepez4cf55152016-11-02 14:37:54 -0700497 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498}
499
500int CPDFSDK_Widget::GetFieldType() const {
dsinclair92828192016-08-17 13:28:51 -0700501 CPDF_FormField* pField = GetFormField();
502 return pField ? pField->GetFieldType() : FIELDTYPE_UNKNOWN;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503}
504
tsepez4cf55152016-11-02 14:37:54 -0700505bool CPDFSDK_Widget::IsAppearanceValid() {
Tom Sepez51da0932015-11-25 16:05:49 -0800506#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -0700507 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
508 int nDocType = pContext->GetDocType();
Tom Sepez540c4362015-11-24 13:33:57 -0800509 if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA)
tsepez4cf55152016-11-02 14:37:54 -0700510 return true;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800511#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800512 return CPDFSDK_BAAnnot::IsAppearanceValid();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700513}
514
weili625ad662016-06-15 11:21:33 -0700515int CPDFSDK_Widget::GetLayoutOrder() const {
516 return 2;
517}
518
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700519int CPDFSDK_Widget::GetFieldFlags() const {
520 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521 CPDF_FormControl* pFormControl =
522 pPDFInterForm->GetControlByDict(m_pAnnot->GetAnnotDict());
523 CPDF_FormField* pFormField = pFormControl->GetField();
524 return pFormField->GetFieldFlags();
525}
526
jaepark9ed91372016-08-26 16:16:10 -0700527bool CPDFSDK_Widget::IsSignatureWidget() const {
528 return GetFieldType() == FIELDTYPE_SIGNATURE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529}
530
531CPDF_FormField* CPDFSDK_Widget::GetFormField() const {
dsinclair92828192016-08-17 13:28:51 -0700532 CPDF_FormControl* pControl = GetFormControl();
533 return pControl ? pControl->GetField() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534}
535
536CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 return pPDFInterForm->GetControlByDict(GetAnnotDict());
539}
540
Lei Zhang1b700c32015-10-30 23:55:35 -0700541CPDF_FormControl* CPDFSDK_Widget::GetFormControl(
542 CPDF_InterForm* pInterForm,
543 const CPDF_Dictionary* pAnnotDict) {
Lei Zhang96660d62015-12-14 18:27:25 -0800544 ASSERT(pAnnotDict);
Lei Zhang1b700c32015-10-30 23:55:35 -0700545 return pInterForm->GetControlByDict(pAnnotDict);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700546}
547
548int CPDFSDK_Widget::GetRotate() const {
549 CPDF_FormControl* pCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700550 return pCtrl->GetRotation() % 360;
551}
552
Tom Sepez51da0932015-11-25 16:05:49 -0800553#ifdef PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700554CFX_WideString CPDFSDK_Widget::GetName() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700556 return pFormField->GetFullName();
557}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800558#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559
tsepez4cf55152016-11-02 14:37:54 -0700560bool CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562 int iColorType = 0;
dsinclair72177da2016-09-15 12:07:23 -0700563 color = ARGBToColorRef(pFormCtrl->GetBackgroundColor(iColorType));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700564 return iColorType != COLORTYPE_TRANSPARENT;
565}
566
tsepez4cf55152016-11-02 14:37:54 -0700567bool CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700568 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569 int iColorType = 0;
dsinclair72177da2016-09-15 12:07:23 -0700570 color = ARGBToColorRef(pFormCtrl->GetBorderColor(iColorType));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700571 return iColorType != COLORTYPE_TRANSPARENT;
572}
573
tsepez4cf55152016-11-02 14:37:54 -0700574bool CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
jaepark611adb82016-08-17 11:34:36 -0700577 if (!da.HasColor())
tsepez4cf55152016-11-02 14:37:54 -0700578 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579
jaepark611adb82016-08-17 11:34:36 -0700580 FX_ARGB argb;
581 int iColorType = COLORTYPE_TRANSPARENT;
582 da.GetColor(argb, iColorType);
dsinclair72177da2016-09-15 12:07:23 -0700583 color = ARGBToColorRef(argb);
jaepark611adb82016-08-17 11:34:36 -0700584 return iColorType != COLORTYPE_TRANSPARENT;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585}
586
587FX_FLOAT CPDFSDK_Widget::GetFontSize() const {
588 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589 CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
590 CFX_ByteString csFont = "";
591 FX_FLOAT fFontSize = 0.0f;
592 pDa.GetFont(csFont, fFontSize);
593
594 return fFontSize;
595}
596
Tom Sepezbf59a072015-10-21 14:07:23 -0700597int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700598#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700599 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700600 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
601 if (nIndex < pWidgetAcc->CountSelectedItems())
602 return pWidgetAcc->GetSelectedItem(nIndex);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700603 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700604 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700605#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700606 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700607 return pFormField->GetSelectedIndex(nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700608}
609
Tom Sepeza8a39e22015-10-12 15:47:07 -0700610#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700611CFX_WideString CPDFSDK_Widget::GetValue(bool bDisplay) const {
dsinclairdf4bc592016-03-31 20:34:43 -0700612 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700613 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
614 CFX_WideString sValue;
615 pWidgetAcc->GetValue(
616 sValue, bDisplay ? XFA_VALUEPICTURE_Display : XFA_VALUEPICTURE_Edit);
617 return sValue;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700618 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700619 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800620#else
621CFX_WideString CPDFSDK_Widget::GetValue() const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700622#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624 return pFormField->GetValue();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700625}
626
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700627CFX_WideString CPDFSDK_Widget::GetDefaultValue() const {
628 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700629 return pFormField->GetDefaultValue();
630}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700631
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700632CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const {
633 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700634 return pFormField->GetOptionLabel(nIndex);
635}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700636
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700637int CPDFSDK_Widget::CountOptions() const {
638 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700639 return pFormField->CountOptions();
640}
641
tsepez4cf55152016-11-02 14:37:54 -0700642bool CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700643#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700644 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700645 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
646 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems())
647 return pWidgetAcc->GetItemState(nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700648
tsepez4cf55152016-11-02 14:37:54 -0700649 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650 }
651 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700652#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700653 CPDF_FormField* pFormField = GetFormField();
654 return pFormField->IsItemSelected(nIndex);
655}
656
657int CPDFSDK_Widget::GetTopVisibleIndex() const {
658 CPDF_FormField* pFormField = GetFormField();
659 return pFormField->GetTopVisibleIndex();
660}
661
Wei Li97da9762016-03-11 17:00:48 -0800662bool CPDFSDK_Widget::IsChecked() const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700663#ifdef PDF_ENABLE_XFA
dsinclair221caf62016-04-04 12:08:40 -0700664 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
665 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc())
666 return pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700668#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700670 return pFormCtrl->IsChecked();
671}
672
673int CPDFSDK_Widget::GetAlignment() const {
674 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675 return pFormCtrl->GetControlAlignment();
676}
677
678int CPDFSDK_Widget::GetMaxLen() const {
679 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700680 return pFormField->GetMaxLen();
681}
682
Wei Li97da9762016-03-11 17:00:48 -0800683void CPDFSDK_Widget::SetCheck(bool bChecked, bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685 CPDF_FormField* pFormField = pFormCtrl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686 pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
687 bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800688#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700689 if (!IsWidgetAppearanceValid(CPDF_Annot::Normal))
tsepez4cf55152016-11-02 14:37:54 -0700690 ResetAppearance(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700692 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800693#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700694}
695
tsepez4cf55152016-11-02 14:37:54 -0700696void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700698 pFormField->SetValue(sValue, bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800699#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700700 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700701 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800702#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700703}
704
705void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {}
706void CPDFSDK_Widget::SetOptionSelection(int index,
tsepez4cf55152016-11-02 14:37:54 -0700707 bool bSelected,
708 bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700710 pFormField->SetItemSelection(index, bSelected, bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800711#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700712 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700713 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800714#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700715}
716
tsepez4cf55152016-11-02 14:37:54 -0700717void CPDFSDK_Widget::ClearSelection(bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719 pFormField->ClearSelection(bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800720#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700722 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800723#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700724}
725
726void CPDFSDK_Widget::SetTopVisibleIndex(int index) {}
727
728void CPDFSDK_Widget::SetAppModified() {
tsepez4cf55152016-11-02 14:37:54 -0700729 m_bAppModified = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700730}
731
732void CPDFSDK_Widget::ClearAppModified() {
tsepez4cf55152016-11-02 14:37:54 -0700733 m_bAppModified = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734}
735
tsepez4cf55152016-11-02 14:37:54 -0700736bool CPDFSDK_Widget::IsAppModified() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737 return m_bAppModified;
738}
739
Tom Sepez51da0932015-11-25 16:05:49 -0800740#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700741void CPDFSDK_Widget::ResetAppearance(bool bValueChanged) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700742 switch (GetFieldType()) {
743 case FIELDTYPE_TEXTFIELD:
744 case FIELDTYPE_COMBOBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700745 bool bFormatted = false;
tsepez8c2a8cd2016-09-07 15:29:11 -0700746 CFX_WideString sValue = OnFormat(bFormatted);
tsepez4cf55152016-11-02 14:37:54 -0700747 ResetAppearance(bFormatted ? &sValue : nullptr, true);
jaepark611adb82016-08-17 11:34:36 -0700748 break;
749 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700750 default:
tsepez4cf55152016-11-02 14:37:54 -0700751 ResetAppearance(nullptr, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700752 break;
753 }
754}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800755#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700756
tsepeza31da742016-09-08 11:28:14 -0700757void CPDFSDK_Widget::ResetAppearance(const CFX_WideString* sValue,
tsepez4cf55152016-11-02 14:37:54 -0700758 bool bValueChanged) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700759 SetAppModified();
760
761 m_nAppAge++;
762 if (m_nAppAge > 999999)
763 m_nAppAge = 0;
764 if (bValueChanged)
765 m_nValueAge++;
766
767 int nFieldType = GetFieldType();
768
769 switch (nFieldType) {
770 case FIELDTYPE_PUSHBUTTON:
771 ResetAppearance_PushButton();
772 break;
773 case FIELDTYPE_CHECKBOX:
774 ResetAppearance_CheckBox();
775 break;
776 case FIELDTYPE_RADIOBUTTON:
777 ResetAppearance_RadioButton();
778 break;
779 case FIELDTYPE_COMBOBOX:
780 ResetAppearance_ComboBox(sValue);
781 break;
782 case FIELDTYPE_LISTBOX:
783 ResetAppearance_ListBox();
784 break;
785 case FIELDTYPE_TEXTFIELD:
786 ResetAppearance_TextField(sValue);
787 break;
788 }
789
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700790 m_pAnnot->ClearCachedAP();
791}
792
tsepez4cf55152016-11-02 14:37:54 -0700793CFX_WideString CPDFSDK_Widget::OnFormat(bool& bFormatted) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700794 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800795 ASSERT(pFormField);
tsepez8c2a8cd2016-09-07 15:29:11 -0700796 return m_pInterForm->OnFormat(pFormField, bFormatted);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700797}
798
tsepez4cf55152016-11-02 14:37:54 -0700799void CPDFSDK_Widget::ResetFieldAppearance(bool bValueChanged) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700800 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800801 ASSERT(pFormField);
thestig1cd352e2016-06-07 17:53:06 -0700802 m_pInterForm->ResetFieldAppearance(pFormField, nullptr, bValueChanged);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700803}
804
805void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800806 const CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700807 CPDF_Annot::AppearanceMode mode,
808 const CPDF_RenderOptions* pOptions) {
809 int nFieldType = GetFieldType();
810
811 if ((nFieldType == FIELDTYPE_CHECKBOX ||
812 nFieldType == FIELDTYPE_RADIOBUTTON) &&
813 mode == CPDF_Annot::Normal &&
814 !IsWidgetAppearanceValid(CPDF_Annot::Normal)) {
815 CFX_PathData pathData;
816
Tom Sepez281a9ea2016-02-26 14:24:28 -0800817 CFX_FloatRect rcAnnot = GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700818
819 pathData.AppendRect(rcAnnot.left, rcAnnot.bottom, rcAnnot.right,
820 rcAnnot.top);
821
822 CFX_GraphStateData gsd;
823 gsd.m_LineWidth = 0.0f;
824
825 pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA,
826 FXFILL_ALTERNATE);
827 } else {
828 CPDFSDK_BAAnnot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);
829 }
830}
831
832void CPDFSDK_Widget::UpdateField() {
833 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800834 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700835 m_pInterForm->UpdateField(pFormField);
836}
837
838void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
839 CPDFSDK_PageView* pPageView) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700840 int nFieldType = GetFieldType();
jaepark611adb82016-08-17 11:34:36 -0700841 if (!m_pInterForm->IsNeedHighLight(nFieldType))
842 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700843
jaepark611adb82016-08-17 11:34:36 -0700844 CFX_FloatRect rc = GetRect();
845 FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);
846 uint8_t alpha = m_pInterForm->GetHighlightAlpha();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700847
jaepark611adb82016-08-17 11:34:36 -0700848 CFX_FloatRect rcDevice;
jaepark611adb82016-08-17 11:34:36 -0700849 CFX_Matrix page2device;
850 pPageView->GetCurrentMatrix(page2device);
851 page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom),
852 rcDevice.left, rcDevice.bottom);
853 page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top),
854 rcDevice.right, rcDevice.top);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700855
jaepark611adb82016-08-17 11:34:36 -0700856 rcDevice.Normalize();
857
858 FX_ARGB argb = ArgbEncode((int)alpha, color);
859 FX_RECT rcDev((int)rcDevice.left, (int)rcDevice.top, (int)rcDevice.right,
860 (int)rcDevice.bottom);
861 pDevice->FillRect(&rcDev, argb);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700862}
863
864void CPDFSDK_Widget::ResetAppearance_PushButton() {
865 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800866 CFX_FloatRect rcWindow = GetRotatedRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700867 int32_t nLayout = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700868 switch (pControl->GetTextPosition()) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700869 case TEXTPOS_ICON:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700870 nLayout = PPBL_ICON;
871 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700872 case TEXTPOS_BELOW:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700873 nLayout = PPBL_ICONTOPLABELBOTTOM;
874 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700875 case TEXTPOS_ABOVE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700876 nLayout = PPBL_LABELTOPICONBOTTOM;
877 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700878 case TEXTPOS_RIGHT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700879 nLayout = PPBL_ICONLEFTLABELRIGHT;
880 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700881 case TEXTPOS_LEFT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700882 nLayout = PPBL_LABELLEFTICONRIGHT;
883 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700884 case TEXTPOS_OVERLAID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700885 nLayout = PPBL_LABELOVERICON;
886 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700887 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700888 nLayout = PPBL_LABEL;
889 break;
890 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700891
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700892 CPWL_Color crBackground, crBorder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700893
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700894 int iColorType;
895 FX_FLOAT fc[4];
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700896
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700897 pControl->GetOriginalBackgroundColor(iColorType, fc);
898 if (iColorType > 0)
899 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700900
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700901 pControl->GetOriginalBorderColor(iColorType, fc);
902 if (iColorType > 0)
903 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700904
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700905 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700906 CPWL_Dash dsBorder(3, 0, 0);
907 CPWL_Color crLeftTop, crRightBottom;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700908
dsinclair92cb5e52016-05-16 11:38:28 -0700909 BorderStyle nBorderStyle = GetBorderStyle();
910 switch (nBorderStyle) {
911 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700912 dsBorder = CPWL_Dash(3, 3, 0);
913 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700914 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700915 fBorderWidth *= 2;
916 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
917 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
918 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700919 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700920 fBorderWidth *= 2;
921 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
922 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
923 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700924 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700925 break;
926 }
927
Tom Sepez281a9ea2016-02-26 14:24:28 -0800928 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700929
930 CPWL_Color crText(COLORTYPE_GRAY, 0);
931
932 FX_FLOAT fFontSize = 12.0f;
933 CFX_ByteString csNameTag;
934
935 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
936 if (da.HasColor()) {
937 da.GetColor(iColorType, fc);
938 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
939 }
940
941 if (da.HasFont())
942 da.GetFont(csNameTag, fFontSize);
943
944 CFX_WideString csWCaption;
945 CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption;
946
jaepark611adb82016-08-17 11:34:36 -0700947 if (pControl->HasMKEntry("CA"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700948 csNormalCaption = pControl->GetNormalCaption();
jaepark611adb82016-08-17 11:34:36 -0700949
950 if (pControl->HasMKEntry("RC"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700951 csRolloverCaption = pControl->GetRolloverCaption();
jaepark611adb82016-08-17 11:34:36 -0700952
953 if (pControl->HasMKEntry("AC"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700954 csDownCaption = pControl->GetDownCaption();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700955
thestig1cd352e2016-06-07 17:53:06 -0700956 CPDF_Stream* pNormalIcon = nullptr;
957 CPDF_Stream* pRolloverIcon = nullptr;
958 CPDF_Stream* pDownIcon = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700959
jaepark611adb82016-08-17 11:34:36 -0700960 if (pControl->HasMKEntry("I"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700961 pNormalIcon = pControl->GetNormalIcon();
jaepark611adb82016-08-17 11:34:36 -0700962
963 if (pControl->HasMKEntry("RI"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700964 pRolloverIcon = pControl->GetRolloverIcon();
jaepark611adb82016-08-17 11:34:36 -0700965
966 if (pControl->HasMKEntry("IX"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700967 pDownIcon = pControl->GetDownIcon();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700968
969 if (pNormalIcon) {
970 if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -0700971 if (pImageDict->GetStringFor("Name").IsEmpty())
tsepez0e606b52016-11-18 16:22:41 -0800972 pImageDict->SetNewFor<CPDF_String>("Name", "ImgA", false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700973 }
974 }
975
976 if (pRolloverIcon) {
977 if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -0700978 if (pImageDict->GetStringFor("Name").IsEmpty())
tsepez0e606b52016-11-18 16:22:41 -0800979 pImageDict->SetNewFor<CPDF_String>("Name", "ImgB", false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700980 }
981 }
982
983 if (pDownIcon) {
984 if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -0700985 if (pImageDict->GetStringFor("Name").IsEmpty())
tsepez0e606b52016-11-18 16:22:41 -0800986 pImageDict->SetNewFor<CPDF_String>("Name", "ImgC", false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700987 }
988 }
989
990 CPDF_IconFit iconFit = pControl->GetIconFit();
991
dsinclair690c0332016-10-11 09:13:01 -0700992 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
Lei Zhangfcfa3b82015-12-24 21:07:28 -0800993 font_map.SetAPType("N");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700994
995 CFX_ByteString csAP =
996 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
997 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
998 crLeftTop, crRightBottom, nBorderStyle,
999 dsBorder) +
1000 CPWL_Utils::GetPushButtonAppStream(
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001001 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001002 pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout);
1003
1004 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP);
1005 if (pNormalIcon)
1006 AddImageToAppearance("N", pNormalIcon);
1007
1008 CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode();
1009 if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) {
1010 if (csRolloverCaption.IsEmpty() && !pRolloverIcon) {
1011 csRolloverCaption = csNormalCaption;
1012 pRolloverIcon = pNormalIcon;
1013 }
1014
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001015 font_map.SetAPType("R");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001016
1017 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1018 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1019 crLeftTop, crRightBottom,
1020 nBorderStyle, dsBorder) +
1021 CPWL_Utils::GetPushButtonAppStream(
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001022 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001023 pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize,
1024 nLayout);
1025
1026 WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP);
1027 if (pRolloverIcon)
1028 AddImageToAppearance("R", pRolloverIcon);
1029
1030 if (csDownCaption.IsEmpty() && !pDownIcon) {
1031 csDownCaption = csNormalCaption;
1032 pDownIcon = pNormalIcon;
1033 }
1034
1035 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -07001036 case BorderStyle::BEVELED: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001037 CPWL_Color crTemp = crLeftTop;
1038 crLeftTop = crRightBottom;
1039 crRightBottom = crTemp;
dsinclair92cb5e52016-05-16 11:38:28 -07001040 break;
1041 }
1042 case BorderStyle::INSET: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001043 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1044 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001045 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001046 }
1047 default:
1048 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001049 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001050
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001051 font_map.SetAPType("D");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001052
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001053 csAP = CPWL_Utils::GetRectFillAppStream(
1054 rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) +
1055 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1056 crLeftTop, crRightBottom,
1057 nBorderStyle, dsBorder) +
1058 CPWL_Utils::GetPushButtonAppStream(
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001059 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001060 pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001061
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001062 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001063 if (pDownIcon)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001064 AddImageToAppearance("D", pDownIcon);
1065 } else {
1066 RemoveAppearance("D");
1067 RemoveAppearance("R");
1068 }
1069}
1070
1071void CPDFSDK_Widget::ResetAppearance_CheckBox() {
1072 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001073 CPWL_Color crBackground, crBorder, crText;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001074 int iColorType;
1075 FX_FLOAT fc[4];
1076
1077 pControl->GetOriginalBackgroundColor(iColorType, fc);
1078 if (iColorType > 0)
1079 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1080
1081 pControl->GetOriginalBorderColor(iColorType, fc);
1082 if (iColorType > 0)
1083 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1084
1085 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001086 CPWL_Dash dsBorder(3, 0, 0);
1087 CPWL_Color crLeftTop, crRightBottom;
1088
dsinclair92cb5e52016-05-16 11:38:28 -07001089 BorderStyle nBorderStyle = GetBorderStyle();
1090 switch (nBorderStyle) {
1091 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001092 dsBorder = CPWL_Dash(3, 3, 0);
1093 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001094 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001095 fBorderWidth *= 2;
1096 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1097 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
1098 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001099 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001100 fBorderWidth *= 2;
1101 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1102 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1103 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001104 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001105 break;
1106 }
1107
Tom Sepez281a9ea2016-02-26 14:24:28 -08001108 CFX_FloatRect rcWindow = GetRotatedRect();
1109 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001110
1111 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
1112 if (da.HasColor()) {
1113 da.GetColor(iColorType, fc);
1114 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1115 }
1116
1117 int32_t nStyle = 0;
1118
1119 CFX_WideString csWCaption = pControl->GetNormalCaption();
1120 if (csWCaption.GetLength() > 0) {
1121 switch (csWCaption[0]) {
1122 case L'l':
1123 nStyle = PCS_CIRCLE;
1124 break;
1125 case L'8':
1126 nStyle = PCS_CROSS;
1127 break;
1128 case L'u':
1129 nStyle = PCS_DIAMOND;
1130 break;
1131 case L'n':
1132 nStyle = PCS_SQUARE;
1133 break;
1134 case L'H':
1135 nStyle = PCS_STAR;
1136 break;
1137 default: // L'4'
1138 nStyle = PCS_CHECK;
1139 break;
1140 }
1141 } else {
1142 nStyle = PCS_CHECK;
1143 }
1144
1145 CFX_ByteString csAP_N_ON =
1146 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1147 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1148 crLeftTop, crRightBottom, nBorderStyle,
1149 dsBorder);
1150
1151 CFX_ByteString csAP_N_OFF = csAP_N_ON;
1152
1153 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -07001154 case BorderStyle::BEVELED: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001155 CPWL_Color crTemp = crLeftTop;
1156 crLeftTop = crRightBottom;
1157 crRightBottom = crTemp;
dsinclair92cb5e52016-05-16 11:38:28 -07001158 break;
1159 }
1160 case BorderStyle::INSET: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001161 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1162 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1163 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001164 }
1165 default:
1166 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001167 }
1168
1169 CFX_ByteString csAP_D_ON =
1170 CPWL_Utils::GetRectFillAppStream(
1171 rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) +
1172 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1173 crLeftTop, crRightBottom, nBorderStyle,
1174 dsBorder);
1175
1176 CFX_ByteString csAP_D_OFF = csAP_D_ON;
1177
1178 csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
1179 csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
1180
1181 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
1182 pControl->GetCheckedAPState());
1183 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
1184
1185 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
1186 pControl->GetCheckedAPState());
1187 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
1188
1189 CFX_ByteString csAS = GetAppState();
1190 if (csAS.IsEmpty())
1191 SetAppState("Off");
1192}
1193
1194void CPDFSDK_Widget::ResetAppearance_RadioButton() {
1195 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001196 CPWL_Color crBackground, crBorder, crText;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001197 int iColorType;
1198 FX_FLOAT fc[4];
1199
1200 pControl->GetOriginalBackgroundColor(iColorType, fc);
1201 if (iColorType > 0)
1202 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1203
1204 pControl->GetOriginalBorderColor(iColorType, fc);
1205 if (iColorType > 0)
1206 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1207
1208 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001209 CPWL_Dash dsBorder(3, 0, 0);
1210 CPWL_Color crLeftTop, crRightBottom;
1211
dsinclair92cb5e52016-05-16 11:38:28 -07001212 BorderStyle nBorderStyle = GetBorderStyle();
1213 switch (nBorderStyle) {
1214 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001215 dsBorder = CPWL_Dash(3, 3, 0);
1216 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001217 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001218 fBorderWidth *= 2;
1219 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1220 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
1221 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001222 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001223 fBorderWidth *= 2;
1224 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1225 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1226 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001227 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001228 break;
1229 }
1230
Tom Sepez281a9ea2016-02-26 14:24:28 -08001231 CFX_FloatRect rcWindow = GetRotatedRect();
1232 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001233
1234 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
1235 if (da.HasColor()) {
1236 da.GetColor(iColorType, fc);
1237 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1238 }
1239
1240 int32_t nStyle = 0;
1241
1242 CFX_WideString csWCaption = pControl->GetNormalCaption();
1243 if (csWCaption.GetLength() > 0) {
1244 switch (csWCaption[0]) {
1245 default: // L'l':
1246 nStyle = PCS_CIRCLE;
1247 break;
1248 case L'8':
1249 nStyle = PCS_CROSS;
1250 break;
1251 case L'u':
1252 nStyle = PCS_DIAMOND;
1253 break;
1254 case L'n':
1255 nStyle = PCS_SQUARE;
1256 break;
1257 case L'H':
1258 nStyle = PCS_STAR;
1259 break;
1260 case L'4':
1261 nStyle = PCS_CHECK;
1262 break;
1263 }
1264 } else {
1265 nStyle = PCS_CIRCLE;
1266 }
1267
1268 CFX_ByteString csAP_N_ON;
1269
Tom Sepez281a9ea2016-02-26 14:24:28 -08001270 CFX_FloatRect rcCenter =
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001271 CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f);
1272
1273 if (nStyle == PCS_CIRCLE) {
dsinclair92cb5e52016-05-16 11:38:28 -07001274 if (nBorderStyle == BorderStyle::BEVELED) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001275 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1276 crRightBottom = CPWL_Utils::SubstractColor(crBackground, 0.25f);
dsinclair92cb5e52016-05-16 11:38:28 -07001277 } else if (nBorderStyle == BorderStyle::INSET) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001278 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5f);
1279 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75f);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001280 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001281
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001282 csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBackground) +
1283 CPWL_Utils::GetCircleBorderAppStream(
1284 rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
1285 nBorderStyle, dsBorder);
1286 } else {
1287 csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1288 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1289 crLeftTop, crRightBottom,
1290 nBorderStyle, dsBorder);
1291 }
1292
1293 CFX_ByteString csAP_N_OFF = csAP_N_ON;
1294
1295 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -07001296 case BorderStyle::BEVELED: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001297 CPWL_Color crTemp = crLeftTop;
1298 crLeftTop = crRightBottom;
1299 crRightBottom = crTemp;
dsinclair92cb5e52016-05-16 11:38:28 -07001300 break;
1301 }
1302 case BorderStyle::INSET: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001303 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1304 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1305 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001306 }
1307 default:
1308 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001309 }
1310
1311 CFX_ByteString csAP_D_ON;
1312
1313 if (nStyle == PCS_CIRCLE) {
1314 CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground, 0.25f);
dsinclair92cb5e52016-05-16 11:38:28 -07001315 if (nBorderStyle == BorderStyle::BEVELED) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001316 crLeftTop = CPWL_Utils::SubstractColor(crBackground, 0.25f);
1317 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1318 crBK = crBackground;
dsinclair92cb5e52016-05-16 11:38:28 -07001319 } else if (nBorderStyle == BorderStyle::INSET) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001320 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1321 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1322 }
1323
1324 csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBK) +
1325 CPWL_Utils::GetCircleBorderAppStream(
1326 rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
1327 nBorderStyle, dsBorder);
1328 } else {
1329 csAP_D_ON = CPWL_Utils::GetRectFillAppStream(
1330 rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) +
1331 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1332 crLeftTop, crRightBottom,
1333 nBorderStyle, dsBorder);
1334 }
1335
1336 CFX_ByteString csAP_D_OFF = csAP_D_ON;
1337
1338 csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
1339 csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
1340
1341 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
1342 pControl->GetCheckedAPState());
1343 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
1344
1345 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
1346 pControl->GetCheckedAPState());
1347 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
1348
1349 CFX_ByteString csAS = GetAppState();
1350 if (csAS.IsEmpty())
1351 SetAppState("Off");
1352}
1353
tsepeza31da742016-09-08 11:28:14 -07001354void CPDFSDK_Widget::ResetAppearance_ComboBox(const CFX_WideString* sValue) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001355 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001356 CPDF_FormField* pField = pControl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001357 CFX_ByteTextBuf sBody, sLines;
1358
Tom Sepez281a9ea2016-02-26 14:24:28 -08001359 CFX_FloatRect rcClient = GetClientRect();
1360 CFX_FloatRect rcButton = rcClient;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001361 rcButton.left = rcButton.right - 13;
1362 rcButton.Normalize();
1363
dsinclaire35af1e2016-07-13 11:26:20 -07001364 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit);
tsepez4cf55152016-11-02 14:37:54 -07001365 pEdit->EnableRefresh(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001366
dsinclair690c0332016-10-11 09:13:01 -07001367 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
thestig732f6a02016-05-12 10:41:56 -07001368 pEdit->SetFontMap(&font_map);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001369
thestig732f6a02016-05-12 10:41:56 -07001370 CFX_FloatRect rcEdit = rcClient;
1371 rcEdit.right = rcButton.left;
1372 rcEdit.Normalize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001373
thestig732f6a02016-05-12 10:41:56 -07001374 pEdit->SetPlateRect(rcEdit);
tsepez4cf55152016-11-02 14:37:54 -07001375 pEdit->SetAlignmentV(1, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001376
thestig732f6a02016-05-12 10:41:56 -07001377 FX_FLOAT fFontSize = GetFontSize();
1378 if (IsFloatZero(fFontSize))
tsepez4cf55152016-11-02 14:37:54 -07001379 pEdit->SetAutoFontSize(true, true);
thestig732f6a02016-05-12 10:41:56 -07001380 else
1381 pEdit->SetFontSize(fFontSize);
1382
1383 pEdit->Initialize();
1384
1385 if (sValue) {
tsepeza31da742016-09-08 11:28:14 -07001386 pEdit->SetText(*sValue);
thestig732f6a02016-05-12 10:41:56 -07001387 } else {
1388 int32_t nCurSel = pField->GetSelectedIndex(0);
thestig732f6a02016-05-12 10:41:56 -07001389 if (nCurSel < 0)
tsepez067990c2016-09-13 06:46:40 -07001390 pEdit->SetText(pField->GetValue());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001391 else
tsepez067990c2016-09-13 06:46:40 -07001392 pEdit->SetText(pField->GetOptionLabel(nCurSel));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001393 }
1394
thestig732f6a02016-05-12 10:41:56 -07001395 CFX_FloatRect rcContent = pEdit->GetContentRect();
1396
1397 CFX_ByteString sEdit =
tsepez63f545c2016-09-13 16:08:49 -07001398 CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_FloatPoint());
thestig732f6a02016-05-12 10:41:56 -07001399 if (sEdit.GetLength() > 0) {
1400 sBody << "/Tx BMC\n"
1401 << "q\n";
1402 if (rcContent.Width() > rcEdit.Width() ||
1403 rcContent.Height() > rcEdit.Height()) {
1404 sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width()
1405 << " " << rcEdit.Height() << " re\nW\nn\n";
1406 }
1407
1408 CPWL_Color crText = GetTextPWLColor();
1409 sBody << "BT\n"
1410 << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"
1411 << "Q\nEMC\n";
1412 }
1413
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001414 sBody << CPWL_Utils::GetDropButtonAppStream(rcButton);
1415
1416 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
tsepez8e4c5052016-04-14 13:42:44 -07001417 sLines.AsStringC() + sBody.AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001418
1419 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1420}
1421
1422void CPDFSDK_Widget::ResetAppearance_ListBox() {
1423 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001424 CPDF_FormField* pField = pControl->GetField();
Tom Sepez281a9ea2016-02-26 14:24:28 -08001425 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001426 CFX_ByteTextBuf sBody, sLines;
1427
dsinclaire35af1e2016-07-13 11:26:20 -07001428 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit);
tsepez4cf55152016-11-02 14:37:54 -07001429 pEdit->EnableRefresh(false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001430
dsinclair690c0332016-10-11 09:13:01 -07001431 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
thestig732f6a02016-05-12 10:41:56 -07001432 pEdit->SetFontMap(&font_map);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001433
thestig732f6a02016-05-12 10:41:56 -07001434 pEdit->SetPlateRect(CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001435
thestig732f6a02016-05-12 10:41:56 -07001436 FX_FLOAT fFontSize = GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001437
thestig594b20b2016-05-12 21:56:43 -07001438 pEdit->SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001439
thestig732f6a02016-05-12 10:41:56 -07001440 pEdit->Initialize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001441
thestig732f6a02016-05-12 10:41:56 -07001442 CFX_ByteTextBuf sList;
1443 FX_FLOAT fy = rcClient.top;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001444
thestig732f6a02016-05-12 10:41:56 -07001445 int32_t nTop = pField->GetTopVisibleIndex();
1446 int32_t nCount = pField->CountOptions();
1447 int32_t nSelCount = pField->CountSelectedItems();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001448
thestig594b20b2016-05-12 21:56:43 -07001449 for (int32_t i = nTop; i < nCount; ++i) {
1450 bool bSelected = false;
1451 for (int32_t j = 0; j < nSelCount; ++j) {
thestig732f6a02016-05-12 10:41:56 -07001452 if (pField->GetSelectedIndex(j) == i) {
thestig594b20b2016-05-12 21:56:43 -07001453 bSelected = true;
thestig732f6a02016-05-12 10:41:56 -07001454 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001455 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001456 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001457
tsepez067990c2016-09-13 06:46:40 -07001458 pEdit->SetText(pField->GetOptionLabel(i));
thestig732f6a02016-05-12 10:41:56 -07001459
1460 CFX_FloatRect rcContent = pEdit->GetContentRect();
1461 FX_FLOAT fItemHeight = rcContent.Height();
1462
1463 if (bSelected) {
1464 CFX_FloatRect rcItem =
1465 CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy);
1466 sList << "q\n"
1467 << CPWL_Utils::GetColorAppStream(
1468 CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f,
1469 113.0f / 255.0f),
tsepez4cf55152016-11-02 14:37:54 -07001470 true)
thestig732f6a02016-05-12 10:41:56 -07001471 << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width()
1472 << " " << rcItem.Height() << " re f\n"
1473 << "Q\n";
1474
1475 sList << "BT\n"
1476 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1),
tsepez4cf55152016-11-02 14:37:54 -07001477 true)
dsinclaire35af1e2016-07-13 11:26:20 -07001478 << CPWL_Utils::GetEditAppStream(pEdit.get(),
1479 CFX_FloatPoint(0.0f, fy))
thestig732f6a02016-05-12 10:41:56 -07001480 << "ET\n";
1481 } else {
1482 CPWL_Color crText = GetTextPWLColor();
1483 sList << "BT\n"
tsepez4cf55152016-11-02 14:37:54 -07001484 << CPWL_Utils::GetColorAppStream(crText, true)
dsinclaire35af1e2016-07-13 11:26:20 -07001485 << CPWL_Utils::GetEditAppStream(pEdit.get(),
1486 CFX_FloatPoint(0.0f, fy))
thestig732f6a02016-05-12 10:41:56 -07001487 << "ET\n";
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001488 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001489
thestig732f6a02016-05-12 10:41:56 -07001490 fy -= fItemHeight;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001491 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001492
thestig732f6a02016-05-12 10:41:56 -07001493 if (sList.GetSize() > 0) {
1494 sBody << "/Tx BMC\n"
1495 << "q\n"
1496 << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width()
1497 << " " << rcClient.Height() << " re\nW\nn\n";
1498 sBody << sList << "Q\nEMC\n";
1499 }
1500
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001501 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
tsepez8e4c5052016-04-14 13:42:44 -07001502 sLines.AsStringC() + sBody.AsStringC();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001503
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001504 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001505}
1506
tsepeza31da742016-09-08 11:28:14 -07001507void CPDFSDK_Widget::ResetAppearance_TextField(const CFX_WideString* sValue) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001508 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001509 CPDF_FormField* pField = pControl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001510 CFX_ByteTextBuf sBody, sLines;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001511
dsinclaire35af1e2016-07-13 11:26:20 -07001512 std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit);
tsepez4cf55152016-11-02 14:37:54 -07001513 pEdit->EnableRefresh(false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001514
dsinclair690c0332016-10-11 09:13:01 -07001515 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
thestig732f6a02016-05-12 10:41:56 -07001516 pEdit->SetFontMap(&font_map);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001517
thestig732f6a02016-05-12 10:41:56 -07001518 CFX_FloatRect rcClient = GetClientRect();
1519 pEdit->SetPlateRect(rcClient);
tsepez4cf55152016-11-02 14:37:54 -07001520 pEdit->SetAlignmentH(pControl->GetControlAlignment(), true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001521
thestig732f6a02016-05-12 10:41:56 -07001522 uint32_t dwFieldFlags = pField->GetFieldFlags();
tsepez4cf55152016-11-02 14:37:54 -07001523 bool bMultiLine = (dwFieldFlags >> 12) & 1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001524
thestig732f6a02016-05-12 10:41:56 -07001525 if (bMultiLine) {
tsepez4cf55152016-11-02 14:37:54 -07001526 pEdit->SetMultiLine(true, true);
1527 pEdit->SetAutoReturn(true, true);
thestig732f6a02016-05-12 10:41:56 -07001528 } else {
tsepez4cf55152016-11-02 14:37:54 -07001529 pEdit->SetAlignmentV(1, true);
thestig732f6a02016-05-12 10:41:56 -07001530 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001531
thestig732f6a02016-05-12 10:41:56 -07001532 uint16_t subWord = 0;
1533 if ((dwFieldFlags >> 13) & 1) {
1534 subWord = '*';
tsepez4cf55152016-11-02 14:37:54 -07001535 pEdit->SetPasswordChar(subWord, true);
thestig732f6a02016-05-12 10:41:56 -07001536 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001537
thestig732f6a02016-05-12 10:41:56 -07001538 int nMaxLen = pField->GetMaxLen();
tsepez4cf55152016-11-02 14:37:54 -07001539 bool bCharArray = (dwFieldFlags >> 24) & 1;
thestig732f6a02016-05-12 10:41:56 -07001540 FX_FLOAT fFontSize = GetFontSize();
Bo Xufdc00a72014-10-28 23:03:33 -07001541
Tom Sepez51da0932015-11-25 16:05:49 -08001542#ifdef PDF_ENABLE_XFA
thestig732f6a02016-05-12 10:41:56 -07001543 CFX_WideString sValueTmp;
1544 if (!sValue && GetMixXFAWidget()) {
tsepez4cf55152016-11-02 14:37:54 -07001545 sValueTmp = GetValue(true);
tsepeza31da742016-09-08 11:28:14 -07001546 sValue = &sValueTmp;
thestig732f6a02016-05-12 10:41:56 -07001547 }
Tom Sepez40e9ff32015-11-30 12:39:54 -08001548#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001549
thestig732f6a02016-05-12 10:41:56 -07001550 if (nMaxLen > 0) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001551 if (bCharArray) {
thestig732f6a02016-05-12 10:41:56 -07001552 pEdit->SetCharArray(nMaxLen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001553
thestig732f6a02016-05-12 10:41:56 -07001554 if (IsFloatZero(fFontSize)) {
1555 fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0),
1556 rcClient, nMaxLen);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001557 }
thestig732f6a02016-05-12 10:41:56 -07001558 } else {
1559 if (sValue)
tsepeza31da742016-09-08 11:28:14 -07001560 nMaxLen = sValue->GetLength();
thestig732f6a02016-05-12 10:41:56 -07001561 pEdit->SetLimitChar(nMaxLen);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001562 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001563 }
1564
thestig732f6a02016-05-12 10:41:56 -07001565 if (IsFloatZero(fFontSize))
tsepez4cf55152016-11-02 14:37:54 -07001566 pEdit->SetAutoFontSize(true, true);
thestig732f6a02016-05-12 10:41:56 -07001567 else
1568 pEdit->SetFontSize(fFontSize);
1569
1570 pEdit->Initialize();
tsepez067990c2016-09-13 06:46:40 -07001571 pEdit->SetText(sValue ? *sValue : pField->GetValue());
thestig732f6a02016-05-12 10:41:56 -07001572
1573 CFX_FloatRect rcContent = pEdit->GetContentRect();
thestig732f6a02016-05-12 10:41:56 -07001574 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(
tsepez63f545c2016-09-13 16:08:49 -07001575 pEdit.get(), CFX_FloatPoint(), nullptr, !bCharArray, subWord);
thestig732f6a02016-05-12 10:41:56 -07001576
1577 if (sEdit.GetLength() > 0) {
1578 sBody << "/Tx BMC\n"
1579 << "q\n";
1580 if (rcContent.Width() > rcClient.Width() ||
1581 rcContent.Height() > rcClient.Height()) {
1582 sBody << rcClient.left << " " << rcClient.bottom << " "
1583 << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
1584 }
1585 CPWL_Color crText = GetTextPWLColor();
1586 sBody << "BT\n"
1587 << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"
1588 << "Q\nEMC\n";
1589 }
1590
1591 if (bCharArray) {
1592 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -07001593 case BorderStyle::SOLID: {
thestig732f6a02016-05-12 10:41:56 -07001594 CFX_ByteString sColor =
tsepez4cf55152016-11-02 14:37:54 -07001595 CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false);
thestig732f6a02016-05-12 10:41:56 -07001596 if (sColor.GetLength() > 0) {
1597 sLines << "q\n"
1598 << GetBorderWidth() << " w\n"
tsepez4cf55152016-11-02 14:37:54 -07001599 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false)
thestig732f6a02016-05-12 10:41:56 -07001600 << " 2 J 0 j\n";
1601
thestig594b20b2016-05-12 21:56:43 -07001602 for (int32_t i = 1; i < nMaxLen; ++i) {
thestig732f6a02016-05-12 10:41:56 -07001603 sLines << rcClient.left +
1604 ((rcClient.right - rcClient.left) / nMaxLen) * i
1605 << " " << rcClient.bottom << " m\n"
1606 << rcClient.left +
1607 ((rcClient.right - rcClient.left) / nMaxLen) * i
1608 << " " << rcClient.top << " l S\n";
1609 }
1610
1611 sLines << "Q\n";
1612 }
dsinclair92cb5e52016-05-16 11:38:28 -07001613 break;
1614 }
1615 case BorderStyle::DASH: {
thestig732f6a02016-05-12 10:41:56 -07001616 CFX_ByteString sColor =
tsepez4cf55152016-11-02 14:37:54 -07001617 CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false);
thestig732f6a02016-05-12 10:41:56 -07001618 if (sColor.GetLength() > 0) {
1619 CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0);
1620
1621 sLines << "q\n"
1622 << GetBorderWidth() << " w\n"
tsepez4cf55152016-11-02 14:37:54 -07001623 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false)
thestig732f6a02016-05-12 10:41:56 -07001624 << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] "
1625 << dsBorder.nPhase << " d\n";
1626
thestig594b20b2016-05-12 21:56:43 -07001627 for (int32_t i = 1; i < nMaxLen; ++i) {
thestig732f6a02016-05-12 10:41:56 -07001628 sLines << rcClient.left +
1629 ((rcClient.right - rcClient.left) / nMaxLen) * i
1630 << " " << rcClient.bottom << " m\n"
1631 << rcClient.left +
1632 ((rcClient.right - rcClient.left) / nMaxLen) * i
1633 << " " << rcClient.top << " l S\n";
1634 }
1635
1636 sLines << "Q\n";
1637 }
dsinclair92cb5e52016-05-16 11:38:28 -07001638 break;
1639 }
1640 default:
1641 break;
thestig732f6a02016-05-12 10:41:56 -07001642 }
1643 }
1644
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001645 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
tsepez8e4c5052016-04-14 13:42:44 -07001646 sLines.AsStringC() + sBody.AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001647 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001648}
1649
Tom Sepez281a9ea2016-02-26 14:24:28 -08001650CFX_FloatRect CPDFSDK_Widget::GetClientRect() const {
1651 CFX_FloatRect rcWindow = GetRotatedRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001652 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
1653 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -07001654 case BorderStyle::BEVELED:
1655 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001656 fBorderWidth *= 2.0f;
1657 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001658 default:
1659 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001660 }
1661
1662 return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001663}
1664
Tom Sepez281a9ea2016-02-26 14:24:28 -08001665CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const {
1666 CFX_FloatRect rectAnnot = GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001667 FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left;
1668 FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;
1669
1670 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -08001671 CFX_FloatRect rcPDFWindow;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001672 switch (abs(pControl->GetRotation() % 360)) {
1673 case 0:
1674 case 180:
1675 default:
Tom Sepez281a9ea2016-02-26 14:24:28 -08001676 rcPDFWindow = CFX_FloatRect(0, 0, fWidth, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001677 break;
1678 case 90:
1679 case 270:
Tom Sepez281a9ea2016-02-26 14:24:28 -08001680 rcPDFWindow = CFX_FloatRect(0, 0, fHeight, fWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001681 break;
1682 }
1683
1684 return rcPDFWindow;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001685}
1686
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001687CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const {
1688 CPWL_Color crBackground = GetFillPWLColor();
jaepark611adb82016-08-17 11:34:36 -07001689 if (crBackground.nColorType != COLORTYPE_TRANSPARENT)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001690 return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);
jaepark611adb82016-08-17 11:34:36 -07001691
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001692 return "";
Bo Xufdc00a72014-10-28 23:03:33 -07001693}
1694
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001695CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001696 CFX_FloatRect rcWindow = GetRotatedRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001697 CPWL_Color crBorder = GetBorderPWLColor();
1698 CPWL_Color crBackground = GetFillPWLColor();
1699 CPWL_Color crLeftTop, crRightBottom;
1700
1701 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001702 CPWL_Dash dsBorder(3, 0, 0);
1703
dsinclair92cb5e52016-05-16 11:38:28 -07001704 BorderStyle nBorderStyle = GetBorderStyle();
1705 switch (nBorderStyle) {
1706 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001707 dsBorder = CPWL_Dash(3, 3, 0);
1708 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001709 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001710 fBorderWidth *= 2;
1711 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1712 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
1713 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001714 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001715 fBorderWidth *= 2;
1716 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1717 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1718 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001719 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001720 break;
1721 }
1722
1723 return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1724 crLeftTop, crRightBottom, nBorderStyle,
1725 dsBorder);
Bo Xufdc00a72014-10-28 23:03:33 -07001726}
1727
Tom Sepez60d909e2015-12-10 15:34:55 -08001728CFX_Matrix CPDFSDK_Widget::GetMatrix() const {
1729 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001730 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -08001731 CFX_FloatRect rcAnnot = GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001732 FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left;
1733 FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom;
1734
1735 switch (abs(pControl->GetRotation() % 360)) {
1736 case 0:
1737 default:
Tom Sepez60d909e2015-12-10 15:34:55 -08001738 mt = CFX_Matrix(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001739 break;
1740 case 90:
Tom Sepez60d909e2015-12-10 15:34:55 -08001741 mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001742 break;
1743 case 180:
Tom Sepez60d909e2015-12-10 15:34:55 -08001744 mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001745 break;
1746 case 270:
Tom Sepez60d909e2015-12-10 15:34:55 -08001747 mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001748 break;
1749 }
1750
1751 return mt;
Bo Xufdc00a72014-10-28 23:03:33 -07001752}
1753
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001754CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const {
1755 CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0);
1756
1757 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001758 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
1759 if (da.HasColor()) {
1760 int32_t iColorType;
1761 FX_FLOAT fc[4];
1762 da.GetColor(iColorType, fc);
1763 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1764 }
1765
1766 return crText;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001767}
1768
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001769CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const {
1770 CPWL_Color crBorder;
1771
1772 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001773 int32_t iColorType;
1774 FX_FLOAT fc[4];
1775 pFormCtrl->GetOriginalBorderColor(iColorType, fc);
1776 if (iColorType > 0)
1777 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1778
1779 return crBorder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001780}
1781
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001782CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const {
1783 CPWL_Color crFill;
1784
1785 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001786 int32_t iColorType;
1787 FX_FLOAT fc[4];
1788 pFormCtrl->GetOriginalBackgroundColor(iColorType, fc);
1789 if (iColorType > 0)
1790 crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1791
1792 return crFill;
Bo Xufdc00a72014-10-28 23:03:33 -07001793}
1794
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001795void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType,
1796 CPDF_Stream* pImage) {
dsinclair38fd8442016-09-15 10:15:32 -07001797 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
1798 CPDF_Stream* pStream = pAPDict->GetStreamFor(sAPType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001799 CPDF_Dictionary* pStreamDict = pStream->GetDict();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001800 CFX_ByteString sImageAlias = "IMG";
1801
1802 if (CPDF_Dictionary* pImageDict = pImage->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -07001803 sImageAlias = pImageDict->GetStringFor("Name");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001804 if (sImageAlias.IsEmpty())
1805 sImageAlias = "IMG";
1806 }
1807
tsepez698c5712016-09-28 16:47:07 -07001808 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
dsinclair38fd8442016-09-15 10:15:32 -07001809 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
tsepez0e606b52016-11-18 16:22:41 -08001810 if (!pStreamResList)
1811 pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001812
tsepez0e606b52016-11-18 16:22:41 -08001813 CPDF_Dictionary* pXObject =
1814 pStreamResList->SetNewFor<CPDF_Dictionary>("XObject");
1815 pXObject->SetNewFor<CPDF_Reference>(sImageAlias, pDoc, pImage->GetObjNum());
Bo Xufdc00a72014-10-28 23:03:33 -07001816}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001817
1818void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) {
dsinclair38fd8442016-09-15 10:15:32 -07001819 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"))
1820 pAPDict->RemoveFor(sAPType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001821}
1822
tsepez4cf55152016-11-02 14:37:54 -07001823bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
1824 PDFSDK_FieldAction& data,
1825 CPDFSDK_PageView* pPageView) {
dsinclairb402b172016-10-11 09:26:32 -07001826 CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001827
Tom Sepez40e9ff32015-11-30 12:39:54 -08001828#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -07001829 CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext();
dsinclairdf4bc592016-03-31 20:34:43 -07001830 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001831 XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit);
1832
1833 if (eEventType != XFA_EVENT_Unknown) {
dsinclairdf4bc592016-03-31 20:34:43 -07001834 if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001835 CXFA_EventParam param;
1836 param.m_eType = eEventType;
1837 param.m_wsChange = data.sChange;
1838 param.m_iCommitKey = data.nCommitKey;
1839 param.m_bShift = data.bShift;
1840 param.m_iSelStart = data.nSelStart;
1841 param.m_iSelEnd = data.nSelEnd;
1842 param.m_wsFullText = data.sValue;
1843 param.m_bKeyDown = data.bKeyDown;
1844 param.m_bModifier = data.bModifier;
1845 param.m_wsNewText = data.sValue;
1846 if (data.nSelEnd > data.nSelStart)
1847 param.m_wsNewText.Delete(data.nSelStart,
1848 data.nSelEnd - data.nSelStart);
1849 for (int i = data.sChange.GetLength() - 1; i >= 0; i--)
1850 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
1851 param.m_wsPrevText = data.sValue;
1852
dsinclair221caf62016-04-04 12:08:40 -07001853 CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001854 param.m_pTarget = pAcc;
1855 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
1856
dsinclair521b7502016-11-02 13:02:28 -07001857 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001858 pDocView->UpdateDocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001859
Wei Lie98ac2e2016-03-18 15:43:04 -07001860 if (nRet == XFA_EVENTERROR_Success)
tsepez4cf55152016-11-02 14:37:54 -07001861 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001862 }
1863 }
1864 }
Tom Sepez40e9ff32015-11-30 12:39:54 -08001865#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001866
1867 CPDF_Action action = GetAAction(type);
Wei Li0fc6b252016-03-01 16:29:41 -08001868 if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) {
dsinclairb402b172016-10-11 09:26:32 -07001869 CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander();
dsinclair19c198b2016-10-11 12:51:37 -07001870 return pActionHandler->DoAction_Field(action, type, pFormFillEnv,
1871 GetFormField(), data);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001872 }
tsepez4cf55152016-11-02 14:37:54 -07001873 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001874}
1875
1876CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) {
1877 switch (eAAT) {
1878 case CPDF_AAction::CursorEnter:
1879 case CPDF_AAction::CursorExit:
1880 case CPDF_AAction::ButtonDown:
1881 case CPDF_AAction::ButtonUp:
1882 case CPDF_AAction::GetFocus:
1883 case CPDF_AAction::LoseFocus:
1884 case CPDF_AAction::PageOpen:
1885 case CPDF_AAction::PageClose:
1886 case CPDF_AAction::PageVisible:
1887 case CPDF_AAction::PageInvisible:
1888 return CPDFSDK_BAAnnot::GetAAction(eAAT);
1889
1890 case CPDF_AAction::KeyStroke:
1891 case CPDF_AAction::Format:
1892 case CPDF_AAction::Validate:
1893 case CPDF_AAction::Calculate: {
1894 CPDF_FormField* pField = GetFormField();
Wei Li0fc6b252016-03-01 16:29:41 -08001895 if (pField->GetAdditionalAction().GetDict())
1896 return pField->GetAdditionalAction().GetAction(eAAT);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001897 return CPDFSDK_BAAnnot::GetAAction(eAAT);
1898 }
1899 default:
1900 break;
1901 }
1902
1903 return CPDF_Action();
1904}
1905
1906CFX_WideString CPDFSDK_Widget::GetAlternateName() const {
1907 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001908 return pFormField->GetAlternateName();
1909}
1910
1911int32_t CPDFSDK_Widget::GetAppearanceAge() const {
1912 return m_nAppAge;
1913}
1914
1915int32_t CPDFSDK_Widget::GetValueAge() const {
1916 return m_nValueAge;
1917}
1918
tsepez4cf55152016-11-02 14:37:54 -07001919bool CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001920 CPDF_Annot* pAnnot = GetPDFAnnot();
jaeparka1d21112016-08-25 13:33:34 -07001921 CFX_FloatRect annotRect = pAnnot->GetRect();
jaepark611adb82016-08-17 11:34:36 -07001922 if (!annotRect.Contains(pageX, pageY))
tsepez4cf55152016-11-02 14:37:54 -07001923 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001924
jaepark611adb82016-08-17 11:34:36 -07001925 if (!IsVisible())
tsepez4cf55152016-11-02 14:37:54 -07001926 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001927
jaepark611adb82016-08-17 11:34:36 -07001928 if ((GetFieldFlags() & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
tsepez4cf55152016-11-02 14:37:54 -07001929 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001930
tsepez4cf55152016-11-02 14:37:54 -07001931 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001932}