John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 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 | |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 7 | #include "fpdfsdk/include/fsdk_baseform.h" |
| 8 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 9 | #include <algorithm> |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 10 | #include <memory> |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 11 | #include <vector> |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 12 | |
Dan Sinclair | 455a419 | 2016-03-16 09:48:56 -0400 | [diff] [blame] | 13 | #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 14 | #include "core/fpdfapi/fpdf_parser/include/cfdf_document.h" |
| 15 | #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
| 16 | #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
Dan Sinclair | 584b1e6 | 2016-03-21 09:15:45 -0400 | [diff] [blame] | 17 | #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" |
Dan Sinclair | edbb319 | 2016-03-21 09:08:24 -0400 | [diff] [blame] | 18 | #include "fpdfsdk/formfiller/cffl_formfiller.h" |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 19 | #include "fpdfsdk/include/fsdk_actionhandler.h" |
| 20 | #include "fpdfsdk/include/fsdk_baseannot.h" |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 21 | #include "fpdfsdk/include/fsdk_define.h" |
| 22 | #include "fpdfsdk/include/fsdk_mgr.h" |
| 23 | #include "fpdfsdk/include/javascript/IJavaScript.h" |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 24 | #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 25 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 26 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | 875b9c9 | 2016-01-08 13:51:10 -0800 | [diff] [blame] | 27 | #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" |
| 28 | #include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h" |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 29 | #endif // PDF_ENABLE_XFA |
| 30 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | #define IsFloatZero(f) ((f) < 0.01 && (f) > -0.01) |
| 32 | #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) |
| 33 | #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) |
| 34 | #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb)) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 35 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 36 | CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, |
| 37 | CPDFSDK_PageView* pPageView, |
| 38 | CPDFSDK_InterForm* pInterForm) |
| 39 | : CPDFSDK_BAAnnot(pAnnot, pPageView), |
| 40 | m_pInterForm(pInterForm), |
| 41 | m_nAppAge(0), |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 42 | m_nValueAge(0) |
| 43 | #ifdef PDF_ENABLE_XFA |
| 44 | , |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 45 | m_hMixXFAWidget(NULL), |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 46 | m_pWidgetHandler(NULL) |
| 47 | #endif // PDF_ENABLE_XFA |
| 48 | { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 51 | CPDFSDK_Widget::~CPDFSDK_Widget() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 52 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 53 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 54 | IXFA_Widget* CPDFSDK_Widget::GetMixXFAWidget() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 56 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { |
| 58 | if (!m_hMixXFAWidget) { |
| 59 | if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) { |
| 60 | CFX_WideString sName; |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 61 | if (GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
| 62 | sName = GetAnnotName(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | if (sName.IsEmpty()) |
| 64 | sName = GetName(); |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 65 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 66 | sName = GetName(); |
Dan Sinclair | 738b08c | 2016-03-01 14:45:20 -0500 | [diff] [blame] | 67 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 68 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 69 | if (!sName.IsEmpty()) |
| 70 | m_hMixXFAWidget = pDocView->GetWidgetByName(sName); |
| 71 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 72 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 73 | return m_hMixXFAWidget; |
| 74 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 75 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 76 | return NULL; |
| 77 | } |
| 78 | |
| 79 | IXFA_Widget* CPDFSDK_Widget::GetGroupMixXFAWidget() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 81 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 82 | if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { |
| 83 | if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) { |
| 84 | CFX_WideString sName = GetName(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 85 | if (!sName.IsEmpty()) |
| 86 | return pDocView->GetWidgetByName(sName); |
| 87 | } |
| 88 | } |
| 89 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 90 | return nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 93 | IXFA_WidgetHandler* CPDFSDK_Widget::GetXFAWidgetHandler() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 95 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { |
| 97 | if (!m_pWidgetHandler) { |
| 98 | if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) { |
| 99 | m_pWidgetHandler = pDocView->GetWidgetHandler(); |
| 100 | } |
| 101 | } |
| 102 | return m_pWidgetHandler; |
| 103 | } |
| 104 | |
| 105 | return NULL; |
| 106 | } |
| 107 | |
| 108 | static XFA_EVENTTYPE GetXFAEventType(PDFSDK_XFAAActionType eXFAAAT) { |
| 109 | XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown; |
| 110 | |
| 111 | switch (eXFAAAT) { |
| 112 | case PDFSDK_XFA_Click: |
| 113 | eEventType = XFA_EVENT_Click; |
| 114 | break; |
| 115 | case PDFSDK_XFA_Full: |
| 116 | eEventType = XFA_EVENT_Full; |
| 117 | break; |
| 118 | case PDFSDK_XFA_PreOpen: |
| 119 | eEventType = XFA_EVENT_PreOpen; |
| 120 | break; |
| 121 | case PDFSDK_XFA_PostOpen: |
| 122 | eEventType = XFA_EVENT_PostOpen; |
| 123 | break; |
| 124 | } |
| 125 | |
| 126 | return eEventType; |
| 127 | } |
| 128 | |
| 129 | static XFA_EVENTTYPE GetXFAEventType(CPDF_AAction::AActionType eAAT, |
| 130 | FX_BOOL bWillCommit) { |
| 131 | XFA_EVENTTYPE eEventType = XFA_EVENT_Unknown; |
| 132 | |
| 133 | switch (eAAT) { |
| 134 | case CPDF_AAction::CursorEnter: |
| 135 | eEventType = XFA_EVENT_MouseEnter; |
| 136 | break; |
| 137 | case CPDF_AAction::CursorExit: |
| 138 | eEventType = XFA_EVENT_MouseExit; |
| 139 | break; |
| 140 | case CPDF_AAction::ButtonDown: |
| 141 | eEventType = XFA_EVENT_MouseDown; |
| 142 | break; |
| 143 | case CPDF_AAction::ButtonUp: |
| 144 | eEventType = XFA_EVENT_MouseUp; |
| 145 | break; |
| 146 | case CPDF_AAction::GetFocus: |
| 147 | eEventType = XFA_EVENT_Enter; |
| 148 | break; |
| 149 | case CPDF_AAction::LoseFocus: |
| 150 | eEventType = XFA_EVENT_Exit; |
| 151 | break; |
| 152 | case CPDF_AAction::PageOpen: |
| 153 | break; |
| 154 | case CPDF_AAction::PageClose: |
| 155 | break; |
| 156 | case CPDF_AAction::PageVisible: |
| 157 | break; |
| 158 | case CPDF_AAction::PageInvisible: |
| 159 | break; |
| 160 | case CPDF_AAction::KeyStroke: |
| 161 | if (!bWillCommit) { |
| 162 | eEventType = XFA_EVENT_Change; |
| 163 | } |
| 164 | break; |
| 165 | case CPDF_AAction::Validate: |
| 166 | eEventType = XFA_EVENT_Validate; |
| 167 | break; |
| 168 | case CPDF_AAction::OpenPage: |
| 169 | case CPDF_AAction::ClosePage: |
| 170 | case CPDF_AAction::Format: |
| 171 | case CPDF_AAction::Calculate: |
| 172 | case CPDF_AAction::CloseDocument: |
| 173 | case CPDF_AAction::SaveDocument: |
| 174 | case CPDF_AAction::DocumentSaved: |
| 175 | case CPDF_AAction::PrintDocument: |
| 176 | case CPDF_AAction::DocumentPrinted: |
| 177 | break; |
| 178 | } |
| 179 | |
| 180 | return eEventType; |
| 181 | } |
| 182 | |
| 183 | FX_BOOL CPDFSDK_Widget::HasXFAAAction(PDFSDK_XFAAActionType eXFAAAT) { |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 184 | if (IXFA_Widget* hWidget = GetMixXFAWidget()) { |
| 185 | if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 186 | XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); |
| 187 | |
| 188 | if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && |
| 189 | GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
| 190 | if (IXFA_Widget* hGroupWidget = GetGroupMixXFAWidget()) { |
| 191 | CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hGroupWidget); |
| 192 | if (pXFAWidgetHandler->HasEvent(pAcc, eEventType)) |
| 193 | return TRUE; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | { |
| 198 | CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget); |
| 199 | return pXFAWidgetHandler->HasEvent(pAcc, eEventType); |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | return FALSE; |
| 205 | } |
| 206 | |
| 207 | FX_BOOL CPDFSDK_Widget::OnXFAAAction(PDFSDK_XFAAActionType eXFAAAT, |
| 208 | PDFSDK_FieldAction& data, |
| 209 | CPDFSDK_PageView* pPageView) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 210 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 211 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
| 212 | if (IXFA_Widget* hWidget = GetMixXFAWidget()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 213 | XFA_EVENTTYPE eEventType = GetXFAEventType(eXFAAAT); |
| 214 | |
| 215 | if (eEventType != XFA_EVENT_Unknown) { |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 216 | if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 217 | CXFA_EventParam param; |
| 218 | param.m_eType = eEventType; |
| 219 | param.m_wsChange = data.sChange; |
| 220 | param.m_iCommitKey = data.nCommitKey; |
| 221 | param.m_bShift = data.bShift; |
| 222 | param.m_iSelStart = data.nSelStart; |
| 223 | param.m_iSelEnd = data.nSelEnd; |
| 224 | param.m_wsFullText = data.sValue; |
| 225 | param.m_bKeyDown = data.bKeyDown; |
| 226 | param.m_bModifier = data.bModifier; |
| 227 | param.m_wsNewText = data.sValue; |
| 228 | if (data.nSelEnd > data.nSelStart) |
| 229 | param.m_wsNewText.Delete(data.nSelStart, |
| 230 | data.nSelEnd - data.nSelStart); |
| 231 | for (int i = 0; i < data.sChange.GetLength(); i++) |
| 232 | param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]); |
| 233 | param.m_wsPrevText = data.sValue; |
| 234 | |
| 235 | if ((eEventType == XFA_EVENT_Click || eEventType == XFA_EVENT_Change) && |
| 236 | GetFieldType() == FIELDTYPE_RADIOBUTTON) { |
| 237 | if (IXFA_Widget* hGroupWidget = GetGroupMixXFAWidget()) { |
| 238 | CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hGroupWidget); |
| 239 | param.m_pTarget = pAcc; |
Wei Li | 42d1c1c | 2016-03-22 12:52:50 -0700 | [diff] [blame] | 240 | if (pXFAWidgetHandler->ProcessEvent(pAcc, ¶m) != |
| 241 | XFA_EVENTERROR_Success) { |
| 242 | return FALSE; |
| 243 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 244 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 245 | } |
Wei Li | 42d1c1c | 2016-03-22 12:52:50 -0700 | [diff] [blame] | 246 | CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget); |
| 247 | param.m_pTarget = pAcc; |
| 248 | int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 249 | |
| 250 | if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) { |
| 251 | pDocView->UpdateDocView(); |
| 252 | } |
Wei Li | 42d1c1c | 2016-03-22 12:52:50 -0700 | [diff] [blame] | 253 | return nRet == XFA_EVENTERROR_Success; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | return FALSE; |
| 259 | } |
| 260 | |
| 261 | void CPDFSDK_Widget::Synchronize(FX_BOOL bSynchronizeElse) { |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 262 | if (IXFA_Widget* hWidget = GetMixXFAWidget()) { |
| 263 | if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 264 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 265 | if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) { |
| 266 | switch (GetFieldType()) { |
| 267 | case FIELDTYPE_CHECKBOX: |
| 268 | case FIELDTYPE_RADIOBUTTON: { |
| 269 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 270 | XFA_CHECKSTATE eCheckState = |
| 271 | pFormCtrl->IsChecked() ? XFA_CHECKSTATE_On : XFA_CHECKSTATE_Off; |
| 272 | pWidgetAcc->SetCheckState(eCheckState); |
| 273 | } break; |
| 274 | case FIELDTYPE_TEXTFIELD: |
| 275 | pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit); |
| 276 | break; |
| 277 | case FIELDTYPE_LISTBOX: { |
| 278 | pWidgetAcc->ClearAllSelections(); |
| 279 | |
| 280 | for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; |
| 281 | i++) { |
| 282 | int nIndex = pFormField->GetSelectedIndex(i); |
| 283 | if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems()) |
| 284 | pWidgetAcc->SetItemState(nIndex, TRUE, FALSE); |
| 285 | } |
| 286 | } break; |
| 287 | case FIELDTYPE_COMBOBOX: { |
| 288 | pWidgetAcc->ClearAllSelections(); |
| 289 | |
| 290 | for (int i = 0, sz = pFormField->CountSelectedItems(); i < sz; |
| 291 | i++) { |
| 292 | int nIndex = pFormField->GetSelectedIndex(i); |
| 293 | if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems()) |
| 294 | pWidgetAcc->SetItemState(nIndex, TRUE, FALSE); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | pWidgetAcc->SetValue(pFormField->GetValue(), XFA_VALUEPICTURE_Edit); |
| 299 | break; |
| 300 | } |
| 301 | |
| 302 | if (bSynchronizeElse) |
| 303 | pWidgetAcc->ProcessValueChanged(); |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | void CPDFSDK_Widget::SynchronizeXFAValue() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 310 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 311 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 312 | IXFA_DocView* pXFADocView = pDoc->GetXFADocView(); |
| 313 | if (!pXFADocView) |
| 314 | return; |
| 315 | |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 316 | if (IXFA_Widget* hWidget = GetMixXFAWidget()) { |
| 317 | if (GetXFAWidgetHandler()) { |
| 318 | CPDFSDK_Widget::SynchronizeXFAValue(pXFADocView, hWidget, GetFormField(), |
| 319 | GetFormControl()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | void CPDFSDK_Widget::SynchronizeXFAItems() { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 325 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 326 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 327 | IXFA_DocView* pXFADocView = pDoc->GetXFADocView(); |
| 328 | if (!pXFADocView) |
| 329 | return; |
| 330 | |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 331 | if (IXFA_Widget* hWidget = GetMixXFAWidget()) { |
| 332 | if (GetXFAWidgetHandler()) |
| 333 | SynchronizeXFAItems(pXFADocView, hWidget, GetFormField(), nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 334 | } |
| 335 | } |
| 336 | |
| 337 | void CPDFSDK_Widget::SynchronizeXFAValue(IXFA_DocView* pXFADocView, |
| 338 | IXFA_Widget* hWidget, |
| 339 | CPDF_FormField* pFormField, |
| 340 | CPDF_FormControl* pFormControl) { |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 341 | ASSERT(hWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 342 | |
| 343 | if (IXFA_WidgetHandler* pXFAWidgetHandler = pXFADocView->GetWidgetHandler()) { |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 344 | ASSERT(pFormControl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 345 | |
| 346 | switch (pFormField->GetFieldType()) { |
| 347 | case FIELDTYPE_CHECKBOX: { |
| 348 | if (CXFA_WidgetAcc* pWidgetAcc = |
| 349 | pXFAWidgetHandler->GetDataAcc(hWidget)) { |
Wei Li | e407648 | 2016-03-15 10:58:40 -0700 | [diff] [blame] | 350 | pFormField->CheckControl( |
| 351 | pFormField->GetControlIndex(pFormControl), |
| 352 | pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 353 | } |
| 354 | } break; |
| 355 | case FIELDTYPE_RADIOBUTTON: { |
Wei Li | e407648 | 2016-03-15 10:58:40 -0700 | [diff] [blame] | 356 | // TODO(weili): Check whether we need to handle checkbox and radio |
| 357 | // button differently, otherwise, merge these two cases. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 358 | if (CXFA_WidgetAcc* pWidgetAcc = |
| 359 | pXFAWidgetHandler->GetDataAcc(hWidget)) { |
Wei Li | e407648 | 2016-03-15 10:58:40 -0700 | [diff] [blame] | 360 | pFormField->CheckControl( |
| 361 | pFormField->GetControlIndex(pFormControl), |
| 362 | pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 363 | } |
| 364 | } break; |
| 365 | case FIELDTYPE_TEXTFIELD: { |
| 366 | if (CXFA_WidgetAcc* pWidgetAcc = |
| 367 | pXFAWidgetHandler->GetDataAcc(hWidget)) { |
| 368 | CFX_WideString sValue; |
| 369 | pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display); |
| 370 | pFormField->SetValue(sValue, TRUE); |
| 371 | } |
| 372 | } break; |
| 373 | case FIELDTYPE_LISTBOX: { |
| 374 | pFormField->ClearSelection(FALSE); |
| 375 | |
| 376 | if (CXFA_WidgetAcc* pWidgetAcc = |
| 377 | pXFAWidgetHandler->GetDataAcc(hWidget)) { |
| 378 | for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) { |
| 379 | int nIndex = pWidgetAcc->GetSelectedItem(i); |
| 380 | |
| 381 | if (nIndex > -1 && nIndex < pFormField->CountOptions()) { |
| 382 | pFormField->SetItemSelection(nIndex, TRUE, TRUE); |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | } break; |
| 387 | case FIELDTYPE_COMBOBOX: { |
| 388 | pFormField->ClearSelection(FALSE); |
| 389 | |
| 390 | if (CXFA_WidgetAcc* pWidgetAcc = |
| 391 | pXFAWidgetHandler->GetDataAcc(hWidget)) { |
| 392 | for (int i = 0, sz = pWidgetAcc->CountSelectedItems(); i < sz; i++) { |
| 393 | int nIndex = pWidgetAcc->GetSelectedItem(i); |
| 394 | |
| 395 | if (nIndex > -1 && nIndex < pFormField->CountOptions()) { |
| 396 | pFormField->SetItemSelection(nIndex, TRUE, TRUE); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | CFX_WideString sValue; |
| 401 | pWidgetAcc->GetValue(sValue, XFA_VALUEPICTURE_Display); |
| 402 | pFormField->SetValue(sValue, TRUE); |
| 403 | } |
| 404 | } break; |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | void CPDFSDK_Widget::SynchronizeXFAItems(IXFA_DocView* pXFADocView, |
| 410 | IXFA_Widget* hWidget, |
| 411 | CPDF_FormField* pFormField, |
| 412 | CPDF_FormControl* pFormControl) { |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 413 | ASSERT(hWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 414 | |
| 415 | if (IXFA_WidgetHandler* pXFAWidgetHandler = pXFADocView->GetWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 416 | switch (pFormField->GetFieldType()) { |
| 417 | case FIELDTYPE_LISTBOX: { |
| 418 | pFormField->ClearSelection(FALSE); |
| 419 | pFormField->ClearOptions(TRUE); |
| 420 | |
| 421 | if (CXFA_WidgetAcc* pWidgetAcc = |
| 422 | pXFAWidgetHandler->GetDataAcc(hWidget)) { |
| 423 | for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz; |
| 424 | i++) { |
| 425 | CFX_WideString swText; |
| 426 | pWidgetAcc->GetChoiceListItem(swText, i); |
| 427 | |
| 428 | pFormField->InsertOption(swText, i, TRUE); |
| 429 | } |
| 430 | } |
| 431 | } break; |
| 432 | case FIELDTYPE_COMBOBOX: { |
| 433 | pFormField->ClearSelection(FALSE); |
| 434 | pFormField->ClearOptions(FALSE); |
| 435 | |
| 436 | if (CXFA_WidgetAcc* pWidgetAcc = |
| 437 | pXFAWidgetHandler->GetDataAcc(hWidget)) { |
| 438 | for (int i = 0, sz = pWidgetAcc->CountChoiceListItems(); i < sz; |
| 439 | i++) { |
| 440 | CFX_WideString swText; |
| 441 | pWidgetAcc->GetChoiceListItem(swText, i); |
| 442 | |
| 443 | pFormField->InsertOption(swText, i, FALSE); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | pFormField->SetValue(L"", TRUE); |
| 448 | } break; |
| 449 | } |
| 450 | } |
| 451 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 452 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 453 | |
| 454 | FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid( |
| 455 | CPDF_Annot::AppearanceMode mode) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 456 | CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDictBy("AP"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 457 | if (!pAP) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 458 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 459 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 460 | // Choose the right sub-ap |
| 461 | const FX_CHAR* ap_entry = "N"; |
| 462 | if (mode == CPDF_Annot::Down) |
| 463 | ap_entry = "D"; |
| 464 | else if (mode == CPDF_Annot::Rollover) |
| 465 | ap_entry = "R"; |
| 466 | if (!pAP->KeyExist(ap_entry)) |
| 467 | ap_entry = "N"; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 468 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 469 | // Get the AP stream or subdirectory |
| 470 | CPDF_Object* psub = pAP->GetElementValue(ap_entry); |
| 471 | if (!psub) |
| 472 | return FALSE; |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 473 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 474 | int nFieldType = GetFieldType(); |
| 475 | switch (nFieldType) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 476 | case FIELDTYPE_PUSHBUTTON: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 477 | case FIELDTYPE_COMBOBOX: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 478 | case FIELDTYPE_LISTBOX: |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 479 | case FIELDTYPE_TEXTFIELD: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 480 | case FIELDTYPE_SIGNATURE: |
Dan Sinclair | aa435ba | 2015-10-22 16:45:48 -0400 | [diff] [blame] | 481 | return psub->IsStream(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 482 | case FIELDTYPE_CHECKBOX: |
| 483 | case FIELDTYPE_RADIOBUTTON: |
Dan Sinclair | f1251c1 | 2015-10-20 16:24:45 -0400 | [diff] [blame] | 484 | if (CPDF_Dictionary* pSubDict = psub->AsDictionary()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 485 | return pSubDict->GetStreamBy(GetAppState()) != NULL; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 486 | } |
| 487 | return FALSE; |
| 488 | } |
| 489 | return TRUE; |
| 490 | } |
| 491 | |
| 492 | int CPDFSDK_Widget::GetFieldType() const { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 493 | return GetFormField()->GetFieldType(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | FX_BOOL CPDFSDK_Widget::IsAppearanceValid() { |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 497 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 498 | CPDFSDK_Document* pSDKDoc = m_pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 499 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 500 | int nDocType = pDoc->GetDocType(); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 501 | if (nDocType != DOCTYPE_PDF && nDocType != DOCTYPE_STATIC_XFA) |
| 502 | return TRUE; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 503 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 504 | return CPDFSDK_BAAnnot::IsAppearanceValid(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | int CPDFSDK_Widget::GetFieldFlags() const { |
| 508 | CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 509 | CPDF_FormControl* pFormControl = |
| 510 | pPDFInterForm->GetControlByDict(m_pAnnot->GetAnnotDict()); |
| 511 | CPDF_FormField* pFormField = pFormControl->GetField(); |
| 512 | return pFormField->GetFieldFlags(); |
| 513 | } |
| 514 | |
| 515 | CFX_ByteString CPDFSDK_Widget::GetSubType() const { |
| 516 | int nType = GetFieldType(); |
| 517 | |
| 518 | if (nType == FIELDTYPE_SIGNATURE) |
| 519 | return BFFT_SIGNATURE; |
| 520 | return CPDFSDK_Annot::GetSubType(); |
| 521 | } |
| 522 | |
| 523 | CPDF_FormField* CPDFSDK_Widget::GetFormField() const { |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 524 | return GetFormControl()->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 528 | CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 529 | return pPDFInterForm->GetControlByDict(GetAnnotDict()); |
| 530 | } |
| 531 | |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 532 | CPDF_FormControl* CPDFSDK_Widget::GetFormControl( |
| 533 | CPDF_InterForm* pInterForm, |
| 534 | const CPDF_Dictionary* pAnnotDict) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 535 | ASSERT(pAnnotDict); |
Lei Zhang | 1b700c3 | 2015-10-30 23:55:35 -0700 | [diff] [blame] | 536 | return pInterForm->GetControlByDict(pAnnotDict); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | int CPDFSDK_Widget::GetRotate() const { |
| 540 | CPDF_FormControl* pCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 541 | return pCtrl->GetRotation() % 360; |
| 542 | } |
| 543 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 544 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 545 | CFX_WideString CPDFSDK_Widget::GetName() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 546 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 547 | return pFormField->GetFullName(); |
| 548 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 549 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 550 | |
| 551 | FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const { |
| 552 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 553 | int iColorType = 0; |
| 554 | color = FX_ARGBTOCOLORREF(pFormCtrl->GetBackgroundColor(iColorType)); |
| 555 | |
| 556 | return iColorType != COLORTYPE_TRANSPARENT; |
| 557 | } |
| 558 | |
| 559 | FX_BOOL CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const { |
| 560 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 561 | int iColorType = 0; |
| 562 | color = FX_ARGBTOCOLORREF(pFormCtrl->GetBorderColor(iColorType)); |
| 563 | |
| 564 | return iColorType != COLORTYPE_TRANSPARENT; |
| 565 | } |
| 566 | |
| 567 | FX_BOOL CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const { |
| 568 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 569 | CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); |
| 570 | if (da.HasColor()) { |
| 571 | FX_ARGB argb; |
| 572 | int iColorType = COLORTYPE_TRANSPARENT; |
| 573 | da.GetColor(argb, iColorType); |
| 574 | color = FX_ARGBTOCOLORREF(argb); |
| 575 | |
| 576 | return iColorType != COLORTYPE_TRANSPARENT; |
| 577 | } |
| 578 | |
| 579 | return FALSE; |
| 580 | } |
| 581 | |
| 582 | FX_FLOAT CPDFSDK_Widget::GetFontSize() const { |
| 583 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 584 | CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance(); |
| 585 | CFX_ByteString csFont = ""; |
| 586 | FX_FLOAT fFontSize = 0.0f; |
| 587 | pDa.GetFont(csFont, fFontSize); |
| 588 | |
| 589 | return fFontSize; |
| 590 | } |
| 591 | |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 592 | int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 593 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 594 | if (IXFA_Widget* hWidget = GetMixXFAWidget()) { |
| 595 | if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 596 | if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) { |
| 597 | if (nIndex < pWidgetAcc->CountSelectedItems()) |
| 598 | return pWidgetAcc->GetSelectedItem(nIndex); |
| 599 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 600 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 601 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 602 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 603 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 604 | return pFormField->GetSelectedIndex(nIndex); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 607 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 608 | CFX_WideString CPDFSDK_Widget::GetValue(FX_BOOL bDisplay) const { |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 609 | if (IXFA_Widget* hWidget = GetMixXFAWidget()) { |
| 610 | if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 611 | if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) { |
| 612 | CFX_WideString sValue; |
| 613 | pWidgetAcc->GetValue(sValue, bDisplay ? XFA_VALUEPICTURE_Display |
| 614 | : XFA_VALUEPICTURE_Edit); |
| 615 | return sValue; |
| 616 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 617 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 618 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 619 | #else |
| 620 | CFX_WideString CPDFSDK_Widget::GetValue() const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 621 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 622 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 623 | return pFormField->GetValue(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 626 | CFX_WideString CPDFSDK_Widget::GetDefaultValue() const { |
| 627 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 628 | return pFormField->GetDefaultValue(); |
| 629 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 630 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 631 | CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const { |
| 632 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 633 | return pFormField->GetOptionLabel(nIndex); |
| 634 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 635 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 636 | int CPDFSDK_Widget::CountOptions() const { |
| 637 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 638 | return pFormField->CountOptions(); |
| 639 | } |
| 640 | |
Tom Sepez | bf59a07 | 2015-10-21 14:07:23 -0700 | [diff] [blame] | 641 | FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 642 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 643 | if (IXFA_Widget* hWidget = GetMixXFAWidget()) { |
| 644 | if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 645 | if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) { |
| 646 | if (nIndex > -1 && nIndex < pWidgetAcc->CountChoiceListItems()) |
| 647 | return pWidgetAcc->GetItemState(nIndex); |
| 648 | |
| 649 | return FALSE; |
| 650 | } |
| 651 | } |
| 652 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 653 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 654 | CPDF_FormField* pFormField = GetFormField(); |
| 655 | return pFormField->IsItemSelected(nIndex); |
| 656 | } |
| 657 | |
| 658 | int CPDFSDK_Widget::GetTopVisibleIndex() const { |
| 659 | CPDF_FormField* pFormField = GetFormField(); |
| 660 | return pFormField->GetTopVisibleIndex(); |
| 661 | } |
| 662 | |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 663 | bool CPDFSDK_Widget::IsChecked() const { |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 664 | #ifdef PDF_ENABLE_XFA |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 665 | if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
| 666 | if (IXFA_Widget* hWidget = GetMixXFAWidget()) { |
Tom Sepez | 007e6c0 | 2016-02-26 14:31:56 -0800 | [diff] [blame] | 667 | if (CXFA_WidgetAcc* pWidgetAcc = pXFAWidgetHandler->GetDataAcc(hWidget)) |
| 668 | return pWidgetAcc->GetCheckState() == XFA_CHECKSTATE_On; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 669 | } |
| 670 | } |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 671 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 672 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 673 | return pFormCtrl->IsChecked(); |
| 674 | } |
| 675 | |
| 676 | int CPDFSDK_Widget::GetAlignment() const { |
| 677 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 678 | return pFormCtrl->GetControlAlignment(); |
| 679 | } |
| 680 | |
| 681 | int CPDFSDK_Widget::GetMaxLen() const { |
| 682 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 683 | return pFormField->GetMaxLen(); |
| 684 | } |
| 685 | |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 686 | void CPDFSDK_Widget::SetCheck(bool bChecked, bool bNotify) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 687 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 688 | CPDF_FormField* pFormField = pFormCtrl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 689 | pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, |
| 690 | bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 691 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 692 | if (!IsWidgetAppearanceValid(CPDF_Annot::Normal)) |
| 693 | ResetAppearance(TRUE); |
| 694 | if (!bNotify) |
| 695 | Synchronize(TRUE); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 696 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify) { |
| 700 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 701 | pFormField->SetValue(sValue, bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 702 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 703 | if (!bNotify) |
| 704 | Synchronize(TRUE); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 705 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {} |
| 709 | void CPDFSDK_Widget::SetOptionSelection(int index, |
| 710 | FX_BOOL bSelected, |
| 711 | FX_BOOL bNotify) { |
| 712 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 713 | pFormField->SetItemSelection(index, bSelected, bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 714 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 715 | if (!bNotify) |
| 716 | Synchronize(TRUE); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 717 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify) { |
| 721 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 722 | pFormField->ClearSelection(bNotify); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 723 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 724 | if (!bNotify) |
| 725 | Synchronize(TRUE); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 726 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | void CPDFSDK_Widget::SetTopVisibleIndex(int index) {} |
| 730 | |
| 731 | void CPDFSDK_Widget::SetAppModified() { |
| 732 | m_bAppModified = TRUE; |
| 733 | } |
| 734 | |
| 735 | void CPDFSDK_Widget::ClearAppModified() { |
| 736 | m_bAppModified = FALSE; |
| 737 | } |
| 738 | |
| 739 | FX_BOOL CPDFSDK_Widget::IsAppModified() const { |
| 740 | return m_bAppModified; |
| 741 | } |
| 742 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 743 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 744 | void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) { |
| 745 | switch (GetFieldType()) { |
| 746 | case FIELDTYPE_TEXTFIELD: |
| 747 | case FIELDTYPE_COMBOBOX: { |
| 748 | FX_BOOL bFormated = FALSE; |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 749 | CFX_WideString sValue = OnFormat(bFormated); |
| 750 | ResetAppearance(bFormated ? sValue : nullptr, TRUE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 751 | } break; |
| 752 | default: |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 753 | ResetAppearance(nullptr, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 754 | break; |
| 755 | } |
| 756 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 757 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 758 | |
| 759 | void CPDFSDK_Widget::ResetAppearance(const FX_WCHAR* sValue, |
| 760 | FX_BOOL bValueChanged) { |
| 761 | SetAppModified(); |
| 762 | |
| 763 | m_nAppAge++; |
| 764 | if (m_nAppAge > 999999) |
| 765 | m_nAppAge = 0; |
| 766 | if (bValueChanged) |
| 767 | m_nValueAge++; |
| 768 | |
| 769 | int nFieldType = GetFieldType(); |
| 770 | |
| 771 | switch (nFieldType) { |
| 772 | case FIELDTYPE_PUSHBUTTON: |
| 773 | ResetAppearance_PushButton(); |
| 774 | break; |
| 775 | case FIELDTYPE_CHECKBOX: |
| 776 | ResetAppearance_CheckBox(); |
| 777 | break; |
| 778 | case FIELDTYPE_RADIOBUTTON: |
| 779 | ResetAppearance_RadioButton(); |
| 780 | break; |
| 781 | case FIELDTYPE_COMBOBOX: |
| 782 | ResetAppearance_ComboBox(sValue); |
| 783 | break; |
| 784 | case FIELDTYPE_LISTBOX: |
| 785 | ResetAppearance_ListBox(); |
| 786 | break; |
| 787 | case FIELDTYPE_TEXTFIELD: |
| 788 | ResetAppearance_TextField(sValue); |
| 789 | break; |
| 790 | } |
| 791 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 792 | m_pAnnot->ClearCachedAP(); |
| 793 | } |
| 794 | |
| 795 | CFX_WideString CPDFSDK_Widget::OnFormat(FX_BOOL& bFormated) { |
| 796 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 797 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 798 | return m_pInterForm->OnFormat(pFormField, bFormated); |
| 799 | } |
| 800 | |
| 801 | void CPDFSDK_Widget::ResetFieldAppearance(FX_BOOL bValueChanged) { |
| 802 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 803 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 804 | m_pInterForm->ResetFieldAppearance(pFormField, NULL, bValueChanged); |
| 805 | } |
| 806 | |
| 807 | void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 808 | const CFX_Matrix* pUser2Device, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 809 | CPDF_Annot::AppearanceMode mode, |
| 810 | const CPDF_RenderOptions* pOptions) { |
| 811 | int nFieldType = GetFieldType(); |
| 812 | |
| 813 | if ((nFieldType == FIELDTYPE_CHECKBOX || |
| 814 | nFieldType == FIELDTYPE_RADIOBUTTON) && |
| 815 | mode == CPDF_Annot::Normal && |
| 816 | !IsWidgetAppearanceValid(CPDF_Annot::Normal)) { |
| 817 | CFX_PathData pathData; |
| 818 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 819 | CFX_FloatRect rcAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 820 | |
| 821 | pathData.AppendRect(rcAnnot.left, rcAnnot.bottom, rcAnnot.right, |
| 822 | rcAnnot.top); |
| 823 | |
| 824 | CFX_GraphStateData gsd; |
| 825 | gsd.m_LineWidth = 0.0f; |
| 826 | |
| 827 | pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA, |
| 828 | FXFILL_ALTERNATE); |
| 829 | } else { |
| 830 | CPDFSDK_BAAnnot::DrawAppearance(pDevice, pUser2Device, mode, pOptions); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | void CPDFSDK_Widget::UpdateField() { |
| 835 | CPDF_FormField* pFormField = GetFormField(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 836 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 837 | m_pInterForm->UpdateField(pFormField); |
| 838 | } |
| 839 | |
| 840 | void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice, |
| 841 | CPDFSDK_PageView* pPageView) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 842 | int nFieldType = GetFieldType(); |
| 843 | if (m_pInterForm->IsNeedHighLight(nFieldType)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 844 | CFX_FloatRect rc = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 845 | FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType); |
| 846 | uint8_t alpha = m_pInterForm->GetHighlightAlpha(); |
| 847 | |
| 848 | CFX_FloatRect rcDevice; |
| 849 | ASSERT(m_pInterForm->GetDocument()); |
| 850 | CPDFDoc_Environment* pEnv = m_pInterForm->GetDocument()->GetEnv(); |
| 851 | if (!pEnv) |
| 852 | return; |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 853 | CFX_Matrix page2device; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 854 | pPageView->GetCurrentMatrix(page2device); |
| 855 | page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom), |
| 856 | rcDevice.left, rcDevice.bottom); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 857 | page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top), |
| 858 | rcDevice.right, rcDevice.top); |
| 859 | |
| 860 | rcDevice.Normalize(); |
| 861 | |
| 862 | FX_ARGB argb = ArgbEncode((int)alpha, color); |
| 863 | FX_RECT rcDev((int)rcDevice.left, (int)rcDevice.top, (int)rcDevice.right, |
| 864 | (int)rcDevice.bottom); |
| 865 | pDevice->FillRect(&rcDev, argb); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | |
| 869 | void CPDFSDK_Widget::ResetAppearance_PushButton() { |
| 870 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 871 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 872 | int32_t nLayout = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 873 | switch (pControl->GetTextPosition()) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 874 | case TEXTPOS_ICON: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 875 | nLayout = PPBL_ICON; |
| 876 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 877 | case TEXTPOS_BELOW: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 878 | nLayout = PPBL_ICONTOPLABELBOTTOM; |
| 879 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 880 | case TEXTPOS_ABOVE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 881 | nLayout = PPBL_LABELTOPICONBOTTOM; |
| 882 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 883 | case TEXTPOS_RIGHT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 884 | nLayout = PPBL_ICONLEFTLABELRIGHT; |
| 885 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 886 | case TEXTPOS_LEFT: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 887 | nLayout = PPBL_LABELLEFTICONRIGHT; |
| 888 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 889 | case TEXTPOS_OVERLAID: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 890 | nLayout = PPBL_LABELOVERICON; |
| 891 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 892 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 893 | nLayout = PPBL_LABEL; |
| 894 | break; |
| 895 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 896 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 897 | CPWL_Color crBackground, crBorder; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 898 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 899 | int iColorType; |
| 900 | FX_FLOAT fc[4]; |
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 | pControl->GetOriginalBackgroundColor(iColorType, fc); |
| 903 | if (iColorType > 0) |
| 904 | 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] | 905 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 906 | pControl->GetOriginalBorderColor(iColorType, fc); |
| 907 | if (iColorType > 0) |
| 908 | 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] | 909 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 910 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
| 911 | int32_t nBorderStyle = 0; |
| 912 | CPWL_Dash dsBorder(3, 0, 0); |
| 913 | CPWL_Color crLeftTop, crRightBottom; |
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 | switch (GetBorderStyle()) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 916 | case BBS_DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 917 | nBorderStyle = PBS_DASH; |
| 918 | dsBorder = CPWL_Dash(3, 3, 0); |
| 919 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 920 | case BBS_BEVELED: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 921 | nBorderStyle = PBS_BEVELED; |
| 922 | fBorderWidth *= 2; |
| 923 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 924 | crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); |
| 925 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 926 | case BBS_INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 927 | nBorderStyle = PBS_INSET; |
| 928 | fBorderWidth *= 2; |
| 929 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 930 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 931 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 932 | case BBS_UNDERLINE: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 933 | nBorderStyle = PBS_UNDERLINED; |
| 934 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 935 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 936 | nBorderStyle = PBS_SOLID; |
| 937 | break; |
| 938 | } |
| 939 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 940 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 941 | |
| 942 | CPWL_Color crText(COLORTYPE_GRAY, 0); |
| 943 | |
| 944 | FX_FLOAT fFontSize = 12.0f; |
| 945 | CFX_ByteString csNameTag; |
| 946 | |
| 947 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 948 | if (da.HasColor()) { |
| 949 | da.GetColor(iColorType, fc); |
| 950 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 951 | } |
| 952 | |
| 953 | if (da.HasFont()) |
| 954 | da.GetFont(csNameTag, fFontSize); |
| 955 | |
| 956 | CFX_WideString csWCaption; |
| 957 | CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption; |
| 958 | |
| 959 | if (pControl->HasMKEntry("CA")) { |
| 960 | csNormalCaption = pControl->GetNormalCaption(); |
| 961 | } |
| 962 | if (pControl->HasMKEntry("RC")) { |
| 963 | csRolloverCaption = pControl->GetRolloverCaption(); |
| 964 | } |
| 965 | if (pControl->HasMKEntry("AC")) { |
| 966 | csDownCaption = pControl->GetDownCaption(); |
| 967 | } |
| 968 | |
| 969 | CPDF_Stream* pNormalIcon = NULL; |
| 970 | CPDF_Stream* pRolloverIcon = NULL; |
| 971 | CPDF_Stream* pDownIcon = NULL; |
| 972 | |
| 973 | if (pControl->HasMKEntry("I")) { |
| 974 | pNormalIcon = pControl->GetNormalIcon(); |
| 975 | } |
| 976 | if (pControl->HasMKEntry("RI")) { |
| 977 | pRolloverIcon = pControl->GetRolloverIcon(); |
| 978 | } |
| 979 | if (pControl->HasMKEntry("IX")) { |
| 980 | pDownIcon = pControl->GetDownIcon(); |
| 981 | } |
| 982 | |
| 983 | if (pNormalIcon) { |
| 984 | if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 985 | if (pImageDict->GetStringBy("Name").IsEmpty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 986 | pImageDict->SetAtString("Name", "ImgA"); |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | if (pRolloverIcon) { |
| 991 | if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 992 | if (pImageDict->GetStringBy("Name").IsEmpty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 993 | pImageDict->SetAtString("Name", "ImgB"); |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | if (pDownIcon) { |
| 998 | if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 999 | if (pImageDict->GetStringBy("Name").IsEmpty()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1000 | pImageDict->SetAtString("Name", "ImgC"); |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | CPDF_IconFit iconFit = pControl->GetIconFit(); |
| 1005 | |
| 1006 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1007 | CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
| 1008 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1009 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1010 | font_map.SetAPType("N"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1011 | |
| 1012 | CFX_ByteString csAP = |
| 1013 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1014 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1015 | crLeftTop, crRightBottom, nBorderStyle, |
| 1016 | dsBorder) + |
| 1017 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1018 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1019 | pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout); |
| 1020 | |
| 1021 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP); |
| 1022 | if (pNormalIcon) |
| 1023 | AddImageToAppearance("N", pNormalIcon); |
| 1024 | |
| 1025 | CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode(); |
| 1026 | if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) { |
| 1027 | if (csRolloverCaption.IsEmpty() && !pRolloverIcon) { |
| 1028 | csRolloverCaption = csNormalCaption; |
| 1029 | pRolloverIcon = pNormalIcon; |
| 1030 | } |
| 1031 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1032 | font_map.SetAPType("R"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1033 | |
| 1034 | csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1035 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1036 | crLeftTop, crRightBottom, |
| 1037 | nBorderStyle, dsBorder) + |
| 1038 | CPWL_Utils::GetPushButtonAppStream( |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1039 | iconFit.GetFittingBounds() ? rcWindow : rcClient, &font_map, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1040 | pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize, |
| 1041 | nLayout); |
| 1042 | |
| 1043 | WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP); |
| 1044 | if (pRolloverIcon) |
| 1045 | AddImageToAppearance("R", pRolloverIcon); |
| 1046 | |
| 1047 | if (csDownCaption.IsEmpty() && !pDownIcon) { |
| 1048 | csDownCaption = csNormalCaption; |
| 1049 | pDownIcon = pNormalIcon; |
| 1050 | } |
| 1051 | |
| 1052 | switch (nBorderStyle) { |
| 1053 | case PBS_BEVELED: { |
| 1054 | CPWL_Color crTemp = crLeftTop; |
| 1055 | crLeftTop = crRightBottom; |
| 1056 | crRightBottom = crTemp; |
| 1057 | } break; |
| 1058 | case PBS_INSET: |
| 1059 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1060 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1061 | break; |
| 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(); |
| 1099 | int32_t nBorderStyle = 0; |
| 1100 | CPWL_Dash dsBorder(3, 0, 0); |
| 1101 | CPWL_Color crLeftTop, crRightBottom; |
| 1102 | |
| 1103 | switch (GetBorderStyle()) { |
| 1104 | case BBS_DASH: |
| 1105 | nBorderStyle = PBS_DASH; |
| 1106 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1107 | break; |
| 1108 | case BBS_BEVELED: |
| 1109 | nBorderStyle = PBS_BEVELED; |
| 1110 | fBorderWidth *= 2; |
| 1111 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1112 | crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); |
| 1113 | break; |
| 1114 | case BBS_INSET: |
| 1115 | nBorderStyle = PBS_INSET; |
| 1116 | fBorderWidth *= 2; |
| 1117 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1118 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1119 | break; |
| 1120 | case BBS_UNDERLINE: |
| 1121 | nBorderStyle = PBS_UNDERLINED; |
| 1122 | break; |
| 1123 | default: |
| 1124 | nBorderStyle = PBS_SOLID; |
| 1125 | break; |
| 1126 | } |
| 1127 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1128 | CFX_FloatRect rcWindow = GetRotatedRect(); |
| 1129 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1130 | |
| 1131 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 1132 | if (da.HasColor()) { |
| 1133 | da.GetColor(iColorType, fc); |
| 1134 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1135 | } |
| 1136 | |
| 1137 | int32_t nStyle = 0; |
| 1138 | |
| 1139 | CFX_WideString csWCaption = pControl->GetNormalCaption(); |
| 1140 | if (csWCaption.GetLength() > 0) { |
| 1141 | switch (csWCaption[0]) { |
| 1142 | case L'l': |
| 1143 | nStyle = PCS_CIRCLE; |
| 1144 | break; |
| 1145 | case L'8': |
| 1146 | nStyle = PCS_CROSS; |
| 1147 | break; |
| 1148 | case L'u': |
| 1149 | nStyle = PCS_DIAMOND; |
| 1150 | break; |
| 1151 | case L'n': |
| 1152 | nStyle = PCS_SQUARE; |
| 1153 | break; |
| 1154 | case L'H': |
| 1155 | nStyle = PCS_STAR; |
| 1156 | break; |
| 1157 | default: // L'4' |
| 1158 | nStyle = PCS_CHECK; |
| 1159 | break; |
| 1160 | } |
| 1161 | } else { |
| 1162 | nStyle = PCS_CHECK; |
| 1163 | } |
| 1164 | |
| 1165 | CFX_ByteString csAP_N_ON = |
| 1166 | CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1167 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1168 | crLeftTop, crRightBottom, nBorderStyle, |
| 1169 | dsBorder); |
| 1170 | |
| 1171 | CFX_ByteString csAP_N_OFF = csAP_N_ON; |
| 1172 | |
| 1173 | switch (nBorderStyle) { |
| 1174 | case PBS_BEVELED: { |
| 1175 | CPWL_Color crTemp = crLeftTop; |
| 1176 | crLeftTop = crRightBottom; |
| 1177 | crRightBottom = crTemp; |
| 1178 | } break; |
| 1179 | case PBS_INSET: |
| 1180 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1181 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1182 | break; |
| 1183 | } |
| 1184 | |
| 1185 | CFX_ByteString csAP_D_ON = |
| 1186 | CPWL_Utils::GetRectFillAppStream( |
| 1187 | rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) + |
| 1188 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1189 | crLeftTop, crRightBottom, nBorderStyle, |
| 1190 | dsBorder); |
| 1191 | |
| 1192 | CFX_ByteString csAP_D_OFF = csAP_D_ON; |
| 1193 | |
| 1194 | csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText); |
| 1195 | csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText); |
| 1196 | |
| 1197 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, |
| 1198 | pControl->GetCheckedAPState()); |
| 1199 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off"); |
| 1200 | |
| 1201 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, |
| 1202 | pControl->GetCheckedAPState()); |
| 1203 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); |
| 1204 | |
| 1205 | CFX_ByteString csAS = GetAppState(); |
| 1206 | if (csAS.IsEmpty()) |
| 1207 | SetAppState("Off"); |
| 1208 | } |
| 1209 | |
| 1210 | void CPDFSDK_Widget::ResetAppearance_RadioButton() { |
| 1211 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1212 | CPWL_Color crBackground, crBorder, crText; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1213 | int iColorType; |
| 1214 | FX_FLOAT fc[4]; |
| 1215 | |
| 1216 | pControl->GetOriginalBackgroundColor(iColorType, fc); |
| 1217 | if (iColorType > 0) |
| 1218 | crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1219 | |
| 1220 | pControl->GetOriginalBorderColor(iColorType, fc); |
| 1221 | if (iColorType > 0) |
| 1222 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1223 | |
| 1224 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
| 1225 | int32_t nBorderStyle = 0; |
| 1226 | CPWL_Dash dsBorder(3, 0, 0); |
| 1227 | CPWL_Color crLeftTop, crRightBottom; |
| 1228 | |
| 1229 | switch (GetBorderStyle()) { |
| 1230 | case BBS_DASH: |
| 1231 | nBorderStyle = PBS_DASH; |
| 1232 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1233 | break; |
| 1234 | case BBS_BEVELED: |
| 1235 | nBorderStyle = PBS_BEVELED; |
| 1236 | fBorderWidth *= 2; |
| 1237 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1238 | crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); |
| 1239 | break; |
| 1240 | case BBS_INSET: |
| 1241 | nBorderStyle = PBS_INSET; |
| 1242 | fBorderWidth *= 2; |
| 1243 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1244 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1245 | break; |
| 1246 | case BBS_UNDERLINE: |
| 1247 | nBorderStyle = PBS_UNDERLINED; |
| 1248 | break; |
| 1249 | default: |
| 1250 | nBorderStyle = PBS_SOLID; |
| 1251 | break; |
| 1252 | } |
| 1253 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1254 | CFX_FloatRect rcWindow = GetRotatedRect(); |
| 1255 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1256 | |
| 1257 | CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); |
| 1258 | if (da.HasColor()) { |
| 1259 | da.GetColor(iColorType, fc); |
| 1260 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1261 | } |
| 1262 | |
| 1263 | int32_t nStyle = 0; |
| 1264 | |
| 1265 | CFX_WideString csWCaption = pControl->GetNormalCaption(); |
| 1266 | if (csWCaption.GetLength() > 0) { |
| 1267 | switch (csWCaption[0]) { |
| 1268 | default: // L'l': |
| 1269 | nStyle = PCS_CIRCLE; |
| 1270 | break; |
| 1271 | case L'8': |
| 1272 | nStyle = PCS_CROSS; |
| 1273 | break; |
| 1274 | case L'u': |
| 1275 | nStyle = PCS_DIAMOND; |
| 1276 | break; |
| 1277 | case L'n': |
| 1278 | nStyle = PCS_SQUARE; |
| 1279 | break; |
| 1280 | case L'H': |
| 1281 | nStyle = PCS_STAR; |
| 1282 | break; |
| 1283 | case L'4': |
| 1284 | nStyle = PCS_CHECK; |
| 1285 | break; |
| 1286 | } |
| 1287 | } else { |
| 1288 | nStyle = PCS_CIRCLE; |
| 1289 | } |
| 1290 | |
| 1291 | CFX_ByteString csAP_N_ON; |
| 1292 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1293 | CFX_FloatRect rcCenter = |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1294 | CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f); |
| 1295 | |
| 1296 | if (nStyle == PCS_CIRCLE) { |
| 1297 | if (nBorderStyle == PBS_BEVELED) { |
| 1298 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1299 | crRightBottom = CPWL_Utils::SubstractColor(crBackground, 0.25f); |
| 1300 | } else if (nBorderStyle == PBS_INSET) { |
| 1301 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5f); |
| 1302 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75f); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1303 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1304 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1305 | csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBackground) + |
| 1306 | CPWL_Utils::GetCircleBorderAppStream( |
| 1307 | rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom, |
| 1308 | nBorderStyle, dsBorder); |
| 1309 | } else { |
| 1310 | csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + |
| 1311 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1312 | crLeftTop, crRightBottom, |
| 1313 | nBorderStyle, dsBorder); |
| 1314 | } |
| 1315 | |
| 1316 | CFX_ByteString csAP_N_OFF = csAP_N_ON; |
| 1317 | |
| 1318 | switch (nBorderStyle) { |
| 1319 | case PBS_BEVELED: { |
| 1320 | CPWL_Color crTemp = crLeftTop; |
| 1321 | crLeftTop = crRightBottom; |
| 1322 | crRightBottom = crTemp; |
| 1323 | } break; |
| 1324 | case PBS_INSET: |
| 1325 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1326 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1327 | break; |
| 1328 | } |
| 1329 | |
| 1330 | CFX_ByteString csAP_D_ON; |
| 1331 | |
| 1332 | if (nStyle == PCS_CIRCLE) { |
| 1333 | CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground, 0.25f); |
| 1334 | if (nBorderStyle == PBS_BEVELED) { |
| 1335 | crLeftTop = CPWL_Utils::SubstractColor(crBackground, 0.25f); |
| 1336 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1337 | crBK = crBackground; |
| 1338 | } else if (nBorderStyle == PBS_INSET) { |
| 1339 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1340 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1341 | } |
| 1342 | |
| 1343 | csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBK) + |
| 1344 | CPWL_Utils::GetCircleBorderAppStream( |
| 1345 | rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom, |
| 1346 | nBorderStyle, dsBorder); |
| 1347 | } else { |
| 1348 | csAP_D_ON = CPWL_Utils::GetRectFillAppStream( |
| 1349 | rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) + |
| 1350 | CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1351 | crLeftTop, crRightBottom, |
| 1352 | nBorderStyle, dsBorder); |
| 1353 | } |
| 1354 | |
| 1355 | CFX_ByteString csAP_D_OFF = csAP_D_ON; |
| 1356 | |
| 1357 | csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText); |
| 1358 | csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText); |
| 1359 | |
| 1360 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, |
| 1361 | pControl->GetCheckedAPState()); |
| 1362 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off"); |
| 1363 | |
| 1364 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, |
| 1365 | pControl->GetCheckedAPState()); |
| 1366 | WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off"); |
| 1367 | |
| 1368 | CFX_ByteString csAS = GetAppState(); |
| 1369 | if (csAS.IsEmpty()) |
| 1370 | SetAppState("Off"); |
| 1371 | } |
| 1372 | |
| 1373 | void CPDFSDK_Widget::ResetAppearance_ComboBox(const FX_WCHAR* sValue) { |
| 1374 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1375 | CPDF_FormField* pField = pControl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1376 | CFX_ByteTextBuf sBody, sLines; |
| 1377 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1378 | CFX_FloatRect rcClient = GetClientRect(); |
| 1379 | CFX_FloatRect rcButton = rcClient; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1380 | rcButton.left = rcButton.right - 13; |
| 1381 | rcButton.Normalize(); |
| 1382 | |
| 1383 | if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) { |
| 1384 | pEdit->EnableRefresh(FALSE); |
| 1385 | |
| 1386 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1387 | CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1388 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1389 | pEdit->SetFontMap(&font_map); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1390 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1391 | CFX_FloatRect rcEdit = rcClient; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1392 | rcEdit.right = rcButton.left; |
| 1393 | rcEdit.Normalize(); |
| 1394 | |
| 1395 | pEdit->SetPlateRect(rcEdit); |
| 1396 | pEdit->SetAlignmentV(1); |
| 1397 | |
| 1398 | FX_FLOAT fFontSize = GetFontSize(); |
| 1399 | if (IsFloatZero(fFontSize)) |
| 1400 | pEdit->SetAutoFontSize(TRUE); |
| 1401 | else |
| 1402 | pEdit->SetFontSize(fFontSize); |
| 1403 | |
| 1404 | pEdit->Initialize(); |
| 1405 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1406 | if (sValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1407 | pEdit->SetText(sValue); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 1408 | } else { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1409 | int32_t nCurSel = pField->GetSelectedIndex(0); |
| 1410 | |
| 1411 | if (nCurSel < 0) |
| 1412 | pEdit->SetText(pField->GetValue().c_str()); |
| 1413 | else |
| 1414 | pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str()); |
| 1415 | } |
| 1416 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1417 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1418 | |
| 1419 | CFX_ByteString sEdit = |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1420 | CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, 0.0f)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1421 | if (sEdit.GetLength() > 0) { |
| 1422 | sBody << "/Tx BMC\n" |
| 1423 | << "q\n"; |
| 1424 | if (rcContent.Width() > rcEdit.Width() || |
| 1425 | rcContent.Height() > rcEdit.Height()) { |
| 1426 | sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width() |
| 1427 | << " " << rcEdit.Height() << " re\nW\nn\n"; |
| 1428 | } |
| 1429 | |
| 1430 | CPWL_Color crText = GetTextPWLColor(); |
| 1431 | sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit |
| 1432 | << "ET\n" |
| 1433 | << "Q\nEMC\n"; |
| 1434 | } |
| 1435 | |
| 1436 | IFX_Edit::DelEdit(pEdit); |
| 1437 | } |
| 1438 | |
| 1439 | sBody << CPWL_Utils::GetDropButtonAppStream(rcButton); |
| 1440 | |
| 1441 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
| 1442 | sLines.GetByteString() + sBody.GetByteString(); |
| 1443 | |
| 1444 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
| 1445 | } |
| 1446 | |
| 1447 | void CPDFSDK_Widget::ResetAppearance_ListBox() { |
| 1448 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1449 | CPDF_FormField* pField = pControl->GetField(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1450 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1451 | CFX_ByteTextBuf sBody, sLines; |
| 1452 | |
| 1453 | if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) { |
| 1454 | pEdit->EnableRefresh(FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1455 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1456 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1457 | CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1458 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1459 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1460 | pEdit->SetFontMap(&font_map); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1461 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1462 | pEdit->SetPlateRect( |
| 1463 | CFX_FloatRect(rcClient.left, 0.0f, rcClient.right, 0.0f)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1464 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1465 | FX_FLOAT fFontSize = GetFontSize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1466 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1467 | if (IsFloatZero(fFontSize)) |
| 1468 | pEdit->SetFontSize(12.0f); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1469 | else |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1470 | pEdit->SetFontSize(fFontSize); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1471 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1472 | pEdit->Initialize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1473 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1474 | CFX_ByteTextBuf sList; |
| 1475 | FX_FLOAT fy = rcClient.top; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1476 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1477 | int32_t nTop = pField->GetTopVisibleIndex(); |
| 1478 | int32_t nCount = pField->CountOptions(); |
| 1479 | int32_t nSelCount = pField->CountSelectedItems(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1480 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1481 | for (int32_t i = nTop; i < nCount; i++) { |
| 1482 | FX_BOOL bSelected = FALSE; |
| 1483 | for (int32_t j = 0; j < nSelCount; j++) { |
| 1484 | if (pField->GetSelectedIndex(j) == i) { |
| 1485 | bSelected = TRUE; |
| 1486 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1487 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | pEdit->SetText(pField->GetOptionLabel(i).c_str()); |
| 1491 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1492 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1493 | FX_FLOAT fItemHeight = rcContent.Height(); |
| 1494 | |
| 1495 | if (bSelected) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1496 | CFX_FloatRect rcItem = |
| 1497 | CFX_FloatRect(rcClient.left, fy - fItemHeight, rcClient.right, fy); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1498 | sList << "q\n" << CPWL_Utils::GetColorAppStream( |
| 1499 | CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f, |
| 1500 | 113.0f / 255.0f), |
| 1501 | TRUE) |
| 1502 | << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width() |
| 1503 | << " " << rcItem.Height() << " re f\n" |
| 1504 | << "Q\n"; |
| 1505 | |
| 1506 | sList << "BT\n" << CPWL_Utils::GetColorAppStream( |
| 1507 | CPWL_Color(COLORTYPE_GRAY, 1), TRUE) |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1508 | << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1509 | << "ET\n"; |
| 1510 | } else { |
| 1511 | CPWL_Color crText = GetTextPWLColor(); |
| 1512 | sList << "BT\n" << CPWL_Utils::GetColorAppStream(crText, TRUE) |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1513 | << CPWL_Utils::GetEditAppStream(pEdit, CFX_FloatPoint(0.0f, fy)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1514 | << "ET\n"; |
| 1515 | } |
| 1516 | |
| 1517 | fy -= fItemHeight; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1518 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1519 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1520 | if (sList.GetSize() > 0) { |
| 1521 | sBody << "/Tx BMC\n" |
| 1522 | << "q\n" << rcClient.left << " " << rcClient.bottom << " " |
| 1523 | << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; |
| 1524 | sBody << sList << "Q\nEMC\n"; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1525 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1526 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1527 | IFX_Edit::DelEdit(pEdit); |
| 1528 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1529 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1530 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
| 1531 | sLines.GetByteString() + sBody.GetByteString(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1532 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1533 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1536 | void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) { |
| 1537 | CPDF_FormControl* pControl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1538 | CPDF_FormField* pField = pControl->GetField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1539 | CFX_ByteTextBuf sBody, sLines; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1540 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1541 | if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) { |
| 1542 | pEdit->EnableRefresh(FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1543 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1544 | CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1545 | CPDFDoc_Environment* pEnv = pDoc->GetEnv(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1546 | |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1547 | CBA_FontMap font_map(this, pEnv->GetSysHandler()); |
| 1548 | pEdit->SetFontMap(&font_map); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1549 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1550 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1551 | pEdit->SetPlateRect(rcClient); |
| 1552 | pEdit->SetAlignmentH(pControl->GetControlAlignment()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1553 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 1554 | uint32_t dwFieldFlags = pField->GetFieldFlags(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1555 | FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1556 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1557 | if (bMultiLine) { |
| 1558 | pEdit->SetMultiLine(TRUE); |
| 1559 | pEdit->SetAutoReturn(TRUE); |
| 1560 | } else { |
| 1561 | pEdit->SetAlignmentV(1); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1562 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1563 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 1564 | uint16_t subWord = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1565 | if ((dwFieldFlags >> 13) & 1) { |
| 1566 | subWord = '*'; |
| 1567 | pEdit->SetPasswordChar(subWord); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1568 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1569 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1570 | int nMaxLen = pField->GetMaxLen(); |
| 1571 | FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1; |
| 1572 | FX_FLOAT fFontSize = GetFontSize(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1573 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 1574 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1575 | CFX_WideString sValueTmp; |
Lei Zhang | 9976672 | 2016-02-23 11:21:48 -0800 | [diff] [blame] | 1576 | if (!sValue && GetMixXFAWidget()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1577 | sValueTmp = GetValue(TRUE); |
| 1578 | sValue = sValueTmp; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1579 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1580 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1581 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1582 | if (nMaxLen > 0) { |
| 1583 | if (bCharArray) { |
| 1584 | pEdit->SetCharArray(nMaxLen); |
Tom Sepez | 7b5bc26 | 2015-03-05 16:44:22 -0800 | [diff] [blame] | 1585 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1586 | if (IsFloatZero(fFontSize)) { |
Lei Zhang | fcfa3b8 | 2015-12-24 21:07:28 -0800 | [diff] [blame] | 1587 | fFontSize = CPWL_Edit::GetCharArrayAutoFontSize( |
| 1588 | font_map.GetPDFFont(0), rcClient, nMaxLen); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1589 | } |
| 1590 | } else { |
| 1591 | if (sValue) |
| 1592 | nMaxLen = wcslen((const wchar_t*)sValue); |
| 1593 | pEdit->SetLimitChar(nMaxLen); |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 1594 | } |
| 1595 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1596 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1597 | if (IsFloatZero(fFontSize)) |
| 1598 | pEdit->SetAutoFontSize(TRUE); |
| 1599 | else |
| 1600 | pEdit->SetFontSize(fFontSize); |
| 1601 | |
| 1602 | pEdit->Initialize(); |
| 1603 | |
| 1604 | if (sValue) |
| 1605 | pEdit->SetText(sValue); |
| 1606 | else |
| 1607 | pEdit->SetText(pField->GetValue().c_str()); |
| 1608 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1609 | CFX_FloatRect rcContent = pEdit->GetContentRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1610 | |
| 1611 | CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream( |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1612 | pEdit, CFX_FloatPoint(0.0f, 0.0f), NULL, !bCharArray, subWord); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1613 | |
| 1614 | if (sEdit.GetLength() > 0) { |
| 1615 | sBody << "/Tx BMC\n" |
| 1616 | << "q\n"; |
| 1617 | if (rcContent.Width() > rcClient.Width() || |
| 1618 | rcContent.Height() > rcClient.Height()) { |
| 1619 | sBody << rcClient.left << " " << rcClient.bottom << " " |
| 1620 | << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n"; |
| 1621 | } |
| 1622 | CPWL_Color crText = GetTextPWLColor(); |
| 1623 | sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit |
| 1624 | << "ET\n" |
| 1625 | << "Q\nEMC\n"; |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 1626 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1627 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1628 | if (bCharArray) { |
| 1629 | switch (GetBorderStyle()) { |
| 1630 | case BBS_SOLID: { |
| 1631 | CFX_ByteString sColor = |
| 1632 | CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); |
| 1633 | if (sColor.GetLength() > 0) { |
| 1634 | sLines << "q\n" << GetBorderWidth() << " w\n" |
| 1635 | << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) |
| 1636 | << " 2 J 0 j\n"; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1637 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1638 | for (int32_t i = 1; i < nMaxLen; i++) { |
| 1639 | sLines << rcClient.left + |
| 1640 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1641 | << " " << rcClient.bottom << " m\n" |
| 1642 | << rcClient.left + |
| 1643 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1644 | << " " << rcClient.top << " l S\n"; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1645 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1646 | |
| 1647 | sLines << "Q\n"; |
| 1648 | } |
| 1649 | } break; |
| 1650 | case BBS_DASH: { |
| 1651 | CFX_ByteString sColor = |
| 1652 | CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE); |
| 1653 | if (sColor.GetLength() > 0) { |
| 1654 | CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0); |
| 1655 | |
| 1656 | sLines << "q\n" << GetBorderWidth() << " w\n" |
| 1657 | << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE) |
| 1658 | << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] " |
| 1659 | << dsBorder.nPhase << " d\n"; |
| 1660 | |
| 1661 | for (int32_t i = 1; i < nMaxLen; i++) { |
| 1662 | sLines << rcClient.left + |
| 1663 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1664 | << " " << rcClient.bottom << " m\n" |
| 1665 | << rcClient.left + |
| 1666 | ((rcClient.right - rcClient.left) / nMaxLen) * i |
| 1667 | << " " << rcClient.top << " l S\n"; |
| 1668 | } |
| 1669 | |
| 1670 | sLines << "Q\n"; |
| 1671 | } |
| 1672 | } break; |
| 1673 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 1674 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1675 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1676 | IFX_Edit::DelEdit(pEdit); |
| 1677 | } |
| 1678 | |
| 1679 | CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + |
| 1680 | sLines.GetByteString() + sBody.GetByteString(); |
| 1681 | WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1684 | CFX_FloatRect CPDFSDK_Widget::GetClientRect() const { |
| 1685 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1686 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
| 1687 | switch (GetBorderStyle()) { |
| 1688 | case BBS_BEVELED: |
| 1689 | case BBS_INSET: |
| 1690 | fBorderWidth *= 2.0f; |
| 1691 | break; |
| 1692 | } |
| 1693 | |
| 1694 | return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1695 | } |
| 1696 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1697 | CFX_FloatRect CPDFSDK_Widget::GetRotatedRect() const { |
| 1698 | CFX_FloatRect rectAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1699 | FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left; |
| 1700 | FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom; |
| 1701 | |
| 1702 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1703 | CFX_FloatRect rcPDFWindow; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1704 | switch (abs(pControl->GetRotation() % 360)) { |
| 1705 | case 0: |
| 1706 | case 180: |
| 1707 | default: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1708 | rcPDFWindow = CFX_FloatRect(0, 0, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1709 | break; |
| 1710 | case 90: |
| 1711 | case 270: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1712 | rcPDFWindow = CFX_FloatRect(0, 0, fHeight, fWidth); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1713 | break; |
| 1714 | } |
| 1715 | |
| 1716 | return rcPDFWindow; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1719 | CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const { |
| 1720 | CPWL_Color crBackground = GetFillPWLColor(); |
| 1721 | if (crBackground.nColorType != COLORTYPE_TRANSPARENT) { |
| 1722 | return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground); |
| 1723 | } |
| 1724 | return ""; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1725 | } |
| 1726 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1727 | CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1728 | CFX_FloatRect rcWindow = GetRotatedRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1729 | CPWL_Color crBorder = GetBorderPWLColor(); |
| 1730 | CPWL_Color crBackground = GetFillPWLColor(); |
| 1731 | CPWL_Color crLeftTop, crRightBottom; |
| 1732 | |
| 1733 | FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); |
| 1734 | int32_t nBorderStyle = 0; |
| 1735 | CPWL_Dash dsBorder(3, 0, 0); |
| 1736 | |
| 1737 | switch (GetBorderStyle()) { |
| 1738 | case BBS_DASH: |
| 1739 | nBorderStyle = PBS_DASH; |
| 1740 | dsBorder = CPWL_Dash(3, 3, 0); |
| 1741 | break; |
| 1742 | case BBS_BEVELED: |
| 1743 | nBorderStyle = PBS_BEVELED; |
| 1744 | fBorderWidth *= 2; |
| 1745 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); |
| 1746 | crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); |
| 1747 | break; |
| 1748 | case BBS_INSET: |
| 1749 | nBorderStyle = PBS_INSET; |
| 1750 | fBorderWidth *= 2; |
| 1751 | crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); |
| 1752 | crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); |
| 1753 | break; |
| 1754 | case BBS_UNDERLINE: |
| 1755 | nBorderStyle = PBS_UNDERLINED; |
| 1756 | break; |
| 1757 | default: |
| 1758 | nBorderStyle = PBS_SOLID; |
| 1759 | break; |
| 1760 | } |
| 1761 | |
| 1762 | return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, |
| 1763 | crLeftTop, crRightBottom, nBorderStyle, |
| 1764 | dsBorder); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1767 | CFX_Matrix CPDFSDK_Widget::GetMatrix() const { |
| 1768 | CFX_Matrix mt; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1769 | CPDF_FormControl* pControl = GetFormControl(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1770 | CFX_FloatRect rcAnnot = GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1771 | FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left; |
| 1772 | FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom; |
| 1773 | |
| 1774 | switch (abs(pControl->GetRotation() % 360)) { |
| 1775 | case 0: |
| 1776 | default: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1777 | mt = CFX_Matrix(1, 0, 0, 1, 0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1778 | break; |
| 1779 | case 90: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1780 | mt = CFX_Matrix(0, 1, -1, 0, fWidth, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1781 | break; |
| 1782 | case 180: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1783 | mt = CFX_Matrix(-1, 0, 0, -1, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1784 | break; |
| 1785 | case 270: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 1786 | mt = CFX_Matrix(0, -1, 1, 0, 0, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1787 | break; |
| 1788 | } |
| 1789 | |
| 1790 | return mt; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1793 | CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const { |
| 1794 | CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0); |
| 1795 | |
| 1796 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1797 | CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); |
| 1798 | if (da.HasColor()) { |
| 1799 | int32_t iColorType; |
| 1800 | FX_FLOAT fc[4]; |
| 1801 | da.GetColor(iColorType, fc); |
| 1802 | crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1803 | } |
| 1804 | |
| 1805 | return crText; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1806 | } |
| 1807 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1808 | CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const { |
| 1809 | CPWL_Color crBorder; |
| 1810 | |
| 1811 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1812 | int32_t iColorType; |
| 1813 | FX_FLOAT fc[4]; |
| 1814 | pFormCtrl->GetOriginalBorderColor(iColorType, fc); |
| 1815 | if (iColorType > 0) |
| 1816 | crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1817 | |
| 1818 | return crBorder; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1821 | CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const { |
| 1822 | CPWL_Color crFill; |
| 1823 | |
| 1824 | CPDF_FormControl* pFormCtrl = GetFormControl(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1825 | int32_t iColorType; |
| 1826 | FX_FLOAT fc[4]; |
| 1827 | pFormCtrl->GetOriginalBackgroundColor(iColorType, fc); |
| 1828 | if (iColorType > 0) |
| 1829 | crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); |
| 1830 | |
| 1831 | return crFill; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1834 | void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, |
| 1835 | CPDF_Stream* pImage) { |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 1836 | CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 1837 | ASSERT(pDoc); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1838 | |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 1839 | CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictBy("AP"); |
| 1840 | CPDF_Stream* pStream = pAPDict->GetStreamBy(sAPType); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1841 | CPDF_Dictionary* pStreamDict = pStream->GetDict(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1842 | CFX_ByteString sImageAlias = "IMG"; |
| 1843 | |
| 1844 | if (CPDF_Dictionary* pImageDict = pImage->GetDict()) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 1845 | sImageAlias = pImageDict->GetStringBy("Name"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1846 | if (sImageAlias.IsEmpty()) |
| 1847 | sImageAlias = "IMG"; |
| 1848 | } |
| 1849 | |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 1850 | CPDF_Dictionary* pStreamResList = pStreamDict->GetDictBy("Resources"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1851 | if (!pStreamResList) { |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 1852 | pStreamResList = new CPDF_Dictionary(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1853 | pStreamDict->SetAt("Resources", pStreamResList); |
| 1854 | } |
| 1855 | |
| 1856 | if (pStreamResList) { |
Tom Sepez | ae51c81 | 2015-08-05 12:34:06 -0700 | [diff] [blame] | 1857 | CPDF_Dictionary* pXObject = new CPDF_Dictionary; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1858 | pXObject->SetAtReference(sImageAlias, pDoc, pImage); |
| 1859 | pStreamResList->SetAt("XObject", pXObject); |
| 1860 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1861 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1862 | |
| 1863 | void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 1864 | if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictBy("AP")) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1865 | pAPDict->RemoveAt(sAPType); |
| 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, |
| 1870 | PDFSDK_FieldAction& data, |
| 1871 | CPDFSDK_PageView* pPageView) { |
| 1872 | CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1873 | CPDFDoc_Environment* pEnv = pDocument->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1874 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1875 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 1876 | CPDFXFA_Document* pDoc = pDocument->GetXFADocument(); |
| 1877 | if (IXFA_Widget* hWidget = GetMixXFAWidget()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1878 | XFA_EVENTTYPE eEventType = GetXFAEventType(type, data.bWillCommit); |
| 1879 | |
| 1880 | if (eEventType != XFA_EVENT_Unknown) { |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 1881 | if (IXFA_WidgetHandler* pXFAWidgetHandler = GetXFAWidgetHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1882 | CXFA_EventParam param; |
| 1883 | param.m_eType = eEventType; |
| 1884 | param.m_wsChange = data.sChange; |
| 1885 | param.m_iCommitKey = data.nCommitKey; |
| 1886 | param.m_bShift = data.bShift; |
| 1887 | param.m_iSelStart = data.nSelStart; |
| 1888 | param.m_iSelEnd = data.nSelEnd; |
| 1889 | param.m_wsFullText = data.sValue; |
| 1890 | param.m_bKeyDown = data.bKeyDown; |
| 1891 | param.m_bModifier = data.bModifier; |
| 1892 | param.m_wsNewText = data.sValue; |
| 1893 | if (data.nSelEnd > data.nSelStart) |
| 1894 | param.m_wsNewText.Delete(data.nSelStart, |
| 1895 | data.nSelEnd - data.nSelStart); |
| 1896 | for (int i = data.sChange.GetLength() - 1; i >= 0; i--) |
| 1897 | param.m_wsNewText.Insert(data.nSelStart, data.sChange[i]); |
| 1898 | param.m_wsPrevText = data.sValue; |
| 1899 | |
| 1900 | CXFA_WidgetAcc* pAcc = pXFAWidgetHandler->GetDataAcc(hWidget); |
| 1901 | param.m_pTarget = pAcc; |
| 1902 | int32_t nRet = pXFAWidgetHandler->ProcessEvent(pAcc, ¶m); |
| 1903 | |
| 1904 | if (IXFA_DocView* pDocView = pDoc->GetXFADocView()) { |
| 1905 | pDocView->UpdateDocView(); |
| 1906 | } |
| 1907 | |
Wei Li | e98ac2e | 2016-03-18 15:43:04 -0700 | [diff] [blame] | 1908 | if (nRet == XFA_EVENTERROR_Success) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1909 | return TRUE; |
| 1910 | } |
| 1911 | } |
| 1912 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1913 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1914 | |
| 1915 | CPDF_Action action = GetAAction(type); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 1916 | if (action.GetDict() && action.GetType() != CPDF_Action::Unknown) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1917 | CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
| 1918 | return pActionHandler->DoAction_Field(action, type, pDocument, |
| 1919 | GetFormField(), data); |
| 1920 | } |
| 1921 | return FALSE; |
| 1922 | } |
| 1923 | |
| 1924 | CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) { |
| 1925 | switch (eAAT) { |
| 1926 | case CPDF_AAction::CursorEnter: |
| 1927 | case CPDF_AAction::CursorExit: |
| 1928 | case CPDF_AAction::ButtonDown: |
| 1929 | case CPDF_AAction::ButtonUp: |
| 1930 | case CPDF_AAction::GetFocus: |
| 1931 | case CPDF_AAction::LoseFocus: |
| 1932 | case CPDF_AAction::PageOpen: |
| 1933 | case CPDF_AAction::PageClose: |
| 1934 | case CPDF_AAction::PageVisible: |
| 1935 | case CPDF_AAction::PageInvisible: |
| 1936 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 1937 | |
| 1938 | case CPDF_AAction::KeyStroke: |
| 1939 | case CPDF_AAction::Format: |
| 1940 | case CPDF_AAction::Validate: |
| 1941 | case CPDF_AAction::Calculate: { |
| 1942 | CPDF_FormField* pField = GetFormField(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 1943 | if (pField->GetAdditionalAction().GetDict()) |
| 1944 | return pField->GetAdditionalAction().GetAction(eAAT); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1945 | return CPDFSDK_BAAnnot::GetAAction(eAAT); |
| 1946 | } |
| 1947 | default: |
| 1948 | break; |
| 1949 | } |
| 1950 | |
| 1951 | return CPDF_Action(); |
| 1952 | } |
| 1953 | |
| 1954 | CFX_WideString CPDFSDK_Widget::GetAlternateName() const { |
| 1955 | CPDF_FormField* pFormField = GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1956 | return pFormField->GetAlternateName(); |
| 1957 | } |
| 1958 | |
| 1959 | int32_t CPDFSDK_Widget::GetAppearanceAge() const { |
| 1960 | return m_nAppAge; |
| 1961 | } |
| 1962 | |
| 1963 | int32_t CPDFSDK_Widget::GetValueAge() const { |
| 1964 | return m_nValueAge; |
| 1965 | } |
| 1966 | |
| 1967 | FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY) { |
| 1968 | CPDF_Annot* pAnnot = GetPDFAnnot(); |
| 1969 | CFX_FloatRect annotRect; |
| 1970 | pAnnot->GetRect(annotRect); |
| 1971 | if (annotRect.Contains(pageX, pageY)) { |
| 1972 | if (!IsVisible()) |
| 1973 | return FALSE; |
| 1974 | |
| 1975 | int nFieldFlags = GetFieldFlags(); |
| 1976 | if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) |
| 1977 | return FALSE; |
| 1978 | |
| 1979 | return TRUE; |
| 1980 | } |
| 1981 | return FALSE; |
| 1982 | } |
| 1983 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 1984 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1985 | CPDFSDK_XFAWidget::CPDFSDK_XFAWidget(IXFA_Widget* pAnnot, |
| 1986 | CPDFSDK_PageView* pPageView, |
| 1987 | CPDFSDK_InterForm* pInterForm) |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 1988 | : CPDFSDK_Annot(pPageView), |
| 1989 | m_pInterForm(pInterForm), |
| 1990 | m_hXFAWidget(pAnnot) {} |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1991 | |
| 1992 | FX_BOOL CPDFSDK_XFAWidget::IsXFAField() { |
| 1993 | return TRUE; |
| 1994 | } |
| 1995 | |
| 1996 | CFX_ByteString CPDFSDK_XFAWidget::GetType() const { |
| 1997 | return FSDK_XFAWIDGET_TYPENAME; |
| 1998 | } |
| 1999 | |
Tom Sepez | 3343d14 | 2015-11-02 09:54:54 -0800 | [diff] [blame] | 2000 | CFX_FloatRect CPDFSDK_XFAWidget::GetRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2001 | CPDFSDK_PageView* pPageView = GetPageView(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2002 | CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 2003 | CPDFXFA_Document* pDoc = pDocument->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2004 | IXFA_DocView* pDocView = pDoc->GetXFADocView(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2005 | IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2006 | |
| 2007 | CFX_RectF rcBBox; |
| 2008 | pWidgetHandler->GetRect(GetXFAWidget(), rcBBox); |
| 2009 | |
| 2010 | return CFX_FloatRect(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, |
| 2011 | rcBBox.top + rcBBox.height); |
| 2012 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 2013 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2014 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2015 | CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument) |
| 2016 | : m_pDocument(pDocument), |
| 2017 | m_pInterForm(NULL), |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 2018 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2019 | m_bXfaCalculate(TRUE), |
| 2020 | m_bXfaValidationsEnabled(TRUE), |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 2021 | #endif // PDF_ENABLE_XFA |
| 2022 | m_bCalculate(TRUE), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2023 | m_bBusy(FALSE) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 2024 | m_pInterForm = new CPDF_InterForm(m_pDocument->GetPDFDocument(), FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2025 | m_pInterForm->SetFormNotify(this); |
| 2026 | |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2027 | for (int i = 0; i < kNumFieldTypes; ++i) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2028 | m_bNeedHightlight[i] = FALSE; |
| 2029 | m_iHighlightAlpha = 0; |
| 2030 | } |
| 2031 | |
| 2032 | CPDFSDK_InterForm::~CPDFSDK_InterForm() { |
| 2033 | delete m_pInterForm; |
| 2034 | m_pInterForm = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2035 | m_Map.clear(); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 2036 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2037 | m_XFAMap.RemoveAll(); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 2038 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2039 | } |
| 2040 | |
| 2041 | FX_BOOL CPDFSDK_InterForm::HighlightWidgets() { |
| 2042 | return FALSE; |
| 2043 | } |
| 2044 | |
| 2045 | CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget, |
| 2046 | FX_BOOL bNext) const { |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 2047 | std::unique_ptr<CBA_AnnotIterator> pIterator( |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2048 | new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", "")); |
| 2049 | |
| 2050 | if (bNext) { |
| 2051 | return (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget); |
| 2052 | } |
| 2053 | return (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget); |
| 2054 | } |
| 2055 | |
| 2056 | CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const { |
| 2057 | if (!pControl || !m_pInterForm) |
| 2058 | return nullptr; |
| 2059 | |
| 2060 | CPDFSDK_Widget* pWidget = nullptr; |
| 2061 | const auto it = m_Map.find(pControl); |
| 2062 | if (it != m_Map.end()) |
| 2063 | pWidget = it->second; |
| 2064 | |
| 2065 | if (pWidget) |
| 2066 | return pWidget; |
| 2067 | |
| 2068 | CPDF_Dictionary* pControlDict = pControl->GetWidget(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 2069 | CPDF_Document* pDocument = m_pDocument->GetPDFDocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2070 | CPDFSDK_PageView* pPage = nullptr; |
| 2071 | |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2072 | if (CPDF_Dictionary* pPageDict = pControlDict->GetDictBy("P")) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2073 | int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum()); |
| 2074 | if (nPageIndex >= 0) { |
| 2075 | pPage = m_pDocument->GetPageView(nPageIndex); |
| 2076 | } |
| 2077 | } |
| 2078 | |
| 2079 | if (!pPage) { |
| 2080 | int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict); |
| 2081 | if (nPageIndex >= 0) { |
| 2082 | pPage = m_pDocument->GetPageView(nPageIndex); |
| 2083 | } |
| 2084 | } |
| 2085 | |
| 2086 | if (!pPage) |
| 2087 | return nullptr; |
| 2088 | return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict); |
| 2089 | } |
| 2090 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2091 | void CPDFSDK_InterForm::GetWidgets( |
| 2092 | const CFX_WideString& sFieldName, |
| 2093 | std::vector<CPDFSDK_Widget*>* widgets) const { |
| 2094 | for (int i = 0, sz = m_pInterForm->CountFields(sFieldName); i < sz; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2095 | CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2096 | ASSERT(pFormField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2097 | GetWidgets(pFormField, widgets); |
| 2098 | } |
| 2099 | } |
| 2100 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2101 | void CPDFSDK_InterForm::GetWidgets( |
| 2102 | CPDF_FormField* pField, |
| 2103 | std::vector<CPDFSDK_Widget*>* widgets) const { |
| 2104 | for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2105 | CPDF_FormControl* pFormCtrl = pField->GetControl(i); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2106 | ASSERT(pFormCtrl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2107 | CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2108 | if (pWidget) |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2109 | widgets->push_back(pWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2110 | } |
| 2111 | } |
| 2112 | |
| 2113 | int CPDFSDK_InterForm::GetPageIndexByAnnotDict( |
| 2114 | CPDF_Document* pDocument, |
| 2115 | CPDF_Dictionary* pAnnotDict) const { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2116 | ASSERT(pAnnotDict); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2117 | |
| 2118 | for (int i = 0, sz = pDocument->GetPageCount(); i < sz; i++) { |
| 2119 | if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i)) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2120 | if (CPDF_Array* pAnnots = pPageDict->GetArrayBy("Annots")) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2121 | for (int j = 0, jsz = pAnnots->GetCount(); j < jsz; j++) { |
| 2122 | CPDF_Object* pDict = pAnnots->GetElementValue(j); |
| 2123 | if (pAnnotDict == pDict) { |
| 2124 | return i; |
| 2125 | } |
| 2126 | } |
| 2127 | } |
| 2128 | } |
| 2129 | } |
| 2130 | |
| 2131 | return -1; |
| 2132 | } |
| 2133 | |
| 2134 | void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl, |
| 2135 | CPDFSDK_Widget* pWidget) { |
| 2136 | m_Map[pControl] = pWidget; |
| 2137 | } |
| 2138 | |
| 2139 | void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl) { |
| 2140 | m_Map.erase(pControl); |
| 2141 | } |
| 2142 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 2143 | void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled) { |
| 2144 | m_bCalculate = bEnabled; |
| 2145 | } |
| 2146 | |
| 2147 | FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const { |
| 2148 | return m_bCalculate; |
| 2149 | } |
| 2150 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 2151 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2152 | void CPDFSDK_InterForm::AddXFAMap(IXFA_Widget* hWidget, |
| 2153 | CPDFSDK_XFAWidget* pWidget) { |
| 2154 | m_XFAMap.SetAt(hWidget, pWidget); |
| 2155 | } |
| 2156 | |
| 2157 | void CPDFSDK_InterForm::RemoveXFAMap(IXFA_Widget* hWidget) { |
| 2158 | m_XFAMap.RemoveKey(hWidget); |
| 2159 | } |
| 2160 | |
| 2161 | CPDFSDK_XFAWidget* CPDFSDK_InterForm::GetXFAWidget(IXFA_Widget* hWidget) { |
| 2162 | CPDFSDK_XFAWidget* pWidget = NULL; |
| 2163 | m_XFAMap.Lookup(hWidget, pWidget); |
| 2164 | |
| 2165 | return pWidget; |
| 2166 | } |
| 2167 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2168 | void CPDFSDK_InterForm::XfaEnableCalculate(FX_BOOL bEnabled) { |
| 2169 | m_bXfaCalculate = bEnabled; |
| 2170 | } |
| 2171 | FX_BOOL CPDFSDK_InterForm::IsXfaCalculateEnabled() const { |
| 2172 | return m_bXfaCalculate; |
| 2173 | } |
| 2174 | |
| 2175 | FX_BOOL CPDFSDK_InterForm::IsXfaValidationsEnabled() { |
| 2176 | return m_bXfaValidationsEnabled; |
| 2177 | } |
| 2178 | void CPDFSDK_InterForm::XfaSetValidationsEnabled(FX_BOOL bEnabled) { |
| 2179 | m_bXfaValidationsEnabled = bEnabled; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 2180 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 2181 | #endif // PDF_ENABLE_XFA |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 2182 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2183 | void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2184 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2185 | ASSERT(pEnv); |
| 2186 | if (!pEnv->IsJSInitiated()) |
| 2187 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2188 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2189 | if (m_bBusy) |
| 2190 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2191 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2192 | m_bBusy = TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2193 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2194 | if (IsCalculateEnabled()) { |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2195 | IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2196 | pRuntime->SetReaderDocument(m_pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2197 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2198 | int nSize = m_pInterForm->CountFieldsInCalculationOrder(); |
| 2199 | for (int i = 0; i < nSize; i++) { |
| 2200 | if (CPDF_FormField* pField = |
| 2201 | m_pInterForm->GetFieldInCalculationOrder(i)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2202 | int nType = pField->GetFieldType(); |
| 2203 | if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { |
| 2204 | CPDF_AAction aAction = pField->GetAdditionalAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2205 | if (aAction.GetDict() && |
| 2206 | aAction.ActionExist(CPDF_AAction::Calculate)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2207 | CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2208 | if (action.GetDict()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2209 | CFX_WideString csJS = action.GetJavaScript(); |
| 2210 | if (!csJS.IsEmpty()) { |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2211 | IJS_Context* pContext = pRuntime->NewContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2212 | CFX_WideString sOldValue = pField->GetValue(); |
| 2213 | CFX_WideString sValue = sOldValue; |
| 2214 | FX_BOOL bRC = TRUE; |
| 2215 | pContext->OnField_Calculate(pFormField, pField, sValue, bRC); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2216 | |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2217 | CFX_WideString sInfo; |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 2218 | FX_BOOL bRet = pContext->RunScript(csJS, &sInfo); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2219 | pRuntime->ReleaseContext(pContext); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2220 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2221 | if (bRet) { |
| 2222 | if (bRC) { |
| 2223 | if (sValue.Compare(sOldValue) != 0) |
| 2224 | pField->SetValue(sValue, TRUE); |
| 2225 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2226 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2227 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2228 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2229 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2230 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2231 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2232 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2233 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2234 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2235 | m_bBusy = FALSE; |
| 2236 | } |
| 2237 | |
| 2238 | CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, |
| 2239 | FX_BOOL& bFormated) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2240 | CFX_WideString sValue = pFormField->GetValue(); |
| 2241 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2242 | ASSERT(pEnv); |
| 2243 | if (!pEnv->IsJSInitiated()) { |
| 2244 | bFormated = FALSE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2245 | return sValue; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2246 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2247 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2248 | IJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2249 | pRuntime->SetReaderDocument(m_pDocument); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2250 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2251 | if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX) { |
| 2252 | if (pFormField->CountSelectedItems() > 0) { |
| 2253 | int index = pFormField->GetSelectedIndex(0); |
| 2254 | if (index >= 0) |
| 2255 | sValue = pFormField->GetOptionLabel(index); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2256 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2257 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2258 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2259 | bFormated = FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2260 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2261 | CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2262 | if (aAction.GetDict() && aAction.ActionExist(CPDF_AAction::Format)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2263 | CPDF_Action action = aAction.GetAction(CPDF_AAction::Format); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2264 | if (action.GetDict()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2265 | CFX_WideString script = action.GetJavaScript(); |
| 2266 | if (!script.IsEmpty()) { |
| 2267 | CFX_WideString Value = sValue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2268 | |
Tom Sepez | ba038bc | 2015-10-08 12:03:00 -0700 | [diff] [blame] | 2269 | IJS_Context* pContext = pRuntime->NewContext(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2270 | pContext->OnField_Format(pFormField, Value, TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2271 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2272 | CFX_WideString sInfo; |
Tom Sepez | 3342090 | 2015-10-13 15:00:10 -0700 | [diff] [blame] | 2273 | FX_BOOL bRet = pContext->RunScript(script, &sInfo); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2274 | pRuntime->ReleaseContext(pContext); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2275 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2276 | if (bRet) { |
| 2277 | sValue = Value; |
| 2278 | bFormated = TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2279 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2280 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2281 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | return sValue; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2287 | void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, |
| 2288 | const FX_WCHAR* sValue, |
| 2289 | FX_BOOL bValueChanged) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2290 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2291 | CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2292 | ASSERT(pFormCtrl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2293 | if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) |
| 2294 | pWidget->ResetAppearance(sValue, bValueChanged); |
| 2295 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2296 | } |
| 2297 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2298 | void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2299 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2300 | CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2301 | ASSERT(pFormCtrl); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2302 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2303 | if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) { |
| 2304 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2305 | CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller(); |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 2306 | UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2307 | CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2308 | FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 2309 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2310 | pEnv->FFI_Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right, |
| 2311 | rcBBox.bottom); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2312 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2313 | } |
| 2314 | } |
| 2315 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2316 | FX_BOOL CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, |
| 2317 | const CFX_WideString& csValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2318 | CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2319 | if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::KeyStroke)) |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2320 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2321 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2322 | CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2323 | if (!action.GetDict()) |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2324 | return TRUE; |
| 2325 | |
| 2326 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2327 | CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
| 2328 | PDFSDK_FieldAction fa; |
| 2329 | fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); |
| 2330 | fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); |
| 2331 | fa.sValue = csValue; |
| 2332 | pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke, |
| 2333 | m_pDocument, pFormField, fa); |
| 2334 | return fa.bRC; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2337 | FX_BOOL CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, |
| 2338 | const CFX_WideString& csValue) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2339 | CPDF_AAction aAction = pFormField->GetAdditionalAction(); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2340 | if (!aAction.GetDict() || !aAction.ActionExist(CPDF_AAction::Validate)) |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2341 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2342 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2343 | CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2344 | if (!action.GetDict()) |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2345 | return TRUE; |
| 2346 | |
| 2347 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
| 2348 | CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); |
| 2349 | PDFSDK_FieldAction fa; |
| 2350 | fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); |
| 2351 | fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); |
| 2352 | fa.sValue = csValue; |
| 2353 | pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate, |
| 2354 | m_pDocument, pFormField, fa); |
| 2355 | return fa.bRC; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2356 | } |
| 2357 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2358 | FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) { |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2359 | ASSERT(action.GetDict()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2360 | |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2361 | CPDF_ActionFields af(&action); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2362 | std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
| 2363 | std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2364 | |
| 2365 | FX_BOOL bHide = action.GetHideStatus(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2366 | FX_BOOL bChanged = FALSE; |
| 2367 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2368 | for (CPDF_FormField* pField : fields) { |
| 2369 | for (int i = 0, sz = pField->CountControls(); i < sz; ++i) { |
| 2370 | CPDF_FormControl* pControl = pField->GetControl(i); |
| 2371 | ASSERT(pControl); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2372 | |
| 2373 | if (CPDFSDK_Widget* pWidget = GetWidget(pControl)) { |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 2374 | uint32_t nFlags = pWidget->GetFlags(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2375 | nFlags &= ~ANNOTFLAG_INVISIBLE; |
| 2376 | nFlags &= ~ANNOTFLAG_NOVIEW; |
| 2377 | if (bHide) |
| 2378 | nFlags |= ANNOTFLAG_HIDDEN; |
| 2379 | else |
| 2380 | nFlags &= ~ANNOTFLAG_HIDDEN; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2381 | pWidget->SetFlags(nFlags); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2382 | pWidget->GetPageView()->UpdateView(pWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2383 | bChanged = TRUE; |
| 2384 | } |
| 2385 | } |
| 2386 | } |
| 2387 | |
| 2388 | return bChanged; |
| 2389 | } |
| 2390 | |
| 2391 | FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2392 | CFX_WideString sDestination = action.GetFilePath(); |
| 2393 | if (sDestination.IsEmpty()) |
| 2394 | return FALSE; |
| 2395 | |
| 2396 | CPDF_Dictionary* pActionDict = action.GetDict(); |
| 2397 | if (pActionDict->KeyExist("Fields")) { |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2398 | CPDF_ActionFields af(&action); |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 2399 | uint32_t dwFlags = action.GetFlags(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2400 | std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
| 2401 | std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
| 2402 | if (!fields.empty()) { |
| 2403 | bool bIncludeOrExclude = !(dwFlags & 0x01); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2404 | if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude)) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2405 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2406 | |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 2407 | return SubmitFields(sDestination, fields, bIncludeOrExclude, false); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2408 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2409 | } |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2410 | if (m_pInterForm->CheckRequiredFields(nullptr, true)) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2411 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2412 | |
| 2413 | return SubmitForm(sDestination, FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2414 | } |
| 2415 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2416 | FX_BOOL CPDFSDK_InterForm::SubmitFields( |
| 2417 | const CFX_WideString& csDestination, |
| 2418 | const std::vector<CPDF_FormField*>& fields, |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 2419 | bool bIncludeOrExclude, |
| 2420 | bool bUrlEncoded) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2421 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2422 | |
| 2423 | CFX_ByteTextBuf textBuf; |
| 2424 | ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf); |
| 2425 | |
| 2426 | uint8_t* pBuffer = textBuf.GetBuffer(); |
| 2427 | FX_STRSIZE nBufSize = textBuf.GetLength(); |
| 2428 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2429 | if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) |
| 2430 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2431 | |
| 2432 | pEnv->JS_docSubmitForm(pBuffer, nBufSize, csDestination.c_str()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2433 | return TRUE; |
| 2434 | } |
| 2435 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2436 | FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, |
| 2437 | CFX_WideString csTxtFile) { |
| 2438 | return TRUE; |
| 2439 | } |
| 2440 | |
| 2441 | FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, |
| 2442 | FX_STRSIZE& nBufSize) { |
| 2443 | CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize); |
| 2444 | if (pFDF) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2445 | CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDictBy("FDF"); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 2446 | if (!pMainDict) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2447 | return FALSE; |
| 2448 | |
| 2449 | // Get fields |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2450 | CPDF_Array* pFields = pMainDict->GetArrayBy("Fields"); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 2451 | if (!pFields) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2452 | return FALSE; |
| 2453 | |
| 2454 | CFX_ByteTextBuf fdfEncodedData; |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 2455 | for (uint32_t i = 0; i < pFields->GetCount(); i++) { |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2456 | CPDF_Dictionary* pField = pFields->GetDictAt(i); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 2457 | if (!pField) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2458 | continue; |
| 2459 | CFX_WideString name; |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2460 | name = pField->GetUnicodeTextBy("T"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2461 | CFX_ByteString name_b = CFX_ByteString::FromUnicode(name); |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2462 | CFX_ByteString csBValue = pField->GetStringBy("V"); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2463 | CFX_WideString csWValue = PDF_DecodeText(csBValue); |
| 2464 | CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue); |
| 2465 | |
Tom Sepez | 052a8d9 | 2016-02-19 14:41:46 -0800 | [diff] [blame] | 2466 | fdfEncodedData << name_b.GetBuffer(name_b.GetLength()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2467 | name_b.ReleaseBuffer(); |
Tom Sepez | 052a8d9 | 2016-02-19 14:41:46 -0800 | [diff] [blame] | 2468 | fdfEncodedData << "="; |
| 2469 | fdfEncodedData << csValue_b.GetBuffer(csValue_b.GetLength()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2470 | csValue_b.ReleaseBuffer(); |
| 2471 | if (i != pFields->GetCount() - 1) |
Tom Sepez | 052a8d9 | 2016-02-19 14:41:46 -0800 | [diff] [blame] | 2472 | fdfEncodedData << "&"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | nBufSize = fdfEncodedData.GetLength(); |
| 2476 | pBuf = FX_Alloc(uint8_t, nBufSize); |
| 2477 | FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize); |
| 2478 | } |
| 2479 | return TRUE; |
| 2480 | } |
| 2481 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2482 | FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( |
| 2483 | const std::vector<CPDF_FormField*>& fields, |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 2484 | bool bIncludeOrExclude, |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2485 | CFX_ByteTextBuf& textBuf) { |
Lei Zhang | aa8bf7e | 2015-12-24 19:13:32 -0800 | [diff] [blame] | 2486 | std::unique_ptr<CFDF_Document> pFDF(m_pInterForm->ExportToFDF( |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2487 | m_pDocument->GetPath(), fields, bIncludeOrExclude)); |
| 2488 | return pFDF ? pFDF->WriteBuf(textBuf) : FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2489 | } |
| 2490 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 2491 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2492 | void CPDFSDK_InterForm::SynchronizeField(CPDF_FormField* pFormField, |
| 2493 | FX_BOOL bSynchronizeElse) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2494 | int x = 0; |
| 2495 | if (m_FieldSynchronizeMap.Lookup(pFormField, x)) |
| 2496 | return; |
| 2497 | |
| 2498 | for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) { |
| 2499 | CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); |
Lei Zhang | 5eca305 | 2016-02-22 20:32:21 -0800 | [diff] [blame] | 2500 | ASSERT(pFormCtrl); |
| 2501 | ASSERT(m_pInterForm); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2502 | if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) { |
| 2503 | pWidget->Synchronize(bSynchronizeElse); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2504 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2505 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2506 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 2507 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2508 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2509 | CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName( |
| 2510 | const CFX_WideString& sFileExt) { |
| 2511 | CFX_WideString sFileName; |
| 2512 | return L""; |
| 2513 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2514 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2515 | FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, |
| 2516 | FX_BOOL bUrlEncoded) { |
| 2517 | if (sDestination.IsEmpty()) |
| 2518 | return FALSE; |
| 2519 | |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 2520 | if (!m_pDocument || !m_pInterForm) |
| 2521 | return FALSE; |
| 2522 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2523 | CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2524 | CFX_WideString wsPDFFilePath = m_pDocument->GetPath(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2525 | CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath); |
Lei Zhang | 997de61 | 2015-11-04 18:17:53 -0800 | [diff] [blame] | 2526 | if (!pFDFDoc) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2527 | return FALSE; |
| 2528 | |
| 2529 | CFX_ByteTextBuf FdfBuffer; |
| 2530 | FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer); |
| 2531 | delete pFDFDoc; |
| 2532 | if (!bRet) |
| 2533 | return FALSE; |
| 2534 | |
| 2535 | uint8_t* pBuffer = FdfBuffer.GetBuffer(); |
| 2536 | FX_STRSIZE nBufSize = FdfBuffer.GetLength(); |
| 2537 | |
| 2538 | if (bUrlEncoded) { |
| 2539 | if (!FDFToURLEncodedData(pBuffer, nBufSize)) |
| 2540 | return FALSE; |
| 2541 | } |
| 2542 | |
| 2543 | pEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str()); |
| 2544 | |
Lei Zhang | da180e9 | 2015-08-14 22:22:13 -0700 | [diff] [blame] | 2545 | if (bUrlEncoded) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2546 | FX_Free(pBuffer); |
| 2547 | pBuffer = NULL; |
| 2548 | } |
| 2549 | |
| 2550 | return TRUE; |
| 2551 | } |
| 2552 | |
| 2553 | FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2554 | CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath()); |
| 2555 | if (!pFDF) |
| 2556 | return FALSE; |
| 2557 | |
| 2558 | FX_BOOL bRet = pFDF->WriteBuf(textBuf); |
| 2559 | delete pFDF; |
| 2560 | |
| 2561 | return bRet; |
| 2562 | } |
| 2563 | |
| 2564 | FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2565 | ASSERT(action.GetDict()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2566 | |
| 2567 | CPDF_Dictionary* pActionDict = action.GetDict(); |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2568 | if (!pActionDict->KeyExist("Fields")) |
| 2569 | return m_pInterForm->ResetForm(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2570 | |
Wei Li | 0fc6b25 | 2016-03-01 16:29:41 -0800 | [diff] [blame] | 2571 | CPDF_ActionFields af(&action); |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 2572 | uint32_t dwFlags = action.GetFlags(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2573 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2574 | std::vector<CPDF_Object*> fieldObjects = af.GetAllFields(); |
| 2575 | std::vector<CPDF_FormField*> fields = GetFieldFromObjects(fieldObjects); |
| 2576 | return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2577 | } |
| 2578 | |
| 2579 | FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action) { |
| 2580 | return FALSE; |
| 2581 | } |
| 2582 | |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2583 | std::vector<CPDF_FormField*> CPDFSDK_InterForm::GetFieldFromObjects( |
| 2584 | const std::vector<CPDF_Object*>& objects) const { |
| 2585 | std::vector<CPDF_FormField*> fields; |
| 2586 | for (CPDF_Object* pObject : objects) { |
| 2587 | if (pObject && pObject->IsString()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2588 | CFX_WideString csName = pObject->GetUnicodeText(); |
| 2589 | CPDF_FormField* pField = m_pInterForm->GetField(0, csName); |
Dan Sinclair | d43ebdd | 2015-10-27 15:37:54 -0400 | [diff] [blame] | 2590 | if (pField) |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2591 | fields.push_back(pField); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2592 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2593 | } |
Lei Zhang | d88a364 | 2015-11-10 09:38:57 -0800 | [diff] [blame] | 2594 | return fields; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2595 | } |
| 2596 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2597 | int CPDFSDK_InterForm::BeforeValueChange(CPDF_FormField* pField, |
| 2598 | const CFX_WideString& csValue) { |
| 2599 | int nType = pField->GetFieldType(); |
| 2600 | if (nType != FIELDTYPE_COMBOBOX && nType != FIELDTYPE_TEXTFIELD) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2601 | return 0; |
| 2602 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2603 | if (!OnKeyStrokeCommit(pField, csValue)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2604 | return -1; |
| 2605 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2606 | if (!OnValidate(pField, csValue)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2607 | return -1; |
| 2608 | |
| 2609 | return 1; |
| 2610 | } |
| 2611 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2612 | void CPDFSDK_InterForm::AfterValueChange(CPDF_FormField* pField) { |
| 2613 | #ifdef PDF_ENABLE_XFA |
| 2614 | SynchronizeField(pField, FALSE); |
| 2615 | #endif // PDF_ENABLE_XFA |
| 2616 | int nType = pField->GetFieldType(); |
| 2617 | if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) { |
| 2618 | OnCalculate(pField); |
| 2619 | FX_BOOL bFormated = FALSE; |
| 2620 | CFX_WideString sValue = OnFormat(pField, bFormated); |
| 2621 | ResetFieldAppearance(pField, bFormated ? sValue.c_str() : nullptr, TRUE); |
| 2622 | UpdateField(pField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2623 | } |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | int CPDFSDK_InterForm::BeforeSelectionChange(CPDF_FormField* pField, |
| 2627 | const CFX_WideString& csValue) { |
| 2628 | if (pField->GetFieldType() != FIELDTYPE_LISTBOX) |
| 2629 | return 0; |
| 2630 | |
| 2631 | if (!OnKeyStrokeCommit(pField, csValue)) |
| 2632 | return -1; |
| 2633 | |
| 2634 | if (!OnValidate(pField, csValue)) |
| 2635 | return -1; |
| 2636 | |
| 2637 | return 1; |
| 2638 | } |
| 2639 | |
| 2640 | void CPDFSDK_InterForm::AfterSelectionChange(CPDF_FormField* pField) { |
| 2641 | if (pField->GetFieldType() == FIELDTYPE_LISTBOX) { |
| 2642 | OnCalculate(pField); |
| 2643 | ResetFieldAppearance(pField, NULL, TRUE); |
| 2644 | UpdateField(pField); |
| 2645 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2646 | } |
| 2647 | |
Tom Sepez | ed5d7aa | 2016-02-02 16:02:03 -0800 | [diff] [blame] | 2648 | void CPDFSDK_InterForm::AfterCheckedStatusChange(CPDF_FormField* pField) { |
| 2649 | int nType = pField->GetFieldType(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2650 | if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON) { |
Tom Sepez | ed5d7aa | 2016-02-02 16:02:03 -0800 | [diff] [blame] | 2651 | OnCalculate(pField); |
| 2652 | UpdateField(pField); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2653 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2654 | } |
| 2655 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2656 | int CPDFSDK_InterForm::BeforeFormReset(CPDF_InterForm* pForm) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2657 | return 0; |
| 2658 | } |
| 2659 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2660 | void CPDFSDK_InterForm::AfterFormReset(CPDF_InterForm* pForm) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2661 | OnCalculate(nullptr); |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | int CPDFSDK_InterForm::BeforeFormImportData(CPDF_InterForm* pForm) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2665 | return 0; |
| 2666 | } |
| 2667 | |
Tom Sepez | d6262c1 | 2016-02-03 14:47:06 -0800 | [diff] [blame] | 2668 | void CPDFSDK_InterForm::AfterFormImportData(CPDF_InterForm* pForm) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2669 | OnCalculate(nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
| 2672 | FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType) { |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2673 | if (nFieldType < 1 || nFieldType > kNumFieldTypes) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2674 | return FALSE; |
| 2675 | return m_bNeedHightlight[nFieldType - 1]; |
| 2676 | } |
| 2677 | |
| 2678 | void CPDFSDK_InterForm::RemoveAllHighLight() { |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2679 | for (int i = 0; i < kNumFieldTypes; ++i) |
| 2680 | m_bNeedHightlight[i] = FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2681 | } |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2682 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2683 | void CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType) { |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2684 | if (nFieldType < 0 || nFieldType > kNumFieldTypes) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2685 | return; |
| 2686 | switch (nFieldType) { |
| 2687 | case 0: { |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2688 | for (int i = 0; i < kNumFieldTypes; ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2689 | m_aHighlightColor[i] = clr; |
| 2690 | m_bNeedHightlight[i] = TRUE; |
| 2691 | } |
| 2692 | break; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2693 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2694 | default: { |
| 2695 | m_aHighlightColor[nFieldType - 1] = clr; |
| 2696 | m_bNeedHightlight[nFieldType - 1] = TRUE; |
| 2697 | break; |
| 2698 | } |
| 2699 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2700 | } |
| 2701 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2702 | FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) { |
Tom Sepez | ae7a917 | 2015-11-23 09:22:46 -0800 | [diff] [blame] | 2703 | if (nFieldType < 0 || nFieldType > kNumFieldTypes) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2704 | return FXSYS_RGB(255, 255, 255); |
| 2705 | if (nFieldType == 0) |
| 2706 | return m_aHighlightColor[0]; |
| 2707 | return m_aHighlightColor[nFieldType - 1]; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2708 | } |
| 2709 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2710 | CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView, |
| 2711 | const CFX_ByteString& sType, |
| 2712 | const CFX_ByteString& sSubType) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2713 | : m_eTabOrder(STRUCTURE), |
| 2714 | m_pPageView(pPageView), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2715 | m_sType(sType), |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2716 | m_sSubType(sSubType) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2717 | CPDF_Page* pPDFPage = m_pPageView->GetPDFPage(); |
Wei Li | 9b76113 | 2016-01-29 15:44:20 -0800 | [diff] [blame] | 2718 | CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetStringBy("Tabs"); |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2719 | if (sTabs == "R") |
| 2720 | m_eTabOrder = ROW; |
| 2721 | else if (sTabs == "C") |
| 2722 | m_eTabOrder = COLUMN; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2723 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2724 | GenerateResults(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2725 | } |
| 2726 | |
Dan Sinclair | f766ad2 | 2016-03-14 13:51:24 -0400 | [diff] [blame] | 2727 | CBA_AnnotIterator::~CBA_AnnotIterator() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2728 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2729 | CPDFSDK_Annot* CBA_AnnotIterator::GetFirstAnnot() { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2730 | return m_Annots.empty() ? nullptr : m_Annots.front(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2731 | } |
| 2732 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2733 | CPDFSDK_Annot* CBA_AnnotIterator::GetLastAnnot() { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2734 | return m_Annots.empty() ? nullptr : m_Annots.back(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2735 | } |
| 2736 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2737 | CPDFSDK_Annot* CBA_AnnotIterator::GetNextAnnot(CPDFSDK_Annot* pAnnot) { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2738 | auto iter = std::find(m_Annots.begin(), m_Annots.end(), pAnnot); |
| 2739 | if (iter == m_Annots.end()) |
| 2740 | return nullptr; |
| 2741 | ++iter; |
| 2742 | if (iter == m_Annots.end()) |
| 2743 | iter = m_Annots.begin(); |
| 2744 | return *iter; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2745 | } |
| 2746 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2747 | CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot) { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2748 | auto iter = std::find(m_Annots.begin(), m_Annots.end(), pAnnot); |
| 2749 | if (iter == m_Annots.end()) |
| 2750 | return nullptr; |
| 2751 | if (iter == m_Annots.begin()) |
| 2752 | iter = m_Annots.end(); |
| 2753 | return *(--iter); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2754 | } |
| 2755 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2756 | // static |
| 2757 | bool CBA_AnnotIterator::CompareByLeftAscending(const CPDFSDK_Annot* p1, |
| 2758 | const CPDFSDK_Annot* p2) { |
| 2759 | return GetAnnotRect(p1).left < GetAnnotRect(p2).left; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2760 | } |
| 2761 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2762 | // static |
| 2763 | bool CBA_AnnotIterator::CompareByTopDescending(const CPDFSDK_Annot* p1, |
| 2764 | const CPDFSDK_Annot* p2) { |
| 2765 | return GetAnnotRect(p1).top > GetAnnotRect(p2).top; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2766 | } |
| 2767 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2768 | void CBA_AnnotIterator::GenerateResults() { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2769 | switch (m_eTabOrder) { |
| 2770 | case STRUCTURE: { |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 2771 | for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2772 | CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2773 | if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2774 | m_Annots.push_back(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2775 | } |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2776 | } break; |
| 2777 | case ROW: { |
| 2778 | std::vector<CPDFSDK_Annot*> sa; |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2779 | for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { |
| 2780 | CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); |
| 2781 | if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2782 | sa.push_back(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2783 | } |
| 2784 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2785 | std::sort(sa.begin(), sa.end(), CompareByLeftAscending); |
| 2786 | while (!sa.empty()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2787 | int nLeftTopIndex = -1; |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2788 | FX_FLOAT fTop = 0.0f; |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2789 | for (int i = sa.size() - 1; i >= 0; i--) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2790 | CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2791 | if (rcAnnot.top > fTop) { |
| 2792 | nLeftTopIndex = i; |
| 2793 | fTop = rcAnnot.top; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2794 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2795 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2796 | if (nLeftTopIndex >= 0) { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2797 | CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex]; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2798 | CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot); |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2799 | m_Annots.push_back(pLeftTopAnnot); |
| 2800 | sa.erase(sa.begin() + nLeftTopIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2801 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2802 | std::vector<int> aSelect; |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame^] | 2803 | for (size_t i = 0; i < sa.size(); ++i) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2804 | CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2805 | FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f; |
| 2806 | if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2807 | aSelect.push_back(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2808 | } |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame^] | 2809 | for (size_t i = 0; i < aSelect.size(); ++i) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2810 | m_Annots.push_back(sa[aSelect[i]]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2811 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2812 | for (int i = aSelect.size() - 1; i >= 0; --i) |
| 2813 | sa.erase(sa.begin() + aSelect[i]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2814 | } |
| 2815 | } |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2816 | } break; |
| 2817 | case COLUMN: { |
| 2818 | std::vector<CPDFSDK_Annot*> sa; |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2819 | for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { |
| 2820 | CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); |
| 2821 | if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2822 | sa.push_back(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2823 | } |
| 2824 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2825 | std::sort(sa.begin(), sa.end(), CompareByTopDescending); |
| 2826 | while (!sa.empty()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2827 | int nLeftTopIndex = -1; |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2828 | FX_FLOAT fLeft = -1.0f; |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2829 | for (int i = sa.size() - 1; i >= 0; --i) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2830 | CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2831 | if (fLeft < 0) { |
| 2832 | nLeftTopIndex = 0; |
| 2833 | fLeft = rcAnnot.left; |
| 2834 | } else if (rcAnnot.left < fLeft) { |
| 2835 | nLeftTopIndex = i; |
| 2836 | fLeft = rcAnnot.left; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2837 | } |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 2838 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2839 | |
| 2840 | if (nLeftTopIndex >= 0) { |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2841 | CPDFSDK_Annot* pLeftTopAnnot = sa[nLeftTopIndex]; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2842 | CFX_FloatRect rcLeftTop = GetAnnotRect(pLeftTopAnnot); |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2843 | m_Annots.push_back(pLeftTopAnnot); |
| 2844 | sa.erase(sa.begin() + nLeftTopIndex); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2845 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2846 | std::vector<int> aSelect; |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame^] | 2847 | for (size_t i = 0; i < sa.size(); ++i) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2848 | CFX_FloatRect rcAnnot = GetAnnotRect(sa[i]); |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2849 | FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f; |
| 2850 | if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2851 | aSelect.push_back(i); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2852 | } |
Wei Li | 8940993 | 2016-03-28 10:33:33 -0700 | [diff] [blame^] | 2853 | for (size_t i = 0; i < aSelect.size(); ++i) |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2854 | m_Annots.push_back(sa[aSelect[i]]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2855 | |
Tom Sepez | b9cc7a0 | 2016-02-01 13:42:30 -0800 | [diff] [blame] | 2856 | for (int i = aSelect.size() - 1; i >= 0; --i) |
| 2857 | sa.erase(sa.begin() + aSelect[i]); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2858 | } |
| 2859 | } |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2860 | break; |
| 2861 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2862 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2863 | } |
| 2864 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 2865 | CFX_FloatRect CBA_AnnotIterator::GetAnnotRect(const CPDFSDK_Annot* pAnnot) { |
| 2866 | CFX_FloatRect rcAnnot; |
Lei Zhang | 5021853 | 2015-10-30 14:03:43 -0700 | [diff] [blame] | 2867 | pAnnot->GetPDFAnnot()->GetRect(rcAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 2868 | return rcAnnot; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 2869 | } |