1 /* 2 * Copyright 2007-2008, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _CALENDAR_VIEW_H_ 6 #define _CALENDAR_VIEW_H_ 7 8 9 #include "DateTime.h" 10 11 12 #include <Invoker.h> 13 #include <List.h> 14 #include <String.h> 15 #include <View.h> 16 17 18 class BMessage; 19 20 21 namespace BPrivate { 22 23 24 enum week_start { 25 B_WEEK_START_MONDAY, 26 B_WEEK_START_SUNDAY 27 }; 28 29 30 class BCalendarView : public BView, public BInvoker { 31 public: 32 BCalendarView(BRect frame, const char *name, 33 uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP, 34 uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); 35 36 BCalendarView(BRect frame, const char *name, week_start start, 37 uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP, 38 uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); 39 40 virtual ~BCalendarView(); 41 42 BCalendarView(BMessage *archive); 43 static BArchivable* Instantiate(BMessage *archive); 44 virtual status_t Archive(BMessage *archive, bool deep = true) const; 45 46 virtual void AttachedToWindow(); 47 virtual void DetachedFromWindow(); 48 49 virtual void AllAttached(); 50 virtual void AllDetached(); 51 52 virtual void FrameMoved(BPoint newPosition); 53 virtual void FrameResized(float width, float height); 54 55 virtual void Draw(BRect updateRect); 56 57 virtual void DrawDay(BView *owner, BRect frame, const char *text, 58 bool isSelected = false, bool isEnabled = true, 59 bool focus = false); 60 virtual void DrawDayName(BView *owner, BRect frame, const char *text); 61 virtual void DrawWeekNumber(BView *owner, BRect frame, const char *text); 62 63 virtual void MessageReceived(BMessage *message); 64 65 uint32 SelectionCommand() const; 66 BMessage* SelectionMessage() const; 67 virtual void SetSelectionMessage(BMessage *message); 68 69 uint32 InvocationCommand() const; 70 BMessage* InvocationMessage() const; 71 virtual void SetInvocationMessage(BMessage *message); 72 73 virtual void WindowActivated(bool state); 74 virtual void MakeFocus(bool state = true); 75 virtual status_t Invoke(BMessage* message = NULL); 76 77 virtual void MouseUp(BPoint point); 78 virtual void MouseDown(BPoint where); 79 virtual void MouseMoved(BPoint point, uint32 code, 80 const BMessage *dragMessage); 81 82 virtual void KeyDown(const char *bytes, int32 numBytes); 83 84 virtual BHandler* ResolveSpecifier(BMessage *message, int32 index, 85 BMessage *specifier, int32 form, const char *property); 86 virtual status_t GetSupportedSuites(BMessage *data); 87 virtual status_t Perform(perform_code code, void* arg); 88 89 virtual void ResizeToPreferred(); 90 virtual void GetPreferredSize(float *width, float *height); 91 92 int32 Day() const; 93 int32 Year() const; 94 int32 Month() const; 95 96 BDate Date() const; 97 bool SetDate(const BDate &date); 98 bool SetDate(int32 year, int32 month, int32 day); 99 100 week_start WeekStart() const; 101 void SetWeekStart(week_start start); 102 103 bool IsDayNameHeaderVisible() const; 104 void SetDayNameHeaderVisible(bool visible); 105 106 bool IsWeekNumberHeaderVisible() const; 107 void SetWeekNumberHeaderVisible(bool visible); 108 109 private: 110 void _InitObject(); 111 112 void _SetToDay(); 113 void _GetYearMonth(int32 *year, int32 *month) const; 114 void _GetPreferredSize(float *width, float *height); 115 116 void _SetupDayNames(); 117 void _SetupDayNumbers(); 118 void _SetupWeekNumbers(); 119 120 void _DrawDays(); 121 void _DrawFocusRect(); 122 void _DrawDayHeader(); 123 void _DrawWeekHeader(); 124 void _DrawDay(int32 curRow, int32 curColumn, 125 int32 row, int32 column, int32 counter, 126 BRect frame, const char *text, bool focus = false); 127 void _DrawItem(BView *owner, BRect frame, const char *text, 128 bool isSelected = false, bool isEnabled = true, 129 bool focus = false); 130 131 void _UpdateSelection(); 132 BRect _FirstCalendarItemFrame() const; 133 BRect _SetNewSelectedDay(const BPoint &where); 134 135 BCalendarView(const BCalendarView &view); 136 BCalendarView& operator=(const BCalendarView &view); 137 138 private: 139 struct Selection { 140 Selection() 141 : row(0), column(0) { } 142 143 void SetTo(int32 _row, int32 _column) 144 { row = _row; column = _column; } 145 146 int32 row; 147 int32 column; 148 149 Selection& operator=(const Selection &s) 150 { row = s.row; column = s.column; return *this; } 151 152 bool operator==(const Selection &s) const 153 { return row == s.row && column == s.column; } 154 155 bool operator!=(const Selection &s) const 156 { return row != s.row || column != s.column; } 157 }; 158 BRect _RectOfDay(const Selection &selection) const; 159 160 BMessage *fSelectionMessage; 161 162 int32 fDay; 163 int32 fYear; 164 int32 fMonth; 165 166 Selection fFocusedDay; 167 bool fFocusChanged; 168 Selection fNewFocusedDay; 169 170 Selection fSelectedDay; 171 Selection fNewSelectedDay; 172 bool fSelectionChanged; 173 174 week_start fWeekStart; 175 bool fDayNameHeaderVisible; 176 bool fWeekNumberHeaderVisible; 177 178 BString fDayNames[7]; 179 BString fWeekNumbers[6]; 180 BString fDayNumbers[6][7]; 181 }; 182 183 184 } // namespace BPrivate 185 186 187 #endif // _CALENDAR_VIEW_H_ 188