xref: /haiku/src/kits/tracker/ContainerWindow.h (revision dd2a1e350b303b855a50fd64e6cb55618be1ae6a)
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 	// 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 
213 protected:
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 
329 private:
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 
354 class 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
360 public:
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 
371 private:
372 	ModelNodeLazyOpener* fModelOpener;
373 	BNode* fNode;
374 	AttributeStreamNode* fStreamNode;
375 };
376 
377 
378 class BorderedView : public BGroupView {
379 public:
380 	BorderedView();
381 
382 	void PoseViewFocused(bool);
383 	virtual void Pulse();
384 
385 	void EnableBorderHighlight(bool);
386 
387 protected:
388 	virtual void WindowActivated(bool);
389 
390 private:
391 	bool fEnableBorderHighlight;
392 
393 	typedef BGroupView _inherited;
394 };
395 
396 
397 // inlines ---------
398 
399 inline BNavigator*
400 BContainerWindow::Navigator() const
401 {
402 	return fNavigator;
403 }
404 
405 
406 inline BPoseView*
407 BContainerWindow::PoseView() const
408 {
409 	return fPoseView;
410 }
411 
412 
413 inline bool
414 BContainerWindow::IsTrash() const
415 {
416 	return fIsTrash;
417 }
418 
419 
420 inline bool
421 BContainerWindow::InTrash() const
422 {
423 	return fInTrash;
424 }
425 
426 
427 inline bool
428 BContainerWindow::IsPrintersDir() const
429 {
430 	return fIsPrinters;
431 }
432 
433 
434 inline void
435 BContainerWindow::SetupDiskMenu(BMenu*)
436 {
437 	// nothing at this level
438 }
439 
440 
441 inline BPopUpMenu*
442 BContainerWindow::ContextMenu()
443 {
444 	return fContextMenu;
445 }
446 
447 
448 inline bool
449 BContainerWindow::Dragging() const
450 {
451 	return fDragMessage && fCachedTypesList;
452 }
453 
454 
455 inline BMessage*
456 BContainerWindow::DragMessage() const
457 {
458 	return fDragMessage;
459 }
460 
461 
462 inline bool
463 BContainerWindow::SaveStateIsEnabled() const
464 {
465 	return fSaveStateIsEnabled;
466 }
467 
468 
469 inline void
470 BContainerWindow::SetSaveStateEnabled(bool value)
471 {
472 	fSaveStateIsEnabled = value;
473 }
474 
475 
476 inline bool
477 BContainerWindow::IsPathWatchingEnabled() const
478 {
479 	return fIsWatchingPath;
480 }
481 
482 
483 filter_result ActivateWindowFilter(BMessage* message, BHandler** target,
484 	BMessageFilter* messageFilter);
485 
486 } // namespace BPrivate
487 
488 using namespace BPrivate;
489 
490 
491 #endif	// _CONTAINER_WINDOW_H
492