Author: bgbnbigben
Date: 2011-03-01 16:51:46 -0800 (Tue, 01 Mar 2011)
New Revision: 8492
Log:
Huge update of the FileChooser widget to re-add the ability to call 
use_system_file_chooser() and file_chooser(). This fixes #1963. Also deleted 
src/FileChooser.fl as it was superflous and slightly old.....

Removed:
   trunk/src/FileChooser.fl
Modified:
   trunk/fltk/FileChooser.h
   trunk/fltk/file_chooser.h
   trunk/ide/visualc/config.h
   trunk/images/zlib/ChangeLog
   trunk/src/FileChooser.cxx
   trunk/src/file_chooser.cxx
   trunk/test/file_chooser.cxx

Modified: trunk/fltk/FileChooser.h
===================================================================
--- trunk/fltk/FileChooser.h    2011-03-01 19:45:05 UTC (rev 8491)
+++ trunk/fltk/FileChooser.h    2011-03-02 00:51:46 UTC (rev 8492)
@@ -1,13 +1,34 @@
-// generated by Fast Light User Interface Designer (fluid) version 2.1000
+//
+// "$Id$"
+//
+// FileChooser dialog for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 1998-2006 by Bill Spitzak and others.
+//
+// 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 on the following page:
+//
+//     http://www.fltk.org/str.php
+//
 
-#ifndef FileChooser_h
-#define FileChooser_h
-// Header for //\n// "$Id: FileChooser.fl 5447 2006-09-19 00:09...
+#ifndef fltk_FileChooser_h
+#define fltk_FileChooser_h
+
 #include <fltk/DoubleBufferWindow.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fltk/Group.h>
 #include <fltk/Choice.h>
 #include <fltk/PopupMenu.h>
 #include <fltk/Button.h>
