FileIcon, FileBrowser, FileChooser stuff.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1517 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet 2001-08-02 16:17:04 +00:00
parent 836d2fac26
commit 75b6b221ce
15 changed files with 1479 additions and 1059 deletions

View File

@ -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 $".
//

View File

@ -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 <FL/Fl_Browser.H>
# include <FL/Fl_FileIcon.H>
# 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 $".
//

View File

@ -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 <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <FL/Fl_Choice.H>
#include <FL/Fl_Button.H>
#include "filename.H"
#include <FL/Fl_FileBrowser.H>
#include <FL/Fl_FileInput.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Return_Button.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Choice.H>
#include <FL/fl_ask.H>
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);

View File

@ -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 <FL/Fl.H>
# 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 $".
//

View File

@ -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)
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 $".
//

View File

@ -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 $".
//

View File

@ -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 <fltk/Fl_FileBrowser.h>
#include <fltk/fl_draw.h>
#include <fltk/filename.h>
#include <fltk/vsnprintf.h>
#include <FL/Fl_FileBrowser.H>
#include <FL/fl_draw.H>
#include <FL/filename.H>
#include <stdio.h>
#include <stdlib.h>
#include <config.h>
#include <string.h>
#if defined(_WIN32)
#if defined(WIN32)
# include <windows.h>
# include <direct.h>
#endif /* _WIN32 */
#endif /* WIN32 */
#if defined(__EMX__)
#define INCL_DOS
@ -54,6 +55,7 @@
#include <os2.h>
#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;
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)
@ -212,42 +243,117 @@ Fl_FileBrowser::item_draw(void *p, // I - List item data
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());
// 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));
}
}
@ -266,7 +372,7 @@ Fl_FileBrowser::Fl_FileBrowser(int x, // I - Upper-lefthand X coordinate
// 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,19 +402,22 @@ 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);
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 $".
//

View File

@ -1,7 +1,6 @@
// generated by Fast Light User Interface Designer (fluid) version 2.0000
// generated by Fast Light User Interface Designer (fluid) version 1.0100
#include <fltk/Fl_FileChooser.h>
#include <fltk/vsnprintf.h>
#include "../FL/Fl_FileChooser.H"
inline void Fl_FileChooser::cb_window_i(Fl_Window*, void*) {
fileList->deselect();
@ -12,14 +11,34 @@ 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 <fltk/Fl_Bitmap.h>
#include <FL/Fl_Bitmap.H>
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() {

View File

@ -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 <fltk/Fl_FileChooser.h>} {}
decl {\#include <config.h>} {}
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 <stdio.h>}
code2 {\#include <stdlib.h>}
code3 {\#include <string.h>} 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 <fltk/Fl_FileBrowser.h>}
callback {fileListCB();} selected
private xywh {10 45 355 180} type Hold resizable hotspot
code0 {\#include <FL/Fl_FileBrowser.H>}
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 <fltk/Fl_FileInput.h>}
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 <FL/fl_ask.H>}
}
}
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
} {

View File

@ -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:
//
@ -39,24 +39,28 @@
// Include necessary headers.
//
#include <fltk/Fl_FileChooser.h>
#include <fltk/filename.h>
#include <fltk/fl_ask.h>
#include <fltk/vsnprintf.h>
#include <fltk/x.h>
#include <config.h>
#include <errno.h>
#include <FL/Fl_FileChooser.H>
#include <FL/filename.H>
#include <FL/fl_ask.H>
#include <FL/x.H>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <ctype.h>
#if defined(_WIN32)
#if defined(WIN32)
# include <direct.h>
# include <io.h>
#else
# include <unistd.h>
# include <pwd.h>
#endif /* _WIN32 */
#endif /* WIN32 */
//
// 'Fl_FileChooser::directory()' - Set the directory in the file chooser.
@ -71,6 +75,8 @@ Fl_FileChooser::directory(const char *d) // I - Directory to change to
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,13 +182,13 @@ 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);
@ -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,6 +436,8 @@ Fl_FileChooser::fileListCB()
else
{
fileName->value(filename);
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 $".
//

File diff suppressed because it is too large Load Diff

View File

@ -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 $".
//

View File

@ -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 $".
#

View File

@ -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 <config.h>
#include <FL/fl_file_chooser.H>
#include <FL/Fl_FileChooser.H>
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Return_Button.H>
#include <FL/Fl_Browser_.H>
#include <FL/Fl_Input.H>
#include <FL/fl_draw.H>
#include <FL/filename.H>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
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; i<n && tolower((*q)->d_name[i])==tolower((*r)->d_name[i]); i++) {}
#else
for (i=0; i<n && (*q)->d_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 $".
//

View File

@ -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