From 0ce11eef157b791c661d7e82e1c5641605b9f03d Mon Sep 17 00:00:00 2001 From: dsinclair Date: Wed, 23 Nov 2016 16:03:10 -0800 Subject: Rename IFWL classes which do not have CFWL equivalents This CL moves the IFWL classes that do not have CFWL class buddies to have the CFWL name. This CL leaves the tree in a weird state of having CFWL be two hierarchies, one of which is intertwined with the IFWL hierarchy. This should be commited just before the CL to move the rest of IFWL to CFWL. Review-Url: https://codereview.chromium.org/2525083002 --- BUILD.gn | 40 +- core/fxge/skia/fx_skia_device.cpp | 4 +- xfa/fwl/core/cfwl_caret.cpp | 108 ++++ xfa/fwl/core/cfwl_caret.h | 57 ++ xfa/fwl/core/cfwl_comboboxproxy.cpp | 119 ++++ xfa/fwl/core/cfwl_comboboxproxy.h | 41 ++ xfa/fwl/core/cfwl_comboedit.cpp | 75 +++ xfa/fwl/core/cfwl_comboedit.h | 35 + xfa/fwl/core/cfwl_combolist.cpp | 249 +++++++ xfa/fwl/core/cfwl_combolist.h | 43 ++ xfa/fwl/core/cfwl_datetimeedit.cpp | 62 ++ xfa/fwl/core/cfwl_datetimeedit.h | 30 + xfa/fwl/core/cfwl_form.cpp | 639 ++++++++++++++++++ xfa/fwl/core/cfwl_form.h | 101 +++ xfa/fwl/core/cfwl_formproxy.cpp | 40 ++ xfa/fwl/core/cfwl_formproxy.h | 32 + xfa/fwl/core/cfwl_monthcalendar.cpp | 1111 ++++++++++++++++++++++++++++++++ xfa/fwl/core/cfwl_monthcalendar.h | 228 +++++++ xfa/fwl/core/cfwl_notedriver.cpp | 12 +- xfa/fwl/core/cfwl_scrollbar.cpp | 563 ++++++++++++++++ xfa/fwl/core/cfwl_scrollbar.h | 150 +++++ xfa/fwl/core/cfwl_spinbutton.cpp | 381 +++++++++++ xfa/fwl/core/cfwl_spinbutton.h | 76 +++ xfa/fwl/core/cfwl_widgetmgr.cpp | 2 +- xfa/fwl/core/ifwl_barcode.h | 2 +- xfa/fwl/core/ifwl_caret.cpp | 108 ---- xfa/fwl/core/ifwl_caret.h | 57 -- xfa/fwl/core/ifwl_combobox.cpp | 18 +- xfa/fwl/core/ifwl_combobox.h | 20 +- xfa/fwl/core/ifwl_comboboxproxy.cpp | 119 ---- xfa/fwl/core/ifwl_comboboxproxy.h | 41 -- xfa/fwl/core/ifwl_comboedit.cpp | 75 --- xfa/fwl/core/ifwl_comboedit.h | 35 - xfa/fwl/core/ifwl_combolist.cpp | 249 ------- xfa/fwl/core/ifwl_combolist.h | 43 -- xfa/fwl/core/ifwl_datetimeedit.cpp | 62 -- xfa/fwl/core/ifwl_datetimeedit.h | 30 - xfa/fwl/core/ifwl_datetimepicker.cpp | 10 +- xfa/fwl/core/ifwl_datetimepicker.h | 16 +- xfa/fwl/core/ifwl_edit.cpp | 18 +- xfa/fwl/core/ifwl_edit.h | 16 +- xfa/fwl/core/ifwl_form.cpp | 639 ------------------ xfa/fwl/core/ifwl_form.h | 101 --- xfa/fwl/core/ifwl_formproxy.cpp | 40 -- xfa/fwl/core/ifwl_formproxy.h | 32 - xfa/fwl/core/ifwl_listbox.cpp | 8 +- xfa/fwl/core/ifwl_listbox.h | 8 +- xfa/fwl/core/ifwl_monthcalendar.cpp | 1111 -------------------------------- xfa/fwl/core/ifwl_monthcalendar.h | 228 ------- xfa/fwl/core/ifwl_scrollbar.cpp | 563 ---------------- xfa/fwl/core/ifwl_scrollbar.h | 150 ----- xfa/fwl/core/ifwl_spinbutton.cpp | 381 ----------- xfa/fwl/core/ifwl_spinbutton.h | 76 --- xfa/fwl/core/ifwl_widget.cpp | 2 +- xfa/fwl/theme/cfwl_carettp.cpp | 2 +- xfa/fwl/theme/cfwl_monthcalendartp.cpp | 2 +- xfa/fwl/theme/cfwl_scrollbartp.cpp | 2 +- xfa/fxfa/app/xfa_fwltheme.cpp | 6 +- 58 files changed, 4234 insertions(+), 4234 deletions(-) create mode 100644 xfa/fwl/core/cfwl_caret.cpp create mode 100644 xfa/fwl/core/cfwl_caret.h create mode 100644 xfa/fwl/core/cfwl_comboboxproxy.cpp create mode 100644 xfa/fwl/core/cfwl_comboboxproxy.h create mode 100644 xfa/fwl/core/cfwl_comboedit.cpp create mode 100644 xfa/fwl/core/cfwl_comboedit.h create mode 100644 xfa/fwl/core/cfwl_combolist.cpp create mode 100644 xfa/fwl/core/cfwl_combolist.h create mode 100644 xfa/fwl/core/cfwl_datetimeedit.cpp create mode 100644 xfa/fwl/core/cfwl_datetimeedit.h create mode 100644 xfa/fwl/core/cfwl_form.cpp create mode 100644 xfa/fwl/core/cfwl_form.h create mode 100644 xfa/fwl/core/cfwl_formproxy.cpp create mode 100644 xfa/fwl/core/cfwl_formproxy.h create mode 100644 xfa/fwl/core/cfwl_monthcalendar.cpp create mode 100644 xfa/fwl/core/cfwl_monthcalendar.h create mode 100644 xfa/fwl/core/cfwl_scrollbar.cpp create mode 100644 xfa/fwl/core/cfwl_scrollbar.h create mode 100644 xfa/fwl/core/cfwl_spinbutton.cpp create mode 100644 xfa/fwl/core/cfwl_spinbutton.h delete mode 100644 xfa/fwl/core/ifwl_caret.cpp delete mode 100644 xfa/fwl/core/ifwl_caret.h delete mode 100644 xfa/fwl/core/ifwl_comboboxproxy.cpp delete mode 100644 xfa/fwl/core/ifwl_comboboxproxy.h delete mode 100644 xfa/fwl/core/ifwl_comboedit.cpp delete mode 100644 xfa/fwl/core/ifwl_comboedit.h delete mode 100644 xfa/fwl/core/ifwl_combolist.cpp delete mode 100644 xfa/fwl/core/ifwl_combolist.h delete mode 100644 xfa/fwl/core/ifwl_datetimeedit.cpp delete mode 100644 xfa/fwl/core/ifwl_datetimeedit.h delete mode 100644 xfa/fwl/core/ifwl_form.cpp delete mode 100644 xfa/fwl/core/ifwl_form.h delete mode 100644 xfa/fwl/core/ifwl_formproxy.cpp delete mode 100644 xfa/fwl/core/ifwl_formproxy.h delete mode 100644 xfa/fwl/core/ifwl_monthcalendar.cpp delete mode 100644 xfa/fwl/core/ifwl_monthcalendar.h delete mode 100644 xfa/fwl/core/ifwl_scrollbar.cpp delete mode 100644 xfa/fwl/core/ifwl_scrollbar.h delete mode 100644 xfa/fwl/core/ifwl_spinbutton.cpp delete mode 100644 xfa/fwl/core/ifwl_spinbutton.h diff --git a/BUILD.gn b/BUILD.gn index 37ae9e0580..00a22f0125 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1189,10 +1189,20 @@ if (pdf_enable_xfa) { "xfa/fwl/core/cfwl_app.h", "xfa/fwl/core/cfwl_barcode.cpp", "xfa/fwl/core/cfwl_barcode.h", + "xfa/fwl/core/cfwl_caret.cpp", + "xfa/fwl/core/cfwl_caret.h", "xfa/fwl/core/cfwl_checkbox.cpp", "xfa/fwl/core/cfwl_checkbox.h", "xfa/fwl/core/cfwl_combobox.cpp", "xfa/fwl/core/cfwl_combobox.h", + "xfa/fwl/core/cfwl_comboboxproxy.cpp", + "xfa/fwl/core/cfwl_comboboxproxy.h", + "xfa/fwl/core/cfwl_comboedit.cpp", + "xfa/fwl/core/cfwl_comboedit.h", + "xfa/fwl/core/cfwl_combolist.cpp", + "xfa/fwl/core/cfwl_combolist.h", + "xfa/fwl/core/cfwl_datetimeedit.cpp", + "xfa/fwl/core/cfwl_datetimeedit.h", "xfa/fwl/core/cfwl_datetimepicker.cpp", "xfa/fwl/core/cfwl_datetimepicker.h", "xfa/fwl/core/cfwl_edit.cpp", @@ -1237,12 +1247,18 @@ if (pdf_enable_xfa) { "xfa/fwl/core/cfwl_evttextfull.h", "xfa/fwl/core/cfwl_evtvalidate.cpp", "xfa/fwl/core/cfwl_evtvalidate.h", + "xfa/fwl/core/cfwl_form.cpp", + "xfa/fwl/core/cfwl_form.h", + "xfa/fwl/core/cfwl_formproxy.cpp", + "xfa/fwl/core/cfwl_formproxy.h", "xfa/fwl/core/cfwl_listbox.cpp", "xfa/fwl/core/cfwl_listbox.h", "xfa/fwl/core/cfwl_listitem.cpp", "xfa/fwl/core/cfwl_listitem.h", "xfa/fwl/core/cfwl_message.cpp", "xfa/fwl/core/cfwl_message.h", + "xfa/fwl/core/cfwl_monthcalendar.cpp", + "xfa/fwl/core/cfwl_monthcalendar.h", "xfa/fwl/core/cfwl_msgkey.cpp", "xfa/fwl/core/cfwl_msgkey.h", "xfa/fwl/core/cfwl_msgkillfocus.cpp", @@ -1261,6 +1277,10 @@ if (pdf_enable_xfa) { "xfa/fwl/core/cfwl_picturebox.h", "xfa/fwl/core/cfwl_pushbutton.cpp", "xfa/fwl/core/cfwl_pushbutton.h", + "xfa/fwl/core/cfwl_scrollbar.cpp", + "xfa/fwl/core/cfwl_scrollbar.h", + "xfa/fwl/core/cfwl_spinbutton.cpp", + "xfa/fwl/core/cfwl_spinbutton.h", "xfa/fwl/core/cfwl_sysbtn.cpp", "xfa/fwl/core/cfwl_sysbtn.h", "xfa/fwl/core/cfwl_themebackground.h", @@ -1285,40 +1305,20 @@ if (pdf_enable_xfa) { "xfa/fwl/core/ifwl_adaptertimermgr.h", "xfa/fwl/core/ifwl_barcode.cpp", "xfa/fwl/core/ifwl_barcode.h", - "xfa/fwl/core/ifwl_caret.cpp", - "xfa/fwl/core/ifwl_caret.h", "xfa/fwl/core/ifwl_checkbox.cpp", "xfa/fwl/core/ifwl_checkbox.h", "xfa/fwl/core/ifwl_combobox.cpp", "xfa/fwl/core/ifwl_combobox.h", - "xfa/fwl/core/ifwl_comboboxproxy.cpp", - "xfa/fwl/core/ifwl_comboboxproxy.h", - "xfa/fwl/core/ifwl_comboedit.cpp", - "xfa/fwl/core/ifwl_comboedit.h", - "xfa/fwl/core/ifwl_combolist.cpp", - "xfa/fwl/core/ifwl_combolist.h", - "xfa/fwl/core/ifwl_datetimeedit.cpp", - "xfa/fwl/core/ifwl_datetimeedit.h", "xfa/fwl/core/ifwl_datetimepicker.cpp", "xfa/fwl/core/ifwl_datetimepicker.h", "xfa/fwl/core/ifwl_edit.cpp", "xfa/fwl/core/ifwl_edit.h", - "xfa/fwl/core/ifwl_form.cpp", - "xfa/fwl/core/ifwl_form.h", - "xfa/fwl/core/ifwl_formproxy.cpp", - "xfa/fwl/core/ifwl_formproxy.h", "xfa/fwl/core/ifwl_listbox.cpp", "xfa/fwl/core/ifwl_listbox.h", - "xfa/fwl/core/ifwl_monthcalendar.cpp", - "xfa/fwl/core/ifwl_monthcalendar.h", "xfa/fwl/core/ifwl_picturebox.cpp", "xfa/fwl/core/ifwl_picturebox.h", "xfa/fwl/core/ifwl_pushbutton.cpp", "xfa/fwl/core/ifwl_pushbutton.h", - "xfa/fwl/core/ifwl_scrollbar.cpp", - "xfa/fwl/core/ifwl_scrollbar.h", - "xfa/fwl/core/ifwl_spinbutton.cpp", - "xfa/fwl/core/ifwl_spinbutton.h", "xfa/fwl/core/ifwl_themeprovider.h", "xfa/fwl/core/ifwl_widget.cpp", "xfa/fwl/core/ifwl_widget.h", diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp index 5f46d0d93a..cf4f42897d 100644 --- a/core/fxge/skia/fx_skia_device.cpp +++ b/core/fxge/skia/fx_skia_device.cpp @@ -30,12 +30,12 @@ #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkPath.h" +#include "third_party/skia/include/core/SkShader.h" #include "third_party/skia/include/core/SkStream.h" #include "third_party/skia/include/core/SkTypeface.h" #include "third_party/skia/include/effects/SkDashPathEffect.h" -#include "third_party/skia/include/pathops/SkPathOps.h" -#include "third_party/skia/include/core/SkShader.h" #include "third_party/skia/include/effects/SkGradientShader.h" +#include "third_party/skia/include/pathops/SkPathOps.h" #ifdef _SKIA_SUPPORT_ #include "third_party/skia/include/core/SkColorFilter.h" diff --git a/xfa/fwl/core/cfwl_caret.cpp b/xfa/fwl/core/cfwl_caret.cpp new file mode 100644 index 0000000000..97cf1e9682 --- /dev/null +++ b/xfa/fwl/core/cfwl_caret.cpp @@ -0,0 +1,108 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/core/cfwl_caret.h" + +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/core/cfwl_notedriver.h" +#include "xfa/fwl/core/cfwl_themebackground.h" +#include "xfa/fwl/core/cfwl_timerinfo.h" +#include "xfa/fwl/core/cfwl_widgetproperties.h" +#include "xfa/fwl/core/ifwl_themeprovider.h" + +namespace { + +const uint32_t kFrequency = 400; + +} // namespace + +CFWL_Caret::CFWL_Caret(const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter) + : IFWL_Widget(app, std::move(properties), pOuter), + m_pTimer(new CFWL_Caret::Timer(this)), + m_pTimerInfo(nullptr) { + SetStates(FWL_STATE_CAT_HightLight); +} + +CFWL_Caret::~CFWL_Caret() { + if (m_pTimerInfo) { + m_pTimerInfo->StopTimer(); + m_pTimerInfo = nullptr; + } +} + +FWL_Type CFWL_Caret::GetClassID() const { + return FWL_Type::Caret; +} + +void CFWL_Caret::Update() {} + +void CFWL_Caret::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + if (!m_pProperties->m_pThemeProvider) + return; + + DrawCaretBK(pGraphics, m_pProperties->m_pThemeProvider, pMatrix); +} + +void CFWL_Caret::ShowCaret(bool bFlag) { + if (m_pTimerInfo) { + m_pTimerInfo->StopTimer(); + m_pTimerInfo = nullptr; + } + if (bFlag) + m_pTimerInfo = m_pTimer->StartTimer(kFrequency, true); + + SetStates(FWL_WGTSTATE_Invisible, !bFlag); +} + +void CFWL_Caret::DrawCaretBK(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + if (!(m_pProperties->m_dwStates & FWL_STATE_CAT_HightLight)) + return; + + CFX_RectF rect; + GetWidgetRect(rect); + rect.Set(0, 0, rect.width, rect.height); + + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_pGraphics = pGraphics; + param.m_rtPart = rect; + param.m_iPart = CFWL_Part::Background; + param.m_dwStates = CFWL_PartState_HightLight; + if (pMatrix) + param.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶m); +} + +void CFWL_Caret::OnProcessMessage(CFWL_Message* pMessage) {} + +void CFWL_Caret::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +CFWL_Caret::Timer::Timer(CFWL_Caret* pCaret) : CFWL_Timer(pCaret) {} + +void CFWL_Caret::Timer::Run(CFWL_TimerInfo* pTimerInfo) { + CFWL_Caret* pCaret = static_cast(m_pWidget); + pCaret->SetStates(FWL_STATE_CAT_HightLight, + !(pCaret->GetStates() & FWL_STATE_CAT_HightLight)); + + CFX_RectF rt; + pCaret->GetWidgetRect(rt); + rt.Set(0, 0, rt.width + 1, rt.height); + pCaret->Repaint(&rt); +} diff --git a/xfa/fwl/core/cfwl_caret.h b/xfa/fwl/core/cfwl_caret.h new file mode 100644 index 0000000000..9e68cdf09d --- /dev/null +++ b/xfa/fwl/core/cfwl_caret.h @@ -0,0 +1,57 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CORE_CFWL_CARET_H_ +#define XFA_FWL_CORE_CFWL_CARET_H_ + +#include + +#include "xfa/fwl/core/cfwl_timer.h" +#include "xfa/fwl/core/ifwl_widget.h" +#include "xfa/fxgraphics/cfx_color.h" + +class CFWL_WidgetProperties; +class IFWL_Widget; + +#define FWL_STATE_CAT_HightLight 1 + +class CFWL_Caret : public IFWL_Widget { + public: + CFWL_Caret(const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter); + ~CFWL_Caret() override; + + // IFWL_Widget + FWL_Type GetClassID() const override; + void DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + void Update() override; + + void ShowCaret(bool bFlag = true); + + private: + class Timer : public CFWL_Timer { + public: + explicit Timer(CFWL_Caret* pCaret); + ~Timer() override {} + + void Run(CFWL_TimerInfo* hTimer) override; + }; + friend class CFWL_Caret::Timer; + + void DrawCaretBK(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + + std::unique_ptr m_pTimer; + CFWL_TimerInfo* m_pTimerInfo; // not owned. +}; + +#endif // XFA_FWL_CORE_CFWL_CARET_H_ diff --git a/xfa/fwl/core/cfwl_comboboxproxy.cpp b/xfa/fwl/core/cfwl_comboboxproxy.cpp new file mode 100644 index 0000000000..c367eefb9c --- /dev/null +++ b/xfa/fwl/core/cfwl_comboboxproxy.cpp @@ -0,0 +1,119 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/core/cfwl_comboboxproxy.h" + +#include +#include + +#include "xfa/fwl/core/cfwl_app.h" +#include "xfa/fwl/core/cfwl_msgkillfocus.h" +#include "xfa/fwl/core/cfwl_msgmouse.h" +#include "xfa/fwl/core/cfwl_notedriver.h" +#include "xfa/fwl/core/ifwl_combobox.h" + +CFWL_ComboBoxProxy::CFWL_ComboBoxProxy( + IFWL_ComboBox* pComboBox, + const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter) + : CFWL_FormProxy(app, std::move(properties), pOuter), + m_bLButtonDown(false), + m_bLButtonUpSelf(false), + m_pComboBox(pComboBox) {} + +CFWL_ComboBoxProxy::~CFWL_ComboBoxProxy() {} + +void CFWL_ComboBoxProxy::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + switch (pMessage->GetClassID()) { + case CFWL_MessageType::Mouse: { + CFWL_MsgMouse* pMsg = static_cast(pMessage); + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(pMsg); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMsg); + break; + default: + break; + } + break; + } + case CFWL_MessageType::KillFocus: + OnFocusChanged(pMessage, false); + break; + case CFWL_MessageType::SetFocus: + OnFocusChanged(pMessage, true); + break; + default: + break; + } + IFWL_Widget::OnProcessMessage(pMessage); +} + +void CFWL_ComboBoxProxy::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + m_pComboBox->DrawStretchHandler(pGraphics, pMatrix); +} + +void CFWL_ComboBoxProxy::OnLButtonDown(CFWL_Message* pMessage) { + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pDriver = + static_cast(pApp->GetNoteDriver()); + CFX_RectF rtWidget; + GetWidgetRect(rtWidget); + rtWidget.left = rtWidget.top = 0; + + CFWL_MsgMouse* pMsg = static_cast(pMessage); + if (rtWidget.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_bLButtonDown = true; + pDriver->SetGrab(this, true); + } else { + m_bLButtonDown = false; + pDriver->SetGrab(this, false); + m_pComboBox->ShowDropList(false); + } +} + +void CFWL_ComboBoxProxy::OnLButtonUp(CFWL_Message* pMessage) { + m_bLButtonDown = false; + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pDriver = + static_cast(pApp->GetNoteDriver()); + pDriver->SetGrab(this, false); + if (!m_bLButtonUpSelf) { + m_bLButtonUpSelf = true; + return; + } + + CFWL_MsgMouse* pMsg = static_cast(pMessage); + CFX_RectF rect; + GetWidgetRect(rect); + rect.left = rect.top = 0; + if (!rect.Contains(pMsg->m_fx, pMsg->m_fy) && + m_pComboBox->IsDropListVisible()) { + m_pComboBox->ShowDropList(false); + } +} + +void CFWL_ComboBoxProxy::OnFocusChanged(CFWL_Message* pMessage, bool bSet) { + if (bSet) + return; + + CFWL_MsgKillFocus* pMsg = static_cast(pMessage); + if (!pMsg->m_pSetFocus) + m_pComboBox->ShowDropList(false); +} diff --git a/xfa/fwl/core/cfwl_comboboxproxy.h b/xfa/fwl/core/cfwl_comboboxproxy.h new file mode 100644 index 0000000000..33f5a82e79 --- /dev/null +++ b/xfa/fwl/core/cfwl_comboboxproxy.h @@ -0,0 +1,41 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CORE_CFWL_COMBOBOXPROXY_H_ +#define XFA_FWL_CORE_CFWL_COMBOBOXPROXY_H_ + +#include + +#include "xfa/fwl/core/cfwl_formproxy.h" + +class IFWL_ComboBox; + +class CFWL_ComboBoxProxy : public CFWL_FormProxy { + public: + CFWL_ComboBoxProxy(IFWL_ComboBox* pCombobBox, + const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter); + ~CFWL_ComboBoxProxy() override; + + // CFWL_FormProxy + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + void Reset() { m_bLButtonUpSelf = false; } + + private: + void OnLButtonDown(CFWL_Message* pMsg); + void OnLButtonUp(CFWL_Message* pMsg); + void OnFocusChanged(CFWL_Message* pMsg, bool bSet); + + bool m_bLButtonDown; + bool m_bLButtonUpSelf; + IFWL_ComboBox* m_pComboBox; +}; + +#endif // XFA_FWL_CORE_CFWL_COMBOBOXPROXY_H_ diff --git a/xfa/fwl/core/cfwl_comboedit.cpp b/xfa/fwl/core/cfwl_comboedit.cpp new file mode 100644 index 0000000000..2051daa786 --- /dev/null +++ b/xfa/fwl/core/cfwl_comboedit.cpp @@ -0,0 +1,75 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/core/cfwl_comboedit.h" + +#include +#include + +#include "xfa/fde/cfde_txtedtengine.h" +#include "xfa/fwl/core/cfwl_msgmouse.h" +#include "xfa/fwl/core/ifwl_combobox.h" + +CFWL_ComboEdit::CFWL_ComboEdit( + const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter) + : IFWL_Edit(app, std::move(properties), pOuter) { + m_pOuter = static_cast(pOuter); +} + +void CFWL_ComboEdit::ClearSelected() { + ClearSelections(); + Repaint(&GetRTClient()); +} + +void CFWL_ComboEdit::SetSelected() { + FlagFocus(true); + GetTxtEdtEngine()->MoveCaretPos(MC_End); + AddSelRange(0); +} + +void CFWL_ComboEdit::FlagFocus(bool bSet) { + if (bSet) { + m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; + return; + } + + m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; + ShowCaret(false); +} + +void CFWL_ComboEdit::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + bool backDefault = true; + switch (pMessage->GetClassID()) { + case CFWL_MessageType::SetFocus: { + m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; + backDefault = false; + break; + } + case CFWL_MessageType::KillFocus: { + m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; + backDefault = false; + break; + } + case CFWL_MessageType::Mouse: { + CFWL_MsgMouse* pMsg = static_cast(pMessage); + if ((pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonDown) && + ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0)) { + SetSelected(); + m_pOuter->SetFocus(true); + } + break; + } + default: + break; + } + if (backDefault) + IFWL_Edit::OnProcessMessage(pMessage); +} diff --git a/xfa/fwl/core/cfwl_comboedit.h b/xfa/fwl/core/cfwl_comboedit.h new file mode 100644 index 0000000000..30c5e85ad1 --- /dev/null +++ b/xfa/fwl/core/cfwl_comboedit.h @@ -0,0 +1,35 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CORE_CFWL_COMBOEDIT_H_ +#define XFA_FWL_CORE_CFWL_COMBOEDIT_H_ + +#include + +#include "xfa/fwl/core/cfwl_widgetproperties.h" +#include "xfa/fwl/core/ifwl_edit.h" +#include "xfa/fwl/core/ifwl_widget.h" + +class IFWL_ComboBox; + +class CFWL_ComboEdit : public IFWL_Edit { + public: + CFWL_ComboEdit(const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter); + + // IFWL_Edit. + void OnProcessMessage(CFWL_Message* pMessage) override; + + void ClearSelected(); + void SetSelected(); + void FlagFocus(bool bSet); + + private: + IFWL_ComboBox* m_pOuter; +}; + +#endif // XFA_FWL_CORE_CFWL_COMBOEDIT_H_ diff --git a/xfa/fwl/core/cfwl_combolist.cpp b/xfa/fwl/core/cfwl_combolist.cpp new file mode 100644 index 0000000000..e98f38e81a --- /dev/null +++ b/xfa/fwl/core/cfwl_combolist.cpp @@ -0,0 +1,249 @@ +// Copyright 2016 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/core/cfwl_combolist.h" + +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/core/cfwl_comboedit.h" +#include "xfa/fwl/core/cfwl_msgkey.h" +#include "xfa/fwl/core/cfwl_msgkillfocus.h" +#include "xfa/fwl/core/cfwl_msgmouse.h" +#include "xfa/fwl/core/ifwl_combobox.h" +#include "xfa/fwl/core/ifwl_listbox.h" + +CFWL_ComboList::CFWL_ComboList( + const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter) + : IFWL_ListBox(app, std::move(properties), pOuter), m_bNotifyOwner(true) { + ASSERT(pOuter); +} + +int32_t CFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { + if (wsMatch.IsEmpty()) + return -1; + + int32_t iCount = CountItems(this); + for (int32_t i = 0; i < iCount; i++) { + CFWL_ListItem* hItem = GetItem(this, i); + CFX_WideString wsText; + GetItemText(this, hItem, wsText); + FX_STRSIZE pos = wsText.Find(wsMatch.c_str()); + if (!pos) + return i; + } + return -1; +} + +void CFWL_ComboList::ChangeSelected(int32_t iSel) { + CFWL_ListItem* hItem = GetItem(this, iSel); + CFX_RectF rtInvalidate; + rtInvalidate.Reset(); + CFWL_ListItem* hOld = GetSelItem(0); + int32_t iOld = GetItemIndex(this, hOld); + if (iOld == iSel) + return; + if (iOld > -1) { + CFWL_ListItem* hItem = GetItem(this, iOld); + GetItemRect(this, hItem, rtInvalidate); + SetSelItem(hOld, false); + } + if (hItem) { + CFX_RectF rect; + CFWL_ListItem* hItem = GetItem(this, iSel); + GetItemRect(this, hItem, rect); + rtInvalidate.Union(rect); + CFWL_ListItem* hSel = GetItem(this, iSel); + SetSelItem(hSel, true); + } + if (!rtInvalidate.IsEmpty()) + Repaint(&rtInvalidate); +} + +void CFWL_ComboList::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) { + fx += m_pProperties->m_rtWidget.left, fy += m_pProperties->m_rtWidget.top; + IFWL_Widget* pOwner = GetOwner(); + if (!pOwner) + return; + pOwner->TransformTo(m_pOuter, fx, fy); +} + +void CFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + CFWL_MessageType dwHashCode = pMessage->GetClassID(); + bool backDefault = true; + if (dwHashCode == CFWL_MessageType::SetFocus || + dwHashCode == CFWL_MessageType::KillFocus) { + OnDropListFocusChanged(pMessage, dwHashCode == CFWL_MessageType::SetFocus); + } else if (dwHashCode == CFWL_MessageType::Mouse) { + CFWL_MsgMouse* pMsg = static_cast(pMessage); + CFWL_ScrollBar* vertSB = GetVertScrollBar(); + if (IsShowScrollBar(true) && vertSB) { + CFX_RectF rect; + vertSB->GetWidgetRect(rect); + if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { + pMsg->m_fx -= rect.left; + pMsg->m_fy -= rect.top; + vertSB->GetDelegate()->OnProcessMessage(pMsg); + return; + } + } + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::Move: { + backDefault = false; + OnDropListMouseMove(pMsg); + break; + } + case FWL_MouseCommand::LeftButtonDown: { + backDefault = false; + OnDropListLButtonDown(pMsg); + break; + } + case FWL_MouseCommand::LeftButtonUp: { + backDefault = false; + OnDropListLButtonUp(pMsg); + break; + } + default: + break; + } + } else if (dwHashCode == CFWL_MessageType::Key) { + backDefault = !OnDropListKey(static_cast(pMessage)); + } + if (backDefault) + IFWL_ListBox::OnProcessMessage(pMessage); +} + +void CFWL_ComboList::OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet) { + if (bSet) + return; + + CFWL_MsgKillFocus* pKill = static_cast(pMsg); + IFWL_ComboBox* pOuter = static_cast(m_pOuter); + if (pKill->m_pSetFocus == m_pOuter || + pKill->m_pSetFocus == pOuter->GetComboEdit()) { + pOuter->ShowDropList(false); + } +} + +void CFWL_ComboList::OnDropListMouseMove(CFWL_MsgMouse* pMsg) { + if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) { + if (m_bNotifyOwner) + m_bNotifyOwner = false; + + CFWL_ScrollBar* vertSB = GetVertScrollBar(); + if (IsShowScrollBar(true) && vertSB) { + CFX_RectF rect; + vertSB->GetWidgetRect(rect); + if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) + return; + } + + CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); + if (!hItem) + return; + + ChangeSelected(GetItemIndex(this, hItem)); + } else if (m_bNotifyOwner) { + ClientToOuter(pMsg->m_fx, pMsg->m_fy); + IFWL_ComboBox* pOuter = static_cast(m_pOuter); + pOuter->GetDelegate()->OnProcessMessage(pMsg); + } +} + +void CFWL_ComboList::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) { + if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) + return; + + IFWL_ComboBox* pOuter = static_cast(m_pOuter); + pOuter->ShowDropList(false); +} + +void CFWL_ComboList::OnDropListLButtonUp(CFWL_MsgMouse* pMsg) { + IFWL_ComboBox* pOuter = static_cast(m_pOuter); + if (m_bNotifyOwner) { + ClientToOuter(pMsg->m_fx, pMsg->m_fy); + pOuter->GetDelegate()->OnProcessMessage(pMsg); + return; + } + + CFWL_ScrollBar* vertSB = GetVertScrollBar(); + if (IsShowScrollBar(true) && vertSB) { + CFX_RectF rect; + vertSB->GetWidgetRect(rect); + if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) + return; + } + pOuter->ShowDropList(false); + + CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); + if (hItem) + pOuter->ProcessSelChanged(true); +} + +bool CFWL_ComboList::OnDropListKey(CFWL_MsgKey* pKey) { + IFWL_ComboBox* pOuter = static_cast(m_pOuter); + bool bPropagate = false; + if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { + uint32_t dwKeyCode = pKey->m_dwKeyCode; + switch (dwKeyCode) { + case FWL_VKEY_Return: + case FWL_VKEY_Escape: { + pOuter->ShowDropList(false); + return true; + } + case FWL_VKEY_Up: + case FWL_VKEY_Down: { + OnDropListKeyDown(pKey); + pOuter->ProcessSelChanged(false); + return true; + } + default: { + bPropagate = true; + break; + } + } + } else if (pKey->m_dwCmd == FWL_KeyCommand::Char) { + bPropagate = true; + } + if (bPropagate) { + pKey->m_pDstTarget = m_pOuter; + pOuter->GetDelegate()->OnProcessMessage(pKey); + return true; + } + return false; +} + +void CFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) { + uint32_t dwKeyCode = pKey->m_dwKeyCode; + switch (dwKeyCode) { + case FWL_VKEY_Up: + case FWL_VKEY_Down: + case FWL_VKEY_Home: + case FWL_VKEY_End: { + IFWL_ComboBox* pOuter = static_cast(m_pOuter); + CFWL_ListItem* hItem = GetItem(this, pOuter->GetCurrentSelection()); + hItem = GetListItem(hItem, dwKeyCode); + if (!hItem) + break; + + SetSelection(hItem, hItem, true); + ScrollToVisible(hItem); + CFX_RectF rtInvalidate; + rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, + m_pProperties->m_rtWidget.height); + Repaint(&rtInvalidate); + break; + } + default: + break; + } +} diff --git a/xfa/fwl/core/cfwl_combolist.h b/xfa/fwl/core/cfwl_combolist.h new file mode 100644 index 0000000000..ad97b5bed7 --- /dev/null +++ b/xfa/fwl/core/cfwl_combolist.h @@ -0,0 +1,43 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CORE_CFWL_COMBOLIST_H_ +#define XFA_FWL_CORE_CFWL_COMBOLIST_H_ + +#include + +#include "xfa/fwl/core/cfwl_widgetproperties.h" +#include "xfa/fwl/core/ifwl_listbox.h" +#include "xfa/fwl/core/ifwl_widget.h" + +class CFWL_ComboList : public IFWL_ListBox { + public: + CFWL_ComboList(const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter); + + // IFWL_ListBox. + void OnProcessMessage(CFWL_Message* pMessage) override; + + int32_t MatchItem(const CFX_WideString& wsMatch); + + void ChangeSelected(int32_t iSel); + + void SetNotifyOwner(bool notify) { m_bNotifyOwner = notify; } + + private: + void ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy); + void OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet); + void OnDropListMouseMove(CFWL_MsgMouse* pMsg); + void OnDropListLButtonDown(CFWL_MsgMouse* pMsg); + void OnDropListLButtonUp(CFWL_MsgMouse* pMsg); + bool OnDropListKey(CFWL_MsgKey* pKey); + void OnDropListKeyDown(CFWL_MsgKey* pKey); + + bool m_bNotifyOwner; +}; + +#endif // XFA_FWL_CORE_CFWL_COMBOLIST_H_ diff --git a/xfa/fwl/core/cfwl_datetimeedit.cpp b/xfa/fwl/core/cfwl_datetimeedit.cpp new file mode 100644 index 0000000000..16ebb3c8cf --- /dev/null +++ b/xfa/fwl/core/cfwl_datetimeedit.cpp @@ -0,0 +1,62 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/core/cfwl_datetimeedit.h" + +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/core/cfwl_msgmouse.h" +#include "xfa/fwl/core/cfwl_widgetmgr.h" +#include "xfa/fwl/core/ifwl_datetimepicker.h" + +CFWL_DateTimeEdit::CFWL_DateTimeEdit( + const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter) + : IFWL_Edit(app, std::move(properties), pOuter) {} + +void CFWL_DateTimeEdit::OnProcessMessage(CFWL_Message* pMessage) { + if (m_pWidgetMgr->IsFormDisabled()) { + DisForm_OnProcessMessage(pMessage); + return; + } + + CFWL_MessageType dwHashCode = pMessage->GetClassID(); + if (dwHashCode == CFWL_MessageType::SetFocus || + dwHashCode == CFWL_MessageType::KillFocus) { + IFWL_Widget* pOuter = GetOuter(); + pOuter->GetDelegate()->OnProcessMessage(pMessage); + } +} + +void CFWL_DateTimeEdit::DisForm_OnProcessMessage(CFWL_Message* pMessage) { + CFWL_MessageType dwHashCode = pMessage->GetClassID(); + if (!m_pWidgetMgr->IsFormDisabled() || + dwHashCode != CFWL_MessageType::Mouse) { + IFWL_Edit::OnProcessMessage(pMessage); + return; + } + + CFWL_MsgMouse* pMouse = static_cast(pMessage); + if (pMouse->m_dwCmd == FWL_MouseCommand::LeftButtonDown || + pMouse->m_dwCmd == FWL_MouseCommand::RightButtonDown) { + if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) + m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; + + IFWL_DateTimePicker* pDateTime = + static_cast(m_pOuter); + if (pDateTime->IsMonthCalendarVisible()) { + CFX_RectF rtInvalidate; + pDateTime->GetWidgetRect(rtInvalidate); + pDateTime->ShowMonthCalendar(false); + rtInvalidate.Offset(-rtInvalidate.left, -rtInvalidate.top); + pDateTime->Repaint(&rtInvalidate); + } + } + IFWL_Edit::OnProcessMessage(pMessage); +} diff --git a/xfa/fwl/core/cfwl_datetimeedit.h b/xfa/fwl/core/cfwl_datetimeedit.h new file mode 100644 index 0000000000..68efd2e13a --- /dev/null +++ b/xfa/fwl/core/cfwl_datetimeedit.h @@ -0,0 +1,30 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CORE_CFWL_DATETIMEEDIT_H_ +#define XFA_FWL_CORE_CFWL_DATETIMEEDIT_H_ + +#include + +#include "xfa/fwl/core/cfwl_widgetproperties.h" +#include "xfa/fwl/core/fwl_error.h" +#include "xfa/fwl/core/ifwl_edit.h" +#include "xfa/fwl/core/ifwl_widget.h" + +class CFWL_DateTimeEdit : public IFWL_Edit { + public: + CFWL_DateTimeEdit(const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter); + + // IFWL_Edit. + void OnProcessMessage(CFWL_Message* pMessage) override; + + private: + void DisForm_OnProcessMessage(CFWL_Message* pMessage); +}; + +#endif // XFA_FWL_CORE_CFWL_DATETIMEEDIT_H_ diff --git a/xfa/fwl/core/cfwl_form.cpp b/xfa/fwl/core/cfwl_form.cpp new file mode 100644 index 0000000000..d2fe14993e --- /dev/null +++ b/xfa/fwl/core/cfwl_form.cpp @@ -0,0 +1,639 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/core/cfwl_form.h" + +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fde/tto/fde_textout.h" +#include "xfa/fwl/core/cfwl_app.h" +#include "xfa/fwl/core/cfwl_evtclose.h" +#include "xfa/fwl/core/cfwl_formproxy.h" +#include "xfa/fwl/core/cfwl_msgmouse.h" +#include "xfa/fwl/core/cfwl_notedriver.h" +#include "xfa/fwl/core/cfwl_noteloop.h" +#include "xfa/fwl/core/cfwl_sysbtn.h" +#include "xfa/fwl/core/cfwl_themebackground.h" +#include "xfa/fwl/core/cfwl_themepart.h" +#include "xfa/fwl/core/cfwl_themetext.h" +#include "xfa/fwl/core/cfwl_widgetmgr.h" +#include "xfa/fwl/core/ifwl_themeprovider.h" +#include "xfa/fwl/theme/cfwl_widgettp.h" + +namespace { + +const int kSystemButtonSize = 21; +const int kSystemButtonMargin = 5; +const int kSystemButtonSpan = 2; + +} // namespace + +namespace { + +const uint8_t kCornerEnlarge = 10; + +} // namespace + +CFWL_Form::CFWL_Form(const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter) + : IFWL_Widget(app, std::move(properties), pOuter), +#if (_FX_OS_ == _FX_MACOSX_) + m_bMouseIn(false), +#endif + m_pCloseBox(nullptr), + m_pMinBox(nullptr), + m_pMaxBox(nullptr), + m_pSubFocus(nullptr), + m_fCXBorder(0), + m_fCYBorder(0), + m_iCaptureBtn(-1), + m_iSysBox(0), + m_bLButtonDown(false), + m_bMaximized(false), + m_bSetMaximize(false), + m_bDoModalFlag(false) { + m_rtRelative.Reset(); + m_rtRestore.Reset(); + + RegisterForm(); + RegisterEventTarget(nullptr); +} + +CFWL_Form::~CFWL_Form() { + UnregisterEventTarget(); + UnRegisterForm(); + RemoveSysButtons(); +} + +FWL_Type CFWL_Form::GetClassID() const { + return FWL_Type::Form; +} + +bool CFWL_Form::IsInstance(const CFX_WideStringC& wsClass) const { + if (wsClass == CFX_WideStringC(FWL_CLASS_Form)) + return true; + return IFWL_Widget::IsInstance(wsClass); +} + +void CFWL_Form::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { + if (!bAutoSize) { + rect = m_pProperties->m_rtWidget; + return; + } + + rect.Reset(); + FX_FLOAT fCXBorder = GetBorderSize(true); + FX_FLOAT fCYBorder = GetBorderSize(false); + FX_FLOAT fEdge = GetEdgeWidth(); + rect.height += fCYBorder + fEdge + fEdge; + rect.width += fCXBorder + fCXBorder + fEdge + fEdge; +} + +void CFWL_Form::GetClientRect(CFX_RectF& rect) { + rect = m_pProperties->m_rtWidget; + rect.Offset(-rect.left, -rect.top); +} + +void CFWL_Form::Update() { + if (m_iLock > 0) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + Layout(); +} + +FWL_WidgetHit CFWL_Form::HitTest(FX_FLOAT fx, FX_FLOAT fy) { + GetAvailableTheme(); + + if (m_pCloseBox && m_pCloseBox->m_rtBtn.Contains(fx, fy)) + return FWL_WidgetHit::CloseBox; + if (m_pMaxBox && m_pMaxBox->m_rtBtn.Contains(fx, fy)) + return FWL_WidgetHit::MaxBox; + if (m_pMinBox && m_pMinBox->m_rtBtn.Contains(fx, fy)) + return FWL_WidgetHit::MinBox; + + CFX_RectF rtCap; + rtCap.Set(m_fCYBorder, m_fCXBorder, + 0 - kSystemButtonSize * m_iSysBox - 2 * m_fCYBorder, + 0 - m_fCXBorder); + if (rtCap.Contains(fx, fy)) + return FWL_WidgetHit::Titlebar; + if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) && + (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_Resize)) { + FX_FLOAT fWidth = m_rtRelative.width - 2 * (m_fCYBorder + kCornerEnlarge); + FX_FLOAT fHeight = m_rtRelative.height - 2 * (m_fCXBorder + kCornerEnlarge); + + CFX_RectF rt; + rt.Set(0, m_fCXBorder + kCornerEnlarge, m_fCYBorder, fHeight); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::Left; + + rt.Set(m_rtRelative.width - m_fCYBorder, m_fCXBorder + kCornerEnlarge, + m_fCYBorder, fHeight); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::Right; + + rt.Set(m_fCYBorder + kCornerEnlarge, 0, fWidth, m_fCXBorder); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::Top; + + rt.Set(m_fCYBorder + kCornerEnlarge, m_rtRelative.height - m_fCXBorder, + fWidth, m_fCXBorder); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::Bottom; + + rt.Set(0, 0, m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::LeftTop; + + rt.Set(0, m_rtRelative.height - m_fCXBorder - kCornerEnlarge, + m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::LeftBottom; + + rt.Set(m_rtRelative.width - m_fCYBorder - kCornerEnlarge, 0, + m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::RightTop; + + rt.Set(m_rtRelative.width - m_fCYBorder - kCornerEnlarge, + m_rtRelative.height - m_fCXBorder - kCornerEnlarge, + m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); + if (rt.Contains(fx, fy)) + return FWL_WidgetHit::RightBottom; + } + return FWL_WidgetHit::Client; +} + +void CFWL_Form::DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + return; + + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + bool bInactive = !IsActive(); + int32_t iState = bInactive ? CFWL_PartState_Inactive : CFWL_PartState_Normal; + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_NoDrawClient) == 0) + DrawBackground(pGraphics, pTheme); + +#ifdef FWL_UseMacSystemBorder + return; +#endif + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_dwStates = iState; + param.m_pGraphics = pGraphics; + param.m_rtPart = m_rtRelative; + if (pMatrix) + param.m_matrix.Concat(*pMatrix); + if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) { + param.m_iPart = CFWL_Part::Border; + pTheme->DrawBackground(¶m); + } + if ((m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_EdgeMask) != + FWL_WGTSTYLE_EdgeNone) { + CFX_RectF rtEdge; + GetEdgeRect(rtEdge); + param.m_iPart = CFWL_Part::Edge; + param.m_rtPart = rtEdge; + param.m_dwStates = iState; + pTheme->DrawBackground(¶m); + } + +#if (_FX_OS_ == _FX_MACOSX_) + { + if (m_pCloseBox) { + param.m_iPart = CFWL_Part::CloseBox; + param.m_dwStates = m_pCloseBox->GetPartState(); + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) + param.m_dwStates = CFWL_PartState_Disabled; + else if (CFWL_PartState_Normal == param.m_dwStates && m_bMouseIn) + param.m_dwStates = CFWL_PartState_Hovered; + param.m_rtPart = m_pCloseBox->m_rtBtn; + pTheme->DrawBackground(¶m); + } + if (m_pMaxBox) { + param.m_iPart = CFWL_Part::MaximizeBox; + param.m_dwStates = m_pMaxBox->GetPartState(); + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) + param.m_dwStates = CFWL_PartState_Disabled; + else if (CFWL_PartState_Normal == param.m_dwStates && m_bMouseIn) + param.m_dwStates = CFWL_PartState_Hovered; + param.m_rtPart = m_pMaxBox->m_rtBtn; + param.m_bMaximize = m_bMaximized; + pTheme->DrawBackground(¶m); + } + if (m_pMinBox) { + param.m_iPart = CFWL_Part::MinimizeBox; + param.m_dwStates = m_pMinBox->GetPartState(); + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) + param.m_dwStates = CFWL_PartState_Disabled; + else if (CFWL_PartState_Normal == param.m_dwStates && m_bMouseIn) + param.m_dwStates = CFWL_PartState_Hovered; + param.m_rtPart = m_pMinBox->m_rtBtn; + pTheme->DrawBackground(¶m); + } + m_bMouseIn = false; + } +#else + { + if (m_pCloseBox) { + param.m_iPart = CFWL_Part::CloseBox; + param.m_dwStates = m_pCloseBox->GetPartState(); + param.m_rtPart = m_pCloseBox->m_rtBtn; + pTheme->DrawBackground(¶m); + } + if (m_pMaxBox) { + param.m_iPart = CFWL_Part::MaximizeBox; + param.m_dwStates = m_pMaxBox->GetPartState(); + param.m_rtPart = m_pMaxBox->m_rtBtn; + param.m_bMaximize = m_bMaximized; + pTheme->DrawBackground(¶m); + } + if (m_pMinBox) { + param.m_iPart = CFWL_Part::MinimizeBox; + param.m_dwStates = m_pMinBox->GetPartState(); + param.m_rtPart = m_pMinBox->m_rtBtn; + pTheme->DrawBackground(¶m); + } + } +#endif +} + +IFWL_Widget* CFWL_Form::DoModal() { + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return nullptr; + + CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); + if (!pDriver) + return nullptr; + + m_pNoteLoop = pdfium::MakeUnique(); + m_pNoteLoop->SetMainForm(this); + + pDriver->PushNoteLoop(m_pNoteLoop.get()); + m_bDoModalFlag = true; + SetStates(FWL_WGTSTATE_Invisible, false); + pDriver->Run(); + +#if _FX_OS_ != _FX_MACOSX_ + pDriver->PopNoteLoop(); +#endif + + m_pNoteLoop.reset(); + return nullptr; +} + +void CFWL_Form::EndDoModal() { + if (!m_pNoteLoop) + return; + + m_bDoModalFlag = false; + +#if (_FX_OS_ == _FX_MACOSX_) + m_pNoteLoop->EndModalLoop(); + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pDriver = + static_cast(pApp->GetNoteDriver()); + if (!pDriver) + return; + + pDriver->PopNoteLoop(); + SetStates(FWL_WGTSTATE_Invisible, true); +#else + SetStates(FWL_WGTSTATE_Invisible, true); + m_pNoteLoop->EndModalLoop(); +#endif +} + +void CFWL_Form::DrawBackground(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme) { + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::Background; + param.m_pGraphics = pGraphics; + param.m_rtPart = m_rtRelative; + param.m_rtPart.Deflate(m_fCYBorder, m_fCXBorder, m_fCYBorder, m_fCXBorder); + pTheme->DrawBackground(¶m); +} + +void CFWL_Form::RemoveSysButtons() { + delete m_pCloseBox; + m_pCloseBox = nullptr; + delete m_pMinBox; + m_pMinBox = nullptr; + delete m_pMaxBox; + m_pMaxBox = nullptr; +} + +CFWL_SysBtn* CFWL_Form::GetSysBtnAtPoint(FX_FLOAT fx, FX_FLOAT fy) { + if (m_pCloseBox && m_pCloseBox->m_rtBtn.Contains(fx, fy)) + return m_pCloseBox; + if (m_pMaxBox && m_pMaxBox->m_rtBtn.Contains(fx, fy)) + return m_pMaxBox; + if (m_pMinBox && m_pMinBox->m_rtBtn.Contains(fx, fy)) + return m_pMinBox; + return nullptr; +} + +CFWL_SysBtn* CFWL_Form::GetSysBtnByState(uint32_t dwState) { + if (m_pCloseBox && (m_pCloseBox->m_dwState & dwState)) + return m_pCloseBox; + if (m_pMaxBox && (m_pMaxBox->m_dwState & dwState)) + return m_pMaxBox; + if (m_pMinBox && (m_pMinBox->m_dwState & dwState)) + return m_pMinBox; + return nullptr; +} + +CFWL_SysBtn* CFWL_Form::GetSysBtnByIndex(int32_t nIndex) { + if (nIndex < 0) + return nullptr; + + CFX_ArrayTemplate arrBtn; + if (m_pMinBox) + arrBtn.Add(m_pMinBox); + if (m_pMaxBox) + arrBtn.Add(m_pMaxBox); + if (m_pCloseBox) + arrBtn.Add(m_pCloseBox); + return arrBtn[nIndex]; +} + +int32_t CFWL_Form::GetSysBtnIndex(CFWL_SysBtn* pBtn) { + CFX_ArrayTemplate arrBtn; + if (m_pMinBox) + arrBtn.Add(m_pMinBox); + if (m_pMaxBox) + arrBtn.Add(m_pMaxBox); + if (m_pCloseBox) + arrBtn.Add(m_pCloseBox); + return arrBtn.Find(pBtn); +} + +void CFWL_Form::GetEdgeRect(CFX_RectF& rtEdge) { + rtEdge = m_rtRelative; + if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) { + FX_FLOAT fCX = GetBorderSize(); + FX_FLOAT fCY = GetBorderSize(false); + rtEdge.Deflate(fCX, fCY, fCX, fCY); + } +} + +void CFWL_Form::SetWorkAreaRect() { + m_rtRestore = m_pProperties->m_rtWidget; + CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr(); + if (!pWidgetMgr) + return; + + m_bSetMaximize = true; + Repaint(&m_rtRelative); +} + +void CFWL_Form::Layout() { + GetRelativeRect(m_rtRelative); + +#ifndef FWL_UseMacSystemBorder + ResetSysBtn(); +#endif +} + +void CFWL_Form::ResetSysBtn() { + m_fCXBorder = + *static_cast(GetThemeCapacity(CFWL_WidgetCapacity::CXBorder)); + m_fCYBorder = + *static_cast(GetThemeCapacity(CFWL_WidgetCapacity::CYBorder)); + RemoveSysButtons(); + + m_iSysBox = 0; + if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_CloseBox) { + m_pCloseBox = new CFWL_SysBtn; + m_pCloseBox->m_rtBtn.Set( + m_rtRelative.right() - kSystemButtonMargin - kSystemButtonSize, + kSystemButtonMargin, kSystemButtonSize, kSystemButtonSize); + m_iSysBox++; + } + if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_MaximizeBox) { + m_pMaxBox = new CFWL_SysBtn; + if (m_pCloseBox) { + m_pMaxBox->m_rtBtn.Set( + m_pCloseBox->m_rtBtn.left - kSystemButtonSpan - kSystemButtonSize, + m_pCloseBox->m_rtBtn.top, kSystemButtonSize, kSystemButtonSize); + } else { + m_pMaxBox->m_rtBtn.Set( + m_rtRelative.right() - kSystemButtonMargin - kSystemButtonSize, + kSystemButtonMargin, kSystemButtonSize, kSystemButtonSize); + } + m_iSysBox++; + } + if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_MinimizeBox) { + m_pMinBox = new CFWL_SysBtn; + if (m_pMaxBox) { + m_pMinBox->m_rtBtn.Set( + m_pMaxBox->m_rtBtn.left - kSystemButtonSpan - kSystemButtonSize, + m_pMaxBox->m_rtBtn.top, kSystemButtonSize, kSystemButtonSize); + } else if (m_pCloseBox) { + m_pMinBox->m_rtBtn.Set( + m_pCloseBox->m_rtBtn.left - kSystemButtonSpan - kSystemButtonSize, + m_pCloseBox->m_rtBtn.top, kSystemButtonSize, kSystemButtonSize); + } else { + m_pMinBox->m_rtBtn.Set( + m_rtRelative.right() - kSystemButtonMargin - kSystemButtonSize, + kSystemButtonMargin, kSystemButtonSize, kSystemButtonSize); + } + m_iSysBox++; + } +} + +void CFWL_Form::RegisterForm() { + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pDriver = + static_cast(pApp->GetNoteDriver()); + if (!pDriver) + return; + + pDriver->RegisterForm(this); +} + +void CFWL_Form::UnRegisterForm() { + const CFWL_App* pApp = GetOwnerApp(); + if (!pApp) + return; + + CFWL_NoteDriver* pDriver = + static_cast(pApp->GetNoteDriver()); + if (!pDriver) + return; + + pDriver->UnRegisterForm(this); +} + +void CFWL_Form::OnProcessMessage(CFWL_Message* pMessage) { +#ifndef FWL_UseMacSystemBorder + if (!pMessage) + return; + + switch (pMessage->GetClassID()) { + case CFWL_MessageType::Mouse: { + CFWL_MsgMouse* pMsg = static_cast(pMessage); + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(pMsg); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMsg); + break; + case FWL_MouseCommand::Move: + OnMouseMove(pMsg); + break; + case FWL_MouseCommand::Leave: + OnMouseLeave(pMsg); + break; + case FWL_MouseCommand::LeftButtonDblClk: + OnLButtonDblClk(pMsg); + break; + default: + break; + } + break; + } + default: + break; + } +#endif // FWL_UseMacSystemBorder +} + +void CFWL_Form::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +void CFWL_Form::OnLButtonDown(CFWL_MsgMouse* pMsg) { + SetGrab(true); + m_bLButtonDown = true; + + CFWL_SysBtn* pPressBtn = GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy); + m_iCaptureBtn = GetSysBtnIndex(pPressBtn); + + if (!pPressBtn) + return; + + pPressBtn->SetPressed(); + Repaint(&pPressBtn->m_rtBtn); +} + +void CFWL_Form::OnLButtonUp(CFWL_MsgMouse* pMsg) { + SetGrab(false); + m_bLButtonDown = false; + CFWL_SysBtn* pPointBtn = GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy); + CFWL_SysBtn* pPressedBtn = GetSysBtnByIndex(m_iCaptureBtn); + if (!pPressedBtn || pPointBtn != pPressedBtn) + return; + if (pPressedBtn == GetSysBtnByState(FWL_SYSBUTTONSTATE_Pressed)) + pPressedBtn->SetNormal(); + if (pPressedBtn == m_pMaxBox) { + if (m_bMaximized) { + SetWidgetRect(m_rtRestore); + Update(); + Repaint(); + } else { + SetWorkAreaRect(); + Update(); + } + m_bMaximized = !m_bMaximized; + } else if (pPressedBtn != m_pMinBox) { + CFWL_EvtClose eClose; + eClose.m_pSrcTarget = this; + DispatchEvent(&eClose); + } +} + +void CFWL_Form::OnMouseMove(CFWL_MsgMouse* pMsg) { + if (m_bLButtonDown) + return; + + CFX_RectF rtInvalidate; + rtInvalidate.Reset(); + CFWL_SysBtn* pPointBtn = GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy); + CFWL_SysBtn* pOldHover = GetSysBtnByState(FWL_SYSBUTTONSTATE_Hover); + +#if _FX_OS_ == _FX_MACOSX_ + { + if (pOldHover && pPointBtn != pOldHover) + pOldHover->SetNormal(); + if (pPointBtn && pPointBtn != pOldHover) + pPointBtn->SetHover(); + if (m_pCloseBox) + rtInvalidate = m_pCloseBox->m_rtBtn; + if (m_pMaxBox) { + if (rtInvalidate.IsEmpty()) + rtInvalidate = m_pMaxBox->m_rtBtn; + else + rtInvalidate.Union(m_pMaxBox->m_rtBtn); + } + if (m_pMinBox) { + if (rtInvalidate.IsEmpty()) + rtInvalidate = m_pMinBox->m_rtBtn; + else + rtInvalidate.Union(m_pMinBox->m_rtBtn); + } + if (!rtInvalidate.IsEmpty() && + rtInvalidate.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_bMouseIn = true; + } + } +#else + { + if (pOldHover && pPointBtn != pOldHover) { + pOldHover->SetNormal(); + rtInvalidate = pOldHover->m_rtBtn; + } + if (pPointBtn && pPointBtn != pOldHover) { + pPointBtn->SetHover(); + if (rtInvalidate.IsEmpty()) + rtInvalidate = pPointBtn->m_rtBtn; + else + rtInvalidate.Union(pPointBtn->m_rtBtn); + } + } +#endif + + if (!rtInvalidate.IsEmpty()) + Repaint(&rtInvalidate); +} + +void CFWL_Form::OnMouseLeave(CFWL_MsgMouse* pMsg) { + CFWL_SysBtn* pHover = GetSysBtnByState(FWL_SYSBUTTONSTATE_Hover); + if (!pHover) + return; + + pHover->SetNormal(); + Repaint(&pHover->m_rtBtn); +} + +void CFWL_Form::OnLButtonDblClk(CFWL_MsgMouse* pMsg) { + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_Resize) && + HitTest(pMsg->m_fx, pMsg->m_fy) == FWL_WidgetHit::Titlebar) { + if (m_bMaximized) + SetWidgetRect(m_rtRestore); + else + SetWorkAreaRect(); + + Update(); + m_bMaximized = !m_bMaximized; + } +} diff --git a/xfa/fwl/core/cfwl_form.h b/xfa/fwl/core/cfwl_form.h new file mode 100644 index 0000000000..cb01c5b7a8 --- /dev/null +++ b/xfa/fwl/core/cfwl_form.h @@ -0,0 +1,101 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CORE_CFWL_FORM_H_ +#define XFA_FWL_CORE_CFWL_FORM_H_ + +#include + +#include "core/fxcrt/fx_system.h" +#include "xfa/fwl/core/cfwl_widgetproperties.h" +#include "xfa/fwl/core/ifwl_widget.h" + +#define FWL_CLASS_Form L"FWL_FORM" +#define FWL_CLASS_FormProxy L"FWL_FORMPROXY" +#define FWL_STYLEEXT_FRM_Resize (1L << 0) +#define FWL_STYLEEXT_FRM_NativeBorder (1L << 1) +#define FWL_STYLEEXT_FRM_RoundCorner (2L << 1) +#define FWL_STYLEEXT_FRM_RoundCorner4 (3L << 1) +#define FWL_STYLEEXT_FRM_NoDrawClient (1L << 3) +#define FWL_STYLEEXT_FRM_BorderCornerMask (3L << 1) +#define FWL_STYLEEXT_FRM_Max (3) + +#if (_FX_OS_ == _FX_MACOSX_) +#define FWL_UseMacSystemBorder +#endif + +class CFWL_MsgMouse; +class CFWL_NoteLoop; +class IFWL_Widget; +class IFWL_ThemeProvider; +class CFWL_SysBtn; + +class CFWL_Form : public IFWL_Widget { + public: + CFWL_Form(const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter); + ~CFWL_Form() override; + + // IFWL_Widget + FWL_Type GetClassID() const override; + bool IsInstance(const CFX_WideStringC& wsClass) const override; + void GetWidgetRect(CFX_RectF& rect, bool bAutoSize = false) override; + void GetClientRect(CFX_RectF& rect) override; + void Update() override; + FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; + void DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + IFWL_Widget* DoModal(); + void EndDoModal(); + + IFWL_Widget* GetSubFocus() const { return m_pSubFocus; } + void SetSubFocus(IFWL_Widget* pWidget) { m_pSubFocus = pWidget; } + + private: + void DrawBackground(CFX_Graphics* pGraphics, IFWL_ThemeProvider* pTheme); + void RemoveSysButtons(); + CFWL_SysBtn* GetSysBtnAtPoint(FX_FLOAT fx, FX_FLOAT fy); + CFWL_SysBtn* GetSysBtnByState(uint32_t dwState); + CFWL_SysBtn* GetSysBtnByIndex(int32_t nIndex); + int32_t GetSysBtnIndex(CFWL_SysBtn* pBtn); + void GetEdgeRect(CFX_RectF& rtEdge); + void SetWorkAreaRect(); + void Layout(); + void ResetSysBtn(); + void RegisterForm(); + void UnRegisterForm(); + void OnLButtonDown(CFWL_MsgMouse* pMsg); + void OnLButtonUp(CFWL_MsgMouse* pMsg); + void OnMouseMove(CFWL_MsgMouse* pMsg); + void OnMouseLeave(CFWL_MsgMouse* pMsg); + void OnLButtonDblClk(CFWL_MsgMouse* pMsg); + +#if (_FX_OS_ == _FX_MACOSX_) + bool m_bMouseIn; +#endif + CFX_RectF m_rtRestore; + CFX_RectF m_rtRelative; + CFWL_SysBtn* m_pCloseBox; + CFWL_SysBtn* m_pMinBox; + CFWL_SysBtn* m_pMaxBox; + std::unique_ptr m_pNoteLoop; + IFWL_Widget* m_pSubFocus; + FX_FLOAT m_fCXBorder; + FX_FLOAT m_fCYBorder; + int32_t m_iCaptureBtn; + int32_t m_iSysBox; + bool m_bLButtonDown; + bool m_bMaximized; + bool m_bSetMaximize; + bool m_bDoModalFlag; +}; + +#endif // XFA_FWL_CORE_CFWL_FORM_H_ diff --git a/xfa/fwl/core/cfwl_formproxy.cpp b/xfa/fwl/core/cfwl_formproxy.cpp new file mode 100644 index 0000000000..ef325c4fdd --- /dev/null +++ b/xfa/fwl/core/cfwl_formproxy.cpp @@ -0,0 +1,40 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/core/cfwl_formproxy.h" + +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/core/cfwl_notedriver.h" + +CFWL_FormProxy::CFWL_FormProxy( + const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter) + : CFWL_Form(app, std::move(properties), pOuter) {} + +CFWL_FormProxy::~CFWL_FormProxy() {} + +FWL_Type CFWL_FormProxy::GetClassID() const { + return FWL_Type::FormProxy; +} + +bool CFWL_FormProxy::IsInstance(const CFX_WideStringC& wsClass) const { + if (wsClass == CFX_WideStringC(FWL_CLASS_FormProxy)) + return true; + return CFWL_Form::IsInstance(wsClass); +} + +void CFWL_FormProxy::Update() {} + +void CFWL_FormProxy::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) {} + +void CFWL_FormProxy::OnProcessMessage(CFWL_Message* pMessage) { + m_pOuter->GetDelegate()->OnProcessMessage(pMessage); +} diff --git a/xfa/fwl/core/cfwl_formproxy.h b/xfa/fwl/core/cfwl_formproxy.h new file mode 100644 index 0000000000..80e0980d0e --- /dev/null +++ b/xfa/fwl/core/cfwl_formproxy.h @@ -0,0 +1,32 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CORE_CFWL_FORMPROXY_H_ +#define XFA_FWL_CORE_CFWL_FORMPROXY_H_ + +#include + +#include "xfa/fwl/core/cfwl_form.h" + +class CFWL_WidgetProperties; + +class CFWL_FormProxy : public CFWL_Form { + public: + CFWL_FormProxy(const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter); + ~CFWL_FormProxy() override; + + // IFWL_Widget + FWL_Type GetClassID() const override; + bool IsInstance(const CFX_WideStringC& wsClass) const override; + void Update() override; + void DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; + void OnProcessMessage(CFWL_Message* pMessage) override; +}; + +#endif // XFA_FWL_CORE_CFWL_FORMPROXY_H_ diff --git a/xfa/fwl/core/cfwl_monthcalendar.cpp b/xfa/fwl/core/cfwl_monthcalendar.cpp new file mode 100644 index 0000000000..4f7cff0322 --- /dev/null +++ b/xfa/fwl/core/cfwl_monthcalendar.cpp @@ -0,0 +1,1111 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/core/cfwl_monthcalendar.h" + +#include +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fde/tto/fde_textout.h" +#include "xfa/fwl/core/cfwl_formproxy.h" +#include "xfa/fwl/core/cfwl_msgmouse.h" +#include "xfa/fwl/core/cfwl_notedriver.h" +#include "xfa/fwl/core/cfwl_themebackground.h" +#include "xfa/fwl/core/cfwl_themetext.h" +#include "xfa/fwl/core/ifwl_datetimepicker.h" +#include "xfa/fwl/core/ifwl_themeprovider.h" + +#define MONTHCAL_HSEP_HEIGHT 1 +#define MONTHCAL_VSEP_WIDTH 1 +#define MONTHCAL_HMARGIN 3 +#define MONTHCAL_VMARGIN 2 +#define MONTHCAL_ROWS 9 +#define MONTHCAL_COLUMNS 7 +#define MONTHCAL_HEADER_BTN_VMARGIN 7 +#define MONTHCAL_HEADER_BTN_HMARGIN 5 + +namespace { + +CFX_WideString* GetCapacityForDay(IFWL_ThemeProvider* pTheme, + CFWL_ThemePart& params, + uint32_t day) { + ASSERT(day < 7); + + if (day == 0) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Sun)); + } + if (day == 1) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Mon)); + } + if (day == 2) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Tue)); + } + if (day == 3) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Wed)); + } + if (day == 4) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Thu)); + } + if (day == 5) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Fri)); + } + + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Sat)); +} + +CFX_WideString* GetCapacityForMonth(IFWL_ThemeProvider* pTheme, + CFWL_ThemePart& params, + uint32_t month) { + ASSERT(month < 12); + + if (month == 0) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::January)); + } + if (month == 1) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::February)); + } + if (month == 2) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::March)); + } + if (month == 3) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::April)); + } + if (month == 4) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::May)); + } + if (month == 5) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::June)); + } + if (month == 6) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::July)); + } + if (month == 7) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::August)); + } + if (month == 8) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::September)); + } + if (month == 9) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::October)); + } + if (month == 10) { + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::November)); + } + + return static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::December)); +} + +} // namespace + +CFWL_MonthCalendar::CFWL_MonthCalendar( + const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter) + : IFWL_Widget(app, std::move(properties), pOuter), + m_bInitialized(false), + m_pDateTime(new CFX_DateTime), + m_iCurYear(2011), + m_iCurMonth(1), + m_iYear(2011), + m_iMonth(1), + m_iDay(1), + m_iHovered(-1), + m_iLBtnPartStates(CFWL_PartState_Normal), + m_iRBtnPartStates(CFWL_PartState_Normal), + m_bFlag(false) { + m_rtHead.Reset(); + m_rtWeek.Reset(); + m_rtLBtn.Reset(); + m_rtRBtn.Reset(); + m_rtDates.Reset(); + m_rtHSep.Reset(); + m_rtHeadText.Reset(); + m_rtToday.Reset(); + m_rtTodayFlag.Reset(); + m_rtClient.Reset(); + m_rtWeekNum.Reset(); + m_rtWeekNumSep.Reset(); +} + +CFWL_MonthCalendar::~CFWL_MonthCalendar() { + ClearDateItem(); + m_arrSelDays.RemoveAll(); +} + +FWL_Type CFWL_MonthCalendar::GetClassID() const { + return FWL_Type::MonthCalendar; +} + +void CFWL_MonthCalendar::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { + if (!bAutoSize) { + rect = m_pProperties->m_rtWidget; + return; + } + + CFX_SizeF fs = CalcSize(true); + rect.Set(0, 0, fs.x, fs.y); + IFWL_Widget::GetWidgetRect(rect, true); +} + +void CFWL_MonthCalendar::Update() { + if (IsLocked()) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + GetCapValue(); + if (!m_bInitialized) { + InitDate(); + m_bInitialized = true; + } + + ClearDateItem(); + ResetDateItem(); + Layout(); +} + +void CFWL_MonthCalendar::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + if (HasBorder()) + DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); + if (HasEdge()) + DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); + + DrawBackground(pGraphics, pTheme, pMatrix); + DrawHeadBK(pGraphics, pTheme, pMatrix); + DrawLButton(pGraphics, pTheme, pMatrix); + DrawRButton(pGraphics, pTheme, pMatrix); + DrawSeperator(pGraphics, pTheme, pMatrix); + DrawDatesInBK(pGraphics, pTheme, pMatrix); + DrawDatesInCircle(pGraphics, pTheme, pMatrix); + DrawCaption(pGraphics, pTheme, pMatrix); + DrawWeek(pGraphics, pTheme, pMatrix); + DrawDatesIn(pGraphics, pTheme, pMatrix); + DrawDatesOut(pGraphics, pTheme, pMatrix); + DrawToday(pGraphics, pTheme, pMatrix); + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) { + DrawWeekNumberSep(pGraphics, pTheme, pMatrix); + DrawWeekNumber(pGraphics, pTheme, pMatrix); + } +} + +void CFWL_MonthCalendar::SetSelect(int32_t iYear, + int32_t iMonth, + int32_t iDay) { + ChangeToMonth(iYear, iMonth); + AddSelDay(iDay); +} + +void CFWL_MonthCalendar::DrawBackground(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::Background; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_rtPart = m_rtClient; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶ms); +} + +void CFWL_MonthCalendar::DrawHeadBK(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::Header; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_rtPart = m_rtHead; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶ms); +} + +void CFWL_MonthCalendar::DrawLButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::LBtn; + params.m_pGraphics = pGraphics; + params.m_dwStates = m_iLBtnPartStates; + params.m_rtPart = m_rtLBtn; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶ms); +} + +void CFWL_MonthCalendar::DrawRButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::RBtn; + params.m_pGraphics = pGraphics; + params.m_dwStates = m_iRBtnPartStates; + params.m_rtPart = m_rtRBtn; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶ms); +} + +void CFWL_MonthCalendar::DrawCaption(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeText textParam; + textParam.m_pWidget = this; + textParam.m_iPart = CFWL_Part::Caption; + textParam.m_dwStates = CFWL_PartState_Normal; + textParam.m_pGraphics = pGraphics; + int32_t iYear; + int32_t iMonth; + iYear = m_iCurYear; + iMonth = m_iCurMonth; + CFX_WideString wsCation; + GetHeadText(iYear, iMonth, wsCation); + textParam.m_wsText = wsCation; + m_szHead = CalcTextSize(textParam.m_wsText, m_pProperties->m_pThemeProvider); + CalcHeadSize(); + textParam.m_rtPart = m_rtHeadText; + textParam.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; + textParam.m_iTTOAlign = FDE_TTOALIGNMENT_Center; + if (pMatrix) + textParam.m_matrix.Concat(*pMatrix); + pTheme->DrawText(&textParam); +} + +void CFWL_MonthCalendar::DrawSeperator(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::HSeparator; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_rtPart = m_rtHSep; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶ms); +} + +void CFWL_MonthCalendar::DrawDatesInBK(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::DateInBK; + params.m_pGraphics = pGraphics; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + + int32_t iCount = m_arrDates.GetSize(); + for (int32_t j = 0; j < iCount; j++) { + DATEINFO* pDataInfo = m_arrDates.GetAt(j); + if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Selected) { + params.m_dwStates |= CFWL_PartState_Selected; + if (((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) == + 0) && + pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) { + params.m_dwStates |= CFWL_PartState_Flagged; + } + if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Focused) + params.m_dwStates |= CFWL_PartState_Focused; + } else if (j == m_iHovered - 1) { + params.m_dwStates |= CFWL_PartState_Hovered; + } else if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) { + params.m_dwStates = CFWL_PartState_Flagged; + pTheme->DrawBackground(¶ms); + } + params.m_rtPart = pDataInfo->rect; + pTheme->DrawBackground(¶ms); + params.m_dwStates = 0; + } +} + +void CFWL_MonthCalendar::DrawWeek(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeText params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::Week; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; + CFX_RectF rtDayOfWeek; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + + for (int32_t i = 0; i < 7; i++) { + rtDayOfWeek.Set(m_rtWeek.left + i * (m_szCell.x + MONTHCAL_HMARGIN * 2), + m_rtWeek.top, m_szCell.x, m_szCell.y); + params.m_rtPart = rtDayOfWeek; + params.m_wsText = *GetCapacityForDay(pTheme, params, i); + params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; + pTheme->DrawText(¶ms); + } +} + +void CFWL_MonthCalendar::DrawWeekNumber(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeText params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::WeekNum; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; + CFX_WideString wsWeekNum; + params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; + params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + + int32_t iMonthNum = m_pDateTime->GetMonth(); + int32_t iDayNum = FX_DaysInMonth(m_iCurYear, iMonthNum); + int32_t iTemp = 0; + FX_FLOAT fVStartPos = m_rtClient.top + m_fHeadHei + m_fHSepHei; + FX_FLOAT fHStartPos = m_rtClient.left; + for (int32_t i = 1; i <= iDayNum; i += 7) { + iTemp++; + m_rtWeekNum.Set(fHStartPos, fVStartPos + m_fDateCellHei * iTemp, + m_fWeekNumWid, m_fDateCellHei); + wsWeekNum.Format(L"0"); + params.m_wsText = wsWeekNum; + params.m_rtPart = m_rtWeekNum; + pTheme->DrawText(¶ms); + } +} + +void CFWL_MonthCalendar::DrawWeekNumberSep(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::WeekNumSep; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_rtPart = m_rtWeekNumSep; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶ms); +} + +void CFWL_MonthCalendar::DrawToday(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) + return; + + CFWL_ThemeText params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::Today; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; + + CFX_WideString* wsDay = static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Today)); + CFX_WideString wsText; + GetTodayText(m_iYear, m_iMonth, m_iDay, wsText); + params.m_wsText = *wsDay + wsText; + + m_szToday = CalcTextSize(params.m_wsText, m_pProperties->m_pThemeProvider); + CalcTodaySize(); + params.m_rtPart = m_rtToday; + params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawText(¶ms); +} + +void CFWL_MonthCalendar::DrawDatesIn(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeText params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::DatesIn; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + + int32_t iCount = m_arrDates.GetSize(); + for (int32_t j = 0; j < iCount; j++) { + DATEINFO* pDataInfo = m_arrDates.GetAt(j); + params.m_wsText = pDataInfo->wsDay; + params.m_rtPart = pDataInfo->rect; + params.m_dwStates = pDataInfo->dwStates; + if (j + 1 == m_iHovered) + params.m_dwStates |= CFWL_PartState_Hovered; + params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; + pTheme->DrawText(¶ms); + } +} + +void CFWL_MonthCalendar::DrawDatesOut(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeText params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::DatesOut; + params.m_pGraphics = pGraphics; + params.m_dwStates = CFWL_PartState_Normal; + params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawText(¶ms); +} + +void CFWL_MonthCalendar::DrawDatesInCircle(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) + return; + if (m_iMonth != m_iCurMonth || m_iYear != m_iCurYear) + return; + if (m_iDay < 1 || m_iDay > m_arrDates.GetSize()) + return; + + DATEINFO* pDate = m_arrDates[m_iDay - 1]; + if (!pDate) + return; + + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::DateInCircle; + params.m_pGraphics = pGraphics; + params.m_rtPart = pDate->rect; + params.m_dwStates = CFWL_PartState_Normal; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + pTheme->DrawBackground(¶ms); +} + +CFX_SizeF CFWL_MonthCalendar::CalcSize(bool bAutoSize) { + if (!m_pProperties->m_pThemeProvider) + return CFX_SizeF(); + if (!bAutoSize) { + GetClientRect(m_rtClient); + return CFX_SizeF(m_rtClient.width, m_rtClient.height); + } + + CFX_SizeF fs; + CFWL_ThemePart params; + params.m_pWidget = this; + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + FX_FLOAT fMaxWeekW = 0.0f; + FX_FLOAT fMaxWeekH = 0.0f; + + for (uint32_t i = 0; i < 7; ++i) { + CFX_SizeF sz = CalcTextSize(*GetCapacityForDay(pTheme, params, i), + m_pProperties->m_pThemeProvider); + fMaxWeekW = (fMaxWeekW >= sz.x) ? fMaxWeekW : sz.x; + fMaxWeekH = (fMaxWeekH >= sz.y) ? fMaxWeekH : sz.y; + } + + FX_FLOAT fDayMaxW = 0.0f; + FX_FLOAT fDayMaxH = 0.0f; + for (int day = 10; day <= 31; day++) { + CFX_WideString wsDay; + wsDay.Format(L"%d", day); + CFX_SizeF sz = CalcTextSize(wsDay, m_pProperties->m_pThemeProvider); + fDayMaxW = (fDayMaxW >= sz.x) ? fDayMaxW : sz.x; + fDayMaxH = (fDayMaxH >= sz.y) ? fDayMaxH : sz.y; + } + m_szCell.x = FX_FLOAT((fMaxWeekW >= fDayMaxW) ? (int)(fMaxWeekW + 0.5) + : (int)(fDayMaxW + 0.5)); + m_szCell.y = (fMaxWeekH >= fDayMaxH) ? fMaxWeekH : fDayMaxH; + fs.x = m_szCell.x * MONTHCAL_COLUMNS + + MONTHCAL_HMARGIN * MONTHCAL_COLUMNS * 2 + + MONTHCAL_HEADER_BTN_HMARGIN * 2; + FX_FLOAT fMonthMaxW = 0.0f; + FX_FLOAT fMonthMaxH = 0.0f; + + for (uint32_t i = 0; i < 12; ++i) { + CFX_SizeF sz = CalcTextSize(*GetCapacityForMonth(pTheme, params, i), + m_pProperties->m_pThemeProvider); + fMonthMaxW = (fMonthMaxW >= sz.x) ? fMonthMaxW : sz.x; + fMonthMaxH = (fMonthMaxH >= sz.y) ? fMonthMaxH : sz.y; + } + + CFX_WideString wsYear; + GetHeadText(m_iYear, m_iMonth, wsYear); + + CFX_SizeF szYear = CalcTextSize(wsYear, m_pProperties->m_pThemeProvider); + fMonthMaxH = std::max(fMonthMaxH, szYear.y); + m_szHead = CFX_SizeF(fMonthMaxW + szYear.x, fMonthMaxH); + fMonthMaxW = m_szHead.x + MONTHCAL_HEADER_BTN_HMARGIN * 2 + m_szCell.x * 2; + fs.x = std::max(fs.x, fMonthMaxW); + + CFX_WideString wsToday; + GetTodayText(m_iYear, m_iMonth, m_iDay, wsToday); + CFX_WideString* wsText = static_cast( + pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Today)); + m_wsToday = *wsText + wsToday; + m_szToday = CalcTextSize(wsToday, m_pProperties->m_pThemeProvider); + m_szToday.y = (m_szToday.y >= m_szCell.y) ? m_szToday.y : m_szCell.y; + fs.y = m_szCell.x + m_szCell.y * (MONTHCAL_ROWS - 2) + m_szToday.y + + MONTHCAL_VMARGIN * MONTHCAL_ROWS * 2 + MONTHCAL_HEADER_BTN_VMARGIN * 4; + return fs; +} + +void CFWL_MonthCalendar::CalcHeadSize() { + FX_FLOAT fHeadHMargin = (m_rtClient.width - m_szHead.x) / 2; + FX_FLOAT fHeadVMargin = (m_szCell.x - m_szHead.y) / 2; + m_rtHeadText.Set(m_rtClient.left + fHeadHMargin, + m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN + + MONTHCAL_VMARGIN + fHeadVMargin, + m_szHead.x, m_szHead.y); +} + +void CFWL_MonthCalendar::CalcTodaySize() { + m_rtTodayFlag.Set( + m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN, + m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN, + m_szCell.x, m_szToday.y); + m_rtToday.Set( + m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + m_szCell.x + + MONTHCAL_HMARGIN * 2, + m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN, + m_szToday.x, m_szToday.y); +} + +void CFWL_MonthCalendar::Layout() { + GetClientRect(m_rtClient); + + m_rtHead.Set( + m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, m_rtClient.top, + m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, + m_szCell.x + (MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN) * 2); + m_rtWeek.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, m_rtHead.bottom(), + m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, + m_szCell.y + MONTHCAL_VMARGIN * 2); + m_rtLBtn.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, + m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN, m_szCell.x, + m_szCell.x); + m_rtRBtn.Set(m_rtClient.left + m_rtClient.width - + MONTHCAL_HEADER_BTN_HMARGIN - m_szCell.x, + m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN, m_szCell.x, + m_szCell.x); + m_rtHSep.Set( + m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN, + m_rtWeek.bottom() - MONTHCAL_VMARGIN, + m_rtClient.width - (MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN) * 2, + MONTHCAL_HSEP_HEIGHT); + m_rtDates.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, + m_rtWeek.bottom(), + m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, + m_szCell.y * (MONTHCAL_ROWS - 3) + + MONTHCAL_VMARGIN * (MONTHCAL_ROWS - 3) * 2); + + CalDateItem(); +} + +void CFWL_MonthCalendar::CalDateItem() { + bool bNewWeek = false; + int32_t iWeekOfMonth = 0; + FX_FLOAT fLeft = m_rtDates.left; + FX_FLOAT fTop = m_rtDates.top; + int32_t iCount = m_arrDates.GetSize(); + for (int32_t i = 0; i < iCount; i++) { + DATEINFO* pDateInfo = m_arrDates.GetAt(i); + if (bNewWeek) { + iWeekOfMonth++; + bNewWeek = false; + } + pDateInfo->rect.Set( + fLeft + pDateInfo->iDayOfWeek * (m_szCell.x + (MONTHCAL_HMARGIN * 2)), + fTop + iWeekOfMonth * (m_szCell.y + (MONTHCAL_VMARGIN * 2)), + m_szCell.x + (MONTHCAL_HMARGIN * 2), + m_szCell.y + (MONTHCAL_VMARGIN * 2)); + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) + pDateInfo->rect.Offset(m_fWeekNumWid, 0); + if (pDateInfo->iDayOfWeek >= 6) + bNewWeek = true; + } +} + +void CFWL_MonthCalendar::GetCapValue() { + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + CFWL_ThemePart part; + part.m_pWidget = this; + m_fHeadWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderWidth)); + m_fHeadHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderHeight)); + m_fHeadBtnWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnWidth)); + m_fHeadBtnHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnHeight)); + m_fHeadBtnHMargin = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnHMargin)); + m_fHeadBtnVMargin = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnVMargin)); + m_fHeadTextWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextWidth)); + m_fHeadTextHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextHeight)); + m_fHeadTextHMargin = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextHMargin)); + m_fHeadTextVMargin = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextVMargin)); + m_fHSepWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HSepWidth)); + m_fHSepHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HSepHeight)); + m_fWeekNumWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekNumWidth)); + m_fSepDOffset = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepDOffset)); + m_fSepX = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepX)); + m_fSepY = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepY)); + m_fWeekNumHeigh = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekNumHeight)); + m_fWeekWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekWidth)); + m_fWeekHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekHeight)); + m_fDateCellWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::DatesCellWidth)); + m_fDateCellHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::DatesCellHeight)); + m_fTodayWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayWidth)); + m_fTodayHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayHeight)); + m_fTodayFlagWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayFlagWidth)); + m_fMCWid = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Width)); + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) + m_fMCWid += m_fWeekNumWid; + + m_fMCHei = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Height)); +} + +void CFWL_MonthCalendar::InitDate() { + // TODO(dsinclair): These should pull the real today values instead of + // pretending it's 2011-01-01. + m_iYear = 2011; + m_iMonth = 1; + m_iDay = 1; + m_iCurYear = m_iYear; + m_iCurMonth = m_iMonth; + + GetTodayText(m_iYear, m_iMonth, m_iDay, m_wsToday); + GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead); + m_dtMin = DATE(1500, 12, 1); + m_dtMax = DATE(2200, 1, 1); +} + +void CFWL_MonthCalendar::ClearDateItem() { + for (int32_t i = 0; i < m_arrDates.GetSize(); i++) + delete m_arrDates.GetAt(i); + m_arrDates.RemoveAll(); +} + +void CFWL_MonthCalendar::ResetDateItem() { + m_pDateTime->Set(m_iCurYear, m_iCurMonth, 1); + int32_t iDays = FX_DaysInMonth(m_iCurYear, m_iCurMonth); + int32_t iDayOfWeek = m_pDateTime->GetDayOfWeek(); + for (int32_t i = 0; i < iDays; i++) { + if (iDayOfWeek >= 7) + iDayOfWeek = 0; + + CFX_WideString wsDay; + wsDay.Format(L"%d", i + 1); + uint32_t dwStates = 0; + if (m_iYear == m_iCurYear && m_iMonth == m_iCurMonth && m_iDay == (i + 1)) + dwStates |= FWL_ITEMSTATE_MCD_Flag; + if (m_arrSelDays.Find(i + 1) != -1) + dwStates |= FWL_ITEMSTATE_MCD_Selected; + + CFX_RectF rtDate; + rtDate.Set(0, 0, 0, 0); + m_arrDates.Add(new DATEINFO(i + 1, iDayOfWeek, dwStates, rtDate, wsDay)); + iDayOfWeek++; + } +} + +void CFWL_MonthCalendar::NextMonth() { + int32_t iYear = m_iCurYear, iMonth = m_iCurMonth; + if (iMonth >= 12) { + iMonth = 1; + iYear++; + } else { + iMonth++; + } + DATE dt(m_iCurYear, m_iCurMonth, 1); + if (!(dt < m_dtMax)) + return; + + m_iCurYear = iYear, m_iCurMonth = iMonth; + ChangeToMonth(m_iCurYear, m_iCurMonth); +} + +void CFWL_MonthCalendar::PrevMonth() { + int32_t iYear = m_iCurYear, iMonth = m_iCurMonth; + if (iMonth <= 1) { + iMonth = 12; + iYear--; + } else { + iMonth--; + } + + DATE dt(m_iCurYear, m_iCurMonth, 1); + if (!(dt > m_dtMin)) + return; + + m_iCurYear = iYear, m_iCurMonth = iMonth; + ChangeToMonth(m_iCurYear, m_iCurMonth); +} + +void CFWL_MonthCalendar::ChangeToMonth(int32_t iYear, int32_t iMonth) { + m_iCurYear = iYear; + m_iCurMonth = iMonth; + m_iHovered = -1; + + ClearDateItem(); + ResetDateItem(); + CalDateItem(); + GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead); +} + +void CFWL_MonthCalendar::RemoveSelDay(int32_t iDay, bool bAll) { + if (iDay == -1 && !bAll) + return; + if (bAll) { + int32_t iCount = m_arrSelDays.GetSize(); + int32_t iDatesCount = m_arrDates.GetSize(); + for (int32_t i = 0; i < iCount; i++) { + int32_t iSelDay = m_arrSelDays.GetAt(i); + if (iSelDay <= iDatesCount) { + DATEINFO* pDateInfo = m_arrDates.GetAt(iSelDay - 1); + pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected; + } + } + m_arrSelDays.RemoveAll(); + return; + } + + int32_t index = m_arrSelDays.Find(iDay); + if (index == -1) + return; + + int32_t iSelDay = m_arrSelDays.GetAt(iDay); + int32_t iDatesCount = m_arrDates.GetSize(); + if (iSelDay <= iDatesCount) { + DATEINFO* pDateInfo = m_arrDates.GetAt(iSelDay - 1); + pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected; + } + m_arrSelDays.RemoveAt(index); +} + +void CFWL_MonthCalendar::AddSelDay(int32_t iDay) { + ASSERT(iDay > 0); + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) + return; + + if (m_arrSelDays.Find(iDay) != -1) + return; + + RemoveSelDay(-1, true); + if (iDay <= m_arrDates.GetSize()) { + DATEINFO* pDateInfo = m_arrDates.GetAt(iDay - 1); + pDateInfo->dwStates |= FWL_ITEMSTATE_MCD_Selected; + } + m_arrSelDays.Add(iDay); +} + +void CFWL_MonthCalendar::JumpToToday() { + if (m_iYear != m_iCurYear || m_iMonth != m_iCurMonth) { + m_iCurYear = m_iYear; + m_iCurMonth = m_iMonth; + ChangeToMonth(m_iYear, m_iMonth); + AddSelDay(m_iDay); + return; + } + + if (m_arrSelDays.Find(m_iDay) == -1) + AddSelDay(m_iDay); +} + +void CFWL_MonthCalendar::GetHeadText(int32_t iYear, + int32_t iMonth, + CFX_WideString& wsHead) { + ASSERT(iMonth > 0 && iMonth < 13); + static const FX_WCHAR* const pMonth[] = { + L"January", L"February", L"March", L"April", + L"May", L"June", L"July", L"August", + L"September", L"October", L"November", L"December"}; + wsHead.Format(L"%s, %d", pMonth[iMonth - 1], iYear); +} + +void CFWL_MonthCalendar::GetTodayText(int32_t iYear, + int32_t iMonth, + int32_t iDay, + CFX_WideString& wsToday) { + wsToday.Format(L", %d/%d/%d", iDay, iMonth, iYear); +} + +int32_t CFWL_MonthCalendar::GetDayAtPoint(FX_FLOAT x, FX_FLOAT y) { + int32_t iCount = m_arrDates.GetSize(); + for (int32_t i = 0; i < iCount; i++) { + DATEINFO* pDateInfo = m_arrDates.GetAt(i); + if (pDateInfo->rect.Contains(x, y)) + return ++i; + } + return -1; +} + +void CFWL_MonthCalendar::GetDayRect(int32_t iDay, CFX_RectF& rtDay) { + if (iDay <= 0 || iDay > m_arrDates.GetSize()) + return; + + DATEINFO* pDateInfo = m_arrDates[iDay - 1]; + if (!pDateInfo) + return; + rtDay = pDateInfo->rect; +} + +void CFWL_MonthCalendar::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + CFWL_MessageType dwMsgCode = pMessage->GetClassID(); + switch (dwMsgCode) { + case CFWL_MessageType::SetFocus: + case CFWL_MessageType::KillFocus: + GetOuter()->GetDelegate()->OnProcessMessage(pMessage); + break; + case CFWL_MessageType::Key: + break; + case CFWL_MessageType::Mouse: { + CFWL_MsgMouse* pMouse = static_cast(pMessage); + switch (pMouse->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(pMouse); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMouse); + break; + case FWL_MouseCommand::Move: + OnMouseMove(pMouse); + break; + case FWL_MouseCommand::Leave: + OnMouseLeave(pMouse); + break; + default: + break; + } + break; + } + default: + break; + } + IFWL_Widget::OnProcessMessage(pMessage); +} + +void CFWL_MonthCalendar::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +void CFWL_MonthCalendar::OnLButtonDown(CFWL_MsgMouse* pMsg) { + if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_iLBtnPartStates = CFWL_PartState_Pressed; + PrevMonth(); + Repaint(&m_rtClient); + } else if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_iRBtnPartStates |= CFWL_PartState_Pressed; + NextMonth(); + Repaint(&m_rtClient); + } else if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) { + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) == 0) { + JumpToToday(); + Repaint(&m_rtClient); + } + } else { + IFWL_DateTimePicker* pIPicker = static_cast(m_pOuter); + if (pIPicker->IsMonthCalendarVisible()) + m_bFlag = 1; + } +} + +void CFWL_MonthCalendar::OnLButtonUp(CFWL_MsgMouse* pMsg) { + if (m_pWidgetMgr->IsFormDisabled()) + return DisForm_OnLButtonUp(pMsg); + + if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_iLBtnPartStates = 0; + Repaint(&m_rtLBtn); + return; + } + if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_iRBtnPartStates = 0; + Repaint(&m_rtRBtn); + return; + } + if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) + return; + + int32_t iOldSel = 0; + if (m_arrSelDays.GetSize() > 0) + iOldSel = m_arrSelDays[0]; + + int32_t iCurSel = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); + CFX_RectF rt; + IFWL_DateTimePicker* pIPicker = static_cast(m_pOuter); + pIPicker->GetFormProxy()->GetWidgetRect(rt); + rt.Set(0, 0, rt.width, rt.height); + if (iCurSel > 0) { + DATEINFO* lpDatesInfo = m_arrDates.GetAt(iCurSel - 1); + CFX_RectF rtInvalidate(lpDatesInfo->rect); + if (iOldSel > 0 && iOldSel <= m_arrDates.GetSize()) { + lpDatesInfo = m_arrDates.GetAt(iOldSel - 1); + rtInvalidate.Union(lpDatesInfo->rect); + } + AddSelDay(iCurSel); + if (!m_pOuter) + return; + + pIPicker->ProcessSelChanged(m_iCurYear, m_iCurMonth, iCurSel); + pIPicker->ShowMonthCalendar(false); + } else if (m_bFlag && (!rt.Contains(pMsg->m_fx, pMsg->m_fy))) { + pIPicker->ShowMonthCalendar(false); + } + m_bFlag = 0; +} + +void CFWL_MonthCalendar::DisForm_OnLButtonUp(CFWL_MsgMouse* pMsg) { + if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_iLBtnPartStates = 0; + Repaint(&(m_rtLBtn)); + return; + } + if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { + m_iRBtnPartStates = 0; + Repaint(&(m_rtRBtn)); + return; + } + if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) + return; + + int32_t iOldSel = 0; + if (m_arrSelDays.GetSize() > 0) + iOldSel = m_arrSelDays[0]; + + int32_t iCurSel = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); + if (iCurSel > 0) { + DATEINFO* lpDatesInfo = m_arrDates.GetAt(iCurSel - 1); + CFX_RectF rtInvalidate(lpDatesInfo->rect); + if (iOldSel > 0 && iOldSel <= m_arrDates.GetSize()) { + lpDatesInfo = m_arrDates.GetAt(iOldSel - 1); + rtInvalidate.Union(lpDatesInfo->rect); + } + AddSelDay(iCurSel); + IFWL_DateTimePicker* pDateTime = + static_cast(m_pOuter); + pDateTime->ProcessSelChanged(m_iCurYear, m_iCurMonth, iCurSel); + pDateTime->ShowMonthCalendar(false); + } +} + +void CFWL_MonthCalendar::OnMouseMove(CFWL_MsgMouse* pMsg) { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) + return; + + bool bRepaint = false; + CFX_RectF rtInvalidate; + rtInvalidate.Set(0, 0, 0, 0); + if (m_rtDates.Contains(pMsg->m_fx, pMsg->m_fy)) { + int32_t iHover = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); + bRepaint = m_iHovered != iHover; + if (bRepaint) { + if (m_iHovered > 0) + GetDayRect(m_iHovered, rtInvalidate); + if (iHover > 0) { + CFX_RectF rtDay; + GetDayRect(iHover, rtDay); + if (rtInvalidate.IsEmpty()) + rtInvalidate = rtDay; + else + rtInvalidate.Union(rtDay); + } + } + m_iHovered = iHover; + } else { + bRepaint = m_iHovered > 0; + if (bRepaint) + GetDayRect(m_iHovered, rtInvalidate); + + m_iHovered = -1; + } + if (bRepaint && !rtInvalidate.IsEmpty()) + Repaint(&rtInvalidate); +} + +void CFWL_MonthCalendar::OnMouseLeave(CFWL_MsgMouse* pMsg) { + if (m_iHovered <= 0) + return; + + CFX_RectF rtInvalidate; + rtInvalidate.Set(0, 0, 0, 0); + GetDayRect(m_iHovered, rtInvalidate); + m_iHovered = -1; + if (!rtInvalidate.IsEmpty()) + Repaint(&rtInvalidate); +} + +CFWL_MonthCalendar::DATEINFO::DATEINFO(int32_t day, + int32_t dayofweek, + uint32_t dwSt, + CFX_RectF rc, + CFX_WideString& wsday) + : iDay(day), + iDayOfWeek(dayofweek), + dwStates(dwSt), + rect(rc), + wsDay(wsday) {} + +CFWL_MonthCalendar::DATEINFO::~DATEINFO() {} diff --git a/xfa/fwl/core/cfwl_monthcalendar.h b/xfa/fwl/core/cfwl_monthcalendar.h new file mode 100644 index 0000000000..1acdf5c977 --- /dev/null +++ b/xfa/fwl/core/cfwl_monthcalendar.h @@ -0,0 +1,228 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CORE_CFWL_MONTHCALENDAR_H_ +#define XFA_FWL_CORE_CFWL_MONTHCALENDAR_H_ + +#include + +#include "xfa/fgas/localization/fgas_datetime.h" +#include "xfa/fwl/core/cfwl_event.h" +#include "xfa/fwl/core/cfwl_widgetproperties.h" +#include "xfa/fwl/core/ifwl_widget.h" + +#define FWL_STYLEEXT_MCD_MultiSelect (1L << 0) +#define FWL_STYLEEXT_MCD_NoToday (1L << 1) +#define FWL_STYLEEXT_MCD_NoTodayCircle (1L << 2) +#define FWL_STYLEEXT_MCD_WeekNumbers (1L << 3) +#define FWL_ITEMSTATE_MCD_Nomal (0L << 0) +#define FWL_ITEMSTATE_MCD_Flag (1L << 0) +#define FWL_ITEMSTATE_MCD_Selected (1L << 1) +#define FWL_ITEMSTATE_MCD_Focused (1L << 2) + +class CFWL_MsgMouse; +class IFWL_Widget; + +class CFWL_MonthCalendar : public IFWL_Widget { + public: + CFWL_MonthCalendar(const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter); + ~CFWL_MonthCalendar() override; + + // FWL_WidgetImp + FWL_Type GetClassID() const override; + void GetWidgetRect(CFX_RectF& rect, bool bAutoSize = false) override; + void Update() override; + void DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + void SetSelect(int32_t iYear, int32_t iMonth, int32_t iDay); + + private: + struct DATE { + DATE() : iYear(0), iMonth(0), iDay(0) {} + + DATE(int32_t year, int32_t month, int32_t day) + : iYear(year), iMonth(month), iDay(day) {} + + bool operator<(const DATE& right) { + if (iYear < right.iYear) + return true; + if (iYear == right.iYear) { + if (iMonth < right.iMonth) + return true; + if (iMonth == right.iMonth) + return iDay < right.iDay; + } + return false; + } + + bool operator>(const DATE& right) { + if (iYear > right.iYear) + return true; + if (iYear == right.iYear) { + if (iMonth > right.iMonth) + return true; + if (iMonth == right.iMonth) + return iDay > right.iDay; + } + return false; + } + + int32_t iYear; + int32_t iMonth; + int32_t iDay; + }; + struct DATEINFO { + DATEINFO(int32_t day, + int32_t dayofweek, + uint32_t dwSt, + CFX_RectF rc, + CFX_WideString& wsday); + ~DATEINFO(); + + int32_t iDay; + int32_t iDayOfWeek; + uint32_t dwStates; + CFX_RectF rect; + CFX_WideString wsDay; + }; + + void DrawBackground(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawHeadBK(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawLButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawRButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawCaption(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawSeperator(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawDatesInBK(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawWeek(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawWeekNumber(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawWeekNumberSep(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawToday(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawDatesIn(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawDatesOut(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawDatesInCircle(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + CFX_SizeF CalcSize(bool bAutoSize = false); + void Layout(); + void CalcHeadSize(); + void CalcTodaySize(); + void CalDateItem(); + void GetCapValue(); + void InitDate(); + void ClearDateItem(); + void ResetDateItem(); + void NextMonth(); + void PrevMonth(); + void ChangeToMonth(int32_t iYear, int32_t iMonth); + void RemoveSelDay(int32_t iDay, bool bAll = false); + void AddSelDay(int32_t iDay); + void JumpToToday(); + void GetHeadText(int32_t iYear, int32_t iMonth, CFX_WideString& wsHead); + void GetTodayText(int32_t iYear, + int32_t iMonth, + int32_t iDay, + CFX_WideString& wsToday); + int32_t GetDayAtPoint(FX_FLOAT x, FX_FLOAT y); + void GetDayRect(int32_t iDay, CFX_RectF& rtDay); + void OnLButtonDown(CFWL_MsgMouse* pMsg); + void OnLButtonUp(CFWL_MsgMouse* pMsg); + void DisForm_OnLButtonUp(CFWL_MsgMouse* pMsg); + void OnMouseMove(CFWL_MsgMouse* pMsg); + void OnMouseLeave(CFWL_MsgMouse* pMsg); + + bool m_bInitialized; + CFX_RectF m_rtHead; + CFX_RectF m_rtWeek; + CFX_RectF m_rtLBtn; + CFX_RectF m_rtRBtn; + CFX_RectF m_rtDates; + CFX_RectF m_rtHSep; + CFX_RectF m_rtHeadText; + CFX_RectF m_rtToday; + CFX_RectF m_rtTodayFlag; + CFX_RectF m_rtWeekNum; + CFX_RectF m_rtWeekNumSep; + CFX_WideString m_wsHead; + CFX_WideString m_wsToday; + std::unique_ptr m_pDateTime; + CFX_ArrayTemplate m_arrDates; + int32_t m_iCurYear; + int32_t m_iCurMonth; + int32_t m_iYear; + int32_t m_iMonth; + int32_t m_iDay; + int32_t m_iHovered; + int32_t m_iLBtnPartStates; + int32_t m_iRBtnPartStates; + DATE m_dtMin; + DATE m_dtMax; + CFX_SizeF m_szHead; + CFX_SizeF m_szCell; + CFX_SizeF m_szToday; + CFX_ArrayTemplate m_arrSelDays; + CFX_RectF m_rtClient; + FX_FLOAT m_fHeadWid; + FX_FLOAT m_fHeadHei; + FX_FLOAT m_fHeadBtnWid; + FX_FLOAT m_fHeadBtnHei; + FX_FLOAT m_fHeadBtnHMargin; + FX_FLOAT m_fHeadBtnVMargin; + FX_FLOAT m_fHeadTextWid; + FX_FLOAT m_fHeadTextHei; + FX_FLOAT m_fHeadTextHMargin; + FX_FLOAT m_fHeadTextVMargin; + FX_FLOAT m_fHSepWid; + FX_FLOAT m_fHSepHei; + FX_FLOAT m_fWeekNumWid; + FX_FLOAT m_fSepDOffset; + FX_FLOAT m_fSepX; + FX_FLOAT m_fSepY; + FX_FLOAT m_fWeekNumHeigh; + FX_FLOAT m_fWeekWid; + FX_FLOAT m_fWeekHei; + FX_FLOAT m_fDateCellWid; + FX_FLOAT m_fDateCellHei; + FX_FLOAT m_fTodayWid; + FX_FLOAT m_fTodayHei; + FX_FLOAT m_fTodayFlagWid; + FX_FLOAT m_fMCWid; + FX_FLOAT m_fMCHei; + bool m_bFlag; +}; + +#endif // XFA_FWL_CORE_CFWL_MONTHCALENDAR_H_ diff --git a/xfa/fwl/core/cfwl_notedriver.cpp b/xfa/fwl/core/cfwl_notedriver.cpp index f4f325f95a..c12882a47e 100644 --- a/xfa/fwl/core/cfwl_notedriver.cpp +++ b/xfa/fwl/core/cfwl_notedriver.cpp @@ -13,6 +13,7 @@ #include "third_party/base/stl_util.h" #include "xfa/fwl/core/cfwl_app.h" #include "xfa/fwl/core/cfwl_eventtarget.h" +#include "xfa/fwl/core/cfwl_form.h" #include "xfa/fwl/core/cfwl_msgkey.h" #include "xfa/fwl/core/cfwl_msgkillfocus.h" #include "xfa/fwl/core/cfwl_msgmouse.h" @@ -20,7 +21,6 @@ #include "xfa/fwl/core/cfwl_msgsetfocus.h" #include "xfa/fwl/core/cfwl_noteloop.h" #include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/ifwl_form.h" CFWL_NoteDriver::CFWL_NoteDriver() : m_pHover(nullptr), @@ -103,7 +103,7 @@ bool CFWL_NoteDriver::SetFocus(IFWL_Widget* pFocus, bool bNotify) { if (pFocus) { IFWL_Widget* pWidget = pFocus->GetOwnerApp()->GetWidgetMgr()->GetSystemFormWidget(pFocus); - IFWL_Form* pForm = static_cast(pWidget); + CFWL_Form* pForm = static_cast(pWidget); if (pForm) pForm->SetSubFocus(pFocus); @@ -149,7 +149,7 @@ void CFWL_NoteDriver::NotifyTargetDestroy(IFWL_Widget* pNoteTarget) { UnregisterEventTarget(pNoteTarget); for (int32_t nIndex = 0; nIndex < m_forms.GetSize(); nIndex++) { - IFWL_Form* pForm = static_cast(m_forms[nIndex]); + CFWL_Form* pForm = static_cast(m_forms[nIndex]); if (!pForm) continue; @@ -275,7 +275,7 @@ bool CFWL_NoteDriver::DoSetFocus(CFWL_Message* pMessage, if (!pWidget) return false; - IFWL_Form* pForm = static_cast(pWidget); + CFWL_Form* pForm = static_cast(pWidget); IFWL_Widget* pSubFocus = pForm->GetSubFocus(); if (pSubFocus && ((pSubFocus->GetStates() & FWL_WGTSTATE_Focused) == 0)) { pMessage->m_pDstTarget = pSubFocus; @@ -296,7 +296,7 @@ bool CFWL_NoteDriver::DoKillFocus(CFWL_Message* pMessage, return true; } - IFWL_Form* pForm = static_cast(pMessage->m_pDstTarget); + CFWL_Form* pForm = static_cast(pMessage->m_pDstTarget); if (!pForm) return false; @@ -450,7 +450,7 @@ bool CFWL_NoteDriver::IsValidMessage(CFWL_Message* pMessage) { } for (int32_t j = 0; j < m_forms.GetSize(); j++) { - IFWL_Form* pForm = static_cast(m_forms[j]); + CFWL_Form* pForm = static_cast(m_forms[j]); if (pForm == pMessage->m_pDstTarget) return true; } diff --git a/xfa/fwl/core/cfwl_scrollbar.cpp b/xfa/fwl/core/cfwl_scrollbar.cpp new file mode 100644 index 0000000000..85ab271258 --- /dev/null +++ b/xfa/fwl/core/cfwl_scrollbar.cpp @@ -0,0 +1,563 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/core/cfwl_scrollbar.h" + +#include +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/core/cfwl_msgmouse.h" +#include "xfa/fwl/core/cfwl_msgmousewheel.h" +#include "xfa/fwl/core/cfwl_notedriver.h" +#include "xfa/fwl/core/cfwl_themebackground.h" +#include "xfa/fwl/core/cfwl_themepart.h" +#include "xfa/fwl/core/cfwl_timerinfo.h" +#include "xfa/fwl/core/ifwl_themeprovider.h" + +#define FWL_SCROLLBAR_Elapse 500 +#define FWL_SCROLLBAR_MinThumb 5 + +CFWL_ScrollBar::CFWL_ScrollBar( + const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter) + : IFWL_Widget(app, std::move(properties), pOuter), + m_pTimerInfo(nullptr), + m_fRangeMin(0), + m_fRangeMax(-1), + m_fPageSize(0), + m_fStepSize(0), + m_fPos(0), + m_fTrackPos(0), + m_iMinButtonState(CFWL_PartState_Normal), + m_iMaxButtonState(CFWL_PartState_Normal), + m_iThumbButtonState(CFWL_PartState_Normal), + m_iMinTrackState(CFWL_PartState_Normal), + m_iMaxTrackState(CFWL_PartState_Normal), + m_fLastTrackPos(0), + m_cpTrackPointX(0), + m_cpTrackPointY(0), + m_iMouseWheel(0), + m_bMouseDown(false), + m_fButtonLen(0), + m_bMinSize(false), + m_fMinThumb(FWL_SCROLLBAR_MinThumb), + m_Timer(this) { + m_rtClient.Reset(); + m_rtThumb.Reset(); + m_rtMinBtn.Reset(); + m_rtMaxBtn.Reset(); + m_rtMinTrack.Reset(); + m_rtMaxTrack.Reset(); +} + +CFWL_ScrollBar::~CFWL_ScrollBar() {} + +FWL_Type CFWL_ScrollBar::GetClassID() const { + return FWL_Type::ScrollBar; +} + +void CFWL_ScrollBar::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { + if (!bAutoSize) { + rect = m_pProperties->m_rtWidget; + return; + } + + rect.Set(0, 0, 0, 0); + FX_FLOAT* pfMinWidth = static_cast( + GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); + if (!pfMinWidth) + return; + if (IsVertical()) + rect.Set(0, 0, (*pfMinWidth), (*pfMinWidth) * 3); + else + rect.Set(0, 0, (*pfMinWidth) * 3, (*pfMinWidth)); + IFWL_Widget::GetWidgetRect(rect, true); +} + +void CFWL_ScrollBar::Update() { + if (IsLocked()) + return; + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + + Layout(); +} + +void CFWL_ScrollBar::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + if (!m_pProperties->m_pThemeProvider) + return; + + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + if (HasBorder()) + DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); + if (HasEdge()) + DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); + DrawTrack(pGraphics, pTheme, true, pMatrix); + DrawTrack(pGraphics, pTheme, false, pMatrix); + DrawArrowBtn(pGraphics, pTheme, true, pMatrix); + DrawArrowBtn(pGraphics, pTheme, false, pMatrix); + DrawThumb(pGraphics, pTheme, pMatrix); +} + +void CFWL_ScrollBar::SetTrackPos(FX_FLOAT fTrackPos) { + m_fTrackPos = fTrackPos; + CalcThumbButtonRect(m_rtThumb); + CalcMinTrackRect(m_rtMinTrack); + CalcMaxTrackRect(m_rtMaxTrack); +} + +bool CFWL_ScrollBar::DoScroll(FWL_SCBCODE dwCode, FX_FLOAT fPos) { + if (dwCode == FWL_SCBCODE::None) + return false; + return OnScroll(dwCode, fPos); +} + +void CFWL_ScrollBar::DrawTrack(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + bool bLower, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = bLower ? CFWL_Part::LowerTrack : CFWL_Part::UpperTrack; + param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) + ? CFWL_PartState_Disabled + : (bLower ? m_iMinTrackState : m_iMaxTrackState); + param.m_pGraphics = pGraphics; + param.m_matrix.Concat(*pMatrix); + param.m_rtPart = bLower ? m_rtMinTrack : m_rtMaxTrack; + pTheme->DrawBackground(¶m); +} + +void CFWL_ScrollBar::DrawArrowBtn(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + bool bMinBtn, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = bMinBtn ? CFWL_Part::ForeArrow : CFWL_Part::BackArrow; + param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) + ? CFWL_PartState_Disabled + : (bMinBtn ? m_iMinButtonState : m_iMaxButtonState); + param.m_pGraphics = pGraphics; + param.m_matrix.Concat(*pMatrix); + param.m_rtPart = bMinBtn ? m_rtMinBtn : m_rtMaxBtn; + if (param.m_rtPart.height > 0 && param.m_rtPart.width > 0) + pTheme->DrawBackground(¶m); +} + +void CFWL_ScrollBar::DrawThumb(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::Thumb; + param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) + ? CFWL_PartState_Disabled + : m_iThumbButtonState; + param.m_pGraphics = pGraphics; + param.m_matrix.Concat(*pMatrix); + param.m_rtPart = m_rtThumb; + pTheme->DrawBackground(¶m); +} + +void CFWL_ScrollBar::Layout() { + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; + CFWL_ThemePart part; + part.m_pWidget = this; + m_fMinThumb = *static_cast( + pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Size)); + GetClientRect(m_rtClient); + CalcButtonLen(); + CalcMinButtonRect(m_rtMinBtn); + CalcMaxButtonRect(m_rtMaxBtn); + CalcThumbButtonRect(m_rtThumb); + CalcMinTrackRect(m_rtMinTrack); + CalcMaxTrackRect(m_rtMaxTrack); +} + +void CFWL_ScrollBar::CalcButtonLen() { + m_fButtonLen = IsVertical() ? m_rtClient.width : m_rtClient.height; + FX_FLOAT fLength = IsVertical() ? m_rtClient.height : m_rtClient.width; + if (fLength < m_fButtonLen * 2) { + m_fButtonLen = fLength / 2; + m_bMinSize = true; + } else { + m_bMinSize = false; + } +} + +void CFWL_ScrollBar::CalcMinButtonRect(CFX_RectF& rect) { + rect.left = m_rtClient.left; + rect.top = m_rtClient.top; + rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen; + rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height; +} + +void CFWL_ScrollBar::CalcMaxButtonRect(CFX_RectF& rect) { + rect.left = + IsVertical() ? m_rtClient.left : m_rtClient.right() - m_fButtonLen; + rect.top = IsVertical() ? m_rtClient.bottom() - m_fButtonLen : m_rtClient.top; + rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen; + rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height; +} + +void CFWL_ScrollBar::CalcThumbButtonRect(CFX_RectF& rect) { + if (!IsEnabled()) { + m_rtThumb.Reset(); + return; + } + if (m_bMinSize) { + m_rtThumb.Empty(); + return; + } + + FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; + memset(&rect, 0, sizeof(CFX_Rect)); + if (fRange < 0) { + if (IsVertical()) + rect.Set(m_rtClient.left, m_rtMaxBtn.bottom(), m_rtClient.width, 0); + else + rect.Set(m_rtMaxBtn.right(), m_rtClient.top, 0, m_rtClient.height); + return; + } + + CFX_RectF rtClient = m_rtClient; + FX_FLOAT fLength = IsVertical() ? rtClient.height : rtClient.width; + FX_FLOAT fSize = m_fButtonLen; + fLength -= fSize * 2.0f; + if (fLength < fSize) + fLength = 0.0f; + + FX_FLOAT fThumbSize = fLength * fLength / (fRange + fLength); + fThumbSize = std::max(fThumbSize, m_fMinThumb); + + FX_FLOAT fDiff = std::max(fLength - fThumbSize, 0.0f); + FX_FLOAT fTrackPos = + std::max(std::min(m_fTrackPos, m_fRangeMax), m_fRangeMin); + if (!fRange) + return; + + FX_FLOAT iPos = fSize + fDiff * (fTrackPos - m_fRangeMin) / fRange; + rect.left = rtClient.left; + if (!IsVertical()) + rect.left += iPos; + + rect.top = rtClient.top; + if (IsVertical()) + rect.top += iPos; + + rect.width = IsVertical() ? rtClient.width : fThumbSize; + rect.height = IsVertical() ? fThumbSize : rtClient.height; +} + +void CFWL_ScrollBar::CalcMinTrackRect(CFX_RectF& rect) { + if (m_bMinSize) { + rect.Empty(); + return; + } + + FX_FLOAT fBottom = m_rtThumb.bottom(); + FX_FLOAT fRight = m_rtThumb.right(); + FX_FLOAT ix = (m_rtThumb.left + fRight) / 2; + FX_FLOAT iy = (m_rtThumb.top + fBottom) / 2; + rect.left = m_rtClient.left; + rect.top = m_rtClient.top; + bool bVertical = IsVertical(); + rect.width = bVertical ? m_rtClient.width : ix; + rect.height = bVertical ? iy : m_rtClient.height; +} + +void CFWL_ScrollBar::CalcMaxTrackRect(CFX_RectF& rect) { + if (m_bMinSize) { + rect.Empty(); + return; + } + + FX_FLOAT ix = (m_rtThumb.left + m_rtThumb.right()) / 2; + FX_FLOAT iy = (m_rtThumb.top + m_rtThumb.bottom()) / 2; + bool bVertical = IsVertical(); + rect.left = bVertical ? m_rtClient.left : ix; + rect.top = bVertical ? iy : m_rtClient.top; + rect.width = bVertical ? m_rtClient.width : m_rtClient.right() - ix; + rect.height = bVertical ? m_rtClient.bottom() - iy : m_rtClient.height; +} + +FX_FLOAT CFWL_ScrollBar::GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy) { + FX_FLOAT fDiffX = fx - m_cpTrackPointX; + FX_FLOAT fDiffY = fy - m_cpTrackPointY; + FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; + FX_FLOAT fPos; + + if (IsVertical()) { + fPos = fRange * fDiffY / + (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height); + } else { + fPos = fRange * fDiffX / + (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width); + } + + fPos += m_fLastTrackPos; + return std::min(std::max(fPos, m_fRangeMin), m_fRangeMax); +} + +void CFWL_ScrollBar::GetTrackRect(CFX_RectF& rect, bool bLower) { + bool bDisabled = !!(m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled); + if (bDisabled) { + rect = bLower ? m_rtMinTrack : m_rtMaxTrack; + return; + } + + FX_FLOAT fW = m_rtThumb.width / 2; + FX_FLOAT fH = m_rtThumb.height / 2; + bool bVert = IsVertical(); + if (bLower) { + if (bVert) { + FX_FLOAT fMinTrackHeight = m_rtMinTrack.height - fH - m_rtMinBtn.height; + fMinTrackHeight = (fMinTrackHeight >= 0.0f) ? fMinTrackHeight : 0.0f; + rect.Set(m_rtMinTrack.left, m_rtMinTrack.top + m_rtMinBtn.height, + m_rtMinTrack.width, fMinTrackHeight); + return; + } + + FX_FLOAT fMinTrackWidth = m_rtMinTrack.width - fW - m_rtMinBtn.width + 2; + fMinTrackWidth = (fMinTrackWidth >= 0.0f) ? fMinTrackWidth : 0.0f; + rect.Set(m_rtMinTrack.left + m_rtMinBtn.width - 1, m_rtMinTrack.top, + fMinTrackWidth, m_rtMinTrack.height); + return; + } + + if (bVert) { + FX_FLOAT fMaxTrackHeight = m_rtMaxTrack.height - fH - m_rtMaxBtn.height; + fMaxTrackHeight = (fMaxTrackHeight >= 0.0f) ? fMaxTrackHeight : 0.0f; + rect.Set(m_rtMaxTrack.left, m_rtMaxTrack.top + fH, m_rtMaxTrack.width, + fMaxTrackHeight); + return; + } + + FX_FLOAT fMaxTrackWidth = m_rtMaxTrack.width - fW - m_rtMaxBtn.width + 2; + fMaxTrackWidth = (fMaxTrackWidth >= 0.0f) ? fMaxTrackWidth : 0.0f; + rect.Set(m_rtMaxTrack.left + fW, m_rtMaxTrack.top, fMaxTrackWidth, + m_rtMaxTrack.height); +} + +bool CFWL_ScrollBar::SendEvent() { + if (m_iMinButtonState == CFWL_PartState_Pressed) { + DoScroll(FWL_SCBCODE::StepBackward, m_fTrackPos); + return false; + } + if (m_iMaxButtonState == CFWL_PartState_Pressed) { + DoScroll(FWL_SCBCODE::StepForward, m_fTrackPos); + return false; + } + if (m_iMinTrackState == CFWL_PartState_Pressed) { + DoScroll(FWL_SCBCODE::PageBackward, m_fTrackPos); + return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); + } + if (m_iMaxTrackState == CFWL_PartState_Pressed) { + DoScroll(FWL_SCBCODE::PageForward, m_fTrackPos); + return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); + } + if (m_iMouseWheel) { + FWL_SCBCODE dwCode = m_iMouseWheel < 0 ? FWL_SCBCODE::StepForward + : FWL_SCBCODE::StepBackward; + DoScroll(dwCode, m_fTrackPos); + } + return true; +} + +bool CFWL_ScrollBar::OnScroll(FWL_SCBCODE dwCode, FX_FLOAT fPos) { + bool bRet = true; + CFWL_EvtScroll ev; + ev.m_iScrollCode = dwCode; + ev.m_pSrcTarget = this; + ev.m_fPos = fPos; + ev.m_pRet = &bRet; + DispatchEvent(&ev); + return bRet; +} + +void CFWL_ScrollBar::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + CFWL_MessageType dwMsgCode = pMessage->GetClassID(); + if (dwMsgCode == CFWL_MessageType::Mouse) { + CFWL_MsgMouse* pMsg = static_cast(pMessage); + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); + break; + case FWL_MouseCommand::Move: + OnMouseMove(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); + break; + case FWL_MouseCommand::Leave: + OnMouseLeave(); + break; + default: + break; + } + } else if (dwMsgCode == CFWL_MessageType::MouseWheel) { + CFWL_MsgMouseWheel* pMsg = static_cast(pMessage); + OnMouseWheel(pMsg->m_fx, pMsg->m_fy, pMsg->m_dwFlags, pMsg->m_fDeltaX, + pMsg->m_fDeltaY); + } +} + +void CFWL_ScrollBar::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +void CFWL_ScrollBar::OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { + if (!IsEnabled()) + return; + + m_bMouseDown = true; + SetGrab(true); + m_cpTrackPointX = fx; + m_cpTrackPointY = fy; + m_fLastTrackPos = m_fTrackPos; + if (m_rtMinBtn.Contains(fx, fy)) + DoMouseDown(0, m_rtMinBtn, m_iMinButtonState, fx, fy); + else if (m_rtThumb.Contains(fx, fy)) + DoMouseDown(1, m_rtThumb, m_iThumbButtonState, fx, fy); + else if (m_rtMaxBtn.Contains(fx, fy)) + DoMouseDown(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); + else if (m_rtMinTrack.Contains(fx, fy)) + DoMouseDown(3, m_rtMinTrack, m_iMinTrackState, fx, fy); + else + DoMouseDown(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); + + if (!SendEvent()) + m_pTimerInfo = m_Timer.StartTimer(FWL_SCROLLBAR_Elapse, true); +} + +void CFWL_ScrollBar::OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { + m_pTimerInfo->StopTimer(); + m_bMouseDown = false; + DoMouseUp(0, m_rtMinBtn, m_iMinButtonState, fx, fy); + DoMouseUp(1, m_rtThumb, m_iThumbButtonState, fx, fy); + DoMouseUp(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); + DoMouseUp(3, m_rtMinTrack, m_iMinTrackState, fx, fy); + DoMouseUp(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); + SetGrab(false); +} + +void CFWL_ScrollBar::OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { + DoMouseMove(0, m_rtMinBtn, m_iMinButtonState, fx, fy); + DoMouseMove(1, m_rtThumb, m_iThumbButtonState, fx, fy); + DoMouseMove(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); + DoMouseMove(3, m_rtMinTrack, m_iMinTrackState, fx, fy); + DoMouseMove(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); +} + +void CFWL_ScrollBar::OnMouseLeave() { + DoMouseLeave(0, m_rtMinBtn, m_iMinButtonState); + DoMouseLeave(1, m_rtThumb, m_iThumbButtonState); + DoMouseLeave(2, m_rtMaxBtn, m_iMaxButtonState); + DoMouseLeave(3, m_rtMinTrack, m_iMinTrackState); + DoMouseLeave(4, m_rtMaxTrack, m_iMaxTrackState); +} + +void CFWL_ScrollBar::OnMouseWheel(FX_FLOAT fx, + FX_FLOAT fy, + uint32_t dwFlags, + FX_FLOAT fDeltaX, + FX_FLOAT fDeltaY) { + m_iMouseWheel = (int32_t)fDeltaX; + SendEvent(); + m_iMouseWheel = 0; +} + +void CFWL_ScrollBar::DoMouseDown(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState, + FX_FLOAT fx, + FX_FLOAT fy) { + if (!rtItem.Contains(fx, fy)) + return; + if (iState == CFWL_PartState_Pressed) + return; + + iState = CFWL_PartState_Pressed; + Repaint(&rtItem); +} + +void CFWL_ScrollBar::DoMouseUp(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState, + FX_FLOAT fx, + FX_FLOAT fy) { + int32_t iNewState = + rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered : CFWL_PartState_Normal; + if (iState == iNewState) + return; + + iState = iNewState; + Repaint(&rtItem); + OnScroll(FWL_SCBCODE::EndScroll, m_fTrackPos); +} + +void CFWL_ScrollBar::DoMouseMove(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState, + FX_FLOAT fx, + FX_FLOAT fy) { + if (!m_bMouseDown) { + int32_t iNewState = rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered + : CFWL_PartState_Normal; + if (iState == iNewState) + return; + + iState = iNewState; + Repaint(&rtItem); + } else if ((2 == iItem) && (m_iThumbButtonState == CFWL_PartState_Pressed)) { + FX_FLOAT fPos = GetTrackPointPos(fx, fy); + m_fTrackPos = fPos; + OnScroll(FWL_SCBCODE::TrackPos, fPos); + } +} + +void CFWL_ScrollBar::DoMouseLeave(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState) { + if (iState == CFWL_PartState_Normal) + return; + + iState = CFWL_PartState_Normal; + Repaint(&rtItem); +} + +void CFWL_ScrollBar::DoMouseHover(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState) { + if (iState == CFWL_PartState_Hovered) + return; + + iState = CFWL_PartState_Hovered; + Repaint(&rtItem); +} + +CFWL_ScrollBar::Timer::Timer(CFWL_ScrollBar* pToolTip) : CFWL_Timer(pToolTip) {} + +void CFWL_ScrollBar::Timer::Run(CFWL_TimerInfo* pTimerInfo) { + CFWL_ScrollBar* pButton = static_cast(m_pWidget); + + if (pButton->m_pTimerInfo) + pButton->m_pTimerInfo->StopTimer(); + + if (!pButton->SendEvent()) + pButton->m_pTimerInfo = StartTimer(0, true); +} diff --git a/xfa/fwl/core/cfwl_scrollbar.h b/xfa/fwl/core/cfwl_scrollbar.h new file mode 100644 index 0000000000..69f362d531 --- /dev/null +++ b/xfa/fwl/core/cfwl_scrollbar.h @@ -0,0 +1,150 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CORE_CFWL_SCROLLBAR_H_ +#define XFA_FWL_CORE_CFWL_SCROLLBAR_H_ + +#include + +#include "core/fxcrt/fx_system.h" +#include "xfa/fwl/core/cfwl_evtscroll.h" +#include "xfa/fwl/core/cfwl_timer.h" +#include "xfa/fwl/core/cfwl_widgetproperties.h" +#include "xfa/fwl/core/ifwl_widget.h" + +class IFWL_Widget; + +#define FWL_STYLEEXT_SCB_Horz (0L << 0) +#define FWL_STYLEEXT_SCB_Vert (1L << 0) + +class CFWL_ScrollBar : public IFWL_Widget { + public: + CFWL_ScrollBar(const CFWL_App* app, + std::unique_ptr properties, + IFWL_Widget* pOuter); + ~CFWL_ScrollBar() override; + + // IFWL_Widget + FWL_Type GetClassID() const override; + void GetWidgetRect(CFX_RectF& rect, bool bAutoSize = false) override; + void Update() override; + void DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + void GetRange(FX_FLOAT* fMin, FX_FLOAT* fMax) const { + ASSERT(fMin); + ASSERT(fMax); + *fMin = m_fRangeMin; + *fMax = m_fRangeMax; + } + void SetRange(FX_FLOAT fMin, FX_FLOAT fMax) { + m_fRangeMin = fMin; + m_fRangeMax = fMax; + } + FX_FLOAT GetPageSize() const { return m_fPageSize; } + void SetPageSize(FX_FLOAT fPageSize) { m_fPageSize = fPageSize; } + FX_FLOAT GetStepSize() const { return m_fStepSize; } + void SetStepSize(FX_FLOAT fStepSize) { m_fStepSize = fStepSize; } + FX_FLOAT GetPos() const { return m_fPos; } + void SetPos(FX_FLOAT fPos) { m_fPos = fPos; } + void SetTrackPos(FX_FLOAT fTrackPos); + + private: + class Timer : public CFWL_Timer { + public: + explicit Timer(CFWL_ScrollBar* pToolTip); + ~Timer() override {} + + void Run(CFWL_TimerInfo* pTimerInfo) override; + }; + friend class CFWL_ScrollBar::Timer; + + bool IsVertical() const { + return !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_SCB_Vert); + } + void DrawTrack(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + bool bLower = true, + const CFX_Matrix* pMatrix = nullptr); + void DrawArrowBtn(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + bool bMinBtn = true, + const CFX_Matrix* pMatrix = nullptr); + void DrawThumb(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix = nullptr); + void Layout(); + void CalcButtonLen(); + void CalcMinButtonRect(CFX_RectF& rect); + void CalcMaxButtonRect(CFX_RectF& rect); + void CalcThumbButtonRect(CFX_RectF& rect); + void CalcMinTrackRect(CFX_RectF& rect); + void CalcMaxTrackRect(CFX_RectF& rect); + FX_FLOAT GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy); + void GetTrackRect(CFX_RectF& rect, bool bLower = true); + bool SendEvent(); + bool OnScroll(FWL_SCBCODE dwCode, FX_FLOAT fPos); + void OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); + void OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); + void OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); + void OnMouseLeave(); + void OnMouseWheel(FX_FLOAT fx, + FX_FLOAT fy, + uint32_t dwFlags, + FX_FLOAT fDeltaX, + FX_FLOAT fDeltaY); + bool DoScroll(FWL_SCBCODE dwCode, FX_FLOAT fPos = 0.0f); + void DoMouseDown(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState, + FX_FLOAT fx, + FX_FLOAT fy); + void DoMouseUp(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState, + FX_FLOAT fx, + FX_FLOAT fy); + void DoMouseMove(int32_t iItem, + const CFX_RectF& rtItem, + int32_t& iState, + FX_FLOAT fx, + FX_FLOAT fy); + void DoMouseLeave(int32_t iItem, const CFX_RectF& rtItem, int32_t& iState); + void DoMouseHover(int32_t iItem, const CFX_RectF& rtItem, int32_t& iState); + + CFWL_TimerInfo* m_pTimerInfo; + FX_FLOAT m_fRangeMin; + FX_FLOAT m_fRangeMax; + FX_FLOAT m_fPageSize; + FX_FLOAT m_fStepSize; + FX_FLOAT m_fPos; + FX_FLOAT m_fTrackPos; + int32_t m_iMinButtonState; + int32_t m_iMaxButtonState; + int32_t m_iThumbButtonState; + int32_t m_iMinTrackState; + int32_t m_iMaxTrackState; + FX_FLOAT m_fLastTrackPos; + FX_FLOAT m_cpTrackPointX; + FX_FLOAT m_cpTrackPointY; + int32_t m_iMouseWheel; + bool m_bMouseDown; + FX_FLOAT m_fButtonLen; + bool m_bMinSize; + CFX_RectF m_rtClient; + CFX_RectF m_rtThumb; + CFX_RectF m_rtMinBtn; + CFX_RectF m_rtMaxBtn; + CFX_RectF m_rtMinTrack; + CFX_RectF m_rtMaxTrack; + FX_FLOAT m_fMinThumb; + CFWL_ScrollBar::Timer m_Timer; +}; + +#endif // XFA_FWL_CORE_CFWL_SCROLLBAR_H_ diff --git a/xfa/fwl/core/cfwl_spinbutton.cpp b/xfa/fwl/core/cfwl_spinbutton.cpp new file mode 100644 index 0000000000..2afbc8297c --- /dev/null +++ b/xfa/fwl/core/cfwl_spinbutton.cpp @@ -0,0 +1,381 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fwl/core/cfwl_spinbutton.h" + +#include +#include + +#include "third_party/base/ptr_util.h" +#include "xfa/fwl/core/cfwl_evtclick.h" +#include "xfa/fwl/core/cfwl_msgkey.h" +#include "xfa/fwl/core/cfwl_msgmouse.h" +#include "xfa/fwl/core/cfwl_notedriver.h" +#include "xfa/fwl/core/cfwl_themebackground.h" +#include "xfa/fwl/core/cfwl_timerinfo.h" +#include "xfa/fwl/core/cfwl_widgetproperties.h" +#include "xfa/fwl/core/ifwl_themeprovider.h" + +namespace { + +const int kMinWidth = 18; +const int kMinHeight = 32; +const int kElapseTime = 200; + +} // namespace + +CFWL_SpinButton::CFWL_SpinButton( + const CFWL_App* app, + std::unique_ptr properties) + : IFWL_Widget(app, std::move(properties), nullptr), + m_dwUpState(CFWL_PartState_Normal), + m_dwDnState(CFWL_PartState_Normal), + m_iButtonIndex(0), + m_bLButtonDwn(false), + m_pTimerInfo(nullptr), + m_Timer(this) { + m_rtClient.Reset(); + m_rtUpButton.Reset(); + m_rtDnButton.Reset(); + m_pProperties->m_dwStyleExes |= FWL_STYLEEXE_SPB_Vert; +} + +CFWL_SpinButton::~CFWL_SpinButton() {} + +FWL_Type CFWL_SpinButton::GetClassID() const { + return FWL_Type::SpinButton; +} + +void CFWL_SpinButton::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { + if (!bAutoSize) { + rect = m_pProperties->m_rtWidget; + return; + } + + rect.Set(0, 0, kMinWidth, kMinHeight); + IFWL_Widget::GetWidgetRect(rect, true); +} + +void CFWL_SpinButton::Update() { + if (IsLocked()) + return; + + GetClientRect(m_rtClient); + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXE_SPB_Vert) { + m_rtUpButton.Set(m_rtClient.top, m_rtClient.left, m_rtClient.width, + m_rtClient.height / 2); + m_rtDnButton.Set(m_rtClient.left, m_rtClient.top + m_rtClient.height / 2, + m_rtClient.width, m_rtClient.height / 2); + } else { + m_rtUpButton.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width / 2, + m_rtClient.height); + m_rtDnButton.Set(m_rtClient.left + m_rtClient.width / 2, m_rtClient.top, + m_rtClient.width / 2, m_rtClient.height); + } +} + +FWL_WidgetHit CFWL_SpinButton::HitTest(FX_FLOAT fx, FX_FLOAT fy) { + if (m_rtClient.Contains(fx, fy)) + return FWL_WidgetHit::Client; + if (HasBorder() && (m_rtClient.Contains(fx, fy))) + return FWL_WidgetHit::Border; + if (HasEdge()) { + CFX_RectF rtEdge; + GetEdgeRect(rtEdge); + if (rtEdge.Contains(fx, fy)) + return FWL_WidgetHit::Left; + } + if (m_rtUpButton.Contains(fx, fy)) + return FWL_WidgetHit::UpButton; + if (m_rtDnButton.Contains(fx, fy)) + return FWL_WidgetHit::DownButton; + return FWL_WidgetHit::Unknown; +} + +void CFWL_SpinButton::DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + if (!pGraphics) + return; + + CFX_RectF rtClip(m_rtClient); + if (pMatrix) + pMatrix->TransformRect(rtClip); + + IFWL_ThemeProvider* pTheme = GetAvailableTheme(); + if (HasBorder()) + DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); + if (HasEdge()) + DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); + + DrawUpButton(pGraphics, pTheme, pMatrix); + DrawDownButton(pGraphics, pTheme, pMatrix); +} + +void CFWL_SpinButton::EnableButton(bool bEnable, bool bUp) { + if (bUp) + m_dwUpState = bEnable ? CFWL_PartState_Normal : CFWL_PartState_Disabled; + else + m_dwDnState = bEnable ? CFWL_PartState_Normal : CFWL_PartState_Disabled; +} + +bool CFWL_SpinButton::IsButtonEnabled(bool bUp) { + if (bUp) + return (m_dwUpState != CFWL_PartState_Disabled); + return (m_dwDnState != CFWL_PartState_Disabled); +} + +void CFWL_SpinButton::DrawUpButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::UpButton; + params.m_pGraphics = pGraphics; + params.m_dwStates = m_dwUpState + 1; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + + params.m_rtPart = m_rtUpButton; + pTheme->DrawBackground(¶ms); +} + +void CFWL_SpinButton::DrawDownButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix) { + CFWL_ThemeBackground params; + params.m_pWidget = this; + params.m_iPart = CFWL_Part::DownButton; + params.m_pGraphics = pGraphics; + params.m_dwStates = m_dwDnState + 1; + if (pMatrix) + params.m_matrix.Concat(*pMatrix); + + params.m_rtPart = m_rtDnButton; + pTheme->DrawBackground(¶ms); +} + +void CFWL_SpinButton::OnProcessMessage(CFWL_Message* pMessage) { + if (!pMessage) + return; + + CFWL_MessageType dwMsgCode = pMessage->GetClassID(); + switch (dwMsgCode) { + case CFWL_MessageType::SetFocus: { + OnFocusChanged(pMessage, true); + break; + } + case CFWL_MessageType::KillFocus: { + OnFocusChanged(pMessage, false); + break; + } + case CFWL_MessageType::Mouse: { + CFWL_MsgMouse* pMsg = static_cast(pMessage); + switch (pMsg->m_dwCmd) { + case FWL_MouseCommand::LeftButtonDown: + OnLButtonDown(pMsg); + break; + case FWL_MouseCommand::LeftButtonUp: + OnLButtonUp(pMsg); + break; + case FWL_MouseCommand::Move: + OnMouseMove(pMsg); + break; + case FWL_MouseCommand::Leave: + OnMouseLeave(pMsg); + break; + default: + break; + } + break; + } + case CFWL_MessageType::Key: { + CFWL_MsgKey* pKey = static_cast(pMessage); + if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) + OnKeyDown(pKey); + break; + } + default: + break; + } + IFWL_Widget::OnProcessMessage(pMessage); +} + +void CFWL_SpinButton::OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) { + DrawWidget(pGraphics, pMatrix); +} + +void CFWL_SpinButton::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { + if (bSet) + m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); + else + m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); + + Repaint(&m_rtClient); +} + +void CFWL_SpinButton::OnLButtonDown(CFWL_MsgMouse* pMsg) { + m_bLButtonDwn = true; + SetGrab(true); + SetFocus(true); + + bool bUpPress = + (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsButtonEnabled(true)); + bool bDnPress = + (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsButtonEnabled(false)); + if (!bUpPress && !bDnPress) + return; + if (bUpPress) { + m_iButtonIndex = 0; + m_dwUpState = CFWL_PartState_Pressed; + } + if (bDnPress) { + m_iButtonIndex = 1; + m_dwDnState = CFWL_PartState_Pressed; + } + + CFWL_EvtClick wmPosChanged; + wmPosChanged.m_pSrcTarget = this; + DispatchEvent(&wmPosChanged); + + Repaint(bUpPress ? &m_rtUpButton : &m_rtDnButton); + m_pTimerInfo = m_Timer.StartTimer(kElapseTime, true); +} + +void CFWL_SpinButton::OnLButtonUp(CFWL_MsgMouse* pMsg) { + if (m_pProperties->m_dwStates & CFWL_PartState_Disabled) + return; + + m_bLButtonDwn = false; + SetGrab(false); + SetFocus(false); + if (m_pTimerInfo) { + m_pTimerInfo->StopTimer(); + m_pTimerInfo = nullptr; + } + bool bRepaint = false; + CFX_RectF rtInvalidate; + if (m_dwUpState == CFWL_PartState_Pressed && IsButtonEnabled(true)) { + m_dwUpState = CFWL_PartState_Normal; + bRepaint = true; + rtInvalidate = m_rtUpButton; + } else if (m_dwDnState == CFWL_PartState_Pressed && IsButtonEnabled(false)) { + m_dwDnState = CFWL_PartState_Normal; + bRepaint = true; + rtInvalidate = m_rtDnButton; + } + if (bRepaint) + Repaint(&rtInvalidate); +} + +void CFWL_SpinButton::OnMouseMove(CFWL_MsgMouse* pMsg) { + if (m_bLButtonDwn) + return; + + bool bRepaint = false; + CFX_RectF rtInvlidate; + rtInvlidate.Reset(); + if (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy)) { + if (IsButtonEnabled(true)) { + if (m_dwUpState == CFWL_PartState_Hovered) { + m_dwUpState = CFWL_PartState_Hovered; + bRepaint = true; + rtInvlidate = m_rtUpButton; + } + if (m_dwDnState != CFWL_PartState_Normal && IsButtonEnabled(false)) { + m_dwDnState = CFWL_PartState_Normal; + if (bRepaint) + rtInvlidate.Union(m_rtDnButton); + else + rtInvlidate = m_rtDnButton; + + bRepaint = true; + } + } + if (!IsButtonEnabled(false)) + EnableButton(false, false); + + } else if (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy)) { + if (IsButtonEnabled(false)) { + if (m_dwDnState != CFWL_PartState_Hovered) { + m_dwDnState = CFWL_PartState_Hovered; + bRepaint = true; + rtInvlidate = m_rtDnButton; + } + if (m_dwUpState != CFWL_PartState_Normal && IsButtonEnabled(true)) { + m_dwUpState = CFWL_PartState_Normal; + if (bRepaint) + rtInvlidate.Union(m_rtUpButton); + else + rtInvlidate = m_rtUpButton; + bRepaint = true; + } + } + } else if (m_dwUpState != CFWL_PartState_Normal || + m_dwDnState != CFWL_PartState_Normal) { + if (m_dwUpState != CFWL_PartState_Normal) { + m_dwUpState = CFWL_PartState_Normal; + bRepaint = true; + rtInvlidate = m_rtUpButton; + } + if (m_dwDnState != CFWL_PartState_Normal) { + m_dwDnState = CFWL_PartState_Normal; + if (bRepaint) + rtInvlidate.Union(m_rtDnButton); + else + rtInvlidate = m_rtDnButton; + + bRepaint = true; + } + } + if (bRepaint) + Repaint(&rtInvlidate); +} + +void CFWL_SpinButton::OnMouseLeave(CFWL_MsgMouse* pMsg) { + if (!pMsg) + return; + if (m_dwUpState != CFWL_PartState_Normal && IsButtonEnabled(true)) + m_dwUpState = CFWL_PartState_Normal; + if (m_dwDnState != CFWL_PartState_Normal && IsButtonEnabled(false)) + m_dwDnState = CFWL_PartState_Normal; + + Repaint(&m_rtClient); +} + +void CFWL_SpinButton::OnKeyDown(CFWL_MsgKey* pMsg) { + bool bUp = + pMsg->m_dwKeyCode == FWL_VKEY_Up || pMsg->m_dwKeyCode == FWL_VKEY_Left; + bool bDown = + pMsg->m_dwKeyCode == FWL_VKEY_Down || pMsg->m_dwKeyCode == FWL_VKEY_Right; + if (!bUp && !bDown) + return; + + bool bUpEnable = IsButtonEnabled(true); + bool bDownEnable = IsButtonEnabled(false); + if (!bUpEnable && !bDownEnable) + return; + + CFWL_EvtClick wmPosChanged; + wmPosChanged.m_pSrcTarget = this; + DispatchEvent(&wmPosChanged); + + Repaint(bUpEnable ? &m_rtUpButton : &m_rtDnButton); +} + +CFWL_SpinButton::Timer::Timer(CFWL_SpinButton* pToolTip) + : CFWL_Timer(pToolTip) {} + +void CFWL_SpinButton::Timer::Run(CFWL_TimerInfo* pTimerInfo) { + CFWL_SpinButton* pButton = static_cast(m_pWidget); + + if (!pButton->m_pTimerInfo) + return; + + CFWL_EvtClick wmPosChanged; + wmPosChanged.m_pSrcTarget = pButton; + pButton->DispatchEvent(&wmPosChanged); +} diff --git a/xfa/fwl/core/cfwl_spinbutton.h b/xfa/fwl/core/cfwl_spinbutton.h new file mode 100644 index 0000000000..87cf16727c --- /dev/null +++ b/xfa/fwl/core/cfwl_spinbutton.h @@ -0,0 +1,76 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FWL_CORE_CFWL_SPINBUTTON_H_ +#define XFA_FWL_CORE_CFWL_SPINBUTTON_H_ + +#include + +#include "xfa/fwl/core/cfwl_event.h" +#include "xfa/fwl/core/cfwl_timer.h" +#include "xfa/fwl/core/ifwl_widget.h" +#include "xfa/fxfa/cxfa_eventparam.h" + +#define FWL_STYLEEXE_SPB_Vert (1L << 0) + +class CFWL_MsgMouse; +class CFWL_WidgetProperties; + +class CFWL_SpinButton : public IFWL_Widget { + public: + CFWL_SpinButton(const CFWL_App* app, + std::unique_ptr properties); + ~CFWL_SpinButton() override; + + // IFWL_Widget + FWL_Type GetClassID() const override; + void GetWidgetRect(CFX_RectF& rect, bool bAutoSize = false) override; + void Update() override; + FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; + void DrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix = nullptr) override; + void OnProcessMessage(CFWL_Message* pMessage) override; + void OnProcessEvent(CFWL_Event* pEvent) override; + void OnDrawWidget(CFX_Graphics* pGraphics, + const CFX_Matrix* pMatrix) override; + + private: + class Timer : public CFWL_Timer { + public: + explicit Timer(CFWL_SpinButton* pToolTip); + ~Timer() override {} + + void Run(CFWL_TimerInfo* pTimerInfo) override; + }; + friend class CFWL_SpinButton::Timer; + + void EnableButton(bool bEnable, bool bUp = true); + bool IsButtonEnabled(bool bUp = true); + void DrawUpButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void DrawDownButton(CFX_Graphics* pGraphics, + IFWL_ThemeProvider* pTheme, + const CFX_Matrix* pMatrix); + void OnFocusChanged(CFWL_Message* pMsg, bool bSet); + void OnLButtonDown(CFWL_MsgMouse* pMsg); + void OnLButtonUp(CFWL_MsgMouse* pMsg); + void OnMouseMove(CFWL_MsgMouse* pMsg); + void OnMouseLeave(CFWL_MsgMouse* pMsg); + void OnKeyDown(CFWL_MsgKey* pMsg); + + CFX_RectF m_rtClient; + CFX_RectF m_rtUpButton; + CFX_RectF m_rtDnButton; + uint32_t m_dwUpState; + uint32_t m_dwDnState; + int32_t m_iButtonIndex; + bool m_bLButtonDwn; + CFWL_TimerInfo* m_pTimerInfo; + CFWL_SpinButton::Timer m_Timer; +}; + +#endif // XFA_FWL_CORE_CFWL_SPINBUTTON_H_ diff --git a/xfa/fwl/core/cfwl_widgetmgr.cpp b/xfa/fwl/core/cfwl_widgetmgr.cpp index 3d5beb4b6b..8a658b5e6e 100644 --- a/xfa/fwl/core/cfwl_widgetmgr.cpp +++ b/xfa/fwl/core/cfwl_widgetmgr.cpp @@ -10,8 +10,8 @@ #include "third_party/base/ptr_util.h" #include "xfa/fwl/core/cfwl_app.h" +#include "xfa/fwl/core/cfwl_form.h" #include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/ifwl_form.h" #include "xfa/fxfa/app/xfa_fwladapter.h" #include "xfa/fxfa/xfa_ffapp.h" diff --git a/xfa/fwl/core/ifwl_barcode.h b/xfa/fwl/core/ifwl_barcode.h index 7c6f346708..38f798fe16 100644 --- a/xfa/fwl/core/ifwl_barcode.h +++ b/xfa/fwl/core/ifwl_barcode.h @@ -9,8 +9,8 @@ #include +#include "xfa/fwl/core/cfwl_scrollbar.h" #include "xfa/fwl/core/ifwl_edit.h" -#include "xfa/fwl/core/ifwl_scrollbar.h" #include "xfa/fwl/core/ifwl_widget.h" #include "xfa/fxbarcode/BC_Library.h" diff --git a/xfa/fwl/core/ifwl_caret.cpp b/xfa/fwl/core/ifwl_caret.cpp deleted file mode 100644 index 1c228242bd..0000000000 --- a/xfa/fwl/core/ifwl_caret.cpp +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/ifwl_caret.h" - -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_timerinfo.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" - -namespace { - -const uint32_t kFrequency = 400; - -} // namespace - -IFWL_Caret::IFWL_Caret(const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter) - : IFWL_Widget(app, std::move(properties), pOuter), - m_pTimer(new IFWL_Caret::Timer(this)), - m_pTimerInfo(nullptr) { - SetStates(FWL_STATE_CAT_HightLight); -} - -IFWL_Caret::~IFWL_Caret() { - if (m_pTimerInfo) { - m_pTimerInfo->StopTimer(); - m_pTimerInfo = nullptr; - } -} - -FWL_Type IFWL_Caret::GetClassID() const { - return FWL_Type::Caret; -} - -void IFWL_Caret::Update() {} - -void IFWL_Caret::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - if (!m_pProperties->m_pThemeProvider) - return; - - DrawCaretBK(pGraphics, m_pProperties->m_pThemeProvider, pMatrix); -} - -void IFWL_Caret::ShowCaret(bool bFlag) { - if (m_pTimerInfo) { - m_pTimerInfo->StopTimer(); - m_pTimerInfo = nullptr; - } - if (bFlag) - m_pTimerInfo = m_pTimer->StartTimer(kFrequency, true); - - SetStates(FWL_WGTSTATE_Invisible, !bFlag); -} - -void IFWL_Caret::DrawCaretBK(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - if (!(m_pProperties->m_dwStates & FWL_STATE_CAT_HightLight)) - return; - - CFX_RectF rect; - GetWidgetRect(rect); - rect.Set(0, 0, rect.width, rect.height); - - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_pGraphics = pGraphics; - param.m_rtPart = rect; - param.m_iPart = CFWL_Part::Background; - param.m_dwStates = CFWL_PartState_HightLight; - if (pMatrix) - param.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶m); -} - -void IFWL_Caret::OnProcessMessage(CFWL_Message* pMessage) {} - -void IFWL_Caret::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -IFWL_Caret::Timer::Timer(IFWL_Caret* pCaret) : CFWL_Timer(pCaret) {} - -void IFWL_Caret::Timer::Run(CFWL_TimerInfo* pTimerInfo) { - IFWL_Caret* pCaret = static_cast(m_pWidget); - pCaret->SetStates(FWL_STATE_CAT_HightLight, - !(pCaret->GetStates() & FWL_STATE_CAT_HightLight)); - - CFX_RectF rt; - pCaret->GetWidgetRect(rt); - rt.Set(0, 0, rt.width + 1, rt.height); - pCaret->Repaint(&rt); -} diff --git a/xfa/fwl/core/ifwl_caret.h b/xfa/fwl/core/ifwl_caret.h deleted file mode 100644 index 51a80911d5..0000000000 --- a/xfa/fwl/core/ifwl_caret.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_IFWL_CARET_H_ -#define XFA_FWL_CORE_IFWL_CARET_H_ - -#include - -#include "xfa/fwl/core/cfwl_timer.h" -#include "xfa/fwl/core/ifwl_widget.h" -#include "xfa/fxgraphics/cfx_color.h" - -class CFWL_WidgetProperties; -class IFWL_Widget; - -#define FWL_STATE_CAT_HightLight 1 - -class IFWL_Caret : public IFWL_Widget { - public: - IFWL_Caret(const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter); - ~IFWL_Caret() override; - - // IFWL_Widget - FWL_Type GetClassID() const override; - void DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - void Update() override; - - void ShowCaret(bool bFlag = true); - - private: - class Timer : public CFWL_Timer { - public: - explicit Timer(IFWL_Caret* pCaret); - ~Timer() override {} - - void Run(CFWL_TimerInfo* hTimer) override; - }; - friend class IFWL_Caret::Timer; - - void DrawCaretBK(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - - std::unique_ptr m_pTimer; - CFWL_TimerInfo* m_pTimerInfo; // not owned. -}; - -#endif // XFA_FWL_CORE_IFWL_CARET_H_ diff --git a/xfa/fwl/core/ifwl_combobox.cpp b/xfa/fwl/core/ifwl_combobox.cpp index 7917b4eabf..07fa64c43a 100644 --- a/xfa/fwl/core/ifwl_combobox.cpp +++ b/xfa/fwl/core/ifwl_combobox.cpp @@ -19,6 +19,7 @@ #include "xfa/fwl/core/cfwl_evtpredropdown.h" #include "xfa/fwl/core/cfwl_evtselectchanged.h" #include "xfa/fwl/core/cfwl_evttextchanged.h" +#include "xfa/fwl/core/cfwl_formproxy.h" #include "xfa/fwl/core/cfwl_msgkey.h" #include "xfa/fwl/core/cfwl_msgkillfocus.h" #include "xfa/fwl/core/cfwl_msgmouse.h" @@ -28,7 +29,6 @@ #include "xfa/fwl/core/cfwl_themepart.h" #include "xfa/fwl/core/cfwl_themetext.h" #include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/ifwl_formproxy.h" #include "xfa/fwl/core/ifwl_listbox.h" #include "xfa/fwl/core/ifwl_themeprovider.h" @@ -56,10 +56,10 @@ IFWL_ComboBox::IFWL_ComboBox(const CFWL_App* app, if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListItemIconText) prop->m_dwStyleExes |= FWL_STYLEEXT_LTB_Icon; m_pListBox = - pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); + pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown) && !m_pEdit) { - m_pEdit.reset(new IFWL_ComboEdit( + m_pEdit.reset(new CFWL_ComboEdit( m_pOwnerApp, pdfium::MakeUnique(), this)); m_pEdit->SetOuter(this); } @@ -122,7 +122,7 @@ void IFWL_ComboBox::ModifyStylesEx(uint32_t dwStylesExAdded, bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); bool bRemoveDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); if (bAddDropDown && !m_pEdit) { - m_pEdit = pdfium::MakeUnique( + m_pEdit = pdfium::MakeUnique( m_pOwnerApp, pdfium::MakeUnique(), nullptr); m_pEdit->SetOuter(this); m_pEdit->SetParent(this); @@ -581,7 +581,7 @@ void IFWL_ComboBox::InitProxyForm() { // TODO(dsinclair): Does this leak? I don't see a delete, but I'm not sure // if the SetParent call is going to transfer ownership. - m_pComboBoxProxy = new IFWL_ComboBoxProxy(this, m_pOwnerApp, std::move(prop), + m_pComboBoxProxy = new CFWL_ComboBoxProxy(this, m_pOwnerApp, std::move(prop), m_pListBox.get()); m_pListBox->SetParent(m_pComboBoxProxy); } @@ -596,7 +596,7 @@ void IFWL_ComboBox::DisForm_InitComboList() { prop->m_dwStates = FWL_WGTSTATE_Invisible; prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; m_pListBox = - pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); + pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); } void IFWL_ComboBox::DisForm_InitComboEdit() { @@ -608,7 +608,7 @@ void IFWL_ComboBox::DisForm_InitComboEdit() { prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; m_pEdit = - pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); + pdfium::MakeUnique(m_pOwnerApp, std::move(prop), this); m_pEdit->SetOuter(this); } @@ -621,7 +621,7 @@ void IFWL_ComboBox::DisForm_ShowDropList(bool bActivate) { preEvent.m_pSrcTarget = this; DispatchEvent(&preEvent); - IFWL_ComboList* pComboList = m_pListBox.get(); + CFWL_ComboList* pComboList = m_pListBox.get(); int32_t iItems = pComboList->CountItems(nullptr); if (iItems < 1) return; @@ -1093,7 +1093,7 @@ void IFWL_ComboBox::DisForm_OnKey(CFWL_MsgKey* pMsg) { const bool bUp = dwKeyCode == FWL_VKEY_Up; const bool bDown = dwKeyCode == FWL_VKEY_Down; if (bUp || bDown) { - IFWL_ComboList* pComboList = m_pListBox.get(); + CFWL_ComboList* pComboList = m_pListBox.get(); int32_t iCount = pComboList->CountItems(nullptr); if (iCount < 1) return; diff --git a/xfa/fwl/core/ifwl_combobox.h b/xfa/fwl/core/ifwl_combobox.h index dfe9d646cd..26d0c0f1b8 100644 --- a/xfa/fwl/core/ifwl_combobox.h +++ b/xfa/fwl/core/ifwl_combobox.h @@ -9,17 +9,17 @@ #include -#include "xfa/fwl/core/ifwl_comboboxproxy.h" -#include "xfa/fwl/core/ifwl_comboedit.h" -#include "xfa/fwl/core/ifwl_combolist.h" -#include "xfa/fwl/core/ifwl_form.h" +#include "xfa/fwl/core/cfwl_comboboxproxy.h" +#include "xfa/fwl/core/cfwl_comboedit.h" +#include "xfa/fwl/core/cfwl_combolist.h" +#include "xfa/fwl/core/cfwl_form.h" #include "xfa/fwl/core/ifwl_listbox.h" #include "xfa/fxgraphics/cfx_graphics.h" class CFWL_WidgetProperties; class IFWL_ComboBox; -class IFWL_ComboBoxProxy; -class IFWL_FormProxy; +class CFWL_ComboBoxProxy; +class CFWL_FormProxy; class IFWL_ListBox; class IFWL_Widget; @@ -114,7 +114,7 @@ class IFWL_ComboBox : public IFWL_Widget { } void ShowDropList(bool bActivate); - IFWL_ComboEdit* GetComboEdit() const { return m_pEdit.get(); } + CFWL_ComboEdit* GetComboEdit() const { return m_pEdit.get(); } void ProcessSelChanged(bool bLButtonUp); int32_t GetCurrentSelection() const { return m_iCurSel; } @@ -162,9 +162,9 @@ class IFWL_ComboBox : public IFWL_Widget { CFX_RectF m_rtList; CFX_RectF m_rtProxy; CFX_RectF m_rtHandler; - std::unique_ptr m_pEdit; - std::unique_ptr m_pListBox; - IFWL_ComboBoxProxy* m_pComboBoxProxy; // Can this be a unique_ptr? + std::unique_ptr m_pEdit; + std::unique_ptr m_pListBox; + CFWL_ComboBoxProxy* m_pComboBoxProxy; // Can this be a unique_ptr? bool m_bLButtonDown; bool m_bUpFormHandler; int32_t m_iCurSel; diff --git a/xfa/fwl/core/ifwl_comboboxproxy.cpp b/xfa/fwl/core/ifwl_comboboxproxy.cpp deleted file mode 100644 index 35c8a0e025..0000000000 --- a/xfa/fwl/core/ifwl_comboboxproxy.cpp +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/ifwl_comboboxproxy.h" - -#include -#include - -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/cfwl_msgkillfocus.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/ifwl_combobox.h" - -IFWL_ComboBoxProxy::IFWL_ComboBoxProxy( - IFWL_ComboBox* pComboBox, - const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter) - : IFWL_FormProxy(app, std::move(properties), pOuter), - m_bLButtonDown(false), - m_bLButtonUpSelf(false), - m_pComboBox(pComboBox) {} - -IFWL_ComboBoxProxy::~IFWL_ComboBoxProxy() {} - -void IFWL_ComboBoxProxy::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - switch (pMessage->GetClassID()) { - case CFWL_MessageType::Mouse: { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMsg); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMsg); - break; - default: - break; - } - break; - } - case CFWL_MessageType::KillFocus: - OnFocusChanged(pMessage, false); - break; - case CFWL_MessageType::SetFocus: - OnFocusChanged(pMessage, true); - break; - default: - break; - } - IFWL_Widget::OnProcessMessage(pMessage); -} - -void IFWL_ComboBoxProxy::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - m_pComboBox->DrawStretchHandler(pGraphics, pMatrix); -} - -void IFWL_ComboBoxProxy::OnLButtonDown(CFWL_Message* pMessage) { - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pDriver = - static_cast(pApp->GetNoteDriver()); - CFX_RectF rtWidget; - GetWidgetRect(rtWidget); - rtWidget.left = rtWidget.top = 0; - - CFWL_MsgMouse* pMsg = static_cast(pMessage); - if (rtWidget.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_bLButtonDown = true; - pDriver->SetGrab(this, true); - } else { - m_bLButtonDown = false; - pDriver->SetGrab(this, false); - m_pComboBox->ShowDropList(false); - } -} - -void IFWL_ComboBoxProxy::OnLButtonUp(CFWL_Message* pMessage) { - m_bLButtonDown = false; - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pDriver = - static_cast(pApp->GetNoteDriver()); - pDriver->SetGrab(this, false); - if (!m_bLButtonUpSelf) { - m_bLButtonUpSelf = true; - return; - } - - CFWL_MsgMouse* pMsg = static_cast(pMessage); - CFX_RectF rect; - GetWidgetRect(rect); - rect.left = rect.top = 0; - if (!rect.Contains(pMsg->m_fx, pMsg->m_fy) && - m_pComboBox->IsDropListVisible()) { - m_pComboBox->ShowDropList(false); - } -} - -void IFWL_ComboBoxProxy::OnFocusChanged(CFWL_Message* pMessage, bool bSet) { - if (bSet) - return; - - CFWL_MsgKillFocus* pMsg = static_cast(pMessage); - if (!pMsg->m_pSetFocus) - m_pComboBox->ShowDropList(false); -} diff --git a/xfa/fwl/core/ifwl_comboboxproxy.h b/xfa/fwl/core/ifwl_comboboxproxy.h deleted file mode 100644 index 228045d750..0000000000 --- a/xfa/fwl/core/ifwl_comboboxproxy.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_IFWL_COMBOBOXPROXY_H_ -#define XFA_FWL_CORE_IFWL_COMBOBOXPROXY_H_ - -#include - -#include "xfa/fwl/core/ifwl_formproxy.h" - -class IFWL_ComboBox; - -class IFWL_ComboBoxProxy : public IFWL_FormProxy { - public: - IFWL_ComboBoxProxy(IFWL_ComboBox* pCombobBox, - const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter); - ~IFWL_ComboBoxProxy() override; - - // IFWL_FormProxy - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - void Reset() { m_bLButtonUpSelf = false; } - - private: - void OnLButtonDown(CFWL_Message* pMsg); - void OnLButtonUp(CFWL_Message* pMsg); - void OnFocusChanged(CFWL_Message* pMsg, bool bSet); - - bool m_bLButtonDown; - bool m_bLButtonUpSelf; - IFWL_ComboBox* m_pComboBox; -}; - -#endif // XFA_FWL_CORE_IFWL_COMBOBOXPROXY_H_ diff --git a/xfa/fwl/core/ifwl_comboedit.cpp b/xfa/fwl/core/ifwl_comboedit.cpp deleted file mode 100644 index 7d1260315c..0000000000 --- a/xfa/fwl/core/ifwl_comboedit.cpp +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/ifwl_comboedit.h" - -#include -#include - -#include "xfa/fde/cfde_txtedtengine.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/ifwl_combobox.h" - -IFWL_ComboEdit::IFWL_ComboEdit( - const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter) - : IFWL_Edit(app, std::move(properties), pOuter) { - m_pOuter = static_cast(pOuter); -} - -void IFWL_ComboEdit::ClearSelected() { - ClearSelections(); - Repaint(&GetRTClient()); -} - -void IFWL_ComboEdit::SetSelected() { - FlagFocus(true); - GetTxtEdtEngine()->MoveCaretPos(MC_End); - AddSelRange(0); -} - -void IFWL_ComboEdit::FlagFocus(bool bSet) { - if (bSet) { - m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; - return; - } - - m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; - ShowCaret(false); -} - -void IFWL_ComboEdit::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - bool backDefault = true; - switch (pMessage->GetClassID()) { - case CFWL_MessageType::SetFocus: { - m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; - backDefault = false; - break; - } - case CFWL_MessageType::KillFocus: { - m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; - backDefault = false; - break; - } - case CFWL_MessageType::Mouse: { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - if ((pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonDown) && - ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0)) { - SetSelected(); - m_pOuter->SetFocus(true); - } - break; - } - default: - break; - } - if (backDefault) - IFWL_Edit::OnProcessMessage(pMessage); -} diff --git a/xfa/fwl/core/ifwl_comboedit.h b/xfa/fwl/core/ifwl_comboedit.h deleted file mode 100644 index 5b71c1e86e..0000000000 --- a/xfa/fwl/core/ifwl_comboedit.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_IFWL_COMBOEDIT_H_ -#define XFA_FWL_CORE_IFWL_COMBOEDIT_H_ - -#include - -#include "xfa/fwl/core/cfwl_widgetproperties.h" -#include "xfa/fwl/core/ifwl_edit.h" -#include "xfa/fwl/core/ifwl_widget.h" - -class IFWL_ComboBox; - -class IFWL_ComboEdit : public IFWL_Edit { - public: - IFWL_ComboEdit(const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter); - - // IFWL_Edit. - void OnProcessMessage(CFWL_Message* pMessage) override; - - void ClearSelected(); - void SetSelected(); - void FlagFocus(bool bSet); - - private: - IFWL_ComboBox* m_pOuter; -}; - -#endif // XFA_FWL_CORE_IFWL_COMBOEDIT_H_ diff --git a/xfa/fwl/core/ifwl_combolist.cpp b/xfa/fwl/core/ifwl_combolist.cpp deleted file mode 100644 index ed7732e0ed..0000000000 --- a/xfa/fwl/core/ifwl_combolist.cpp +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright 2016 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/ifwl_combolist.h" - -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_msgkey.h" -#include "xfa/fwl/core/cfwl_msgkillfocus.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/ifwl_combobox.h" -#include "xfa/fwl/core/ifwl_comboedit.h" -#include "xfa/fwl/core/ifwl_listbox.h" - -IFWL_ComboList::IFWL_ComboList( - const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter) - : IFWL_ListBox(app, std::move(properties), pOuter), m_bNotifyOwner(true) { - ASSERT(pOuter); -} - -int32_t IFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { - if (wsMatch.IsEmpty()) - return -1; - - int32_t iCount = CountItems(this); - for (int32_t i = 0; i < iCount; i++) { - CFWL_ListItem* hItem = GetItem(this, i); - CFX_WideString wsText; - GetItemText(this, hItem, wsText); - FX_STRSIZE pos = wsText.Find(wsMatch.c_str()); - if (!pos) - return i; - } - return -1; -} - -void IFWL_ComboList::ChangeSelected(int32_t iSel) { - CFWL_ListItem* hItem = GetItem(this, iSel); - CFX_RectF rtInvalidate; - rtInvalidate.Reset(); - CFWL_ListItem* hOld = GetSelItem(0); - int32_t iOld = GetItemIndex(this, hOld); - if (iOld == iSel) - return; - if (iOld > -1) { - CFWL_ListItem* hItem = GetItem(this, iOld); - GetItemRect(this, hItem, rtInvalidate); - SetSelItem(hOld, false); - } - if (hItem) { - CFX_RectF rect; - CFWL_ListItem* hItem = GetItem(this, iSel); - GetItemRect(this, hItem, rect); - rtInvalidate.Union(rect); - CFWL_ListItem* hSel = GetItem(this, iSel); - SetSelItem(hSel, true); - } - if (!rtInvalidate.IsEmpty()) - Repaint(&rtInvalidate); -} - -void IFWL_ComboList::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) { - fx += m_pProperties->m_rtWidget.left, fy += m_pProperties->m_rtWidget.top; - IFWL_Widget* pOwner = GetOwner(); - if (!pOwner) - return; - pOwner->TransformTo(m_pOuter, fx, fy); -} - -void IFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - CFWL_MessageType dwHashCode = pMessage->GetClassID(); - bool backDefault = true; - if (dwHashCode == CFWL_MessageType::SetFocus || - dwHashCode == CFWL_MessageType::KillFocus) { - OnDropListFocusChanged(pMessage, dwHashCode == CFWL_MessageType::SetFocus); - } else if (dwHashCode == CFWL_MessageType::Mouse) { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - IFWL_ScrollBar* vertSB = GetVertScrollBar(); - if (IsShowScrollBar(true) && vertSB) { - CFX_RectF rect; - vertSB->GetWidgetRect(rect); - if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { - pMsg->m_fx -= rect.left; - pMsg->m_fy -= rect.top; - vertSB->GetDelegate()->OnProcessMessage(pMsg); - return; - } - } - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::Move: { - backDefault = false; - OnDropListMouseMove(pMsg); - break; - } - case FWL_MouseCommand::LeftButtonDown: { - backDefault = false; - OnDropListLButtonDown(pMsg); - break; - } - case FWL_MouseCommand::LeftButtonUp: { - backDefault = false; - OnDropListLButtonUp(pMsg); - break; - } - default: - break; - } - } else if (dwHashCode == CFWL_MessageType::Key) { - backDefault = !OnDropListKey(static_cast(pMessage)); - } - if (backDefault) - IFWL_ListBox::OnProcessMessage(pMessage); -} - -void IFWL_ComboList::OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet) { - if (bSet) - return; - - CFWL_MsgKillFocus* pKill = static_cast(pMsg); - IFWL_ComboBox* pOuter = static_cast(m_pOuter); - if (pKill->m_pSetFocus == m_pOuter || - pKill->m_pSetFocus == pOuter->GetComboEdit()) { - pOuter->ShowDropList(false); - } -} - -void IFWL_ComboList::OnDropListMouseMove(CFWL_MsgMouse* pMsg) { - if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) { - if (m_bNotifyOwner) - m_bNotifyOwner = false; - - IFWL_ScrollBar* vertSB = GetVertScrollBar(); - if (IsShowScrollBar(true) && vertSB) { - CFX_RectF rect; - vertSB->GetWidgetRect(rect); - if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) - return; - } - - CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); - if (!hItem) - return; - - ChangeSelected(GetItemIndex(this, hItem)); - } else if (m_bNotifyOwner) { - ClientToOuter(pMsg->m_fx, pMsg->m_fy); - IFWL_ComboBox* pOuter = static_cast(m_pOuter); - pOuter->GetDelegate()->OnProcessMessage(pMsg); - } -} - -void IFWL_ComboList::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) { - if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) - return; - - IFWL_ComboBox* pOuter = static_cast(m_pOuter); - pOuter->ShowDropList(false); -} - -void IFWL_ComboList::OnDropListLButtonUp(CFWL_MsgMouse* pMsg) { - IFWL_ComboBox* pOuter = static_cast(m_pOuter); - if (m_bNotifyOwner) { - ClientToOuter(pMsg->m_fx, pMsg->m_fy); - pOuter->GetDelegate()->OnProcessMessage(pMsg); - return; - } - - IFWL_ScrollBar* vertSB = GetVertScrollBar(); - if (IsShowScrollBar(true) && vertSB) { - CFX_RectF rect; - vertSB->GetWidgetRect(rect); - if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) - return; - } - pOuter->ShowDropList(false); - - CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); - if (hItem) - pOuter->ProcessSelChanged(true); -} - -bool IFWL_ComboList::OnDropListKey(CFWL_MsgKey* pKey) { - IFWL_ComboBox* pOuter = static_cast(m_pOuter); - bool bPropagate = false; - if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { - uint32_t dwKeyCode = pKey->m_dwKeyCode; - switch (dwKeyCode) { - case FWL_VKEY_Return: - case FWL_VKEY_Escape: { - pOuter->ShowDropList(false); - return true; - } - case FWL_VKEY_Up: - case FWL_VKEY_Down: { - OnDropListKeyDown(pKey); - pOuter->ProcessSelChanged(false); - return true; - } - default: { - bPropagate = true; - break; - } - } - } else if (pKey->m_dwCmd == FWL_KeyCommand::Char) { - bPropagate = true; - } - if (bPropagate) { - pKey->m_pDstTarget = m_pOuter; - pOuter->GetDelegate()->OnProcessMessage(pKey); - return true; - } - return false; -} - -void IFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) { - uint32_t dwKeyCode = pKey->m_dwKeyCode; - switch (dwKeyCode) { - case FWL_VKEY_Up: - case FWL_VKEY_Down: - case FWL_VKEY_Home: - case FWL_VKEY_End: { - IFWL_ComboBox* pOuter = static_cast(m_pOuter); - CFWL_ListItem* hItem = GetItem(this, pOuter->GetCurrentSelection()); - hItem = GetListItem(hItem, dwKeyCode); - if (!hItem) - break; - - SetSelection(hItem, hItem, true); - ScrollToVisible(hItem); - CFX_RectF rtInvalidate; - rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, - m_pProperties->m_rtWidget.height); - Repaint(&rtInvalidate); - break; - } - default: - break; - } -} diff --git a/xfa/fwl/core/ifwl_combolist.h b/xfa/fwl/core/ifwl_combolist.h deleted file mode 100644 index 8d01494091..0000000000 --- a/xfa/fwl/core/ifwl_combolist.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_IFWL_COMBOLIST_H_ -#define XFA_FWL_CORE_IFWL_COMBOLIST_H_ - -#include - -#include "xfa/fwl/core/cfwl_widgetproperties.h" -#include "xfa/fwl/core/ifwl_listbox.h" -#include "xfa/fwl/core/ifwl_widget.h" - -class IFWL_ComboList : public IFWL_ListBox { - public: - IFWL_ComboList(const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter); - - // IFWL_ListBox. - void OnProcessMessage(CFWL_Message* pMessage) override; - - int32_t MatchItem(const CFX_WideString& wsMatch); - - void ChangeSelected(int32_t iSel); - - void SetNotifyOwner(bool notify) { m_bNotifyOwner = notify; } - - private: - void ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy); - void OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet); - void OnDropListMouseMove(CFWL_MsgMouse* pMsg); - void OnDropListLButtonDown(CFWL_MsgMouse* pMsg); - void OnDropListLButtonUp(CFWL_MsgMouse* pMsg); - bool OnDropListKey(CFWL_MsgKey* pKey); - void OnDropListKeyDown(CFWL_MsgKey* pKey); - - bool m_bNotifyOwner; -}; - -#endif // XFA_FWL_CORE_IFWL_COMBOLIST_H_ diff --git a/xfa/fwl/core/ifwl_datetimeedit.cpp b/xfa/fwl/core/ifwl_datetimeedit.cpp deleted file mode 100644 index 62ab4f6d19..0000000000 --- a/xfa/fwl/core/ifwl_datetimeedit.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/ifwl_datetimeedit.h" - -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/ifwl_datetimepicker.h" - -IFWL_DateTimeEdit::IFWL_DateTimeEdit( - const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter) - : IFWL_Edit(app, std::move(properties), pOuter) {} - -void IFWL_DateTimeEdit::OnProcessMessage(CFWL_Message* pMessage) { - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_OnProcessMessage(pMessage); - return; - } - - CFWL_MessageType dwHashCode = pMessage->GetClassID(); - if (dwHashCode == CFWL_MessageType::SetFocus || - dwHashCode == CFWL_MessageType::KillFocus) { - IFWL_Widget* pOuter = GetOuter(); - pOuter->GetDelegate()->OnProcessMessage(pMessage); - } -} - -void IFWL_DateTimeEdit::DisForm_OnProcessMessage(CFWL_Message* pMessage) { - CFWL_MessageType dwHashCode = pMessage->GetClassID(); - if (!m_pWidgetMgr->IsFormDisabled() || - dwHashCode != CFWL_MessageType::Mouse) { - IFWL_Edit::OnProcessMessage(pMessage); - return; - } - - CFWL_MsgMouse* pMouse = static_cast(pMessage); - if (pMouse->m_dwCmd == FWL_MouseCommand::LeftButtonDown || - pMouse->m_dwCmd == FWL_MouseCommand::RightButtonDown) { - if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) - m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; - - IFWL_DateTimePicker* pDateTime = - static_cast(m_pOuter); - if (pDateTime->IsMonthCalendarVisible()) { - CFX_RectF rtInvalidate; - pDateTime->GetWidgetRect(rtInvalidate); - pDateTime->ShowMonthCalendar(false); - rtInvalidate.Offset(-rtInvalidate.left, -rtInvalidate.top); - pDateTime->Repaint(&rtInvalidate); - } - } - IFWL_Edit::OnProcessMessage(pMessage); -} diff --git a/xfa/fwl/core/ifwl_datetimeedit.h b/xfa/fwl/core/ifwl_datetimeedit.h deleted file mode 100644 index 1d420b5dcd..0000000000 --- a/xfa/fwl/core/ifwl_datetimeedit.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_IFWL_DATETIMEEDIT_H_ -#define XFA_FWL_CORE_IFWL_DATETIMEEDIT_H_ - -#include - -#include "xfa/fwl/core/cfwl_widgetproperties.h" -#include "xfa/fwl/core/fwl_error.h" -#include "xfa/fwl/core/ifwl_edit.h" -#include "xfa/fwl/core/ifwl_widget.h" - -class IFWL_DateTimeEdit : public IFWL_Edit { - public: - IFWL_DateTimeEdit(const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter); - - // IFWL_Edit. - void OnProcessMessage(CFWL_Message* pMessage) override; - - private: - void DisForm_OnProcessMessage(CFWL_Message* pMessage); -}; - -#endif // XFA_FWL_CORE_IFWL_DATETIMEEDIT_H_ diff --git a/xfa/fwl/core/ifwl_datetimepicker.cpp b/xfa/fwl/core/ifwl_datetimepicker.cpp index f97e95579c..787be0cb9b 100644 --- a/xfa/fwl/core/ifwl_datetimepicker.cpp +++ b/xfa/fwl/core/ifwl_datetimepicker.cpp @@ -12,13 +12,13 @@ #include "third_party/base/ptr_util.h" #include "xfa/fwl/core/cfwl_evteditchanged.h" #include "xfa/fwl/core/cfwl_evtselectchanged.h" +#include "xfa/fwl/core/cfwl_formproxy.h" #include "xfa/fwl/core/cfwl_msgmouse.h" #include "xfa/fwl/core/cfwl_msgsetfocus.h" #include "xfa/fwl/core/cfwl_notedriver.h" +#include "xfa/fwl/core/cfwl_spinbutton.h" #include "xfa/fwl/core/cfwl_themebackground.h" #include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/ifwl_formproxy.h" -#include "xfa/fwl/core/ifwl_spinbutton.h" #include "xfa/fwl/core/ifwl_themeprovider.h" namespace { @@ -47,7 +47,7 @@ IFWL_DateTimePicker::IFWL_DateTimePicker( monthProp->m_pParent = this; monthProp->m_pThemeProvider = m_pProperties->m_pThemeProvider; m_pMonthCal.reset( - new IFWL_MonthCalendar(m_pOwnerApp, std::move(monthProp), this)); + new CFWL_MonthCalendar(m_pOwnerApp, std::move(monthProp), this)); CFX_RectF rtMonthCal; m_pMonthCal->GetWidgetRect(rtMonthCal, true); @@ -58,7 +58,7 @@ IFWL_DateTimePicker::IFWL_DateTimePicker( editProp->m_pParent = this; editProp->m_pThemeProvider = m_pProperties->m_pThemeProvider; - m_pEdit.reset(new IFWL_DateTimeEdit(m_pOwnerApp, std::move(editProp), this)); + m_pEdit.reset(new CFWL_DateTimeEdit(m_pOwnerApp, std::move(editProp), this)); RegisterEventTarget(m_pMonthCal.get()); RegisterEventTarget(m_pEdit.get()); } @@ -371,7 +371,7 @@ void IFWL_DateTimePicker::InitProxyForm() { prop->m_dwStates = FWL_WGTSTATE_Invisible; prop->m_pOwner = this; - m_pForm = pdfium::MakeUnique(m_pOwnerApp, std::move(prop), + m_pForm = pdfium::MakeUnique(m_pOwnerApp, std::move(prop), m_pMonthCal.get()); m_pMonthCal->SetParent(m_pForm.get()); } diff --git a/xfa/fwl/core/ifwl_datetimepicker.h b/xfa/fwl/core/ifwl_datetimepicker.h index 7d73002d20..b8bec96d9a 100644 --- a/xfa/fwl/core/ifwl_datetimepicker.h +++ b/xfa/fwl/core/ifwl_datetimepicker.h @@ -9,10 +9,10 @@ #include +#include "xfa/fwl/core/cfwl_datetimeedit.h" #include "xfa/fwl/core/cfwl_event.h" +#include "xfa/fwl/core/cfwl_monthcalendar.h" #include "xfa/fwl/core/cfwl_widgetproperties.h" -#include "xfa/fwl/core/ifwl_datetimeedit.h" -#include "xfa/fwl/core/ifwl_monthcalendar.h" #include "xfa/fwl/core/ifwl_widget.h" #define FWL_STYLEEXT_DTP_AllowEdit (1L << 0) @@ -32,8 +32,8 @@ #define FWL_STYLEEXT_DTP_EditVAlignMask (3L << 6) #define FWL_STYLEEXT_DTP_EditHAlignModeMask (3L << 8) -class IFWL_DateTimeEdit; -class IFWL_FormProxy; +class CFWL_DateTimeEdit; +class CFWL_FormProxy; class IFWL_DateTimePicker : public IFWL_Widget { public: @@ -75,7 +75,7 @@ class IFWL_DateTimePicker : public IFWL_Widget { void ShowMonthCalendar(bool bActivate); void ProcessSelChanged(int32_t iYear, int32_t iMonth, int32_t iDay); - IFWL_FormProxy* GetFormProxy() const { return m_pForm.get(); } + CFWL_FormProxy* GetFormProxy() const { return m_pForm.get(); } private: void DrawDropDownButton(CFX_Graphics* pGraphics, @@ -111,9 +111,9 @@ class IFWL_DateTimePicker : public IFWL_Widget { int32_t m_iMonth; int32_t m_iDay; bool m_bLBtnDown; - std::unique_ptr m_pEdit; - std::unique_ptr m_pMonthCal; - std::unique_ptr m_pForm; + std::unique_ptr m_pEdit; + std::unique_ptr m_pMonthCal; + std::unique_ptr m_pForm; FX_FLOAT m_fBtn; }; diff --git a/xfa/fwl/core/ifwl_edit.cpp b/xfa/fwl/core/ifwl_edit.cpp index f262f85cee..af29745b5c 100644 --- a/xfa/fwl/core/ifwl_edit.cpp +++ b/xfa/fwl/core/ifwl_edit.cpp @@ -19,6 +19,7 @@ #include "xfa/fde/ifde_txtedtpage.h" #include "xfa/fgas/font/cfgas_gefont.h" #include "xfa/fwl/core/cfwl_app.h" +#include "xfa/fwl/core/cfwl_caret.h" #include "xfa/fwl/core/cfwl_evtcheckword.h" #include "xfa/fwl/core/cfwl_evttextchanged.h" #include "xfa/fwl/core/cfwl_evttextfull.h" @@ -28,7 +29,6 @@ #include "xfa/fwl/core/cfwl_themebackground.h" #include "xfa/fwl/core/cfwl_themepart.h" #include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/ifwl_caret.h" #include "xfa/fwl/core/ifwl_themeprovider.h" #include "xfa/fxfa/xfa_ffdoc.h" #include "xfa/fxfa/xfa_ffwidget.h" @@ -435,7 +435,7 @@ void IFWL_Edit::On_CaretChanged(CFDE_TxtEdtEngine* pEdit, rtInvalid.Set(0, 0, 0, 0); bool bRepaintScroll = false; if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) { - IFWL_ScrollBar* pScroll = UpdateScroll(); + CFWL_ScrollBar* pScroll = UpdateScroll(); if (pScroll) { pScroll->GetWidgetRect(rtInvalid); bRepaintScroll = true; @@ -838,7 +838,7 @@ bool IFWL_Edit::UpdateOffset() { return true; } -bool IFWL_Edit::UpdateOffset(IFWL_ScrollBar* pScrollBar, FX_FLOAT fPosChanged) { +bool IFWL_Edit::UpdateOffset(CFWL_ScrollBar* pScrollBar, FX_FLOAT fPosChanged) { if (pScrollBar == m_pHorzScrollBar.get()) m_fScrollOffsetX += fPosChanged; else @@ -906,7 +906,7 @@ void IFWL_Edit::UpdateCaret() { ShowCaret(bShow, &rtCaret); } -IFWL_ScrollBar* IFWL_Edit::UpdateScroll() { +CFWL_ScrollBar* IFWL_Edit::UpdateScroll() { bool bShowHorz = m_pHorzScrollBar && ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Invisible) == 0); @@ -921,7 +921,7 @@ IFWL_ScrollBar* IFWL_Edit::UpdateScroll() { return nullptr; const CFX_RectF& rtFDE = pPage->GetContentsBox(); - IFWL_ScrollBar* pRepaint = nullptr; + CFWL_ScrollBar* pRepaint = nullptr; if (bShowHorz) { CFX_RectF rtScroll; m_pHorzScrollBar->GetWidgetRect(rtScroll); @@ -1170,7 +1170,7 @@ void IFWL_Edit::InitScrollBar(bool bVert) { prop->m_pParent = this; prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; - IFWL_ScrollBar* sb = new IFWL_ScrollBar(m_pOwnerApp, std::move(prop), this); + CFWL_ScrollBar* sb = new CFWL_ScrollBar(m_pOwnerApp, std::move(prop), this); if (bVert) m_pVertScrollBar.reset(sb); else @@ -1262,7 +1262,7 @@ bool IFWL_Edit::ValidateNumberChar(FX_WCHAR cNum) { void IFWL_Edit::InitCaret() { if (!m_pCaret) { if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret)) { - m_pCaret.reset(new IFWL_Caret( + m_pCaret.reset(new CFWL_Caret( m_pOwnerApp, pdfium::MakeUnique(), this)); m_pCaret->SetParent(this); m_pCaret->SetStates(m_pProperties->m_dwStates); @@ -1344,7 +1344,7 @@ void IFWL_Edit::OnProcessEvent(CFWL_Event* pEvent) { if ((pSrcTarget == m_pVertScrollBar.get() && m_pVertScrollBar) || (pSrcTarget == m_pHorzScrollBar.get() && m_pHorzScrollBar)) { CFWL_EvtScroll* pScrollEvent = static_cast(pEvent); - OnScroll(static_cast(pSrcTarget), + OnScroll(static_cast(pSrcTarget), pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos); } } @@ -1593,7 +1593,7 @@ void IFWL_Edit::OnChar(CFWL_MsgKey* pMsg) { ProcessInsertError(iError); } -bool IFWL_Edit::OnScroll(IFWL_ScrollBar* pScrollBar, +bool IFWL_Edit::OnScroll(CFWL_ScrollBar* pScrollBar, FWL_SCBCODE dwCode, FX_FLOAT fPos) { CFX_SizeF fs; diff --git a/xfa/fwl/core/ifwl_edit.h b/xfa/fwl/core/ifwl_edit.h index b695f77a58..8b217fa45d 100644 --- a/xfa/fwl/core/ifwl_edit.h +++ b/xfa/fwl/core/ifwl_edit.h @@ -14,8 +14,8 @@ #include "xfa/fde/cfde_txtedtengine.h" #include "xfa/fde/ifde_txtedtdorecord.h" #include "xfa/fwl/core/cfwl_event.h" +#include "xfa/fwl/core/cfwl_scrollbar.h" #include "xfa/fwl/core/cfwl_widget.h" -#include "xfa/fwl/core/ifwl_scrollbar.h" #include "xfa/fwl/core/ifwl_widget.h" #include "xfa/fxgraphics/cfx_path.h" @@ -55,7 +55,7 @@ class IFDE_TxtEdtDoRecord; class IFWL_Edit; class CFWL_MsgMouse; class CFWL_WidgetProperties; -class IFWL_Caret; +class CFWL_Caret; class IFWL_Edit : public IFWL_Widget { public: @@ -137,10 +137,10 @@ class IFWL_Edit : public IFWL_Widget { void UpdateEditParams(); void UpdateEditLayout(); bool UpdateOffset(); - bool UpdateOffset(IFWL_ScrollBar* pScrollBar, FX_FLOAT fPosChanged); + bool UpdateOffset(CFWL_ScrollBar* pScrollBar, FX_FLOAT fPosChanged); void UpdateVAlignment(); void UpdateCaret(); - IFWL_ScrollBar* UpdateScroll(); + CFWL_ScrollBar* UpdateScroll(); void Layout(); void LayoutScrollBar(); void DeviceToEngine(CFX_PointF& pt); @@ -169,7 +169,7 @@ class IFWL_Edit : public IFWL_Widget { void OnMouseMove(CFWL_MsgMouse* pMsg); void OnKeyDown(CFWL_MsgKey* pMsg); void OnChar(CFWL_MsgKey* pMsg); - bool OnScroll(IFWL_ScrollBar* pScrollBar, FWL_SCBCODE dwCode, FX_FLOAT fPos); + bool OnScroll(CFWL_ScrollBar* pScrollBar, FWL_SCBCODE dwCode, FX_FLOAT fPos); CFX_RectF m_rtClient; CFX_RectF m_rtEngine; @@ -184,9 +184,9 @@ class IFWL_Edit : public IFWL_Widget { FX_FLOAT m_fFontSize; bool m_bSetRange; int32_t m_iMax; - std::unique_ptr m_pVertScrollBar; - std::unique_ptr m_pHorzScrollBar; - std::unique_ptr m_pCaret; + std::unique_ptr m_pVertScrollBar; + std::unique_ptr m_pHorzScrollBar; + std::unique_ptr m_pCaret; CFX_WideString m_wsCache; CFX_WideString m_wsFont; std::deque> m_DoRecords; diff --git a/xfa/fwl/core/ifwl_form.cpp b/xfa/fwl/core/ifwl_form.cpp deleted file mode 100644 index 535205d81a..0000000000 --- a/xfa/fwl/core/ifwl_form.cpp +++ /dev/null @@ -1,639 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/ifwl_form.h" - -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fde/tto/fde_textout.h" -#include "xfa/fwl/core/cfwl_app.h" -#include "xfa/fwl/core/cfwl_evtclose.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_noteloop.h" -#include "xfa/fwl/core/cfwl_sysbtn.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themepart.h" -#include "xfa/fwl/core/cfwl_themetext.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/ifwl_formproxy.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" -#include "xfa/fwl/theme/cfwl_widgettp.h" - -namespace { - -const int kSystemButtonSize = 21; -const int kSystemButtonMargin = 5; -const int kSystemButtonSpan = 2; - -} // namespace - -namespace { - -const uint8_t kCornerEnlarge = 10; - -} // namespace - -IFWL_Form::IFWL_Form(const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter) - : IFWL_Widget(app, std::move(properties), pOuter), -#if (_FX_OS_ == _FX_MACOSX_) - m_bMouseIn(false), -#endif - m_pCloseBox(nullptr), - m_pMinBox(nullptr), - m_pMaxBox(nullptr), - m_pSubFocus(nullptr), - m_fCXBorder(0), - m_fCYBorder(0), - m_iCaptureBtn(-1), - m_iSysBox(0), - m_bLButtonDown(false), - m_bMaximized(false), - m_bSetMaximize(false), - m_bDoModalFlag(false) { - m_rtRelative.Reset(); - m_rtRestore.Reset(); - - RegisterForm(); - RegisterEventTarget(nullptr); -} - -IFWL_Form::~IFWL_Form() { - UnregisterEventTarget(); - UnRegisterForm(); - RemoveSysButtons(); -} - -FWL_Type IFWL_Form::GetClassID() const { - return FWL_Type::Form; -} - -bool IFWL_Form::IsInstance(const CFX_WideStringC& wsClass) const { - if (wsClass == CFX_WideStringC(FWL_CLASS_Form)) - return true; - return IFWL_Widget::IsInstance(wsClass); -} - -void IFWL_Form::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { - if (!bAutoSize) { - rect = m_pProperties->m_rtWidget; - return; - } - - rect.Reset(); - FX_FLOAT fCXBorder = GetBorderSize(true); - FX_FLOAT fCYBorder = GetBorderSize(false); - FX_FLOAT fEdge = GetEdgeWidth(); - rect.height += fCYBorder + fEdge + fEdge; - rect.width += fCXBorder + fCXBorder + fEdge + fEdge; -} - -void IFWL_Form::GetClientRect(CFX_RectF& rect) { - rect = m_pProperties->m_rtWidget; - rect.Offset(-rect.left, -rect.top); -} - -void IFWL_Form::Update() { - if (m_iLock > 0) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - Layout(); -} - -FWL_WidgetHit IFWL_Form::HitTest(FX_FLOAT fx, FX_FLOAT fy) { - GetAvailableTheme(); - - if (m_pCloseBox && m_pCloseBox->m_rtBtn.Contains(fx, fy)) - return FWL_WidgetHit::CloseBox; - if (m_pMaxBox && m_pMaxBox->m_rtBtn.Contains(fx, fy)) - return FWL_WidgetHit::MaxBox; - if (m_pMinBox && m_pMinBox->m_rtBtn.Contains(fx, fy)) - return FWL_WidgetHit::MinBox; - - CFX_RectF rtCap; - rtCap.Set(m_fCYBorder, m_fCXBorder, - 0 - kSystemButtonSize * m_iSysBox - 2 * m_fCYBorder, - 0 - m_fCXBorder); - if (rtCap.Contains(fx, fy)) - return FWL_WidgetHit::Titlebar; - if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) && - (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_Resize)) { - FX_FLOAT fWidth = m_rtRelative.width - 2 * (m_fCYBorder + kCornerEnlarge); - FX_FLOAT fHeight = m_rtRelative.height - 2 * (m_fCXBorder + kCornerEnlarge); - - CFX_RectF rt; - rt.Set(0, m_fCXBorder + kCornerEnlarge, m_fCYBorder, fHeight); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::Left; - - rt.Set(m_rtRelative.width - m_fCYBorder, m_fCXBorder + kCornerEnlarge, - m_fCYBorder, fHeight); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::Right; - - rt.Set(m_fCYBorder + kCornerEnlarge, 0, fWidth, m_fCXBorder); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::Top; - - rt.Set(m_fCYBorder + kCornerEnlarge, m_rtRelative.height - m_fCXBorder, - fWidth, m_fCXBorder); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::Bottom; - - rt.Set(0, 0, m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::LeftTop; - - rt.Set(0, m_rtRelative.height - m_fCXBorder - kCornerEnlarge, - m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::LeftBottom; - - rt.Set(m_rtRelative.width - m_fCYBorder - kCornerEnlarge, 0, - m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::RightTop; - - rt.Set(m_rtRelative.width - m_fCYBorder - kCornerEnlarge, - m_rtRelative.height - m_fCXBorder - kCornerEnlarge, - m_fCYBorder + kCornerEnlarge, m_fCXBorder + kCornerEnlarge); - if (rt.Contains(fx, fy)) - return FWL_WidgetHit::RightBottom; - } - return FWL_WidgetHit::Client; -} - -void IFWL_Form::DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - return; - - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - bool bInactive = !IsActive(); - int32_t iState = bInactive ? CFWL_PartState_Inactive : CFWL_PartState_Normal; - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_NoDrawClient) == 0) - DrawBackground(pGraphics, pTheme); - -#ifdef FWL_UseMacSystemBorder - return; -#endif - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_dwStates = iState; - param.m_pGraphics = pGraphics; - param.m_rtPart = m_rtRelative; - if (pMatrix) - param.m_matrix.Concat(*pMatrix); - if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) { - param.m_iPart = CFWL_Part::Border; - pTheme->DrawBackground(¶m); - } - if ((m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_EdgeMask) != - FWL_WGTSTYLE_EdgeNone) { - CFX_RectF rtEdge; - GetEdgeRect(rtEdge); - param.m_iPart = CFWL_Part::Edge; - param.m_rtPart = rtEdge; - param.m_dwStates = iState; - pTheme->DrawBackground(¶m); - } - -#if (_FX_OS_ == _FX_MACOSX_) - { - if (m_pCloseBox) { - param.m_iPart = CFWL_Part::CloseBox; - param.m_dwStates = m_pCloseBox->GetPartState(); - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) - param.m_dwStates = CFWL_PartState_Disabled; - else if (CFWL_PartState_Normal == param.m_dwStates && m_bMouseIn) - param.m_dwStates = CFWL_PartState_Hovered; - param.m_rtPart = m_pCloseBox->m_rtBtn; - pTheme->DrawBackground(¶m); - } - if (m_pMaxBox) { - param.m_iPart = CFWL_Part::MaximizeBox; - param.m_dwStates = m_pMaxBox->GetPartState(); - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) - param.m_dwStates = CFWL_PartState_Disabled; - else if (CFWL_PartState_Normal == param.m_dwStates && m_bMouseIn) - param.m_dwStates = CFWL_PartState_Hovered; - param.m_rtPart = m_pMaxBox->m_rtBtn; - param.m_bMaximize = m_bMaximized; - pTheme->DrawBackground(¶m); - } - if (m_pMinBox) { - param.m_iPart = CFWL_Part::MinimizeBox; - param.m_dwStates = m_pMinBox->GetPartState(); - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Deactivated) - param.m_dwStates = CFWL_PartState_Disabled; - else if (CFWL_PartState_Normal == param.m_dwStates && m_bMouseIn) - param.m_dwStates = CFWL_PartState_Hovered; - param.m_rtPart = m_pMinBox->m_rtBtn; - pTheme->DrawBackground(¶m); - } - m_bMouseIn = false; - } -#else - { - if (m_pCloseBox) { - param.m_iPart = CFWL_Part::CloseBox; - param.m_dwStates = m_pCloseBox->GetPartState(); - param.m_rtPart = m_pCloseBox->m_rtBtn; - pTheme->DrawBackground(¶m); - } - if (m_pMaxBox) { - param.m_iPart = CFWL_Part::MaximizeBox; - param.m_dwStates = m_pMaxBox->GetPartState(); - param.m_rtPart = m_pMaxBox->m_rtBtn; - param.m_bMaximize = m_bMaximized; - pTheme->DrawBackground(¶m); - } - if (m_pMinBox) { - param.m_iPart = CFWL_Part::MinimizeBox; - param.m_dwStates = m_pMinBox->GetPartState(); - param.m_rtPart = m_pMinBox->m_rtBtn; - pTheme->DrawBackground(¶m); - } - } -#endif -} - -IFWL_Widget* IFWL_Form::DoModal() { - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return nullptr; - - CFWL_NoteDriver* pDriver = pApp->GetNoteDriver(); - if (!pDriver) - return nullptr; - - m_pNoteLoop = pdfium::MakeUnique(); - m_pNoteLoop->SetMainForm(this); - - pDriver->PushNoteLoop(m_pNoteLoop.get()); - m_bDoModalFlag = true; - SetStates(FWL_WGTSTATE_Invisible, false); - pDriver->Run(); - -#if _FX_OS_ != _FX_MACOSX_ - pDriver->PopNoteLoop(); -#endif - - m_pNoteLoop.reset(); - return nullptr; -} - -void IFWL_Form::EndDoModal() { - if (!m_pNoteLoop) - return; - - m_bDoModalFlag = false; - -#if (_FX_OS_ == _FX_MACOSX_) - m_pNoteLoop->EndModalLoop(); - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pDriver = - static_cast(pApp->GetNoteDriver()); - if (!pDriver) - return; - - pDriver->PopNoteLoop(); - SetStates(FWL_WGTSTATE_Invisible, true); -#else - SetStates(FWL_WGTSTATE_Invisible, true); - m_pNoteLoop->EndModalLoop(); -#endif -} - -void IFWL_Form::DrawBackground(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme) { - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::Background; - param.m_pGraphics = pGraphics; - param.m_rtPart = m_rtRelative; - param.m_rtPart.Deflate(m_fCYBorder, m_fCXBorder, m_fCYBorder, m_fCXBorder); - pTheme->DrawBackground(¶m); -} - -void IFWL_Form::RemoveSysButtons() { - delete m_pCloseBox; - m_pCloseBox = nullptr; - delete m_pMinBox; - m_pMinBox = nullptr; - delete m_pMaxBox; - m_pMaxBox = nullptr; -} - -CFWL_SysBtn* IFWL_Form::GetSysBtnAtPoint(FX_FLOAT fx, FX_FLOAT fy) { - if (m_pCloseBox && m_pCloseBox->m_rtBtn.Contains(fx, fy)) - return m_pCloseBox; - if (m_pMaxBox && m_pMaxBox->m_rtBtn.Contains(fx, fy)) - return m_pMaxBox; - if (m_pMinBox && m_pMinBox->m_rtBtn.Contains(fx, fy)) - return m_pMinBox; - return nullptr; -} - -CFWL_SysBtn* IFWL_Form::GetSysBtnByState(uint32_t dwState) { - if (m_pCloseBox && (m_pCloseBox->m_dwState & dwState)) - return m_pCloseBox; - if (m_pMaxBox && (m_pMaxBox->m_dwState & dwState)) - return m_pMaxBox; - if (m_pMinBox && (m_pMinBox->m_dwState & dwState)) - return m_pMinBox; - return nullptr; -} - -CFWL_SysBtn* IFWL_Form::GetSysBtnByIndex(int32_t nIndex) { - if (nIndex < 0) - return nullptr; - - CFX_ArrayTemplate arrBtn; - if (m_pMinBox) - arrBtn.Add(m_pMinBox); - if (m_pMaxBox) - arrBtn.Add(m_pMaxBox); - if (m_pCloseBox) - arrBtn.Add(m_pCloseBox); - return arrBtn[nIndex]; -} - -int32_t IFWL_Form::GetSysBtnIndex(CFWL_SysBtn* pBtn) { - CFX_ArrayTemplate arrBtn; - if (m_pMinBox) - arrBtn.Add(m_pMinBox); - if (m_pMaxBox) - arrBtn.Add(m_pMaxBox); - if (m_pCloseBox) - arrBtn.Add(m_pCloseBox); - return arrBtn.Find(pBtn); -} - -void IFWL_Form::GetEdgeRect(CFX_RectF& rtEdge) { - rtEdge = m_rtRelative; - if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) { - FX_FLOAT fCX = GetBorderSize(); - FX_FLOAT fCY = GetBorderSize(false); - rtEdge.Deflate(fCX, fCY, fCX, fCY); - } -} - -void IFWL_Form::SetWorkAreaRect() { - m_rtRestore = m_pProperties->m_rtWidget; - CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr(); - if (!pWidgetMgr) - return; - - m_bSetMaximize = true; - Repaint(&m_rtRelative); -} - -void IFWL_Form::Layout() { - GetRelativeRect(m_rtRelative); - -#ifndef FWL_UseMacSystemBorder - ResetSysBtn(); -#endif -} - -void IFWL_Form::ResetSysBtn() { - m_fCXBorder = - *static_cast(GetThemeCapacity(CFWL_WidgetCapacity::CXBorder)); - m_fCYBorder = - *static_cast(GetThemeCapacity(CFWL_WidgetCapacity::CYBorder)); - RemoveSysButtons(); - - m_iSysBox = 0; - if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_CloseBox) { - m_pCloseBox = new CFWL_SysBtn; - m_pCloseBox->m_rtBtn.Set( - m_rtRelative.right() - kSystemButtonMargin - kSystemButtonSize, - kSystemButtonMargin, kSystemButtonSize, kSystemButtonSize); - m_iSysBox++; - } - if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_MaximizeBox) { - m_pMaxBox = new CFWL_SysBtn; - if (m_pCloseBox) { - m_pMaxBox->m_rtBtn.Set( - m_pCloseBox->m_rtBtn.left - kSystemButtonSpan - kSystemButtonSize, - m_pCloseBox->m_rtBtn.top, kSystemButtonSize, kSystemButtonSize); - } else { - m_pMaxBox->m_rtBtn.Set( - m_rtRelative.right() - kSystemButtonMargin - kSystemButtonSize, - kSystemButtonMargin, kSystemButtonSize, kSystemButtonSize); - } - m_iSysBox++; - } - if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_MinimizeBox) { - m_pMinBox = new CFWL_SysBtn; - if (m_pMaxBox) { - m_pMinBox->m_rtBtn.Set( - m_pMaxBox->m_rtBtn.left - kSystemButtonSpan - kSystemButtonSize, - m_pMaxBox->m_rtBtn.top, kSystemButtonSize, kSystemButtonSize); - } else if (m_pCloseBox) { - m_pMinBox->m_rtBtn.Set( - m_pCloseBox->m_rtBtn.left - kSystemButtonSpan - kSystemButtonSize, - m_pCloseBox->m_rtBtn.top, kSystemButtonSize, kSystemButtonSize); - } else { - m_pMinBox->m_rtBtn.Set( - m_rtRelative.right() - kSystemButtonMargin - kSystemButtonSize, - kSystemButtonMargin, kSystemButtonSize, kSystemButtonSize); - } - m_iSysBox++; - } -} - -void IFWL_Form::RegisterForm() { - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pDriver = - static_cast(pApp->GetNoteDriver()); - if (!pDriver) - return; - - pDriver->RegisterForm(this); -} - -void IFWL_Form::UnRegisterForm() { - const CFWL_App* pApp = GetOwnerApp(); - if (!pApp) - return; - - CFWL_NoteDriver* pDriver = - static_cast(pApp->GetNoteDriver()); - if (!pDriver) - return; - - pDriver->UnRegisterForm(this); -} - -void IFWL_Form::OnProcessMessage(CFWL_Message* pMessage) { -#ifndef FWL_UseMacSystemBorder - if (!pMessage) - return; - - switch (pMessage->GetClassID()) { - case CFWL_MessageType::Mouse: { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMsg); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMsg); - break; - case FWL_MouseCommand::Move: - OnMouseMove(pMsg); - break; - case FWL_MouseCommand::Leave: - OnMouseLeave(pMsg); - break; - case FWL_MouseCommand::LeftButtonDblClk: - OnLButtonDblClk(pMsg); - break; - default: - break; - } - break; - } - default: - break; - } -#endif // FWL_UseMacSystemBorder -} - -void IFWL_Form::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -void IFWL_Form::OnLButtonDown(CFWL_MsgMouse* pMsg) { - SetGrab(true); - m_bLButtonDown = true; - - CFWL_SysBtn* pPressBtn = GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy); - m_iCaptureBtn = GetSysBtnIndex(pPressBtn); - - if (!pPressBtn) - return; - - pPressBtn->SetPressed(); - Repaint(&pPressBtn->m_rtBtn); -} - -void IFWL_Form::OnLButtonUp(CFWL_MsgMouse* pMsg) { - SetGrab(false); - m_bLButtonDown = false; - CFWL_SysBtn* pPointBtn = GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy); - CFWL_SysBtn* pPressedBtn = GetSysBtnByIndex(m_iCaptureBtn); - if (!pPressedBtn || pPointBtn != pPressedBtn) - return; - if (pPressedBtn == GetSysBtnByState(FWL_SYSBUTTONSTATE_Pressed)) - pPressedBtn->SetNormal(); - if (pPressedBtn == m_pMaxBox) { - if (m_bMaximized) { - SetWidgetRect(m_rtRestore); - Update(); - Repaint(); - } else { - SetWorkAreaRect(); - Update(); - } - m_bMaximized = !m_bMaximized; - } else if (pPressedBtn != m_pMinBox) { - CFWL_EvtClose eClose; - eClose.m_pSrcTarget = this; - DispatchEvent(&eClose); - } -} - -void IFWL_Form::OnMouseMove(CFWL_MsgMouse* pMsg) { - if (m_bLButtonDown) - return; - - CFX_RectF rtInvalidate; - rtInvalidate.Reset(); - CFWL_SysBtn* pPointBtn = GetSysBtnAtPoint(pMsg->m_fx, pMsg->m_fy); - CFWL_SysBtn* pOldHover = GetSysBtnByState(FWL_SYSBUTTONSTATE_Hover); - -#if _FX_OS_ == _FX_MACOSX_ - { - if (pOldHover && pPointBtn != pOldHover) - pOldHover->SetNormal(); - if (pPointBtn && pPointBtn != pOldHover) - pPointBtn->SetHover(); - if (m_pCloseBox) - rtInvalidate = m_pCloseBox->m_rtBtn; - if (m_pMaxBox) { - if (rtInvalidate.IsEmpty()) - rtInvalidate = m_pMaxBox->m_rtBtn; - else - rtInvalidate.Union(m_pMaxBox->m_rtBtn); - } - if (m_pMinBox) { - if (rtInvalidate.IsEmpty()) - rtInvalidate = m_pMinBox->m_rtBtn; - else - rtInvalidate.Union(m_pMinBox->m_rtBtn); - } - if (!rtInvalidate.IsEmpty() && - rtInvalidate.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_bMouseIn = true; - } - } -#else - { - if (pOldHover && pPointBtn != pOldHover) { - pOldHover->SetNormal(); - rtInvalidate = pOldHover->m_rtBtn; - } - if (pPointBtn && pPointBtn != pOldHover) { - pPointBtn->SetHover(); - if (rtInvalidate.IsEmpty()) - rtInvalidate = pPointBtn->m_rtBtn; - else - rtInvalidate.Union(pPointBtn->m_rtBtn); - } - } -#endif - - if (!rtInvalidate.IsEmpty()) - Repaint(&rtInvalidate); -} - -void IFWL_Form::OnMouseLeave(CFWL_MsgMouse* pMsg) { - CFWL_SysBtn* pHover = GetSysBtnByState(FWL_SYSBUTTONSTATE_Hover); - if (!pHover) - return; - - pHover->SetNormal(); - Repaint(&pHover->m_rtBtn); -} - -void IFWL_Form::OnLButtonDblClk(CFWL_MsgMouse* pMsg) { - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_FRM_Resize) && - HitTest(pMsg->m_fx, pMsg->m_fy) == FWL_WidgetHit::Titlebar) { - if (m_bMaximized) - SetWidgetRect(m_rtRestore); - else - SetWorkAreaRect(); - - Update(); - m_bMaximized = !m_bMaximized; - } -} diff --git a/xfa/fwl/core/ifwl_form.h b/xfa/fwl/core/ifwl_form.h deleted file mode 100644 index 5c4c00dbf3..0000000000 --- a/xfa/fwl/core/ifwl_form.h +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_IFWL_FORM_H_ -#define XFA_FWL_CORE_IFWL_FORM_H_ - -#include - -#include "core/fxcrt/fx_system.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" -#include "xfa/fwl/core/ifwl_widget.h" - -#define FWL_CLASS_Form L"FWL_FORM" -#define FWL_CLASS_FormProxy L"FWL_FORMPROXY" -#define FWL_STYLEEXT_FRM_Resize (1L << 0) -#define FWL_STYLEEXT_FRM_NativeBorder (1L << 1) -#define FWL_STYLEEXT_FRM_RoundCorner (2L << 1) -#define FWL_STYLEEXT_FRM_RoundCorner4 (3L << 1) -#define FWL_STYLEEXT_FRM_NoDrawClient (1L << 3) -#define FWL_STYLEEXT_FRM_BorderCornerMask (3L << 1) -#define FWL_STYLEEXT_FRM_Max (3) - -#if (_FX_OS_ == _FX_MACOSX_) -#define FWL_UseMacSystemBorder -#endif - -class CFWL_MsgMouse; -class CFWL_NoteLoop; -class IFWL_Widget; -class IFWL_ThemeProvider; -class CFWL_SysBtn; - -class IFWL_Form : public IFWL_Widget { - public: - IFWL_Form(const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter); - ~IFWL_Form() override; - - // IFWL_Widget - FWL_Type GetClassID() const override; - bool IsInstance(const CFX_WideStringC& wsClass) const override; - void GetWidgetRect(CFX_RectF& rect, bool bAutoSize = false) override; - void GetClientRect(CFX_RectF& rect) override; - void Update() override; - FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; - void DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - IFWL_Widget* DoModal(); - void EndDoModal(); - - IFWL_Widget* GetSubFocus() const { return m_pSubFocus; } - void SetSubFocus(IFWL_Widget* pWidget) { m_pSubFocus = pWidget; } - - private: - void DrawBackground(CFX_Graphics* pGraphics, IFWL_ThemeProvider* pTheme); - void RemoveSysButtons(); - CFWL_SysBtn* GetSysBtnAtPoint(FX_FLOAT fx, FX_FLOAT fy); - CFWL_SysBtn* GetSysBtnByState(uint32_t dwState); - CFWL_SysBtn* GetSysBtnByIndex(int32_t nIndex); - int32_t GetSysBtnIndex(CFWL_SysBtn* pBtn); - void GetEdgeRect(CFX_RectF& rtEdge); - void SetWorkAreaRect(); - void Layout(); - void ResetSysBtn(); - void RegisterForm(); - void UnRegisterForm(); - void OnLButtonDown(CFWL_MsgMouse* pMsg); - void OnLButtonUp(CFWL_MsgMouse* pMsg); - void OnMouseMove(CFWL_MsgMouse* pMsg); - void OnMouseLeave(CFWL_MsgMouse* pMsg); - void OnLButtonDblClk(CFWL_MsgMouse* pMsg); - -#if (_FX_OS_ == _FX_MACOSX_) - bool m_bMouseIn; -#endif - CFX_RectF m_rtRestore; - CFX_RectF m_rtRelative; - CFWL_SysBtn* m_pCloseBox; - CFWL_SysBtn* m_pMinBox; - CFWL_SysBtn* m_pMaxBox; - std::unique_ptr m_pNoteLoop; - IFWL_Widget* m_pSubFocus; - FX_FLOAT m_fCXBorder; - FX_FLOAT m_fCYBorder; - int32_t m_iCaptureBtn; - int32_t m_iSysBox; - bool m_bLButtonDown; - bool m_bMaximized; - bool m_bSetMaximize; - bool m_bDoModalFlag; -}; - -#endif // XFA_FWL_CORE_IFWL_FORM_H_ diff --git a/xfa/fwl/core/ifwl_formproxy.cpp b/xfa/fwl/core/ifwl_formproxy.cpp deleted file mode 100644 index 521e056c75..0000000000 --- a/xfa/fwl/core/ifwl_formproxy.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/ifwl_formproxy.h" - -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_notedriver.h" - -IFWL_FormProxy::IFWL_FormProxy( - const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter) - : IFWL_Form(app, std::move(properties), pOuter) {} - -IFWL_FormProxy::~IFWL_FormProxy() {} - -FWL_Type IFWL_FormProxy::GetClassID() const { - return FWL_Type::FormProxy; -} - -bool IFWL_FormProxy::IsInstance(const CFX_WideStringC& wsClass) const { - if (wsClass == CFX_WideStringC(FWL_CLASS_FormProxy)) - return true; - return IFWL_Form::IsInstance(wsClass); -} - -void IFWL_FormProxy::Update() {} - -void IFWL_FormProxy::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) {} - -void IFWL_FormProxy::OnProcessMessage(CFWL_Message* pMessage) { - m_pOuter->GetDelegate()->OnProcessMessage(pMessage); -} diff --git a/xfa/fwl/core/ifwl_formproxy.h b/xfa/fwl/core/ifwl_formproxy.h deleted file mode 100644 index b3c6a10f28..0000000000 --- a/xfa/fwl/core/ifwl_formproxy.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_IFWL_FORMPROXY_H_ -#define XFA_FWL_CORE_IFWL_FORMPROXY_H_ - -#include - -#include "xfa/fwl/core/ifwl_form.h" - -class CFWL_WidgetProperties; - -class IFWL_FormProxy : public IFWL_Form { - public: - IFWL_FormProxy(const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter); - ~IFWL_FormProxy() override; - - // IFWL_Widget - FWL_Type GetClassID() const override; - bool IsInstance(const CFX_WideStringC& wsClass) const override; - void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; - void OnProcessMessage(CFWL_Message* pMessage) override; -}; - -#endif // XFA_FWL_CORE_IFWL_FORMPROXY_H_ diff --git a/xfa/fwl/core/ifwl_listbox.cpp b/xfa/fwl/core/ifwl_listbox.cpp index 2961732024..6186e64a4b 100644 --- a/xfa/fwl/core/ifwl_listbox.cpp +++ b/xfa/fwl/core/ifwl_listbox.cpp @@ -748,7 +748,7 @@ void IFWL_ListBox::InitScrollBar(bool bVert) { prop->m_dwStates = FWL_WGTSTATE_Invisible; prop->m_pParent = this; prop->m_pThemeProvider = m_pScrollBarTP; - IFWL_ScrollBar* sb = new IFWL_ScrollBar(m_pOwnerApp, std::move(prop), this); + CFWL_ScrollBar* sb = new CFWL_ScrollBar(m_pOwnerApp, std::move(prop), this); if (bVert) m_pVertScrollBar.reset(sb); else @@ -756,7 +756,7 @@ void IFWL_ListBox::InitScrollBar(bool bVert) { } bool IFWL_ListBox::IsShowScrollBar(bool bVert) { - IFWL_ScrollBar* pScrollbar = + CFWL_ScrollBar* pScrollbar = bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); if (!pScrollbar || (pScrollbar->GetStates() & FWL_WGTSTATE_Invisible)) return false; @@ -818,7 +818,7 @@ void IFWL_ListBox::OnProcessEvent(CFWL_Event* pEvent) { if ((pSrcTarget == m_pVertScrollBar.get() && m_pVertScrollBar) || (pSrcTarget == m_pHorzScrollBar.get() && m_pHorzScrollBar)) { CFWL_EvtScroll* pScrollEvent = static_cast(pEvent); - OnScroll(static_cast(pSrcTarget), + OnScroll(static_cast(pSrcTarget), pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos); } } @@ -947,7 +947,7 @@ void IFWL_ListBox::OnVK(CFWL_ListItem* pItem, bool bShift, bool bCtrl) { Repaint(&rtInvalidate); } -bool IFWL_ListBox::OnScroll(IFWL_ScrollBar* pScrollBar, +bool IFWL_ListBox::OnScroll(CFWL_ScrollBar* pScrollBar, FWL_SCBCODE dwCode, FX_FLOAT fPos) { CFX_SizeF fs; diff --git a/xfa/fwl/core/ifwl_listbox.h b/xfa/fwl/core/ifwl_listbox.h index 7b23881c21..a8638eb3b6 100644 --- a/xfa/fwl/core/ifwl_listbox.h +++ b/xfa/fwl/core/ifwl_listbox.h @@ -107,7 +107,7 @@ class IFWL_ListBox : public IFWL_Widget { bool ScrollToVisible(CFWL_ListItem* hItem); void InitScrollBar(bool bVert = true); bool IsShowScrollBar(bool bVert); - IFWL_ScrollBar* GetVertScrollBar() const { return m_pVertScrollBar.get(); } + CFWL_ScrollBar* GetVertScrollBar() const { return m_pVertScrollBar.get(); } const CFX_RectF& GetRTClient() const { return m_rtClient; } private: @@ -148,13 +148,13 @@ class IFWL_ListBox : public IFWL_Widget { void OnMouseWheel(CFWL_MsgMouseWheel* pMsg); void OnKeyDown(CFWL_MsgKey* pMsg); void OnVK(CFWL_ListItem* hItem, bool bShift, bool bCtrl); - bool OnScroll(IFWL_ScrollBar* pScrollBar, FWL_SCBCODE dwCode, FX_FLOAT fPos); + bool OnScroll(CFWL_ScrollBar* pScrollBar, FWL_SCBCODE dwCode, FX_FLOAT fPos); CFX_RectF m_rtClient; CFX_RectF m_rtStatic; CFX_RectF m_rtConent; - std::unique_ptr m_pHorzScrollBar; - std::unique_ptr m_pVertScrollBar; + std::unique_ptr m_pHorzScrollBar; + std::unique_ptr m_pVertScrollBar; uint32_t m_dwTTOStyles; int32_t m_iTTOAligns; CFWL_ListItem* m_hAnchor; diff --git a/xfa/fwl/core/ifwl_monthcalendar.cpp b/xfa/fwl/core/ifwl_monthcalendar.cpp deleted file mode 100644 index aaa15e47ae..0000000000 --- a/xfa/fwl/core/ifwl_monthcalendar.cpp +++ /dev/null @@ -1,1111 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/ifwl_monthcalendar.h" - -#include -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fde/tto/fde_textout.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themetext.h" -#include "xfa/fwl/core/ifwl_datetimepicker.h" -#include "xfa/fwl/core/ifwl_formproxy.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" - -#define MONTHCAL_HSEP_HEIGHT 1 -#define MONTHCAL_VSEP_WIDTH 1 -#define MONTHCAL_HMARGIN 3 -#define MONTHCAL_VMARGIN 2 -#define MONTHCAL_ROWS 9 -#define MONTHCAL_COLUMNS 7 -#define MONTHCAL_HEADER_BTN_VMARGIN 7 -#define MONTHCAL_HEADER_BTN_HMARGIN 5 - -namespace { - -CFX_WideString* GetCapacityForDay(IFWL_ThemeProvider* pTheme, - CFWL_ThemePart& params, - uint32_t day) { - ASSERT(day < 7); - - if (day == 0) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Sun)); - } - if (day == 1) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Mon)); - } - if (day == 2) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Tue)); - } - if (day == 3) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Wed)); - } - if (day == 4) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Thu)); - } - if (day == 5) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Fri)); - } - - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Sat)); -} - -CFX_WideString* GetCapacityForMonth(IFWL_ThemeProvider* pTheme, - CFWL_ThemePart& params, - uint32_t month) { - ASSERT(month < 12); - - if (month == 0) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::January)); - } - if (month == 1) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::February)); - } - if (month == 2) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::March)); - } - if (month == 3) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::April)); - } - if (month == 4) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::May)); - } - if (month == 5) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::June)); - } - if (month == 6) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::July)); - } - if (month == 7) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::August)); - } - if (month == 8) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::September)); - } - if (month == 9) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::October)); - } - if (month == 10) { - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::November)); - } - - return static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::December)); -} - -} // namespace - -IFWL_MonthCalendar::IFWL_MonthCalendar( - const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter) - : IFWL_Widget(app, std::move(properties), pOuter), - m_bInitialized(false), - m_pDateTime(new CFX_DateTime), - m_iCurYear(2011), - m_iCurMonth(1), - m_iYear(2011), - m_iMonth(1), - m_iDay(1), - m_iHovered(-1), - m_iLBtnPartStates(CFWL_PartState_Normal), - m_iRBtnPartStates(CFWL_PartState_Normal), - m_bFlag(false) { - m_rtHead.Reset(); - m_rtWeek.Reset(); - m_rtLBtn.Reset(); - m_rtRBtn.Reset(); - m_rtDates.Reset(); - m_rtHSep.Reset(); - m_rtHeadText.Reset(); - m_rtToday.Reset(); - m_rtTodayFlag.Reset(); - m_rtClient.Reset(); - m_rtWeekNum.Reset(); - m_rtWeekNumSep.Reset(); -} - -IFWL_MonthCalendar::~IFWL_MonthCalendar() { - ClearDateItem(); - m_arrSelDays.RemoveAll(); -} - -FWL_Type IFWL_MonthCalendar::GetClassID() const { - return FWL_Type::MonthCalendar; -} - -void IFWL_MonthCalendar::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { - if (!bAutoSize) { - rect = m_pProperties->m_rtWidget; - return; - } - - CFX_SizeF fs = CalcSize(true); - rect.Set(0, 0, fs.x, fs.y); - IFWL_Widget::GetWidgetRect(rect, true); -} - -void IFWL_MonthCalendar::Update() { - if (IsLocked()) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - GetCapValue(); - if (!m_bInitialized) { - InitDate(); - m_bInitialized = true; - } - - ClearDateItem(); - ResetDateItem(); - Layout(); -} - -void IFWL_MonthCalendar::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - if (HasBorder()) - DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); - if (HasEdge()) - DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); - - DrawBackground(pGraphics, pTheme, pMatrix); - DrawHeadBK(pGraphics, pTheme, pMatrix); - DrawLButton(pGraphics, pTheme, pMatrix); - DrawRButton(pGraphics, pTheme, pMatrix); - DrawSeperator(pGraphics, pTheme, pMatrix); - DrawDatesInBK(pGraphics, pTheme, pMatrix); - DrawDatesInCircle(pGraphics, pTheme, pMatrix); - DrawCaption(pGraphics, pTheme, pMatrix); - DrawWeek(pGraphics, pTheme, pMatrix); - DrawDatesIn(pGraphics, pTheme, pMatrix); - DrawDatesOut(pGraphics, pTheme, pMatrix); - DrawToday(pGraphics, pTheme, pMatrix); - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) { - DrawWeekNumberSep(pGraphics, pTheme, pMatrix); - DrawWeekNumber(pGraphics, pTheme, pMatrix); - } -} - -void IFWL_MonthCalendar::SetSelect(int32_t iYear, - int32_t iMonth, - int32_t iDay) { - ChangeToMonth(iYear, iMonth); - AddSelDay(iDay); -} - -void IFWL_MonthCalendar::DrawBackground(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::Background; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_rtPart = m_rtClient; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶ms); -} - -void IFWL_MonthCalendar::DrawHeadBK(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::Header; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_rtPart = m_rtHead; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶ms); -} - -void IFWL_MonthCalendar::DrawLButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::LBtn; - params.m_pGraphics = pGraphics; - params.m_dwStates = m_iLBtnPartStates; - params.m_rtPart = m_rtLBtn; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶ms); -} - -void IFWL_MonthCalendar::DrawRButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::RBtn; - params.m_pGraphics = pGraphics; - params.m_dwStates = m_iRBtnPartStates; - params.m_rtPart = m_rtRBtn; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶ms); -} - -void IFWL_MonthCalendar::DrawCaption(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeText textParam; - textParam.m_pWidget = this; - textParam.m_iPart = CFWL_Part::Caption; - textParam.m_dwStates = CFWL_PartState_Normal; - textParam.m_pGraphics = pGraphics; - int32_t iYear; - int32_t iMonth; - iYear = m_iCurYear; - iMonth = m_iCurMonth; - CFX_WideString wsCation; - GetHeadText(iYear, iMonth, wsCation); - textParam.m_wsText = wsCation; - m_szHead = CalcTextSize(textParam.m_wsText, m_pProperties->m_pThemeProvider); - CalcHeadSize(); - textParam.m_rtPart = m_rtHeadText; - textParam.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; - textParam.m_iTTOAlign = FDE_TTOALIGNMENT_Center; - if (pMatrix) - textParam.m_matrix.Concat(*pMatrix); - pTheme->DrawText(&textParam); -} - -void IFWL_MonthCalendar::DrawSeperator(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::HSeparator; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_rtPart = m_rtHSep; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶ms); -} - -void IFWL_MonthCalendar::DrawDatesInBK(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::DateInBK; - params.m_pGraphics = pGraphics; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - - int32_t iCount = m_arrDates.GetSize(); - for (int32_t j = 0; j < iCount; j++) { - DATEINFO* pDataInfo = m_arrDates.GetAt(j); - if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Selected) { - params.m_dwStates |= CFWL_PartState_Selected; - if (((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) == - 0) && - pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) { - params.m_dwStates |= CFWL_PartState_Flagged; - } - if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Focused) - params.m_dwStates |= CFWL_PartState_Focused; - } else if (j == m_iHovered - 1) { - params.m_dwStates |= CFWL_PartState_Hovered; - } else if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) { - params.m_dwStates = CFWL_PartState_Flagged; - pTheme->DrawBackground(¶ms); - } - params.m_rtPart = pDataInfo->rect; - pTheme->DrawBackground(¶ms); - params.m_dwStates = 0; - } -} - -void IFWL_MonthCalendar::DrawWeek(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeText params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::Week; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; - CFX_RectF rtDayOfWeek; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - - for (int32_t i = 0; i < 7; i++) { - rtDayOfWeek.Set(m_rtWeek.left + i * (m_szCell.x + MONTHCAL_HMARGIN * 2), - m_rtWeek.top, m_szCell.x, m_szCell.y); - params.m_rtPart = rtDayOfWeek; - params.m_wsText = *GetCapacityForDay(pTheme, params, i); - params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; - pTheme->DrawText(¶ms); - } -} - -void IFWL_MonthCalendar::DrawWeekNumber(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeText params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::WeekNum; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; - CFX_WideString wsWeekNum; - params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; - params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - - int32_t iMonthNum = m_pDateTime->GetMonth(); - int32_t iDayNum = FX_DaysInMonth(m_iCurYear, iMonthNum); - int32_t iTemp = 0; - FX_FLOAT fVStartPos = m_rtClient.top + m_fHeadHei + m_fHSepHei; - FX_FLOAT fHStartPos = m_rtClient.left; - for (int32_t i = 1; i <= iDayNum; i += 7) { - iTemp++; - m_rtWeekNum.Set(fHStartPos, fVStartPos + m_fDateCellHei * iTemp, - m_fWeekNumWid, m_fDateCellHei); - wsWeekNum.Format(L"0"); - params.m_wsText = wsWeekNum; - params.m_rtPart = m_rtWeekNum; - pTheme->DrawText(¶ms); - } -} - -void IFWL_MonthCalendar::DrawWeekNumberSep(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::WeekNumSep; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_rtPart = m_rtWeekNumSep; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶ms); -} - -void IFWL_MonthCalendar::DrawToday(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) - return; - - CFWL_ThemeText params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::Today; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; - - CFX_WideString* wsDay = static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Today)); - CFX_WideString wsText; - GetTodayText(m_iYear, m_iMonth, m_iDay, wsText); - params.m_wsText = *wsDay + wsText; - - m_szToday = CalcTextSize(params.m_wsText, m_pProperties->m_pThemeProvider); - CalcTodaySize(); - params.m_rtPart = m_rtToday; - params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawText(¶ms); -} - -void IFWL_MonthCalendar::DrawDatesIn(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeText params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::DatesIn; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - - int32_t iCount = m_arrDates.GetSize(); - for (int32_t j = 0; j < iCount; j++) { - DATEINFO* pDataInfo = m_arrDates.GetAt(j); - params.m_wsText = pDataInfo->wsDay; - params.m_rtPart = pDataInfo->rect; - params.m_dwStates = pDataInfo->dwStates; - if (j + 1 == m_iHovered) - params.m_dwStates |= CFWL_PartState_Hovered; - params.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; - pTheme->DrawText(¶ms); - } -} - -void IFWL_MonthCalendar::DrawDatesOut(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeText params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::DatesOut; - params.m_pGraphics = pGraphics; - params.m_dwStates = CFWL_PartState_Normal; - params.m_iTTOAlign = FDE_TTOALIGNMENT_Center; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawText(¶ms); -} - -void IFWL_MonthCalendar::DrawDatesInCircle(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoTodayCircle) - return; - if (m_iMonth != m_iCurMonth || m_iYear != m_iCurYear) - return; - if (m_iDay < 1 || m_iDay > m_arrDates.GetSize()) - return; - - DATEINFO* pDate = m_arrDates[m_iDay - 1]; - if (!pDate) - return; - - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::DateInCircle; - params.m_pGraphics = pGraphics; - params.m_rtPart = pDate->rect; - params.m_dwStates = CFWL_PartState_Normal; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶ms); -} - -CFX_SizeF IFWL_MonthCalendar::CalcSize(bool bAutoSize) { - if (!m_pProperties->m_pThemeProvider) - return CFX_SizeF(); - if (!bAutoSize) { - GetClientRect(m_rtClient); - return CFX_SizeF(m_rtClient.width, m_rtClient.height); - } - - CFX_SizeF fs; - CFWL_ThemePart params; - params.m_pWidget = this; - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - FX_FLOAT fMaxWeekW = 0.0f; - FX_FLOAT fMaxWeekH = 0.0f; - - for (uint32_t i = 0; i < 7; ++i) { - CFX_SizeF sz = CalcTextSize(*GetCapacityForDay(pTheme, params, i), - m_pProperties->m_pThemeProvider); - fMaxWeekW = (fMaxWeekW >= sz.x) ? fMaxWeekW : sz.x; - fMaxWeekH = (fMaxWeekH >= sz.y) ? fMaxWeekH : sz.y; - } - - FX_FLOAT fDayMaxW = 0.0f; - FX_FLOAT fDayMaxH = 0.0f; - for (int day = 10; day <= 31; day++) { - CFX_WideString wsDay; - wsDay.Format(L"%d", day); - CFX_SizeF sz = CalcTextSize(wsDay, m_pProperties->m_pThemeProvider); - fDayMaxW = (fDayMaxW >= sz.x) ? fDayMaxW : sz.x; - fDayMaxH = (fDayMaxH >= sz.y) ? fDayMaxH : sz.y; - } - m_szCell.x = FX_FLOAT((fMaxWeekW >= fDayMaxW) ? (int)(fMaxWeekW + 0.5) - : (int)(fDayMaxW + 0.5)); - m_szCell.y = (fMaxWeekH >= fDayMaxH) ? fMaxWeekH : fDayMaxH; - fs.x = m_szCell.x * MONTHCAL_COLUMNS + - MONTHCAL_HMARGIN * MONTHCAL_COLUMNS * 2 + - MONTHCAL_HEADER_BTN_HMARGIN * 2; - FX_FLOAT fMonthMaxW = 0.0f; - FX_FLOAT fMonthMaxH = 0.0f; - - for (uint32_t i = 0; i < 12; ++i) { - CFX_SizeF sz = CalcTextSize(*GetCapacityForMonth(pTheme, params, i), - m_pProperties->m_pThemeProvider); - fMonthMaxW = (fMonthMaxW >= sz.x) ? fMonthMaxW : sz.x; - fMonthMaxH = (fMonthMaxH >= sz.y) ? fMonthMaxH : sz.y; - } - - CFX_WideString wsYear; - GetHeadText(m_iYear, m_iMonth, wsYear); - - CFX_SizeF szYear = CalcTextSize(wsYear, m_pProperties->m_pThemeProvider); - fMonthMaxH = std::max(fMonthMaxH, szYear.y); - m_szHead = CFX_SizeF(fMonthMaxW + szYear.x, fMonthMaxH); - fMonthMaxW = m_szHead.x + MONTHCAL_HEADER_BTN_HMARGIN * 2 + m_szCell.x * 2; - fs.x = std::max(fs.x, fMonthMaxW); - - CFX_WideString wsToday; - GetTodayText(m_iYear, m_iMonth, m_iDay, wsToday); - CFX_WideString* wsText = static_cast( - pTheme->GetCapacity(¶ms, CFWL_WidgetCapacity::Today)); - m_wsToday = *wsText + wsToday; - m_szToday = CalcTextSize(wsToday, m_pProperties->m_pThemeProvider); - m_szToday.y = (m_szToday.y >= m_szCell.y) ? m_szToday.y : m_szCell.y; - fs.y = m_szCell.x + m_szCell.y * (MONTHCAL_ROWS - 2) + m_szToday.y + - MONTHCAL_VMARGIN * MONTHCAL_ROWS * 2 + MONTHCAL_HEADER_BTN_VMARGIN * 4; - return fs; -} - -void IFWL_MonthCalendar::CalcHeadSize() { - FX_FLOAT fHeadHMargin = (m_rtClient.width - m_szHead.x) / 2; - FX_FLOAT fHeadVMargin = (m_szCell.x - m_szHead.y) / 2; - m_rtHeadText.Set(m_rtClient.left + fHeadHMargin, - m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN + - MONTHCAL_VMARGIN + fHeadVMargin, - m_szHead.x, m_szHead.y); -} - -void IFWL_MonthCalendar::CalcTodaySize() { - m_rtTodayFlag.Set( - m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN, - m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN, - m_szCell.x, m_szToday.y); - m_rtToday.Set( - m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + m_szCell.x + - MONTHCAL_HMARGIN * 2, - m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN, - m_szToday.x, m_szToday.y); -} - -void IFWL_MonthCalendar::Layout() { - GetClientRect(m_rtClient); - - m_rtHead.Set( - m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, m_rtClient.top, - m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, - m_szCell.x + (MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN) * 2); - m_rtWeek.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, m_rtHead.bottom(), - m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, - m_szCell.y + MONTHCAL_VMARGIN * 2); - m_rtLBtn.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, - m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN, m_szCell.x, - m_szCell.x); - m_rtRBtn.Set(m_rtClient.left + m_rtClient.width - - MONTHCAL_HEADER_BTN_HMARGIN - m_szCell.x, - m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN, m_szCell.x, - m_szCell.x); - m_rtHSep.Set( - m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN, - m_rtWeek.bottom() - MONTHCAL_VMARGIN, - m_rtClient.width - (MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN) * 2, - MONTHCAL_HSEP_HEIGHT); - m_rtDates.Set(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, - m_rtWeek.bottom(), - m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2, - m_szCell.y * (MONTHCAL_ROWS - 3) + - MONTHCAL_VMARGIN * (MONTHCAL_ROWS - 3) * 2); - - CalDateItem(); -} - -void IFWL_MonthCalendar::CalDateItem() { - bool bNewWeek = false; - int32_t iWeekOfMonth = 0; - FX_FLOAT fLeft = m_rtDates.left; - FX_FLOAT fTop = m_rtDates.top; - int32_t iCount = m_arrDates.GetSize(); - for (int32_t i = 0; i < iCount; i++) { - DATEINFO* pDateInfo = m_arrDates.GetAt(i); - if (bNewWeek) { - iWeekOfMonth++; - bNewWeek = false; - } - pDateInfo->rect.Set( - fLeft + pDateInfo->iDayOfWeek * (m_szCell.x + (MONTHCAL_HMARGIN * 2)), - fTop + iWeekOfMonth * (m_szCell.y + (MONTHCAL_VMARGIN * 2)), - m_szCell.x + (MONTHCAL_HMARGIN * 2), - m_szCell.y + (MONTHCAL_VMARGIN * 2)); - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) - pDateInfo->rect.Offset(m_fWeekNumWid, 0); - if (pDateInfo->iDayOfWeek >= 6) - bNewWeek = true; - } -} - -void IFWL_MonthCalendar::GetCapValue() { - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - CFWL_ThemePart part; - part.m_pWidget = this; - m_fHeadWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderWidth)); - m_fHeadHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderHeight)); - m_fHeadBtnWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnWidth)); - m_fHeadBtnHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnHeight)); - m_fHeadBtnHMargin = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnHMargin)); - m_fHeadBtnVMargin = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderBtnVMargin)); - m_fHeadTextWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextWidth)); - m_fHeadTextHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextHeight)); - m_fHeadTextHMargin = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextHMargin)); - m_fHeadTextVMargin = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HeaderTextVMargin)); - m_fHSepWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HSepWidth)); - m_fHSepHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::HSepHeight)); - m_fWeekNumWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekNumWidth)); - m_fSepDOffset = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepDOffset)); - m_fSepX = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepX)); - m_fSepY = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::SepY)); - m_fWeekNumHeigh = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekNumHeight)); - m_fWeekWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekWidth)); - m_fWeekHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::WeekHeight)); - m_fDateCellWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::DatesCellWidth)); - m_fDateCellHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::DatesCellHeight)); - m_fTodayWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayWidth)); - m_fTodayHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayHeight)); - m_fTodayFlagWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TodayFlagWidth)); - m_fMCWid = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Width)); - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_WeekNumbers) - m_fMCWid += m_fWeekNumWid; - - m_fMCHei = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Height)); -} - -void IFWL_MonthCalendar::InitDate() { - // TODO(dsinclair): These should pull the real today values instead of - // pretending it's 2011-01-01. - m_iYear = 2011; - m_iMonth = 1; - m_iDay = 1; - m_iCurYear = m_iYear; - m_iCurMonth = m_iMonth; - - GetTodayText(m_iYear, m_iMonth, m_iDay, m_wsToday); - GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead); - m_dtMin = DATE(1500, 12, 1); - m_dtMax = DATE(2200, 1, 1); -} - -void IFWL_MonthCalendar::ClearDateItem() { - for (int32_t i = 0; i < m_arrDates.GetSize(); i++) - delete m_arrDates.GetAt(i); - m_arrDates.RemoveAll(); -} - -void IFWL_MonthCalendar::ResetDateItem() { - m_pDateTime->Set(m_iCurYear, m_iCurMonth, 1); - int32_t iDays = FX_DaysInMonth(m_iCurYear, m_iCurMonth); - int32_t iDayOfWeek = m_pDateTime->GetDayOfWeek(); - for (int32_t i = 0; i < iDays; i++) { - if (iDayOfWeek >= 7) - iDayOfWeek = 0; - - CFX_WideString wsDay; - wsDay.Format(L"%d", i + 1); - uint32_t dwStates = 0; - if (m_iYear == m_iCurYear && m_iMonth == m_iCurMonth && m_iDay == (i + 1)) - dwStates |= FWL_ITEMSTATE_MCD_Flag; - if (m_arrSelDays.Find(i + 1) != -1) - dwStates |= FWL_ITEMSTATE_MCD_Selected; - - CFX_RectF rtDate; - rtDate.Set(0, 0, 0, 0); - m_arrDates.Add(new DATEINFO(i + 1, iDayOfWeek, dwStates, rtDate, wsDay)); - iDayOfWeek++; - } -} - -void IFWL_MonthCalendar::NextMonth() { - int32_t iYear = m_iCurYear, iMonth = m_iCurMonth; - if (iMonth >= 12) { - iMonth = 1; - iYear++; - } else { - iMonth++; - } - DATE dt(m_iCurYear, m_iCurMonth, 1); - if (!(dt < m_dtMax)) - return; - - m_iCurYear = iYear, m_iCurMonth = iMonth; - ChangeToMonth(m_iCurYear, m_iCurMonth); -} - -void IFWL_MonthCalendar::PrevMonth() { - int32_t iYear = m_iCurYear, iMonth = m_iCurMonth; - if (iMonth <= 1) { - iMonth = 12; - iYear--; - } else { - iMonth--; - } - - DATE dt(m_iCurYear, m_iCurMonth, 1); - if (!(dt > m_dtMin)) - return; - - m_iCurYear = iYear, m_iCurMonth = iMonth; - ChangeToMonth(m_iCurYear, m_iCurMonth); -} - -void IFWL_MonthCalendar::ChangeToMonth(int32_t iYear, int32_t iMonth) { - m_iCurYear = iYear; - m_iCurMonth = iMonth; - m_iHovered = -1; - - ClearDateItem(); - ResetDateItem(); - CalDateItem(); - GetHeadText(m_iCurYear, m_iCurMonth, m_wsHead); -} - -void IFWL_MonthCalendar::RemoveSelDay(int32_t iDay, bool bAll) { - if (iDay == -1 && !bAll) - return; - if (bAll) { - int32_t iCount = m_arrSelDays.GetSize(); - int32_t iDatesCount = m_arrDates.GetSize(); - for (int32_t i = 0; i < iCount; i++) { - int32_t iSelDay = m_arrSelDays.GetAt(i); - if (iSelDay <= iDatesCount) { - DATEINFO* pDateInfo = m_arrDates.GetAt(iSelDay - 1); - pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected; - } - } - m_arrSelDays.RemoveAll(); - return; - } - - int32_t index = m_arrSelDays.Find(iDay); - if (index == -1) - return; - - int32_t iSelDay = m_arrSelDays.GetAt(iDay); - int32_t iDatesCount = m_arrDates.GetSize(); - if (iSelDay <= iDatesCount) { - DATEINFO* pDateInfo = m_arrDates.GetAt(iSelDay - 1); - pDateInfo->dwStates &= ~FWL_ITEMSTATE_MCD_Selected; - } - m_arrSelDays.RemoveAt(index); -} - -void IFWL_MonthCalendar::AddSelDay(int32_t iDay) { - ASSERT(iDay > 0); - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) - return; - - if (m_arrSelDays.Find(iDay) != -1) - return; - - RemoveSelDay(-1, true); - if (iDay <= m_arrDates.GetSize()) { - DATEINFO* pDateInfo = m_arrDates.GetAt(iDay - 1); - pDateInfo->dwStates |= FWL_ITEMSTATE_MCD_Selected; - } - m_arrSelDays.Add(iDay); -} - -void IFWL_MonthCalendar::JumpToToday() { - if (m_iYear != m_iCurYear || m_iMonth != m_iCurMonth) { - m_iCurYear = m_iYear; - m_iCurMonth = m_iMonth; - ChangeToMonth(m_iYear, m_iMonth); - AddSelDay(m_iDay); - return; - } - - if (m_arrSelDays.Find(m_iDay) == -1) - AddSelDay(m_iDay); -} - -void IFWL_MonthCalendar::GetHeadText(int32_t iYear, - int32_t iMonth, - CFX_WideString& wsHead) { - ASSERT(iMonth > 0 && iMonth < 13); - static const FX_WCHAR* const pMonth[] = { - L"January", L"February", L"March", L"April", - L"May", L"June", L"July", L"August", - L"September", L"October", L"November", L"December"}; - wsHead.Format(L"%s, %d", pMonth[iMonth - 1], iYear); -} - -void IFWL_MonthCalendar::GetTodayText(int32_t iYear, - int32_t iMonth, - int32_t iDay, - CFX_WideString& wsToday) { - wsToday.Format(L", %d/%d/%d", iDay, iMonth, iYear); -} - -int32_t IFWL_MonthCalendar::GetDayAtPoint(FX_FLOAT x, FX_FLOAT y) { - int32_t iCount = m_arrDates.GetSize(); - for (int32_t i = 0; i < iCount; i++) { - DATEINFO* pDateInfo = m_arrDates.GetAt(i); - if (pDateInfo->rect.Contains(x, y)) - return ++i; - } - return -1; -} - -void IFWL_MonthCalendar::GetDayRect(int32_t iDay, CFX_RectF& rtDay) { - if (iDay <= 0 || iDay > m_arrDates.GetSize()) - return; - - DATEINFO* pDateInfo = m_arrDates[iDay - 1]; - if (!pDateInfo) - return; - rtDay = pDateInfo->rect; -} - -void IFWL_MonthCalendar::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - CFWL_MessageType dwMsgCode = pMessage->GetClassID(); - switch (dwMsgCode) { - case CFWL_MessageType::SetFocus: - case CFWL_MessageType::KillFocus: - GetOuter()->GetDelegate()->OnProcessMessage(pMessage); - break; - case CFWL_MessageType::Key: - break; - case CFWL_MessageType::Mouse: { - CFWL_MsgMouse* pMouse = static_cast(pMessage); - switch (pMouse->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMouse); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMouse); - break; - case FWL_MouseCommand::Move: - OnMouseMove(pMouse); - break; - case FWL_MouseCommand::Leave: - OnMouseLeave(pMouse); - break; - default: - break; - } - break; - } - default: - break; - } - IFWL_Widget::OnProcessMessage(pMessage); -} - -void IFWL_MonthCalendar::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -void IFWL_MonthCalendar::OnLButtonDown(CFWL_MsgMouse* pMsg) { - if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_iLBtnPartStates = CFWL_PartState_Pressed; - PrevMonth(); - Repaint(&m_rtClient); - } else if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_iRBtnPartStates |= CFWL_PartState_Pressed; - NextMonth(); - Repaint(&m_rtClient); - } else if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) { - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_NoToday) == 0) { - JumpToToday(); - Repaint(&m_rtClient); - } - } else { - IFWL_DateTimePicker* pIPicker = static_cast(m_pOuter); - if (pIPicker->IsMonthCalendarVisible()) - m_bFlag = 1; - } -} - -void IFWL_MonthCalendar::OnLButtonUp(CFWL_MsgMouse* pMsg) { - if (m_pWidgetMgr->IsFormDisabled()) - return DisForm_OnLButtonUp(pMsg); - - if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_iLBtnPartStates = 0; - Repaint(&m_rtLBtn); - return; - } - if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_iRBtnPartStates = 0; - Repaint(&m_rtRBtn); - return; - } - if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) - return; - - int32_t iOldSel = 0; - if (m_arrSelDays.GetSize() > 0) - iOldSel = m_arrSelDays[0]; - - int32_t iCurSel = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); - CFX_RectF rt; - IFWL_DateTimePicker* pIPicker = static_cast(m_pOuter); - pIPicker->GetFormProxy()->GetWidgetRect(rt); - rt.Set(0, 0, rt.width, rt.height); - if (iCurSel > 0) { - DATEINFO* lpDatesInfo = m_arrDates.GetAt(iCurSel - 1); - CFX_RectF rtInvalidate(lpDatesInfo->rect); - if (iOldSel > 0 && iOldSel <= m_arrDates.GetSize()) { - lpDatesInfo = m_arrDates.GetAt(iOldSel - 1); - rtInvalidate.Union(lpDatesInfo->rect); - } - AddSelDay(iCurSel); - if (!m_pOuter) - return; - - pIPicker->ProcessSelChanged(m_iCurYear, m_iCurMonth, iCurSel); - pIPicker->ShowMonthCalendar(false); - } else if (m_bFlag && (!rt.Contains(pMsg->m_fx, pMsg->m_fy))) { - pIPicker->ShowMonthCalendar(false); - } - m_bFlag = 0; -} - -void IFWL_MonthCalendar::DisForm_OnLButtonUp(CFWL_MsgMouse* pMsg) { - if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_iLBtnPartStates = 0; - Repaint(&(m_rtLBtn)); - return; - } - if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { - m_iRBtnPartStates = 0; - Repaint(&(m_rtRBtn)); - return; - } - if (m_rtToday.Contains(pMsg->m_fx, pMsg->m_fy)) - return; - - int32_t iOldSel = 0; - if (m_arrSelDays.GetSize() > 0) - iOldSel = m_arrSelDays[0]; - - int32_t iCurSel = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); - if (iCurSel > 0) { - DATEINFO* lpDatesInfo = m_arrDates.GetAt(iCurSel - 1); - CFX_RectF rtInvalidate(lpDatesInfo->rect); - if (iOldSel > 0 && iOldSel <= m_arrDates.GetSize()) { - lpDatesInfo = m_arrDates.GetAt(iOldSel - 1); - rtInvalidate.Union(lpDatesInfo->rect); - } - AddSelDay(iCurSel); - IFWL_DateTimePicker* pDateTime = - static_cast(m_pOuter); - pDateTime->ProcessSelChanged(m_iCurYear, m_iCurMonth, iCurSel); - pDateTime->ShowMonthCalendar(false); - } -} - -void IFWL_MonthCalendar::OnMouseMove(CFWL_MsgMouse* pMsg) { - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect) - return; - - bool bRepaint = false; - CFX_RectF rtInvalidate; - rtInvalidate.Set(0, 0, 0, 0); - if (m_rtDates.Contains(pMsg->m_fx, pMsg->m_fy)) { - int32_t iHover = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); - bRepaint = m_iHovered != iHover; - if (bRepaint) { - if (m_iHovered > 0) - GetDayRect(m_iHovered, rtInvalidate); - if (iHover > 0) { - CFX_RectF rtDay; - GetDayRect(iHover, rtDay); - if (rtInvalidate.IsEmpty()) - rtInvalidate = rtDay; - else - rtInvalidate.Union(rtDay); - } - } - m_iHovered = iHover; - } else { - bRepaint = m_iHovered > 0; - if (bRepaint) - GetDayRect(m_iHovered, rtInvalidate); - - m_iHovered = -1; - } - if (bRepaint && !rtInvalidate.IsEmpty()) - Repaint(&rtInvalidate); -} - -void IFWL_MonthCalendar::OnMouseLeave(CFWL_MsgMouse* pMsg) { - if (m_iHovered <= 0) - return; - - CFX_RectF rtInvalidate; - rtInvalidate.Set(0, 0, 0, 0); - GetDayRect(m_iHovered, rtInvalidate); - m_iHovered = -1; - if (!rtInvalidate.IsEmpty()) - Repaint(&rtInvalidate); -} - -IFWL_MonthCalendar::DATEINFO::DATEINFO(int32_t day, - int32_t dayofweek, - uint32_t dwSt, - CFX_RectF rc, - CFX_WideString& wsday) - : iDay(day), - iDayOfWeek(dayofweek), - dwStates(dwSt), - rect(rc), - wsDay(wsday) {} - -IFWL_MonthCalendar::DATEINFO::~DATEINFO() {} diff --git a/xfa/fwl/core/ifwl_monthcalendar.h b/xfa/fwl/core/ifwl_monthcalendar.h deleted file mode 100644 index 758ce5c730..0000000000 --- a/xfa/fwl/core/ifwl_monthcalendar.h +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_IFWL_MONTHCALENDAR_H_ -#define XFA_FWL_CORE_IFWL_MONTHCALENDAR_H_ - -#include - -#include "xfa/fgas/localization/fgas_datetime.h" -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" -#include "xfa/fwl/core/ifwl_widget.h" - -#define FWL_STYLEEXT_MCD_MultiSelect (1L << 0) -#define FWL_STYLEEXT_MCD_NoToday (1L << 1) -#define FWL_STYLEEXT_MCD_NoTodayCircle (1L << 2) -#define FWL_STYLEEXT_MCD_WeekNumbers (1L << 3) -#define FWL_ITEMSTATE_MCD_Nomal (0L << 0) -#define FWL_ITEMSTATE_MCD_Flag (1L << 0) -#define FWL_ITEMSTATE_MCD_Selected (1L << 1) -#define FWL_ITEMSTATE_MCD_Focused (1L << 2) - -class CFWL_MsgMouse; -class IFWL_Widget; - -class IFWL_MonthCalendar : public IFWL_Widget { - public: - IFWL_MonthCalendar(const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter); - ~IFWL_MonthCalendar() override; - - // FWL_WidgetImp - FWL_Type GetClassID() const override; - void GetWidgetRect(CFX_RectF& rect, bool bAutoSize = false) override; - void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - void SetSelect(int32_t iYear, int32_t iMonth, int32_t iDay); - - private: - struct DATE { - DATE() : iYear(0), iMonth(0), iDay(0) {} - - DATE(int32_t year, int32_t month, int32_t day) - : iYear(year), iMonth(month), iDay(day) {} - - bool operator<(const DATE& right) { - if (iYear < right.iYear) - return true; - if (iYear == right.iYear) { - if (iMonth < right.iMonth) - return true; - if (iMonth == right.iMonth) - return iDay < right.iDay; - } - return false; - } - - bool operator>(const DATE& right) { - if (iYear > right.iYear) - return true; - if (iYear == right.iYear) { - if (iMonth > right.iMonth) - return true; - if (iMonth == right.iMonth) - return iDay > right.iDay; - } - return false; - } - - int32_t iYear; - int32_t iMonth; - int32_t iDay; - }; - struct DATEINFO { - DATEINFO(int32_t day, - int32_t dayofweek, - uint32_t dwSt, - CFX_RectF rc, - CFX_WideString& wsday); - ~DATEINFO(); - - int32_t iDay; - int32_t iDayOfWeek; - uint32_t dwStates; - CFX_RectF rect; - CFX_WideString wsDay; - }; - - void DrawBackground(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawHeadBK(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawLButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawRButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawCaption(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawSeperator(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawDatesInBK(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawWeek(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawWeekNumber(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawWeekNumberSep(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawToday(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawDatesIn(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawDatesOut(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawDatesInCircle(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - CFX_SizeF CalcSize(bool bAutoSize = false); - void Layout(); - void CalcHeadSize(); - void CalcTodaySize(); - void CalDateItem(); - void GetCapValue(); - void InitDate(); - void ClearDateItem(); - void ResetDateItem(); - void NextMonth(); - void PrevMonth(); - void ChangeToMonth(int32_t iYear, int32_t iMonth); - void RemoveSelDay(int32_t iDay, bool bAll = false); - void AddSelDay(int32_t iDay); - void JumpToToday(); - void GetHeadText(int32_t iYear, int32_t iMonth, CFX_WideString& wsHead); - void GetTodayText(int32_t iYear, - int32_t iMonth, - int32_t iDay, - CFX_WideString& wsToday); - int32_t GetDayAtPoint(FX_FLOAT x, FX_FLOAT y); - void GetDayRect(int32_t iDay, CFX_RectF& rtDay); - void OnLButtonDown(CFWL_MsgMouse* pMsg); - void OnLButtonUp(CFWL_MsgMouse* pMsg); - void DisForm_OnLButtonUp(CFWL_MsgMouse* pMsg); - void OnMouseMove(CFWL_MsgMouse* pMsg); - void OnMouseLeave(CFWL_MsgMouse* pMsg); - - bool m_bInitialized; - CFX_RectF m_rtHead; - CFX_RectF m_rtWeek; - CFX_RectF m_rtLBtn; - CFX_RectF m_rtRBtn; - CFX_RectF m_rtDates; - CFX_RectF m_rtHSep; - CFX_RectF m_rtHeadText; - CFX_RectF m_rtToday; - CFX_RectF m_rtTodayFlag; - CFX_RectF m_rtWeekNum; - CFX_RectF m_rtWeekNumSep; - CFX_WideString m_wsHead; - CFX_WideString m_wsToday; - std::unique_ptr m_pDateTime; - CFX_ArrayTemplate m_arrDates; - int32_t m_iCurYear; - int32_t m_iCurMonth; - int32_t m_iYear; - int32_t m_iMonth; - int32_t m_iDay; - int32_t m_iHovered; - int32_t m_iLBtnPartStates; - int32_t m_iRBtnPartStates; - DATE m_dtMin; - DATE m_dtMax; - CFX_SizeF m_szHead; - CFX_SizeF m_szCell; - CFX_SizeF m_szToday; - CFX_ArrayTemplate m_arrSelDays; - CFX_RectF m_rtClient; - FX_FLOAT m_fHeadWid; - FX_FLOAT m_fHeadHei; - FX_FLOAT m_fHeadBtnWid; - FX_FLOAT m_fHeadBtnHei; - FX_FLOAT m_fHeadBtnHMargin; - FX_FLOAT m_fHeadBtnVMargin; - FX_FLOAT m_fHeadTextWid; - FX_FLOAT m_fHeadTextHei; - FX_FLOAT m_fHeadTextHMargin; - FX_FLOAT m_fHeadTextVMargin; - FX_FLOAT m_fHSepWid; - FX_FLOAT m_fHSepHei; - FX_FLOAT m_fWeekNumWid; - FX_FLOAT m_fSepDOffset; - FX_FLOAT m_fSepX; - FX_FLOAT m_fSepY; - FX_FLOAT m_fWeekNumHeigh; - FX_FLOAT m_fWeekWid; - FX_FLOAT m_fWeekHei; - FX_FLOAT m_fDateCellWid; - FX_FLOAT m_fDateCellHei; - FX_FLOAT m_fTodayWid; - FX_FLOAT m_fTodayHei; - FX_FLOAT m_fTodayFlagWid; - FX_FLOAT m_fMCWid; - FX_FLOAT m_fMCHei; - bool m_bFlag; -}; - -#endif // XFA_FWL_CORE_IFWL_MONTHCALENDAR_H_ diff --git a/xfa/fwl/core/ifwl_scrollbar.cpp b/xfa/fwl/core/ifwl_scrollbar.cpp deleted file mode 100644 index c1feeb847b..0000000000 --- a/xfa/fwl/core/ifwl_scrollbar.cpp +++ /dev/null @@ -1,563 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/ifwl_scrollbar.h" - -#include -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_msgmousewheel.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_themepart.h" -#include "xfa/fwl/core/cfwl_timerinfo.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" - -#define FWL_SCROLLBAR_Elapse 500 -#define FWL_SCROLLBAR_MinThumb 5 - -IFWL_ScrollBar::IFWL_ScrollBar( - const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter) - : IFWL_Widget(app, std::move(properties), pOuter), - m_pTimerInfo(nullptr), - m_fRangeMin(0), - m_fRangeMax(-1), - m_fPageSize(0), - m_fStepSize(0), - m_fPos(0), - m_fTrackPos(0), - m_iMinButtonState(CFWL_PartState_Normal), - m_iMaxButtonState(CFWL_PartState_Normal), - m_iThumbButtonState(CFWL_PartState_Normal), - m_iMinTrackState(CFWL_PartState_Normal), - m_iMaxTrackState(CFWL_PartState_Normal), - m_fLastTrackPos(0), - m_cpTrackPointX(0), - m_cpTrackPointY(0), - m_iMouseWheel(0), - m_bMouseDown(false), - m_fButtonLen(0), - m_bMinSize(false), - m_fMinThumb(FWL_SCROLLBAR_MinThumb), - m_Timer(this) { - m_rtClient.Reset(); - m_rtThumb.Reset(); - m_rtMinBtn.Reset(); - m_rtMaxBtn.Reset(); - m_rtMinTrack.Reset(); - m_rtMaxTrack.Reset(); -} - -IFWL_ScrollBar::~IFWL_ScrollBar() {} - -FWL_Type IFWL_ScrollBar::GetClassID() const { - return FWL_Type::ScrollBar; -} - -void IFWL_ScrollBar::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { - if (!bAutoSize) { - rect = m_pProperties->m_rtWidget; - return; - } - - rect.Set(0, 0, 0, 0); - FX_FLOAT* pfMinWidth = static_cast( - GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); - if (!pfMinWidth) - return; - if (IsVertical()) - rect.Set(0, 0, (*pfMinWidth), (*pfMinWidth) * 3); - else - rect.Set(0, 0, (*pfMinWidth) * 3, (*pfMinWidth)); - IFWL_Widget::GetWidgetRect(rect, true); -} - -void IFWL_ScrollBar::Update() { - if (IsLocked()) - return; - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - Layout(); -} - -void IFWL_ScrollBar::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - return; - - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - if (HasBorder()) - DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); - if (HasEdge()) - DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); - DrawTrack(pGraphics, pTheme, true, pMatrix); - DrawTrack(pGraphics, pTheme, false, pMatrix); - DrawArrowBtn(pGraphics, pTheme, true, pMatrix); - DrawArrowBtn(pGraphics, pTheme, false, pMatrix); - DrawThumb(pGraphics, pTheme, pMatrix); -} - -void IFWL_ScrollBar::SetTrackPos(FX_FLOAT fTrackPos) { - m_fTrackPos = fTrackPos; - CalcThumbButtonRect(m_rtThumb); - CalcMinTrackRect(m_rtMinTrack); - CalcMaxTrackRect(m_rtMaxTrack); -} - -bool IFWL_ScrollBar::DoScroll(FWL_SCBCODE dwCode, FX_FLOAT fPos) { - if (dwCode == FWL_SCBCODE::None) - return false; - return OnScroll(dwCode, fPos); -} - -void IFWL_ScrollBar::DrawTrack(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - bool bLower, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = bLower ? CFWL_Part::LowerTrack : CFWL_Part::UpperTrack; - param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) - ? CFWL_PartState_Disabled - : (bLower ? m_iMinTrackState : m_iMaxTrackState); - param.m_pGraphics = pGraphics; - param.m_matrix.Concat(*pMatrix); - param.m_rtPart = bLower ? m_rtMinTrack : m_rtMaxTrack; - pTheme->DrawBackground(¶m); -} - -void IFWL_ScrollBar::DrawArrowBtn(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - bool bMinBtn, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = bMinBtn ? CFWL_Part::ForeArrow : CFWL_Part::BackArrow; - param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) - ? CFWL_PartState_Disabled - : (bMinBtn ? m_iMinButtonState : m_iMaxButtonState); - param.m_pGraphics = pGraphics; - param.m_matrix.Concat(*pMatrix); - param.m_rtPart = bMinBtn ? m_rtMinBtn : m_rtMaxBtn; - if (param.m_rtPart.height > 0 && param.m_rtPart.width > 0) - pTheme->DrawBackground(¶m); -} - -void IFWL_ScrollBar::DrawThumb(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::Thumb; - param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) - ? CFWL_PartState_Disabled - : m_iThumbButtonState; - param.m_pGraphics = pGraphics; - param.m_matrix.Concat(*pMatrix); - param.m_rtPart = m_rtThumb; - pTheme->DrawBackground(¶m); -} - -void IFWL_ScrollBar::Layout() { - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - CFWL_ThemePart part; - part.m_pWidget = this; - m_fMinThumb = *static_cast( - pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Size)); - GetClientRect(m_rtClient); - CalcButtonLen(); - CalcMinButtonRect(m_rtMinBtn); - CalcMaxButtonRect(m_rtMaxBtn); - CalcThumbButtonRect(m_rtThumb); - CalcMinTrackRect(m_rtMinTrack); - CalcMaxTrackRect(m_rtMaxTrack); -} - -void IFWL_ScrollBar::CalcButtonLen() { - m_fButtonLen = IsVertical() ? m_rtClient.width : m_rtClient.height; - FX_FLOAT fLength = IsVertical() ? m_rtClient.height : m_rtClient.width; - if (fLength < m_fButtonLen * 2) { - m_fButtonLen = fLength / 2; - m_bMinSize = true; - } else { - m_bMinSize = false; - } -} - -void IFWL_ScrollBar::CalcMinButtonRect(CFX_RectF& rect) { - rect.left = m_rtClient.left; - rect.top = m_rtClient.top; - rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen; - rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height; -} - -void IFWL_ScrollBar::CalcMaxButtonRect(CFX_RectF& rect) { - rect.left = - IsVertical() ? m_rtClient.left : m_rtClient.right() - m_fButtonLen; - rect.top = IsVertical() ? m_rtClient.bottom() - m_fButtonLen : m_rtClient.top; - rect.width = IsVertical() ? m_rtClient.width : m_fButtonLen; - rect.height = IsVertical() ? m_fButtonLen : m_rtClient.height; -} - -void IFWL_ScrollBar::CalcThumbButtonRect(CFX_RectF& rect) { - if (!IsEnabled()) { - m_rtThumb.Reset(); - return; - } - if (m_bMinSize) { - m_rtThumb.Empty(); - return; - } - - FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; - memset(&rect, 0, sizeof(CFX_Rect)); - if (fRange < 0) { - if (IsVertical()) - rect.Set(m_rtClient.left, m_rtMaxBtn.bottom(), m_rtClient.width, 0); - else - rect.Set(m_rtMaxBtn.right(), m_rtClient.top, 0, m_rtClient.height); - return; - } - - CFX_RectF rtClient = m_rtClient; - FX_FLOAT fLength = IsVertical() ? rtClient.height : rtClient.width; - FX_FLOAT fSize = m_fButtonLen; - fLength -= fSize * 2.0f; - if (fLength < fSize) - fLength = 0.0f; - - FX_FLOAT fThumbSize = fLength * fLength / (fRange + fLength); - fThumbSize = std::max(fThumbSize, m_fMinThumb); - - FX_FLOAT fDiff = std::max(fLength - fThumbSize, 0.0f); - FX_FLOAT fTrackPos = - std::max(std::min(m_fTrackPos, m_fRangeMax), m_fRangeMin); - if (!fRange) - return; - - FX_FLOAT iPos = fSize + fDiff * (fTrackPos - m_fRangeMin) / fRange; - rect.left = rtClient.left; - if (!IsVertical()) - rect.left += iPos; - - rect.top = rtClient.top; - if (IsVertical()) - rect.top += iPos; - - rect.width = IsVertical() ? rtClient.width : fThumbSize; - rect.height = IsVertical() ? fThumbSize : rtClient.height; -} - -void IFWL_ScrollBar::CalcMinTrackRect(CFX_RectF& rect) { - if (m_bMinSize) { - rect.Empty(); - return; - } - - FX_FLOAT fBottom = m_rtThumb.bottom(); - FX_FLOAT fRight = m_rtThumb.right(); - FX_FLOAT ix = (m_rtThumb.left + fRight) / 2; - FX_FLOAT iy = (m_rtThumb.top + fBottom) / 2; - rect.left = m_rtClient.left; - rect.top = m_rtClient.top; - bool bVertical = IsVertical(); - rect.width = bVertical ? m_rtClient.width : ix; - rect.height = bVertical ? iy : m_rtClient.height; -} - -void IFWL_ScrollBar::CalcMaxTrackRect(CFX_RectF& rect) { - if (m_bMinSize) { - rect.Empty(); - return; - } - - FX_FLOAT ix = (m_rtThumb.left + m_rtThumb.right()) / 2; - FX_FLOAT iy = (m_rtThumb.top + m_rtThumb.bottom()) / 2; - bool bVertical = IsVertical(); - rect.left = bVertical ? m_rtClient.left : ix; - rect.top = bVertical ? iy : m_rtClient.top; - rect.width = bVertical ? m_rtClient.width : m_rtClient.right() - ix; - rect.height = bVertical ? m_rtClient.bottom() - iy : m_rtClient.height; -} - -FX_FLOAT IFWL_ScrollBar::GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy) { - FX_FLOAT fDiffX = fx - m_cpTrackPointX; - FX_FLOAT fDiffY = fy - m_cpTrackPointY; - FX_FLOAT fRange = m_fRangeMax - m_fRangeMin; - FX_FLOAT fPos; - - if (IsVertical()) { - fPos = fRange * fDiffY / - (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height); - } else { - fPos = fRange * fDiffX / - (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width); - } - - fPos += m_fLastTrackPos; - return std::min(std::max(fPos, m_fRangeMin), m_fRangeMax); -} - -void IFWL_ScrollBar::GetTrackRect(CFX_RectF& rect, bool bLower) { - bool bDisabled = !!(m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled); - if (bDisabled) { - rect = bLower ? m_rtMinTrack : m_rtMaxTrack; - return; - } - - FX_FLOAT fW = m_rtThumb.width / 2; - FX_FLOAT fH = m_rtThumb.height / 2; - bool bVert = IsVertical(); - if (bLower) { - if (bVert) { - FX_FLOAT fMinTrackHeight = m_rtMinTrack.height - fH - m_rtMinBtn.height; - fMinTrackHeight = (fMinTrackHeight >= 0.0f) ? fMinTrackHeight : 0.0f; - rect.Set(m_rtMinTrack.left, m_rtMinTrack.top + m_rtMinBtn.height, - m_rtMinTrack.width, fMinTrackHeight); - return; - } - - FX_FLOAT fMinTrackWidth = m_rtMinTrack.width - fW - m_rtMinBtn.width + 2; - fMinTrackWidth = (fMinTrackWidth >= 0.0f) ? fMinTrackWidth : 0.0f; - rect.Set(m_rtMinTrack.left + m_rtMinBtn.width - 1, m_rtMinTrack.top, - fMinTrackWidth, m_rtMinTrack.height); - return; - } - - if (bVert) { - FX_FLOAT fMaxTrackHeight = m_rtMaxTrack.height - fH - m_rtMaxBtn.height; - fMaxTrackHeight = (fMaxTrackHeight >= 0.0f) ? fMaxTrackHeight : 0.0f; - rect.Set(m_rtMaxTrack.left, m_rtMaxTrack.top + fH, m_rtMaxTrack.width, - fMaxTrackHeight); - return; - } - - FX_FLOAT fMaxTrackWidth = m_rtMaxTrack.width - fW - m_rtMaxBtn.width + 2; - fMaxTrackWidth = (fMaxTrackWidth >= 0.0f) ? fMaxTrackWidth : 0.0f; - rect.Set(m_rtMaxTrack.left + fW, m_rtMaxTrack.top, fMaxTrackWidth, - m_rtMaxTrack.height); -} - -bool IFWL_ScrollBar::SendEvent() { - if (m_iMinButtonState == CFWL_PartState_Pressed) { - DoScroll(FWL_SCBCODE::StepBackward, m_fTrackPos); - return false; - } - if (m_iMaxButtonState == CFWL_PartState_Pressed) { - DoScroll(FWL_SCBCODE::StepForward, m_fTrackPos); - return false; - } - if (m_iMinTrackState == CFWL_PartState_Pressed) { - DoScroll(FWL_SCBCODE::PageBackward, m_fTrackPos); - return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); - } - if (m_iMaxTrackState == CFWL_PartState_Pressed) { - DoScroll(FWL_SCBCODE::PageForward, m_fTrackPos); - return m_rtThumb.Contains(m_cpTrackPointX, m_cpTrackPointY); - } - if (m_iMouseWheel) { - FWL_SCBCODE dwCode = m_iMouseWheel < 0 ? FWL_SCBCODE::StepForward - : FWL_SCBCODE::StepBackward; - DoScroll(dwCode, m_fTrackPos); - } - return true; -} - -bool IFWL_ScrollBar::OnScroll(FWL_SCBCODE dwCode, FX_FLOAT fPos) { - bool bRet = true; - CFWL_EvtScroll ev; - ev.m_iScrollCode = dwCode; - ev.m_pSrcTarget = this; - ev.m_fPos = fPos; - ev.m_pRet = &bRet; - DispatchEvent(&ev); - return bRet; -} - -void IFWL_ScrollBar::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - CFWL_MessageType dwMsgCode = pMessage->GetClassID(); - if (dwMsgCode == CFWL_MessageType::Mouse) { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); - break; - case FWL_MouseCommand::Move: - OnMouseMove(pMsg->m_dwFlags, pMsg->m_fx, pMsg->m_fy); - break; - case FWL_MouseCommand::Leave: - OnMouseLeave(); - break; - default: - break; - } - } else if (dwMsgCode == CFWL_MessageType::MouseWheel) { - CFWL_MsgMouseWheel* pMsg = static_cast(pMessage); - OnMouseWheel(pMsg->m_fx, pMsg->m_fy, pMsg->m_dwFlags, pMsg->m_fDeltaX, - pMsg->m_fDeltaY); - } -} - -void IFWL_ScrollBar::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -void IFWL_ScrollBar::OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { - if (!IsEnabled()) - return; - - m_bMouseDown = true; - SetGrab(true); - m_cpTrackPointX = fx; - m_cpTrackPointY = fy; - m_fLastTrackPos = m_fTrackPos; - if (m_rtMinBtn.Contains(fx, fy)) - DoMouseDown(0, m_rtMinBtn, m_iMinButtonState, fx, fy); - else if (m_rtThumb.Contains(fx, fy)) - DoMouseDown(1, m_rtThumb, m_iThumbButtonState, fx, fy); - else if (m_rtMaxBtn.Contains(fx, fy)) - DoMouseDown(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); - else if (m_rtMinTrack.Contains(fx, fy)) - DoMouseDown(3, m_rtMinTrack, m_iMinTrackState, fx, fy); - else - DoMouseDown(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); - - if (!SendEvent()) - m_pTimerInfo = m_Timer.StartTimer(FWL_SCROLLBAR_Elapse, true); -} - -void IFWL_ScrollBar::OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { - m_pTimerInfo->StopTimer(); - m_bMouseDown = false; - DoMouseUp(0, m_rtMinBtn, m_iMinButtonState, fx, fy); - DoMouseUp(1, m_rtThumb, m_iThumbButtonState, fx, fy); - DoMouseUp(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); - DoMouseUp(3, m_rtMinTrack, m_iMinTrackState, fx, fy); - DoMouseUp(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); - SetGrab(false); -} - -void IFWL_ScrollBar::OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { - DoMouseMove(0, m_rtMinBtn, m_iMinButtonState, fx, fy); - DoMouseMove(1, m_rtThumb, m_iThumbButtonState, fx, fy); - DoMouseMove(2, m_rtMaxBtn, m_iMaxButtonState, fx, fy); - DoMouseMove(3, m_rtMinTrack, m_iMinTrackState, fx, fy); - DoMouseMove(4, m_rtMaxTrack, m_iMaxTrackState, fx, fy); -} - -void IFWL_ScrollBar::OnMouseLeave() { - DoMouseLeave(0, m_rtMinBtn, m_iMinButtonState); - DoMouseLeave(1, m_rtThumb, m_iThumbButtonState); - DoMouseLeave(2, m_rtMaxBtn, m_iMaxButtonState); - DoMouseLeave(3, m_rtMinTrack, m_iMinTrackState); - DoMouseLeave(4, m_rtMaxTrack, m_iMaxTrackState); -} - -void IFWL_ScrollBar::OnMouseWheel(FX_FLOAT fx, - FX_FLOAT fy, - uint32_t dwFlags, - FX_FLOAT fDeltaX, - FX_FLOAT fDeltaY) { - m_iMouseWheel = (int32_t)fDeltaX; - SendEvent(); - m_iMouseWheel = 0; -} - -void IFWL_ScrollBar::DoMouseDown(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState, - FX_FLOAT fx, - FX_FLOAT fy) { - if (!rtItem.Contains(fx, fy)) - return; - if (iState == CFWL_PartState_Pressed) - return; - - iState = CFWL_PartState_Pressed; - Repaint(&rtItem); -} - -void IFWL_ScrollBar::DoMouseUp(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState, - FX_FLOAT fx, - FX_FLOAT fy) { - int32_t iNewState = - rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered : CFWL_PartState_Normal; - if (iState == iNewState) - return; - - iState = iNewState; - Repaint(&rtItem); - OnScroll(FWL_SCBCODE::EndScroll, m_fTrackPos); -} - -void IFWL_ScrollBar::DoMouseMove(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState, - FX_FLOAT fx, - FX_FLOAT fy) { - if (!m_bMouseDown) { - int32_t iNewState = rtItem.Contains(fx, fy) ? CFWL_PartState_Hovered - : CFWL_PartState_Normal; - if (iState == iNewState) - return; - - iState = iNewState; - Repaint(&rtItem); - } else if ((2 == iItem) && (m_iThumbButtonState == CFWL_PartState_Pressed)) { - FX_FLOAT fPos = GetTrackPointPos(fx, fy); - m_fTrackPos = fPos; - OnScroll(FWL_SCBCODE::TrackPos, fPos); - } -} - -void IFWL_ScrollBar::DoMouseLeave(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState) { - if (iState == CFWL_PartState_Normal) - return; - - iState = CFWL_PartState_Normal; - Repaint(&rtItem); -} - -void IFWL_ScrollBar::DoMouseHover(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState) { - if (iState == CFWL_PartState_Hovered) - return; - - iState = CFWL_PartState_Hovered; - Repaint(&rtItem); -} - -IFWL_ScrollBar::Timer::Timer(IFWL_ScrollBar* pToolTip) : CFWL_Timer(pToolTip) {} - -void IFWL_ScrollBar::Timer::Run(CFWL_TimerInfo* pTimerInfo) { - IFWL_ScrollBar* pButton = static_cast(m_pWidget); - - if (pButton->m_pTimerInfo) - pButton->m_pTimerInfo->StopTimer(); - - if (!pButton->SendEvent()) - pButton->m_pTimerInfo = StartTimer(0, true); -} diff --git a/xfa/fwl/core/ifwl_scrollbar.h b/xfa/fwl/core/ifwl_scrollbar.h deleted file mode 100644 index a5619b79a4..0000000000 --- a/xfa/fwl/core/ifwl_scrollbar.h +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_IFWL_SCROLLBAR_H_ -#define XFA_FWL_CORE_IFWL_SCROLLBAR_H_ - -#include - -#include "core/fxcrt/fx_system.h" -#include "xfa/fwl/core/cfwl_evtscroll.h" -#include "xfa/fwl/core/cfwl_timer.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" -#include "xfa/fwl/core/ifwl_widget.h" - -class IFWL_Widget; - -#define FWL_STYLEEXT_SCB_Horz (0L << 0) -#define FWL_STYLEEXT_SCB_Vert (1L << 0) - -class IFWL_ScrollBar : public IFWL_Widget { - public: - IFWL_ScrollBar(const CFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter); - ~IFWL_ScrollBar() override; - - // IFWL_Widget - FWL_Type GetClassID() const override; - void GetWidgetRect(CFX_RectF& rect, bool bAutoSize = false) override; - void Update() override; - void DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - void GetRange(FX_FLOAT* fMin, FX_FLOAT* fMax) const { - ASSERT(fMin); - ASSERT(fMax); - *fMin = m_fRangeMin; - *fMax = m_fRangeMax; - } - void SetRange(FX_FLOAT fMin, FX_FLOAT fMax) { - m_fRangeMin = fMin; - m_fRangeMax = fMax; - } - FX_FLOAT GetPageSize() const { return m_fPageSize; } - void SetPageSize(FX_FLOAT fPageSize) { m_fPageSize = fPageSize; } - FX_FLOAT GetStepSize() const { return m_fStepSize; } - void SetStepSize(FX_FLOAT fStepSize) { m_fStepSize = fStepSize; } - FX_FLOAT GetPos() const { return m_fPos; } - void SetPos(FX_FLOAT fPos) { m_fPos = fPos; } - void SetTrackPos(FX_FLOAT fTrackPos); - - private: - class Timer : public CFWL_Timer { - public: - explicit Timer(IFWL_ScrollBar* pToolTip); - ~Timer() override {} - - void Run(CFWL_TimerInfo* pTimerInfo) override; - }; - friend class IFWL_ScrollBar::Timer; - - bool IsVertical() const { - return !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_SCB_Vert); - } - void DrawTrack(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - bool bLower = true, - const CFX_Matrix* pMatrix = nullptr); - void DrawArrowBtn(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - bool bMinBtn = true, - const CFX_Matrix* pMatrix = nullptr); - void DrawThumb(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix = nullptr); - void Layout(); - void CalcButtonLen(); - void CalcMinButtonRect(CFX_RectF& rect); - void CalcMaxButtonRect(CFX_RectF& rect); - void CalcThumbButtonRect(CFX_RectF& rect); - void CalcMinTrackRect(CFX_RectF& rect); - void CalcMaxTrackRect(CFX_RectF& rect); - FX_FLOAT GetTrackPointPos(FX_FLOAT fx, FX_FLOAT fy); - void GetTrackRect(CFX_RectF& rect, bool bLower = true); - bool SendEvent(); - bool OnScroll(FWL_SCBCODE dwCode, FX_FLOAT fPos); - void OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); - void OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); - void OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy); - void OnMouseLeave(); - void OnMouseWheel(FX_FLOAT fx, - FX_FLOAT fy, - uint32_t dwFlags, - FX_FLOAT fDeltaX, - FX_FLOAT fDeltaY); - bool DoScroll(FWL_SCBCODE dwCode, FX_FLOAT fPos = 0.0f); - void DoMouseDown(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState, - FX_FLOAT fx, - FX_FLOAT fy); - void DoMouseUp(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState, - FX_FLOAT fx, - FX_FLOAT fy); - void DoMouseMove(int32_t iItem, - const CFX_RectF& rtItem, - int32_t& iState, - FX_FLOAT fx, - FX_FLOAT fy); - void DoMouseLeave(int32_t iItem, const CFX_RectF& rtItem, int32_t& iState); - void DoMouseHover(int32_t iItem, const CFX_RectF& rtItem, int32_t& iState); - - CFWL_TimerInfo* m_pTimerInfo; - FX_FLOAT m_fRangeMin; - FX_FLOAT m_fRangeMax; - FX_FLOAT m_fPageSize; - FX_FLOAT m_fStepSize; - FX_FLOAT m_fPos; - FX_FLOAT m_fTrackPos; - int32_t m_iMinButtonState; - int32_t m_iMaxButtonState; - int32_t m_iThumbButtonState; - int32_t m_iMinTrackState; - int32_t m_iMaxTrackState; - FX_FLOAT m_fLastTrackPos; - FX_FLOAT m_cpTrackPointX; - FX_FLOAT m_cpTrackPointY; - int32_t m_iMouseWheel; - bool m_bMouseDown; - FX_FLOAT m_fButtonLen; - bool m_bMinSize; - CFX_RectF m_rtClient; - CFX_RectF m_rtThumb; - CFX_RectF m_rtMinBtn; - CFX_RectF m_rtMaxBtn; - CFX_RectF m_rtMinTrack; - CFX_RectF m_rtMaxTrack; - FX_FLOAT m_fMinThumb; - IFWL_ScrollBar::Timer m_Timer; -}; - -#endif // XFA_FWL_CORE_IFWL_SCROLLBAR_H_ diff --git a/xfa/fwl/core/ifwl_spinbutton.cpp b/xfa/fwl/core/ifwl_spinbutton.cpp deleted file mode 100644 index d4b790afe9..0000000000 --- a/xfa/fwl/core/ifwl_spinbutton.cpp +++ /dev/null @@ -1,381 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fwl/core/ifwl_spinbutton.h" - -#include -#include - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_evtclick.h" -#include "xfa/fwl/core/cfwl_msgkey.h" -#include "xfa/fwl/core/cfwl_msgmouse.h" -#include "xfa/fwl/core/cfwl_notedriver.h" -#include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/cfwl_timerinfo.h" -#include "xfa/fwl/core/cfwl_widgetproperties.h" -#include "xfa/fwl/core/ifwl_themeprovider.h" - -namespace { - -const int kMinWidth = 18; -const int kMinHeight = 32; -const int kElapseTime = 200; - -} // namespace - -IFWL_SpinButton::IFWL_SpinButton( - const CFWL_App* app, - std::unique_ptr properties) - : IFWL_Widget(app, std::move(properties), nullptr), - m_dwUpState(CFWL_PartState_Normal), - m_dwDnState(CFWL_PartState_Normal), - m_iButtonIndex(0), - m_bLButtonDwn(false), - m_pTimerInfo(nullptr), - m_Timer(this) { - m_rtClient.Reset(); - m_rtUpButton.Reset(); - m_rtDnButton.Reset(); - m_pProperties->m_dwStyleExes |= FWL_STYLEEXE_SPB_Vert; -} - -IFWL_SpinButton::~IFWL_SpinButton() {} - -FWL_Type IFWL_SpinButton::GetClassID() const { - return FWL_Type::SpinButton; -} - -void IFWL_SpinButton::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { - if (!bAutoSize) { - rect = m_pProperties->m_rtWidget; - return; - } - - rect.Set(0, 0, kMinWidth, kMinHeight); - IFWL_Widget::GetWidgetRect(rect, true); -} - -void IFWL_SpinButton::Update() { - if (IsLocked()) - return; - - GetClientRect(m_rtClient); - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXE_SPB_Vert) { - m_rtUpButton.Set(m_rtClient.top, m_rtClient.left, m_rtClient.width, - m_rtClient.height / 2); - m_rtDnButton.Set(m_rtClient.left, m_rtClient.top + m_rtClient.height / 2, - m_rtClient.width, m_rtClient.height / 2); - } else { - m_rtUpButton.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width / 2, - m_rtClient.height); - m_rtDnButton.Set(m_rtClient.left + m_rtClient.width / 2, m_rtClient.top, - m_rtClient.width / 2, m_rtClient.height); - } -} - -FWL_WidgetHit IFWL_SpinButton::HitTest(FX_FLOAT fx, FX_FLOAT fy) { - if (m_rtClient.Contains(fx, fy)) - return FWL_WidgetHit::Client; - if (HasBorder() && (m_rtClient.Contains(fx, fy))) - return FWL_WidgetHit::Border; - if (HasEdge()) { - CFX_RectF rtEdge; - GetEdgeRect(rtEdge); - if (rtEdge.Contains(fx, fy)) - return FWL_WidgetHit::Left; - } - if (m_rtUpButton.Contains(fx, fy)) - return FWL_WidgetHit::UpButton; - if (m_rtDnButton.Contains(fx, fy)) - return FWL_WidgetHit::DownButton; - return FWL_WidgetHit::Unknown; -} - -void IFWL_SpinButton::DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - if (!pGraphics) - return; - - CFX_RectF rtClip(m_rtClient); - if (pMatrix) - pMatrix->TransformRect(rtClip); - - IFWL_ThemeProvider* pTheme = GetAvailableTheme(); - if (HasBorder()) - DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); - if (HasEdge()) - DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); - - DrawUpButton(pGraphics, pTheme, pMatrix); - DrawDownButton(pGraphics, pTheme, pMatrix); -} - -void IFWL_SpinButton::EnableButton(bool bEnable, bool bUp) { - if (bUp) - m_dwUpState = bEnable ? CFWL_PartState_Normal : CFWL_PartState_Disabled; - else - m_dwDnState = bEnable ? CFWL_PartState_Normal : CFWL_PartState_Disabled; -} - -bool IFWL_SpinButton::IsButtonEnabled(bool bUp) { - if (bUp) - return (m_dwUpState != CFWL_PartState_Disabled); - return (m_dwDnState != CFWL_PartState_Disabled); -} - -void IFWL_SpinButton::DrawUpButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::UpButton; - params.m_pGraphics = pGraphics; - params.m_dwStates = m_dwUpState + 1; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - - params.m_rtPart = m_rtUpButton; - pTheme->DrawBackground(¶ms); -} - -void IFWL_SpinButton::DrawDownButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix) { - CFWL_ThemeBackground params; - params.m_pWidget = this; - params.m_iPart = CFWL_Part::DownButton; - params.m_pGraphics = pGraphics; - params.m_dwStates = m_dwDnState + 1; - if (pMatrix) - params.m_matrix.Concat(*pMatrix); - - params.m_rtPart = m_rtDnButton; - pTheme->DrawBackground(¶ms); -} - -void IFWL_SpinButton::OnProcessMessage(CFWL_Message* pMessage) { - if (!pMessage) - return; - - CFWL_MessageType dwMsgCode = pMessage->GetClassID(); - switch (dwMsgCode) { - case CFWL_MessageType::SetFocus: { - OnFocusChanged(pMessage, true); - break; - } - case CFWL_MessageType::KillFocus: { - OnFocusChanged(pMessage, false); - break; - } - case CFWL_MessageType::Mouse: { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMsg); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMsg); - break; - case FWL_MouseCommand::Move: - OnMouseMove(pMsg); - break; - case FWL_MouseCommand::Leave: - OnMouseLeave(pMsg); - break; - default: - break; - } - break; - } - case CFWL_MessageType::Key: { - CFWL_MsgKey* pKey = static_cast(pMessage); - if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) - OnKeyDown(pKey); - break; - } - default: - break; - } - IFWL_Widget::OnProcessMessage(pMessage); -} - -void IFWL_SpinButton::OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) { - DrawWidget(pGraphics, pMatrix); -} - -void IFWL_SpinButton::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { - if (bSet) - m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); - else - m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); - - Repaint(&m_rtClient); -} - -void IFWL_SpinButton::OnLButtonDown(CFWL_MsgMouse* pMsg) { - m_bLButtonDwn = true; - SetGrab(true); - SetFocus(true); - - bool bUpPress = - (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsButtonEnabled(true)); - bool bDnPress = - (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsButtonEnabled(false)); - if (!bUpPress && !bDnPress) - return; - if (bUpPress) { - m_iButtonIndex = 0; - m_dwUpState = CFWL_PartState_Pressed; - } - if (bDnPress) { - m_iButtonIndex = 1; - m_dwDnState = CFWL_PartState_Pressed; - } - - CFWL_EvtClick wmPosChanged; - wmPosChanged.m_pSrcTarget = this; - DispatchEvent(&wmPosChanged); - - Repaint(bUpPress ? &m_rtUpButton : &m_rtDnButton); - m_pTimerInfo = m_Timer.StartTimer(kElapseTime, true); -} - -void IFWL_SpinButton::OnLButtonUp(CFWL_MsgMouse* pMsg) { - if (m_pProperties->m_dwStates & CFWL_PartState_Disabled) - return; - - m_bLButtonDwn = false; - SetGrab(false); - SetFocus(false); - if (m_pTimerInfo) { - m_pTimerInfo->StopTimer(); - m_pTimerInfo = nullptr; - } - bool bRepaint = false; - CFX_RectF rtInvalidate; - if (m_dwUpState == CFWL_PartState_Pressed && IsButtonEnabled(true)) { - m_dwUpState = CFWL_PartState_Normal; - bRepaint = true; - rtInvalidate = m_rtUpButton; - } else if (m_dwDnState == CFWL_PartState_Pressed && IsButtonEnabled(false)) { - m_dwDnState = CFWL_PartState_Normal; - bRepaint = true; - rtInvalidate = m_rtDnButton; - } - if (bRepaint) - Repaint(&rtInvalidate); -} - -void IFWL_SpinButton::OnMouseMove(CFWL_MsgMouse* pMsg) { - if (m_bLButtonDwn) - return; - - bool bRepaint = false; - CFX_RectF rtInvlidate; - rtInvlidate.Reset(); - if (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy)) { - if (IsButtonEnabled(true)) { - if (m_dwUpState == CFWL_PartState_Hovered) { - m_dwUpState = CFWL_PartState_Hovered; - bRepaint = true; - rtInvlidate = m_rtUpButton; - } - if (m_dwDnState != CFWL_PartState_Normal && IsButtonEnabled(false)) { - m_dwDnState = CFWL_PartState_Normal; - if (bRepaint) - rtInvlidate.Union(m_rtDnButton); - else - rtInvlidate = m_rtDnButton; - - bRepaint = true; - } - } - if (!IsButtonEnabled(false)) - EnableButton(false, false); - - } else if (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy)) { - if (IsButtonEnabled(false)) { - if (m_dwDnState != CFWL_PartState_Hovered) { - m_dwDnState = CFWL_PartState_Hovered; - bRepaint = true; - rtInvlidate = m_rtDnButton; - } - if (m_dwUpState != CFWL_PartState_Normal && IsButtonEnabled(true)) { - m_dwUpState = CFWL_PartState_Normal; - if (bRepaint) - rtInvlidate.Union(m_rtUpButton); - else - rtInvlidate = m_rtUpButton; - bRepaint = true; - } - } - } else if (m_dwUpState != CFWL_PartState_Normal || - m_dwDnState != CFWL_PartState_Normal) { - if (m_dwUpState != CFWL_PartState_Normal) { - m_dwUpState = CFWL_PartState_Normal; - bRepaint = true; - rtInvlidate = m_rtUpButton; - } - if (m_dwDnState != CFWL_PartState_Normal) { - m_dwDnState = CFWL_PartState_Normal; - if (bRepaint) - rtInvlidate.Union(m_rtDnButton); - else - rtInvlidate = m_rtDnButton; - - bRepaint = true; - } - } - if (bRepaint) - Repaint(&rtInvlidate); -} - -void IFWL_SpinButton::OnMouseLeave(CFWL_MsgMouse* pMsg) { - if (!pMsg) - return; - if (m_dwUpState != CFWL_PartState_Normal && IsButtonEnabled(true)) - m_dwUpState = CFWL_PartState_Normal; - if (m_dwDnState != CFWL_PartState_Normal && IsButtonEnabled(false)) - m_dwDnState = CFWL_PartState_Normal; - - Repaint(&m_rtClient); -} - -void IFWL_SpinButton::OnKeyDown(CFWL_MsgKey* pMsg) { - bool bUp = - pMsg->m_dwKeyCode == FWL_VKEY_Up || pMsg->m_dwKeyCode == FWL_VKEY_Left; - bool bDown = - pMsg->m_dwKeyCode == FWL_VKEY_Down || pMsg->m_dwKeyCode == FWL_VKEY_Right; - if (!bUp && !bDown) - return; - - bool bUpEnable = IsButtonEnabled(true); - bool bDownEnable = IsButtonEnabled(false); - if (!bUpEnable && !bDownEnable) - return; - - CFWL_EvtClick wmPosChanged; - wmPosChanged.m_pSrcTarget = this; - DispatchEvent(&wmPosChanged); - - Repaint(bUpEnable ? &m_rtUpButton : &m_rtDnButton); -} - -IFWL_SpinButton::Timer::Timer(IFWL_SpinButton* pToolTip) - : CFWL_Timer(pToolTip) {} - -void IFWL_SpinButton::Timer::Run(CFWL_TimerInfo* pTimerInfo) { - IFWL_SpinButton* pButton = static_cast(m_pWidget); - - if (!pButton->m_pTimerInfo) - return; - - CFWL_EvtClick wmPosChanged; - wmPosChanged.m_pSrcTarget = pButton; - pButton->DispatchEvent(&wmPosChanged); -} diff --git a/xfa/fwl/core/ifwl_spinbutton.h b/xfa/fwl/core/ifwl_spinbutton.h deleted file mode 100644 index ab888b1b0c..0000000000 --- a/xfa/fwl/core/ifwl_spinbutton.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FWL_CORE_IFWL_SPINBUTTON_H_ -#define XFA_FWL_CORE_IFWL_SPINBUTTON_H_ - -#include - -#include "xfa/fwl/core/cfwl_event.h" -#include "xfa/fwl/core/cfwl_timer.h" -#include "xfa/fwl/core/ifwl_widget.h" -#include "xfa/fxfa/cxfa_eventparam.h" - -#define FWL_STYLEEXE_SPB_Vert (1L << 0) - -class CFWL_MsgMouse; -class CFWL_WidgetProperties; - -class IFWL_SpinButton : public IFWL_Widget { - public: - IFWL_SpinButton(const CFWL_App* app, - std::unique_ptr properties); - ~IFWL_SpinButton() override; - - // IFWL_Widget - FWL_Type GetClassID() const override; - void GetWidgetRect(CFX_RectF& rect, bool bAutoSize = false) override; - void Update() override; - FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; - void DrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix = nullptr) override; - void OnProcessMessage(CFWL_Message* pMessage) override; - void OnProcessEvent(CFWL_Event* pEvent) override; - void OnDrawWidget(CFX_Graphics* pGraphics, - const CFX_Matrix* pMatrix) override; - - private: - class Timer : public CFWL_Timer { - public: - explicit Timer(IFWL_SpinButton* pToolTip); - ~Timer() override {} - - void Run(CFWL_TimerInfo* pTimerInfo) override; - }; - friend class IFWL_SpinButton::Timer; - - void EnableButton(bool bEnable, bool bUp = true); - bool IsButtonEnabled(bool bUp = true); - void DrawUpButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void DrawDownButton(CFX_Graphics* pGraphics, - IFWL_ThemeProvider* pTheme, - const CFX_Matrix* pMatrix); - void OnFocusChanged(CFWL_Message* pMsg, bool bSet); - void OnLButtonDown(CFWL_MsgMouse* pMsg); - void OnLButtonUp(CFWL_MsgMouse* pMsg); - void OnMouseMove(CFWL_MsgMouse* pMsg); - void OnMouseLeave(CFWL_MsgMouse* pMsg); - void OnKeyDown(CFWL_MsgKey* pMsg); - - CFX_RectF m_rtClient; - CFX_RectF m_rtUpButton; - CFX_RectF m_rtDnButton; - uint32_t m_dwUpState; - uint32_t m_dwDnState; - int32_t m_iButtonIndex; - bool m_bLButtonDwn; - CFWL_TimerInfo* m_pTimerInfo; - IFWL_SpinButton::Timer m_Timer; -}; - -#endif // XFA_FWL_CORE_IFWL_SPINBUTTON_H_ diff --git a/xfa/fwl/core/ifwl_widget.cpp b/xfa/fwl/core/ifwl_widget.cpp index dca89c9c94..9a37cc89ca 100644 --- a/xfa/fwl/core/ifwl_widget.cpp +++ b/xfa/fwl/core/ifwl_widget.cpp @@ -17,6 +17,7 @@ #include "xfa/fwl/core/cfwl_evtmousewheel.h" #include "xfa/fwl/core/cfwl_evtsetfocus.h" #include "xfa/fwl/core/cfwl_evtsizechanged.h" +#include "xfa/fwl/core/cfwl_form.h" #include "xfa/fwl/core/cfwl_msgkey.h" #include "xfa/fwl/core/cfwl_msgkillfocus.h" #include "xfa/fwl/core/cfwl_msgmouse.h" @@ -28,7 +29,6 @@ #include "xfa/fwl/core/cfwl_themetext.h" #include "xfa/fwl/core/cfwl_widgetmgr.h" #include "xfa/fwl/core/ifwl_combobox.h" -#include "xfa/fwl/core/ifwl_form.h" #include "xfa/fwl/core/ifwl_themeprovider.h" #include "xfa/fxfa/xfa_ffapp.h" diff --git a/xfa/fwl/theme/cfwl_carettp.cpp b/xfa/fwl/theme/cfwl_carettp.cpp index 1297b13497..55de2a7d4f 100644 --- a/xfa/fwl/theme/cfwl_carettp.cpp +++ b/xfa/fwl/theme/cfwl_carettp.cpp @@ -6,8 +6,8 @@ #include "xfa/fwl/theme/cfwl_carettp.h" +#include "xfa/fwl/core/cfwl_caret.h" #include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/ifwl_caret.h" #include "xfa/fwl/core/ifwl_widget.h" #include "xfa/fxgraphics/cfx_color.h" #include "xfa/fxgraphics/cfx_path.h" diff --git a/xfa/fwl/theme/cfwl_monthcalendartp.cpp b/xfa/fwl/theme/cfwl_monthcalendartp.cpp index 8aff0f1690..c0f29b6665 100644 --- a/xfa/fwl/theme/cfwl_monthcalendartp.cpp +++ b/xfa/fwl/theme/cfwl_monthcalendartp.cpp @@ -7,9 +7,9 @@ #include "xfa/fwl/theme/cfwl_monthcalendartp.h" #include "xfa/fde/tto/fde_textout.h" +#include "xfa/fwl/core/cfwl_monthcalendar.h" #include "xfa/fwl/core/cfwl_themebackground.h" #include "xfa/fwl/core/cfwl_themetext.h" -#include "xfa/fwl/core/ifwl_monthcalendar.h" #include "xfa/fwl/core/ifwl_themeprovider.h" #include "xfa/fwl/core/ifwl_widget.h" #include "xfa/fxgraphics/cfx_color.h" diff --git a/xfa/fwl/theme/cfwl_scrollbartp.cpp b/xfa/fwl/theme/cfwl_scrollbartp.cpp index 13e89587df..d9f364e6db 100644 --- a/xfa/fwl/theme/cfwl_scrollbartp.cpp +++ b/xfa/fwl/theme/cfwl_scrollbartp.cpp @@ -6,8 +6,8 @@ #include "xfa/fwl/theme/cfwl_scrollbartp.h" +#include "xfa/fwl/core/cfwl_scrollbar.h" #include "xfa/fwl/core/cfwl_themebackground.h" -#include "xfa/fwl/core/ifwl_scrollbar.h" #include "xfa/fwl/core/ifwl_themeprovider.h" #include "xfa/fwl/core/ifwl_widget.h" #include "xfa/fxgraphics/cfx_color.h" diff --git a/xfa/fxfa/app/xfa_fwltheme.cpp b/xfa/fxfa/app/xfa_fwltheme.cpp index eb45cf12b7..782038a741 100644 --- a/xfa/fxfa/app/xfa_fwltheme.cpp +++ b/xfa/fxfa/app/xfa_fwltheme.cpp @@ -9,19 +9,19 @@ #include "xfa/fde/tto/fde_textout.h" #include "xfa/fgas/crt/fgas_codepage.h" #include "xfa/fgas/font/cfgas_gefont.h" +#include "xfa/fwl/core/cfwl_caret.h" +#include "xfa/fwl/core/cfwl_monthcalendar.h" +#include "xfa/fwl/core/cfwl_scrollbar.h" #include "xfa/fwl/core/cfwl_themebackground.h" #include "xfa/fwl/core/cfwl_themetext.h" #include "xfa/fwl/core/ifwl_barcode.h" -#include "xfa/fwl/core/ifwl_caret.h" #include "xfa/fwl/core/ifwl_checkbox.h" #include "xfa/fwl/core/ifwl_combobox.h" #include "xfa/fwl/core/ifwl_datetimepicker.h" #include "xfa/fwl/core/ifwl_edit.h" #include "xfa/fwl/core/ifwl_listbox.h" -#include "xfa/fwl/core/ifwl_monthcalendar.h" #include "xfa/fwl/core/ifwl_picturebox.h" #include "xfa/fwl/core/ifwl_pushbutton.h" -#include "xfa/fwl/core/ifwl_scrollbar.h" #include "xfa/fxfa/xfa_ffapp.h" #include "xfa/fxfa/xfa_ffwidget.h" #include "xfa/fxgraphics/cfx_color.h" -- cgit v1.2.3