1/*
2 * Copyright 2002-2009 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Jerome Duval, jerome.duval@free.fr
7 */
8#ifndef BACKGROUNDS_VIEW_H
9#define BACKGROUNDS_VIEW_H
10
11
12#include <Box.h>
13#include <Button.h>
14#include <CheckBox.h>
15#include <ColorControl.h>
16#include <Control.h>
17#include <Cursor.h>
18#include <Entry.h>
19#include <FilePanel.h>
20#include <Menu.h>
21#include <MenuItem.h>
22#include <Message.h>
23#include <Picture.h>
24#include <Screen.h>
25#include <ScrollView.h>
26#include <ScrollBar.h>
27#include <String.h>
28#include <StringView.h>
29#include <TextControl.h>
30#include <View.h>
31
32#include "BackgroundImage.h"
33
34
35#define SETTINGS_FILE		"Backgrounds_settings"
36
37
38class ImageFilePanel;
39
40
41class BGImageMenuItem : public BMenuItem {
42public:
43							BGImageMenuItem(const char* label, int32 imageIndex,
44								BMessage* message, char shortcut = 0,
45								uint32 modifiers = 0);
46
47			int32			ImageIndex() { return fImageIndex; }
48
49private:
50			int32			fImageIndex;
51};
52
53
54enum frame_parts {
55	FRAME_TOP_LEFT = 0,
56	FRAME_TOP,
57	FRAME_TOP_RIGHT,
58	FRAME_LEFT_SIDE,
59	FRAME_RIGHT_SIDE,
60	FRAME_BOTTOM_LEFT,
61	FRAME_BOTTOM,
62	FRAME_BOTTOM_RIGHT,
63};
64
65
66class FramePart : public BView {
67public:
68								FramePart(int32 part);
69
70	virtual	void				Draw(BRect rect);
71			void				SetDesktop(bool isDesktop);
72
73private:
74			void				_SetSizeAndAlignment();
75
76			int32				fFramePart;
77			bool				fIsDesktop;
78};
79
80
81class Preview : public BControl {
82public:
83								Preview();
84
85			BPoint				fPoint;
86			BRect				fImageBounds;
87
88protected:
89	virtual	void				MouseDown(BPoint point);
90	virtual	void				MouseUp(BPoint point);
91	virtual	void				MouseMoved(BPoint point, uint32 transit,
92									const BMessage* message);
93	virtual	void				AttachedToWindow();
94
95			BPoint				fOldPoint;
96			float				fXRatio;
97			float				fYRatio;
98			display_mode		fMode;
99};
100
101
102class BackgroundsView : public BBox {
103public:
104								BackgroundsView();
105								~BackgroundsView();
106
107			void				AllAttached();
108			void				MessageReceived(BMessage* message);
109
110			void				RefsReceived(BMessage* message);
111
112			void				SaveSettings();
113			void				WorkspaceActivated(uint32 oldWorkspaces,
114									bool active);
115			int32				AddImage(BPath path);
116			Image*				GetImage(int32 imageIndex);
117
118			bool				FoundPositionSetting();
119
120protected:
121			void				_Save();
122			void				_NotifyServer();
123			void				_NotifyScreenPreflet();
124			void				_LoadSettings();
125			void				_LoadDesktopFolder();
126			void				_LoadDefaultFolder();
127			void				_LoadFolder(bool isDesktop);
128			void				_LoadRecentFolder(BPath path);
129			void				_UpdateWithCurrent();
130			void				_UpdatePreview();
131			void				_UpdateButtons();
132			void				_SetDesktop(bool isDesktop);
133			void				_AddRecentFolder(BPath path,
134									bool notifyApp = false);
135
136	static	int32				_NotifyThread(void* data);
137
138			BGImageMenuItem*	_FindImageItem(const int32 imageIndex);
139
140			bool				_AddItem(BGImageMenuItem* item);
141
142			BackgroundImage::Mode	_FindPlacementMode();
143
144			BColorControl*		fPicker;
145			BButton*			fApply;
146			BButton*			fRevert;
147			BCheckBox*			fIconLabelOutline;
148			BMenu*				fPlacementMenu;
149			BMenu*				fImageMenu;
150			BMenu*				fWorkspaceMenu;
151			BTextControl*		fXPlacementText;
152			BTextControl*		fYPlacementText;
153			Preview*			fPreview;
154			BFilePanel*			fFolderPanel;
155			ImageFilePanel*		fPanel;
156
157			BackgroundImage*	fCurrent;
158
159			BackgroundImage::BackgroundImageInfo*	fCurrentInfo;
160
161			entry_ref			fCurrentRef;
162			int32				fLastImageIndex;
163			int32				fRecentFoldersLimit;
164			BMessage			fSettings;
165
166			BObjectList<BPath>	fPathList;
167			BObjectList<Image>	fImageList;
168
169			FramePart*			fTopLeft;
170			FramePart*			fTop;
171			FramePart*			fTopRight;
172			FramePart*			fLeft;
173			FramePart*			fRight;
174			FramePart*			fBottomLeft;
175			FramePart*			fBottom;
176			FramePart*			fBottomRight;
177
178			bool				fFoundPositionSetting;
179};
180
181#endif	// BACKGROUNDS_VIEW_H
182