1/*
2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		McCall <mccall@@digitalparadise.co.uk>
7 *		Mike Berg <mike@berg-net.us>
8 *		Julun <host.haiku@gmx.de>
9 *		Hamish Morrison <hamish@lavabit.com>
10 */
11#ifndef _DATE_TIME_EDIT_H
12#define _DATE_TIME_EDIT_H
13
14
15#include <DateFormat.h>
16#include <DateTime.h>
17#include <Locale.h>
18#include <String.h>
19#include <TimeFormat.h>
20
21#include "SectionEdit.h"
22
23
24class TTimeEdit : public TSectionEdit {
25public:
26								TTimeEdit(const char* name,	uint32 sections);
27	virtual						~TTimeEdit();
28
29	virtual	void				KeyDown(const char* bytes, int32 numBytes);
30
31	virtual	void				InitView();
32	virtual	void				DrawSection(uint32 index, BRect bounds,
33									bool isfocus);
34	virtual	void				DrawSeparator(uint32 index, BRect bounds);
35
36	virtual	void				SectionFocus(uint32 index);
37	virtual float				MinSectionWidth();
38	virtual float				SeparatorWidth();
39
40	virtual float				PreferredHeight();
41	virtual	void				DoUpPress();
42	virtual	void				DoDownPress();
43
44	virtual	void				BuildDispatch(BMessage* message);
45
46			void				SetTime(int32 hour, int32 minute, int32 second);
47
48private:
49			void				_UpdateFields();
50			void				_CheckRange();
51			bool				_IsValidDoubleDigit(int32 value);
52			int32				_SectionValue(int32 index) const;
53
54			BDateTime			fTime;
55			BTimeFormat			fTimeFormat;
56			bigtime_t			fLastKeyDownTime;
57			int32				fLastKeyDownInt;
58
59			BString				fText;
60
61			// TODO: morph the following into a proper class
62			BDateElement*		fFields;
63			int					fFieldCount;
64			int*				fFieldPositions;
65			int					fFieldPosCount;
66};
67
68
69class TDateEdit : public TSectionEdit {
70public:
71								TDateEdit(const char* name, uint32 sections);
72	virtual						~TDateEdit();
73	virtual	void				KeyDown(const char* bytes, int32 numBytes);
74
75	virtual void				InitView();
76	virtual void				DrawSection(uint32 index, BRect bounds,
77									bool isfocus);
78	virtual void				DrawSeparator(uint32 index, BRect bounds);
79
80	virtual void				SectionFocus(uint32 index);
81	virtual float				MinSectionWidth();
82	virtual float				SeparatorWidth();
83
84	virtual float				PreferredHeight();
85	virtual void				DoUpPress();
86	virtual void				DoDownPress();
87
88	virtual void				BuildDispatch(BMessage* message);
89
90
91			void				SetDate(int32 year, int32 month, int32 day);
92
93private:
94			void				_UpdateFields();
95			void				_CheckRange();
96			bool				_IsValidDoubleDigit(int32 value);
97			int32				_SectionValue(int32 index) const;
98
99			BDate				fDate;
100			BDateFormat			fDateFormat;
101			bigtime_t			fLastKeyDownTime;
102			int32				fLastKeyDownInt;
103
104			BString				fText;
105
106			// TODO: morph the following into a proper class
107			BDateElement*		fFields;
108			int					fFieldCount;
109			int*				fFieldPositions;
110			int					fFieldPosCount;
111};
112
113
114#endif	// _DATE_TIME_EDIT_H
115
116