2 * Copyright 2007-2011, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 #ifndef _CALENDAR_VIEW_H_
6 #define _CALENDAR_VIEW_H_
12 #include <DateFormat.h>
26 class BCalendarView
: public BView
, public BInvoker
{
28 BCalendarView(BRect frame
, const char* name
,
29 uint32 resizeMask
= B_FOLLOW_LEFT_TOP
,
30 uint32 flags
= B_WILL_DRAW
| B_FRAME_EVENTS
31 | B_NAVIGABLE
| B_PULSE_NEEDED
);
33 BCalendarView(const char* name
,
34 uint32 flags
= B_WILL_DRAW
| B_FRAME_EVENTS
35 | B_NAVIGABLE
| B_PULSE_NEEDED
);
37 virtual ~BCalendarView();
39 BCalendarView(BMessage
* archive
);
40 static BArchivable
* Instantiate(BMessage
* archive
);
41 virtual status_t
Archive(BMessage
* archive
,
42 bool deep
= true) const;
44 virtual void AttachedToWindow();
46 virtual void FrameResized(float width
, float height
);
48 virtual void Draw(BRect updateRect
);
50 virtual void DrawDay(BView
* owner
, BRect frame
,
51 const char* text
, bool isSelected
= false,
52 bool isEnabled
= true, bool focus
= false,
53 bool highlight
= false);
54 virtual void DrawDayName(BView
* owner
, BRect frame
,
56 virtual void DrawWeekNumber(BView
* owner
, BRect frame
,
59 uint32
SelectionCommand() const;
60 BMessage
* SelectionMessage() const;
61 virtual void SetSelectionMessage(BMessage
* message
);
63 uint32
InvocationCommand() const;
64 BMessage
* InvocationMessage() const;
65 virtual void SetInvocationMessage(BMessage
* message
);
67 virtual void MakeFocus(bool state
= true);
68 virtual status_t
Invoke(BMessage
* message
= NULL
);
70 virtual void MouseDown(BPoint where
);
72 virtual void KeyDown(const char* bytes
, int32 numBytes
);
76 virtual void ResizeToPreferred();
77 virtual void GetPreferredSize(float* width
, float* height
);
79 virtual BSize
MaxSize();
80 virtual BSize
MinSize();
81 virtual BSize
PreferredSize();
87 bool SetDay(int32 day
);
88 bool SetMonth(int32 month
);
89 bool SetYear(int32 year
);
92 bool SetDate(const BDate
& date
);
93 bool SetDate(int32 year
, int32 month
, int32 day
);
95 BWeekday
StartOfWeek() const;
96 void SetStartOfWeek(BWeekday startOfWeek
);
98 bool IsDayNameHeaderVisible() const;
99 void SetDayNameHeaderVisible(bool visible
);
100 void UpdateDayNameHeader();
102 bool IsWeekNumberHeaderVisible() const;
103 void SetWeekNumberHeaderVisible(bool visible
);
113 SetTo(int32 _row
, int32 _column
)
122 Selection
& operator=(const Selection
& s
)
129 bool operator==(const Selection
& s
) const
132 && column
== s
.column
;
135 bool operator!=(const Selection
& s
) const
138 || column
!= s
.column
;
145 void _SetToCurrentDay();
146 void _GetYearMonthForSelection(
147 const Selection
& selection
, int32
* year
,
149 void _GetPreferredSize(float* width
, float* height
);
151 void _SetupDayNames();
152 void _SetupDayNumbers();
153 void _SetupWeekNumbers();
155 void _PopulateDayNames(BDateFormatStyle style
);
158 void _DrawFocusRect();
159 void _DrawDayHeader();
160 void _DrawWeekHeader();
161 void _DrawDay(int32 curRow
, int32 curColumn
,
162 int32 row
, int32 column
, int32 counter
,
163 BRect frame
, const char* text
,
164 bool focus
= false, bool highlight
= false);
165 void _DrawItem(BView
* owner
, BRect frame
,
166 const char* text
, bool isSelected
= false,
167 bool isEnabled
= true, bool focus
= false,
168 bool highlight
= false);
170 void _UpdateSelection();
171 void _UpdateCurrentDay();
172 void _UpdateCurrentDate();
174 BRect
_FirstCalendarItemFrame() const;
175 BRect
_SetNewSelectedDay(const BPoint
& where
);
177 BRect
_RectOfDay(const Selection
& selection
) const;
180 BMessage
* fSelectionMessage
;
185 Selection fFocusedDay
;
186 Selection fNewFocusedDay
;
189 Selection fSelectedDay
;
190 Selection fNewSelectedDay
;
191 bool fSelectionChanged
;
193 Selection fCurrentDay
;
194 Selection fNewCurrentDay
;
195 bool fCurrentDayChanged
;
198 bool fDayNameHeaderVisible
;
199 bool fWeekNumberHeaderVisible
;
201 BString fDayNames
[7];
202 BString fWeekNumbers
[6];
203 BString fDayNumbers
[6][7];
205 // hide copy constructor & assignment
206 BCalendarView(const BCalendarView
& view
);
207 BCalendarView
& operator=(const BCalendarView
& view
);
211 } // namespace BPrivate
214 #endif // _CALENDAR_VIEW_H_