1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2005, Haiku, Inc. 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 // 22 // File Name: Workspace.h 23 // Author: Adi Oanca <adioanca@cotty.iren.com> 24 // Description: Tracks workspaces 25 // 26 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 27 // Notes: IMPORTANT WARNING 28 // This object does not use any locking mechanism. It is designed 29 // to be used only by RootLayer class. DO NOT USE from another class! 30 //------------------------------------------------------------------------------ 31 #ifndef _WORKSPACE_H_ 32 #define _WORKSPACE_H_ 33 34 #include <SupportDefs.h> 35 #include <Locker.h> 36 #include <Accelerant.h> 37 38 #include "RGBColor.h" 39 40 class WinBorder; 41 42 struct ListData 43 { 44 bool isFree; 45 WinBorder *layerPtr; 46 ListData *upperItem; 47 ListData *lowerItem; 48 }; 49 50 class Workspace { 51 public: 52 class State { 53 public: 54 State() : Front(NULL), Focus(NULL), WindowList(50) { } 55 56 void PrintToStream(); 57 58 WinBorder* Front; 59 WinBorder* Focus; 60 WinBorder* Active; 61 BList WindowList; 62 }; 63 Workspace( const int32 ID, 64 const uint32 colorspace, 65 const RGBColor& BGColor); 66 ~Workspace(); 67 68 int32 ID() const { return fID; } 69 70 void AddWinBorder(WinBorder *winBorder); 71 void RemoveWinBorder(WinBorder *winBorder); 72 bool HasWinBorder(const WinBorder *winBorder) const; 73 74 WinBorder* Focus() const; 75 WinBorder* Front() const; 76 WinBorder* Active() const; 77 void GetState(Workspace::State *state) const; 78 bool AttemptToSetFront(WinBorder *newFront); 79 int32 AttemptToSetFocus(WinBorder *newFocus); 80 bool AttemptToMoveToBack(WinBorder *newBack); 81 bool AttemptToActivate(WinBorder *toActivate); 82 83 bool GetWinBorderList(void **list, int32 *itemCount ) const; 84 85 bool MoveToBack(WinBorder *newLast); 86 bool MoveToFront(WinBorder *newFront, bool doNotDisturb = false); 87 88 bool HideWinBorder(WinBorder *winBorder); 89 bool ShowWinBorder(WinBorder *winBorder, bool userBusy = false); 90 91 // resolution related methods. 92 status_t SetDisplayMode(const display_mode &mode); 93 status_t GetDisplayMode(display_mode &mode) const; 94 95 void SetBGColor(const RGBColor &c); 96 RGBColor BGColor(void) const; 97 98 // settings related methods 99 void GetSettings(const BMessage &msg); 100 void GetDefaultSettings(void); 101 void PutSettings(BMessage *msg, const uint8 &index) const; 102 static void PutDefaultSettings(BMessage *msg, const uint8 &index); 103 104 // debug methods 105 void PrintToStream(void) const; 106 void PrintItem(ListData *item) const; 107 108 private: 109 void InsertItem(ListData *item, ListData *before); 110 void RemoveItem(ListData *item); 111 ListData* HasItem(const ListData *item, int32 *index = NULL) const; 112 ListData* HasItem(const WinBorder *layer, int32 *index = NULL) const; 113 int32 IndexOf(const ListData *item) const; 114 115 bool placeToBack(ListData *newLast); 116 void placeInFront(ListData *item, const bool userBusy); 117 118 int32 _SetFocus(ListData *newFocusItem); 119 120 bool removeAndPlaceBefore(const WinBorder *wb, ListData *beforeItem); 121 bool removeAndPlaceBefore(ListData *item, ListData *beforeItem); 122 123 WinBorder* searchFirstMainWindow(WinBorder *wb) const; 124 WinBorder* searchANormalWindow(WinBorder *wb) const; 125 126 bool windowHasVisibleModals(const WinBorder *winBorder) const; 127 ListData* putModalsInFront(ListData *item); 128 void putFloatingInFront(ListData *item); 129 void saveFloatingWindows(ListData *itemNormal); 130 131 ListData* findNextFront() const; 132 133 class MemoryPool 134 { 135 public: 136 MemoryPool(); 137 ~MemoryPool(); 138 ListData* GetCleanMemory(WinBorder* winborder); 139 void ReleaseMemory(ListData* mem); 140 private: 141 void expandBuffer(int32 start); 142 ListData *buffer; 143 int32 count; 144 }; 145 146 int32 fID; 147 RGBColor fBGColor; 148 149 // first visible onscreen 150 ListData *fBottomItem; 151 152 // the last visible(or covered by other Layers) 153 ListData *fTopItem; 154 155 // the focus WinBorder - for keyboard events 156 ListData *fFocusItem; 157 158 // pointer for which "big" actions are intended 159 ListData *fFrontItem; 160 161 // settings for each workspace 162 display_mode fDisplayMode; 163 164 MemoryPool fPool; 165 }; 166 167 #endif 168