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