summaryrefslogtreecommitdiff
path: root/fpdfsdk/formfiller/cffl_formfiller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/formfiller/cffl_formfiller.cpp')
-rw-r--r--fpdfsdk/formfiller/cffl_formfiller.cpp244
1 files changed, 68 insertions, 176 deletions
diff --git a/fpdfsdk/formfiller/cffl_formfiller.cpp b/fpdfsdk/formfiller/cffl_formfiller.cpp
index f45a52cd21..31f6963348 100644
--- a/fpdfsdk/formfiller/cffl_formfiller.cpp
+++ b/fpdfsdk/formfiller/cffl_formfiller.cpp
@@ -17,11 +17,13 @@
#include "fpdfsdk/fsdk_common.h"
#include "fpdfsdk/pdfwindow/cpwl_utils.h"
-#define GetRed(rgb) ((uint8_t)(rgb))
-#define GetGreen(rgb) ((uint8_t)(((uint16_t)(rgb)) >> 8))
-#define GetBlue(rgb) ((uint8_t)((rgb) >> 16))
+namespace {
-#define FFL_HINT_ELAPSE 800
+CPDFSDK_Widget* CPDFSDKAnnotToWidget(CPDFSDK_Annot* annot) {
+ return static_cast<CPDFSDK_Widget*>(annot);
+}
+
+} // namespace
CFFL_FormFiller::CFFL_FormFiller(CPDFSDK_FormFillEnvironment* pFormFillEnv,
CPDFSDK_Widget* pWidget)
@@ -36,7 +38,8 @@ CFFL_FormFiller::~CFFL_FormFiller() {
void CFFL_FormFiller::DestroyWindows() {
for (const auto& it : m_Maps) {
CPWL_Wnd* pWnd = it.second;
- CFFL_PrivateData* pData = (CFFL_PrivateData*)pWnd->GetAttachedData();
+ CFFL_PrivateData* pData =
+ static_cast<CFFL_PrivateData*>(pWnd->GetAttachedData());
pWnd->InvalidateProvider(this);
pWnd->Destroy();
delete pWnd;
@@ -47,16 +50,13 @@ void CFFL_FormFiller::DestroyWindows() {
void CFFL_FormFiller::SetWindowRect(CPDFSDK_PageView* pPageView,
const CFX_FloatRect& rcWindow) {
- if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) {
+ if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false))
pWnd->Move(CFX_FloatRect(rcWindow), true, false);
- }
}
CFX_FloatRect CFFL_FormFiller::GetWindowRect(CPDFSDK_PageView* pPageView) {
- if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) {
- return pWnd->GetWindowRect();
- }
- return CFX_FloatRect();
+ CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false);
+ return pWnd ? pWnd->GetWindowRect() : CFX_FloatRect();
}
FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView* pPageView,
@@ -65,21 +65,15 @@ FX_RECT CFFL_FormFiller::GetViewBBox(CPDFSDK_PageView* pPageView,
ASSERT(pAnnot);
CFX_FloatRect rcAnnot = m_pWidget->GetRect();
-
- if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) {
- CFX_FloatRect rcWindow = pWnd->GetWindowRect();
- rcAnnot = PWLtoFFL(rcWindow);
- }
+ if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false))
+ rcAnnot = PWLtoFFL(pWnd->GetWindowRect());
CFX_FloatRect rcWin = rcAnnot;
-
CFX_FloatRect rcFocus = GetFocusBox(pPageView);
if (!rcFocus.IsEmpty())
rcWin.Union(rcFocus);
- CFX_FloatRect rect = CPWL_Utils::InflateRect(rcWin, 1);
-
- return rect.GetOuterRect();
+ return CPWL_Utils::InflateRect(rcWin, 1).GetOuterRect();
}
void CFFL_FormFiller::OnDraw(CPDFSDK_PageView* pPageView,
@@ -92,20 +86,22 @@ void CFFL_FormFiller::OnDraw(CPDFSDK_PageView* pPageView,
CFX_Matrix mt = GetCurMatrix();
mt.Concat(*pUser2Device);
pWnd->DrawAppearance(pDevice, &mt);
- } else {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
- if (CFFL_InteractiveFormFiller::IsVisible(pWidget))
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal,
- nullptr);
+ return;
}
+
+ CPDFSDK_Widget* pWidget = CPDFSDKAnnotToWidget(pAnnot);
+ if (!CFFL_InteractiveFormFiller::IsVisible(pWidget))
+ return;
+
+ pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
}
void CFFL_FormFiller::OnDrawDeactive(CPDFSDK_PageView* pPageView,
CPDFSDK_Annot* pAnnot,
CFX_RenderDevice* pDevice,
CFX_Matrix* pUser2Device) {
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
+ CPDFSDKAnnotToWidget(pAnnot)->DrawAppearance(pDevice, pUser2Device,
+ CPDF_Annot::Normal, nullptr);
}
void CFFL_FormFiller::OnMouseEnter(CPDFSDK_PageView* pPageView,
@@ -262,12 +258,8 @@ void CFFL_FormFiller::KillFocusForAnnot(CPDFSDK_Annot* pAnnot, uint32_t nFlag) {
return;
CPDFSDK_PageView* pPageView = GetCurPageView(false);
- if (!pPageView)
+ if (!pPageView || !CommitData(pPageView, nFlag))
return;
-
- if (!CommitData(pPageView, nFlag))
- return;
-
if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false))
pWnd->KillFocus();
@@ -297,26 +289,19 @@ PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam() {
uint32_t dwCreateFlags = PWS_BORDER | PWS_BACKGROUND | PWS_VISIBLE;
uint32_t dwFieldFlag = m_pWidget->GetFieldFlags();
- if (dwFieldFlag & FIELDFLAG_READONLY) {
+ if (dwFieldFlag & FIELDFLAG_READONLY)
dwCreateFlags |= PWS_READONLY;
- }
FX_COLORREF color;
- if (m_pWidget->GetFillColor(color)) {
- cp.sBackgroundColor =
- CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
- }
-
- if (m_pWidget->GetBorderColor(color)) {
- cp.sBorderColor =
- CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
- }
+ if (m_pWidget->GetFillColor(color))
+ cp.sBackgroundColor = CPWL_Color(color);
+ if (m_pWidget->GetBorderColor(color))
+ cp.sBorderColor = CPWL_Color(color);
cp.sTextColor = CPWL_Color(COLORTYPE_GRAY, 0);
- if (m_pWidget->GetTextColor(color)) {
- cp.sTextColor = CPWL_Color(GetRed(color), GetGreen(color), GetBlue(color));
- }
+ if (m_pWidget->GetTextColor(color))
+ cp.sTextColor = CPWL_Color(color);
cp.fFontSize = m_pWidget->GetFontSize();
cp.dwBorderWidth = m_pWidget->GetBorderWidth();
@@ -327,8 +312,6 @@ PWL_CREATEPARAM CFFL_FormFiller::GetCreateParam() {
cp.sDash = CPWL_Dash(3, 3, 0);
break;
case BorderStyle::BEVELED:
- cp.dwBorderWidth *= 2;
- break;
case BorderStyle::INSET:
cp.dwBorderWidth *= 2;
break;
@@ -408,9 +391,6 @@ CFX_Matrix CFFL_FormFiller::GetCurMatrix() {
CFX_Matrix mt;
CFX_FloatRect rcDA = m_pWidget->GetPDFAnnot()->GetRect();
switch (m_pWidget->GetRotate()) {
- default:
- case 0:
- break;
case 90:
mt = CFX_Matrix(0, 1, -1, 0, rcDA.right - rcDA.left, 0);
break;
@@ -421,6 +401,9 @@ CFX_Matrix CFFL_FormFiller::GetCurMatrix() {
case 270:
mt = CFX_Matrix(0, -1, 1, 0, 0, rcDA.top - rcDA.bottom);
break;
+ case 0:
+ default:
+ break;
}
mt.e += rcDA.left;
mt.f += rcDA.bottom;
@@ -444,13 +427,14 @@ CPDFSDK_PageView* CFFL_FormFiller::GetCurPageView(bool renew) {
}
CFX_FloatRect CFFL_FormFiller::GetFocusBox(CPDFSDK_PageView* pPageView) {
- if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false)) {
- CFX_FloatRect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect()));
- CFX_FloatRect rcPage = pPageView->GetPDFPage()->GetPageBBox();
- if (rcPage.Contains(rcFocus))
- return rcFocus;
- }
- return CFX_FloatRect();
+ CPWL_Wnd* pWnd = GetPDFWindow(pPageView, false);
+ if (!pWnd)
+ return CFX_FloatRect();
+
+ CFX_FloatRect rcFocus = FFLtoWnd(pPageView, PWLtoFFL(pWnd->GetFocusRect()));
+ return pPageView->GetPDFPage()->GetPageBBox().Contains(rcFocus)
+ ? rcFocus
+ : CFX_FloatRect();
}
CFX_FloatRect CFFL_FormFiller::FFLtoPWL(const CFX_FloatRect& rect) {
@@ -484,38 +468,40 @@ CFX_FloatRect CFFL_FormFiller::FFLtoWnd(CPDFSDK_PageView* pPageView,
}
bool CFFL_FormFiller::CommitData(CPDFSDK_PageView* pPageView, uint32_t nFlag) {
- if (IsDataChanged(pPageView)) {
- CFFL_InteractiveFormFiller* pFormFiller =
- m_pFormFillEnv->GetInteractiveFormFiller();
- CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget.Get());
-
- if (!pFormFiller->OnKeyStrokeCommit(&pObserved, pPageView, nFlag)) {
- if (!pObserved)
- return false;
- ResetPDFWindow(pPageView, false);
- return true;
- }
- if (!pObserved)
- return false;
+ if (!IsDataChanged(pPageView))
+ return true;
- if (!pFormFiller->OnValidate(&pObserved, pPageView, nFlag)) {
- if (!pObserved)
- return false;
- ResetPDFWindow(pPageView, false);
- return true;
- }
- if (!pObserved)
- return false;
+ CFFL_InteractiveFormFiller* pFormFiller =
+ m_pFormFillEnv->GetInteractiveFormFiller();
+ CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget.Get());
- SaveData(pPageView);
- pFormFiller->OnCalculate(&pObserved, pPageView, nFlag);
+ if (!pFormFiller->OnKeyStrokeCommit(&pObserved, pPageView, nFlag)) {
if (!pObserved)
return false;
+ ResetPDFWindow(pPageView, false);
+ return true;
+ }
+ if (!pObserved)
+ return false;
- pFormFiller->OnFormat(&pObserved, pPageView, nFlag);
+ if (!pFormFiller->OnValidate(&pObserved, pPageView, nFlag)) {
if (!pObserved)
return false;
+ ResetPDFWindow(pPageView, false);
+ return true;
}
+ if (!pObserved)
+ return false;
+
+ SaveData(pPageView);
+ pFormFiller->OnCalculate(&pObserved, pPageView, nFlag);
+ if (!pObserved)
+ return false;
+
+ pFormFiller->OnFormat(&pObserved, pPageView, nFlag);
+ if (!pObserved)
+ return false;
+
return true;
}
@@ -578,97 +564,3 @@ void CFFL_FormFiller::EscapeFiller(CPDFSDK_PageView* pPageView,
void CFFL_FormFiller::InvalidateRect(const FX_RECT& rect) {
m_pFormFillEnv->Invalidate(m_pWidget->GetUnderlyingPage(), rect);
}
-
-CFFL_Button::CFFL_Button(CPDFSDK_FormFillEnvironment* pApp,
- CPDFSDK_Widget* pWidget)
- : CFFL_FormFiller(pApp, pWidget), m_bMouseIn(false), m_bMouseDown(false) {}
-
-CFFL_Button::~CFFL_Button() {}
-
-void CFFL_Button::OnMouseEnter(CPDFSDK_PageView* pPageView,
- CPDFSDK_Annot* pAnnot) {
- m_bMouseIn = true;
- InvalidateRect(GetViewBBox(pPageView, pAnnot));
-}
-
-void CFFL_Button::OnMouseExit(CPDFSDK_PageView* pPageView,
- CPDFSDK_Annot* pAnnot) {
- m_bMouseIn = false;
-
- InvalidateRect(GetViewBBox(pPageView, pAnnot));
- EndTimer();
- ASSERT(m_pWidget);
-}
-
-bool CFFL_Button::OnLButtonDown(CPDFSDK_PageView* pPageView,
- CPDFSDK_Annot* pAnnot,
- uint32_t nFlags,
- const CFX_PointF& point) {
- if (!pAnnot->GetRect().Contains(point))
- return false;
-
- m_bMouseDown = true;
- m_bValid = true;
- InvalidateRect(GetViewBBox(pPageView, pAnnot));
- return true;
-}
-
-bool CFFL_Button::OnLButtonUp(CPDFSDK_PageView* pPageView,
- CPDFSDK_Annot* pAnnot,
- uint32_t nFlags,
- const CFX_PointF& point) {
- if (!pAnnot->GetRect().Contains(point))
- return false;
-
- m_bMouseDown = false;
- m_pWidget->GetPDFPage();
-
- InvalidateRect(GetViewBBox(pPageView, pAnnot));
- return true;
-}
-
-bool CFFL_Button::OnMouseMove(CPDFSDK_PageView* pPageView,
- CPDFSDK_Annot* pAnnot,
- uint32_t nFlags,
- const CFX_PointF& point) {
- return true;
-}
-
-void CFFL_Button::OnDraw(CPDFSDK_PageView* pPageView,
- CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice,
- CFX_Matrix* pUser2Device) {
- ASSERT(pPageView);
- CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot;
- CPDF_FormControl* pCtrl = pWidget->GetFormControl();
- CPDF_FormControl::HighlightingMode eHM = pCtrl->GetHighlightingMode();
-
- if (eHM != CPDF_FormControl::Push) {
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
- return;
- }
-
- if (m_bMouseDown) {
- if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Down))
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Down, nullptr);
- else
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal,
- nullptr);
- } else if (m_bMouseIn) {
- if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Rollover))
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Rollover,
- nullptr);
- else
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal,
- nullptr);
- } else {
- pWidget->DrawAppearance(pDevice, pUser2Device, CPDF_Annot::Normal, nullptr);
- }
-}
-
-void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView* pPageView,
- CPDFSDK_Annot* pAnnot,
- CFX_RenderDevice* pDevice,
- CFX_Matrix* pUser2Device) {
- OnDraw(pPageView, pAnnot, pDevice, pUser2Device);
-}