From 78092ae789179f1b5199224109b17898f68a9f9a Mon Sep 17 00:00:00 2001 From: Karsten Heimrich Date: Fri, 29 Aug 2008 19:26:58 +0000 Subject: [PATCH] * move DateTime and CalendarView into shared * adjust Time preflet to take that into account git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27235 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../private/shared}/CalendarView.h | 26 +++--- .../private/shared}/DateTime.h | 9 ++- .../time => kits/shared}/CalendarView.cpp | 52 ++++++------ .../time => kits/shared}/DateTime.cpp | 79 ++++++++++--------- src/kits/shared/Jamfile | 2 + src/preferences/time/BaseView.cpp | 10 ++- src/preferences/time/DateTimeEdit.cpp | 3 + src/preferences/time/DateTimeEdit.h | 18 +++-- src/preferences/time/DateTimeView.cpp | 27 ++++--- src/preferences/time/DateTimeView.h | 7 +- src/preferences/time/Jamfile | 5 +- 11 files changed, 142 insertions(+), 96 deletions(-) rename {src/preferences/time => headers/private/shared}/CalendarView.h (92%) rename {src/preferences/time => headers/private/shared}/DateTime.h (94%) rename src/{preferences/time => kits/shared}/CalendarView.cpp (97%) rename src/{preferences/time => kits/shared}/DateTime.cpp (84%) diff --git a/src/preferences/time/CalendarView.h b/headers/private/shared/CalendarView.h similarity index 92% rename from src/preferences/time/CalendarView.h rename to headers/private/shared/CalendarView.h index 5e78f86c29..b12475bd85 100644 --- a/src/preferences/time/CalendarView.h +++ b/headers/private/shared/CalendarView.h @@ -1,5 +1,5 @@ /* - * Copyright 2007, Haiku, Inc. All Rights Reserved. + * Copyright 2007-2008, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _CALENDAR_VIEW_H_ @@ -18,6 +18,9 @@ class BMessage; +namespace BPrivate { + + enum week_start { B_WEEK_START_MONDAY, B_WEEK_START_SUNDAY @@ -50,7 +53,7 @@ class BCalendarView : public BView, public BInvoker { virtual void FrameResized(float width, float height); virtual void Draw(BRect updateRect); - + virtual void DrawDay(BView *owner, BRect frame, const char *text, bool isSelected = false, bool isEnabled = true, bool focus = false); @@ -66,14 +69,14 @@ class BCalendarView : public BView, public BInvoker { uint32 InvocationCommand() const; BMessage* InvocationMessage() const; virtual void SetInvocationMessage(BMessage *message); - + virtual void WindowActivated(bool state); virtual void MakeFocus(bool state = true); - virtual status_t Invoke(BMessage* message = NULL); + virtual status_t Invoke(BMessage* message = NULL); virtual void MouseUp(BPoint point); virtual void MouseDown(BPoint where); - virtual void MouseMoved(BPoint point, uint32 code, + virtual void MouseMoved(BPoint point, uint32 code, const BMessage *dragMessage); virtual void KeyDown(const char *bytes, int32 numBytes); @@ -89,7 +92,7 @@ class BCalendarView : public BView, public BInvoker { int32 Day() const; int32 Year() const; int32 Month() const; - + BDate Date() const; bool SetDate(const BDate &date); bool SetDate(int32 year, int32 month, int32 day); @@ -105,7 +108,7 @@ class BCalendarView : public BView, public BInvoker { private: void _InitObject(); - + void _SetToDay(); void _GetYearMonth(int32 *year, int32 *month) const; void _GetPreferredSize(float *width, float *height); @@ -119,16 +122,17 @@ class BCalendarView : public BView, public BInvoker { void _DrawDayHeader(); void _DrawWeekHeader(); void _DrawDay(int32 curRow, int32 curColumn, - int32 row, int32 column, int32 counter, + int32 row, int32 column, int32 counter, BRect frame, const char *text, bool focus = false); void _DrawItem(BView *owner, BRect frame, const char *text, - bool isSelected = false, bool isEnabled = true, + bool isSelected = false, bool isEnabled = true, bool focus = false); void _UpdateSelection(); BRect _FirstCalendarItemFrame() const; BRect _SetNewSelectedDay(const BPoint &where); + BCalendarView(const BCalendarView &view); BCalendarView& operator=(const BCalendarView &view); private: @@ -176,4 +180,8 @@ class BCalendarView : public BView, public BInvoker { BString fDayNumbers[6][7]; }; + +} // namespace BPrivate + + #endif // _CALENDAR_VIEW_H_ diff --git a/src/preferences/time/DateTime.h b/headers/private/shared/DateTime.h similarity index 94% rename from src/preferences/time/DateTime.h rename to headers/private/shared/DateTime.h index 3fe9a3ce2a..66a1a94e5d 100755 --- a/src/preferences/time/DateTime.h +++ b/headers/private/shared/DateTime.h @@ -1,5 +1,5 @@ /* - * Copyright 2007, Haiku, Inc. All Rights Reserved. + * Copyright 2007-2008, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _DATE_TIME_H_ @@ -9,6 +9,9 @@ #include +namespace BPrivate { + + enum time_type { B_GMT_TIME, B_LOCAL_TIME @@ -97,4 +100,8 @@ class BDateTime { BTime fTime; }; + +} // namespace BPrivate + + #endif // _DATE_TIME_H_ diff --git a/src/preferences/time/CalendarView.cpp b/src/kits/shared/CalendarView.cpp similarity index 97% rename from src/preferences/time/CalendarView.cpp rename to src/kits/shared/CalendarView.cpp index bfae23f9f2..070cc9b3f1 100644 --- a/src/preferences/time/CalendarView.cpp +++ b/src/kits/shared/CalendarView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2007, Haiku, Inc. All Rights Reserved. + * Copyright 2007-2008, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -15,6 +15,9 @@ #include +namespace BPrivate { + + namespace { float FontHeight(const BView *view) @@ -225,7 +228,6 @@ BCalendarView::Draw(BRect updateRect) _UpdateSelection(); UnlockLooper(); return; - } _DrawDays(); @@ -334,7 +336,7 @@ BCalendarView::MakeFocus(bool state) return; BView::MakeFocus(state); - + fFocusChanged = true; Draw(_RectOfDay(fFocusedDay)); fFocusChanged = false; @@ -408,7 +410,7 @@ BCalendarView::MouseDown(BPoint where) // try to set to new day frame = _SetNewSelectedDay(where); - + // on success if (fSelectedDay != fNewSelectedDay) { // update focus @@ -428,7 +430,7 @@ BCalendarView::MouseDown(BPoint where) } int32 clicks; - // on double click invoke + // on double click invoke BMessage *message = Looper()->CurrentMessage(); if (message->FindInt32("clicks", &clicks) == B_OK && clicks > 1) Invoke(); @@ -637,7 +639,7 @@ BCalendarView::SetDate(int32 year, int32 month, int32 day) if (fWeekNumberHeaderVisible) frame.left += frame.Width() / 8 - 1.0; - Invalidate(frame.InsetBySelf(4.0, 4.0)); + Draw(frame.InsetBySelf(4.0, 4.0)); } return true; @@ -913,22 +915,22 @@ BCalendarView::_SetupWeekNumbers() return; date.SetDate(fYear, fMonth, 1); - int32 firstDay = date.DayOfWeek(); - if (fWeekStart == B_WEEK_START_MONDAY) - firstDay -= 1; + fWeekNumbers[0].SetTo(""); + fWeekNumbers[0] << date.WeekNumber(); - const int32 kWeekNumber = date.WeekNumber(); - int32 dateWeekNumber = kWeekNumber; - if (kWeekNumber == 52 && firstDay == 0) - dateWeekNumber = 1; - - for (int32 row = 0; row < 6; ++row) { - int32 weekNumber = dateWeekNumber + row; - if (kWeekNumber == 52 && firstDay != 0 || kWeekNumber == 53) - dateWeekNumber = 0; + for (int32 row = 1; row < 5; ++row) { + date.SetDate(fYear, fMonth, date.Day() + 7); fWeekNumbers[row].SetTo(""); - fWeekNumbers[row] << weekNumber; + fWeekNumbers[row] << date.WeekNumber(); } + + if (fMonth == 12) + date.SetDate(fYear + 1, 1, 5); + else + date.SetDate(fYear, fMonth + 1, 7); + + fWeekNumbers[5].SetTo(""); + fWeekNumbers[5] << date.WeekNumber(); } @@ -981,7 +983,7 @@ BCalendarView::_DrawDays() const char *day = fDayNumbers[row][column].String(); bool focus = isFocus && focusRow == row && focusColumn == column; _DrawDay(currRow, currColumn, row, column, counter, tmp, day, focus); - + tmp.OffsetBy(tmp.Width(), 0.0); } frame.OffsetBy(0.0, frame.Height()); @@ -1086,9 +1088,9 @@ BCalendarView::_DrawItem(BView *owner, BRect frame, const char *text, { rgb_color lColor = LowColor(); rgb_color highColor = HighColor(); - + rgb_color lowColor = { 255, 255, 255, 255 }; - + if (isSelected) { SetHighColor(tint_color(lowColor, B_DARKEN_2_TINT)); SetLowColor(HighColor()); @@ -1227,8 +1229,4 @@ BCalendarView::_RectOfDay(const Selection &selection) const } -BCalendarView& -BCalendarView::operator=(const BCalendarView &view) -{ - return *this; -} +} // namespace BPrivate diff --git a/src/preferences/time/DateTime.cpp b/src/kits/shared/DateTime.cpp similarity index 84% rename from src/preferences/time/DateTime.cpp rename to src/kits/shared/DateTime.cpp index e3b5cad819..0eb4b4174b 100755 --- a/src/preferences/time/DateTime.cpp +++ b/src/kits/shared/DateTime.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2004-2006, Haiku, Inc. All Rights Reserved. + * Copyright 2004-2008, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -13,6 +13,9 @@ #include +namespace BPrivate { + + BTime::BTime() : fHour(-1), fMinute(-1), @@ -199,7 +202,7 @@ BDate::WeekNumber() const /* This algorithm is taken from: Frequently Asked Questions about Calendars - Version 2.8 Claus Tøndering 15 December 2005 + Version 2.8 Claus Tøndering 15 December 2005 Note: it will work only within the Gregorian Calendar */ @@ -207,40 +210,40 @@ BDate::WeekNumber() const if (!IsValid()) return 0; - int32 a; - int32 b; - int32 s; - int32 e; - int32 f; + int32 a; + int32 b; + int32 s; + int32 e; + int32 f; if (fMonth > 0 && fMonth < 3) { - a = fYear - 1; - b = (a / 4) - (a / 100) + (a / 400); - int32 c = ((a - 1) / 4) - ((a - 1) / 100) + ((a -1) / 400); - s = b - c; - e = 0; - f = fDay - 1 + 31 * (fMonth - 1); - } else if (fMonth >= 3 && fMonth <= 12) { - a = fYear; - b = (a / 4) - (a / 100) + (a / 400); - int32 c = ((a - 1) / 4) - ((a - 1) / 100) + ((a -1) / 400); - s = b - c; - e = s + 1; - f = fDay + ((153 * (fMonth - 3) + 2) / 5) + 58 + s; - } else - return 0; + a = fYear - 1; + b = (a / 4) - (a / 100) + (a / 400); + int32 c = ((a - 1) / 4) - ((a - 1) / 100) + ((a -1) / 400); + s = b - c; + e = 0; + f = fDay - 1 + 31 * (fMonth - 1); + } else if (fMonth >= 3 && fMonth <= 12) { + a = fYear; + b = (a / 4) - (a / 100) + (a / 400); + int32 c = ((a - 1) / 4) - ((a - 1) / 100) + ((a -1) / 400); + s = b - c; + e = s + 1; + f = fDay + ((153 * (fMonth - 3) + 2) / 5) + 58 + s; + } else + return 0; - int32 g = (a + b) % 7; - int32 d = (f + g - e) % 7; - int32 n = f + 3 - d; + int32 g = (a + b) % 7; + int32 d = (f + g - e) % 7; + int32 n = f + 3 - d; - int32 weekNumber; - if (n < 0) - weekNumber = 53 - (g -s) / 5; - else if (n > 364 + s) - weekNumber = 1; - else - weekNumber = n / 7 + 1; + int32 weekNumber; + if (n < 0) + weekNumber = 53 - (g -s) / 5; + else if (n > 364 + s) + weekNumber = 1; + else + weekNumber = n / 7 + 1; return weekNumber; } @@ -252,7 +255,7 @@ BDate::DayOfWeek() const /* This algorithm is taken from: Frequently Asked Questions about Calendars - Version 2.8 Claus Tøndering 15 December 2005 + Version 2.8 Claus Tøndering 15 December 2005 Note: it will work only within the Gregorian Calendar */ @@ -276,15 +279,15 @@ BDate::DayOfYear() const Note: this function might fail for 1582... http://en.wikipedia.org/wiki/Gregorian_calendar: - The last day of the Julian calendar was Thursday October 4, 1582 + The last day of the Julian calendar was Thursday October 4, 1582 and this was followed by the first day of the Gregorian calendar, Friday October 15, 1582 (the cycle of weekdays was not affected). */ if (!IsValid()) - return -1; + return -1; - const int kFirstDayOfMonth[2][12] = { + const int kFirstDayOfMonth[2][12] = { { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }, { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 } }; @@ -292,7 +295,7 @@ BDate::DayOfYear() const if (IsLeapYear(fYear)) return kFirstDayOfMonth[1][fMonth -1] + fDay; - return kFirstDayOfMonth[0][fMonth -1] + fDay; + return kFirstDayOfMonth[0][fMonth -1] + fDay; } @@ -481,3 +484,5 @@ BDateTime::Time_t() const // return secs_since_jan1_1970 or -1 on error return uint32(mktime(&tm_struct)); } + +} //namespace BPrivate diff --git a/src/kits/shared/Jamfile b/src/kits/shared/Jamfile index d3297a300b..fa6072c826 100644 --- a/src/kits/shared/Jamfile +++ b/src/kits/shared/Jamfile @@ -7,7 +7,9 @@ UsePrivateHeaders shared ; StaticLibrary libshared.a : AboutWindow.cpp + CalendarView.cpp ColorQuantizer.cpp CommandPipe.cpp + DateTime.cpp HashString.cpp ; diff --git a/src/preferences/time/BaseView.cpp b/src/preferences/time/BaseView.cpp index 1d67dcaaae..6a47bec9e1 100644 --- a/src/preferences/time/BaseView.cpp +++ b/src/preferences/time/BaseView.cpp @@ -8,13 +8,19 @@ */ #include "BaseView.h" -#include "DateTime.h" #include "TimeMessages.h" +#include #include +using BPrivate::BDate; +using BPrivate::BTime; +using BPrivate::BDateTime; +using BPrivate::B_LOCAL_TIME; + + TTimeBaseView::TTimeBaseView(BRect frame, const char *name) : BView(frame, name, B_FOLLOW_NONE, B_PULSE_NEEDED), fMessage(H_TIME_UPDATE) @@ -95,7 +101,7 @@ void TTimeBaseView::_SendNotices() { fMessage.MakeEmpty(); - + BDate date = BDate::CurrentDate(B_LOCAL_TIME); fMessage.AddInt32("day", date.Day()); fMessage.AddInt32("year", date.Year()); diff --git a/src/preferences/time/DateTimeEdit.cpp b/src/preferences/time/DateTimeEdit.cpp index 3468935620..943f0ebd24 100644 --- a/src/preferences/time/DateTimeEdit.cpp +++ b/src/preferences/time/DateTimeEdit.cpp @@ -16,6 +16,9 @@ #include +using BPrivate::B_LOCAL_TIME; + + TTimeEdit::TTimeEdit(BRect frame, const char *name, uint32 sections) : TSectionEdit(frame, name, sections) { diff --git a/src/preferences/time/DateTimeEdit.h b/src/preferences/time/DateTimeEdit.h index 13eac1523d..b765f1f616 100644 --- a/src/preferences/time/DateTimeEdit.h +++ b/src/preferences/time/DateTimeEdit.h @@ -12,10 +12,16 @@ #define DATETIME_H -#include "DateTime.h" #include "SectionEdit.h" +#include + + +using BPrivate::BDate; +using BPrivate::BTime; + + class TTimeEdit : public TSectionEdit { public: TTimeEdit(BRect frame, const char *name, uint32 sections); @@ -49,20 +55,20 @@ class TDateEdit : public TSectionEdit { public: TDateEdit(BRect frame, const char *name, uint32 sections); virtual ~TDateEdit(); - + virtual void InitView(); virtual void DrawSection(uint32 index, bool isfocus); virtual void DrawSeperator(uint32 index); - + virtual void SetSections(BRect area); virtual void SectionFocus(uint32 index); virtual float SeperatorWidth() const; - + virtual void DoUpPress(); virtual void DoDownPress(); - + virtual void BuildDispatch(BMessage *message); - + void SetDate(int32 year, int32 month, int32 day); private: diff --git a/src/preferences/time/DateTimeView.cpp b/src/preferences/time/DateTimeView.cpp index 5a1088214b..79ca53bd6a 100644 --- a/src/preferences/time/DateTimeView.cpp +++ b/src/preferences/time/DateTimeView.cpp @@ -11,14 +11,14 @@ #include "DateTimeView.h" #include "AnalogClock.h" -#include "CalendarView.h" #include "DateTimeEdit.h" #include "TimeMessages.h" -#include "DateTime.h" #include "TimeWindow.h" +#include #include +#include #include #include #include @@ -31,6 +31,11 @@ #include +using BPrivate::BCalendarView; +using BPrivate::BDateTime; +using BPrivate::B_LOCAL_TIME; + + #ifdef HAIKU_TARGET_PLATFORM_HAIKU # include #else @@ -133,7 +138,7 @@ DateTimeView::MessageReceived(BMessage *message) case kMsgRevert: _Revert(); break; - + default: BView::MessageReceived(message); break; @@ -159,7 +164,7 @@ DateTimeView::CheckCanRevert() void DateTimeView::_Revert() { - // Set the clock and calendar as they were at launch time + + // Set the clock and calendar as they were at launch time + // time ellapsed since application launch. fUseGmtTime = fOldUseGmtTime; @@ -180,10 +185,10 @@ DateTimeView::_Revert() BDate date = dateTime.Date(); time.SetTime(timeInfo->tm_hour, timeInfo->tm_min, timeInfo->tm_sec % 60); date.SetDate(timeInfo->tm_year + 1900, timeInfo->tm_mon + 1, - timeInfo->tm_mday); + timeInfo->tm_mday); dateTime.SetTime(time); dateTime.SetDate(date); - + set_real_time_clock(dateTime.Time_t()); } @@ -200,7 +205,7 @@ DateTimeView::_InitView() { font_height fontHeight; be_plain_font->GetHeight(&fontHeight); - float textHeight = fontHeight.descent + fontHeight.ascent + float textHeight = fontHeight.descent + fontHeight.ascent + fontHeight.leading + 6.0; // 6px border // left side @@ -232,6 +237,8 @@ DateTimeView::_InitView() fClock = new TAnalogClock(bounds, "analogClock"); AddChild(fClock); + BTime time(BTime::CurrentTime(B_LOCAL_TIME)); + fClock->SetTime(time.Hour(), time.Minute(), time.Second()); // clock radio buttons bounds.top = fClock->Frame().bottom + 10.0; @@ -241,7 +248,7 @@ DateTimeView::_InitView() bounds.left += 10.0f; bounds.top = text->Frame().bottom; - fLocalTime = new BRadioButton(bounds, "localTime", "Local Time", + fLocalTime = new BRadioButton(bounds, "localTime", "Local Time", new BMessage(kRTCUpdate)); AddChild(fLocalTime); fLocalTime->ResizeToPreferred(); @@ -251,7 +258,7 @@ DateTimeView::_InitView() new BMessage(kRTCUpdate)); AddChild(fGmtTime); fGmtTime->ResizeToPreferred(); - + if (fUseGmtTime) fGmtTime->SetValue(B_CONTROL_ON); else @@ -271,7 +278,7 @@ DateTimeView::_ReadRTCSettings() return; path.Append("RTC_time_settings"); - + BEntry entry(path.Path()); if (entry.Exists()) { BFile file(&entry, B_READ_ONLY); diff --git a/src/preferences/time/DateTimeView.h b/src/preferences/time/DateTimeView.h index 75a432bdec..8dc68a85ef 100644 --- a/src/preferences/time/DateTimeView.h +++ b/src/preferences/time/DateTimeView.h @@ -17,11 +17,16 @@ class TDateEdit; class TTimeEdit; -class BCalendarView; class BRadioButton; class TAnalogClock; +namespace BPrivate { + class BCalendarView; +} +using BPrivate::BCalendarView; + + class DateTimeView : public BView { public: DateTimeView(BRect frame); diff --git a/src/preferences/time/Jamfile b/src/preferences/time/Jamfile index a00f13607b..41c1540580 100644 --- a/src/preferences/time/Jamfile +++ b/src/preferences/time/Jamfile @@ -2,13 +2,13 @@ SubDir HAIKU_TOP src preferences time ; SetSubDirSupportedPlatformsBeOSCompatible ; +UsePrivateHeaders shared ; UsePrivateSystemHeaders ; Preference Time : AnalogClock.cpp BaseView.cpp Bitmaps.cpp - CalendarView.cpp DateTimeEdit.cpp SectionEdit.cpp DateTimeView.cpp @@ -17,8 +17,7 @@ Preference Time : TimeWindow.cpp TZDisplay.cpp ZoneView.cpp - DateTime.cpp - : be + : be libshared.a : Time.rdef ;