ContainerWindow.h revision be8c87ab
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		BMenu* CreateMimeMenu(const BMimeType& mimeType, bool isSuperType,
150			BMenu* menu, int32 start, int32 count);
151		virtual	void AddMimeTypesToMenu(BMenu *);
152		void AddMimeTypesToMenu();
153		virtual	void MarkAttributeMenu(BMenu *);
154		void MarkAttributeMenu();
155		BMenuItem *NewAttributeMenuItem(const char *label, const char *name,
156			int32 type, float width, int32 align, bool editable, bool statField);
157		BMenuItem *NewAttributeMenuItem(const char *label, const char *name,
158			int32 type, const char* displayAs, float width, int32 align,
159			bool editable, bool statField);
160		virtual	void NewAttributeMenu(BMenu *);
161
162		void HideAttributeMenu();
163		void ShowAttributeMenu();
164		PiggybackTaskLoop *DelayedTaskLoop();
165			// use for RunLater queueing
166		void PulseTaskLoop();
167			// called by some view that has pulse, either BackgroundView or BPoseView
168
169		static bool DefaultStateSourceNode(const char *name, BNode *result,
170			bool createNew = false, bool createFolder = true);
171
172		// add-on iteration
173		void EachAddon(bool(*)(const Model *, const char *, uint32 shortcut, bool primary, void *), void *);
174
175		BPopUpMenu *ContextMenu();
176
177		// drag&drop support
178		status_t DragStart(const BMessage *);
179		void DragStop();
180		bool Dragging() const;
181		BMessage *DragMessage() const;
182
183		void ShowSelectionWindow();
184
185		void ShowNavigator(bool);
186		void SetSingleWindowBrowseShortcuts(bool);
187
188		void SetPathWatchingEnabled(bool);
189		bool IsPathWatchingEnabled(void) const;
190
191	protected:
192		virtual BPoseView *NewPoseView(Model *, BRect, uint32);
193			// instantiate a different flavor of BPoseView for different
194			// ContainerWindows
195
196		virtual void RestoreWindowState(AttributeStreamNode *);
197		virtual void RestoreWindowState(const BMessage &);
198		virtual void SaveWindowState(AttributeStreamNode *);
199		virtual void SaveWindowState(BMessage &) const;
200
201		virtual bool NeedsDefaultStateSetup();
202		virtual void SetUpDefaultState();
203			// these two virtuals control setting up a new folder that
204			// does not have any state settings yet with the default
205
206		virtual	void AddMenus();
207		virtual void AddShortcuts();
208			// add equivalents of the menu shortcuts to the menuless desktop window
209		virtual	void AddFileMenu(BMenu *menu);
210		virtual	void AddWindowMenu(BMenu *menu);
211
212		virtual void AddContextMenus();
213
214		virtual	void AddFileContextMenus(BMenu *);
215		virtual	void AddWindowContextMenus(BMenu *);
216		virtual	void AddVolumeContextMenus(BMenu *);
217		virtual	void AddDropContextMenus(BMenu *);
218
219		virtual void RepopulateMenus();
220
221		virtual	void SetCutItem(BMenu *);
222		virtual	void SetCopyItem(BMenu *);
223		virtual	void SetPasteItem(BMenu *);
224		virtual	void SetCleanUpItem(BMenu *);
225		virtual void SetCloseItem(BMenu *);
226		virtual	void SetupNavigationMenu(const entry_ref *, BMenu *);
227		virtual	void SetupMoveCopyMenus(const entry_ref *, BMenu *);
228		virtual	void PopulateMoveCopyNavMenu(BNavMenu *, uint32, const entry_ref *, bool);
229
230		virtual	void SetupOpenWithMenu(BMenu *);
231		virtual	void SetUpEditQueryItem(BMenu *);
232		virtual	void SetUpDiskMenu(BMenu *);
233
234		virtual	void BuildAddOnMenu(BMenu *);
235
236		enum UpdateMenuContext {
237			kMenuBarContext,
238			kPosePopUpContext,
239			kWindowPopUpContext
240		};
241
242		virtual void UpdateMenu(BMenu *menu, UpdateMenuContext context);
243
244		BHandler *ResolveSpecifier(BMessage *, int32, BMessage *, int32,
245			const char *);
246
247		bool EachAddon(BPath &path, bool(*)(const Model *, const char *, uint32, bool, void *),
248			BObjectList<Model> *, void *);
249		void LoadAddOn(BMessage *);
250
251		BPopUpMenu *fFileContextMenu;
252		BPopUpMenu *fWindowContextMenu;
253		BPopUpMenu *fDropContextMenu;
254		BPopUpMenu *fVolumeContextMenu;
255		BSlowContextMenu *fDragContextMenu;
256		BMenuItem *fMoveToItem;
257		BMenuItem *fCopyToItem;
258		BMenuItem *fCreateLinkItem;
259		BMenuItem *fOpenWithItem;
260		ModelMenuItem *fNavigationItem;
261		BMenuBar *fMenuBar;
262		BNavigator *fNavigator;
263		BPoseView *fPoseView;
264		LockingList<BWindow> *fWindowList;
265		BMenu *fAttrMenu;
266		BMenu *fWindowMenu;
267		BMenu *fFileMenu;
268
269		SelectionWindow *fSelectionWindow;
270
271		PiggybackTaskLoop *fTaskLoop;
272
273		bool fIsTrash;
274		bool fInTrash;
275		bool fIsPrinters;
276
277		uint32 fContainerWindowFlags;
278		BackgroundImage *fBackgroundImage;
279
280	private:
281		BRect fSavedZoomRect;
282		BRect fPreviousBounds;
283
284		static BRect sNewWindRect;
285
286		BPopUpMenu *fContextMenu;
287		BMessage *fDragMessage;
288		BObjectList<BString> *fCachedTypesList;
289		bool fWaitingForRefs;
290
291		bool fStateNeedsSaving;
292		bool fSaveStateIsEnabled;
293
294		bool fIsWatchingPath;
295
296		typedef BWindow _inherited;
297
298		friend int32 show_context_menu(void*);
299		friend class BackgroundView;
300};
301
302class WindowStateNodeOpener {
303	// this class manages opening and closing the proper node for
304	// state restoring / saving; the constructor knows how to decide wether
305	// to use a special directory for root, etc.
306	// setter calls used when no attributes can be read from a node and defaults
307	// are to be substituted
308	public:
309		WindowStateNodeOpener(BContainerWindow *window, bool forWriting);
310		virtual ~WindowStateNodeOpener();
311
312		void SetTo(const BDirectory *);
313		void SetTo(const BEntry *entry, bool forWriting);
314		void SetTo(Model *, bool forWriting);
315
316		AttributeStreamNode *StreamNode() const;
317		BNode *Node() const;
318
319	private:
320		ModelNodeLazyOpener *fModelOpener;
321		BNode *fNode;
322		AttributeStreamNode *fStreamNode;
323};
324
325class BackgroundView : public BView {
326	// background view placed in a BContainerWindow, under the pose view
327	public:
328		BackgroundView(BRect);
329		virtual	void AttachedToWindow();
330		virtual	void FrameResized(float, float);
331		virtual	void Draw(BRect);
332
333		void PoseViewFocused(bool);
334		virtual void Pulse();
335
336	protected:
337		virtual void WindowActivated(bool);
338
339	private:
340		typedef BView _inherited;
341};
342
343int CompareLabels(const BMenuItem *, const BMenuItem *);
344
345// inlines ---------
346
347inline BNavigator *
348BContainerWindow::Navigator() const
349{
350	return fNavigator;
351}
352
353inline BPoseView *
354BContainerWindow::PoseView() const
355{
356	return fPoseView;
357}
358
359inline bool
360BContainerWindow::IsTrash() const
361{
362	return fIsTrash;
363}
364
365inline bool
366BContainerWindow::InTrash() const
367{
368	return fInTrash;
369}
370
371inline bool
372BContainerWindow::IsPrintersDir() const
373{
374	return fIsPrinters;
375}
376
377inline void
378BContainerWindow::SetUpDiskMenu(BMenu *)
379{
380	// nothing at this level
381}
382
383inline BPopUpMenu *
384BContainerWindow::ContextMenu()
385{
386	return fContextMenu;
387}
388
389inline bool
390BContainerWindow::Dragging() const
391{
392	return fDragMessage && fCachedTypesList;
393}
394
395inline BMessage *
396BContainerWindow::DragMessage() const
397{
398	return fDragMessage;
399}
400inline
401bool
402BContainerWindow::SaveStateIsEnabled() const
403{
404	return fSaveStateIsEnabled;
405}
406
407inline
408void
409BContainerWindow::SetSaveStateEnabled(bool value)
410{
411	fSaveStateIsEnabled = value;
412}
413
414inline
415bool
416BContainerWindow::IsPathWatchingEnabled() const
417{
418	return fIsWatchingPath;
419}
420
421filter_result ActivateWindowFilter(BMessage *message, BHandler **target,
422	BMessageFilter *messageFilter);
423
424} // namespace BPrivate
425
426using namespace BPrivate;
427
428#endif
429