John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | |
Lei Zhang | bde53d2 | 2015-11-12 22:21:30 -0800 | [diff] [blame] | 9 | #include "fpdfsdk/include/formfiller/FFL_FormFiller.h" |
| 10 | #include "fpdfsdk/include/fsdk_annothandler.h" |
| 11 | #include "fpdfsdk/include/fsdk_define.h" |
| 12 | #include "fpdfsdk/include/fsdk_mgr.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 13 | |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 14 | #ifdef PDF_ENABLE_XFA |
| 15 | #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 16 | #include "../include/fpdfxfa/fpdfxfa_util.h" |
| 17 | #endif // PDF_ENABLE_XFA |
| 18 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 19 | CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) { |
| 20 | m_pApp = pApp; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 21 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 22 | CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); |
| 23 | pHandler->SetFormFiller(m_pApp->GetIFormFiller()); |
| 24 | RegisterAnnotHandler(pHandler); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 25 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 26 | CPDFSDK_XFAAnnotHandler* pXFAAnnotHandler = |
| 27 | new CPDFSDK_XFAAnnotHandler(m_pApp); |
| 28 | RegisterAnnotHandler(pXFAAnnotHandler); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 29 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 32 | CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { |
| 33 | for (int i = 0; i < m_Handlers.GetSize(); i++) { |
| 34 | IPDFSDK_AnnotHandler* pHandler = m_Handlers.GetAt(i); |
| 35 | delete pHandler; |
| 36 | } |
| 37 | m_Handlers.RemoveAll(); |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 38 | m_mapType2Handler.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void CPDFSDK_AnnotHandlerMgr::RegisterAnnotHandler( |
| 42 | IPDFSDK_AnnotHandler* pAnnotHandler) { |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 43 | ASSERT(!GetAnnotHandler(pAnnotHandler->GetType())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 44 | |
| 45 | m_Handlers.Add(pAnnotHandler); |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 46 | m_mapType2Handler[pAnnotHandler->GetType()] = pAnnotHandler; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void CPDFSDK_AnnotHandlerMgr::UnRegisterAnnotHandler( |
| 50 | IPDFSDK_AnnotHandler* pAnnotHandler) { |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 51 | m_mapType2Handler.erase(pAnnotHandler->GetType()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | for (int i = 0, sz = m_Handlers.GetSize(); i < sz; i++) { |
| 53 | if (m_Handlers.GetAt(i) == pAnnotHandler) { |
| 54 | m_Handlers.RemoveAt(i); |
| 55 | break; |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 56 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 57 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 60 | CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(CPDF_Annot* pAnnot, |
| 61 | CPDFSDK_PageView* pPageView) { |
| 62 | ASSERT(pAnnot != NULL); |
| 63 | ASSERT(pPageView != NULL); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 64 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 65 | if (IPDFSDK_AnnotHandler* pAnnotHandler = |
| 66 | GetAnnotHandler(pAnnot->GetSubType())) { |
| 67 | return pAnnotHandler->NewAnnot(pAnnot, pPageView); |
| 68 | } |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 69 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | return new CPDFSDK_BAAnnot(pAnnot, pPageView); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 73 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 74 | CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::NewAnnot(IXFA_Widget* pAnnot, |
| 75 | CPDFSDK_PageView* pPageView) { |
| 76 | ASSERT(pAnnot != NULL); |
| 77 | ASSERT(pPageView != NULL); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 78 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 79 | if (IPDFSDK_AnnotHandler* pAnnotHandler = |
| 80 | GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)) { |
| 81 | return pAnnotHandler->NewAnnot(pAnnot, pPageView); |
| 82 | } |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 83 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 85 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 86 | #endif // PDF_ENABLE_XFA |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 87 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 88 | void CPDFSDK_AnnotHandlerMgr::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { |
| 89 | ASSERT(pAnnot != NULL); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 90 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 91 | pAnnot->GetPDFPage(); |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 92 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 93 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 94 | pAnnotHandler->OnRelease(pAnnot); |
| 95 | pAnnotHandler->ReleaseAnnot(pAnnot); |
| 96 | } else { |
| 97 | delete (CPDFSDK_Annot*)pAnnot; |
| 98 | } |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 101 | void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) { |
| 102 | ASSERT(pAnnot != NULL); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 103 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 104 | CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 105 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 106 | CPDFSDK_DateTime curTime; |
| 107 | pPDFAnnot->GetAnnotDict()->SetAtString("M", curTime.ToPDFDateTimeString()); |
| 108 | pPDFAnnot->GetAnnotDict()->SetAtNumber("F", 0); |
| 109 | |
| 110 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 111 | pAnnotHandler->OnCreate(pAnnot); |
| 112 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 115 | void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) { |
| 116 | ASSERT(pAnnot != NULL); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 117 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 118 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 119 | pAnnotHandler->OnLoad(pAnnot); |
| 120 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 123 | IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( |
| 124 | CPDFSDK_Annot* pAnnot) const { |
| 125 | ASSERT(pAnnot != NULL); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 126 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 127 | CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot(); |
| 128 | if (pPDFAnnot) |
| 129 | return GetAnnotHandler(pPDFAnnot->GetSubType()); |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 130 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | c7e4c4f | 2015-11-20 09:45:24 -0800 | [diff] [blame] | 131 | if (pAnnot->GetXFAWidget()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 132 | return GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 133 | #endif // PDF_ENABLE_XFA |
Tom Sepez | c7e4c4f | 2015-11-20 09:45:24 -0800 | [diff] [blame] | 134 | return nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 137 | IPDFSDK_AnnotHandler* CPDFSDK_AnnotHandlerMgr::GetAnnotHandler( |
| 138 | const CFX_ByteString& sType) const { |
Tom Sepez | 09d33bc | 2015-08-19 09:49:24 -0700 | [diff] [blame] | 139 | auto it = m_mapType2Handler.find(sType); |
| 140 | return it != m_mapType2Handler.end() ? it->second : nullptr; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 143 | void CPDFSDK_AnnotHandlerMgr::Annot_OnDraw(CPDFSDK_PageView* pPageView, |
| 144 | CPDFSDK_Annot* pAnnot, |
| 145 | CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame^] | 146 | CFX_Matrix* pUser2Device, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 147 | FX_DWORD dwFlags) { |
Dan Sinclair | bfe042a | 2015-11-04 14:04:13 -0500 | [diff] [blame] | 148 | ASSERT(pAnnot); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 149 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 150 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 151 | pAnnotHandler->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); |
| 152 | } else { |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 153 | #ifdef PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 154 | if (pAnnot->IsXFAField()) |
| 155 | return; |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 156 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 540c436 | 2015-11-24 13:33:57 -0800 | [diff] [blame] | 157 | static_cast<CPDFSDK_BAAnnot*>(pAnnot) |
| 158 | ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 159 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 162 | FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDown( |
| 163 | CPDFSDK_PageView* pPageView, |
| 164 | CPDFSDK_Annot* pAnnot, |
| 165 | FX_DWORD nFlags, |
| 166 | const CPDF_Point& point) { |
| 167 | ASSERT(pAnnot != NULL); |
| 168 | |
| 169 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 170 | return pAnnotHandler->OnLButtonDown(pPageView, pAnnot, nFlags, point); |
| 171 | } |
| 172 | return FALSE; |
| 173 | } |
| 174 | FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonUp(CPDFSDK_PageView* pPageView, |
| 175 | CPDFSDK_Annot* pAnnot, |
| 176 | FX_DWORD nFlags, |
| 177 | const CPDF_Point& point) { |
| 178 | ASSERT(pAnnot != NULL); |
| 179 | |
| 180 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 181 | return pAnnotHandler->OnLButtonUp(pPageView, pAnnot, nFlags, point); |
| 182 | } |
| 183 | return FALSE; |
| 184 | } |
| 185 | FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnLButtonDblClk( |
| 186 | CPDFSDK_PageView* pPageView, |
| 187 | CPDFSDK_Annot* pAnnot, |
| 188 | FX_DWORD nFlags, |
| 189 | const CPDF_Point& point) { |
| 190 | ASSERT(pAnnot != NULL); |
| 191 | |
| 192 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 193 | return pAnnotHandler->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); |
| 194 | } |
| 195 | return FALSE; |
| 196 | } |
| 197 | FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseMove(CPDFSDK_PageView* pPageView, |
| 198 | CPDFSDK_Annot* pAnnot, |
| 199 | FX_DWORD nFlags, |
| 200 | const CPDF_Point& point) { |
| 201 | ASSERT(pAnnot != NULL); |
| 202 | |
| 203 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 204 | return pAnnotHandler->OnMouseMove(pPageView, pAnnot, nFlags, point); |
| 205 | } |
| 206 | return FALSE; |
| 207 | } |
| 208 | FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnMouseWheel(CPDFSDK_PageView* pPageView, |
| 209 | CPDFSDK_Annot* pAnnot, |
| 210 | FX_DWORD nFlags, |
| 211 | short zDelta, |
| 212 | const CPDF_Point& point) { |
| 213 | ASSERT(pAnnot != NULL); |
| 214 | |
| 215 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 216 | return pAnnotHandler->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, |
| 217 | point); |
| 218 | } |
| 219 | return FALSE; |
| 220 | } |
| 221 | FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonDown( |
| 222 | CPDFSDK_PageView* pPageView, |
| 223 | CPDFSDK_Annot* pAnnot, |
| 224 | FX_DWORD nFlags, |
| 225 | const CPDF_Point& point) { |
| 226 | ASSERT(pAnnot != NULL); |
| 227 | |
| 228 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 229 | return pAnnotHandler->OnRButtonDown(pPageView, pAnnot, nFlags, point); |
| 230 | } |
| 231 | return FALSE; |
| 232 | } |
| 233 | FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnRButtonUp(CPDFSDK_PageView* pPageView, |
| 234 | CPDFSDK_Annot* pAnnot, |
| 235 | FX_DWORD nFlags, |
| 236 | const CPDF_Point& point) { |
| 237 | ASSERT(pAnnot != NULL); |
| 238 | |
| 239 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 240 | return pAnnotHandler->OnRButtonUp(pPageView, pAnnot, nFlags, point); |
| 241 | } |
| 242 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 245 | void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseEnter(CPDFSDK_PageView* pPageView, |
| 246 | CPDFSDK_Annot* pAnnot, |
| 247 | FX_DWORD nFlag) { |
| 248 | ASSERT(pAnnot != NULL); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 249 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 250 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 251 | pAnnotHandler->OnMouseEnter(pPageView, pAnnot, nFlag); |
| 252 | } |
| 253 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 256 | void CPDFSDK_AnnotHandlerMgr::Annot_OnMouseExit(CPDFSDK_PageView* pPageView, |
| 257 | CPDFSDK_Annot* pAnnot, |
| 258 | FX_DWORD nFlag) { |
| 259 | ASSERT(pAnnot != NULL); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 260 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 261 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 262 | pAnnotHandler->OnMouseExit(pPageView, pAnnot, nFlag); |
| 263 | } |
| 264 | return; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 267 | FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChar(CPDFSDK_Annot* pAnnot, |
| 268 | FX_DWORD nChar, |
| 269 | FX_DWORD nFlags) { |
| 270 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 271 | return pAnnotHandler->OnChar(pAnnot, nChar, nFlags); |
| 272 | } |
| 273 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 276 | FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyDown(CPDFSDK_Annot* pAnnot, |
| 277 | int nKeyCode, |
| 278 | int nFlag) { |
| 279 | if (!m_pApp->FFI_IsCTRLKeyDown(nFlag) && !m_pApp->FFI_IsALTKeyDown(nFlag)) { |
| 280 | CPDFSDK_PageView* pPage = pAnnot->GetPageView(); |
| 281 | CPDFSDK_Annot* pFocusAnnot = pPage->GetFocusAnnot(); |
| 282 | if (pFocusAnnot && (nKeyCode == FWL_VKEY_Tab)) { |
| 283 | CPDFSDK_Annot* pNext = |
| 284 | GetNextAnnot(pFocusAnnot, !m_pApp->FFI_IsSHIFTKeyDown(nFlag)); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 285 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 286 | if (pNext && pNext != pFocusAnnot) { |
| 287 | CPDFSDK_Document* pDocument = pPage->GetSDKDocument(); |
| 288 | pDocument->SetFocusAnnot(pNext); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 289 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | } |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 293 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 294 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 295 | return pAnnotHandler->OnKeyDown(pAnnot, nKeyCode, nFlag); |
| 296 | } |
| 297 | return FALSE; |
| 298 | } |
| 299 | FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKeyUp(CPDFSDK_Annot* pAnnot, |
| 300 | int nKeyCode, |
| 301 | int nFlag) { |
| 302 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 305 | FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnSetFocus(CPDFSDK_Annot* pAnnot, |
| 306 | FX_DWORD nFlag) { |
| 307 | ASSERT(pAnnot != NULL); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 308 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 309 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 310 | if (pAnnotHandler->OnSetFocus(pAnnot, nFlag)) { |
| 311 | CPDFSDK_PageView* pPage = pAnnot->GetPageView(); |
| 312 | pPage->GetSDKDocument(); |
| 313 | return TRUE; |
| 314 | } |
| 315 | } |
| 316 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 319 | FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnKillFocus(CPDFSDK_Annot* pAnnot, |
| 320 | FX_DWORD nFlag) { |
| 321 | ASSERT(pAnnot); |
| 322 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) |
| 323 | return pAnnotHandler->OnKillFocus(pAnnot, nFlag); |
| 324 | |
| 325 | return FALSE; |
| 326 | } |
| 327 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 328 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 329 | FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnChangeFocus( |
| 330 | CPDFSDK_Annot* pSetAnnot, |
| 331 | CPDFSDK_Annot* pKillAnnot) { |
| 332 | FX_BOOL bXFA = (pSetAnnot && pSetAnnot->GetXFAWidget()) || |
| 333 | (pKillAnnot && pKillAnnot->GetXFAWidget()); |
| 334 | |
| 335 | if (bXFA) { |
| 336 | if (IPDFSDK_AnnotHandler* pXFAAnnotHandler = |
| 337 | GetAnnotHandler(FSDK_XFAWIDGET_TYPENAME)) |
| 338 | return pXFAAnnotHandler->OnXFAChangedFocus(pKillAnnot, pSetAnnot); |
| 339 | } |
| 340 | |
| 341 | return TRUE; |
| 342 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 343 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 344 | |
| 345 | CPDF_Rect CPDFSDK_AnnotHandlerMgr::Annot_OnGetViewBBox( |
| 346 | CPDFSDK_PageView* pPageView, |
| 347 | CPDFSDK_Annot* pAnnot) { |
| 348 | ASSERT(pAnnot); |
| 349 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) |
| 350 | return pAnnotHandler->GetViewBBox(pPageView, pAnnot); |
| 351 | |
| 352 | return pAnnot->GetRect(); |
| 353 | } |
| 354 | |
| 355 | FX_BOOL CPDFSDK_AnnotHandlerMgr::Annot_OnHitTest(CPDFSDK_PageView* pPageView, |
| 356 | CPDFSDK_Annot* pAnnot, |
| 357 | const CPDF_Point& point) { |
| 358 | ASSERT(pAnnot); |
| 359 | if (IPDFSDK_AnnotHandler* pAnnotHandler = GetAnnotHandler(pAnnot)) { |
| 360 | if (pAnnotHandler->CanAnswer(pAnnot)) |
| 361 | return pAnnotHandler->HitTest(pPageView, pAnnot, point); |
| 362 | } |
| 363 | return FALSE; |
| 364 | } |
| 365 | |
| 366 | CPDFSDK_Annot* CPDFSDK_AnnotHandlerMgr::GetNextAnnot(CPDFSDK_Annot* pSDKAnnot, |
| 367 | FX_BOOL bNext) { |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 368 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 369 | CPDFSDK_PageView* pPageView = pSDKAnnot->GetPageView(); |
| 370 | CPDFXFA_Page* pPage = pPageView->GetPDFXFAPage(); |
| 371 | if (pPage == NULL) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 372 | return NULL; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 373 | if (pPage->GetPDFPage()) { // for pdf annots. |
| 374 | CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), pSDKAnnot->GetType(), ""); |
| 375 | CPDFSDK_Annot* pNext = |
| 376 | bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot); |
| 377 | return pNext; |
| 378 | } |
| 379 | // for xfa annots |
| 380 | IXFA_WidgetIterator* pWidgetIterator = |
| 381 | pPage->GetXFAPageView()->CreateWidgetIterator( |
| 382 | XFA_TRAVERSEWAY_Tranvalse, XFA_WIDGETFILTER_Visible | |
| 383 | XFA_WIDGETFILTER_Viewable | |
| 384 | XFA_WIDGETFILTER_Field); |
| 385 | if (pWidgetIterator == NULL) |
| 386 | return NULL; |
| 387 | if (pWidgetIterator->GetCurrentWidget() != pSDKAnnot->GetXFAWidget()) |
| 388 | pWidgetIterator->SetCurrentWidget(pSDKAnnot->GetXFAWidget()); |
| 389 | IXFA_Widget* hNextFocus = NULL; |
| 390 | hNextFocus = |
| 391 | bNext ? pWidgetIterator->MoveToNext() : pWidgetIterator->MoveToPrevious(); |
| 392 | if (hNextFocus == NULL && pSDKAnnot != NULL) |
| 393 | hNextFocus = pWidgetIterator->MoveToFirst(); |
| 394 | |
| 395 | pWidgetIterator->Release(); |
| 396 | return pPageView->GetAnnotByXFAWidget(hNextFocus); |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 397 | #else // PDF_ENABLE_XFA |
| 398 | CBA_AnnotIterator ai(pSDKAnnot->GetPageView(), "Widget", ""); |
| 399 | return bNext ? ai.GetNextAnnot(pSDKAnnot) : ai.GetPrevAnnot(pSDKAnnot); |
| 400 | #endif // PDF_ENABLE_XFA |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 403 | FX_BOOL CPDFSDK_BFAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { |
| 404 | ASSERT(pAnnot->GetType() == "Widget"); |
| 405 | if (pAnnot->GetSubType() == BFFT_SIGNATURE) |
| 406 | return FALSE; |
| 407 | |
| 408 | CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; |
| 409 | if (!pWidget->IsVisible()) |
| 410 | return FALSE; |
| 411 | |
| 412 | int nFieldFlags = pWidget->GetFieldFlags(); |
| 413 | if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY) |
| 414 | return FALSE; |
| 415 | |
| 416 | if (pWidget->GetFieldType() == FIELDTYPE_PUSHBUTTON) |
| 417 | return TRUE; |
| 418 | |
| 419 | CPDF_Page* pPage = pWidget->GetPDFPage(); |
| 420 | CPDF_Document* pDocument = pPage->m_pDocument; |
| 421 | FX_DWORD dwPermissions = pDocument->GetUserPermissions(); |
| 422 | return (dwPermissions & FPDFPERM_FILL_FORM) || |
| 423 | (dwPermissions & FPDFPERM_ANNOT_FORM); |
| 424 | } |
| 425 | |
| 426 | CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(CPDF_Annot* pAnnot, |
| 427 | CPDFSDK_PageView* pPage) { |
| 428 | CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument(); |
| 429 | CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm(); |
| 430 | CPDF_FormControl* pCtrl = CPDFSDK_Widget::GetFormControl( |
| 431 | pInterForm->GetInterForm(), pAnnot->GetAnnotDict()); |
| 432 | if (!pCtrl) |
| 433 | return nullptr; |
| 434 | |
| 435 | CPDFSDK_Widget* pWidget = new CPDFSDK_Widget(pAnnot, pPage, pInterForm); |
| 436 | pInterForm->AddMap(pCtrl, pWidget); |
| 437 | CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
| 438 | if (pPDFInterForm && pPDFInterForm->NeedConstructAP()) |
| 439 | pWidget->ResetAppearance(nullptr, FALSE); |
| 440 | |
| 441 | return pWidget; |
| 442 | } |
| 443 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 444 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 445 | CPDFSDK_Annot* CPDFSDK_BFAnnotHandler::NewAnnot(IXFA_Widget* hWidget, |
| 446 | CPDFSDK_PageView* pPage) { |
| 447 | return NULL; |
| 448 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 449 | #endif // PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 450 | |
| 451 | void CPDFSDK_BFAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { |
| 452 | ASSERT(pAnnot != NULL); |
| 453 | |
| 454 | if (m_pFormFiller) |
| 455 | m_pFormFiller->OnDelete(pAnnot); |
| 456 | |
| 457 | CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; |
| 458 | CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); |
| 459 | ASSERT(pInterForm != NULL); |
| 460 | |
| 461 | CPDF_FormControl* pCtrol = pWidget->GetFormControl(); |
| 462 | pInterForm->RemoveMap(pCtrol); |
| 463 | |
| 464 | delete pWidget; |
| 465 | } |
| 466 | |
| 467 | void CPDFSDK_BFAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView, |
| 468 | CPDFSDK_Annot* pAnnot, |
| 469 | CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame^] | 470 | CFX_Matrix* pUser2Device, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 471 | FX_DWORD dwFlags) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 472 | CFX_ByteString sSubType = pAnnot->GetSubType(); |
| 473 | |
| 474 | if (sSubType == BFFT_SIGNATURE) { |
Dan Sinclair | bfe042a | 2015-11-04 14:04:13 -0500 | [diff] [blame] | 475 | static_cast<CPDFSDK_BAAnnot*>(pAnnot) |
| 476 | ->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 477 | } else { |
| 478 | if (m_pFormFiller) { |
| 479 | m_pFormFiller->OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); |
| 480 | } |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | void CPDFSDK_BFAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, |
| 485 | CPDFSDK_Annot* pAnnot, |
| 486 | FX_DWORD nFlag) { |
| 487 | ASSERT(pAnnot != NULL); |
| 488 | CFX_ByteString sSubType = pAnnot->GetSubType(); |
| 489 | |
| 490 | if (sSubType == BFFT_SIGNATURE) { |
| 491 | } else { |
| 492 | if (m_pFormFiller) |
| 493 | m_pFormFiller->OnMouseEnter(pPageView, pAnnot, nFlag); |
| 494 | } |
| 495 | } |
| 496 | void CPDFSDK_BFAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView, |
| 497 | CPDFSDK_Annot* pAnnot, |
| 498 | FX_DWORD nFlag) { |
| 499 | ASSERT(pAnnot != NULL); |
| 500 | CFX_ByteString sSubType = pAnnot->GetSubType(); |
| 501 | |
| 502 | if (sSubType == BFFT_SIGNATURE) { |
| 503 | } else { |
| 504 | if (m_pFormFiller) |
| 505 | m_pFormFiller->OnMouseExit(pPageView, pAnnot, nFlag); |
| 506 | } |
| 507 | } |
| 508 | FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, |
| 509 | CPDFSDK_Annot* pAnnot, |
| 510 | FX_DWORD nFlags, |
| 511 | const CPDF_Point& point) { |
| 512 | ASSERT(pAnnot != NULL); |
| 513 | CFX_ByteString sSubType = pAnnot->GetSubType(); |
| 514 | |
| 515 | if (sSubType == BFFT_SIGNATURE) { |
| 516 | } else { |
| 517 | if (m_pFormFiller) |
| 518 | return m_pFormFiller->OnLButtonDown(pPageView, pAnnot, nFlags, point); |
| 519 | } |
| 520 | |
| 521 | return FALSE; |
| 522 | } |
| 523 | |
| 524 | FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, |
| 525 | CPDFSDK_Annot* pAnnot, |
| 526 | FX_DWORD nFlags, |
| 527 | const CPDF_Point& point) { |
| 528 | ASSERT(pAnnot != NULL); |
| 529 | CFX_ByteString sSubType = pAnnot->GetSubType(); |
| 530 | |
| 531 | if (sSubType == BFFT_SIGNATURE) { |
| 532 | } else { |
| 533 | if (m_pFormFiller) |
| 534 | return m_pFormFiller->OnLButtonUp(pPageView, pAnnot, nFlags, point); |
| 535 | } |
| 536 | |
| 537 | return FALSE; |
| 538 | } |
| 539 | |
| 540 | FX_BOOL CPDFSDK_BFAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView, |
| 541 | CPDFSDK_Annot* pAnnot, |
| 542 | FX_DWORD nFlags, |
| 543 | const CPDF_Point& point) { |
| 544 | ASSERT(pAnnot != NULL); |
| 545 | CFX_ByteString sSubType = pAnnot->GetSubType(); |
| 546 | |
| 547 | if (sSubType == BFFT_SIGNATURE) { |
| 548 | } else { |
| 549 | if (m_pFormFiller) |
| 550 | return m_pFormFiller->OnLButtonDblClk(pPageView, pAnnot, nFlags, point); |
| 551 | } |
| 552 | |
| 553 | return FALSE; |
| 554 | } |
| 555 | |
| 556 | FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView, |
| 557 | CPDFSDK_Annot* pAnnot, |
| 558 | FX_DWORD nFlags, |
| 559 | const CPDF_Point& point) { |
| 560 | ASSERT(pAnnot != NULL); |
| 561 | CFX_ByteString sSubType = pAnnot->GetSubType(); |
| 562 | |
| 563 | if (sSubType == BFFT_SIGNATURE) { |
| 564 | } else { |
| 565 | if (m_pFormFiller) |
| 566 | return m_pFormFiller->OnMouseMove(pPageView, pAnnot, nFlags, point); |
| 567 | } |
| 568 | |
| 569 | return FALSE; |
| 570 | } |
| 571 | |
| 572 | FX_BOOL CPDFSDK_BFAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, |
| 573 | CPDFSDK_Annot* pAnnot, |
| 574 | FX_DWORD nFlags, |
| 575 | short zDelta, |
| 576 | const CPDF_Point& point) { |
| 577 | ASSERT(pAnnot != NULL); |
| 578 | CFX_ByteString sSubType = pAnnot->GetSubType(); |
| 579 | |
| 580 | if (sSubType == BFFT_SIGNATURE) { |
| 581 | } else { |
| 582 | if (m_pFormFiller) |
| 583 | return m_pFormFiller->OnMouseWheel(pPageView, pAnnot, nFlags, zDelta, |
| 584 | point); |
| 585 | } |
| 586 | |
| 587 | return FALSE; |
| 588 | } |
| 589 | |
| 590 | FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, |
| 591 | CPDFSDK_Annot* pAnnot, |
| 592 | FX_DWORD nFlags, |
| 593 | const CPDF_Point& point) { |
| 594 | ASSERT(pAnnot != NULL); |
| 595 | CFX_ByteString sSubType = pAnnot->GetSubType(); |
| 596 | |
| 597 | if (sSubType == BFFT_SIGNATURE) { |
| 598 | } else { |
| 599 | if (m_pFormFiller) |
| 600 | return m_pFormFiller->OnRButtonDown(pPageView, pAnnot, nFlags, point); |
| 601 | } |
| 602 | |
| 603 | return FALSE; |
| 604 | } |
| 605 | FX_BOOL CPDFSDK_BFAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, |
| 606 | CPDFSDK_Annot* pAnnot, |
| 607 | FX_DWORD nFlags, |
| 608 | const CPDF_Point& point) { |
| 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->OnRButtonUp(pPageView, pAnnot, nFlags, point); |
| 616 | } |
| 617 | |
| 618 | return FALSE; |
| 619 | } |
| 620 | |
| 621 | FX_BOOL CPDFSDK_BFAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, |
| 622 | FX_DWORD nChar, |
| 623 | FX_DWORD nFlags) { |
| 624 | ASSERT(pAnnot != NULL); |
| 625 | CFX_ByteString sSubType = pAnnot->GetSubType(); |
| 626 | |
| 627 | if (sSubType == BFFT_SIGNATURE) { |
| 628 | } else { |
| 629 | if (m_pFormFiller) |
| 630 | return m_pFormFiller->OnChar(pAnnot, nChar, nFlags); |
| 631 | } |
| 632 | |
| 633 | return FALSE; |
| 634 | } |
| 635 | |
| 636 | FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, |
| 637 | int nKeyCode, |
| 638 | int nFlag) { |
| 639 | ASSERT(pAnnot != NULL); |
| 640 | CFX_ByteString sSubType = pAnnot->GetSubType(); |
| 641 | |
| 642 | if (sSubType == BFFT_SIGNATURE) { |
| 643 | } else { |
| 644 | if (m_pFormFiller) |
| 645 | return m_pFormFiller->OnKeyDown(pAnnot, nKeyCode, nFlag); |
| 646 | } |
| 647 | |
| 648 | return FALSE; |
| 649 | } |
| 650 | |
| 651 | FX_BOOL CPDFSDK_BFAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, |
| 652 | int nKeyCode, |
| 653 | int nFlag) { |
| 654 | return FALSE; |
| 655 | } |
| 656 | void CPDFSDK_BFAnnotHandler::OnCreate(CPDFSDK_Annot* pAnnot) { |
| 657 | ASSERT(pAnnot != NULL); |
| 658 | CFX_ByteString sSubType = pAnnot->GetSubType(); |
| 659 | |
| 660 | if (sSubType == BFFT_SIGNATURE) { |
| 661 | } else { |
| 662 | if (m_pFormFiller) |
| 663 | m_pFormFiller->OnCreate(pAnnot); |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | void CPDFSDK_BFAnnotHandler::OnLoad(CPDFSDK_Annot* pAnnot) { |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 668 | if (pAnnot->GetSubType() == BFFT_SIGNATURE) |
| 669 | return; |
| 670 | |
| 671 | CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; |
| 672 | if (!pWidget->IsAppearanceValid()) |
| 673 | pWidget->ResetAppearance(NULL, FALSE); |
| 674 | |
| 675 | int nFieldType = pWidget->GetFieldType(); |
| 676 | if (nFieldType == FIELDTYPE_TEXTFIELD || nFieldType == FIELDTYPE_COMBOBOX) { |
| 677 | FX_BOOL bFormated = FALSE; |
| 678 | CFX_WideString sValue = pWidget->OnFormat(bFormated); |
| 679 | if (bFormated && nFieldType == FIELDTYPE_COMBOBOX) { |
| 680 | pWidget->ResetAppearance(sValue.c_str(), FALSE); |
| 681 | } |
| 682 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 683 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 684 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 685 | CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 686 | CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 687 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
| 688 | if (pDoc->GetDocType() == DOCTYPE_STATIC_XFA) { |
| 689 | if (!pWidget->IsAppearanceValid() && !pWidget->GetValue().IsEmpty()) |
| 690 | pWidget->ResetAppearance(FALSE); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 691 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 692 | #endif // PDF_ENABLE_XFA |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 693 | if (m_pFormFiller) |
| 694 | m_pFormFiller->OnLoad(pAnnot); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 695 | } |
| 696 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 697 | FX_BOOL CPDFSDK_BFAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, |
| 698 | FX_DWORD nFlag) { |
| 699 | ASSERT(pAnnot != NULL); |
| 700 | CFX_ByteString sSubType = pAnnot->GetSubType(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 701 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 702 | if (sSubType == BFFT_SIGNATURE) { |
| 703 | } else { |
| 704 | if (m_pFormFiller) |
| 705 | return m_pFormFiller->OnSetFocus(pAnnot, nFlag); |
| 706 | } |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 707 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 708 | return TRUE; |
| 709 | } |
| 710 | FX_BOOL CPDFSDK_BFAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, |
| 711 | FX_DWORD nFlag) { |
| 712 | ASSERT(pAnnot != NULL); |
| 713 | CFX_ByteString sSubType = pAnnot->GetSubType(); |
| 714 | |
| 715 | if (sSubType == BFFT_SIGNATURE) { |
| 716 | } else { |
| 717 | if (m_pFormFiller) |
| 718 | return m_pFormFiller->OnKillFocus(pAnnot, nFlag); |
| 719 | } |
| 720 | |
| 721 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 724 | CPDF_Rect CPDFSDK_BFAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView, |
| 725 | CPDFSDK_Annot* pAnnot) { |
| 726 | ASSERT(pAnnot != NULL); |
| 727 | CFX_ByteString sSubType = pAnnot->GetSubType(); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 728 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 729 | if (sSubType == BFFT_SIGNATURE) { |
| 730 | } else { |
| 731 | if (m_pFormFiller) |
| 732 | return m_pFormFiller->GetViewBBox(pPageView, pAnnot); |
| 733 | } |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 734 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 735 | return CPDF_Rect(0, 0, 0, 0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 736 | } |
| 737 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 738 | FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, |
| 739 | CPDFSDK_Annot* pAnnot, |
| 740 | const CPDF_Point& point) { |
| 741 | ASSERT(pPageView); |
| 742 | ASSERT(pAnnot); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 743 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 744 | CPDF_Rect rect = GetViewBBox(pPageView, pAnnot); |
| 745 | return rect.Contains(point.x, point.y); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 746 | } |
| 747 | |
Tom Sepez | 51da093 | 2015-11-25 16:05:49 -0800 | [diff] [blame] | 748 | #ifdef PDF_ENABLE_XFA |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 749 | #define FWL_WGTHITTEST_Unknown 0 |
Nico Weber | 077f1a3 | 2015-08-06 15:08:57 -0700 | [diff] [blame] | 750 | #define FWL_WGTHITTEST_Client 1 // arrow |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 751 | #define FWL_WGTHITTEST_Titlebar 11 // caption |
| 752 | #define FWL_WGTHITTEST_HScrollBar 15 |
| 753 | #define FWL_WGTHITTEST_VScrollBar 16 |
| 754 | #define FWL_WGTHITTEST_Border 17 |
| 755 | #define FWL_WGTHITTEST_Edit 19 |
| 756 | #define FWL_WGTHITTEST_HyperLink 20 |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 757 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 758 | CPDFSDK_XFAAnnotHandler::CPDFSDK_XFAAnnotHandler(CPDFDoc_Environment* pApp) |
| 759 | : m_pApp(pApp) {} |
| 760 | |
| 761 | CPDFSDK_Annot* CPDFSDK_XFAAnnotHandler::NewAnnot(IXFA_Widget* pAnnot, |
| 762 | CPDFSDK_PageView* pPage) { |
| 763 | CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument(); |
| 764 | CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pSDKDoc->GetInterForm(); |
| 765 | CPDFSDK_XFAWidget* pWidget = new CPDFSDK_XFAWidget(pAnnot, pPage, pInterForm); |
| 766 | pInterForm->AddXFAMap(pAnnot, pWidget); |
| 767 | return pWidget; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 768 | } |
| 769 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 770 | FX_BOOL CPDFSDK_XFAAnnotHandler::CanAnswer(CPDFSDK_Annot* pAnnot) { |
| 771 | return pAnnot->GetXFAWidget() != NULL; |
| 772 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 773 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 774 | void CPDFSDK_XFAAnnotHandler::OnDraw(CPDFSDK_PageView* pPageView, |
| 775 | CPDFSDK_Annot* pAnnot, |
| 776 | CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame^] | 777 | CFX_Matrix* pUser2Device, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 778 | FX_DWORD dwFlags) { |
| 779 | ASSERT(pPageView != NULL); |
| 780 | ASSERT(pAnnot != NULL); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 781 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 782 | CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); |
| 783 | ASSERT(pSDKDoc != NULL); |
| 784 | |
| 785 | IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 786 | ASSERT(pWidgetHandler != NULL); |
| 787 | |
| 788 | CFX_Graphics gs; |
| 789 | gs.Create(pDevice); |
| 790 | |
| 791 | CFX_Matrix mt; |
| 792 | mt = *(CFX_Matrix*)pUser2Device; |
| 793 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 794 | FX_BOOL bIsHighlight = FALSE; |
| 795 | if (pSDKDoc->GetFocusAnnot() != pAnnot) |
| 796 | bIsHighlight = TRUE; |
| 797 | |
| 798 | pWidgetHandler->RenderWidget(pAnnot->GetXFAWidget(), &gs, &mt, bIsHighlight); |
| 799 | |
| 800 | // to do highlight and shadow |
| 801 | } |
| 802 | |
| 803 | void CPDFSDK_XFAAnnotHandler::ReleaseAnnot(CPDFSDK_Annot* pAnnot) { |
| 804 | ASSERT(pAnnot != NULL); |
| 805 | |
| 806 | CPDFSDK_XFAWidget* pWidget = (CPDFSDK_XFAWidget*)pAnnot; |
| 807 | CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); |
| 808 | ASSERT(pInterForm != NULL); |
| 809 | |
| 810 | pInterForm->RemoveXFAMap(pWidget->GetXFAWidget()); |
| 811 | |
| 812 | delete pWidget; |
| 813 | } |
| 814 | |
| 815 | CPDF_Rect CPDFSDK_XFAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView, |
| 816 | CPDFSDK_Annot* pAnnot) { |
| 817 | ASSERT(pAnnot != NULL); |
| 818 | |
| 819 | IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 820 | ASSERT(pWidgetHandler != NULL); |
| 821 | |
Tom Sepez | a8a39e2 | 2015-10-12 15:47:07 -0700 | [diff] [blame] | 822 | CFX_RectF rcBBox; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 823 | XFA_ELEMENT eType = |
| 824 | pWidgetHandler->GetDataAcc(pAnnot->GetXFAWidget())->GetUIType(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 825 | if (eType == XFA_ELEMENT_Signature) |
| 826 | pWidgetHandler->GetBBox(pAnnot->GetXFAWidget(), rcBBox, |
| 827 | XFA_WIDGETSTATUS_Visible, TRUE); |
| 828 | else |
| 829 | pWidgetHandler->GetBBox(pAnnot->GetXFAWidget(), rcBBox, 0); |
| 830 | |
| 831 | CFX_FloatRect rcWidget(rcBBox.left, rcBBox.top, rcBBox.left + rcBBox.width, |
| 832 | rcBBox.top + rcBBox.height); |
| 833 | rcWidget.left -= 1.0f; |
| 834 | rcWidget.right += 1.0f; |
| 835 | rcWidget.bottom -= 1.0f; |
| 836 | rcWidget.top += 1.0f; |
| 837 | |
| 838 | return rcWidget; |
| 839 | } |
| 840 | |
| 841 | FX_BOOL CPDFSDK_XFAAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, |
| 842 | CPDFSDK_Annot* pAnnot, |
| 843 | const CPDF_Point& point) { |
| 844 | if (!pPageView || !pAnnot) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 845 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 846 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 847 | CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); |
| 848 | if (!pSDKDoc) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 849 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 850 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 851 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 852 | if (!pDoc) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 853 | return FALSE; |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 854 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 855 | IXFA_DocView* pDocView = pDoc->GetXFADocView(); |
| 856 | if (!pDocView) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 857 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 858 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 859 | IXFA_WidgetHandler* pWidgetHandler = pDocView->GetWidgetHandler(); |
| 860 | if (!pWidgetHandler) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 861 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 862 | |
| 863 | FX_DWORD dwHitTest = |
| 864 | pWidgetHandler->OnHitTest(pAnnot->GetXFAWidget(), point.x, point.y); |
| 865 | return (dwHitTest != FWL_WGTHITTEST_Unknown); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 866 | } |
| 867 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 868 | void CPDFSDK_XFAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView, |
| 869 | CPDFSDK_Annot* pAnnot, |
| 870 | FX_DWORD nFlag) { |
| 871 | if (!pPageView || !pAnnot) |
| 872 | return; |
| 873 | IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 874 | ASSERT(pWidgetHandler != NULL); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 875 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 876 | pWidgetHandler->OnMouseEnter(pAnnot->GetXFAWidget()); |
| 877 | } |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 878 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 879 | void CPDFSDK_XFAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView, |
| 880 | CPDFSDK_Annot* pAnnot, |
| 881 | FX_DWORD nFlag) { |
| 882 | if (!pPageView || !pAnnot) |
| 883 | return; |
| 884 | |
| 885 | IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 886 | ASSERT(pWidgetHandler != NULL); |
| 887 | |
| 888 | pWidgetHandler->OnMouseExit(pAnnot->GetXFAWidget()); |
| 889 | } |
| 890 | |
| 891 | FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDown(CPDFSDK_PageView* pPageView, |
| 892 | CPDFSDK_Annot* pAnnot, |
| 893 | FX_DWORD nFlags, |
| 894 | const CPDF_Point& point) { |
| 895 | if (!pPageView || !pAnnot) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 896 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 897 | |
| 898 | IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 899 | ASSERT(pWidgetHandler != NULL); |
| 900 | |
| 901 | FX_BOOL bRet = FALSE; |
| 902 | bRet = pWidgetHandler->OnLButtonDown(pAnnot->GetXFAWidget(), |
| 903 | GetFWLFlags(nFlags), point.x, point.y); |
| 904 | |
| 905 | return bRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 906 | } |
| 907 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 908 | FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonUp(CPDFSDK_PageView* pPageView, |
| 909 | CPDFSDK_Annot* pAnnot, |
| 910 | FX_DWORD nFlags, |
| 911 | const CPDF_Point& point) { |
| 912 | if (!pPageView || !pAnnot) |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 913 | return FALSE; |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 914 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 915 | IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 916 | ASSERT(pWidgetHandler != NULL); |
| 917 | |
| 918 | FX_BOOL bRet = FALSE; |
| 919 | bRet = pWidgetHandler->OnLButtonUp(pAnnot->GetXFAWidget(), |
| 920 | GetFWLFlags(nFlags), point.x, point.y); |
| 921 | |
| 922 | return bRet; |
| 923 | } |
| 924 | |
| 925 | FX_BOOL CPDFSDK_XFAAnnotHandler::OnLButtonDblClk(CPDFSDK_PageView* pPageView, |
| 926 | CPDFSDK_Annot* pAnnot, |
| 927 | FX_DWORD nFlags, |
| 928 | const CPDF_Point& point) { |
| 929 | if (!pPageView || !pAnnot) |
| 930 | return FALSE; |
| 931 | |
| 932 | IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 933 | ASSERT(pWidgetHandler != NULL); |
| 934 | |
| 935 | FX_BOOL bRet = FALSE; |
| 936 | bRet = pWidgetHandler->OnLButtonDblClk(pAnnot->GetXFAWidget(), |
| 937 | GetFWLFlags(nFlags), point.x, point.y); |
| 938 | |
| 939 | return bRet; |
| 940 | } |
| 941 | |
| 942 | FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseMove(CPDFSDK_PageView* pPageView, |
| 943 | CPDFSDK_Annot* pAnnot, |
| 944 | FX_DWORD nFlags, |
| 945 | const CPDF_Point& point) { |
| 946 | if (!pPageView || !pAnnot) |
| 947 | return FALSE; |
| 948 | |
| 949 | IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 950 | ASSERT(pWidgetHandler != NULL); |
| 951 | |
| 952 | FX_BOOL bRet = FALSE; |
| 953 | bRet = pWidgetHandler->OnMouseMove(pAnnot->GetXFAWidget(), |
| 954 | GetFWLFlags(nFlags), point.x, point.y); |
| 955 | |
| 956 | return bRet; |
| 957 | } |
| 958 | |
| 959 | FX_BOOL CPDFSDK_XFAAnnotHandler::OnMouseWheel(CPDFSDK_PageView* pPageView, |
| 960 | CPDFSDK_Annot* pAnnot, |
| 961 | FX_DWORD nFlags, |
| 962 | short zDelta, |
| 963 | const CPDF_Point& point) { |
| 964 | if (!pPageView || !pAnnot) |
| 965 | return FALSE; |
| 966 | |
| 967 | IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 968 | ASSERT(pWidgetHandler != NULL); |
| 969 | |
| 970 | FX_BOOL bRet = FALSE; |
| 971 | bRet = pWidgetHandler->OnMouseWheel( |
| 972 | pAnnot->GetXFAWidget(), GetFWLFlags(nFlags), zDelta, point.x, point.y); |
| 973 | |
| 974 | return bRet; |
| 975 | } |
| 976 | |
| 977 | FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDown(CPDFSDK_PageView* pPageView, |
| 978 | CPDFSDK_Annot* pAnnot, |
| 979 | FX_DWORD nFlags, |
| 980 | const CPDF_Point& point) { |
| 981 | if (!pPageView || !pAnnot) |
| 982 | return FALSE; |
| 983 | |
| 984 | IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 985 | ASSERT(pWidgetHandler != NULL); |
| 986 | |
| 987 | FX_BOOL bRet = FALSE; |
| 988 | bRet = pWidgetHandler->OnRButtonDown(pAnnot->GetXFAWidget(), |
| 989 | GetFWLFlags(nFlags), point.x, point.y); |
| 990 | |
| 991 | return bRet; |
| 992 | } |
| 993 | |
| 994 | FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonUp(CPDFSDK_PageView* pPageView, |
| 995 | CPDFSDK_Annot* pAnnot, |
| 996 | FX_DWORD nFlags, |
| 997 | const CPDF_Point& point) { |
| 998 | if (!pPageView || !pAnnot) |
| 999 | return FALSE; |
| 1000 | |
| 1001 | IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 1002 | ASSERT(pWidgetHandler != NULL); |
| 1003 | |
| 1004 | FX_BOOL bRet = FALSE; |
| 1005 | bRet = pWidgetHandler->OnRButtonUp(pAnnot->GetXFAWidget(), |
| 1006 | GetFWLFlags(nFlags), point.x, point.y); |
| 1007 | |
| 1008 | return bRet; |
| 1009 | } |
| 1010 | |
| 1011 | FX_BOOL CPDFSDK_XFAAnnotHandler::OnRButtonDblClk(CPDFSDK_PageView* pPageView, |
| 1012 | CPDFSDK_Annot* pAnnot, |
| 1013 | FX_DWORD nFlags, |
| 1014 | const CPDF_Point& point) { |
| 1015 | if (!pPageView || !pAnnot) |
| 1016 | return FALSE; |
| 1017 | |
| 1018 | IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 1019 | ASSERT(pWidgetHandler != NULL); |
| 1020 | |
| 1021 | FX_BOOL bRet = FALSE; |
| 1022 | bRet = pWidgetHandler->OnRButtonDblClk(pAnnot->GetXFAWidget(), |
| 1023 | GetFWLFlags(nFlags), point.x, point.y); |
| 1024 | |
| 1025 | return bRet; |
| 1026 | } |
| 1027 | |
| 1028 | FX_BOOL CPDFSDK_XFAAnnotHandler::OnChar(CPDFSDK_Annot* pAnnot, |
| 1029 | FX_DWORD nChar, |
| 1030 | FX_DWORD nFlags) { |
| 1031 | if (!pAnnot) |
| 1032 | return FALSE; |
| 1033 | |
| 1034 | IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 1035 | ASSERT(pWidgetHandler != NULL); |
| 1036 | |
| 1037 | FX_BOOL bRet = FALSE; |
| 1038 | bRet = pWidgetHandler->OnChar(pAnnot->GetXFAWidget(), nChar, |
| 1039 | GetFWLFlags(nFlags)); |
| 1040 | |
| 1041 | return bRet; |
| 1042 | } |
| 1043 | |
| 1044 | FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyDown(CPDFSDK_Annot* pAnnot, |
| 1045 | int nKeyCode, |
| 1046 | int nFlag) { |
| 1047 | if (!pAnnot) |
| 1048 | return FALSE; |
| 1049 | |
| 1050 | IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 1051 | ASSERT(pWidgetHandler != NULL); |
| 1052 | |
| 1053 | FX_BOOL bRet = FALSE; |
| 1054 | bRet = pWidgetHandler->OnKeyDown(pAnnot->GetXFAWidget(), nKeyCode, |
| 1055 | GetFWLFlags(nFlag)); |
| 1056 | |
| 1057 | return bRet; |
| 1058 | } |
| 1059 | |
| 1060 | FX_BOOL CPDFSDK_XFAAnnotHandler::OnKeyUp(CPDFSDK_Annot* pAnnot, |
| 1061 | int nKeyCode, |
| 1062 | int nFlag) { |
| 1063 | if (!pAnnot) |
| 1064 | return FALSE; |
| 1065 | |
| 1066 | IXFA_WidgetHandler* pWidgetHandler = GetXFAWidgetHandler(pAnnot); |
| 1067 | ASSERT(pWidgetHandler != NULL); |
| 1068 | |
| 1069 | FX_BOOL bRet = FALSE; |
| 1070 | bRet = pWidgetHandler->OnKeyUp(pAnnot->GetXFAWidget(), nKeyCode, |
| 1071 | GetFWLFlags(nFlag)); |
| 1072 | |
| 1073 | return bRet; |
| 1074 | } |
| 1075 | |
| 1076 | FX_BOOL CPDFSDK_XFAAnnotHandler::OnSetFocus(CPDFSDK_Annot* pAnnot, |
| 1077 | FX_DWORD nFlag) { |
| 1078 | return TRUE; |
| 1079 | } |
| 1080 | |
| 1081 | FX_BOOL CPDFSDK_XFAAnnotHandler::OnKillFocus(CPDFSDK_Annot* pAnnot, |
| 1082 | FX_DWORD nFlag) { |
| 1083 | return TRUE; |
| 1084 | } |
| 1085 | |
| 1086 | FX_BOOL CPDFSDK_XFAAnnotHandler::OnXFAChangedFocus(CPDFSDK_Annot* pOldAnnot, |
| 1087 | CPDFSDK_Annot* pNewAnnot) { |
| 1088 | IXFA_WidgetHandler* pWidgetHandler = NULL; |
| 1089 | |
| 1090 | if (pOldAnnot) |
| 1091 | pWidgetHandler = GetXFAWidgetHandler(pOldAnnot); |
| 1092 | else if (pNewAnnot) |
| 1093 | pWidgetHandler = GetXFAWidgetHandler(pNewAnnot); |
| 1094 | |
| 1095 | if (pWidgetHandler) { |
| 1096 | FX_BOOL bRet = TRUE; |
| 1097 | IXFA_Widget* hWidget = pNewAnnot ? pNewAnnot->GetXFAWidget() : NULL; |
| 1098 | if (hWidget) { |
| 1099 | IXFA_PageView* pXFAPageView = pWidgetHandler->GetPageView(hWidget); |
| 1100 | if (pXFAPageView) { |
| 1101 | bRet = pXFAPageView->GetDocView()->SetFocus(hWidget); |
| 1102 | if (pXFAPageView->GetDocView()->GetFocusWidget() == hWidget) |
| 1103 | bRet = TRUE; |
| 1104 | } |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1105 | } |
Tom Sepez | dcbc02f | 2015-07-17 09:16:17 -0700 | [diff] [blame] | 1106 | return bRet; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | return TRUE; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1112 | IXFA_WidgetHandler* CPDFSDK_XFAAnnotHandler::GetXFAWidgetHandler( |
| 1113 | CPDFSDK_Annot* pAnnot) { |
| 1114 | if (!pAnnot) |
| 1115 | return NULL; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1116 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1117 | CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); |
| 1118 | if (!pPageView) |
| 1119 | return NULL; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1120 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1121 | CPDFSDK_Document* pSDKDoc = pPageView->GetSDKDocument(); |
| 1122 | if (!pSDKDoc) |
| 1123 | return NULL; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1124 | |
Tom Sepez | 50d12ad | 2015-11-24 09:50:51 -0800 | [diff] [blame] | 1125 | CPDFXFA_Document* pDoc = pSDKDoc->GetXFADocument(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1126 | if (!pDoc) |
| 1127 | return NULL; |
| 1128 | |
| 1129 | IXFA_DocView* pDocView = pDoc->GetXFADocView(); |
| 1130 | if (!pDocView) |
| 1131 | return NULL; |
| 1132 | |
| 1133 | return pDocView->GetWidgetHandler(); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1136 | #define FWL_KEYFLAG_Ctrl (1 << 0) |
| 1137 | #define FWL_KEYFLAG_Alt (1 << 1) |
| 1138 | #define FWL_KEYFLAG_Shift (1 << 2) |
| 1139 | #define FWL_KEYFLAG_LButton (1 << 3) |
| 1140 | #define FWL_KEYFLAG_RButton (1 << 4) |
| 1141 | #define FWL_KEYFLAG_MButton (1 << 5) |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1142 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1143 | FX_DWORD CPDFSDK_XFAAnnotHandler::GetFWLFlags(FX_DWORD dwFlag) { |
| 1144 | FX_DWORD dwFWLFlag = 0; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1145 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1146 | if (dwFlag & FWL_EVENTFLAG_ControlKey) |
| 1147 | dwFWLFlag |= FWL_KEYFLAG_Ctrl; |
| 1148 | if (dwFlag & FWL_EVENTFLAG_LeftButtonDown) |
| 1149 | dwFWLFlag |= FWL_KEYFLAG_LButton; |
| 1150 | if (dwFlag & FWL_EVENTFLAG_MiddleButtonDown) |
| 1151 | dwFWLFlag |= FWL_KEYFLAG_MButton; |
| 1152 | if (dwFlag & FWL_EVENTFLAG_RightButtonDown) |
| 1153 | dwFWLFlag |= FWL_KEYFLAG_RButton; |
| 1154 | if (dwFlag & FWL_EVENTFLAG_ShiftKey) |
| 1155 | dwFWLFlag |= FWL_KEYFLAG_Shift; |
| 1156 | if (dwFlag & FWL_EVENTFLAG_AltKey) |
| 1157 | dwFWLFlag |= FWL_KEYFLAG_Alt; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1158 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1159 | return dwFWLFlag; |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1160 | } |
Tom Sepez | 40e9ff3 | 2015-11-30 12:39:54 -0800 | [diff] [blame] | 1161 | #endif // PDF_ENABLE_XFA |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1162 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1163 | CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView, |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1164 | bool bReverse) |
| 1165 | : m_bReverse(bReverse), m_pos(0) { |
| 1166 | const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList(); |
| 1167 | m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), annots.rbegin(), |
| 1168 | annots.rend()); |
| 1169 | std::stable_sort(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(), |
| 1170 | [](CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) { |
| 1171 | return p1->GetLayoutOrder() < p2->GetLayoutOrder(); |
| 1172 | }); |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 1173 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1174 | CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot(); |
| 1175 | if (!pTopMostAnnot) |
| 1176 | return; |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 1177 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1178 | auto it = std::find(m_iteratorAnnotList.begin(), m_iteratorAnnotList.end(), |
| 1179 | pTopMostAnnot); |
| 1180 | if (it != m_iteratorAnnotList.end()) { |
| 1181 | CPDFSDK_Annot* pReaderAnnot = *it; |
| 1182 | m_iteratorAnnotList.erase(it); |
| 1183 | m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), pReaderAnnot); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1184 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1187 | CPDFSDK_AnnotIterator::~CPDFSDK_AnnotIterator() { |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1190 | CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot() { |
| 1191 | if (m_pos < m_iteratorAnnotList.size()) |
| 1192 | return m_iteratorAnnotList[m_pos++]; |
| 1193 | return nullptr; |
| 1194 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1195 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1196 | CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot() { |
| 1197 | if (m_pos < m_iteratorAnnotList.size()) |
| 1198 | return m_iteratorAnnotList[m_iteratorAnnotList.size() - ++m_pos]; |
| 1199 | return nullptr; |
| 1200 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1201 | |
Lei Zhang | bf60b29 | 2015-10-26 12:14:35 -0700 | [diff] [blame] | 1202 | CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next() { |
| 1203 | return m_bReverse ? PrevAnnot() : NextAnnot(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1204 | } |