blob: e65a94b2b3565469f67f48c1eeb8d2b0ada31132 [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"
Dan Sinclair80c48782017-03-23 12:11:20 -040038#include "xfa/fxfa/cxfa_ffdocview.h"
39#include "xfa/fxfa/cxfa_ffwidget.h"
40#include "xfa/fxfa/cxfa_ffwidgethandler.h"
41#include "xfa/fxfa/cxfa_widgetacc.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();
Dan Sinclaircdba7472017-03-23 09:17:10 -040075 if (pContext->GetDocType() == XFA_DocType::Static) {
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();
Dan Sinclaircdba7472017-03-23 09:17:10 -040099 if (pContext->GetDocType() != XFA_DocType::Static)
100 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101
Dan Sinclaircdba7472017-03-23 09:17:10 -0400102 CXFA_FFDocView* pDocView = pContext->GetXFADocView();
103 if (!pDocView)
104 return nullptr;
105
106 CFX_WideString sName = GetName();
107 return !sName.IsEmpty() ? pDocView->GetWidgetByName(sName, nullptr) : 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();
Dan Sinclaircdba7472017-03-23 09:17:10 -0400112 if (pContext->GetDocType() != XFA_DocType::Static)
113 return nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114
Dan Sinclaircdba7472017-03-23 09:17:10 -0400115 if (!m_pWidgetHandler) {
116 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
117 m_pWidgetHandler = pDocView->GetWidgetHandler();
118 }
119 return m_pWidgetHandler;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120}
121
122static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) {
123 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
124
125 switch (eXFAAAT) {
126 case PDFSDK_XFA_Click:
127 eEventType = XFA_EVENT_Click;
128 break;
129 case PDFSDK_XFA_Full:
130 eEventType = XFA_EVENT_Full;
131 break;
132 case PDFSDK_XFA_PreOpen:
133 eEventType = XFA_EVENT_PreOpen;
134 break;
135 case PDFSDK_XFA_PostOpen:
136 eEventType = XFA_EVENT_PostOpen;
137 break;
138 }
139
140 return eEventType;
141}
142
143static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT,
tsepez4cf55152016-11-02 14:37:54 -0700144 bool bWillCommit) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145 XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown;
146
147 switch (eAAT) {
148 case CPDF_AAction::CursorEnter:
149 eEventType = XFA_EVENT_MouseEnter;
150 break;
151 case CPDF_AAction::CursorExit:
152 eEventType = XFA_EVENT_MouseExit;
153 break;
154 case CPDF_AAction::ButtonDown:
155 eEventType = XFA_EVENT_MouseDown;
156 break;
157 case CPDF_AAction::ButtonUp:
158 eEventType = XFA_EVENT_MouseUp;
159 break;
160 case CPDF_AAction::GetFocus:
161 eEventType = XFA_EVENT_Enter;
162 break;
163 case CPDF_AAction::LoseFocus:
164 eEventType = XFA_EVENT_Exit;
165 break;
166 case CPDF_AAction::PageOpen:
167 break;
168 case CPDF_AAction::PageClose:
169 break;
170 case CPDF_AAction::PageVisible:
171 break;
172 case CPDF_AAction::PageInvisible:
173 break;
174 case CPDF_AAction::KeyStroke:
jaepark611adb82016-08-17 11:34:36 -0700175 if (!bWillCommit)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 eEventType = XFA_EVENT_Change;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700177 break;
178 case CPDF_AAction::Validate:
179 eEventType = XFA_EVENT_Validate;
180 break;
181 case CPDF_AAction::OpenPage:
182 case CPDF_AAction::ClosePage:
183 case CPDF_AAction::Format:
184 case CPDF_AAction::Calculate:
185 case CPDF_AAction::CloseDocument:
186 case CPDF_AAction::SaveDocument:
187 case CPDF_AAction::DocumentSaved:
188 case CPDF_AAction::PrintDocument:
189 case CPDF_AAction::DocumentPrinted:
190 break;
191 }
192
193 return eEventType;
194}
195
tsepez4cf55152016-11-02 14:37:54 -0700196bool CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) {
jaepark611adb82016-08-17 11:34:36 -0700197 CXFA_FFWidget* hWidget = GetMixXFAWidget();
198 if (!hWidget)
tsepez4cf55152016-11-02 14:37:54 -0700199 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200
jaepark611adb82016-08-17 11:34:36 -0700201 CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
202 if (!pXFAWidgetHandler)
tsepez4cf55152016-11-02 14:37:54 -0700203 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204
jaepark611adb82016-08-17 11:34:36 -0700205 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
206
207 CXFA_WidgetAcc* pAcc;
208 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
209 GetFieldType() == FIELDTYPE_RADIOBUTTON) {
210 if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) {
211 pAcc = hGroupWidget->GetDataAcc();
212 if (pXFAWidgetHandler->HasEvent(pAcc, eEventType))
tsepez4cf55152016-11-02 14:37:54 -0700213 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 }
215 }
216
jaepark611adb82016-08-17 11:34:36 -0700217 pAcc = hWidget->GetDataAcc();
218 return pXFAWidgetHandler->HasEvent(pAcc, eEventType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219}
220
tsepez4cf55152016-11-02 14:37:54 -0700221bool CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT,
222 PDFSDK_FieldAction& data,
223 CPDFSDK_PageView* pPageView) {
dsinclair521b7502016-11-02 13:02:28 -0700224 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225
jaepark611adb82016-08-17 11:34:36 -0700226 CXFA_FFWidget* hWidget = GetMixXFAWidget();
227 if (!hWidget)
tsepez4cf55152016-11-02 14:37:54 -0700228 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700229
jaepark611adb82016-08-17 11:34:36 -0700230 XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT);
231 if (eEventType == XFA_EVENT_Unknown)
tsepez4cf55152016-11-02 14:37:54 -0700232 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233
jaepark611adb82016-08-17 11:34:36 -0700234 CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler();
235 if (!pXFAWidgetHandler)
tsepez4cf55152016-11-02 14:37:54 -0700236 return false;
jaepark611adb82016-08-17 11:34:36 -0700237
238 CXFA_EventParam param;
239 param.m_eType = eEventType;
240 param.m_wsChange = data.sChange;
241 param.m_iCommitKey = data.nCommitKey;
242 param.m_bShift = data.bShift;
243 param.m_iSelStart = data.nSelStart;
244 param.m_iSelEnd = data.nSelEnd;
245 param.m_wsFullText = data.sValue;
246 param.m_bKeyDown = data.bKeyDown;
247 param.m_bModifier = data.bModifier;
248 param.m_wsNewText = data.sValue;
249 if (data.nSelEnd > data.nSelStart)
250 param.m_wsNewText.Delete(data.nSelStart, data.nSelEnd - data.nSelStart);
251
252 for (int i = 0; i < data.sChange.GetLength(); i++)
253 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
254 param.m_wsPrevText = data.sValue;
255
256 if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) &&
257 GetFieldType() == FIELDTYPE_RADIOBUTTON) {
258 if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) {
259 CXFA_WidgetAcc* pAcc = hGroupWidget->GetDataAcc();
260 param.m_pTarget = pAcc;
261 if (pXFAWidgetHandler->ProcessEvent(pAcc, &param) !=
262 XFA_EVENTERROR_Success) {
tsepez4cf55152016-11-02 14:37:54 -0700263 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700264 }
265 }
266 }
jaepark611adb82016-08-17 11:34:36 -0700267 CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc();
268 param.m_pTarget = pAcc;
269 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700270
dsinclair521b7502016-11-02 13:02:28 -0700271 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
jaepark611adb82016-08-17 11:34:36 -0700272 pDocView->UpdateDocView();
273
274 return nRet == XFA_EVENTERROR_Success;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275}
276
tsepez4cf55152016-11-02 14:37:54 -0700277void CPDFSDK_Widget::Synchronize(bool bSynchronizeElse) {
jaepark611adb82016-08-17 11:34:36 -0700278 CXFA_FFWidget* hWidget = GetMixXFAWidget();
279 if (!hWidget)
280 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700281
jaepark611adb82016-08-17 11:34:36 -0700282 CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc();
283 if (!pWidgetAcc)
284 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285
jaepark611adb82016-08-17 11:34:36 -0700286 CPDF_FormField* pFormField = GetFormField();
287 switch (GetFieldType()) {
288 case FIELDTYPE_CHECKBOX:
289 case FIELDTYPE_RADIOBUTTON: {
290 CPDF_FormControl* pFormCtrl = GetFormControl();
291 XFA_CHECKSTATE eCheckState =
292 pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off;
293 pWidgetAcc->SetCheckState(eCheckState, true);
294 break;
295 }
296 case FIELDTYPE_TEXTFIELD:
297 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
298 break;
299 case FIELDTYPE_LISTBOX: {
300 pWidgetAcc->ClearAllSelections();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301
jaepark611adb82016-08-17 11:34:36 -0700302 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
303 int nIndex = pFormField->GetSelectedIndex(i);
Tom Sepez5c500ac2017-03-27 12:44:20 -0700304 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems(false))
tsepez4cf55152016-11-02 14:37:54 -0700305 pWidgetAcc->SetItemState(nIndex, true, false, false, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700306 }
jaepark611adb82016-08-17 11:34:36 -0700307 break;
308 }
309 case FIELDTYPE_COMBOBOX: {
310 pWidgetAcc->ClearAllSelections();
dsinclair221caf62016-04-04 12:08:40 -0700311
jaepark611adb82016-08-17 11:34:36 -0700312 for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) {
313 int nIndex = pFormField->GetSelectedIndex(i);
Tom Sepez5c500ac2017-03-27 12:44:20 -0700314 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems(false))
tsepez4cf55152016-11-02 14:37:54 -0700315 pWidgetAcc->SetItemState(nIndex, true, false, false, true);
jaepark611adb82016-08-17 11:34:36 -0700316 }
317 pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit);
318 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319 }
320 }
jaepark611adb82016-08-17 11:34:36 -0700321
322 if (bSynchronizeElse)
323 pWidgetAcc->ProcessValueChanged();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700324}
325
326void CPDFSDK_Widget::SynchronizeXFAValue() {
dsinclair521b7502016-11-02 13:02:28 -0700327 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
328 CXFA_FFDocView* pXFADocView = pContext->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700329 if (!pXFADocView)
330 return;
331
dsinclairdf4bc592016-03-31 20:34:43 -0700332 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700333 if (GetXFAWidgetHandler()) {
334 CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(),
335 GetFormControl());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700336 }
337 }
338}
339
340void CPDFSDK_Widget::SynchronizeXFAItems() {
dsinclair521b7502016-11-02 13:02:28 -0700341 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
342 CXFA_FFDocView* pXFADocView = pContext->GetXFADocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700343 if (!pXFADocView)
344 return;
345
dsinclairdf4bc592016-03-31 20:34:43 -0700346 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Tom Sepezbf59a072015-10-21 14:07:23 -0700347 if (GetXFAWidgetHandler())
348 SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349 }
350}
351
dsinclairdf4bc592016-03-31 20:34:43 -0700352void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView,
353 CXFA_FFWidget* hWidget,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 CPDF_FormField* pFormField,
355 CPDF_FormControl* pFormControl) {
Lei Zhang5eca3052016-02-22 20:32:21 -0800356 ASSERT(hWidget);
dsinclair221caf62016-04-04 12:08:40 -0700357 ASSERT(pFormControl);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700358
dsinclair221caf62016-04-04 12:08:40 -0700359 switch (pFormField->GetFieldType()) {
360 case FIELDTYPE_CHECKBOX: {
361 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
362 pFormField->CheckControl(
363 pFormField->GetControlIndex(pFormControl),
364 pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true);
365 }
jaepark611adb82016-08-17 11:34:36 -0700366 break;
367 }
dsinclair221caf62016-04-04 12:08:40 -0700368 case FIELDTYPE_RADIOBUTTON: {
369 // TODO(weili): Check whether we need to handle checkbox and radio
370 // button differently, otherwise, merge these two cases.
371 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
372 pFormField->CheckControl(
373 pFormField->GetControlIndex(pFormControl),
374 pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true);
375 }
jaepark611adb82016-08-17 11:34:36 -0700376 break;
377 }
dsinclair221caf62016-04-04 12:08:40 -0700378 case FIELDTYPE_TEXTFIELD: {
379 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
380 CFX_WideString sValue;
381 pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
tsepez4cf55152016-11-02 14:37:54 -0700382 pFormField->SetValue(sValue, true);
dsinclair221caf62016-04-04 12:08:40 -0700383 }
jaepark611adb82016-08-17 11:34:36 -0700384 break;
385 }
dsinclair221caf62016-04-04 12:08:40 -0700386 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700387 pFormField->ClearSelection(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388
dsinclair221caf62016-04-04 12:08:40 -0700389 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
390 for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
391 int nIndex = pWidgetAcc->GetSelectedItem(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392
dsinclair221caf62016-04-04 12:08:40 -0700393 if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
tsepez4cf55152016-11-02 14:37:54 -0700394 pFormField->SetItemSelection(nIndex, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700395 }
396 }
dsinclair221caf62016-04-04 12:08:40 -0700397 }
jaepark611adb82016-08-17 11:34:36 -0700398 break;
399 }
dsinclair221caf62016-04-04 12:08:40 -0700400 case FIELDTYPE_COMBOBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700401 pFormField->ClearSelection(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402
dsinclair221caf62016-04-04 12:08:40 -0700403 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
404 for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) {
405 int nIndex = pWidgetAcc->GetSelectedItem(i);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406
dsinclair221caf62016-04-04 12:08:40 -0700407 if (nIndex > -1 && nIndex < pFormField->CountOptions()) {
tsepez4cf55152016-11-02 14:37:54 -0700408 pFormField->SetItemSelection(nIndex, true, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700409 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410 }
dsinclair221caf62016-04-04 12:08:40 -0700411
412 CFX_WideString sValue;
413 pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display);
tsepez4cf55152016-11-02 14:37:54 -0700414 pFormField->SetValue(sValue, true);
dsinclair221caf62016-04-04 12:08:40 -0700415 }
jaepark611adb82016-08-17 11:34:36 -0700416 break;
417 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700418 }
419}
420
dsinclairdf4bc592016-03-31 20:34:43 -0700421void CPDFSDK_Widget::SynchronizeXFAItems(CXFA_FFDocView* pXFADocView,
422 CXFA_FFWidget* hWidget,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423 CPDF_FormField* pFormField,
424 CPDF_FormControl* pFormControl) {
Lei Zhang5eca3052016-02-22 20:32:21 -0800425 ASSERT(hWidget);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700426
dsinclair221caf62016-04-04 12:08:40 -0700427 switch (pFormField->GetFieldType()) {
428 case FIELDTYPE_LISTBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700429 pFormField->ClearSelection(false);
430 pFormField->ClearOptions(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431
dsinclair221caf62016-04-04 12:08:40 -0700432 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
Tom Sepez5c500ac2017-03-27 12:44:20 -0700433 for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(false); i < sz;
434 i++) {
dsinclair221caf62016-04-04 12:08:40 -0700435 CFX_WideString swText;
Tom Sepez5c500ac2017-03-27 12:44:20 -0700436 pWidgetAcc->GetChoiceListItem(swText, i, false);
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()) {
Tom Sepez5c500ac2017-03-27 12:44:20 -0700448 for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(false); i < sz;
449 i++) {
dsinclair221caf62016-04-04 12:08:40 -0700450 CFX_WideString swText;
Tom Sepez5c500ac2017-03-27 12:44:20 -0700451 pWidgetAcc->GetChoiceListItem(swText, i, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452
tsepez4cf55152016-11-02 14:37:54 -0700453 pFormField->InsertOption(swText, i, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454 }
dsinclair221caf62016-04-04 12:08:40 -0700455 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456
tsepez4cf55152016-11-02 14:37:54 -0700457 pFormField->SetValue(L"", true);
jaepark611adb82016-08-17 11:34:36 -0700458 break;
459 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460 }
461}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800462#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463
tsepez4cf55152016-11-02 14:37:54 -0700464bool CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode mode) {
dsinclair38fd8442016-09-15 10:15:32 -0700465 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 if (!pAP)
tsepez4cf55152016-11-02 14:37:54 -0700467 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700468
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 // Choose the right sub-ap
Dan Sinclair812e96c2017-03-13 16:43:37 -0400470 const char* ap_entry = "N";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 if (mode == CPDF_Annot::Down)
472 ap_entry = "D";
473 else if (mode == CPDF_Annot::Rollover)
474 ap_entry = "R";
475 if (!pAP->KeyExist(ap_entry))
476 ap_entry = "N";
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700477
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 // Get the AP stream or subdirectory
dsinclair38fd8442016-09-15 10:15:32 -0700479 CPDF_Object* psub = pAP->GetDirectObjectFor(ap_entry);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480 if (!psub)
tsepez4cf55152016-11-02 14:37:54 -0700481 return false;
Lei Zhanga6d9f0e2015-06-13 00:48:38 -0700482
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483 int nFieldType = GetFieldType();
484 switch (nFieldType) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700485 case FIELDTYPE_PUSHBUTTON:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700486 case FIELDTYPE_COMBOBOX:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700487 case FIELDTYPE_LISTBOX:
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700488 case FIELDTYPE_TEXTFIELD:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489 case FIELDTYPE_SIGNATURE:
Dan Sinclairaa435ba2015-10-22 16:45:48 -0400490 return psub->IsStream();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700491 case FIELDTYPE_CHECKBOX:
492 case FIELDTYPE_RADIOBUTTON:
Dan Sinclairf1251c12015-10-20 16:24:45 -0400493 if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) {
dsinclair38fd8442016-09-15 10:15:32 -0700494 return !!pSubDict->GetStreamFor(GetAppState());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495 }
tsepez4cf55152016-11-02 14:37:54 -0700496 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497 }
tsepez4cf55152016-11-02 14:37:54 -0700498 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499}
500
501int CPDFSDK_Widget::GetFieldType() const {
dsinclair92828192016-08-17 13:28:51 -0700502 CPDF_FormField* pField = GetFormField();
503 return pField ? pField->GetFieldType() : FIELDTYPE_UNKNOWN;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504}
505
tsepez4cf55152016-11-02 14:37:54 -0700506bool CPDFSDK_Widget::IsAppearanceValid() {
Tom Sepez51da0932015-11-25 16:05:49 -0800507#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -0700508 CPDFXFA_Context* pContext = m_pPageView->GetFormFillEnv()->GetXFAContext();
Dan Sinclaircdba7472017-03-23 09:17:10 -0400509 XFA_DocType nDocType = pContext->GetDocType();
510 if (nDocType != XFA_DocType::PDF && nDocType != XFA_DocType::Static)
tsepez4cf55152016-11-02 14:37:54 -0700511 return true;
Tom Sepez40e9ff32015-11-30 12:39:54 -0800512#endif // PDF_ENABLE_XFA
Tom Sepez540c4362015-11-24 13:33:57 -0800513 return CPDFSDK_BAAnnot::IsAppearanceValid();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514}
515
weili625ad662016-06-15 11:21:33 -0700516int CPDFSDK_Widget::GetLayoutOrder() const {
517 return 2;
518}
519
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520int CPDFSDK_Widget::GetFieldFlags() const {
521 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 CPDF_FormControl* pFormControl =
523 pPDFInterForm->GetControlByDict(m_pAnnot->GetAnnotDict());
524 CPDF_FormField* pFormField = pFormControl->GetField();
525 return pFormField->GetFieldFlags();
526}
527
jaepark9ed91372016-08-26 16:16:10 -0700528bool CPDFSDK_Widget::IsSignatureWidget() const {
529 return GetFieldType() == FIELDTYPE_SIGNATURE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530}
531
532CPDF_FormField* CPDFSDK_Widget::GetFormField() const {
dsinclair92828192016-08-17 13:28:51 -0700533 CPDF_FormControl* pControl = GetFormControl();
534 return pControl ? pControl->GetField() : nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535}
536
537CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539 return pPDFInterForm->GetControlByDict(GetAnnotDict());
540}
541
Lei Zhang1b700c32015-10-30 23:55:35 -0700542CPDF_FormControl* CPDFSDK_Widget::GetFormControl(
543 CPDF_InterForm* pInterForm,
544 const CPDF_Dictionary* pAnnotDict) {
Lei Zhang96660d62015-12-14 18:27:25 -0800545 ASSERT(pAnnotDict);
Lei Zhang1b700c32015-10-30 23:55:35 -0700546 return pInterForm->GetControlByDict(pAnnotDict);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547}
548
549int CPDFSDK_Widget::GetRotate() const {
550 CPDF_FormControl* pCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700551 return pCtrl->GetRotation() % 360;
552}
553
Tom Sepez51da0932015-11-25 16:05:49 -0800554#ifdef PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700555CFX_WideString CPDFSDK_Widget::GetName() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700556 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 return pFormField->GetFullName();
558}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800559#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700560
tsepez4cf55152016-11-02 14:37:54 -0700561bool CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563 int iColorType = 0;
dsinclair72177da2016-09-15 12:07:23 -0700564 color = ARGBToColorRef(pFormCtrl->GetBackgroundColor(iColorType));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565 return iColorType != COLORTYPE_TRANSPARENT;
566}
567
tsepez4cf55152016-11-02 14:37:54 -0700568bool CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570 int iColorType = 0;
dsinclair72177da2016-09-15 12:07:23 -0700571 color = ARGBToColorRef(pFormCtrl->GetBorderColor(iColorType));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572 return iColorType != COLORTYPE_TRANSPARENT;
573}
574
tsepez4cf55152016-11-02 14:37:54 -0700575bool CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700577 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
jaepark611adb82016-08-17 11:34:36 -0700578 if (!da.HasColor())
tsepez4cf55152016-11-02 14:37:54 -0700579 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580
jaepark611adb82016-08-17 11:34:36 -0700581 FX_ARGB argb;
582 int iColorType = COLORTYPE_TRANSPARENT;
583 da.GetColor(argb, iColorType);
dsinclair72177da2016-09-15 12:07:23 -0700584 color = ARGBToColorRef(argb);
jaepark611adb82016-08-17 11:34:36 -0700585 return iColorType != COLORTYPE_TRANSPARENT;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586}
587
Dan Sinclair05df0752017-03-14 14:43:42 -0400588float CPDFSDK_Widget::GetFontSize() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700590 CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
591 CFX_ByteString csFont = "";
Dan Sinclair05df0752017-03-14 14:43:42 -0400592 float fFontSize = 0.0f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700593 pDa.GetFont(csFont, fFontSize);
594
595 return fFontSize;
596}
597
Tom Sepezbf59a072015-10-21 14:07:23 -0700598int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700599#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700600 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700601 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
602 if (nIndex < pWidgetAcc->CountSelectedItems())
603 return pWidgetAcc->GetSelectedItem(nIndex);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700604 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700606#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700607 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700608 return pFormField->GetSelectedIndex(nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700609}
610
Tom Sepeza8a39e22015-10-12 15:47:07 -0700611#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700612CFX_WideString CPDFSDK_Widget::GetValue(bool bDisplay) const {
dsinclairdf4bc592016-03-31 20:34:43 -0700613 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700614 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
615 CFX_WideString sValue;
616 pWidgetAcc->GetValue(
617 sValue, bDisplay ? XFA_VALUEPICTURE_Display : XFA_VALUEPICTURE_Edit);
618 return sValue;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700619 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800621#else
622CFX_WideString CPDFSDK_Widget::GetValue() const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700623#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700625 return pFormField->GetValue();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700626}
627
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700628CFX_WideString CPDFSDK_Widget::GetDefaultValue() const {
629 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630 return pFormField->GetDefaultValue();
631}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700632
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const {
634 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700635 return pFormField->GetOptionLabel(nIndex);
636}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700637
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700638int CPDFSDK_Widget::CountOptions() const {
639 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700640 return pFormField->CountOptions();
641}
642
tsepez4cf55152016-11-02 14:37:54 -0700643bool CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700644#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700645 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700646 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
Tom Sepez5c500ac2017-03-27 12:44:20 -0700647 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems(false))
dsinclair221caf62016-04-04 12:08:40 -0700648 return pWidgetAcc->GetItemState(nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649
tsepez4cf55152016-11-02 14:37:54 -0700650 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700651 }
652 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700653#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700654 CPDF_FormField* pFormField = GetFormField();
655 return pFormField->IsItemSelected(nIndex);
656}
657
658int CPDFSDK_Widget::GetTopVisibleIndex() const {
659 CPDF_FormField* pFormField = GetFormField();
660 return pFormField->GetTopVisibleIndex();
661}
662
Wei Li97da9762016-03-11 17:00:48 -0800663bool CPDFSDK_Widget::IsChecked() const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700664#ifdef PDF_ENABLE_XFA
dsinclair221caf62016-04-04 12:08:40 -0700665 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
666 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc())
667 return pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700668 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700669#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700670 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700671 return pFormCtrl->IsChecked();
672}
673
674int CPDFSDK_Widget::GetAlignment() const {
675 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700676 return pFormCtrl->GetControlAlignment();
677}
678
679int CPDFSDK_Widget::GetMaxLen() const {
680 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681 return pFormField->GetMaxLen();
682}
683
Wei Li97da9762016-03-11 17:00:48 -0800684void CPDFSDK_Widget::SetCheck(bool bChecked, bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700686 CPDF_FormField* pFormField = pFormCtrl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700687 pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
688 bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800689#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690 if (!IsWidgetAppearanceValid(CPDF_Annot::Normal))
tsepez4cf55152016-11-02 14:37:54 -0700691 ResetAppearance(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700693 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800694#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700695}
696
tsepez4cf55152016-11-02 14:37:54 -0700697void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700698 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700699 pFormField->SetValue(sValue, bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800700#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700701 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700702 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800703#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700704}
705
706void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {}
707void CPDFSDK_Widget::SetOptionSelection(int index,
tsepez4cf55152016-11-02 14:37:54 -0700708 bool bSelected,
709 bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700710 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711 pFormField->SetItemSelection(index, bSelected, bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800712#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700713 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700714 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800715#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700716}
717
tsepez4cf55152016-11-02 14:37:54 -0700718void CPDFSDK_Widget::ClearSelection(bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700720 pFormField->ClearSelection(bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800721#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700723 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800724#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725}
726
727void CPDFSDK_Widget::SetTopVisibleIndex(int index) {}
728
729void CPDFSDK_Widget::SetAppModified() {
tsepez4cf55152016-11-02 14:37:54 -0700730 m_bAppModified = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731}
732
733void CPDFSDK_Widget::ClearAppModified() {
tsepez4cf55152016-11-02 14:37:54 -0700734 m_bAppModified = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700735}
736
tsepez4cf55152016-11-02 14:37:54 -0700737bool CPDFSDK_Widget::IsAppModified() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700738 return m_bAppModified;
739}
740
Tom Sepez51da0932015-11-25 16:05:49 -0800741#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700742void CPDFSDK_Widget::ResetAppearance(bool bValueChanged) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743 switch (GetFieldType()) {
744 case FIELDTYPE_TEXTFIELD:
745 case FIELDTYPE_COMBOBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700746 bool bFormatted = false;
tsepez8c2a8cd2016-09-07 15:29:11 -0700747 CFX_WideString sValue = OnFormat(bFormatted);
tsepez4cf55152016-11-02 14:37:54 -0700748 ResetAppearance(bFormatted ? &sValue : nullptr, true);
jaepark611adb82016-08-17 11:34:36 -0700749 break;
750 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700751 default:
tsepez4cf55152016-11-02 14:37:54 -0700752 ResetAppearance(nullptr, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700753 break;
754 }
755}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800756#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700757
tsepeza31da742016-09-08 11:28:14 -0700758void CPDFSDK_Widget::ResetAppearance(const CFX_WideString* sValue,
tsepez4cf55152016-11-02 14:37:54 -0700759 bool bValueChanged) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700760 SetAppModified();
761
762 m_nAppAge++;
763 if (m_nAppAge > 999999)
764 m_nAppAge = 0;
765 if (bValueChanged)
766 m_nValueAge++;
767
768 int nFieldType = GetFieldType();
769
770 switch (nFieldType) {
771 case FIELDTYPE_PUSHBUTTON:
772 ResetAppearance_PushButton();
773 break;
774 case FIELDTYPE_CHECKBOX:
775 ResetAppearance_CheckBox();
776 break;
777 case FIELDTYPE_RADIOBUTTON:
778 ResetAppearance_RadioButton();
779 break;
780 case FIELDTYPE_COMBOBOX:
781 ResetAppearance_ComboBox(sValue);
782 break;
783 case FIELDTYPE_LISTBOX:
784 ResetAppearance_ListBox();
785 break;
786 case FIELDTYPE_TEXTFIELD:
787 ResetAppearance_TextField(sValue);
788 break;
789 }
790
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700791 m_pAnnot->ClearCachedAP();
792}
793
tsepez4cf55152016-11-02 14:37:54 -0700794CFX_WideString CPDFSDK_Widget::OnFormat(bool& bFormatted) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700795 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800796 ASSERT(pFormField);
tsepez8c2a8cd2016-09-07 15:29:11 -0700797 return m_pInterForm->OnFormat(pFormField, bFormatted);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700798}
799
tsepez4cf55152016-11-02 14:37:54 -0700800void CPDFSDK_Widget::ResetFieldAppearance(bool bValueChanged) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700801 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800802 ASSERT(pFormField);
thestig1cd352e2016-06-07 17:53:06 -0700803 m_pInterForm->ResetFieldAppearance(pFormField, nullptr, bValueChanged);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700804}
805
806void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800807 const CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700808 CPDF_Annot::AppearanceMode mode,
809 const CPDF_RenderOptions* pOptions) {
810 int nFieldType = GetFieldType();
811
812 if ((nFieldType == FIELDTYPE_CHECKBOX ||
813 nFieldType == FIELDTYPE_RADIOBUTTON) &&
814 mode == CPDF_Annot::Normal &&
815 !IsWidgetAppearanceValid(CPDF_Annot::Normal)) {
816 CFX_PathData pathData;
817
Tom Sepez281a9ea2016-02-26 14:24:28 -0800818 CFX_FloatRect rcAnnot = GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700819
820 pathData.AppendRect(rcAnnot.left, rcAnnot.bottom, rcAnnot.right,
821 rcAnnot.top);
822
823 CFX_GraphStateData gsd;
824 gsd.m_LineWidth = 0.0f;
825
826 pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA,
827 FXFILL_ALTERNATE);
828 } else {
829 CPDFSDK_BAAnnot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);
830 }
831}
832
833void CPDFSDK_Widget::UpdateField() {
834 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800835 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700836 m_pInterForm->UpdateField(pFormField);
837}
838
839void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
840 CPDFSDK_PageView* pPageView) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700841 int nFieldType = GetFieldType();
jaepark611adb82016-08-17 11:34:36 -0700842 if (!m_pInterForm->IsNeedHighLight(nFieldType))
843 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700844
jaepark611adb82016-08-17 11:34:36 -0700845 CFX_Matrix page2device;
846 pPageView->GetCurrentMatrix(page2device);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700847
Dan Sinclairafb44562017-02-09 13:07:43 -0500848 CFX_FloatRect rcDevice = GetRect();
Dan Sinclaira0061af2017-02-23 09:25:17 -0500849 CFX_PointF tmp =
850 page2device.Transform(CFX_PointF(rcDevice.left, rcDevice.bottom));
851 rcDevice.left = tmp.x;
852 rcDevice.bottom = tmp.y;
853
854 tmp = page2device.Transform(CFX_PointF(rcDevice.right, rcDevice.top));
855 rcDevice.right = tmp.x;
856 rcDevice.top = tmp.y;
jaepark611adb82016-08-17 11:34:36 -0700857 rcDevice.Normalize();
858
Dan Sinclairafb44562017-02-09 13:07:43 -0500859 FX_RECT rcDev = rcDevice.ToFxRect();
860 pDevice->FillRect(
861 &rcDev, ArgbEncode(static_cast<int>(m_pInterForm->GetHighlightAlpha()),
862 m_pInterForm->GetHighlightColor(nFieldType)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700863}
864
865void CPDFSDK_Widget::ResetAppearance_PushButton() {
866 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800867 CFX_FloatRect rcWindow = GetRotatedRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700868 int32_t nLayout = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700869 switch (pControl->GetTextPosition()) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700870 case TEXTPOS_ICON:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700871 nLayout = PPBL_ICON;
872 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700873 case TEXTPOS_BELOW:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700874 nLayout = PPBL_ICONTOPLABELBOTTOM;
875 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700876 case TEXTPOS_ABOVE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700877 nLayout = PPBL_LABELTOPICONBOTTOM;
878 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700879 case TEXTPOS_RIGHT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700880 nLayout = PPBL_ICONLEFTLABELRIGHT;
881 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700882 case TEXTPOS_LEFT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700883 nLayout = PPBL_LABELLEFTICONRIGHT;
884 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700885 case TEXTPOS_OVERLAID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700886 nLayout = PPBL_LABELOVERICON;
887 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700888 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700889 nLayout = PPBL_LABEL;
890 break;
891 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700892
Dan Sinclairfc54e052017-02-23 09:59:05 -0500893 CPWL_Color crBackground;
894 CPWL_Color crBorder;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700895 int iColorType;
Dan Sinclair05df0752017-03-14 14:43:42 -0400896 float fc[4];
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
Dan Sinclair05df0752017-03-14 14:43:42 -0400905 float fBorderWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700906 CPWL_Dash dsBorder(3, 0, 0);
Dan Sinclairfc54e052017-02-23 09:59:05 -0500907 CPWL_Color crLeftTop;
908 CPWL_Color crRightBottom;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700909
dsinclair92cb5e52016-05-16 11:38:28 -0700910 BorderStyle nBorderStyle = GetBorderStyle();
911 switch (nBorderStyle) {
912 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700913 dsBorder = CPWL_Dash(3, 3, 0);
914 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700915 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700916 fBorderWidth *= 2;
917 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
Dan Sinclairfc54e052017-02-23 09:59:05 -0500918 crRightBottom = crBackground / 2.0f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700919 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700920 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700921 fBorderWidth *= 2;
922 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
923 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
924 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700925 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700926 break;
927 }
928
Tom Sepez281a9ea2016-02-26 14:24:28 -0800929 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700930
931 CPWL_Color crText(COLORTYPE_GRAY, 0);
932
Dan Sinclair05df0752017-03-14 14:43:42 -0400933 float fFontSize = 12.0f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700934 CFX_ByteString csNameTag;
935
936 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
937 if (da.HasColor()) {
938 da.GetColor(iColorType, fc);
939 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
940 }
941
942 if (da.HasFont())
943 da.GetFont(csNameTag, fFontSize);
944
945 CFX_WideString csWCaption;
946 CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption;
947
jaepark611adb82016-08-17 11:34:36 -0700948 if (pControl->HasMKEntry("CA"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700949 csNormalCaption = pControl->GetNormalCaption();
jaepark611adb82016-08-17 11:34:36 -0700950
951 if (pControl->HasMKEntry("RC"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700952 csRolloverCaption = pControl->GetRolloverCaption();
jaepark611adb82016-08-17 11:34:36 -0700953
954 if (pControl->HasMKEntry("AC"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700955 csDownCaption = pControl->GetDownCaption();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700956
thestig1cd352e2016-06-07 17:53:06 -0700957 CPDF_Stream* pNormalIcon = nullptr;
958 CPDF_Stream* pRolloverIcon = nullptr;
959 CPDF_Stream* pDownIcon = nullptr;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700960
jaepark611adb82016-08-17 11:34:36 -0700961 if (pControl->HasMKEntry("I"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700962 pNormalIcon = pControl->GetNormalIcon();
jaepark611adb82016-08-17 11:34:36 -0700963
964 if (pControl->HasMKEntry("RI"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700965 pRolloverIcon = pControl->GetRolloverIcon();
jaepark611adb82016-08-17 11:34:36 -0700966
967 if (pControl->HasMKEntry("IX"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700968 pDownIcon = pControl->GetDownIcon();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700969
970 if (pNormalIcon) {
971 if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -0700972 if (pImageDict->GetStringFor("Name").IsEmpty())
tsepez0e606b52016-11-18 16:22:41 -0800973 pImageDict->SetNewFor<CPDF_String>("Name", "ImgA", false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700974 }
975 }
976
977 if (pRolloverIcon) {
978 if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -0700979 if (pImageDict->GetStringFor("Name").IsEmpty())
tsepez0e606b52016-11-18 16:22:41 -0800980 pImageDict->SetNewFor<CPDF_String>("Name", "ImgB", false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700981 }
982 }
983
984 if (pDownIcon) {
985 if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -0700986 if (pImageDict->GetStringFor("Name").IsEmpty())
tsepez0e606b52016-11-18 16:22:41 -0800987 pImageDict->SetNewFor<CPDF_String>("Name", "ImgC", false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700988 }
989 }
990
991 CPDF_IconFit iconFit = pControl->GetIconFit();
992
dsinclair690c0332016-10-11 09:13:01 -0700993 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
Lei Zhangfcfa3b82015-12-24 21:07:28 -0800994 font_map.SetAPType("N");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700995
996 CFX_ByteString csAP =
997 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
998 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
999 crLeftTop, crRightBottom, nBorderStyle,
1000 dsBorder) +
1001 CPWL_Utils::GetPushButtonAppStream(
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001002 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001003 pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout);
1004
1005 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP);
1006 if (pNormalIcon)
1007 AddImageToAppearance("N", pNormalIcon);
1008
1009 CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode();
1010 if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) {
1011 if (csRolloverCaption.IsEmpty() && !pRolloverIcon) {
1012 csRolloverCaption = csNormalCaption;
1013 pRolloverIcon = pNormalIcon;
1014 }
1015
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001016 font_map.SetAPType("R");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001017
1018 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1019 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1020 crLeftTop, crRightBottom,
1021 nBorderStyle, dsBorder) +
1022 CPWL_Utils::GetPushButtonAppStream(
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001023 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001024 pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize,
1025 nLayout);
1026
1027 WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP);
1028 if (pRolloverIcon)
1029 AddImageToAppearance("R", pRolloverIcon);
1030
1031 if (csDownCaption.IsEmpty() && !pDownIcon) {
1032 csDownCaption = csNormalCaption;
1033 pDownIcon = pNormalIcon;
1034 }
1035
1036 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -07001037 case BorderStyle::BEVELED: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001038 CPWL_Color crTemp = crLeftTop;
1039 crLeftTop = crRightBottom;
1040 crRightBottom = crTemp;
dsinclair92cb5e52016-05-16 11:38:28 -07001041 break;
1042 }
1043 case BorderStyle::INSET: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001044 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1045 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001046 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001047 }
1048 default:
1049 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001050 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001051
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001052 font_map.SetAPType("D");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001053
Dan Sinclairfc54e052017-02-23 09:59:05 -05001054 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) +
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001055 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;
Dan Sinclair05df0752017-03-14 14:43:42 -04001075 float fc[4];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001076
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
Dan Sinclair05df0752017-03-14 14:43:42 -04001085 float fBorderWidth = (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);
Dan Sinclairfc54e052017-02-23 09:59:05 -05001097 crRightBottom = crBackground / 2.0f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001098 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 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
1111 if (da.HasColor()) {
1112 da.GetColor(iColorType, fc);
1113 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1114 }
1115
1116 int32_t nStyle = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001117 CFX_WideString csWCaption = pControl->GetNormalCaption();
1118 if (csWCaption.GetLength() > 0) {
1119 switch (csWCaption[0]) {
1120 case L'l':
1121 nStyle = PCS_CIRCLE;
1122 break;
1123 case L'8':
1124 nStyle = PCS_CROSS;
1125 break;
1126 case L'u':
1127 nStyle = PCS_DIAMOND;
1128 break;
1129 case L'n':
1130 nStyle = PCS_SQUARE;
1131 break;
1132 case L'H':
1133 nStyle = PCS_STAR;
1134 break;
1135 default: // L'4'
1136 nStyle = PCS_CHECK;
1137 break;
1138 }
1139 } else {
1140 nStyle = PCS_CHECK;
1141 }
1142
1143 CFX_ByteString csAP_N_ON =
1144 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1145 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1146 crLeftTop, crRightBottom, nBorderStyle,
1147 dsBorder);
1148
1149 CFX_ByteString csAP_N_OFF = csAP_N_ON;
1150
1151 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -07001152 case BorderStyle::BEVELED: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001153 CPWL_Color crTemp = crLeftTop;
1154 crLeftTop = crRightBottom;
1155 crRightBottom = crTemp;
dsinclair92cb5e52016-05-16 11:38:28 -07001156 break;
1157 }
1158 case BorderStyle::INSET: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001159 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1160 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1161 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001162 }
1163 default:
1164 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001165 }
1166
1167 CFX_ByteString csAP_D_ON =
Dan Sinclairfc54e052017-02-23 09:59:05 -05001168 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) +
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001169 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1170 crLeftTop, crRightBottom, nBorderStyle,
1171 dsBorder);
1172
1173 CFX_ByteString csAP_D_OFF = csAP_D_ON;
1174
1175 csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
1176 csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
1177
1178 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
1179 pControl->GetCheckedAPState());
1180 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
1181
1182 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
1183 pControl->GetCheckedAPState());
1184 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
1185
1186 CFX_ByteString csAS = GetAppState();
1187 if (csAS.IsEmpty())
1188 SetAppState("Off");
1189}
1190
1191void CPDFSDK_Widget::ResetAppearance_RadioButton() {
1192 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001193 CPWL_Color crBackground, crBorder, crText;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001194 int iColorType;
Dan Sinclair05df0752017-03-14 14:43:42 -04001195 float fc[4];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001196
1197 pControl->GetOriginalBackgroundColor(iColorType, fc);
1198 if (iColorType > 0)
1199 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1200
1201 pControl->GetOriginalBorderColor(iColorType, fc);
1202 if (iColorType > 0)
1203 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1204
Dan Sinclair05df0752017-03-14 14:43:42 -04001205 float fBorderWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001206 CPWL_Dash dsBorder(3, 0, 0);
Dan Sinclairfc54e052017-02-23 09:59:05 -05001207 CPWL_Color crLeftTop;
1208 CPWL_Color crRightBottom;
dsinclair92cb5e52016-05-16 11:38:28 -07001209 BorderStyle nBorderStyle = GetBorderStyle();
1210 switch (nBorderStyle) {
1211 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001212 dsBorder = CPWL_Dash(3, 3, 0);
1213 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001214 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001215 fBorderWidth *= 2;
1216 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
Dan Sinclairfc54e052017-02-23 09:59:05 -05001217 crRightBottom = crBackground / 2.0f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001218 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001219 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001220 fBorderWidth *= 2;
1221 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1222 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1223 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001224 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001225 break;
1226 }
1227
Tom Sepez281a9ea2016-02-26 14:24:28 -08001228 CFX_FloatRect rcWindow = GetRotatedRect();
1229 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001230
1231 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
1232 if (da.HasColor()) {
1233 da.GetColor(iColorType, fc);
1234 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1235 }
1236
1237 int32_t nStyle = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001238 CFX_WideString csWCaption = pControl->GetNormalCaption();
1239 if (csWCaption.GetLength() > 0) {
1240 switch (csWCaption[0]) {
1241 default: // L'l':
1242 nStyle = PCS_CIRCLE;
1243 break;
1244 case L'8':
1245 nStyle = PCS_CROSS;
1246 break;
1247 case L'u':
1248 nStyle = PCS_DIAMOND;
1249 break;
1250 case L'n':
1251 nStyle = PCS_SQUARE;
1252 break;
1253 case L'H':
1254 nStyle = PCS_STAR;
1255 break;
1256 case L'4':
1257 nStyle = PCS_CHECK;
1258 break;
1259 }
1260 } else {
1261 nStyle = PCS_CIRCLE;
1262 }
1263
1264 CFX_ByteString csAP_N_ON;
1265
Tom Sepez281a9ea2016-02-26 14:24:28 -08001266 CFX_FloatRect rcCenter =
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001267 CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f);
1268
1269 if (nStyle == PCS_CIRCLE) {
dsinclair92cb5e52016-05-16 11:38:28 -07001270 if (nBorderStyle == BorderStyle::BEVELED) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001271 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
Dan Sinclairfc54e052017-02-23 09:59:05 -05001272 crRightBottom = crBackground - 0.25f;
dsinclair92cb5e52016-05-16 11:38:28 -07001273 } else if (nBorderStyle == BorderStyle::INSET) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001274 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5f);
1275 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75f);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001276 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001277
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001278 csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBackground) +
1279 CPWL_Utils::GetCircleBorderAppStream(
1280 rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
1281 nBorderStyle, dsBorder);
1282 } else {
1283 csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1284 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1285 crLeftTop, crRightBottom,
1286 nBorderStyle, dsBorder);
1287 }
1288
1289 CFX_ByteString csAP_N_OFF = csAP_N_ON;
1290
1291 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -07001292 case BorderStyle::BEVELED: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001293 CPWL_Color crTemp = crLeftTop;
1294 crLeftTop = crRightBottom;
1295 crRightBottom = crTemp;
dsinclair92cb5e52016-05-16 11:38:28 -07001296 break;
1297 }
1298 case BorderStyle::INSET: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001299 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1300 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1301 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001302 }
1303 default:
1304 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001305 }
1306
1307 CFX_ByteString csAP_D_ON;
1308
1309 if (nStyle == PCS_CIRCLE) {
Dan Sinclairfc54e052017-02-23 09:59:05 -05001310 CPWL_Color crBK = crBackground - 0.25f;
dsinclair92cb5e52016-05-16 11:38:28 -07001311 if (nBorderStyle == BorderStyle::BEVELED) {
Dan Sinclairfc54e052017-02-23 09:59:05 -05001312 crLeftTop = crBackground - 0.25f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001313 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1314 crBK = crBackground;
dsinclair92cb5e52016-05-16 11:38:28 -07001315 } else if (nBorderStyle == BorderStyle::INSET) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001316 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1317 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1318 }
1319
1320 csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBK) +
1321 CPWL_Utils::GetCircleBorderAppStream(
1322 rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
1323 nBorderStyle, dsBorder);
1324 } else {
Dan Sinclairfc54e052017-02-23 09:59:05 -05001325 csAP_D_ON =
1326 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) +
1327 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1328 crLeftTop, crRightBottom, nBorderStyle,
1329 dsBorder);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001330 }
1331
1332 CFX_ByteString csAP_D_OFF = csAP_D_ON;
1333
1334 csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
1335 csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
1336
1337 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
1338 pControl->GetCheckedAPState());
1339 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
1340
1341 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
1342 pControl->GetCheckedAPState());
1343 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
1344
1345 CFX_ByteString csAS = GetAppState();
1346 if (csAS.IsEmpty())
1347 SetAppState("Off");
1348}
1349
tsepeza31da742016-09-08 11:28:14 -07001350void CPDFSDK_Widget::ResetAppearance_ComboBox(const CFX_WideString* sValue) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001351 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001352 CPDF_FormField* pField = pControl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001353 CFX_ByteTextBuf sBody, sLines;
1354
Tom Sepez281a9ea2016-02-26 14:24:28 -08001355 CFX_FloatRect rcClient = GetClientRect();
1356 CFX_FloatRect rcButton = rcClient;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001357 rcButton.left = rcButton.right - 13;
1358 rcButton.Normalize();
1359
Dan Sinclair0bb13332017-03-30 16:12:02 -04001360 auto pEdit = pdfium::MakeUnique<CFX_Edit>();
tsepez4cf55152016-11-02 14:37:54 -07001361 pEdit->EnableRefresh(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001362
dsinclair690c0332016-10-11 09:13:01 -07001363 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
thestig732f6a02016-05-12 10:41:56 -07001364 pEdit->SetFontMap(&font_map);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001365
thestig732f6a02016-05-12 10:41:56 -07001366 CFX_FloatRect rcEdit = rcClient;
1367 rcEdit.right = rcButton.left;
1368 rcEdit.Normalize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001369
thestig732f6a02016-05-12 10:41:56 -07001370 pEdit->SetPlateRect(rcEdit);
tsepez4cf55152016-11-02 14:37:54 -07001371 pEdit->SetAlignmentV(1, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001372
Dan Sinclair05df0752017-03-14 14:43:42 -04001373 float fFontSize = GetFontSize();
thestig732f6a02016-05-12 10:41:56 -07001374 if (IsFloatZero(fFontSize))
tsepez4cf55152016-11-02 14:37:54 -07001375 pEdit->SetAutoFontSize(true, true);
thestig732f6a02016-05-12 10:41:56 -07001376 else
1377 pEdit->SetFontSize(fFontSize);
1378
1379 pEdit->Initialize();
1380
1381 if (sValue) {
tsepeza31da742016-09-08 11:28:14 -07001382 pEdit->SetText(*sValue);
thestig732f6a02016-05-12 10:41:56 -07001383 } else {
1384 int32_t nCurSel = pField->GetSelectedIndex(0);
thestig732f6a02016-05-12 10:41:56 -07001385 if (nCurSel < 0)
tsepez067990c2016-09-13 06:46:40 -07001386 pEdit->SetText(pField->GetValue());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001387 else
tsepez067990c2016-09-13 06:46:40 -07001388 pEdit->SetText(pField->GetOptionLabel(nCurSel));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001389 }
1390
thestig732f6a02016-05-12 10:41:56 -07001391 CFX_FloatRect rcContent = pEdit->GetContentRect();
1392
1393 CFX_ByteString sEdit =
Dan Sinclairf528eee2017-02-14 11:52:07 -05001394 CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF());
thestig732f6a02016-05-12 10:41:56 -07001395 if (sEdit.GetLength() > 0) {
1396 sBody << "/Tx BMC\n"
1397 << "q\n";
1398 if (rcContent.Width() > rcEdit.Width() ||
1399 rcContent.Height() > rcEdit.Height()) {
1400 sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width()
1401 << " " << rcEdit.Height() << " re\nW\nn\n";
1402 }
1403
1404 CPWL_Color crText = GetTextPWLColor();
1405 sBody << "BT\n"
1406 << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"
1407 << "Q\nEMC\n";
1408 }
1409
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001410 sBody << CPWL_Utils::GetDropButtonAppStream(rcButton);
1411
1412 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
tsepez8e4c5052016-04-14 13:42:44 -07001413 sLines.AsStringC() + sBody.AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001414
1415 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1416}
1417
1418void CPDFSDK_Widget::ResetAppearance_ListBox() {
1419 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001420 CPDF_FormField* pField = pControl->GetField();
Tom Sepez281a9ea2016-02-26 14:24:28 -08001421 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001422 CFX_ByteTextBuf sBody, sLines;
1423
Dan Sinclair0bb13332017-03-30 16:12:02 -04001424 auto pEdit = pdfium::MakeUnique<CFX_Edit>();
tsepez4cf55152016-11-02 14:37:54 -07001425 pEdit->EnableRefresh(false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001426
dsinclair690c0332016-10-11 09:13:01 -07001427 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
thestig732f6a02016-05-12 10:41:56 -07001428 pEdit->SetFontMap(&font_map);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001429
thestig732f6a02016-05-12 10:41:56 -07001430 pEdit->SetPlateRect(CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001431
Dan Sinclair05df0752017-03-14 14:43:42 -04001432 float fFontSize = GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001433
thestig594b20b2016-05-12 21:56:43 -07001434 pEdit->SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001435
thestig732f6a02016-05-12 10:41:56 -07001436 pEdit->Initialize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001437
thestig732f6a02016-05-12 10:41:56 -07001438 CFX_ByteTextBuf sList;
Dan Sinclair05df0752017-03-14 14:43:42 -04001439 float fy = rcClient.top;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001440
thestig732f6a02016-05-12 10:41:56 -07001441 int32_t nTop = pField->GetTopVisibleIndex();
1442 int32_t nCount = pField->CountOptions();
1443 int32_t nSelCount = pField->CountSelectedItems();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001444
thestig594b20b2016-05-12 21:56:43 -07001445 for (int32_t i = nTop; i < nCount; ++i) {
1446 bool bSelected = false;
1447 for (int32_t j = 0; j < nSelCount; ++j) {
thestig732f6a02016-05-12 10:41:56 -07001448 if (pField->GetSelectedIndex(j) == i) {
thestig594b20b2016-05-12 21:56:43 -07001449 bSelected = true;
thestig732f6a02016-05-12 10:41:56 -07001450 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001451 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001452 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001453
tsepez067990c2016-09-13 06:46:40 -07001454 pEdit->SetText(pField->GetOptionLabel(i));
thestig732f6a02016-05-12 10:41:56 -07001455
1456 CFX_FloatRect rcContent = pEdit->GetContentRect();
Dan Sinclair05df0752017-03-14 14:43:42 -04001457 float fItemHeight = rcContent.Height();
thestig732f6a02016-05-12 10:41:56 -07001458
1459 if (bSelected) {
1460 CFX_FloatRect rcItem =
1461 CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy);
1462 sList << "q\n"
1463 << CPWL_Utils::GetColorAppStream(
1464 CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f,
1465 113.0f / 255.0f),
tsepez4cf55152016-11-02 14:37:54 -07001466 true)
thestig732f6a02016-05-12 10:41:56 -07001467 << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width()
1468 << " " << rcItem.Height() << " re f\n"
1469 << "Q\n";
1470
1471 sList << "BT\n"
1472 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1),
tsepez4cf55152016-11-02 14:37:54 -07001473 true)
Dan Sinclairf528eee2017-02-14 11:52:07 -05001474 << CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, fy))
thestig732f6a02016-05-12 10:41:56 -07001475 << "ET\n";
1476 } else {
1477 CPWL_Color crText = GetTextPWLColor();
1478 sList << "BT\n"
tsepez4cf55152016-11-02 14:37:54 -07001479 << CPWL_Utils::GetColorAppStream(crText, true)
Dan Sinclairf528eee2017-02-14 11:52:07 -05001480 << CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, fy))
thestig732f6a02016-05-12 10:41:56 -07001481 << "ET\n";
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001482 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001483
thestig732f6a02016-05-12 10:41:56 -07001484 fy -= fItemHeight;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001485 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001486
thestig732f6a02016-05-12 10:41:56 -07001487 if (sList.GetSize() > 0) {
1488 sBody << "/Tx BMC\n"
1489 << "q\n"
1490 << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width()
1491 << " " << rcClient.Height() << " re\nW\nn\n";
1492 sBody << sList << "Q\nEMC\n";
1493 }
1494
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001495 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
tsepez8e4c5052016-04-14 13:42:44 -07001496 sLines.AsStringC() + sBody.AsStringC();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001497
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001498 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001499}
1500
tsepeza31da742016-09-08 11:28:14 -07001501void CPDFSDK_Widget::ResetAppearance_TextField(const CFX_WideString* sValue) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001502 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001503 CPDF_FormField* pField = pControl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001504 CFX_ByteTextBuf sBody, sLines;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001505
Dan Sinclair0bb13332017-03-30 16:12:02 -04001506 auto pEdit = pdfium::MakeUnique<CFX_Edit>();
tsepez4cf55152016-11-02 14:37:54 -07001507 pEdit->EnableRefresh(false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001508
dsinclair690c0332016-10-11 09:13:01 -07001509 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
thestig732f6a02016-05-12 10:41:56 -07001510 pEdit->SetFontMap(&font_map);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001511
thestig732f6a02016-05-12 10:41:56 -07001512 CFX_FloatRect rcClient = GetClientRect();
1513 pEdit->SetPlateRect(rcClient);
tsepez4cf55152016-11-02 14:37:54 -07001514 pEdit->SetAlignmentH(pControl->GetControlAlignment(), true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001515
thestig732f6a02016-05-12 10:41:56 -07001516 uint32_t dwFieldFlags = pField->GetFieldFlags();
tsepez4cf55152016-11-02 14:37:54 -07001517 bool bMultiLine = (dwFieldFlags >> 12) & 1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001518
thestig732f6a02016-05-12 10:41:56 -07001519 if (bMultiLine) {
tsepez4cf55152016-11-02 14:37:54 -07001520 pEdit->SetMultiLine(true, true);
1521 pEdit->SetAutoReturn(true, true);
thestig732f6a02016-05-12 10:41:56 -07001522 } else {
tsepez4cf55152016-11-02 14:37:54 -07001523 pEdit->SetAlignmentV(1, true);
thestig732f6a02016-05-12 10:41:56 -07001524 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001525
thestig732f6a02016-05-12 10:41:56 -07001526 uint16_t subWord = 0;
1527 if ((dwFieldFlags >> 13) & 1) {
1528 subWord = '*';
tsepez4cf55152016-11-02 14:37:54 -07001529 pEdit->SetPasswordChar(subWord, 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 int nMaxLen = pField->GetMaxLen();
tsepez4cf55152016-11-02 14:37:54 -07001533 bool bCharArray = (dwFieldFlags >> 24) & 1;
Dan Sinclair05df0752017-03-14 14:43:42 -04001534 float fFontSize = GetFontSize();
Bo Xufdc00a72014-10-28 23:03:33 -07001535
Tom Sepez51da0932015-11-25 16:05:49 -08001536#ifdef PDF_ENABLE_XFA
thestig732f6a02016-05-12 10:41:56 -07001537 CFX_WideString sValueTmp;
1538 if (!sValue && GetMixXFAWidget()) {
tsepez4cf55152016-11-02 14:37:54 -07001539 sValueTmp = GetValue(true);
tsepeza31da742016-09-08 11:28:14 -07001540 sValue = &sValueTmp;
thestig732f6a02016-05-12 10:41:56 -07001541 }
Tom Sepez40e9ff32015-11-30 12:39:54 -08001542#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001543
thestig732f6a02016-05-12 10:41:56 -07001544 if (nMaxLen > 0) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001545 if (bCharArray) {
thestig732f6a02016-05-12 10:41:56 -07001546 pEdit->SetCharArray(nMaxLen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001547
thestig732f6a02016-05-12 10:41:56 -07001548 if (IsFloatZero(fFontSize)) {
1549 fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0),
1550 rcClient, nMaxLen);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001551 }
thestig732f6a02016-05-12 10:41:56 -07001552 } else {
1553 if (sValue)
tsepeza31da742016-09-08 11:28:14 -07001554 nMaxLen = sValue->GetLength();
thestig732f6a02016-05-12 10:41:56 -07001555 pEdit->SetLimitChar(nMaxLen);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001556 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001557 }
1558
thestig732f6a02016-05-12 10:41:56 -07001559 if (IsFloatZero(fFontSize))
tsepez4cf55152016-11-02 14:37:54 -07001560 pEdit->SetAutoFontSize(true, true);
thestig732f6a02016-05-12 10:41:56 -07001561 else
1562 pEdit->SetFontSize(fFontSize);
1563
1564 pEdit->Initialize();
tsepez067990c2016-09-13 06:46:40 -07001565 pEdit->SetText(sValue ? *sValue : pField->GetValue());
thestig732f6a02016-05-12 10:41:56 -07001566
1567 CFX_FloatRect rcContent = pEdit->GetContentRect();
thestig732f6a02016-05-12 10:41:56 -07001568 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -05001569 pEdit.get(), CFX_PointF(), nullptr, !bCharArray, subWord);
thestig732f6a02016-05-12 10:41:56 -07001570
1571 if (sEdit.GetLength() > 0) {
1572 sBody << "/Tx BMC\n"
1573 << "q\n";
1574 if (rcContent.Width() > rcClient.Width() ||
1575 rcContent.Height() > rcClient.Height()) {
1576 sBody << rcClient.left << " " << rcClient.bottom << " "
1577 << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
1578 }
1579 CPWL_Color crText = GetTextPWLColor();
1580 sBody << "BT\n"
1581 << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"
1582 << "Q\nEMC\n";
1583 }
1584
1585 if (bCharArray) {
1586 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -07001587 case BorderStyle::SOLID: {
thestig732f6a02016-05-12 10:41:56 -07001588 CFX_ByteString sColor =
tsepez4cf55152016-11-02 14:37:54 -07001589 CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false);
thestig732f6a02016-05-12 10:41:56 -07001590 if (sColor.GetLength() > 0) {
1591 sLines << "q\n"
1592 << GetBorderWidth() << " w\n"
tsepez4cf55152016-11-02 14:37:54 -07001593 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false)
thestig732f6a02016-05-12 10:41:56 -07001594 << " 2 J 0 j\n";
1595
thestig594b20b2016-05-12 21:56:43 -07001596 for (int32_t i = 1; i < nMaxLen; ++i) {
thestig732f6a02016-05-12 10:41:56 -07001597 sLines << rcClient.left +
1598 ((rcClient.right - rcClient.left) / nMaxLen) * i
1599 << " " << rcClient.bottom << " m\n"
1600 << rcClient.left +
1601 ((rcClient.right - rcClient.left) / nMaxLen) * i
1602 << " " << rcClient.top << " l S\n";
1603 }
1604
1605 sLines << "Q\n";
1606 }
dsinclair92cb5e52016-05-16 11:38:28 -07001607 break;
1608 }
1609 case BorderStyle::DASH: {
thestig732f6a02016-05-12 10:41:56 -07001610 CFX_ByteString sColor =
tsepez4cf55152016-11-02 14:37:54 -07001611 CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false);
thestig732f6a02016-05-12 10:41:56 -07001612 if (sColor.GetLength() > 0) {
1613 CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0);
1614
1615 sLines << "q\n"
1616 << GetBorderWidth() << " w\n"
tsepez4cf55152016-11-02 14:37:54 -07001617 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false)
thestig732f6a02016-05-12 10:41:56 -07001618 << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] "
1619 << dsBorder.nPhase << " d\n";
1620
thestig594b20b2016-05-12 21:56:43 -07001621 for (int32_t i = 1; i < nMaxLen; ++i) {
thestig732f6a02016-05-12 10:41:56 -07001622 sLines << rcClient.left +
1623 ((rcClient.right - rcClient.left) / nMaxLen) * i
1624 << " " << rcClient.bottom << " m\n"
1625 << rcClient.left +
1626 ((rcClient.right - rcClient.left) / nMaxLen) * i
1627 << " " << rcClient.top << " l S\n";
1628 }
1629
1630 sLines << "Q\n";
1631 }
dsinclair92cb5e52016-05-16 11:38:28 -07001632 break;
1633 }
1634 default:
1635 break;
thestig732f6a02016-05-12 10:41:56 -07001636 }
1637 }
1638
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001639 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
tsepez8e4c5052016-04-14 13:42:44 -07001640 sLines.AsStringC() + sBody.AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001641 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001642}
1643
Tom Sepez281a9ea2016-02-26 14:24:28 -08001644CFX_FloatRect CPDFSDK_Widget::GetClientRect() const {
1645 CFX_FloatRect rcWindow = GetRotatedRect();
Dan Sinclair05df0752017-03-14 14:43:42 -04001646 float fBorderWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001647 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -07001648 case BorderStyle::BEVELED:
1649 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001650 fBorderWidth *= 2.0f;
1651 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001652 default:
1653 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001654 }
1655
1656 return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001657}
1658
Tom Sepez281a9ea2016-02-26 14:24:28 -08001659CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const {
1660 CFX_FloatRect rectAnnot = GetRect();
Dan Sinclair05df0752017-03-14 14:43:42 -04001661 float fWidth = rectAnnot.right - rectAnnot.left;
1662 float fHeight = rectAnnot.top - rectAnnot.bottom;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001663
1664 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -08001665 CFX_FloatRect rcPDFWindow;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001666 switch (abs(pControl->GetRotation() % 360)) {
1667 case 0:
1668 case 180:
1669 default:
Tom Sepez281a9ea2016-02-26 14:24:28 -08001670 rcPDFWindow = CFX_FloatRect(0, 0, fWidth, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001671 break;
1672 case 90:
1673 case 270:
Tom Sepez281a9ea2016-02-26 14:24:28 -08001674 rcPDFWindow = CFX_FloatRect(0, 0, fHeight, fWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001675 break;
1676 }
1677
1678 return rcPDFWindow;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001679}
1680
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001681CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const {
1682 CPWL_Color crBackground = GetFillPWLColor();
jaepark611adb82016-08-17 11:34:36 -07001683 if (crBackground.nColorType != COLORTYPE_TRANSPARENT)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001684 return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);
jaepark611adb82016-08-17 11:34:36 -07001685
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001686 return "";
Bo Xufdc00a72014-10-28 23:03:33 -07001687}
1688
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001689CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001690 CFX_FloatRect rcWindow = GetRotatedRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001691 CPWL_Color crBorder = GetBorderPWLColor();
1692 CPWL_Color crBackground = GetFillPWLColor();
1693 CPWL_Color crLeftTop, crRightBottom;
1694
Dan Sinclair05df0752017-03-14 14:43:42 -04001695 float fBorderWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001696 CPWL_Dash dsBorder(3, 0, 0);
1697
dsinclair92cb5e52016-05-16 11:38:28 -07001698 BorderStyle nBorderStyle = GetBorderStyle();
1699 switch (nBorderStyle) {
1700 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001701 dsBorder = CPWL_Dash(3, 3, 0);
1702 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001703 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001704 fBorderWidth *= 2;
1705 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
Dan Sinclairfc54e052017-02-23 09:59:05 -05001706 crRightBottom = crBackground / 2.0f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001707 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001708 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001709 fBorderWidth *= 2;
1710 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1711 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1712 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001713 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001714 break;
1715 }
1716
1717 return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1718 crLeftTop, crRightBottom, nBorderStyle,
1719 dsBorder);
Bo Xufdc00a72014-10-28 23:03:33 -07001720}
1721
Tom Sepez60d909e2015-12-10 15:34:55 -08001722CFX_Matrix CPDFSDK_Widget::GetMatrix() const {
1723 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001724 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -08001725 CFX_FloatRect rcAnnot = GetRect();
Dan Sinclair05df0752017-03-14 14:43:42 -04001726 float fWidth = rcAnnot.right - rcAnnot.left;
1727 float fHeight = rcAnnot.top - rcAnnot.bottom;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001728
1729 switch (abs(pControl->GetRotation() % 360)) {
1730 case 0:
1731 default:
Tom Sepez60d909e2015-12-10 15:34:55 -08001732 mt = CFX_Matrix(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001733 break;
1734 case 90:
Tom Sepez60d909e2015-12-10 15:34:55 -08001735 mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001736 break;
1737 case 180:
Tom Sepez60d909e2015-12-10 15:34:55 -08001738 mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001739 break;
1740 case 270:
Tom Sepez60d909e2015-12-10 15:34:55 -08001741 mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001742 break;
1743 }
1744
1745 return mt;
Bo Xufdc00a72014-10-28 23:03:33 -07001746}
1747
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001748CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const {
1749 CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0);
1750
1751 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001752 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
1753 if (da.HasColor()) {
1754 int32_t iColorType;
Dan Sinclair05df0752017-03-14 14:43:42 -04001755 float fc[4];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001756 da.GetColor(iColorType, fc);
1757 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1758 }
1759
1760 return crText;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001761}
1762
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001763CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const {
1764 CPWL_Color crBorder;
1765
1766 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001767 int32_t iColorType;
Dan Sinclair05df0752017-03-14 14:43:42 -04001768 float fc[4];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001769 pFormCtrl->GetOriginalBorderColor(iColorType, fc);
1770 if (iColorType > 0)
1771 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1772
1773 return crBorder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001774}
1775
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001776CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const {
1777 CPWL_Color crFill;
1778
1779 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001780 int32_t iColorType;
Dan Sinclair05df0752017-03-14 14:43:42 -04001781 float fc[4];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001782 pFormCtrl->GetOriginalBackgroundColor(iColorType, fc);
1783 if (iColorType > 0)
1784 crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1785
1786 return crFill;
Bo Xufdc00a72014-10-28 23:03:33 -07001787}
1788
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001789void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType,
1790 CPDF_Stream* pImage) {
dsinclair38fd8442016-09-15 10:15:32 -07001791 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
1792 CPDF_Stream* pStream = pAPDict->GetStreamFor(sAPType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001793 CPDF_Dictionary* pStreamDict = pStream->GetDict();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001794 CFX_ByteString sImageAlias = "IMG";
1795
1796 if (CPDF_Dictionary* pImageDict = pImage->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -07001797 sImageAlias = pImageDict->GetStringFor("Name");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001798 if (sImageAlias.IsEmpty())
1799 sImageAlias = "IMG";
1800 }
1801
tsepez698c5712016-09-28 16:47:07 -07001802 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
dsinclair38fd8442016-09-15 10:15:32 -07001803 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
tsepez0e606b52016-11-18 16:22:41 -08001804 if (!pStreamResList)
1805 pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001806
tsepez0e606b52016-11-18 16:22:41 -08001807 CPDF_Dictionary* pXObject =
1808 pStreamResList->SetNewFor<CPDF_Dictionary>("XObject");
1809 pXObject->SetNewFor<CPDF_Reference>(sImageAlias, pDoc, pImage->GetObjNum());
Bo Xufdc00a72014-10-28 23:03:33 -07001810}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001811
1812void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) {
dsinclair38fd8442016-09-15 10:15:32 -07001813 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"))
1814 pAPDict->RemoveFor(sAPType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001815}
1816
tsepez4cf55152016-11-02 14:37:54 -07001817bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
1818 PDFSDK_FieldAction& data,
1819 CPDFSDK_PageView* pPageView) {
dsinclairb402b172016-10-11 09:26:32 -07001820 CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001821
Tom Sepez40e9ff32015-11-30 12:39:54 -08001822#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -07001823 CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext();
dsinclairdf4bc592016-03-31 20:34:43 -07001824 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001825 XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit);
1826
1827 if (eEventType != XFA_EVENT_Unknown) {
dsinclairdf4bc592016-03-31 20:34:43 -07001828 if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001829 CXFA_EventParam param;
1830 param.m_eType = eEventType;
1831 param.m_wsChange = data.sChange;
1832 param.m_iCommitKey = data.nCommitKey;
1833 param.m_bShift = data.bShift;
1834 param.m_iSelStart = data.nSelStart;
1835 param.m_iSelEnd = data.nSelEnd;
1836 param.m_wsFullText = data.sValue;
1837 param.m_bKeyDown = data.bKeyDown;
1838 param.m_bModifier = data.bModifier;
1839 param.m_wsNewText = data.sValue;
1840 if (data.nSelEnd > data.nSelStart)
1841 param.m_wsNewText.Delete(data.nSelStart,
1842 data.nSelEnd - data.nSelStart);
1843 for (int i = data.sChange.GetLength() - 1; i >= 0; i--)
1844 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
1845 param.m_wsPrevText = data.sValue;
1846
dsinclair221caf62016-04-04 12:08:40 -07001847 CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001848 param.m_pTarget = pAcc;
1849 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
1850
dsinclair521b7502016-11-02 13:02:28 -07001851 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001852 pDocView->UpdateDocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001853
Wei Lie98ac2e2016-03-18 15:43:04 -07001854 if (nRet == XFA_EVENTERROR_Success)
tsepez4cf55152016-11-02 14:37:54 -07001855 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001856 }
1857 }
1858 }
Tom Sepez40e9ff32015-11-30 12:39:54 -08001859#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001860
1861 CPDF_Action action = GetAAction(type);
Wei Li0fc6b252016-03-01 16:29:41 -08001862 if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) {
dsinclairb402b172016-10-11 09:26:32 -07001863 CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander();
dsinclair19c198b2016-10-11 12:51:37 -07001864 return pActionHandler->DoAction_Field(action, type, pFormFillEnv,
1865 GetFormField(), data);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001866 }
tsepez4cf55152016-11-02 14:37:54 -07001867 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001868}
1869
1870CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) {
1871 switch (eAAT) {
1872 case CPDF_AAction::CursorEnter:
1873 case CPDF_AAction::CursorExit:
1874 case CPDF_AAction::ButtonDown:
1875 case CPDF_AAction::ButtonUp:
1876 case CPDF_AAction::GetFocus:
1877 case CPDF_AAction::LoseFocus:
1878 case CPDF_AAction::PageOpen:
1879 case CPDF_AAction::PageClose:
1880 case CPDF_AAction::PageVisible:
1881 case CPDF_AAction::PageInvisible:
1882 return CPDFSDK_BAAnnot::GetAAction(eAAT);
1883
1884 case CPDF_AAction::KeyStroke:
1885 case CPDF_AAction::Format:
1886 case CPDF_AAction::Validate:
1887 case CPDF_AAction::Calculate: {
1888 CPDF_FormField* pField = GetFormField();
Wei Li0fc6b252016-03-01 16:29:41 -08001889 if (pField->GetAdditionalAction().GetDict())
1890 return pField->GetAdditionalAction().GetAction(eAAT);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001891 return CPDFSDK_BAAnnot::GetAAction(eAAT);
1892 }
1893 default:
1894 break;
1895 }
1896
1897 return CPDF_Action();
1898}
1899
1900CFX_WideString CPDFSDK_Widget::GetAlternateName() const {
1901 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001902 return pFormField->GetAlternateName();
1903}
1904
1905int32_t CPDFSDK_Widget::GetAppearanceAge() const {
1906 return m_nAppAge;
1907}
1908
1909int32_t CPDFSDK_Widget::GetValueAge() const {
1910 return m_nValueAge;
1911}