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 8 #include "../../include/formfiller/FFL_FormFiller.h" 9 #include "../../include/formfiller/FFL_Notify.h" 10 #include "../../include/formfiller/FFL_CBA_Fontmap.h" 11 12 #define GetRed(rgb) ((FX_BYTE)(rgb)) 13 #define GetGreen(rgb) ((FX_BYTE)(((FX_WORD)(rgb)) >> 8)) 14 #define GetBlue(rgb) ((FX_BYTE)((rgb)>>16)) 15 16 #define FFL_HINT_ELAPSE 800 17 18 /* ------------------------- CFFL_FormFiller ------------------------- */ 19 20 CFFL_FormFiller::CFFL_FormFiller(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) 21 :m_pApp(pApp), 22 m_pAnnot(pAnnot), 23 m_bValid(FALSE), 24 m_ptOldPos(0,0) 25 { 26 m_pWidget = (CPDFSDK_Widget*) pAnnot; 27 } 28 29 CFFL_FormFiller::~CFFL_FormFiller() 30 { 31 FX_POSITION pos = m_Maps.GetStartPosition(); 32 while (pos) 33 { 34 CPDFSDK_PageView * pPageView = NULL; 35 CPWL_Wnd* pWnd = NULL; 36 m_Maps.GetNextAssoc(pos, pPageView, pWnd); 37 38 if (pWnd) 39 { 40 CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); 41 pWnd->Destroy(); 42 delete pWnd; 43 delete pData; 44 } 45 } 46 m_Maps.RemoveAll(); 47 48 } 49 50 void CFFL_FormFiller::SetWindowRect(CPDFSDK_PageView* pPageView, const CPDF_Rect& rcWindow) 51 { 52 if (CPWL_Wnd* pWnd = this->GetPDFWindow(pPageView, FALSE)) 53 { 54 pWnd->Move(CPDF_Rect(rcWindow), TRUE, FALSE); 55 } 56 } 57 58 CPDF_Rect CFFL_FormFiller::GetWindowRect(CPDFSDK_PageView* pPageView) 59 { 60 if (CPWL_Wnd* pWnd = this->GetPDFWindow(pPageView, FALSE)) 61 { 62 return pWnd->GetWindowRect(); 63 } 64 65 return CPDF_Rect(0,0,0,0); 66 } 67 68 FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) 69 { 70 ASSERT(pPageView != NULL); 71 ASSERT(pAnnot != NULL); 72 73 CPDF_Rect rcAnnot = m_pWidget->GetRect(); 74 75 if (CPWL_Wnd* pWnd = this->GetPDFWindow(pPageView, FALSE)) 76 { 77 CPDF_Rect rcWindow = pWnd->GetWindowRect(); 78 rcAnnot = PWLtoFFL(rcWindow); 79 } 80 81 CPDF_Rect rcWin = rcAnnot; 82 // pPageView->DocToWindow(rcAnnot, rcWin); 83 84 CPDF_Rect rcFocus = this->GetFocusBox(pPageView); 85 if (!rcFocus.IsEmpty()) 86 rcWin.Union(rcFocus); 87 88 CPDF_Rect rect = CPWL_Utils::InflateRect(rcWin,1); 89 90 return rect.GetOutterRect(); 91 } 92 93 void CFFL_FormFiller::OnDraw(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot, 94 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, 95 /*const CRect& rcWindow,*/ FX_DWORD dwFlags) 96 { 97 ASSERT(pAnnot->GetPDFAnnot()->GetSubType() == "Widget"); 98 99 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) 100 { 101 CPDF_Matrix mt = this->GetCurMatrix(); 102 mt.Concat(*pUser2Device); 103 pWnd->DrawAppearance(pDevice,&mt); 104 } 105 else 106 { 107 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; 108 if (CFFL_IFormFiller::IsVisible(pWidget)) 109 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); 110 } 111 } 112 113 void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot, 114 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, 115 /*const CRect& rcWindow,*/ FX_DWORD dwFlags) 116 { 117 ASSERT(pAnnot != NULL); 118 119 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; 120 121 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); 122 } 123 124 125 void CFFL_FormFiller::OnCreate(CPDFSDK_Annot* pAnnot) 126 { 127 } 128 129 void CFFL_FormFiller::OnLoad(CPDFSDK_Annot* pAnnot) 130 { 131 } 132 133 void CFFL_FormFiller::OnDelete(CPDFSDK_Annot* pAnnot) 134 { 135 } 136 137 void CFFL_FormFiller::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) 138 { 139 } 140 141 void CFFL_FormFiller::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) 142 { 143 EndTimer(); 144 ASSERT(m_pWidget != NULL); 145 } 146 147 FX_BOOL CFFL_FormFiller::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) 148 { 149 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE)) 150 { 151 m_bValid = TRUE; 152 FX_RECT rect = this->GetViewBBox(pPageView,pAnnot); 153 this->InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); 154 155 if(!rect.Contains((int)point.x, (int)point.y)) 156 return FALSE; 157 158 return pWnd->OnLButtonDown(WndtoPWL(pPageView, point),nFlags); 159 } 160 161 return FALSE; 162 } 163 164 FX_BOOL CFFL_FormFiller::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) 165 { 166 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) 167 { 168 FX_RECT rcFFL = this->GetViewBBox(pPageView, pAnnot); 169 this->InvalidateRect(rcFFL.left, rcFFL.top, rcFFL.right, rcFFL.bottom); 170 pWnd->OnLButtonUp(WndtoPWL(pPageView, point),nFlags); 171 return TRUE; 172 } 173 174 return FALSE; 175 } 176 177 FX_BOOL CFFL_FormFiller::OnLButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) 178 { 179 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) 180 { 181 pWnd->OnLButtonDblClk(WndtoPWL(pPageView, point),nFlags); 182 return TRUE; 183 } 184 185 return FALSE; 186 } 187 188 FX_BOOL CFFL_FormFiller::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) 189 { 190 if ((m_ptOldPos.x != point.x) || (m_ptOldPos.y != point.y)) 191 { 192 m_ptOldPos = point; 193 } 194 195 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) 196 { 197 pWnd->OnMouseMove(WndtoPWL(pPageView, point),nFlags); 198 return TRUE; 199 } 200 201 return FALSE; 202 } 203 204 FX_BOOL CFFL_FormFiller::OnMouseWheel(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, short zDelta, const CPDF_Point& point) 205 { 206 if (!IsValid()) return FALSE; 207 208 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE)) 209 { 210 return pWnd->OnMouseWheel(zDelta, WndtoPWL(pPageView, point),nFlags); 211 } 212 213 return FALSE; 214 } 215 216 FX_BOOL CFFL_FormFiller::OnRButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) 217 { 218 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, TRUE)) 219 { 220 pWnd->OnRButtonDown(WndtoPWL(pPageView, point),nFlags); 221 return TRUE; 222 } 223 224 return FALSE; 225 } 226 227 FX_BOOL CFFL_FormFiller::OnRButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) 228 { 229 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) 230 { 231 pWnd->OnRButtonUp(WndtoPWL(pPageView, point),nFlags); 232 return TRUE; 233 } 234 235 return FALSE; 236 } 237 238 FX_BOOL CFFL_FormFiller::OnRButtonDblClk(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) 239 { 240 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) 241 { 242 pWnd->OnRButtonDblClk(WndtoPWL(pPageView, point),nFlags); 243 return TRUE; 244 } 245 246 return FALSE; 247 } 248 249 FX_BOOL CFFL_FormFiller::OnKeyDown(CPDFSDK_Annot* pAnnot, FX_UINT nKeyCode, FX_UINT nFlags) 250 { 251 if (IsValid()) 252 { 253 CPDFSDK_PageView* pPageView = this->GetCurPageView(); 254 ASSERT(pPageView != NULL); 255 256 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) 257 { 258 return pWnd->OnKeyDown(nKeyCode,nFlags); 259 } 260 } 261 262 return FALSE; 263 } 264 265 FX_BOOL CFFL_FormFiller::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags) 266 { 267 if (IsValid()) 268 { 269 CPDFSDK_PageView* pPageView = this->GetCurPageView(); 270 ASSERT(pPageView != NULL); 271 272 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) 273 { 274 return pWnd->OnChar(nChar,nFlags); 275 } 276 } 277 278 return FALSE; 279 } 280 281 void CFFL_FormFiller::OnDeSelected(CPDFSDK_Annot* pAnnot) 282 { 283 ASSERT(FALSE); 284 } 285 286 void CFFL_FormFiller::OnSelected(CPDFSDK_Annot* pAnnot) 287 { 288 ASSERT(FALSE); 289 } 290 291 FX_BOOL CFFL_FormFiller::OnSetFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) 292 { 293 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; 294 295 CPDF_Page * pPage = pWidget->GetPDFPage(); 296 CPDFSDK_Document * pDoc = m_pApp->GetCurrentDoc(); 297 CPDFSDK_PageView* pPageView = pDoc->GetPageView(pPage); 298 ASSERT(pPageView != NULL); 299 300 301 302 CPWL_Wnd * pWnd = NULL; 303 if ( (pWnd = GetPDFWindow(pPageView, TRUE))) 304 { 305 pWnd->SetFocus(); 306 } 307 308 m_bValid = TRUE; 309 310 311 312 313 m_bValid = TRUE; 314 FX_RECT rcRect = this->GetViewBBox(pPageView,pAnnot); 315 this->InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); 316 317 return TRUE; 318 } 319 320 FX_BOOL CFFL_FormFiller::OnKillFocus(CPDFSDK_Annot* pAnnot, FX_UINT nFlag) 321 { 322 if (IsValid()) 323 { 324 CPDFSDK_PageView* pPageView = this->GetCurPageView(); 325 ASSERT(pPageView != NULL); 326 327 CommitData(pPageView, nFlag); 328 329 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, FALSE)) 330 { 331 pWnd->KillFocus(); 332 } 333 334 switch (m_pWidget->GetFieldType()) 335 { 336 case FIELDTYPE_PUSHBUTTON: 337 case FIELDTYPE_CHECKBOX: 338 case FIELDTYPE_RADIOBUTTON: 339 EscapeFiller(pPageView, TRUE); 340 break; 341 default: 342 EscapeFiller(pPageView, FALSE); 343 break; 344 } 345 } 346 347 return TRUE; 348 } 349 350 FX_BOOL CFFL_FormFiller::IsValid() const 351 { 352 return m_bValid; 353 } 354 355 PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam() 356 { 357 ASSERT(m_pApp != NULL); 358 359 PWL_CREATEPARAM cp; 360 361 cp.pParentWnd = NULL; 362 cp.pProvider = this; 363 cp.rcRectWnd = GetPDFWindowRect(); 364 365 FX_DWORD dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE; 366 367 ASSERT(m_pWidget != NULL); 368 369 370 FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags(); 371 372 if (dwFieldFlag & FIELDFLAG_READONLY) 373 { 374 dwCreateFlags |= PWS_READONLY; 375 } 376 377 FX_COLORREF color; 378 if (m_pWidget->GetFillColor(color)) 379 { 380 cp.sBackgroundColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); 381 } 382 383 if (m_pWidget->GetBorderColor(color)) 384 { 385 cp.sBorderColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); 386 } 387 388 cp.sTextColor = CPWL_Color(COLORTYPE_GRAY,0); 389 390 if (m_pWidget->GetTextColor(color)) 391 { 392 cp.sTextColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color)); 393 } 394 395 cp.fFontSize = m_pWidget->GetFontSize(); 396 cp.dwBorderWidth = m_pWidget->GetBorderWidth(); 397 398 int nBorderStyle = m_pWidget->GetBorderStyle(); 399 400 switch (nBorderStyle) 401 { 402 case BBS_SOLID: 403 cp.nBorderStyle = PBS_SOLID; 404 break; 405 case BBS_DASH: 406 cp.nBorderStyle = PBS_DASH; 407 cp.sDash = CPWL_Dash(3,3,0); 408 break; 409 case BBS_BEVELED: 410 cp.nBorderStyle = PBS_BEVELED; 411 cp.dwBorderWidth *= 2; 412 break; 413 case BBS_INSET: 414 cp.nBorderStyle = PBS_INSET; 415 cp.dwBorderWidth *= 2; 416 break; 417 case BBS_UNDERLINE: 418 cp.nBorderStyle = PBS_UNDERLINED; 419 break; 420 } 421 422 if (cp.fFontSize <= 0) 423 { 424 dwCreateFlags |= PWS_AUTOFONTSIZE; 425 } 426 427 cp.dwFlags = dwCreateFlags; 428 cp.pSystemHandler = m_pApp->GetSysHandler(); 429 return cp; 430 } 431 432 CPWL_Wnd* CFFL_FormFiller::GetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bNew) 433 { 434 ASSERT(pPageView != NULL); 435 ASSERT(m_pWidget != NULL); 436 437 CPWL_Wnd* pWnd = NULL; 438 m_Maps.Lookup(pPageView, pWnd); 439 440 if (bNew) 441 { 442 if (pWnd) 443 { 444 CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pWnd->GetAttachedData(); 445 ASSERT(pPrivateData != NULL); 446 447 if (pPrivateData->nWidgetAge != m_pWidget->GetAppearanceAge()) 448 { 449 return this->ResetPDFWindow(pPageView, m_pWidget->GetValueAge() == pPrivateData->nValueAge); 450 } 451 } 452 else 453 { 454 PWL_CREATEPARAM cp = GetCreateParam(); 455 cp.hAttachedWnd = (FX_HWND)m_pWidget; 456 457 CFFL_PrivateData* pPrivateData = new CFFL_PrivateData; 458 pPrivateData->pWidget = m_pWidget; 459 pPrivateData->pPageView = pPageView; 460 pPrivateData->nWidgetAge = m_pWidget->GetAppearanceAge(); 461 pPrivateData->nValueAge = 0; 462 463 cp.pAttachedData = pPrivateData; 464 465 pWnd = NewPDFWindow(cp, pPageView); 466 467 if (pWnd) 468 { 469 m_Maps.SetAt(pPageView, pWnd); 470 } 471 } 472 } 473 474 return pWnd; 475 } 476 477 void CFFL_FormFiller::DestroyPDFWindow(CPDFSDK_PageView* pPageView) 478 { 479 CPWL_Wnd* pWnd = NULL; 480 m_Maps.Lookup(pPageView, pWnd); 481 482 if (pWnd) 483 { 484 CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData(); 485 pData->pPageView = NULL; 486 pWnd->Destroy(); 487 delete pWnd; 488 delete pData; 489 } 490 491 m_Maps.RemoveKey(pPageView); 492 } 493 494 CPDF_Matrix CFFL_FormFiller::GetWindowMatrix(void* pAttachedData) 495 { 496 if (CFFL_PrivateData* pPrivateData = (CFFL_PrivateData*)pAttachedData) 497 { 498 if (pPrivateData->pPageView) 499 { 500 CPDF_Matrix mtPageView; 501 pPrivateData->pPageView->GetCurrentMatrix(mtPageView); 502 CPDF_Matrix mt = GetCurMatrix(); 503 mt.Concat(mtPageView); 504 505 return mt; 506 } 507 } 508 return CPDF_Matrix(1,0,0,1,0,0); 509 } 510 511 CPDF_Matrix CFFL_FormFiller::GetCurMatrix() 512 { 513 CPDF_Matrix mt; 514 515 ASSERT(m_pWidget != NULL); 516 517 CPDF_Rect rcDA ; 518 m_pWidget->GetPDFAnnot()->GetRect(rcDA); 519 520 521 switch (m_pWidget->GetRotate()) 522 { 523 default: 524 case 0: 525 mt = CPDF_Matrix(1,0,0,1,0,0); 526 break; 527 case 90: 528 mt = CPDF_Matrix(0,1,-1,0,rcDA.right - rcDA.left,0); 529 break; 530 case 180: 531 mt = CPDF_Matrix(-1,0,0,-1,rcDA.right - rcDA.left,rcDA.top - rcDA.bottom); 532 break; 533 case 270: 534 mt = CPDF_Matrix(0,-1,1,0,0,rcDA.top - rcDA.bottom); 535 break; 536 } 537 mt.e += rcDA.left; 538 mt.f += rcDA.bottom; 539 540 return mt; 541 } 542 543 CFX_WideString CFFL_FormFiller::LoadPopupMenuString(int nIndex) 544 { 545 ASSERT(m_pApp != NULL); 546 547 return L""; 548 } 549 550 CPDF_Rect CFFL_FormFiller::GetPDFWindowRect() const 551 { 552 ASSERT(m_pWidget != NULL); 553 554 CPDF_Rect rectAnnot; 555 m_pWidget->GetPDFAnnot()->GetRect(rectAnnot); 556 557 FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left; 558 FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom; 559 560 561 if ((m_pWidget->GetRotate() / 90) & 0x01) 562 return CPDF_Rect(0,0,fHeight,fWidth); 563 else 564 return CPDF_Rect(0,0,fWidth,fHeight); 565 } 566 567 CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView() 568 { 569 570 CPDF_Page* pPage = m_pAnnot->GetPDFPage(); 571 CPDFSDK_Document* pSDKDoc = m_pApp->GetCurrentDoc(); 572 if(pSDKDoc) 573 { 574 return pSDKDoc->GetPageView(pPage); 575 } 576 return NULL; 577 } 578 579 CPDF_Rect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView) 580 { 581 if (CPWL_Wnd * pWnd = GetPDFWindow(pPageView, FALSE)) 582 { 583 CPDF_Rect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect())); 584 ASSERT(pPageView); 585 CPDF_Rect rcPage = pPageView->GetPDFPage()->GetPageBBox(); 586 if(rcPage.Contains(rcFocus)) 587 return rcFocus; 588 else 589 return CPDF_Rect(0,0,0,0); 590 } 591 return CPDF_Rect(0,0,0,0); 592 } 593 594 CPDF_Rect CFFL_FormFiller::FFLtoPWL(const CPDF_Rect& rect) 595 { 596 CPDF_Matrix mt; 597 mt.SetReverse(GetCurMatrix()); 598 599 CPDF_Rect temp = rect; 600 mt.TransformRect(temp); 601 602 return temp; 603 } 604 605 CPDF_Rect CFFL_FormFiller::PWLtoFFL(const CPDF_Rect& rect) 606 { 607 CPDF_Matrix mt = GetCurMatrix(); 608 609 CPDF_Rect temp = rect; 610 mt.TransformRect(temp); 611 612 return temp; 613 } 614 615 CPDF_Point CFFL_FormFiller::FFLtoPWL(const CPDF_Point& point) 616 { 617 CPDF_Matrix mt; 618 mt.SetReverse(GetCurMatrix()); 619 620 CPDF_Point pt = point; 621 mt.Transform(pt.x,pt.y); 622 623 return pt; 624 } 625 626 CPDF_Point CFFL_FormFiller::PWLtoFFL(const CPDF_Point & point) 627 { 628 CPDF_Matrix mt = GetCurMatrix(); 629 630 CPDF_Point pt = point; 631 mt.Transform(pt.x,pt.y); 632 633 return pt; 634 } 635 636 CPDF_Point CFFL_FormFiller::WndtoPWL(CPDFSDK_PageView* pPageView, const CPDF_Point& pt) 637 { 638 // ASSERT(pPageView != NULL); 639 // 640 // CPDF_Point point(0.0f, 0.0f); 641 // pPageView->WindowToDoc(pt.x, pt.y, point.x, point.y); 642 // 643 return FFLtoPWL(pt); 644 // return CPDF_Point(0, 0); 645 } 646 647 CPDF_Rect CFFL_FormFiller::FFLtoWnd(CPDFSDK_PageView* pPageView, const CPDF_Rect & rect) 648 { 649 // FX_RECT rcRet(0,0,0,0); 650 // 651 // ASSERT(pPageView != NULL); 652 // pPageView->DocToWindow(rect, rcRet); 653 // 654 return rect; 655 656 } 657 658 void CFFL_FormFiller::FFL_FreeData(void* pData) 659 { 660 ASSERT(pData != NULL); 661 662 delete (CFFL_PrivateData*)pData; 663 } 664 665 FX_BOOL CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, FX_UINT nFlag) 666 { 667 if (IsDataChanged(pPageView)) 668 { 669 //CFFL_IFormFiller* pIFormFiller = CFFL_Module::GetFormFiller(m_pApp); 670 CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();//NULL; 671 ASSERT(pIFormFiller != NULL); 672 673 FX_BOOL bRC = TRUE; 674 FX_BOOL bExit = FALSE; 675 676 pIFormFiller->OnKeyStrokeCommit(m_pWidget, pPageView, bRC, bExit, nFlag); 677 if (bExit) return TRUE; 678 if (!bRC) 679 { 680 this->ResetPDFWindow(pPageView, FALSE); 681 return TRUE; 682 } 683 684 pIFormFiller->OnValidate(m_pWidget, pPageView, bRC, bExit, nFlag); 685 if (bExit) return TRUE; 686 if (!bRC) 687 { 688 this->ResetPDFWindow(pPageView, FALSE); 689 return TRUE; 690 } 691 692 SaveData(pPageView); 693 694 pIFormFiller->OnCalculate(m_pWidget, pPageView, bExit,nFlag); 695 if (bExit) return TRUE; 696 697 pIFormFiller->OnFormat(m_pWidget, pPageView, bExit,nFlag); 698 } 699 700 return TRUE; 701 } 702 703 FX_BOOL CFFL_FormFiller::IsDataChanged(CPDFSDK_PageView* pPageView) 704 { 705 return FALSE; 706 } 707 708 void CFFL_FormFiller::SaveData(CPDFSDK_PageView* pPageView) 709 { 710 } 711 712 void CFFL_FormFiller::GetKeyStrokeData(CPDFSDK_PageView* pPageView, FFL_KeyStrokeData& data) 713 { 714 } 715 716 void CFFL_FormFiller::SetChangeMark() 717 { 718 m_pApp->FFI_OnChange(); 719 } 720 721 void CFFL_FormFiller::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, 722 PDFSDK_FieldAction& fa) 723 { 724 fa.sValue = m_pWidget->GetValue(); 725 } 726 727 void CFFL_FormFiller::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AActionType type, 728 const PDFSDK_FieldAction& fa) 729 { 730 } 731 732 FX_BOOL CFFL_FormFiller::IsActionDataChanged(CPDF_AAction::AActionType type, const PDFSDK_FieldAction& faOld, 733 const PDFSDK_FieldAction& faNew) 734 { 735 return FALSE; 736 } 737 738 void CFFL_FormFiller::SaveState(CPDFSDK_PageView* pPageView) 739 { 740 } 741 742 void CFFL_FormFiller::RestoreState(CPDFSDK_PageView* pPageView) 743 { 744 } 745 746 CPWL_Wnd* CFFL_FormFiller::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bRestoreValue) 747 { 748 return GetPDFWindow(pPageView, FALSE); 749 } 750 751 void CFFL_FormFiller::TimerProc() 752 { 753 754 } 755 756 IFX_SystemHandler* CFFL_FormFiller::GetSystemHandler() const 757 { 758 return m_pApp->GetSysHandler(); 759 // return NULL; 760 } 761 762 void CFFL_FormFiller::OnKeyStroke(FX_BOOL bKeyDown) 763 { 764 } 765 766 void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView, FX_BOOL bDestroyPDFWindow) 767 { 768 m_bValid = FALSE; 769 770 FX_RECT rcRect = this->GetViewBBox(pPageView, m_pWidget); 771 this->InvalidateRect(rcRect.left, rcRect.top, rcRect.right, rcRect.bottom); 772 773 if(bDestroyPDFWindow) 774 DestroyPDFWindow(pPageView); 775 } 776 777 FX_BOOL CFFL_FormFiller::CanCopy(CPDFSDK_Document* pDocument) 778 { 779 return FALSE; 780 } 781 782 FX_BOOL CFFL_FormFiller::CanCut(CPDFSDK_Document* pDocument) 783 { 784 return FALSE; 785 } 786 787 FX_BOOL CFFL_FormFiller::CanPaste(CPDFSDK_Document* pDocument) 788 { 789 return FALSE; 790 } 791 792 void CFFL_FormFiller::DoCopy(CPDFSDK_Document* pDocument) 793 { 794 } 795 796 void CFFL_FormFiller::DoCut(CPDFSDK_Document* pDocument) 797 { 798 } 799 800 void CFFL_FormFiller::DoPaste(CPDFSDK_Document* pDocument) 801 { 802 } 803 804 void CFFL_FormFiller::InvalidateRect(double left, double top, double right, double bottom) 805 { 806 CPDF_Page * pPage = m_pWidget->GetPDFPage(); 807 m_pApp->FFI_Invalidate(pPage, left, top, right, bottom); 808 } 809 810 /* ------------------------- CFFL_Button ------------------------- */ 811 812 CFFL_Button::CFFL_Button(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) : 813 CFFL_FormFiller(pApp, pWidget), 814 m_bMouseIn(FALSE), 815 m_bMouseDown(FALSE) 816 { 817 } 818 819 CFFL_Button::~CFFL_Button() 820 { 821 } 822 823 void CFFL_Button::OnMouseEnter(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) 824 { 825 m_bMouseIn = TRUE; 826 FX_RECT rect = this->GetViewBBox(pPageView,pAnnot); 827 this->InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); 828 // ::InvalidateRect(pPageView->GetPageViewWnd(), &this->GetViewBBox(pPageView, pAnnot), TRUE); 829 } 830 831 void CFFL_Button::OnMouseExit(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot) 832 { 833 m_bMouseIn = FALSE; 834 835 FX_RECT rect = this->GetViewBBox(pPageView,pAnnot); 836 this->InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); 837 // ::InvalidateRect(pPageView->GetPageViewWnd(), &this->GetViewBBox(pPageView, pAnnot), TRUE); 838 EndTimer(); 839 ASSERT(m_pWidget != NULL); 840 // m_pWidget->HideHint(); 841 } 842 843 FX_BOOL CFFL_Button::OnLButtonDown(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) 844 { 845 CPDF_Rect rcAnnot = pAnnot->GetRect(); 846 if(!rcAnnot.Contains(point.x, point.y)) 847 return FALSE; 848 849 m_bMouseDown = TRUE; 850 m_bValid = TRUE; 851 FX_RECT rect = this->GetViewBBox(pPageView, pAnnot); 852 this->InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); 853 // ::InvalidateRect(pPageView->GetPageViewWnd(), &this->GetViewBBox(pPageView, pAnnot), TRUE); 854 return TRUE; 855 } 856 857 FX_BOOL CFFL_Button::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) 858 { 859 CPDF_Rect rcAnnot = pAnnot->GetRect(); 860 if(!rcAnnot.Contains(point.x, point.y)) 861 return FALSE; 862 863 m_bMouseDown = FALSE; 864 m_pWidget->GetPDFPage(); 865 866 867 FX_RECT rect = this->GetViewBBox(pPageView, pAnnot); 868 this->InvalidateRect(rect.left, rect.top, rect.right, rect.bottom); 869 // ::InvalidateRect(pPageView->GetPageViewWnd(), &this->GetViewBBox(pPageView, pAnnot), TRUE); 870 return TRUE; 871 } 872 873 FX_BOOL CFFL_Button::OnMouseMove(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* pAnnot, FX_UINT nFlags, const CPDF_Point& point) 874 { 875 ASSERT(m_pApp != NULL); 876 877 return TRUE; 878 } 879 880 void CFFL_Button::OnDraw(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot, 881 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, 882 /*const CRect& rcWindow,*/ FX_DWORD dwFlags) 883 { 884 ASSERT(pPageView != NULL); 885 ASSERT(pAnnot != NULL); 886 887 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; 888 889 CPDF_FormControl* pCtrl = pWidget->GetFormControl(); 890 ASSERT(pCtrl != NULL); 891 892 CPDF_FormControl::HighlightingMode eHM = pCtrl->GetHighlightingMode(); 893 894 if (eHM == CPDF_FormControl::Push) 895 { 896 if (m_bMouseDown) 897 { 898 if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Down)) 899 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Down, NULL); 900 else 901 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); 902 } 903 else if (m_bMouseIn) 904 { 905 if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Rollover)) 906 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Rollover, NULL); 907 else 908 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); 909 } 910 else 911 { 912 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); 913 } 914 } 915 else 916 pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, NULL); 917 } 918 919 920 void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView *pPageView, /*HDC hDC,*/ CPDFSDK_Annot* pAnnot, 921 CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device, 922 /*const CRect& rcWindow, */FX_DWORD dwFlags) 923 { 924 OnDraw(pPageView, pAnnot, pDevice, pUser2Device, dwFlags); 925 } 926