xref: /haiku/headers/private/tracker/NavMenu.h (revision e1c4049fed1047bdb957b0529e1921e97ef94770)
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 //	NavMenu is a hierarchical menu of volumes, folders, files and queries
36 //	displays icons, uses the SlowMenu API for full interruptability
37 
38 #ifndef NAV_MENU_H
39 #define NAV_MENU_H
40 
41 
42 #include <Messenger.h>
43 #include <StorageDefs.h>
44 #include <Entry.h>
45 
46 #include "SlowMenu.h"
47 
48 
49 template<class T> class BObjectList;
50 class BMenuItem;
51 
52 
53 namespace BPrivate {
54 
55 class Model;
56 class BContainerWindow;
57 class ModelMenuItem;
58 class EntryListBase;
59 
60 
61 struct TrackingHookData {
62 	TrackingHookData()
63 		:
64 		fTrackingHook(NULL),
65 		fDragMessage(NULL)
66 	{
67 	}
68 
69 	bool (*fTrackingHook)(BMenu*, void*);
70 	BMessenger fTarget;
71 	const BMessage* fDragMessage;
72 };
73 
74 
75 class BNavMenu : public BSlowMenu {
76 public:
77 	BNavMenu(const char* title, uint32 message, const BHandler*,
78 		BWindow* parentWindow = NULL, const BObjectList<BString>* list = NULL);
79 	BNavMenu(const char* title, uint32 message, const BMessenger&,
80 		BWindow* parentWindow = NULL, const BObjectList<BString>* list = NULL);
81 		// parentWindow, if specified, will be closed if nav menu item invoked
82 		// with option held down
83 
84 	virtual ~BNavMenu();
85 
86 	virtual void AttachedToWindow();
87 	virtual void DetachedFromWindow();
88 
89 	void SetNavDir(const entry_ref*);
90 	void ForceRebuild();
91 	bool NeedsToRebuild() const;
92 		// will cause menu to get rebuilt next time it is shown
93 
94 	virtual void ResetTargets();
95 	void SetTarget(const BMessenger&);
96 	BMessenger Target();
97 
98 	void SetTypesList(const BObjectList<BString>* list);
99 	const BObjectList<BString>* TypesList() const;
100 
101 	void AddNavDir(const Model* model, uint32 what, BHandler* target,
102 		bool populateSubmenu);
103 
104 	void AddNavParentDir(const char* name, const Model* model, uint32 what,
105 		BHandler* target);
106 	void AddNavParentDir(const Model* model, uint32 what, BHandler* target);
107 	void SetShowParent(bool show);
108 
109 	static int32 GetMaxMenuWidth();
110 
111 	static int CompareFolderNamesFirstOne(const BMenuItem*, const BMenuItem*);
112 	static int CompareOne(const BMenuItem*, const BMenuItem*);
113 
114 	static ModelMenuItem* NewModelItem(Model*, const BMessage*,
115 		const BMessenger&, bool suppressFolderHierarchy = false,
116 		BContainerWindow* = NULL, const BObjectList<BString>* typeslist = NULL,
117 		TrackingHookData* hook = NULL);
118 
119 	TrackingHookData* InitTrackingHook(bool (*hookfunction)(BMenu*, void*),
120 		const BMessenger* target, const BMessage* dragMessage);
121 
122 protected:
123 	virtual bool StartBuildingItemList();
124 	virtual bool AddNextItem();
125 	virtual void DoneBuildingItemList();
126 	virtual void ClearMenuBuildingState();
127 
128 	void BuildVolumeMenu();
129 
130 	void AddOneItem(Model*);
131 	void AddRootItemsIfNeeded();
132 	void AddTrashItem();
133 	static void SetTrackingHookDeep(BMenu*, bool (*)(BMenu*, void*), void*);
134 
135 	entry_ref fNavDir;
136 	BMessage fMessage;
137 	BMessenger fMessenger;
138 	BWindow* fParentWindow;
139 
140 	// menu building state
141 	uint8 fFlags;
142 	BObjectList<BMenuItem>* fItemList;
143 	EntryListBase* fContainer;
144 	bool fIteratingDesktop;
145 
146 	BObjectList<BString>* fTypesList;
147 
148 	TrackingHookData fTrackingHook;
149 };
150 
151 
152 class BPopUpNavMenu : public BNavMenu {
153 public:
154 	BPopUpNavMenu(const char* title);
155 	~BPopUpNavMenu();
156 
157 	void ClearMenu();
158 
159 	void Go(BPoint where);
160 	bool IsShowing() const;
161 
162 protected:
163 	BPoint ScreenLocation();
164 
165 private:
166 	void _WaitForTrackThread();
167 	static int32 _TrackThread(void* menu);
168 
169 private:
170 	BPoint fWhere;
171 	thread_id fTrackThread;
172 };
173 
174 
175 //	Spring Loaded Folder convenience routines
176 //		used in both Tracker and Deskbar
177 #ifndef _IMPEXP_TRACKER
178 #	define _IMPEXP_TRACKER
179 #endif
180 _IMPEXP_TRACKER bool SpringLoadedFolderCompareMessages(const BMessage *incoming,
181 	const BMessage *dragmessage);
182 _IMPEXP_TRACKER void SpringLoadedFolderSetMenuStates(const BMenu *menu,
183 	const BObjectList<BString> *typeslist);
184 _IMPEXP_TRACKER void SpringLoadedFolderAddUniqueTypeToList(entry_ref *ref,
185 	BObjectList<BString> *typeslist);
186 _IMPEXP_TRACKER void SpringLoadedFolderCacheDragData(const BMessage *incoming,
187 	BMessage **, BObjectList<BString> **typeslist);
188 
189 } // namespace BPrivate
190 
191 using namespace BPrivate;
192 
193 
194 #endif	// NAV_MENU_H
195