From be4017f89bcffe7773934677f11964465e40c87a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 22 Dec 1999 00:16:02 +0000 Subject: [PATCH] 1. coloured buttons seem to work 2. wxDateTime::ParseFormat() starts to work git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5061 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 3 ++- include/wx/datetime.h | 9 ++++++++ include/wx/datetime.inl | 29 ++++++++++++++++++++++++ src/common/datetime.cpp | 40 ++++++++++++++++++++++++++++----- src/msw/button.cpp | 49 +++++++++++++++-------------------------- 5 files changed, 92 insertions(+), 38 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index d213d1c4b3..dc57c3efc7 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -15,7 +15,7 @@ wxBase: - wxLog functions are now (more) MT-safe - wxStopWatch class, timer functions have more chances to return correct results for your platform (use ANSI functions where available) -- wxString::ToLong, ToULong, ToDouble methods added +- wxString::ToLong, ToULong, ToDouble methods and Format() static one added - buffer overflows in wxString and wxLog classes fixed (if snprintf() function is available) - wxArray::RemoveAt() replaces deprectaed wxArray::Remove(index) @@ -37,6 +37,7 @@ all (GUI): wxMSW: +- implemented setting colours for push buttons - wxTreeCtrl::IsVisible() bug fixed (thanks to Gary Chessun) - tooltips work with wxRadioBox - returning FALSE from OnPrintPage() aborts printing diff --git a/include/wx/datetime.h b/include/wx/datetime.h index 74927e3c7f..d0de3f9773 100644 --- a/include/wx/datetime.h +++ b/include/wx/datetime.h @@ -791,6 +791,15 @@ public: // returns TRUE if the date is in the given range inline bool IsBetween(const wxDateTime& t1, const wxDateTime& t2) const; + // do these two objects refer to the same date? + inline bool IsSameDate(const wxDateTime& dt) const; + + // do these two objects have the same time? + inline bool IsSameTime(const wxDateTime& dt) const; + + // are these two objects equal up to given timespan? + inline bool IsEqualUpTo(const wxDateTime& dt, const wxTimeSpan& ts) const; + // arithmetics with dates (see also below for more operators) // ------------------------------------------------------------------------ diff --git a/include/wx/datetime.inl b/include/wx/datetime.inl index e0ba83042f..8be3bf69b2 100644 --- a/include/wx/datetime.inl +++ b/include/wx/datetime.inl @@ -16,6 +16,8 @@ #error "This file is only included by wx/datetime.h, don't include it manually!" #endif +#define MILLISECONDS_PER_DAY 86400000l + // ---------------------------------------------------------------------------- // wxDateTime construction // ---------------------------------------------------------------------------- @@ -169,6 +171,32 @@ bool wxDateTime::IsBetween(const wxDateTime& t1, const wxDateTime& t2) const return IsEqualTo(t1) || IsEqualTo(t2) || IsStrictlyBetween(t1, t2); } +bool wxDateTime::IsSameDate(const wxDateTime& dt) const +{ + return (m_time - dt.m_time).Abs() < MILLISECONDS_PER_DAY; +} + +bool wxDateTime::IsSameTime(const wxDateTime& dt) const +{ + // notice that we can't do something like this: + // + // m_time % MILLISECONDS_PER_DAY == dt.m_time % MILLISECONDS_PER_DAY + // + // because we have also to deal with (possibly) different DST settings! + Tm tm1 = GetTm(), + tm2 = dt.GetTm(); + + return tm1.hour == tm2.hour && + tm1.min == tm2.min && + tm1.sec == tm2.sec && + tm1.msec == tm2.msec; +} + +bool wxDateTime::IsEqualUpTo(const wxDateTime& dt, const wxTimeSpan& ts) const +{ + return IsBetween(dt.Substract(ts), dt.Add(ts)); +} + // ---------------------------------------------------------------------------- // wxDateTime arithmetics // ---------------------------------------------------------------------------- @@ -401,3 +429,4 @@ wxDateSpan& wxDateSpan::Neg() return *this; } +#undef MILLISECONDS_PER_DAY diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 47607ede47..99d5d7f0c8 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -1545,7 +1545,7 @@ wxDateTime::wxDateTime_t wxDateTime::GetWeekOfMonth(const TimeZone& tz) const wxDateTime& wxDateTime::SetToYearDay(wxDateTime::wxDateTime_t yday) { int year = GetYear(); - wxCHECK_MSG( (0 < yday) && (yday < GetNumberOfDays(year)), + wxCHECK_MSG( (0 < yday) && (yday <= GetNumberOfDays(year)), ms_InvDateTime, _T("invalid year day") ); bool isLeap = IsLeapYear(year); @@ -2400,6 +2400,19 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date, return (wxChar *)NULL; } + Tm tm = dt.GetTm(); + + haveDay = haveMon = haveYear = + haveHour = haveMin = haveSec = TRUE; + + hour = tm.hour; + min = tm.min; + sec = tm.sec; + + year = tm.year; + mon = tm.mon; + mday = tm.mday; + input = result; } break; @@ -2459,7 +2472,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date, } haveMon = TRUE; - mon = (Month)num; + mon = (Month)(num - 1); break; case _T('M'): // minute as a decimal number (00-59) @@ -2554,6 +2567,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date, min = tm.min; sec = tm.sec; } + break; case _T('w'): // weekday as a number (0-6), Sunday = 0 if ( !GetNumericToken(input, &num) || (wday > 6) ) @@ -2687,14 +2701,14 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date, break; case _T('Y'): // year with century - if ( !GetNumericToken(input, &num) || !num || (num > 366) ) + if ( !GetNumericToken(input, &num) ) { // no match return (wxChar *)NULL; } - haveYDay = TRUE; - yday = (wxDateTime_t)num; + haveYear = TRUE; + year = (wxDateTime_t)num; break; case _T('Z'): // timezone name @@ -2726,7 +2740,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date, // take this date as default tmDef = dateDef.GetTm(); } - else if ( IsValid() ) + else if ( m_time != 0 ) { // if this date is valid, don't change it tmDef = GetTm(); @@ -2750,11 +2764,25 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date, // also always ignore the week day if ( haveMon && haveDay ) { + if ( mday > GetNumOfDaysInMonth(tm.year, mon) ) + { + wxLogDebug(_T("bad month day in wxDateTime::ParseFormat")); + + return (wxChar *)NULL; + } + tm.mon = mon; tm.mday = mday; } else if ( haveYDay ) { + if ( yday > GetNumberOfDays(tm.year) ) + { + wxLogDebug(_T("bad year day in wxDateTime::ParseFormat")); + + return (wxChar *)NULL; + } + Tm tm2 = wxDateTime(1, Jan, tm.year).SetToYearDay(yday).GetTm(); tm.mon = tm2.mon; diff --git a/src/msw/button.cpp b/src/msw/button.cpp index e913563260..5c30bf807b 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -198,17 +198,26 @@ void wxButton::SetDefault() // don't do it with the owner drawn buttons because it will reset // BS_OWNERDRAW style bit too (BS_OWNERDRAW & BS_DEFPUSHBUTTON != 0)! - if ( !(style & BS_OWNERDRAW) ) + if ( (style & BS_OWNERDRAW) != BS_OWNERDRAW ) { style &= ~BS_DEFPUSHBUTTON; SendMessage(GetHwndOf(btnOldDefault), BM_SETSTYLE, style, 1L); } + else + { + // redraw the button - it will notice itself that it's not the + // default one any longer + btnOldDefault->Refresh(); + } } // set this button as the default long style = GetWindowLong(GetHwnd(), GWL_STYLE); - style |= BS_DEFPUSHBUTTON; - SendMessage(GetHwnd(), BM_SETSTYLE, style, 1L); + if ( (style & BS_OWNERDRAW) != BS_OWNERDRAW ) + { + style |= BS_DEFPUSHBUTTON; + SendMessage(GetHwnd(), BM_SETSTYLE, style, 1L); + } } // ---------------------------------------------------------------------------- @@ -248,24 +257,13 @@ bool wxButton::MSWCommand(WXUINT param, WXWORD id) long wxButton::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { - // make sure that we won't have BS_DEFPUSHBUTTON style any more if the - // focus is being transfered to another button with the same parent - - // otherwise, we could finish with 2 default buttons inside one panel - if ( (nMsg == WM_KILLFOCUS) && - (GetWindowLong(GetHwnd(), GWL_STYLE) & BS_DEFPUSHBUTTON) ) + // when we receive focus, we want to become the default button in our + // parent panel + if ( nMsg == WM_SETFOCUS ) { - wxWindow *parent = GetParent(); - wxWindow *win = wxFindWinFromHandle((WXHWND)wParam); - if ( win && win->GetParent() == parent ) - { - wxPanel *panel = wxDynamicCast(parent, wxPanel); - if ( panel ) - { - panel->SetDefaultItem(this); - } - // else: I don't know what to do - we'll still have the problem - // with multiple default buttons in a dialog... - } + SetDefault(); + + // let the default processign take place too } // let the base class do all real processing @@ -483,17 +481,6 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis) ::DeleteObject(hbrushBackground); -#if 0 - wxString s = "button state: "; - if ( selected ) - s += "selected "; - if ( pushed ) - s += "pushed "; - if ( state & ODS_FOCUS ) - s += "focused "; - wxLogStatus(s); -#endif - return TRUE; } -- 2.45.2