xref: /haiku/src/apps/deskbar/TimeView.h (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 #ifndef TIME_VIEW_H
35 #define TIME_VIEW_H
36 
37 #include <OS.h>
38 #include <View.h>
39 
40 const uint32 kMsgShowSeconds = 'ShSc';
41 const uint32 kMsgMilTime = 'MilT';
42 const uint32 kMsgFullDate = 'FDat';
43 const uint32 kMsgEuroDate = 'EDat';
44 
45 class BMessageRunner;
46 
47 #ifdef AS_REPLICANT
48 class _EXPORT	TTimeView;
49 #endif
50 
51 class TTimeView : public BView {
52 	public:
53 		TTimeView(float maxWidth, float height, bool showSeconds = false, bool milTime = false, bool fullDate = false,
54 			bool euroDate = false, bool showInterval = false);
55 		TTimeView(BMessage *data);
56 		~TTimeView();
57 
58 #ifdef AS_REPLICANT
59 		status_t Archive(BMessage *data, bool deep = true) const;
60 		static BArchivable *Instantiate(BMessage *data);
61 #endif
62 
63 		void		AttachedToWindow();
64 		void		Draw(BRect update);
65 		void		GetPreferredSize(float *width, float *height);
66 		void		ResizeToPreferred();
67 		void		FrameMoved(BPoint);
68 		void		MessageReceived(BMessage*);
69 		void		MouseDown(BPoint where);
70 		void		MouseUp(BPoint where);
71 		void		Pulse();
72 
73 		bool		ShowingSeconds() 	{ return fShowSeconds; }
74 		void		ShowSeconds(bool);
75 		bool		ShowingMilTime()	{ return fMilTime; }
76 		void		ShowMilTime(bool);
77 		bool		ShowingDate()		{ return fShowingDate; }
78 		void		ShowDate(bool);
79 		bool		ShowingFullDate()	{ return fFullDate; }
80 		void		ShowFullDate(bool);
81 		bool		CanShowFullDate() const { return fCanShowFullDate; }
82 		void		AllowFullDate(bool);
83 		bool		ShowingEuroDate()	{return fEuroDate; }
84 		void		ShowEuroDate(bool);
85 		void		ShowCalendar(BPoint where);
86 		void		StartLongClickNotifier(BPoint where);
87 		void		StopLongClickNotifier();
88 
89 		bool		Orientation() const;
90 		void		SetOrientation(bool o);
91 
92 	private:
93 		friend class TReplicantTray;
94 
95 		void		Update();
96 		void		GetCurrentTime();
97 		void		GetCurrentDate();
98 		void		CalculateTextPlacement();
99 		void		ShowClockOptions(BPoint);
100 
101 		BView		*fParent;
102 		bool		fNeedToUpdate;
103 
104 		time_t		fTime;
105 		time_t		fLastTime;
106 
107 		char		fTimeStr[64];
108 		char		fLastTimeStr[64];
109 		char		fDateStr[64];
110 		char		fLastDateStr[64];
111 
112 		int			fSeconds;
113 		int			fMinute;
114 		int			fHour;
115 		bool		fInterval;
116 
117 		bool		fShowInterval;
118 		bool		fShowSeconds;
119 		bool		fMilTime;
120 		bool		fShowingDate;
121 		bool		fFullDate;
122 		bool		fCanShowFullDate;
123 		bool		fEuroDate;
124 
125 		float		fMaxWidth;
126 		float		fHeight;
127 		bool		fOrientation;		// vertical = true
128 		BPoint		fTimeLocation;
129 		BPoint		fDateLocation;
130 
131 		BMessageRunner*	fLongClickMessageRunner;
132 };
133 
134 
135 inline bool
136 TTimeView::Orientation() const
137 {
138 	return fOrientation;
139 }
140 
141 
142 #endif	/* TIME_VIEW_H */
143