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