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