Index: BackgroundsView.h
===================================================================
--- BackgroundsView.h	(revision 37293)
+++ BackgroundsView.h	(working copy)
@@ -4,6 +4,7 @@
  *
  * Authors:
  *		Jerome Duval (jerome.duval@free.fr)
+ *		Markku Hyppönen, make.hypponen@pp.inet.fi
  */
 #ifndef BACKGROUNDS_VIEW_H
 #define BACKGROUNDS_VIEW_H
@@ -40,14 +41,13 @@
 
 class BGImageMenuItem : public BMenuItem {
 public:
-							BGImageMenuItem(const char* label, int32 imageIndex,
-								BMessage* message, char shortcut = 0,
-								uint32 modifiers = 0);
+								BGImageMenuItem(const char* label,
+									int32 imageIndex, BMessage* message,
+									char shortcut = 0, uint32 modifiers = 0);
+			int32				ImageIndex() { return fImageIndex; }
 
-			int32			ImageIndex() { return fImageIndex; }
-
 private:
-			int32			fImageIndex;
+			int32				fImageIndex;
 };
 
 
@@ -65,118 +65,141 @@
 
 class FramePart : public BView {
 public:
-							FramePart(int32 part);
+								FramePart(int32 part);
+	virtual	void				Draw(BRect rect);
+			void				SetDesktop(bool isDesktop);
 
-			void			Draw(BRect rect);
-			void			SetDesktop(bool isDesktop);
-
 private:
-			void			_SetSizeAndAlignment();
+			void				_SetSizeAndAlignment();
 
-			int32			fFramePart;
-			bool			fIsDesktop;
+			int32				fFramePart;
+			bool				fIsDesktop;
 };
 
 
 class PreView : public BControl {
 public:
-							PreView();
+								PreView();
 
-			BPoint			fPoint;
-			BRect			fImageBounds;
+			BPoint				fPoint;
+			BRect				fImageBounds;
 
 protected:
-			void			MouseDown(BPoint point);
-			void			MouseUp(BPoint point);
-			void			MouseMoved(BPoint point, uint32 transit,
+	virtual	void				MouseDown(BPoint point);
+	virtual	void				MouseUp(BPoint point);
+	virtual	void				MouseMoved(BPoint point, uint32 transit,
 								const BMessage* message);
-			void			AttachedToWindow();
+	virtual	void				AttachedToWindow();
 
-			BPoint			fOldPoint;
-			float			fXRatio;
-			float			fYRatio;
-			display_mode	fMode;
-
-			BCursor			fMoveHandCursor;
+			BPoint				fOldPoint;
+			float				fXRatio;
+			float				fYRatio;
+			display_mode		fMode;
+			BCursor				fMoveHandCursor;
 };
 
 
-class BackgroundsView : public BBox {
+class Settings {
 public:
-							BackgroundsView();
-							~BackgroundsView();
+								Settings();
 
-			void			AllAttached();
-			void			MessageReceived(BMessage* msg);
+			int32				fWorkspace;
+			BackgroundImage*	fImage;
+			BackgroundImage::BackgroundImageInfo* fInfo;
+			rgb_color			fColor;
+			bool				fIsAllWorkspacesSelected;
 
-			void			RefsReceived(BMessage* msg);
+};
 
-			void			SaveSettings();
-			void			WorkspaceActivated(uint32 oldWorkspaces,
-								bool active);
-			int32			AddImage(BPath path);
-			Image*			GetImage(int32 imageIndex);
+class Controls {
+public:
+								Controls();
 
-			bool			FoundPositionSetting();
+			int32				fWorkspace;
+			rgb_color			fColor;
+			bool				fTextWidgetLabelOutline;
+			int32				fImageIndex;
+			int32				fPlacementIndex;
+			float				fOffsetX;
+			float				fOffsetY;
+};
 
-protected:
-			void			_Save();
-			void			_NotifyServer();
-			void			_LoadSettings();
-			void			_LoadDesktopFolder();
-			void			_LoadDefaultFolder();
-			void			_LoadFolder(bool isDesktop);
-			void			_LoadRecentFolder(BPath path);
-			void			_UpdateWithCurrent();
-			void			_UpdatePreview();
-			void			_UpdateButtons();
-			void			_SetDesktop(bool isDesktop);
-			int32			_AddPath(BPath path);
 
-	static	int32			_NotifyThread(void* data);
+class BackgroundsView : public BBox {
+public:
+								BackgroundsView();
+								~BackgroundsView();
+	virtual	void				AllAttached();
+	virtual void				MessageReceived(BMessage* msg);
+			void				RefsReceived(BMessage* msg);
+			void				SaveSettings();
+			void				WorkspaceActivated(uint32 workspace,
+									bool active);
+			int32				AddImage(BPath path);
+			Image*				GetImage(int32 imageIndex);
+			bool				FoundPositionSetting();
 
+protected:
+			void				_Save();
+			void				_Revert();
+			void				_RevertTo(BackgroundImage*& image,
+									BackgroundImage::BackgroundImageInfo*& info,
+									rgb_color& color);
+			void				_NotifyServer();
+			void				_LoadSettings();
+			void				_LoadDesktopFolder();
+			void				_LoadDefaultFolder();
+			void				_LoadFolder(bool isDesktop);
+			void				_LoadRecentFolder(BPath path);
+			void				_UpdateWithCurrent();
+			void				_UpdatePreview();
+			void				_UpdateButtons();
+			void				_SetDesktop(bool isDesktop);
+			int32				_AddPath(BPath path);
+	static	int32				_NotifyThread(void* data);
 			BGImageMenuItem*	_FindImageItem(const int32 imageIndex);
+			bool				_AddItem(BGImageMenuItem* item);
+			BackgroundImage::Mode _FindPlacementMode();
+			void				_SetInitialSettings();
+			void				_SetControlSettings(int32 workspace);
+			Settings*			_GetInitialSettings(int32 workspace);
+			Controls*			_GetControlSettings(int32 workspace,
+									bool remove);
+			void				_ResetControlSettings();
 
-			bool			_AddItem(BGImageMenuItem* item);
-
-			BackgroundImage::Mode	_FindPlacementMode();
-
-			BColorControl*	fPicker;
-			BButton*		fApply;
-			BButton*		fRevert;
-			BCheckBox*		fIconLabelOutline;
-			BMenu*			fPlacementMenu;
-			BMenu*			fImageMenu;
-			BMenu*			fWorkspaceMenu;
-			BTextControl*	fXPlacementText;
-			BTextControl*	fYPlacementText;
-			PreView*		fPreView;
-			BBox*			fPreview;
-			BFilePanel*		fFolderPanel;
-			ImageFilePanel*	fPanel;
-
+			BColorControl*		fPicker;
+			BButton*			fApply;
+			BButton*			fRevert;
+			BCheckBox*			fIconLabelOutline;
+			BMenu*				fPlacementMenu;
+			BMenu*				fImageMenu;
+			BMenu*				fWorkspaceMenu;
+			BTextControl*		fXPlacementText;
+			BTextControl*		fYPlacementText;
+			PreView*			fPreView;
+			BBox*				fPreview;
+			BFilePanel*			fFolderPanel;
+			ImageFilePanel*		fPanel;
 			BackgroundImage*	fCurrent;
-
-			BackgroundImage::BackgroundImageInfo*	fCurrentInfo;
-
-			entry_ref		fCurrentRef;
-			int32			fLastImageIndex;
-			int32			fLastWorkspaceIndex;
-			BMessage		fSettings;
-
+			BackgroundImage::BackgroundImageInfo* fCurrentInfo;
+			entry_ref			fCurrentRef;
+			int32				fLastImageIndex;
+			int32				fLastWorkspaceIndex;
+			BMessage			fSettings;
 			BObjectList<BPath>	fPathList;
 			BObjectList<Image>	fImageList;
-
-			FramePart*		fTopLeft;
-			FramePart*		fTop;
-			FramePart*		fTopRight;
-			FramePart*		fLeft;
-			FramePart*		fRight;
-			FramePart*		fBottomLeft;
-			FramePart*		fBottom;
-			FramePart*		fBottomRight;
-
-			bool			fFoundPositionSetting;
+			FramePart*			fTopLeft;
+			FramePart*			fTop;
+			FramePart*			fTopRight;
+			FramePart*			fLeft;
+			FramePart*			fRight;
+			FramePart*			fBottomLeft;
+			FramePart*			fBottom;
+			FramePart*			fBottomRight;
+			bool				fFoundPositionSetting;
+			rgb_color			color;
+			BObjectList<Settings>* fInitialSettings;
+			BObjectList<Controls>* fControlSettings;
 };
 
 #endif	// BACKGROUNDS_VIEW_H
Index: BackgroundsView.cpp
===================================================================
--- BackgroundsView.cpp	(revision 37293)
+++ BackgroundsView.cpp	(working copy)
@@ -6,6 +6,7 @@
  *		Jerome Duval (jerome.duval@free.fr)
  *		Axel Dörfler, axeld@pinc-software.de
  *		Jonas Sundström, jonas@kirilla.se
+ *		Markku Hyppönen, make.hypponen@pp.inet.fi
  */
 
 
@@ -179,8 +180,7 @@
 		B_TRANSLATE("Current workspace"),
 		new BMessage(kMsgCurrentWorkspace)));
 	menuItem->SetMarked(true);
