New Fl_File_Input widget, courtesy of Curtis Edwards old Fl_Input_File

widget (Fl_File_Input is much lighter-weight, and is simpler in function.)

Update file chooser dialog to use new Fl_File_Input widget and always
display absolute path.

Still need to do docos, new screenshots, and update FLUID to support the
new widget.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2145 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet
2002-04-30 21:50:16 +00:00
parent 1f5448409b
commit 8972642109
9 changed files with 468 additions and 150 deletions

View File

@@ -1,5 +1,9 @@
CHANGES IN FLTK 1.1.0rc1
- New Fl_File_Input widget that shows directory
separators with filename in input field.
- The Fl_File_Chooser dialog now shows the absolute path
in the filename field using the Fl_File_Input widget.
- FLUID now keeps track of grid, tooltip, and other
GUI options, along with the last 10 files opened.
- Tooltip windows would show up in the task bar under

View File

@@ -11,7 +11,7 @@
#include <FL/Fl_Button.H>
#include <FL/fl_ask.H>
#include <FL/Fl_File_Browser.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_File_Input.H>
#include <FL/Fl_Return_Button.H>
class Fl_File_Chooser {
@@ -36,9 +36,9 @@ private:
Fl_File_Browser *fileList;
inline void cb_fileList_i(Fl_File_Browser*, void*);
static void cb_fileList(Fl_File_Browser*, void*);
Fl_Input *fileName;
inline void cb_fileName_i(Fl_Input*, void*);
static void cb_fileName(Fl_Input*, void*);
Fl_File_Input *fileName;
inline void cb_fileName_i(Fl_File_Input*, void*);
static void cb_fileName(Fl_File_Input*, void*);
Fl_Return_Button *okButton;
inline void cb_okButton_i(Fl_Return_Button*, void*);
static void cb_okButton(Fl_Return_Button*, void*);

66
FL/Fl_File_Input.H Normal file
View File

@@ -0,0 +1,66 @@
//
// "$Id: Fl_File_Input.H,v 1.1.2.1 2002/04/30 21:50:16 easysw Exp $"
//
// File_Input header file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2002 by Bill Spitzak and others.
// Original version Copyright 1998 by Curtis Edwards.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems to "fltk-bugs@fltk.org".
//
#ifndef Fl_File_Input_H
# define Fl_File_Input_H
# include <FL/Fl_Input.H>
class Fl_File_Input : public Fl_Input
{
Fl_Color errorcolor_;
char ok_entry_;
uchar down_box_;
short buttons_[200];
short pressed_;
void draw_buttons();
int handle_button(int event);
void update_buttons();
public:
FL_EXPORT Fl_File_Input(int,int,int,int,const char *t=0);
FL_EXPORT virtual int handle(int);
FL_EXPORT virtual void draw();
Fl_Boxtype down_box() const { return (Fl_Boxtype)down_box_; }
void down_box(Fl_Boxtype b) { down_box_ = b; }
Fl_Color errorcolor() const { return errorcolor_; }
void errorcolor(Fl_Color c) { errorcolor_ = c; }
FL_EXPORT int value(const char*);
FL_EXPORT int value(const char*, int);
const char *value() { return Fl_Input_::value(); }
};
#endif // !Fl_File_Input_H
//
// End of "$Id: Fl_File_Input.H,v 1.1.2.1 2002/04/30 21:50:16 easysw Exp $".
//

View File

@@ -2,10 +2,6 @@
#include "../FL/Fl_File_Chooser.H"
const char *Fl_File_Chooser::directory_label = "Directory:";
const char *Fl_File_Chooser::filename_label = "Filename:";
const char *Fl_File_Chooser::filter_label = "New Filter?";
inline void Fl_File_Chooser::cb_window_i(Fl_Window*, void*) {
fileList->deselect();
fileName->value("");
@@ -77,10 +73,10 @@ void Fl_File_Chooser::cb_fileList(Fl_File_Browser* o, void* v) {
((Fl_File_Chooser*)(o->parent()->user_data()))->cb_fileList_i(o,v);
}
inline void Fl_File_Chooser::cb_fileName_i(Fl_Input*, void*) {
inline void Fl_File_Chooser::cb_fileName_i(Fl_File_Input*, void*) {
fileNameCB();
}
void Fl_File_Chooser::cb_fileName(Fl_Input* o, void* v) {
void Fl_File_Chooser::cb_fileName(Fl_File_Input* o, void* v) {
((Fl_File_Chooser*)(o->parent()->user_data()))->cb_fileName_i(o,v);
}
@@ -106,7 +102,7 @@ void Fl_File_Chooser::cb_Cancel(Fl_Button* o, void* v) {
Fl_File_Chooser::Fl_File_Chooser(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");
{ Fl_Window* o = window = new Fl_Window(375, 325, "Pick a File");
w = o;
o->callback((Fl_Callback*)cb_window, (void*)(this));
{ Fl_Choice* o = dirMenu = new Fl_Choice(95, 10, 180, 25, "Directory:");
@@ -141,18 +137,18 @@ Fl_File_Chooser::Fl_File_Chooser(const char *d, const char *p, int t, const char
Fl_Group::current()->resizable(o);
w->hotspot(o);
}
{ Fl_Input* o = fileName = new Fl_Input(10, 245, 355, 25, "Filename:");
{ Fl_File_Input* o = fileName = new Fl_File_Input(10, 245, 355, 35, "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);
fileName->label(filename_label);
}
{ Fl_Return_Button* o = okButton = new Fl_Return_Button(200, 280, 75, 25, "OK");
{ Fl_Return_Button* o = okButton = new Fl_Return_Button(200, 290, 75, 25, "OK");
o->callback((Fl_Callback*)cb_okButton);
okButton->label(fl_ok);
}
{ Fl_Button* o = new Fl_Button(285, 280, 80, 25, "Cancel");
{ Fl_Button* o = new Fl_Button(285, 290, 80, 25, "Cancel");
o->callback((Fl_Callback*)cb_Cancel);
o->label(fl_cancel);
}

View File

@@ -1,10 +1,7 @@
# data file for the Fltk User Interface Designer (fluid)
version 1.0100
header_name {../FL/Fl_File_Chooser.H}
code_name {.cxx}
gridx 5
gridy 5
snap 3
code_name {.cxx}
class Fl_File_Chooser {open
} {
decl {enum { SINGLE = 0, MULTI = 1, CREATE = 2, DIRECTORY = 4 };} {public
@@ -16,7 +13,7 @@ class Fl_File_Chooser {open
callback {fileList->deselect();
fileName->value("");
window->hide();} open
private xywh {99 225 375 315} resizable
private xywh {99 225 375 325} resizable
code0 {if (title) window->label(title);}
code1 {\#include <stdio.h>}
code2 {\#include <stdlib.h>}
@@ -62,9 +59,11 @@ if ((f = fl_input(filter_label,
Fl_Input fileName {
label {Filename:}
callback {fileNameCB();}
private xywh {10 245 355 25} align 5 when 8
private xywh {10 245 355 35} align 5 when 8
code0 {fileName->when(FL_WHEN_CHANGED | FL_WHEN_ENTER_KEY_ALWAYS);}
code1 {fileName->label(filename_label);}
code2 {\#include <FL/Fl_File_Input.H>}
class Fl_File_Input
}
Fl_Return_Button okButton {
label OK
@@ -73,7 +72,7 @@ if (callback_)
(*callback_)(this, data_);
window->hide();}
private xywh {200 280 75 25}
private xywh {200 290 75 25}
code0 {\#include <FL/fl_ask.H>}
code1 {okButton->label(fl_ok);}
}
@@ -82,7 +81,7 @@ window->hide();}
callback {fileList->deselect();
fileName->value("");
window->hide();}
private xywh {285 280 80 25}
private xywh {285 290 80 25}
code0 {o->label(fl_cancel);}
}
}
@@ -214,11 +213,11 @@ else
} {
code {return window->visible();} {}
}
decl {static const char *directory_label = "Directory:";} {public
decl {static const char *directory_label;} {public
}
decl {static const char *filename_label = "Filename:";} {public
decl {static const char *filename_label;} {public
}
decl {static const char *filter_label = "New Filter?";} {selected public
decl {static const char *filter_label;} {selected public
}
}

View File

@@ -1,5 +1,5 @@
//
// "$Id: Fl_File_Chooser2.cxx,v 1.1.2.7 2002/03/25 21:08:41 easysw Exp $"
// "$Id: Fl_File_Chooser2.cxx,v 1.1.2.8 2002/04/30 21:50:16 easysw Exp $"
//
// More Fl_File_Chooser routines.
//
@@ -61,12 +61,21 @@
#endif /* WIN32 */
//
// File chooser label strings...
//
const char *Fl_File_Chooser::directory_label = "Directory:";
const char *Fl_File_Chooser::filename_label = "Filename:";
const char *Fl_File_Chooser::filter_label = "New Filter?";
//
// 'Fl_File_Chooser::directory()' - Set the directory in the file chooser.
//
void
Fl_File_Chooser::directory(const char *d) // I - Directory to change to
Fl_File_Chooser::directory(const char *d)// I - Directory to change to
{
char pathname[1024], // Full path of directory
*pathptr, // Pointer into full path
@@ -218,17 +227,8 @@ Fl_File_Chooser::value(int f) // I - File number
if (!(type_ & MULTI))
{
name = fileName->value();
if (name[0] == '\0')
return (NULL);
if (directory_[0]) {
snprintf(pathname, sizeof(pathname), "%s/%s", directory_, name);
} else {
strncpy(pathname, name, sizeof(pathname) - 1);
pathname[sizeof(pathname) - 1] = '\0';
}
return ((const char *)pathname);
if (name[0] == '\0') return NULL;
else return name;
}
for (i = 1, count = 0; i <= fileList->size(); i ++)
@@ -272,11 +272,12 @@ Fl_File_Chooser::value(const char *filename) // I - Filename + directory
// printf("Fl_File_Chooser::value(\"%s\")\n", filename == NULL ? "(null)" : filename);
// See if the filename is actually a directory...
if (filename == NULL || !filename[0] || fl_filename_isdir(filename))
{
// See if the filename is the "My System" directory...
if (filename == NULL || !filename[0]) {
// Yes, just change the current directory...
directory(filename);
fileName->value("");
okButton->deactivate();
return;
}
@@ -285,8 +286,7 @@ Fl_File_Chooser::value(const char *filename) // I - Filename + directory
type(SINGLE);
// See if there is a directory in there...
strncpy(pathname, filename, sizeof(pathname) - 1);
pathname[sizeof(pathname) - 1] = '\0';
fl_filename_absolute(pathname, sizeof(pathname), filename);
if ((slash = strrchr(pathname, '/')) == NULL)
slash = strrchr(pathname, '\\');
@@ -303,17 +303,27 @@ Fl_File_Chooser::value(const char *filename) // I - Filename + directory
slash = pathname;
}
// Set the input field to the remaining portion
fileName->value(slash);
fileName->position(0, strlen(slash));
// Set the input field to the absolute path...
if (slash > pathname) slash[-1] = '/';
fileName->value(pathname);
fileName->position(0, strlen(pathname));
okButton->activate();
// Then find the file in the file list and select it...
count = fileList->size();
fileList->deselect(0);
fileList->redraw();
for (i = 1; i <= count; i ++)
if (strcmp(fileList->text(i), slash) == 0)
{
#if defined(WIN32) || defined(__EMX__)
if (strcasecmp(fileList->text(i), slash) == 0) {
#else
if (strcmp(fileList->text(i), slash) == 0) {
#endif // WIN32 || __EMX__
// printf("Selecting line %d...\n", i);
fileList->topline(i);
fileList->select(i);
break;
}
@@ -400,10 +410,17 @@ Fl_File_Chooser::newdir()
void
Fl_File_Chooser::rescan()
{
char pathname[1024]; // New pathname for filename field
// printf("Fl_File_Chooser::rescan(); directory = \"%s\"\n", directory_);
// Clear the current filename
fileName->value("");
pathname[sizeof(pathname) - 1] = '\0';
strncpy(pathname, directory_, sizeof(pathname) - 1);
if (pathname[strlen(pathname) - 1] != '/') {
strncat(pathname, "/", sizeof(pathname) - 1);
}
fileName->value(pathname);
okButton->deactivate();
// Build the file list...
@@ -459,7 +476,11 @@ Fl_File_Chooser::fileListCB()
}
else
{
fileName->value(filename);
// Strip any trailing slash from the directory name...
filename = pathname + strlen(pathname) - 1;
if (*filename == '/') *filename = '\0';
fileName->value(pathname);
if (!fl_filename_isdir(pathname) || (type_ & DIRECTORY))
okButton->activate();
@@ -476,7 +497,8 @@ Fl_File_Chooser::fileNameCB()
{
char *filename, // New filename
*slash, // Pointer to trailing slash
pathname[1024]; // Full pathname to file
pathname[1024], // Full pathname to file
matchname[256]; // Matching filename
int i, // Looping var
min_match, // Minimum number of matching chars
max_match, // Maximum number of matching chars
@@ -494,64 +516,35 @@ Fl_File_Chooser::fileNameCB()
return;
}
#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
if (directory_[0] != '\0' &&
filename[0] != '/' &&
// Expand ~ and $ variables as needed...
if (strchr(filename, '~') || strchr(filename, '$')) {
fl_filename_expand(pathname, sizeof(pathname), filename);
filename = pathname;
value(pathname);
}
// Make sure we have an absolute path...
#if (defined(WIN32) && !defined(__CYGWIN__)) || defined(__EMX__)
if (directory_[0] != '\0' && filename[0] != '/' &&
filename[0] != '\\' &&
!(isalpha(filename[0]) && filename[1] == ':'))
snprintf(pathname, sizeof(pathname), "%s/%s", directory_, filename);
else
{
strncpy(pathname, filename, sizeof(pathname) - 1);
pathname[sizeof(pathname) - 1] = '\0';
}
!(isalpha(filename[0]) && filename[1] == ':')) {
#else
if (filename[0] == '~')
{
// Lookup user...
struct passwd *pwd;
if (!filename[1] || filename[1] == '/')
pwd = getpwuid(getuid());
else
{
strncpy(pathname, filename + 1, sizeof(pathname) - 1);
pathname[sizeof(pathname) - 1] = '\0';
i = strlen(pathname) - 1;
if (pathname[i] == '/')
pathname[i] = '\0';
pwd = getpwnam(pathname);
}
if (pwd)
{
strncpy(pathname, pwd->pw_dir, sizeof(pathname) - 1);
pathname[sizeof(pathname) - 1] = '\0';
if (filename[strlen(filename) - 1] == '/')
strncat(pathname, "/", sizeof(pathname) - 1);
}
else
snprintf(pathname, sizeof(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] != '/') {
#endif /* WIN32 || __EMX__ */
fl_filename_absolute(pathname, sizeof(pathname), filename);
value(pathname);
} else if (filename != pathname) {
// Finally, make sure that we have a writable copy...
strncpy(pathname, filename, sizeof(pathname) - 1);
pathname[sizeof(pathname) - 1] = '\0';
}
#endif /* WIN32 || __EMX__ */
filename = pathname;
// Now process things according to the key pressed...
if (Fl::event_key() == FL_Enter)
{
// Enter pressed - select or change directory...
#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
if ((strlen(pathname) == 2 && pathname[1] == ':') ||
fl_filename_isdir(pathname))
@@ -582,33 +575,31 @@ Fl_File_Chooser::fileNameCB()
else if (Fl::event_key() != FL_Delete)
{
// Check to see if the user has entered a directory...
if ((slash = strrchr(filename, '/')) == NULL)
slash = strrchr(filename, '\\');
if ((slash = strrchr(pathname, '/')) == NULL)
slash = strrchr(pathname, '\\');
if (slash != NULL)
{
// Yes, change directories and update the file name field...
if ((slash = strrchr(pathname, '/')) == NULL)
slash = strrchr(pathname, '\\');
// Yes, change directories if necessary...
if (slash > pathname) // Special case for "/"
*slash++ = '\0';
else
slash++;
if (strcmp(filename, "../") == 0) // Special case for "../"
up();
else
filename = slash;
#if defined(WIN32) || defined(__EMX__)
if (strcasecmp(pathname, directory_)) {
#else
if (strcmp(pathname, directory_)) {
#endif // WIN32 || __EMX__
int p = fileName->position();
int m = fileName->mark();
directory(pathname);
// If the string ended after the slash, we're done for now...
if (*slash == '\0')
return;
// Otherwise copy the remainder and proceed...
fileName->value(slash);
fileName->position(strlen(slash));
filename = slash;
fileName->position(p, m);
}
}
// Other key pressed - do filename completion as possible...
@@ -631,15 +622,15 @@ Fl_File_Chooser::fileNameCB()
if (max_match == 100000)
{
// First match; copy stuff over...
strncpy(pathname, file, sizeof(pathname) - 1);
pathname[sizeof(pathname) - 1] = '\0';
max_match = strlen(pathname);
strncpy(matchname, file, sizeof(matchname) - 1);
matchname[sizeof(matchname) - 1] = '\0';
max_match = strlen(matchname);
// Strip trailing /, if any...
if (pathname[max_match - 1] == '/')
if (matchname[max_match - 1] == '/')
{
max_match --;
pathname[max_match] = '\0';
matchname[max_match] = '\0';
}
// And then make sure that the item is visible
@@ -651,16 +642,16 @@ Fl_File_Chooser::fileNameCB()
// Succeeding match; compare to find maximum string match...
while (max_match > min_match)
#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
if (strnicmp(file, pathname, max_match) == 0)
if (strnicmp(file, matchname, max_match) == 0)
#else
if (strncmp(file, pathname, max_match) == 0)
if (strncmp(file, matchname, max_match) == 0)
#endif // WIN32 || __EMX__
break;
else
max_match --;
// Truncate the string as needed...
pathname[max_match] = '\0';
matchname[max_match] = '\0';
}
}
}
@@ -670,12 +661,15 @@ Fl_File_Chooser::fileNameCB()
// If we have any matches, add them to the input field...
if (first_line > 0 && min_match == max_match &&
max_match == (int)strlen(fileList->text(first_line)))
max_match == (int)strlen(fileList->text(first_line))) {
// This is the only possible match...
fileList->select(first_line);
}
else if (max_match > min_match && max_match != 100000)
{
// Add the matching portion...
fileName->replace(0, min_match, pathname);
fileName->replace(filename - pathname, filename - pathname + min_match,
matchname);
// Highlight it; if the user just pressed the backspace
// key, position the cursor at the start of the selection.
@@ -683,22 +677,16 @@ Fl_File_Chooser::fileNameCB()
// s/he can press the right arrow to accept the selection
// (Tab and End also do this for both cases.)
if (Fl::event_key() == FL_BackSpace)
fileName->position(min_match - 1, max_match);
fileName->position(filename - pathname + min_match - 1,
filename - pathname + max_match);
else
fileName->position(max_match, min_match);
fileName->position(filename - pathname + max_match,
filename - pathname + min_match);
}
// See if we need to enable the OK button...
if (directory_[0]) {
snprintf(pathname, sizeof(pathname), "%s/%s", directory_,
fileName->value());
} else {
strncpy(pathname, fileName->value(), sizeof(pathname) - 1);
pathname[sizeof(pathname) - 1] = '\0';
}
if ((type_ & CREATE || access(pathname, 0) == 0) &&
(!fl_filename_isdir(pathname) || type_ & DIRECTORY))
if ((type_ & CREATE || access(fileName->value(), 0) == 0) &&
(!fl_filename_isdir(fileName->value()) || type_ & DIRECTORY))
okButton->activate();
else
okButton->deactivate();
@@ -707,5 +695,5 @@ Fl_File_Chooser::fileNameCB()
//
// End of "$Id: Fl_File_Chooser2.cxx,v 1.1.2.7 2002/03/25 21:08:41 easysw Exp $".
// End of "$Id: Fl_File_Chooser2.cxx,v 1.1.2.8 2002/04/30 21:50:16 easysw Exp $".
//

259
src/Fl_File_Input.cxx Normal file
View File

@@ -0,0 +1,259 @@
//
// "$Id: Fl_File_Input.cxx,v 1.1.2.1 2002/04/30 21:50:16 easysw Exp $"
//
// File_Input header file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2002 by Bill Spitzak and others.
// Original version Copyright 1998 by Curtis Edwards.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems to "fltk-bugs@fltk.org".
//
//#include <FL/Fl_File_Input.H>
#include <FL/Fl.H>
#include <FL/Fl_File_Input.H>
#include <FL/fl_draw.H>
#include <stdio.h>
#include "flstring.h"
//
// Height of directory buttons...
//
#define DIR_HEIGHT 10
//
// Redraw bit for directory bar...
//
#define FL_DAMAGE_BAR 0x10
//
// 'Fl_File_Input::Fl_File_Input()' - Create a Fl_File_Input widget.
//
Fl_File_Input::Fl_File_Input(int x, int y, int w, int h, const char *l)
: Fl_Input(x, y, w, h, l) {
buttons_[0] = 0;
errorcolor_ = FL_RED;
ok_entry_ = 1;
pressed_ = -1;
down_box(FL_UP_BOX);
}
//
// 'Fl_File_Input::draw_buttons()' - Draw directory buttons.
//
void
Fl_File_Input::draw_buttons() {
int i, // Looping var
X; // Current X position
if (damage() & (FL_DAMAGE_BAR | FL_DAMAGE_ALL)) {
update_buttons();
}
for (X = 0, i = 0; buttons_[i]; i ++)
{
if ((X + buttons_[i]) > xscroll()) {
if (X < xscroll()) {
draw_box(pressed_ == i ? fl_down(down_box()) : down_box(),
x(), y(), X + buttons_[i] - xscroll(), DIR_HEIGHT, FL_GRAY);
} else if ((X + buttons_[i] - xscroll()) > w()) {
draw_box(pressed_ == i ? fl_down(down_box()) : down_box(),
x() + X - xscroll(), y(), w() - X + xscroll(), DIR_HEIGHT,
FL_GRAY);
} else {
draw_box(pressed_ == i ? fl_down(down_box()) : down_box(),
x() + X - xscroll(), y(), buttons_[i], DIR_HEIGHT, FL_GRAY);
}
}
X += buttons_[i];
}
if (X < w()) {
draw_box(pressed_ == i ? fl_down(down_box()) : down_box(),
x() + X - xscroll(), y(), w() - X + xscroll(), DIR_HEIGHT, FL_GRAY);
}
}
//
// 'Fl_File_Input::update_buttons()' - Update the sizes of the directory buttons.
//
void
Fl_File_Input::update_buttons() {
int i; // Looping var
const char *start, // Start of path component
*end; // End of path component
// puts("update_buttons()");
// Set the current font & size...
fl_font(textfont(), textsize());
// Loop through the value string, setting widths...
for (i = 0, start = value();
start && i < (int)(sizeof(buttons_) / sizeof(buttons_[0]) - 1);
start = end, i ++) {
// printf(" start = \"%s\"\n", start);
if ((end = strchr(start, '/')) == NULL)
#if defined(WIN32) || defined(__EMX__)
if ((end = strchr(start, '\\')) == NULL)
#endif // WIN32 || __EMX__
break;
end ++;
buttons_[i] = (int)fl_width(start, end - start);
if (!i) buttons_[i] += Fl::box_dx(box()) + 6;
}
// printf(" found %d components/buttons...\n", i);
buttons_[i] = 0;
}
//
// 'Fl_File_Input::value()' - Set the value of the widget...
//
int // O - TRUE on success
Fl_File_Input::value(const char *str, // I - New string value
int len) { // I - Length of value
damage(FL_DAMAGE_BAR);
return Fl_Input::value(str,len);
}
int // O - TRUE on success
Fl_File_Input::value(const char *str) { // I - New string value
damage(FL_DAMAGE_BAR);
if (*str) return Fl_Input::value(str);
else return 0;
}
//
// 'Fl_File_Input::draw()' - Draw the file input widget...
//
void
Fl_File_Input::draw() {
Fl_Boxtype b = box();
if (damage() & (FL_DAMAGE_BAR | FL_DAMAGE_ALL)) draw_buttons();
if (damage() & FL_DAMAGE_ALL) draw_box(b,x(),y()+DIR_HEIGHT,w(),h()-DIR_HEIGHT,color());
Fl_Input_::drawtext(x()+Fl::box_dx(b)+3, y()+Fl::box_dy(b)+DIR_HEIGHT,
w()-Fl::box_dw(b)-6, h()-Fl::box_dh(b)-DIR_HEIGHT);
}
//
// 'Fl_File_Input::handle()' - Handle events in the widget...
//
int // O - TRUE if we handled event
Fl_File_Input::handle(int event) // I - Event
{
// printf("handle(event = %d)\n", event);
if ((event == FL_PUSH || event == FL_RELEASE || event == FL_DRAG) &&
(Fl::event_y() < (y() + DIR_HEIGHT) || pressed_ >= 0)) {
return handle_button(event);
}
if (Fl_Input::handle(event)) {
if (changed()) damage(FL_DAMAGE_BAR);
return 1;
} else return 0;
}
//
// 'Fl_File_Input::handle_button()' - Handle button events in the widget...
//
int // O - TRUE if we handled event
Fl_File_Input::handle_button(int event) // I - Event
{
int i, // Looping var
X; // Current X position
const char *start, // Start of path component
*end; // End of path component
char newvalue[1024]; // New value
// Figure out which button is being pressed...
for (X = 0, i = 0; buttons_[i]; i ++)
{
X += buttons_[i];
if (X > xscroll() && Fl::event_x() < (x() + X - xscroll())) break;
}
// printf("handle_button(event = %d), button = %d\n", event, i);
// Redraw the directory bar...
if (event == FL_RELEASE) pressed_ = -1;
else pressed_ = i;
draw_buttons();
// Return immediately if the user is clicking on the last button or
// has not released the mouse button...
if (!buttons_[i] || event != FL_RELEASE) return 1;
// Figure out where to truncate the path...
strncpy(newvalue, value(), sizeof(newvalue) - 1);
newvalue[sizeof(newvalue) - 1] = '\0';
for (start = newvalue, end = start; start && i >= 0; start = end, i --) {
// printf(" start = \"%s\"\n", start);
if ((end = strchr(start, '/')) == NULL)
#if defined(WIN32) || defined(__EMX__)
if ((end = strchr(start, '\\')) == NULL)
#endif // WIN32 || __EMX__
break;
end ++;
}
if (i < 0) {
// Found the end; truncate the value and update the buttons...
value(newvalue, start - newvalue);
// Then do the callbacks, if necessary...
if (when() & FL_WHEN_CHANGED) do_callback();
}
return 1;
}
//
// End of "$Id: Fl_File_Input.cxx,v 1.1.2.1 2002/04/30 21:50:16 easysw Exp $".
//

View File

@@ -1,5 +1,5 @@
#
# "$Id: Makefile,v 1.18.2.14.2.40 2002/04/28 16:41:16 easysw Exp $"
# "$Id: Makefile,v 1.18.2.14.2.41 2002/04/30 21:50:16 easysw Exp $"
#
# Library makefile for the Fast Light Tool Kit (FLTK).
#
@@ -47,6 +47,7 @@ CPPFILES = \
Fl_File_Chooser2.cxx \
Fl_File_Icon.cxx \
Fl_File_Icon2.cxx \
Fl_File_Input.cxx \
Fl_GIF_Image.cxx \
Fl_Group.cxx \
Fl_Help_Dialog.cxx \
@@ -428,5 +429,5 @@ uninstall:
#
# End of "$Id: Makefile,v 1.18.2.14.2.40 2002/04/28 16:41:16 easysw Exp $".
# End of "$Id: Makefile,v 1.18.2.14.2.41 2002/04/30 21:50:16 easysw Exp $".
#

View File

@@ -77,7 +77,7 @@ Fl_File_Chooser.o: ../FL/Fl_Menu_Item.H ../FL/Fl_Button.H ../FL/fl_ask.H
Fl_File_Chooser.o: ../FL/Fl_File_Browser.H ../FL/Fl_Browser.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_File_Icon.H ../FL/Fl.H
Fl_File_Chooser.o: ../FL/Fl_Input.H ../FL/Fl_Input_.H
Fl_File_Chooser.o: ../FL/Fl_File_Input.H ../FL/Fl_Input.H ../FL/Fl_Input_.H
Fl_File_Chooser.o: ../FL/Fl_Return_Button.H ../FL/Fl_Button.H
Fl_File_Chooser.o: ../FL/Fl_Bitmap.H ../FL/Fl_Image.H ../FL/x.H
Fl_File_Chooser.o: ../FL/Fl_Window.H
@@ -88,10 +88,11 @@ Fl_File_Chooser2.o: ../FL/Fl_Menu_Item.H ../FL/Fl_Button.H ../FL/fl_ask.H
Fl_File_Chooser2.o: ../FL/Fl_File_Browser.H ../FL/Fl_Browser.H
Fl_File_Chooser2.o: ../FL/Fl_Browser_.H ../FL/Fl_Scrollbar.H
Fl_File_Chooser2.o: ../FL/Fl_Slider.H ../FL/Fl_Valuator.H
Fl_File_Chooser2.o: ../FL/Fl_File_Icon.H ../FL/Fl.H ../FL/Fl_Input.H
Fl_File_Chooser2.o: ../FL/Fl_Input_.H ../FL/Fl_Return_Button.H
Fl_File_Chooser2.o: ../FL/Fl_Button.H ../FL/filename.H ../FL/x.H
Fl_File_Chooser2.o: ../FL/Fl_Window.H flstring.h ../config.h
Fl_File_Chooser2.o: ../FL/Fl_File_Icon.H ../FL/Fl.H ../FL/Fl_File_Input.H
Fl_File_Chooser2.o: ../FL/Fl_Input.H ../FL/Fl_Input_.H
Fl_File_Chooser2.o: ../FL/Fl_Return_Button.H ../FL/Fl_Button.H
Fl_File_Chooser2.o: ../FL/filename.H ../FL/x.H ../FL/Fl_Window.H flstring.h
Fl_File_Chooser2.o: ../config.h
Fl_File_Icon.o: ../config.h flstring.h ../FL/Fl_File_Icon.H ../FL/Fl.H
Fl_File_Icon.o: ../FL/Enumerations.H ../FL/Fl_Export.H ../FL/Fl_Widget.H
Fl_File_Icon.o: ../FL/fl_draw.H ../FL/filename.H
@@ -100,6 +101,9 @@ Fl_File_Icon2.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H
Fl_File_Icon2.o: ../FL/Fl_Shared_Image.H ../FL/Fl_Image.H ../FL/x.H
Fl_File_Icon2.o: ../FL/Fl_Window.H ../FL/Fl_Widget.H ../FL/fl_draw.H
Fl_File_Icon2.o: ../FL/filename.H
Fl_File_Input.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H
Fl_File_Input.o: ../FL/Fl_File_Input.H ../FL/Fl_Input.H ../FL/Fl_Input_.H
Fl_File_Input.o: ../FL/fl_draw.H flstring.h ../config.h
Fl_GIF_Image.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H
Fl_GIF_Image.o: ../FL/Fl_GIF_Image.H ../FL/Fl_Pixmap.H ../FL/Fl_Image.H
Fl_GIF_Image.o: ../FL/x.H ../FL/Fl_Window.H ../config.h flstring.h
@@ -179,7 +183,8 @@ Fl_PNM_Image.o: ../FL/Fl_Window.H ../config.h flstring.h
Fl_Positioner.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H
Fl_Positioner.o: ../FL/Fl_Positioner.H ../FL/Fl_Widget.H ../FL/fl_draw.H
Fl_Preferences.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H
Fl_Preferences.o: ../FL/Fl_Preferences.H flstring.h ../config.h
Fl_Preferences.o: ../FL/Fl_Preferences.H ../FL/filename.H flstring.h
Fl_Preferences.o: ../config.h
Fl_Progress.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H
Fl_Progress.o: ../FL/Fl_Progress.H ../FL/Fl_Widget.H ../FL/fl_draw.H
Fl_Repeat_Button.o: ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H
@@ -343,8 +348,8 @@ fl_file_dir.o: ../FL/Fl_Choice.H ../FL/Fl_Menu_.H ../FL/Fl_Menu_Item.H
fl_file_dir.o: ../FL/Fl_Button.H ../FL/fl_ask.H ../FL/Fl_File_Browser.H
fl_file_dir.o: ../FL/Fl_Browser.H ../FL/Fl_Browser_.H ../FL/Fl_Scrollbar.H
fl_file_dir.o: ../FL/Fl_Slider.H ../FL/Fl_Valuator.H ../FL/Fl_File_Icon.H
fl_file_dir.o: ../FL/Fl.H ../FL/Fl_Input.H ../FL/Fl_Input_.H
fl_file_dir.o: ../FL/Fl_Return_Button.H ../FL/Fl_Button.H
fl_file_dir.o: ../FL/Fl.H ../FL/Fl_File_Input.H ../FL/Fl_Input.H
fl_file_dir.o: ../FL/Fl_Input_.H ../FL/Fl_Return_Button.H ../FL/Fl_Button.H
fl_font.o: ../config.h ../FL/Fl.H ../FL/Enumerations.H ../FL/Fl_Export.H
fl_font.o: ../FL/fl_draw.H ../FL/x.H ../FL/Fl_Window.H Fl_Font.H flstring.h
fl_font.o: fl_font_x.cxx