diff --git a/FL/Fl_FileChooser.H b/FL/Fl_FileChooser.H index bef45d128..5e594111c 100644 --- a/FL/Fl_FileChooser.H +++ b/FL/Fl_FileChooser.H @@ -10,9 +10,9 @@ #include #include #include +#include #include #include -#include class Fl_FileChooser { public: diff --git a/FL/fl_file_chooser.H b/FL/fl_file_chooser.H index aa079975f..d7068d416 100644 --- a/FL/fl_file_chooser.H +++ b/FL/fl_file_chooser.H @@ -1,5 +1,5 @@ // -// "$Id: fl_file_chooser.H,v 1.5.2.3 2001/01/22 15:13:38 easysw Exp $" +// "$Id: fl_file_chooser.H,v 1.5.2.3.2.1 2001/08/03 18:46:57 easysw Exp $" // // File chooser header file for the Fast Light Tool Kit (FLTK). // @@ -29,10 +29,9 @@ #include "Enumerations.H" FL_EXPORT char *fl_file_chooser(const char *message,const char *pat,const char *fname); -FL_EXPORT void fl_file_chooser_callback(void (*cb)(const char *)); #endif // -// End of "$Id: fl_file_chooser.H,v 1.5.2.3 2001/01/22 15:13:38 easysw Exp $". +// End of "$Id: fl_file_chooser.H,v 1.5.2.3.2.1 2001/08/03 18:46:57 easysw Exp $". // diff --git a/src/Fl_FileBrowser.cxx b/src/Fl_FileBrowser.cxx index bf0534b89..c50a5b694 100644 --- a/src/Fl_FileBrowser.cxx +++ b/src/Fl_FileBrowser.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_FileBrowser.cxx,v 1.13.2.1 2001/08/02 16:17:04 easysw Exp $" +// "$Id: Fl_FileBrowser.cxx,v 1.13.2.2 2001/08/03 18:46:57 easysw Exp $" // // Fl_FileBrowser routines. // @@ -237,11 +237,11 @@ Fl_FileBrowser::item_width(void *p) const // I - List item data // void -Fl_FileBrowser::item_draw(void *p, // I - List item data - int x, // I - Upper-lefthand X coordinate - int y, // I - Upper-lefthand Y coordinate - int w, // I - Width of item - int h) const // I - Height of item +Fl_FileBrowser::item_draw(void *p, // I - List item data + int x, // I - Upper-lefthand X coordinate + int y, // I - Upper-lefthand Y coordinate + int w, // I - Width of item + int h) const // I - Height of item { int i; // Looping var FL_BLINE *line; // Pointer to line @@ -260,7 +260,10 @@ Fl_FileBrowser::item_draw(void *p, // I - List item data // Draw the list item text... line = (FL_BLINE *)p; - fl_font(textfont(), textsize()); + if (line->txt[strlen(line->txt) - 1] == '/') + fl_font(textfont() | FL_BOLD, textsize()); + else + fl_font(textfont(), textsize()); if (line->flags & SELECTED) c = contrast(textcolor(), selection_color()); @@ -278,16 +281,15 @@ Fl_FileBrowser::item_draw(void *p, // I - List item data // Draw the icon if it is set... if (line->data) ((Fl_FileIcon *)line->data)->draw(x, y, iconsize_, iconsize_, - (line->flags & SELECTED) ? FL_YELLOW : - FL_LIGHT2, - active_r()); + (line->flags & SELECTED) ? FL_YELLOW : + FL_LIGHT2, + active_r()); // Draw the text offset to the right... x += iconsize_ + 9; w -= iconsize_ - 10; // Center the text vertically... - line = (FL_BLINE *)p; height = fl_height(); for (text = line->txt; *text != '\0'; text ++) @@ -385,6 +387,7 @@ Fl_FileBrowser::load(const char *directory)// I - Directory to load { int i; // Looping var int num_files; // Number of files in directory + int num_dirs; // Number of directories in list char filename[4096]; // Current file Fl_FileIcon *icon; // Icon to use @@ -413,7 +416,7 @@ Fl_FileBrowser::load(const char *directory)// I - Directory to load for (i = 'A'; i <= 'Z'; i ++, drives >>= 1) if (drives & 1) { - sprintf(filename, "%c:", i); + sprintf(filename, "%c:/", i); if (i < 'C') add(filename, icon); @@ -433,7 +436,7 @@ Fl_FileBrowser::load(const char *directory)// I - Directory to load for (i = 'A'; i <= 'Z'; i ++, drives >>= 1) if (drives & 1) { - sprintf(filename, "%c:", i); + sprintf(filename, "%c:/", i); add(filename, icon); num_files ++; @@ -465,6 +468,8 @@ Fl_FileBrowser::load(const char *directory)// I - Directory to load if (sscanf(line, "%*s%4095s", filename) != 1) continue; + strncat(filename, "/", sizeof(filename) - 1); + // printf("Fl_FileBrowser::load() - adding \"%s\" to list...\n", filename); add(filename, icon); num_files ++; @@ -502,15 +507,24 @@ Fl_FileBrowser::load(const char *directory)// I - Directory to load if (num_files <= 0) return (0); - for (i = 0; i < num_files; i ++) + for (i = 0, num_dirs = 0; i < num_files; i ++) { if (strcmp(files[i]->d_name, ".") != 0 && strcmp(files[i]->d_name, "..") != 0) { - sprintf(filename, "%s/%s", directory_, files[i]->d_name); + snprintf(filename, sizeof(filename), "%s/%s", directory_, + files[i]->d_name); - if (filename_isdir(filename) || - filename_match(files[i]->d_name, pattern_)) + if (filename_isdir(filename)) + { + char name[1024]; // Temporary directory name + + snprintf(name, sizeof(name), "%s/", files[i]->d_name); + + num_dirs ++; + insert(num_dirs, name, Fl_FileIcon::find(filename)); + } + else if (filename_match(files[i]->d_name, pattern_)) add(files[i]->d_name, Fl_FileIcon::find(filename)); } @@ -543,5 +557,5 @@ Fl_FileBrowser::filter(const char *pattern) // I - Pattern string // -// End of "$Id: Fl_FileBrowser.cxx,v 1.13.2.1 2001/08/02 16:17:04 easysw Exp $". +// End of "$Id: Fl_FileBrowser.cxx,v 1.13.2.2 2001/08/03 18:46:57 easysw Exp $". // diff --git a/src/Fl_FileChooser.cxx b/src/Fl_FileChooser.cxx index ffba23d5d..08f124ca3 100644 --- a/src/Fl_FileChooser.cxx +++ b/src/Fl_FileChooser.cxx @@ -104,16 +104,17 @@ Fl_FileChooser::Fl_FileChooser(const char *d, const char *p, int t, const char * w->hotspot(o); { Fl_FileBrowser* o = fileList = new Fl_FileBrowser(10, 45, 355, 180); o->type(2); - o->when(FL_WHEN_RELEASE_ALWAYS); o->callback((Fl_Callback*)cb_fileList); Fl_Group::current()->resizable(o); w->hotspot(o); } { Fl_Button* o = new Fl_Button(285, 280, 80, 25, "Cancel"); o->callback((Fl_Callback*)cb_Cancel); + o->label(fl_cancel); } - { Fl_Return_Button* o = okButton = new Fl_Return_Button(205, 280, 75, 25, "OK"); + { Fl_Return_Button* o = okButton = new Fl_Return_Button(200, 280, 75, 25, "OK"); o->callback((Fl_Callback*)cb_okButton); + okButton->label(fl_ok); } { Fl_Input* o = fileName = new Fl_Input(10, 245, 355, 25, "Filename:"); o->callback((Fl_Callback*)cb_fileName); diff --git a/src/Fl_FileChooser.fl b/src/Fl_FileChooser.fl index 0ac411656..0074a9c1a 100644 --- a/src/Fl_FileChooser.fl +++ b/src/Fl_FileChooser.fl @@ -23,7 +23,7 @@ window->hide();} open code3 {\#include } modal visible } { Fl_Browser fileList { - callback {fileListCB();} selected + callback {fileListCB();} private xywh {10 45 355 180} type Hold resizable hotspot code0 {\#include } class Fl_FileBrowser @@ -32,13 +32,16 @@ window->hide();} open label Cancel callback {fileList->deselect(); fileName->value(""); -window->hide();} +window->hide();} selected private xywh {285 280 80 25} + code0 {o->label(fl_cancel);} } Fl_Return_Button okButton { label OK callback {window->hide();} - private xywh {205 280 75 25} + private xywh {200 280 75 25} + code0 {\#include } + code1 {okButton->label(fl_ok);} } Fl_Input fileName { label {Filename:} diff --git a/src/fl_file_chooser.cxx b/src/fl_file_chooser.cxx index d53adc7d8..8f6a37548 100644 --- a/src/fl_file_chooser.cxx +++ b/src/fl_file_chooser.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_file_chooser.cxx,v 1.10.2.10.2.2 2001/08/03 15:48:20 easysw Exp $" +// "$Id: fl_file_chooser.cxx,v 1.10.2.10.2.3 2001/08/03 18:46:57 easysw Exp $" // // File chooser widget for the Fast Light Tool Kit (FLTK). // @@ -29,12 +29,6 @@ static Fl_FileChooser *fc = (Fl_FileChooser *)0; -static void default_callback(const char*) {} -static void (*current_callback)(const char*) = default_callback; -void fl_file_chooser_callback(void (*cb)(const char*)) { - current_callback = cb ? cb : default_callback; -} - char* fl_file_chooser(const char* message, const char* pat, const char* fname) { if (!fname || !*fname) fname = "."; @@ -56,5 +50,5 @@ char* fl_file_chooser(const char* message, const char* pat, const char* fname) // -// End of "$Id: fl_file_chooser.cxx,v 1.10.2.10.2.2 2001/08/03 15:48:20 easysw Exp $". +// End of "$Id: fl_file_chooser.cxx,v 1.10.2.10.2.3 2001/08/03 18:46:57 easysw Exp $". // diff --git a/test/file_chooser.cxx b/test/file_chooser.cxx index 2da1d1f56..cafb2e8d7 100644 --- a/test/file_chooser.cxx +++ b/test/file_chooser.cxx @@ -1,5 +1,5 @@ // -// "$Id: file_chooser.cxx,v 1.4.2.3 2001/01/22 15:13:41 easysw Exp $" +// "$Id: file_chooser.cxx,v 1.4.2.3.2.1 2001/08/03 18:46:57 easysw Exp $" // // File chooser test program for the Fast Light Tool Kit (FLTK). // @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -41,23 +42,19 @@ void pickfile(Fl_Widget *) { if (p) current->value(p); } -void thecb(const char *name) { - printf("Callback '%s'\n",name); -} - int main(int argc, char **argv) { - Fl_Window window(400,200); - pattern = new Fl_Input(100,50,280,30,"Pattern:"); + Fl_FileIcon::load_system_icons(); + Fl_Window window(310,110); + pattern = new Fl_Input(100,10,200,25,"Pattern:"); pattern->static_value("*"); - current = new Fl_Input(100,90,280,30,"Current:"); - Fl_Button button(100,120,100,30,"&Choose file"); + current = new Fl_Input(100,40,200,25,"Current:"); + Fl_Button button(200,75,100,25,"&Choose file"); button.callback(pickfile); window.end(); window.show(argc, argv); - fl_file_chooser_callback(thecb); return Fl::run(); } // -// End of "$Id: file_chooser.cxx,v 1.4.2.3 2001/01/22 15:13:41 easysw Exp $". +// End of "$Id: file_chooser.cxx,v 1.4.2.3.2.1 2001/08/03 18:46:57 easysw Exp $". //