diff options
Diffstat (limited to 'src/lib/FL/Fl_Native_File_Chooser_MAC.H')
-rw-r--r-- | src/lib/FL/Fl_Native_File_Chooser_MAC.H | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/src/lib/FL/Fl_Native_File_Chooser_MAC.H b/src/lib/FL/Fl_Native_File_Chooser_MAC.H new file mode 100644 index 0000000..49577c4 --- /dev/null +++ b/src/lib/FL/Fl_Native_File_Chooser_MAC.H | |||
@@ -0,0 +1,138 @@ | |||
1 | // | ||
2 | // Fl_Native_File_Chooser_MAC.H -- FLTK native OS file chooser widget | ||
3 | // | ||
4 | // Copyright 2004 by Greg Ercolano. | ||
5 | // | ||
6 | // This library is free software; you can redistribute it and/or | ||
7 | // modify it under the terms of the GNU Library General Public | ||
8 | // License as published by the Free Software Foundation; either | ||
9 | // version 2 of the License, or (at your option) any later version. | ||
10 | // | ||
11 | // This library is distributed in the hope that it will be useful, | ||
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | // Library General Public License for more details. | ||
15 | // | ||
16 | // You should have received a copy of the GNU Library General Public | ||
17 | // License along with this library; if not, write to the Free Software | ||
18 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
19 | // USA. | ||
20 | // | ||
21 | // 10 20 30 40 50 60 70 | ||
22 | // | | | | | | | | ||
23 | // 4567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
24 | |||
25 | // OSX-SPECIFIC NATIVE BROWSER | ||
26 | #ifdef __APPLE_CC__ | ||
27 | #include <Carbon/Carbon.h> | ||
28 | #else | ||
29 | #include <Carbon.h> | ||
30 | #endif | ||
31 | |||
32 | #include <FL/filename.H> | ||
33 | #define MAXFILTERS 80 | ||
34 | |||
35 | class Fl_Native_File_Chooser { | ||
36 | public: | ||
37 | enum Type { | ||
38 | BROWSE_FILE = 0, | ||
39 | BROWSE_DIRECTORY, | ||
40 | BROWSE_MULTI_FILE, | ||
41 | BROWSE_MULTI_DIRECTORY, | ||
42 | BROWSE_SAVE_FILE, | ||
43 | BROWSE_SAVE_DIRECTORY | ||
44 | }; | ||
45 | enum Option { | ||
46 | NO_OPTIONS = 0x0000, // no options enabled | ||
47 | SAVEAS_CONFIRM = 0x0001, // Show native 'Save As' overwrite | ||
48 | // confirm dialog (if supported) | ||
49 | NEW_FOLDER = 0x0002, // Show 'New Folder' icon | ||
50 | // (if supported) | ||
51 | PREVIEW = 0x0004, // enable preview mode | ||
52 | }; | ||
53 | protected: | ||
54 | NavDialogCreationOptions _opts; // file navigation options | ||
55 | private: | ||
56 | int _btype; // kind-of browser to show() | ||
57 | int _options; // general options | ||
58 | NavDialogRef _ref; // file navigation reference | ||
59 | NavActionState _keepstate; // holds button permissions | ||
60 | NavMenuItemSpec _tempitem; // Popup menu selection | ||
61 | char **_pathnames; // array of pathnames | ||
62 | int _tpathnames; // total pathnames | ||
63 | char *_directory; // default pathname to use | ||
64 | char *_title; // title for window | ||
65 | char *_preset_file; // the 'save as' filename | ||
66 | |||
67 | char *_filter; // user-side search filter, eg: | ||
68 | // C Files\t*.[ch]\nText Files\t*.txt" | ||
69 | |||
70 | char *_filt_names; // filter names (tab delimited) | ||
71 | // eg. "C Files\tText Files" | ||
72 | |||
73 | char *_filt_patt[MAXFILTERS]; | ||
74 | // array of filter patterns, eg: | ||
75 | // _filt_patt[0]="*.{cxx,h}" | ||
76 | // _filt_patt[1]="*.txt" | ||
77 | |||
78 | int _filt_total; // parse_filter() # of filters loaded | ||
79 | int _filt_value; // index of the selected filter | ||
80 | char *_errmsg; // error message | ||
81 | |||
82 | // PRIVATE CLASS TO HANDLE NAVIGATION DIALOG REPLY STRUCT | ||
83 | // Class-ified, mainly to ensure proper cleanup. | ||
84 | // | ||
85 | class NavReply { | ||
86 | int _valid_reply; | ||
87 | NavReplyRecord _reply; | ||
88 | public: | ||
89 | NavReply(); | ||
90 | ~NavReply(); | ||
91 | int get_reply(NavDialogRef& ref); | ||
92 | int get_saveas_basename(char *s, int slen); | ||
93 | int get_dirname(char *s, int slen); | ||
94 | int get_pathnames(char **&pathnames, int& tpathnames); | ||
95 | }; | ||
96 | |||
97 | // Private methods | ||
98 | void errmsg(const char *msg); | ||
99 | void clear_pathnames(); | ||
100 | void set_single_pathname(const char *s); | ||
101 | int get_saveas_basename(NavDialogRef& ref); | ||
102 | int get_pathnames(NavDialogRef& ref); | ||
103 | static void event_handler(NavEventCallbackMessage callBackSelector, | ||
104 | NavCBRecPtr cbparm, void *data); | ||
105 | |||
106 | void clear_filters(); | ||
107 | void add_filter(const char *, const char *); | ||
108 | void parse_filter(const char *from); | ||
109 | static Boolean filter_proc_cb(AEDesc *, void *, void *, NavFilterModes); | ||
110 | Boolean filter_proc_cb2(AEDesc*, void*, void*, NavFilterModes); | ||
111 | int post(); | ||
112 | |||
113 | public: | ||
114 | Fl_Native_File_Chooser(int val = BROWSE_FILE); | ||
115 | ~Fl_Native_File_Chooser(); | ||
116 | |||
117 | // Public methods | ||
118 | void type(int); | ||
119 | int type() const; | ||
120 | void options(int); | ||
121 | int options() const; | ||
122 | int count() const; | ||
123 | const char *filename() const; | ||
124 | const char *filename(int i) const; | ||
125 | void directory(const char *); | ||
126 | const char *directory() const; | ||
127 | void title(const char *); | ||
128 | const char *title() const; | ||
129 | const char *filter() const; | ||
130 | void filter(const char *); | ||
131 | void filter_value(int i) { _filt_value = i; } | ||
132 | int filter_value() { return(_filt_value); } | ||
133 | int filters() { return(_filt_total); } | ||
134 | void preset_file(const char *); | ||
135 | const char *preset_file(); | ||
136 | const char *errmsg() const; | ||
137 | int show(); | ||
138 | }; | ||