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