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
This commit is contained in:
Vadim Zeitlin
1999-12-22 00:16:02 +00:00
parent 5f287370dd
commit be4017f89b
5 changed files with 92 additions and 38 deletions

View File

@@ -15,7 +15,7 @@ wxBase:
- wxLog functions are now (more) MT-safe - wxLog functions are now (more) MT-safe
- wxStopWatch class, timer functions have more chances to return correct - wxStopWatch class, timer functions have more chances to return correct
results for your platform (use ANSI functions where available) 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 - buffer overflows in wxString and wxLog classes fixed (if snprintf() function
is available) is available)
- wxArray::RemoveAt() replaces deprectaed wxArray::Remove(index) - wxArray::RemoveAt() replaces deprectaed wxArray::Remove(index)
@@ -37,6 +37,7 @@ all (GUI):
wxMSW: wxMSW:
- implemented setting colours for push buttons
- wxTreeCtrl::IsVisible() bug fixed (thanks to Gary Chessun) - wxTreeCtrl::IsVisible() bug fixed (thanks to Gary Chessun)
- tooltips work with wxRadioBox - tooltips work with wxRadioBox
- returning FALSE from OnPrintPage() aborts printing - returning FALSE from OnPrintPage() aborts printing

View File

@@ -791,6 +791,15 @@ public:
// returns TRUE if the date is in the given range // returns TRUE if the date is in the given range
inline bool IsBetween(const wxDateTime& t1, const wxDateTime& t2) const; 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) // arithmetics with dates (see also below for more operators)
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------

View File

@@ -16,6 +16,8 @@
#error "This file is only included by wx/datetime.h, don't include it manually!" #error "This file is only included by wx/datetime.h, don't include it manually!"
#endif #endif
#define MILLISECONDS_PER_DAY 86400000l
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxDateTime construction // wxDateTime construction
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -169,6 +171,32 @@ bool wxDateTime::IsBetween(const wxDateTime& t1, const wxDateTime& t2) const
return IsEqualTo(t1) || IsEqualTo(t2) || IsStrictlyBetween(t1, t2); 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 // wxDateTime arithmetics
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -401,3 +429,4 @@ wxDateSpan& wxDateSpan::Neg()
return *this; return *this;
} }
#undef MILLISECONDS_PER_DAY

View File

