xref: /haiku/src/kits/tracker/ContainerWindow.h (revision 4052469d007d17112b0fdf8814c92c77414a1398)
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 		BMenuItem *NewAttributeMenuItem(const char *label, const char *name,
154 			int32 type, float width, int32 align, bool editable, bool statField);
155 		BMenuItem *NewAttributeMenuItem(const char *label, const char *name,
156 			int32 type, const char* displayAs, float width, int32 align,
157 			bool editable, bool statField);
158 		virtual	void NewAttributeMenu(BMenu *);
159 
160 		void HideAttributeMenu();
161 		void ShowAttributeMenu();
162 		PiggybackTaskLoop *DelayedTaskLoop();
163 			// use for RunLater queueing
164 		void PulseTaskLoop();
165 			// called by some view that has pulse, either BackgroundView or BPoseView
166 
167 		static bool DefaultStateSourceNode(const char *name, BNode *result,
168 			bool createNew = false, bool createFolder = true);
169 
170 		// add-on iteration
171 		void EachAddon(bool(*)(const Model *, const char *, uint32 shortcut, bool primary, void *), void *);
172 
173 		BPopUpMenu *ContextMenu();
174 
175 		// drag&drop support
176 		status_t DragStart(const BMessage *);
177 		void DragStop();
178 		bool Dragging() const;
179 		BMessage *DragMessage() const;
180 
181 		void ShowSelectionWindow();
182 
183 		void ShowNavigator(bool);
184 		void SetSingleWindowBrowseShortcuts(bool);
185 
186 		void SetPathWatchingEnabled(bool);
187 		bool IsPathWatchingEnabled(void) const;
188 
189 	protected:
190 		virtual BPoseView *NewPoseView(Model *, BRect, uint32);
191 			// instantiate a different flavor of BPoseView for different
192 			// ContainerWindows
193 
194 		virtual void RestoreWindowState(AttributeStreamNode *);
195 		virtual void RestoreWindowState(const BMessage &);
196 		virtual void SaveWindowState(AttributeStreamNode *);
197 		virtual void SaveWindowState(BMessage &) const;
198 
199 		virtual bool NeedsDefaultStateSetup();
200 		virtual void SetUpDefaultState();
201 			// these two virtuals control setting up a new folder that
202 			// does not have any state settings yet with the default
203 
204 		virtual	void AddMenus();
205 		virtual void AddShortcuts();
206 			// add equivalents of the menu shortcuts to the menuless desktop window
207 		virtual	void AddFileMenu(BMenu *menu);
208 		virtual	void AddWindowMenu(BMenu *menu);
209 
210 		virtual void AddContextMenus();
211 
212 		virtual	void AddFileContextMenus(BMenu *);
213 		virtual	void AddWindowContextMenus(BMenu *);
214 		virtual	void AddVolumeContextMenus(BMenu *);
215 		virtual	void AddDropContextMenus(BMenu *);
216 		virtual void AddTrashContextMenus(BMenu *);
217 
218 		virtual void RepopulateMenus();
219 
220 		virtual	void SetCutItem(BMenu *);
221 		virtual	void SetCopyItem(BMenu *);
222 		virtual	void SetPasteItem(BMenu *);
223 		virtual	void SetCleanUpItem(BMenu *);
224 		virtual void SetCloseItem(BMenu *);
225 		virtual	void SetupNavigationMenu(const entry_ref *, BMenu *);
226 		virtual	void SetupMoveCopyMenus(const entry_ref *, BMenu *);
227 		virtual	void PopulateMoveCopyNavMenu(BNavMenu *, uint32, const entry_ref *, bool);
228 
229 		virtual	void SetupOpenWithMenu(BMenu *);
230 		virtual	void SetUpEditQueryItem(BMenu *);
231 		virtual	void SetUpDiskMenu(BMenu *);
232 
233 		virtual	void BuildAddOnMenu(BMenu *);
234 
235 		enum UpdateMenuContext {
236 			kMenuBarContext,
237 			kPosePopUpContext,
238 			kWindowPopUpContext
239 		};
240 
241 		virtual void UpdateMenu(BMenu *menu, UpdateMenuContext context);
242 
243 		BMenu* AddMimeMenu(const BMimeType& mimeType, bool isSuperType,
244 			BMenu* menu, int32 start);
245 
246 		BHandler *ResolveSpecifier(BMessage *, int32, BMessage *, int32,
247 			const char *);
248 
249 		bool EachAddon(BPath &path, bool(*)(const Model *, const char *, uint32, bool, void *),
250 			BObjectList<Model> *, void *);
251 		void LoadAddOn(BMessage *);
252 
253 		BPopUpMenu *fFileContextMenu;
254 		BPopUpMenu *fWindowContextMenu;
255 		BPopUpMenu *fDropContextMenu;
256 		BPopUpMenu *fVolumeContextMenu;
257 		BPopUpMenu *fTrashContextMenu;
258 		BSlowContextMenu *fDragContextMenu;
259 		BMenuItem *fMoveToItem;
260 		BMenuItem *fCopyToItem;
261 		BMenuItem *fCreateLinkItem;
262 		BMenuItem *fOpenWithItem;
263 		ModelMenuItem *fNavigationItem;
264 		BMenuBar *fMenuBar;
265 		BNavigator *fNavigator;
266 		BPoseView *fPoseView;
267 		LockingList<BWindow> *fWindowList;
268 		BMenu *fAttrMenu;
269 		BMenu *fWindowMenu;
270 		BMenu *fFileMenu;
271 
272 		SelectionWindow *fSelectionWindow;
273 
274 		PiggybackTaskLoop *fTaskLoop;
275 
276 		bool fIsTrash;
277 		bool fInTrash;
278 		bool fIsPrinters;
279 
280 		uint32 fContainerWindowFlags;
281 		BackgroundImage *fBackgroundImage;
282 
283 	private:
284 		BRect fSavedZoomRect;
285 		BRect fPreviousBounds;
286 
287 		static BRect sNewWindRect;
288 
289 		BPopUpMenu *fContextMenu;
290 		BMessage *fDragMessage;
291 		BObjectList<BString> *fCachedTypesList;
292 		bool fWaitingForRefs;
293 
294 		bool fStateNeedsSaving;
295 		bool fSaveStateIsEnabled;
296 
297 		bool fIsWatchingPath;
298 
299 		typedef BWindow _inherited;
300 
301 		friend int32 show_context_menu(void*);
302 		friend class BackgroundView;
303 };
304 
305 class WindowStateNodeOpener {
306 	// this class manages opening and closing the proper node for
307 	// state restoring / saving; the constructor knows how to decide wether
308 	// to use a special directory for root, etc.
309 	// setter calls used when no attributes can be read from a node and defaults
310 	// are to be substituted
311 	public:
312 		WindowStateNodeOpener(BContainerWindow *window, bool forWriting);
313 		virtual ~WindowStateNodeOpener();
314 
315 		void SetTo(const BDirectory *);
316 		void SetTo(const BEntry *entry, bool forWriting);
317 		void SetTo(Model *, bool forWriting);
318 
319 		AttributeStreamNode *StreamNode() const;
320 		BNode *Node() const;
321 
322 	private:
323 		ModelNodeLazyOpener *fModelOpener;
324 		BNode *fNode;
325 		AttributeStreamNode *fStreamNode;
326 };
327 
328 class BackgroundView : public BView {
329 	// background view placed in a BContainerWindow, under the pose view
330 	public:
331 		BackgroundView(BRect);
332 		virtual	void AttachedToWindow();
333 		virtual	void FrameResized(float, float);
334 		virtual	void Draw(BRect);
335 
336 		void PoseViewFocused(bool);
337 		virtual void Pulse();
338 
339 	protected:
340 		virtual void WindowActivated(bool);
341 
342 	private:
343 		typedef BView _inherited;
344 };
345 
346 int CompareLabels(const BMenuItem *, const BMenuItem *);
347 
348 // inlines ---------
349 
350 inline BNavigator *
351 BContainerWindow::Navigator() const
352 {
353 	return fNavigator;
354 }
355 
356 inline BPoseView *
357 BContainerWindow::PoseView() const
358 {
359 	return fPoseView;
360 }
361 
362 inline bool
363 BContainerWindow::IsTrash() const
364 {
365 	return fIsTrash;
366 }
367 
368 inline bool
369 BContainerWindow::InTrash() const
370 {
371 	return fInTrash;
372 }
373 
374 inline bool
375 BContainerWindow::IsPrintersDir() const
376 {
377 	return fIsPrinters;
378 }
379 
380 inline void
381 BContainerWindow::SetUpDiskMenu(BMenu *)
382 {
383 	// nothing at this level
384 }
385 
386 inline BPopUpMenu *
387 BContainerWindow::ContextMenu()
388 {
389 	return fContextMenu;
390 }
391 
392 inline bool
393 BContainerWindow::Dragging() const
394 {
395 	return fDragMessage && fCachedTypesList;
396 }
397 
398 inline BMessage *
399 BContainerWindow::DragMessage() const
400 {
401 	return fDragMessage;
402 }
403 inline
404 bool
405 BContainerWindow::SaveStateIsEnabled() const
406 {
407 	return fSaveStateIsEnabled;
408 }
409 
410 inline
411 void
412 BContainerWindow::SetSaveStateEnabled(bool value)
413 {
414 	fSaveStateIsEnabled = value;
415 }
416 
417 inline
418 bool
419 BContainerWindow::IsPathWatchingEnabled() const
420 {
421 	return fIsWatchingPath;
422 }
423 
424 filter_result ActivateWindowFilter(BMessage *message, BHandler **target,
425 	BMessageFilter *messageFilter);
426 
427 } // namespace BPrivate
428 
429 using namespace BPrivate;
430 
431 #endif
432