xref: /haiku/src/apps/deskbar/BarApp.h (revision 048f079571dbb5717b8f6f4096c1740b9f5423c7)
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 BAR_APP_H
36 #define BAR_APP_H
37 
38 
39 #include <Application.h>
40 
41 #include "BarSettings.h"
42 
43 
44 /* ------------------------------------ */
45 // Private app_server defines that I need to use
46 
47 #define _DESKTOP_W_TYPE_ 1024
48 #define _FLOATER_W_TYPE_ 4
49 #define _STD_W_TYPE_ 0
50 
51 
52 const uint32 kWin95 = 'Bill';
53 const uint32 kAmiga = 'Ncro';
54 const uint32 kMac = 'WcOS';
55 const uint32 kBe = 'Tabs';
56 const uint32 kAlwaysTop = 'TTop';
57 const uint32 kToggleDraggers = 'TDra';
58 const uint32 kUnsubscribe = 'Unsb';
59 const uint32 kAddTeam = 'AdTm';
60 const uint32 kRemoveTeam = 'RmTm';
61 const uint32 kRestart = 'Rtrt';
62 const uint32 kShutDown = 'ShDn';
63 const uint32 kRestartTracker = 'Trak';
64 
65 // from roster_private.h
66 const uint32 kShutdownSystem = 301;
67 const uint32 kRebootSystem = 302;
68 const uint32 kSuspendSystem = 304;
69 
70 // icon size constants
71 const int32 kMinimumIconSize = 16;
72 const int32 kMaximumIconSize = 96;
73 const int32 kIconSizeInterval = 8;
74 const int32 kIconCacheCount = (kMaximumIconSize - kMinimumIconSize)
75 								/ kIconSizeInterval + 1;
76 
77 // update preferences message constant
78 const uint32 kUpdatePreferences = 'Pref';
79 
80 /* --------------------------------------------- */
81 
82 class BBitmap;
83 class BFile;
84 class BList;
85 class PreferencesWindow;
86 class TBarView;
87 class TBarWindow;
88 
89 class BarTeamInfo {
90 public:
91 									BarTeamInfo(BList* teams, uint32 flags,
92 										char* sig, BBitmap* icon, char* name);
93 									BarTeamInfo(const BarTeamInfo &info);
94 									~BarTeamInfo();
95 
96 			BList*					teams;
97 			uint32					flags;
98 			char*					sig;
99 			BBitmap*				icon;
100 			char*					name;
101 			BBitmap*				iconCache[kIconCacheCount];
102 };
103 
104 class TBarApp : public BApplication {
105 public:
106 									TBarApp();
107 	virtual							~TBarApp();
108 
109 	virtual	bool					QuitRequested();
110 	virtual	void					MessageReceived(BMessage* message);
111 	virtual	void					RefsReceived(BMessage* refs);
112 
113 			desk_settings*			Settings() { return &fSettings; }
114 			desk_settings*			DefaultSettings()
115 										{ return &fDefaultSettings; }
116 			clock_settings*			ClockSettings() { return &fClockSettings; }
117 
118 			TBarView*				BarView() const { return fBarView; }
119 			TBarWindow*				BarWindow() const { return fBarWindow; }
120 
121 	static	void					Subscribe(const BMessenger &subscriber,
122 										BList*);
123 	static	void					Unsubscribe(const BMessenger &subscriber);
124 
125 			int32					IconSize();
126 
127 private:
128 			void					AddTeam(team_id team, uint32 flags,
129 										const char* sig, entry_ref*);
130 			void					RemoveTeam(team_id);
131 
132 			void					InitSettings();
133 			void					SaveSettings();
134 
135 			void					ShowPreferencesWindow();
136 			void					QuitPreferencesWindow();
137 
138 			void					ResizeTeamIcons();
139 			void					FetchAppIcon(BarTeamInfo* barInfo);
140 
141 			BRect					IconRect();
142 
143 private:
144 			TBarWindow*				fBarWindow;
145 			TBarView*				fBarView;
146 			BMessenger				fSwitcherMessenger;
147 			BMessenger				fStatusViewMessenger;
148 			BFile*					fSettingsFile;
149 			BFile*					fClockSettingsFile;
150 			desk_settings			fSettings;
151 			desk_settings			fDefaultSettings;
152 			clock_settings			fClockSettings;
153 			PreferencesWindow*		fPreferencesWindow;
154 
155 	static	BLocker					sSubscriberLock;
156 	static	BList					sBarTeamInfoList;
157 	static	BList					sSubscribers;
158 };
159 
160 
161 #endif	// BAR_APP_H
162