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