1/*
2Open Tracker License
3
4Terms and Conditions
5
6Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7
8Permission is hereby granted, free of charge, to any person obtaining a copy of
9this software and associated documentation files (the "Software"), to deal in
10the Software without restriction, including without limitation the rights to
11use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12of the Software, and to permit persons to whom the Software is furnished to do
13so, subject to the following conditions:
14
15The above copyright notice and this permission notice applies to all licensees
16and shall be included in all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25Except as contained in this notice, the name of Be Incorporated shall not be
26used in advertising or otherwise to promote the sale, use or other dealings in
27this Software without prior written authorization from Be Incorporated.
28
29Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30of Be Incorporated in the United States and other countries. Other brand product
31names are registered trademarks or trademarks of their respective holders.
32All 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
49template<class T> class BObjectList;
50class BMenuItem;
51
52
53namespace BPrivate {
54
55class Model;
56class BContainerWindow;
57class ModelMenuItem;
58class EntryListBase;
59
60
61struct 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
75class BNavMenu : public BSlowMenu {
76public:
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
122protected:
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
152class BPopUpNavMenu : public BNavMenu {
153public:
154	BPopUpNavMenu(const char* title);
155	~BPopUpNavMenu();
156
157	void ClearMenu();
158
159	void Go(BPoint where);
160	bool IsShowing() const;
161
162protected:
163	BPoint ScreenLocation();
164
165private:
166	void _WaitForTrackThread();
167	static int32 _TrackThread(void* menu);
168
169private:
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
191using namespace BPrivate;
192
193
194#endif	// NAV_MENU_H
195