xref: /haiku/src/apps/deskbar/TimeView.h (revision 56187df6ebd9d1fb16bf954fce8df0999e9e3048)
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 
38 #include <OS.h>
39 #include <Locale.h>
40 #include <Messenger.h>
41 #include <View.h>
42 
43 
44 const uint32 kShowSeconds = 'ShSc';
45 const uint32 kFullDate = 'FDat';
46 
47 class BCountry;
48 class BMessageRunner;
49 
50 #ifdef AS_REPLICANT
51 class _EXPORT	TTimeView;
52 #endif
53 
54 
55 class TTimeView : public BView {
56 	public:
57 		TTimeView(float maxWidth, float height, bool showSeconds = false,
58 			bool showInterval = false);
59 		TTimeView(BMessage* data);
60 		~TTimeView();
61 
62 #ifdef AS_REPLICANT
63 		status_t Archive(BMessage* data, bool deep = true) const;
64 		static BArchivable* Instantiate(BMessage* data);
65 #endif
66 
67 		void		AttachedToWindow();
68 		void		Draw(BRect update);
69 		void		GetPreferredSize(float* width, float* height);
70 		void		ResizeToPreferred();
71 		void		FrameMoved(BPoint);
72 		void		MessageReceived(BMessage*);
73 		void		MouseDown(BPoint where);
74 		void		Pulse();
75 
76 		bool		ShowingSeconds() 	{ return fShowSeconds; }
77 		void		ShowSeconds(bool);
78 		void		ShowCalendar(BPoint where);
79 
80 		bool		Orientation() const;
81 		void		SetOrientation(bool o);
82 
83 	private:
84 		friend class TReplicantTray;
85 
86 		void		Update();
87 		void		GetCurrentTime();
88 		void		GetCurrentDate();
89 		void		CalculateTextPlacement();
90 		void		ShowClockOptions(BPoint);
91 
92 		BView		*fParent;
93 		bool		fNeedToUpdate;
94 
95 		time_t		fTime;
96 		time_t		fLastTime;
97 
98 		char		fTimeStr[64];
99 		char		fLastTimeStr[64];
100 		char		fDateStr[64];
101 		char		fLastDateStr[64];
102 
103 		int			fSeconds;
104 		int			fMinute;
105 		int			fHour;
106 		bool		fInterval;
107 
108 		bool		fShowInterval;
109 		bool		fShowSeconds;
110 
111 		float		fMaxWidth;
112 		float		fHeight;
113 		bool		fOrientation;		// vertical = true
114 		BPoint		fTimeLocation;
115 		BPoint		fDateLocation;
116 
117 		BMessenger	fCalendarWindow;
118 
119 		BLocale		fLocale; // For date and time localizing purposes
120 };
121 
122 
123 inline bool
124 TTimeView::Orientation() const
125 {
126 	return fOrientation;
127 }
128 
129 
130 #endif	/* TIME_VIEW_H */
131 
132