xref: /haiku/src/preferences/backgrounds/BackgroundsView.h (revision 9ecf9d1c1d4888d341a6eac72112c72d1ae3a4cb)
1 /*
2  * Copyright 2002-2005, 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 "BackgroundImage.h"
13 
14 #include <View.h>
15 #include <ColorControl.h>
16 #include <Message.h>
17 #include <Button.h>
18 #include <ScrollView.h>
19 #include <ScrollBar.h>
20 #include <String.h>
21 #include <Box.h>
22 #include <CheckBox.h>
23 #include <TextControl.h>
24 #include <Menu.h>
25 #include <MenuItem.h>
26 #include <Entry.h>
27 #include <Screen.h>
28 #include <Control.h>
29 #include <Picture.h>
30 #include <FilePanel.h>
31 #include <StringView.h>
32 #include <Cursor.h>
33 
34 #define SETTINGS_FILE					"Backgrounds_settings"
35 
36 class ImageFilePanel;
37 
38 class BGImageMenuItem : public BMenuItem {
39 	public:
40 		BGImageMenuItem(const char *label, int32 imageIndex, BMessage *message,
41 			char shortcut = 0, uint32 modifiers = 0);
42 
43 		int32 ImageIndex() { return fImageIndex; }
44 
45 	private:
46 		int32 fImageIndex;
47 };
48 
49 
50 class PreviewBox : public BBox {
51 	public:
52 		PreviewBox(BRect frame, const char *name);
53 
54 		void Draw(BRect rect);
55 		void SetDesktop(bool isDesktop);
56 
57 	protected:
58 		bool fIsDesktop;
59 };
60 
61 
62 class PreView : public BControl {
63 	public:
64 		PreView(BRect frame, const char *name, int32 resize, int32 flags);
65 
66 		BPoint fPoint;
67 		BRect fImageBounds;
68 
69 	protected:
70 		void MouseDown(BPoint point);
71 		void MouseUp(BPoint point);
72 		void MouseMoved(BPoint point, uint32 transit, const BMessage *message);
73 		void AttachedToWindow();
74 
75 		BPoint fOldPoint;
76 		float x_ratio,y_ratio;
77 		display_mode mode;
78 
79 		BCursor fMoveHandCursor;
80 };
81 
82 
83 class BackgroundsView : public BBox {
84 	public:
85 		BackgroundsView(BRect frame, const char *name, int32 resize, int32 flags);
86 		~BackgroundsView(void);
87 
88 		void SaveSettings();
89 		void WorkspaceActivated(uint32 oldWorkspaces, bool active);
90 		int32 AddImage(BPath path);
91 		Image* GetImage(int32 imageIndex);
92 		void ProcessRefs(entry_ref dir_ref, BMessage* msg);
93 
94 	protected:
95 		void Save();
96 		void NotifyServer();
97 		void LoadSettings();
98 		void AllAttached();
99 		void MessageReceived(BMessage *msg);
100 		void LoadDesktopFolder();
101 		void LoadDefaultFolder();
102 		void LoadFolder(bool isDesktop);
103 		void LoadRecentFolder(BPath path);
104 		void UpdateWithCurrent();
105 		void UpdatePreview();
106 		void UpdateButtons();
107 		void RefsReceived(BMessage *msg);
108 		int32 AddPath(BPath path);
109 
110 		static int32 NotifyThread(void *data);
111 
112 		BGImageMenuItem *FindImageItem(const int32 imageIndex);
113 		bool AddItem(BGImageMenuItem *item);
114 
115 		BackgroundImage::Mode FindPlacementMode();
116 
117 		BColorControl *fPicker;			// color picker
118 		BButton *fApply, *fRevert;		// apply and revert buttons
119 		BCheckBox *fIconLabelBackground;	// label ckeckbox
120 		BMenu* fPlacementMenu, *fImageMenu, *fWorkspaceMenu;	// the three comboboxes
121 		BTextControl *fXPlacementText, *fYPlacementText;		// x and y textboxes
122 		PreView *fPreView;				// the view for previewing the result
123 		PreviewBox *fPreview;			// the box which draws a computer/folder
124 		BFilePanel *fFolderPanel;		// the file panels for folders
125 		ImageFilePanel *fPanel;			// the file panels for images
126 
127 		BackgroundImage *fCurrent;		// the current BackgroundImage object
128 		BackgroundImage::BackgroundImageInfo *fCurrentInfo;//the current BackgroundImageInfo object
129 		entry_ref fCurrentRef;			// the entry for the node which holds current
130 		int32 fLastImageIndex, fLastWorkspaceIndex;		// last indexes for cancel
131 		BMessage fSettings;				// settings loaded from settings directory
132 
133 		BObjectList<BPath> fPathList;
134 		BObjectList<Image> fImageList;
135 };
136 
137 #endif	// BACKGROUNDS_VIEW_H
138