xref: /haiku/src/apps/deskbar/BarView.h (revision cb9c3e9cede30851ba29be2e955fb8cfcecef7ac)
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 
61 class BShelf;
62 class TBarMenuBar;
63 class TExpandoMenuBar;
64 class TReplicantTray;
65 class TDragRegion;
66 class TTeamMenuItem;
67 
68 
69 class TBarView : public BView {
70 	public:
71 		TBarView(BRect frame, bool vertical, bool left, bool top,
72 			bool ampmMode, uint32 state, float width, bool showClock);
73 		~TBarView();
74 
75 		virtual void AttachedToWindow();
76 		virtual void DetachedFromWindow();
77 		virtual void Draw(BRect updateRect);
78 		virtual void MessageReceived(BMessage* message);
79 		virtual void MouseMoved(BPoint where, uint32 transit,
80 			const BMessage* dragMessage);
81 
82 		void SaveSettings();
83 		void UpdateAutoRaise();
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 
99 		void CacheDragData(const BMessage* incoming);
100 		status_t DragStart();
101 		static bool MenuTrackingHook(BMenu* menu, void* castToThis);
102 		void DragStop(bool full = false);
103 		TrackingHookData* GetTrackingHookData();
104 		bool Dragging() const;
105 		const BMessage* DragMessage() const;
106 		BObjectList<BString>*CachedTypesList() const;
107 		bool AppCanHandleTypes(const char* signature);
108 		void SetDragOverride(bool);
109 		bool DragOverride();
110 		bool InvokeItem(const char* signature);
111 
112 		void HandleBeMenu(BMessage* targetmessage);
113 
114 		status_t ItemInfo(int32 id, const char** name, DeskbarShelf* shelf);
115 		status_t ItemInfo(const char* name, int32* id, DeskbarShelf* shelf);
116 
117 		bool ItemExists(int32 id, DeskbarShelf shelf);
118 		bool ItemExists(const char* name, DeskbarShelf shelf);
119 
120 		int32 CountItems(DeskbarShelf shelf);
121 
122 		status_t AddItem(BMessage* archive, DeskbarShelf shelf, int32* id);
123 
124 		void RemoveItem(int32 id);
125 		void RemoveItem(const char* name, DeskbarShelf shelf);
126 
127 		BRect OffsetIconFrame(BRect rect) const;
128 		BRect IconFrame(int32 id) const;
129 		BRect IconFrame(const char* name) const;
130 
131 		void GetPreferredWindowSize(BRect screenFrame, float* width,
132 			float* height);
133 		void SizeWindow(BRect screenFrame);
134 		void PositionWindow(BRect screenFrame);
135 
136 		TExpandoMenuBar* ExpandoMenuBar() const;
137 		TBarMenuBar* BarMenuBar() const;
138 		TDragRegion* DragRegion() const { return fDragRegion; }
139 
140 	private:
141 		friend class TBeMenu;
142 		friend class PreferencesWindow;
143 
144 		status_t SendDragMessage(const char* signature, entry_ref* ref = NULL);
145 
146 		void PlaceBeMenu();
147 		void PlaceTray(bool vertSwap, bool leftSwap, BRect screenFrame);
148 		void PlaceApplicationBar(BRect screenFrame);
149 
150 		TBarMenuBar* fBarMenuBar;
151 		TExpandoMenuBar* fExpando;
152 
153 		int32 fTrayLocation;
154 		TDragRegion* fDragRegion;
155 		TReplicantTray* fReplicantTray;
156 
157 		bool fShowInterval : 1;
158 		bool fShowClock : 1;
159 		bool fVertical : 1;
160 		bool fTop : 1;
161 		bool fLeft : 1;
162 
163 		int32 fState;
164 
165 		bigtime_t fPulseRate;
166 		bool fRefsRcvdOnly;
167 		BMessage* fDragMessage;
168 		BObjectList<BString>*fCachedTypesList;
169 		TrackingHookData fTrackingHookData;
170 
171 		uint32 fMaxRecentDocs;
172 		uint32 fMaxRecentApps;
173 
174 		TTeamMenuItem* fLastDragItem;
175 };
176 
177 
178 inline TExpandoMenuBar*
179 TBarView::ExpandoMenuBar() const
180 {
181 	return fExpando;
182 }
183 
184 
185 inline TBarMenuBar*
186 TBarView::BarMenuBar() const
187 {
188 	return fBarMenuBar;
189 }
190 
191 
192 inline bool
193 TBarView::Dragging() const
194 {
195 	return (fCachedTypesList && fDragMessage);
196 }
197 
198 
199 inline const BMessage*
200 TBarView::DragMessage() const
201 {
202 	return fDragMessage;
203 }
204 
205 
206 inline BObjectList<BString>*
207 TBarView::CachedTypesList() const
208 {
209 	return fCachedTypesList;
210 }
211 
212 #endif /* BARVIEW_H */
213 
214