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