Tweak themes for more color consistency.
[ntk.git] / src / Fl_File_Chooser.cxx
blob4d879d2af826257645aa4f233af0cea3f190049d
1 //
2 // "$Id: Fl_File_Chooser.cxx 8786 2011-06-07 11:41:36Z manolo $"
3 //
4 // Fl_File_Chooser dialog for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2011 by Bill Spitzak and others.
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 // USA.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 // generated by Fast Light User Interface Designer (fluid) version 1.0300
30 #include "../FL/Fl_File_Chooser.H"
31 #include <FL/fl_draw.H>
33 void Fl_File_Chooser::cb_window_i(Fl_Double_Window*, void*) {
34 fileName->value("");
35 fileList->deselect();
36 Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
37 window->hide();
39 void Fl_File_Chooser::cb_window(Fl_Double_Window* o, void* v) {
40 ((Fl_File_Chooser*)(o->user_data()))->cb_window_i(o,v);
43 void Fl_File_Chooser::cb_showChoice_i(Fl_Choice*, void*) {
44 showChoiceCB();
46 void Fl_File_Chooser::cb_showChoice(Fl_Choice* o, void* v) {
47 ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_showChoice_i(o,v);
50 void Fl_File_Chooser::cb_favoritesButton_i(Fl_Menu_Button*, void*) {
51 favoritesButtonCB();
53 void Fl_File_Chooser::cb_favoritesButton(Fl_Menu_Button* o, void* v) {
54 ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_favoritesButton_i(o,v);
57 void Fl_File_Chooser::cb_newButton_i(Fl_Button*, void*) {
58 newdir();
60 void Fl_File_Chooser::cb_newButton(Fl_Button* o, void* v) {
61 ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_newButton_i(o,v);
64 #include <FL/Fl_Bitmap.H>
65 static unsigned char idata_new[] =
66 {0,0,120,0,132,0,2,1,1,254,1,128,49,128,49,128,253,128,253,128,49,128,49,
67 128,1,128,1,128,255,255,0,0};
68 static Fl_Bitmap image_new(idata_new, 16, 16);
70 void Fl_File_Chooser::cb__i(Fl_Tile*, void*) {
71 update_preview();
73 void Fl_File_Chooser::cb_(Fl_Tile* o, void* v) {
74 ((Fl_File_Chooser*)(o->parent()->user_data()))->cb__i(o,v);
77 void Fl_File_Chooser::cb_fileList_i(Fl_File_Browser*, void*) {
78 fileListCB();
80 void Fl_File_Chooser::cb_fileList(Fl_File_Browser* o, void* v) {
81 ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_fileList_i(o,v);
84 void Fl_File_Chooser::cb_previewButton_i(Fl_Check_Button*, void*) {
85 preview(previewButton->value());
87 void Fl_File_Chooser::cb_previewButton(Fl_Check_Button* o, void* v) {
88 ((Fl_File_Chooser*)(o->parent()->parent()->parent()->user_data()))->cb_previewButton_i(o,v);
91 void Fl_File_Chooser::cb_showHiddenButton_i(Fl_Check_Button*, void*) {
92 showHidden(showHiddenButton->value());
94 void Fl_File_Chooser::cb_showHiddenButton(Fl_Check_Button* o, void* v) {
95 ((Fl_File_Chooser*)(o->parent()->parent()->parent()->user_data()))->cb_showHiddenButton_i(o,v);
98 void Fl_File_Chooser::cb_fileName_i(Fl_File_Input*, void*) {
99 fileNameCB();
101 void Fl_File_Chooser::cb_fileName(Fl_File_Input* o, void* v) {
102 ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_fileName_i(o,v);
105 void Fl_File_Chooser::cb_okButton_i(Fl_Return_Button*, void*) {
106 window->hide();
108 // Do any callback that is registered...
109 if (callback_)
110 (*callback_)(this, data_);
112 void Fl_File_Chooser::cb_okButton(Fl_Return_Button* o, void* v) {
113 ((Fl_File_Chooser*)(o->parent()->parent()->parent()->user_data()))->cb_okButton_i(o,v);
116 void Fl_File_Chooser::cb_cancelButton_i(Fl_Button*, void*) {
117 fileName->value("");
118 fileList->deselect();
119 Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
120 window->hide();
122 void Fl_File_Chooser::cb_cancelButton(Fl_Button* o, void* v) {
123 ((Fl_File_Chooser*)(o->parent()->parent()->parent()->user_data()))->cb_cancelButton_i(o,v);
126 void Fl_File_Chooser::cb_favList_i(Fl_File_Browser*, void*) {
127 favoritesCB(favList);
129 void Fl_File_Chooser::cb_favList(Fl_File_Browser* o, void* v) {
130 ((Fl_File_Chooser*)(o->parent()->user_data()))->cb_favList_i(o,v);
133 void Fl_File_Chooser::cb_favUpButton_i(Fl_Button*, void*) {
134 favoritesCB(favUpButton);
136 void Fl_File_Chooser::cb_favUpButton(Fl_Button* o, void* v) {
137 ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_favUpButton_i(o,v);
140 void Fl_File_Chooser::cb_favDeleteButton_i(Fl_Button*, void*) {
141 favoritesCB(favDeleteButton);
143 void Fl_File_Chooser::cb_favDeleteButton(Fl_Button* o, void* v) {
144 ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_favDeleteButton_i(o,v);
147 void Fl_File_Chooser::cb_favDownButton_i(Fl_Button*, void*) {
148 favoritesCB(favDownButton);
150 void Fl_File_Chooser::cb_favDownButton(Fl_Button* o, void* v) {
151 ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_favDownButton_i(o,v);
154 void Fl_File_Chooser::cb_favCancelButton_i(Fl_Button*, void*) {
155 favWindow->hide();
157 void Fl_File_Chooser::cb_favCancelButton(Fl_Button* o, void* v) {
158 ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_favCancelButton_i(o,v);
161 void Fl_File_Chooser::cb_favOkButton_i(Fl_Return_Button*, void*) {
162 favoritesCB(favOkButton);
164 void Fl_File_Chooser::cb_favOkButton(Fl_Return_Button* o, void* v) {
165 ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_favOkButton_i(o,v);
168 Fl_File_Chooser::Fl_File_Chooser(const char *d, const char *p, int t, const char *title) {
169 Fl_Group *prev_current = Fl_Group::current();
170 { window = new Fl_Double_Window(490, 380, "Choose File");
171 window->callback((Fl_Callback*)cb_window, (void*)(this));
172 { Fl_Group* o = new Fl_Group(10, 10, 470, 25);
173 { showChoice = new Fl_Choice(65, 10, 215, 25, "Show:");
174 showChoice->down_box(FL_BORDER_BOX);
175 showChoice->labelfont(1);
176 showChoice->callback((Fl_Callback*)cb_showChoice);
177 Fl_Group::current()->resizable(showChoice);
178 showChoice->label(show_label);
179 } // Fl_Choice* showChoice
180 { favoritesButton = new Fl_Menu_Button(290, 10, 155, 25, "Favorites");
181 favoritesButton->down_box(FL_BORDER_BOX);
182 favoritesButton->callback((Fl_Callback*)cb_favoritesButton);
183 favoritesButton->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
184 favoritesButton->label(favorites_label);
185 } // Fl_Menu_Button* favoritesButton
186 { Fl_Button* o = newButton = new Fl_Button(455, 10, 25, 25);
187 newButton->image(image_new);
188 newButton->labelsize(8);
189 newButton->callback((Fl_Callback*)cb_newButton);
190 o->tooltip(new_directory_tooltip);
191 } // Fl_Button* newButton
192 o->end();
193 } // Fl_Group* o
194 { Fl_Tile* o = new Fl_Tile(10, 45, 470, 225);
195 o->callback((Fl_Callback*)cb_);
196 { fileList = new Fl_File_Browser(10, 45, 295, 225);
197 fileList->type(2);
198 fileList->callback((Fl_Callback*)cb_fileList);
199 fileList->window()->hotspot(fileList);
200 } // Fl_File_Browser* fileList
201 { previewBox = new Fl_Box(305, 45, 175, 225, "?");
202 previewBox->box(FL_DOWN_BOX);
203 previewBox->labelsize(100);
204 previewBox->align(Fl_Align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE));
205 } // Fl_Box* previewBox
206 o->end();
207 Fl_Group::current()->resizable(o);
208 } // Fl_Tile* o
209 { Fl_Group* o = new Fl_Group(10, 275, 470, 95);
210 { Fl_Group* o = new Fl_Group(10, 275, 470, 20);
211 { previewButton = new Fl_Check_Button(10, 275, 73, 20, "Preview");
212 previewButton->shortcut(0x80070);
213 previewButton->down_box(FL_DOWN_BOX);
214 previewButton->value(1);
215 previewButton->callback((Fl_Callback*)cb_previewButton);
216 previewButton->label(preview_label);
217 } // Fl_Check_Button* previewButton
218 { showHiddenButton = new Fl_Check_Button(115, 275, 165, 20, "Show hidden files");
219 showHiddenButton->down_box(FL_DOWN_BOX);
220 showHiddenButton->callback((Fl_Callback*)cb_showHiddenButton);
221 showHiddenButton->label(hidden_label);
222 } // Fl_Check_Button* showHiddenButton
223 { Fl_Box* o = new Fl_Box(115, 275, 365, 20);
224 Fl_Group::current()->resizable(o);
225 } // Fl_Box* o
226 o->end();
227 } // Fl_Group* o
228 { fileName = new Fl_File_Input(115, 300, 365, 35);
229 fileName->labelfont(1);
230 fileName->callback((Fl_Callback*)cb_fileName);
231 fileName->when(FL_WHEN_ENTER_KEY);
232 Fl_Group::current()->resizable(fileName);
233 fileName->when(FL_WHEN_CHANGED | FL_WHEN_ENTER_KEY);
234 } // Fl_File_Input* fileName
235 { Fl_Box* o = new Fl_Box(10, 310, 105, 25, "Filename:");
236 o->labelfont(1);
237 o->align(Fl_Align(FL_ALIGN_RIGHT|FL_ALIGN_INSIDE));
238 o->label(filename_label);
239 } // Fl_Box* o
240 { Fl_Group* o = new Fl_Group(10, 345, 470, 25);
241 { okButton = new Fl_Return_Button(313, 345, 85, 25, "OK");
242 okButton->callback((Fl_Callback*)cb_okButton);
243 okButton->label(fl_ok);
244 } // Fl_Return_Button* okButton
245 { Fl_Button* o = cancelButton = new Fl_Button(408, 345, 72, 25, "Cancel");
246 cancelButton->callback((Fl_Callback*)cb_cancelButton);
247 o->label(fl_cancel);
248 } // Fl_Button* cancelButton
249 { Fl_Box* o = new Fl_Box(10, 345, 30, 25);
250 Fl_Group::current()->resizable(o);
251 } // Fl_Box* o
252 o->end();
253 } // Fl_Group* o
254 o->end();
255 } // Fl_Group* o
256 if (title) window->label(title);
257 window->set_modal();
258 window->end();
259 } // Fl_Double_Window* window
260 { favWindow = new Fl_Double_Window(355, 150, "Manage Favorites");
261 favWindow->user_data((void*)(this));
262 { favList = new Fl_File_Browser(10, 10, 300, 95);
263 favList->type(2);
264 favList->callback((Fl_Callback*)cb_favList);
265 Fl_Group::current()->resizable(favList);
266 } // Fl_File_Browser* favList
267 { Fl_Group* o = new Fl_Group(320, 10, 25, 95);
268 { favUpButton = new Fl_Button(320, 10, 25, 25, "@8>");
269 favUpButton->callback((Fl_Callback*)cb_favUpButton);
270 } // Fl_Button* favUpButton
271 { favDeleteButton = new Fl_Button(320, 45, 25, 25, "X");
272 favDeleteButton->labelfont(1);
273 favDeleteButton->callback((Fl_Callback*)cb_favDeleteButton);
274 Fl_Group::current()->resizable(favDeleteButton);
275 } // Fl_Button* favDeleteButton
276 { favDownButton = new Fl_Button(320, 80, 25, 25, "@2>");
277 favDownButton->callback((Fl_Callback*)cb_favDownButton);
278 } // Fl_Button* favDownButton
279 o->end();
280 } // Fl_Group* o
281 { Fl_Group* o = new Fl_Group(10, 113, 335, 29);
282 { favCancelButton = new Fl_Button(273, 115, 72, 25, "Cancel");
283 favCancelButton->callback((Fl_Callback*)cb_favCancelButton);
284 favCancelButton->label(fl_cancel);
285 } // Fl_Button* favCancelButton
286 { favOkButton = new Fl_Return_Button(181, 115, 79, 25, "Save");
287 favOkButton->callback((Fl_Callback*)cb_favOkButton);
288 favOkButton->label(save_label);
289 } // Fl_Return_Button* favOkButton
290 { Fl_Box* o = new Fl_Box(10, 115, 161, 25);
291 Fl_Group::current()->resizable(o);
292 } // Fl_Box* o
293 o->end();
294 } // Fl_Group* o
295 favWindow->label(manage_favorites_label);
296 favWindow->set_modal();
297 favWindow->size_range(181, 150);
298 favWindow->end();
299 } // Fl_Double_Window* favWindow
300 callback_ = 0;
301 data_ = 0;
302 directory_[0] = 0;
303 window->size_range(window->w(), window->h(), Fl::w(), Fl::h());
304 type(t);
305 filter(p);
306 update_favorites();
307 value(d);
308 type(t);
309 int e;
310 prefs_.get("preview", e, 1);
311 preview(e);
312 Fl_Group::current(prev_current);
313 ext_group=(Fl_Widget*)0;
316 Fl_File_Chooser::~Fl_File_Chooser() {
317 Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
318 if(ext_group)window->remove(ext_group);
319 delete window;
320 delete favWindow;
323 void Fl_File_Chooser::callback(void (*cb)(Fl_File_Chooser *, void *), void *d ) {
324 callback_ = cb;
325 data_ = d;
328 void Fl_File_Chooser::color(Fl_Color c) {
329 fileList->color(c);
332 Fl_Color Fl_File_Chooser::color() {
333 return (fileList->color());
336 char * Fl_File_Chooser::directory() {
337 return directory_;
340 const char * Fl_File_Chooser::filter() {
341 return (fileList->filter());
344 int Fl_File_Chooser::filter_value() {
345 return showChoice->value();
348 void Fl_File_Chooser::filter_value(int f) {
349 showChoice->value(f);
350 showChoiceCB();
353 void Fl_File_Chooser::hide() {
354 window->hide();
357 void Fl_File_Chooser::iconsize(uchar s) {
358 fileList->iconsize(s);
361 uchar Fl_File_Chooser::iconsize() {
362 return (fileList->iconsize());
365 void Fl_File_Chooser::label(const char *l) {
366 window->label(l);
369 const char * Fl_File_Chooser::label() {
370 return (window->label());
373 void Fl_File_Chooser::ok_label(const char *l) {
374 okButton->label(l);
375 int w=0, h=0;
376 okButton->measure_label(w, h);
377 okButton->resize(cancelButton->x() - 50 - w, cancelButton->y(),
378 w + 40, 25);
379 okButton->parent()->init_sizes();
382 const char * Fl_File_Chooser::ok_label() {
383 return (okButton->label());
386 int Fl_File_Chooser::shown() {
387 return window->shown();
390 void Fl_File_Chooser::textcolor(Fl_Color c) {
391 fileList->textcolor(c);
394 Fl_Color Fl_File_Chooser::textcolor() {
395 return (fileList->textcolor());
398 void Fl_File_Chooser::textfont(Fl_Font f) {
399 fileList->textfont(f);
402 Fl_Font Fl_File_Chooser::textfont() {
403 return (fileList->textfont());
406 void Fl_File_Chooser::textsize(Fl_Fontsize s) {
407 fileList->textsize(s);
410 Fl_Fontsize Fl_File_Chooser::textsize() {
411 return (fileList->textsize());
414 void Fl_File_Chooser::type(int t) {
415 type_ = t;
416 if (t & MULTI)
417 fileList->type(FL_MULTI_BROWSER);
418 else
419 fileList->type(FL_HOLD_BROWSER);
420 if (t & CREATE)
421 newButton->activate();
422 else
423 newButton->deactivate();
424 if (t & DIRECTORY)
425 fileList->filetype(Fl_File_Browser::DIRECTORIES);
426 else
427 fileList->filetype(Fl_File_Browser::FILES);
430 int Fl_File_Chooser::type() {
431 return (type_);
434 void * Fl_File_Chooser::user_data() const {
435 return (data_);
438 void Fl_File_Chooser::user_data(void *d) {
439 data_ = d;
442 int Fl_File_Chooser::visible() {
443 return window->visible();
446 Fl_Widget* Fl_File_Chooser::add_extra(Fl_Widget* gr) {
447 Fl_Widget* ret=ext_group;
448 if (gr==ext_group) {
449 return ret;
451 if (ext_group) {
452 int sh=ext_group->h()+4;
453 Fl_Widget* svres=window->resizable();
454 window->resizable(NULL);
455 window->size(window->w(),window->h()-sh);
456 window->remove(ext_group);
457 ext_group=NULL;
458 window->resizable(svres);
460 if (gr) {
461 int nh=window->h()+gr->h()+4;
462 Fl_Widget* svres=window->resizable();
463 window->resizable(NULL);
464 window->size(window->w(),nh);
465 gr->position(2,okButton->y()+okButton->h()+2);
466 window->add(gr);
467 ext_group=gr;
468 window->resizable(svres);
470 return ret;
474 // End of "$Id: Fl_File_Chooser.cxx 8786 2011-06-07 11:41:36Z manolo $".