xref: /haiku/src/servers/app/Workspace.cpp (revision 17889a8c70dbb3d59c1412f6431968753c767bab)
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, bool readOnly)
83 	:
84 	fWorkspace(desktop.WorkspaceAt(index)),
85 	fDesktop(desktop),
86 	fCurrentWorkspace(index == desktop.CurrentWorkspace())
87 {
88 	ASSERT(desktop.WindowLocker().IsWriteLocked()
89 		|| ( readOnly && desktop.WindowLocker().IsReadLocked()));
90 	RewindWindows();
91 }
92 
93 
94 Workspace::~Workspace()
95 {
96 }
97 
98 
99 const rgb_color&
100 Workspace::Color() const
101 {
102 	return fWorkspace.Color();
103 }
104 
105 
106 void
107 Workspace::SetColor(const rgb_color& color, bool makeDefault)
108 {
109 	if (color == Color())
110 		return;
111 
112 	fWorkspace.SetColor(color);
113 	fDesktop.RedrawBackground();
114 	if (makeDefault)
115 		fDesktop.StoreWorkspaceConfiguration(fWorkspace.Index());
116 }
117 
118 
119 status_t
120 Workspace::GetNextWindow(Window*& _window, BPoint& _leftTop)
121 {
122 	if (fCurrent == NULL)
123 		fCurrent = fWorkspace.Windows().FirstWindow();
124 	else
125 		fCurrent = fCurrent->NextWindow(fWorkspace.Index());
126 
127 	if (fCurrent == NULL)
128 		return B_ENTRY_NOT_FOUND;
129 
130 	_window = fCurrent;
131 
132 	if (fCurrentWorkspace)
133 		_leftTop = fCurrent->Frame().LeftTop();
134 	else
135 		_leftTop = fCurrent->Anchor(fWorkspace.Index()).position;
136 
137 	return B_OK;
138 }
139 
140 
141 status_t
142 Workspace::GetPreviousWindow(Window*& _window, BPoint& _leftTop)
143 {
144 	if (fCurrent == NULL)
145 		fCurrent = fWorkspace.Windows().LastWindow();
146 	else
147 		fCurrent = fCurrent->PreviousWindow(fWorkspace.Index());
148 
149 	if (fCurrent == NULL)
150 		return B_ENTRY_NOT_FOUND;
151 
152 	_window = fCurrent;
153 
154 	if (fCurrentWorkspace)
155 		_leftTop = fCurrent->Frame().LeftTop();
156 	else
157 		_leftTop = fCurrent->Anchor(fWorkspace.Index()).position;
158 
159 	return B_OK;
160 }
161 
162 
163 void
164 Workspace::RewindWindows()
165 {
166 	fCurrent = NULL;
167 }
168 
169