Index: timespin.h =================================================================== RCS file: /projects/pgadmin3/src/include/timespin.h,v retrieving revision 1.5 retrieving revision 1.6 diff -Lsrc/include/timespin.h -Lsrc/include/timespin.h -u -w -r1.5 -r1.6 --- src/include/timespin.h +++ src/include/timespin.h @@ -62,6 +62,9 @@ long spinValue, maxSpinValue; bool canWrap, hasDay; + wxSize DoGetBestSize() const; + void OnSize(wxSizeEvent& event); + DECLARE_DYNAMIC_CLASS(wxTimeSpinCtrl) DECLARE_EVENT_TABLE() DECLARE_NO_COPY_CLASS(wxTimeSpinCtrl) Index: calbox.h =================================================================== RCS file: /projects/pgadmin3/src/include/calbox.h,v retrieving revision 1.8 retrieving revision 1.9 diff -Lsrc/include/calbox.h -Lsrc/include/calbox.h -u -w -r1.8 -r1.9 --- src/include/calbox.h +++ src/include/calbox.h @@ -14,7 +14,40 @@ #include "wx/calctrl.h" +#if wxUSE_DATEPICKCTRL +#define pgUSE_WX_CAL 0 +#else +#define pgUSE_WX_CAL 0 +#endif +#if pgUSE_WX_CAL +#include "wx/datectrl.h" + + +#ifdef __WXMSW__ + +#include "wx/generic/datectrl.h" +#define wxDPC wxDatePickerCtrlGeneric + +#else + +#define wxDPC wxDatePickerCtrl + +#endif + +class wxCalendarBox : public wxDPC +{ +public: + wxCalendarBox(); + wxCalendarBox(wxWindow *parent, + wxWindowID id, + const wxDateTime& date = wxDefaultDateTime, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize); +}; + + +#else class wxCalendarBox : public wxControl { public: @@ -36,8 +69,8 @@ long style, const wxString& name); - bool SetDate(const wxDateTime& date); - wxDateTime GetDate(); + bool SetValue(const wxDateTime& date); + wxDateTime GetValue(); bool SetLowerDateLimit(const wxDateTime& date = wxDefaultDateTime) { return m_cal->SetLowerDateLimit(date); } const wxDateTime& GetLowerDateLimit() const { return m_cal->GetLowerDateLimit(); } @@ -69,6 +102,9 @@ void Init(); void DropDown(bool down=true); + wxSize DoGetBestSize() const; + void OnSize(wxSizeEvent& event); + void OnText(wxCommandEvent &ev); void OnEditKey(wxKeyEvent & event); void OnCalKey(wxKeyEvent & event); @@ -83,6 +119,7 @@ DECLARE_NO_COPY_CLASS(wxCalendarBox) }; +#endif #endif // _WX_CALBOX_H_ Index: dlgUser.h =================================================================== RCS file: /projects/pgadmin3/src/include/dlgUser.h,v retrieving revision 1.17 retrieving revision 1.18 diff -Lsrc/include/dlgUser.h -Lsrc/include/dlgUser.h -u -w -r1.17 -r1.18 --- src/include/dlgUser.h +++ src/include/dlgUser.h @@ -39,6 +39,7 @@ void OnChangeSuperuser(wxCommandEvent &ev); void OnChangeSpin(wxSpinEvent &ev); void OnChangeCal(wxCalendarEvent &ev); + void OnChangeDate(wxDateEvent &ev); void OnGroupAdd(wxCommandEvent &ev); void OnGroupRemove(wxCommandEvent &ev); Index: dlgUser.cpp =================================================================== RCS file: /projects/pgadmin3/src/ui/dlgUser.cpp,v retrieving revision 1.39 retrieving revision 1.40 diff -Lsrc/ui/dlgUser.cpp -Lsrc/ui/dlgUser.cpp -u -w -r1.39 -r1.40 --- src/ui/dlgUser.cpp +++ src/ui/dlgUser.cpp @@ -47,6 +47,7 @@ BEGIN_EVENT_TABLE(dlgUser, dlgProperty) EVT_CALENDAR_SEL_CHANGED(XRCID("datValidUntil"),dlgUser::OnChangeCal) + EVT_DATE_CHANGED(XRCID("datValidUntil"), dlgUser::OnChangeDate) EVT_SPIN(XRCID("timValidUntil"), dlgUser::OnChangeSpin) EVT_LISTBOX_DCLICK(XRCID("lbGroupsNotIn"), dlgUser::OnGroupAdd) @@ -111,7 +112,7 @@ txtID->SetValue(NumToStr(user->GetUserId())); chkCreateDB->SetValue(user->GetCreateDatabase()); chkCreateUser->SetValue(user->GetSuperuser()); - datValidUntil->SetDate(user->GetAccountExpires()); + datValidUntil->SetValue(user->GetAccountExpires()); timValidUntil->SetTime(user->GetAccountExpires()); if (!connection->BackendMinimumVersion(7, 4)) txtName->Disable(); @@ -189,6 +190,16 @@ } +void dlgUser::OnChangeDate(wxDateEvent &ev) +{ + CheckChange(); + + bool timEn=ev.GetDate().IsValid(); + timValidUntil->Enable(timEn); + if (!timEn) + timValidUntil->SetTime(wxDefaultDateTime); +} + void dlgUser::OnChangeSpin(wxSpinEvent &ev) { CheckChange(); @@ -226,7 +237,7 @@ void dlgUser::CheckChange() { - bool timEn=datValidUntil->GetDate().IsValid(); + bool timEn=datValidUntil->GetValue().IsValid(); timValidUntil->Enable(timEn); if (!timEn) timValidUntil->SetTime(wxDefaultDateTime); @@ -399,10 +410,10 @@ options += wxT(" NOCREATEUSER"); } - if (DateToStr(datValidUntil->GetDate()) != DateToStr(user->GetAccountExpires())) + if (DateToStr(datValidUntil->GetValue()) != DateToStr(user->GetAccountExpires())) { - if (datValidUntil->GetDate().IsValid()) - options += wxT("\n VALID UNTIL ") + qtString(DateToAnsiStr(datValidUntil->GetDate() + timValidUntil->GetValue())); + if (datValidUntil->GetValue().IsValid()) + options += wxT("\n VALID UNTIL ") + qtString(DateToAnsiStr(datValidUntil->GetValue() + timValidUntil->GetValue())); else options += wxT("\n VALID UNTIL 'infinity'"); } @@ -498,8 +509,8 @@ sql += wxT(" CREATEDB"); if (createUser) sql += wxT(" CREATEUSER"); - if (datValidUntil->GetDate().IsValid()) - sql += wxT("\n VALID UNTIL ") + qtString(DateToAnsiStr(datValidUntil->GetDate() + timValidUntil->GetValue())); + if (datValidUntil->GetValue().IsValid()) + sql += wxT("\n VALID UNTIL ") + qtString(DateToAnsiStr(datValidUntil->GetValue() + timValidUntil->GetValue())); else sql += wxT("\n VALID UNTIL 'infinity'"); sql += wxT(";\n"); Index: calbox.cpp =================================================================== RCS file: /projects/pgadmin3/src/ui/calbox.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -Lsrc/ui/calbox.cpp -Lsrc/ui/calbox.cpp -u -w -r1.16 -r1.17 --- src/ui/calbox.cpp +++ src/ui/calbox.cpp @@ -13,6 +13,43 @@ #include "calbox.h" + +#if pgUSE_WX_CAL + + +wxCalendarBox::wxCalendarBox(wxWindow *parent, + wxWindowID id, + const wxDateTime& date, + const wxPoint& pos, + const wxSize& size) +: wxDPC(parent, id, date, pos, size, wxDP_DROPDOWN|wxDP_SHOWCENTURY|wxDP_ALLOWNONE) +{ +} + +wxCalendarBox::wxCalendarBox() : wxDPC() +{ +} + +#else + +#if defined(__WXMSW__) + #define TXTCTRL_FLAGS wxNO_BORDER + #define CALBORDER 0 + #define TXTPOSX 0 + #define TXTPOSY 1 +#elif defined(__WXGTK__) + #define TXTCTRL_FLAGS 0 + #define CALBORDER 4 + #define TXTPOSX 0 + #define TXTPOSY 0 +#else + #define TXTCTRL_FLAGS 0 + #define CALBORDER 4 + #define TXTPOSX 0 + #define TXTPOSY 0 +#endif + + #define CTRLID_TXT 101 #define CTRLID_CAL 102 #define CTRLID_BTN 103 @@ -22,6 +59,7 @@ EVT_BUTTON(CTRLID_BTN, wxCalendarBox::OnClick) EVT_TEXT(CTRLID_TXT, wxCalendarBox::OnText) EVT_CHILD_FOCUS(wxCalendarBox::OnChildSetFocus) + EVT_SIZE(wxCalendarBox::OnSize) END_EVENT_TABLE() IMPLEMENT_DYNAMIC_CLASS(wxCalendarBox, wxControl) @@ -61,8 +99,7 @@ return false; } - SetWindowStyle(style | wxWANTS_CHARS); - SetFont(parent->GetFont()); + InheritAttributes(); wxSize cs=GetClientSize(); wxSize bs=ConvertDialogToPixels(wxSize(10, 0)); @@ -83,12 +120,12 @@ dc.SelectObject(wxNullBitmap); } - m_txt=new wxTextCtrl(this, CTRLID_TXT, txt, wxPoint(0,0), wxSize(cs.x-bs.x-1, cs.y), wxNO_BORDER); + m_txt=new wxTextCtrl(this, CTRLID_TXT, txt, wxDefaultPosition, size, TXTCTRL_FLAGS); m_txt->Connect(wxID_ANY, wxID_ANY, wxEVT_KEY_DOWN, wxKeyEventHandler(wxCalendarBox::OnEditKey), 0, this); m_txt->Connect(wxID_ANY, wxID_ANY, wxEVT_KILL_FOCUS, wxFocusEventHandler(wxCalendarBox::OnKillFocus), 0, this); SetFormat(wxT("%x")); - m_btn = new wxBitmapButton(this, CTRLID_BTN, bmp, wxPoint(cs.x - bs.x, 0), wxSize(bs.x, cs.y)); + m_btn = new wxBitmapButton(this, CTRLID_BTN, bmp, wxDefaultPosition, bs); m_dlg = new wxDialog(this, CTRLID_CAL, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER); m_dlg->SetFont(GetFont()); @@ -118,12 +155,6 @@ wxPoint yearPosition = yearControl->GetPosition(); -#ifdef __WXMSW__ -#define CALBORDER 0 -#else -#define CALBORDER 4 -#endif - width = yearPosition.x + yearSize.x+2+CALBORDER/2; if (width < calSize.x-4) width = calSize.x-4; @@ -138,12 +169,13 @@ yearControl->SetSize(width-yearSize.x-CALBORDER/2, yearPosition.y, yearSize.x, yearSize.y); m_cal->GetMonthControl()->Move(0, 0); + SetBestFittingSize(size); panel->SetClientSize(width+CALBORDER/2, calSize.y-2+CALBORDER); m_dlg->SetClientSize(panel->GetSize()); - return TRUE; + return true; } @@ -189,6 +221,31 @@ } +wxSize wxCalendarBox::DoGetBestSize() const +{ + int bh=m_btn->GetBestSize().y; + int eh=m_txt->GetBestSize().y; + return wxSize(DEFAULT_ITEM_WIDTH, bh > eh ? bh : eh); +} + + +void wxCalendarBox::OnSize(wxSizeEvent& event) +{ + if ( m_btn ) + { + wxSize sz = GetClientSize(); + + wxSize bs=m_btn->GetSize(); + int eh=m_txt->GetBestSize().y; + + m_txt->SetSize(TXTPOSX, TXTPOSY, sz.x-bs.x-TXTPOSX, sz.y > eh ? eh-TXTPOSY : sz.y-TXTPOSY); + m_btn->SetSize(sz.x - bs.x, 0, bs.x, sz.y); + } + + event.Skip(); +} + + bool wxCalendarBox::Show(bool show) { if ( !wxControl::Show(show) ) @@ -281,7 +338,7 @@ } -wxDateTime wxCalendarBox::GetDate() +wxDateTime wxCalendarBox::GetValue() { wxDateTime dt; wxString txt=m_txt->GetValue(); @@ -293,7 +350,7 @@ } -bool wxCalendarBox::SetDate(const wxDateTime& date) +bool wxCalendarBox::SetValue(const wxDateTime& date) { bool retval=false; @@ -428,11 +485,7 @@ wxString txt=m_txt->GetValue(); wxDateTime dt; if (!txt.IsEmpty()) - { dt.ParseFormat(txt, m_format); - if (!dt.IsValid()) - return; - } wxCalendarEvent cev(m_cal, wxEVT_CALENDAR_SEL_CHANGED); cev.SetEventObject(this); @@ -459,3 +512,4 @@ else ev.Skip(); } +#endif Index: xh_calb.cpp =================================================================== RCS file: /projects/pgadmin3/src/ui/xh_calb.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -Lsrc/ui/xh_calb.cpp -Lsrc/ui/xh_calb.cpp -u -w -r1.4 -r1.5 --- src/ui/xh_calb.cpp +++ src/ui/xh_calb.cpp @@ -19,9 +19,12 @@ wxCalendarBoxXmlHandler::wxCalendarBoxXmlHandler() : wxXmlResourceHandler() { +#if pgUSE_WX_CAL +#else XRC_ADD_STYLE(wxCAL_SUNDAY_FIRST); XRC_ADD_STYLE(wxCAL_MONDAY_FIRST); XRC_ADD_STYLE(wxCAL_SHOW_HOLIDAYS); +#endif AddWindowStyles(); } @@ -31,12 +34,23 @@ { XRC_MAKE_INSTANCE(calendar, wxCalendarBox); +#if pgUSE_WX_CAL + calendar->Create(m_parentAsWindow, + GetID(), + wxDefaultDateTime, + GetPosition(), GetSize(), + wxDP_DEFAULT | wxDP_SHOWCENTURY | wxDP_ALLOWNONE, + wxDefaultValidator, + GetName()); + +#else calendar->Create(m_parentAsWindow, GetID(), wxDefaultDateTime, GetPosition(), GetSize(), GetStyle(), GetName()); +#endif SetupWindow(calendar); Index: timespin.cpp =================================================================== RCS file: /projects/pgadmin3/src/ui/timespin.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -Lsrc/ui/timespin.cpp -Lsrc/ui/timespin.cpp -u -w -r1.7 -r1.8 --- src/ui/timespin.cpp +++ src/ui/timespin.cpp @@ -23,6 +23,7 @@ EVT_SPIN_UP(CTRLID_SPN, wxTimeSpinCtrl::OnSpinUp) EVT_SPIN_DOWN(CTRLID_SPN, wxTimeSpinCtrl::OnSpinDown) EVT_SET_FOCUS(wxTimeSpinCtrl::OnSetFocus) + EVT_SIZE(wxTimeSpinCtrl::OnSize) END_EVENT_TABLE() @@ -75,9 +76,29 @@ canWrap = (style & wxSP_WRAP) != 0; SetMax(24*60*60 -1); + SetBestFittingSize(size); + return true; } +#define TXTPOSX 0 +#define TXTPOSY 0 +void wxTimeSpinCtrl::OnSize(wxSizeEvent& event) +{ + if ( m_spn ) + { + wxSize sz = GetClientSize(); + + wxSize ss=m_spn->GetSize(); + int eh=m_txt->GetBestSize().y; + + m_txt->SetSize(TXTPOSX, TXTPOSY, sz.x-ss.x-TXTPOSX, sz.y > eh ? eh-TXTPOSY : sz.y-TXTPOSY); + m_spn->SetSize(sz.x - ss.x, 0, ss.x, sz.y); + } + + event.Skip(); +} + bool wxTimeSpinCtrl::Destroy() { @@ -103,6 +124,12 @@ } +wxSize wxTimeSpinCtrl::DoGetBestSize() const +{ + return wxSize(DEFAULT_ITEM_WIDTH, m_txt->GetBestSize().y); +} + + bool wxTimeSpinCtrl::Enable(bool enable) { if ( !wxControl::Enable(enable) ) Index: dlgSchedule.cpp =================================================================== RCS file: /projects/pgadmin3/src/agent/dlgSchedule.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -Lsrc/agent/dlgSchedule.cpp -Lsrc/agent/dlgSchedule.cpp -u -w -r1.22 -r1.23 --- src/agent/dlgSchedule.cpp +++ src/agent/dlgSchedule.cpp @@ -92,11 +92,11 @@ recId = schedule->GetRecId(); txtID->SetValue(NumToStr(recId)); chkEnabled->SetValue(schedule->GetEnabled()); - calStart->SetDate(schedule->GetStart()); + calStart->SetValue(schedule->GetStart()); timStart->SetTime(schedule->GetStart()); if (schedule->GetEnd().IsValid()) { - calEnd->SetDate(schedule->GetEnd()); + calEnd->SetValue(schedule->GetEnd()); timEnd->SetTime(schedule->GetEnd()); } else @@ -150,7 +150,7 @@ void dlgSchedule::CheckChange() { - timEnd->Enable(calEnd->GetDate().IsValid()); + timEnd->Enable(calEnd->GetValue().IsValid()); wxString name=GetName(); bool enable; @@ -165,7 +165,7 @@ enable=true; } CheckValid(enable, !name.IsEmpty(), _("Please specify name.")); - CheckValid(enable, calStart->GetDate().IsValid(), _("Please specify start date.")); + CheckValid(enable, calStart->GetValue().IsValid(), _("Please specify start date.")); EnableOK(enable); } @@ -221,10 +221,10 @@ + wxT("'") + ChkListBox2PgArray(chkMonthdays) + wxT("', ") + wxT("'") + ChkListBox2PgArray(chkMonths) + wxT("', ") + BoolToStr(chkEnabled->GetValue()) + wxT(", ") - + wxT("'") + DateToAnsiStr(calStart->GetDate() + timStart->GetValue()) + wxT("'"); + + wxT("'") + DateToAnsiStr(calStart->GetValue() + timStart->GetValue()) + wxT("'"); - if (calEnd->GetDate().IsValid()) - sql += wxT(", '") + DateToAnsiStr(calEnd->GetDate() + timEnd->GetValue()) + wxT("'"); + if (calEnd->GetValue().IsValid()) + sql += wxT(", '") + DateToAnsiStr(calEnd->GetValue() + timEnd->GetValue()) + wxT("'"); else sql += wxT(", NULL"); @@ -265,30 +265,30 @@ vars.Append(wxT("jscenabled = ") + BoolToStr(chkEnabled->IsChecked())); } - if (calStart->GetDate() + timStart->GetValue() != schedule->GetStart()) + if (calStart->GetValue() + timStart->GetValue() != schedule->GetStart()) { if (!vars.IsEmpty()) vars.Append(wxT(", ")); - vars.Append(wxT("jscstart = '") + DateToAnsiStr(calStart->GetDate() + timStart->GetValue()) + wxT("'")); + vars.Append(wxT("jscstart = '") + DateToAnsiStr(calStart->GetValue() + timStart->GetValue()) + wxT("'")); } - if (calEnd->GetDate().IsValid()) + if (calEnd->GetValue().IsValid()) { if (schedule->GetEnd().IsValid()) { - if (calEnd->GetDate() + timEnd->GetValue() != schedule->GetEnd()) + if (calEnd->GetValue() + timEnd->GetValue() != schedule->GetEnd()) { if (!vars.IsEmpty()) vars.Append(wxT(", ")); - vars.Append(wxT("jscend = '") + DateToAnsiStr(calEnd->GetDate() + timEnd->GetValue()) + wxT("'")); + vars.Append(wxT("jscend = '") + DateToAnsiStr(calEnd->GetValue() + timEnd->GetValue()) + wxT("'")); } } else { if (!vars.IsEmpty()) vars.Append(wxT(", ")); - vars.Append(wxT("jscend = '") + DateToAnsiStr(calEnd->GetDate() + wxTimeSpan()) + wxT("'")); + vars.Append(wxT("jscend = '") + DateToAnsiStr(calEnd->GetValue() + wxTimeSpan()) + wxT("'")); } } else Index: dlgUser.xrc =================================================================== RCS file: /projects/pgadmin3/src/ui/common/dlgUser.xrc,v retrieving revision 1.22 retrieving revision 1.23 diff -Lsrc/ui/common/dlgUser.xrc -Lsrc/ui/common/dlgUser.xrc -u -w -r1.22 -r1.23 --- src/ui/common/dlgUser.xrc +++ src/ui/common/dlgUser.xrc @@ -46,11 +46,11 @@ 70,70d - 65,15d + 65,-1d 140,70d - 65,12d + 65,-1d