Begin to rewrite Fl_File_Chooser2.cxx for the driver model.

The parts with case-insensitive filename comparisons for WIN32
and for WIN32 but not CYGWIN still have to be rewritten.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11588 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2016-04-12 17:06:20 +00:00
parent fce1483eb8
commit 4ebdf97b70
5 changed files with 97 additions and 77 deletions

View File

@ -162,6 +162,16 @@ public:
// the default implementations of pixmap_extra_transparent_processing() and make_unused_color() and are most probably enough
virtual int pixmap_extra_transparent_processing() {return 0;}
virtual void make_unused_color(unsigned char &r, unsigned char &g, unsigned char &b) {}
// implement to return the user's home directory name
virtual const char *home_directory_name() { return ""; }
// the default implementation is most probably enough
virtual const char *filesystems_label() { return "File Systems"; }
// return TRUE means \ same as / in file names
virtual int backslash_as_slash() {return 0;}
// return TRUE means : indicates a drive letter in file names
virtual int colon_is_drive() {return 0;}
// return TRUE means that files whose name begins with dot are hidden
virtual int dot_file_hidden() {return 0;}
};
#endif // FL_SYSTEM_DRIVER_H

View File

@ -364,7 +364,7 @@
#else
#endif
#if defined(WIN32) && ! defined (__CYGWIN__)
/*#if defined(WIN32) && ! defined (__CYGWIN__)
# include <direct.h>
# include <io.h>
// Visual C++ 2005 incorrectly displays a warning about the use of POSIX APIs
@ -379,7 +379,7 @@
#else
# include <unistd.h>
# include <pwd.h>
#endif /* WIN32 */
#endif / * WIN32 */
//
@ -394,11 +394,12 @@ const char *Fl_File_Chooser::custom_filter_label = "Custom Filter";
const char *Fl_File_Chooser::existing_file_label = "Please choose an existing file!";
const char *Fl_File_Chooser::favorites_label = "Favorites";
const char *Fl_File_Chooser::filename_label = "Filename:";
#ifdef WIN32
/*#ifdef WIN32
const char *Fl_File_Chooser::filesystems_label = "My Computer";
#else
const char *Fl_File_Chooser::filesystems_label = "File Systems";
#endif // WIN32
#endif // WIN32*/
const char *Fl_File_Chooser::filesystems_label = Fl::system_driver()->filesystems_label();
const char *Fl_File_Chooser::manage_favorites_label = "Manage Favorites";
const char *Fl_File_Chooser::new_directory_label = "New Directory?";
const char *Fl_File_Chooser::new_directory_tooltip = "Create a new directory.";
@ -417,9 +418,6 @@ static int compare_dirnames(const char *a, const char *b);
static void quote_pathname(char *, const char *, int);
static void unquote_pathname(char *, const char *, int);
// use platform dependent getenv() to get the home directory (STR #3166)
static const char* get_homedir();
//
// 'Fl_File_Chooser::count()' - Return the number of selected files.
//
@ -473,29 +471,32 @@ Fl_File_Chooser::directory(const char *d)// I - Directory to change to
if (d == NULL)
d = ".";
#ifdef WIN32
// See if the filename contains backslashes...
char *slash; // Pointer to slashes
char fixpath[FL_PATH_MAX]; // Path with slashes converted
if (strchr(d, '\\')) {
// Convert backslashes to slashes...
strlcpy(fixpath, d, sizeof(fixpath));
for (slash = strchr(fixpath, '\\'); slash; slash = strchr(slash + 1, '\\'))
*slash = '/';
d = fixpath;
if (Fl::system_driver()->backslash_as_slash()) {
//#ifdef WIN32
// See if the filename contains backslashes...
char *slash; // Pointer to slashes
char fixpath[FL_PATH_MAX]; // Path with slashes converted
if (strchr(d, '\\')) {
// Convert backslashes to slashes...
strlcpy(fixpath, d, sizeof(fixpath));
for (slash = strchr(fixpath, '\\'); slash; slash = strchr(slash + 1, '\\'))
*slash = '/';
d = fixpath;
}
}
#endif // WIN32
//#endif // WIN32
if (d[0] != '\0')
{
// Make the directory absolute...
#if (defined(WIN32) && ! defined(__CYGWIN__))|| defined(__EMX__)
/*#if (defined(WIN32) && ! defined(__CYGWIN__))|| defined(__EMX__)
if (d[0] != '/' && d[0] != '\\' && d[1] != ':')
#else
if (d[0] != '/' && d[0] != '\\')
#endif /* WIN32 || __EMX__ */
} else {
#else*/
if (d[0] != '/' && d[0] != '\\' && ( !Fl::system_driver()->colon_is_drive() || d[1] != ':' ) )
//#endif /* WIN32 || __EMX__ */
fl_filename_absolute(directory_, d);
else
strlcpy(directory_, d, sizeof(directory_));
@ -548,7 +549,7 @@ Fl_File_Chooser::favoritesButtonCB()
if (!v) {
// Add current directory to favorites...
if (get_homedir()) v = favoritesButton->size() - 5;
if (Fl::system_driver()->home_directory_name()) v = favoritesButton->size() - 5;
else v = favoritesButton->size() - 4;
sprintf(menuname, "favorite%02d", v);
@ -723,13 +724,17 @@ Fl_File_Chooser::fileListCB()
}
if (Fl::event_clicks()) {
#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
/*#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
if ((strlen(pathname) == 2 && pathname[1] == ':') ||
Fl::system_driver()->filename_isdir_quick(pathname))
#else
if (Fl::system_driver()->filename_isdir_quick(pathname))
#endif /* WIN32 || __EMX__ */
{
int condition = 0;
if (Fl::system_driver()->colon_is_drive() && strlen(pathname) == 2 && pathname[1] == ':') condition = 1;
if (!condition) condition = Fl::system_driver()->filename_isdir_quick(pathname);
if (condition)
{
// Change directories...
directory(pathname);
@ -836,13 +841,16 @@ Fl_File_Chooser::fileNameCB()
}
// Make sure we have an absolute path...
#if (defined(WIN32) && !defined(__CYGWIN__)) || defined(__EMX__)
/*#if (defined(WIN32) && !defined(__CYGWIN__)) || defined(__EMX__)
if (directory_[0] != '\0' && filename[0] != '/' &&
filename[0] != '\\' &&
!(isalpha(filename[0] & 255) && (!filename[1] || filename[1] == ':'))) {
#else
if (directory_[0] != '\0' && filename[0] != '/') {
#endif /* WIN32 || __EMX__ */
int condition = directory_[0] != '\0' && filename[0] != '/';
if (condition && Fl::system_driver()->colon_is_drive()) condition = !(isalpha(filename[0] & 255) && (!filename[1] || filename[1] == ':'));
if (condition) {
fl_filename_absolute(pathname, sizeof(pathname), filename);
value(pathname);
fileName->mark(fileName->position()); // no selection after expansion
@ -856,7 +864,7 @@ Fl_File_Chooser::fileNameCB()
// Now process things according to the key pressed...
if (Fl::event_key() == FL_Enter || Fl::event_key() == FL_KP_Enter) {
// Enter pressed - select or change directory...
#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
/*#if (defined(WIN32) && ! defined(__CYGWIN__)) || defined(__EMX__)
if ((isalpha(pathname[0] & 255) && pathname[1] == ':' && !pathname[2]) ||
(Fl::system_driver()->filename_isdir_quick(pathname) &&
compare_dirnames(pathname, directory_))) {
@ -864,8 +872,12 @@ Fl_File_Chooser::fileNameCB()
if (Fl::system_driver()->filename_isdir_quick(pathname) &&
compare_dirnames(pathname, directory_)) {
#endif /* WIN32 || __EMX__ */
int condition = 0;
if (Fl::system_driver()->colon_is_drive()) condition = isalpha(pathname[0] & 255) && pathname[1] == ':' && !pathname[2];
if (!condition) condition = ( Fl::system_driver()->filename_isdir_quick(pathname) && compare_dirnames(pathname, directory_) );
if (condition) {
directory(pathname);
} else if ((type_ & CREATE) || access(pathname, 0) == 0) {
} else if ((type_ & CREATE) || fl_access(pathname, 0) == 0) {
if (!Fl::system_driver()->filename_isdir_quick(pathname) || (type_ & DIRECTORY)) {
// Update the preview box...
update_preview();
@ -989,7 +1001,7 @@ Fl_File_Chooser::fileNameCB()
}
// See if we need to enable the OK button...
if (((type_ & CREATE) || !access(fileName->value(), 0)) &&
if (((type_ & CREATE) || !fl_access(fileName->value(), 0)) &&
(!fl_filename_isdir(fileName->value()) || (type_ & DIRECTORY))) {
okButton->activate();
} else {
@ -999,7 +1011,7 @@ Fl_File_Chooser::fileNameCB()
// FL_Delete or FL_BackSpace
fileList->deselect(0);
fileList->redraw();
if (((type_ & CREATE) || !access(fileName->value(), 0)) &&
if (((type_ & CREATE) || !fl_access(fileName->value(), 0)) &&
(!fl_filename_isdir(fileName->value()) || (type_ & DIRECTORY))) {
okButton->activate();
} else {
@ -1073,21 +1085,22 @@ Fl_File_Chooser::newdir()
return;
// Make it relative to the current directory as needed...
#if (defined(WIN32) && ! defined (__CYGWIN__)) || defined(__EMX__)
/*#if (defined(WIN32) && ! defined (__CYGWIN__)) || defined(__EMX__)
if (dir[0] != '/' && dir[0] != '\\' && dir[1] != ':')
#else
if (dir[0] != '/' && dir[0] != '\\')
#endif /* WIN32 || __EMX__ */
if (dir[0] != '/' && dir[0] != '\\' && (!Fl::system_driver()->colon_is_drive() || dir[1] != ':') )
snprintf(pathname, sizeof(pathname), "%s/%s", directory_, dir);
else
strlcpy(pathname, dir, sizeof(pathname));
// Create the directory; ignore EEXIST errors...
#if defined(WIN32) && ! defined (__CYGWIN__)
/*#if defined(WIN32) && ! defined (__CYGWIN__)
if (mkdir(pathname))
#else
if (mkdir(pathname, 0777))
#endif /* WIN32 */
#else*/
if (fl_mkdir(pathname, 0777))
//#endif /* WIN32 */
if (errno != EEXIST)
{
fl_alert("%s", strerror(errno));
@ -1164,9 +1177,9 @@ Fl_File_Chooser::rescan()
// Build the file list...
fileList->load(directory_, sort);
#ifndef WIN32
if (!showHiddenButton->value()) remove_hidden_files();
#endif
//#ifndef WIN32
if (Fl::system_driver()->dot_file_hidden() && !showHiddenButton->value()) remove_hidden_files();
//#endif
// Update the preview box...
update_preview();
}
@ -1191,9 +1204,9 @@ void Fl_File_Chooser::rescan_keep_filename()
// Build the file list...
fileList->load(directory_, sort);
#ifndef WIN32
if (!showHiddenButton->value()) remove_hidden_files();
#endif
//#ifndef WIN32
if (Fl::system_driver()->dot_file_hidden() && !showHiddenButton->value()) remove_hidden_files();
//#endif
// Update the preview box...
update_preview();
@ -1283,7 +1296,7 @@ Fl_File_Chooser::update_favorites()
favoritesButton->add(manage_favorites_label, FL_ALT + 'm', 0, 0, FL_MENU_DIVIDER);
favoritesButton->add(filesystems_label, FL_ALT + 'f', 0);
if ((home = get_homedir()) != NULL) {
if ((home = Fl::system_driver()->home_directory_name()) != NULL) {
quote_pathname(menuname, home, sizeof(menuname));
favoritesButton->add(menuname, FL_ALT + 'h', 0);
}
@ -1547,19 +1560,21 @@ Fl_File_Chooser::value(const char *filename)
return;
}
#ifdef WIN32
// See if the filename contains backslashes...
char fixpath[FL_PATH_MAX]; // Path with slashes converted
if (strchr(filename, '\\')) {
// Convert backslashes to slashes...
strlcpy(fixpath, filename, sizeof(fixpath));
for (slash = strchr(fixpath, '\\'); slash; slash = strchr(slash + 1, '\\'))
*slash = '/';
filename = fixpath;
//#ifdef WIN32
if (Fl::system_driver()->backslash_as_slash()) {
// See if the filename contains backslashes...
char fixpath[FL_PATH_MAX]; // Path with slashes converted
if (strchr(filename, '\\')) {
// Convert backslashes to slashes...
strlcpy(fixpath, filename, sizeof(fixpath));
for (slash = strchr(fixpath, '\\'); slash; slash = strchr(slash + 1, '\\'))
*slash = '/';
filename = fixpath;
}
}
#endif // WIN32
//#endif // WIN32
// See if there is a directory in there...
fl_filename_absolute(pathname, sizeof(pathname), filename);
@ -1610,9 +1625,9 @@ void Fl_File_Chooser::show()
rescan_keep_filename();
fl_cursor(FL_CURSOR_DEFAULT);
fileName->take_focus();
#ifdef WIN32
showHiddenButton->hide();
#endif
//#ifdef WIN32
if (!Fl::system_driver()->dot_file_hidden()) showHiddenButton->hide();
//#endif
}
void Fl_File_Chooser::showHidden(int value)
@ -1718,24 +1733,6 @@ unquote_pathname(char *dst, // O - Destination string
*dst = '\0';
}
//
// 'get_homedir()' - Try to find the home directory (platform dependent).
static const char*
get_homedir() {
const char *home = fl_getenv("HOME");
#ifdef WIN32
if (!home) home = fl_getenv("UserProfile");
#endif // WIN32
return home;
}
//
// End of "$Id$".
//

View File

@ -73,6 +73,8 @@ public:
virtual void unlock();
virtual void* thread_message();
virtual int file_type(const char *filename);
virtual const char *home_directory_name() { return ::getenv("HOME"); }
virtual int dot_file_hidden() {return 1;}
};
#endif // FL_POSIX_SYSTEM_DRIVER_H

View File

@ -97,6 +97,10 @@ public:
virtual int pixmap_extra_transparent_processing() {return 1;}
// this one is implemented in fl_draw_pixmap.cxx
virtual void make_unused_color(unsigned char &r, unsigned char &g, unsigned char &b);
virtual const char *home_directory_name();
virtual const char *filesystems_label() { return "My Computer"; }
virtual int backslash_as_slash() {return 1;}
virtual int colon_is_drive() {return 1;}
};
#endif // FL_WINAPI_SYSTEM_DRIVER_H

View File

@ -898,6 +898,13 @@ int Fl_WinAPI_System_Driver::file_type(const char *filename)
return filetype;
}
const char *Fl_WinAPI_System_Driver::home_directory_name()
{
const char *h = getenv("HOME");
if (!h) h = getenv("UserProfile");
return h;
}
//
// End of "$Id$".
//