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