xref: /haiku/headers/os/storage/FilePanel.h (revision 51978af14a173e7fae0563b562be5603bc652aeb)
1 /*******************************************************************************
2 /
3 /	File:		FilePanel.h
4 /
5 /	Description:	BFilePanel and BRefFilter classes, and
6 /					run_open_panel()/run_save_panel functions.
7 /
8 /	Copyright 1993-98, Be Incorporated, All Rights Reserved.
9 /
10 *******************************************************************************/
11 
12 #ifndef	_FILE_PANEL_H
13 #define _FILE_PANEL_H
14 
15 #ifndef _BE_BUILD_H
16 #include <BeBuild.h>
17 #endif
18 
19 #include <sys/stat.h>
20 #include <Entry.h>
21 #include <Directory.h>
22 #include <Node.h>
23 
24 
25 /*- Old fashioned, one-shot, heavily-defaulted panel functions. -*/
26 
27 extern _IMPEXP_TRACKER void run_open_panel();
28 extern _IMPEXP_TRACKER void run_save_panel();
29 
30 
31 /*---BRefFilter--------------------------------------------------*/
32 
33 /* BRefFilter is used by BFilePanel.  Every time the user selects
34  * an item in a file panel, the Filter() func is sent to the
35  * panel's BRefFilter object.  Filter()'s return value determines
36  * whether the item is admitted into the panel's list of
37  * displayed items.  Optional.
38  */
39 class BRefFilter {
40 public:
41 virtual	bool	Filter(const entry_ref *, BNode *, struct stat *,
42 					   const char *mimetype) = 0;
43 };
44 
45 
46 /*---File Panel constants etc------------------------------------*/
47 
48 enum file_panel_mode {
49 	B_OPEN_PANEL,
50 	B_SAVE_PANEL
51 };
52 
53 enum file_panel_button {
54 	B_CANCEL_BUTTON,
55 	B_DEFAULT_BUTTON
56 };
57 
58 class BWindow;
59 class BMessenger;
60 class BMessage;
61 
62 /*---------------------------------------------------------------*/
63 /*----BFilePanel-------------------------------------------------*/
64 
65 /* Most of the contructor parameters can also be set through individual
66  * funcs.  But these can't:
67  *
68  *  file_panel_mode mode
69  *  uint32 node_flavors
70  *  bool modal
71  */
72 
73 class BFilePanel {
74 
75 public:
76 						BFilePanel(file_panel_mode mode = B_OPEN_PANEL,
77 							BMessenger *target = 0,
78 							const entry_ref *start_directory = 0,
79 							uint32 node_flavors = 0,
80 							bool allow_multiple_selection = true,
81 							BMessage *message = 0,
82 							BRefFilter * = 0,
83 							bool modal = false,
84 							bool hide_when_done = true);
85 
86 virtual					~BFilePanel();
87 
88 		void			Show();
89 		void			Hide();
90 		bool			IsShowing() const;
91 
92 virtual	void			WasHidden();
93 virtual	void			SelectionChanged();
94 virtual	void			SendMessage(const BMessenger*, BMessage*);
95 
96 		BWindow*		Window() const;
97 		BMessenger		Messenger() const;
98 		BRefFilter*		RefFilter() const;
99 		void			GetPanelDirectory(entry_ref *) const;
100 
101 		file_panel_mode	PanelMode() const;
102 
103 		void			SetTarget(BMessenger);
104 		void			SetMessage(BMessage *msg);
105 
106 		void			SetRefFilter(BRefFilter* filter);
107 		void			SetSaveText(const char* text);
108 		void			SetButtonLabel(file_panel_button, const char *label);
109 
110 		void			SetPanelDirectory(const BEntry *new_directory);
111 		void			SetPanelDirectory(const BDirectory *new_directory);
112 		void			SetPanelDirectory(const entry_ref *new_directory);
113 		void 			SetPanelDirectory(const char *new_directory);
114 
115 		void			SetHideWhenDone(bool);
116 		bool			HidesWhenDone(void) const;
117 
118 		void			Refresh();
119 		void			Rewind();
120 		status_t		GetNextSelectedRef(entry_ref*);
121 
122 private:
123 
124 #if !_PR3_COMPATIBLE_
125 virtual	void			_ReservedFilePanel1();
126 virtual	void			_ReservedFilePanel2();
127 virtual	void			_ReservedFilePanel3();
128 virtual	void			_ReservedFilePanel4();
129 virtual	void			_ReservedFilePanel5();
130 virtual	void			_ReservedFilePanel6();
131 virtual	void			_ReservedFilePanel7();
132 virtual	void			_ReservedFilePanel8();
133 #endif
134 
135 		BWindow		*fWindow;
136 
137 #if !_PR3_COMPATIBLE_
138 		uint32			_reserved[10];
139 #endif
140 
141 public:
142 	// deprecated calls, do not use
143 	BFilePanel(file_panel_mode mode, BMessenger *, entry_ref *,
144 		uint32 , bool, BMessage *, BRefFilter *, bool modal,
145 		bool hide_when_done);
146 	void SetPanelDirectory(BEntry*);
147 	void SetPanelDirectory(BDirectory*);
148 	void SetPanelDirectory(entry_ref*);
149 };
150 
151 #endif
152