-	fLastWorkspaceIndex =
-		fWorkspaceMenu->IndexOf(fWorkspaceMenu->FindMarked());
+	fLastWorkspaceIndex = fWorkspaceMenu->IndexOf(fWorkspaceMenu->FindMarked());
 	fWorkspaceMenu->AddSeparatorItem();
 	fWorkspaceMenu->AddItem(new BMenuItem(B_TRANSLATE("Default folder"),
 		new BMessage(kMsgDefaultFolder)));
@@ -333,12 +333,12 @@
 
 
 void
-BackgroundsView::MessageReceived(BMessage* msg)
+BackgroundsView::MessageReceived(BMessage* message)
 {
-	switch (msg->what) {
+	switch (message->what) {
 		case B_SIMPLE_DATA:
 		case B_REFS_RECEIVED:
-			RefsReceived(msg);
+			RefsReceived(message);
 			break;
 
 		case kMsgUpdatePreviewPlacement:
@@ -354,10 +354,8 @@
 		}
 
 		case kMsgManualPlacement:
-			_UpdatePreview();
-			_UpdateButtons();
-			break;
-
+		case kMsgUpdateColor:
+		case kMsgImagePlacement:
 		case kMsgTilePlacement:
 		case kMsgScalePlacement:
 		case kMsgCenterPlacement:
@@ -369,12 +367,6 @@
 			_UpdateButtons();
 			break;
 
-		case kMsgUpdateColor:
-		case kMsgImagePlacement:
-			_UpdatePreview();
-			_UpdateButtons();
-			break;
-
 		case kMsgCurrentWorkspace:
 		case kMsgAllWorkspaces:
 			fImageMenu->FindItem(kMsgNoImage)->SetLabel(B_TRANSLATE("None"));
@@ -408,7 +400,7 @@
 		{
 			PRINT(("cancel received\n"));
 			void* pointer;
-			msg->FindPointer("source", &pointer);
+			message->FindPointer("source", &pointer);
 			if (pointer == fPanel) {
 				if (fLastImageIndex >= 0)
 					_FindImageItem(fLastImageIndex)->SetMarked(true);
@@ -445,19 +437,19 @@
 			_Save();
 
 			//_NotifyServer();
-			thread_id notify_thread;
-			notify_thread = spawn_thread(BackgroundsView::_NotifyThread,
+			thread_id notifyThread;
+			notifyThread = spawn_thread(BackgroundsView::_NotifyThread,
 				"notifyServer", B_NORMAL_PRIORITY, this);
-			resume_thread(notify_thread);
+			resume_thread(notifyThread);
 			_UpdateButtons();
 			break;
 		}
 		case kMsgRevertSettings:
-			_UpdateWithCurrent();
+			_Revert();
 			break;
 
 		default:
-			BView::MessageReceived(msg);
+			BView::MessageReceived(message);
 			break;
 	}
 }
@@ -468,9 +460,9 @@
 {
 	BPath path;
 	if (find_directory(B_DESKTOP_DIRECTORY, &path) == B_OK) {
-		status_t err;
-		err = get_ref_for_path(path.Path(), &fCurrentRef);
-		if (err != B_OK)
+		status_t error;
+		error = get_ref_for_path(path.Path(), &fCurrentRef);
+		if (error != B_OK)
 			printf("error in LoadDesktopSettings\n");
 		_LoadFolder(true);
 	}
@@ -484,9 +476,9 @@
 	if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
 		BString pathString = path.Path();
 		pathString << "/Tracker/DefaultFolderTemplate";
-		status_t err;
-		err = get_ref_for_path(pathString.String(), &fCurrentRef);
-		if (err != B_OK)
+		status_t error;
+		error = get_ref_for_path(pathString.String(), &fCurrentRef);
+		if (error != B_OK)
 			printf("error in LoadDefaultFolderSettings\n");
 		_LoadFolder(false);
 	}
@@ -496,15 +488,113 @@
 void
 BackgroundsView::_LoadRecentFolder(BPath path)
 {
-	status_t err;
-	err = get_ref_for_path(path.Path(), &fCurrentRef);
-	if (err != B_OK)
+	status_t error;
+	error = get_ref_for_path(path.Path(), &fCurrentRef);
+	if (error != B_OK)
 		printf("error in LoadRecentFolder\n");
 	_LoadFolder(false);
 }
 
 
+Settings*
+BackgroundsView::_GetInitialSettings(int32 workspace)
+{
+	for (int32 i=0; i < fInitialSettings->CountItems(); i++) {
+		Settings* settings = (Settings*)fInitialSettings->ItemAt(i);
+		if (settings != NULL && settings->fWorkspace == workspace)
+			return settings;
+	}
+	return NULL;
+}
+
+
+Controls*
+BackgroundsView::_GetControlSettings(int32 workspace, bool remove)
+{
+	if (fControlSettings == NULL)
+		fControlSettings = new BObjectList<Controls>();
+
+	int32 count = fControlSettings->CountItems();
+
+	for (int32 i=0; i < count; i++) {
+	Controls* controls = (Controls*)fControlSettings->ItemAt(i);
+		if (controls != NULL && controls->fWorkspace == workspace) {
+			if (remove)
+				return fControlSettings->RemoveItemAt(i);
+			else
+				return controls;
+		}			
+	}
+	return NULL;
+}
+
+
 void
+BackgroundsView::_SetInitialSettings()
+{
+	if (fInitialSettings == NULL)
+		fInitialSettings = new BObjectList<Settings>();
+
+	if (_GetInitialSettings(current_workspace()) == NULL) {
+		BNode node(&fCurrentRef);
+		if (node.InitCheck() != B_OK)
+			return;
+
+		Settings* settings = new Settings();
+		settings->fWorkspace = current_workspace();
+		settings->fColor = BScreen().DesktopColor();
+		settings->fImage =
+				BackgroundImage::GetBackgroundImage(&node, true, this);
+		settings->fInfo = settings->fImage
+				->ImageInfoForWorkspace(current_workspace());
+
+		fInitialSettings->AddItem(settings);
+	} 
+}
+
+void
+BackgroundsView::_SetControlSettings(int32 workspace)
+{
+	if (fControlSettings == NULL)
+		fControlSettings = new BObjectList<Controls>();
+
+	Controls* controls = _GetControlSettings(workspace, true);
+
+	if (controls != NULL)
+		delete controls;
+
+	controls = new Controls();
+	rgb_color color = fPicker->ValueAsColor();
+
+	controls->fWorkspace = workspace;
+	controls->fColor = color;
+	controls->fTextWidgetLabelOutline =
+			fIconLabelOutline->Value() == B_CONTROL_ON;
+	controls->fImageIndex = fImageMenu->IndexOf(fImageMenu->FindMarked());
+	controls->fPlacementIndex =
+			fPlacementMenu->IndexOf(fPlacementMenu->FindMarked());
+	controls->fOffsetX = atoi(fXPlacementText->Text());
+	controls->fOffsetY = atoi(fYPlacementText->Text());
+	
+	fControlSettings->AddItem(controls);
+
+
+}
+
+void
+BackgroundsView::_ResetControlSettings()
+{
+	if (!fControlSettings)
+		return;
+
+	if (fWorkspaceMenu->IndexOf(fWorkspaceMenu->FindMarked()) == 0) {
+		while (fControlSettings->CountItems() > 0) {
+			delete fControlSettings->RemoveItemAt(0);
+		}
+	}
+}
+
+void
 BackgroundsView::_LoadFolder(bool isDesktop)
 {
 	if (fCurrent) {
@@ -513,9 +603,10 @@
 	}
 
 	BNode node(&fCurrentRef);
-	if (node.InitCheck() == B_OK)
+	if (node.InitCheck() == B_OK) {
 		fCurrent = BackgroundImage::GetBackgroundImage(&node, isDesktop, this);
-
+		_SetInitialSettings();
+	}
 	_UpdateWithCurrent();
 }
 
@@ -523,13 +614,38 @@
 void
 BackgroundsView::_UpdateWithCurrent(void)
 {
-	if (fCurrent == NULL)
+	rgb_color color = BScreen().DesktopColor();
+	_RevertTo(fCurrent,fCurrentInfo,color);
+	_UpdatePreview();
+	_UpdateButtons();
+}
+
+
+void
+BackgroundsView::_Revert()
+{
+	Settings* bgInfo = (Settings*)_GetInitialSettings(current_workspace());
+	_RevertTo(bgInfo->fImage,bgInfo->fInfo,bgInfo->fColor);
+	_ResetControlSettings();
+	_SetInitialSettings();
+	_UpdatePreview();
+	_UpdateButtons();
+
+	fRevert->SetEnabled(false);
+}
+
+
+void
+BackgroundsView::_RevertTo(BackgroundImage*& image, 
+	BackgroundImage::BackgroundImageInfo*& info, rgb_color& color)
+{
+	if (image == NULL)
 		return;
 
 	fPlacementMenu->FindItem(kMsgScalePlacement)
-		->SetEnabled(fCurrent->IsDesktop());
+		->SetEnabled(image->IsDesktop());
 	fPlacementMenu->FindItem(kMsgCenterPlacement)
-		->SetEnabled(fCurrent->IsDesktop());
+		->SetEnabled(image->IsDesktop());
 
 	if (fWorkspaceMenu->IndexOf(fWorkspaceMenu->FindMarked()) > 5)
 		fImageMenu->FindItem(kMsgNoImage)->SetLabel(B_TRANSLATE("Default"));
@@ -546,36 +662,38 @@
 	}
 
 	fImageMenu->SetTargetForItems(this);
+        
+	info = image->ImageInfoForWorkspace(current_workspace());
 
-	fCurrentInfo = fCurrent->ImageInfoForWorkspace(current_workspace());
-
-	if (!fCurrentInfo) {
+	if (!info) {
 		fImageMenu->FindItem(kMsgNoImage)->SetMarked(true);
 		fPlacementMenu->FindItem(kMsgManualPlacement)->SetMarked(true);
 		fIconLabelOutline->SetValue(B_CONTROL_ON);
 	} else {
-		fIconLabelOutline->SetValue(fCurrentInfo->fTextWidgetLabelOutline
+		fIconLabelOutline->SetValue(info->fTextWidgetLabelOutline
 			? B_CONTROL_ON : B_CONTROL_OFF);
 
-		fLastImageIndex = fCurrentInfo->fImageIndex;
+		fLastImageIndex = info->fImageIndex;
 		_FindImageItem(fLastImageIndex)->SetMarked(true);
 
 		if (fLastImageIndex > -1) {
-
 			BString xtext, ytext;
 			int32 cmd = 0;
-			switch (fCurrentInfo->fMode) {
+			switch (info->fMode) {
 				case BackgroundImage::kCentered:
 					cmd = kMsgCenterPlacement;
 					break;
+
 				case BackgroundImage::kScaledToFit:
 					cmd = kMsgScalePlacement;
 					break;
+
 				case BackgroundImage::kAtOffset:
 					cmd = kMsgManualPlacement;
-					xtext << (int)fCurrentInfo->fOffset.x;
-					ytext << (int)fCurrentInfo->fOffset.y;
+					xtext << (int)info->fOffset.x;
+					ytext << (int)info->fOffset.y;
 					break;
+
 				case BackgroundImage::kTiled:
 					cmd = kMsgTilePlacement;
 					break;
@@ -591,26 +709,15 @@
 		}
 	}
 
-	rgb_color color = {255, 255, 255, 255};
-	if (fCurrent->IsDesktop()) {
-		color = BScreen().DesktopColor();
-		fPicker->SetEnabled(true);
-	} else
-		fPicker->SetEnabled(false);
-
+	fPicker->SetEnabled(true);
 	fPicker->SetValue(color);
-
-	_UpdatePreview();
-	_UpdateButtons();
 }
 
 
 void
 BackgroundsView::_Save()
 {
-	bool textWidgetLabelOutline
-		= fIconLabelOutline->Value() == B_CONTROL_ON;
-
+	bool textWidgetLabelOutline = fIconLabelOutline->Value() == B_CONTROL_ON;
 	BackgroundImage::Mode mode = _FindPlacementMode();
 	BPoint offset(atoi(fXPlacementText->Text()), atoi(fYPlacementText->Text()));
 
@@ -637,8 +744,8 @@
 			if (fWorkspaceMenu->FindItem(kMsgCurrentWorkspace)->IsMarked()) {
 				if (fCurrentInfo->fWorkspace & workspaceMask
 					&& fCurrentInfo->fWorkspace != workspaceMask) {
-					fCurrentInfo->fWorkspace = fCurrentInfo->fWorkspace
-						^ workspaceMask;
+					fCurrentInfo->fWorkspace =
+						fCurrentInfo->fWorkspace ^ workspaceMask;
 					fCurrentInfo = new BackgroundImage::BackgroundImageInfo(
 						workspaceMask, fLastImageIndex, mode, offset,
 						textWidgetLabelOutline, fCurrentInfo->fImageSet,
@@ -704,36 +811,36 @@
 	} else {
 		int32 i = -1;
 		BMessage reply;
-		int32 err;
+		int32 error;
 		BEntry currentEntry(&fCurrentRef);
 		BPath currentPath(&currentEntry);
 		bool isCustomFolder
 			= !fWorkspaceMenu->FindItem(kMsgDefaultFolder)->IsMarked();
 
 		do {
-			BMessage msg(B_GET_PROPERTY);
+			BMessage message = B_GET_PROPERTY;
 			i++;
 
 			// look at the "Poses" in every Tracker window
-			msg.AddSpecifier("Poses");
-			msg.AddSpecifier("Window", i);
+			message.AddSpecifier("Poses");
+			message.AddSpecifier("Window", i);
 
 			reply.MakeEmpty();
-			tracker.SendMessage(&msg, &reply);
+			tracker.SendMessage(&message, &reply);
 
 			// break out of the loop when we're at the end of
 			// the windows
 			if (reply.what == B_MESSAGE_NOT_UNDERSTOOD
-				&& reply.FindInt32("error", &err) == B_OK
-				&& err == B_BAD_INDEX)
+				&& reply.FindInt32("error", &error) == B_OK
+				&& error == B_BAD_INDEX)
 				break;
 
 			// don't stop for windows that don't understand
 			// a request for "Poses"; they're not displaying
 			// folders
 			if (reply.what == B_MESSAGE_NOT_UNDERSTOOD
-				&& reply.FindInt32("error", &err) == B_OK
-				&& err != B_BAD_SCRIPT_SYNTAX)
+				&& reply.FindInt32("error", &error) == B_OK
+				&& error != B_BAD_SCRIPT_SYNTAX)
 				continue;
 
 			BMessenger trackerWindow;
@@ -742,14 +849,14 @@
 
 			if (isCustomFolder) {
 				// found a window with poses, ask for its path
-				msg.MakeEmpty();
-				msg.what = B_GET_PROPERTY;
-				msg.AddSpecifier("Path");
-				msg.AddSpecifier("Poses");
-				msg.AddSpecifier("Window", i);
+				message.MakeEmpty();
+				message.what = B_GET_PROPERTY;
+				message.AddSpecifier("Path");
+				message.AddSpecifier("Poses");
+				message.AddSpecifier("Window", i);
 
 				reply.MakeEmpty();
-				tracker.SendMessage(&msg, &reply);
+				tracker.SendMessage(&message, &reply);
 
 				// go on with the next if this din't have a path
 				if (reply.what == B_MESSAGE_NOT_UNDERSTOOD)
@@ -854,9 +961,9 @@
 
 		path.SetTo(string.String());
 		int32 i = _AddPath(path);
-		BString s;
-		s << B_TRANSLATE("Folder: ") << path.Leaf();
-		BMenuItem* item = new BMenuItem(s.String(),
+		BString title;
+		title << B_TRANSLATE("Folder: ") << path.Leaf();
+		BMenuItem* item = new BMenuItem(title.String(),
 			new BMessage(kMsgFolderSelected));
 		fWorkspaceMenu->AddItem(item, -i - 1 + 6);
 		index++;
@@ -868,9 +975,40 @@
 
 
 void
-BackgroundsView::WorkspaceActivated(uint32 oldWorkspaces, bool active)
+BackgroundsView::WorkspaceActivated(uint32 workspace, bool active)
 {
+	rgb_color color = fPicker->ValueAsColor();
+
+	if ((int)workspace == current_workspace()) {		
+		return;
+	} else {
+		_SetControlSettings(workspace);
+	}
+
+	_SetInitialSettings();
 	_UpdateWithCurrent();
+	_UpdatePreview();
+
+	Controls* controls =
+			(Controls*)_GetControlSettings(current_workspace(),false);
+
+	if (controls != NULL) {
+		fPicker->SetValue(controls->fColor);
+		fIconLabelOutline->SetValue(controls->fTextWidgetLabelOutline ?
+			B_CONTROL_ON : B_CONTROL_OFF);
+
+		fImageMenu->ItemAt(controls->fImageIndex)->SetMarked(true);
+		fPlacementMenu->ItemAt(controls->fPlacementIndex)->SetMarked(true);
+		
+		BString xtext, ytext;
+		xtext << (int)controls->fOffsetX;
+		ytext << (int)controls->fOffsetY;
+		fXPlacementText->SetText(xtext);
+		fYPlacementText->SetText(ytext);
+
+		_UpdateButtons();
+		_UpdatePreview();
+	}
 }
 
 
@@ -886,6 +1024,7 @@
 		&& imageEnabled;
 	if (fXPlacementText->IsEnabled() ^ textEnabled)
 		fXPlacementText->SetEnabled(textEnabled);
+
 	if (fYPlacementText->IsEnabled() ^ textEnabled)
 		fYPlacementText->SetEnabled(textEnabled);
 
@@ -939,10 +1078,13 @@
 
 	if (fPlacementMenu->FindItem(kMsgCenterPlacement)->IsMarked())
 		mode = BackgroundImage::kCentered;
+
 	if (fPlacementMenu->FindItem(kMsgScalePlacement)->IsMarked())
 		mode = BackgroundImage::kScaledToFit;
+
 	if (fPlacementMenu->FindItem(kMsgManualPlacement)->IsMarked())
 		mode = BackgroundImage::kAtOffset;
+
 	if (fPlacementMenu->FindItem(kMsgTilePlacement)->IsMarked())
 		mode = BackgroundImage::kTiled;
 
@@ -953,55 +1095,95 @@
 void
 BackgroundsView::_UpdateButtons()
 {
-	bool hasChanged = false;
+	Settings* initialSettings =
+			(Settings*)_GetInitialSettings(current_workspace());
+
+	if (initialSettings == NULL) {
+		return;
+	}
+
+	BackgroundImage* image = initialSettings->fImage;
+	BackgroundImage::BackgroundImageInfo* info = initialSettings->fInfo;
+	rgb_color color = initialSettings->fColor;
+	bool differsFromInitial = false;
+	bool differsFromControls = false;
+
 	if (fPicker->IsEnabled()
 		&& fPicker->ValueAsColor() != BScreen().DesktopColor()) {
-		hasChanged = true;
+		differsFromControls = true;
 	} else if (fCurrentInfo) {
 		if ((fIconLabelOutline->Value() == B_CONTROL_ON)
 			^ fCurrentInfo->fTextWidgetLabelOutline) {
-			hasChanged = true;
+			differsFromControls = true;
 		} else if (_FindPlacementMode() != fCurrentInfo->fMode) {
-			hasChanged = true;
+			differsFromControls = true;
 		} else if (fCurrentInfo->fImageIndex
 			!= ((BGImageMenuItem*)fImageMenu->FindMarked())->ImageIndex()) {
-			hasChanged = true;
-		} else if (fCurrent->IsDesktop()
+			differsFromControls = true;
+		} else if (image->IsDesktop()
 			&& ((fCurrentInfo->fWorkspace != B_ALL_WORKSPACES)
 				^ (fWorkspaceMenu->FindItem(kMsgCurrentWorkspace)->IsMarked())))
 		{
-			hasChanged = true;
+			differsFromControls = true;
 		} else if (fCurrentInfo->fImageIndex > -1
 			&& fCurrentInfo->fMode == BackgroundImage::kAtOffset) {
-			BString oldString, newString;
+			BString oldString;
 			oldString << (int)fCurrentInfo->fOffset.x;
 			if (oldString != BString(fXPlacementText->Text())) {
-				hasChanged = true;
+				differsFromControls = true;
 			}
 			oldString = "";
 			oldString << (int)fCurrentInfo->fOffset.y;
 			if (oldString != BString(fYPlacementText->Text())) {
-				hasChanged = true;
+				differsFromControls = true;
 			}
 		}
-	} else if (fImageMenu->IndexOf(fImageMenu->FindMarked()) > 0) {
-		hasChanged = true;
+	}
+
+	if (fPicker->IsEnabled()
+		&& fPicker->ValueAsColor() != color) {
+		differsFromInitial = true;
+	} else if (info) {
+		if ((fIconLabelOutline->Value() == B_CONTROL_ON)
+			^ info->fTextWidgetLabelOutline) {
+			differsFromInitial = true;
+		} else if (_FindPlacementMode() != info->fMode) {
+			differsFromInitial = true;
+		} else if (info->fImageIndex
+			!= ((BGImageMenuItem*)fImageMenu->FindMarked())->ImageIndex()) {
+			differsFromInitial = true;
+		} else if (info->fImageIndex > -1
+			&& info->fMode == BackgroundImage::kAtOffset) {
+			BString oldString;
+			oldString << (int)info->fOffset.x;
+			if (oldString != BString(fXPlacementText->Text())) {
+				differsFromInitial = true;
+			}
+			oldString = "";
+			oldString << (int)info->fOffset.y;
+			if (oldString != BString(fYPlacementText->Text())) {
+				differsFromInitial = true;
+			}
+		}
+	} else if (fImageMenu->IndexOf(fImageMenu->FindMarked())
+			!= info->fImageIndex) {
+		differsFromInitial = true;
 	} else if (fIconLabelOutline->Value() == B_CONTROL_OFF) {
-		hasChanged = true;
+		differsFromInitial = true;
 	}
 
-	fApply->SetEnabled(hasChanged);
-	fRevert->SetEnabled(hasChanged);
+	fApply->SetEnabled(differsFromControls);
+	fRevert->SetEnabled(differsFromInitial);
 }
 
 
 void
-BackgroundsView::RefsReceived(BMessage* msg)
+BackgroundsView::RefsReceived(BMessage* message)
 {
-	if (!msg->HasRef("refs") && msg->HasRef("dir_ref")) {
+	if (!message->HasRef("refs") && message->HasRef("dir_ref")) {
 		entry_ref dirRef;
-		if (msg->FindRef("dir_ref", &dirRef) == B_OK)
-			msg->AddRef("refs", &dirRef);
+		if (message->FindRef("dir_ref", &dirRef) == B_OK)
+			message->AddRef("refs", &dirRef);
 	}
 
 	entry_ref ref;
@@ -1010,7 +1192,7 @@
 	BPath desktopPath;
 	find_directory(B_DESKTOP_DIRECTORY, &desktopPath);
 
-	while (msg->FindRef("refs", i++, &ref) == B_OK) {
+	while (message->FindRef("refs", i++, &ref) == B_OK) {
 		BPath path;
 		BEntry entry(&ref, true);
 		path.SetTo(&entry);
@@ -1038,7 +1220,7 @@
 
 			// An optional placement may have been sent
 			int32 placement = 0;
-			if (msg->FindInt32("placement", &placement) == B_OK) {
+			if (message->FindInt32("placement", &placement) == B_OK) {
 				BMenuItem* item = fPlacementMenu->FindItem(placement);
 				if (item)
 					item->SetMarked(true);
@@ -1059,9 +1241,9 @@
 			} else {
 				if (fWorkspaceMenu->CountItems() <= 5)
 					fWorkspaceMenu->AddSeparatorItem();
-				BString s;
-				s << B_TRANSLATE("Folder: ") << path.Leaf();
-				item = new BMenuItem(s.String(),
+				BString title;
+				title << B_TRANSLATE("Folder: ") << path.Leaf();
+				item = new BMenuItem(title.String(),
 					new BMessage(kMsgFolderSelected));
 				fWorkspaceMenu->AddItem(item, -index - 1 + 6);
 				item->SetTarget(this);
@@ -1646,3 +1828,18 @@
 	}
 }
 
+
+Settings::Settings()
+	:	
+	fImage(NULL),
+	fInfo(NULL),
+	fColor(rgb_color())
+{
+}
+
+
+Controls::Controls()
+	:
+	fColor(rgb_color())
+{
+}
