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 #ifndef SWITCHER_H 35 #define SWITCHER_H 36 37 #include <Box.h> 38 #include <List.h> 39 #include <OS.h> 40 #include <StringView.h> 41 #include <Window.h> 42 43 44 class TTeamGroup { 45 public: 46 TTeamGroup(); 47 TTeamGroup(BList *teams, uint32 flags, char *name, const char *sig); 48 virtual ~TTeamGroup(); 49 50 void Draw(BView *, BRect bounds, bool main); 51 52 BList *TeamList() const 53 { return fTeams; } 54 const char *Name() const 55 { return fName; } 56 const char *Signature() const 57 { return fSignature; } 58 uint32 Flags() const 59 { return fFlags; } 60 const BBitmap *SmallIcon() const 61 { return fSmallIcon; } 62 const BBitmap *LargeIcon() const 63 { return fLargeIcon; } 64 65 private: 66 BList *fTeams; 67 uint32 fFlags; 68 char fSignature[B_MIME_TYPE_LENGTH]; 69 char *fName; 70 BBitmap *fSmallIcon; 71 BBitmap *fLargeIcon; 72 }; 73 74 class TIconView; 75 class TBox; 76 class TWindowView; 77 class TSwitcherWindow; 78 struct window_info; 79 80 class TSwitchManager : public BHandler { 81 public: 82 TSwitchManager(BPoint where); 83 virtual ~TSwitchManager(); 84 85 virtual void MessageReceived(BMessage *message); 86 87 void Stop(bool doAction, uint32 mods); 88 void Unblock(); 89 int32 CurrentIndex(); 90 int32 CurrentWindow(); 91 int32 CurrentSlot(); 92 BList *GroupList(); 93 int32 CountVisibleGroups(); 94 95 void QuitApp(); 96 void CycleApp(bool forward, bool activate = false); 97 void CycleWindow(bool forward, bool wrap = true); 98 void SwitchToApp(int32 prevIndex, int32 newIndex, bool forward); 99 100 void Touch(bool zero = false); 101 bigtime_t IdleTime(); 102 103 window_info *WindowInfo(int32 groupIndex, int32 wdIndex); 104 int32 CountWindows(int32 groupIndex, bool inCurrentWorkspace = false); 105 TTeamGroup *FindTeam(team_id, int32 *index); 106 107 private: 108 void MainEntry(BMessage *message); 109 void Process(bool forward, bool byWindow = false); 110 void QuickSwitch(BMessage *message); 111 void SwitchWindow(team_id team, bool forward, bool activate); 112 bool ActivateApp(bool forceShow, bool allowWorkspaceSwitch); 113 void ActivateWindow(int32 windowID = -1); 114 115 TSwitcherWindow *fWindow; 116 sem_id fMainMonitor; 117 bool fBlock; 118 bigtime_t fSkipUntil; 119 BList fGroupList; 120 int32 fCurrentIndex; 121 int32 fCurrentWindow; 122 int32 fCurrentSlot; 123 int32 fWindowID; 124 bigtime_t fLastActivity; 125 }; 126 127 class TSwitcherWindow : public BWindow { 128 public: 129 TSwitcherWindow(BRect frame, TSwitchManager *mgr); 130 virtual ~TSwitcherWindow(); 131 132 virtual bool QuitRequested(); 133 virtual void DispatchMessage(BMessage *message, BHandler *target); 134 virtual void MessageReceived(BMessage *message); 135 virtual void Show(); 136 virtual void Hide(); 137 virtual void WindowActivated(bool state); 138 139 void DoKey(uint32 key, uint32 mods); 140 TIconView *IconView(); 141 TWindowView *WindowView(); 142 TBox *TopView(); 143 bool HairTrigger(); 144 void Update(int32 previous, int32 current, int32 prevSlot, 145 int32 currentSlot, bool forward); 146 int32 SlotOf(int32); 147 void Redraw(int32 index); 148 149 private: 150 TSwitchManager *fManager; 151 TIconView *fIconView; 152 TBox *fTopView; 153 TWindowView *fWindowView; 154 bool fHairTrigger; 155 }; 156 157 class TWindowView : public BView { 158 public: 159 TWindowView(BRect frame, TSwitchManager *manager, TSwitcherWindow *switcher); 160 161 void UpdateGroup(int32 groupIndex, int32 windowIndex); 162 163 virtual void AttachedToWindow(); 164 virtual void Draw(BRect update); 165 virtual void Pulse(); 166 virtual void GetPreferredSize(float *w, float *h); 167 void ScrollTo(float x, float y) 168 { ScrollTo(BPoint(x,y)); } 169 virtual void ScrollTo(BPoint where); 170 171 void ShowIndex(int32 windex); 172 BRect FrameOf(int32 index) const; 173 174 private: 175 int32 fCurrentToken; 176 float fItemHeight; 177 TSwitcherWindow *fSwitcher; 178 TSwitchManager *fManager; 179 bool fLocal; 180 }; 181 182 class TIconView : public BView { 183 public: 184 TIconView(BRect frame, TSwitchManager *manager, TSwitcherWindow *switcher); 185 ~TIconView(); 186 187 void Showing(); 188 void Hiding(); 189 190 virtual void KeyDown(const char *bytes, int32 numBytes); 191 virtual void Pulse(); 192 virtual void MouseDown(BPoint ); 193 virtual void Draw(BRect ); 194 195 void ScrollTo(float x, float y) 196 { ScrollTo(BPoint(x,y)); } 197 virtual void ScrollTo(BPoint where); 198 void Update(int32 previous, int32 current, int32 previousSlot, 199 int32 currentSlot, bool forward); 200 void DrawTeams(BRect update); 201 int32 SlotOf(int32) const; 202 BRect FrameOf(int32) const; 203 int32 ItemAtPoint(BPoint) const; 204 int32 IndexAt(int32 slot) const; 205 void CenterOn(int32 index); 206 207 private: 208 void CacheIcons(TTeamGroup *); 209 void AnimateIcon(BBitmap *startIcon, BBitmap *endIcon); 210 211 bool fAutoScrolling; 212 bool fCapsState; 213 TSwitcherWindow *fSwitcher; 214 TSwitchManager *fManager; 215 BBitmap *fOffBitmap; 216 BView *fOffView; 217 BBitmap *fCurrentSmall; 218 BBitmap *fCurrentLarge; 219 }; 220 221 class TBox : public BBox { 222 public: 223 TBox(BRect bounds, TSwitchManager *manager, TSwitcherWindow *, TIconView *iconView); 224 225 virtual void Draw(BRect update); 226 virtual void AllAttached(); 227 virtual void DrawIconScrollers(bool force); 228 virtual void DrawWindowScrollers(bool force); 229 virtual void MouseDown(BPoint where); 230 231 private: 232 TSwitchManager *fManager; 233 TSwitcherWindow *fWindow; 234 TIconView *fIconView; 235 BRect fCenter; 236 bool fLeftScroller; 237 bool fRightScroller; 238 bool fUpScroller; 239 bool fDownScroller; 240 }; 241 242 inline int32 243 TSwitcherWindow::SlotOf(int32 i) 244 { 245 return fIconView->SlotOf(i); 246 } 247 248 inline TIconView * 249 TSwitcherWindow::IconView() 250 { 251 return fIconView; 252 } 253 254 inline TWindowView * 255 TSwitcherWindow::WindowView() 256 { 257 return fWindowView; 258 } 259 260 inline void 261 TSwitchManager::Touch(bool zero) 262 { 263 fLastActivity = zero ? 0 : system_time(); 264 } 265 266 #endif /* SWITCHER_H */ 267