xref: /haiku/src/apps/deskbar/StatusView.h (revision fef6144999c2fa611f59ee6ffe6dd7999501385c)
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 trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 
35 #ifndef __STATUS_VIEW__
36 #define __STATUS_VIEW__
37 
38 #include <Control.h>
39 #include <Node.h>
40 #include <Query.h>
41 #include <Shelf.h>
42 #include <View.h>
43 
44 #include "BarView.h"
45 #include "TimeView.h"
46 
47 const float kMaxReplicantHeight = 16.0f;
48 const float kMaxReplicantWidth = 16.0f;
49 const int32 kMinimumReplicantCount = 6;
50 const int32	kIconGap = 2;
51 const int32 kGutter = 1;
52 const int32 kDragRegionWidth = 6;
53 
54 //	1 pixel left gutter
55 //	space for replicant tray (6 items)
56 //	6 pixel drag region
57 const float kMinimumTrayWidth = kIconGap
58 		+ (kMinimumReplicantCount * kIconGap)
59 		+ (kMinimumReplicantCount * kMaxReplicantWidth) + kGutter;
60 const float kMinimumTrayHeight = kGutter + kMaxReplicantHeight + kGutter;
61 
62 const float kMinimumWindowWidth = kGutter + kMinimumTrayWidth + kDragRegionWidth;
63 
64 #ifdef DB_ADDONS
65 struct DeskbarItemInfo {
66 	bool isAddOn;		// attribute tagged item
67 	int32 id;			// id given to replicant
68 	entry_ref entryRef;	// entry_ref to item tagged
69 	node_ref nodeRef;	// node_ref to boot vol item
70 };
71 #endif
72 
73 class TReplicantTray : public BView {
74 public:
75 	TReplicantTray(TBarView *bv, bool vertical);
76 	virtual ~TReplicantTray();
77 
78 	virtual void AttachedToWindow();
79 	virtual void DetachedFromWindow();
80 	virtual void Draw(BRect updateRect);
81 	virtual void MouseDown(BPoint point);
82 	virtual void MessageReceived(BMessage *);
83 	virtual void GetPreferredSize(float *, float *);
84 
85 	void AdjustPlacement();
86 
87 	void ShowReplicantMenu(BPoint);
88 
89 	void SetMultiRow(bool state);
90 	bool IsMultiRow() const { return fMultiRowMode; }
91 
92 	status_t ItemInfo(int32 target, const char **name);
93 	status_t ItemInfo(const char *name, int32 *id);
94 	status_t ItemInfo(int32 index, const char **name, int32 *id);
95 
96 	bool IconExists(int32 target, bool byIndex = false);
97 	bool IconExists(const char *name);
98 
99 	int32  IconCount() const;
100 
101 	status_t AddIcon(BMessage *, int32 *id, const entry_ref * = NULL);
102 
103 	void RemoveIcon(int32 target, bool byIndex = false);
104 	void RemoveIcon(const char *name);
105 
106 	BRect IconFrame(int32 target, bool byIndex=false);
107 	BRect IconFrame(const char *name);
108 
109 	bool AcceptAddon(BRect frame, BMessage *message);
110 	void RealignReplicants(int32 startIndex = -1);
111 
112 	bool ShowingSeconds(void);
113 	bool ShowingMiltime(void);
114 	bool ShowingEuroDate(void);
115 	bool ShowingFullDate(void);
116 	bool CanShowFullDate(void);
117 
118 	void RememberClockSettings();
119 	void DealWithClock(bool);
120 
121 #ifdef DB_ADDONS
122 	status_t LoadAddOn(BEntry *entry, int32 *id, bool force = false);
123 #endif
124 
125 private:
126 	BView *ViewAt(int32 *index, int32 *id, int32 target, bool byIndex = false);
127 	BView *ViewAt(int32 *index, int32 *id, const char *name);
128 
129 	void RealReplicantAdjustment(int32 startindex);
130 
131 #ifdef DB_ADDONS
132 	void InitAddOnSupport();
133 	void DeleteAddOnSupport();
134 	void RunAddOnQuery(BVolume *volume, const char *predicated);
135 
136 	bool IsAddOn(entry_ref &ref);
137 	DeskbarItemInfo *DeskbarItemFor(node_ref &nodeRef);
138 	DeskbarItemInfo *DeskbarItemFor(int32 id);
139 	bool NodeExists(node_ref &nodeRef);
140 
141 	void HandleEntryUpdate(BMessage *);
142 	status_t AddItem(int32 id, node_ref nodeRef, BEntry &entry, bool isAddon);
143 
144 	void UnloadAddOn(node_ref *, dev_t *, bool which, bool removeAll);
145 	void RemoveItem(int32 id);
146 
147 	void MoveItem(entry_ref *, ino_t toDirectory);
148 #endif
149 
150 	BPoint LocForReplicant(int32 replicantCount, int32 index, float width);
151 	BShelf *Shelf() const;
152 
153 	friend class TReplicantShelf;
154 
155 	TTimeView *fClock;
156 	TBarView *fBarView;
157 	TReplicantShelf *fShelf;
158 
159 	bool fMultiRowMode;
160 
161 	bool fAlignmentSupport;
162 #ifdef DB_ADDONS
163 	BList *fItemList;
164 	uint64 fDeskbarSecurityCode;
165 #endif
166 
167 };
168 
169 enum {
170 	kNoDragRegion,
171 	kDontDrawDragRegion,
172 	kAutoPlaceDragRegion,
173 	kDragRegionLeft,
174 	kDragRegionRight,
175 	kDragRegionTop,
176 	kDragRegionBottom
177 };
178 
179 class TDragRegion : public BControl {
180 public:
181 	TDragRegion(TBarView *, BView *);
182 
183 	virtual void AttachedToWindow();
184 	virtual void GetPreferredSize(float *, float *);
185 	virtual void Draw(BRect);
186 	virtual void FrameMoved(BPoint);
187 	virtual void MouseDown(BPoint );
188 	virtual void MouseUp(BPoint );
189 	virtual void MouseMoved(BPoint , uint32 , const BMessage *);
190 
191 	void DrawDragRegion();
192 	BRect DragRegion() const;
193 
194 	bool SwitchModeForRect(BPoint mouse, BRect rect,
195 		bool newVertical, bool newLeft, bool newTop, int32 newState);
196 
197 	int32 DragRegionLocation() const;
198 	void SetDragRegionLocation(int32);
199 
200 private:
201 	TBarView *fBarView;
202 	BView *fChild;
203 	BPoint fPreviousPosition;
204 	int32 fDragLocation;
205 };
206 
207 #endif
208 
209