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