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 "public/fpdf_formfill.h" | 7 #include "public/fpdf_formfill.h" |
8 | 8 |
| 9 #ifdef PDF_ENABLE_XFA |
| 10 #include "../include/fpdfxfa/fpdfxfa_app.h" |
| 11 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 12 #include "../include/fpdfxfa/fpdfxfa_page.h" |
| 13 #endif |
9 #include "fpdfsdk/include/fsdk_define.h" | 14 #include "fpdfsdk/include/fsdk_define.h" |
10 #include "fpdfsdk/include/fsdk_mgr.h" | 15 #include "fpdfsdk/include/fsdk_mgr.h" |
11 #include "public/fpdfview.h" | 16 #include "public/fpdfview.h" |
12 #include "third_party/base/nonstd_unique_ptr.h" | 17 #include "third_party/base/nonstd_unique_ptr.h" |
13 | 18 |
14 namespace { | 19 namespace { |
15 | 20 |
16 CPDFSDK_Document* FormHandleToSDKDoc(FPDF_FORMHANDLE hHandle) { | 21 CPDFSDK_Document* FormHandleToSDKDoc(FPDF_FORMHANDLE hHandle) { |
17 CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; | 22 CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; |
18 return pEnv ? pEnv->GetSDKDocument() : nullptr; | 23 return pEnv ? pEnv->GetSDKDocument() : nullptr; |
(...skipping 16 matching lines...) Expand all Loading... |
35 | 40 |
36 } // namespace | 41 } // namespace |
37 | 42 |
38 DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, | 43 DLLEXPORT int STDCALL FPDFPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
39 FPDF_PAGE page, | 44 FPDF_PAGE page, |
40 double page_x, | 45 double page_x, |
41 double page_y) { | 46 double page_y) { |
42 if (!hHandle) | 47 if (!hHandle) |
43 return -1; | 48 return -1; |
44 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 49 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
| 50 #ifndef PDF_ENABLE_XFA |
45 if (!pPage) | 51 if (!pPage) |
46 return -1; | 52 return -1; |
47 CPDF_InterForm interform(pPage->m_pDocument, FALSE); | 53 CPDF_InterForm interform(pPage->m_pDocument, FALSE); |
48 CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint( | 54 CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint( |
49 pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, nullptr); | 55 pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, nullptr); |
50 if (!pFormCtrl) | 56 if (!pFormCtrl) |
51 return -1; | 57 return -1; |
| 58 #else |
| 59 if (pPage) { |
| 60 CPDF_InterForm interform(pPage->m_pDocument, FALSE); |
| 61 CPDF_FormControl* pFormCtrl = interform.GetControlAtPoint( |
| 62 pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, nullptr); |
| 63 if (!pFormCtrl) |
| 64 return -1; |
52 | 65 |
| 66 CPDF_FormField* pFormField = pFormCtrl->GetField(); |
| 67 if (!pFormField) |
| 68 return -1; |
| 69 |
| 70 int nType = pFormField->GetFieldType(); |
| 71 return nType; |
| 72 } |
| 73 |
| 74 IXFA_PageView* pPageView = ((CPDFXFA_Page*)page)->GetXFAPageView(); |
| 75 if (pPageView) { |
| 76 IXFA_WidgetHandler* pWidgetHandler = NULL; |
| 77 IXFA_DocView* pDocView = pPageView->GetDocView(); |
| 78 if (!pDocView) |
| 79 return -1; |
| 80 |
| 81 pWidgetHandler = pDocView->GetWidgetHandler(); |
| 82 if (!pWidgetHandler) |
| 83 return -1; |
| 84 |
| 85 IXFA_Widget* pXFAAnnot = NULL; |
| 86 IXFA_WidgetIterator* pWidgetIterator = pPageView->CreateWidgetIterator( |
| 87 XFA_TRAVERSEWAY_Form, |
| 88 XFA_WIDGETFILTER_Viewable | XFA_WIDGETFILTER_AllType); |
| 89 if (!pWidgetIterator) |
| 90 return -1; |
| 91 pXFAAnnot = pWidgetIterator->MoveToNext(); |
| 92 while (pXFAAnnot) { |
| 93 CFX_RectF rcBBox; |
| 94 pWidgetHandler->GetBBox(pXFAAnnot, rcBBox, 0); |
| 95 CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, |
| 96 rcBBox.left + rcBBox.width, |
| 97 rcBBox.top + rcBBox.height); |
| 98 rcWidget.left -= 1.0f; |
| 99 rcWidget.right += 1.0f; |
| 100 rcWidget.bottom -= 1.0f; |
| 101 rcWidget.top += 1.0f; |
| 102 |
| 103 if (rcWidget.Contains(static_cast<FX_FLOAT>(page_x), |
| 104 static_cast<FX_FLOAT>(page_y))) { |
| 105 pWidgetIterator->Release(); |
| 106 return FPDF_FORMFIELD_XFA; |
| 107 } |
| 108 pXFAAnnot = pWidgetIterator->MoveToNext(); |
| 109 } |
| 110 |
| 111 pWidgetIterator->Release(); |
| 112 } |
| 113 #endif |
| 114 |
| 115 #ifndef PDF_ENABLE_XFA |
53 CPDF_FormField* pFormField = pFormCtrl->GetField(); | 116 CPDF_FormField* pFormField = pFormCtrl->GetField(); |
54 return pFormField ? pFormField->GetFieldType() : -1; | 117 return pFormField ? pFormField->GetFieldType() : -1; |
| 118 #else |
| 119 return -1; |
| 120 #endif |
55 } | 121 } |
56 | 122 |
57 DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, | 123 DLLEXPORT int STDCALL FPDPage_HasFormFieldAtPoint(FPDF_FORMHANDLE hHandle, |
58 FPDF_PAGE page, | 124 FPDF_PAGE page, |
59 double page_x, | 125 double page_x, |
60 double page_y) { | 126 double page_y) { |
61 return FPDFPage_HasFormFieldAtPoint(hHandle, page, page_x, page_y); | 127 return FPDFPage_HasFormFieldAtPoint(hHandle, page, page_x, page_y); |
62 } | 128 } |
63 | 129 |
64 DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle, | 130 DLLEXPORT int STDCALL FPDFPage_FormFieldZOrderAtPoint(FPDF_FORMHANDLE hHandle, |
65 FPDF_PAGE page, | 131 FPDF_PAGE page, |
66 double page_x, | 132 double page_x, |
67 double page_y) { | 133 double page_y) { |
68 if (!hHandle) | 134 if (!hHandle) |
69 return -1; | 135 return -1; |
70 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); | 136 CPDF_Page* pPage = CPDFPageFromFPDFPage(page); |
71 if (!pPage) | 137 if (!pPage) |
72 return -1; | 138 return -1; |
73 CPDF_InterForm interform(pPage->m_pDocument, FALSE); | 139 CPDF_InterForm interform(pPage->m_pDocument, FALSE); |
74 int z_order = -1; | 140 int z_order = -1; |
75 (void)interform.GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, | 141 (void)interform.GetControlAtPoint(pPage, (FX_FLOAT)page_x, (FX_FLOAT)page_y, |
76 &z_order); | 142 &z_order); |
77 return z_order; | 143 return z_order; |
78 } | 144 } |
79 | 145 |
80 DLLEXPORT FPDF_FORMHANDLE STDCALL | 146 DLLEXPORT FPDF_FORMHANDLE STDCALL |
81 FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, | 147 FPDFDOC_InitFormFillEnvironment(FPDF_DOCUMENT document, |
82 FPDF_FORMFILLINFO* formInfo) { | 148 FPDF_FORMFILLINFO* formInfo) { |
| 149 #ifndef PDF_ENABLE_XFA |
83 const int kRequiredVersion = 1; | 150 const int kRequiredVersion = 1; |
| 151 #else |
| 152 const int kRequiredVersion = 2; |
| 153 #endif |
84 if (!formInfo || formInfo->version != kRequiredVersion) | 154 if (!formInfo || formInfo->version != kRequiredVersion) |
85 return nullptr; | 155 return nullptr; |
86 | 156 |
87 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document); | 157 UnderlyingDocumentType* pDocument = UnderlyingFromFPDFDocument(document); |
88 if (!pDocument) | 158 if (!pDocument) |
89 return nullptr; | 159 return nullptr; |
90 | 160 |
91 CPDFDoc_Environment* pEnv = new CPDFDoc_Environment(pDocument, formInfo); | 161 CPDFDoc_Environment* pEnv = new CPDFDoc_Environment(pDocument, formInfo); |
| 162 #ifndef PDF_ENABLE_XFA |
92 pEnv->SetSDKDocument(new CPDFSDK_Document(pDocument, pEnv)); | 163 pEnv->SetSDKDocument(new CPDFSDK_Document(pDocument, pEnv)); |
| 164 #else |
| 165 pEnv->SetSDKDocument(pDocument->GetSDKDocument(pEnv)); |
| 166 |
| 167 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); |
| 168 pApp->AddFormFillEnv(pEnv); |
| 169 #endif |
93 return pEnv; | 170 return pEnv; |
94 } | 171 } |
95 | 172 |
96 DLLEXPORT void STDCALL | 173 DLLEXPORT void STDCALL |
97 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { | 174 FPDFDOC_ExitFormFillEnvironment(FPDF_FORMHANDLE hHandle) { |
98 if (!hHandle) | 175 if (!hHandle) |
99 return; | 176 return; |
| 177 #ifndef PDF_ENABLE_XFA |
100 | 178 |
101 CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; | 179 CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; |
102 if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) { | 180 if (CPDFSDK_Document* pSDKDoc = pEnv->GetSDKDocument()) { |
103 pEnv->SetSDKDocument(NULL); | 181 pEnv->SetSDKDocument(NULL); |
104 delete pSDKDoc; | 182 delete pSDKDoc; |
105 } | 183 } |
106 delete pEnv; | 184 delete pEnv; |
| 185 #else |
| 186 CPDFXFA_App* pApp = CPDFXFA_App::GetInstance(); |
| 187 pApp->RemoveFormFillEnv((CPDFDoc_Environment*)hHandle); |
| 188 delete (CPDFDoc_Environment*)hHandle; |
| 189 #endif |
107 } | 190 } |
108 | 191 |
109 DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, | 192 DLLEXPORT FPDF_BOOL STDCALL FORM_OnMouseMove(FPDF_FORMHANDLE hHandle, |
110 FPDF_PAGE page, | 193 FPDF_PAGE page, |
111 int modifier, | 194 int modifier, |
112 double page_x, | 195 double page_x, |
113 double page_y) { | 196 double page_y) { |
114 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); | 197 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
115 if (!pPageView) | 198 if (!pPageView) |
116 return FALSE; | 199 return FALSE; |
(...skipping 21 matching lines...) Expand all Loading... |
138 double page_x, | 221 double page_x, |
139 double page_y) { | 222 double page_y) { |
140 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); | 223 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
141 if (!pPageView) | 224 if (!pPageView) |
142 return FALSE; | 225 return FALSE; |
143 | 226 |
144 CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); | 227 CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); |
145 return pPageView->OnLButtonUp(pt, modifier); | 228 return pPageView->OnLButtonUp(pt, modifier); |
146 } | 229 } |
147 | 230 |
| 231 #ifdef PDF_ENABLE_XFA |
| 232 DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonDown(FPDF_FORMHANDLE hHandle, |
| 233 FPDF_PAGE page, |
| 234 int modifier, |
| 235 double page_x, |
| 236 double page_y) { |
| 237 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 238 if (!pPageView) |
| 239 return FALSE; |
| 240 |
| 241 CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); |
| 242 return pPageView->OnRButtonDown(pt, modifier); |
| 243 } |
| 244 |
| 245 DLLEXPORT FPDF_BOOL STDCALL FORM_OnRButtonUp(FPDF_FORMHANDLE hHandle, |
| 246 FPDF_PAGE page, |
| 247 int modifier, |
| 248 double page_x, |
| 249 double page_y) { |
| 250 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
| 251 if (!pPageView) |
| 252 return FALSE; |
| 253 |
| 254 CPDF_Point pt((FX_FLOAT)page_x, (FX_FLOAT)page_y); |
| 255 return pPageView->OnRButtonUp(pt, modifier); |
| 256 } |
| 257 |
| 258 #endif |
148 DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, | 259 DLLEXPORT FPDF_BOOL STDCALL FORM_OnKeyDown(FPDF_FORMHANDLE hHandle, |
149 FPDF_PAGE page, | 260 FPDF_PAGE page, |
150 int nKeyCode, | 261 int nKeyCode, |
151 int modifier) { | 262 int modifier) { |
152 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); | 263 CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, page); |
153 if (!pPageView) | 264 if (!pPageView) |
154 return FALSE; | 265 return FALSE; |
155 | 266 |
156 return pPageView->OnKeyDown(nKeyCode, modifier); | 267 return pPageView->OnKeyDown(nKeyCode, modifier); |
157 } | 268 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 int size_y, | 306 int size_y, |
196 int rotate, | 307 int rotate, |
197 int flags) { | 308 int flags) { |
198 if (!hHandle) | 309 if (!hHandle) |
199 return; | 310 return; |
200 | 311 |
201 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); | 312 UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); |
202 if (!pPage) | 313 if (!pPage) |
203 return; | 314 return; |
204 | 315 |
| 316 #ifndef PDF_ENABLE_XFA |
205 CPDF_RenderOptions options; | 317 CPDF_RenderOptions options; |
206 if (flags & FPDF_LCD_TEXT) | 318 if (flags & FPDF_LCD_TEXT) |
207 options.m_Flags |= RENDER_CLEARTYPE; | 319 options.m_Flags |= RENDER_CLEARTYPE; |
208 else | 320 else |
209 options.m_Flags &= ~RENDER_CLEARTYPE; | 321 options.m_Flags &= ~RENDER_CLEARTYPE; |
| 322 #else |
| 323 CPDFXFA_Document* pDocument = pPage->GetDocument(); |
| 324 if (!pDocument) |
| 325 return; |
| 326 #endif |
210 | 327 |
| 328 #ifndef PDF_ENABLE_XFA |
211 // Grayscale output | 329 // Grayscale output |
212 if (flags & FPDF_GRAYSCALE) { | 330 if (flags & FPDF_GRAYSCALE) { |
213 options.m_ColorMode = RENDER_COLOR_GRAY; | 331 options.m_ColorMode = RENDER_COLOR_GRAY; |
214 options.m_ForeColor = 0; | 332 options.m_ForeColor = 0; |
215 options.m_BackColor = 0xffffff; | 333 options.m_BackColor = 0xffffff; |
216 } | 334 } |
| 335 #else |
| 336 CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); |
| 337 if (!pPDFDoc) |
| 338 return; |
| 339 #endif |
217 | 340 |
| 341 #ifndef PDF_ENABLE_XFA |
218 options.m_AddFlags = flags >> 8; | 342 options.m_AddFlags = flags >> 8; |
219 options.m_pOCContext = new CPDF_OCContext(pPage->m_pDocument); | 343 options.m_pOCContext = new CPDF_OCContext(pPage->m_pDocument); |
| 344 #else |
| 345 CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; |
| 346 CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument(); |
| 347 if (!pFXDoc) |
| 348 return; |
| 349 #endif |
220 | 350 |
221 CFX_AffineMatrix matrix; | 351 CFX_AffineMatrix matrix; |
222 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); | 352 pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); |
223 | 353 |
224 FX_RECT clip; | 354 FX_RECT clip; |
225 clip.left = start_x; | 355 clip.left = start_x; |
226 clip.right = start_x + size_x; | 356 clip.right = start_x + size_x; |
227 clip.top = start_y; | 357 clip.top = start_y; |
228 clip.bottom = start_y + size_y; | 358 clip.bottom = start_y + size_y; |
229 | 359 |
230 #ifdef _SKIA_SUPPORT_ | 360 #ifdef _SKIA_SUPPORT_ |
231 nonstd::unique_ptr<CFX_SkiaDevice> pDevice(new CFX_SkiaDevice); | 361 nonstd::unique_ptr<CFX_SkiaDevice> pDevice(new CFX_SkiaDevice); |
232 #else | 362 #else |
233 nonstd::unique_ptr<CFX_FxgeDevice> pDevice(new CFX_FxgeDevice); | 363 nonstd::unique_ptr<CFX_FxgeDevice> pDevice(new CFX_FxgeDevice); |
234 #endif | 364 #endif |
| 365 #ifdef PDF_ENABLE_XFA |
| 366 |
| 367 if (!pDevice) |
| 368 return; |
| 369 #endif |
235 pDevice->Attach((CFX_DIBitmap*)bitmap); | 370 pDevice->Attach((CFX_DIBitmap*)bitmap); |
236 pDevice->SaveState(); | 371 pDevice->SaveState(); |
237 pDevice->SetClip_Rect(&clip); | 372 pDevice->SetClip_Rect(&clip); |
238 | 373 |
| 374 #ifndef PDF_ENABLE_XFA |
239 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage)) | 375 if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage)) |
240 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options); | 376 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options); |
| 377 #else |
| 378 CPDF_RenderOptions options; |
| 379 if (flags & FPDF_LCD_TEXT) |
| 380 options.m_Flags |= RENDER_CLEARTYPE; |
| 381 else |
| 382 options.m_Flags &= ~RENDER_CLEARTYPE; |
| 383 |
| 384 // Grayscale output |
| 385 if (flags & FPDF_GRAYSCALE) { |
| 386 options.m_ColorMode = RENDER_COLOR_GRAY; |
| 387 options.m_ForeColor = 0; |
| 388 options.m_BackColor = 0xffffff; |
| 389 } |
| 390 options.m_AddFlags = flags >> 8; |
| 391 options.m_pOCContext = new CPDF_OCContext(pPDFDoc); |
| 392 |
| 393 if (CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage)) |
| 394 pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip); |
| 395 #endif |
241 | 396 |
242 pDevice->RestoreState(); | 397 pDevice->RestoreState(); |
243 delete options.m_pOCContext; | 398 delete options.m_pOCContext; |
| 399 #ifdef PDF_ENABLE_XFA |
| 400 options.m_pOCContext = NULL; |
| 401 } |
| 402 DLLEXPORT void STDCALL FPDF_Widget_Undo(FPDF_DOCUMENT document, |
| 403 FPDF_WIDGET hWidget) { |
| 404 if (NULL == hWidget || NULL == document) |
| 405 return; |
| 406 |
| 407 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 408 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 409 pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 410 return; |
| 411 |
| 412 IXFA_MenuHandler* pXFAMenuHander = |
| 413 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 414 if (pXFAMenuHander == NULL) |
| 415 return; |
| 416 |
| 417 pXFAMenuHander->Undo((IXFA_Widget*)hWidget); |
| 418 } |
| 419 DLLEXPORT void STDCALL FPDF_Widget_Redo(FPDF_DOCUMENT document, |
| 420 FPDF_WIDGET hWidget) { |
| 421 if (NULL == hWidget || NULL == document) |
| 422 return; |
| 423 |
| 424 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 425 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 426 pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 427 return; |
| 428 |
| 429 IXFA_MenuHandler* pXFAMenuHander = |
| 430 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 431 if (pXFAMenuHander == NULL) |
| 432 return; |
| 433 |
| 434 pXFAMenuHander->Redo((IXFA_Widget*)hWidget); |
| 435 } |
| 436 |
| 437 DLLEXPORT void STDCALL FPDF_Widget_SelectAll(FPDF_DOCUMENT document, |
| 438 FPDF_WIDGET hWidget) { |
| 439 if (NULL == hWidget || NULL == document) |
| 440 return; |
| 441 |
| 442 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 443 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 444 pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 445 return; |
| 446 |
| 447 IXFA_MenuHandler* pXFAMenuHander = |
| 448 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 449 if (pXFAMenuHander == NULL) |
| 450 return; |
| 451 |
| 452 pXFAMenuHander->SelectAll((IXFA_Widget*)hWidget); |
| 453 } |
| 454 DLLEXPORT void STDCALL FPDF_Widget_Copy(FPDF_DOCUMENT document, |
| 455 FPDF_WIDGET hWidget, |
| 456 FPDF_WIDESTRING wsText, |
| 457 FPDF_DWORD* size) { |
| 458 if (NULL == hWidget || NULL == document) |
| 459 return; |
| 460 |
| 461 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 462 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 463 pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 464 return; |
| 465 |
| 466 IXFA_MenuHandler* pXFAMenuHander = |
| 467 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 468 if (pXFAMenuHander == NULL) |
| 469 return; |
| 470 |
| 471 CFX_WideString wsCpText; |
| 472 pXFAMenuHander->Copy((IXFA_Widget*)hWidget, wsCpText); |
| 473 |
| 474 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode(); |
| 475 int len = bsCpText.GetLength() / sizeof(unsigned short); |
| 476 if (wsText == NULL) { |
| 477 *size = len; |
| 478 return; |
| 479 } |
| 480 |
| 481 int real_size = len < *size ? len : *size; |
| 482 if (real_size > 0) { |
| 483 FXSYS_memcpy((void*)wsText, |
| 484 bsCpText.GetBuffer(real_size * sizeof(unsigned short)), |
| 485 real_size * sizeof(unsigned short)); |
| 486 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short)); |
| 487 } |
| 488 *size = real_size; |
| 489 } |
| 490 DLLEXPORT void STDCALL FPDF_Widget_Cut(FPDF_DOCUMENT document, |
| 491 FPDF_WIDGET hWidget, |
| 492 FPDF_WIDESTRING wsText, |
| 493 FPDF_DWORD* size) { |
| 494 if (NULL == hWidget || NULL == document) |
| 495 return; |
| 496 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 497 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 498 pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 499 return; |
| 500 |
| 501 IXFA_MenuHandler* pXFAMenuHander = |
| 502 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 503 if (pXFAMenuHander == NULL) |
| 504 return; |
| 505 |
| 506 CFX_WideString wsCpText; |
| 507 pXFAMenuHander->Cut((IXFA_Widget*)hWidget, wsCpText); |
| 508 |
| 509 CFX_ByteString bsCpText = wsCpText.UTF16LE_Encode(); |
| 510 int len = bsCpText.GetLength() / sizeof(unsigned short); |
| 511 if (wsText == NULL) { |
| 512 *size = len; |
| 513 return; |
| 514 } |
| 515 |
| 516 int real_size = len < *size ? len : *size; |
| 517 if (real_size > 0) { |
| 518 FXSYS_memcpy((void*)wsText, |
| 519 bsCpText.GetBuffer(real_size * sizeof(unsigned short)), |
| 520 real_size * sizeof(unsigned short)); |
| 521 bsCpText.ReleaseBuffer(real_size * sizeof(unsigned short)); |
| 522 } |
| 523 *size = real_size; |
| 524 } |
| 525 DLLEXPORT void STDCALL FPDF_Widget_Paste(FPDF_DOCUMENT document, |
| 526 FPDF_WIDGET hWidget, |
| 527 FPDF_WIDESTRING wsText, |
| 528 FPDF_DWORD size) { |
| 529 if (NULL == hWidget || NULL == document) |
| 530 return; |
| 531 |
| 532 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 533 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 534 pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 535 return; |
| 536 |
| 537 IXFA_MenuHandler* pXFAMenuHander = |
| 538 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 539 if (pXFAMenuHander == NULL) |
| 540 return; |
| 541 |
| 542 CFX_WideString wstr = CFX_WideString::FromUTF16LE(wsText, size); |
| 543 pXFAMenuHander->Paste((IXFA_Widget*)hWidget, wstr); |
| 544 } |
| 545 DLLEXPORT void STDCALL |
| 546 FPDF_Widget_ReplaceSpellCheckWord(FPDF_DOCUMENT document, |
| 547 FPDF_WIDGET hWidget, |
| 548 float x, |
| 549 float y, |
| 550 FPDF_BYTESTRING bsText) { |
| 551 if (NULL == hWidget || NULL == document) |
| 552 return; |
| 553 |
| 554 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 555 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 556 pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 557 return; |
| 558 |
| 559 IXFA_MenuHandler* pXFAMenuHander = |
| 560 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 561 if (pXFAMenuHander == NULL) |
| 562 return; |
| 563 |
| 564 CFX_PointF ptPopup; |
| 565 ptPopup.x = x; |
| 566 ptPopup.y = y; |
| 567 CFX_ByteStringC bs(bsText); |
| 568 pXFAMenuHander->ReplaceSpellCheckWord((IXFA_Widget*)hWidget, ptPopup, bs); |
| 569 } |
| 570 DLLEXPORT void STDCALL |
| 571 FPDF_Widget_GetSpellCheckWords(FPDF_DOCUMENT document, |
| 572 FPDF_WIDGET hWidget, |
| 573 float x, |
| 574 float y, |
| 575 FPDF_STRINGHANDLE* stringHandle) { |
| 576 if (NULL == hWidget || NULL == document) |
| 577 return; |
| 578 |
| 579 CPDFXFA_Document* pDocument = (CPDFXFA_Document*)document; |
| 580 if (pDocument->GetDocType() != XFA_DOCTYPE_Dynamic && |
| 581 pDocument->GetDocType() != XFA_DOCTYPE_Static) |
| 582 return; |
| 583 |
| 584 IXFA_MenuHandler* pXFAMenuHander = |
| 585 CPDFXFA_App::GetInstance()->GetXFAApp()->GetMenuHandler(); |
| 586 if (pXFAMenuHander == NULL) |
| 587 return; |
| 588 |
| 589 CFX_ByteStringArray* sSuggestWords = new CFX_ByteStringArray; |
| 590 CFX_PointF ptPopup; |
| 591 ptPopup.x = x; |
| 592 ptPopup.y = y; |
| 593 pXFAMenuHander->GetSuggestWords((IXFA_Widget*)hWidget, ptPopup, |
| 594 *sSuggestWords); |
| 595 *stringHandle = (FPDF_STRINGHANDLE)sSuggestWords; |
| 596 } |
| 597 DLLEXPORT int STDCALL FPDF_StringHandleCounts(FPDF_STRINGHANDLE stringHandle) { |
| 598 if (stringHandle == NULL) |
| 599 return -1; |
| 600 CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle; |
| 601 return sSuggestWords->GetSize(); |
| 602 } |
| 603 DLLEXPORT FPDF_BOOL STDCALL |
| 604 FPDF_StringHandleGetStringByIndex(FPDF_STRINGHANDLE stringHandle, |
| 605 int index, |
| 606 FPDF_BYTESTRING bsText, |
| 607 FPDF_DWORD* size) { |
| 608 if (stringHandle == NULL || size == NULL) |
| 609 return FALSE; |
| 610 int count = FPDF_StringHandleCounts(stringHandle); |
| 611 if (index < 0 || index >= count) |
| 612 return FALSE; |
| 613 |
| 614 CFX_ByteStringArray sSuggestWords = *(CFX_ByteStringArray*)stringHandle; |
| 615 int len = sSuggestWords[index].GetLength(); |
| 616 |
| 617 if (bsText == NULL) { |
| 618 *size = len; |
| 619 return TRUE; |
| 620 } |
| 621 |
| 622 int real_size = len < *size ? len : *size; |
| 623 if (real_size > 0) |
| 624 FXSYS_memcpy((void*)bsText, (const FX_CHAR*)(sSuggestWords[index]), |
| 625 real_size); |
| 626 *size = real_size; |
| 627 |
| 628 return TRUE; |
| 629 } |
| 630 DLLEXPORT void STDCALL |
| 631 FPDF_StringHandleRelease(FPDF_STRINGHANDLE stringHandle) { |
| 632 if (stringHandle == NULL) |
| 633 return; |
| 634 CFX_ByteStringArray* sSuggestWords = (CFX_ByteStringArray*)stringHandle; |
| 635 delete sSuggestWords; |
| 636 } |
| 637 |
| 638 DLLEXPORT FPDF_BOOL STDCALL |
| 639 FPDF_StringHandleAddString(FPDF_STRINGHANDLE stringHandle, |
| 640 FPDF_BYTESTRING bsText, |
| 641 FPDF_DWORD size) { |
| 642 if (stringHandle == NULL || bsText == NULL || size <= 0) |
| 643 return FALSE; |
| 644 |
| 645 CFX_ByteStringArray* stringArr = (CFX_ByteStringArray*)stringHandle; |
| 646 CFX_ByteString bsStr(bsText, size); |
| 647 |
| 648 stringArr->Add(bsStr); |
| 649 return TRUE; |
| 650 #endif |
244 } | 651 } |
245 | 652 |
246 DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, | 653 DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightColor(FPDF_FORMHANDLE hHandle, |
247 int fieldType, | 654 int fieldType, |
248 unsigned long color) { | 655 unsigned long color) { |
249 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) | 656 if (CPDFSDK_InterForm* pInterForm = FormHandleToInterForm(hHandle)) |
250 pInterForm->SetHighlightColor(color, fieldType); | 657 pInterForm->SetHighlightColor(color, fieldType); |
251 } | 658 } |
252 | 659 |
253 DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, | 660 DLLEXPORT void STDCALL FPDF_SetFormFieldHighlightAlpha(FPDF_FORMHANDLE hHandle, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); | 750 pActionHandler->DoAction_Page(action, CPDF_AAction::OpenPage, pSDKDoc); |
344 } | 751 } |
345 } else { | 752 } else { |
346 if (aa.ActionExist(CPDF_AAction::ClosePage)) { | 753 if (aa.ActionExist(CPDF_AAction::ClosePage)) { |
347 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); | 754 CPDF_Action action = aa.GetAction(CPDF_AAction::ClosePage); |
348 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); | 755 pActionHandler->DoAction_Page(action, CPDF_AAction::ClosePage, pSDKDoc); |
349 } | 756 } |
350 } | 757 } |
351 } | 758 } |
352 } | 759 } |
OLD | NEW |