vfs: check userland buffers before reading them.
[haiku.git] / headers / private / shared / CalendarView.h
blob9ce4216d0eb62671709d4500da93d42e04039268
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_
9 #include "DateTime.h"
12 #include <DateFormat.h>
13 #include <Invoker.h>
14 #include <List.h>
15 #include <Locale.h>
16 #include <String.h>
17 #include <View.h>
20 class BMessage;
23 namespace BPrivate {
26 class BCalendarView : public BView, public BInvoker {
27 public:
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,
55 const char* text);
56 virtual void DrawWeekNumber(BView* owner, BRect frame,
57 const char* text);
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);
74 virtual void Pulse();
76 virtual void ResizeToPreferred();
77 virtual void GetPreferredSize(float* width, float* height);
79 virtual BSize MaxSize();
80 virtual BSize MinSize();
81 virtual BSize PreferredSize();
83 int32 Day() const;
84 int32 Month() const;
85 int32 Year() const;
87 bool SetDay(int32 day);
88 bool SetMonth(int32 month);
89 bool SetYear(int32 year);
91 BDate Date() const;
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);
105 private:
106 struct Selection {
107 Selection()
108 : row(0), column(0)
112 void
113 SetTo(int32 _row, int32 _column)
115 row = _row;
116 column = _column;
119 int32 row;
120 int32 column;
122 Selection& operator=(const Selection& s)
124 row = s.row;
125 column = s.column;
126 return *this;
129 bool operator==(const Selection& s) const
131 return row == s.row
132 && column == s.column;
135 bool operator!=(const Selection& s) const
137 return row != s.row
138 || column != s.column;
142 void _InitObject();
144 void _SetToDay();
145 void _SetToCurrentDay();
146 void _GetYearMonthForSelection(
147 const Selection& selection, int32* year,
148 int32* month) const;
149 void _GetPreferredSize(float* width, float* height);
151 void _SetupDayNames();
152 void _SetupDayNumbers();
153 void _SetupWeekNumbers();
155 void _PopulateDayNames(BDateFormatStyle style);
157 void _DrawDays();
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;
179 private:
180 BMessage* fSelectionMessage;
182 BDate fDate;
183 BDate fCurrentDate;
185 Selection fFocusedDay;
186 Selection fNewFocusedDay;
187 bool fFocusChanged;
189 Selection fSelectedDay;
190 Selection fNewSelectedDay;
191 bool fSelectionChanged;
193 Selection fCurrentDay;
194 Selection fNewCurrentDay;
195 bool fCurrentDayChanged;
197 int32 fStartOfWeek;
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_