ContainerWindow.h revision eeb608e1
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
35#ifndef	_CONTAINER_WINDOW_H
36#define _CONTAINER_WINDOW_H
37
38#include <Window.h>
39
40#include "LockingList.h"
41#include "Model.h"
42#include "SlowContextPopup.h"
43#include "TaskLoop.h"
44
45class BPopUpMenu;
46class BMenuBar;
47
48namespace BPrivate {
49
50class BNavigator;
51class BPoseView;
52class ModelMenuItem;
53class AttributeStreamNode;
54class BackgroundImage;
55class Model;
56class ModelNodeLazyOpener;
57class SelectionWindow;
58
59#define kDefaultFolderTemplate "DefaultFolderTemplate"
60
61extern const char *kAddOnsMenuName;
62
63const window_feel kPrivateDesktopWindowFeel = window_feel(1024);
64const window_look kPrivateDesktopWindowLook = window_look(4);
65	// this is a mirror of an app server private values
66
67enum {
68	// flags that describe opening of the window
69	kRestoreWorkspace	= 0x1,
70	kIsHidden			= 0x2,
71		// set when opening a window during initial Tracker start
72	kRestoreDecor		= 0x4
73};
74
75class BContainerWindow : public BWindow {
76	public:
77		BContainerWindow(LockingList<BWindow> *windowList,
78			uint32 containerWindowFlags,
79			window_look look = B_DOCUMENT_WINDOW_LOOK,
80			window_feel feel = B_NORMAL_WINDOW_FEEL,
81			uint32 flags = B_WILL_ACCEPT_FIRST_CLICK | B_NO_WORKSPACE_ACTIVATION,
82			uint32 workspace = B_CURRENT_WORKSPACE);
83
84		virtual ~BContainerWindow();
85
86		virtual void Init(const BMessage *message = NULL);
87
88		static BRect InitialWindowRect(window_feel);
89
90		virtual void Minimize(bool minimize);
91		virtual void Quit();
92		virtual bool QuitRequested();
93
94		virtual void UpdateIfTrash(Model *);
95
96		virtual	void CreatePoseView(Model *);
97
98		virtual	void ShowContextMenu(BPoint, const entry_ref *, BView *);
99		virtual	uint32 ShowDropContextMenu(BPoint);
100		virtual	void MenusBeginning();
101		virtual	void MenusEnded();
102		virtual	void MessageReceived(BMessage *);
103		virtual	void FrameResized(float, float);
104		virtual	void FrameMoved(BPoint);
105		virtual	void Zoom(BPoint, float, float);
106		virtual void WorkspacesChanged(uint32, uint32);
107
108		// virtuals that control setup of window
109		virtual	bool ShouldAddMenus() const;
110		virtual	bool ShouldAddScrollBars() const;
111		virtual	bool ShouldAddCountView() const;
112
113		virtual	void CheckScreenIntersect();
114
115		bool IsTrash() const;
116		bool InTrash() const;
117		bool IsPrintersDir() const;
118
119		virtual bool IsShowing(const node_ref *) const;
120		virtual bool IsShowing(const entry_ref *) const;
121
122		void ResizeToFit();
123
124		Model *TargetModel() const;
125		BPoseView *PoseView() const;
126		BNavigator *Navigator() const;
127
128		virtual	void SelectionChanged();
129		virtual void ViewModeChanged(uint32 oldMode, uint32 newMode);
130
131		virtual	void RestoreState();
132		virtual	void RestoreState(const BMessage &);
133		void RestoreStateCommon();
134		virtual	void SaveState(bool hide = true);
135		virtual	void SaveState(BMessage &) const;
136		void UpdateTitle();
137
138		bool StateNeedsSaving() const;
139		bool SaveStateIsEnabled() const;
140		void SetSaveStateEnabled(bool);
141
142		void UpdateBackgroundImage();
143
144		static status_t GetLayoutState(BNode *, BMessage *);
145		static status_t SetLayoutState(BNode *, const BMessage *);
146			// calls for inheriting window size, attribute layout, etc.
147			// deprecated
148
149		virtual	void AddMimeTypesToMenu(BMenu *);
150		void AddMimeTypesToMenu();
151		virtual	void MarkAttributeMenu(BMenu *);
152		void MarkAttributeMenu();
153		BMenuItem *NewAttributeMenuItem(const char *label, const char *name,
154			int32 type, float width, int32 align, bool editable, bool statField);
155		BMenuItem *NewAttributeMenuItem(const char *label, const char *name,
156			int32 type, const char* displayAs, float width, int32 align,
157			bool editable, bool statField);
158		virtual	void NewAttributeMenu(BMenu *);
159
160		void HideAttributeMenu();
161		void ShowAttributeMenu();
162		PiggybackTaskLoop *DelayedTaskLoop();
163			// use for RunLater queueing
164		void PulseTaskLoop();
165			// called by some view that has pulse, either BackgroundView or BPoseView
166
167		static bool DefaultStateSourceNode(const char *name, BNode *result,
168			bool createNew = false, bool createFolder = true);
169
170		// add-on iteration
171		void EachAddon(bool(*)(const Model *, const char *, uint32 shortcut, bool primary, void *), void *);
172
173		BPopUpMenu *ContextMenu();
174
175		// drag&drop support
176		status_t DragStart(const BMessage *);
177		void DragStop();
178		bool Dragging() const;
179		BMessage *DragMessage() const;
180
181		void ShowSelectionWindow();
182
183		void ShowNavigator(bool);
184		void SetSingleWindowBrowseShortcuts(bool);
185
186		void SetPathWatchingEnabled(bool);
187		bool IsPathWatchingEnabled(void) const;
188
189	protected:
190		virtual BPoseView *NewPoseView(Model *, BRect, uint32);
191			// instantiate a different flavor of BPoseView for different
192			// ContainerWindows
193
194		virtual void RestoreWindowState(AttributeStreamNode *);
195		virtual void RestoreWindowState(const BMessage &);
196		virtual void SaveWindowState(AttributeStreamNode *);
197		virtual void SaveWindowState(BMessage &) const;
198
199		virtual bool NeedsDefaultStateSetup();
200		virtual void SetUpDefaultState();
201			// these two virtuals control setting up a new folder that
202			// does not have any state settings yet with the default
203
204		virtual	void AddMenus();
205		virtual void AddShortcuts();
206			// add equivalents of the menu shortcuts to the menuless desktop window
207		virtual	void AddFileMenu(BMenu *menu);
208		virtual	void AddWindowMenu(BMenu *menu);
209
210		virtual void AddContextMenus();
211
212		virtual	void AddFileContextMenus(BMenu *);
213		virtual	void AddWindowContextMenus(BMenu *);
214		virtual	void AddVolumeContextMenus(BMenu *);
215		virtual	void AddDropContextMenus(BMenu *);
216
217		virtual void RepopulateMenus();
218
219		virtual	void SetCutItem(BMenu *);
220		virtual	void SetCopyItem(BMenu *);
221		virtual	void SetPasteItem(BMenu *);
222		virtual	void SetCleanUpItem(BMenu *);
223		virtual void SetCloseItem(BMenu *);
224		virtual	void SetupNavigationMenu(const entry_ref *, BMenu *);
225		virtual	void SetupMoveCopyMenus(const entry_ref *, BMenu *);
226		virtual	void PopulateMoveCopyNavMenu(BNavMenu *, uint32, const entry_ref *, bool);
227
228		virtual	void SetupOpenWithMenu(BMenu *);
229		virtual	void SetUpEditQueryItem(BMenu *);
230		virtual	void SetUpDiskMenu(BMenu *);
231
232		virtual	void BuildAddOnMenu(BMenu *);
233
234		enum UpdateMenuContext {
235			kMenuBarContext,
236			kPosePopUpContext,
237			kWindowPopUpContext
238		};
239
240		virtual void UpdateMenu(BMenu *menu, UpdateMenuContext context);
241
242		BHandler *ResolveSpecifier(BMessage *, int32, BMessage *, int32,
243			const char *);
244
245		bool EachAddon(BPath &path, bool(*)(const Model *, const char *, uint32, bool, void *),
246			BObjectList<Model> *, void *);
247		void LoadAddOn(BMessage *);
248
249		BPopUpMenu *fFileContextMenu;
250		BPopUpMenu *fWindowContextMenu;
251		BPopUpMenu *fDropContextMenu;
252		BPopUpMenu *fVolumeContextMenu;
253		BSlowContextMenu *fDragContextMenu;
254		BMenuItem *fMoveToItem;
255		BMenuItem *fCopyToItem;
256		BMenuItem *fCreateLinkItem;
257		BMenuItem *fOpenWithItem;
258		ModelMenuItem *fNavigationItem;
259		BMenuBar *fMenuBar;
260		BNavigator *fNavigator;
261		BPoseView *fPoseView;
262		LockingList<BWindow> *fWindowList;
263		BMenu *fAttrMenu;
264		BMenu *fWindowMenu;
265		BMenu *fFileMenu;
266
267		SelectionWindow *fSelectionWindow;
268
269		PiggybackTaskLoop *fTaskLoop;
270
271		bool fIsTrash;
272		bool fInTrash;
273		bool fIsPrinters;
274
275		uint32 fContainerWindowFlags;
276		BackgroundImage *fBackgroundImage;
277
278	private:
279		BRect fSavedZoomRect;
280		BRect fPreviousBounds;
281
282		static BRect sNewWindRect;
283
284		BPopUpMenu *fContextMenu;
285		BMessage *fDragMessage;
286		BObjectList<BString> *fCachedTypesList;
287		bool fWaitingForRefs;
288
289		bool fStateNeedsSaving;
290		bool fSaveStateIsEnabled;
291
292		bool fIsWatchingPath;
293
294		typedef BWindow _inherited;
295
296		friend int32 show_context_menu(void*);
297		friend class BackgroundView;
298};
299
300class WindowStateNodeOpener {
301	// this class manages opening and closing the proper node for
302	// state restoring / saving; the constructor knows how to decide wether
303	// to use a special directory for root, etc.
304	// setter calls used when no attributes can be read from a node and defaults
305	// are to be substituted
306	public:
307		WindowStateNodeOpener(BContainerWindow *window, bool forWriting);
308		virtual ~WindowStateNodeOpener();
309
310		void SetTo(const BDirectory *);
311		void SetTo(const BEntry *entry, bool forWriting);
312		void SetTo(Model *, bool forWriting);
313
314		AttributeStreamNode *StreamNode() const;
315		BNode *Node() const;
316
317	private:
318		ModelNodeLazyOpener *fModelOpener;
319		BNode *fNode;
320		AttributeStreamNode *fStreamNode;
321};
322
323class BackgroundView : public BView {
324	// background view placed in a BContainerWindow, under the pose view
325	public:
326		BackgroundView(BRect);
327		virtual	void AttachedToWindow();
328		virtual	void FrameResized(float, float);
329		virtual	void Draw(BRect);
330
331		void PoseViewFocused(bool);
332		virtual void Pulse();
333
334	protected:
335		virtual void WindowActivated(bool);
336
337	private:
338		typedef BView _inherited;
339};
340
341int CompareLabels(const BMenuItem *, const BMenuItem *);
342
343// inlines ---------
344
345inline BNavigator *
346BContainerWindow::Navigator() const
347{
348	return fNavigator;
349}
350
351inline BPoseView *
352BContainerWindow::PoseView() const
353{
354	return fPoseView;
355}
356
357inline bool
358BContainerWindow::IsTrash() const
359{
360	return fIsTrash;
361}
362
363inline bool
364BContainerWindow::InTrash() const
365{
366	return fInTrash;
367}
368
369inline bool
370BContainerWindow::IsPrintersDir() const
371{
372	return fIsPrinters;
373}
374
375inline void
376BContainerWindow::SetUpDiskMenu(BMenu *)
377{
378	// nothing at this level
379}
380
381inline BPopUpMenu *
382BContainerWindow::ContextMenu()
383{
384	return fContextMenu;
385}
386
387inline bool
388BContainerWindow::Dragging() const
389{
390	return fDragMessage && fCachedTypesList;
391}
392
393inline BMessage *
394BContainerWindow::DragMessage() const
395{
396	return fDragMessage;
397}
398inline
399bool
400BContainerWindow::SaveStateIsEnabled() const
401{
402	return fSaveStateIsEnabled;
403}
404
405inline
406void
407BContainerWindow::SetSaveStateEnabled(bool value)
408{
409	fSaveStateIsEnabled = value;
410}
411
412inline
413bool
414BContainerWindow::IsPathWatchingEnabled() const
415{
416	return fIsWatchingPath;
417}
418
419filter_result ActivateWindowFilter(BMessage *message, BHandler **target,
420	BMessageFilter *messageFilter);
421
422} // namespace BPrivate
423
424using namespace BPrivate;
425
426#endif
427