implemented HitTest() in the native MSW version; added test for it to the sample
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53006 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -44,6 +44,10 @@ public:
|
|||||||
|
|
||||||
virtual void Mark(size_t day, bool mark);
|
virtual void Mark(size_t day, bool mark);
|
||||||
|
|
||||||
|
virtual wxCalendarHitTestResult HitTest(const wxPoint& pos,
|
||||||
|
wxDateTime *date = NULL,
|
||||||
|
wxDateTime::WeekDay *wd = NULL);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual wxSize wxCalendarCtrl::DoGetBestSize() const;
|
virtual wxSize wxCalendarCtrl::DoGetBestSize() const;
|
||||||
|
|
||||||
|
@@ -102,6 +102,8 @@ public:
|
|||||||
void SetDate(const wxDateTime& dt) { m_calendar->SetDate(dt); }
|
void SetDate(const wxDateTime& dt) { m_calendar->SetDate(dt); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
wxCalendarCtrlBase *DoCreateCalendar(const wxDateTime& dt, long style);
|
||||||
|
|
||||||
void RecreateCalendar(long style);
|
void RecreateCalendar(long style);
|
||||||
|
|
||||||
wxCalendarCtrlBase *m_calendar;
|
wxCalendarCtrlBase *m_calendar;
|
||||||
@@ -159,6 +161,8 @@ public:
|
|||||||
event.Enable(m_panel->IsUsingGeneric());
|
event.Enable(m_panel->IsUsingGeneric());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnCalRClick(wxMouseEvent& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MyPanel *m_panel;
|
MyPanel *m_panel;
|
||||||
wxTextCtrl *m_logWindow;
|
wxTextCtrl *m_logWindow;
|
||||||
@@ -506,6 +510,48 @@ void MyFrame::OnCalToggleResizable(wxCommandEvent& event)
|
|||||||
sizer->Layout();
|
sizer->Layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnCalRClick(wxMouseEvent& event)
|
||||||
|
{
|
||||||
|
wxDateTime dt;
|
||||||
|
wxDateTime::WeekDay wd;
|
||||||
|
|
||||||
|
const wxPoint pt = event.GetPosition();
|
||||||
|
wxString msg = wxString::Format("Point (%d, %d) is ", pt.x, pt.y);
|
||||||
|
|
||||||
|
switch ( m_panel->GetCal()->HitTest(pt, &dt, &wd) )
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
wxFAIL_MSG( "unexpected" );
|
||||||
|
// fall through
|
||||||
|
|
||||||
|
case wxCAL_HITTEST_NOWHERE:
|
||||||
|
msg += "nowhere";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxCAL_HITTEST_HEADER:
|
||||||
|
msg += wxString::Format("over %s", wxDateTime::GetWeekDayName(wd));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxCAL_HITTEST_DAY:
|
||||||
|
msg += wxString::Format("over %s", dt.FormatISODate());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxCAL_HITTEST_INCMONTH:
|
||||||
|
msg += "over next month button";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxCAL_HITTEST_DECMONTH:
|
||||||
|
msg += "over previous month button";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxCAL_HITTEST_SURROUNDING_WEEK:
|
||||||
|
msg += "over a day from another month";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxLogMessage("%s", msg);
|
||||||
|
}
|
||||||
|
|
||||||
#if wxUSE_DATEPICKCTRL
|
#if wxUSE_DATEPICKCTRL
|
||||||
|
|
||||||
void MyFrame::OnUpdateUIStartWithNone(wxUpdateUIEvent& event)
|
void MyFrame::OnUpdateUIStartWithNone(wxUpdateUIEvent& event)
|
||||||
@@ -575,13 +621,8 @@ MyPanel::MyPanel(wxWindow *parent)
|
|||||||
date.Printf(wxT("Selected date: %s"),
|
date.Printf(wxT("Selected date: %s"),
|
||||||
wxDateTime::Today().FormatISODate().c_str());
|
wxDateTime::Today().FormatISODate().c_str());
|
||||||
m_date = new wxStaticText(this, wxID_ANY, date);
|
m_date = new wxStaticText(this, wxID_ANY, date);
|
||||||
m_calendar = new wxCalendarCtrl(this, Calendar_CalCtrl,
|
m_calendar = DoCreateCalendar(wxDefaultDateTime,
|
||||||
wxDefaultDateTime,
|
wxCAL_MONDAY_FIRST | wxCAL_SHOW_HOLIDAYS);
|
||||||
wxDefaultPosition,
|
|
||||||
wxDefaultSize,
|
|
||||||
wxCAL_MONDAY_FIRST |
|
|
||||||
wxCAL_SHOW_HOLIDAYS |
|
|
||||||
wxRAISED_BORDER);
|
|
||||||
|
|
||||||
// adjust to vertical/horizontal display, check mostly dedicated to WinCE
|
// adjust to vertical/horizontal display, check mostly dedicated to WinCE
|
||||||
bool horizontal = ( wxSystemSettings::GetMetric(wxSYS_SCREEN_X) > wxSystemSettings::GetMetric(wxSYS_SCREEN_Y) );
|
bool horizontal = ( wxSystemSettings::GetMetric(wxSYS_SCREEN_X) > wxSystemSettings::GetMetric(wxSYS_SCREEN_Y) );
|
||||||
@@ -623,24 +664,36 @@ void MyPanel::OnCalendarWeekDayClick(wxCalendarEvent& event)
|
|||||||
wxDateTime::GetWeekDayName(event.GetWeekDay()).c_str());
|
wxDateTime::GetWeekDayName(event.GetWeekDay()).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyPanel::RecreateCalendar(long style)
|
wxCalendarCtrlBase *MyPanel::DoCreateCalendar(const wxDateTime& dt, long style)
|
||||||
{
|
{
|
||||||
wxCalendarCtrlBase *calendar;
|
wxCalendarCtrlBase *calendar;
|
||||||
#ifdef wxHAS_NATIVE_CALENDARCTRL
|
#ifdef wxHAS_NATIVE_CALENDARCTRL
|
||||||
if ( m_usingGeneric )
|
if ( m_usingGeneric )
|
||||||
calendar = new wxGenericCalendarCtrl(this, Calendar_CalCtrl,
|
calendar = new wxGenericCalendarCtrl(this, Calendar_CalCtrl,
|
||||||
m_calendar->GetDate(),
|
dt,
|
||||||
wxDefaultPosition,
|
wxDefaultPosition,
|
||||||
wxDefaultSize,
|
wxDefaultSize,
|
||||||
style);
|
style);
|
||||||
else
|
else
|
||||||
#endif // wxHAS_NATIVE_CALENDARCTRL
|
#endif // wxHAS_NATIVE_CALENDARCTRL
|
||||||
calendar = new wxCalendarCtrl(this, Calendar_CalCtrl,
|
calendar = new wxCalendarCtrl(this, Calendar_CalCtrl,
|
||||||
m_calendar->GetDate(),
|
dt,
|
||||||
wxDefaultPosition,
|
wxDefaultPosition,
|
||||||
wxDefaultSize,
|
wxDefaultSize,
|
||||||
style);
|
style);
|
||||||
|
|
||||||
|
calendar->Connect(wxEVT_RIGHT_DOWN,
|
||||||
|
wxMouseEventHandler(MyFrame::OnCalRClick),
|
||||||
|
NULL,
|
||||||
|
wxGetTopLevelParent(this));
|
||||||
|
|
||||||
|
return calendar;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyPanel::RecreateCalendar(long style)
|
||||||
|
{
|
||||||
|
wxCalendarCtrlBase *calendar = DoCreateCalendar(m_calendar->GetDate(), style);
|
||||||
|
|
||||||
m_sizer->Replace(m_calendar, calendar);
|
m_sizer->Replace(m_calendar, calendar);
|
||||||
delete m_calendar;
|
delete m_calendar;
|
||||||
m_calendar = calendar;
|
m_calendar = calendar;
|
||||||
|
@@ -103,6 +103,52 @@ wxSize wxCalendarCtrl::DoGetBestSize() const
|
|||||||
return best;
|
return best;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxCalendarHitTestResult
|
||||||
|
wxCalendarCtrl::HitTest(const wxPoint& pos,
|
||||||
|
wxDateTime *date,
|
||||||
|
wxDateTime::WeekDay *wd)
|
||||||
|
{
|
||||||
|
WinStruct<MCHITTESTINFO> hti;
|
||||||
|
hti.pt.x = pos.x;
|
||||||
|
hti.pt.y = pos.y;
|
||||||
|
switch ( MonthCal_HitTest(GetHwnd(), &hti) )
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case MCHT_CALENDARWEEKNUM:
|
||||||
|
wxFAIL_MSG( "unexpected" );
|
||||||
|
// fall through
|
||||||
|
|
||||||
|
case MCHT_NOWHERE:
|
||||||
|
case MCHT_CALENDARBK:
|
||||||
|
case MCHT_TITLEBK:
|
||||||
|
case MCHT_TITLEMONTH:
|
||||||
|
case MCHT_TITLEYEAR:
|
||||||
|
return wxCAL_HITTEST_NOWHERE;
|
||||||
|
|
||||||
|
case MCHT_CALENDARDATE:
|
||||||
|
if ( date )
|
||||||
|
wxMSWDateControls::FromSystemTime(date, hti.st);
|
||||||
|
return wxCAL_HITTEST_DAY;
|
||||||
|
|
||||||
|
case MCHT_CALENDARDAY:
|
||||||
|
if ( wd )
|
||||||
|
{
|
||||||
|
*wd = wx_static_cast(wxDateTime::WeekDay, hti.st.wDayOfWeek);
|
||||||
|
}
|
||||||
|
return wxCAL_HITTEST_HEADER;
|
||||||
|
|
||||||
|
case MCHT_TITLEBTNNEXT:
|
||||||
|
return wxCAL_HITTEST_INCMONTH;
|
||||||
|
|
||||||
|
case MCHT_TITLEBTNPREV:
|
||||||
|
return wxCAL_HITTEST_DECMONTH;
|
||||||
|
|
||||||
|
case MCHT_CALENDARDATENEXT:
|
||||||
|
case MCHT_CALENDARDATEPREV:
|
||||||
|
return wxCAL_HITTEST_SURROUNDING_WEEK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxCalendarCtrl operations
|
// wxCalendarCtrl operations
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user