switched to using wxPopupWindow
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31526 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -16,6 +16,8 @@ class WXDLLIMPEXP_ADV wxCalendarDateAttr;
|
|||||||
class WXDLLIMPEXP_ADV wxCalendarCtrl;
|
class WXDLLIMPEXP_ADV wxCalendarCtrl;
|
||||||
class WXDLLIMPEXP_ADV wxCalendarEvent;
|
class WXDLLIMPEXP_ADV wxCalendarEvent;
|
||||||
|
|
||||||
|
#include <wx/popupwin.h>
|
||||||
|
|
||||||
class WXDLLIMPEXP_ADV wxDatePickerCtrl : public wxDatePickerCtrlBase
|
class WXDLLIMPEXP_ADV wxDatePickerCtrl : public wxDatePickerCtrlBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -66,7 +68,7 @@ protected:
|
|||||||
virtual void DoMoveWindow(int x, int y, int width, int height);
|
virtual void DoMoveWindow(int x, int y, int width, int height);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxDialog *m_dlg;
|
wxPopupWindow *m_popup;
|
||||||
wxTextCtrl *m_txt;
|
wxTextCtrl *m_txt;
|
||||||
wxCalendarCtrl *m_cal;
|
wxCalendarCtrl *m_cal;
|
||||||
wxButton *m_btn;
|
wxButton *m_btn;
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: generic/datectrl.cpp
|
// Name: generic/datectlg.cpp
|
||||||
// Purpose: generic wxDatePickerCtrl implementation
|
// Purpose: generic wxDatePickerCtrl implementation
|
||||||
// Author: Andreas Pflug
|
// Author: Andreas Pflug
|
||||||
// Modified by:
|
// Modified by:
|
||||||
@@ -94,10 +94,6 @@ bool wxDatePickerCtrl::Create(wxWindow *parent,
|
|||||||
wxASSERT_MSG( !(style & wxDP_SPIN),
|
wxASSERT_MSG( !(style & wxDP_SPIN),
|
||||||
_T("wxDP_SPIN style not supported, use wxDP_DEFAULT") );
|
_T("wxDP_SPIN style not supported, use wxDP_DEFAULT") );
|
||||||
|
|
||||||
wxString txt;
|
|
||||||
if (date.IsValid())
|
|
||||||
txt = date.FormatDate();
|
|
||||||
|
|
||||||
if ( !wxControl::Create(parent, id, pos, size,
|
if ( !wxControl::Create(parent, id, pos, size,
|
||||||
style | wxCLIP_CHILDREN | wxWANTS_CHARS,
|
style | wxCLIP_CHILDREN | wxWANTS_CHARS,
|
||||||
wxDefaultValidator, name) )
|
wxDefaultValidator, name) )
|
||||||
@@ -125,23 +121,20 @@ bool wxDatePickerCtrl::Create(wxWindow *parent,
|
|||||||
dc.SelectObject(wxNullBitmap);
|
dc.SelectObject(wxNullBitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_txt=new wxTextCtrl(this, CTRLID_TXT, txt);
|
m_txt=new wxTextCtrl(this, CTRLID_TXT);
|
||||||
m_txt->Connect(wxID_ANY, wxID_ANY, wxEVT_KEY_DOWN,
|
m_txt->Connect(wxID_ANY, wxID_ANY, wxEVT_KEY_DOWN,
|
||||||
(wxObjectEventFunction)&wxDatePickerCtrl::OnEditKey,
|
(wxObjectEventFunction)&wxDatePickerCtrl::OnEditKey,
|
||||||
0, this);
|
0, this);
|
||||||
m_txt->Connect(wxID_ANY, wxID_ANY, wxEVT_KILL_FOCUS,
|
m_txt->Connect(wxID_ANY, wxID_ANY, wxEVT_KILL_FOCUS,
|
||||||
(wxObjectEventFunction)&wxDatePickerCtrl::OnKillFocus,
|
(wxObjectEventFunction)&wxDatePickerCtrl::OnKillFocus,
|
||||||
0, this);
|
0, this);
|
||||||
SetFormat(wxT("%x"));
|
|
||||||
|
|
||||||
m_btn = new wxBitmapButton(this, CTRLID_BTN, bmp);
|
m_btn = new wxBitmapButton(this, CTRLID_BTN, bmp);
|
||||||
|
|
||||||
m_dlg = new wxDialog(this, CTRLID_CAL, wxEmptyString,
|
m_popup = new wxPopupWindow(this);
|
||||||
wxDefaultPosition, wxDefaultSize,
|
m_popup->SetFont(GetFont());
|
||||||
wxSIMPLE_BORDER);
|
|
||||||
m_dlg->SetFont(GetFont());
|
|
||||||
|
|
||||||
wxPanel *panel=new wxPanel(m_dlg, CTRLID_PAN,
|
wxPanel *panel=new wxPanel(m_popup, CTRLID_PAN,
|
||||||
wxPoint(0, 0), wxDefaultSize,
|
wxPoint(0, 0), wxDefaultSize,
|
||||||
wxSUNKEN_BORDER);
|
wxSUNKEN_BORDER);
|
||||||
m_cal = new wxCalendarCtrl(panel, CTRLID_CAL, wxDefaultDateTime,
|
m_cal = new wxCalendarCtrl(panel, CTRLID_CAL, wxDefaultDateTime,
|
||||||
@@ -183,6 +176,12 @@ bool wxDatePickerCtrl::Create(wxWindow *parent,
|
|||||||
|
|
||||||
wxPoint yearPosition = yearControl->GetPosition();
|
wxPoint yearPosition = yearControl->GetPosition();
|
||||||
|
|
||||||
|
SetFormat(wxT("%x"));
|
||||||
|
|
||||||
|
if (date.IsValid())
|
||||||
|
m_txt->SetValue(date.Format(m_format));
|
||||||
|
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
#define CALBORDER 0
|
#define CALBORDER 0
|
||||||
#else
|
#else
|
||||||
@@ -207,7 +206,8 @@ bool wxDatePickerCtrl::Create(wxWindow *parent,
|
|||||||
|
|
||||||
|
|
||||||
panel->SetClientSize(width+CALBORDER/2, calSize.y-2+CALBORDER);
|
panel->SetClientSize(width+CALBORDER/2, calSize.y-2+CALBORDER);
|
||||||
m_dlg->SetClientSize(panel->GetSize());
|
m_popup->SetClientSize(panel->GetSize());
|
||||||
|
m_popup->Hide();
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,7 @@ bool wxDatePickerCtrl::Create(wxWindow *parent,
|
|||||||
|
|
||||||
void wxDatePickerCtrl::Init()
|
void wxDatePickerCtrl::Init()
|
||||||
{
|
{
|
||||||
m_dlg = NULL;
|
m_popup = NULL;
|
||||||
m_txt = NULL;
|
m_txt = NULL;
|
||||||
m_cal = NULL;
|
m_cal = NULL;
|
||||||
m_btn = NULL;
|
m_btn = NULL;
|
||||||
@@ -229,14 +229,14 @@ bool wxDatePickerCtrl::Destroy()
|
|||||||
{
|
{
|
||||||
if (m_cal)
|
if (m_cal)
|
||||||
m_cal->Destroy();
|
m_cal->Destroy();
|
||||||
if (m_dlg)
|
if (m_popup)
|
||||||
m_dlg->Destroy();
|
m_popup->Destroy();
|
||||||
if (m_txt)
|
if (m_txt)
|
||||||
m_txt->Destroy();
|
m_txt->Destroy();
|
||||||
if (m_btn)
|
if (m_btn)
|
||||||
m_btn->Destroy();
|
m_btn->Destroy();
|
||||||
|
|
||||||
m_dlg = NULL;
|
m_popup = NULL;
|
||||||
m_txt = NULL;
|
m_txt = NULL;
|
||||||
m_cal = NULL;
|
m_cal = NULL;
|
||||||
m_btn = NULL;
|
m_btn = NULL;
|
||||||
@@ -278,9 +278,9 @@ bool wxDatePickerCtrl::Show(bool show)
|
|||||||
|
|
||||||
if (!show)
|
if (!show)
|
||||||
{
|
{
|
||||||
if (m_dlg)
|
if (m_popup)
|
||||||
{
|
{
|
||||||
m_dlg->Hide();
|
m_popup->Hide();
|
||||||
m_dropped = false;
|
m_dropped = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -319,6 +319,14 @@ wxDatePickerCtrl::SetDateRange(const wxDateTime& lowerdate,
|
|||||||
|
|
||||||
bool wxDatePickerCtrl::SetFormat(const wxChar *fmt)
|
bool wxDatePickerCtrl::SetFormat(const wxChar *fmt)
|
||||||
{
|
{
|
||||||
|
wxString currentText;
|
||||||
|
wxDateTime currentDate;
|
||||||
|
if (m_txt)
|
||||||
|
{
|
||||||
|
currentText = m_txt->GetValue();
|
||||||
|
if (!currentText.IsEmpty())
|
||||||
|
currentDate.ParseFormat(currentText, m_format);
|
||||||
|
}
|
||||||
wxDateTime dt;
|
wxDateTime dt;
|
||||||
dt.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
|
dt.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
|
||||||
wxString str=dt.Format(fmt);
|
wxString str=dt.Format(fmt);
|
||||||
@@ -344,6 +352,11 @@ bool wxDatePickerCtrl::SetFormat(const wxChar *fmt)
|
|||||||
m_format.Append(wxT("%Y"));
|
m_format.Append(wxT("%Y"));
|
||||||
p += 4;
|
p += 4;
|
||||||
}
|
}
|
||||||
|
else if (n == (dt.GetYear() % 100))
|
||||||
|
{
|
||||||
|
m_format.Append(wxT("%y"));
|
||||||
|
p += 2;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
m_format.Append(*p++);
|
m_format.Append(*p++);
|
||||||
}
|
}
|
||||||
@@ -366,6 +379,9 @@ bool wxDatePickerCtrl::SetFormat(const wxChar *fmt)
|
|||||||
tv.SetIncludeList(valList);
|
tv.SetIncludeList(valList);
|
||||||
|
|
||||||
m_txt->SetValidator(tv);
|
m_txt->SetValidator(tv);
|
||||||
|
|
||||||
|
if (!currentText.IsEmpty())
|
||||||
|
m_txt->SetValue(currentDate.Format(m_format));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -388,7 +404,7 @@ void wxDatePickerCtrl::SetValue(const wxDateTime& date)
|
|||||||
if (m_cal)
|
if (m_cal)
|
||||||
{
|
{
|
||||||
if (date.IsValid())
|
if (date.IsValid())
|
||||||
m_txt->SetValue(date.FormatDate());
|
m_txt->SetValue(date.Format(m_format));
|
||||||
else
|
else
|
||||||
m_txt->SetValue(wxEmptyString);
|
m_txt->SetValue(wxEmptyString);
|
||||||
}
|
}
|
||||||
@@ -416,28 +432,28 @@ void wxDatePickerCtrl::SetRange(const wxDateTime &dt1, const wxDateTime &dt2)
|
|||||||
|
|
||||||
void wxDatePickerCtrl::DropDown(bool down)
|
void wxDatePickerCtrl::DropDown(bool down)
|
||||||
{
|
{
|
||||||
if (m_dlg)
|
if (m_popup)
|
||||||
{
|
{
|
||||||
if (down)
|
if (down)
|
||||||
{
|
{
|
||||||
if (m_txt->GetValue().IsEmpty())
|
wxDateTime dt;
|
||||||
m_cal->SetDate(wxDateTime::Today());
|
if (!m_txt->GetValue().IsEmpty())
|
||||||
else
|
|
||||||
{
|
|
||||||
wxDateTime dt;
|
|
||||||
dt.ParseFormat(m_txt->GetValue(), m_format);
|
dt.ParseFormat(m_txt->GetValue(), m_format);
|
||||||
m_cal->SetDate(dt);
|
|
||||||
}
|
|
||||||
wxPoint pos=GetParent()->ClientToScreen(GetPosition());
|
|
||||||
|
|
||||||
m_dlg->Move(pos.x, pos.y + GetSize().y);
|
if (dt.IsValid())
|
||||||
m_dlg->Show();
|
m_cal->SetDate(dt);
|
||||||
|
else
|
||||||
|
m_cal->SetDate(wxDateTime::Today());
|
||||||
|
|
||||||
|
wxPoint pos=GetParent()->ClientToScreen(GetPosition());
|
||||||
|
m_popup->Move(pos.x, pos.y + GetSize().y);
|
||||||
|
m_popup->Show();
|
||||||
m_dropped = true;
|
m_dropped = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (m_dropped)
|
if (m_dropped)
|
||||||
m_dlg->Hide();
|
m_popup->Hide();
|
||||||
m_dropped = false;
|
m_dropped = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -452,7 +468,7 @@ void wxDatePickerCtrl::OnChildSetFocus(wxChildFocusEvent &ev)
|
|||||||
wxWindow *w=(wxWindow*)ev.GetEventObject();
|
wxWindow *w=(wxWindow*)ev.GetEventObject();
|
||||||
while (w)
|
while (w)
|
||||||
{
|
{
|
||||||
if (w == m_dlg)
|
if (w == m_popup)
|
||||||
return;
|
return;
|
||||||
w = w->GetParent();
|
w = w->GetParent();
|
||||||
}
|
}
|
||||||
@@ -508,7 +524,7 @@ void wxDatePickerCtrl::OnSelChange(wxCalendarEvent &ev)
|
|||||||
{
|
{
|
||||||
if (m_cal)
|
if (m_cal)
|
||||||
{
|
{
|
||||||
m_txt->SetValue(m_cal->GetDate().FormatDate());
|
m_txt->SetValue(m_cal->GetDate().Format(m_format));
|
||||||
if (ev.GetEventType() == wxEVT_CALENDAR_DOUBLECLICKED)
|
if (ev.GetEventType() == wxEVT_CALENDAR_DOUBLECLICKED)
|
||||||
{
|
{
|
||||||
DropDown(false);
|
DropDown(false);
|
||||||
|
Reference in New Issue
Block a user