@@ -23,8 +44,6 @@
 namespace fltk  {
 
 class FL_API FileChooser  {
-public:
-  enum { SINGLE = 0, MULTI = 1, CREATE = 2, DIRECTORY = 4 };
 private:
   static fltk::Preferences prefs_;
   void (*callback_)(FileChooser*, void *);
@@ -45,68 +64,95 @@
   int favorites_showing;
   void activate_okButton_if_file();
   void directory(const char *d, bool);
-public:
-  FileChooser(const char *d, const char *p, int t, const char *title);
-private:
+
+  // FileChooser window
   fltk::DoubleBufferWindow *window;
   inline void cb_window_i(fltk::DoubleBufferWindow*, void*);
   static void cb_window(fltk::DoubleBufferWindow*, void*);
-      fltk::Choice *showChoice;
-      inline void cb_showChoice_i(fltk::Choice*, void*);
-      static void cb_showChoice(fltk::Choice*, void*);
-      fltk::PopupMenu *favoritesButton;
-      inline void cb_favoritesButton_i(fltk::PopupMenu*, void*);
-      static void cb_favoritesButton(fltk::PopupMenu*, void*);
-public:
-      fltk::Button *newButton;
-private:
-      inline void cb_newButton_i(fltk::Button*, void*);
-      static void cb_newButton(fltk::Button*, void*);
-    inline void cb__i(fltk::TiledGroup*, void*);
-    static void cb_(fltk::TiledGroup*, void*);
-      fltk::FileBrowser *fileList;
-      inline void cb_fileList_i(fltk::FileBrowser*, void*);
-      static void cb_fileList(fltk::FileBrowser*, void*);
-      fltk::InvisibleBox *previewBox;
-public:
-        fltk::CheckButton *previewButton;
-private:
-        inline void cb_previewButton_i(fltk::CheckButton*, void*);
-        static void cb_previewButton(fltk::CheckButton*, void*);
-public:
-        fltk::CheckButton *showHiddenButton;
-private:
-        inline void cb_showHiddenButton_i(fltk::CheckButton*, void*);
-        static void cb_showHiddenButton(fltk::CheckButton*, void*);
-      fltk::FileInput *fileName;
-      inline void cb_fileName_i(fltk::FileInput*, void*);
-      static void cb_fileName(fltk::FileInput*, void*);
-        fltk::ReturnButton *okButton;
-        inline void cb_okButton_i(fltk::ReturnButton*, void*);
-        static void cb_okButton(fltk::ReturnButton*, void*);
-        fltk::Button *cancelButton;
-        inline void cb_cancelButton_i(fltk::Button*, void*);
-        static void cb_cancelButton(fltk::Button*, void*);
+
+  // Show button
+  fltk::Choice *showChoice;
+  inline void cb_showChoice_i(fltk::Choice*, void*);
+  static void cb_showChoice(fltk::Choice*, void*);
+
+  // Favorites button
+  fltk::PopupMenu *favoritesButton;
+  inline void cb_favoritesButton_i(fltk::PopupMenu*, void*);
+  static void cb_favoritesButton(fltk::PopupMenu*, void*);
+
+  // "New" button
+  inline void cb_newButton_i(fltk::Button*, void*);
+  static void cb_newButton(fltk::Button*, void*);
+
+  // Default callback (update_preview())
+  inline void cb__i(fltk::TiledGroup*, void*);
+  static void cb_(fltk::TiledGroup*, void*);
+
+  // List of files in the directory
+  fltk::FileBrowser *fileList;
+  inline void cb_fileList_i(fltk::FileBrowser*, void*);
+  static void cb_fileList(fltk::FileBrowser*, void*);
+
+  // Preview box
+  fltk::InvisibleBox *previewBox;
+  inline void cb_previewButton_i(fltk::CheckButton*, void*);
+  static void cb_previewButton(fltk::CheckButton*, void*);
+
+  // Show "hidden" files
+  inline void cb_showHiddenButton_i(fltk::CheckButton*, void*);
+  static void cb_showHiddenButton(fltk::CheckButton*, void*);
+
+  // Filename (input section)
+  fltk::FileInput *fileName;
+  inline void cb_fileName_i(fltk::FileInput*, void*);
+  static void cb_fileName(fltk::FileInput*, void*);
+
+  // "OK" button
+  fltk::ReturnButton *okButton;
+  inline void cb_okButton_i(fltk::ReturnButton*, void*);
+  static void cb_okButton(fltk::ReturnButton*, void*);
+
+  // "Cancel" button
+  fltk::Button *cancelButton;
+  inline void cb_cancelButton_i(fltk::Button*, void*);
+  static void cb_cancelButton(fltk::Button*, void*);
+
+  // Window for favorite directories
   fltk::DoubleBufferWindow *favWindow;
-    fltk::FileBrowser *favList;
-    inline void cb_favList_i(fltk::FileBrowser*, void*);
-    static void cb_favList(fltk::FileBrowser*, void*);
-      fltk::Button *favUpButton;
-      inline void cb_favUpButton_i(fltk::Button*, void*);
-      static void cb_favUpButton(fltk::Button*, void*);
-      fltk::Button *favDeleteButton;
-      inline void cb_favDeleteButton_i(fltk::Button*, void*);
-      static void cb_favDeleteButton(fltk::Button*, void*);
-      fltk::Button *favDownButton;
-      inline void cb_favDownButton_i(fltk::Button*, void*);
-      static void cb_favDownButton(fltk::Button*, void*);
-      fltk::Button *favCancelButton;
-      inline void cb_favCancelButton_i(fltk::Button*, void*);
-      static void cb_favCancelButton(fltk::Button*, void*);
-      fltk::ReturnButton *favOkButton;
-      inline void cb_favOkButton_i(fltk::ReturnButton*, void*);
-      static void cb_favOkButton(fltk::ReturnButton*, void*);
+
+  // List of favorite directories.
+  fltk::FileBrowser *favList;
+  inline void cb_favList_i(fltk::FileBrowser*, void*);
+  static void cb_favList(fltk::FileBrowser*, void*);
+
+  // Favorites menu "Up" button
+  fltk::Button *favUpButton;
+  inline void cb_favUpButton_i(fltk::Button*, void*);
+  static void cb_favUpButton(fltk::Button*, void*);
+
+  // Favorites menu "Delete" button
+  fltk::Button *favDeleteButton;
+  inline void cb_favDeleteButton_i(fltk::Button*, void*);
+  static void cb_favDeleteButton(fltk::Button*, void*);
+
+  // Favorites menu "Down" button
+  fltk::Button *favDownButton;
+  inline void cb_favDownButton_i(fltk::Button*, void*);
+  static void cb_favDownButton(fltk::Button*, void*);
+
+  // Favorites menu "Cancel" button
+  fltk::Button *favCancelButton;
+  inline void cb_favCancelButton_i(fltk::Button*, void*);
+  static void cb_favCancelButton(fltk::Button*, void*);
+
+  // Favorites menu "OK" button
+  fltk::ReturnButton *favOkButton;
+  inline void cb_favOkButton_i(fltk::ReturnButton*, void*);
+  static void cb_favOkButton(fltk::ReturnButton*, void*);
+
 public:
+  enum { SINGLE = 0, MULTI = 1, CREATE = 2, DIRECTORY = 4 };
+  FileChooser(const char *d, const char *p, int t, const char *title);
   ~FileChooser();
   void callback(void (*cb)(FileChooser *, void *), void *d = 0);
   void color(Color c);
@@ -161,8 +207,16 @@
   static const char *save_label;
   static const char *show_label;
   static File_Sort_F *sort;
+
+  fltk::Button *newButton;
+  fltk::CheckButton *previewButton;
+  fltk::CheckButton *showHiddenButton;
 };
-extern FL_API void file_chooser_ok_label(const char*l);
+
 }
