1 /* 2 * Copyright 2005-2009, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 9 10 #include "Workspace.h" 11 12 #include <math.h> 13 #include <stdio.h> 14 #include <stdlib.h> 15 16 #include <Debug.h> 17 18 #include "Desktop.h" 19 #include "WorkspacePrivate.h" 20 #include "Window.h" 21 22 23 static rgb_color kDefaultColor = (rgb_color){ 51, 102, 152, 255 }; 24 25 26 Workspace::Private::Private() 27 { 28 _SetDefaults(); 29 } 30 31 32 Workspace::Private::~Private() 33 { 34 } 35 36 37 void 38 Workspace::Private::SetDisplaysFromDesktop(Desktop* desktop) 39 { 40 } 41 42 43 void 44 Workspace::Private::SetColor(const rgb_color& color) 45 { 46 fColor = color; 47 } 48 49 50 void 51 Workspace::Private::RestoreConfiguration(const BMessage& settings) 52 { 53 rgb_color color; 54 if (settings.FindInt32("color", (int32 *)&color) == B_OK) 55 fColor = color; 56 57 fStoredScreenConfiguration.Restore(settings); 58 fCurrentScreenConfiguration.Restore(settings); 59 } 60 61 62 /*! \brief Store the workspace configuration in a message 63 */ 64 void 65 Workspace::Private::StoreConfiguration(BMessage& settings) 66 { 67 fStoredScreenConfiguration.Store(settings); 68 settings.AddInt32("color", *(int32 *)&fColor); 69 } 70 71 72 void 73 Workspace::Private::_SetDefaults() 74 { 75 fColor = kDefaultColor; 76 } 77 78 79 // #pragma mark - 80 81 82 Workspace::Workspace(Desktop& desktop, int32 index) 83 : 84 fWorkspace(desktop.WorkspaceAt(index)), 85 fDesktop(desktop), 86 fCurrentWorkspace(index == desktop.CurrentWorkspace()) 87 { 88 ASSERT(desktop.IsLocked()); 89 RewindWindows(); 90 } 91 92 93 Workspace::~Workspace() 94 { 95 } 96 97 98 const rgb_color& 99 Workspace::Color() const 100 { 101 return fWorkspace.Color(); 102 } 103 104 105 void 106 Workspace::SetColor(const rgb_color& color, bool makeDefault) 107 { 108 if (color == Color()) 109 return; 110 111 fWorkspace.SetColor(color); 112 fDesktop.RedrawBackground(); 113 if (makeDefault) 114 fDesktop.StoreWorkspaceConfiguration(fWorkspace.Index()); 115 } 116 117 118 status_t 119 Workspace::GetNextWindow(Window*& _window, BPoint& _leftTop) 120 { 121 if (fCurrent == NULL) 122 fCurrent = fWorkspace.Windows().FirstWindow(); 123 else 124 fCurrent = fCurrent->NextWindow(fWorkspace.Index()); 125 126 if (fCurrent == NULL) 127 return B_ENTRY_NOT_FOUND; 128 129 _window = fCurrent; 130 131 if (fCurrentWorkspace) 132 _leftTop = fCurrent->Frame().LeftTop(); 133 else 134 _leftTop = fCurrent->Anchor(fWorkspace.Index()).position; 135 136 return B_OK; 137 } 138 139 140 status_t 141 Workspace::GetPreviousWindow(Window*& _window, BPoint& _leftTop) 142 { 143 if (fCurrent == NULL) 144 fCurrent = fWorkspace.Windows().LastWindow(); 145 else 146 fCurrent = fCurrent->PreviousWindow(fWorkspace.Index()); 147 148 if (fCurrent == NULL) 149 return B_ENTRY_NOT_FOUND; 150 151 _window = fCurrent; 152 153 if (fCurrentWorkspace) 154 _leftTop = fCurrent->Frame().LeftTop(); 155 else 156 _leftTop = fCurrent->Anchor(fWorkspace.Index()).position; 157 158 return B_OK; 159 } 160 161 162 void 163 Workspace::RewindWindows() 164 { 165 fCurrent = NULL; 166 } 167 168