| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h" | |
| 8 | |
| 9 #include "core/fpdfapi/fpdf_page/include/cpdf_page.h" | |
| 10 #include "fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h" | |
| 11 #include "fpdfsdk/include/fsdk_common.h" | |
| 12 #include "fpdfsdk/include/fsdk_mgr.h" | |
| 13 #include "fpdfsdk/include/pdfwindow/PWL_Utils.h" | |
| 14 | |
| 15 #define GetRed(rgb) ((uint8_t)(rgb)) | |
| 16 #define GetGreen(rgb) ((uint8_t)(((FX_WORD)(rgb)) >> 8)) | |
| 17 #define GetBlue(rgb) ((uint8_t)((rgb) >> 16)) | |
| 18 | |
| 19 #define FFL_HINT_ELAPSE 800 | |
| 20 | |
| 21 CFFL_FormFiller::CFFL_FormFiller(CPDFDoc_Environment* pApp, | |
| 22 CPDFSDK_Annot* pAnnot) | |
| 23 : m_pApp(pApp), m_pAnnot(pAnnot), m_bValid(FALSE), m_ptOldPos(0, 0) { | |
| 24 m_pWidget = (CPDFSDK_Widget*)pAnnot; | |
| 25 } | |
| 26 | |
| 27 CFFL_FormFiller::~CFFL_FormFiller() { | |
| 28 for (const auto& it : m_Maps) { | |
| 29 CPWL_Wnd* pWnd = it.second; | |
| 30 CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); | |
| 31 pWnd->InvalidateProvider(this); | |
| 32 pWnd->Destroy(); | |
| 33 delete pWnd; | |
| 34 delete pData; | |
| 35 } | |
| 36 m_Maps.clear(); | |
| 37 } | |
| 38 | |
| 39 void CFFL_FormFiller::SetWindowRect(CPDFSDK_PageView* pPageView, | |
| 40 const CFX_FloatRect& rcWindow) { | |
| 41 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | |
| 42 pWnd->Move(CFX_FloatRect(rcWindow), TRUE, FALSE); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 CFX_FloatRect CFFL_FormFiller::GetWindowRect(CPDFSDK_PageView* pPageView) { | |
| 47 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | |
| 48 return pWnd->GetWindowRect(); | |
| 49 } | |
| 50 | |
| 51 return CFX_FloatRect(0, 0, 0, 0); | |
| 52 } | |
| 53 | |
| 54 FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView* pPageView, | |
| 55 CPDFSDK_Annot* pAnnot) { | |
| 56 ASSERT(pPageView); | |
| 57 ASSERT(pAnnot); | |
| 58 | |
| 59 CFX_FloatRect rcAnnot = m_pWidget->GetRect(); | |
| 60 | |
| 61 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | |
| 62 CFX_FloatRect rcWindow = pWnd->GetWindowRect(); | |
| 63 rcAnnot = PWLtoFFL(rcWindow); | |
| 64 } | |
| 65 | |
| 66 CFX_FloatRect rcWin = rcAnnot; | |
| 67 | |
| 68 CFX_FloatRect rcFocus = GetFocusBox(pPageView); | |
| 69 if (!rcFocus.IsEmpty()) | |
| 70 rcWin.Union(rcFocus); | |
| 71 | |
| 72 CFX_FloatRect rect = CPWL_Utils::InflateRect(rcWin, 1); | |
| 73 | |
| 74 return rect.GetOutterRect(); | |
| 75 } | |
| 76 | |
| 77 void CFFL_FormFiller::OnDraw(CPDFSDK_PageView* pPageView, | |
| 78 CPDFSDK_Annot* pAnnot, | |
| 79 CFX_RenderDevice* pDevice, | |
| 80 CFX_Matrix* pUser2Device, | |
| 81 FX_DWORD dwFlags) { | |
| 82 ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget"); | |
| 83 | |
| 84 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | |
| 85 CFX_Matrix mt = GetCurMatrix(); | |
| 86 mt.Concat(*pUser2Device); | |
| 87 pWnd->DrawAppearance(pDevice, &mt); | |
| 88 } else { | |
| 89 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; | |
| 90 if (CFFL_IFormFiller::IsVisible(pWidget)) | |
| 91 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView* pPageView, | |
| 96 CPDFSDK_Annot* pAnnot, | |
| 97 CFX_RenderDevice* pDevice, | |
| 98 CFX_Matrix* pUser2Device, | |
| 99 FX_DWORD dwFlags) { | |
| 100 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; | |
| 101 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); | |
| 102 } | |
| 103 | |
| 104 void CFFL_FormFiller::OnCreate(CPDFSDK_Annot* pAnnot) {} | |
| 105 | |
| 106 void CFFL_FormFiller::OnLoad(CPDFSDK_Annot* pAnnot) {} | |
| 107 | |
| 108 void CFFL_FormFiller::OnDelete(CPDFSDK_Annot* pAnnot) {} | |
| 109 | |
| 110 void CFFL_FormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView, | |
| 111 CPDFSDK_Annot* pAnnot) {} | |
| 112 | |
| 113 void CFFL_FormFiller::OnMouseExit(CPDFSDK_PageView* pPageView, | |
| 114 CPDFSDK_Annot* pAnnot) { | |
| 115 EndTimer(); | |
| 116 ASSERT(m_pWidget); | |
| 117 } | |
| 118 | |
| 119 FX_BOOL CFFL_FormFiller::OnLButtonDown(CPDFSDK_PageView* pPageView, | |
| 120 CPDFSDK_Annot* pAnnot, | |
| 121 FX_UINT nFlags, | |
| 122 const CFX_FloatPoint& point) { | |
| 123 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) { | |
| 124 m_bValid = TRUE; | |
| 125 FX_RECT rect = GetViewBBox(pPageView, pAnnot); | |
| 126 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); | |
| 127 | |
| 128 if (!rect.Contains((int)point.x, (int)point.y)) | |
| 129 return FALSE; | |
| 130 | |
| 131 return pWnd->OnLButtonDown(WndtoPWL(pPageView, point), nFlags); | |
| 132 } | |
| 133 | |
| 134 return FALSE; | |
| 135 } | |
| 136 | |
| 137 FX_BOOL CFFL_FormFiller::OnLButtonUp(CPDFSDK_PageView* pPageView, | |
| 138 CPDFSDK_Annot* pAnnot, | |
| 139 FX_UINT nFlags, | |
| 140 const CFX_FloatPoint& point) { | |
| 141 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | |
| 142 FX_RECT rcFFL = GetViewBBox(pPageView, pAnnot); | |
| 143 InvalidateRect(rcFFL.left, rcFFL.top, rcFFL.right, rcFFL.bottom); | |
| 144 pWnd->OnLButtonUp(WndtoPWL(pPageView, point), nFlags); | |
| 145 return TRUE; | |
| 146 } | |
| 147 | |
| 148 return FALSE; | |
| 149 } | |
| 150 | |
| 151 FX_BOOL CFFL_FormFiller::OnLButtonDblClk(CPDFSDK_PageView* pPageView, | |
| 152 CPDFSDK_Annot* pAnnot, | |
| 153 FX_UINT nFlags, | |
| 154 const CFX_FloatPoint& point) { | |
| 155 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | |
| 156 pWnd->OnLButtonDblClk(WndtoPWL(pPageView, point), nFlags); | |
| 157 return TRUE; | |
| 158 } | |
| 159 | |
| 160 return FALSE; | |
| 161 } | |
| 162 | |
| 163 FX_BOOL CFFL_FormFiller::OnMouseMove(CPDFSDK_PageView* pPageView, | |
| 164 CPDFSDK_Annot* pAnnot, | |
| 165 FX_UINT nFlags, | |
| 166 const CFX_FloatPoint& point) { | |
| 167 if ((m_ptOldPos.x != point.x) || (m_ptOldPos.y != point.y)) { | |
| 168 m_ptOldPos = point; | |
| 169 } | |
| 170 | |
| 171 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | |
| 172 pWnd->OnMouseMove(WndtoPWL(pPageView, point), nFlags); | |
| 173 return TRUE; | |
| 174 } | |
| 175 | |
| 176 return FALSE; | |
| 177 } | |
| 178 | |
| 179 FX_BOOL CFFL_FormFiller::OnMouseWheel(CPDFSDK_PageView* pPageView, | |
| 180 CPDFSDK_Annot* pAnnot, | |
| 181 FX_UINT nFlags, | |
| 182 short zDelta, | |
| 183 const CFX_FloatPoint& point) { | |
| 184 if (!IsValid()) | |
| 185 return FALSE; | |
| 186 | |
| 187 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) { | |
| 188 return pWnd->OnMouseWheel(zDelta, WndtoPWL(pPageView, point), nFlags); | |
| 189 } | |
| 190 | |
| 191 return FALSE; | |
| 192 } | |
| 193 | |
| 194 FX_BOOL CFFL_FormFiller::OnRButtonDown(CPDFSDK_PageView* pPageView, | |
| 195 CPDFSDK_Annot* pAnnot, | |
| 196 FX_UINT nFlags, | |
| 197 const CFX_FloatPoint& point) { | |
| 198 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) { | |
| 199 pWnd->OnRButtonDown(WndtoPWL(pPageView, point), nFlags); | |
| 200 return TRUE; | |
| 201 } | |
| 202 | |
| 203 return FALSE; | |
| 204 } | |
| 205 | |
| 206 FX_BOOL CFFL_FormFiller::OnRButtonUp(CPDFSDK_PageView* pPageView, | |
| 207 CPDFSDK_Annot* pAnnot, | |
| 208 FX_UINT nFlags, | |
| 209 const CFX_FloatPoint& point) { | |
| 210 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | |
| 211 pWnd->OnRButtonUp(WndtoPWL(pPageView, point), nFlags); | |
| 212 return TRUE; | |
| 213 } | |
| 214 | |
| 215 return FALSE; | |
| 216 } | |
| 217 | |
| 218 FX_BOOL CFFL_FormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, | |
| 219 FX_UINT nKeyCode, | |
| 220 FX_UINT nFlags) { | |
| 221 if (IsValid()) { | |
| 222 CPDFSDK_PageView* pPageView = GetCurPageView(); | |
| 223 ASSERT(pPageView); | |
| 224 | |
| 225 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | |
| 226 return pWnd->OnKeyDown(nKeyCode, nFlags); | |
| 227 } | |
| 228 } | |
| 229 | |
| 230 return FALSE; | |
| 231 } | |
| 232 | |
| 233 FX_BOOL CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, | |
| 234 FX_UINT nChar, | |
| 235 FX_UINT nFlags) { | |
| 236 if (IsValid()) { | |
| 237 CPDFSDK_PageView* pPageView = GetCurPageView(); | |
| 238 ASSERT(pPageView); | |
| 239 | |
| 240 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | |
| 241 return pWnd->OnChar(nChar, nFlags); | |
| 242 } | |
| 243 } | |
| 244 | |
| 245 return FALSE; | |
| 246 } | |
| 247 | |
| 248 void CFFL_FormFiller::SetFocusForAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { | |
| 249 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; | |
| 250 UnderlyingPageType* pPage = pWidget->GetUnderlyingPage(); | |
| 251 CPDFSDK_Document* pDoc = m_pApp->GetSDKDocument(); | |
| 252 CPDFSDK_PageView* pPageView = pDoc->GetPageView(pPage); | |
| 253 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) | |
| 254 pWnd->SetFocus(); | |
| 255 | |
| 256 m_bValid = TRUE; | |
| 257 FX_RECT rcRect = GetViewBBox(pPageView, pAnnot); | |
| 258 InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); | |
| 259 } | |
| 260 | |
| 261 void CFFL_FormFiller::KillFocusForAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) { | |
| 262 if (!IsValid()) | |
| 263 return; | |
| 264 | |
| 265 CPDFSDK_PageView* pPageView = GetCurPageView(); | |
| 266 if (!pPageView) | |
| 267 return; | |
| 268 | |
| 269 CommitData(pPageView, nFlag); | |
| 270 | |
| 271 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) | |
| 272 pWnd->KillFocus(); | |
| 273 | |
| 274 FX_BOOL bDestroyPDFWindow; | |
| 275 switch (m_pWidget->GetFieldType()) { | |
| 276 case FIELDTYPE_PUSHBUTTON: | |
| 277 case FIELDTYPE_CHECKBOX: | |
| 278 case FIELDTYPE_RADIOBUTTON: | |
| 279 bDestroyPDFWindow = TRUE; | |
| 280 break; | |
| 281 default: | |
| 282 bDestroyPDFWindow = FALSE; | |
| 283 break; | |
| 284 } | |
| 285 EscapeFiller(pPageView, bDestroyPDFWindow); | |
| 286 } | |
| 287 | |
| 288 FX_BOOL CFFL_FormFiller::IsValid() const { | |
| 289 return m_bValid; | |
| 290 } | |
| 291 | |
| 292 PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam() { | |
| 293 ASSERT(m_pApp); | |
| 294 | |
| 295 PWL_CREATEPARAM cp; | |
| 296 cp.pParentWnd = NULL; | |
| 297 cp.pProvider = this; | |
| 298 cp.rcRectWnd = GetPDFWindowRect(); | |
| 299 | |
| 300 FX_DWORD dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE; | |
| 301 FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags(); | |
| 302 if (dwFieldFlag & FIELDFLAG_READONLY) { | |
| 303 dwCreateFlags |= PWS_READONLY; | |
| 304 } | |
| 305 | |
| 306 FX_COLORREF color; | |
| 307 if (m_pWidget->GetFillColor(color)) { | |
| 308 cp.sBackgroundColor = | |
| 309 CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); | |
| 310 } | |
| 311 | |
| 312 if (m_pWidget->GetBorderColor(color)) { | |
| 313 cp.sBorderColor = | |
| 314 CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); | |
| 315 } | |
| 316 | |
| 317 cp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0); | |
| 318 | |
| 319 if (m_pWidget->GetTextColor(color)) { | |
| 320 cp.sTextColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); | |
| 321 } | |
| 322 | |
| 323 cp.fFontSize = m_pWidget->GetFontSize(); | |
| 324 cp.dwBorderWidth = m_pWidget->GetBorderWidth(); | |
| 325 | |
| 326 int nBorderStyle = m_pWidget->GetBorderStyle(); | |
| 327 | |
| 328 switch (nBorderStyle) { | |
| 329 case BBS_SOLID: | |
| 330 cp.nBorderStyle = PBS_SOLID; | |
| 331 break; | |
| 332 case BBS_DASH: | |
| 333 cp.nBorderStyle = PBS_DASH; | |
| 334 cp.sDash = CPWL_Dash(3, 3, 0); | |
| 335 break; | |
| 336 case BBS_BEVELED: | |
| 337 cp.nBorderStyle = PBS_BEVELED; | |
| 338 cp.dwBorderWidth *= 2; | |
| 339 break; | |
| 340 case BBS_INSET: | |
| 341 cp.nBorderStyle = PBS_INSET; | |
| 342 cp.dwBorderWidth *= 2; | |
| 343 break; | |
| 344 case BBS_UNDERLINE: | |
| 345 cp.nBorderStyle = PBS_UNDERLINED; | |
| 346 break; | |
| 347 } | |
| 348 | |
| 349 if (cp.fFontSize <= 0) { | |
| 350 dwCreateFlags |= PWS_AUTOFONTSIZE; | |
| 351 } | |
| 352 | |
| 353 cp.dwFlags = dwCreateFlags; | |
| 354 cp.pSystemHandler = m_pApp->GetSysHandler(); | |
| 355 return cp; | |
| 356 } | |
| 357 | |
| 358 CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, | |
| 359 FX_BOOL bNew) { | |
| 360 ASSERT(pPageView); | |
| 361 | |
| 362 auto it = m_Maps.find(pPageView); | |
| 363 const bool found = it != m_Maps.end(); | |
| 364 CPWL_Wnd* pWnd = found ? it->second : nullptr; | |
| 365 if (!bNew) | |
| 366 return pWnd; | |
| 367 | |
| 368 if (found) { | |
| 369 CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pWnd->GetAttachedData(); | |
| 370 if (pPrivateData->nWidgetAge != m_pWidget->GetAppearanceAge()) { | |
| 371 return ResetPDFWindow( | |
| 372 pPageView, m_pWidget->GetValueAge() == pPrivateData->nValueAge); | |
| 373 } | |
| 374 } else { | |
| 375 PWL_CREATEPARAM cp = GetCreateParam(); | |
| 376 cp.hAttachedWnd = (FX_HWND)m_pWidget; | |
| 377 | |
| 378 CFFL_PrivateData* pPrivateData = new CFFL_PrivateData; | |
| 379 pPrivateData->pWidget = m_pWidget; | |
| 380 pPrivateData->pPageView = pPageView; | |
| 381 pPrivateData->nWidgetAge = m_pWidget->GetAppearanceAge(); | |
| 382 pPrivateData->nValueAge = 0; | |
| 383 | |
| 384 cp.pAttachedData = pPrivateData; | |
| 385 | |
| 386 pWnd = NewPDFWindow(cp, pPageView); | |
| 387 m_Maps[pPageView] = pWnd; | |
| 388 } | |
| 389 | |
| 390 return pWnd; | |
| 391 } | |
| 392 | |
| 393 void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView) { | |
| 394 auto it = m_Maps.find(pPageView); | |
| 395 if (it == m_Maps.end()) | |
| 396 return; | |
| 397 | |
| 398 CPWL_Wnd* pWnd = it->second; | |
| 399 CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); | |
| 400 pWnd->Destroy(); | |
| 401 delete pWnd; | |
| 402 delete pData; | |
| 403 | |
| 404 m_Maps.erase(it); | |
| 405 } | |
| 406 | |
| 407 CFX_Matrix CFFL_FormFiller::GetWindowMatrix(void* pAttachedData) { | |
| 408 if (CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pAttachedData) { | |
| 409 if (pPrivateData->pPageView) { | |
| 410 CFX_Matrix mtPageView; | |
| 411 pPrivateData->pPageView->GetCurrentMatrix(mtPageView); | |
| 412 CFX_Matrix mt = GetCurMatrix(); | |
| 413 mt.Concat(mtPageView); | |
| 414 | |
| 415 return mt; | |
| 416 } | |
| 417 } | |
| 418 return CFX_Matrix(1, 0, 0, 1, 0, 0); | |
| 419 } | |
| 420 | |
| 421 CFX_Matrix CFFL_FormFiller::GetCurMatrix() { | |
| 422 CFX_Matrix mt; | |
| 423 | |
| 424 CFX_FloatRect rcDA; | |
| 425 m_pWidget->GetPDFAnnot()->GetRect(rcDA); | |
| 426 | |
| 427 switch (m_pWidget->GetRotate()) { | |
| 428 default: | |
| 429 case 0: | |
| 430 mt = CFX_Matrix(1, 0, 0, 1, 0, 0); | |
| 431 break; | |
| 432 case 90: | |
| 433 mt = CFX_Matrix(0, 1, -1, 0, rcDA.right - rcDA.left, 0); | |
| 434 break; | |
| 435 case 180: | |
| 436 mt = CFX_Matrix(-1, 0, 0, -1, rcDA.right - rcDA.left, | |
| 437 rcDA.top - rcDA.bottom); | |
| 438 break; | |
| 439 case 270: | |
| 440 mt = CFX_Matrix(0, -1, 1, 0, 0, rcDA.top - rcDA.bottom); | |
| 441 break; | |
| 442 } | |
| 443 mt.e += rcDA.left; | |
| 444 mt.f += rcDA.bottom; | |
| 445 | |
| 446 return mt; | |
| 447 } | |
| 448 | |
| 449 CFX_WideString CFFL_FormFiller::LoadPopupMenuString(int nIndex) { | |
| 450 ASSERT(m_pApp); | |
| 451 | |
| 452 return L""; | |
| 453 } | |
| 454 | |
| 455 CFX_FloatRect CFFL_FormFiller::GetPDFWindowRect() const { | |
| 456 CFX_FloatRect rectAnnot; | |
| 457 m_pWidget->GetPDFAnnot()->GetRect(rectAnnot); | |
| 458 | |
| 459 FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left; | |
| 460 FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom; | |
| 461 if ((m_pWidget->GetRotate() / 90) & 0x01) | |
| 462 return CFX_FloatRect(0, 0, fHeight, fWidth); | |
| 463 | |
| 464 return CFX_FloatRect(0, 0, fWidth, fHeight); | |
| 465 } | |
| 466 | |
| 467 CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView() { | |
| 468 UnderlyingPageType* pPage = m_pAnnot->GetUnderlyingPage(); | |
| 469 CPDFSDK_Document* pSDKDoc = m_pApp->GetSDKDocument(); | |
| 470 return pSDKDoc ? pSDKDoc->GetPageView(pPage) : nullptr; | |
| 471 } | |
| 472 | |
| 473 CFX_FloatRect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView) { | |
| 474 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) { | |
| 475 CFX_FloatRect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect())); | |
| 476 CFX_FloatRect rcPage = pPageView->GetPDFPage()->GetPageBBox(); | |
| 477 if (rcPage.Contains(rcFocus)) | |
| 478 return rcFocus; | |
| 479 } | |
| 480 return CFX_FloatRect(0, 0, 0, 0); | |
| 481 } | |
| 482 | |
| 483 CFX_FloatRect CFFL_FormFiller::FFLtoPWL(const CFX_FloatRect& rect) { | |
| 484 CFX_Matrix mt; | |
| 485 mt.SetReverse(GetCurMatrix()); | |
| 486 | |
| 487 CFX_FloatRect temp = rect; | |
| 488 mt.TransformRect(temp); | |
| 489 | |
| 490 return temp; | |
| 491 } | |
| 492 | |
| 493 CFX_FloatRect CFFL_FormFiller::PWLtoFFL(const CFX_FloatRect& rect) { | |
| 494 CFX_Matrix mt = GetCurMatrix(); | |
| 495 | |
| 496 CFX_FloatRect temp = rect; | |
| 497 mt.TransformRect(temp); | |
| 498 | |
| 499 return temp; | |
| 500 } | |
| 501 | |
| 502 CFX_FloatPoint CFFL_FormFiller::FFLtoPWL(const CFX_FloatPoint& point) { | |
| 503 CFX_Matrix mt; | |
| 504 mt.SetReverse(GetCurMatrix()); | |
| 505 | |
| 506 CFX_FloatPoint pt = point; | |
| 507 mt.Transform(pt.x, pt.y); | |
| 508 | |
| 509 return pt; | |
| 510 } | |
| 511 | |
| 512 CFX_FloatPoint CFFL_FormFiller::PWLtoFFL(const CFX_FloatPoint& point) { | |
| 513 CFX_Matrix mt = GetCurMatrix(); | |
| 514 | |
| 515 CFX_FloatPoint pt = point; | |
| 516 mt.Transform(pt.x, pt.y); | |
| 517 | |
| 518 return pt; | |
| 519 } | |
| 520 | |
| 521 CFX_FloatPoint CFFL_FormFiller::WndtoPWL(CPDFSDK_PageView* pPageView, | |
| 522 const CFX_FloatPoint& pt) { | |
| 523 return FFLtoPWL(pt); | |
| 524 } | |
| 525 | |
| 526 CFX_FloatRect CFFL_FormFiller::FFLtoWnd(CPDFSDK_PageView* pPageView, | |
| 527 const CFX_FloatRect& rect) { | |
| 528 return rect; | |
| 529 } | |
| 530 | |
| 531 FX_BOOL CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, | |
| 532 FX_UINT nFlag) { | |
| 533 if (IsDataChanged(pPageView)) { | |
| 534 FX_BOOL bRC = TRUE; | |
| 535 FX_BOOL bExit = FALSE; | |
| 536 CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); | |
| 537 pIFormFiller->OnKeyStrokeCommit(m_pWidget, pPageView, bRC, bExit, nFlag); | |
| 538 if (bExit) | |
| 539 return TRUE; | |
| 540 if (!bRC) { | |
| 541 ResetPDFWindow(pPageView, FALSE); | |
| 542 return TRUE; | |
| 543 } | |
| 544 | |
| 545 pIFormFiller->OnValidate(m_pWidget, pPageView, bRC, bExit, nFlag); | |
| 546 if (bExit) | |
| 547 return TRUE; | |
| 548 if (!bRC) { | |
| 549 ResetPDFWindow(pPageView, FALSE); | |
| 550 return TRUE; | |
| 551 } | |
| 552 | |
| 553 SaveData(pPageView); | |
| 554 pIFormFiller->OnCalculate(m_pWidget, pPageView, bExit, nFlag); | |
| 555 if (bExit) | |
| 556 return TRUE; | |
| 557 | |
| 558 pIFormFiller->OnFormat(m_pWidget, pPageView, bExit, nFlag); | |
| 559 } | |
| 560 return TRUE; | |
| 561 } | |
| 562 | |
| 563 FX_BOOL CFFL_FormFiller::IsDataChanged(CPDFSDK_PageView* pPageView) { | |
| 564 return FALSE; | |
| 565 } | |
| 566 | |
| 567 void CFFL_FormFiller::SaveData(CPDFSDK_PageView* pPageView) {} | |
| 568 | |
| 569 #ifdef PDF_ENABLE_XFA | |
| 570 FX_BOOL CFFL_FormFiller::IsFieldFull(CPDFSDK_PageView* pPageView) { | |
| 571 return FALSE; | |
| 572 } | |
| 573 #endif // PDF_ENABLE_XFA | |
| 574 | |
| 575 void CFFL_FormFiller::SetChangeMark() { | |
| 576 m_pApp->FFI_OnChange(); | |
| 577 } | |
| 578 | |
| 579 void CFFL_FormFiller::GetActionData(CPDFSDK_PageView* pPageView, | |
| 580 CPDF_AAction::AActionType type, | |
| 581 PDFSDK_FieldAction& fa) { | |
| 582 fa.sValue = m_pWidget->GetValue(); | |
| 583 } | |
| 584 | |
| 585 void CFFL_FormFiller::SetActionData(CPDFSDK_PageView* pPageView, | |
| 586 CPDF_AAction::AActionType type, | |
| 587 const PDFSDK_FieldAction& fa) {} | |
| 588 | |
| 589 FX_BOOL CFFL_FormFiller::IsActionDataChanged(CPDF_AAction::AActionType type, | |
| 590 const PDFSDK_FieldAction& faOld, | |
| 591 const PDFSDK_FieldAction& faNew) { | |
| 592 return FALSE; | |
| 593 } | |
| 594 | |
| 595 void CFFL_FormFiller::SaveState(CPDFSDK_PageView* pPageView) {} | |
| 596 | |
| 597 void CFFL_FormFiller::RestoreState(CPDFSDK_PageView* pPageView) {} | |
| 598 | |
| 599 CPWL_Wnd* CFFL_FormFiller::ResetPDFWindow(CPDFSDK_PageView* pPageView, | |
| 600 FX_BOOL bRestoreValue) { | |
| 601 return GetPDFWindow(pPageView, FALSE); | |
| 602 } | |
| 603 | |
| 604 void CFFL_FormFiller::TimerProc() {} | |
| 605 | |
| 606 IFX_SystemHandler* CFFL_FormFiller::GetSystemHandler() const { | |
| 607 return m_pApp->GetSysHandler(); | |
| 608 } | |
| 609 | |
| 610 void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView, | |
| 611 FX_BOOL bDestroyPDFWindow) { | |
| 612 m_bValid = FALSE; | |
| 613 | |
| 614 FX_RECT rcRect = GetViewBBox(pPageView, m_pWidget); | |
| 615 InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); | |
| 616 | |
| 617 if (bDestroyPDFWindow) | |
| 618 DestroyPDFWindow(pPageView); | |
| 619 } | |
| 620 | |
| 621 void CFFL_FormFiller::InvalidateRect(double left, | |
| 622 double top, | |
| 623 double right, | |
| 624 double bottom) { | |
| 625 UnderlyingPageType* pPage = m_pWidget->GetUnderlyingPage(); | |
| 626 m_pApp->FFI_Invalidate(pPage, left, top, right, bottom); | |
| 627 } | |
| 628 | |
| 629 CFFL_Button::CFFL_Button(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) | |
| 630 : CFFL_FormFiller(pApp, pWidget), m_bMouseIn(FALSE), m_bMouseDown(FALSE) {} | |
| 631 | |
| 632 CFFL_Button::~CFFL_Button() {} | |
| 633 | |
| 634 void CFFL_Button::OnMouseEnter(CPDFSDK_PageView* pPageView, | |
| 635 CPDFSDK_Annot* pAnnot) { | |
| 636 m_bMouseIn = TRUE; | |
| 637 FX_RECT rect = GetViewBBox(pPageView, pAnnot); | |
| 638 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); | |
| 639 } | |
| 640 | |
| 641 void CFFL_Button::OnMouseExit(CPDFSDK_PageView* pPageView, | |
| 642 CPDFSDK_Annot* pAnnot) { | |
| 643 m_bMouseIn = FALSE; | |
| 644 | |
| 645 FX_RECT rect = GetViewBBox(pPageView, pAnnot); | |
| 646 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); | |
| 647 EndTimer(); | |
| 648 ASSERT(m_pWidget); | |
| 649 } | |
| 650 | |
| 651 FX_BOOL CFFL_Button::OnLButtonDown(CPDFSDK_PageView* pPageView, | |
| 652 CPDFSDK_Annot* pAnnot, | |
| 653 FX_UINT nFlags, | |
| 654 const CFX_FloatPoint& point) { | |
| 655 CFX_FloatRect rcAnnot = pAnnot->GetRect(); | |
| 656 if (!rcAnnot.Contains(point.x, point.y)) | |
| 657 return FALSE; | |
| 658 | |
| 659 m_bMouseDown = TRUE; | |
| 660 m_bValid = TRUE; | |
| 661 FX_RECT rect = GetViewBBox(pPageView, pAnnot); | |
| 662 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); | |
| 663 return TRUE; | |
| 664 } | |
| 665 | |
| 666 FX_BOOL CFFL_Button::OnLButtonUp(CPDFSDK_PageView* pPageView, | |
| 667 CPDFSDK_Annot* pAnnot, | |
| 668 FX_UINT nFlags, | |
| 669 const CFX_FloatPoint& point) { | |
| 670 CFX_FloatRect rcAnnot = pAnnot->GetRect(); | |
| 671 if (!rcAnnot.Contains(point.x, point.y)) | |
| 672 return FALSE; | |
| 673 | |
| 674 m_bMouseDown = FALSE; | |
| 675 m_pWidget->GetPDFPage(); | |
| 676 | |
| 677 FX_RECT rect = GetViewBBox(pPageView, pAnnot); | |
| 678 InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); | |
| 679 return TRUE; | |
| 680 } | |
| 681 | |
| 682 FX_BOOL CFFL_Button::OnMouseMove(CPDFSDK_PageView* pPageView, | |
| 683 CPDFSDK_Annot* pAnnot, | |
| 684 FX_UINT nFlags, | |
| 685 const CFX_FloatPoint& point) { | |
| 686 ASSERT(m_pApp); | |
| 687 | |
| 688 return TRUE; | |
| 689 } | |
| 690 | |
| 691 void CFFL_Button::OnDraw(CPDFSDK_PageView* pPageView, | |
| 692 CPDFSDK_Annot* pAnnot, | |
| 693 CFX_RenderDevice* pDevice, | |
| 694 CFX_Matrix* pUser2Device, | |
| 695 FX_DWORD dwFlags) { | |
| 696 ASSERT(pPageView); | |
| 697 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; | |
| 698 CPDF_FormControl* pCtrl = pWidget->GetFormControl(); | |
| 699 CPDF_FormControl::HighlightingMode eHM = pCtrl->GetHighlightingMode(); | |
| 700 | |
| 701 if (eHM != CPDF_FormControl::Push) { | |
| 702 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); | |
| 703 return; | |
| 704 } | |
| 705 | |
| 706 if (m_bMouseDown) { | |
| 707 if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Down)) | |
| 708 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Down, NULL); | |
| 709 else | |
| 710 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); | |
| 711 } else if (m_bMouseIn) { | |
| 712 if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Rollover)) | |
| 713 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Rollover, | |
| 714 NULL); | |
| 715 else | |
| 716 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); | |
| 717 } else { | |
| 718 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); | |
| 719 } | |
| 720 } | |
| 721 | |
| 722 void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView* pPageView, | |
| 723 CPDFSDK_Annot* pAnnot, | |
| 724 CFX_RenderDevice* pDevice, | |
| 725 CFX_Matrix* pUser2Device, | |
| 726 FX_DWORD dwFlags) { | |
| 727 OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); | |
| 728 } | |
| OLD | NEW |