diff --git a/FL/Enumerations.H b/FL/Enumerations.H index fb0a2aab5..51574fd79 100644 --- a/FL/Enumerations.H +++ b/FL/Enumerations.H @@ -1,5 +1,5 @@ // -// "$Id: Enumerations.H,v 1.18.2.14.2.1 2001/08/01 21:24:48 easysw Exp $" +// "$Id: Enumerations.H,v 1.18.2.14.2.2 2001/08/02 16:17:04 easysw Exp $" // // Enumerations for the Fast Light Tool Kit (FLTK). // @@ -212,6 +212,8 @@ enum Fl_Labeltype { // labeltypes: _FL_PIXMAP_LABEL, _FL_IMAGE_LABEL, _FL_MULTI_LABEL, + _FL_ICON_LABEL, + FL_FREE_LABELTYPE }; extern Fl_Labeltype FL_EXPORT define_FL_SYMBOL_LABEL(); @@ -372,5 +374,5 @@ enum Fl_Damage { #endif // -// End of "$Id: Enumerations.H,v 1.18.2.14.2.1 2001/08/01 21:24:48 easysw Exp $". +// End of "$Id: Enumerations.H,v 1.18.2.14.2.2 2001/08/02 16:17:04 easysw Exp $". // diff --git a/FL/Fl_FileBrowser.H b/FL/Fl_FileBrowser.H index 4b3f2bd11..b0cc38432 100644 --- a/FL/Fl_FileBrowser.H +++ b/FL/Fl_FileBrowser.H @@ -1,9 +1,9 @@ // -// "$Id: Fl_FileBrowser.H,v 1.4 2000/01/16 07:44:20 robertk Exp $" +// "$Id: Fl_FileBrowser.H,v 1.4.2.1 2001/08/02 16:17:04 easysw Exp $" // -// Fl_FileBrowser definitions for the Fast Light Tool Kit (FLTK). +// FileBrowser definitions. // -// Copyright 1997-1999 by Easy Software Products. +// Copyright 1999-2001 by Michael Sweet. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -20,30 +20,31 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // USA. // -// Please report all bugs and problems to "fltk-bugs@easysw.com". +// Please report all bugs and problems to "fltk-bugs@fltk.org". // // // Include necessary header files... // -#ifndef _FL_FILEBROWSER_H_ -# define _FL_FILEBROWSER_H_ +#ifndef _Fl_FileBrowser_H_ +# define _Fl_FileBrowser_H_ -# include -# include +# include "Fl_Browser.H" +# include "Fl_FileIcon.H" // // Fl_FileBrowser class... // -class FL_API Fl_FileBrowser : public Fl_Browser +class Fl_FileBrowser : public Fl_Browser { const char *directory_; uchar iconsize_; const char *pattern_; + int full_height() const; int item_height(void *) const; int item_width(void *) const; void item_draw(void *, int, int, int, int) const; @@ -55,26 +56,18 @@ public: uchar iconsize() const { return (iconsize_); }; void iconsize(uchar s) { iconsize_ = s; redraw(); }; - void directory(const char *directory) { load(directory); } - const char *directory(void) const { return (directory_); } - void filter(const char *pattern); const char *filter() const { return (pattern_); }; int load(const char *directory); -#ifdef FLTK_2 - unsigned textsize() const { return (Fl_Browser::text_size()); }; - void textsize(unsigned s) { Fl_Browser::text_size(s); }; -#else uchar textsize() const { return (Fl_Browser::textsize()); }; - void textsize(uchar s) { Fl_Browser::textsize(s); }; -#endif + void textsize(uchar s) { Fl_Browser::textsize(s); iconsize_ = 3 * s / 2; }; }; -#endif // !_FL_FILEBROWSER_H_ +#endif // !_Fl_FileBrowser_H_ // -// End of "$Id: Fl_FileBrowser.H,v 1.4 2000/01/16 07:44:20 robertk Exp $". +// End of "$Id: Fl_FileBrowser.H,v 1.4.2.1 2001/08/02 16:17:04 easysw Exp $". // diff --git a/FL/Fl_FileChooser.H b/FL/Fl_FileChooser.H index 81790510b..bef45d128 100644 --- a/FL/Fl_FileChooser.H +++ b/FL/Fl_FileChooser.H @@ -1,49 +1,49 @@ -// generated by Fast Light User Interface Designer (fluid) version 2.0000 +// generated by Fast Light User Interface Designer (fluid) version 1.0100 -#ifndef Fl_FileChooser_h -#define Fl_FileChooser_h +#ifndef Fl_FileChooser_H +#define Fl_FileChooser_H #include #include #include #include #include -#include -#include -#include "filename.H" #include -#include +#include #include +#include +#include +#include -class FL_API Fl_FileChooser { +class Fl_FileChooser { public: enum { SINGLE, MULTI, CREATE }; Fl_FileChooser(const char *d, const char *p, int t, const char *title); - Fl_Window *window; private: + Fl_Window *window; inline void cb_window_i(Fl_Window*, void*); static void cb_window(Fl_Window*, void*); - Fl_Choice *dirMenu; - inline void cb_dirMenu_i(Fl_Choice*, void*); - static void cb_dirMenu(Fl_Choice*, void*); + Fl_FileBrowser *fileList; + inline void cb_fileList_i(Fl_FileBrowser*, void*); + static void cb_fileList(Fl_FileBrowser*, void*); + inline void cb_Cancel_i(Fl_Button*, void*); + static void cb_Cancel(Fl_Button*, void*); + Fl_Return_Button *okButton; + inline void cb_okButton_i(Fl_Return_Button*, void*); + static void cb_okButton(Fl_Return_Button*, void*); + Fl_Input *fileName; + inline void cb_fileName_i(Fl_Input*, void*); + static void cb_fileName(Fl_Input*, void*); Fl_Button *upButton; inline void cb_upButton_i(Fl_Button*, void*); static void cb_upButton(Fl_Button*, void*); Fl_Button *newButton; inline void cb_newButton_i(Fl_Button*, void*); static void cb_newButton(Fl_Button*, void*); - inline void cb__i(Fl_Button*, void*); - static void cb_(Fl_Button*, void*); - Fl_FileBrowser *fileList; - inline void cb_fileList_i(Fl_FileBrowser*, void*); - static void cb_fileList(Fl_FileBrowser*, void*); - Fl_FileInput *fileName; - inline void cb_fileName_i(Fl_FileInput*, void*); - static void cb_fileName(Fl_FileInput*, void*); - Fl_Return_Button *okButton; - inline void cb_okButton_i(Fl_Return_Button*, void*); - static void cb_okButton(Fl_Return_Button*, void*); - inline void cb_Cancel_i(Fl_Button*, void*); - static void cb_Cancel(Fl_Button*, void*); + Fl_Choice *dirMenu; + inline void cb_dirMenu_i(Fl_Choice*, void*); + static void cb_dirMenu(Fl_Choice*, void*); + inline void cb_allfiles_i(Fl_Button*, void*); + static void cb_allfiles(Fl_Button*, void*); char directory_[1024]; int type_; void fileListCB(); @@ -56,7 +56,6 @@ public: int count(); void directory(const char *d); char * directory(); - void exec(); void filter(const char *p); const char * filter(); void hide(); @@ -65,10 +64,11 @@ public: void label(const char *l); const char * label(); void rescan(); + void show(); void textcolor(Fl_Color c); Fl_Color textcolor(); - void textfont(Fl_Font f); - Fl_Font textfont(); + void textfont(uchar f); + uchar textfont(); void textsize(uchar s); uchar textsize(); void type(int t); diff --git a/FL/Fl_FileIcon.H b/FL/Fl_FileIcon.H index 6df0f7d54..ae777b969 100644 --- a/FL/Fl_FileIcon.H +++ b/FL/Fl_FileIcon.H @@ -1,9 +1,9 @@ // -// "$Id: Fl_FileIcon.H,v 1.1 2000/01/08 22:14:13 vincent Exp $" +// "$Id: Fl_FileIcon.H,v 1.1.2.1 2001/08/02 16:17:04 easysw Exp $" // -// Fl_FileIcon definitions for the Fast Light Tool Kit (FLTK). +// Fl_FileIcon definitions. // -// Copyright 1997-1999 by Easy Software Products. +// Copyright 1999-2001 by Michael Sweet. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -20,24 +20,24 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // USA. // -// Please report all bugs and problems to "fltk-bugs@easysw.com". +// Please report all bugs and problems to "fltk-bugs@fltk.org". // // // Include necessary header files... // -#ifndef _FL_FILEICON_H_ -# define _FL_FILEICON_H_ +#ifndef _Fl_Fl_FileIcon_H_ +# define _Fl_Fl_FileIcon_H_ -# include +# include "Fl.H" // // Fl_FileIcon class... // -class FL_API Fl_FileIcon //// Icon data +class Fl_FileIcon //// Icon data { static Fl_FileIcon *first_; // Pointer to first icon/filetype Fl_FileIcon *next_; // Pointer to next icon/filetype @@ -56,7 +56,7 @@ class FL_API Fl_FileIcon //// Icon data FIFO, // Only named pipes DEVICE, // Only character and block devices LINK, // Only symbolic links - DIR // Only directories + DIRECTORY // Only directories }; enum // Data opcodes @@ -84,7 +84,7 @@ class FL_API Fl_FileIcon //// Icon data void clear() { num_data_ = 0; } void draw(int x, int y, int w, int h, Fl_Color ic, int active = 1); void label(Fl_Widget *w); -// static void labeltype(const Fl_Label *o, int x, int y, int w, int h, Fl_Align a); + static void labeltype(const Fl_Label *o, int x, int y, int w, int h, Fl_Align a); void load(const char *f); void load_fti(const char *fti); void load_xpm(const char *xpm); @@ -98,10 +98,8 @@ class FL_API Fl_FileIcon //// Icon data static void load_system_icons(void); }; -//#define _FL_ICON_LABEL FL_FREE_LABELTYPE - -#endif // !_FL_FILEICON_H_ +#endif // !_Fl_Fl_FileIcon_H_ // -// End of "$Id: Fl_FileIcon.H,v 1.1 2000/01/08 22:14:13 vincent Exp $". +// End of "$Id: Fl_FileIcon.H,v 1.1.2.1 2001/08/02 16:17:04 easysw Exp $". // diff --git a/fluid/code.cxx b/fluid/code.cxx index 0d6975746..f523ec085 100644 --- a/fluid/code.cxx +++ b/fluid/code.cxx @@ -1,5 +1,5 @@ // -// "$Id: code.cxx,v 1.9.2.9 2001/01/22 15:13:39 easysw Exp $" +// "$Id: code.cxx,v 1.9.2.9.2.1 2001/08/02 16:17:04 easysw Exp $" // // Code output routines for the Fast Light Tool Kit (FLTK). // @@ -254,6 +254,8 @@ static Fl_Type* write_code(Fl_Type* p) { return q; } +extern const char* header_file_name; + int write_code(const char *s, const char *t) { write_number++; delete id_root; id_root = 0; @@ -303,8 +305,13 @@ int write_code(const char *s, const char *t) { } } } - if (t && include_H_from_C) - write_c("#include \"%s\"\n", filename_name(t)); + if (t && include_H_from_C) { + if (*header_file_name == '.' && strchr(header_file_name, '/') == NULL) { + write_c("#include \"%s\"\n", filename_name(t)); + } else { + write_c("#include \"%s\"\n", t); + } + } for (Fl_Type* p = Fl_Type::first; p;) { // write all static data for this & all children first p->write_static(); @@ -405,5 +412,5 @@ void Fl_Type::write_code1() { void Fl_Type::write_code2() {} // -// End of "$Id: code.cxx,v 1.9.2.9 2001/01/22 15:13:39 easysw Exp $". +// End of "$Id: code.cxx,v 1.9.2.9.2.1 2001/08/02 16:17:04 easysw Exp $". // diff --git a/fluid/fluid.cxx b/fluid/fluid.cxx index 7c359b078..b1f317f6b 100644 --- a/fluid/fluid.cxx +++ b/fluid/fluid.cxx @@ -1,5 +1,5 @@ // -// "$Id: fluid.cxx,v 1.15.2.13 2001/03/15 22:39:56 easysw Exp $" +// "$Id: fluid.cxx,v 1.15.2.13.2.1 2001/08/02 16:17:04 easysw Exp $" // // FLUID main entry for the Fast Light Tool Kit (FLTK). // @@ -181,13 +181,13 @@ void write_cb(Fl_Widget *, void *) { char hname[1024]; strcpy(i18n_program, filename_name(filename)); filename_setext(i18n_program, ""); - if (*code_file_name == '.') { + if (*code_file_name == '.' && strchr(code_file_name, '/') == NULL) { strcpy(cname,filename_name(filename)); filename_setext(cname, code_file_name); } else { strcpy(cname, code_file_name); } - if (*header_file_name == '.') { + if (*header_file_name == '.' && strchr(header_file_name, '/') == NULL) { strcpy(hname,filename_name(filename)); filename_setext(hname, header_file_name); } else { @@ -196,7 +196,7 @@ void write_cb(Fl_Widget *, void *) { if (!compile_only) goto_source_dir(); int x = write_code(cname,hname); if (!compile_only) leave_source_dir(); - strcat(cname, "/"); strcat(cname,header_file_name); + strcat(cname, " and "); strcat(cname,hname); if (compile_only) { if (!x) {fprintf(stderr,"%s : %s\n",cname,strerror(errno)); exit(1);} } else { @@ -474,5 +474,5 @@ int main(int argc,char **argv) { } // -// End of "$Id: fluid.cxx,v 1.15.2.13 2001/03/15 22:39:56 easysw Exp $". +// End of "$Id: fluid.cxx,v 1.15.2.13.2.1 2001/08/02 16:17:04 easysw Exp $". // diff --git a/src/Fl_FileBrowser.cxx b/src/Fl_FileBrowser.cxx index 610837efb..bf0534b89 100644 --- a/src/Fl_FileBrowser.cxx +++ b/src/Fl_FileBrowser.cxx @@ -1,9 +1,9 @@ // -// "$Id: Fl_FileBrowser.cxx,v 1.13 2001/07/29 22:04:43 spitzak Exp $" +// "$Id: Fl_FileBrowser.cxx,v 1.13.2.1 2001/08/02 16:17:04 easysw Exp $" // -// Fl_FileBrowser routines for the Fast Light Tool Kit (FLTK). +// Fl_FileBrowser routines. // -// Copyright 1997-1999 by Easy Software Products. +// Copyright 1999-2001 by Michael Sweet. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -20,33 +20,34 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // USA. // -// Please report all bugs and problems to "fltk-bugs@easysw.com". +// Please report all bugs and problems to "fltk-bugs@fltk.org". // // Contents: // -// Fl_Fl_FileBrowser::item_width() - Return the width of a list item. -// Fl_Fl_FileBrowser::item_draw() - Draw a list item. -// Fl_Fl_FileBrowser::FileBrowser() - Create a FileBrowser widget. -// Fl_Fl_FileBrowser::load() - Load a directory into the browser. -// Fl_Fl_FileBrowser::filter() - Set the filename filter. +// Fl_FileBrowser::full_height() - Return the height of the list. +// Fl_FileBrowser::item_height() - Return the height of a list item. +// Fl_FileBrowser::item_width() - Return the width of a list item. +// Fl_FileBrowser::item_draw() - Draw a list item. +// Fl_FileBrowser::Fl_FileBrowser() - Create a Fl_FileBrowser widget. +// Fl_FileBrowser::load() - Load a directory into the browser. +// Fl_FileBrowser::filter() - Set the filename filter. // // // Include necessary header files... // -#include -#include -#include -#include +#include +#include +#include +#include #include -#include #include -#if defined(_WIN32) +#if defined(WIN32) # include # include -#endif /* _WIN32 */ +#endif /* WIN32 */ #if defined(__EMX__) #define INCL_DOS @@ -54,6 +55,7 @@ #include #endif /* __EMX__ */ + // // FL_BLINE definition from "Fl_Browser.cxx"... // @@ -72,6 +74,24 @@ struct FL_BLINE // data is in a linked list of these }; +// +// 'Fl_FileBrowser::full_height()' - Return the height of the list. +// + +int // O - Height in pixels +Fl_FileBrowser::full_height() const +{ + int i, // Looping var + th; // Total height of list. + + + for (i = 0, th = 0; i < size(); i ++) + th += item_height(find_line(i)); + + return (th); +} + + // // 'Fl_FileBrowser::item_height()' - Return the height of a list item. // @@ -86,7 +106,8 @@ Fl_FileBrowser::item_height(void *p) const // I - List item data // Figure out the standard text height... - textheight = fl_height(textfont(), textsize())+leading(); + fl_font(textfont(), textsize()); + textheight = fl_height(); // We always have at least 1 line... height = textheight; @@ -118,6 +139,7 @@ Fl_FileBrowser::item_height(void *p) const // I - List item data int // O - Width in pixels Fl_FileBrowser::item_width(void *p) const // I - List item data { + int i; // Looping var FL_BLINE *line; // Pointer to line char *text, // Pointer into text *ptr, // Pointer into fragment @@ -125,19 +147,21 @@ Fl_FileBrowser::item_width(void *p) const // I - List item data int width, // Width of line tempwidth; // Width of fragment int column; // Current column + const int *columns; // Columns // Set the font and size... - fl_font(text_font(), text_size()); + fl_font(textfont(), textsize()); // Scan for newlines... - line = (FL_BLINE *)p; + line = (FL_BLINE *)p; + columns = column_widths(); if (strchr(line->txt, '\n') == NULL && - strchr(line->txt, '\t') == NULL) + strchr(line->txt, column_char()) == NULL) { // Do a fast width calculation... - width = fl_width(line->txt); + width = (int)fl_width(line->txt); } else { @@ -152,7 +176,7 @@ Fl_FileBrowser::item_width(void *p) const // I - List item data // Newline - nul terminate this fragment and get the width... *ptr = '\0'; - tempwidth += fl_width(fragment); + tempwidth += (int)fl_width(fragment); // Update the max width as needed... if (tempwidth > width) @@ -161,12 +185,19 @@ Fl_FileBrowser::item_width(void *p) const // I - List item data // Point back to the start of the fragment... ptr = fragment; tempwidth = 0; + column = 0; } - else if (*text == '\t') + else if (*text == column_char()) { // Advance to the next column... column ++; - tempwidth = column * fl_width(" "); + if (columns) + { + for (i = 0, tempwidth = 0; i < column && columns[i]; i ++) + tempwidth += columns[i]; + } + else + tempwidth = column * (int)(fl_height() * 0.6 * 8.0); if (tempwidth > width) width = tempwidth; @@ -181,7 +212,7 @@ Fl_FileBrowser::item_width(void *p) const // I - List item data // Nul terminate this fragment and get the width... *ptr = '\0'; - tempwidth += fl_width(fragment); + tempwidth += (int)fl_width(fragment); // Update the max width as needed... if (tempwidth > width) @@ -206,48 +237,123 @@ 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 { - Fl_Color c; // Color of text + int i; // Looping var FL_BLINE *line; // Pointer to line + Fl_Color c; // Text color + char *text, // Pointer into text + *ptr, // Pointer into fragment + fragment[10240]; // Fragment of text + int width, // Width of line + height; // Height of line + int column; // Current column + const int *columns; // Columns - puts("Fl_FileBrowser::item_draw()"); + (void)h; + // Draw the list item text... line = (FL_BLINE *)p; - fl_font(text_font(), text_size()); - if (line->flags & SELECTED) - c = fl_contrast(text_color(), selection_color()); - else - c = text_color(); + fl_font(textfont(), textsize()); - if (active_r()) - fl_color(c); + if (line->flags & SELECTED) + c = contrast(textcolor(), selection_color()); else - fl_color(fl_inactive(c)); + c = textcolor(); if (Fl_FileIcon::first() == NULL) { // No icons, just draw the text... - fl_draw(line->txt, x + 1, y, w - 2, h, FL_ALIGN_LEFT); + x ++; + w -= 2; } else { - // Icons; draw the text offset to the right... - fl_draw(line->txt, x + iconsize_ + 9, y, w - iconsize_ - 10, h, - FL_ALIGN_LEFT); - - // And then draw the icon if it is set... + // 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 ++) + if (*text == '\n') + height += fl_height(); + + if (height < iconsize_) + y += (iconsize_ - height) / 2; + } + + // Draw the text... + line = (FL_BLINE *)p; + columns = column_widths(); + width = 0; + column = 0; + + if (active_r()) + fl_color(c); + else + fl_color(inactive(c)); + + for (text = line->txt, ptr = fragment; *text != '\0'; text ++) + if (*text == '\n') + { + // Newline - nul terminate this fragment and draw it... + *ptr = '\0'; + + fl_draw(fragment, x + width, y, w - width, fl_height(), + (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP)); + + // Point back to the start of the fragment... + ptr = fragment; + width = 0; + y += fl_height(); + column = 0; + } + else if (*text == column_char()) + { + // Tab - nul terminate this fragment and draw it... + *ptr = '\0'; + + fl_draw(fragment, x + width, y, w - width, fl_height(), + (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP)); + + // Advance to the next column... + column ++; + if (columns) + { + for (i = 0, width = 0; i < column && columns[i]; i ++) + width += columns[i]; + } + else + width = column * (int)(fl_height() * 0.6 * 8.0); + + ptr = fragment; + } + else + *ptr++ = *text; + + if (ptr > fragment) + { + // Nul terminate this fragment and draw it... + *ptr = '\0'; + + fl_draw(fragment, x + width, y, w - width, fl_height(), + (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP)); } } @@ -257,16 +363,16 @@ Fl_FileBrowser::item_draw(void *p, // I - List item data // Fl_FileBrowser::Fl_FileBrowser(int x, // I - Upper-lefthand X coordinate - int y, // I - Upper-lefthand Y coordinate - int w, // I - Width in pixels - int h, // I - Height in pixels - const char *l) // I - Label text + int y, // I - Upper-lefthand Y coordinate + int w, // I - Width in pixels + int h, // I - Height in pixels + const char *l) // I - Label text : Fl_Browser(x, y, w, h, l) { // Initialize the filter pattern, current directory, and icon size... pattern_ = "*"; directory_ = ""; - iconsize_ = 20; // This looks best for the default icons, if loaded... + iconsize_ = 3 * textsize() / 2; } @@ -283,6 +389,8 @@ Fl_FileBrowser::load(const char *directory)// I - Directory to load Fl_FileIcon *icon; // Icon to use +// printf("Fl_FileBrowser::load(\"%s\")\n", directory); + clear(); directory_ = directory; @@ -294,20 +402,23 @@ Fl_FileBrowser::load(const char *directory)// I - Directory to load // num_files = 0; - icon = Fl_FileIcon::find("any", Fl_FileIcon::DEVICE); + if ((icon = Fl_FileIcon::find("any", Fl_FileIcon::DEVICE)) == NULL) + icon = Fl_FileIcon::find("any", Fl_FileIcon::DIRECTORY); - if (icon == (Fl_FileIcon *)0) - icon = Fl_FileIcon::find("any", Fl_FileIcon::DIR); - -#if defined(_WIN32) +#if defined(WIN32) DWORD drives; // Drive available bits + drives = GetLogicalDrives(); for (i = 'A'; i <= 'Z'; i ++, drives >>= 1) if (drives & 1) { sprintf(filename, "%c:", i); - add(filename, icon); + + if (i < 'C') + add(filename, icon); + else + add(filename, icon); num_files ++; } @@ -331,10 +442,11 @@ Fl_FileBrowser::load(const char *directory)// I - Directory to load FILE *mtab; // /etc/mtab or /etc/mnttab file char line[1024]; // Input line + // // Open the file that contains a list of mounted filesystems... // -# if defined(__hpux) || defined(__sun) +# if defined(hpux) || defined(__sun) mtab = fopen("/etc/mnttab", "r"); // Fairly standard # elif defined(__sgi) || defined(linux) mtab = fopen("/etc/mtab", "r"); // More standard @@ -353,13 +465,14 @@ Fl_FileBrowser::load(const char *directory)// I - Directory to load if (sscanf(line, "%*s%4095s", filename) != 1) continue; +// printf("Fl_FileBrowser::load() - adding \"%s\" to list...\n", filename); add(filename, icon); num_files ++; } fclose(mtab); } -#endif // _WIN32 +#endif // WIN32 || __EMX__ } else { @@ -370,10 +483,9 @@ Fl_FileBrowser::load(const char *directory)// I - Directory to load // Build the file list... // -#if defined(_WIN32) || defined(__EMX__) +#if defined(WIN32) || defined(__EMX__) strncpy(filename, directory_, sizeof(filename) - 1); filename[sizeof(filename) - 1] = '\0'; - i = strlen(filename) - 1; if (i == 2 && filename[1] == ':' && @@ -385,30 +497,19 @@ Fl_FileBrowser::load(const char *directory)// I - Directory to load num_files = filename_list(filename, &files); #else num_files = filename_list(directory_, &files); -#endif /* _WIN32 || __EMX__ */ +#endif /* WIN32 || __EMX__ */ if (num_files <= 0) return (0); - // Add directories first... - for (i = 0; i < num_files; i ++) - if (strcmp(files[i]->d_name, ".") != 0 && - strcmp(files[i]->d_name, "..") != 0) - { - snprintf(filename, sizeof(filename), "%s/%s", directory_, files[i]->d_name); - - if (filename_isdir(filename)) - add(files[i]->d_name, Fl_FileIcon::find(filename)); - } - for (i = 0; i < num_files; i ++) { if (strcmp(files[i]->d_name, ".") != 0 && strcmp(files[i]->d_name, "..") != 0) { - snprintf(filename, sizeof(filename), "%s/%s", directory_, files[i]->d_name); + sprintf(filename, "%s/%s", directory_, files[i]->d_name); - if (!filename_isdir(filename) && + if (filename_isdir(filename) || filename_match(files[i]->d_name, pattern_)) add(files[i]->d_name, Fl_FileIcon::find(filename)); } @@ -442,5 +543,5 @@ Fl_FileBrowser::filter(const char *pattern) // I - Pattern string // -// End of "$Id: Fl_FileBrowser.cxx,v 1.13 2001/07/29 22:04:43 spitzak Exp $". +// End of "$Id: Fl_FileBrowser.cxx,v 1.13.2.1 2001/08/02 16:17:04 easysw Exp $". // diff --git a/src/Fl_FileChooser.cxx b/src/Fl_FileChooser.cxx index 249567ee8..9daf75e87 100644 --- a/src/Fl_FileChooser.cxx +++ b/src/Fl_FileChooser.cxx @@ -1,25 +1,44 @@ -// generated by Fast Light User Interface Designer (fluid) version 2.0000 +// generated by Fast Light User Interface Designer (fluid) version 1.0100 -#include -#include +#include "../FL/Fl_FileChooser.H" inline void Fl_FileChooser::cb_window_i(Fl_Window*, void*) { fileList->deselect(); - fileName->value(""); - window->hide(); +fileName->value(""); +window->hide(); } void Fl_FileChooser::cb_window(Fl_Window* o, void* v) { ((Fl_FileChooser*)(o->user_data()))->cb_window_i(o,v); } -inline void Fl_FileChooser::cb_dirMenu_i(Fl_Choice*, void*) { - if (dirMenu->value()) - directory(dirMenu->text(dirMenu->value())); -else - directory(""); +inline void Fl_FileChooser::cb_fileList_i(Fl_FileBrowser*, void*) { + fileListCB(); } -void Fl_FileChooser::cb_dirMenu(Fl_Choice* o, void* v) { - ((Fl_FileChooser*)(o->parent()->user_data()))->cb_dirMenu_i(o,v); +void Fl_FileChooser::cb_fileList(Fl_FileBrowser* o, void* v) { + ((Fl_FileChooser*)(o->parent()->user_data()))->cb_fileList_i(o,v); +} + +inline void Fl_FileChooser::cb_Cancel_i(Fl_Button*, void*) { + fileList->deselect(); +fileName->value(""); +window->hide(); +} +void Fl_FileChooser::cb_Cancel(Fl_Button* o, void* v) { + ((Fl_FileChooser*)(o->parent()->user_data()))->cb_Cancel_i(o,v); +} + +inline void Fl_FileChooser::cb_okButton_i(Fl_Return_Button*, void*) { + window->hide(); +} +void Fl_FileChooser::cb_okButton(Fl_Return_Button* o, void* v) { + ((Fl_FileChooser*)(o->parent()->user_data()))->cb_okButton_i(o,v); +} + +inline void Fl_FileChooser::cb_fileName_i(Fl_Input*, void*) { + fileNameCB(); +} +void Fl_FileChooser::cb_fileName(Fl_Input* o, void* v) { + ((Fl_FileChooser*)(o->parent()->user_data()))->cb_fileName_i(o,v); } inline void Fl_FileChooser::cb_upButton_i(Fl_Button*, void*) { @@ -29,7 +48,7 @@ void Fl_FileChooser::cb_upButton(Fl_Button* o, void* v) { ((Fl_FileChooser*)(o->parent()->user_data()))->cb_upButton_i(o,v); } -#include +#include static unsigned char bits_up[] = "\0\0x\0\204\0\2\1""1\376y\200\375\200""1\200""1\200""1\200""1\200""1\200\1\ \200\1\200\377\377\0\0"; @@ -47,104 +66,79 @@ static unsigned char bits_new[] = \200\1\200\377\377\0\0"; static Fl_Bitmap bitmap_new(bits_new, 16, 16); -inline void Fl_FileChooser::cb__i(Fl_Button*, void*) { - fileList->filter("*");; -rescan(); +inline void Fl_FileChooser::cb_dirMenu_i(Fl_Choice*, void*) { + char pathname[1024]; +int i; + +pathname[0] = '\0'; +for (i = 1; i <= dirMenu->value(); i ++) + strcat(pathname, dirMenu->text(i)); +directory(pathname); } -void Fl_FileChooser::cb_(Fl_Button* o, void* v) { - ((Fl_FileChooser*)(o->parent()->user_data()))->cb__i(o,v); +void Fl_FileChooser::cb_dirMenu(Fl_Choice* o, void* v) { + ((Fl_FileChooser*)(o->parent()->user_data()))->cb_dirMenu_i(o,v); +} + +inline void Fl_FileChooser::cb_allfiles_i(Fl_Button*, void*) { + const char *f; +if ((f = fl_input("New Filter?", + fileList->filter())) != NULL) +{ + fileList->filter(f); + rescan(); +}; +} +void Fl_FileChooser::cb_allfiles(Fl_Button* o, void* v) { + ((Fl_FileChooser*)(o->parent()->user_data()))->cb_allfiles_i(o,v); } static unsigned char bits_allfiles[] = "\374?\4 \4 \4 \204!\244%\304#\364/\364/\304#\244%\204!\4 \4 \4 \374?"; static Fl_Bitmap bitmap_allfiles(bits_allfiles, 16, 16); -inline void Fl_FileChooser::cb_fileList_i(Fl_FileBrowser*, void*) { - fileListCB(); -} -void Fl_FileChooser::cb_fileList(Fl_FileBrowser* o, void* v) { - ((Fl_FileChooser*)(o->parent()->user_data()))->cb_fileList_i(o,v); -} - -inline void Fl_FileChooser::cb_fileName_i(Fl_FileInput*, void*) { - fileNameCB(); -} -void Fl_FileChooser::cb_fileName(Fl_FileInput* o, void* v) { - ((Fl_FileChooser*)(o->parent()->user_data()))->cb_fileName_i(o,v); -} - -inline void Fl_FileChooser::cb_okButton_i(Fl_Return_Button*, void*) { - char pathname[1024]; - -snprintf(pathname, sizeof(pathname), "%s/%s", - fileList->directory(), fileName->value()); -if (filename_isdir(pathname)) - directory(pathname); -else - window->hide(); -} -void Fl_FileChooser::cb_okButton(Fl_Return_Button* o, void* v) { - ((Fl_FileChooser*)(o->parent()->user_data()))->cb_okButton_i(o,v); -} - -inline void Fl_FileChooser::cb_Cancel_i(Fl_Button*, void*) { - fileList->deselect(); -fileName->value(""); -window->hide(); -} -void Fl_FileChooser::cb_Cancel(Fl_Button* o, void* v) { - ((Fl_FileChooser*)(o->parent()->user_data()))->cb_Cancel_i(o,v); -} - Fl_FileChooser::Fl_FileChooser(const char *d, const char *p, int t, const char *title) { + Fl_Window* w; { Fl_Window* o = window = new Fl_Window(375, 315, "Pick a File"); + w = o; o->callback((Fl_Callback*)cb_window, (void*)(this)); - ((Fl_Window*)(o))->hotspot(o); - { Fl_Choice* o = dirMenu = new Fl_Choice(65, 10, 210, 25, "Directory:"); o->begin(); - o->callback((Fl_Callback*)cb_dirMenu); - o->tooltip("Click to access directory tree."); - o->set_flag(FL_ALIGN_LEFT | FL_ALIGN_RIGHT); - o->align(FL_ALIGN_LEFT | FL_ALIGN_RIGHT); - o->end(); - } - { Fl_Button* o = upButton = new Fl_Button(280, 10, 25, 25); - o->image(bitmap_up); - o->label_size(8); - o->callback((Fl_Callback*)cb_upButton); - o->tooltip("Click to display parent directory."); - } - { Fl_Button* o = newButton = new Fl_Button(310, 10, 25, 25); - o->image(bitmap_new); - o->label_size(8); - o->callback((Fl_Callback*)cb_newButton); - o->tooltip("Click to create a new directory."); - } - { Fl_Button* o = new Fl_Button(340, 10, 25, 25); - o->image(bitmap_allfiles); - o->label_color((Fl_Color)4); - o->label_size(28); - o->callback((Fl_Callback*)cb_); - o->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE); - o->tooltip("Click to show all files."); - } + w->hotspot(o); { Fl_FileBrowser* o = fileList = new Fl_FileBrowser(10, 45, 355, 180); + o->type(2); o->callback((Fl_Callback*)cb_fileList); Fl_Group::current()->resizable(o); - o->tooltip("Double-click to change directories."); + w->hotspot(o); } - { Fl_FileInput* o = fileName = new Fl_FileInput(10, 245, 355, 25, "Filename:"); - o->callback((Fl_Callback*)cb_fileName); - o->align(FL_ALIGN_TOP | FL_ALIGN_LEFT); - o->when(FL_WHEN_ENTER_KEY); - o->tooltip("Type a filename or directory name here."); - fileName->when(FL_WHEN_CHANGED | FL_WHEN_ENTER_KEY_ALWAYS); + { Fl_Button* o = new Fl_Button(285, 280, 80, 25, "Cancel"); + o->callback((Fl_Callback*)cb_Cancel); } - { Fl_Return_Button* o = okButton = new Fl_Return_Button(240, 280, 55, 25, "OK"); - o->shortcut(0xff0d); + { Fl_Return_Button* o = okButton = new Fl_Return_Button(205, 280, 75, 25, "OK"); o->callback((Fl_Callback*)cb_okButton); } - { Fl_Button* o = new Fl_Button(300, 280, 65, 25, "Cancel"); - o->callback((Fl_Callback*)cb_Cancel); + { Fl_Input* o = fileName = new Fl_Input(10, 245, 355, 25, "Filename:"); + o->callback((Fl_Callback*)cb_fileName); + o->align(FL_ALIGN_TOP_LEFT); + o->when(FL_WHEN_ENTER_KEY); + fileName->when(FL_WHEN_CHANGED | FL_WHEN_ENTER_KEY_ALWAYS); + } + { Fl_Button* o = upButton = new Fl_Button(280, 10, 25, 25); + bitmap_up.label(o); + o->labelsize(8); + o->callback((Fl_Callback*)cb_upButton); + } + { Fl_Button* o = newButton = new Fl_Button(310, 10, 25, 25); + bitmap_new.label(o); + o->labelsize(8); + o->callback((Fl_Callback*)cb_newButton); + } + { Fl_Choice* o = dirMenu = new Fl_Choice(95, 10, 180, 25, "Directory:"); + o->callback((Fl_Callback*)cb_dirMenu); + } + { Fl_Button* o = new Fl_Button(340, 10, 25, 25); + bitmap_allfiles.label(o); + o->labelsize(28); + o->labelcolor(4); + o->callback((Fl_Callback*)cb_allfiles); + o->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE); } if (title) window->label(title); o->set_modal(); @@ -197,30 +191,29 @@ const char * Fl_FileChooser::label() { return (window->label()); } -void Fl_FileChooser::exec() { - window->exec(); +void Fl_FileChooser::show() { + window->show(); fileList->deselect(); } void Fl_FileChooser::textcolor(Fl_Color c) { fileList->textcolor(c); - fileList->text_color(c); } Fl_Color Fl_FileChooser::textcolor() { return (fileList->textcolor()); } -void Fl_FileChooser::textfont(Fl_Font f) { - fileList->text_font(f); +void Fl_FileChooser::textfont(uchar f) { + fileList->textfont(f); } -Fl_Font Fl_FileChooser::textfont() { - return (fileList->text_font()); +uchar Fl_FileChooser::textfont() { + return (fileList->textfont()); } void Fl_FileChooser::textsize(uchar s) { - fileList->text_size(s); + fileList->textsize(s); } uchar Fl_FileChooser::textsize() { diff --git a/src/Fl_FileChooser.fl b/src/Fl_FileChooser.fl index 5fa2d22bd..0ac411656 100644 --- a/src/Fl_FileChooser.fl +++ b/src/Fl_FileChooser.fl @@ -1,16 +1,10 @@ -# data file for the FLTK User Interface Designer (FLUID) -version 2.0000 -images_dir ./ -do_not_include_H_from_C -header_name {.H} +# data file for the Fltk User Interface Designer (fluid) +version 1.0100 +header_name {../FL/Fl_FileChooser.H} code_name {.cxx} gridx 5 gridy 5 snap 3 -decl {\#include } {} - -decl {\#include } {} - class Fl_FileChooser {open } { decl {enum { SINGLE, MULTI, CREATE };} {public @@ -22,74 +16,68 @@ class Fl_FileChooser {open callback {fileList->deselect(); fileName->value(""); window->hide();} open - xywh {269 372 375 315} resizable hotspot + private xywh {208 292 375 315} resizable hotspot code0 {if (title) window->label(title);} code1 {\#include } code2 {\#include } code3 {\#include } modal visible } { - Fl_Choice dirMenu { - label {Directory:} - callback {if (dirMenu->value()) - directory(dirMenu->text(dirMenu->value())); -else - directory("");} open - tooltip {Click to access directory tree.} - private xywh {65 10 210 25} - code0 {o->set_flag(FL_ALIGN_LEFT | FL_ALIGN_RIGHT); - o->align(FL_ALIGN_LEFT | FL_ALIGN_RIGHT);} - } {} - Fl_Button upButton { - callback {up();} - tooltip {Click to display parent directory.} - private xywh {280 10 25 25} image not_inlined {up.xbm} labelsize 8 - } - Fl_Button newButton { - callback {newdir();} - tooltip {Click to create a new directory.} - private xywh {310 10 25 25} image not_inlined {new.xbm} labelsize 8 - } - Fl_Button {} { - callback {fileList->filter("*");; -rescan();} - tooltip {Click to show all files.} - private xywh {340 10 25 25} align 524304 image not_inlined {allfiles.xbm} labelcolor 4 labelsize 28 - } Fl_Browser fileList { - callback {fileListCB();} - tooltip {Double-click to change directories.} - private xywh {10 45 355 180} resizable - code0 {\#include "filename.H"} - code1 {\#include } + callback {fileListCB();} selected + private xywh {10 45 355 180} type Hold resizable hotspot + code0 {\#include } class Fl_FileBrowser } - Fl_Input fileName { - label {Filename:} - callback {fileNameCB();} selected - tooltip {Type a filename or directory name here.} - private xywh {10 245 355 25} align 5 when 8 - code0 {fileName->when(FL_WHEN_CHANGED | FL_WHEN_ENTER_KEY_ALWAYS);} - code1 {\#include } - class Fl_FileInput - } - Fl_Return_Button okButton { - label OK - callback {char pathname[1024]; - -snprintf(pathname, sizeof(pathname), "%s/%s", - fileList->directory(), fileName->value()); -if (filename_isdir(pathname)) - directory(pathname); -else - window->hide();} - private xywh {240 280 55 25} shortcut 0xff0d - } Fl_Button {} { label Cancel callback {fileList->deselect(); fileName->value(""); window->hide();} - private xywh {300 280 65 25} + private xywh {285 280 80 25} + } + Fl_Return_Button okButton { + label OK + callback {window->hide();} + private xywh {205 280 75 25} + } + Fl_Input fileName { + label {Filename:} + callback {fileNameCB();} + private xywh {10 245 355 25} align 5 when 8 + code0 {fileName->when(FL_WHEN_CHANGED | FL_WHEN_ENTER_KEY_ALWAYS);} + } + Fl_Button upButton { + label {up.xbm} + callback {up();} + private xywh {280 10 25 25} labeltype image labelsize 8 + } + Fl_Button newButton { + label {new.xbm} + callback {newdir();} + private xywh {310 10 25 25} labeltype image labelsize 8 + } + Fl_Choice dirMenu { + label {Directory:} + callback {char pathname[1024]; +int i; + +pathname[0] = '\\0'; +for (i = 1; i <= dirMenu->value(); i ++) + strcat(pathname, dirMenu->text(i)); +directory(pathname);} open + private xywh {95 10 180 25} + } {} + Fl_Button {} { + label {allfiles.xbm} + callback {const char *f; +if ((f = fl_input("New Filter?", + fileList->filter())) != NULL) +{ + fileList->filter(f); + rescan(); +}} + private xywh {340 10 25 25} labeltype image labelsize 28 labelcolor 4 align 16 + code0 {\#include } } } code {window->size_range(345, 270, 345); @@ -149,33 +137,30 @@ rescan();} {} } decl {void rescan();} {public } - Function {exec()} {return_type void + Function {show()} {return_type void } { - code {window->exec(); + code {window->show(); fileList->deselect();} {} } Function {textcolor(Fl_Color c)} {return_type void } { - code {fileList->textcolor(c); - fileList->text_color(c);} {} + code {fileList->textcolor(c);} {} } Function {textcolor()} {return_type Fl_Color } { - code {return (fileList->textcolor()); - return (fileList->textcolor());} {} + code {return (fileList->textcolor());} {} } - Function {textfont(Fl_Font f)} {return_type void + Function {textfont(uchar f)} {return_type void } { - code {fileList->text_font(f);} {} + code {fileList->textfont(f);} {} } - Function {textfont()} {return_type Fl_Font + Function {textfont()} {return_type uchar } { - code {return (fileList->text_font()); - return (fileList->textfont());} {} + code {return (fileList->textfont());} {} } Function {textsize(uchar s)} {return_type void } { - code {fileList->text_size(s);} {} + code {fileList->textsize(s);} {} } Function {textsize()} {return_type uchar } { diff --git a/src/Fl_FileChooser2.cxx b/src/Fl_FileChooser2.cxx index 40837e910..67ab98ff6 100644 --- a/src/Fl_FileChooser2.cxx +++ b/src/Fl_FileChooser2.cxx @@ -1,9 +1,9 @@ // -// "$Id: Fl_FileChooser2.cxx,v 1.15 2001/07/29 22:04:43 spitzak Exp $" +// "$Id: Fl_FileChooser2.cxx,v 1.15.2.1 2001/08/02 16:17:04 easysw Exp $" // -// More Fl_FileChooser routines for the Fast Light Tool Kit (FLTK). +// More Fl_FileChooser routines. // -// Copyright 1997-2000 by Easy Software Products. +// Copyright 1999-2001 by Michael Sweet. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -20,7 +20,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // USA. // -// Please report all bugs and problems to "fltk-bugs@easysw.com". +// Please report all bugs and problems to "fltk-bugs@fltk.org". // // Contents: // @@ -31,7 +31,7 @@ // Fl_FileChooser::newdir() - Make a new directory. // Fl_FileChooser::rescan() - Rescan the current directory. // Fl_FileChooser::fileListCB() - Handle clicks (and double-clicks) in the -// FileBrowser. +// FileBrowser. // Fl_FileChooser::fileNameCB() - Handle text entry in the FileBrowser. // @@ -39,24 +39,28 @@ // Include necessary headers. // -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include + +#include +#include #include +#include #include #include +#include +#include -#if defined(_WIN32) +#if defined(WIN32) # include # include #else # include # include -#endif /* _WIN32 */ +#endif /* WIN32 */ + // // 'Fl_FileChooser::directory()' - Set the directory in the file chooser. @@ -65,12 +69,14 @@ void Fl_FileChooser::directory(const char *d) // I - Directory to change to { - char pathname[1024], // Full path of directory - *pathptr, // Pointer into full path - *dirptr; // Pointer into directory - int levels; // Number of levels in directory + char pathname[1024], // Full path of directory + *pathptr, // Pointer into full path + *dirptr; // Pointer into directory + int levels; // Number of levels in directory +// printf("Fl_FileChooser::directory(\"%s\")\n", d == NULL ? "(null)" : d); + // NULL == current directory if (d == NULL) d = "."; @@ -78,11 +84,11 @@ Fl_FileChooser::directory(const char *d) // I - Directory to change to if (d[0] != '\0') { // Make the directory absolute... -#if defined(_WIN32) || defined(__EMX__) +#if defined(WIN32) || defined(__EMX__) if (d[0] != '/' && d[0] != '\\' && d[1] != ':') #else if (d[0] != '/' && d[0] != '\\') -#endif /* _WIN32 || __EMX__ */ +#endif /* WIN32 || __EMX__ */ filename_absolute(directory_, d); else { @@ -102,11 +108,11 @@ Fl_FileChooser::directory(const char *d) // I - Directory to change to // Clear the directory menu and fill it as needed... dirMenu->clear(); -#if defined(_WIN32) || defined(__EMX__) +#if defined(WIN32) || defined(__EMX__) dirMenu->add("My Computer"); #else dirMenu->add("File Systems"); -#endif /* _WIN32 || __EMX__ */ +#endif /* WIN32 || __EMX__ */ levels = 0; for (dirptr = directory_, pathptr = pathname; *dirptr != '\0';) @@ -116,11 +122,12 @@ Fl_FileChooser::directory(const char *d) // I - Directory to change to // Need to quote the slash first, and then add it to the menu... *pathptr++ = '\\'; *pathptr++ = '/'; - *pathptr = '\0'; + *pathptr++ = '\0'; dirptr ++; dirMenu->add(pathname); levels ++; + pathptr = pathname; } else *pathptr++ = *dirptr++; @@ -134,7 +141,6 @@ Fl_FileChooser::directory(const char *d) // I - Directory to change to } dirMenu->value(levels); - dirMenu->redraw(); // Rescan the directory... rescan(); @@ -163,7 +169,7 @@ Fl_FileChooser::count() // Is the file name a directory? if (directory_[0] != '\0') - snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename); + sprintf(pathname, "%s/%s", directory_, filename); else { strncpy(pathname, filename, sizeof(pathname) - 1); @@ -176,17 +182,17 @@ Fl_FileChooser::count() return (1); } - for (i = 0, count = 0; i < fileList->size(); i ++) + for (i = 1, count = 0; i <= fileList->size(); i ++) if (fileList->selected(i)) { // See if this file is a directory... filename = (char *)fileList->text(i); if (directory_[0] != '\0') - snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename); + sprintf(pathname, "%s/%s", directory_, filename); else { - strncpy(pathname, filename, sizeof(pathname) - 1); - pathname[sizeof(pathname) - 1] = '\0'; + strncpy(pathname, filename, sizeof(pathname) - 1); + pathname[sizeof(pathname) - 1] = '\0'; } if (!filename_isdir(pathname)) @@ -216,16 +222,16 @@ Fl_FileChooser::value(int f) // I - File number if (name[0] == '\0') return (NULL); - snprintf(pathname, sizeof(pathname), "%s/%s", directory_, name); + sprintf(pathname, "%s/%s", directory_, name); return ((const char *)pathname); } - for (i = 0, count = 0; i < fileList->size(); i ++) + for (i = 1, count = 0; i <= fileList->size(); i ++) if (fileList->selected(i)) { // See if this file is a directory... name = fileList->text(i); - snprintf(pathname, sizeof(pathname), "%s/%s", directory_, name); + sprintf(pathname, "%s/%s", directory_, name); if (!filename_isdir(pathname)) { @@ -253,21 +259,16 @@ Fl_FileChooser::value(const char *filename) // I - Filename + directory char pathname[1024]; // Local copy of filename +// printf("Fl_FileChooser::value(\"%s\")\n", filename == NULL ? "(null)" : filename); + // See if the filename is actually a directory... - if (filename == NULL || filename_isdir(filename)) + if (filename == NULL || !filename[0] || filename_isdir(filename)) { // Yes, just change the current directory... directory(filename); return; } - if (!filename[0]) - { - // Just show the current directory... - directory(NULL); - return; - } - // Switch to single-selection mode as needed if (type_ == MULTI) type(SINGLE); @@ -286,10 +287,7 @@ Fl_FileChooser::value(const char *filename) // I - Filename + directory directory(pathname); } else - { - directory(NULL); slash = pathname; - } // Set the input field to the remaining portion fileName->value(slash); @@ -299,7 +297,7 @@ Fl_FileChooser::value(const char *filename) // I - Filename + directory // Then find the file in the file list and select it... count = fileList->size(); - for (i = 0; i < count; i ++) + for (i = 1; i <= count; i ++) if (strcmp(fileList->text(i), slash) == 0) { fileList->select(i); @@ -348,16 +346,16 @@ Fl_FileChooser::newdir() // Get a directory name from the user - if ((dir = fl_input("New Directory?")) == NULL) + if ((dir = fl_input("New Directory?", NULL)) == NULL) return; // Make it relative to the current directory as needed... -#if defined(_WIN32) || defined(__EMX__) +#if defined(WIN32) || defined(__EMX__) if (dir[0] != '/' && dir[0] != '\\' && dir[1] != ':') #else if (dir[0] != '/' && dir[0] != '\\') -#endif /* _WIN32 || __EMX__ */ - snprintf(pathname, sizeof(pathname), "%s/%s", directory_, dir); +#endif /* WIN32 || __EMX__ */ + sprintf(pathname, "%s/%s", directory_, dir); else { strncpy(pathname, dir, sizeof(pathname) - 1); @@ -365,11 +363,11 @@ Fl_FileChooser::newdir() } // Create the directory; ignore EEXIST errors... -#if defined(_WIN32) +#if defined(WIN32) if (mkdir(pathname)) #else if (mkdir(pathname, 0777)) -#endif /* _WIN32 || __EMX__ */ +#endif /* WIN32 */ if (errno != EEXIST) { fl_alert("Unable to create directory!"); @@ -388,13 +386,14 @@ Fl_FileChooser::newdir() void Fl_FileChooser::rescan() { +// printf("Fl_FileChooser::rescan(); directory = \"%s\"\n", directory_); + // Clear the current filename fileName->value(""); okButton->deactivate(); // Build the file list... fileList->load(directory_); - fileList->redraw(); } @@ -406,38 +405,28 @@ Fl_FileChooser::rescan() void Fl_FileChooser::fileListCB() { - char filename[1024], // New filename + char *filename, // New filename pathname[1024]; // Full pathname to file - strncpy(filename, fileList->text(fileList->value()), sizeof(filename) - 1); - filename[sizeof(filename) - 1] = '\0'; - -#if defined(_WIN32) || defined(__EMX__) - if (directory_[0] != '\0' && filename[0] != '/' && filename[0] != '\\' && - !(isalpha(filename[0]) && filename[1] == ':')) - snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename); + filename = (char *)fileList->text(fileList->value()); + if (directory_[0] != '\0') + sprintf(pathname, "%s/%s", directory_, filename); else { strncpy(pathname, filename, sizeof(pathname) - 1); pathname[sizeof(pathname) - 1] = '\0'; } + + if (Fl::event_clicks()) + { +#if defined(WIN32) || defined(__EMX__) + if ((strlen(pathname) == 2 && pathname[1] == ':') || + filename_isdir(pathname)) #else - if (directory_[0] != '\0' && filename[0] != '/') - snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename); - else - { - strncpy(pathname, filename, sizeof(pathname) - 1); - pathname[sizeof(pathname) - 1] = '\0'; - } -#endif /* _WIN32 || __EMX__ */ - - if (Fl::event_clicks() || Fl::event_key() == FL_Enter) - { - puts("double-click"); if (filename_isdir(pathname)) +#endif /* WIN32 || __EMX__ */ { - puts("directory"); directory(pathname); upButton->activate(); } @@ -447,7 +436,9 @@ Fl_FileChooser::fileListCB() else { fileName->value(filename); - okButton->activate(); + + if (!filename_isdir(pathname)) + okButton->activate(); } } @@ -479,10 +470,12 @@ Fl_FileChooser::fileNameCB() return; } -#if defined(_WIN32) || defined(__EMX__) - if (directory_[0] != '\0' && filename[0] != '/' && filename[0] != '\\' && +#if defined(WIN32) || defined(__EMX__) + if (directory_[0] != '\0' && + filename[0] != '/' && + filename[0] != '\\' && !(isalpha(filename[0]) && filename[1] == ':')) - snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename); + sprintf(pathname, "%s/%s", directory_, filename); else { strncpy(pathname, filename, sizeof(pathname) - 1); @@ -514,26 +507,33 @@ Fl_FileChooser::fileNameCB() pathname[sizeof(pathname) - 1] = '\0'; if (filename[strlen(filename) - 1] == '/') - strncat(pathname, "/", sizeof(pathname) - strlen(pathname) - 1); + strncat(pathname, "/", sizeof(pathname) - 1); } else - snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename); + sprintf(pathname, "%s/%s", directory_, filename); endpwent(); } - else if (directory_[0] != '\0' && filename[0] != '/') - snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename); + else if (directory_[0] != '\0' && + filename[0] != '/') + sprintf(pathname, "%s/%s", directory_, filename); else { strncpy(pathname, filename, sizeof(pathname) - 1); pathname[sizeof(pathname) - 1] = '\0'; } -#endif /* _WIN32 || __EMX__ */ +#endif /* WIN32 || __EMX__ */ if (Fl::event_key() == FL_Enter) { // Enter pressed - select or change directory... + +#if defined(WIN32) || defined(__EMX__) + if ((strlen(pathname) == 2 && pathname[1] == ':') || + filename_isdir(pathname)) +#else if (filename_isdir(pathname)) +#endif /* WIN32 || __EMX__ */ directory(pathname); else if (type_ == CREATE || access(pathname, 0) == 0) { @@ -547,7 +547,14 @@ Fl_FileChooser::fileNameCB() } else { - // File doesn't exist, so alert the user... + // File doesn't exist, so beep at and alert the user... + // TODO: NEED TO ADD fl_beep() FUNCTION TO 2.0! +#ifdef WIN32 + MessageBeep(MB_ICONEXCLAMATION); +#else + XBell(fl_display, 100); +#endif // WIN32 + fl_alert("Please choose an existing file!"); } } @@ -589,15 +596,15 @@ Fl_FileChooser::fileNameCB() max_match = 100000; first_line = 0; - for (i = 0; i < num_files && max_match > min_match; i ++) + for (i = 1; i <= num_files && max_match > min_match; i ++) { file = fileList->text(i); -#if defined(_WIN32) || defined(__EMX__) +#if defined(WIN32) || defined(__EMX__) if (strnicmp(filename, file, min_match) == 0) #else if (strncmp(filename, file, min_match) == 0) -#endif // _WIN32 || __EMX__ +#endif // WIN32 || __EMX__ { // OK, this one matches; check against the previous match if (max_match == 100000) @@ -615,11 +622,11 @@ Fl_FileChooser::fileNameCB() { // Succeeding match; compare to find maximum string match... while (max_match > min_match) -#if defined(_WIN32) || defined(__EMX__) +#if defined(WIN32) || defined(__EMX__) if (strnicmp(file, pathname, max_match) == 0) #else if (strncmp(file, pathname, max_match) == 0) -#endif // _WIN32 || __EMX__ +#endif // WIN32 || __EMX__ break; else max_match --; @@ -640,7 +647,7 @@ Fl_FileChooser::fileNameCB() else if (max_match > min_match && max_match != 100000) { // Add the matching portion... - fileName->replace(0, min_match, pathname, strlen(pathname)); + fileName->replace(0, min_match, pathname); // Highlight it; if the user just pressed the backspace // key, position the cursor at the start of the selection. @@ -654,9 +661,10 @@ Fl_FileChooser::fileNameCB() } // See if we need to enable the OK button... - snprintf(pathname, sizeof(pathname), "%s/%s", directory_, fileName->value()); + sprintf(pathname, "%s/%s", directory_, fileName->value()); - if (type_ == CREATE || access(pathname, 0) == 0) + if ((type_ == CREATE || access(pathname, 0) == 0) && + !filename_isdir(pathname)) okButton->activate(); else okButton->deactivate(); @@ -665,5 +673,5 @@ Fl_FileChooser::fileNameCB() // -// End of "$Id: Fl_FileChooser2.cxx,v 1.15 2001/07/29 22:04:43 spitzak Exp $". +// End of "$Id: Fl_FileChooser2.cxx,v 1.15.2.1 2001/08/02 16:17:04 easysw Exp $". // diff --git a/src/Fl_FileIcon.cxx b/src/Fl_FileIcon.cxx index 20a947223..dc0273d95 100644 --- a/src/Fl_FileIcon.cxx +++ b/src/Fl_FileIcon.cxx @@ -1,9 +1,11 @@ // -// "$Id: Fl_FileIcon.cxx,v 1.10 2001/07/29 22:04:43 spitzak Exp $" +// "$Id: Fl_FileIcon.cxx,v 1.10.2.1 2001/08/02 16:17:04 easysw Exp $" // -// Fl_FileIcon routines for the Fast Light Tool Kit (FLTK). +// Fl_FileIcon routines. // -// Copyright 1997-1999 by Easy Software Products. +// KDE icon code donated by Maarten De Boer. +// +// Copyright 1999-2001 by Michael Sweet. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public @@ -20,7 +22,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 // USA. // -// Please report all bugs and problems to "fltk-bugs@easysw.com". +// Please report all bugs and problems to "fltk-bugs@fltk.org". // // Contents: // @@ -29,29 +31,42 @@ // Fl_FileIcon::add() - Add data to an icon. // Fl_FileIcon::find() - Find an icon based upon a given file. // Fl_FileIcon::draw() - Draw an icon. +// Fl_FileIcon::label() - Set the widgets label to an icon. +// Fl_FileIcon::labeltype() - Draw the icon label. +// Fl_FileIcon::load() - Load an icon file... +// Fl_FileIcon::load_fti() - Load an SGI-format FTI file... +// Fl_FileIcon::load_xpm() - Load an XPM icon file... +// Fl_FileIcon::load_system_icons() - Load the standard system icons/filetypes. // // // Include necessary header files... // +#include #include #include #include +#ifdef HAVE_STRINGS_H +# include +#endif /* HAVE_STRINGS_H */ #include +#include #include #include -#ifdef _WIN32 -# include -# define F_OK 0 +#if defined(WIN32) || defined(__EMX__) +# include +# define F_OK 0 +# define strcasecmp stricmp +# define strncasecmp strnicmp #else -# include -#endif +# include +#endif /* WIN32 || __EMX__ */ -#include -#include -#include -#include +#include +#include +#include +#include // @@ -74,14 +89,24 @@ Fl_FileIcon *Fl_FileIcon::first_ = (Fl_FileIcon *)0; +// +// Local functions... +// + +static void load_kde_icons(const char *directory); +static void load_kde_mimelnk(const char *filename); +static char *kde_to_fltk_pattern(const char *kdepattern); +static char *get_kde_val(char *str, const char *key); + + // // 'Fl_FileIcon::Fl_FileIcon()' - Create a new file icon. // Fl_FileIcon::Fl_FileIcon(const char *p, /* I - Filename pattern */ - int t, /* I - File type */ - int nd, /* I - Number of data values */ - short *d) /* I - Data values */ + int t, /* I - File type */ + int nd, /* I - Number of data values */ + short *d) /* I - Data values */ { // Initialize the pattern and type... pattern_ = p; @@ -177,7 +202,7 @@ Fl_FileIcon::add(short d) // I - Data to add Fl_FileIcon * // O - Matching file icon or NULL Fl_FileIcon::find(const char *filename, // I - Name of file */ - int filetype) // I - Enumerated file type + int filetype) // I - Enumerated file type { Fl_FileIcon *current; // Current file in list struct stat fileinfo; // Information on file @@ -188,7 +213,7 @@ Fl_FileIcon::find(const char *filename, // I - Name of file */ if (!stat(filename, &fileinfo)) { if (S_ISDIR(fileinfo.st_mode)) - filetype = DIR; + filetype = DIRECTORY; #ifdef S_IFIFO else if (S_ISFIFO(fileinfo.st_mode)) filetype = FIFO; @@ -222,12 +247,12 @@ Fl_FileIcon::find(const char *filename, // I - Name of file */ // void -Fl_FileIcon::draw(int x, // I - Upper-lefthand X - int y, // I - Upper-lefthand Y - int w, // I - Width of bounding box - int h, // I - Height of bounding box - Fl_Color ic, // I - Icon color... - int active) // I - Active or inactive? +Fl_FileIcon::draw(int x, // I - Upper-lefthand X + int y, // I - Upper-lefthand Y + int w, // I - Width of bounding box + int h, // I - Height of bounding box + Fl_Color ic, // I - Icon color... + int active) // I - Active or inactive? { Fl_Color c; // Current color short *d; // Pointer to data @@ -255,7 +280,7 @@ Fl_FileIcon::draw(int x, // I - Upper-lefthand X if (active) fl_color(c); else - fl_color(fl_inactive(c)); + fl_color(inactive(c)); while (*d != END || prim) switch (*d) @@ -264,23 +289,47 @@ Fl_FileIcon::draw(int x, // I - Upper-lefthand X switch (*prim) { case LINE : - fl_stroke(); + fl_end_line(); break; case CLOSEDLINE : - fl_closepath(); - fl_stroke(); + fl_end_loop(); break; case POLYGON : - fl_fill(); + fl_end_polygon(); break; - case OUTLINEPOLYGON : { - Fl_Color color = prim[1]==256 ? ic : (Fl_Color)prim[1]; - if (!active) color = fl_inactive(color); - fl_fill_stroke(color); - break;} + case OUTLINEPOLYGON : + fl_end_polygon(); + + if (active) + { + if (prim[1] == 256) + fl_color(ic); + else + fl_color((Fl_Color)prim[1]); + } + else + { + if (prim[1] == 256) + fl_color(inactive(ic)); + else + fl_color(inactive((Fl_Color)prim[1])); + } + + fl_begin_loop(); + + prim += 2; + while (*prim == VERTEX) + { + fl_vertex(prim[1] * 0.0001, prim[2] * 0.0001); + prim += 3; + } + + fl_end_loop(); + fl_color(c); + break; } prim = NULL; @@ -294,22 +343,34 @@ Fl_FileIcon::draw(int x, // I - Upper-lefthand X c = (Fl_Color)d[1]; if (!active) - c = fl_inactive(c); + c = inactive(c); fl_color(c); d += 2; break; case LINE : + prim = d; + d ++; + fl_begin_line(); + break; + case CLOSEDLINE : + prim = d; + d ++; + fl_begin_loop(); + break; + case POLYGON : prim = d; d ++; + fl_begin_polygon(); break; case OUTLINEPOLYGON : prim = d; d += 2; + fl_begin_polygon(); break; case VERTEX : @@ -319,11 +380,846 @@ Fl_FileIcon::draw(int x, // I - Upper-lefthand X break; } + // If we still have an open primitive, close it... + if (prim) + switch (*prim) + { + case LINE : + fl_end_line(); + break; + + case CLOSEDLINE : + fl_end_loop(); + break; + + case POLYGON : + fl_end_polygon(); + break; + + case OUTLINEPOLYGON : + fl_end_polygon(); + + if (active) + { + if (prim[1] == 256) + fl_color(ic); + else + fl_color((Fl_Color)prim[1]); + } + else + { + if (prim[1] == 256) + fl_color(inactive(ic)); + else + fl_color(inactive((Fl_Color)prim[1])); + } + + fl_begin_loop(); + + prim += 2; + while (*prim == VERTEX) + { + fl_vertex(prim[1] * 0.0001, prim[2] * 0.0001); + prim += 3; + } + + fl_end_loop(); + fl_color(c); + break; + } + // Restore the transform matrix fl_pop_matrix(); } // -// End of "$Id: Fl_FileIcon.cxx,v 1.10 2001/07/29 22:04:43 spitzak Exp $". +// 'Fl_FileIcon::label()' - Set the widget's label to an icon. +// + +void +Fl_FileIcon::label(Fl_Widget *w) // I - Widget to label +{ + Fl::set_labeltype(_FL_ICON_LABEL, labeltype, 0); + w->label(_FL_ICON_LABEL, (const char*)this); +} + + +// +// 'Fl_FileIcon::labeltype()' - Draw the icon label. +// + +void +Fl_FileIcon::labeltype(const Fl_Label *o, // I - Label data + int x, // I - X position of label + int y, // I - Y position of label + int w, // I - Width of label + int h, // I - Height of label + Fl_Align a) // I - Label alignment (not used) +{ + Fl_FileIcon *icon; // Pointer to icon data + + + (void)a; + + icon = (Fl_FileIcon *)(o->value); + + icon->draw(x, y, w, h, (Fl_Color)(o->color)); +} + + +// +// 'Fl_FileIcon::load()' - Load an icon file... +// + +void +Fl_FileIcon::load(const char *f) // I - File to read from +{ + const char *ext; // File extension + + + if ((ext = filename_ext(f)) == NULL) + { + fprintf(stderr, "Fl_FileIcon::load(): Unknown file type for \"%s\".\n", f); + return; + } + + if (strcmp(ext, ".fti") == 0) + load_fti(f); + else if (strcmp(ext, ".xpm") == 0) + load_xpm(f); +#if 0 + else if (strcmp(ext, ".png") == 0) + load_png(f); +#endif /* 0 */ + else + { + fprintf(stderr, "Fl_FileIcon::load(): Unknown file type for \"%s\".\n", f); + return; + } +} + + +// +// 'Fl_FileIcon::load_fti()' - Load an SGI-format FTI file... +// + +void +Fl_FileIcon::load_fti(const char *fti) // I - File to read from +{ + FILE *fp; // File pointer + int ch; // Current character + char command[255], // Command string ("vertex", etc.) + params[255], // Parameter string ("10.0,20.0", etc.) + *ptr; // Pointer into strings + int outline; // Outline polygon + + + // Try to open the file... + if ((fp = fopen(fti, "rb")) == NULL) + { + fprintf(stderr, "Fl_FileIcon::load_fti(): Unable to open \"%s\" - %s\n", + fti, strerror(errno)); + return; + } + + // Read the entire file, adding data as needed... + outline = 0; + + while ((ch = getc(fp)) != EOF) + { + // Skip whitespace + if (isspace(ch)) + continue; + + // Skip comments starting with "#"... + if (ch == '#') + { + while ((ch = getc(fp)) != EOF) + if (ch == '\n') + break; + + if (ch == EOF) + break; + else + continue; + } + + // OK, this character better be a letter... + if (!isalpha(ch)) + { + fprintf(stderr, "Fl_FileIcon::load_fti(): Expected a letter at file position %ld (saw '%c')\n", + ftell(fp) - 1, ch); + break; + } + + // Scan the command name... + ptr = command; + *ptr++ = ch; + + while ((ch = getc(fp)) != EOF) + { + if (ch == '(') + break; + else if (ptr < (command + sizeof(command) - 1)) + *ptr++ = ch; + } + + *ptr++ = '\0'; + + // Make sure we stopped on a parenthesis... + if (ch != '(') + { + fprintf(stderr, "Fl_FileIcon::load_fti(): Expected a ( at file position %ld (saw '%c')\n", + ftell(fp) - 1, ch); + break; + } + + // Scan the parameters... + ptr = params; + + while ((ch = getc(fp)) != EOF) + { + if (ch == ')') + break; + else if (ptr < (params + sizeof(params) - 1)) + *ptr++ = ch; + } + + *ptr++ = '\0'; + + // Make sure we stopped on a parenthesis... + if (ch != ')') + { + fprintf(stderr, "Fl_FileIcon::load_fti(): Expected a ) at file position %ld (saw '%c')\n", + ftell(fp) - 1, ch); + break; + } + + // Make sure the next character is a semicolon... + if ((ch = getc(fp)) != ';') + { + fprintf(stderr, "Fl_FileIcon::load_fti(): Expected a ; at file position %ld (saw '%c')\n", + ftell(fp) - 1, ch); + break; + } + + // Now process the command... + if (strcmp(command, "color") == 0) + { + // Set the color; for negative colors blend the two primaries to + // produce a composite color. Also, the following symbolic color + // names are understood: + // + // name FLTK color + // ------------- ---------- + // iconcolor 256; mapped to the icon color in Fl_FileIcon::draw() + // shadowcolor FL_DARK3 + // outlinecolor FL_BLACK + if (strcmp(params, "iconcolor") == 0) + add_color(256); + else if (strcmp(params, "shadowcolor") == 0) + add_color(FL_DARK3); + else if (strcmp(params, "outlinecolor") == 0) + add_color(FL_BLACK); + else + { + short c = atoi(params); // Color value + + + if (c < 0) + { + // Composite color; compute average... + c = -c; + add_color(fl_color_average((Fl_Color)(c >> 4), + (Fl_Color)(c & 15), 0.5)); + } + else + add_color(c); + } + } + else if (strcmp(command, "bgnline") == 0) + add(LINE); + else if (strcmp(command, "bgnclosedline") == 0) + add(CLOSEDLINE); + else if (strcmp(command, "bgnpolygon") == 0) + add(POLYGON); + else if (strcmp(command, "bgnoutlinepolygon") == 0) + { + add(OUTLINEPOLYGON); + outline = add(0) - data_; + } + else if (strcmp(command, "endoutlinepolygon") == 0 && outline) + { + // Set the outline color; see above for valid values... + if (strcmp(params, "iconcolor") == 0) + data_[outline] = 256; + else if (strcmp(params, "shadowcolor") == 0) + data_[outline] = FL_DARK3; + else if (strcmp(params, "outlinecolor") == 0) + data_[outline] = FL_BLACK; + else + { + short c = atoi(params); // Color value + + + if (c < 0) + { + // Composite color; compute average... + c = -c; + data_[outline] = fl_color_average((Fl_Color)(c >> 4), (Fl_Color)(c & 15), 0.5); + } + else + data_[outline] = c; + } + + outline = 0; + add(END); + } + else if (strncmp(command, "end", 3) == 0) + add(END); + else if (strcmp(command, "vertex") == 0) + { + float x, y; // Coordinates of vertex + + + if (sscanf(params, "%f,%f", &x, &y) != 2) + break; + + add_vertex((short)(x * 100.0 + 0.5), (short)(y * 100.0 + 0.5)); + } + else + { + fprintf(stderr, "Fl_FileIcon::load_fti(): Unknown command \"%s\" at file position %ld.\n", + command, ftell(fp) - 1); + break; + } + } + + // Close the file and return... + fclose(fp); + +#ifdef DEBUG + printf("Icon File \"%s\":\n", fti); + for (int i = 0; i < num_data_; i ++) + printf(" %d,\n", data_[i]); +#endif /* DEBUG */ +} + + +// +// 'Fl_FileIcon::load_xpm()' - Load an XPM icon file... +// + +void +Fl_FileIcon::load_xpm(const char *xpm) // I - File to read from +{ + FILE *fp; // File pointer + int i, j; // Looping vars + int ch; // Current character + int bg; // Background color + char line[1024], // Line from file + val[16], // Color value + *ptr; // Pointer into line + int x, y; // X & Y in image + int startx; // Starting X coord + int width, height; // Width and height of image + int ncolors; // Number of colors + short colors[256]; // Colors + int red, green, blue; // Red, green, and blue values + + + // Try to open the file... + if ((fp = fopen(xpm, "rb")) == NULL) + return; + + // Read the file header until we find the first string... + ptr = NULL; + while (fgets(line, sizeof(line), fp) != NULL) + if ((ptr = strchr(line, '\"')) != NULL) + break; + + if (ptr == NULL) + { + // Nothing to load... + fclose(fp); + return; + } + + // Get the size of the image... + sscanf(ptr + 1, "%d%d%d", &width, &height, &ncolors); + + // Now read the colormap... + memset(colors, 0, sizeof(colors)); + bg = ' '; + + for (i = 0; i < ncolors; i ++) + { + while (fgets(line, sizeof(line), fp) != NULL) + if ((ptr = strchr(line, '\"')) != NULL) + break; + + if (ptr == NULL) + { + // Nothing to load... + fclose(fp); + return; + } + + // Get the color's character + ptr ++; + ch = *ptr++; + + // Get the color value... + if ((ptr = strstr(ptr, "c ")) == NULL) + { + // No color; make this black... + colors[ch] = FL_BLACK; + } + else if (ptr[2] == '#') + { + // Read the RGB triplet... + ptr += 3; + for (j = 0; j < 12; j ++) + if (!isxdigit(ptr[j])) + break; + + switch (j) + { + case 0 : + bg = ch; + default : + red = green = blue = 0; + break; + + case 3 : + val[0] = ptr[0]; + val[1] = '\0'; + red = 255 * strtol(val, NULL, 16) / 15; + + val[0] = ptr[1]; + val[1] = '\0'; + green = 255 * strtol(val, NULL, 16) / 15; + + val[0] = ptr[2]; + val[1] = '\0'; + blue = 255 * strtol(val, NULL, 16) / 15; + break; + + case 6 : + case 9 : + case 12 : + j /= 3; + + val[0] = ptr[0]; + val[1] = ptr[1]; + val[2] = '\0'; + red = strtol(val, NULL, 16); + + val[0] = ptr[j + 0]; + val[1] = ptr[j + 1]; + val[2] = '\0'; + green = strtol(val, NULL, 16); + + val[0] = ptr[2 * j + 0]; + val[1] = ptr[2 * j + 1]; + val[2] = '\0'; + blue = strtol(val, NULL, 16); + break; + } + + if (red == green && green == blue) + colors[ch] = FL_GRAY_RAMP + (FL_NUM_GRAY - 1) * red / 255; + else + colors[ch] = fl_color_cube((FL_NUM_RED - 1) * red / 255, + (FL_NUM_GREEN - 1) * green / 255, + (FL_NUM_BLUE - 1) * blue / 255); + } + else + { + // Read a color name... + if (strncasecmp(ptr + 2, "white", 5) == 0) + colors[ch] = FL_WHITE; + else if (strncasecmp(ptr + 2, "black", 5) == 0) + colors[ch] = FL_BLACK; + else if (strncasecmp(ptr + 2, "none", 4) == 0) + { + colors[ch] = FL_BLACK; + bg = ch; + } + else + colors[ch] = FL_GRAY; + } + } + + // Read the image data... + for (y = height - 1; y >= 0; y --) + { + while (fgets(line, sizeof(line), fp) != NULL) + if ((ptr = strchr(line, '\"')) != NULL) + break; + + if (ptr == NULL) + { + // Nothing to load... + fclose(fp); + return; + } + + startx = 0; + ch = bg; + ptr ++; + + for (x = 0; x < width; x ++, ptr ++) + if (*ptr != ch) + { + if (ch != bg) + { + add_color(colors[ch]); + add(POLYGON); + add_vertex(startx * 9000 / width + 1000, y * 9000 / height + 500); + add_vertex(x * 9000 / width + 1000, y * 9000 / height + 500); + add_vertex(x * 9000 / width + 1000, (y + 1) * 9000 / height + 500); + add_vertex(startx * 9000 / width + 1000, (y + 1) * 9000 / height + 500); + add(END); + } + + ch = *ptr; + startx = x; + } + + if (ch != bg) + { + add_color(colors[ch]); + add(POLYGON); + add_vertex(startx * 9000 / width + 1000, y * 9000 / height + 500); + add_vertex(x * 9000 / width + 1000, y * 9000 / height + 500); + add_vertex(x * 9000 / width + 1000, (y + 1) * 9000 / height + 500); + add_vertex(startx * 9000 / width + 1000, (y + 1) * 9000 / height + 500); + add(END); + } + } + + // Close the file and return... + fclose(fp); + +#ifdef DEBUG + printf("Icon File \"%s\":\n", xpm); + for (i = 0; i < num_data_; i ++) + printf(" %d,\n", data_[i]); +#endif /* DEBUG */ +} + + +// +// 'Fl_FileIcon::load_system_icons()' - Load the standard system icons/filetypes. + +void +Fl_FileIcon::load_system_icons(void) +{ + Fl_FileIcon *icon; // New icons + static int init = 0; // Have the icons been initialized? + static short plain[] = // Plain file icon + { + COLOR, 256, OUTLINEPOLYGON, FL_GRAY, + VERTEX, 2000, 1000, VERTEX, 2000, 9000, + VERTEX, 6000, 9000, VERTEX, 8000, 7000, + VERTEX, 8000, 1000, END, OUTLINEPOLYGON, FL_GRAY, + VERTEX, 6000, 9000, VERTEX, 6000, 7000, + VERTEX, 8000, 7000, END, + COLOR, FL_BLACK, LINE, VERTEX, 6000, 7000, + VERTEX, 8000, 7000, VERTEX, 8000, 1000, + VERTEX, 2000, 1000, END, LINE, VERTEX, 3000, 7000, + VERTEX, 5000, 7000, END, LINE, VERTEX, 3000, 6000, + VERTEX, 5000, 6000, END, LINE, VERTEX, 3000, 5000, + VERTEX, 7000, 5000, END, LINE, VERTEX, 3000, 4000, + VERTEX, 7000, 4000, END, LINE, VERTEX, 3000, 3000, + VERTEX, 7000, 3000, END, LINE, VERTEX, 3000, 2000, + VERTEX, 7000, 2000, END, + END + }; + static short image[] = // Image file icon + { + COLOR, 256, OUTLINEPOLYGON, FL_GRAY, + VERTEX, 2000, 1000, VERTEX, 2000, 9000, + VERTEX, 6000, 9000, VERTEX, 8000, 7000, + VERTEX, 8000, 1000, END, OUTLINEPOLYGON, FL_GRAY, + VERTEX, 6000, 9000, VERTEX, 6000, 7000, + VERTEX, 8000, 7000, END, + COLOR, FL_BLACK, LINE, VERTEX, 6000, 7000, + VERTEX, 8000, 7000, VERTEX, 8000, 1000, + VERTEX, 2000, 1000, END, + COLOR, FL_RED, POLYGON, VERTEX, 3500, 2500, + VERTEX, 3000, 3000, VERTEX, 3000, 4000, + VERTEX, 3500, 4500, VERTEX, 4500, 4500, + VERTEX, 5000, 4000, VERTEX, 5000, 3000, + VERTEX, 4500, 2500, END, + COLOR, FL_GREEN, POLYGON, VERTEX, 5500, 2500, + VERTEX, 5000, 3000, VERTEX, 5000, 4000, + VERTEX, 5500, 4500, VERTEX, 6500, 4500, + VERTEX, 7000, 4000, VERTEX, 7000, 3000, + VERTEX, 6500, 2500, END, + COLOR, FL_BLUE, POLYGON, VERTEX, 4500, 3500, + VERTEX, 4000, 4000, VERTEX, 4000, 5000, + VERTEX, 4500, 5500, VERTEX, 5500, 5500, + VERTEX, 6000, 5000, VERTEX, 6000, 4000, + VERTEX, 5500, 3500, END, + END + }; + static short dir[] = // Directory icon + { + COLOR, 256, POLYGON, VERTEX, 1000, 1000, + VERTEX, 1000, 7500, VERTEX, 9000, 7500, + VERTEX, 9000, 1000, END, + POLYGON, VERTEX, 1000, 7500, VERTEX, 2500, 9000, + VERTEX, 5000, 9000, VERTEX, 6500, 7500, END, + COLOR, FL_WHITE, LINE, VERTEX, 1500, 1500, + VERTEX, 1500, 7000, VERTEX, 9000, 7000, END, + COLOR, FL_BLACK, LINE, VERTEX, 9000, 7500, + VERTEX, 9000, 1000, VERTEX, 1000, 1000, END, + COLOR, FL_GRAY, LINE, VERTEX, 1000, 1000, + VERTEX, 1000, 7500, VERTEX, 2500, 9000, + VERTEX, 5000, 9000, VERTEX, 6500, 7500, + VERTEX, 9000, 7500, END, + END + }; + + + // Add symbols if they haven't been added already... + if (!init) + { + if (!access("/usr/share/mimelnk", F_OK)) + { + // Load KDE icons... + icon = new Fl_FileIcon("*", Fl_FileIcon::PLAIN); + icon->load_xpm("/usr/share/icons/unknown.xpm"); + + load_kde_icons("/usr/share/mimelnk"); + } + else if (!access("/usr/share/icons/folder.xpm", F_OK)) + { + // Load GNOME icons... + icon = new Fl_FileIcon("*", Fl_FileIcon::PLAIN); + icon->load_xpm("/usr/share/icons/page.xpm"); + + icon = new Fl_FileIcon("*", Fl_FileIcon::DIRECTORY); + icon->load_xpm("/usr/share/icons/folder.xpm"); + } + else if (!access("/usr/dt/appconfig/icons", F_OK)) + { + // Load CDE icons... + icon = new Fl_FileIcon("*", Fl_FileIcon::PLAIN); + icon->load_xpm("/usr/dt/appconfig/icons/C/Dtdata.m.pm"); + + icon = new Fl_FileIcon("*", Fl_FileIcon::DIRECTORY); + icon->load_xpm("/usr/dt/appconfig/icons/C/DtdirB.m.pm"); + + icon = new Fl_FileIcon("core", Fl_FileIcon::PLAIN); + icon->load_xpm("/usr/dt/appconfig/icons/C/Dtcore.m.pm"); + + icon = new Fl_FileIcon("*.{bmp|bw|gif|jpg|pbm|pcd|pgm|ppm|png|ras|rgb|tif|xbm|xpm}", Fl_FileIcon::PLAIN); + icon->load_xpm("/usr/dt/appconfig/icons/C/Dtimage.m.pm"); + + icon = new Fl_FileIcon("*.{eps|pdf|ps}", Fl_FileIcon::PLAIN); + icon->load_xpm("/usr/dt/appconfig/icons/C/Dtps.m.pm"); + + icon = new Fl_FileIcon("*.ppd", Fl_FileIcon::PLAIN); + icon->load_xpm("/usr/dt/appconfig/icons/C/DtPrtpr.m.pm"); + } + else if (!access("/usr/lib/filetype", F_OK)) + { + // Load SGI icons... + icon = new Fl_FileIcon("*", Fl_FileIcon::PLAIN); + icon->load_fti("/usr/lib/filetype/iconlib/generic.doc.fti"); + + icon = new Fl_FileIcon("*", Fl_FileIcon::DIRECTORY); + icon->load_fti("/usr/lib/filetype/iconlib/generic.folder.closed.fti"); + + icon = new Fl_FileIcon("core", Fl_FileIcon::PLAIN); + icon->load_fti("/usr/lib/filetype/default/iconlib/CoreFile.fti"); + + icon = new Fl_FileIcon("*.{bmp|bw|gif|jpg|pbm|pcd|pgm|ppm|png|ras|rgb|tif|xbm|xpm}", Fl_FileIcon::PLAIN); + icon->load_fti("/usr/lib/filetype/system/iconlib/ImageFile.fti"); + + if (!access("/usr/lib/filetype/install/iconlib/acroread.doc.fti", F_OK)) + { + icon = new Fl_FileIcon("*.{eps|ps}", Fl_FileIcon::PLAIN); + icon->load_fti("/usr/lib/filetype/system/iconlib/PostScriptFile.closed.fti"); + + icon = new Fl_FileIcon("*.pdf", Fl_FileIcon::PLAIN); + icon->load_fti("/usr/lib/filetype/install/iconlib/acroread.doc.fti"); + } + else + { + icon = new Fl_FileIcon("*.{eps|pdf|ps}", Fl_FileIcon::PLAIN); + icon->load_fti("/usr/lib/filetype/system/iconlib/PostScriptFile.closed.fti"); + } + + if (!access("/usr/lib/filetype/install/iconlib/html.fti", F_OK)) + { + icon = new Fl_FileIcon("*.{htm|html|shtml}", Fl_FileIcon::PLAIN); + icon->load_fti("/usr/lib/filetype/iconlib/generic.doc.fti"); + icon->load_fti("/usr/lib/filetype/install/iconlib/html.fti"); + } + + if (!access("/usr/lib/filetype/install/iconlib/color.ps.idle.fti", F_OK)) + { + icon = new Fl_FileIcon("*.ppd", Fl_FileIcon::PLAIN); + icon->load_fti("/usr/lib/filetype/install/iconlib/color.ps.idle.fti"); + } + } + else + { + // Create the default icons... + new Fl_FileIcon("*", Fl_FileIcon::PLAIN, sizeof(plain) / sizeof(plain[0]), plain); + new Fl_FileIcon("*.{bmp|bw|gif|jpg|pbm|pcd|pgm|ppm|png|ras|rgb|tif|xbm|xpm}", Fl_FileIcon::PLAIN, + sizeof(image) / sizeof(image[0]), image); + new Fl_FileIcon("*", Fl_FileIcon::DIRECTORY, sizeof(dir) / sizeof(dir[0]), dir); + } + + // Mark things as initialized... + init = 1; + } +} + + +// +// 'load_kde_icons()' - Load KDE icon files. +// + +static void +load_kde_icons(const char *directory) // I - Directory to load +{ + int i; // Looping var + int n; // Number of entries in directory + dirent **entries; // Entries in directory + char full[1024]; // Full name of file + + + entries = (dirent **)0; + n = filename_list(directory, &entries); + + for (i = 0; i < n; i ++) + { + if (entries[i]->d_name[0] != '.') + { + strcpy(full, directory); + strcat(full,"/"); + strcat(full, entries[i]->d_name); + + if (filename_isdir(full)) + load_kde_icons(full); + else + load_kde_mimelnk(full); + } + + free((void *)entries[i]); + } + + free((void*)entries); +} + + +// +// 'load_kde_mimelnk()' - Load a KDE "mimelnk" file. +// + +static void +load_kde_mimelnk(const char *filename) +{ + FILE *fp; + char tmp[256]; + char iconfilename[1024]; + char pattern[1024]; + char mimetype[1024]; + char *val; + char full_iconfilename[1024]; + Fl_FileIcon *icon; + + + if ((fp = fopen(filename, "rb")) != NULL) + { + while (fgets(tmp, sizeof(tmp), fp)) + { + if ((val = get_kde_val(tmp, "Icon")) != NULL) + strcpy(iconfilename, val); + else if ((val = get_kde_val(tmp, "MimeType")) != NULL) + strcpy(mimetype, val); + else if ((val = get_kde_val(tmp, "Patterns")) != NULL) + strcpy(pattern, val); + } + + if (iconfilename && pattern) + { + sprintf(full_iconfilename, "/usr/share/icons/%s", iconfilename); + + if (strcmp(mimetype, "inode/directory") == 0) + icon = new Fl_FileIcon("*", Fl_FileIcon::DIRECTORY); + else + icon = new Fl_FileIcon(kde_to_fltk_pattern(pattern), Fl_FileIcon::PLAIN); + + icon->load_xpm(full_iconfilename); + } + + fclose(fp); + } +} + + +// +// 'kde_to_fltk_pattern()' - Convert a KDE pattern to a FLTK pattern. +// + +static char * +kde_to_fltk_pattern(const char *kdepattern) +{ + char *pattern, + *patptr; + + + pattern = (char *)malloc(strlen(kdepattern) + 3); + strcpy(pattern, "{"); + strcat(pattern, kdepattern); + + if (pattern[strlen(pattern) - 1] == ';') + pattern[strlen(pattern) - 1] = '\0'; + + strcat(pattern, "}"); + + for (patptr = pattern; *patptr; patptr ++) + if (*patptr == ';') + *patptr = '|'; + + return (pattern); +} + + +// +// 'get_kde_val()' - Get a KDE value. +// + +static char * +get_kde_val(char *str, + const char *key) +{ + while (*str == *key) + { + str ++; + key ++; + } + + if (*key == '\0' && *str == '=') + { + if (str[strlen(str) - 1] == '\n') + str[strlen(str) - 1] = '\0'; + + return (str + 1); + } + + return ((char *)0); +} + + +// +// End of "$Id: Fl_FileIcon.cxx,v 1.10.2.1 2001/08/02 16:17:04 easysw Exp $". // diff --git a/src/Fl_Input.cxx b/src/Fl_Input.cxx index c4950f4d9..6dea29917 100644 --- a/src/Fl_Input.cxx +++ b/src/Fl_Input.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Input.cxx,v 1.10.2.15 2001/01/28 06:57:33 spitzak Exp $" +// "$Id: Fl_Input.cxx,v 1.10.2.15.2.1 2001/08/02 16:17:04 easysw Exp $" // // Input widget for the Fast Light Tool Kit (FLTK). // @@ -239,7 +239,14 @@ int Fl_Input::handle(int event) { break; case FL_KEYBOARD: - return handle_key(); + if (Fl::event_key() == FL_Tab && mark() != position()) { + // Set the current cursor position to the end of the selection... + if (mark() > position()) + position(mark()); + else + position(position()); + return (1); + } else return handle_key(); case FL_PUSH: if (Fl::focus() != this) { @@ -277,5 +284,5 @@ Fl_Input::Fl_Input(int x, int y, int w, int h, const char *l) } // -// End of "$Id: Fl_Input.cxx,v 1.10.2.15 2001/01/28 06:57:33 spitzak Exp $". +// End of "$Id: Fl_Input.cxx,v 1.10.2.15.2.1 2001/08/02 16:17:04 easysw Exp $". // diff --git a/src/Makefile b/src/Makefile index 15d1c3d86..f49143974 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ # -# "$Id: Makefile,v 1.18.2.14.2.2 2001/08/02 15:31:59 easysw Exp $" +# "$Id: Makefile,v 1.18.2.14.2.3 2001/08/02 16:17:04 easysw Exp $" # # Library makefile for the Fast Light Tool Kit (FLTK). # @@ -40,6 +40,10 @@ CPPFILES = \ Fl_Counter.cxx \ Fl_Dial.cxx \ Fl_Double_Window.cxx \ + Fl_FileBrowser.cxx \ + Fl_FileChooser.cxx \ + Fl_FileChooser2.cxx \ + Fl_FileIcon.cxx \ Fl_Gl_Choice.cxx \ Fl_Gl_Overlay.cxx \ Fl_Gl_Window.cxx \ @@ -209,5 +213,5 @@ install: $(LIBRARY) $(DSONAME) ln -s FL $(includedir)/Fl # -# End of "$Id: Makefile,v 1.18.2.14.2.2 2001/08/02 15:31:59 easysw Exp $". +# End of "$Id: Makefile,v 1.18.2.14.2.3 2001/08/02 16:17:04 easysw Exp $". # diff --git a/src/fl_file_chooser.cxx b/src/fl_file_chooser.cxx index 7b5cb2380..271810db8 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 2001/05/05 23:39:01 spitzak Exp $" +// "$Id: fl_file_chooser.cxx,v 1.10.2.10.2.1 2001/08/02 16:17:04 easysw Exp $" // // File chooser widget for the Fast Light Tool Kit (FLTK). // @@ -25,21 +25,9 @@ #include #include +#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include +static Fl_FileChooser *fc = (Fl_FileChooser *)0; static void default_callback(const char*) {} static void (*current_callback)(const char*) = default_callback; @@ -47,591 +35,24 @@ void fl_file_chooser_callback(void (*cb)(const char*)) { current_callback = cb ? cb : default_callback; } -// "File Chooser Browser" widget: -class FCB : public Fl_Browser_ { - void* item_first() const ; - void* item_next(void*) const ; - void* item_prev(void*) const ; - int item_height(const dirent*, int) const ; - int item_height(void*) const ; - int item_width(const dirent*) const ; - int item_width(void*) const ; - int item_quick_height(void*) const ; - int incr_height() const ; - void item_draw(void*, int, int, int, int) const ; - int checkdir(const dirent*, char*) const ; - void draw(); - void clear_prev(); -public: - char listed[FL_PATH_MAX];// current dir & starname - int dirend; // points after last / before starname - int nameend; // length to trailing '*' or '\0' - const char* pattern; // default pattern - dirent** list; // the file names - dirent** last; // pointer after end of list - const char* message; // message if no file names - char preved[FL_PATH_MAX];// directory listed in prev - dirent** prev; // cached list of another directory - dirent** prev_last; // end of that list - int prev_count; - FCB(int x, int y, int w, int h) : Fl_Browser_(x, y, w, h, 0) { - type(FL_HOLD_BROWSER); - listed[0] = 0; - dirend = nameend = 1; - pattern = 0; - list = prev = 0; - message = 0; - } - // ~FCB nyi - void clear(); - void set(const char*); - int get(char*); -}; - -// "File Chooser Window" widget: -class FCW : public Fl_Window { -public: - int handle(int); - Fl_Input input; - Fl_Button* ok_button; - Fl_Button* cancel_button; - Fl_Button* normal_button; - FCB browser; - FCW(); -}; - -/* Files are marked as being directories by replacing the trailing null - with a '/' if it is a directory, a '\001' if it is *not* a directory. - An item has height (and is thus selectable) if it is either a directory - or if it matches the pattern. Quick-height assummes all unknown files - are directories, and thus saves the time needed to do a stat(). -*/ - -// return pointer to last character: -static const char* end_of_name(const dirent* d) { -#if HAVE_DIRENT_H - const char* e; - for (e = d->d_name; ;e++) switch (*e) { - case 0: case 1: case '/': return e; - } -#else - // warning: clobbers byte after end of name - return d->d_name + d->d_namelen; -#endif -} - -// return true if item is directory, when given pointer to last character: -int FCB::checkdir(const dirent* d, char* e) const { - if (*e == 1) return 0; - if (*e == '/') return 1; - char buf[FL_PATH_MAX]; - memcpy(buf, listed, dirend); - memcpy(buf+dirend, d->d_name, e-d->d_name); - *(buf+dirend+(e-d->d_name)) = 0; - if (filename_isdir(buf)) { - *e = '/'; return 1; - } else { - *e = 1; return 0; - } -} - -void* FCB::item_first() const {return list;} - -void* FCB::item_next(void* p) const { - if ((dirent**)p+1 >= last) return 0; - return (dirent**)p+1; -} - -void* FCB::item_prev(void* p) const { - if ((dirent**)p <= list) return 0; - return ((dirent**)p)-1; -} - -#ifdef _MSC_VER -#pragma optimize("a",off) // without this it does not change *e -#endif -static int ido_matching(const dirent* p, const char* e, const char* n) { - // replace / or 1 at end with 0 and do match, then put back. yukko - int save = *e; *(char*)e = 0; - int r = filename_match(p->d_name, n); - *(char*)e = save; - return(r); -} -#ifdef _MSC_VER -#pragma optimize("",on) -#endif - -int FCB::incr_height() const {return textsize()+2;} - -int FCB::item_height(const dirent* p, int slow) const { - const char* e = end_of_name(p); - if (listed[dirend]) { -// if (p->d_name[0]=='.' && listed[dirend]!='.') return 0; - if (listed[nameend-1]=='/') { - if (slow ? !checkdir(p, (char*)e) : *e==1) return 0; - ((char*)listed)[nameend-1] = 0; - int r = ido_matching(p, e, listed+dirend); - ((char*)listed)[nameend-1] = '/'; - if (!r) return 0; - } else { - if (!ido_matching(p, e, listed+dirend)) return 0; - } - } else { - if (p->d_name[0]=='.') return 0; - if (pattern && (slow ? !checkdir(p, (char*)e) : *e==1) && - !ido_matching(p, e, pattern)) return 0; - } - return textsize()+2; -} - -int FCB::item_height(void* x) const { - return item_height(*(const dirent**)x, 1); -} - -int FCB::item_quick_height(void* x) const { - return item_height(*(const dirent**)x, 0); -} - -void FCB::item_draw(void* v, int x, int y, int, int h) const { - const dirent* p = *(const dirent**)v; - const char* e = end_of_name(p); - if (checkdir(p, (char*)e)) e++; - if (v == selection()) fl_color(contrast(textcolor(), selection_color())); - else fl_color(textcolor()); - fl_font(textfont(), textsize()); - fl_draw(p->d_name, e-p->d_name, x+4, y+h-3); -} - -int FCB::item_width(const dirent* p) const { - const char* e = end_of_name(p); if (*e == '/') e++; - fl_font(textfont(), textsize()); - return (int)fl_width(p->d_name, e-p->d_name)+4; -} - -int FCB::item_width(void* x) const { - return item_width(*(const dirent**)x); -} - -// "get" the current value by copying the name of the selected file -// or if none are selected, by copying as many common letters as -// possible of the matched file list: -int FCB::get(char* buf) { - dirent** q = (dirent**)selection(); // the file to copy from - int n = 0; // number of letters - if (q) { // a file is selected - const char* e = end_of_name(*q); - n = e - (*q)->d_name; - if (*e == '/') n++; - } else { // do filename completion - for (q = list; q < last && !item_height(*q, 0); q++); - if (q < last) { - const char* e = end_of_name(*q); - n = e - (*q)->d_name; - if (*e == '/') n++; - for (dirent** r = q+1; n && r < last; r++) { - if (!item_height(*r, 0)) continue; - int i; -#ifdef WIN32 - for (i=0; id_name[i])==tolower((*r)->d_name[i]); i++) {} -#else - for (i=0; id_name[i]==(*r)->d_name[i]; i++) {} -#endif - n = i; - } - } - } - if (n) { - memcpy(buf, listed, dirend); - memcpy(buf+dirend, (*q)->d_name, n); - buf[dirend+n]=0; - } - return n; -} - -// "set" the current value by changing the directory being listed and -// changing the highlighted item, if possible: -void FCB::set(const char* buf) { - - int bufdirend; - int ispattern = 0; - const char* c = buf; - for (bufdirend=0; *c;) switch(*c++) { - case '?': case '[': case '*': case '{': ispattern = 1; goto BREAK; -#if defined(WIN32) || defined(__EMX__) && !defined(__CYGWIN__) - case '\\': -#endif - case '/': bufdirend=c-buf; break; - } -#if defined(WIN32) || defined(__EMX__) && !defined(__CYGWIN__) - if ((!bufdirend) && isalpha(buf[0]) && (buf[1]==':')) bufdirend = 2; -#endif - BREAK: - int bufend = strlen(buf); - if (bufend<=bufdirend) ispattern = 1; - - // if directory is different, change list to xxx/ : - if (bufdirend != dirend || strncmp(buf, listed, bufdirend)) { - if (prev && - preved[bufdirend]==0 && !strncmp(buf, preved, bufdirend)) { - strcpy(preved, listed); preved[dirend] = 0; - dirent** t; - t = prev; prev = list; list = t; - t = prev_last; prev_last = last; last = t; - strcpy(listed, buf); - dirend = nameend = bufdirend; - message = 0; - } else { - if (list) { - clear_prev(); - strcpy(preved, listed); preved[dirend]=0; - prev = list; - prev_last = last; - } - list = last = 0; - message = "reading..."; redraw(); Fl::flush(); redraw(); - strcpy(listed, buf); - dirend = nameend = bufdirend; - listed[dirend] = listed[dirend+1] = 0; - int n = filename_list(dirend ? listed : ".", &list); - if (n < 0) { - if (errno==ENOENT) message = "No such directory"; - else message = strerror(errno); - n = 0; list = 0; - } else message = 0; - last = list+n; - } - if (list && last <= list+2) message = "Empty directory"; - new_list(); - } - - dirent** q = 0; // will point to future selection - int any = 0; // true if any names shown - - // do we match one item in the previous list? - if (!ispattern && bufend >= nameend) { - for (q = list; ; q++) { - if (q >= last) {q = 0; break;} - if (item_height(*q, 0)==0) continue; - any = 1; - const char* a = (*q)->d_name; - const char* b = buf+bufdirend; -#if defined(WIN32) && !defined(__CYGWIN__) - while (*b && tolower(*a)==tolower(*b)) {a++; b++;} -#else - while (*b && *a==*b) {a++; b++;} -#endif - if (!*b && (*a==0 || /* *a=='/' ||*/ *a==1)) break; - } - } - - // no, change the list pattern to the new text + a star: - if (!q) { - strcpy(listed+dirend, buf+bufdirend); - nameend = bufend; - if (!ispattern) {listed[nameend]='*'; listed[nameend+1]=0;} - any = 0; - // search again for an exact match: - for (q = list; ; q++) { - if (q >= last) {q = 0; break;} - if (item_height(*q, 0)==0) continue; - any = 1; - const char* a = (*q)->d_name; - const char* b = buf+bufdirend; -#if defined(WIN32) && !defined(__CYGWIN__) - while (*b && tolower(*a)==tolower(*b)) {a++; b++;} -#else - while (*b && *a==*b) {a++; b++;} -#endif - if (!*b && (*a==0 || /* *a=='/' ||*/ *a==1)) break; - } - new_list(); - } - - if (any) message = 0; - else if (!message) message = "No matching files"; - select_only(q); - if (q) current_callback(buf); -} - -void FCB::draw() { - if (!message) { - Fl_Browser_::draw(); - if (full_height() > 0) return; - message = "No matching files"; - } - Fl_Boxtype b = box(); if (!b) b = FL_DOWN_BOX; - draw_box(b,color()); - fl_color(FL_INACTIVE_COLOR); - fl_font(textfont(), textsize()); - fl_draw(message, x()+7, y()+3, w(), h()-3, FL_ALIGN_TOP_LEFT); - // insure scrollbars are redrawn if error message goes away: - scrollbar.redraw(); - hscrollbar.redraw(); -} - -void FCB::clear_prev() { - if (prev) { - for (dirent**p=prev_last-1; p>=prev; p--) free((void*)*p); - free((void*)prev); - prev = prev_last = 0; - } -} - -void FCB::clear() { - if (list) { - for (dirent**p=last-1; p>=list; p--) free((void*)*p); - free((void*)list); - list = last = 0; - } - clear_prev(); - listed[0] = 0; dirend = 1; -} - -//////////////////////////////////////////////////////////////// - -static void fcb_cb(Fl_Widget*, void* v) { - FCW* w = (FCW*)v; - char buf[FL_PATH_MAX]; - if (w->browser.get(buf)) { - w->input.value(buf); - w->input.position(10000); -// w->input.position(10000, w->browser.dirend); - if (Fl::event_button()==1) { - if (Fl::event_clicks()) w->ok_button->do_callback(); - else w->browser.set(buf); - } else { - current_callback(buf); - } - } -} - -static void tab_cb(Fl_Widget*, void* v) { - FCW* w = (FCW*)v; - char buf[FL_PATH_MAX]; - if (w->browser.get(buf)) { - w->input.value(buf); - w->input.position(10000); - w->browser.set(buf); - } -} - -#if defined(WIN32) || defined(__EMX__) && !defined(__CYGWIN__) -// ':' needs very special handling! -static inline int isdirsep(char c) {return c=='/' || c=='\\';} -#else -#define isdirsep(c) ((c)=='/') -#endif - -static void input_cb(Fl_Widget*, void* v) { - FCW* w = (FCW*)v; - const char* buf = w->input.value(); - char localbuf[FL_PATH_MAX]; - if (buf[0] && isdirsep(buf[w->input.size()-1]) - && filename_expand(localbuf, buf)) { - buf = localbuf; - w->input.value(localbuf); - w->input.position(10000); - } - w->browser.set(buf); -} - -static void up_cb(Fl_Widget*wd, void*) { // the .. button - FCW* w = (FCW*)(wd->window()); - char* p; - const char* newname; - char buf[FL_PATH_MAX]; - p = w->browser.listed+w->browser.dirend-1; // point right before last '/' - if (p < w->browser.listed) - newname = "../"; // go up from current directory - else { - for (; p>w->browser.listed; p--) if (isdirsep(*(p-1))) break; - if (isdirsep(*p) || *p=='.' && - (isdirsep(p[1]) || p[1]=='.' && isdirsep(p[2]))) { - p = w->browser.listed+w->browser.dirend; - memcpy(buf, w->browser.listed, p-w->browser.listed); - strcpy(buf+(p-w->browser.listed), "../"); - } else { - memcpy(buf, w->browser.listed, p-w->browser.listed); - buf[p-w->browser.listed] = 0; - } - newname = buf; - } - w->input.value(newname); - w->input.position(10000); - w->browser.set(newname); -} - -static void dir_cb(Fl_Widget* obj, void* v) { // directory buttons - FCW* w = (FCW*)(obj->window()); - char buf[FL_PATH_MAX]; - filename_expand(buf, (const char*)v); - w->input.value(buf); - w->input.position(10000); - w->browser.set(buf); -} - -static void working_cb(Fl_Widget* obj, void*) { // directory buttons - FCW* w = (FCW*)(obj->window()); - char buf[FL_PATH_MAX]; - filename_absolute(buf, ""); - w->input.value(buf); - w->input.position(10000); - w->browser.set(buf); -} - -static void files_cb(Fl_Widget* obj, void* v) { // file pattern buttons - FCW* w = (FCW*)(obj->window()); - char buf[FL_PATH_MAX]; - strcpy(buf, w->input.value()); - char* q = buf+w->browser.dirend; - if (v) strcpy(q, (char*)v); else *q = 0; - w->input.value(buf); - w->input.position(10000, w->browser.dirend); - w->browser.set(buf); -} - -/*----------------------- The Main Routine ----------------------*/ -#define HEIGHT_BOX (4*WIDTH_SPC+HEIGHT_BUT+HEIGHT_INPUT+HEIGHT_BROWSER) -#define HEIGHT_BUT 23 -#define HEIGHT_INPUT 23 -#define HEIGHT_BROWSER (9*HEIGHT_BUT+2) // must be > buttons*HEIGHT_BUT -#define WIDTH_BOX (3*WIDTH_SPC+WIDTH_BUT+WIDTH_BROWSER) -#define WIDTH_BROWSER 350 -#define WIDTH_BUT 125 -#define WIDTH_OK 60 -#define WIDTH_SPC 5 - -int FCW::handle(int event) { - if (Fl_Window::handle(event)) return 1; - if (event==FL_KEYBOARD && Fl::event_key()==FL_Tab) { - tab_cb(this, this); - return 1; - } - return 0; -} - -// set this to make extra directory-jumping button: -static Fl_Button* extra_button; -const char* fl_file_chooser_button; -const char* fl_file_chooser_data; -extern const char* fl_ok; -extern const char* fl_cancel; - -FCW::FCW() : Fl_Window(WIDTH_BOX, HEIGHT_BOX), - input(WIDTH_SPC, HEIGHT_BOX-HEIGHT_BUT-2*WIDTH_SPC-HEIGHT_INPUT, - WIDTH_BOX-2*WIDTH_SPC, HEIGHT_INPUT, 0), - browser(2*WIDTH_SPC+WIDTH_BUT, WIDTH_SPC, - WIDTH_BROWSER, HEIGHT_BROWSER) -{ - int but_y = WIDTH_SPC; - input.callback(input_cb, this); - input.when(FL_WHEN_CHANGED); - // add(browser); - browser.callback(fcb_cb, this); - - begin(); - Fl_Widget* obj; - obj = ok_button = new Fl_Return_Button( - WIDTH_BOX-2*(WIDTH_SPC+WIDTH_OK), HEIGHT_BOX-WIDTH_SPC-HEIGHT_BUT, - WIDTH_OK, HEIGHT_BUT, fl_ok); - obj = cancel_button = new Fl_Button( - WIDTH_BOX-WIDTH_SPC-WIDTH_OK, HEIGHT_BOX-WIDTH_SPC-HEIGHT_BUT, - WIDTH_OK, HEIGHT_BUT, fl_cancel); - cancel_button->shortcut("^["); - - obj=new Fl_Button(WIDTH_SPC,but_y,WIDTH_BUT,HEIGHT_BUT, "&Up one directory"); - obj->callback(up_cb); - but_y += HEIGHT_BUT; - - obj = new Fl_Button(WIDTH_SPC, but_y, WIDTH_BUT, HEIGHT_BUT, "&~ Home"); - obj->callback(dir_cb, (void*)"~/"); - but_y += HEIGHT_BUT; - - obj = new Fl_Button(WIDTH_SPC, but_y, WIDTH_BUT, HEIGHT_BUT, "&/ Root"); - obj->callback(dir_cb, (void*)"/"); - but_y += HEIGHT_BUT; - - obj=new Fl_Button(WIDTH_SPC, but_y, WIDTH_BUT, HEIGHT_BUT, "&Current dir"); - obj->callback(working_cb); - but_y += HEIGHT_BUT; - - if (fl_file_chooser_button) { - obj = extra_button = new Fl_Button(WIDTH_SPC,but_y,WIDTH_BUT,HEIGHT_BUT,fl_file_chooser_button); - obj->callback(dir_cb, (void*)fl_file_chooser_button); - but_y += HEIGHT_BUT; - } - - normal_button = new Fl_Button(WIDTH_SPC, but_y, WIDTH_BUT, HEIGHT_BUT, ""); - normal_button->callback(files_cb, 0); - but_y += HEIGHT_BUT; - - obj = new Fl_Button(WIDTH_SPC,but_y, WIDTH_BUT, HEIGHT_BUT, "&All files"); - obj->callback(files_cb, (void*)"*"); - but_y += HEIGHT_BUT; - - obj = new Fl_Button(WIDTH_SPC,but_y,WIDTH_BUT,HEIGHT_BUT, "&Hidden files"); - obj->callback(files_cb, (void*)"."); - but_y += HEIGHT_BUT; - - obj = new Fl_Button(WIDTH_SPC,but_y,WIDTH_BUT,HEIGHT_BUT, "&Directories"); - obj->callback(files_cb, (void*)"*/"); - but_y += HEIGHT_BUT; - - resizable(new Fl_Box(browser.x(), but_y, - ok_button->x()-browser.x(), - browser.y()+browser.h()-but_y)); - // add(input); // put last for better draw() speed - end(); - set_modal(); -} - char* fl_file_chooser(const char* message, const char* pat, const char* fname) { - static FCW* f; if (!f) f = new FCW(); - f->ok_button->label(fl_ok); - f->cancel_button->label(fl_cancel); - if (extra_button) { - extra_button->label(fl_file_chooser_button); - extra_button->user_data((void*)(fl_file_chooser_data ? fl_file_chooser_data : fl_file_chooser_button)); + if (!fc) fc = new Fl_FileChooser(fname, pat, Fl_FileChooser::CREATE, message); + else { + fc->filter(pat); + fc->value(fname); + fc->label(message); } - if (pat && !*pat) pat = 0; - if (fname && *fname) { - f->input.value(fname); - } else if (f->browser.pattern != pat && (!pat || !f->browser.pattern || - strcmp(pat,f->browser.pattern))) { - // if pattern is different, remove name but leave old directory: - const char* p = f->input.value(); - const char* q = filename_name(p); - f->input.value(p, q-p); - } - f->browser.pattern = pat; - f->normal_button->label(pat ? pat : "visible files"); - f->normal_button->user_data((void*)(pat ? pat : 0)); - f->browser.set(f->input.value()); - f->input.position(10000, f->browser.dirend); + fc->show(); - f->label(message); - f->hotspot(f); - f->show(); - int ok = 0; - for (;;) { + while (fc->visible()) Fl::wait(); - Fl_Widget* o = Fl::readqueue(); - if (o == f->ok_button) {ok = 1; break;} - else if (o == f->cancel_button || o == f) break; - } - f->hide(); - f->browser.clear(); - if (!ok) return 0; - const char* r = f->input.value(); - const char* p; - for (p=r+f->browser.dirend; *p; p++) - if (*p=='*' || *p=='?' || *p=='[' || *p=='{') return 0; - return (char*)r; + return ((char *)fc->value()); } + // -// End of "$Id: fl_file_chooser.cxx,v 1.10.2.10 2001/05/05 23:39:01 spitzak Exp $". +// End of "$Id: fl_file_chooser.cxx,v 1.10.2.10.2.1 2001/08/02 16:17:04 easysw Exp $". // diff --git a/src/makedepend b/src/makedepend index 334ec39d3..3758c7b6d 100644 --- a/src/makedepend +++ b/src/makedepend @@ -48,6 +48,12 @@ Fl_Dial.o: ../FL/Fl_Valuator.H ../FL/Fl_Widget.H ../FL/fl_draw.H ../FL/math.h Fl_Double_Window.o: ../config.h ../FL/Fl.H ../FL/Enumerations.H Fl_Double_Window.o: ../FL/Fl_Double_Window.H ../FL/Fl_Window.H ../FL/x.H Fl_Double_Window.o: ../FL/fl_draw.H +Fl_FileBrowser.o: ../FL/fl_draw.H ../FL/Enumerations.H ../FL/filename.H +Fl_FileChooser.o: ../FL/Fl_Bitmap.H +Fl_FileChooser2.o: ../FL/filename.H ../FL/fl_ask.H ../FL/Enumerations.H +Fl_FileChooser2.o: ../FL/x.H ../FL/Fl_Window.H +Fl_FileIcon.o: ../config.h ../FL/Fl_Widget.H ../FL/fl_draw.H +Fl_FileIcon.o: ../FL/Enumerations.H ../FL/filename.H Fl_Gl_Choice.o: ../config.h ../FL/Fl.H ../FL/Enumerations.H ../FL/x.H Fl_Gl_Choice.o: ../FL/Fl_Window.H Fl_Gl_Choice.H Fl_Gl_Overlay.o: ../config.h ../FL/Fl.H ../FL/Enumerations.H ../FL/x.H @@ -198,12 +204,11 @@ fl_draw_pixmap.o: ../FL/x.H ../FL/Fl_Window.H fl_engraved_label.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Widget.H fl_engraved_label.o: ../FL/fl_draw.H fl_file_chooser.o: ../config.h ../FL/fl_file_chooser.H ../FL/Enumerations.H -fl_file_chooser.o: ../FL/Fl.H ../FL/Fl_Window.H ../FL/Fl_Group.H -fl_file_chooser.o: ../FL/Fl_Widget.H ../FL/Fl_Box.H ../FL/Fl_Button.H +fl_file_chooser.o: ../FL/Fl_FileChooser.H ../FL/Fl.H ../FL/Fl_Window.H +fl_file_chooser.o: ../FL/Fl_Group.H ../FL/Fl_Widget.H ../FL/Fl_Button.H fl_file_chooser.o: ../FL/Fl_Return_Button.H ../FL/Fl_Button.H -fl_file_chooser.o: ../FL/Fl_Browser_.H ../FL/Fl_Scrollbar.H ../FL/Fl_Slider.H -fl_file_chooser.o: ../FL/Fl_Valuator.H ../FL/Fl_Input.H ../FL/Fl_Input_.H -fl_file_chooser.o: ../FL/fl_draw.H ../FL/filename.H +fl_file_chooser.o: ../FL/Fl_Input.H ../FL/Fl_Input_.H ../FL/Fl_Choice.H +fl_file_chooser.o: ../FL/Fl_Menu_.H ../FL/Fl_Menu_Item.H ../FL/fl_ask.H fl_font.o: ../config.h ../FL/Fl.H ../FL/Enumerations.H ../FL/fl_draw.H fl_font.o: ../FL/x.H ../FL/Fl_Window.H Fl_Font.H fl_labeltype.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Widget.H