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