From 72f15a08aa47afb61e3c60b3f754309696c471ec Mon Sep 17 00:00:00 2001 From: dsinclair Date: Thu, 10 Nov 2016 13:01:54 -0800 Subject: Fold IFWL_DateTimeCalendar into IFWL_MonthCalendar The IFWL_MonthCalendar was never instantiated and had a single sub-class. This CL folds the subclass into IFWL_MonthCalendar and uses MonthCalendar directly. Review-Url: https://codereview.chromium.org/2491443003 --- xfa/fwl/core/ifwl_datetimecalendar.cpp | 184 --------------------------------- xfa/fwl/core/ifwl_datetimecalendar.h | 31 ------ xfa/fwl/core/ifwl_datetimepicker.cpp | 10 +- xfa/fwl/core/ifwl_datetimepicker.h | 5 +- xfa/fwl/core/ifwl_monthcalendar.cpp | 125 +++++++++++++--------- xfa/fwl/core/ifwl_monthcalendar.h | 3 +- 6 files changed, 86 insertions(+), 272 deletions(-) delete mode 100644 xfa/fwl/core/ifwl_datetimecalendar.cpp delete mode 100644 xfa/fwl/core/ifwl_datetimecalendar.h (limited to 'xfa') diff --git a/xfa/fwl/core/ifwl_datetimecalendar.cpp b/xfa/fwl/core/ifwl_datetimecalendar.cpp deleted file mode 100644 index c9f640fe63..0000000000 --- a/xfa/fwl/core/ifwl_datetimecalendar.cpp +++ /dev/null @@ -1,184 +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_datetimecalendar.h" - -#include "third_party/base/ptr_util.h" -#include "xfa/fwl/core/cfwl_widgetmgr.h" -#include "xfa/fwl/core/ifwl_datetimepicker.h" -#include "xfa/fwl/core/ifwl_formproxy.h" - -IFWL_DateTimeCalendar::IFWL_DateTimeCalendar( - const IFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter) - : IFWL_MonthCalendar(app, std::move(properties), pOuter), m_bFlag(false) {} - -void IFWL_DateTimeCalendar::OnProcessMessage(CFWL_Message* pMessage) { - CFWL_MessageType dwCode = pMessage->GetClassID(); - if (dwCode == CFWL_MessageType::SetFocus || - dwCode == CFWL_MessageType::KillFocus) { - IFWL_Widget* pOuter = GetOuter(); - pOuter->GetDelegate()->OnProcessMessage(pMessage); - return; - } - if (dwCode == CFWL_MessageType::Mouse) { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - if (pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonDown) - OnLButtonDownEx(pMsg); - else if (pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonUp) - OnLButtonUpEx(pMsg); - return; - } - IFWL_MonthCalendar::OnProcessMessage(pMessage); -} - -void IFWL_DateTimeCalendar::OnLButtonDownEx(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->IsMonthCalendarShowed()) - m_bFlag = 1; - } -} - -void IFWL_DateTimeCalendar::OnLButtonUpEx(CFWL_MsgMouse* pMsg) { - if (m_pWidgetMgr->IsFormDisabled()) - return DisForm_OnLButtonUpEx(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) { - FWL_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_DateTimeCalendar::OnMouseMoveEx(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; - CFWL_Event_DtpHoverChanged ev; - ev.hoverday = iHover; - DispatchEvent(&ev); - } else { - bRepaint = m_iHovered > 0; - if (bRepaint) - GetDayRect(m_iHovered, rtInvalidate); - - m_iHovered = -1; - } - if (bRepaint && !rtInvalidate.IsEmpty()) - Repaint(&rtInvalidate); -} - -void IFWL_DateTimeCalendar::DisForm_OnProcessMessage(CFWL_Message* pMessage) { - if (pMessage->GetClassID() == CFWL_MessageType::Mouse) { - CFWL_MsgMouse* pMsg = static_cast(pMessage); - if (pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonUp) { - DisForm_OnLButtonUpEx(pMsg); - return; - } - } - IFWL_MonthCalendar::OnProcessMessage(pMessage); -} - -void IFWL_DateTimeCalendar::DisForm_OnLButtonUpEx(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) { - FWL_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); - } -} diff --git a/xfa/fwl/core/ifwl_datetimecalendar.h b/xfa/fwl/core/ifwl_datetimecalendar.h deleted file mode 100644 index d47e32edb5..0000000000 --- a/xfa/fwl/core/ifwl_datetimecalendar.h +++ /dev/null @@ -1,31 +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_DATETIMECALENDAR_H_ -#define XFA_FWL_CORE_IFWL_DATETIMECALENDAR_H_ - -#include "xfa/fwl/core/ifwl_monthcalendar.h" - -class IFWL_DateTimeCalendar : public IFWL_MonthCalendar { - public: - IFWL_DateTimeCalendar(const IFWL_App* app, - std::unique_ptr properties, - IFWL_Widget* pOuter); - - // IFWL_MonthCalendar - void OnProcessMessage(CFWL_Message* pMessage) override; - - private: - void OnLButtonDownEx(CFWL_MsgMouse* pMsg); - void OnLButtonUpEx(CFWL_MsgMouse* pMsg); - void OnMouseMoveEx(CFWL_MsgMouse* pMsg); - void DisForm_OnProcessMessage(CFWL_Message* pMessage); - void DisForm_OnLButtonUpEx(CFWL_MsgMouse* pMsg); - - bool m_bFlag; -}; - -#endif // XFA_FWL_CORE_IFWL_DATETIMECALENDAR_H_ diff --git a/xfa/fwl/core/ifwl_datetimepicker.cpp b/xfa/fwl/core/ifwl_datetimepicker.cpp index 4ac43ea114..31e5b65cf0 100644 --- a/xfa/fwl/core/ifwl_datetimepicker.cpp +++ b/xfa/fwl/core/ifwl_datetimepicker.cpp @@ -11,7 +11,6 @@ #include "xfa/fwl/core/cfwl_themebackground.h" #include "xfa/fwl/core/cfwl_widgetmgr.h" #include "xfa/fwl/core/fwl_noteimp.h" -#include "xfa/fwl/core/ifwl_datetimecalendar.h" #include "xfa/fwl/core/ifwl_datetimeedit.h" #include "xfa/fwl/core/ifwl_formproxy.h" #include "xfa/fwl/core/ifwl_spinbutton.h" @@ -46,7 +45,7 @@ IFWL_DateTimePicker::IFWL_DateTimePicker( monthProp->m_pParent = this; monthProp->m_pThemeProvider = m_pProperties->m_pThemeProvider; m_pMonthCal.reset( - new IFWL_DateTimeCalendar(m_pOwnerApp, std::move(monthProp), this)); + new IFWL_MonthCalendar(m_pOwnerApp, std::move(monthProp), this)); CFX_RectF rtMonthCal; m_pMonthCal->GetWidgetRect(rtMonthCal, true); @@ -454,14 +453,14 @@ IFWL_DateTimeEdit* IFWL_DateTimePicker::GetDataTimeEdit() { FWL_Error IFWL_DateTimePicker::DisForm_Initialize() { m_pProperties->m_dwStyleExes = FWL_STYLEEXT_DTP_ShortDateFormat; - DisForm_InitDateTimeCalendar(); + DisForm_InitMonthCalendar(); DisForm_InitDateTimeEdit(); RegisterEventTarget(m_pMonthCal.get()); RegisterEventTarget(m_pEdit.get()); return FWL_Error::Succeeded; } -void IFWL_DateTimePicker::DisForm_InitDateTimeCalendar() { +void IFWL_DateTimePicker::DisForm_InitMonthCalendar() { if (m_pMonthCal) return; @@ -472,8 +471,7 @@ void IFWL_DateTimePicker::DisForm_InitDateTimeCalendar() { prop->m_pParent = this; prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; - m_pMonthCal.reset( - new IFWL_DateTimeCalendar(m_pOwnerApp, std::move(prop), this)); + m_pMonthCal.reset(new IFWL_MonthCalendar(m_pOwnerApp, std::move(prop), this)); CFX_RectF rtMonthCal; m_pMonthCal->GetWidgetRect(rtMonthCal, true); rtMonthCal.Set(0, 0, rtMonthCal.width, rtMonthCal.height); diff --git a/xfa/fwl/core/ifwl_datetimepicker.h b/xfa/fwl/core/ifwl_datetimepicker.h index a7464e78e6..f6742838c4 100644 --- a/xfa/fwl/core/ifwl_datetimepicker.h +++ b/xfa/fwl/core/ifwl_datetimepicker.h @@ -30,7 +30,6 @@ #define FWL_STYLEEXT_DTP_EditVAlignMask (3L << 6) #define FWL_STYLEEXT_DTP_EditHAlignModeMask (3L << 8) -class IFWL_DateTimeCalendar; class IFWL_DateTimeEdit; class IFWL_FormProxy; @@ -140,13 +139,13 @@ class IFWL_DateTimePicker : public IFWL_Widget, public IFWL_MonthCalendarDP { int32_t m_iDay; bool m_bLBtnDown; std::unique_ptr m_pEdit; - std::unique_ptr m_pMonthCal; + std::unique_ptr m_pMonthCal; std::unique_ptr m_pForm; FX_FLOAT m_fBtn; private: FWL_Error DisForm_Initialize(); - void DisForm_InitDateTimeCalendar(); + void DisForm_InitMonthCalendar(); void DisForm_InitDateTimeEdit(); bool DisForm_IsMonthCalendarShowed(); void DisForm_ShowMonthCalendar(bool bActivate); diff --git a/xfa/fwl/core/ifwl_monthcalendar.cpp b/xfa/fwl/core/ifwl_monthcalendar.cpp index 7351e7e29a..dcc66fe677 100644 --- a/xfa/fwl/core/ifwl_monthcalendar.cpp +++ b/xfa/fwl/core/ifwl_monthcalendar.cpp @@ -14,6 +14,8 @@ #include "xfa/fwl/core/cfwl_themebackground.h" #include "xfa/fwl/core/cfwl_themetext.h" #include "xfa/fwl/core/fwl_noteimp.h" +#include "xfa/fwl/core/ifwl_datetimepicker.h" +#include "xfa/fwl/core/ifwl_formproxy.h" #include "xfa/fwl/core/ifwl_monthcalendar.h" #include "xfa/fwl/core/ifwl_themeprovider.h" @@ -133,7 +135,8 @@ IFWL_MonthCalendar::IFWL_MonthCalendar( m_iHovered(-1), m_iLBtnPartStates(CFWL_PartState_Normal), m_iRBtnPartStates(CFWL_PartState_Normal), - m_iMaxSel(1) { + m_iMaxSel(1), + m_bFlag(false) { m_rtHead.Reset(); m_rtWeek.Reset(); m_rtLBtn.Reset(); @@ -1016,10 +1019,8 @@ void IFWL_MonthCalendar::OnProcessMessage(CFWL_Message* pMessage) { CFWL_MessageType dwMsgCode = pMessage->GetClassID(); switch (dwMsgCode) { case CFWL_MessageType::SetFocus: - OnFocusChanged(pMessage, true); - break; case CFWL_MessageType::KillFocus: - OnFocusChanged(pMessage, false); + GetOuter()->GetDelegate()->OnProcessMessage(pMessage); break; case CFWL_MessageType::Key: break; @@ -1054,15 +1055,6 @@ void IFWL_MonthCalendar::OnDrawWidget(CFX_Graphics* pGraphics, DrawWidget(pGraphics, pMatrix); } -void IFWL_MonthCalendar::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_MonthCalendar::OnLButtonDown(CFWL_MsgMouse* pMsg) { if (m_rtLBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { m_iLBtnPartStates = CFWL_PartState_Pressed; @@ -1078,49 +1070,88 @@ void IFWL_MonthCalendar::OnLButtonDown(CFWL_MsgMouse* pMsg) { Repaint(&m_rtClient); } } else { - if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_MCD_MultiSelect)) { - int32_t iOldSel = 0; - if (m_arrSelDays.GetSize() <= 0) - return; - iOldSel = m_arrSelDays[0]; - - int32_t iCurSel = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); - bool bSelChanged = iCurSel > 0 && iCurSel != iOldSel; - if (bSelChanged) { - FWL_DATEINFO* lpDatesInfo = m_arrDates.GetAt(iCurSel - 1); - CFX_RectF rtInvalidate(lpDatesInfo->rect); - if (iOldSel > 0) { - lpDatesInfo = m_arrDates.GetAt(iOldSel - 1); - rtInvalidate.Union(lpDatesInfo->rect); - } - AddSelDay(iCurSel); - CFWL_EvtClick wmClick; - wmClick.m_pSrcTarget = this; - DispatchEvent(&wmClick); - CFWL_EventMcdDateChanged wmDateSelected; - wmDateSelected.m_iStartDay = iCurSel; - wmDateSelected.m_iEndDay = iCurSel; - wmDateSelected.m_iOldMonth = m_iCurMonth; - wmDateSelected.m_iOldYear = m_iCurYear; - wmDateSelected.m_pSrcTarget = this; - DispatchEvent(&wmDateSelected); - Repaint(&rtInvalidate); - } - } + IFWL_DateTimePicker* pIPicker = static_cast(m_pOuter); + if (pIPicker->IsMonthCalendarShowed()) + 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); - } else if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { + return; + } + if (m_rtRBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { m_iRBtnPartStates = 0; Repaint(&m_rtRBtn); - } else if (m_rtDates.Contains(pMsg->m_fx, pMsg->m_fy)) { - int32_t iDay = GetDayAtPoint(pMsg->m_fx, pMsg->m_fy); - if (iDay != -1) - AddSelDay(iDay); + 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) { + FWL_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) { + FWL_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); } } diff --git a/xfa/fwl/core/ifwl_monthcalendar.h b/xfa/fwl/core/ifwl_monthcalendar.h index 60679e27c8..1d63c80e58 100644 --- a/xfa/fwl/core/ifwl_monthcalendar.h +++ b/xfa/fwl/core/ifwl_monthcalendar.h @@ -238,11 +238,12 @@ class IFWL_MonthCalendar : public IFWL_Widget { FX_FLOAT m_fTodayFlagWid; FX_FLOAT m_fMCWid; FX_FLOAT m_fMCHei; + bool m_bFlag; private: - void OnFocusChanged(CFWL_Message* pMsg, bool bSet); 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); }; -- cgit v1.2.3