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