-// Header for //\n// End of "$Id: FileChooser.fl 5447 2006-09-1...
+
 #endif
+
+//
+// End of "$Id$".
+//

Modified: trunk/fltk/file_chooser.h
===================================================================
--- trunk/fltk/file_chooser.h   2011-03-01 19:45:05 UTC (rev 8491)
+++ trunk/fltk/file_chooser.h   2011-03-02 00:51:46 UTC (rev 8492)
@@ -29,13 +29,13 @@
 /// \name fltk/file_chooser.h
 //@{
 
+FL_API void file_chooser_ok_label(const char*l);
 FL_API void use_system_file_chooser(bool = true);
-
-FL_API const char *dir_chooser(const char *message,const char *fname,int 
relative=0);
-FL_API const char *file_chooser(const char *message,const char *pattern,
-                               const char *filename, int relative = 0);
+FL_API const char *dir_chooser(const char *message, const char *fname, int 
relative = 0);
 FL_API void file_chooser_callback(void (*cb)(const char *));
+FL_API const char *file_chooser(const char *message, const char *pattern, 
const char *filename, bool save = false, int relative = 1);
 
+
 //@}
 
 }

Modified: trunk/ide/visualc/config.h
===================================================================
(Binary files differ)

Modified: trunk/images/zlib/ChangeLog
===================================================================
--- trunk/images/zlib/ChangeLog 2011-03-01 19:45:05 UTC (rev 8491)
+++ trunk/images/zlib/ChangeLog 2011-03-02 00:51:46 UTC (rev 8492)
@@ -225,7 +225,7 @@
 - use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau)
 - added makelcc.bat for lcc-win32 (Tom St Denis)
 - in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe)
-- Avoid expanded $Id: ChangeLog,v 1.1 2004/08/04 20:44:16 laza2000 Exp $. Use 
"rcs -kb" or "cvs admin -kb" to avoid Id expansion.
+- Avoid expanded $Id$. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion.
 - check for unistd.h in configure (for off_t)
 - remove useless check parameter in inflate_blocks_free
 - avoid useless assignment of s->check to itself in inflate_blocks_new

Modified: trunk/src/FileChooser.cxx
===================================================================
--- trunk/src/FileChooser.cxx   2011-03-01 19:45:05 UTC (rev 8491)
+++ trunk/src/FileChooser.cxx   2011-03-02 00:51:46 UTC (rev 8492)
@@ -1,7 +1,32 @@
-// generated by Fast Light User Interface Designer (fluid) version 2.1000
+//
+// "$Id$"
+//
+// FileChooser dialog for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 1998-2006 by Bill Spitzak and others.
+//
+// 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 on the following page:
+//
+//     http://www.fltk.org/str.php
+//
 
-#include "../fltk/FileChooser.h"
-// Code for //\n// "$Id: FileChooser.fl 5447 2006-09-19 00:09...
+
+#include <fltk/FileChooser.h>
 #include <fltk/draw.h>
 #include <fltk/run.h>
 #include <fltk/Cursor.h>
