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 | |
Dan Sinclair | edbb319 | 2016-03-21 09:08:24 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/formfiller/cffl_formfiller.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 8 | |
Lei Zhang | d24236a | 2017-06-29 18:28:58 -0700 | [diff] [blame] | 9 | #include <utility> |
| 10 | |
dsinclair | 41872fa | 2016-10-04 11:29:35 -0700 | [diff] [blame] | 11 | #include "core/fpdfapi/page/cpdf_page.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 12 | #include "core/fxge/cfx_renderdevice.h" |
dsinclair | 735606d | 2016-10-05 15:47:02 -0700 | [diff] [blame] | 13 | #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 14 | #include "fpdfsdk/cpdfsdk_pageview.h" |
| 15 | #include "fpdfsdk/cpdfsdk_widget.h" |
Dan Sinclair | edbb319 | 2016-03-21 09:08:24 -0400 | [diff] [blame] | 16 | #include "fpdfsdk/formfiller/cba_fontmap.h" |
dsinclair | 114e46a | 2016-09-29 17:18:21 -0700 | [diff] [blame] | 17 | #include "fpdfsdk/fsdk_common.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 18 | |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 19 | namespace { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 20 | |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 21 | CPDFSDK_Widget* CPDFSDKAnnotToWidget(CPDFSDK_Annot* annot) { |
| 22 | return static_cast<CPDFSDK_Widget*>(annot); |
| 23 | } |
| 24 | |
| 25 | } // namespace |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 26 | |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 27 | CFFL_FormFiller::CFFL_FormFiller(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
Lei Zhang | 4f34c64 | 2017-06-02 00:45:14 -0700 | [diff] [blame] | 28 | CPDFSDK_Widget* pWidget) |
| 29 | : m_pFormFillEnv(pFormFillEnv), m_pWidget(pWidget), m_bValid(false) { |
| 30 | ASSERT(m_pFormFillEnv); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | CFFL_FormFiller::~CFFL_FormFiller() { |
dsinclair | 28a4a24 | 2016-08-22 13:36:02 -0700 | [diff] [blame] | 34 | DestroyWindows(); |
| 35 | } |
| 36 | |
| 37 | void CFFL_FormFiller::DestroyWindows() { |
Lei Zhang | ab5537d | 2016-01-06 14:58:14 -0800 | [diff] [blame] | 38 | for (const auto& it : m_Maps) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 39 | CPWL_Wnd* pWnd = it.second; |
Tom Sepez | 134ac91 | 2017-09-15 15:32:01 -0700 | [diff] [blame] | 40 | auto* pData = static_cast<CFFL_PrivateData*>(pWnd->GetAttachedData()); |
Lei Zhang | ab5537d | 2016-01-06 14:58:14 -0800 | [diff] [blame] | 41 | pWnd->InvalidateProvider(this); |
Lei Zhang | 606346f | 2015-06-19 18:11:07 -0700 | [diff] [blame] | 42 | pWnd->Destroy(); |
| 43 | delete pWnd; |
| 44 | delete pData; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 45 | } |
| 46 | m_Maps.clear(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 49 | FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, |
| 50 | CPDFSDK_Annot* pAnnot) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 51 | ASSERT(pPageView); |
| 52 | ASSERT(pAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 53 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 54 | CFX_FloatRect rcAnnot = m_pWidget->GetRect(); |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 55 | if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) |
| 56 | rcAnnot = PWLtoFFL(pWnd->GetWindowRect()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 58 | CFX_FloatRect rcWin = rcAnnot; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 59 | CFX_FloatRect rcFocus = GetFocusBox(pPageView); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 60 | if (!rcFocus.IsEmpty()) |
| 61 | rcWin.Union(rcFocus); |
| 62 | |
dan sinclair | adf922f | 2017-07-12 21:56:27 -0400 | [diff] [blame] | 63 | if (!rcWin.IsEmpty()) { |
| 64 | rcWin.Inflate(1, 1); |
| 65 | rcWin.Normalize(); |
| 66 | } |
| 67 | return rcWin.GetOuterRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void CFFL_FormFiller::OnDraw(CPDFSDK_PageView* pPageView, |
| 71 | CPDFSDK_Annot* pAnnot, |
| 72 | CFX_RenderDevice* pDevice, |
Lei Zhang | 2b6e2a7 | 2017-08-28 11:34:16 -0700 | [diff] [blame] | 73 | const CFX_Matrix& mtUser2Device) { |
jaepark | 956553e | 2016-08-31 06:49:27 -0700 | [diff] [blame] | 74 | ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 75 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 76 | if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 77 | CFX_Matrix mt = GetCurMatrix(); |
Lei Zhang | 2b6e2a7 | 2017-08-28 11:34:16 -0700 | [diff] [blame] | 78 | mt.Concat(mtUser2Device); |
Lei Zhang | eb14e04 | 2017-08-15 13:56:43 -0700 | [diff] [blame] | 79 | pWnd->DrawAppearance(pDevice, mt); |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 80 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 81 | } |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 82 | |
| 83 | CPDFSDK_Widget* pWidget = CPDFSDKAnnotToWidget(pAnnot); |
| 84 | if (!CFFL_InteractiveFormFiller::IsVisible(pWidget)) |
| 85 | return; |
| 86 | |
Lei Zhang | 2b6e2a7 | 2017-08-28 11:34:16 -0700 | [diff] [blame] | 87 | pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Normal, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView* pPageView, |
| 91 | CPDFSDK_Annot* pAnnot, |
| 92 | CFX_RenderDevice* pDevice, |
Lei Zhang | 2b6e2a7 | 2017-08-28 11:34:16 -0700 | [diff] [blame] | 93 | const CFX_Matrix& mtUser2Device) { |
| 94 | CPDFSDKAnnotToWidget(pAnnot)->DrawAppearance(pDevice, mtUser2Device, |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 95 | CPDF_Annot::Normal, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 98 | void CFFL_FormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView, |
| 99 | CPDFSDK_Annot* pAnnot) {} |
| 100 | |
| 101 | void CFFL_FormFiller::OnMouseExit(CPDFSDK_PageView* pPageView, |
| 102 | CPDFSDK_Annot* pAnnot) { |
| 103 | EndTimer(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 104 | ASSERT(m_pWidget); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 105 | } |
| 106 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 107 | bool CFFL_FormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView, |
| 108 | CPDFSDK_Annot* pAnnot, |
| 109 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 110 | const CFX_PointF& point) { |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 111 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true); |
| 112 | if (!pWnd) |
| 113 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 114 | |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 115 | m_bValid = true; |
| 116 | FX_RECT rect = GetViewBBox(pPageView, pAnnot); |
| 117 | InvalidateRect(rect); |
| 118 | if (!rect.Contains(static_cast<int>(point.x), static_cast<int>(point.y))) |
| 119 | return false; |
| 120 | return pWnd->OnLButtonDown(WndtoPWL(pPageView, point), nFlags); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 121 | } |
| 122 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 123 | bool CFFL_FormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, |
| 124 | CPDFSDK_Annot* pAnnot, |
| 125 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 126 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 127 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 128 | if (!pWnd) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 129 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 130 | |
Dan Sinclair | 6eec1c4 | 2017-02-21 17:20:43 -0500 | [diff] [blame] | 131 | InvalidateRect(GetViewBBox(pPageView, pAnnot)); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 132 | pWnd->OnLButtonUp(WndtoPWL(pPageView, point), nFlags); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 133 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 134 | } |
| 135 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 136 | bool CFFL_FormFiller::OnLButtonDblClk(CPDFSDK_PageView* pPageView, |
| 137 | CPDFSDK_Annot* pAnnot, |
| 138 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 139 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 140 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 141 | if (!pWnd) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 142 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 143 | |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 144 | pWnd->OnLButtonDblClk(WndtoPWL(pPageView, point), nFlags); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 145 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 146 | } |
| 147 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 148 | bool CFFL_FormFiller::OnMouseMove(CPDFSDK_PageView* pPageView, |
| 149 | CPDFSDK_Annot* pAnnot, |
| 150 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 151 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 152 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 153 | if (!pWnd) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 154 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 155 | |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 156 | pWnd->OnMouseMove(WndtoPWL(pPageView, point), nFlags); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 157 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 158 | } |
| 159 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 160 | bool CFFL_FormFiller::OnMouseWheel(CPDFSDK_PageView* pPageView, |
| 161 | CPDFSDK_Annot* pAnnot, |
| 162 | uint32_t nFlags, |
| 163 | short zDelta, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 164 | const CFX_PointF& point) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | if (!IsValid()) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 166 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 167 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 168 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 169 | return pWnd && pWnd->OnMouseWheel(zDelta, WndtoPWL(pPageView, point), nFlags); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 170 | } |
| 171 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 172 | bool CFFL_FormFiller::OnRButtonDown(CPDFSDK_PageView* pPageView, |
| 173 | CPDFSDK_Annot* pAnnot, |
| 174 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 175 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 176 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 177 | if (!pWnd) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 178 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 179 | |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 180 | pWnd->OnRButtonDown(WndtoPWL(pPageView, point), nFlags); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 181 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 182 | } |
| 183 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 184 | bool CFFL_FormFiller::OnRButtonUp(CPDFSDK_PageView* pPageView, |
| 185 | CPDFSDK_Annot* pAnnot, |
| 186 | uint32_t nFlags, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 187 | const CFX_PointF& point) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 188 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 189 | if (!pWnd) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 190 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 191 | |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 192 | pWnd->OnRButtonUp(WndtoPWL(pPageView, point), nFlags); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 193 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 194 | } |
| 195 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 196 | bool CFFL_FormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, |
| 197 | uint32_t nKeyCode, |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 198 | uint32_t nFlags) { |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 199 | if (!IsValid()) |
| 200 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 201 | |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 202 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
| 203 | ASSERT(pPageView); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 204 | |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 205 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
| 206 | return pWnd && pWnd->OnKeyDown(nKeyCode, nFlags); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | bool CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, |
| 210 | uint32_t nChar, |
| 211 | uint32_t nFlags) { |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 212 | if (!IsValid()) |
| 213 | return false; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 214 | |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 215 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
| 216 | ASSERT(pPageView); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 217 | |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 218 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
| 219 | return pWnd && pWnd->OnChar(nChar, nFlags); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 220 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 221 | |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 222 | WideString CFFL_FormFiller::GetSelectedText(CPDFSDK_Annot* pAnnot) { |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 223 | if (!IsValid()) |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 224 | return WideString(); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 225 | |
| 226 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
| 227 | ASSERT(pPageView); |
| 228 | |
| 229 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 230 | return pWnd ? pWnd->GetSelectedText() : WideString(); |
Diana Gage | dce2d72 | 2017-06-20 11:17:11 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 233 | void CFFL_FormFiller::ReplaceSelection(CPDFSDK_Annot* pAnnot, |
Ryan Harrison | 275e260 | 2017-09-18 14:23:18 -0400 | [diff] [blame] | 234 | const WideString& text) { |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 235 | if (!IsValid()) |
| 236 | return; |
| 237 | |
| 238 | CPDFSDK_PageView* pPageView = GetCurPageView(true); |
| 239 | ASSERT(pPageView); |
| 240 | |
| 241 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
| 242 | if (!pWnd) |
| 243 | return; |
| 244 | |
Diana Gage | ab39097 | 2017-07-28 17:07:39 -0700 | [diff] [blame] | 245 | pWnd->ReplaceSelection(text); |
Diana Gage | 1c7f142 | 2017-07-24 11:19:52 -0700 | [diff] [blame] | 246 | } |
| 247 | |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 248 | void CFFL_FormFiller::SetFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 249 | CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; |
Tom Sepez | 1b24628 | 2015-11-25 15:15:31 -0800 | [diff] [blame] | 250 | UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 251 | CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, true); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 252 | if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 253 | pWnd->SetFocus(); |
| 254 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 255 | m_bValid = true; |
Dan Sinclair | 6eec1c4 | 2017-02-21 17:20:43 -0500 | [diff] [blame] | 256 | InvalidateRect(GetViewBBox(pPageView, pAnnot)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 257 | } |
| 258 | |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 259 | void CFFL_FormFiller::KillFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 260 | if (!IsValid()) |
Lei Zhang | 8c217c5 | 2015-10-03 23:26:09 -0700 | [diff] [blame] | 261 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 262 | |
dsinclair | 461eeaf | 2016-07-27 07:40:05 -0700 | [diff] [blame] | 263 | CPDFSDK_PageView* pPageView = GetCurPageView(false); |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 264 | if (!pPageView || !CommitData(pPageView, nFlag)) |
Lei Zhang | 8c217c5 | 2015-10-03 23:26:09 -0700 | [diff] [blame] | 265 | return; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 266 | if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 267 | pWnd->KillFocus(); |
| 268 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 269 | bool bDestroyPDFWindow; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 270 | switch (m_pWidget->GetFieldType()) { |
Ryan Harrison | 9baf31f | 2018-01-12 18:36:30 +0000 | [diff] [blame] | 271 | case FormFieldType::kPushButton: |
| 272 | case FormFieldType::kCheckBox: |
| 273 | case FormFieldType::kRadioButton: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 274 | bDestroyPDFWindow = true; |
Lei Zhang | d77f03f | 2015-12-28 13:12:26 -0800 | [diff] [blame] | 275 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 276 | default: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 277 | bDestroyPDFWindow = false; |
Lei Zhang | d77f03f | 2015-12-28 13:12:26 -0800 | [diff] [blame] | 278 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 279 | } |
Lei Zhang | 8c217c5 | 2015-10-03 23:26:09 -0700 | [diff] [blame] | 280 | EscapeFiller(pPageView, bDestroyPDFWindow); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 281 | } |
| 282 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 283 | bool CFFL_FormFiller::IsValid() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 284 | return m_bValid; |
| 285 | } |
| 286 | |
Tom Sepez | bf15730 | 2017-09-15 13:26:32 -0700 | [diff] [blame] | 287 | CPWL_Wnd::CreateParams CFFL_FormFiller::GetCreateParam() { |
| 288 | CPWL_Wnd::CreateParams cp; |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 289 | cp.pParentWnd = nullptr; |
Dan Sinclair | bc8dcc3 | 2017-01-19 13:53:02 -0500 | [diff] [blame] | 290 | cp.pProvider.Reset(this); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 291 | cp.rcRectWnd = GetPDFWindowRect(); |
| 292 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 293 | uint32_t dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE; |
| 294 | uint32_t dwFieldFlag = m_pWidget->GetFieldFlags(); |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 295 | if (dwFieldFlag & FIELDFLAG_READONLY) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 296 | dwCreateFlags |= PWS_READONLY; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 297 | |
| 298 | FX_COLORREF color; |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 299 | if (m_pWidget->GetFillColor(color)) |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 300 | cp.sBackgroundColor = CFX_Color(color); |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 301 | if (m_pWidget->GetBorderColor(color)) |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 302 | cp.sBorderColor = CFX_Color(color); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 303 | |
Dan Sinclair | 8e7f932 | 2017-10-16 11:35:42 -0400 | [diff] [blame] | 304 | cp.sTextColor = CFX_Color(CFX_Color::kGray, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 305 | |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 306 | if (m_pWidget->GetTextColor(color)) |
Dan Sinclair | 7f55a54 | 2017-07-13 14:17:10 -0400 | [diff] [blame] | 307 | cp.sTextColor = CFX_Color(color); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 308 | |
| 309 | cp.fFontSize = m_pWidget->GetFontSize(); |
| 310 | cp.dwBorderWidth = m_pWidget->GetBorderWidth(); |
| 311 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 312 | cp.nBorderStyle = m_pWidget->GetBorderStyle(); |
| 313 | switch (cp.nBorderStyle) { |
| 314 | case BorderStyle::DASH: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 315 | cp.sDash = CPWL_Dash(3, 3, 0); |
| 316 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 317 | case BorderStyle::BEVELED: |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 318 | case BorderStyle::INSET: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 319 | cp.dwBorderWidth *= 2; |
| 320 | break; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 321 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 322 | break; |
| 323 | } |
| 324 | |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 325 | if (cp.fFontSize <= 0) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 326 | dwCreateFlags |= PWS_AUTOFONTSIZE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 327 | |
| 328 | cp.dwFlags = dwCreateFlags; |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 329 | cp.pSystemHandler = m_pFormFillEnv->GetSysHandler(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 330 | return cp; |
| 331 | } |
| 332 | |
| 333 | CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 334 | bool bNew) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 335 | ASSERT(pPageView); |
| 336 | |
| 337 | auto it = m_Maps.find(pPageView); |
| 338 | const bool found = it != m_Maps.end(); |
| 339 | CPWL_Wnd* pWnd = found ? it->second : nullptr; |
| 340 | if (!bNew) |
| 341 | return pWnd; |
| 342 | |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 343 | if (!found) { |
Tom Sepez | bf15730 | 2017-09-15 13:26:32 -0700 | [diff] [blame] | 344 | CPWL_Wnd::CreateParams cp = GetCreateParam(); |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 345 | cp.pAttachedWidget.Reset(m_pWidget.Get()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 346 | |
Tom Sepez | 134ac91 | 2017-09-15 15:32:01 -0700 | [diff] [blame] | 347 | auto* pPrivateData = new CFFL_PrivateData; |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 348 | pPrivateData->pWidget = m_pWidget.Get(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 349 | pPrivateData->pPageView = pPageView; |
Tom Sepez | 7b1e53c | 2017-09-15 15:43:11 -0700 | [diff] [blame] | 350 | pPrivateData->nWidgetAppearanceAge = m_pWidget->GetAppearanceAge(); |
| 351 | pPrivateData->nWidgetValueAge = 0; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 352 | cp.pAttachedData = pPrivateData; |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 353 | CPWL_Wnd* pNewWnd = NewPDFWindow(cp); |
| 354 | m_Maps[pPageView] = pNewWnd; |
| 355 | return pNewWnd; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 358 | auto* pPrivateData = static_cast<CFFL_PrivateData*>(pWnd->GetAttachedData()); |
Tom Sepez | 7b1e53c | 2017-09-15 15:43:11 -0700 | [diff] [blame] | 359 | if (pPrivateData->nWidgetAppearanceAge == m_pWidget->GetAppearanceAge()) |
Lei Zhang | f552cca | 2017-06-29 18:28:05 -0700 | [diff] [blame] | 360 | return pWnd; |
| 361 | |
Tom Sepez | 7b1e53c | 2017-09-15 15:43:11 -0700 | [diff] [blame] | 362 | return ResetPDFWindow( |
| 363 | pPageView, pPrivateData->nWidgetValueAge == m_pWidget->GetValueAge()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView) { |
| 367 | auto it = m_Maps.find(pPageView); |
| 368 | if (it == m_Maps.end()) |
| 369 | return; |
| 370 | |
| 371 | CPWL_Wnd* pWnd = it->second; |
Tom Sepez | 134ac91 | 2017-09-15 15:32:01 -0700 | [diff] [blame] | 372 | auto* pData = static_cast<CFFL_PrivateData*>(pWnd->GetAttachedData()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 373 | pWnd->Destroy(); |
| 374 | delete pWnd; |
| 375 | delete pData; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 376 | m_Maps.erase(it); |
| 377 | } |
| 378 | |
Tom Sepez | 134ac91 | 2017-09-15 15:32:01 -0700 | [diff] [blame] | 379 | CFX_Matrix CFFL_FormFiller::GetWindowMatrix(CPWL_Wnd::PrivateData* pAttached) { |
Lei Zhang | 0a91394 | 2017-06-01 01:37:51 -0700 | [diff] [blame] | 380 | CFX_Matrix mt; |
Tom Sepez | 134ac91 | 2017-09-15 15:32:01 -0700 | [diff] [blame] | 381 | auto* pPrivateData = static_cast<CFFL_PrivateData*>(pAttached); |
| 382 | if (!pPrivateData || !pPrivateData->pPageView) |
Lei Zhang | 0a91394 | 2017-06-01 01:37:51 -0700 | [diff] [blame] | 383 | return mt; |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 384 | |
Lei Zhang | 0a91394 | 2017-06-01 01:37:51 -0700 | [diff] [blame] | 385 | CFX_Matrix mtPageView; |
| 386 | pPrivateData->pPageView->GetCurrentMatrix(mtPageView); |
| 387 | mt = GetCurMatrix(); |
| 388 | mt.Concat(mtPageView); |
| 389 | return mt; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 392 | CFX_Matrix CFFL_FormFiller::GetCurMatrix() { |
| 393 | CFX_Matrix mt; |
jaepark | a1d2111 | 2016-08-25 13:33:34 -0700 | [diff] [blame] | 394 | CFX_FloatRect rcDA = m_pWidget->GetPDFAnnot()->GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 395 | switch (m_pWidget->GetRotate()) { |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 396 | case 90: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 397 | mt = CFX_Matrix(0, 1, -1, 0, rcDA.right - rcDA.left, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 398 | break; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 399 | case 180: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 400 | mt = CFX_Matrix(-1, 0, 0, -1, rcDA.right - rcDA.left, |
| 401 | rcDA.top - rcDA.bottom); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 402 | break; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 403 | case 270: |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 404 | mt = CFX_Matrix(0, -1, 1, 0, 0, rcDA.top - rcDA.bottom); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 405 | break; |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 406 | case 0: |
| 407 | default: |
| 408 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 409 | } |
| 410 | mt.e += rcDA.left; |
| 411 | mt.f += rcDA.bottom; |
| 412 | |
| 413 | return mt; |
| 414 | } |
| 415 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 416 | CFX_FloatRect CFFL_FormFiller::GetPDFWindowRect() const { |
jaepark | a1d2111 | 2016-08-25 13:33:34 -0700 | [diff] [blame] | 417 | CFX_FloatRect rectAnnot = m_pWidget->GetPDFAnnot()->GetRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 418 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 419 | float fWidth = rectAnnot.right - rectAnnot.left; |
| 420 | float fHeight = rectAnnot.top - rectAnnot.bottom; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 421 | if ((m_pWidget->GetRotate() / 90) & 0x01) |
Lei Zhang | d24236a | 2017-06-29 18:28:58 -0700 | [diff] [blame] | 422 | std::swap(fWidth, fHeight); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 423 | return CFX_FloatRect(0, 0, fWidth, fHeight); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 424 | } |
| 425 | |
dsinclair | 461eeaf | 2016-07-27 07:40:05 -0700 | [diff] [blame] | 426 | CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView(bool renew) { |
Lei Zhang | 4f34c64 | 2017-06-02 00:45:14 -0700 | [diff] [blame] | 427 | UnderlyingPageType* pPage = m_pWidget->GetUnderlyingPage(); |
| 428 | return m_pFormFillEnv->GetPageView(pPage, renew); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 431 | CFX_FloatRect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView) { |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 432 | CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
| 433 | if (!pWnd) |
| 434 | return CFX_FloatRect(); |
| 435 | |
| 436 | CFX_FloatRect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect())); |
| 437 | return pPageView->GetPDFPage()->GetPageBBox().Contains(rcFocus) |
| 438 | ? rcFocus |
| 439 | : CFX_FloatRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 442 | CFX_FloatRect CFFL_FormFiller::FFLtoPWL(const CFX_FloatRect& rect) { |
Jane Liu | 878b27d | 2017-08-22 10:50:06 -0400 | [diff] [blame] | 443 | return GetCurMatrix().GetInverse().TransformRect(rect); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 446 | CFX_FloatRect CFFL_FormFiller::PWLtoFFL(const CFX_FloatRect& rect) { |
Jane Liu | 878b27d | 2017-08-22 10:50:06 -0400 | [diff] [blame] | 447 | return GetCurMatrix().TransformRect(rect); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 448 | } |
| 449 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 450 | CFX_PointF CFFL_FormFiller::FFLtoPWL(const CFX_PointF& point) { |
Nicolas Pena | b21f174 | 2017-06-29 12:02:06 -0400 | [diff] [blame] | 451 | return GetCurMatrix().GetInverse().Transform(point); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 454 | CFX_PointF CFFL_FormFiller::PWLtoFFL(const CFX_PointF& point) { |
Dan Sinclair | a0061af | 2017-02-23 09:25:17 -0500 | [diff] [blame] | 455 | return GetCurMatrix().Transform(point); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 458 | CFX_PointF CFFL_FormFiller::WndtoPWL(CPDFSDK_PageView* pPageView, |
| 459 | const CFX_PointF& pt) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 460 | return FFLtoPWL(pt); |
| 461 | } |
| 462 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 463 | CFX_FloatRect CFFL_FormFiller::FFLtoWnd(CPDFSDK_PageView* pPageView, |
| 464 | const CFX_FloatRect& rect) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 465 | return rect; |
| 466 | } |
| 467 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 468 | bool CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, uint32_t nFlag) { |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 469 | if (!IsDataChanged(pPageView)) |
| 470 | return true; |
Lei Zhang | 6a3fc45 | 2017-06-13 14:04:02 -0700 | [diff] [blame] | 471 | |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 472 | CFFL_InteractiveFormFiller* pFormFiller = |
| 473 | m_pFormFillEnv->GetInteractiveFormFiller(); |
| 474 | CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget.Get()); |
| 475 | |
| 476 | if (!pFormFiller->OnKeyStrokeCommit(&pObserved, pPageView, nFlag)) { |
Dan Sinclair | bdb9653 | 2017-07-06 10:40:51 -0400 | [diff] [blame] | 477 | if (!pObserved) |
| 478 | return false; |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 479 | ResetPDFWindow(pPageView, false); |
| 480 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 481 | } |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 482 | if (!pObserved) |
| 483 | return false; |
| 484 | |
| 485 | if (!pFormFiller->OnValidate(&pObserved, pPageView, nFlag)) { |
| 486 | if (!pObserved) |
| 487 | return false; |
| 488 | ResetPDFWindow(pPageView, false); |
| 489 | return true; |
| 490 | } |
| 491 | if (!pObserved) |
| 492 | return false; |
| 493 | |
Luật Nguyễn | 1886471 | 2017-10-10 12:39:22 +0800 | [diff] [blame] | 494 | SaveData(pPageView); // may invoking JS to delete this widget. |
| 495 | if (!pObserved) |
| 496 | return false; |
| 497 | |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 498 | pFormFiller->OnCalculate(&pObserved, pPageView, nFlag); |
| 499 | if (!pObserved) |
| 500 | return false; |
| 501 | |
| 502 | pFormFiller->OnFormat(&pObserved, pPageView, nFlag); |
| 503 | if (!pObserved) |
| 504 | return false; |
| 505 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 506 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 507 | } |
| 508 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 509 | bool CFFL_FormFiller::IsDataChanged(CPDFSDK_PageView* pPageView) { |
| 510 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 513 | void CFFL_FormFiller::SaveData(CPDFSDK_PageView* pPageView) {} |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 514 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 515 | #ifdef PDF_ENABLE_XFA |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 516 | bool CFFL_FormFiller::IsFieldFull(CPDFSDK_PageView* pPageView) { |
| 517 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 518 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 519 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 520 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 521 | void CFFL_FormFiller::SetChangeMark() { |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 522 | m_pFormFillEnv->OnChange(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 525 | void CFFL_FormFiller::GetActionData(CPDFSDK_PageView* pPageView, |
| 526 | CPDF_AAction::AActionType type, |
| 527 | PDFSDK_FieldAction& fa) { |
| 528 | fa.sValue = m_pWidget->GetValue(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 531 | void CFFL_FormFiller::SetActionData(CPDFSDK_PageView* pPageView, |
| 532 | CPDF_AAction::AActionType type, |
| 533 | const PDFSDK_FieldAction& fa) {} |
| 534 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 535 | bool CFFL_FormFiller::IsActionDataChanged(CPDF_AAction::AActionType type, |
| 536 | const PDFSDK_FieldAction& faOld, |
| 537 | const PDFSDK_FieldAction& faNew) { |
| 538 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 541 | void CFFL_FormFiller::SaveState(CPDFSDK_PageView* pPageView) {} |
| 542 | |
| 543 | void CFFL_FormFiller::RestoreState(CPDFSDK_PageView* pPageView) {} |
| 544 | |
| 545 | CPWL_Wnd* CFFL_FormFiller::ResetPDFWindow(CPDFSDK_PageView* pPageView, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 546 | bool bRestoreValue) { |
| 547 | return GetPDFWindow(pPageView, false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 550 | void CFFL_FormFiller::TimerProc() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 551 | |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 552 | CFX_SystemHandler* CFFL_FormFiller::GetSystemHandler() const { |
dsinclair | 8779fa8 | 2016-10-12 12:05:44 -0700 | [diff] [blame] | 553 | return m_pFormFillEnv->GetSysHandler(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 556 | void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 557 | bool bDestroyPDFWindow) { |
| 558 | m_bValid = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 559 | |
Tom Sepez | d0409af | 2017-05-25 15:53:57 -0700 | [diff] [blame] | 560 | InvalidateRect(GetViewBBox(pPageView, m_pWidget.Get())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 561 | if (bDestroyPDFWindow) |
| 562 | DestroyPDFWindow(pPageView); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Dan Sinclair | 6eec1c4 | 2017-02-21 17:20:43 -0500 | [diff] [blame] | 565 | void CFFL_FormFiller::InvalidateRect(const FX_RECT& rect) { |
| 566 | m_pFormFillEnv->Invalidate(m_pWidget->GetUnderlyingPage(), rect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 567 | } |