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