xref: /haiku/src/kits/tracker/ContainerWindow.h (revision 13581b3d2a71545960b98fefebc5225b5bf29072)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All 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 
48 class BGridView;
49 class BGroupLayout;
50 class BGroupView;
51 class BPopUpMenu;
52 class BMenuBar;
53 
54 namespace BPrivate {
55 
56 class BNavigator;
57 class BPoseView;
58 class DraggableContainerIcon;
59 class ModelMenuItem;
60 class AttributeStreamNode;
61 class BackgroundImage;
62 class Model;
63 class ModelNodeLazyOpener;
64 class BorderedView;
65 class SelectionWindow;
66 
67 
68 #define kDefaultFolderTemplate "DefaultFolderTemplate"
69 
70 
71 extern const char* kAddOnsMenuName;
72 
73 
74 enum {
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 
83 struct AddOnShortcut {
84 	Model*	model;
85 	char	key;
86 	char	defaultKey;
87 	uint32	modifiers;
88 };
89 
90 
91 class BContainerWindow : public BWindow {
92 public:
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 	BMessage* AddOnMessage(int32);
190 	BPopUpMenu* ContextMenu();
191 
192 	// drag&drop support
193 	status_t DragStart(const BMessage*);
194 	void DragStop();
195 	bool Dragging() const;
196 	BMessage* DragMessage() const;
197 
198 	void ShowSelectionWindow();
199 
200 	void ShowNavigator(bool);
201 	void SetSingleWindowBrowseShortcuts(bool);
202 
203 	void SetPathWatchingEnabled(bool);
204 	bool IsPathWatchingEnabled(void) const;
205 
206 protected:
207 	virtual BPoseView* NewPoseView(Model*, uint32);
208 		// instantiate a different flavor of BPoseView for different
209 		// ContainerWindows
210 
211 	virtual void RestoreWindowState(AttributeStreamNode*);
212 	virtual void RestoreWindowState(const BMessage &);
213 	virtual void SaveWindowState(AttributeStreamNode*);
214 	virtual void SaveWindowState(BMessage&) const;
215 
216 	virtual bool NeedsDefaultStateSetup();
217 	virtual void SetupDefaultState();
218 		// these two virtuals control setting up a new folder that
219 		// does not have any state settings yet with the default
220 
221 	virtual void AddMenus();
222 	virtual void AddShortcuts();
223 		// add equivalents of the menu shortcuts to the menuless
224 		// desktop window
225 	virtual void AddFileMenu(BMenu* menu);
226 	virtual void AddWindowMenu(BMenu* menu);
227 
228 	virtual void AddContextMenus();
229 
230 	virtual void AddFileContextMenus(BMenu*);
231 	virtual void AddWindowContextMenus(BMenu*);
232 	virtual void AddVolumeContextMenus(BMenu*);
233 	virtual void AddDropContextMenus(BMenu*);
234 	virtual void AddTrashContextMenus(BMenu*);
235 
236 	virtual void RepopulateMenus();
237 	void PopulateArrangeByMenu(BMenu*);
238 
239 	virtual void SetCutItem(BMenu*);
240 	virtual void SetCopyItem(BMenu*);
241 	virtual void SetPasteItem(BMenu*);
242 	virtual void SetArrangeMenu(BMenu*);
243 	virtual void SetCloseItem(BMenu*);
244 	virtual void SetupNavigationMenu(const entry_ref*, BMenu*);
245 	virtual void SetupMoveCopyMenus(const entry_ref*, BMenu*);
246 	virtual void PopulateMoveCopyNavMenu(BNavMenu*, uint32,
247 		const entry_ref*, bool);
248 
249 	virtual void SetupOpenWithMenu(BMenu*);
250 	virtual void SetupEditQueryItem(BMenu*);
251 	virtual void SetupDiskMenu(BMenu*);
252 
253 	virtual void BuildAddOnsMenu(BMenu*);
254 	void BuildMimeTypeList(BStringList& mimeTypes);
255 
256 	enum UpdateMenuContext {
257 		kMenuBarContext,
258 		kPosePopUpContext,
259 		kWindowPopUpContext
260 	};
261 
262 	virtual void UpdateMenu(BMenu* menu, UpdateMenuContext context);
263 
264 	BMenu* AddMimeMenu(const BMimeType& mimeType, bool isSuperType,
265 		BMenu* menu, int32 start);
266 
267 	BHandler* ResolveSpecifier(BMessage*, int32, BMessage*, int32,
268 		const char*);
269 
270 	void LoadAddOn(BMessage*);
271 	void EachAddOn(void (*)(const Model*, const char*, uint32 shortcut,
272 			uint32 modifiers, bool primary, void*, BContainerWindow*, BMenu*),
273 		void*, BStringList&, BMenu*);
274 
275 protected:
276 	LockingList<BWindow>* fWindowList;
277 	uint32 fOpenFlags;
278 	bool fUsesLayout;
279 
280 	BGroupLayout* fRootLayout;
281 	BGroupView* fMenuContainer;
282 	BGridView* fPoseContainer;
283 	BorderedView* fBorderedView;
284 	BGroupView* fVScrollBarContainer;
285 	BGroupView* fCountContainer;
286 
287 	BPopUpMenu* fContextMenu;
288 	BPopUpMenu* fFileContextMenu;
289 	BPopUpMenu* fWindowContextMenu;
290 	BPopUpMenu* fDropContextMenu;
291 	BPopUpMenu* fVolumeContextMenu;
292 	BPopUpMenu* fTrashContextMenu;
293 	BPopUpNavMenu* fDragContextMenu;
294 	BMenuItem* fMoveToItem;
295 	BMenuItem* fCopyToItem;
296 	BMenuItem* fCreateLinkItem;
297 	BMenuItem* fOpenWithItem;
298 	ModelMenuItem* fNavigationItem;
299 	BMenuBar* fMenuBar;
300 	DraggableContainerIcon* fDraggableIcon;
301 	BNavigator* fNavigator;
302 	BPoseView* fPoseView;
303 	BMenu* fAttrMenu;
304 	BMenu* fWindowMenu;
305 	BMenu* fFileMenu;
306 	BMenu* fArrangeByMenu;
307 
308 	SelectionWindow* fSelectionWindow;
309 
310 	PiggybackTaskLoop* fTaskLoop;
311 
312 	bool fStateNeedsSaving;
313 
314 	bool fIsTrash;
315 	bool fInTrash;
316 	bool fIsPrinters;
317 	bool fIsDesktop;
318 
319 	BackgroundImage* fBackgroundImage;
320 
321 	static LockingList<struct AddOnShortcut>* fAddOnsList;
322 
323 private:
324 	BRect fSavedZoomRect;
325 	BRect fPreviousBounds;
326 
327 	static BRect sNewWindRect;
328 
329 	BMessage* fDragMessage;
330 	BObjectList<BString>* fCachedTypesList;
331 	bool fWaitingForRefs;
332 
333 	bool fSaveStateIsEnabled;
334 
335 	bool fIsWatchingPath;
336 
337 	typedef BWindow _inherited;
338 
339 	friend int32 show_context_menu(void*);
340 	friend class BackgroundView;
341 
342 	void _UpdateSelectionMIMEInfo();
343 	void _AddFolderIcon();
344 	void _PassMessageToAddOn(BMessage*);
345 };
346 
347 
348 class WindowStateNodeOpener {
349 	// this class manages opening and closing the proper node for
350 	// state restoring / saving; the constructor knows how to decide whether
351 	// to use a special directory for root, etc.
352 	// setter calls used when no attributes can be read from a node and
353 	// defaults are to be substituted
354 public:
355 	WindowStateNodeOpener(BContainerWindow* window, bool forWriting);
356 	virtual ~WindowStateNodeOpener();
357 
358 	void SetTo(const BDirectory*);
359 	void SetTo(const BEntry* entry, bool forWriting);
360 	void SetTo(Model*, bool forWriting);
361 
362 	AttributeStreamNode* StreamNode() const;
363 	BNode* Node() const;
364 
365 private:
366 	ModelNodeLazyOpener* fModelOpener;
367 	BNode* fNode;
368 	AttributeStreamNode* fStreamNode;
369 };
370 
371 
372 class BorderedView : public BGroupView {
373 public:
374 	BorderedView();
375 
376 	void PoseViewFocused(bool);
377 	virtual void Pulse();
378 
379 	void EnableBorderHighlight(bool);
380 
381 protected:
382 	virtual void WindowActivated(bool);
383 
384 private:
385 	bool fEnableBorderHighlight;
386 
387 	typedef BGroupView _inherited;
388 };
389 
390 
391 // inlines ---------
392 
393 inline BNavigator*
394 BContainerWindow::Navigator() const
395 {
396 	return fNavigator;
397 }
398 
399 
400 inline BPoseView*
401 BContainerWindow::PoseView() const
402 {
403 	return fPoseView;
404 }
405 
406 
407 inline bool
408 BContainerWindow::IsTrash() const
409 {
410 	return fIsTrash;
411 }
412 
413 
414 inline bool
415 BContainerWindow::InTrash() const
416 {
417 	return fInTrash;
418 }
419 
420 
421 inline bool
422 BContainerWindow::IsPrintersDir() const
423 {
424 	return fIsPrinters;
425 }
426 
427 
428 inline void
429 BContainerWindow::SetupDiskMenu(BMenu*)
430 {
431 	// nothing at this level
432 }
433 
434 
435 inline BPopUpMenu*
436 BContainerWindow::ContextMenu()
437 {
438 	return fContextMenu;
439 }
440 
441 
442 inline bool
443 BContainerWindow::Dragging() const
444 {
445 	return fDragMessage && fCachedTypesList;
446 }
447 
448 
449 inline BMessage*
450 BContainerWindow::DragMessage() const
451 {
452 	return fDragMessage;
453 }
454 
455 
456 inline bool
457 BContainerWindow::SaveStateIsEnabled() const
458 {
459 	return fSaveStateIsEnabled;
460 }
461 
462 
463 inline void
464 BContainerWindow::SetSaveStateEnabled(bool value)
465 {
466 	fSaveStateIsEnabled = value;
467 }
468 
469 
470 inline bool
471 BContainerWindow::IsPathWatchingEnabled() const
472 {
473 	return fIsWatchingPath;
474 }
475 
476 
477 filter_result ActivateWindowFilter(BMessage* message, BHandler** target,
478 	BMessageFilter* messageFilter);
479 
480 } // namespace BPrivate
481 
482 using namespace BPrivate;
483 
484 
485 #endif	// _CONTAINER_WINDOW_H
486