xref: /haiku/src/kits/tracker/FilePanelPriv.h (revision b289aaf66bbf6e173aa90fa194fc256965f1b34d)
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 
57 class TFilePanel : public BContainerWindow {
58 public:
59 	TFilePanel(file_panel_mode = B_OPEN_PANEL,
60 		BMessenger *target = NULL, const BEntry *startDirectory = NULL,
61 		uint32 nodeFlavors = B_FILE_NODE | B_SYMLINK_NODE,
62 		bool multipleSelection = true, BMessage * = NULL, BRefFilter * = NULL,
63 		uint32 containerWindowFlags = 0,
64 		window_look look = B_DOCUMENT_WINDOW_LOOK,
65 		window_feel feel = B_NORMAL_WINDOW_FEEL,
66 		bool hideWhenDone = true);
67 
68 	virtual ~TFilePanel();
69 
70 	BFilePanelPoseView *PoseView() const;
71 
72 	virtual	bool QuitRequested();
73 	virtual	void MenusBeginning();
74 	virtual void MenusEnded();
75 	virtual	void DispatchMessage(BMessage *message, BHandler *handler);
76 	virtual	void ShowContextMenu(BPoint, const entry_ref *, BView *);
77 
78 	void SetClientObject(BFilePanel *);
79 	void SetRefFilter(BRefFilter *);
80 	void SetSaveText(const char *text);
81 	void SetButtonLabel(file_panel_button, const char *text);
82 	void SetTo(const entry_ref *ref);
83 	virtual	void SelectionChanged();
84 	void HandleOpenButton();
85 	void HandleSaveButton();
86 	void Rewind();
87 	bool IsSavePanel() const;
88 	void Refresh();
89 	const BMessenger *Target() const;
90 	BRefFilter *Filter() const;
91 
92 	void SetTarget(BMessenger);
93 	void SetMessage(BMessage *message);
94 
95 	virtual	status_t GetNextEntryRef(entry_ref *);
96 	virtual	void MessageReceived(BMessage *);
97 
98 	void SetHideWhenDone(bool);
99 	bool HidesWhenDone(void);
100 
101 	bool TrackingMenu() const;
102 
103 protected:
104 	BPoseView *NewPoseView(Model *model, BRect rect, uint32 viewMode);
105 	virtual	void Init(const BMessage *message = NULL);
106 	virtual	void SaveState(bool hide = true);
107 	virtual	void SaveState(BMessage &) const;
108 	virtual void RestoreState();
109 	virtual void RestoreWindowState(AttributeStreamNode *);
110 	virtual void RestoreWindowState(const BMessage &);
111 	virtual void RestoreState(const BMessage &);
112 
113 	virtual	void AddFileContextMenus(BMenu *);
114 	virtual	void AddWindowContextMenus(BMenu *);
115 	virtual	void AddDropContextMenus(BMenu *);
116 	virtual	void AddVolumeContextMenus(BMenu *);
117 
118 	virtual	void SetupNavigationMenu(const entry_ref *, BMenu *);
119 	virtual void OpenDirectory();
120 	virtual void OpenParent();
121 	virtual	void WindowActivated(bool state);
122 
123 	static filter_result FSFilter(BMessage *, BHandler **, BMessageFilter *);
124 	static filter_result MessageDropFilter(BMessage *, BHandler **, BMessageFilter *);
125 	int32 ShowCenteredAlert(const char *text, const char *button1, const char *button2 = NULL,
126 		const char *button3 = NULL);
127 
128 
129 private:
130 	bool SwitchDirToDesktopIfNeeded(entry_ref &ref);
131 	bool CanOpenParent() const;
132 	void SwitchDirMenuTo(const entry_ref *ref);
133 	void AdjustButton();
134 	bool SelectChildInParent(const entry_ref *parent, const node_ref *child);
135 	void OpenSelectionCommon(BMessage *);
136 
137 
138 	bool fIsSavePanel;
139 	uint32 fNodeFlavors;
140 	BackgroundView *fBackView;
141 	BDirMenu *fDirMenu;
142 	BMenuField *fDirMenuField;
143 	BTextControl *fTextControl;
144 	BMessenger fTarget;
145 	BFilePanel *fClientObject;
146 	int32 fSelectionIterator;
147 	BMessage *fMessage;
148 	BString fButtonText;
149 	bool fHideWhenDone;
150 	bool fIsTrackingMenu;
151 
152 	typedef BContainerWindow _inherited;
153 
154 friend class BackgroundView;
155 };
156 
157 
158 class BFilePanelPoseView : public BPoseView {
159 public:
160 	BFilePanelPoseView(Model *, BRect, uint32 resizeMask = B_FOLLOW_ALL);
161 
162 	virtual bool IsFilePanel() const;
163 	virtual bool FSNotification(const BMessage *);
164 
165 	void SetIsDesktop(bool);
166 
167 protected:
168 	// don't do any volume watching and memtamime watching in file panels for now
169 	virtual void StartWatching();
170 	virtual void StopWatching();
171 
172 	virtual void RestoreState(AttributeStreamNode *);
173 	virtual void RestoreState(const BMessage &);
174 	virtual void SavePoseLocations(BRect * = NULL);
175 
176 	virtual EntryListBase *InitDirentIterator(const entry_ref *);
177 	virtual void AddPosesCompleted();
178 	virtual bool IsDesktopView() const;
179 
180 	void ShowVolumes(bool visible, bool showShared);
181 
182 	void AdaptToVolumeChange(BMessage *);
183 	void AdaptToDesktopIntegrationChange(BMessage *);
184 
185 private:
186 	bool fIsDesktop;
187 		// this flags makes the distinction between the Desktop as the Root of
188 		// the world and "/boot/home/Desktop" to which we might have navigated
189 		// from the home dir
190 
191 	typedef BPoseView _inherited;
192 };
193 
194 // inlines follow
195 
196 inline bool
197 BFilePanelPoseView::IsFilePanel() const
198 {
199 	return true;
200 }
201 
202 inline bool
203 TFilePanel::IsSavePanel() const
204 {
205 	return fIsSavePanel;
206 }
207 
208 inline const BMessenger *
209 TFilePanel::Target() const
210 {
211 	return &fTarget;
212 }
213 
214 inline void
215 TFilePanel::Refresh()
216 {
217 	fPoseView->Refresh();
218 }
219 
220 inline bool
221 TFilePanel::HidesWhenDone(void)
222 {
223 	return fHideWhenDone;
224 }
225 
226 inline void
227 TFilePanel::SetHideWhenDone(bool on)
228 {
229 	fHideWhenDone = on;
230 }
231 
232 inline bool
233 TFilePanel::TrackingMenu() const
234 {
235 	return fIsTrackingMenu;
236 }
237 
238 } // namespace BPrivate
239 
240 using namespace BPrivate;
241 
242 #endif
243