7#include "xfa/fwl/cfwl_datetimepicker.h"
9#include "xfa/fwl/cfwl_app.h"
10#include "xfa/fwl/cfwl_event.h"
11#include "xfa/fwl/cfwl_eventselectchanged.h"
12#include "xfa/fwl/cfwl_messagemouse.h"
13#include "xfa/fwl/cfwl_messagesetfocus.h"
14#include "xfa/fwl/cfwl_notedriver.h"
15#include "xfa/fwl/cfwl_themebackground.h"
16#include "xfa/fwl/cfwl_widgetmgr.h"
17#include "xfa/fwl/ifwl_themeprovider.h"
21constexpr int kDateTimePickerHeight = 20;
25CFWL_DateTimePicker::CFWL_DateTimePicker(CFWL_App* app)
29 m_pEdit(cppgc::MakeGarbageCollected<CFWL_DateTimeEdit>(
30 app->GetHeap()->GetAllocationHandle(),
34 m_pMonthCal(cppgc::MakeGarbageCollected<CFWL_MonthCalendar>(
35 app->GetHeap()->GetAllocationHandle(),
40 m_pMonthCal->SetWidgetRect(
41 CFX_RectF(0, 0, m_pMonthCal->GetAutosizedWidgetRect().Size()));
43 CFWL_NoteDriver* pNoteDriver =
GetFWLApp()->GetNoteDriver();
44 pNoteDriver->RegisterEventTarget(
this, m_pMonthCal);
45 pNoteDriver->RegisterEventTarget(
this, m_pEdit);
55void CFWL_DateTimePicker::
Trace(cppgc::Visitor* visitor)
const {
56 CFWL_Widget::Trace(visitor);
57 visitor->Trace(m_pEdit);
58 visitor->Trace(m_pMonthCal);
70 m_pEdit->SetWidgetRect(m_ClientRect);
75 CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect();
78 m_pMonthCal->SetWidgetRect(rtPopUp);
79 m_pMonthCal->Update();
86 if (NeedsToShowButton())
91 if (m_pMonthCal->GetWidgetRect().Contains(point))
106 DrawDropDownButton(pGraphics, matrix);
109 CFX_RectF rtEdit = m_pEdit->GetWidgetRect();
112 m_pEdit->DrawWidget(pGraphics, mt);
117 CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect();
120 m_pMonthCal->DrawWidget(pGraphics, mt);
134 if (iYear <= 0 || iYear >= 3000)
136 if (iMonth <= 0 || iMonth >= 13)
138 if (iDay <= 0 || iDay >= 32)
144 m_pMonthCal->SetSelect(iYear, iMonth, iDay);
151 m_pEdit->SetText(wsText);
159 return m_pEdit ? m_pEdit->GetText() : WideString();
163 return m_pEdit ? m_pEdit->GetTextLength() : 0;
168 if (NeedsToShowButton())
173 CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect();
180 uint32_t dwStyleExtsRemoved) {
181 m_pEdit->ModifyStyleExts(dwStyleExtsAdded, dwStyleExtsRemoved);
188 param.m_dwStates = m_iBtnState;
194WideString CFWL_DateTimePicker::FormatDateString(int32_t iYear,
200 return WideString
::Format(L"%d Year %d Month %d Day"
, iYear
, iMonth
, iDay
);
207 CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect();
208 float fPopupMin = rtMonthCal
.height;
209 float fPopupMax = rtMonthCal
.height;
214 GetPopupPos(fPopupMin, fPopupMax, rtAnchor, &rtMonthCal);
215 m_pMonthCal->SetWidgetRect(rtMonthCal);
216 if (m_iYear > 0 && m_iMonth > 0 && m_iDay > 0)
217 m_pMonthCal->SetSelect(m_iYear, m_iMonth, m_iDay);
218 m_pMonthCal->Update();
221 CFWL_MessageSetFocus msg(m_pMonthCal);
222 m_pEdit->GetDelegate()->OnProcessMessage(&msg);
223 RepaintInflatedMonthCalRect();
231 RepaintInflatedMonthCalRect();
234void CFWL_DateTimePicker::RepaintInflatedMonthCalRect() {
236 CFX_RectF rtCal = m_pMonthCal->GetWidgetRect();
243 return m_pMonthCal && m_pMonthCal->IsVisible();
246void CFWL_DateTimePicker::ResetEditAlignment() {
293 m_pEdit->SetText(FormatDateString(m_iYear, m_iMonth, m_iDay));
297 CFWL_EventSelectChanged ev(
this, m_iYear, m_iMonth, m_iDay);
301bool CFWL_DateTimePicker::NeedsToShowButton()
const {
310 OnFocusGained(pMessage);
313 OnFocusLost(pMessage);
316 CFWL_MessageMouse* pMouse =
static_cast<CFWL_MessageMouse*>(pMessage);
319 OnLButtonDown(pMouse);
328 OnMouseLeave(pMouse);
337 m_pEdit->GetDelegate()->OnProcessMessage(pMessage);
355void CFWL_DateTimePicker::OnFocusGained(
CFWL_Message* pMsg) {
362 pMsg->SetDstTarget(m_pEdit);
363 m_pEdit->GetDelegate()->OnProcessMessage(pMsg);
368void CFWL_DateTimePicker::OnFocusLost(
CFWL_Message* pMsg) {
374 m_pEdit->GetDelegate()->OnProcessMessage(pMsg);
379void CFWL_DateTimePicker::OnLButtonDown(CFWL_MessageMouse* pMsg) {
382 if (!m_BtnRect.Contains(pMsg->m_pos))
394void CFWL_DateTimePicker::OnLButtonUp(CFWL_MessageMouse* pMsg) {
399 if (m_BtnRect.Contains(pMsg->m_pos))
400 m_iBtnState = CFWL_PartState::kHovered;
402 m_iBtnState = CFWL_PartState::kNormal;
406void CFWL_DateTimePicker::OnMouseMove(CFWL_MessageMouse* pMsg) {
407 if (!m_BtnRect.Contains(pMsg->m_pos))
408 m_iBtnState = CFWL_PartState::kNormal;
412void CFWL_DateTimePicker::OnMouseLeave(CFWL_MessageMouse* pMsg) {
415 m_iBtnState = CFWL_PartState::kNormal;
419void CFWL_DateTimePicker::GetPopupPos(
float fMinHeight,
423 GetWidgetMgr()->GetAdapterPopupPos(
this, fMinHeight, fMaxHeight, rtAnchor,
428 m_pEdit->ClearText();
432 m_pEdit->SelectAll();
436 m_pEdit->ClearSelection();
440 return m_pEdit->Copy();
444 return m_pEdit->Cut();
447bool CFWL_DateTimePicker::
Paste(
const WideString& wsPaste) {
448 return m_pEdit->Paste(wsPaste);
451bool CFWL_DateTimePicker::
Undo() {
452 return m_pEdit->Undo();
455bool CFWL_DateTimePicker::
Redo() {
456 return m_pEdit->Redo();
460 return m_pEdit->CanUndo();
464 return m_pEdit->CanRedo();
#define FWL_STYLEEXT_DTP_EditVCenter
#define FWL_STYLEEXT_DTP_EditJustified
#define FWL_STYLEEXT_DTP_ShortDateFormat
#define FWL_STYLEEXT_DTP_EditHCenter
#define FWL_STYLEEXT_DTP_EditVFar
#define FWL_STYLEEXT_DTP_EditHAlignMask
#define FWL_STYLEEXT_DTP_EditVAlignMask
#define FWL_STYLEEXT_DTP_EditHFar
#define FWL_STYLEEXT_EDT_HFar
#define FWL_STYLEEXT_EDT_VAlignMask
#define FWL_STYLEEXT_EDT_HAlignModeMask
#define FWL_STYLEEXT_EDT_HAlignMask
#define FWL_STYLEEXT_EDT_VNear
#define FWL_STYLEEXT_EDT_VCenter
#define FWL_STYLEEXT_EDT_ReadOnly
#define FWL_STYLEEXT_EDT_VFar
#define FWL_STYLEEXT_EDT_HNear
#define FWL_STYLEEXT_EDT_Justified
#define FWL_STYLEEXT_EDT_HCenter
void OnProcessMessage(CFWL_Message *pMessage) override
bool IsMonthCalendarVisible() const
CFX_RectF GetBBox() const
bool Paste(const WideString &wsPaste)
void SetCurSel(int32_t iYear, int32_t iMonth, int32_t iDay)
~CFWL_DateTimePicker() override
absl::optional< WideString > Copy()
void Trace(cppgc::Visitor *visitor) const override
FWL_Type GetClassID() const override
absl::optional< WideString > Cut()
void GetCurSel(int32_t &iYear, int32_t &iMonth, int32_t &iDay)
WideString GetEditText() const
void PreFinalize() override
void SetEditText(const WideString &wsText)
void DrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
void ProcessSelChanged(int32_t iYear, int32_t iMonth, int32_t iDay)
FWL_WidgetHit HitTest(const CFX_PointF &point) override
size_t GetEditTextLength() const
void ModifyEditStyleExts(uint32_t dwStyleExtsAdded, uint32_t dwStyleExtsRemoved)
void OnDrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
const MouseCommand m_dwCmd
CFWL_Widget * GetDstTarget() const
CFX_Matrix & operator=(const CFX_Matrix &other)=default
CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
void Concat(const CFX_Matrix &right)
CFX_RectF(const CFX_RectF &other)=default
void Offset(float dx, float dy)
constexpr CFX_RectF()=default
void Inflate(float x, float y)
CFX_RectF & operator=(const CFX_RectF &other)=default
bool Contains(const PointType &p) const
constexpr CFX_RectF(float dst_left, float dst_top, float dst_width, float dst_height)
void Union(const CFX_RectF &rt)
static WideString Format(const wchar_t *pFormat,...)