xref: /haiku/src/apps/deskbar/BarView.h (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
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 
35 #ifndef BARVIEW_H
36 #define BARVIEW_H
37 
38 #include <Deskbar.h>
39 #include <View.h>
40 
41 #include "NavMenu.h"
42 #include "ObjectList.h"
43 
44 enum DeskbarShelf {
45 	B_DESKBAR_ANY_SHELF = 0,
46 	B_DESKBAR_TRAY = 1
47 };
48 
49 enum {
50 	kMiniState = 0,
51 	kExpandoState = 1,
52 	kFullState = 2
53 };
54 
55 const float kMiniHeight = 46.0f;
56 const float kHModeHeight = 21.0f;
57 const float kMenuBarHeight = 21.0f;
58 const float kStatusHeight = 22.0f;
59 
60 #define SA_CLOCK 0
61 
62 class BShelf;
63 class TBarMenuBar;
64 class TExpandoMenuBar;
65 class TReplicantTray;
66 class TDragRegion;
67 #if SA_CLOCK
68 class TTimeView;
69 #endif
70 class TTeamMenuItem;
71 
72 
73 class TBarView : public BView {
74 	public:
75 		TBarView(BRect frame, bool vertical, bool left, bool top,
76 			bool ampmMode, uint32 state, float width, bool showClock);
77 		~TBarView();
78 
79 		virtual void AttachedToWindow();
80 		virtual void Draw(BRect);
81 		virtual void MessageReceived(BMessage *);
82 
83 		void SaveSettings();
84 		void UpdatePlacement();
85 		void ChangeState(int32 state, bool vertical, bool left, bool top);
86 
87 		bool Vertical() const;
88 		bool Left() const;
89 		bool Top() const;
90 		bool AcrossTop() const;
91 		bool AcrossBottom() const;
92 		bool Expando() const;
93 		int32 State() const;
94 
95 		bool MilTime() const;
96 		void ShowClock(bool);
97 		bool ShowingClock() const;
98 	#if SA_CLOCK
99 		void ToggleClock();
100 	#endif
101 
102 		void CacheDragData(BMessage *incoming);
103 		status_t DragStart();
104 		static bool MenuTrackingHook(BMenu *menu, void *castToThis);
105 		void DragStop(bool full=false);
106 		TrackingHookData *GetTrackingHookData();
107 		bool Dragging() const;
108 		const BMessage *DragMessage() const;
109 		BObjectList<BString> *CachedTypesList() const;
110 		bool AppCanHandleTypes(const char *signature);
111 		void SetDragOverride(bool);
112 		bool DragOverride();
113 		bool InvokeItem(const char *signature);
114 
115 		void HandleBeMenu(BMessage *targetmessage);
116 
117 		status_t ItemInfo(int32 id, const char **name, DeskbarShelf *shelf);
118 		status_t ItemInfo(const char *name, int32 *id, DeskbarShelf *shelf);
119 
120 		bool ItemExists(int32 id, DeskbarShelf shelf);
121 		bool ItemExists(const char *name, DeskbarShelf shelf);
122 
123 		int32 CountItems(DeskbarShelf shelf);
124 
125 		status_t AddItem(BMessage *, DeskbarShelf shelf, int32 *id);
126 
127 		void RemoveItem(int32 id);
128 		void RemoveItem(const char *name, DeskbarShelf shelf);
129 
130 		BRect OffsetIconFrame(BRect rect) const;
131 		BRect IconFrame(int32 id) const;
132 		BRect IconFrame(const char *name) const;
133 
134 		void GetPreferredWindowSize(BRect screenFrame, float *width, float *height);
135 		void SizeWindow(BRect screenFrame);
136 		void PositionWindow(BRect screenFrame);
137 
138 		TExpandoMenuBar *ExpandoMenuBar() const;
139 		TBarMenuBar *BarMenuBar() const;
140 		friend class TBeMenu;
141 
142 	private:
143 		status_t SendDragMessage(const char *signature, entry_ref *ref = NULL);
144 
145 		void PlaceBeMenu();
146 		void PlaceTray(bool vertSwap, bool leftSwap, BRect screenFrame);
147 	#if SA_CLOCK
148 		void PlaceClock();
149 	#endif
150 		void PlaceApplicationBar(BRect screenFrame);
151 
152 		TBarMenuBar *fBarMenuBar;
153 		TExpandoMenuBar *fExpando;
154 
155 		int32 fTrayLocation;
156 		TDragRegion *fDragRegion;
157 		TReplicantTray *fReplicantTray;
158 
159 		bool fShowInterval;
160 		bool fShowClock;
161 	#if SA_CLOCK
162 		TTimeView *fClock;
163 	#endif
164 		bool fVertical;
165 		bool fTop;
166 		bool fLeft;
167 
168 		int32 fState;
169 
170 		bigtime_t fPulseRate;
171 		bool fRefsRcvdOnly;
172 		BMessage *fDragMessage;
173 		BObjectList<BString> *fCachedTypesList;
174 		TrackingHookData fTrackingHookData;
175 
176 		uint32 fMaxRecentDocs;
177 		uint32 fMaxRecentApps;
178 
179 		TTeamMenuItem *fLastDragItem;
180 		bool fClickToOpen;
181 };
182 
183 
184 inline TExpandoMenuBar *
185 TBarView::ExpandoMenuBar() const
186 {
187 	return fExpando;
188 }
189 
190 
191 inline TBarMenuBar *
192 TBarView::BarMenuBar() const
193 {
194 	return fBarMenuBar;
195 }
196 
197 
198 inline bool
199 TBarView::Dragging() const
200 {
201 	return (fCachedTypesList && fDragMessage);
202 }
203 
204 
205 inline const BMessage *
206 TBarView::DragMessage() const
207 {
208 	return fDragMessage;
209 }
210 
211 
212 inline BObjectList<BString> *
213 TBarView::CachedTypesList() const
214 {
215 	return fCachedTypesList;
216 }
217 
218 #endif /* BARVIEW_H */
219