OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "fpdfsdk/formfiller/cffl_formfiller.h" | 7 #include "fpdfsdk/formfiller/cffl_formfiller.h" |
8 | 8 |
9 #include "core/fpdfapi/page/cpdf_page.h" | 9 #include "core/fpdfapi/page/cpdf_page.h" |
10 #include "core/fxge/cfx_renderdevice.h" | 10 #include "core/fxge/cfx_renderdevice.h" |
11 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" | 11 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
12 #include "fpdfsdk/cpdfsdk_pageview.h" | 12 #include "fpdfsdk/cpdfsdk_pageview.h" |
13 #include "fpdfsdk/cpdfsdk_widget.h" | 13 #include "fpdfsdk/cpdfsdk_widget.h" |
14 #include "fpdfsdk/formfiller/cba_fontmap.h" | 14 #include "fpdfsdk/formfiller/cba_fontmap.h" |
15 #include "fpdfsdk/fsdk_common.h" | 15 #include "fpdfsdk/fsdk_common.h" |
16 #include "fpdfsdk/pdfwindow/PWL_Utils.h" | 16 #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
17 | 17 |
18 #define GetRed(rgb) ((uint8_t)(rgb)) | 18 #define GetRed(rgb) ((uint8_t)(rgb)) |
19 #define GetGreen(rgb) ((uint8_t)(((uint16_t)(rgb)) >> 8)) | 19 #define GetGreen(rgb) ((uint8_t)(((uint16_t)(rgb)) >> 8)) |
20 #define GetBlue(rgb) ((uint8_t)((rgb) >> 16)) | 20 #define GetBlue(rgb) ((uint8_t)((rgb) >> 16)) |
21 | 21 |
22 #define FFL_HINT_ELAPSE 800 | 22 #define FFL_HINT_ELAPSE 800 |
23 | 23 |
24 CFFL_FormFiller::CFFL_FormFiller(CPDFSDK_FormFillEnvironment* pFormFillEnv, | 24 CFFL_FormFiller::CFFL_FormFiller(CPDFSDK_FormFillEnvironment* pFormFillEnv, |
25 CPDFSDK_Annot* pAnnot) | 25 CPDFSDK_Annot* pAnnot) |
26 : m_pFormFillEnv(pFormFillEnv), m_pAnnot(pAnnot), m_bValid(FALSE) { | 26 : m_pFormFillEnv(pFormFillEnv), m_pAnnot(pAnnot), m_bValid(false) { |
27 m_pWidget = static_cast<CPDFSDK_Widget*>(pAnnot); | 27 m_pWidget = static_cast<CPDFSDK_Widget*>(pAnnot); |
28 } | 28 } |
29 | 29 |
30 CFFL_FormFiller::~CFFL_FormFiller() { | 30 CFFL_FormFiller::~CFFL_FormFiller() { |
31 DestroyWindows(); | 31 DestroyWindows(); |
32 } | 32 } |
33 | 33 |
34 void CFFL_FormFiller::DestroyWindows() { | 34 void CFFL_FormFiller::DestroyWindows() { |
35 for (const auto& it : m_Maps) { | 35 for (const auto& it : m_Maps) { |
36 CPWL_Wnd* pWnd = it.second; | 36 CPWL_Wnd* pWnd = it.second; |
37 CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); | 37 CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); |
38 pWnd->InvalidateProvider(this); | 38 pWnd->InvalidateProvider(this); |
39 pWnd->Destroy(); | 39 pWnd->Destroy(); |
40 delete pWnd; | 40 delete pWnd; |
41 delete pData; | 41 delete pData; |
42 } | 42 } |
43 m_Maps.clear(); | 43 m_Maps.clear(); |
44 } | 44 } |
45 | 45 |
46 void CFFL_FormFiller::SetWindowRect(CPDFSDK_PageView* pPageView, | 46 void CFFL_FormFiller::SetWindowRect(CPDFSDK_PageView* pPageView, |
47 const CFX_FloatRect& rcWindow) { | 47 const CFX_FloatRect& rcWindow) { |
48 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | 48 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) { |
49 pWnd->Move(CFX_FloatRect(rcWindow), TRUE, FALSE); | 49 pWnd->Move(CFX_FloatRect(rcWindow), true, false); |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 CFX_FloatRect CFFL_FormFiller::GetWindowRect(CPDFSDK_PageView* pPageView) { | 53 CFX_FloatRect CFFL_FormFiller::GetWindowRect(CPDFSDK_PageView* pPageView) { |
54 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | 54 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) { |
55 return pWnd->GetWindowRect(); | 55 return pWnd->GetWindowRect(); |
56 } | 56 } |
57 | 57 |
58 return CFX_FloatRect(0, 0, 0, 0); | 58 return CFX_FloatRect(0, 0, 0, 0); |
59 } | 59 } |
60 | 60 |
61 FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, | 61 FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, |
62 CPDFSDK_Annot* pAnnot) { | 62 CPDFSDK_Annot* pAnnot) { |
63 ASSERT(pPageView); | 63 ASSERT(pPageView); |
64 ASSERT(pAnnot); | 64 ASSERT(pAnnot); |
65 | 65 |
66 CFX_FloatRect rcAnnot = m_pWidget->GetRect(); | 66 CFX_FloatRect rcAnnot = m_pWidget->GetRect(); |
67 | 67 |
68 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | 68 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) { |
69 CFX_FloatRect rcWindow = pWnd->GetWindowRect(); | 69 CFX_FloatRect rcWindow = pWnd->GetWindowRect(); |
70 rcAnnot = PWLtoFFL(rcWindow); | 70 rcAnnot = PWLtoFFL(rcWindow); |
71 } | 71 } |
72 | 72 |
73 CFX_FloatRect rcWin = rcAnnot; | 73 CFX_FloatRect rcWin = rcAnnot; |
74 | 74 |
75 CFX_FloatRect rcFocus = GetFocusBox(pPageView); | 75 CFX_FloatRect rcFocus = GetFocusBox(pPageView); |
76 if (!rcFocus.IsEmpty()) | 76 if (!rcFocus.IsEmpty()) |
77 rcWin.Union(rcFocus); | 77 rcWin.Union(rcFocus); |
78 | 78 |
79 CFX_FloatRect rect = CPWL_Utils::InflateRect(rcWin, 1); | 79 CFX_FloatRect rect = CPWL_Utils::InflateRect(rcWin, 1); |
80 | 80 |
81 return rect.GetOuterRect(); | 81 return rect.GetOuterRect(); |
82 } | 82 } |
83 | 83 |
84 void CFFL_FormFiller::OnDraw(CPDFSDK_PageView* pPageView, | 84 void CFFL_FormFiller::OnDraw(CPDFSDK_PageView* pPageView, |
85 CPDFSDK_Annot* pAnnot, | 85 CPDFSDK_Annot* pAnnot, |
86 CFX_RenderDevice* pDevice, | 86 CFX_RenderDevice* pDevice, |
87 CFX_Matrix* pUser2Device) { | 87 CFX_Matrix* pUser2Device) { |
88 ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); | 88 ASSERT(pAnnot->GetPDFAnnot()->GetSubtype() == CPDF_Annot::Subtype::WIDGET); |
89 | 89 |
90 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | 90 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) { |
91 CFX_Matrix mt = GetCurMatrix(); | 91 CFX_Matrix mt = GetCurMatrix(); |
92 mt.Concat(*pUser2Device); | 92 mt.Concat(*pUser2Device); |
93 pWnd->DrawAppearance(pDevice, &mt); | 93 pWnd->DrawAppearance(pDevice, &mt); |
94 } else { | 94 } else { |
95 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; | 95 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; |
96 if (CFFL_InteractiveFormFiller::IsVisible(pWidget)) | 96 if (CFFL_InteractiveFormFiller::IsVisible(pWidget)) |
97 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, | 97 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, |
98 nullptr); | 98 nullptr); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView* pPageView, | 102 void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView* pPageView, |
103 CPDFSDK_Annot* pAnnot, | 103 CPDFSDK_Annot* pAnnot, |
104 CFX_RenderDevice* pDevice, | 104 CFX_RenderDevice* pDevice, |
105 CFX_Matrix* pUser2Device) { | 105 CFX_Matrix* pUser2Device) { |
106 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; | 106 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; |
107 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); | 107 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); |
108 } | 108 } |
109 | 109 |
110 void CFFL_FormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView, | 110 void CFFL_FormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView, |
111 CPDFSDK_Annot* pAnnot) {} | 111 CPDFSDK_Annot* pAnnot) {} |
112 | 112 |
113 void CFFL_FormFiller::OnMouseExit(CPDFSDK_PageView* pPageView, | 113 void CFFL_FormFiller::OnMouseExit(CPDFSDK_PageView* pPageView, |
114 CPDFSDK_Annot* pAnnot) { | 114 CPDFSDK_Annot* pAnnot) { |
115 EndTimer(); | 115 EndTimer(); |
116 ASSERT(m_pWidget); | 116 ASSERT(m_pWidget); |
117 } | 117 } |
118 | 118 |
119 FX_BOOL CFFL_FormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView, | 119 bool CFFL_FormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView, |
120 CPDFSDK_Annot* pAnnot, | 120 CPDFSDK_Annot* pAnnot, |
121 uint32_t nFlags, | 121 uint32_t nFlags, |
122 const CFX_FloatPoint& point) { | 122 const CFX_FloatPoint& point) { |
123 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) { | 123 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true)) { |
124 m_bValid = TRUE; | 124 m_bValid = true; |
125 FX_RECT rect = GetViewBBox(pPageView, pAnnot); | 125 FX_RECT rect = GetViewBBox(pPageView, pAnnot); |
126 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); | 126 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); |
127 | 127 |
128 if (!rect.Contains((int)point.x, (int)point.y)) | 128 if (!rect.Contains((int)point.x, (int)point.y)) |
129 return FALSE; | 129 return false; |
130 | 130 |
131 return pWnd->OnLButtonDown(WndtoPWL(pPageView, point), nFlags); | 131 return pWnd->OnLButtonDown(WndtoPWL(pPageView, point), nFlags); |
132 } | 132 } |
133 | 133 |
134 return FALSE; | 134 return false; |
135 } | 135 } |
136 | 136 |
137 FX_BOOL CFFL_FormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, | 137 bool CFFL_FormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, |
138 CPDFSDK_Annot* pAnnot, | 138 CPDFSDK_Annot* pAnnot, |
139 uint32_t nFlags, | 139 uint32_t nFlags, |
140 const CFX_FloatPoint& point) { | 140 const CFX_FloatPoint& point) { |
141 CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE); | 141 CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
142 if (!pWnd) | 142 if (!pWnd) |
143 return FALSE; | 143 return false; |
144 | 144 |
145 FX_RECT rcFFL = GetViewBBox(pPageView, pAnnot); | 145 FX_RECT rcFFL = GetViewBBox(pPageView, pAnnot); |
146 InvalidateRect(rcFFL.left, rcFFL.top, rcFFL.right, rcFFL.bottom); | 146 InvalidateRect(rcFFL.left, rcFFL.top, rcFFL.right, rcFFL.bottom); |
147 pWnd->OnLButtonUp(WndtoPWL(pPageView, point), nFlags); | 147 pWnd->OnLButtonUp(WndtoPWL(pPageView, point), nFlags); |
148 return TRUE; | 148 return true; |
149 } | 149 } |
150 | 150 |
151 FX_BOOL CFFL_FormFiller::OnLButtonDblClk(CPDFSDK_PageView* pPageView, | 151 bool CFFL_FormFiller::OnLButtonDblClk(CPDFSDK_PageView* pPageView, |
152 CPDFSDK_Annot* pAnnot, | 152 CPDFSDK_Annot* pAnnot, |
153 uint32_t nFlags, | 153 uint32_t nFlags, |
154 const CFX_FloatPoint& point) { | 154 const CFX_FloatPoint& point) { |
155 CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE); | 155 CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
156 if (!pWnd) | 156 if (!pWnd) |
157 return FALSE; | 157 return false; |
158 | 158 |
159 pWnd->OnLButtonDblClk(WndtoPWL(pPageView, point), nFlags); | 159 pWnd->OnLButtonDblClk(WndtoPWL(pPageView, point), nFlags); |
160 return TRUE; | 160 return true; |
161 } | 161 } |
162 | 162 |
163 FX_BOOL CFFL_FormFiller::OnMouseMove(CPDFSDK_PageView* pPageView, | 163 bool CFFL_FormFiller::OnMouseMove(CPDFSDK_PageView* pPageView, |
164 CPDFSDK_Annot* pAnnot, | 164 CPDFSDK_Annot* pAnnot, |
165 uint32_t nFlags, | 165 uint32_t nFlags, |
166 const CFX_FloatPoint& point) { | 166 const CFX_FloatPoint& point) { |
167 if (m_ptOldPos != point) | 167 if (m_ptOldPos != point) |
168 m_ptOldPos = point; | 168 m_ptOldPos = point; |
169 | 169 |
170 CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE); | 170 CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
171 if (!pWnd) | 171 if (!pWnd) |
172 return FALSE; | 172 return false; |
173 | 173 |
174 pWnd->OnMouseMove(WndtoPWL(pPageView, point), nFlags); | 174 pWnd->OnMouseMove(WndtoPWL(pPageView, point), nFlags); |
175 return TRUE; | 175 return true; |
176 } | 176 } |
177 | 177 |
178 FX_BOOL CFFL_FormFiller::OnMouseWheel(CPDFSDK_PageView* pPageView, | 178 bool CFFL_FormFiller::OnMouseWheel(CPDFSDK_PageView* pPageView, |
179 CPDFSDK_Annot* pAnnot, | 179 CPDFSDK_Annot* pAnnot, |
180 uint32_t nFlags, | 180 uint32_t nFlags, |
181 short zDelta, | 181 short zDelta, |
182 const CFX_FloatPoint& point) { | 182 const CFX_FloatPoint& point) { |
183 if (!IsValid()) | 183 if (!IsValid()) |
184 return FALSE; | 184 return false; |
185 | 185 |
186 CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE); | 186 CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true); |
187 return pWnd && pWnd->OnMouseWheel(zDelta, WndtoPWL(pPageView, point), nFlags); | 187 return pWnd && pWnd->OnMouseWheel(zDelta, WndtoPWL(pPageView, point), nFlags); |
188 } | 188 } |
189 | 189 |
190 FX_BOOL CFFL_FormFiller::OnRButtonDown(CPDFSDK_PageView* pPageView, | 190 bool CFFL_FormFiller::OnRButtonDown(CPDFSDK_PageView* pPageView, |
191 CPDFSDK_Annot* pAnnot, | 191 CPDFSDK_Annot* pAnnot, |
192 uint32_t nFlags, | 192 uint32_t nFlags, |
193 const CFX_FloatPoint& point) { | 193 const CFX_FloatPoint& point) { |
194 CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE); | 194 CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true); |
195 if (!pWnd) | 195 if (!pWnd) |
196 return FALSE; | 196 return false; |
197 | 197 |
198 pWnd->OnRButtonDown(WndtoPWL(pPageView, point), nFlags); | 198 pWnd->OnRButtonDown(WndtoPWL(pPageView, point), nFlags); |
199 return TRUE; | 199 return true; |
200 } | 200 } |
201 | 201 |
202 FX_BOOL CFFL_FormFiller::OnRButtonUp(CPDFSDK_PageView* pPageView, | 202 bool CFFL_FormFiller::OnRButtonUp(CPDFSDK_PageView* pPageView, |
203 CPDFSDK_Annot* pAnnot, | 203 CPDFSDK_Annot* pAnnot, |
204 uint32_t nFlags, | 204 uint32_t nFlags, |
205 const CFX_FloatPoint& point) { | 205 const CFX_FloatPoint& point) { |
206 CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE); | 206 CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false); |
207 if (!pWnd) | 207 if (!pWnd) |
208 return FALSE; | 208 return false; |
209 | 209 |
210 pWnd->OnRButtonUp(WndtoPWL(pPageView, point), nFlags); | 210 pWnd->OnRButtonUp(WndtoPWL(pPageView, point), nFlags); |
211 return TRUE; | 211 return true; |
212 } | 212 } |
213 | 213 |
214 FX_BOOL CFFL_FormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, | 214 bool CFFL_FormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, |
215 uint32_t nKeyCode, | 215 uint32_t nKeyCode, |
216 uint32_t nFlags) { | |
217 if (IsValid()) { | |
218 CPDFSDK_PageView* pPageView = GetCurPageView(true); | |
219 ASSERT(pPageView); | |
220 | |
221 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | |
222 return pWnd->OnKeyDown(nKeyCode, nFlags); | |
223 } | |
224 } | |
225 | |
226 return FALSE; | |
227 } | |
228 | |
229 FX_BOOL CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, | |
230 uint32_t nChar, | |
231 uint32_t nFlags) { | 216 uint32_t nFlags) { |
232 if (IsValid()) { | 217 if (IsValid()) { |
233 CPDFSDK_PageView* pPageView = GetCurPageView(true); | 218 CPDFSDK_PageView* pPageView = GetCurPageView(true); |
234 ASSERT(pPageView); | 219 ASSERT(pPageView); |
235 | 220 |
236 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | 221 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) { |
| 222 return pWnd->OnKeyDown(nKeyCode, nFlags); |
| 223 } |
| 224 } |
| 225 |
| 226 return false; |
| 227 } |
| 228 |
| 229 bool CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, |
| 230 uint32_t nChar, |
| 231 uint32_t nFlags) { |
| 232 if (IsValid()) { |
| 233 CPDFSDK_PageView* pPageView = GetCurPageView(true); |
| 234 ASSERT(pPageView); |
| 235 |
| 236 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) { |
237 return pWnd->OnChar(nChar, nFlags); | 237 return pWnd->OnChar(nChar, nFlags); |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 return FALSE; | 241 return false; |
242 } | 242 } |
243 | 243 |
244 void CFFL_FormFiller::SetFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag) { | 244 void CFFL_FormFiller::SetFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag) { |
245 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; | 245 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; |
246 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); | 246 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); |
247 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, true); | 247 CPDFSDK_PageView* pPageView = m_pFormFillEnv->GetPageView(pPage, true); |
248 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) | 248 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true)) |
249 pWnd->SetFocus(); | 249 pWnd->SetFocus(); |
250 | 250 |
251 m_bValid = TRUE; | 251 m_bValid = true; |
252 FX_RECT rcRect = GetViewBBox(pPageView, pAnnot); | 252 FX_RECT rcRect = GetViewBBox(pPageView, pAnnot); |
253 InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); | 253 InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); |
254 } | 254 } |
255 | 255 |
256 void CFFL_FormFiller::KillFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag) { | 256 void CFFL_FormFiller::KillFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag) { |
257 if (!IsValid()) | 257 if (!IsValid()) |
258 return; | 258 return; |
259 | 259 |
260 CPDFSDK_PageView* pPageView = GetCurPageView(false); | 260 CPDFSDK_PageView* pPageView = GetCurPageView(false); |
261 if (!pPageView) | 261 if (!pPageView) |
262 return; | 262 return; |
263 | 263 |
264 CommitData(pPageView, nFlag); | 264 CommitData(pPageView, nFlag); |
265 | 265 |
266 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) | 266 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) |
267 pWnd->KillFocus(); | 267 pWnd->KillFocus(); |
268 | 268 |
269 FX_BOOL bDestroyPDFWindow; | 269 bool bDestroyPDFWindow; |
270 switch (m_pWidget->GetFieldType()) { | 270 switch (m_pWidget->GetFieldType()) { |
271 case FIELDTYPE_PUSHBUTTON: | 271 case FIELDTYPE_PUSHBUTTON: |
272 case FIELDTYPE_CHECKBOX: | 272 case FIELDTYPE_CHECKBOX: |
273 case FIELDTYPE_RADIOBUTTON: | 273 case FIELDTYPE_RADIOBUTTON: |
274 bDestroyPDFWindow = TRUE; | 274 bDestroyPDFWindow = true; |
275 break; | 275 break; |
276 default: | 276 default: |
277 bDestroyPDFWindow = FALSE; | 277 bDestroyPDFWindow = false; |
278 break; | 278 break; |
279 } | 279 } |
280 EscapeFiller(pPageView, bDestroyPDFWindow); | 280 EscapeFiller(pPageView, bDestroyPDFWindow); |
281 } | 281 } |
282 | 282 |
283 FX_BOOL CFFL_FormFiller::IsValid() const { | 283 bool CFFL_FormFiller::IsValid() const { |
284 return m_bValid; | 284 return m_bValid; |
285 } | 285 } |
286 | 286 |
287 PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam() { | 287 PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam() { |
288 ASSERT(m_pFormFillEnv); | 288 ASSERT(m_pFormFillEnv); |
289 | 289 |
290 PWL_CREATEPARAM cp; | 290 PWL_CREATEPARAM cp; |
291 cp.pParentWnd = nullptr; | 291 cp.pParentWnd = nullptr; |
292 cp.pProvider = this; | 292 cp.pProvider = this; |
293 cp.rcRectWnd = GetPDFWindowRect(); | 293 cp.rcRectWnd = GetPDFWindowRect(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 | 335 |
336 if (cp.fFontSize <= 0) | 336 if (cp.fFontSize <= 0) |
337 dwCreateFlags |= PWS_AUTOFONTSIZE; | 337 dwCreateFlags |= PWS_AUTOFONTSIZE; |
338 | 338 |
339 cp.dwFlags = dwCreateFlags; | 339 cp.dwFlags = dwCreateFlags; |
340 cp.pSystemHandler = m_pFormFillEnv->GetSysHandler(); | 340 cp.pSystemHandler = m_pFormFillEnv->GetSysHandler(); |
341 return cp; | 341 return cp; |
342 } | 342 } |
343 | 343 |
344 CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, | 344 CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, |
345 FX_BOOL bNew) { | 345 bool bNew) { |
346 ASSERT(pPageView); | 346 ASSERT(pPageView); |
347 | 347 |
348 auto it = m_Maps.find(pPageView); | 348 auto it = m_Maps.find(pPageView); |
349 const bool found = it != m_Maps.end(); | 349 const bool found = it != m_Maps.end(); |
350 CPWL_Wnd* pWnd = found ? it->second : nullptr; | 350 CPWL_Wnd* pWnd = found ? it->second : nullptr; |
351 if (!bNew) | 351 if (!bNew) |
352 return pWnd; | 352 return pWnd; |
353 | 353 |
354 if (found) { | 354 if (found) { |
355 CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pWnd->GetAttachedData(); | 355 CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pWnd->GetAttachedData(); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 | 447 |
448 return CFX_FloatRect(0, 0, fWidth, fHeight); | 448 return CFX_FloatRect(0, 0, fWidth, fHeight); |
449 } | 449 } |
450 | 450 |
451 CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView(bool renew) { | 451 CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView(bool renew) { |
452 UnderlyingPageType* pPage = m_pAnnot->GetUnderlyingPage(); | 452 UnderlyingPageType* pPage = m_pAnnot->GetUnderlyingPage(); |
453 return m_pFormFillEnv ? m_pFormFillEnv->GetPageView(pPage, renew) : nullptr; | 453 return m_pFormFillEnv ? m_pFormFillEnv->GetPageView(pPage, renew) : nullptr; |
454 } | 454 } |
455 | 455 |
456 CFX_FloatRect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView) { | 456 CFX_FloatRect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView) { |
457 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | 457 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) { |
458 CFX_FloatRect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect())); | 458 CFX_FloatRect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect())); |
459 CFX_FloatRect rcPage = pPageView->GetPDFPage()->GetPageBBox(); | 459 CFX_FloatRect rcPage = pPageView->GetPDFPage()->GetPageBBox(); |
460 if (rcPage.Contains(rcFocus)) | 460 if (rcPage.Contains(rcFocus)) |
461 return rcFocus; | 461 return rcFocus; |
462 } | 462 } |
463 return CFX_FloatRect(0, 0, 0, 0); | 463 return CFX_FloatRect(0, 0, 0, 0); |
464 } | 464 } |
465 | 465 |
466 CFX_FloatRect CFFL_FormFiller::FFLtoPWL(const CFX_FloatRect& rect) { | 466 CFX_FloatRect CFFL_FormFiller::FFLtoPWL(const CFX_FloatRect& rect) { |
467 CFX_Matrix mt; | 467 CFX_Matrix mt; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 CFX_FloatPoint CFFL_FormFiller::WndtoPWL(CPDFSDK_PageView* pPageView, | 504 CFX_FloatPoint CFFL_FormFiller::WndtoPWL(CPDFSDK_PageView* pPageView, |
505 const CFX_FloatPoint& pt) { | 505 const CFX_FloatPoint& pt) { |
506 return FFLtoPWL(pt); | 506 return FFLtoPWL(pt); |
507 } | 507 } |
508 | 508 |
509 CFX_FloatRect CFFL_FormFiller::FFLtoWnd(CPDFSDK_PageView* pPageView, | 509 CFX_FloatRect CFFL_FormFiller::FFLtoWnd(CPDFSDK_PageView* pPageView, |
510 const CFX_FloatRect& rect) { | 510 const CFX_FloatRect& rect) { |
511 return rect; | 511 return rect; |
512 } | 512 } |
513 | 513 |
514 FX_BOOL CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, | 514 bool CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, uint32_t nFlag) { |
515 uint32_t nFlag) { | |
516 if (IsDataChanged(pPageView)) { | 515 if (IsDataChanged(pPageView)) { |
517 FX_BOOL bRC = TRUE; | 516 bool bRC = true; |
518 FX_BOOL bExit = FALSE; | 517 bool bExit = false; |
519 CFFL_InteractiveFormFiller* pFormFiller = | 518 CFFL_InteractiveFormFiller* pFormFiller = |
520 m_pFormFillEnv->GetInteractiveFormFiller(); | 519 m_pFormFillEnv->GetInteractiveFormFiller(); |
521 CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget); | 520 CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget); |
522 pFormFiller->OnKeyStrokeCommit(&pObserved, pPageView, bRC, bExit, nFlag); | 521 pFormFiller->OnKeyStrokeCommit(&pObserved, pPageView, bRC, bExit, nFlag); |
523 if (!pObserved || bExit) | 522 if (!pObserved || bExit) |
524 return TRUE; | 523 return true; |
525 if (!bRC) { | 524 if (!bRC) { |
526 ResetPDFWindow(pPageView, FALSE); | 525 ResetPDFWindow(pPageView, false); |
527 return TRUE; | 526 return true; |
528 } | 527 } |
529 pFormFiller->OnValidate(&pObserved, pPageView, bRC, bExit, nFlag); | 528 pFormFiller->OnValidate(&pObserved, pPageView, bRC, bExit, nFlag); |
530 if (!pObserved || bExit) | 529 if (!pObserved || bExit) |
531 return TRUE; | 530 return true; |
532 if (!bRC) { | 531 if (!bRC) { |
533 ResetPDFWindow(pPageView, FALSE); | 532 ResetPDFWindow(pPageView, false); |
534 return TRUE; | 533 return true; |
535 } | 534 } |
536 SaveData(pPageView); | 535 SaveData(pPageView); |
537 pFormFiller->OnCalculate(m_pWidget, pPageView, bExit, nFlag); | 536 pFormFiller->OnCalculate(m_pWidget, pPageView, bExit, nFlag); |
538 if (bExit) | 537 if (bExit) |
539 return TRUE; | 538 return true; |
540 | 539 |
541 pFormFiller->OnFormat(m_pWidget, pPageView, bExit, nFlag); | 540 pFormFiller->OnFormat(m_pWidget, pPageView, bExit, nFlag); |
542 } | 541 } |
543 return TRUE; | 542 return true; |
544 } | 543 } |
545 | 544 |
546 FX_BOOL CFFL_FormFiller::IsDataChanged(CPDFSDK_PageView* pPageView) { | 545 bool CFFL_FormFiller::IsDataChanged(CPDFSDK_PageView* pPageView) { |
547 return FALSE; | 546 return false; |
548 } | 547 } |
549 | 548 |
550 void CFFL_FormFiller::SaveData(CPDFSDK_PageView* pPageView) {} | 549 void CFFL_FormFiller::SaveData(CPDFSDK_PageView* pPageView) {} |
551 | 550 |
552 #ifdef PDF_ENABLE_XFA | 551 #ifdef PDF_ENABLE_XFA |
553 FX_BOOL CFFL_FormFiller::IsFieldFull(CPDFSDK_PageView* pPageView) { | 552 bool CFFL_FormFiller::IsFieldFull(CPDFSDK_PageView* pPageView) { |
554 return FALSE; | 553 return false; |
555 } | 554 } |
556 #endif // PDF_ENABLE_XFA | 555 #endif // PDF_ENABLE_XFA |
557 | 556 |
558 void CFFL_FormFiller::SetChangeMark() { | 557 void CFFL_FormFiller::SetChangeMark() { |
559 m_pFormFillEnv->OnChange(); | 558 m_pFormFillEnv->OnChange(); |
560 } | 559 } |
561 | 560 |
562 void CFFL_FormFiller::GetActionData(CPDFSDK_PageView* pPageView, | 561 void CFFL_FormFiller::GetActionData(CPDFSDK_PageView* pPageView, |
563 CPDF_AAction::AActionType type, | 562 CPDF_AAction::AActionType type, |
564 PDFSDK_FieldAction& fa) { | 563 PDFSDK_FieldAction& fa) { |
565 fa.sValue = m_pWidget->GetValue(); | 564 fa.sValue = m_pWidget->GetValue(); |
566 } | 565 } |
567 | 566 |
568 void CFFL_FormFiller::SetActionData(CPDFSDK_PageView* pPageView, | 567 void CFFL_FormFiller::SetActionData(CPDFSDK_PageView* pPageView, |
569 CPDF_AAction::AActionType type, | 568 CPDF_AAction::AActionType type, |
570 const PDFSDK_FieldAction& fa) {} | 569 const PDFSDK_FieldAction& fa) {} |
571 | 570 |
572 FX_BOOL CFFL_FormFiller::IsActionDataChanged(CPDF_AAction::AActionType type, | 571 bool CFFL_FormFiller::IsActionDataChanged(CPDF_AAction::AActionType type, |
573 const PDFSDK_FieldAction& faOld, | 572 const PDFSDK_FieldAction& faOld, |
574 const PDFSDK_FieldAction& faNew) { | 573 const PDFSDK_FieldAction& faNew) { |
575 return FALSE; | 574 return false; |
576 } | 575 } |
577 | 576 |
578 void CFFL_FormFiller::SaveState(CPDFSDK_PageView* pPageView) {} | 577 void CFFL_FormFiller::SaveState(CPDFSDK_PageView* pPageView) {} |
579 | 578 |
580 void CFFL_FormFiller::RestoreState(CPDFSDK_PageView* pPageView) {} | 579 void CFFL_FormFiller::RestoreState(CPDFSDK_PageView* pPageView) {} |
581 | 580 |
582 CPWL_Wnd* CFFL_FormFiller::ResetPDFWindow(CPDFSDK_PageView* pPageView, | 581 CPWL_Wnd* CFFL_FormFiller::ResetPDFWindow(CPDFSDK_PageView* pPageView, |
583 FX_BOOL bRestoreValue) { | 582 bool bRestoreValue) { |
584 return GetPDFWindow(pPageView, FALSE); | 583 return GetPDFWindow(pPageView, false); |
585 } | 584 } |
586 | 585 |
587 void CFFL_FormFiller::TimerProc() {} | 586 void CFFL_FormFiller::TimerProc() {} |
588 | 587 |
589 CFX_SystemHandler* CFFL_FormFiller::GetSystemHandler() const { | 588 CFX_SystemHandler* CFFL_FormFiller::GetSystemHandler() const { |
590 return m_pFormFillEnv->GetSysHandler(); | 589 return m_pFormFillEnv->GetSysHandler(); |
591 } | 590 } |
592 | 591 |
593 void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView, | 592 void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView, |
594 FX_BOOL bDestroyPDFWindow) { | 593 bool bDestroyPDFWindow) { |
595 m_bValid = FALSE; | 594 m_bValid = false; |
596 | 595 |
597 FX_RECT rcRect = GetViewBBox(pPageView, m_pWidget); | 596 FX_RECT rcRect = GetViewBBox(pPageView, m_pWidget); |
598 InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); | 597 InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); |
599 | 598 |
600 if (bDestroyPDFWindow) | 599 if (bDestroyPDFWindow) |
601 DestroyPDFWindow(pPageView); | 600 DestroyPDFWindow(pPageView); |
602 } | 601 } |
603 | 602 |
604 void CFFL_FormFiller::InvalidateRect(double left, | 603 void CFFL_FormFiller::InvalidateRect(double left, |
605 double top, | 604 double top, |
606 double right, | 605 double right, |
607 double bottom) { | 606 double bottom) { |
608 UnderlyingPageType* pPage = m_pWidget->GetUnderlyingPage(); | 607 UnderlyingPageType* pPage = m_pWidget->GetUnderlyingPage(); |
609 m_pFormFillEnv->Invalidate(pPage, left, top, right, bottom); | 608 m_pFormFillEnv->Invalidate(pPage, left, top, right, bottom); |
610 } | 609 } |
611 | 610 |
612 CFFL_Button::CFFL_Button(CPDFSDK_FormFillEnvironment* pApp, | 611 CFFL_Button::CFFL_Button(CPDFSDK_FormFillEnvironment* pApp, |
613 CPDFSDK_Annot* pWidget) | 612 CPDFSDK_Annot* pWidget) |
614 : CFFL_FormFiller(pApp, pWidget), m_bMouseIn(FALSE), m_bMouseDown(FALSE) {} | 613 : CFFL_FormFiller(pApp, pWidget), m_bMouseIn(false), m_bMouseDown(false) {} |
615 | 614 |
616 CFFL_Button::~CFFL_Button() {} | 615 CFFL_Button::~CFFL_Button() {} |
617 | 616 |
618 void CFFL_Button::OnMouseEnter(CPDFSDK_PageView* pPageView, | 617 void CFFL_Button::OnMouseEnter(CPDFSDK_PageView* pPageView, |
619 CPDFSDK_Annot* pAnnot) { | 618 CPDFSDK_Annot* pAnnot) { |
620 m_bMouseIn = TRUE; | 619 m_bMouseIn = true; |
621 FX_RECT rect = GetViewBBox(pPageView, pAnnot); | 620 FX_RECT rect = GetViewBBox(pPageView, pAnnot); |
622 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); | 621 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); |
623 } | 622 } |
624 | 623 |
625 void CFFL_Button::OnMouseExit(CPDFSDK_PageView* pPageView, | 624 void CFFL_Button::OnMouseExit(CPDFSDK_PageView* pPageView, |
626 CPDFSDK_Annot* pAnnot) { | 625 CPDFSDK_Annot* pAnnot) { |
627 m_bMouseIn = FALSE; | 626 m_bMouseIn = false; |
628 | 627 |
629 FX_RECT rect = GetViewBBox(pPageView, pAnnot); | 628 FX_RECT rect = GetViewBBox(pPageView, pAnnot); |
630 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); | 629 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); |
631 EndTimer(); | 630 EndTimer(); |
632 ASSERT(m_pWidget); | 631 ASSERT(m_pWidget); |
633 } | 632 } |
634 | 633 |
635 FX_BOOL CFFL_Button::OnLButtonDown(CPDFSDK_PageView* pPageView, | 634 bool CFFL_Button::OnLButtonDown(CPDFSDK_PageView* pPageView, |
636 CPDFSDK_Annot* pAnnot, | 635 CPDFSDK_Annot* pAnnot, |
637 uint32_t nFlags, | 636 uint32_t nFlags, |
638 const CFX_FloatPoint& point) { | 637 const CFX_FloatPoint& point) { |
639 CFX_FloatRect rcAnnot = pAnnot->GetRect(); | 638 CFX_FloatRect rcAnnot = pAnnot->GetRect(); |
640 if (!rcAnnot.Contains(point.x, point.y)) | 639 if (!rcAnnot.Contains(point.x, point.y)) |
641 return FALSE; | 640 return false; |
642 | 641 |
643 m_bMouseDown = TRUE; | 642 m_bMouseDown = true; |
644 m_bValid = TRUE; | 643 m_bValid = true; |
645 FX_RECT rect = GetViewBBox(pPageView, pAnnot); | 644 FX_RECT rect = GetViewBBox(pPageView, pAnnot); |
646 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); | 645 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); |
647 return TRUE; | 646 return true; |
648 } | 647 } |
649 | 648 |
650 FX_BOOL CFFL_Button::OnLButtonUp(CPDFSDK_PageView* pPageView, | 649 bool CFFL_Button::OnLButtonUp(CPDFSDK_PageView* pPageView, |
651 CPDFSDK_Annot* pAnnot, | 650 CPDFSDK_Annot* pAnnot, |
652 uint32_t nFlags, | 651 uint32_t nFlags, |
653 const CFX_FloatPoint& point) { | 652 const CFX_FloatPoint& point) { |
654 CFX_FloatRect rcAnnot = pAnnot->GetRect(); | 653 CFX_FloatRect rcAnnot = pAnnot->GetRect(); |
655 if (!rcAnnot.Contains(point.x, point.y)) | 654 if (!rcAnnot.Contains(point.x, point.y)) |
656 return FALSE; | 655 return false; |
657 | 656 |
658 m_bMouseDown = FALSE; | 657 m_bMouseDown = false; |
659 m_pWidget->GetPDFPage(); | 658 m_pWidget->GetPDFPage(); |
660 | 659 |
661 FX_RECT rect = GetViewBBox(pPageView, pAnnot); | 660 FX_RECT rect = GetViewBBox(pPageView, pAnnot); |
662 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); | 661 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); |
663 return TRUE; | 662 return true; |
664 } | 663 } |
665 | 664 |
666 FX_BOOL CFFL_Button::OnMouseMove(CPDFSDK_PageView* pPageView, | 665 bool CFFL_Button::OnMouseMove(CPDFSDK_PageView* pPageView, |
667 CPDFSDK_Annot* pAnnot, | 666 CPDFSDK_Annot* pAnnot, |
668 uint32_t nFlags, | 667 uint32_t nFlags, |
669 const CFX_FloatPoint& point) { | 668 const CFX_FloatPoint& point) { |
670 ASSERT(m_pFormFillEnv); | 669 ASSERT(m_pFormFillEnv); |
671 | 670 |
672 return TRUE; | 671 return true; |
673 } | 672 } |
674 | 673 |
675 void CFFL_Button::OnDraw(CPDFSDK_PageView* pPageView, | 674 void CFFL_Button::OnDraw(CPDFSDK_PageView* pPageView, |
676 CPDFSDK_Annot* pAnnot, | 675 CPDFSDK_Annot* pAnnot, |
677 CFX_RenderDevice* pDevice, | 676 CFX_RenderDevice* pDevice, |
678 CFX_Matrix* pUser2Device) { | 677 CFX_Matrix* pUser2Device) { |
679 ASSERT(pPageView); | 678 ASSERT(pPageView); |
680 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; | 679 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; |
681 CPDF_FormControl* pCtrl = pWidget->GetFormControl(); | 680 CPDF_FormControl* pCtrl = pWidget->GetFormControl(); |
682 CPDF_FormControl::HighlightingMode eHM = pCtrl->GetHighlightingMode(); | 681 CPDF_FormControl::HighlightingMode eHM = pCtrl->GetHighlightingMode(); |
(...skipping 20 matching lines...) Expand all Loading... |
703 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); | 702 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); |
704 } | 703 } |
705 } | 704 } |
706 | 705 |
707 void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView* pPageView, | 706 void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView* pPageView, |
708 CPDFSDK_Annot* pAnnot, | 707 CPDFSDK_Annot* pAnnot, |
709 CFX_RenderDevice* pDevice, | 708 CFX_RenderDevice* pDevice, |
710 CFX_Matrix* pUser2Device) { | 709 CFX_Matrix* pUser2Device) { |
711 OnDraw(pPageView, pAnnot, pDevice, pUser2Device); | 710 OnDraw(pPageView, pAnnot, pDevice, pUser2Device); |
712 } | 711 } |
OLD | NEW |