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