xref: /haiku/src/kits/tracker/FilePanelPriv.h (revision 239222b2369c39dc52df52b0a7cdd6cc0a91bc92)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 
35 #ifndef	_FILE_PANEL_PRIV_H
36 #define _FILE_PANEL_PRIV_H
37 
38 #include <FilePanel.h>
39 
40 #include "ContainerWindow.h"
41 #include "PoseView.h"
42 #include "TaskLoop.h"
43 
44 class BTextControl;
45 class BFilePanel;
46 class BRefFilter;
47 class BMessenger;
48 class BMenuField;
49 
50 namespace BPrivate {
51 
52 class BackgroundView;
53 class BDirMenu;
54 class AttributeStreamNode;
55 class BFilePanelPoseView;
56 class TFavoritesConfigWindow;
57 
58 class TFilePanel : public BContainerWindow {
59 public:
60 	TFilePanel(file_panel_mode = B_OPEN_PANEL,
61 		BMessenger *target = NULL, const BEntry *startDirectory = NULL,
62 		uint32 nodeFlavors = B_FILE_NODE | B_SYMLINK_NODE,
63 		bool multipleSelection = true, BMessage * = NULL, BRefFilter * = NULL,
64 		uint32 containerWindowFlags = 0,
65 		window_look look = B_DOCUMENT_WINDOW_LOOK,
66 		window_feel feel = B_NORMAL_WINDOW_FEEL,
67 		bool hideWhenDone = true);
68 
69 	virtual ~TFilePanel();
70 
71 	BFilePanelPoseView *PoseView() const;
72 
73 	virtual	bool QuitRequested();
74 	virtual	void MenusBeginning();
75 	virtual void MenusEnded();
76 	virtual	void DispatchMessage(BMessage *message, BHandler *handler);
77 	virtual	void ShowContextMenu(BPoint, const entry_ref *, BView *);
78 
79 	void SetClientObject(BFilePanel *);
80 	void SetRefFilter(BRefFilter *);
81 	void SetSaveText(const char *text);
82 	void SetButtonLabel(file_panel_button, const char *text);
83 	void SetTo(const entry_ref *ref);
84 	virtual	void SelectionChanged();
85 	void HandleOpenButton();
86 	void HandleSaveButton();
87 	void Rewind();
88 	bool IsSavePanel() const;
89 	void Refresh();
90 	const BMessenger *Target() const;
91 	BRefFilter *Filter() const;
92 
93 	void SetTarget(BMessenger);
94 	void SetMessage(BMessage *message);
95 
96 	virtual	status_t GetNextEntryRef(entry_ref *);
97 	virtual	void MessageReceived(BMessage *);
98 
99 	void SetHideWhenDone(bool);
100 	bool HidesWhenDone(void);
101 
102 	bool TrackingMenu() const;
103 
104 protected:
105 	BPoseView *NewPoseView(Model *model, BRect rect, uint32 viewMode);
106 	virtual	void Init(const BMessage *message = NULL);
107 	virtual	void SaveState(bool hide = true);
108 	virtual	void SaveState(BMessage &) const;
109 	virtual void RestoreState();
110 	virtual void RestoreWindowState(AttributeStreamNode *);
111 	virtual void RestoreWindowState(const BMessage &);
112 	virtual void RestoreState(const BMessage &);
113 
114 	virtual	void AddFileContextMenus(BMenu *);
115 	virtual	void AddWindowContextMenus(BMenu *);
116 	virtual	void AddDropContextMenus(BMenu *);
117 	virtual	void AddVolumeContextMenus(BMenu *);
118 
119 	virtual	void SetupNavigationMenu(const entry_ref *, BMenu *);
120 	virtual void OpenDirectory();
121 	virtual void OpenParent();
122 	virtual	void WindowActivated(bool state);
123 
124 	static filter_result FSFilter(BMessage *, BHandler **, BMessageFilter *);
125 	static filter_result MessageDropFilter(BMessage *, BHandler **, BMessageFilter *);
126 	int32 ShowCenteredAlert(const char *text, const char *button1, const char *button2 = NULL,
127 		const char *button3 = NULL);
128 
129 
130 private:
131 	bool SwitchDirToDesktopIfNeeded(entry_ref &ref);
132 	bool CanOpenParent() const;
133 	void SwitchDirMenuTo(const entry_ref *ref);
134 	void AdjustButton();
135 	bool SelectChildInParent(const entry_ref *parent, const node_ref *child);
136 	void OpenSelectionCommon(BMessage *);
137 
138 
139 	bool fIsSavePanel;
140 	uint32 fNodeFlavors;
141 	BackgroundView *fBackView;
142 	BDirMenu *fDirMenu;
143 	BMenuField *fDirMenuField;
144 	BTextControl *fTextControl;
145 	BMessenger fTarget;
146 	BFilePanel *fClientObject;
147 	int32 fSelectionIterator;
148 	BMessage *fMessage;
149 	BString fButtonText;
150 	bool fHideWhenDone;
151 	bool fIsTrackingMenu;
152 	TFavoritesConfigWindow *fConfigWindow;
153 
154 	typedef BContainerWindow _inherited;
155 
156 friend class BackgroundView;
157 };
158 
159 
160 class BFilePanelPoseView : public BPoseView {
161 public:
162 	BFilePanelPoseView(Model *, BRect, uint32 resizeMask = B_FOLLOW_ALL);
163 
164 	virtual bool IsFilePanel() const;
165 	virtual bool FSNotification(const BMessage *);
166 
167 	void SetIsDesktop(bool);
168 
169 protected:
170 	// don't do any volume watching and memtamime watching in file panels for now
171 	virtual void StartWatching();
172 	virtual void StopWatching();
173 
174 	virtual void RestoreState(AttributeStreamNode *);
175 	virtual void RestoreState(const BMessage &);
176 	virtual void SavePoseLocations(BRect * = NULL);
177 
178 	virtual EntryListBase *InitDirentIterator(const entry_ref *);
179 	virtual bool ShouldShowPose(const Model *, const PoseInfo *);
180 	virtual bool IsDesktopView() const;
181 
182 	void ShowVolumes(bool visible, bool showShared);
183 
184 	void AdaptToVolumeChange(BMessage *);
185 	void AdaptToDesktopIntegrationChange(BMessage *);
186 
187 private:
188 	bool fIsDesktop;
189 		// this flags makes the distinction between the Desktop as the Root of
190 		// the world and "/boot/home/Desktop" to which we might have navigated
191 		// from the home dir
192 
193 	typedef BPoseView _inherited;
194 };
195 
196 // inlines follow
197 
198 inline bool
199 BFilePanelPoseView::IsFilePanel() const
200 {
201 	return true;
202 }
203 
204 inline bool
205 TFilePanel::IsSavePanel() const
206 {
207 	return fIsSavePanel;
208 }
209 
210 inline const BMessenger *
211 TFilePanel::Target() const
212 {
213 	return &fTarget;
214 }
215 
216 inline void
217 TFilePanel::Refresh()
218 {
219 	fPoseView->Refresh();
220 }
221 
222 inline bool
223 TFilePanel::HidesWhenDone(void)
224 {
225 	return fHideWhenDone;
226 }
227 
228 inline void
229 TFilePanel::SetHideWhenDone(bool on)
230 {
231 	fHideWhenDone = on;
232 }
233 
234 inline bool
235 TFilePanel::TrackingMenu() const
236 {
237 	return fIsTrackingMenu;
238 }
239 
240 } // namespace BPrivate
241 
242 using namespace BPrivate;
243 
244 #endif
245