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