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