xref: /haiku/src/kits/tracker/ContainerWindow.h (revision fc7456e9b1ec38c941134ed6d01c438cf289381e)
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 	void _NewTemplateSubmenu(entry_ref);
346 };
347 
348 
349 class WindowStateNodeOpener {
350 	// this class manages opening and closing the proper node for
351 	// state restoring / saving; the constructor knows how to decide whether
352 	// to use a special directory for root, etc.
353 	// setter calls used when no attributes can be read from a node and
354 	// defaults are to be substituted
355 public:
356 	WindowStateNodeOpener(BContainerWindow* window, bool forWriting);
357 	virtual ~WindowStateNodeOpener();
358 
359 	void SetTo(const BDirectory*);
360 	void SetTo(const BEntry* entry, bool forWriting);
361 	void SetTo(Model*, bool forWriting);
362 
363 	AttributeStreamNode* StreamNode() const;
364 	BNode* Node() const;
365 
366 private:
367 	ModelNodeLazyOpener* fModelOpener;
368 	BNode* fNode;
369 	AttributeStreamNode* fStreamNode;
370 };
371 
372 
373 class BorderedView : public BGroupView {
374 public:
375 	BorderedView();
376 
377 	void PoseViewFocused(bool);
378 	virtual void Pulse();
379 
380 	void EnableBorderHighlight(bool);
381 
382 protected:
383 	virtual void WindowActivated(bool);
384 
385 private:
386 	bool fEnableBorderHighlight;
387 
388 	typedef BGroupView _inherited;
389 };
390 
391 
392 // inlines ---------
393 
394 inline BNavigator*
395 BContainerWindow::Navigator() const
396 {
397 	return fNavigator;
398 }
399 
400 
401 inline BPoseView*
402 BContainerWindow::PoseView() const
403 {
404 	return fPoseView;
405 }
406 
407 
408 inline bool
409 BContainerWindow::IsTrash() const
410 {
411 	return fIsTrash;
412 }
413 
414 
415 inline bool
416 BContainerWindow::InTrash() const
417 {
418 	return fInTrash;
419 }
420 
421 
422 inline bool
423 BContainerWindow::IsPrintersDir() const
424 {
425 	return fIsPrinters;
426 }
427 
428 
429 inline void
430 BContainerWindow::SetupDiskMenu(BMenu*)
431 {
432 	// nothing at this level
433 }
434 
435 
436 inline BPopUpMenu*
437 BContainerWindow::ContextMenu()
438 {
439 	return fContextMenu;
440 }
441 
442 
443 inline bool
444 BContainerWindow::Dragging() const
445 {
446 	return fDragMessage && fCachedTypesList;
447 }
448 
449 
450 inline BMessage*
451 BContainerWindow::DragMessage() const
452 {
453 	return fDragMessage;
454 }
455 
456 
457 inline bool
458 BContainerWindow::SaveStateIsEnabled() const
459 {
460 	return fSaveStateIsEnabled;
461 }
462 
463 
464 inline void
465 BContainerWindow::SetSaveStateEnabled(bool value)
466 {
467 	fSaveStateIsEnabled = value;
468 }
469 
470 
471 inline bool
472 BContainerWindow::IsPathWatchingEnabled() const
473 {
474 	return fIsWatchingPath;
475 }
476 
477 
478 filter_result ActivateWindowFilter(BMessage* message, BHandler** target,
479 	BMessageFilter* messageFilter);
480 
481 } // namespace BPrivate
482 
483 using namespace BPrivate;
484 
485 
486 #endif	// _CONTAINER_WINDOW_H
487