@@ -67,7 +92,7 @@
 
 inline void FileChooser::cb_showHiddenButton_i(fltk::CheckButton*, void*) {
   fileList->show_hidden(showHiddenButton->value() ? true: false);
-                       fileList->load(fileList->directory());
+  fileList->load(fileList->directory());
 }
 void FileChooser::cb_showHiddenButton(fltk::CheckButton* o, void* v) {
   
((FileChooser*)(o->parent()->parent()->parent()->user_data()))->cb_showHiddenButton_i(o,v);
@@ -399,8 +424,8 @@
 }
 
 bool FileChooser::exec(Window* p, bool grab) {
- if (shown()) window->hide();
- return window->exec(p, grab);
+  if (shown()) window->hide();
+  return window->exec(p, grab);
 }
 
 int FileChooser::shown() {
@@ -471,5 +496,5 @@
 int FileChooser::favorites() const {
   return favorites_showing;
 }
-FL_API void file_chooser_ok_label(const char*l);
-// Code for //\n// End of "$Id: FileChooser.fl 5447 2006-09-1...
+
+//  End of "$Id$"
\ No newline at end of file

Deleted: trunk/src/FileChooser.fl

Modified: trunk/src/file_chooser.cxx
===================================================================
--- trunk/src/file_chooser.cxx  2011-03-01 19:45:05 UTC (rev 8491)
+++ trunk/src/file_chooser.cxx  2011-03-02 00:51:46 UTC (rev 8492)
@@ -24,17 +24,22 @@
 //
 
 #include <config.h>
+#include <fltk/FileChooser.h>
 #include <fltk/file_chooser.h>
-#include <fltk/FileChooser.h>
 #include <fltk/run.h>
 #include <fltk/string.h>
+#include <fltk/utf.h>
 
 using namespace fltk;
 
 static FileChooser     *fc = (FileChooser *)0;
-static void            (*current_callback)(const char*) = 0;
+static void default_callback(const char*) {}
+static void            (*current_callback)(const char*) = default_callback;
 static const char      *current_label = "Ok";
 
+// Prototype for a local function
+static wchar_t* patternToWin(const char* const pat, int len);
+static unsigned windowsWLen(const wchar_t* const string);
 
 // Do a file chooser callback...
 static void callback(FileChooser *, void*) {
@@ -43,9 +48,11 @@
 }
 
 
-// Set the file chooser callback
+/*! This function is called every time the user navigates to a new file
+  or directory in the file chooser. It can be used to preview the result
+  in the main window. */
 void fltk::file_chooser_callback(void (*cb)(const char*)) {
-  current_callback = cb;
+  current_callback = cb ? cb : default_callback;
 }
 
 
@@ -57,71 +64,9 @@
 
 
 //
-// 'fl_file_chooser()' - Show a file chooser dialog and get a filename.
+// 'fltk::dir_chooser()' - Show a file chooser dialog and get a directory.
 //
 
-const char *                                   // O - Filename or NULL
-fltk::file_chooser(const char *message,        // I - Message in titlebar
-                const char *pat,       // I - Filename pattern
-               const char *fname,      // I - Initial filename selection
-               int        relative) {  // I - 0 for absolute path
-  static char  retname[1024];          // Returned filename
-
-  if (!fc) {
-    if (!fname || !*fname) fname = ".";
-    
-    fc = new FileChooser(fname, pat, FileChooser::CREATE, message);
-    fc->callback(callback, 0);
-  }
-  fc->type(FileChooser::CREATE);
-  fc->filter(pat);
-  fc->label(message);
-  
-  if (!fname || !*fname) {
-    if (fc->filter() != pat && (!pat || !fc->filter() ||
-                               strcmp(pat, fc->filter())) && fc->value()) {
-      // if pattern is different, remove name but leave old directory:
-      strlcpy(retname, fc->value(), sizeof(retname));
-      
-       char *p = strrchr(retname, '/');
-       
-        if (p) {
-         // If the filename is "/foo", then the directory will be "/", not
-         // ""...
-         if (p == retname)
-           retname[1] = '\0';
-         else
-           *p = '\0';
-       }
-       
-       // Set the directory...
-       fc->directory(retname);
-    }
-  }
-  else {
-    fc->ok_label(current_label);
-  }  
-
-  fc->value(fname);
-  //fc->show(); while (fc->visible()) fltk::wait();
-  fc->exec(0, true);
-  
-  if (fc->value() && relative) {
-    fltk::filename_relative(retname, sizeof(retname), fc->value());
-    
-    return retname;
-  } else if (fc->value()) {
-    fltk::filename_absolute(retname, sizeof(retname), fc->value());
-    return retname;
-  }
-  else return 0;
-}
-
-
-//
-// 'fl_dir_chooser()' - Show a file chooser dialog and get a directory.
-//
-
 const char *                                   // O - Directory or NULL
 fltk::dir_chooser(const char *message, // I - Message for titlebar
                const char *fname,      // I - Initial directory name
@@ -154,8 +99,6 @@
   else return 0;
 }
 
-#if 0
-
 static bool use_system_fc = false;
 /*! On Windows this makes file_chooser() call the Win32 file chooser
   API instead of using the one constructed in fltk. Ignored on other
@@ -177,29 +120,23 @@
 # endif
 #endif
 
-static void default_callback(const char*) {}
-static void (*current_callback)(const char*) = default_callback;
-/*! This function is called every time the user navigates to a new file
-  or directory in the file chooser. It can be used to preview the result
-  in the main window. */
-void fltk::file_chooser_callback(void (*cb)(const char*)) {
-  current_callback = cb ? cb : default_callback;
-}
-
 /*!
   \image html filechooser.gif
 
   pops up the file chooser, waits for the user to pick a file or
   Cancel, and then returns a pointer to that filename or NULL if
-  Cancel is chosen.
+  Cancel is chosen. If use_system_file_chooser() is set to true, a
+  system FileChooser is opened. If the user picks multiple files,
+  these will be separated by a new line.
 
-  \a message is a string used to title the window.
+  \param \a message is a string used to title the window.
 
-  \a pattern is used to limit the files listed in a directory to those
+  \param \a pattern is used to limit the files listed in a directory to those
   matching the pattern. This matching is done by filename_match(). Use
-  NULL to show all files.
+  NULL to show all files. If use_system_file_chooser() is set to true, this
+  will automatically include the "All Files" option.
 
-  \a fname is a default folder/filename to fill in the chooser
+  \param \a fname is a default folder/filename to fill in the chooser
   with. If this ends with a '/' then this is a default folder and
   no file is preselected.
 
@@ -208,52 +145,209 @@
   is used. The first time the file chooser is called this defaults to
   a blank string.
 
-  The returned value points at a static buffer that is only good until
+  \param \a save determines whether or not the chooser is created in "save"
+  or "open" mode. This only effects WIN32 and will probably be replaced by the
+  option to OR FileChooser flags together.
+
+  \param \a relative is used to determine whether this function returns a 
relative
+  or an absolute pathname.
+
+  \return The returned value points at a static buffer that is only good until
   the next time the file_chooser() is called.
+
+  \todo Add a "flags" variable that allows the user to override flags.
 */
-const char* fltk::file_chooser(const char* message,
-                              const char* pattern,
-                              const char* fname,
-                              bool save)
-{
+
+const char * fltk::file_chooser(const char *message, const char *pattern,
+                               const char *fname, bool save,
+                               int        relative) {
+  static char  retname[1024];          // Returned filename
+
 #if defined( _WIN32 ) && !defined( __CYGWIN__ )
   if (use_system_fc) {
-    static char filenamebuffer[MAX_PATH];
-    static OPENFILENAME wreq;
+    static wchar_t filenamebuffer[MAX_PATH];
+    static wchar_t currentDirBuffer[MAX_PATH];
+    int length;
+    wchar_t *messageW, *patternW = NULL, *fnameW;
+    OPENFILENAMEW wreq;
+    static char ret[PATH_MAX];
+
+    // Convert all input to wide-char format.
+    length = utf8towc(message, strlen(message), NULL, 0);
+    messageW = new wchar_t [length+1];
+    *messageW = 0;
+    utf8towc(message, strlen(message), messageW, length + 1);
+    length = utf8towc(fname, strlen(fname), NULL, 0);
+    fnameW = new wchar_t [length+1];
+    *fnameW = 0;
+    utf8towc(fname, strlen(fname), fnameW, length + 1);
+
+    // convert the fltk filename pattern to a windows pattern
+    patternW = patternToWin(pattern, strlen(pattern)+1);
+
+    // set up the wreq struct. This sets the appropriate pattern(s),
+    // title of the window, and the flags (including MULTI)
     memset(&wreq, 0, sizeof(wreq));
     wreq.lStructSize = OPENFILENAME_SIZE_VERSION_400; // needed for Win < Win2k
-    wreq.lpstrFilter = pattern;
-    wreq.nFilterIndex = (pattern) ? 1 : 0;     
-    wreq.lpstrFile = filenamebuffer;
+    wreq.lpstrFilter = patternW;
+    wreq.nFilterIndex = (patternW) ? 1 : 0;
     wreq.nMaxFile = MAX_PATH;
-    wreq.lpstrTitle = message ? message : "Select the filename";
-    if(fname) {
+    wreq.lpstrTitle = messageW ? messageW : L"Select the filename";
+    
+    if (fnameW) {
       memset(filenamebuffer, 0, MAX_PATH);
       if((filenamebuffer[1] == ':') && (_getdrive() + 'A' - 1 == 
filenamebuffer[0]))
-       strncpy(filenamebuffer, fname + 2, MAX_PATH);
+       wcsncpy(filenamebuffer, fnameW + 2, MAX_PATH);
       else
-       strncpy(filenamebuffer, fname, MAX_PATH);
+       wcsncat(filenamebuffer, fnameW, MAX_PATH);
     }
-    wreq.Flags = OFN_NOCHANGEDIR;
-    if (save ? GetSaveFileName(&wreq) : GetOpenFileName(&wreq))
-      return wreq.lpstrFile;
+    wreq.lpstrFile = filenamebuffer;
+    GetCurrentDirectoryW(MAX_PATH, currentDirBuffer);
+    wreq.lpstrInitialDir = currentDirBuffer;
+    wreq.Flags = OFN_NOCHANGEDIR | OFN_NOVALIDATE | OFN_HIDEREADONLY |
+                OFN_EXPLORER | OFN_ENABLESIZING | OFN_ALLOWMULTISELECT;
+    if (save ? GetSaveFileNameW(&wreq) : GetOpenFileNameW(&wreq)) {
+      char temp[PATH_MAX], dir[PATH_MAX];
+      memset(temp, 0, PATH_MAX); memset(dir, 0, PATH_MAX);
+      ret[0] = 0;
+      int count = utf8fromwc(temp, PATH_MAX, wreq.lpstrFile, 
windowsWLen(wreq.lpstrFile)+1);
+      sprintf(dir, "%s\\", temp);
+      for (char *s = temp + strlen(temp) + 1; s && *s; s += strlen(s) + 1) {
+       sprintf(ret + strlen(ret), "%s%s\n", dir, s);
+      }
+      if (!ret[0]) sprintf(ret, "%s", temp);
+      delete [] messageW; delete [] fnameW; delete [] patternW;
+      return ret;
+    }
+    delete [] messageW; delete [] fnameW; delete [] patternW;
     return 0;
   }
 #endif
-  static FileChooser *fc;
-  if (!fc)
+  if (!fc) {
+    if (!fname || !*fname) fname = ".";
+    
     fc = new FileChooser(fname, pattern, FileChooser::CREATE, message);
+    fc->callback(callback, 0);
+  }
+  fc->type(FileChooser::CREATE);
+  fc->filter(pattern);
+  fc->label(message);
+  
+  if (!fname || !*fname) {
+    if (fc->filter() != pattern && (!pattern || !fc->filter() ||
+                               strcmp(pattern, fc->filter())) && fc->value()) {
+      // if pattern is different, remove name but leave old directory:
+      strlcpy(retname, fc->value(), sizeof(retname));
+      
+       char *p = strrchr(retname, '/');
+       
+        if (p) {
+         // If the filename is "/foo", then the directory will be "/", not
+         // ""...
+         if (p == retname)
+           retname[1] = '\0';
+         else
+           *p = '\0';
+       }
+       
+       // Set the directory...
+       fc->directory(retname);
+    }
+  }
   else {
-    fc->filter(pattern);
-    fc->text(fname);
-    fc->label(message);
+    fc->ok_label(current_label);
+  }  
+
+  fc->value(fname);
+  fc->exec(0, true);
+  
+  if (fc->value() && relative) {
+    fltk::filename_relative(retname, sizeof(retname), fc->value());
+    
+    return retname;
+  } else if (fc->value()) {
+    fltk::filename_absolute(retname, sizeof(retname), fc->value());
+    return retname;
   }
-  fc->exec(0,true);
-  return fc->text();
+  else return 0;
 }
 
-#endif
 
+// This function converts a FLTK pattern to Windows' format.
+// It is only static and not available via the API.
+wchar_t* patternToWin(const char* const pat, int len) {
+  wchar_t *out;
+  char temp[4096];
+  const char *ptr = pat;
+  char *tmp = temp;
+  bool wildCard = false;
+  int length;
+  for ( ; ptr && *ptr && ptr - pat < len; ptr += length) {
+    unsigned code;
+    if (*ptr & 0x80) {
+      code = utf8decode(ptr, pat+len, &length);
+    } else {
+      code = *ptr; length = 1;
+    }
+    switch (code) {
+      case '(':
+        if ((ptr-1) > pat) *(tmp-1) = '\0';
+        break;
+      case ')':
+        if ((tmp - temp + 1) < 4096 ) {
+          *tmp = '\0';
+          tmp++; // legal; '\0' is one-byte
+        }
+        break;
+      case '{':
+        wildCard = true;
+        break;
+      case '}':
+        wildCard = false;
+        break;
+      case ',':
+        if (wildCard && (tmp - temp + 2 < 4096)) {
+          *tmp = ';'; 
+          *(tmp+1) = '*';
+          *(tmp+2) = '.';
+         tmp += 3; // legal; ";*." makes up 3 bytes
+        }
+        break;
+      case '\t':
+      case '\n':
+        break;
+      default:
+        utf8encode(code, tmp);
+        tmp += length;
+        break;
+       }
+  }
+  // Make sure there's space for "All Files\0*.*\0\0
+  if (tmp + 15 < temp + 4096) {
+    tmp[0] = 'A'; tmp[1] = 'l'; tmp[2] = 'l'; tmp[3] = ' ';
+    tmp[4] = 'F'; tmp[5] = 'i'; tmp[6] = 'l'; tmp[7] = 'e';
+    tmp[8] = 's'; tmp[9] = '\0'; tmp[10] = '*'; tmp[11] = '.';
+    tmp[12] = '*'; tmp[13] = '\0'; tmp[14] = '\0';
+    tmp += 15;
+  }
+
+  length = utf8towc(temp, tmp - temp, NULL, 0);
+  out = new wchar_t [length];
+  memset(out, 0, sizeof(wchar_t)*(length));
+  utf8towc(temp, tmp - temp, out, length);
+  return out;
+}
+  
+// This function determines the length of a Windows
+// double-null-terminated string. It is static and 
+// not available via the public API.
+unsigned windowsWLen(const wchar_t* const string) {
+  unsigned out = 0;
+  for ( ; ; out++)
+    if (!string[out] && !string[out+1])
+      return out;
+}
+
 //
 // End of "$Id$".
 //

Modified: trunk/test/file_chooser.cxx
===================================================================
--- trunk/test/file_chooser.cxx 2011-03-01 19:45:05 UTC (rev 8491)
+++ trunk/test/file_chooser.cxx 2011-03-02 00:51:46 UTC (rev 8492)
@@ -40,7 +40,9 @@
 //
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <fltk/FileChooser.h>
+#include <fltk/file_chooser.h>
 #include <fltk/FileIcon.h>
 #include <fltk/SharedImage.h>
 #include <fltk/pnmImage.h>
@@ -48,7 +50,6 @@
 #include <fltk/LightButton.h>
 #include <fltk/run.h>
 #include <string.h>
-#include <fltk/file_chooser.h>
 #include <fltk/ask.h>
 
 using namespace fltk;
@@ -347,7 +348,8 @@
 
 #else
   const char *defaultname = "images/testimg.jpg";
-  const char * name = fltk::file_chooser("Open","Image Files 
(*.{bmp,gif,jpg,png})\t", defaultname );
+  fltk::use_system_file_chooser(true);
+  const char * name = fltk::file_chooser("Open","Image Files 
(*.{bmp,gif,jpg,png})\t", defaultname);
   fltk::message("File selected is : %s", name && strlen(name) ? name : 
"<no_selection>");
 #endif
 

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to