xref: /haiku/src/preferences/backgrounds/BackgroundsView.h (revision f8da8f3477d3c18142e59d17d05a545982faa5a8)
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 
38 class ImageFilePanel;
39 
40 
41 class BGImageMenuItem : public BMenuItem {
42 public:
43 							BGImageMenuItem(const char* label, int32 imageIndex,
44 								BMessage* message, char shortcut = 0,
45 								uint32 modifiers = 0);
46 
47 			int32			ImageIndex() { return fImageIndex; }
48 
49 private:
50 			int32			fImageIndex;
51 };
52 
53 
54 enum 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 
66 class FramePart : public BView {
67 public:
68 								FramePart(int32 part);
69 
70 			void				Draw(BRect rect);
71 			void				SetDesktop(bool isDesktop);
72 
73 private:
74 			void				_SetSizeAndAlignment();
75 
76 			int32				fFramePart;
77 			bool				fIsDesktop;
78 };
79 
80 
81 class Preview : public BControl {
82 public:
83 								Preview();
84 
85 			BPoint				fPoint;
86 			BRect				fImageBounds;
87 
88 protected:
89 			void				MouseDown(BPoint point);
90 			void				MouseUp(BPoint point);
91 			void				MouseMoved(BPoint point, uint32 transit,
92 									const BMessage* message);
93 			void				AttachedToWindow();
94 
95 			BPoint				fOldPoint;
96 			float				fXRatio;
97 			float				fYRatio;
98 			display_mode		fMode;
99 };
100 
101 
102 class BackgroundsView : public BBox {
103 public:
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 
120 protected:
121 			void				_Save();
122 			void				_NotifyServer();
123 			void				_LoadSettings();
124 			void				_LoadDesktopFolder();
125 			void				_LoadDefaultFolder();
126 			void				_LoadFolder(bool isDesktop);
127 			void				_LoadRecentFolder(BPath path);
128 			void				_UpdateWithCurrent();
129 			void				_UpdatePreview();
130 			void				_UpdateButtons();
131 			void				_SetDesktop(bool isDesktop);
132 			int32				_AddPath(BPath path);
133 
134 	static	int32				_NotifyThread(void* data);
135 
136 			BGImageMenuItem*	_FindImageItem(const int32 imageIndex);
137 
138 			bool				_AddItem(BGImageMenuItem* item);
139 
140 			BackgroundImage::Mode	_FindPlacementMode();
141 
142 			BColorControl*		fPicker;
143 			BButton*			fApply;
144 			BButton*			fRevert;
145 			BCheckBox*			fIconLabelOutline;
146 			BMenu*				fPlacementMenu;
147 			BMenu*				fImageMenu;
148 			BMenu*				fWorkspaceMenu;
149 			BTextControl*		fXPlacementText;
150 			BTextControl*		fYPlacementText;
151 			Preview*			fPreview;
152 			BFilePanel*			fFolderPanel;
153 			ImageFilePanel*		fPanel;
154 
155 			BackgroundImage*	fCurrent;
156 
157 			BackgroundImage::BackgroundImageInfo*	fCurrentInfo;
158 
159 			entry_ref			fCurrentRef;
160 			int32				fLastImageIndex;
161 			int32				fLastWorkspaceIndex;
162 			BMessage			fSettings;
163 
164 			BObjectList<BPath>	fPathList;
165 			BObjectList<Image>	fImageList;
166 
167 			FramePart*			fTopLeft;
168 			FramePart*			fTop;
169 			FramePart*			fTopRight;
170 			FramePart*			fLeft;
171 			FramePart*			fRight;
172 			FramePart*			fBottomLeft;
173 			FramePart*			fBottom;
174 			FramePart*			fBottomRight;
175 
176 			bool				fFoundPositionSetting;
177 };
178 
179 #endif	// BACKGROUNDS_VIEW_H
180