1 /* 2 * Copyright 2007-2011, 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 <Locale.h> 15 #include <String.h> 16 #include <View.h> 17 18 19 class BMessage; 20 21 22 namespace BPrivate { 23 24 25 class BCalendarView : public BView, public BInvoker { 26 public: 27 BCalendarView(BRect frame, const char* name, 28 uint32 resizeMask = B_FOLLOW_LEFT 29 | B_FOLLOW_TOP, 30 uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS 31 | B_NAVIGABLE); 32 33 BCalendarView(const char* name, 34 uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS 35 | B_NAVIGABLE); 36 37 virtual ~BCalendarView(); 38 39 BCalendarView(BMessage* archive); 40 static BArchivable* Instantiate(BMessage* archive); 41 virtual status_t Archive(BMessage* archive, 42 bool deep = true) const; 43 44 virtual void AttachedToWindow(); 45 46 virtual void FrameResized(float width, float height); 47 48 virtual void Draw(BRect updateRect); 49 50 virtual void DrawDay(BView* owner, BRect frame, 51 const char* text, bool isSelected = false, 52 bool isEnabled = true, bool focus = false); 53 virtual void DrawDayName(BView* owner, BRect frame, 54 const char* text); 55 virtual void DrawWeekNumber(BView* owner, BRect frame, 56 const char* text); 57 58 uint32 SelectionCommand() const; 59 BMessage* SelectionMessage() const; 60 virtual void SetSelectionMessage(BMessage* message); 61 62 uint32 InvocationCommand() const; 63 BMessage* InvocationMessage() const; 64 virtual void SetInvocationMessage(BMessage* message); 65 66 virtual void MakeFocus(bool state = true); 67 virtual status_t Invoke(BMessage* message = NULL); 68 69 virtual void MouseDown(BPoint where); 70 71 virtual void KeyDown(const char* bytes, int32 numBytes); 72 73 virtual void ResizeToPreferred(); 74 virtual void GetPreferredSize(float* width, float* height); 75 76 virtual BSize MaxSize(); 77 virtual BSize MinSize(); 78 virtual BSize PreferredSize(); 79 80 int32 Day() const; 81 int32 Year() const; 82 int32 Month() const; 83 84 BDate Date() const; 85 bool SetDate(const BDate& date); 86 bool SetDate(int32 year, int32 month, int32 day); 87 88 BWeekday StartOfWeek() const; 89 void SetStartOfWeek(BWeekday startOfWeek); 90 91 bool IsDayNameHeaderVisible() const; 92 void SetDayNameHeaderVisible(bool visible); 93 94 bool IsWeekNumberHeaderVisible() const; 95 void SetWeekNumberHeaderVisible(bool visible); 96 97 private: 98 struct Selection { 99 Selection() 100 : row(0), column(0) 101 { 102 } 103 104 void 105 SetTo(int32 _row, int32 _column) 106 { 107 row = _row; 108 column = _column; 109 } 110 111 int32 row; 112 int32 column; 113 114 Selection& operator=(const Selection& s) 115 { 116 row = s.row; 117 column = s.column; 118 return *this; 119 } 120 121 bool operator==(const Selection& s) const 122 { 123 return row == s.row 124 && column == s.column; 125 } 126 127 bool operator!=(const Selection& s) const 128 { 129 return row != s.row 130 || column != s.column; 131 } 132 }; 133 134 void _InitObject(); 135 136 void _SetToDay(); 137 void _GetYearMonthForSelection( 138 const Selection& selection, int32* year, 139 int32* month) const; 140 void _GetPreferredSize(float* width, float* height); 141 142 void _SetupDayNames(); 143 void _SetupDayNumbers(); 144 void _SetupWeekNumbers(); 145 146 void _DrawDays(); 147 void _DrawFocusRect(); 148 void _DrawDayHeader(); 149 void _DrawWeekHeader(); 150 void _DrawDay(int32 curRow, int32 curColumn, 151 int32 row, int32 column, int32 counter, 152 BRect frame, const char* text, 153 bool focus = false); 154 void _DrawItem(BView* owner, BRect frame, 155 const char* text, bool isSelected = false, 156 bool isEnabled = true, bool focus = false); 157 158 void _UpdateSelection(); 159 BRect _FirstCalendarItemFrame() const; 160 BRect _SetNewSelectedDay(const BPoint& where); 161 162 BRect _RectOfDay(const Selection& selection) const; 163 164 private: 165 BMessage* fSelectionMessage; 166 167 BDate fDate; 168 169 Selection fFocusedDay; 170 Selection fNewFocusedDay; 171 bool fFocusChanged; 172 173 Selection fSelectedDay; 174 Selection fNewSelectedDay; 175 bool fSelectionChanged; 176 177 int32 fStartOfWeek; 178 bool fDayNameHeaderVisible; 179 bool fWeekNumberHeaderVisible; 180 181 BString fDayNames[7]; 182 BString fWeekNumbers[6]; 183 BString fDayNumbers[6][7]; 184 185 // hide copy constructor & assignment 186 BCalendarView(const BCalendarView& view); 187 BCalendarView& operator=(const BCalendarView& view); 188 }; 189 190 191 } // namespace BPrivate 192 193 194 #endif // _CALENDAR_VIEW_H_ 195