Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: fpdfsdk/src/fsdk_annothandler.cpp

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "../include/fsdk_define.h" 7 #include "../include/fsdk_define.h"
8 #include "../include/fsdk_mgr.h" 8 #include "../include/fsdk_mgr.h"
9 #include "../include/formfiller/FFL_FormFiller.h" 9 #include "../include/formfiller/FFL_FormFiller.h"
10 #include "../include/fsdk_annothandler.h" 10 #include "../include/fsdk_annothandler.h"
11 11
12 12 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) {
13 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) 13 m_pApp = pApp;
14 { 14
15 m_pApp = pApp; 15 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);
16 16 pHandler->SetFormFiller(m_pApp->GetIFormFiller());
17 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); 17 RegisterAnnotHandler(pHandler);
18 pHandler->SetFormFiller(m_pApp->GetIFormFiller()); 18 }
19 RegisterAnnotHandler(pHandler); 19
20 } 20 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {
21 21 for (int i = 0; i < m_Handlers.GetSize(); i++) {
22 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() 22 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i);
23 { 23 delete pHandler;
24 for(int i=0; i<m_Handlers.GetSize(); i++) 24 }
25 { 25 m_Handlers.RemoveAll();
26 IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i); 26 m_mapType2Handler.RemoveAll();
27 delete pHandler; 27 }
28 } 28
29 m_Handlers.RemoveAll(); 29 void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler(
30 m_mapType2Handler.RemoveAll(); 30 IPDFSDK_AnnotHandler* pAnnotHandler) {
31 } 31 ASSERT(pAnnotHandler != NULL);
32 32
33 void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnn otHandler) 33 ASSERT(GetAnnotHandler(pAnnotHandler->GetType()) == NULL);
34 { 34
35 ASSERT(pAnnotHandler != NULL); 35 m_Handlers.Add(pAnnotHandler);
36 36 m_mapType2Handler.SetAt(pAnnotHandler->GetType(), (void*)pAnnotHandler);
37 ASSERT(GetAnnotHandler(pAnnotHandler->GetType()) == NULL); 37 }
38 38
39 m_Handlers.Add(pAnnotHandler); 39 void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler(
40 m_mapType2Handler.SetAt(pAnnotHandler->GetType(), (void*)pAnnotHandler); 40 IPDFSDK_AnnotHandler* pAnnotHandler) {
41 } 41 ASSERT(pAnnotHandler != NULL);
42 42
43 void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler(IPDFSDK_AnnotHandler* pAnno tHandler) 43 m_mapType2Handler.RemoveKey(pAnnotHandler->GetType());
44 { 44
45 ASSERT(pAnnotHandler != NULL); 45 for (int i = 0, sz = m_Handlers.GetSize(); i < sz; i++) {
46 46 if (m_Handlers.GetAt(i) == pAnnotHandler) {
47 m_mapType2Handler.RemoveKey(pAnnotHandler->GetType()); 47 m_Handlers.RemoveAt(i);
48 48 break;
49 for (int i=0, sz=m_Handlers.GetSize(); i<sz; i++) 49 }
50 { 50 }
51 if (m_Handlers.GetAt(i) == pAnnotHandler) 51 }
52 { 52
53 m_Handlers.RemoveAt(i); 53 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot,
54 break; 54 CPDFSDK_PageView* pPageView) {
55 } 55 ASSERT(pAnnot != NULL);
56 } 56 ASSERT(pPageView != NULL);
57 } 57
58 58 if (IPDFSDK_AnnotHandler* pAnnotHandler =
59 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot * pAnnot, CPDFSDK_Pa geView *pPageView) 59 GetAnnotHandler(pAnnot->GetSubType())) {
60 { 60 return pAnnotHandler->NewAnnot(pAnnot, pPageView);
61 ASSERT(pAnnot != NULL); 61 }
62 ASSERT(pPageView != NULL); 62
63 63 return new CPDFSDK_Annot(pAnnot, pPageView);
64 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot->GetSubType ())) 64 }
65 { 65
66 return pAnnotHandler->NewAnnot(pAnnot, pPageView); 66 void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
67 } 67 ASSERT(pAnnot != NULL);
68 68
69 return new CPDFSDK_Annot(pAnnot, pPageView); 69 pAnnot->GetPDFPage();
70 } 70
71 71 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
72 void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) 72 pAnnotHandler->OnRelease(pAnnot);
73 { 73 pAnnotHandler->ReleaseAnnot(pAnnot);
74 ASSERT(pAnnot != NULL); 74 } else {
75 75 delete (CPDFSDK_Annot*)pAnnot;
76 pAnnot->GetPDFPage(); 76 }
77 77 }
78 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) 78
79 { 79 void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) {
80 pAnnotHandler->OnRelease(pAnnot); 80 ASSERT(pAnnot != NULL);
81 pAnnotHandler->ReleaseAnnot(pAnnot); 81
82 } 82 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
83 else 83
84 { 84 CPDFSDK_DateTime curTime;
85 delete (CPDFSDK_Annot*)pAnnot; 85 pPDFAnnot->GetAnnotDict()->SetAtString("M", curTime.ToPDFDateTimeString());
86 } 86 pPDFAnnot->GetAnnotDict()->SetAtNumber("F", 0);
87 } 87
88 88 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
89 void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) 89 pAnnotHandler->OnCreate(pAnnot);
90 { 90 }
91 ASSERT(pAnnot != NULL); 91 }
92 92
93 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); 93 void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) {
94 94 ASSERT(pAnnot != NULL);
95 CPDFSDK_DateTime curTime; 95
96 pPDFAnnot->GetAnnotDict()->SetAtString("M", curTime.ToPDFDateTimeString()); 96 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
97 pPDFAnnot->GetAnnotDict()->SetAtNumber("F", 0); 97 pAnnotHandler->OnLoad(pAnnot);
98 98 }
99 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) 99 }
100 { 100
101 pAnnotHandler->OnCreate(pAnnot); 101 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
102 } 102 CPDFSDK_Annot* pAnnot) const {
103 } 103 ASSERT(pAnnot != NULL);
104 104
105 void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) 105 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
106 { 106 ASSERT(pPDFAnnot != NULL);
107 ASSERT(pAnnot != NULL); 107
108 108 return GetAnnotHandler(pPDFAnnot->GetSubType());
109 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) 109 }
110 { 110
111 pAnnotHandler->OnLoad(pAnnot); 111 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(
112 } 112 const CFX_ByteString& sType) const {
113 } 113 void* pRet = NULL;
114 114 m_mapType2Handler.Lookup(sType, pRet);
115 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(CPDFSDK_Annot* pA nnot) const 115 return (IPDFSDK_AnnotHandler*)pRet;
116 { 116 }
117 ASSERT(pAnnot != NULL); 117
118 118 void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView,
119 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); 119 CPDFSDK_Annot* pAnnot,
120 ASSERT(pPDFAnnot != NULL); 120 CFX_RenderDevice* pDevice,
121 121 CPDF_Matrix* pUser2Device,
122 return GetAnnotHandler(pPDFAnnot->GetSubType()); 122 FX_DWORD dwFlags) {
123 } 123 ASSERT(pAnnot != NULL);
124 124
125 IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler(const CFX_ByteStr ing& sType) const 125 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
126 { 126 pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
127 void* pRet = NULL; 127 } else {
128 m_mapType2Handler.Lookup(sType, pRet); 128 pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
129 return (IPDFSDK_AnnotHandler*)pRet; 129 }
130 } 130 }
131 131
132 void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, CPDFSDK_ Annot* pAnnot, CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device,FX_DWORD dwF lags) 132 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(
133 { 133 CPDFSDK_PageView* pPageView,
134 ASSERT(pAnnot != NULL); 134 CPDFSDK_Annot* pAnnot,
135 135 FX_DWORD nFlags,
136 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) 136 const CPDF_Point& point) {
137 { 137 ASSERT(pAnnot != NULL);
138 pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags) ; 138
139 } 139 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
140 else 140 return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point);
141 { 141 }
142 pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); 142 return FALSE;
143 } 143 }
144 } 144 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(CPDFSDK_PageView* pPageView,
145 145 CPDFSDK_Annot* pAnnot,
146 146 FX_DWORD nFlags,
147 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown(CPDFSDK_PageView * pPageVie w, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) 147 const CPDF_Point& point) {
148 { 148 ASSERT(pAnnot != NULL);
149 ASSERT(pAnnot != NULL); 149
150 150 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
151 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) 151 return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point);
152 { 152 }
153 return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point); 153 return FALSE;
154 } 154 }
155 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(
156 CPDFSDK_PageView* pPageView,
157 CPDFSDK_Annot* pAnnot,
158 FX_DWORD nFlags,
159 const CPDF_Point& point) {
160 ASSERT(pAnnot != NULL);
161
162 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
163 return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
164 }
165 return FALSE;
166 }
167 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(CPDFSDK_PageView* pPageView,
168 CPDFSDK_Annot* pAnnot,
169 FX_DWORD nFlags,
170 const CPDF_Point& point) {
171 ASSERT(pAnnot != NULL);
172
173 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
174 return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point);
175 }
176 return FALSE;
177 }
178 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(CPDFSDK_PageView* pPageView,
179 CPDFSDK_Annot* pAnnot,
180 FX_DWORD nFlags,
181 short zDelta,
182 const CPDF_Point& point) {
183 ASSERT(pAnnot != NULL);
184
185 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
186 return pAnnotHandler->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
187 point);
188 }
189 return FALSE;
190 }
191 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(
192 CPDFSDK_PageView* pPageView,
193 CPDFSDK_Annot* pAnnot,
194 FX_DWORD nFlags,
195 const CPDF_Point& point) {
196 ASSERT(pAnnot != NULL);
197
198 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
199 return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point);
200 }
201 return FALSE;
202 }
203 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(CPDFSDK_PageView* pPageView,
204 CPDFSDK_Annot* pAnnot,
205 FX_DWORD nFlags,
206 const CPDF_Point& point) {
207 ASSERT(pAnnot != NULL);
208
209 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
210 return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point);
211 }
212 return FALSE;
213 }
214
215 void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView* pPageView,
216 CPDFSDK_Annot* pAnnot,
217 FX_DWORD nFlag) {
218 ASSERT(pAnnot != NULL);
219
220 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
221 pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag);
222 }
223 return;
224 }
225
226 void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(CPDFSDK_PageView* pPageView,
227 CPDFSDK_Annot* pAnnot,
228 FX_DWORD nFlag) {
229 ASSERT(pAnnot != NULL);
230
231 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
232 pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag);
233 }
234 return;
235 }
236
237 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot,
238 FX_DWORD nChar,
239 FX_DWORD nFlags) {
240 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
241 return pAnnotHandler->OnChar(pAnnot, nChar, nFlags);
242 }
243 return FALSE;
244 }
245
246 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot,
247 int nKeyCode,
248 int nFlag) {
249 if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag)) {
250 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
251 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
252 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) {
253 CPDFSDK_Annot* pNext =
254 GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag));
255
256 if (pNext && pNext != pFocusAnnot) {
257 CPDFSDK_Document* pDocument = pPage->GetSDKDocument();
258 pDocument->SetFocusAnnot(pNext);
259 return TRUE;
260 }
261 }
262 }
263
264 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
265 return pAnnotHandler->OnKeyDown(pAnnot, nKeyCode, nFlag);
266 }
267 return FALSE;
268 }
269 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot,
270 int nKeyCode,
271 int nFlag) {
272 return FALSE;
273 }
274
275 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot,
276 FX_DWORD nFlag) {
277 ASSERT(pAnnot != NULL);
278
279 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
280 if (pAnnotHandler->OnSetFocus(pAnnot, nFlag)) {
281 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
282 pPage->GetSDKDocument();
283 return TRUE;
284 }
285 }
286 return FALSE;
287 }
288
289 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot,
290 FX_DWORD nFlag) {
291 ASSERT(pAnnot);
292 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
293 return pAnnotHandler->OnKillFocus(pAnnot, nFlag);
294
295 return FALSE;
296 }
297
298 CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(
299 CPDFSDK_PageView* pPageView,
300 CPDFSDK_Annot* pAnnot) {
301 ASSERT(pAnnot);
302 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
303 return pAnnotHandler->GetViewBBox(pPageView, pAnnot);
304
305 return pAnnot->GetRect();
306 }
307
308 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView,
309 CPDFSDK_Annot* pAnnot,
310 const CPDF_Point& point) {
311 ASSERT(pAnnot);
312 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) {
313 if (pAnnotHandler->CanAnswer(pAnnot))
314 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
315 }
316 return FALSE;
317 }
318
319 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,
320 FX_BOOL bNext) {
321 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", "");
322 return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
323 }
324
325 FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) {
326 ASSERT(pAnnot->GetType() == "Widget");
327 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
155 return FALSE; 328 return FALSE;
156 } 329
157 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) 330 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
158 { 331 if (!pWidget->IsVisible())
159 ASSERT(pAnnot != NULL);
160
161 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
162 {
163 return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point);
164 }
165 return FALSE; 332 return FALSE;
166 } 333
167 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk(CPDFSDK_PageView * pPageV iew, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) 334 int nFieldFlags = pWidget->GetFieldFlags();
168 { 335 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
169 ASSERT(pAnnot != NULL);
170
171 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
172 {
173 return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
174 }
175 return FALSE; 336 return FALSE;
176 } 337
177 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) 338 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
178 { 339 return TRUE;
179 ASSERT(pAnnot != NULL); 340
180 341 CPDF_Page* pPage = pWidget->GetPDFPage();
181 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) 342 CPDF_Document* pDocument = pPage->m_pDocument;
182 { 343 FX_DWORD dwPermissions = pDocument->GetUserPermissions();
183 return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point); 344 return (dwPermissions & FPDFPERM_FILL_FORM) ||
184 } 345 (dwPermissions & FPDFPERM_ANNOT_FORM);
346 }
347
348 CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot,
349 CPDFSDK_PageView* pPage) {
350 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
351 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm();
352 CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(
353 pInterForm->GetInterForm(), pAnnot->GetAnnotDict());
354 if (!pCtrl)
355 return nullptr;
356
357 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);
358 pInterForm->AddMap(pCtrl, pWidget);
359 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
360 if (pPDFInterForm && pPDFInterForm->NeedConstructAP())
361 pWidget->ResetAppearance(nullptr, FALSE);
362
363 return pWidget;
364 }
365
366 void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) {
367 ASSERT(pAnnot != NULL);
368
369 if (m_pFormFiller)
370 m_pFormFiller->OnDelete(pAnnot);
371
372 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
373 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
374 ASSERT(pInterForm != NULL);
375
376 CPDF_FormControl* pCtrol = pWidget->GetFormControl();
377 pInterForm->RemoveMap(pCtrol);
378
379 delete pWidget;
380 }
381
382 void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView,
383 CPDFSDK_Annot* pAnnot,
384 CFX_RenderDevice* pDevice,
385 CPDF_Matrix* pUser2Device,
386 FX_DWORD dwFlags) {
387 ASSERT(pAnnot != NULL);
388 CFX_ByteString sSubType = pAnnot->GetSubType();
389
390 if (sSubType == BFFT_SIGNATURE) {
391 pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
392 } else {
393 if (m_pFormFiller) {
394 m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags);
395 }
396 }
397 }
398
399 void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
400 CPDFSDK_Annot* pAnnot,
401 FX_DWORD nFlag) {
402 ASSERT(pAnnot != NULL);
403 CFX_ByteString sSubType = pAnnot->GetSubType();
404
405 if (sSubType == BFFT_SIGNATURE) {
406 } else {
407 if (m_pFormFiller)
408 m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag);
409 }
410 }
411 void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
412 CPDFSDK_Annot* pAnnot,
413 FX_DWORD nFlag) {
414 ASSERT(pAnnot != NULL);
415 CFX_ByteString sSubType = pAnnot->GetSubType();
416
417 if (sSubType == BFFT_SIGNATURE) {
418 } else {
419 if (m_pFormFiller)
420 m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag);
421 }
422 }
423 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView,
424 CPDFSDK_Annot* pAnnot,
425 FX_DWORD nFlags,
426 const CPDF_Point& point) {
427 ASSERT(pAnnot != NULL);
428 CFX_ByteString sSubType = pAnnot->GetSubType();
429
430 if (sSubType == BFFT_SIGNATURE) {
431 } else {
432 if (m_pFormFiller)
433 return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point);
434 }
435
436 return FALSE;
437 }
438
439 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView,
440 CPDFSDK_Annot* pAnnot,
441 FX_DWORD nFlags,
442 const CPDF_Point& point) {
443 ASSERT(pAnnot != NULL);
444 CFX_ByteString sSubType = pAnnot->GetSubType();
445
446 if (sSubType == BFFT_SIGNATURE) {
447 } else {
448 if (m_pFormFiller)
449 return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
450 }
451
452 return FALSE;
453 }
454
455 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView,
456 CPDFSDK_Annot* pAnnot,
457 FX_DWORD nFlags,
458 const CPDF_Point& point) {
459 ASSERT(pAnnot != NULL);
460 CFX_ByteString sSubType = pAnnot->GetSubType();
461
462 if (sSubType == BFFT_SIGNATURE) {
463 } else {
464 if (m_pFormFiller)
465 return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point);
466 }
467
468 return FALSE;
469 }
470
471 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView,
472 CPDFSDK_Annot* pAnnot,
473 FX_DWORD nFlags,
474 const CPDF_Point& point) {
475 ASSERT(pAnnot != NULL);
476 CFX_ByteString sSubType = pAnnot->GetSubType();
477
478 if (sSubType == BFFT_SIGNATURE) {
479 } else {
480 if (m_pFormFiller)
481 return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
482 }
483
484 return FALSE;
485 }
486
487 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView,
488 CPDFSDK_Annot* pAnnot,
489 FX_DWORD nFlags,
490 short zDelta,
491 const CPDF_Point& point) {
492 ASSERT(pAnnot != NULL);
493 CFX_ByteString sSubType = pAnnot->GetSubType();
494
495 if (sSubType == BFFT_SIGNATURE) {
496 } else {
497 if (m_pFormFiller)
498 return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta,
499 point);
500 }
501
502 return FALSE;
503 }
504
505 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView,
506 CPDFSDK_Annot* pAnnot,
507 FX_DWORD nFlags,
508 const CPDF_Point& point) {
509 ASSERT(pAnnot != NULL);
510 CFX_ByteString sSubType = pAnnot->GetSubType();
511
512 if (sSubType == BFFT_SIGNATURE) {
513 } else {
514 if (m_pFormFiller)
515 return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point);
516 }
517
518 return FALSE;
519 }
520 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView,
521 CPDFSDK_Annot* pAnnot,
522 FX_DWORD nFlags,
523 const CPDF_Point& point) {
524 ASSERT(pAnnot != NULL);
525 CFX_ByteString sSubType = pAnnot->GetSubType();
526
527 if (sSubType == BFFT_SIGNATURE) {
528 } else {
529 if (m_pFormFiller)
530 return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
531 }
532
533 return FALSE;
534 }
535
536 FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot,
537 FX_DWORD nChar,
538 FX_DWORD nFlags) {
539 ASSERT(pAnnot != NULL);
540 CFX_ByteString sSubType = pAnnot->GetSubType();
541
542 if (sSubType == BFFT_SIGNATURE) {
543 } else {
544 if (m_pFormFiller)
545 return m_pFormFiller->OnChar(pAnnot, nChar, nFlags);
546 }
547
548 return FALSE;
549 }
550
551 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot,
552 int nKeyCode,
553 int nFlag) {
554 ASSERT(pAnnot != NULL);
555 CFX_ByteString sSubType = pAnnot->GetSubType();
556
557 if (sSubType == BFFT_SIGNATURE) {
558 } else {
559 if (m_pFormFiller)
560 return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag);
561 }
562
563 return FALSE;
564 }
565
566 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot,
567 int nKeyCode,
568 int nFlag) {
569 return FALSE;
570 }
571 void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) {
572 ASSERT(pAnnot != NULL);
573 CFX_ByteString sSubType = pAnnot->GetSubType();
574
575 if (sSubType == BFFT_SIGNATURE) {
576 } else {
577 if (m_pFormFiller)
578 m_pFormFiller->OnCreate(pAnnot);
579 }
580 }
581
582 void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) {
583 ASSERT(pAnnot != NULL);
584
585 CFX_ByteString sSubType = pAnnot->GetSubType();
586
587 if (sSubType == BFFT_SIGNATURE) {
588 } else {
589 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
590 if (!pWidget->IsAppearanceValid())
591 pWidget->ResetAppearance(NULL, FALSE);
592
593 int nFieldType = pWidget->GetFieldType();
594 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) {
595 FX_BOOL bFormated = FALSE;
596 CFX_WideString sValue = pWidget->OnFormat(bFormated);
597 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) {
598 pWidget->ResetAppearance(sValue.c_str(), FALSE);
599 }
600 }
601
602 if (m_pFormFiller)
603 m_pFormFiller->OnLoad(pAnnot);
604 }
605 }
606
607 FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot,
608 FX_DWORD nFlag) {
609 ASSERT(pAnnot != NULL);
610 CFX_ByteString sSubType = pAnnot->GetSubType();
611
612 if (sSubType == BFFT_SIGNATURE) {
613 } else {
614 if (m_pFormFiller)
615 return m_pFormFiller->OnSetFocus(pAnnot, nFlag);
616 }
617
618 return TRUE;
619 }
620 FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot,
621 FX_DWORD nFlag) {
622 ASSERT(pAnnot != NULL);
623 CFX_ByteString sSubType = pAnnot->GetSubType();
624
625 if (sSubType == BFFT_SIGNATURE) {
626 } else {
627 if (m_pFormFiller)
628 return m_pFormFiller->OnKillFocus(pAnnot, nFlag);
629 }
630
631 return TRUE;
632 }
633
634 CPDF_Rect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
635 CPDFSDK_Annot* pAnnot) {
636 ASSERT(pAnnot != NULL);
637 CFX_ByteString sSubType = pAnnot->GetSubType();
638
639 if (sSubType == BFFT_SIGNATURE) {
640 } else {
641 if (m_pFormFiller)
642 return m_pFormFiller->GetViewBBox(pPageView, pAnnot);
643 }
644
645 return CPDF_Rect(0, 0, 0, 0);
646 }
647
648 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
649 CPDFSDK_Annot* pAnnot,
650 const CPDF_Point& point) {
651 ASSERT(pPageView);
652 ASSERT(pAnnot);
653
654 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot);
655 return rect.Contains(point.x, point.y);
656 }
657
658 // CReader_AnnotIteratorEx
659
660 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView,
661 FX_BOOL bReverse,
662 FX_BOOL bIgnoreTopmost /*=FALSE*/,
663 FX_BOOL bCircle /*=FALSE*/,
664 CFX_PtrArray* pList /*=NULL*/) {
665 ASSERT(pPageView);
666 m_bReverse = bReverse;
667 m_bIgnoreTopmost = bIgnoreTopmost;
668 m_bCircle = bCircle;
669 m_pIteratorAnnotList.RemoveAll();
670 InitIteratorAnnotList(pPageView, pList);
671 }
672
673 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot(const CPDFSDK_Annot* pCurrent) {
674 int index = -1;
675 int nCount = m_pIteratorAnnotList.GetSize();
676 if (pCurrent) {
677 for (int i = 0; i < nCount; i++) {
678 CPDFSDK_Annot* pReaderAnnot =
679 (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
680 if (pReaderAnnot == pCurrent) {
681 index = i;
682 break;
683 }
684 }
685 }
686 return NextAnnot(index);
687 }
688 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot(const CPDFSDK_Annot* pCurrent) {
689 int index = -1;
690 int nCount = m_pIteratorAnnotList.GetSize();
691 if (pCurrent) {
692 for (int i = 0; i < nCount; i++) {
693 CPDFSDK_Annot* pReaderAnnot =
694 (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
695 if (pReaderAnnot == pCurrent) {
696 index = i;
697 break;
698 }
699 }
700 }
701 return PrevAnnot(index);
702 }
703 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot(int& index) {
704 int nCount = m_pIteratorAnnotList.GetSize();
705 if (nCount <= 0)
706 index = -1;
707 else {
708 if (index < 0) {
709 index = 0;
710 } else {
711 if (m_bCircle) {
712 index = (index < nCount - 1) ? (index + 1) : 0;
713 } else {
714 index = (index < nCount - 1) ? (index + 1) : -1;
715 }
716 }
717 }
718 return (index < 0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);
719 }
720
721 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot(int& index) {
722 int nCount = m_pIteratorAnnotList.GetSize();
723 if (nCount <= 0)
724 index = -1;
725 else {
726 if (index < 0) {
727 index = nCount - 1;
728 } else {
729 if (m_bCircle) {
730 index = (index > 0) ? (index - 1) : nCount - 1;
731 } else {
732 index = (index > 0) ? (index - 1) : -1;
733 }
734 }
735 }
736 return (index < 0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);
737 }
738
739 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next(const CPDFSDK_Annot* pCurrent) {
740 return (m_bReverse) ? PrevAnnot(pCurrent) : NextAnnot(pCurrent);
741 }
742
743 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(const CPDFSDK_Annot* pCurrent) {
744 return (m_bReverse) ? NextAnnot(pCurrent) : PrevAnnot(pCurrent);
745 }
746
747 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next(int& index) {
748 return (m_bReverse) ? PrevAnnot(index) : NextAnnot(index);
749 }
750
751 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(int& index) {
752 return (m_bReverse) ? NextAnnot(index) : PrevAnnot(index);
753 }
754
755 void CPDFSDK_AnnotIterator::InsertSort(CFX_PtrArray& arrayList,
756 AI_COMPARE pCompare) {
757 for (int i = 1; i < arrayList.GetSize(); i++) {
758 if (pCompare((CPDFSDK_Annot*)(arrayList[i]),
759 (CPDFSDK_Annot*)(arrayList[i - 1])) < 0) {
760 int j = i - 1;
761 CPDFSDK_Annot* pTemp = (CPDFSDK_Annot*)arrayList[i];
762
763 do {
764 arrayList[j + 1] = arrayList[j];
765 } while (--j >= 0 && pCompare(pTemp, (CPDFSDK_Annot*)arrayList[j]) < 0);
766
767 arrayList[j + 1] = pTemp;
768 }
769 }
770 }
771
772 int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
773 if (p1->GetLayoutOrder() < p2->GetLayoutOrder())
774 return -1;
775 if (p1->GetLayoutOrder() > p2->GetLayoutOrder())
776 return 1;
777 return 0;
778 }
779
780 FX_BOOL CPDFSDK_AnnotIterator::InitIteratorAnnotList(
781 CPDFSDK_PageView* pPageView,
782 CFX_PtrArray* pAnnotList) {
783 ASSERT(pPageView);
784
785 if (pAnnotList == NULL) {
786 pAnnotList = pPageView->GetAnnotList();
787 }
788
789 m_pIteratorAnnotList.RemoveAll();
790 if (!pAnnotList)
185 return FALSE; 791 return FALSE;
186 } 792
187 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(CPDFSDK_PageView * pPageView , CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point) 793 CPDFSDK_Annot* pTopMostAnnot =
188 { 794 (m_bIgnoreTopmost) ? NULL : pPageView->GetFocusAnnot();
189 ASSERT(pAnnot != NULL); 795
190 796 int nCount = pAnnotList->GetSize();
191 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) 797
192 { 798 for (int i = nCount - 1; i >= 0; i--) {
193 return pAnnotHandler->OnMouseWheel(pPageView, pAnnot,nFlags,zDelta, poin t); 799 CPDFSDK_Annot* pReaderAnnot = (CPDFSDK_Annot*)pAnnotList->GetAt(i);
194 } 800 m_pIteratorAnnotList.Add(pReaderAnnot);
195 return FALSE; 801 }
196 } 802
197 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown(CPDFSDK_PageView * pPageVie w, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) 803 InsertSort(m_pIteratorAnnotList, &LyOrderCompare);
198 { 804
199 ASSERT(pAnnot != NULL); 805 if (pTopMostAnnot) {
200 806 for (int i = 0; i < nCount; i++) {
201 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) 807 CPDFSDK_Annot* pReaderAnnot =
202 { 808 (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
203 return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point); 809 if (pReaderAnnot == pTopMostAnnot) {
204 } 810 m_pIteratorAnnotList.RemoveAt(i);
205 return FALSE; 811 m_pIteratorAnnotList.InsertAt(0, pReaderAnnot);
206 } 812 break;
207 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(CPDFSDK_PageView * pPageView, CPDFSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point) 813 }
208 { 814 }
209 ASSERT(pAnnot != NULL); 815 }
210 816
211 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) 817 return TRUE;
212 { 818 }
213 return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point);
214 }
215 return FALSE;
216 }
217
218 void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView * pPageView, C PDFSDK_Annot* pAnnot, FX_DWORD nFlag)
219 {
220 ASSERT(pAnnot != NULL);
221
222 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
223 {
224 pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag);
225 }
226 return ;
227 }
228
229 void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(CPDFSDK_PageView * pPageView, CP DFSDK_Annot* pAnnot, FX_DWORD nFlag)
230 {
231 ASSERT(pAnnot != NULL);
232
233 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
234 {
235 pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag);
236 }
237 return;
238 }
239
240 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nC har, FX_DWORD nFlags)
241 {
242
243 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
244 {
245 return pAnnotHandler->OnChar(pAnnot,nChar, nFlags);
246 }
247 return FALSE;
248
249 }
250
251 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
252 {
253
254 if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag))
255 {
256 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
257 CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot();
258 if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab))
259 {
260 CPDFSDK_Annot* pNext = GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIF TKeyDown(nFlag));
261
262 if(pNext && pNext != pFocusAnnot)
263 {
264 CPDFSDK_Document* pDocument = pPage->GetSDKDocument();
265 pDocument->SetFocusAnnot(pNext);
266 return TRUE;
267 }
268 }
269 }
270
271 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
272 {
273 return pAnnotHandler->OnKeyDown(pAnnot,nKeyCode, nFlag);
274 }
275 return FALSE;
276 }
277 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot, in t nKeyCode, int nFlag)
278 {
279 return FALSE;
280 }
281
282 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag)
283 {
284 ASSERT(pAnnot != NULL);
285
286 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
287 {
288 if (pAnnotHandler->OnSetFocus(pAnnot, nFlag))
289 {
290 CPDFSDK_PageView* pPage = pAnnot->GetPageView();
291 pPage->GetSDKDocument();
292 return TRUE;
293 }
294 }
295 return FALSE;
296 }
297
298 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot , FX_DWORD nFlag)
299 {
300 ASSERT(pAnnot);
301 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
302 return pAnnotHandler->OnKillFocus(pAnnot, nFlag);
303
304 return FALSE;
305 }
306
307 CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox(CPDFSDK_PageView *pPage View, CPDFSDK_Annot* pAnnot)
308 {
309 ASSERT(pAnnot);
310 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
311 return pAnnotHandler->GetViewBBox(pPageView, pAnnot);
312
313 return pAnnot->GetRect();
314 }
315
316 FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView *pPageView, CP DFSDK_Annot* pAnnot, const CPDF_Point& point)
317 {
318 ASSERT(pAnnot);
319 if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot))
320 {
321 if (pAnnotHandler->CanAnswer(pAnnot))
322 return pAnnotHandler->HitTest(pPageView, pAnnot, point);
323 }
324 return FALSE;
325 }
326
327 CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot,F X_BOOL bNext)
328 {
329 CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", "");
330 return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot);
331 }
332
333 FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot)
334 {
335 ASSERT(pAnnot->GetType() == "Widget");
336 if (pAnnot->GetSubType() == BFFT_SIGNATURE)
337 return FALSE;
338
339 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
340 if (!pWidget->IsVisible())
341 return FALSE;
342
343 int nFieldFlags = pWidget->GetFieldFlags();
344 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
345 return FALSE;
346
347 if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON)
348 return TRUE;
349
350 CPDF_Page* pPage = pWidget->GetPDFPage();
351 CPDF_Document* pDocument = pPage->m_pDocument;
352 FX_DWORD dwPermissions = pDocument->GetUserPermissions();
353 return (dwPermissions & FPDFPERM_FILL_FORM) ||
354 (dwPermissions & FPDFPERM_ANNOT_FORM);
355 }
356
357 CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, CPDFSDK_Page View* pPage)
358 {
359 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument();
360 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm();
361 CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl(pInterForm->GetInte rForm(), pAnnot->GetAnnotDict());
362 if (!pCtrl)
363 return nullptr;
364
365 CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm);
366 pInterForm->AddMap(pCtrl, pWidget);
367 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
368 if (pPDFInterForm && pPDFInterForm->NeedConstructAP())
369 pWidget->ResetAppearance(nullptr, FALSE);
370
371 return pWidget;
372 }
373
374 void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot)
375 {
376 ASSERT(pAnnot != NULL);
377
378 if (m_pFormFiller)
379 m_pFormFiller->OnDelete(pAnnot);
380
381 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
382 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm();
383 ASSERT(pInterForm != NULL);
384
385 CPDF_FormControl* pCtrol = pWidget->GetFormControl();
386 pInterForm->RemoveMap(pCtrol);
387
388
389 delete pWidget;
390 }
391
392
393 void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, FX_DWORD dwFlags)
394 {
395 ASSERT(pAnnot != NULL);
396 CFX_ByteString sSubType = pAnnot->GetSubType();
397
398 if (sSubType == BFFT_SIGNATURE)
399 {
400 pAnnot->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL);
401 }
402 else
403 {
404 if (m_pFormFiller)
405 {
406 m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFl ags);
407 }
408 }
409 }
410
411 void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_A nnot* pAnnot, FX_DWORD nFlag)
412 {
413 ASSERT(pAnnot != NULL);
414 CFX_ByteString sSubType = pAnnot->GetSubType();
415
416 if (sSubType == BFFT_SIGNATURE)
417 {
418 }
419 else
420 {
421 if (m_pFormFiller)
422 m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag);
423 }
424
425
426 }
427 void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_An not* pAnnot, FX_DWORD nFlag)
428 {
429 ASSERT(pAnnot != NULL);
430 CFX_ByteString sSubType = pAnnot->GetSubType();
431
432 if (sSubType == BFFT_SIGNATURE)
433 {
434 }
435 else
436 {
437 if (m_pFormFiller)
438 m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag);
439 }
440
441 }
442 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFS DK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
443 {
444 ASSERT(pAnnot != NULL);
445 CFX_ByteString sSubType = pAnnot->GetSubType();
446
447 if (sSubType == BFFT_SIGNATURE)
448 {
449 }
450 else
451 {
452 if (m_pFormFiller)
453 return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point );
454 }
455
456 return FALSE;
457 }
458
459 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK _Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
460 {
461 ASSERT(pAnnot != NULL);
462 CFX_ByteString sSubType = pAnnot->GetSubType();
463
464 if (sSubType == BFFT_SIGNATURE)
465 {
466 }
467 else
468 {
469 if (m_pFormFiller)
470 return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point);
471 }
472
473 return FALSE;
474 }
475
476 FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPD FSDK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
477 {
478 ASSERT(pAnnot != NULL);
479 CFX_ByteString sSubType = pAnnot->GetSubType();
480
481 if (sSubType == BFFT_SIGNATURE)
482 {
483 }
484 else
485 {
486 if (m_pFormFiller)
487 return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, poi nt);
488 }
489
490 return FALSE;
491 }
492
493 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK _Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
494 {
495 ASSERT(pAnnot != NULL);
496 CFX_ByteString sSubType = pAnnot->GetSubType();
497
498 if (sSubType == BFFT_SIGNATURE)
499 {
500 }
501 else
502 {
503 if (m_pFormFiller)
504 return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point);
505 }
506
507 return FALSE;
508
509 }
510
511
512 FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSD K_Annot* pAnnot, FX_DWORD nFlags, short zDelta, const CPDF_Point& point)
513 {
514 ASSERT(pAnnot != NULL);
515 CFX_ByteString sSubType = pAnnot->GetSubType();
516
517 if (sSubType == BFFT_SIGNATURE)
518 {
519 }
520 else
521 {
522 if (m_pFormFiller)
523 return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta ,point);
524 }
525
526 return FALSE;
527 }
528
529 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFS DK_Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
530 {
531 ASSERT(pAnnot != NULL);
532 CFX_ByteString sSubType = pAnnot->GetSubType();
533
534 if (sSubType == BFFT_SIGNATURE)
535 {
536 }
537 else
538 {
539 if (m_pFormFiller)
540 return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point );
541 }
542
543 return FALSE;
544 }
545 FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK _Annot* pAnnot, FX_DWORD nFlags, const CPDF_Point& point)
546 {
547 ASSERT(pAnnot != NULL);
548 CFX_ByteString sSubType = pAnnot->GetSubType();
549
550 if (sSubType == BFFT_SIGNATURE)
551 {
552 }
553 else
554 {
555 if (m_pFormFiller)
556 return m_pFormFiller->OnRButtonUp(pPageView, pAnnot, nFlags, point);
557 }
558
559 return FALSE;
560 }
561
562 FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, FX_DWORD nChar, FX _DWORD nFlags)
563 {
564 ASSERT(pAnnot != NULL);
565 CFX_ByteString sSubType = pAnnot->GetSubType();
566
567 if (sSubType == BFFT_SIGNATURE)
568 {
569 }
570 else
571 {
572 if (m_pFormFiller)
573 return m_pFormFiller->OnChar(pAnnot,nChar, nFlags);
574 }
575
576 return FALSE;
577 }
578
579 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, int nKeyCode, i nt nFlag)
580 {
581 ASSERT(pAnnot != NULL);
582 CFX_ByteString sSubType = pAnnot->GetSubType();
583
584 if (sSubType == BFFT_SIGNATURE)
585 {
586 }
587 else
588 {
589 if (m_pFormFiller)
590 return m_pFormFiller->OnKeyDown(pAnnot,nKeyCode, nFlag);
591 }
592
593 return FALSE;
594 }
595
596 FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, int nKeyCode, int nFlag)
597 {
598
599 return FALSE;
600 }
601 void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot)
602 {
603 ASSERT(pAnnot != NULL);
604 CFX_ByteString sSubType = pAnnot->GetSubType();
605
606 if (sSubType == BFFT_SIGNATURE)
607 {
608 }
609 else
610 {
611 if (m_pFormFiller)
612 m_pFormFiller->OnCreate(pAnnot);
613 }
614 }
615
616 void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot)
617 {
618 ASSERT(pAnnot != NULL);
619
620 CFX_ByteString sSubType = pAnnot->GetSubType();
621
622 if (sSubType == BFFT_SIGNATURE)
623 {
624 }
625 else
626 {
627 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
628 if (!pWidget->IsAppearanceValid())
629 pWidget->ResetAppearance(NULL, FALSE);
630
631 int nFieldType = pWidget->GetFieldType();
632 if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBO X)
633 {
634 FX_BOOL bFormated = FALSE;
635 CFX_WideString sValue = pWidget->OnFormat(bFormated);
636 if (bFormated && nFieldType == FIELDTYPE_COMBOBOX)
637 {
638 pWidget->ResetAppearance(sValue.c_str(), FALSE);
639 }
640 }
641
642 if (m_pFormFiller)
643 m_pFormFiller->OnLoad(pAnnot);
644 }
645 }
646
647 FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFlag )
648 {
649 ASSERT(pAnnot != NULL);
650 CFX_ByteString sSubType = pAnnot->GetSubType();
651
652 if (sSubType == BFFT_SIGNATURE)
653 {
654 }
655 else
656 {
657 if (m_pFormFiller)
658 return m_pFormFiller->OnSetFocus(pAnnot,nFlag);
659 }
660
661 return TRUE;
662 }
663 FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_DWORD nFla g)
664 {
665 ASSERT(pAnnot != NULL);
666 CFX_ByteString sSubType = pAnnot->GetSubType();
667
668 if (sSubType == BFFT_SIGNATURE)
669 {
670 }
671 else
672 {
673 if (m_pFormFiller)
674 return m_pFormFiller->OnKillFocus(pAnnot,nFlag);
675 }
676
677 return TRUE;
678 }
679
680 CPDF_Rect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView *pPageView, CPDFS DK_Annot* pAnnot)
681 {
682 ASSERT(pAnnot != NULL);
683 CFX_ByteString sSubType = pAnnot->GetSubType();
684
685 if (sSubType == BFFT_SIGNATURE)
686 {
687 }
688 else
689 {
690 if (m_pFormFiller)
691 return m_pFormFiller->GetViewBBox(pPageView, pAnnot);
692
693 }
694
695 return CPDF_Rect(0,0,0,0);
696 }
697
698 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView *pPageView, CPDFSDK_Ann ot* pAnnot, const CPDF_Point& point)
699 {
700 ASSERT(pPageView);
701 ASSERT(pAnnot);
702
703 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot);
704 return rect.Contains(point.x, point.y);
705 }
706
707 //CReader_AnnotIteratorEx
708
709 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView * pPageView,FX_BOO L bReverse,
710 FX_BOOL bIgnoreTopmost/*=FALSE* /,
711 FX_BOOL bCircle/*=FALSE*/,
712 CFX_PtrArray *pList/*=NULL*/)
713 {
714 ASSERT(pPageView);
715 m_bReverse=bReverse;
716 m_bIgnoreTopmost= bIgnoreTopmost;
717 m_bCircle=bCircle;
718 m_pIteratorAnnotList.RemoveAll();
719 InitIteratorAnnotList(pPageView,pList);
720 }
721
722 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot (const CPDFSDK_Annot* pCurrent)
723 {
724
725 int index = -1;
726 int nCount = m_pIteratorAnnotList.GetSize();
727 if (pCurrent) {
728 for(int i=0;i<nCount;i++){
729 CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot *)m_pIteratorAnnotList. GetAt(i);
730 if(pReaderAnnot ==pCurrent){
731 index=i;
732 break;
733 }
734 }
735 }
736 return NextAnnot(index);
737 }
738 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot (const CPDFSDK_Annot*pCurrent)
739 {
740 int index = -1;
741 int nCount = m_pIteratorAnnotList.GetSize();
742 if(pCurrent){
743 for(int i=0;i<nCount;i++){
744 CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot*)m_pIteratorAnnotList.G etAt(i);
745 if(pReaderAnnot ==pCurrent){
746 index=i;
747 break;
748 }
749 }
750 }
751 return PrevAnnot(index);
752 }
753 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot (int& index)
754 {
755
756 int nCount=m_pIteratorAnnotList.GetSize();
757 if(nCount<=0) index=-1;
758 else{
759 if(index<0){
760 index=0;
761 }
762 else{
763 if(m_bCircle){
764 index=( index <nCount-1) ? (index+1) :0;
765 }
766 else{
767 index=( index <nCount-1) ? (index+1) :-1;
768 }
769
770 }
771 }
772 return (index <0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index) ;
773 }
774
775
776 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot (int& index)
777 {
778
779 int nCount=m_pIteratorAnnotList.GetSize();
780 if(nCount<=0) index=-1;
781 else{
782 if(index<0){
783 index=nCount-1;
784 }
785 else{
786 if(m_bCircle){
787 index = ( index >0) ? (index-1) :nCount-1;
788 }
789 else{
790 index = ( index >0) ? (index-1) :-1;
791 }
792 }
793 }
794 return (index <0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index) ;
795 }
796
797
798 CPDFSDK_Annot*CPDFSDK_AnnotIterator::Next(const CPDFSDK_Annot* pCurrent)
799 {
800
801 return (m_bReverse) ? PrevAnnot(pCurrent):NextAnnot(pCurrent);
802
803 }
804
805 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(const CPDFSDK_Annot* pCurrent)
806 {
807
808 return (m_bReverse) ? NextAnnot(pCurrent):PrevAnnot(pCurrent);
809 }
810
811 CPDFSDK_Annot*CPDFSDK_AnnotIterator::Next(int& index )
812 {
813
814 return (m_bReverse) ? PrevAnnot(index):NextAnnot(index);
815
816 }
817
818 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(int& index )
819 {
820
821 return (m_bReverse) ? NextAnnot(index):PrevAnnot(index);
822 }
823
824
825 void CPDFSDK_AnnotIterator::InsertSort(CFX_PtrArray &arrayList, AI_COMPARE pComp are)
826 {
827 for (int i = 1; i < arrayList.GetSize(); i++)
828 {
829 if (pCompare((CPDFSDK_Annot*)(arrayList[i]) , (CPDFSDK_Annot*)(arrayList [i-1])) < 0)
830 {
831 int j = i-1;
832 CPDFSDK_Annot* pTemp = (CPDFSDK_Annot*)arrayList[i];
833
834 do
835 {
836 arrayList[j + 1] = arrayList[j];
837 } while (--j >= 0 && pCompare(pTemp, (CPDFSDK_Annot*)arrayList[j]) < 0);
838
839 arrayList[j+1] = pTemp;
840 }
841 }
842 }
843
844 int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)
845 {
846 if (p1->GetLayoutOrder() < p2->GetLayoutOrder())
847 return -1;
848 if (p1->GetLayoutOrder() > p2->GetLayoutOrder())
849 return 1;
850 return 0;
851 }
852
853 FX_BOOL CPDFSDK_AnnotIterator::InitIteratorAnnotList(CPDFSDK_PageView* pPageView ,CFX_PtrArray * pAnnotList)
854 {
855 ASSERT(pPageView);
856
857 if(pAnnotList==NULL){
858 pAnnotList=pPageView->GetAnnotList();
859 }
860
861 m_pIteratorAnnotList.RemoveAll();
862 if(!pAnnotList) return FALSE;
863
864 CPDFSDK_Annot * pTopMostAnnot= (m_bIgnoreTopmost) ? NULL : pPageView->GetFoc usAnnot();
865
866
867 int nCount =pAnnotList->GetSize();
868
869 for(int i = nCount- 1 ;i >= 0;i--)
870 {
871 CPDFSDK_Annot * pReaderAnnot= (CPDFSDK_Annot*)pAnnotList->GetAt(i);
872 m_pIteratorAnnotList.Add(pReaderAnnot);
873 }
874
875 InsertSort(m_pIteratorAnnotList,&LyOrderCompare);
876
877 if(pTopMostAnnot)
878 {
879 for(int i=0 ;i<nCount;i++)
880 {
881 CPDFSDK_Annot * pReaderAnnot = (CPDFSDK_Annot*)m_pIteratorAnnotList. GetAt(i);
882 if(pReaderAnnot == pTopMostAnnot)
883 {
884 m_pIteratorAnnotList.RemoveAt(i);
885 m_pIteratorAnnotList.InsertAt(0, pReaderAnnot);
886 break;
887 }
888 }
889 }
890
891 return TRUE;
892 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698