xref: /haiku/src/apps/deskbar/StatusView.h (revision 1a7208e060deb8cd1e2309891bfbe977f083774f)
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 __STATUS_VIEW__
36 #define __STATUS_VIEW__
37 
38 
39 #include <Control.h>
40 #include <Node.h>
41 #include <Region.h>
42 #include <Query.h>
43 #include <Shelf.h>
44 #include <View.h>
45 
46 #include "BarView.h"
47 #include "TimeView.h"
48 
49 
50 //#define FULL_MODE
51 
52 const float kDragWidth = 4.0f;
53 const float kMinReplicantHeight = 16.0f;
54 const float kMinReplicantWidth = 16.0f;
55 const int32 kMinimumReplicantCount = 6;
56 const int32 kIconGap = 2;
57 const int32 kGutter = 1;
58 const int32 kDragRegionWidth = 6;
59 const int32 kTrayPadding = 3;
60 const int32 kClockMargin = 12;
61 
62 // 1 pixel for left gutter
63 // space for replicant tray (6 items)
64 // 6 pixel drag region
65 const float kMinimumTrayWidth = kIconGap + kMinReplicantWidth
66 	+ (kMinimumReplicantCount * kIconGap)
67 	+ (kMinimumReplicantCount * kMinReplicantWidth) + kGutter;
68 
69 extern float gMinimumWindowWidth;
70 extern float gMaximumWindowWidth;
71 
72 #ifdef DB_ADDONS
73 struct DeskbarItemInfo {
74 	bool isAddOn;		// attribute tagged item
75 	int32 id;			// id given to replicant
76 	entry_ref entryRef;	// entry_ref to item tagged
77 	node_ref nodeRef;	// node_ref to boot vol item
78 };
79 #endif
80 
81 class TReplicantShelf;
82 
83 class TReplicantTray : public BView {
84 public:
85 									TReplicantTray(TBarView* barView);
86 		virtual						~TReplicantTray();
87 
88 		virtual	void				AttachedToWindow();
89 		virtual	void				DetachedFromWindow();
90 		virtual	void				MouseDown(BPoint point);
91 		virtual	void				MessageReceived(BMessage*);
92 		virtual	void				GetPreferredSize(float*, float*);
93 
94 				void				AdjustPlacement();
95 				void				ShowReplicantMenu(BPoint);
96 
97 				TTimeView*			Time() const { return fTime; }
98 				void				ShowHideTime();
99 
100 				status_t			ItemInfo(int32 target, const char** name);
101 				status_t			ItemInfo(const char* name, int32* id);
102 				status_t			ItemInfo(int32 index, const char** name,
103 										int32* id);
104 
105 				bool				IconExists(int32 target, bool byIndex = false);
106 				bool				IconExists(const char* name);
107 
108 				int32				ReplicantCount() const;
109 				float				MaxReplicantWidth() const
110 										{ return fMaxReplicantWidth; }
111 				float				MaxReplicantHeight() const
112 										{ return fMaxReplicantHeight; }
113 
114 				status_t			AddIcon(BMessage*, int32* id,
115 										const entry_ref* = NULL);
116 
117 				void				RemoveIcon(int32 target,
118 										bool byIndex = false);
119 				void				RemoveIcon(const char* name);
120 
121 				BRect				IconFrame(int32 target,
122 										bool byIndex = false);
123 				BRect				IconFrame(const char* name);
124 
125 				bool				AcceptAddon(BRect frame,
126 										BMessage* message);
127 				void				RealignReplicants(int32 startIndex = -1);
128 
129 				void				SaveTimeSettings();
130 
131 #ifdef DB_ADDONS
132 				status_t			LoadAddOn(BEntry* entry, int32* id,
133 										bool addToSettings = true);
134 #endif
135 
136 private:
137 				BView*				ViewAt(int32* index, int32* id,
138 										int32 target,
139 										bool byIndex = false);
140 				BView*				ViewAt(int32* index, int32* id,
141 										const char* name);
142 
143 				void				RealReplicantAdjustment(int32 startindex);
144 
145 #ifdef DB_ADDONS
146 				void				InitAddOnSupport();
147 				void				DeleteAddOnSupport();
148 
149 				DeskbarItemInfo*	DeskbarItemFor(node_ref &nodeRef);
150 				DeskbarItemInfo*	DeskbarItemFor(int32 id);
151 				bool				NodeExists(node_ref &nodeRef);
152 
153 				void				HandleEntryUpdate(BMessage*);
154 				status_t			AddItem(int32 id, node_ref nodeRef,
155 										BEntry &entry, bool isAddon);
156 
157 				void				UnloadAddOn(node_ref*, dev_t*, bool which,
158 										bool removeAll);
159 				void				RemoveItem(int32 id);
160 
161 				void				MoveItem(entry_ref*, ino_t toDirectory);
162 #endif
163 
164 				BPoint				LocationForReplicant(int32 index,
165 										float replicantWidth);
166 				BShelf*				Shelf() const;
167 
168 				status_t			_SaveSettings();
169 
170 	friend class TReplicantShelf;
171 	friend class TBarView;
172 
173 				TTimeView*			fTime;
174 				TBarView*			fBarView;
175 				TReplicantShelf*	fShelf;
176 				BRect				fRightBottomReplicant;
177 				int32				fLastReplicant;
178 				float				fMaxReplicantWidth;
179 				float				fMaxReplicantHeight;
180 				float				fMinTrayHeight;
181 
182 				float				fMinimumTrayWidth;
183 
184 				bool				fAlignmentSupport;
185 #ifdef DB_ADDONS
186 				BList*				fItemList;
187 				BMessage			fAddOnSettings;
188 #endif
189 
190 };
191 
192 enum {
193 	kNoDragRegion,
194 	kDontDrawDragRegion,
195 	kAutoPlaceDragRegion,
196 	kDragRegionLeft,
197 	kDragRegionRight,
198 	kDragRegionTop,
199 	kDragRegionBottom
200 };
201 
202 class TDragRegion : public BControl {
203 public:
204 	TDragRegion(TBarView* barView, BView* replicantTray);
205 
206 	virtual void AttachedToWindow();
207 	virtual void GetPreferredSize(float*, float*);
208 	virtual void Draw(BRect);
209 	virtual void DrawAfterChildren(BRect);
210 	virtual void MouseDown(BPoint);
211 	virtual void MouseUp(BPoint);
212 	virtual void MouseMoved(BPoint, uint32, const BMessage*);
213 
214 	BRect DragRegion() const;
215 
216 	bool SwitchModeForRegion(BPoint where, BRegion region,
217 		bool newVertical, bool newLeft, bool newTop, int32 newState);
218 	void CalculateRegions();
219 
220 	int32 DragRegionLocation() const;
221 	void SetDragRegionLocation(int32);
222 
223 	bool IsDragging() { return IsTracking(); };
224 
225 private:
226 	void DrawDragger();
227 
228 private:
229 	TBarView* fBarView;
230 	BView* fReplicantTray;
231 	BPoint fPreviousPosition;
232 	int32 fDragLocation;
233 
234 	BRegion fTopLeftVertical;
235 	BRegion fTopRightVertical;
236 	BRegion fBottomLeftVertical;
237 	BRegion fBottomRightVertical;
238 
239 	BRegion fTopLeftHorizontal;
240 	BRegion fTopRightHorizontal;
241 	BRegion fBottomLeftHorizontal;
242 	BRegion fBottomRightHorizontal;
243 
244 	BRegion fMiddleLeft;
245 	BRegion fMiddleRight;
246 #ifdef FULL_MODE
247 	BRegion fLeftSide;
248 	BRegion fRightSide;
249 #endif
250 	BRegion fTopHalf;
251 	BRegion fBottomHalf;
252 };
253 
254 class TResizeControl : public BControl {
255 public:
256 	TResizeControl(TBarView* barView);
257 	virtual	~TResizeControl();
258 
259 	virtual void AttachedToWindow();
260 	virtual void Draw(BRect);
261 	virtual void MouseDown(BPoint);
262 	virtual void MouseUp(BPoint);
263 	virtual void MouseMoved(BPoint, uint32, const BMessage*);
264 
265 	bool IsResizing() { return IsTracking(); };
266 
267 private:
268 	TBarView* fBarView;
269 };
270 
271 
272 #endif	/* __STATUS_VIEW__ */
273