blob: a1cd8c7ce429c270fbaba64dea16de84ddd2477d [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
Tom Sepez3c3e2712017-04-17 15:38:19 -0700252 for (const auto& c : data.sChange)
253 param.m_wsNewText.Insert(data.nSelStart, c);
jaepark611adb82016-08-17 11:34:36 -0700254
Tom Sepez3c3e2712017-04-17 15:38:19 -0700255 param.m_wsPrevText = data.sValue;
jaepark611adb82016-08-17 11:34:36 -0700256 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();
Tom Sepezc4a2b752017-04-07 13:56:13 -0700591 float fFontSize;
592 pDa.GetFont(&fFontSize);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700593 return fFontSize;
594}
595
Tom Sepezbf59a072015-10-21 14:07:23 -0700596int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700597#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700598 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700599 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
600 if (nIndex < pWidgetAcc->CountSelectedItems())
601 return pWidgetAcc->GetSelectedItem(nIndex);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700602 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700603 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700604#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700605 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700606 return pFormField->GetSelectedIndex(nIndex);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700607}
608
Tom Sepeza8a39e22015-10-12 15:47:07 -0700609#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700610CFX_WideString CPDFSDK_Widget::GetValue(bool bDisplay) const {
dsinclairdf4bc592016-03-31 20:34:43 -0700611 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700612 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
613 CFX_WideString sValue;
614 pWidgetAcc->GetValue(
615 sValue, bDisplay ? XFA_VALUEPICTURE_Display : XFA_VALUEPICTURE_Edit);
616 return sValue;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700617 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800619#else
620CFX_WideString CPDFSDK_Widget::GetValue() const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700621#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700623 return pFormField->GetValue();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700624}
625
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700626CFX_WideString CPDFSDK_Widget::GetDefaultValue() const {
627 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700628 return pFormField->GetDefaultValue();
629}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700630
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700631CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const {
632 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633 return pFormField->GetOptionLabel(nIndex);
634}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700635
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700636int CPDFSDK_Widget::CountOptions() const {
637 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700638 return pFormField->CountOptions();
639}
640
tsepez4cf55152016-11-02 14:37:54 -0700641bool CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700642#ifdef PDF_ENABLE_XFA
dsinclairdf4bc592016-03-31 20:34:43 -0700643 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
dsinclair221caf62016-04-04 12:08:40 -0700644 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) {
Tom Sepez5c500ac2017-03-27 12:44:20 -0700645 if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems(false))
dsinclair221caf62016-04-04 12:08:40 -0700646 return pWidgetAcc->GetItemState(nIndex);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700647
tsepez4cf55152016-11-02 14:37:54 -0700648 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649 }
650 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700651#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700652 CPDF_FormField* pFormField = GetFormField();
653 return pFormField->IsItemSelected(nIndex);
654}
655
656int CPDFSDK_Widget::GetTopVisibleIndex() const {
657 CPDF_FormField* pFormField = GetFormField();
658 return pFormField->GetTopVisibleIndex();
659}
660
Wei Li97da9762016-03-11 17:00:48 -0800661bool CPDFSDK_Widget::IsChecked() const {
Tom Sepeza8a39e22015-10-12 15:47:07 -0700662#ifdef PDF_ENABLE_XFA
dsinclair221caf62016-04-04 12:08:40 -0700663 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
664 if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc())
665 return pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700666 }
Tom Sepeza8a39e22015-10-12 15:47:07 -0700667#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700668 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669 return pFormCtrl->IsChecked();
670}
671
672int CPDFSDK_Widget::GetAlignment() const {
673 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700674 return pFormCtrl->GetControlAlignment();
675}
676
677int CPDFSDK_Widget::GetMaxLen() const {
678 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700679 return pFormField->GetMaxLen();
680}
681
Wei Li97da9762016-03-11 17:00:48 -0800682void CPDFSDK_Widget::SetCheck(bool bChecked, bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700683 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684 CPDF_FormField* pFormField = pFormCtrl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685 pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
686 bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800687#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700688 if (!IsWidgetAppearanceValid(CPDF_Annot::Normal))
tsepez4cf55152016-11-02 14:37:54 -0700689 ResetAppearance(true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700691 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800692#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700693}
694
tsepez4cf55152016-11-02 14:37:54 -0700695void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697 pFormField->SetValue(sValue, bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800698#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700699 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700700 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800701#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700702}
703
704void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {}
705void CPDFSDK_Widget::SetOptionSelection(int index,
tsepez4cf55152016-11-02 14:37:54 -0700706 bool bSelected,
707 bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700708 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709 pFormField->SetItemSelection(index, bSelected, bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800710#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700712 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800713#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700714}
715
tsepez4cf55152016-11-02 14:37:54 -0700716void CPDFSDK_Widget::ClearSelection(bool bNotify) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 pFormField->ClearSelection(bNotify);
Tom Sepez51da0932015-11-25 16:05:49 -0800719#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700720 if (!bNotify)
tsepez4cf55152016-11-02 14:37:54 -0700721 Synchronize(true);
Tom Sepez40e9ff32015-11-30 12:39:54 -0800722#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700723}
724
725void CPDFSDK_Widget::SetTopVisibleIndex(int index) {}
726
727void CPDFSDK_Widget::SetAppModified() {
tsepez4cf55152016-11-02 14:37:54 -0700728 m_bAppModified = true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729}
730
731void CPDFSDK_Widget::ClearAppModified() {
tsepez4cf55152016-11-02 14:37:54 -0700732 m_bAppModified = false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700733}
734
tsepez4cf55152016-11-02 14:37:54 -0700735bool CPDFSDK_Widget::IsAppModified() const {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736 return m_bAppModified;
737}
738
Tom Sepez51da0932015-11-25 16:05:49 -0800739#ifdef PDF_ENABLE_XFA
tsepez4cf55152016-11-02 14:37:54 -0700740void CPDFSDK_Widget::ResetAppearance(bool bValueChanged) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700741 switch (GetFieldType()) {
742 case FIELDTYPE_TEXTFIELD:
743 case FIELDTYPE_COMBOBOX: {
tsepez4cf55152016-11-02 14:37:54 -0700744 bool bFormatted = false;
tsepez8c2a8cd2016-09-07 15:29:11 -0700745 CFX_WideString sValue = OnFormat(bFormatted);
tsepez4cf55152016-11-02 14:37:54 -0700746 ResetAppearance(bFormatted ? &sValue : nullptr, true);
jaepark611adb82016-08-17 11:34:36 -0700747 break;
748 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700749 default:
tsepez4cf55152016-11-02 14:37:54 -0700750 ResetAppearance(nullptr, false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700751 break;
752 }
753}
Tom Sepez40e9ff32015-11-30 12:39:54 -0800754#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700755
tsepeza31da742016-09-08 11:28:14 -0700756void CPDFSDK_Widget::ResetAppearance(const CFX_WideString* sValue,
tsepez4cf55152016-11-02 14:37:54 -0700757 bool bValueChanged) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758 SetAppModified();
759
760 m_nAppAge++;
761 if (m_nAppAge > 999999)
762 m_nAppAge = 0;
763 if (bValueChanged)
764 m_nValueAge++;
765
766 int nFieldType = GetFieldType();
767
768 switch (nFieldType) {
769 case FIELDTYPE_PUSHBUTTON:
770 ResetAppearance_PushButton();
771 break;
772 case FIELDTYPE_CHECKBOX:
773 ResetAppearance_CheckBox();
774 break;
775 case FIELDTYPE_RADIOBUTTON:
776 ResetAppearance_RadioButton();
777 break;
778 case FIELDTYPE_COMBOBOX:
779 ResetAppearance_ComboBox(sValue);
780 break;
781 case FIELDTYPE_LISTBOX:
782 ResetAppearance_ListBox();
783 break;
784 case FIELDTYPE_TEXTFIELD:
785 ResetAppearance_TextField(sValue);
786 break;
787 }
788
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700789 m_pAnnot->ClearCachedAP();
790}
791
tsepez4cf55152016-11-02 14:37:54 -0700792CFX_WideString CPDFSDK_Widget::OnFormat(bool& bFormatted) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700793 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800794 ASSERT(pFormField);
tsepez8c2a8cd2016-09-07 15:29:11 -0700795 return m_pInterForm->OnFormat(pFormField, bFormatted);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700796}
797
tsepez4cf55152016-11-02 14:37:54 -0700798void CPDFSDK_Widget::ResetFieldAppearance(bool bValueChanged) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700799 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800800 ASSERT(pFormField);
thestig1cd352e2016-06-07 17:53:06 -0700801 m_pInterForm->ResetFieldAppearance(pFormField, nullptr, bValueChanged);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700802}
803
804void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice,
Tom Sepez60d909e2015-12-10 15:34:55 -0800805 const CFX_Matrix* pUser2Device,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700806 CPDF_Annot::AppearanceMode mode,
807 const CPDF_RenderOptions* pOptions) {
808 int nFieldType = GetFieldType();
809
810 if ((nFieldType == FIELDTYPE_CHECKBOX ||
811 nFieldType == FIELDTYPE_RADIOBUTTON) &&
812 mode == CPDF_Annot::Normal &&
813 !IsWidgetAppearanceValid(CPDF_Annot::Normal)) {
814 CFX_PathData pathData;
815
Tom Sepez281a9ea2016-02-26 14:24:28 -0800816 CFX_FloatRect rcAnnot = GetRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700817
818 pathData.AppendRect(rcAnnot.left, rcAnnot.bottom, rcAnnot.right,
819 rcAnnot.top);
820
821 CFX_GraphStateData gsd;
822 gsd.m_LineWidth = 0.0f;
823
824 pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA,
825 FXFILL_ALTERNATE);
826 } else {
827 CPDFSDK_BAAnnot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);
828 }
829}
830
831void CPDFSDK_Widget::UpdateField() {
832 CPDF_FormField* pFormField = GetFormField();
Lei Zhang96660d62015-12-14 18:27:25 -0800833 ASSERT(pFormField);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700834 m_pInterForm->UpdateField(pFormField);
835}
836
837void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
838 CPDFSDK_PageView* pPageView) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700839 int nFieldType = GetFieldType();
jaepark611adb82016-08-17 11:34:36 -0700840 if (!m_pInterForm->IsNeedHighLight(nFieldType))
841 return;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700842
jaepark611adb82016-08-17 11:34:36 -0700843 CFX_Matrix page2device;
844 pPageView->GetCurrentMatrix(page2device);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700845
Dan Sinclairafb44562017-02-09 13:07:43 -0500846 CFX_FloatRect rcDevice = GetRect();
Dan Sinclaira0061af2017-02-23 09:25:17 -0500847 CFX_PointF tmp =
848 page2device.Transform(CFX_PointF(rcDevice.left, rcDevice.bottom));
849 rcDevice.left = tmp.x;
850 rcDevice.bottom = tmp.y;
851
852 tmp = page2device.Transform(CFX_PointF(rcDevice.right, rcDevice.top));
853 rcDevice.right = tmp.x;
854 rcDevice.top = tmp.y;
jaepark611adb82016-08-17 11:34:36 -0700855 rcDevice.Normalize();
856
Dan Sinclairafb44562017-02-09 13:07:43 -0500857 FX_RECT rcDev = rcDevice.ToFxRect();
858 pDevice->FillRect(
859 &rcDev, ArgbEncode(static_cast<int>(m_pInterForm->GetHighlightAlpha()),
860 m_pInterForm->GetHighlightColor(nFieldType)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700861}
862
863void CPDFSDK_Widget::ResetAppearance_PushButton() {
864 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -0800865 CFX_FloatRect rcWindow = GetRotatedRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700866 int32_t nLayout = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700867 switch (pControl->GetTextPosition()) {
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700868 case TEXTPOS_ICON:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700869 nLayout = PPBL_ICON;
870 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700871 case TEXTPOS_BELOW:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700872 nLayout = PPBL_ICONTOPLABELBOTTOM;
873 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700874 case TEXTPOS_ABOVE:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700875 nLayout = PPBL_LABELTOPICONBOTTOM;
876 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700877 case TEXTPOS_RIGHT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700878 nLayout = PPBL_ICONLEFTLABELRIGHT;
879 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700880 case TEXTPOS_LEFT:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700881 nLayout = PPBL_LABELLEFTICONRIGHT;
882 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700883 case TEXTPOS_OVERLAID:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700884 nLayout = PPBL_LABELOVERICON;
885 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700886 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700887 nLayout = PPBL_LABEL;
888 break;
889 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700890
Dan Sinclairfc54e052017-02-23 09:59:05 -0500891 CPWL_Color crBackground;
892 CPWL_Color crBorder;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700893 int iColorType;
Dan Sinclair05df0752017-03-14 14:43:42 -0400894 float fc[4];
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700895 pControl->GetOriginalBackgroundColor(iColorType, fc);
896 if (iColorType > 0)
897 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700898
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700899 pControl->GetOriginalBorderColor(iColorType, fc);
900 if (iColorType > 0)
901 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700902
Dan Sinclair05df0752017-03-14 14:43:42 -0400903 float fBorderWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700904 CPWL_Dash dsBorder(3, 0, 0);
Dan Sinclairfc54e052017-02-23 09:59:05 -0500905 CPWL_Color crLeftTop;
906 CPWL_Color crRightBottom;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700907
dsinclair92cb5e52016-05-16 11:38:28 -0700908 BorderStyle nBorderStyle = GetBorderStyle();
909 switch (nBorderStyle) {
910 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700911 dsBorder = CPWL_Dash(3, 3, 0);
912 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700913 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700914 fBorderWidth *= 2;
915 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
Dan Sinclairfc54e052017-02-23 09:59:05 -0500916 crRightBottom = crBackground / 2.0f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700917 break;
dsinclair92cb5e52016-05-16 11:38:28 -0700918 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700919 fBorderWidth *= 2;
920 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
921 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
922 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700923 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700924 break;
925 }
926
Tom Sepez281a9ea2016-02-26 14:24:28 -0800927 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700928
929 CPWL_Color crText(COLORTYPE_GRAY, 0);
930
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700931 CFX_ByteString csNameTag;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700932 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
933 if (da.HasColor()) {
934 da.GetColor(iColorType, fc);
935 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
936 }
Tom Sepezc4a2b752017-04-07 13:56:13 -0700937 float fFontSize = 12.0f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700938 if (da.HasFont())
Tom Sepezc4a2b752017-04-07 13:56:13 -0700939 csNameTag = da.GetFont(&fFontSize);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700940
941 CFX_WideString csWCaption;
Tom Sepezc4a2b752017-04-07 13:56:13 -0700942 CFX_WideString csNormalCaption;
943 CFX_WideString csRolloverCaption;
944 CFX_WideString csDownCaption;
jaepark611adb82016-08-17 11:34:36 -0700945 if (pControl->HasMKEntry("CA"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700946 csNormalCaption = pControl->GetNormalCaption();
jaepark611adb82016-08-17 11:34:36 -0700947
948 if (pControl->HasMKEntry("RC"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700949 csRolloverCaption = pControl->GetRolloverCaption();
jaepark611adb82016-08-17 11:34:36 -0700950
951 if (pControl->HasMKEntry("AC"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700952 csDownCaption = pControl->GetDownCaption();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700953
thestig1cd352e2016-06-07 17:53:06 -0700954 CPDF_Stream* pNormalIcon = nullptr;
955 CPDF_Stream* pRolloverIcon = nullptr;
956 CPDF_Stream* pDownIcon = nullptr;
jaepark611adb82016-08-17 11:34:36 -0700957 if (pControl->HasMKEntry("I"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700958 pNormalIcon = pControl->GetNormalIcon();
jaepark611adb82016-08-17 11:34:36 -0700959
960 if (pControl->HasMKEntry("RI"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700961 pRolloverIcon = pControl->GetRolloverIcon();
jaepark611adb82016-08-17 11:34:36 -0700962
963 if (pControl->HasMKEntry("IX"))
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700964 pDownIcon = pControl->GetDownIcon();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700965
966 if (pNormalIcon) {
967 if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -0700968 if (pImageDict->GetStringFor("Name").IsEmpty())
tsepez0e606b52016-11-18 16:22:41 -0800969 pImageDict->SetNewFor<CPDF_String>("Name", "ImgA", false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700970 }
971 }
972
973 if (pRolloverIcon) {
974 if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -0700975 if (pImageDict->GetStringFor("Name").IsEmpty())
tsepez0e606b52016-11-18 16:22:41 -0800976 pImageDict->SetNewFor<CPDF_String>("Name", "ImgB", false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700977 }
978 }
979
980 if (pDownIcon) {
981 if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -0700982 if (pImageDict->GetStringFor("Name").IsEmpty())
tsepez0e606b52016-11-18 16:22:41 -0800983 pImageDict->SetNewFor<CPDF_String>("Name", "ImgC", false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700984 }
985 }
986
987 CPDF_IconFit iconFit = pControl->GetIconFit();
988
dsinclair690c0332016-10-11 09:13:01 -0700989 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
Lei Zhangfcfa3b82015-12-24 21:07:28 -0800990 font_map.SetAPType("N");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700991
992 CFX_ByteString csAP =
993 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
994 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
995 crLeftTop, crRightBottom, nBorderStyle,
996 dsBorder) +
997 CPWL_Utils::GetPushButtonAppStream(
Lei Zhangfcfa3b82015-12-24 21:07:28 -0800998 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700999 pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout);
1000
1001 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP);
1002 if (pNormalIcon)
1003 AddImageToAppearance("N", pNormalIcon);
1004
1005 CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode();
1006 if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) {
1007 if (csRolloverCaption.IsEmpty() && !pRolloverIcon) {
1008 csRolloverCaption = csNormalCaption;
1009 pRolloverIcon = pNormalIcon;
1010 }
1011
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001012 font_map.SetAPType("R");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001013
1014 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1015 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1016 crLeftTop, crRightBottom,
1017 nBorderStyle, dsBorder) +
1018 CPWL_Utils::GetPushButtonAppStream(
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001019 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001020 pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize,
1021 nLayout);
1022
1023 WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP);
1024 if (pRolloverIcon)
1025 AddImageToAppearance("R", pRolloverIcon);
1026
1027 if (csDownCaption.IsEmpty() && !pDownIcon) {
1028 csDownCaption = csNormalCaption;
1029 pDownIcon = pNormalIcon;
1030 }
1031
1032 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -07001033 case BorderStyle::BEVELED: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001034 CPWL_Color crTemp = crLeftTop;
1035 crLeftTop = crRightBottom;
1036 crRightBottom = crTemp;
dsinclair92cb5e52016-05-16 11:38:28 -07001037 break;
1038 }
1039 case BorderStyle::INSET: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001040 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1041 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001042 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001043 }
1044 default:
1045 break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001046 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001047
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001048 font_map.SetAPType("D");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001049
Dan Sinclairfc54e052017-02-23 09:59:05 -05001050 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) +
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001051 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1052 crLeftTop, crRightBottom,
1053 nBorderStyle, dsBorder) +
1054 CPWL_Utils::GetPushButtonAppStream(
Lei Zhangfcfa3b82015-12-24 21:07:28 -08001055 iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map,
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001056 pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001057
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001058 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001059 if (pDownIcon)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001060 AddImageToAppearance("D", pDownIcon);
1061 } else {
1062 RemoveAppearance("D");
1063 RemoveAppearance("R");
1064 }
1065}
1066
1067void CPDFSDK_Widget::ResetAppearance_CheckBox() {
1068 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001069 CPWL_Color crBackground, crBorder, crText;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001070 int iColorType;
Dan Sinclair05df0752017-03-14 14:43:42 -04001071 float fc[4];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001072
1073 pControl->GetOriginalBackgroundColor(iColorType, fc);
1074 if (iColorType > 0)
1075 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1076
1077 pControl->GetOriginalBorderColor(iColorType, fc);
1078 if (iColorType > 0)
1079 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1080
Dan Sinclair05df0752017-03-14 14:43:42 -04001081 float fBorderWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001082 CPWL_Dash dsBorder(3, 0, 0);
1083 CPWL_Color crLeftTop, crRightBottom;
1084
dsinclair92cb5e52016-05-16 11:38:28 -07001085 BorderStyle nBorderStyle = GetBorderStyle();
1086 switch (nBorderStyle) {
1087 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001088 dsBorder = CPWL_Dash(3, 3, 0);
1089 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001090 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001091 fBorderWidth *= 2;
1092 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
Dan Sinclairfc54e052017-02-23 09:59:05 -05001093 crRightBottom = crBackground / 2.0f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001094 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001095 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001096 fBorderWidth *= 2;
1097 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1098 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1099 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001100 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001101 break;
1102 }
1103
Tom Sepez281a9ea2016-02-26 14:24:28 -08001104 CFX_FloatRect rcWindow = GetRotatedRect();
1105 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001106 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
1107 if (da.HasColor()) {
1108 da.GetColor(iColorType, fc);
1109 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1110 }
1111
1112 int32_t nStyle = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001113 CFX_WideString csWCaption = pControl->GetNormalCaption();
1114 if (csWCaption.GetLength() > 0) {
1115 switch (csWCaption[0]) {
1116 case L'l':
1117 nStyle = PCS_CIRCLE;
1118 break;
1119 case L'8':
1120 nStyle = PCS_CROSS;
1121 break;
1122 case L'u':
1123 nStyle = PCS_DIAMOND;
1124 break;
1125 case L'n':
1126 nStyle = PCS_SQUARE;
1127 break;
1128 case L'H':
1129 nStyle = PCS_STAR;
1130 break;
1131 default: // L'4'
1132 nStyle = PCS_CHECK;
1133 break;
1134 }
1135 } else {
1136 nStyle = PCS_CHECK;
1137 }
1138
1139 CFX_ByteString csAP_N_ON =
1140 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1141 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1142 crLeftTop, crRightBottom, nBorderStyle,
1143 dsBorder);
1144
1145 CFX_ByteString csAP_N_OFF = csAP_N_ON;
1146
1147 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -07001148 case BorderStyle::BEVELED: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001149 CPWL_Color crTemp = crLeftTop;
1150 crLeftTop = crRightBottom;
1151 crRightBottom = crTemp;
dsinclair92cb5e52016-05-16 11:38:28 -07001152 break;
1153 }
1154 case BorderStyle::INSET: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001155 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1156 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1157 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001158 }
1159 default:
1160 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001161 }
1162
1163 CFX_ByteString csAP_D_ON =
Dan Sinclairfc54e052017-02-23 09:59:05 -05001164 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) +
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001165 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1166 crLeftTop, crRightBottom, nBorderStyle,
1167 dsBorder);
1168
1169 CFX_ByteString csAP_D_OFF = csAP_D_ON;
1170
1171 csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
1172 csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
1173
1174 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
1175 pControl->GetCheckedAPState());
1176 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
1177
1178 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
1179 pControl->GetCheckedAPState());
1180 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
1181
1182 CFX_ByteString csAS = GetAppState();
1183 if (csAS.IsEmpty())
1184 SetAppState("Off");
1185}
1186
1187void CPDFSDK_Widget::ResetAppearance_RadioButton() {
1188 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001189 CPWL_Color crBackground, crBorder, crText;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001190 int iColorType;
Dan Sinclair05df0752017-03-14 14:43:42 -04001191 float fc[4];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001192
1193 pControl->GetOriginalBackgroundColor(iColorType, fc);
1194 if (iColorType > 0)
1195 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1196
1197 pControl->GetOriginalBorderColor(iColorType, fc);
1198 if (iColorType > 0)
1199 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1200
Dan Sinclair05df0752017-03-14 14:43:42 -04001201 float fBorderWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001202 CPWL_Dash dsBorder(3, 0, 0);
Dan Sinclairfc54e052017-02-23 09:59:05 -05001203 CPWL_Color crLeftTop;
1204 CPWL_Color crRightBottom;
dsinclair92cb5e52016-05-16 11:38:28 -07001205 BorderStyle nBorderStyle = GetBorderStyle();
1206 switch (nBorderStyle) {
1207 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001208 dsBorder = CPWL_Dash(3, 3, 0);
1209 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001210 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001211 fBorderWidth *= 2;
1212 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
Dan Sinclairfc54e052017-02-23 09:59:05 -05001213 crRightBottom = crBackground / 2.0f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001214 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001215 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001216 fBorderWidth *= 2;
1217 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1218 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1219 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001220 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001221 break;
1222 }
1223
Tom Sepez281a9ea2016-02-26 14:24:28 -08001224 CFX_FloatRect rcWindow = GetRotatedRect();
1225 CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001226
1227 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
1228 if (da.HasColor()) {
1229 da.GetColor(iColorType, fc);
1230 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1231 }
1232
1233 int32_t nStyle = 0;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001234 CFX_WideString csWCaption = pControl->GetNormalCaption();
1235 if (csWCaption.GetLength() > 0) {
1236 switch (csWCaption[0]) {
1237 default: // L'l':
1238 nStyle = PCS_CIRCLE;
1239 break;
1240 case L'8':
1241 nStyle = PCS_CROSS;
1242 break;
1243 case L'u':
1244 nStyle = PCS_DIAMOND;
1245 break;
1246 case L'n':
1247 nStyle = PCS_SQUARE;
1248 break;
1249 case L'H':
1250 nStyle = PCS_STAR;
1251 break;
1252 case L'4':
1253 nStyle = PCS_CHECK;
1254 break;
1255 }
1256 } else {
1257 nStyle = PCS_CIRCLE;
1258 }
1259
1260 CFX_ByteString csAP_N_ON;
1261
Tom Sepez281a9ea2016-02-26 14:24:28 -08001262 CFX_FloatRect rcCenter =
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001263 CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f);
1264
1265 if (nStyle == PCS_CIRCLE) {
dsinclair92cb5e52016-05-16 11:38:28 -07001266 if (nBorderStyle == BorderStyle::BEVELED) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001267 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
Dan Sinclairfc54e052017-02-23 09:59:05 -05001268 crRightBottom = crBackground - 0.25f;
dsinclair92cb5e52016-05-16 11:38:28 -07001269 } else if (nBorderStyle == BorderStyle::INSET) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001270 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5f);
1271 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75f);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001272 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001273
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001274 csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBackground) +
1275 CPWL_Utils::GetCircleBorderAppStream(
1276 rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
1277 nBorderStyle, dsBorder);
1278 } else {
1279 csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
1280 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1281 crLeftTop, crRightBottom,
1282 nBorderStyle, dsBorder);
1283 }
1284
1285 CFX_ByteString csAP_N_OFF = csAP_N_ON;
1286
1287 switch (nBorderStyle) {
dsinclair92cb5e52016-05-16 11:38:28 -07001288 case BorderStyle::BEVELED: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001289 CPWL_Color crTemp = crLeftTop;
1290 crLeftTop = crRightBottom;
1291 crRightBottom = crTemp;
dsinclair92cb5e52016-05-16 11:38:28 -07001292 break;
1293 }
1294 case BorderStyle::INSET: {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001295 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1296 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1297 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001298 }
1299 default:
1300 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001301 }
1302
1303 CFX_ByteString csAP_D_ON;
1304
1305 if (nStyle == PCS_CIRCLE) {
Dan Sinclairfc54e052017-02-23 09:59:05 -05001306 CPWL_Color crBK = crBackground - 0.25f;
dsinclair92cb5e52016-05-16 11:38:28 -07001307 if (nBorderStyle == BorderStyle::BEVELED) {
Dan Sinclairfc54e052017-02-23 09:59:05 -05001308 crLeftTop = crBackground - 0.25f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001309 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1310 crBK = crBackground;
dsinclair92cb5e52016-05-16 11:38:28 -07001311 } else if (nBorderStyle == BorderStyle::INSET) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001312 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
1313 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
1314 }
1315
1316 csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBK) +
1317 CPWL_Utils::GetCircleBorderAppStream(
1318 rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
1319 nBorderStyle, dsBorder);
1320 } else {
Dan Sinclairfc54e052017-02-23 09:59:05 -05001321 csAP_D_ON =
1322 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground - 0.25f) +
1323 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1324 crLeftTop, crRightBottom, nBorderStyle,
1325 dsBorder);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001326 }
1327
1328 CFX_ByteString csAP_D_OFF = csAP_D_ON;
1329
1330 csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
1331 csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
1332
1333 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
1334 pControl->GetCheckedAPState());
1335 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
1336
1337 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
1338 pControl->GetCheckedAPState());
1339 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
1340
1341 CFX_ByteString csAS = GetAppState();
1342 if (csAS.IsEmpty())
1343 SetAppState("Off");
1344}
1345
tsepeza31da742016-09-08 11:28:14 -07001346void CPDFSDK_Widget::ResetAppearance_ComboBox(const CFX_WideString* sValue) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001347 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001348 CPDF_FormField* pField = pControl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001349 CFX_ByteTextBuf sBody, sLines;
1350
Tom Sepez281a9ea2016-02-26 14:24:28 -08001351 CFX_FloatRect rcClient = GetClientRect();
1352 CFX_FloatRect rcButton = rcClient;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001353 rcButton.left = rcButton.right - 13;
1354 rcButton.Normalize();
1355
Dan Sinclair0bb13332017-03-30 16:12:02 -04001356 auto pEdit = pdfium::MakeUnique<CFX_Edit>();
tsepez4cf55152016-11-02 14:37:54 -07001357 pEdit->EnableRefresh(false);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001358
dsinclair690c0332016-10-11 09:13:01 -07001359 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
thestig732f6a02016-05-12 10:41:56 -07001360 pEdit->SetFontMap(&font_map);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001361
thestig732f6a02016-05-12 10:41:56 -07001362 CFX_FloatRect rcEdit = rcClient;
1363 rcEdit.right = rcButton.left;
1364 rcEdit.Normalize();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001365
thestig732f6a02016-05-12 10:41:56 -07001366 pEdit->SetPlateRect(rcEdit);
tsepez4cf55152016-11-02 14:37:54 -07001367 pEdit->SetAlignmentV(1, true);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001368
Dan Sinclair05df0752017-03-14 14:43:42 -04001369 float fFontSize = GetFontSize();
thestig732f6a02016-05-12 10:41:56 -07001370 if (IsFloatZero(fFontSize))
tsepez4cf55152016-11-02 14:37:54 -07001371 pEdit->SetAutoFontSize(true, true);
thestig732f6a02016-05-12 10:41:56 -07001372 else
1373 pEdit->SetFontSize(fFontSize);
1374
1375 pEdit->Initialize();
1376
1377 if (sValue) {
tsepeza31da742016-09-08 11:28:14 -07001378 pEdit->SetText(*sValue);
thestig732f6a02016-05-12 10:41:56 -07001379 } else {
1380 int32_t nCurSel = pField->GetSelectedIndex(0);
thestig732f6a02016-05-12 10:41:56 -07001381 if (nCurSel < 0)
tsepez067990c2016-09-13 06:46:40 -07001382 pEdit->SetText(pField->GetValue());
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001383 else
tsepez067990c2016-09-13 06:46:40 -07001384 pEdit->SetText(pField->GetOptionLabel(nCurSel));
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001385 }
1386
thestig732f6a02016-05-12 10:41:56 -07001387 CFX_FloatRect rcContent = pEdit->GetContentRect();
1388
1389 CFX_ByteString sEdit =
Dan Sinclairf528eee2017-02-14 11:52:07 -05001390 CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF());
thestig732f6a02016-05-12 10:41:56 -07001391 if (sEdit.GetLength() > 0) {
1392 sBody << "/Tx BMC\n"
1393 << "q\n";
1394 if (rcContent.Width() > rcEdit.Width() ||
1395 rcContent.Height() > rcEdit.Height()) {
1396 sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width()
1397 << " " << rcEdit.Height() << " re\nW\nn\n";
1398 }
1399
1400 CPWL_Color crText = GetTextPWLColor();
1401 sBody << "BT\n"
1402 << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"
1403 << "Q\nEMC\n";
1404 }
1405
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001406 sBody << CPWL_Utils::GetDropButtonAppStream(rcButton);
1407
1408 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
tsepez8e4c5052016-04-14 13:42:44 -07001409 sLines.AsStringC() + sBody.AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001410
1411 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1412}
1413
1414void CPDFSDK_Widget::ResetAppearance_ListBox() {
1415 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001416 CPDF_FormField* pField = pControl->GetField();
Tom Sepez281a9ea2016-02-26 14:24:28 -08001417 CFX_FloatRect rcClient = GetClientRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001418 CFX_ByteTextBuf sBody, sLines;
1419
Dan Sinclair0bb13332017-03-30 16:12:02 -04001420 auto pEdit = pdfium::MakeUnique<CFX_Edit>();
tsepez4cf55152016-11-02 14:37:54 -07001421 pEdit->EnableRefresh(false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001422
dsinclair690c0332016-10-11 09:13:01 -07001423 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
thestig732f6a02016-05-12 10:41:56 -07001424 pEdit->SetFontMap(&font_map);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001425
thestig732f6a02016-05-12 10:41:56 -07001426 pEdit->SetPlateRect(CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001427
Dan Sinclair05df0752017-03-14 14:43:42 -04001428 float fFontSize = GetFontSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001429
thestig594b20b2016-05-12 21:56:43 -07001430 pEdit->SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001431
thestig732f6a02016-05-12 10:41:56 -07001432 pEdit->Initialize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001433
thestig732f6a02016-05-12 10:41:56 -07001434 CFX_ByteTextBuf sList;
Dan Sinclair05df0752017-03-14 14:43:42 -04001435 float fy = rcClient.top;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001436
thestig732f6a02016-05-12 10:41:56 -07001437 int32_t nTop = pField->GetTopVisibleIndex();
1438 int32_t nCount = pField->CountOptions();
1439 int32_t nSelCount = pField->CountSelectedItems();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001440
thestig594b20b2016-05-12 21:56:43 -07001441 for (int32_t i = nTop; i < nCount; ++i) {
1442 bool bSelected = false;
1443 for (int32_t j = 0; j < nSelCount; ++j) {
thestig732f6a02016-05-12 10:41:56 -07001444 if (pField->GetSelectedIndex(j) == i) {
thestig594b20b2016-05-12 21:56:43 -07001445 bSelected = true;
thestig732f6a02016-05-12 10:41:56 -07001446 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001447 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001448 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001449
tsepez067990c2016-09-13 06:46:40 -07001450 pEdit->SetText(pField->GetOptionLabel(i));
thestig732f6a02016-05-12 10:41:56 -07001451
1452 CFX_FloatRect rcContent = pEdit->GetContentRect();
Dan Sinclair05df0752017-03-14 14:43:42 -04001453 float fItemHeight = rcContent.Height();
thestig732f6a02016-05-12 10:41:56 -07001454
1455 if (bSelected) {
1456 CFX_FloatRect rcItem =
1457 CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy);
1458 sList << "q\n"
1459 << CPWL_Utils::GetColorAppStream(
1460 CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f,
1461 113.0f / 255.0f),
tsepez4cf55152016-11-02 14:37:54 -07001462 true)
thestig732f6a02016-05-12 10:41:56 -07001463 << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width()
1464 << " " << rcItem.Height() << " re f\n"
1465 << "Q\n";
1466
1467 sList << "BT\n"
1468 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1),
tsepez4cf55152016-11-02 14:37:54 -07001469 true)
Dan Sinclairf528eee2017-02-14 11:52:07 -05001470 << CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, fy))
thestig732f6a02016-05-12 10:41:56 -07001471 << "ET\n";
1472 } else {
1473 CPWL_Color crText = GetTextPWLColor();
1474 sList << "BT\n"
tsepez4cf55152016-11-02 14:37:54 -07001475 << CPWL_Utils::GetColorAppStream(crText, true)
Dan Sinclairf528eee2017-02-14 11:52:07 -05001476 << CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_PointF(0.0f, fy))
thestig732f6a02016-05-12 10:41:56 -07001477 << "ET\n";
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001478 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001479
thestig732f6a02016-05-12 10:41:56 -07001480 fy -= fItemHeight;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001481 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001482
thestig732f6a02016-05-12 10:41:56 -07001483 if (sList.GetSize() > 0) {
1484 sBody << "/Tx BMC\n"
1485 << "q\n"
1486 << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width()
1487 << " " << rcClient.Height() << " re\nW\nn\n";
1488 sBody << sList << "Q\nEMC\n";
1489 }
1490
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001491 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
tsepez8e4c5052016-04-14 13:42:44 -07001492 sLines.AsStringC() + sBody.AsStringC();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001493
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001494 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001495}
1496
tsepeza31da742016-09-08 11:28:14 -07001497void CPDFSDK_Widget::ResetAppearance_TextField(const CFX_WideString* sValue) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001498 CPDF_FormControl* pControl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001499 CPDF_FormField* pField = pControl->GetField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001500 CFX_ByteTextBuf sBody, sLines;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001501
Dan Sinclair0bb13332017-03-30 16:12:02 -04001502 auto pEdit = pdfium::MakeUnique<CFX_Edit>();
tsepez4cf55152016-11-02 14:37:54 -07001503 pEdit->EnableRefresh(false);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001504
dsinclair690c0332016-10-11 09:13:01 -07001505 CBA_FontMap font_map(this, m_pInterForm->GetFormFillEnv()->GetSysHandler());
thestig732f6a02016-05-12 10:41:56 -07001506 pEdit->SetFontMap(&font_map);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001507
thestig732f6a02016-05-12 10:41:56 -07001508 CFX_FloatRect rcClient = GetClientRect();
1509 pEdit->SetPlateRect(rcClient);
tsepez4cf55152016-11-02 14:37:54 -07001510 pEdit->SetAlignmentH(pControl->GetControlAlignment(), true);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001511
thestig732f6a02016-05-12 10:41:56 -07001512 uint32_t dwFieldFlags = pField->GetFieldFlags();
tsepez4cf55152016-11-02 14:37:54 -07001513 bool bMultiLine = (dwFieldFlags >> 12) & 1;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001514
thestig732f6a02016-05-12 10:41:56 -07001515 if (bMultiLine) {
tsepez4cf55152016-11-02 14:37:54 -07001516 pEdit->SetMultiLine(true, true);
1517 pEdit->SetAutoReturn(true, true);
thestig732f6a02016-05-12 10:41:56 -07001518 } else {
tsepez4cf55152016-11-02 14:37:54 -07001519 pEdit->SetAlignmentV(1, true);
thestig732f6a02016-05-12 10:41:56 -07001520 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001521
thestig732f6a02016-05-12 10:41:56 -07001522 uint16_t subWord = 0;
1523 if ((dwFieldFlags >> 13) & 1) {
1524 subWord = '*';
tsepez4cf55152016-11-02 14:37:54 -07001525 pEdit->SetPasswordChar(subWord, true);
thestig732f6a02016-05-12 10:41:56 -07001526 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001527
thestig732f6a02016-05-12 10:41:56 -07001528 int nMaxLen = pField->GetMaxLen();
tsepez4cf55152016-11-02 14:37:54 -07001529 bool bCharArray = (dwFieldFlags >> 24) & 1;
Dan Sinclair05df0752017-03-14 14:43:42 -04001530 float fFontSize = GetFontSize();
Bo Xufdc00a72014-10-28 23:03:33 -07001531
Tom Sepez51da0932015-11-25 16:05:49 -08001532#ifdef PDF_ENABLE_XFA
thestig732f6a02016-05-12 10:41:56 -07001533 CFX_WideString sValueTmp;
1534 if (!sValue && GetMixXFAWidget()) {
tsepez4cf55152016-11-02 14:37:54 -07001535 sValueTmp = GetValue(true);
tsepeza31da742016-09-08 11:28:14 -07001536 sValue = &sValueTmp;
thestig732f6a02016-05-12 10:41:56 -07001537 }
Tom Sepez40e9ff32015-11-30 12:39:54 -08001538#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001539
thestig732f6a02016-05-12 10:41:56 -07001540 if (nMaxLen > 0) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001541 if (bCharArray) {
thestig732f6a02016-05-12 10:41:56 -07001542 pEdit->SetCharArray(nMaxLen);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001543
thestig732f6a02016-05-12 10:41:56 -07001544 if (IsFloatZero(fFontSize)) {
1545 fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0),
1546 rcClient, nMaxLen);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001547 }
thestig732f6a02016-05-12 10:41:56 -07001548 } else {
1549 if (sValue)
tsepeza31da742016-09-08 11:28:14 -07001550 nMaxLen = sValue->GetLength();
thestig732f6a02016-05-12 10:41:56 -07001551 pEdit->SetLimitChar(nMaxLen);
Tom Sepez2f2ffec2015-07-23 14:42:09 -07001552 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001553 }
1554
thestig732f6a02016-05-12 10:41:56 -07001555 if (IsFloatZero(fFontSize))
tsepez4cf55152016-11-02 14:37:54 -07001556 pEdit->SetAutoFontSize(true, true);
thestig732f6a02016-05-12 10:41:56 -07001557 else
1558 pEdit->SetFontSize(fFontSize);
1559
1560 pEdit->Initialize();
tsepez067990c2016-09-13 06:46:40 -07001561 pEdit->SetText(sValue ? *sValue : pField->GetValue());
thestig732f6a02016-05-12 10:41:56 -07001562
1563 CFX_FloatRect rcContent = pEdit->GetContentRect();
thestig732f6a02016-05-12 10:41:56 -07001564 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(
Dan Sinclairf528eee2017-02-14 11:52:07 -05001565 pEdit.get(), CFX_PointF(), nullptr, !bCharArray, subWord);
thestig732f6a02016-05-12 10:41:56 -07001566
1567 if (sEdit.GetLength() > 0) {
1568 sBody << "/Tx BMC\n"
1569 << "q\n";
1570 if (rcContent.Width() > rcClient.Width() ||
1571 rcContent.Height() > rcClient.Height()) {
1572 sBody << rcClient.left << " " << rcClient.bottom << " "
1573 << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
1574 }
1575 CPWL_Color crText = GetTextPWLColor();
1576 sBody << "BT\n"
1577 << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n"
1578 << "Q\nEMC\n";
1579 }
1580
1581 if (bCharArray) {
1582 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -07001583 case BorderStyle::SOLID: {
thestig732f6a02016-05-12 10:41:56 -07001584 CFX_ByteString sColor =
tsepez4cf55152016-11-02 14:37:54 -07001585 CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false);
thestig732f6a02016-05-12 10:41:56 -07001586 if (sColor.GetLength() > 0) {
1587 sLines << "q\n"
1588 << GetBorderWidth() << " w\n"
tsepez4cf55152016-11-02 14:37:54 -07001589 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false)
thestig732f6a02016-05-12 10:41:56 -07001590 << " 2 J 0 j\n";
1591
thestig594b20b2016-05-12 21:56:43 -07001592 for (int32_t i = 1; i < nMaxLen; ++i) {
thestig732f6a02016-05-12 10:41:56 -07001593 sLines << rcClient.left +
1594 ((rcClient.right - rcClient.left) / nMaxLen) * i
1595 << " " << rcClient.bottom << " m\n"
1596 << rcClient.left +
1597 ((rcClient.right - rcClient.left) / nMaxLen) * i
1598 << " " << rcClient.top << " l S\n";
1599 }
1600
1601 sLines << "Q\n";
1602 }
dsinclair92cb5e52016-05-16 11:38:28 -07001603 break;
1604 }
1605 case BorderStyle::DASH: {
thestig732f6a02016-05-12 10:41:56 -07001606 CFX_ByteString sColor =
tsepez4cf55152016-11-02 14:37:54 -07001607 CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false);
thestig732f6a02016-05-12 10:41:56 -07001608 if (sColor.GetLength() > 0) {
1609 CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0);
1610
1611 sLines << "q\n"
1612 << GetBorderWidth() << " w\n"
tsepez4cf55152016-11-02 14:37:54 -07001613 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), false)
thestig732f6a02016-05-12 10:41:56 -07001614 << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] "
1615 << dsBorder.nPhase << " d\n";
1616
thestig594b20b2016-05-12 21:56:43 -07001617 for (int32_t i = 1; i < nMaxLen; ++i) {
thestig732f6a02016-05-12 10:41:56 -07001618 sLines << rcClient.left +
1619 ((rcClient.right - rcClient.left) / nMaxLen) * i
1620 << " " << rcClient.bottom << " m\n"
1621 << rcClient.left +
1622 ((rcClient.right - rcClient.left) / nMaxLen) * i
1623 << " " << rcClient.top << " l S\n";
1624 }
1625
1626 sLines << "Q\n";
1627 }
dsinclair92cb5e52016-05-16 11:38:28 -07001628 break;
1629 }
1630 default:
1631 break;
thestig732f6a02016-05-12 10:41:56 -07001632 }
1633 }
1634
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001635 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
tsepez8e4c5052016-04-14 13:42:44 -07001636 sLines.AsStringC() + sBody.AsStringC();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001637 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001638}
1639
Tom Sepez281a9ea2016-02-26 14:24:28 -08001640CFX_FloatRect CPDFSDK_Widget::GetClientRect() const {
1641 CFX_FloatRect rcWindow = GetRotatedRect();
Dan Sinclair05df0752017-03-14 14:43:42 -04001642 float fBorderWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001643 switch (GetBorderStyle()) {
dsinclair92cb5e52016-05-16 11:38:28 -07001644 case BorderStyle::BEVELED:
1645 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001646 fBorderWidth *= 2.0f;
1647 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001648 default:
1649 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001650 }
1651
1652 return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001653}
1654
Tom Sepez281a9ea2016-02-26 14:24:28 -08001655CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const {
1656 CFX_FloatRect rectAnnot = GetRect();
Dan Sinclair05df0752017-03-14 14:43:42 -04001657 float fWidth = rectAnnot.right - rectAnnot.left;
1658 float fHeight = rectAnnot.top - rectAnnot.bottom;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001659
1660 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -08001661 CFX_FloatRect rcPDFWindow;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001662 switch (abs(pControl->GetRotation() % 360)) {
1663 case 0:
1664 case 180:
1665 default:
Tom Sepez281a9ea2016-02-26 14:24:28 -08001666 rcPDFWindow = CFX_FloatRect(0, 0, fWidth, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001667 break;
1668 case 90:
1669 case 270:
Tom Sepez281a9ea2016-02-26 14:24:28 -08001670 rcPDFWindow = CFX_FloatRect(0, 0, fHeight, fWidth);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001671 break;
1672 }
1673
1674 return rcPDFWindow;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001675}
1676
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001677CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const {
1678 CPWL_Color crBackground = GetFillPWLColor();
jaepark611adb82016-08-17 11:34:36 -07001679 if (crBackground.nColorType != COLORTYPE_TRANSPARENT)
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001680 return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);
jaepark611adb82016-08-17 11:34:36 -07001681
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001682 return "";
Bo Xufdc00a72014-10-28 23:03:33 -07001683}
1684
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001685CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const {
Tom Sepez281a9ea2016-02-26 14:24:28 -08001686 CFX_FloatRect rcWindow = GetRotatedRect();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001687 CPWL_Color crBorder = GetBorderPWLColor();
1688 CPWL_Color crBackground = GetFillPWLColor();
1689 CPWL_Color crLeftTop, crRightBottom;
1690
Dan Sinclair05df0752017-03-14 14:43:42 -04001691 float fBorderWidth = (float)GetBorderWidth();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001692 CPWL_Dash dsBorder(3, 0, 0);
1693
dsinclair92cb5e52016-05-16 11:38:28 -07001694 BorderStyle nBorderStyle = GetBorderStyle();
1695 switch (nBorderStyle) {
1696 case BorderStyle::DASH:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001697 dsBorder = CPWL_Dash(3, 3, 0);
1698 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001699 case BorderStyle::BEVELED:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001700 fBorderWidth *= 2;
1701 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
Dan Sinclairfc54e052017-02-23 09:59:05 -05001702 crRightBottom = crBackground / 2.0f;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001703 break;
dsinclair92cb5e52016-05-16 11:38:28 -07001704 case BorderStyle::INSET:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001705 fBorderWidth *= 2;
1706 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1707 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1708 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001709 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001710 break;
1711 }
1712
1713 return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1714 crLeftTop, crRightBottom, nBorderStyle,
1715 dsBorder);
Bo Xufdc00a72014-10-28 23:03:33 -07001716}
1717
Tom Sepez60d909e2015-12-10 15:34:55 -08001718CFX_Matrix CPDFSDK_Widget::GetMatrix() const {
1719 CFX_Matrix mt;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001720 CPDF_FormControl* pControl = GetFormControl();
Tom Sepez281a9ea2016-02-26 14:24:28 -08001721 CFX_FloatRect rcAnnot = GetRect();
Dan Sinclair05df0752017-03-14 14:43:42 -04001722 float fWidth = rcAnnot.right - rcAnnot.left;
1723 float fHeight = rcAnnot.top - rcAnnot.bottom;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001724
1725 switch (abs(pControl->GetRotation() % 360)) {
1726 case 0:
1727 default:
Tom Sepez60d909e2015-12-10 15:34:55 -08001728 mt = CFX_Matrix(1, 0, 0, 1, 0, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001729 break;
1730 case 90:
Tom Sepez60d909e2015-12-10 15:34:55 -08001731 mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001732 break;
1733 case 180:
Tom Sepez60d909e2015-12-10 15:34:55 -08001734 mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001735 break;
1736 case 270:
Tom Sepez60d909e2015-12-10 15:34:55 -08001737 mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001738 break;
1739 }
1740
1741 return mt;
Bo Xufdc00a72014-10-28 23:03:33 -07001742}
1743
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001744CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const {
1745 CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0);
1746
1747 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001748 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
1749 if (da.HasColor()) {
1750 int32_t iColorType;
Dan Sinclair05df0752017-03-14 14:43:42 -04001751 float fc[4];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001752 da.GetColor(iColorType, fc);
1753 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1754 }
1755
1756 return crText;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001757}
1758
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001759CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const {
1760 CPWL_Color crBorder;
1761
1762 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001763 int32_t iColorType;
Dan Sinclair05df0752017-03-14 14:43:42 -04001764 float fc[4];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001765 pFormCtrl->GetOriginalBorderColor(iColorType, fc);
1766 if (iColorType > 0)
1767 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1768
1769 return crBorder;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001770}
1771
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001772CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const {
1773 CPWL_Color crFill;
1774
1775 CPDF_FormControl* pFormCtrl = GetFormControl();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001776 int32_t iColorType;
Dan Sinclair05df0752017-03-14 14:43:42 -04001777 float fc[4];
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001778 pFormCtrl->GetOriginalBackgroundColor(iColorType, fc);
1779 if (iColorType > 0)
1780 crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1781
1782 return crFill;
Bo Xufdc00a72014-10-28 23:03:33 -07001783}
1784
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001785void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType,
1786 CPDF_Stream* pImage) {
dsinclair38fd8442016-09-15 10:15:32 -07001787 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
1788 CPDF_Stream* pStream = pAPDict->GetStreamFor(sAPType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001789 CPDF_Dictionary* pStreamDict = pStream->GetDict();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001790 CFX_ByteString sImageAlias = "IMG";
1791
1792 if (CPDF_Dictionary* pImageDict = pImage->GetDict()) {
dsinclair38fd8442016-09-15 10:15:32 -07001793 sImageAlias = pImageDict->GetStringFor("Name");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001794 if (sImageAlias.IsEmpty())
1795 sImageAlias = "IMG";
1796 }
1797
tsepez698c5712016-09-28 16:47:07 -07001798 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
dsinclair38fd8442016-09-15 10:15:32 -07001799 CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
tsepez0e606b52016-11-18 16:22:41 -08001800 if (!pStreamResList)
1801 pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources");
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001802
tsepez0e606b52016-11-18 16:22:41 -08001803 CPDF_Dictionary* pXObject =
1804 pStreamResList->SetNewFor<CPDF_Dictionary>("XObject");
1805 pXObject->SetNewFor<CPDF_Reference>(sImageAlias, pDoc, pImage->GetObjNum());
Bo Xufdc00a72014-10-28 23:03:33 -07001806}
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001807
1808void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) {
dsinclair38fd8442016-09-15 10:15:32 -07001809 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"))
1810 pAPDict->RemoveFor(sAPType);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001811}
1812
tsepez4cf55152016-11-02 14:37:54 -07001813bool CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
1814 PDFSDK_FieldAction& data,
1815 CPDFSDK_PageView* pPageView) {
dsinclairb402b172016-10-11 09:26:32 -07001816 CPDFSDK_FormFillEnvironment* pFormFillEnv = pPageView->GetFormFillEnv();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001817
Tom Sepez40e9ff32015-11-30 12:39:54 -08001818#ifdef PDF_ENABLE_XFA
dsinclair521b7502016-11-02 13:02:28 -07001819 CPDFXFA_Context* pContext = pFormFillEnv->GetXFAContext();
dsinclairdf4bc592016-03-31 20:34:43 -07001820 if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001821 XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit);
1822
1823 if (eEventType != XFA_EVENT_Unknown) {
dsinclairdf4bc592016-03-31 20:34:43 -07001824 if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001825 CXFA_EventParam param;
1826 param.m_eType = eEventType;
1827 param.m_wsChange = data.sChange;
1828 param.m_iCommitKey = data.nCommitKey;
1829 param.m_bShift = data.bShift;
1830 param.m_iSelStart = data.nSelStart;
1831 param.m_iSelEnd = data.nSelEnd;
1832 param.m_wsFullText = data.sValue;
1833 param.m_bKeyDown = data.bKeyDown;
1834 param.m_bModifier = data.bModifier;
1835 param.m_wsNewText = data.sValue;
1836 if (data.nSelEnd > data.nSelStart)
1837 param.m_wsNewText.Delete(data.nSelStart,
1838 data.nSelEnd - data.nSelStart);
1839 for (int i = data.sChange.GetLength() - 1; i >= 0; i--)
1840 param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]);
1841 param.m_wsPrevText = data.sValue;
1842
dsinclair221caf62016-04-04 12:08:40 -07001843 CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001844 param.m_pTarget = pAcc;
1845 int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, &param);
1846
dsinclair521b7502016-11-02 13:02:28 -07001847 if (CXFA_FFDocView* pDocView = pContext->GetXFADocView())
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001848 pDocView->UpdateDocView();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001849
Wei Lie98ac2e2016-03-18 15:43:04 -07001850 if (nRet == XFA_EVENTERROR_Success)
tsepez4cf55152016-11-02 14:37:54 -07001851 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001852 }
1853 }
1854 }
Tom Sepez40e9ff32015-11-30 12:39:54 -08001855#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001856
1857 CPDF_Action action = GetAAction(type);
Wei Li0fc6b252016-03-01 16:29:41 -08001858 if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) {
dsinclairb402b172016-10-11 09:26:32 -07001859 CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHander();
dsinclair19c198b2016-10-11 12:51:37 -07001860 return pActionHandler->DoAction_Field(action, type, pFormFillEnv,
1861 GetFormField(), data);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001862 }
tsepez4cf55152016-11-02 14:37:54 -07001863 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001864}
1865
1866CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) {
1867 switch (eAAT) {
1868 case CPDF_AAction::CursorEnter:
1869 case CPDF_AAction::CursorExit:
1870 case CPDF_AAction::ButtonDown:
1871 case CPDF_AAction::ButtonUp:
1872 case CPDF_AAction::GetFocus:
1873 case CPDF_AAction::LoseFocus:
1874 case CPDF_AAction::PageOpen:
1875 case CPDF_AAction::PageClose:
1876 case CPDF_AAction::PageVisible:
1877 case CPDF_AAction::PageInvisible:
1878 return CPDFSDK_BAAnnot::GetAAction(eAAT);
1879
1880 case CPDF_AAction::KeyStroke:
1881 case CPDF_AAction::Format:
1882 case CPDF_AAction::Validate:
1883 case CPDF_AAction::Calculate: {
1884 CPDF_FormField* pField = GetFormField();
Wei Li0fc6b252016-03-01 16:29:41 -08001885 if (pField->GetAdditionalAction().GetDict())
1886 return pField->GetAdditionalAction().GetAction(eAAT);
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001887 return CPDFSDK_BAAnnot::GetAAction(eAAT);
1888 }
1889 default:
1890 break;
1891 }
1892
1893 return CPDF_Action();
1894}
1895
1896CFX_WideString CPDFSDK_Widget::GetAlternateName() const {
1897 CPDF_FormField* pFormField = GetFormField();
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001898 return pFormField->GetAlternateName();
1899}
1900
1901int32_t CPDFSDK_Widget::GetAppearanceAge() const {
1902 return m_nAppAge;
1903}
1904
1905int32_t CPDFSDK_Widget::GetValueAge() const {
1906 return m_nValueAge;
1907}