xref: /haiku/src/kits/tracker/ContainerWindow.h (revision 344ded80d400028c8f561b4b876257b94c12db4a)
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, bool useLayout = true);
98 
99 	virtual ~BContainerWindow();
100 
101 	virtual void Init(const BMessage* message = NULL);
102 	virtual void InitLayout();
103 
104 	static BRect InitialWindowRect(window_feel);
105 
106 	virtual void Minimize(bool minimize);
107 	virtual void Quit();
108 	virtual bool QuitRequested();
109 
110 	virtual void CreatePoseView(Model*);
111 
112 	virtual void ShowContextMenu(BPoint, const entry_ref*);
113 	virtual uint32 ShowDropContextMenu(BPoint, BPoseView* source = NULL);
114 	virtual void MenusBeginning();
115 	virtual void MenusEnded();
116 	virtual void MessageReceived(BMessage*);
117 	virtual void FrameResized(float, float);
118 	virtual void FrameMoved(BPoint);
119 	virtual void Zoom(BPoint, float, float);
120 	virtual void WorkspacesChanged(uint32, uint32);
121 
122 	// virtuals that control setup of window
123 	virtual bool ShouldAddMenus() const;
124 	virtual bool ShouldAddScrollBars() const;
125 
126 	virtual void CheckScreenIntersect();
127 
128 	virtual bool IsShowing(const node_ref*) const;
129 	virtual bool IsShowing(const entry_ref*) const;
130 
131 	void ResizeToFit();
132 
133 	Model* TargetModel() const;
134 	BPoseView* PoseView() const;
135 	BNavigator* Navigator() const;
136 
137 	virtual void SelectionChanged();
138 	virtual void ViewModeChanged(uint32 oldMode, uint32 newMode);
139 
140 	virtual void RestoreState();
141 	virtual void RestoreState(const BMessage &);
142 	void RestoreStateCommon();
143 	virtual void SaveState(bool hide = true);
144 	virtual void SaveState(BMessage &) const;
145 	void UpdateTitle();
146 
147 	bool StateNeedsSaving() const;
148 	bool SaveStateIsEnabled() const;
149 	void SetSaveStateEnabled(bool);
150 
151 	void UpdateBackgroundImage();
152 
153 	static status_t GetLayoutState(BNode*, BMessage*);
154 	static status_t SetLayoutState(BNode*, const BMessage*);
155 		// calls for inheriting window size, attribute layout, etc.
156 		// deprecated
157 
158 	virtual void AddMimeTypesToMenu(BMenu*);
159 	void AddMimeTypesToMenu();
160 	virtual void MarkAttributesMenu(BMenu*);
161 	void MarkAttributesMenu();
162 	void MarkArrangeByMenu(BMenu*);
163 	BMenuItem* NewAttributeMenuItem(const char* label, const char* name,
164 		int32 type, float width, int32 align, bool editable,
165 		bool statField);
166 	BMenuItem* NewAttributeMenuItem(const char* label, const char* name,
167 		int32 type, const char* displayAs, float width, int32 align,
168 		bool editable, bool statField);
169 	virtual void NewAttributesMenu(BMenu*);
170 
171 	void HideAttributesMenu();
172 	void ShowAttributesMenu();
173 	PiggybackTaskLoop* DelayedTaskLoop();
174 		// use for RunLater queueing
175 	void PulseTaskLoop();
176 		// called by some view that has pulse, either BackgroundView
177 		// or BPoseView
178 
179 	static bool DefaultStateSourceNode(const char* name, BNode* result,
180 		bool createNew = false, bool createFolder = true);
181 
182 	BMessage* AddOnMessage(int32);
183 	BPopUpMenu* ContextMenu();
184 
185 	// drag&drop support
186 	status_t DragStart(const BMessage*);
187 	void DragStop();
188 	bool Dragging() const;
189 	BMessage* DragMessage() const;
190 
191 	void ShowSelectionWindow();
192 
193 	void ShowNavigator(bool);
194 	void SetSingleWindowBrowseShortcuts(bool);
195 
196 	void SetPathWatchingEnabled(bool);
197 	bool IsPathWatchingEnabled(void) const;
198 
199 protected:
200 	virtual BPoseView* NewPoseView(Model*, uint32);
201 		// instantiate a different flavor of BPoseView for different
202 		// ContainerWindows
203 
204 	virtual void RestoreWindowState(AttributeStreamNode*);
205 	virtual void RestoreWindowState(const BMessage &);
206 	virtual void SaveWindowState(AttributeStreamNode*);
207 	virtual void SaveWindowState(BMessage&) const;
208 
209 	virtual bool NeedsDefaultStateSetup();
210 	virtual void SetupDefaultState();
211 		// these two virtuals control setting up a new folder that
212 		// does not have any state settings yet with the default
213 
214 	virtual void AddMenus();
215 	virtual void AddShortcuts();
216 		// add equivalents of the menu shortcuts to the menuless
217 		// desktop window
218 	virtual void AddFileMenu(BMenu* menu);
219 	virtual void AddWindowMenu(BMenu* menu);
220 
221 	virtual void AddContextMenus();
222 
223 	virtual void AddFileContextMenus(BMenu*);
224 	virtual void AddWindowContextMenus(BMenu*);
225 	virtual void AddVolumeContextMenus(BMenu*);
226 	virtual void AddDropContextMenus(BMenu*);
227 	virtual void AddTrashContextMenus(BMenu*);
228 
229 	virtual void RepopulateMenus();
230 	void PopulateArrangeByMenu(BMenu*);
231 
232 	virtual void SetCutItem(BMenu*);
233 	virtual void SetCopyItem(BMenu*);
234 	virtual void SetPasteItem(BMenu*);
235 	virtual void SetArrangeMenu(BMenu*);
236 	virtual void SetCloseItem(BMenu*);
237 	virtual void SetupNavigationMenu(const entry_ref*, BMenu*);
238 	virtual void SetupMoveCopyMenus(const entry_ref*, BMenu*);
239 	virtual void PopulateMoveCopyNavMenu(BNavMenu*, uint32,
240 		const entry_ref*, bool);
241 
242 	virtual void SetupOpenWithMenu(BMenu*);
243 	virtual void SetupEditQueryItem(BMenu*);
244 	virtual void SetupDiskMenu(BMenu*);
245 
246 	virtual void BuildAddOnsMenu(BMenu*);
247 	void BuildMimeTypeList(BStringList& mimeTypes);
248 
249 	enum UpdateMenuContext {
250 		kMenuBarContext,
251 		kPosePopUpContext,
252 		kWindowPopUpContext
253 	};
254 
255 	virtual void UpdateMenu(BMenu* menu, UpdateMenuContext context);
256 
257 	BMenu* AddMimeMenu(const BMimeType& mimeType, bool isSuperType,
258 		BMenu* menu, int32 start);
259 
260 	BHandler* ResolveSpecifier(BMessage*, int32, BMessage*, int32,
261 		const char*);
262 
263 	void LoadAddOn(BMessage*);
264 	void EachAddOn(void (*)(const Model*, const char*, uint32 shortcut,
265 			uint32 modifiers, bool primary, void*, BContainerWindow*, BMenu*),
266 		void*, BStringList&, BMenu*);
267 
268 protected:
269 	LockingList<BWindow>* fWindowList;
270 	uint32 fOpenFlags;
271 	bool fUsesLayout;
272 
273 	BGroupLayout* fRootLayout;
274 	BGroupView* fMenuContainer;
275 	BGridView* fPoseContainer;
276 	BorderedView* fBorderedView;
277 	BGroupView* fVScrollBarContainer;
278 	BGroupView* fCountContainer;
279 
280 	BPopUpMenu* fContextMenu;
281 	BPopUpMenu* fFileContextMenu;
282 	BPopUpMenu* fWindowContextMenu;
283 	BPopUpMenu* fDropContextMenu;
284 	BPopUpMenu* fVolumeContextMenu;
285 	BPopUpMenu* fTrashContextMenu;
286 	BPopUpNavMenu* fDragContextMenu;
287 	BMenuItem* fMoveToItem;
288 	BMenuItem* fCopyToItem;
289 	BMenuItem* fCreateLinkItem;
290 	BMenuItem* fOpenWithItem;
291 	ModelMenuItem* fNavigationItem;
292 	BMenuBar* fMenuBar;
293 	DraggableContainerIcon* fDraggableIcon;
294 	BNavigator* fNavigator;
295 	BPoseView* fPoseView;
296 	BMenu* fAttrMenu;
297 	BMenu* fWindowMenu;
298 	BMenu* fFileMenu;
299 	BMenu* fArrangeByMenu;
300 
301 	SelectionWindow* fSelectionWindow;
302 
303 	PiggybackTaskLoop* fTaskLoop;
304 
305 	bool fStateNeedsSaving;
306 
307 	BackgroundImage* fBackgroundImage;
308 
309 	static LockingList<struct AddOnShortcut>* fAddOnsList;
310 
311 private:
312 	BRect fSavedZoomRect;
313 	BRect fPreviousBounds;
314 
315 	static BRect sNewWindRect;
316 
317 	BMessage* fDragMessage;
318 	BObjectList<BString>* fCachedTypesList;
319 	bool fWaitingForRefs;
320 	bool fSaveStateIsEnabled;
321 	bool fIsWatchingPath;
322 
323 	typedef BWindow _inherited;
324 
325 	friend int32 show_context_menu(void*);
326 	friend class BackgroundView;
327 
328 	void _UpdateSelectionMIMEInfo();
329 	void _AddFolderIcon();
330 	void _PassMessageToAddOn(BMessage*);
331 	void _NewTemplateSubmenu(entry_ref);
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 BorderedView : public BGroupView {
360 public:
361 	BorderedView();
362 
363 	void PoseViewFocused(bool);
364 	virtual void Pulse();
365 
366 	void EnableBorderHighlight(bool);
367 
368 protected:
369 	virtual void WindowActivated(bool);
370 
371 private:
372 	bool fEnableBorderHighlight;
373 
374 	typedef BGroupView _inherited;
375 };
376 
377 
378 // inlines ---------
379 
380 inline BNavigator*
381 BContainerWindow::Navigator() const
382 {
383 	return fNavigator;
384 }
385 
386 
387 inline BPoseView*
388 BContainerWindow::PoseView() const
389 {
390 	return fPoseView;
391 }
392 
393 
394 inline void
395 BContainerWindow::SetupDiskMenu(BMenu*)
396 {
397 	// nothing at this level
398 }
399 
400 
401 inline BPopUpMenu*
402 BContainerWindow::ContextMenu()
403 {
404 	return fContextMenu;
405 }
406 
407 
408 inline bool
409 BContainerWindow::Dragging() const
410 {
411 	return fDragMessage && fCachedTypesList;
412 }
413 
414 
415 inline BMessage*
416 BContainerWindow::DragMessage() const
417 {
418 	return fDragMessage;
419 }
420 
421 
422 inline bool
423 BContainerWindow::SaveStateIsEnabled() const
424 {
425 	return fSaveStateIsEnabled;
426 }
427 
428 
429 inline void
430 BContainerWindow::SetSaveStateEnabled(bool value)
431 {
432 	fSaveStateIsEnabled = value;
433 }
434 
435 
436 inline bool
437 BContainerWindow::IsPathWatchingEnabled() const
438 {
439 	return fIsWatchingPath;
440 }
441 
442 
443 filter_result ActivateWindowFilter(BMessage* message, BHandler** target,
444 	BMessageFilter* messageFilter);
445 
446 } // namespace BPrivate
447 
448 using namespace BPrivate;
449 
450 
451 #endif	// _CONTAINER_WINDOW_H
452