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
+4 -2
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 $".
//
+13 -20
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 $".
//
+28 -28
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);
+12 -14
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 $".
//
+11 -4
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)
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 $".
//
+5 -5
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 $".
//
+180 -79
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;
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 $".
//
+95 -102
View File
@@ -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 <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();
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 <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() {
+61 -76
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
} {
+99 -91
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:
//
@@ -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 <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.
@@ -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 $".
//
+932 -36
View File
File diff suppressed because it is too large Load Diff
+10 -3
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 $".
//
+6 -2
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 $".
#
+13 -592
View File
File diff suppressed because it is too large Load Diff
+10 -5
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