jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 1 | // Copyright 2016 PDFium Authors. All rights reserved. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 7 | #include "fpdfsdk/include/cpdfsdk_widget.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 8 | |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 9 | #include <memory> |
| 10 | |
dsinclair | c6c425a | 2016-09-29 12:01:30 -0700 | [diff] [blame] | 11 | #include "core/fpdfapi/fpdf_parser/cpdf_dictionary.h" |
| 12 | #include "core/fpdfapi/fpdf_parser/cpdf_document.h" |
| 13 | #include "core/fpdfapi/fpdf_parser/cpdf_stream.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 14 | #include "core/fpdfdoc/cpdf_defaultappearance.h" |
| 15 | #include "core/fpdfdoc/cpdf_formcontrol.h" |
| 16 | #include "core/fpdfdoc/cpdf_formfield.h" |
| 17 | #include "core/fpdfdoc/cpdf_iconfit.h" |
| 18 | #include "core/fpdfdoc/cpdf_interform.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame^] | 19 | #include "core/fxge/cfx_graphstatedata.h" |
| 20 | #include "core/fxge/cfx_pathdata.h" |
| 21 | #include "core/fxge/cfx_renderdevice.h" |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 22 | #include "fpdfsdk/formfiller/cba_fontmap.h" |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 23 | #include "fpdfsdk/fxedit/include/fxet_edit.h" |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 24 | #include "fpdfsdk/include/cpdfsdk_document.h" |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 25 | #include "fpdfsdk/include/cpdfsdk_environment.h" |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 26 | #include "fpdfsdk/include/cpdfsdk_interform.h" |
dsinclair | f34518b | 2016-09-13 12:03:48 -0700 | [diff] [blame] | 27 | #include "fpdfsdk/include/cpdfsdk_pageview.h" |
| 28 | #include "fpdfsdk/include/fsdk_actionhandler.h" |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 29 | #include "fpdfsdk/include/fsdk_define.h" |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 30 | #include "fpdfsdk/pdfwindow/PWL_Edit.h" |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 31 | #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 33 | #ifdef PDF_ENABLE_XFA |
dsinclair | 89bdd08 | 2016-04-06 10:47:54 -0700 | [diff] [blame] | 34 | #include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h" |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 35 | #include "xfa/fxfa/include/cxfa_eventparam.h" |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 36 | #include "xfa/fxfa/include/fxfa_widget.h" |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 37 | #include "xfa/fxfa/include/xfa_ffdocview.h" |
dsinclair | 7222ea6 | 2016-04-06 14:33:07 -0700 | [diff] [blame] | 38 | #include "xfa/fxfa/include/xfa_ffwidget.h" |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 39 | #include "xfa/fxfa/include/xfa_ffwidgethandler.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 40 | #endif // PDF_ENABLE_XFA |
| 41 | |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 42 | namespace { |
| 43 | |
| 44 | // Convert a FX_ARGB to a FX_COLORREF. |
| 45 | FX_COLORREF ARGBToColorRef(FX_ARGB argb) { |
| 46 | return (((static_cast<uint32_t>(argb) & 0x00FF0000) >> 16) | |
| 47 | (static_cast<uint32_t>(argb) & 0x0000FF00) | |
| 48 | ((static_cast<uint32_t>(argb) & 0x000000FF) << 16)); |
| 49 | } |
| 50 | |
| 51 | } // namespace |
| 52 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 53 | CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, |
| 54 | CPDFSDK_PageView* pPageView, |
| 55 | CPDFSDK_InterForm* pInterForm) |
| 56 | : CPDFSDK_BAAnnot(pAnnot, pPageView), |
| 57 | m_pInterForm(pInterForm), |
| 58 | m_nAppAge(0), |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 59 | m_nValueAge(0) |
| 60 | #ifdef PDF_ENABLE_XFA |
| 61 | , |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 62 | m_hMixXFAWidget(nullptr), |
| 63 | m_pWidgetHandler(nullptr) |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 64 | #endif // PDF_ENABLE_XFA |
| 65 | { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 66 | } |
| 67 | |
dsinclair | ce04a45 | 2016-09-07 05:46:55 -0700 | [diff] [blame] | 68 | CPDFSDK_Widget::~CPDFSDK_Widget() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 69 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 70 | #ifdef PDF_ENABLE_XFA |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 71 | CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 72 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 73 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 74 | if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { |
| 75 | if (!m_hMixXFAWidget) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 76 | if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 77 | CFX_WideString sName; |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 78 | if (GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
| 79 | sName = GetAnnotName(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | if (sName.IsEmpty()) |
| 81 | sName = GetName(); |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 82 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 83 | sName = GetName(); |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 84 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 85 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 86 | if (!sName.IsEmpty()) |
weili | b4d1b57 | 2016-08-10 14:50:48 -0700 | [diff] [blame] | 87 | m_hMixXFAWidget = pDocView->GetWidgetByName(sName, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 88 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 89 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 90 | return m_hMixXFAWidget; |
| 91 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 92 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 93 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | } |
| 95 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 96 | CXFA_FFWidget* CPDFSDK_Widget::GetGroupMixXFAWidget() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 97 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 98 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 99 | if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 100 | if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 101 | CFX_WideString sName = GetName(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 102 | if (!sName.IsEmpty()) |
weili | b4d1b57 | 2016-08-10 14:50:48 -0700 | [diff] [blame] | 103 | return pDocView->GetWidgetByName(sName, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 107 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 108 | } |
| 109 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 110 | CXFA_FFWidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 111 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 112 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 113 | if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { |
| 114 | if (!m_pWidgetHandler) { |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 115 | if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 116 | m_pWidgetHandler = pDocView->GetWidgetHandler(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 117 | } |
| 118 | return m_pWidgetHandler; |
| 119 | } |
| 120 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 121 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) { |
| 125 | XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown; |
| 126 | |
| 127 | switch (eXFAAAT) { |
| 128 | case PDFSDK_XFA_Click: |
| 129 | eEventType = XFA_EVENT_Click; |
| 130 | break; |
| 131 | case PDFSDK_XFA_Full: |
| 132 | eEventType = XFA_EVENT_Full; |
| 133 | break; |
| 134 | case PDFSDK_XFA_PreOpen: |
| 135 | eEventType = XFA_EVENT_PreOpen; |
| 136 | break; |
| 137 | case PDFSDK_XFA_PostOpen: |
| 138 | eEventType = XFA_EVENT_PostOpen; |
| 139 | break; |
| 140 | } |
| 141 | |
| 142 | return eEventType; |
| 143 | } |
| 144 | |
| 145 | static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT, |
| 146 | FX_BOOL bWillCommit) { |
| 147 | XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown; |
| 148 | |
| 149 | switch (eAAT) { |
| 150 | case CPDF_AAction::CursorEnter: |
| 151 | eEventType = XFA_EVENT_MouseEnter; |
| 152 | break; |
| 153 | case CPDF_AAction::CursorExit: |
| 154 | eEventType = XFA_EVENT_MouseExit; |
| 155 | break; |
| 156 | case CPDF_AAction::ButtonDown: |
| 157 | eEventType = XFA_EVENT_MouseDown; |
| 158 | break; |
| 159 | case CPDF_AAction::ButtonUp: |
| 160 | eEventType = XFA_EVENT_MouseUp; |
| 161 | break; |
| 162 | case CPDF_AAction::GetFocus: |
| 163 | eEventType = XFA_EVENT_Enter; |
| 164 | break; |
| 165 | case CPDF_AAction::LoseFocus: |
| 166 | eEventType = XFA_EVENT_Exit; |
| 167 | break; |
| 168 | case CPDF_AAction::PageOpen: |
| 169 | break; |
| 170 | case CPDF_AAction::PageClose: |
| 171 | break; |
| 172 | case CPDF_AAction::PageVisible: |
| 173 | break; |
| 174 | case CPDF_AAction::PageInvisible: |
| 175 | break; |
| 176 | case CPDF_AAction::KeyStroke: |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 177 | if (!bWillCommit) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | eEventType = XFA_EVENT_Change; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 179 | break; |
| 180 | case CPDF_AAction::Validate: |
| 181 | eEventType = XFA_EVENT_Validate; |
| 182 | break; |
| 183 | case CPDF_AAction::OpenPage: |
| 184 | case CPDF_AAction::ClosePage: |
| 185 | case CPDF_AAction::Format: |
| 186 | case CPDF_AAction::Calculate: |
| 187 | case CPDF_AAction::CloseDocument: |
| 188 | case CPDF_AAction::SaveDocument: |
| 189 | case CPDF_AAction::DocumentSaved: |
| 190 | case CPDF_AAction::PrintDocument: |
| 191 | case CPDF_AAction::DocumentPrinted: |
| 192 | break; |
| 193 | } |
| 194 | |
| 195 | return eEventType; |
| 196 | } |
| 197 | |
| 198 | FX_BOOL CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) { |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 199 | CXFA_FFWidget* hWidget = GetMixXFAWidget(); |
| 200 | if (!hWidget) |
| 201 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 202 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 203 | CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler(); |
| 204 | if (!pXFAWidgetHandler) |
| 205 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 206 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 207 | XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); |
| 208 | |
| 209 | CXFA_WidgetAcc* pAcc; |
| 210 | if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && |
| 211 | GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
| 212 | if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) { |
| 213 | pAcc = hGroupWidget->GetDataAcc(); |
| 214 | if (pXFAWidgetHandler->HasEvent(pAcc, eEventType)) |
| 215 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 219 | pAcc = hWidget->GetDataAcc(); |
| 220 | return pXFAWidgetHandler->HasEvent(pAcc, eEventType); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, |
| 224 | PDFSDK_FieldAction& data, |
| 225 | CPDFSDK_PageView* pPageView) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 226 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 227 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 228 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 229 | CXFA_FFWidget* hWidget = GetMixXFAWidget(); |
| 230 | if (!hWidget) |
| 231 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 232 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 233 | XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); |
| 234 | if (eEventType == XFA_EVENT_Unknown) |
| 235 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 236 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 237 | CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler(); |
| 238 | if (!pXFAWidgetHandler) |
| 239 | return FALSE; |
| 240 | |
| 241 | CXFA_EventParam param; |
| 242 | param.m_eType = eEventType; |
| 243 | param.m_wsChange = data.sChange; |
| 244 | param.m_iCommitKey = data.nCommitKey; |
| 245 | param.m_bShift = data.bShift; |
| 246 | param.m_iSelStart = data.nSelStart; |
| 247 | param.m_iSelEnd = data.nSelEnd; |
| 248 | param.m_wsFullText = data.sValue; |
| 249 | param.m_bKeyDown = data.bKeyDown; |
| 250 | param.m_bModifier = data.bModifier; |
| 251 | param.m_wsNewText = data.sValue; |
| 252 | if (data.nSelEnd > data.nSelStart) |
| 253 | param.m_wsNewText.Delete(data.nSelStart, data.nSelEnd - data.nSelStart); |
| 254 | |
| 255 | for (int i = 0; i < data.sChange.GetLength(); i++) |
| 256 | param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]); |
| 257 | param.m_wsPrevText = data.sValue; |
| 258 | |
| 259 | if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && |
| 260 | GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
| 261 | if (CXFA_FFWidget* hGroupWidget = GetGroupMixXFAWidget()) { |
| 262 | CXFA_WidgetAcc* pAcc = hGroupWidget->GetDataAcc(); |
| 263 | param.m_pTarget = pAcc; |
| 264 | if (pXFAWidgetHandler->ProcessEvent(pAcc, ¶m) != |
| 265 | XFA_EVENTERROR_Success) { |
| 266 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 270 | CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc(); |
| 271 | param.m_pTarget = pAcc; |
| 272 | int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 273 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 274 | if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) |
| 275 | pDocView->UpdateDocView(); |
| 276 | |
| 277 | return nRet == XFA_EVENTERROR_Success; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | void CPDFSDK_Widget::Synchronize(FX_BOOL bSynchronizeElse) { |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 281 | CXFA_FFWidget* hWidget = GetMixXFAWidget(); |
| 282 | if (!hWidget) |
| 283 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 284 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 285 | CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc(); |
| 286 | if (!pWidgetAcc) |
| 287 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 288 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 289 | CPDF_FormField* pFormField = GetFormField(); |
| 290 | switch (GetFieldType()) { |
| 291 | case FIELDTYPE_CHECKBOX: |
| 292 | case FIELDTYPE_RADIOBUTTON: { |
| 293 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
| 294 | XFA_CHECKSTATE eCheckState = |
| 295 | pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off; |
| 296 | pWidgetAcc->SetCheckState(eCheckState, true); |
| 297 | break; |
| 298 | } |
| 299 | case FIELDTYPE_TEXTFIELD: |
| 300 | pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit); |
| 301 | break; |
| 302 | case FIELDTYPE_LISTBOX: { |
| 303 | pWidgetAcc->ClearAllSelections(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 304 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 305 | for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { |
| 306 | int nIndex = pFormField->GetSelectedIndex(i); |
| 307 | if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems()) |
| 308 | pWidgetAcc->SetItemState(nIndex, TRUE, false, FALSE, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 309 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 310 | break; |
| 311 | } |
| 312 | case FIELDTYPE_COMBOBOX: { |
| 313 | pWidgetAcc->ClearAllSelections(); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 314 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 315 | for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; i++) { |
| 316 | int nIndex = pFormField->GetSelectedIndex(i); |
| 317 | if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems()) |
| 318 | pWidgetAcc->SetItemState(nIndex, TRUE, false, FALSE, TRUE); |
| 319 | } |
| 320 | pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit); |
| 321 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 322 | } |
| 323 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 324 | |
| 325 | if (bSynchronizeElse) |
| 326 | pWidgetAcc->ProcessValueChanged(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | void CPDFSDK_Widget::SynchronizeXFAValue() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 330 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 331 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 332 | CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 333 | if (!pXFADocView) |
| 334 | return; |
| 335 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 336 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 337 | if (GetXFAWidgetHandler()) { |
| 338 | CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(), |
| 339 | GetFormControl()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | void CPDFSDK_Widget::SynchronizeXFAItems() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 345 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 346 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 347 | CXFA_FFDocView* pXFADocView = pDoc->GetXFADocView(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 348 | if (!pXFADocView) |
| 349 | return; |
| 350 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 351 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 352 | if (GetXFAWidgetHandler()) |
| 353 | SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 357 | void CPDFSDK_Widget::SynchronizeXFAValue(CXFA_FFDocView* pXFADocView, |
| 358 | CXFA_FFWidget* hWidget, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 359 | CPDF_FormField* pFormField, |
| 360 | CPDF_FormControl* pFormControl) { |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 361 | ASSERT(hWidget); |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 362 | ASSERT(pFormControl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 363 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 364 | switch (pFormField->GetFieldType()) { |
| 365 | case FIELDTYPE_CHECKBOX: { |
| 366 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 367 | pFormField->CheckControl( |
| 368 | pFormField->GetControlIndex(pFormControl), |
| 369 | pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true); |
| 370 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 371 | break; |
| 372 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 373 | case FIELDTYPE_RADIOBUTTON: { |
| 374 | // TODO(weili): Check whether we need to handle checkbox and radio |
| 375 | // button differently, otherwise, merge these two cases. |
| 376 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 377 | pFormField->CheckControl( |
| 378 | pFormField->GetControlIndex(pFormControl), |
| 379 | pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true); |
| 380 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 381 | break; |
| 382 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 383 | case FIELDTYPE_TEXTFIELD: { |
| 384 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 385 | CFX_WideString sValue; |
| 386 | pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display); |
| 387 | pFormField->SetValue(sValue, TRUE); |
| 388 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 389 | break; |
| 390 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 391 | case FIELDTYPE_LISTBOX: { |
| 392 | pFormField->ClearSelection(FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 393 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 394 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 395 | for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) { |
| 396 | int nIndex = pWidgetAcc->GetSelectedItem(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 397 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 398 | if (nIndex > -1 && nIndex < pFormField->CountOptions()) { |
| 399 | pFormField->SetItemSelection(nIndex, TRUE, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 400 | } |
| 401 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 402 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 403 | break; |
| 404 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 405 | case FIELDTYPE_COMBOBOX: { |
| 406 | pFormField->ClearSelection(FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 407 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 408 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 409 | for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) { |
| 410 | int nIndex = pWidgetAcc->GetSelectedItem(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 411 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 412 | if (nIndex > -1 && nIndex < pFormField->CountOptions()) { |
| 413 | pFormField->SetItemSelection(nIndex, TRUE, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 414 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 415 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 416 | |
| 417 | CFX_WideString sValue; |
| 418 | pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display); |
| 419 | pFormField->SetValue(sValue, TRUE); |
| 420 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 421 | break; |
| 422 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 426 | void CPDFSDK_Widget::SynchronizeXFAItems(CXFA_FFDocView* pXFADocView, |
| 427 | CXFA_FFWidget* hWidget, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 428 | CPDF_FormField* pFormField, |
| 429 | CPDF_FormControl* pFormControl) { |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 430 | ASSERT(hWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 431 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 432 | switch (pFormField->GetFieldType()) { |
| 433 | case FIELDTYPE_LISTBOX: { |
| 434 | pFormField->ClearSelection(FALSE); |
| 435 | pFormField->ClearOptions(TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 436 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 437 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 438 | for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz; i++) { |
| 439 | CFX_WideString swText; |
| 440 | pWidgetAcc->GetChoiceListItem(swText, i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 441 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 442 | pFormField->InsertOption(swText, i, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 443 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 444 | } |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 445 | break; |
| 446 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 447 | case FIELDTYPE_COMBOBOX: { |
| 448 | pFormField->ClearSelection(FALSE); |
| 449 | pFormField->ClearOptions(FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 450 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 451 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 452 | for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz; i++) { |
| 453 | CFX_WideString swText; |
| 454 | pWidgetAcc->GetChoiceListItem(swText, i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 455 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 456 | pFormField->InsertOption(swText, i, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 457 | } |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 458 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 459 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 460 | pFormField->SetValue(L"", TRUE); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 461 | break; |
| 462 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 463 | } |
| 464 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 465 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 466 | |
| 467 | FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid( |
| 468 | CPDF_Annot::AppearanceMode mode) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 469 | CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 470 | if (!pAP) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 471 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 472 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 473 | // Choose the right sub-ap |
| 474 | const FX_CHAR* ap_entry = "N"; |
| 475 | if (mode == CPDF_Annot::Down) |
| 476 | ap_entry = "D"; |
| 477 | else if (mode == CPDF_Annot::Rollover) |
| 478 | ap_entry = "R"; |
| 479 | if (!pAP->KeyExist(ap_entry)) |
| 480 | ap_entry = "N"; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 481 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 482 | // Get the AP stream or subdirectory |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 483 | CPDF_Object* psub = pAP->GetDirectObjectFor(ap_entry); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 484 | if (!psub) |
| 485 | return FALSE; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 486 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 487 | int nFieldType = GetFieldType(); |
| 488 | switch (nFieldType) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 489 | case FIELDTYPE_PUSHBUTTON: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 490 | case FIELDTYPE_COMBOBOX: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 491 | case FIELDTYPE_LISTBOX: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 492 | case FIELDTYPE_TEXTFIELD: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 493 | case FIELDTYPE_SIGNATURE: |
Dan Sinclair | aa435ba | 2015-10-22 16:45:48 -0400 | [diff] [blame] | 494 | return psub->IsStream(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 495 | case FIELDTYPE_CHECKBOX: |
| 496 | case FIELDTYPE_RADIOBUTTON: |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 497 | if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 498 | return !!pSubDict->GetStreamFor(GetAppState()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 499 | } |
| 500 | return FALSE; |
| 501 | } |
| 502 | return TRUE; |
| 503 | } |
| 504 | |
| 505 | int CPDFSDK_Widget::GetFieldType() const { |
dsinclair | 9282819 | 2016-08-17 13:28:51 -0700 | [diff] [blame] | 506 | CPDF_FormField* pField = GetFormField(); |
| 507 | return pField ? pField->GetFieldType() : FIELDTYPE_UNKNOWN; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | FX_BOOL CPDFSDK_Widget::IsAppearanceValid() { |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 511 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 512 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 513 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 514 | int nDocType = pDoc->GetDocType(); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 515 | if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA) |
| 516 | return TRUE; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 517 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 518 | return CPDFSDK_BAAnnot::IsAppearanceValid(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 519 | } |
| 520 | |
weili | 625ad66 | 2016-06-15 11:21:33 -0700 | [diff] [blame] | 521 | int CPDFSDK_Widget::GetLayoutOrder() const { |
| 522 | return 2; |
| 523 | } |
| 524 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 525 | int CPDFSDK_Widget::GetFieldFlags() const { |
| 526 | CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 527 | CPDF_FormControl* pFormControl = |
| 528 | pPDFInterForm->GetControlByDict(m_pAnnot->GetAnnotDict()); |
| 529 | CPDF_FormField* pFormField = pFormControl->GetField(); |
| 530 | return pFormField->GetFieldFlags(); |
| 531 | } |
| 532 | |
jaepark | 9ed9137 | 2016-08-26 16:16:10 -0700 | [diff] [blame] | 533 | bool CPDFSDK_Widget::IsSignatureWidget() const { |
| 534 | return GetFieldType() == FIELDTYPE_SIGNATURE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | CPDF_FormField* CPDFSDK_Widget::GetFormField() const { |
dsinclair | 9282819 | 2016-08-17 13:28:51 -0700 | [diff] [blame] | 538 | CPDF_FormControl* pControl = GetFormControl(); |
| 539 | return pControl ? pControl->GetField() : nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 543 | CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 544 | return pPDFInterForm->GetControlByDict(GetAnnotDict()); |
| 545 | } |
| 546 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 547 | CPDF_FormControl* CPDFSDK_Widget::GetFormControl( |
| 548 | CPDF_InterForm* pInterForm, |
| 549 | const CPDF_Dictionary* pAnnotDict) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 550 | ASSERT(pAnnotDict); |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 551 | return pInterForm->GetControlByDict(pAnnotDict); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | int CPDFSDK_Widget::GetRotate() const { |
| 555 | CPDF_FormControl* pCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 556 | return pCtrl->GetRotation() % 360; |
| 557 | } |
| 558 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 559 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 560 | CFX_WideString CPDFSDK_Widget::GetName() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 561 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 562 | return pFormField->GetFullName(); |
| 563 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 564 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 565 | |
| 566 | FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const { |
| 567 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 568 | int iColorType = 0; |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 569 | color = ARGBToColorRef(pFormCtrl->GetBackgroundColor(iColorType)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 570 | return iColorType != COLORTYPE_TRANSPARENT; |
| 571 | } |
| 572 | |
| 573 | FX_BOOL CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const { |
| 574 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 575 | int iColorType = 0; |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 576 | color = ARGBToColorRef(pFormCtrl->GetBorderColor(iColorType)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 577 | return iColorType != COLORTYPE_TRANSPARENT; |
| 578 | } |
| 579 | |
| 580 | FX_BOOL CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const { |
| 581 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 582 | CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 583 | if (!da.HasColor()) |
| 584 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 585 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 586 | FX_ARGB argb; |
| 587 | int iColorType = COLORTYPE_TRANSPARENT; |
| 588 | da.GetColor(argb, iColorType); |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 589 | color = ARGBToColorRef(argb); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 590 | return iColorType != COLORTYPE_TRANSPARENT; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | FX_FLOAT CPDFSDK_Widget::GetFontSize() const { |
| 594 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 595 | CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance(); |
| 596 | CFX_ByteString csFont = ""; |
| 597 | FX_FLOAT fFontSize = 0.0f; |
| 598 | pDa.GetFont(csFont, fFontSize); |
| 599 | |
| 600 | return fFontSize; |
| 601 | } |
| 602 | |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 603 | int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 604 | #ifdef PDF_ENABLE_XFA |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 605 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 606 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 607 | if (nIndex < pWidgetAcc->CountSelectedItems()) |
| 608 | return pWidgetAcc->GetSelectedItem(nIndex); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 609 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 610 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 611 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 612 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 613 | return pFormField->GetSelectedIndex(nIndex); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 616 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 617 | CFX_WideString CPDFSDK_Widget::GetValue(FX_BOOL bDisplay) const { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 618 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 619 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 620 | CFX_WideString sValue; |
| 621 | pWidgetAcc->GetValue( |
| 622 | sValue, bDisplay ? XFA_VALUEPICTURE_Display : XFA_VALUEPICTURE_Edit); |
| 623 | return sValue; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 624 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 625 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 626 | #else |
| 627 | CFX_WideString CPDFSDK_Widget::GetValue() const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 628 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 629 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 630 | return pFormField->GetValue(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 633 | CFX_WideString CPDFSDK_Widget::GetDefaultValue() const { |
| 634 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 635 | return pFormField->GetDefaultValue(); |
| 636 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 637 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 638 | CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const { |
| 639 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 640 | return pFormField->GetOptionLabel(nIndex); |
| 641 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 642 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 643 | int CPDFSDK_Widget::CountOptions() const { |
| 644 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 645 | return pFormField->CountOptions(); |
| 646 | } |
| 647 | |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 648 | FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 649 | #ifdef PDF_ENABLE_XFA |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 650 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 651 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) { |
| 652 | if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems()) |
| 653 | return pWidgetAcc->GetItemState(nIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 654 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 655 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 656 | } |
| 657 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 658 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 659 | CPDF_FormField* pFormField = GetFormField(); |
| 660 | return pFormField->IsItemSelected(nIndex); |
| 661 | } |
| 662 | |
| 663 | int CPDFSDK_Widget::GetTopVisibleIndex() const { |
| 664 | CPDF_FormField* pFormField = GetFormField(); |
| 665 | return pFormField->GetTopVisibleIndex(); |
| 666 | } |
| 667 | |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 668 | bool CPDFSDK_Widget::IsChecked() const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 669 | #ifdef PDF_ENABLE_XFA |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 670 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
| 671 | if (CXFA_WidgetAcc* pWidgetAcc = hWidget->GetDataAcc()) |
| 672 | return pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 673 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 674 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 675 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 676 | return pFormCtrl->IsChecked(); |
| 677 | } |
| 678 | |
| 679 | int CPDFSDK_Widget::GetAlignment() const { |
| 680 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 681 | return pFormCtrl->GetControlAlignment(); |
| 682 | } |
| 683 | |
| 684 | int CPDFSDK_Widget::GetMaxLen() const { |
| 685 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 686 | return pFormField->GetMaxLen(); |
| 687 | } |
| 688 | |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 689 | void CPDFSDK_Widget::SetCheck(bool bChecked, bool bNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 690 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 691 | CPDF_FormField* pFormField = pFormCtrl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 692 | pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, |
| 693 | bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 694 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 695 | if (!IsWidgetAppearanceValid(CPDF_Annot::Normal)) |
| 696 | ResetAppearance(TRUE); |
| 697 | if (!bNotify) |
| 698 | Synchronize(TRUE); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 699 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify) { |
| 703 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 704 | pFormField->SetValue(sValue, bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 705 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 706 | if (!bNotify) |
| 707 | Synchronize(TRUE); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 708 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {} |
| 712 | void CPDFSDK_Widget::SetOptionSelection(int index, |
| 713 | FX_BOOL bSelected, |
| 714 | FX_BOOL bNotify) { |
| 715 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 716 | pFormField->SetItemSelection(index, bSelected, bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 717 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 718 | if (!bNotify) |
| 719 | Synchronize(TRUE); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 720 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify) { |
| 724 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 725 | pFormField->ClearSelection(bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 726 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 727 | if (!bNotify) |
| 728 | Synchronize(TRUE); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 729 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | void CPDFSDK_Widget::SetTopVisibleIndex(int index) {} |
| 733 | |
| 734 | void CPDFSDK_Widget::SetAppModified() { |
| 735 | m_bAppModified = TRUE; |
| 736 | } |
| 737 | |
| 738 | void CPDFSDK_Widget::ClearAppModified() { |
| 739 | m_bAppModified = FALSE; |
| 740 | } |
| 741 | |
| 742 | FX_BOOL CPDFSDK_Widget::IsAppModified() const { |
| 743 | return m_bAppModified; |
| 744 | } |
| 745 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 746 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 747 | void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) { |
| 748 | switch (GetFieldType()) { |
| 749 | case FIELDTYPE_TEXTFIELD: |
| 750 | case FIELDTYPE_COMBOBOX: { |
tsepez | 8c2a8cd | 2016-09-07 15:29:11 -0700 | [diff] [blame] | 751 | FX_BOOL bFormatted = FALSE; |
| 752 | CFX_WideString sValue = OnFormat(bFormatted); |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 753 | ResetAppearance(bFormatted ? &sValue : nullptr, TRUE); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 754 | break; |
| 755 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 756 | default: |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 757 | ResetAppearance(nullptr, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 758 | break; |
| 759 | } |
| 760 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 761 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 762 | |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 763 | void CPDFSDK_Widget::ResetAppearance(const CFX_WideString* sValue, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 764 | FX_BOOL bValueChanged) { |
| 765 | SetAppModified(); |
| 766 | |
| 767 | m_nAppAge++; |
| 768 | if (m_nAppAge > 999999) |
| 769 | m_nAppAge = 0; |
| 770 | if (bValueChanged) |
| 771 | m_nValueAge++; |
| 772 | |
| 773 | int nFieldType = GetFieldType(); |
| 774 | |
| 775 | switch (nFieldType) { |
| 776 | case FIELDTYPE_PUSHBUTTON: |
| 777 | ResetAppearance_PushButton(); |
| 778 | break; |
| 779 | case FIELDTYPE_CHECKBOX: |
| 780 | ResetAppearance_CheckBox(); |
| 781 | break; |
| 782 | case FIELDTYPE_RADIOBUTTON: |
| 783 | ResetAppearance_RadioButton(); |
| 784 | break; |
| 785 | case FIELDTYPE_COMBOBOX: |
| 786 | ResetAppearance_ComboBox(sValue); |
| 787 | break; |
| 788 | case FIELDTYPE_LISTBOX: |
| 789 | ResetAppearance_ListBox(); |
| 790 | break; |
| 791 | case FIELDTYPE_TEXTFIELD: |
| 792 | ResetAppearance_TextField(sValue); |
| 793 | break; |
| 794 | } |
| 795 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 796 | m_pAnnot->ClearCachedAP(); |
| 797 | } |
| 798 | |
tsepez | 8c2a8cd | 2016-09-07 15:29:11 -0700 | [diff] [blame] | 799 | CFX_WideString CPDFSDK_Widget::OnFormat(FX_BOOL& bFormatted) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 800 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 801 | ASSERT(pFormField); |
tsepez | 8c2a8cd | 2016-09-07 15:29:11 -0700 | [diff] [blame] | 802 | return m_pInterForm->OnFormat(pFormField, bFormatted); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | void CPDFSDK_Widget::ResetFieldAppearance(FX_BOOL bValueChanged) { |
| 806 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 807 | ASSERT(pFormField); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 808 | m_pInterForm->ResetFieldAppearance(pFormField, nullptr, bValueChanged); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 812 | const CFX_Matrix* pUser2Device, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 813 | CPDF_Annot::AppearanceMode mode, |
| 814 | const CPDF_RenderOptions* pOptions) { |
| 815 | int nFieldType = GetFieldType(); |
| 816 | |
| 817 | if ((nFieldType == FIELDTYPE_CHECKBOX || |
| 818 | nFieldType == FIELDTYPE_RADIOBUTTON) && |
| 819 | mode == CPDF_Annot::Normal && |
| 820 | !IsWidgetAppearanceValid(CPDF_Annot::Normal)) { |
| 821 | CFX_PathData pathData; |
| 822 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 823 | CFX_FloatRect rcAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 824 | |
| 825 | pathData.AppendRect(rcAnnot.left, rcAnnot.bottom, rcAnnot.right, |
| 826 | rcAnnot.top); |
| 827 | |
| 828 | CFX_GraphStateData gsd; |
| 829 | gsd.m_LineWidth = 0.0f; |
| 830 | |
| 831 | pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA, |
| 832 | FXFILL_ALTERNATE); |
| 833 | } else { |
| 834 | CPDFSDK_BAAnnot::DrawAppearance(pDevice, pUser2Device, mode, pOptions); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | void CPDFSDK_Widget::UpdateField() { |
| 839 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 840 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 841 | m_pInterForm->UpdateField(pFormField); |
| 842 | } |
| 843 | |
| 844 | void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice, |
| 845 | CPDFSDK_PageView* pPageView) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 846 | int nFieldType = GetFieldType(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 847 | if (!m_pInterForm->IsNeedHighLight(nFieldType)) |
| 848 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 849 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 850 | CFX_FloatRect rc = GetRect(); |
| 851 | FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType); |
| 852 | uint8_t alpha = m_pInterForm->GetHighlightAlpha(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 853 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 854 | CFX_FloatRect rcDevice; |
| 855 | ASSERT(m_pInterForm->GetDocument()); |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 856 | CPDFSDK_Environment* pEnv = m_pInterForm->GetDocument()->GetEnv(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 857 | if (!pEnv) |
| 858 | return; |
| 859 | CFX_Matrix page2device; |
| 860 | pPageView->GetCurrentMatrix(page2device); |
| 861 | page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom), |
| 862 | rcDevice.left, rcDevice.bottom); |
| 863 | page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top), |
| 864 | rcDevice.right, rcDevice.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 865 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 866 | rcDevice.Normalize(); |
| 867 | |
| 868 | FX_ARGB argb = ArgbEncode((int)alpha, color); |
| 869 | FX_RECT rcDev((int)rcDevice.left, (int)rcDevice.top, (int)rcDevice.right, |
| 870 | (int)rcDevice.bottom); |
| 871 | pDevice->FillRect(&rcDev, argb); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | void CPDFSDK_Widget::ResetAppearance_PushButton() { |
| 875 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 876 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 877 | int32_t nLayout = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 878 | switch (pControl->GetTextPosition()) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 879 | case TEXTPOS_ICON: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 880 | nLayout = PPBL_ICON; |
| 881 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 882 | case TEXTPOS_BELOW: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 883 | nLayout = PPBL_ICONTOPLABELBOTTOM; |
| 884 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 885 | case TEXTPOS_ABOVE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 886 | nLayout = PPBL_LABELTOPICONBOTTOM; |
| 887 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 888 | case TEXTPOS_RIGHT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 889 | nLayout = PPBL_ICONLEFTLABELRIGHT; |
| 890 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 891 | case TEXTPOS_LEFT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 892 | nLayout = PPBL_LABELLEFTICONRIGHT; |
| 893 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 894 | case TEXTPOS_OVERLAID: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 895 | nLayout = PPBL_LABELOVERICON; |
| 896 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 897 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 898 | nLayout = PPBL_LABEL; |
| 899 | break; |
| 900 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 901 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 902 | CPWL_Color crBackground, crBorder; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 903 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 904 | int iColorType; |
| 905 | FX_FLOAT fc[4]; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 906 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 907 | pControl->GetOriginalBackgroundColor(iColorType, fc); |
| 908 | if (iColorType > 0) |
| 909 | crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 910 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 911 | pControl->GetOriginalBorderColor(iColorType, fc); |
| 912 | if (iColorType > 0) |
| 913 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 914 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 915 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 916 | CPWL_Dash dsBorder(3, 0, 0); |
| 917 | CPWL_Color crLeftTop, crRightBottom; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 918 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 919 | BorderStyle nBorderStyle = GetBorderStyle(); |
| 920 | switch (nBorderStyle) { |
| 921 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 922 | dsBorder = CPWL_Dash(3, 3, 0); |
| 923 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 924 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 925 | fBorderWidth *= 2; |
| 926 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 927 | crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); |
| 928 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 929 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 930 | fBorderWidth *= 2; |
| 931 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 932 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 933 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 934 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 935 | break; |
| 936 | } |
| 937 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 938 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 939 | |
| 940 | CPWL_Color crText(COLORTYPE_GRAY, 0); |
| 941 | |
| 942 | FX_FLOAT fFontSize = 12.0f; |
| 943 | CFX_ByteString csNameTag; |
| 944 | |
| 945 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 946 | if (da.HasColor()) { |
| 947 | da.GetColor(iColorType, fc); |
| 948 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 949 | } |
| 950 | |
| 951 | if (da.HasFont()) |
| 952 | da.GetFont(csNameTag, fFontSize); |
| 953 | |
| 954 | CFX_WideString csWCaption; |
| 955 | CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption; |
| 956 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 957 | if (pControl->HasMKEntry("CA")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 958 | csNormalCaption = pControl->GetNormalCaption(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 959 | |
| 960 | if (pControl->HasMKEntry("RC")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 961 | csRolloverCaption = pControl->GetRolloverCaption(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 962 | |
| 963 | if (pControl->HasMKEntry("AC")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 964 | csDownCaption = pControl->GetDownCaption(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 965 | |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 966 | CPDF_Stream* pNormalIcon = nullptr; |
| 967 | CPDF_Stream* pRolloverIcon = nullptr; |
| 968 | CPDF_Stream* pDownIcon = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 969 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 970 | if (pControl->HasMKEntry("I")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 971 | pNormalIcon = pControl->GetNormalIcon(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 972 | |
| 973 | if (pControl->HasMKEntry("RI")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 974 | pRolloverIcon = pControl->GetRolloverIcon(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 975 | |
| 976 | if (pControl->HasMKEntry("IX")) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 977 | pDownIcon = pControl->GetDownIcon(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 978 | |
| 979 | if (pNormalIcon) { |
| 980 | if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 981 | if (pImageDict->GetStringFor("Name").IsEmpty()) |
| 982 | pImageDict->SetStringFor("Name", "ImgA"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | |
| 986 | if (pRolloverIcon) { |
| 987 | if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 988 | if (pImageDict->GetStringFor("Name").IsEmpty()) |
| 989 | pImageDict->SetStringFor("Name", "ImgB"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
| 993 | if (pDownIcon) { |
| 994 | if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 995 | if (pImageDict->GetStringFor("Name").IsEmpty()) |
| 996 | pImageDict->SetStringFor("Name", "ImgC"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 997 | } |
| 998 | } |
| 999 | |
| 1000 | CPDF_IconFit iconFit = pControl->GetIconFit(); |
| 1001 | |
| 1002 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 1003 | CPDFSDK_Environment* pEnv = pDoc->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1004 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1005 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1006 | font_map.SetAPType("N"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1007 | |
| 1008 | CFX_ByteString csAP = |
| 1009 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1010 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1011 | crLeftTop, crRightBottom, nBorderStyle, |
| 1012 | dsBorder) + |
| 1013 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1014 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1015 | pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout); |
| 1016 | |
| 1017 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP); |
| 1018 | if (pNormalIcon) |
| 1019 | AddImageToAppearance("N", pNormalIcon); |
| 1020 | |
| 1021 | CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode(); |
| 1022 | if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) { |
| 1023 | if (csRolloverCaption.IsEmpty() && !pRolloverIcon) { |
| 1024 | csRolloverCaption = csNormalCaption; |
| 1025 | pRolloverIcon = pNormalIcon; |
| 1026 | } |
| 1027 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1028 | font_map.SetAPType("R"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1029 | |
| 1030 | csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1031 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1032 | crLeftTop, crRightBottom, |
| 1033 | nBorderStyle, dsBorder) + |
| 1034 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1035 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1036 | pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize, |
| 1037 | nLayout); |
| 1038 | |
| 1039 | WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP); |
| 1040 | if (pRolloverIcon) |
| 1041 | AddImageToAppearance("R", pRolloverIcon); |
| 1042 | |
| 1043 | if (csDownCaption.IsEmpty() && !pDownIcon) { |
| 1044 | csDownCaption = csNormalCaption; |
| 1045 | pDownIcon = pNormalIcon; |
| 1046 | } |
| 1047 | |
| 1048 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1049 | case BorderStyle::BEVELED: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1050 | CPWL_Color crTemp = crLeftTop; |
| 1051 | crLeftTop = crRightBottom; |
| 1052 | crRightBottom = crTemp; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1053 | break; |
| 1054 | } |
| 1055 | case BorderStyle::INSET: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1056 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1057 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1058 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1059 | } |
| 1060 | default: |
| 1061 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1062 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1063 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1064 | font_map.SetAPType("D"); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1065 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1066 | csAP = CPWL_Utils::GetRectFillAppStream( |
| 1067 | rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) + |
| 1068 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1069 | crLeftTop, crRightBottom, |
| 1070 | nBorderStyle, dsBorder) + |
| 1071 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1072 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1073 | pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1074 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1075 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1076 | if (pDownIcon) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1077 | AddImageToAppearance("D", pDownIcon); |
| 1078 | } else { |
| 1079 | RemoveAppearance("D"); |
| 1080 | RemoveAppearance("R"); |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | void CPDFSDK_Widget::ResetAppearance_CheckBox() { |
| 1085 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1086 | CPWL_Color crBackground, crBorder, crText; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1087 | int iColorType; |
| 1088 | FX_FLOAT fc[4]; |
| 1089 | |
| 1090 | pControl->GetOriginalBackgroundColor(iColorType, fc); |
| 1091 | if (iColorType > 0) |
| 1092 | crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1093 | |
| 1094 | pControl->GetOriginalBorderColor(iColorType, fc); |
| 1095 | if (iColorType > 0) |
| 1096 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1097 | |
| 1098 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1099 | CPWL_Dash dsBorder(3, 0, 0); |
| 1100 | CPWL_Color crLeftTop, crRightBottom; |
| 1101 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1102 | BorderStyle nBorderStyle = GetBorderStyle(); |
| 1103 | switch (nBorderStyle) { |
| 1104 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1105 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1106 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1107 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1108 | fBorderWidth *= 2; |
| 1109 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1110 | crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); |
| 1111 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1112 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1113 | fBorderWidth *= 2; |
| 1114 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1115 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1116 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1117 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1118 | break; |
| 1119 | } |
| 1120 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1121 | CFX_FloatRect rcWindow = GetRotatedRect(); |
| 1122 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1123 | |
| 1124 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 1125 | if (da.HasColor()) { |
| 1126 | da.GetColor(iColorType, fc); |
| 1127 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1128 | } |
| 1129 | |
| 1130 | int32_t nStyle = 0; |
| 1131 | |
| 1132 | CFX_WideString csWCaption = pControl->GetNormalCaption(); |
| 1133 | if (csWCaption.GetLength() > 0) { |
| 1134 | switch (csWCaption[0]) { |
| 1135 | case L'l': |
| 1136 | nStyle = PCS_CIRCLE; |
| 1137 | break; |
| 1138 | case L'8': |
| 1139 | nStyle = PCS_CROSS; |
| 1140 | break; |
| 1141 | case L'u': |
| 1142 | nStyle = PCS_DIAMOND; |
| 1143 | break; |
| 1144 | case L'n': |
| 1145 | nStyle = PCS_SQUARE; |
| 1146 | break; |
| 1147 | case L'H': |
| 1148 | nStyle = PCS_STAR; |
| 1149 | break; |
| 1150 | default: // L'4' |
| 1151 | nStyle = PCS_CHECK; |
| 1152 | break; |
| 1153 | } |
| 1154 | } else { |
| 1155 | nStyle = PCS_CHECK; |
| 1156 | } |
| 1157 | |
| 1158 | CFX_ByteString csAP_N_ON = |
| 1159 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1160 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1161 | crLeftTop, crRightBottom, nBorderStyle, |
| 1162 | dsBorder); |
| 1163 | |
| 1164 | CFX_ByteString csAP_N_OFF = csAP_N_ON; |
| 1165 | |
| 1166 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1167 | case BorderStyle::BEVELED: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1168 | CPWL_Color crTemp = crLeftTop; |
| 1169 | crLeftTop = crRightBottom; |
| 1170 | crRightBottom = crTemp; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1171 | break; |
| 1172 | } |
| 1173 | case BorderStyle::INSET: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1174 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1175 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1176 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1177 | } |
| 1178 | default: |
| 1179 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | CFX_ByteString csAP_D_ON = |
| 1183 | CPWL_Utils::GetRectFillAppStream( |
| 1184 | rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) + |
| 1185 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1186 | crLeftTop, crRightBottom, nBorderStyle, |
| 1187 | dsBorder); |
| 1188 | |
| 1189 | CFX_ByteString csAP_D_OFF = csAP_D_ON; |
| 1190 | |
| 1191 | csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText); |
| 1192 | csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText); |
| 1193 | |
| 1194 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, |
| 1195 | pControl->GetCheckedAPState()); |
| 1196 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off"); |
| 1197 | |
| 1198 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, |
| 1199 | pControl->GetCheckedAPState()); |
| 1200 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); |
| 1201 | |
| 1202 | CFX_ByteString csAS = GetAppState(); |
| 1203 | if (csAS.IsEmpty()) |
| 1204 | SetAppState("Off"); |
| 1205 | } |
| 1206 | |
| 1207 | void CPDFSDK_Widget::ResetAppearance_RadioButton() { |
| 1208 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1209 | CPWL_Color crBackground, crBorder, crText; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1210 | int iColorType; |
| 1211 | FX_FLOAT fc[4]; |
| 1212 | |
| 1213 | pControl->GetOriginalBackgroundColor(iColorType, fc); |
| 1214 | if (iColorType > 0) |
| 1215 | crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1216 | |
| 1217 | pControl->GetOriginalBorderColor(iColorType, fc); |
| 1218 | if (iColorType > 0) |
| 1219 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1220 | |
| 1221 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1222 | CPWL_Dash dsBorder(3, 0, 0); |
| 1223 | CPWL_Color crLeftTop, crRightBottom; |
| 1224 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1225 | BorderStyle nBorderStyle = GetBorderStyle(); |
| 1226 | switch (nBorderStyle) { |
| 1227 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1228 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1229 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1230 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1231 | fBorderWidth *= 2; |
| 1232 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1233 | crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); |
| 1234 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1235 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1236 | fBorderWidth *= 2; |
| 1237 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1238 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1239 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1240 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1241 | break; |
| 1242 | } |
| 1243 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1244 | CFX_FloatRect rcWindow = GetRotatedRect(); |
| 1245 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1246 | |
| 1247 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 1248 | if (da.HasColor()) { |
| 1249 | da.GetColor(iColorType, fc); |
| 1250 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1251 | } |
| 1252 | |
| 1253 | int32_t nStyle = 0; |
| 1254 | |
| 1255 | CFX_WideString csWCaption = pControl->GetNormalCaption(); |
| 1256 | if (csWCaption.GetLength() > 0) { |
| 1257 | switch (csWCaption[0]) { |
| 1258 | default: // L'l': |
| 1259 | nStyle = PCS_CIRCLE; |
| 1260 | break; |
| 1261 | case L'8': |
| 1262 | nStyle = PCS_CROSS; |
| 1263 | break; |
| 1264 | case L'u': |
| 1265 | nStyle = PCS_DIAMOND; |
| 1266 | break; |
| 1267 | case L'n': |
| 1268 | nStyle = PCS_SQUARE; |
| 1269 | break; |
| 1270 | case L'H': |
| 1271 | nStyle = PCS_STAR; |
| 1272 | break; |
| 1273 | case L'4': |
| 1274 | nStyle = PCS_CHECK; |
| 1275 | break; |
| 1276 | } |
| 1277 | } else { |
| 1278 | nStyle = PCS_CIRCLE; |
| 1279 | } |
| 1280 | |
| 1281 | CFX_ByteString csAP_N_ON; |
| 1282 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1283 | CFX_FloatRect rcCenter = |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1284 | CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f); |
| 1285 | |
| 1286 | if (nStyle == PCS_CIRCLE) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1287 | if (nBorderStyle == BorderStyle::BEVELED) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1288 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1289 | crRightBottom = CPWL_Utils::SubstractColor(crBackground, 0.25f); |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1290 | } else if (nBorderStyle == BorderStyle::INSET) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1291 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5f); |
| 1292 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75f); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1293 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1294 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1295 | csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBackground) + |
| 1296 | CPWL_Utils::GetCircleBorderAppStream( |
| 1297 | rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom, |
| 1298 | nBorderStyle, dsBorder); |
| 1299 | } else { |
| 1300 | csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1301 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1302 | crLeftTop, crRightBottom, |
| 1303 | nBorderStyle, dsBorder); |
| 1304 | } |
| 1305 | |
| 1306 | CFX_ByteString csAP_N_OFF = csAP_N_ON; |
| 1307 | |
| 1308 | switch (nBorderStyle) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1309 | case BorderStyle::BEVELED: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1310 | CPWL_Color crTemp = crLeftTop; |
| 1311 | crLeftTop = crRightBottom; |
| 1312 | crRightBottom = crTemp; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1313 | break; |
| 1314 | } |
| 1315 | case BorderStyle::INSET: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1316 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1317 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1318 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1319 | } |
| 1320 | default: |
| 1321 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | CFX_ByteString csAP_D_ON; |
| 1325 | |
| 1326 | if (nStyle == PCS_CIRCLE) { |
| 1327 | CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground, 0.25f); |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1328 | if (nBorderStyle == BorderStyle::BEVELED) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1329 | crLeftTop = CPWL_Utils::SubstractColor(crBackground, 0.25f); |
| 1330 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1331 | crBK = crBackground; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1332 | } else if (nBorderStyle == BorderStyle::INSET) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1333 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1334 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1335 | } |
| 1336 | |
| 1337 | csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBK) + |
| 1338 | CPWL_Utils::GetCircleBorderAppStream( |
| 1339 | rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom, |
| 1340 | nBorderStyle, dsBorder); |
| 1341 | } else { |
| 1342 | csAP_D_ON = CPWL_Utils::GetRectFillAppStream( |
| 1343 | rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) + |
| 1344 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1345 | crLeftTop, crRightBottom, |
| 1346 | nBorderStyle, dsBorder); |
| 1347 | } |
| 1348 | |
| 1349 | CFX_ByteString csAP_D_OFF = csAP_D_ON; |
| 1350 | |
| 1351 | csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText); |
| 1352 | csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText); |
| 1353 | |
| 1354 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, |
| 1355 | pControl->GetCheckedAPState()); |
| 1356 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off"); |
| 1357 | |
| 1358 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, |
| 1359 | pControl->GetCheckedAPState()); |
| 1360 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); |
| 1361 | |
| 1362 | CFX_ByteString csAS = GetAppState(); |
| 1363 | if (csAS.IsEmpty()) |
| 1364 | SetAppState("Off"); |
| 1365 | } |
| 1366 | |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1367 | void CPDFSDK_Widget::ResetAppearance_ComboBox(const CFX_WideString* sValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1368 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1369 | CPDF_FormField* pField = pControl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1370 | CFX_ByteTextBuf sBody, sLines; |
| 1371 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1372 | CFX_FloatRect rcClient = GetClientRect(); |
| 1373 | CFX_FloatRect rcButton = rcClient; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1374 | rcButton.left = rcButton.right - 13; |
| 1375 | rcButton.Normalize(); |
| 1376 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 1377 | std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1378 | pEdit->EnableRefresh(FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1379 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1380 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 1381 | CPDFSDK_Environment* pEnv = pDoc->GetEnv(); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1382 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1383 | pEdit->SetFontMap(&font_map); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1384 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1385 | CFX_FloatRect rcEdit = rcClient; |
| 1386 | rcEdit.right = rcButton.left; |
| 1387 | rcEdit.Normalize(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1388 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1389 | pEdit->SetPlateRect(rcEdit); |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1390 | pEdit->SetAlignmentV(1, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1391 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1392 | FX_FLOAT fFontSize = GetFontSize(); |
| 1393 | if (IsFloatZero(fFontSize)) |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1394 | pEdit->SetAutoFontSize(TRUE, TRUE); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1395 | else |
| 1396 | pEdit->SetFontSize(fFontSize); |
| 1397 | |
| 1398 | pEdit->Initialize(); |
| 1399 | |
| 1400 | if (sValue) { |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1401 | pEdit->SetText(*sValue); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1402 | } else { |
| 1403 | int32_t nCurSel = pField->GetSelectedIndex(0); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1404 | if (nCurSel < 0) |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 1405 | pEdit->SetText(pField->GetValue()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1406 | else |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 1407 | pEdit->SetText(pField->GetOptionLabel(nCurSel)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1408 | } |
| 1409 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1410 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
| 1411 | |
| 1412 | CFX_ByteString sEdit = |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 1413 | CPWL_Utils::GetEditAppStream(pEdit.get(), CFX_FloatPoint()); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1414 | if (sEdit.GetLength() > 0) { |
| 1415 | sBody << "/Tx BMC\n" |
| 1416 | << "q\n"; |
| 1417 | if (rcContent.Width() > rcEdit.Width() || |
| 1418 | rcContent.Height() > rcEdit.Height()) { |
| 1419 | sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width() |
| 1420 | << " " << rcEdit.Height() << " re\nW\nn\n"; |
| 1421 | } |
| 1422 | |
| 1423 | CPWL_Color crText = GetTextPWLColor(); |
| 1424 | sBody << "BT\n" |
| 1425 | << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" |
| 1426 | << "Q\nEMC\n"; |
| 1427 | } |
| 1428 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1429 | sBody << CPWL_Utils::GetDropButtonAppStream(rcButton); |
| 1430 | |
| 1431 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
tsepez | 8e4c505 | 2016-04-14 13:42:44 -0700 | [diff] [blame] | 1432 | sLines.AsStringC() + sBody.AsStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1433 | |
| 1434 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
| 1435 | } |
| 1436 | |
| 1437 | void CPDFSDK_Widget::ResetAppearance_ListBox() { |
| 1438 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1439 | CPDF_FormField* pField = pControl->GetField(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1440 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1441 | CFX_ByteTextBuf sBody, sLines; |
| 1442 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 1443 | std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1444 | pEdit->EnableRefresh(FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1445 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1446 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 1447 | CPDFSDK_Environment* pEnv = pDoc->GetEnv(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1448 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1449 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1450 | pEdit->SetFontMap(&font_map); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1451 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1452 | pEdit->SetPlateRect(CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1453 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1454 | FX_FLOAT fFontSize = GetFontSize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1455 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1456 | pEdit->SetFontSize(IsFloatZero(fFontSize) ? 12.0f : fFontSize); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1457 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1458 | pEdit->Initialize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1459 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1460 | CFX_ByteTextBuf sList; |
| 1461 | FX_FLOAT fy = rcClient.top; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1462 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1463 | int32_t nTop = pField->GetTopVisibleIndex(); |
| 1464 | int32_t nCount = pField->CountOptions(); |
| 1465 | int32_t nSelCount = pField->CountSelectedItems(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1466 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1467 | for (int32_t i = nTop; i < nCount; ++i) { |
| 1468 | bool bSelected = false; |
| 1469 | for (int32_t j = 0; j < nSelCount; ++j) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1470 | if (pField->GetSelectedIndex(j) == i) { |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1471 | bSelected = true; |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1472 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1473 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1474 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1475 | |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 1476 | pEdit->SetText(pField->GetOptionLabel(i)); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1477 | |
| 1478 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
| 1479 | FX_FLOAT fItemHeight = rcContent.Height(); |
| 1480 | |
| 1481 | if (bSelected) { |
| 1482 | CFX_FloatRect rcItem = |
| 1483 | CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy); |
| 1484 | sList << "q\n" |
| 1485 | << CPWL_Utils::GetColorAppStream( |
| 1486 | CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, |
| 1487 | 113.0f / 255.0f), |
| 1488 | TRUE) |
| 1489 | << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() |
| 1490 | << " " << rcItem.Height() << " re f\n" |
| 1491 | << "Q\n"; |
| 1492 | |
| 1493 | sList << "BT\n" |
| 1494 | << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1), |
| 1495 | TRUE) |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 1496 | << CPWL_Utils::GetEditAppStream(pEdit.get(), |
| 1497 | CFX_FloatPoint(0.0f, fy)) |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1498 | << "ET\n"; |
| 1499 | } else { |
| 1500 | CPWL_Color crText = GetTextPWLColor(); |
| 1501 | sList << "BT\n" |
| 1502 | << CPWL_Utils::GetColorAppStream(crText, TRUE) |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 1503 | << CPWL_Utils::GetEditAppStream(pEdit.get(), |
| 1504 | CFX_FloatPoint(0.0f, fy)) |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1505 | << "ET\n"; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1506 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1507 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1508 | fy -= fItemHeight; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1509 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1510 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1511 | if (sList.GetSize() > 0) { |
| 1512 | sBody << "/Tx BMC\n" |
| 1513 | << "q\n" |
| 1514 | << rcClient.left << " " << rcClient.bottom << " " << rcClient.Width() |
| 1515 | << " " << rcClient.Height() << " re\nW\nn\n"; |
| 1516 | sBody << sList << "Q\nEMC\n"; |
| 1517 | } |
| 1518 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1519 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
tsepez | 8e4c505 | 2016-04-14 13:42:44 -0700 | [diff] [blame] | 1520 | sLines.AsStringC() + sBody.AsStringC(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1521 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1522 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1525 | void CPDFSDK_Widget::ResetAppearance_TextField(const CFX_WideString* sValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1526 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1527 | CPDF_FormField* pField = pControl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1528 | CFX_ByteTextBuf sBody, sLines; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1529 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 1530 | std::unique_ptr<CFX_Edit> pEdit(new CFX_Edit); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1531 | pEdit->EnableRefresh(FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1532 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1533 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 1534 | CPDFSDK_Environment* pEnv = pDoc->GetEnv(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1535 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1536 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1537 | pEdit->SetFontMap(&font_map); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1538 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1539 | CFX_FloatRect rcClient = GetClientRect(); |
| 1540 | pEdit->SetPlateRect(rcClient); |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1541 | pEdit->SetAlignmentH(pControl->GetControlAlignment(), TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1542 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1543 | uint32_t dwFieldFlags = pField->GetFieldFlags(); |
| 1544 | FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1545 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1546 | if (bMultiLine) { |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1547 | pEdit->SetMultiLine(TRUE, TRUE); |
| 1548 | pEdit->SetAutoReturn(TRUE, TRUE); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1549 | } else { |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1550 | pEdit->SetAlignmentV(1, TRUE); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1551 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1552 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1553 | uint16_t subWord = 0; |
| 1554 | if ((dwFieldFlags >> 13) & 1) { |
| 1555 | subWord = '*'; |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1556 | pEdit->SetPasswordChar(subWord, TRUE); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1557 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1558 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1559 | int nMaxLen = pField->GetMaxLen(); |
| 1560 | FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1; |
| 1561 | FX_FLOAT fFontSize = GetFontSize(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1562 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 1563 | #ifdef PDF_ENABLE_XFA |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1564 | CFX_WideString sValueTmp; |
| 1565 | if (!sValue && GetMixXFAWidget()) { |
| 1566 | sValueTmp = GetValue(TRUE); |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1567 | sValue = &sValueTmp; |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1568 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1569 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1570 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1571 | if (nMaxLen > 0) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1572 | if (bCharArray) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1573 | pEdit->SetCharArray(nMaxLen); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1574 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1575 | if (IsFloatZero(fFontSize)) { |
| 1576 | fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(font_map.GetPDFFont(0), |
| 1577 | rcClient, nMaxLen); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1578 | } |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1579 | } else { |
| 1580 | if (sValue) |
tsepez | a31da74 | 2016-09-08 11:28:14 -0700 | [diff] [blame] | 1581 | nMaxLen = sValue->GetLength(); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1582 | pEdit->SetLimitChar(nMaxLen); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1583 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1586 | if (IsFloatZero(fFontSize)) |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 1587 | pEdit->SetAutoFontSize(TRUE, TRUE); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1588 | else |
| 1589 | pEdit->SetFontSize(fFontSize); |
| 1590 | |
| 1591 | pEdit->Initialize(); |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 1592 | pEdit->SetText(sValue ? *sValue : pField->GetValue()); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1593 | |
| 1594 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1595 | CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream( |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 1596 | pEdit.get(), CFX_FloatPoint(), nullptr, !bCharArray, subWord); |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1597 | |
| 1598 | if (sEdit.GetLength() > 0) { |
| 1599 | sBody << "/Tx BMC\n" |
| 1600 | << "q\n"; |
| 1601 | if (rcContent.Width() > rcClient.Width() || |
| 1602 | rcContent.Height() > rcClient.Height()) { |
| 1603 | sBody << rcClient.left << " " << rcClient.bottom << " " |
| 1604 | << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; |
| 1605 | } |
| 1606 | CPWL_Color crText = GetTextPWLColor(); |
| 1607 | sBody << "BT\n" |
| 1608 | << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" |
| 1609 | << "Q\nEMC\n"; |
| 1610 | } |
| 1611 | |
| 1612 | if (bCharArray) { |
| 1613 | switch (GetBorderStyle()) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1614 | case BorderStyle::SOLID: { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1615 | CFX_ByteString sColor = |
| 1616 | CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); |
| 1617 | if (sColor.GetLength() > 0) { |
| 1618 | sLines << "q\n" |
| 1619 | << GetBorderWidth() << " w\n" |
| 1620 | << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) |
| 1621 | << " 2 J 0 j\n"; |
| 1622 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1623 | for (int32_t i = 1; i < nMaxLen; ++i) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1624 | sLines << rcClient.left + |
| 1625 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1626 | << " " << rcClient.bottom << " m\n" |
| 1627 | << rcClient.left + |
| 1628 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1629 | << " " << rcClient.top << " l S\n"; |
| 1630 | } |
| 1631 | |
| 1632 | sLines << "Q\n"; |
| 1633 | } |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1634 | break; |
| 1635 | } |
| 1636 | case BorderStyle::DASH: { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1637 | CFX_ByteString sColor = |
| 1638 | CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); |
| 1639 | if (sColor.GetLength() > 0) { |
| 1640 | CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0); |
| 1641 | |
| 1642 | sLines << "q\n" |
| 1643 | << GetBorderWidth() << " w\n" |
| 1644 | << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) |
| 1645 | << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] " |
| 1646 | << dsBorder.nPhase << " d\n"; |
| 1647 | |
thestig | 594b20b | 2016-05-12 21:56:43 -0700 | [diff] [blame] | 1648 | for (int32_t i = 1; i < nMaxLen; ++i) { |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1649 | sLines << rcClient.left + |
| 1650 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1651 | << " " << rcClient.bottom << " m\n" |
| 1652 | << rcClient.left + |
| 1653 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1654 | << " " << rcClient.top << " l S\n"; |
| 1655 | } |
| 1656 | |
| 1657 | sLines << "Q\n"; |
| 1658 | } |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1659 | break; |
| 1660 | } |
| 1661 | default: |
| 1662 | break; |
thestig | 732f6a0 | 2016-05-12 10:41:56 -0700 | [diff] [blame] | 1663 | } |
| 1664 | } |
| 1665 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1666 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
tsepez | 8e4c505 | 2016-04-14 13:42:44 -0700 | [diff] [blame] | 1667 | sLines.AsStringC() + sBody.AsStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1668 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1669 | } |
| 1670 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1671 | CFX_FloatRect CPDFSDK_Widget::GetClientRect() const { |
| 1672 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1673 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
| 1674 | switch (GetBorderStyle()) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1675 | case BorderStyle::BEVELED: |
| 1676 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1677 | fBorderWidth *= 2.0f; |
| 1678 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1679 | default: |
| 1680 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1684 | } |
| 1685 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1686 | CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const { |
| 1687 | CFX_FloatRect rectAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1688 | FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left; |
| 1689 | FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom; |
| 1690 | |
| 1691 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1692 | CFX_FloatRect rcPDFWindow; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1693 | switch (abs(pControl->GetRotation() % 360)) { |
| 1694 | case 0: |
| 1695 | case 180: |
| 1696 | default: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1697 | rcPDFWindow = CFX_FloatRect(0, 0, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1698 | break; |
| 1699 | case 90: |
| 1700 | case 270: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1701 | rcPDFWindow = CFX_FloatRect(0, 0, fHeight, fWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1702 | break; |
| 1703 | } |
| 1704 | |
| 1705 | return rcPDFWindow; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1706 | } |
| 1707 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1708 | CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const { |
| 1709 | CPWL_Color crBackground = GetFillPWLColor(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 1710 | if (crBackground.nColorType != COLORTYPE_TRANSPARENT) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1711 | return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 1712 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1713 | return ""; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1716 | CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1717 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1718 | CPWL_Color crBorder = GetBorderPWLColor(); |
| 1719 | CPWL_Color crBackground = GetFillPWLColor(); |
| 1720 | CPWL_Color crLeftTop, crRightBottom; |
| 1721 | |
| 1722 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1723 | CPWL_Dash dsBorder(3, 0, 0); |
| 1724 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1725 | BorderStyle nBorderStyle = GetBorderStyle(); |
| 1726 | switch (nBorderStyle) { |
| 1727 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1728 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1729 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1730 | case BorderStyle::BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1731 | fBorderWidth *= 2; |
| 1732 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1733 | crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); |
| 1734 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 1735 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1736 | fBorderWidth *= 2; |
| 1737 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1738 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1739 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1740 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1741 | break; |
| 1742 | } |
| 1743 | |
| 1744 | return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1745 | crLeftTop, crRightBottom, nBorderStyle, |
| 1746 | dsBorder); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1749 | CFX_Matrix CPDFSDK_Widget::GetMatrix() const { |
| 1750 | CFX_Matrix mt; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1751 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1752 | CFX_FloatRect rcAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1753 | FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left; |
| 1754 | FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom; |
| 1755 | |
| 1756 | switch (abs(pControl->GetRotation() % 360)) { |
| 1757 | case 0: |
| 1758 | default: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1759 | mt = CFX_Matrix(1, 0, 0, 1, 0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1760 | break; |
| 1761 | case 90: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1762 | mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1763 | break; |
| 1764 | case 180: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1765 | mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1766 | break; |
| 1767 | case 270: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1768 | mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1769 | break; |
| 1770 | } |
| 1771 | |
| 1772 | return mt; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1773 | } |
| 1774 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1775 | CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const { |
| 1776 | CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1777 | |
| 1778 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1779 | CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); |
| 1780 | if (da.HasColor()) { |
| 1781 | int32_t iColorType; |
| 1782 | FX_FLOAT fc[4]; |
| 1783 | da.GetColor(iColorType, fc); |
| 1784 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1785 | } |
| 1786 | |
| 1787 | return crText; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1788 | } |
| 1789 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1790 | CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const { |
| 1791 | CPWL_Color crBorder; |
| 1792 | |
| 1793 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1794 | int32_t iColorType; |
| 1795 | FX_FLOAT fc[4]; |
| 1796 | pFormCtrl->GetOriginalBorderColor(iColorType, fc); |
| 1797 | if (iColorType > 0) |
| 1798 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1799 | |
| 1800 | return crBorder; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1803 | CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const { |
| 1804 | CPWL_Color crFill; |
| 1805 | |
| 1806 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1807 | int32_t iColorType; |
| 1808 | FX_FLOAT fc[4]; |
| 1809 | pFormCtrl->GetOriginalBackgroundColor(iColorType, fc); |
| 1810 | if (iColorType > 0) |
| 1811 | crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1812 | |
| 1813 | return crFill; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1814 | } |
| 1815 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1816 | void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, |
| 1817 | CPDF_Stream* pImage) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 1818 | CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP"); |
| 1819 | CPDF_Stream* pStream = pAPDict->GetStreamFor(sAPType); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1820 | CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1821 | CFX_ByteString sImageAlias = "IMG"; |
| 1822 | |
| 1823 | if (CPDF_Dictionary* pImageDict = pImage->GetDict()) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 1824 | sImageAlias = pImageDict->GetStringFor("Name"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1825 | if (sImageAlias.IsEmpty()) |
| 1826 | sImageAlias = "IMG"; |
| 1827 | } |
| 1828 | |
tsepez | 698c571 | 2016-09-28 16:47:07 -0700 | [diff] [blame] | 1829 | CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 1830 | CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1831 | if (!pStreamResList) { |
tsepez | 698c571 | 2016-09-28 16:47:07 -0700 | [diff] [blame] | 1832 | pStreamResList = new CPDF_Dictionary(pDoc->GetByteStringPool()); |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 1833 | pStreamDict->SetFor("Resources", pStreamResList); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1834 | } |
| 1835 | |
tsepez | 698c571 | 2016-09-28 16:47:07 -0700 | [diff] [blame] | 1836 | CPDF_Dictionary* pXObject = new CPDF_Dictionary(pDoc->GetByteStringPool()); |
tsepez | bb577af | 2016-09-21 19:10:19 -0700 | [diff] [blame] | 1837 | pXObject->SetReferenceFor(sImageAlias, pDoc, pImage->GetObjNum()); |
| 1838 | pStreamResList->SetFor("XObject", pXObject); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1839 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1840 | |
| 1841 | void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) { |
dsinclair | 38fd844 | 2016-09-15 10:15:32 -0700 | [diff] [blame] | 1842 | if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP")) |
| 1843 | pAPDict->RemoveFor(sAPType); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, |
| 1847 | PDFSDK_FieldAction& data, |
| 1848 | CPDFSDK_PageView* pPageView) { |
| 1849 | CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 1850 | CPDFSDK_Environment* pEnv = pDocument->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1851 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1852 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 1853 | CPDFXFA_Document* pDoc = pDocument->GetXFADocument(); |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1854 | if (CXFA_FFWidget* hWidget = GetMixXFAWidget()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1855 | XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit); |
| 1856 | |
| 1857 | if (eEventType != XFA_EVENT_Unknown) { |
dsinclair | df4bc59 | 2016-03-31 20:34:43 -0700 | [diff] [blame] | 1858 | if (CXFA_FFWidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1859 | CXFA_EventParam param; |
| 1860 | param.m_eType = eEventType; |
| 1861 | param.m_wsChange = data.sChange; |
| 1862 | param.m_iCommitKey = data.nCommitKey; |
| 1863 | param.m_bShift = data.bShift; |
| 1864 | param.m_iSelStart = data.nSelStart; |
| 1865 | param.m_iSelEnd = data.nSelEnd; |
| 1866 | param.m_wsFullText = data.sValue; |
| 1867 | param.m_bKeyDown = data.bKeyDown; |
| 1868 | param.m_bModifier = data.bModifier; |
| 1869 | param.m_wsNewText = data.sValue; |
| 1870 | if (data.nSelEnd > data.nSelStart) |
| 1871 | param.m_wsNewText.Delete(data.nSelStart, |
| 1872 | data.nSelEnd - data.nSelStart); |
| 1873 | for (int i = data.sChange.GetLength() - 1; i >= 0; i--) |
| 1874 | param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]); |
| 1875 | param.m_wsPrevText = data.sValue; |
| 1876 | |
dsinclair | 221caf6 | 2016-04-04 12:08:40 -0700 | [diff] [blame] | 1877 | CXFA_WidgetAcc* pAcc = hWidget->GetDataAcc(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1878 | param.m_pTarget = pAcc; |
| 1879 | int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); |
| 1880 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 1881 | if (CXFA_FFDocView* pDocView = pDoc->GetXFADocView()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1882 | pDocView->UpdateDocView(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1883 | |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 1884 | if (nRet == XFA_EVENTERROR_Success) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1885 | return TRUE; |
| 1886 | } |
| 1887 | } |
| 1888 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1889 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1890 | |
| 1891 | CPDF_Action action = GetAAction(type); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 1892 | if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1893 | CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
| 1894 | return pActionHandler->DoAction_Field(action, type, pDocument, |
| 1895 | GetFormField(), data); |
| 1896 | } |
| 1897 | return FALSE; |
| 1898 | } |
| 1899 | |
| 1900 | CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) { |
| 1901 | switch (eAAT) { |
| 1902 | case CPDF_AAction::CursorEnter: |
| 1903 | case CPDF_AAction::CursorExit: |
| 1904 | case CPDF_AAction::ButtonDown: |
| 1905 | case CPDF_AAction::ButtonUp: |
| 1906 | case CPDF_AAction::GetFocus: |
| 1907 | case CPDF_AAction::LoseFocus: |
| 1908 | case CPDF_AAction::PageOpen: |
| 1909 | case CPDF_AAction::PageClose: |
| 1910 | case CPDF_AAction::PageVisible: |
| 1911 | case CPDF_AAction::PageInvisible: |
| 1912 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 1913 | |
| 1914 | case CPDF_AAction::KeyStroke: |
| 1915 | case CPDF_AAction::Format: |
| 1916 | case CPDF_AAction::Validate: |
| 1917 | case CPDF_AAction::Calculate: { |
| 1918 | CPDF_FormField* pField = GetFormField(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 1919 | if (pField->GetAdditionalAction().GetDict()) |
| 1920 | return pField->GetAdditionalAction().GetAction(eAAT); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1921 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 1922 | } |
| 1923 | default: |
| 1924 | break; |
| 1925 | } |
| 1926 | |
| 1927 | return CPDF_Action(); |
| 1928 | } |
| 1929 | |
| 1930 | CFX_WideString CPDFSDK_Widget::GetAlternateName() const { |
| 1931 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1932 | return pFormField->GetAlternateName(); |
| 1933 | } |
| 1934 | |
| 1935 | int32_t CPDFSDK_Widget::GetAppearanceAge() const { |
| 1936 | return m_nAppAge; |
| 1937 | } |
| 1938 | |
| 1939 | int32_t CPDFSDK_Widget::GetValueAge() const { |
| 1940 | return m_nValueAge; |
| 1941 | } |
| 1942 | |
| 1943 | FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY) { |
| 1944 | CPDF_Annot* pAnnot = GetPDFAnnot(); |
jaepark | a1d2111 | 2016-08-25 13:33:34 -0700 | [diff] [blame] | 1945 | CFX_FloatRect annotRect = pAnnot->GetRect(); |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 1946 | if (!annotRect.Contains(pageX, pageY)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1947 | return FALSE; |
| 1948 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 1949 | if (!IsVisible()) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1950 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1951 | |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 1952 | if ((GetFieldFlags() & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1953 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1954 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1955 | return TRUE; |
| 1956 | } |