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