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