@@ -1545,7 +1545,7 @@ wxDateTime::wxDateTime_t wxDateTime::GetWeekOfMonth(const TimeZone& tz) const
wxDateTime& wxDateTime::SetToYearDay(wxDateTime::wxDateTime_t yday) wxDateTime& wxDateTime::SetToYearDay(wxDateTime::wxDateTime_t yday)
{ {
int year = GetYear(); int year = GetYear();
wxCHECK_MSG( (0 < yday) && (yday < GetNumberOfDays(year)), wxCHECK_MSG( (0 < yday) && (yday <= GetNumberOfDays(year)),
ms_InvDateTime, _T("invalid year day") ); ms_InvDateTime, _T("invalid year day") );
bool isLeap = IsLeapYear(year); bool isLeap = IsLeapYear(year);
@@ -2400,6 +2400,19 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
return (wxChar *)NULL; 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; input = result;
} }
break; break;
@@ -2459,7 +2472,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
} }
haveMon = TRUE; haveMon = TRUE;
mon = (Month)num; mon = (Month)(num - 1);
break; break;
case _T('M'): // minute as a decimal number (00-59) case _T('M'): // minute as a decimal number (00-59)
@@ -2554,6 +2567,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
min = tm.min; min = tm.min;
sec = tm.sec; sec = tm.sec;
} }
break;
case _T('w'): // weekday as a number (0-6), Sunday = 0 case _T('w'): // weekday as a number (0-6), Sunday = 0
if ( !GetNumericToken(input, &num) || (wday > 6) ) if ( !GetNumericToken(input, &num) || (wday > 6) )
@@ -2687,14 +2701,14 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
break; break;
case _T('Y'): // year with century case _T('Y'): // year with century
if ( !GetNumericToken(input, &num) || !num || (num > 366) ) if ( !GetNumericToken(input, &num) )
{ {
// no match // no match
return (wxChar *)NULL; return (wxChar *)NULL;
} }
haveYDay = TRUE; haveYear = TRUE;
yday = (wxDateTime_t)num; year = (wxDateTime_t)num;
break; break;
case _T('Z'): // timezone name case _T('Z'): // timezone name
@@ -2726,7 +2740,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
// take this date as default // take this date as default
tmDef = dateDef.GetTm(); tmDef = dateDef.GetTm();
} }
else if ( IsValid() ) else if ( m_time != 0 )
{ {
// if this date is valid, don't change it // if this date is valid, don't change it
tmDef = GetTm(); tmDef = GetTm();
@@ -2750,11 +2764,25 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
// also always ignore the week day // also always ignore the week day
if ( haveMon && haveDay ) if ( haveMon && haveDay )
{ {
if ( mday > GetNumOfDaysInMonth(tm.year, mon) )
{
wxLogDebug(_T("bad month day in wxDateTime::ParseFormat"));
return (wxChar *)NULL;
}
tm.mon = mon; tm.mon = mon;
tm.mday = mday; tm.mday = mday;
} }
else if ( haveYDay ) 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 tm2 = wxDateTime(1, Jan, tm.year).SetToYearDay(yday).GetTm();
tm.mon = tm2.mon; tm.mon = tm2.mon;

View File

@@ -198,18 +198,27 @@ void wxButton::SetDefault()
// don't do it with the owner drawn buttons because it will reset // don't do it with the owner drawn buttons because it will reset
// BS_OWNERDRAW style bit too (BS_OWNERDRAW & BS_DEFPUSHBUTTON != 0)! // BS_OWNERDRAW style bit too (BS_OWNERDRAW & BS_DEFPUSHBUTTON != 0)!
if ( !(style & BS_OWNERDRAW) ) if ( (style & BS_OWNERDRAW) != BS_OWNERDRAW )
{ {
style &= ~BS_DEFPUSHBUTTON; style &= ~BS_DEFPUSHBUTTON;
SendMessage(GetHwndOf(btnOldDefault), BM_SETSTYLE, style, 1L); 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 // set this button as the default
long style = GetWindowLong(GetHwnd(), GWL_STYLE); long style = GetWindowLong(GetHwnd(), GWL_STYLE);
if ( (style & BS_OWNERDRAW) != BS_OWNERDRAW )
{
style |= BS_DEFPUSHBUTTON; style |= BS_DEFPUSHBUTTON;
SendMessage(GetHwnd(), BM_SETSTYLE, style, 1L); SendMessage(GetHwnd(), BM_SETSTYLE, style, 1L);
} }
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// helpers // helpers
@@ -248,24 +257,13 @@ bool wxButton::MSWCommand(WXUINT param, WXWORD id)
long wxButton::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) long wxButton::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{ {
// make sure that we won't have BS_DEFPUSHBUTTON style any more if the // when we receive focus, we want to become the default button in our
// focus is being transfered to another button with the same parent - // parent panel
// otherwise, we could finish with 2 default buttons inside one panel if ( nMsg == WM_SETFOCUS )
if ( (nMsg == WM_KILLFOCUS) &&
(GetWindowLong(GetHwnd(), GWL_STYLE) & BS_DEFPUSHBUTTON) )
{ {
wxWindow *parent = GetParent(); SetDefault();
wxWindow *win = wxFindWinFromHandle((WXHWND)wParam);
if ( win && win->GetParent() == parent ) // let the default processign take place too
{
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...
}
} }
// let the base class do all real processing // let the base class do all real processing
@@ -483,17 +481,6 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis)
::DeleteObject(hbrushBackground); ::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; return TRUE;
} }