FLTK 1.3.2
Fl_Native_File_Chooser.H
Go to the documentation of this file.
00001 //
00002 // "$Id$"
00003 //
00004 // FLTK native OS file chooser widget
00005 //
00006 // Copyright 1998-2010 by Bill Spitzak and others.
00007 // Copyright 2004 Greg Ercolano.
00008 //
00009 // This library is free software. Distribution and use rights are outlined in
00010 // the file "COPYING" which should have been included with this file.  If this
00011 // file is missing or damaged, see the license at:
00012 //
00013 //     http://www.fltk.org/COPYING.php
00014 //
00015 // Please report all bugs and problems on the following page:
00016 //
00017 //     http://www.fltk.org/str.php
00018 //
00019 
00023 #ifndef FL_NATIVE_FILE_CHOOSER_H
00024 #define FL_NATIVE_FILE_CHOOSER_H
00025 
00026 /* \file
00027  Fl_Native_File_Chooser widget. */
00028 
00029 // Use Windows' chooser
00030 #ifdef WIN32
00031 // #define _WIN32_WINNT 0x0501  // needed for OPENFILENAME's 'FlagsEx'
00032 #include <stdio.h>
00033 #include <stdlib.h>             // malloc
00034 #include <windows.h>
00035 #include <commdlg.h>            // OPENFILENAME, GetOpenFileName()
00036 #include <shlobj.h>             // BROWSEINFO, SHBrowseForFolder()
00037 #endif
00038 
00039 // Use Apple's chooser
00040 #ifdef __APPLE__
00041 #define MAXFILTERS      80
00042 #endif
00043 
00044 // All else falls back to FLTK's own chooser
00045 #if ! defined(__APPLE__) && !defined(WIN32)
00046 #include <FL/Fl_File_Chooser.H>
00047 #include <unistd.h>             // _POSIX_NAME_MAX
00048 #else
00049 #include <FL/filename.H>        // FL_EXPORT
00050 #endif
00051 
00052 
00105 class FL_EXPORT Fl_Native_File_Chooser {
00106 public:
00107   enum Type {
00108     BROWSE_FILE = 0,                    
00109     BROWSE_DIRECTORY,                   
00110     BROWSE_MULTI_FILE,                  
00111     BROWSE_MULTI_DIRECTORY,             
00112     BROWSE_SAVE_FILE,                   
00113     BROWSE_SAVE_DIRECTORY               
00114   };
00115   enum Option {
00116     NO_OPTIONS     = 0x0000,            
00117     SAVEAS_CONFIRM = 0x0001,            
00118     NEW_FOLDER     = 0x0002,            
00119     PREVIEW        = 0x0004             
00120   };
00122   static const char *file_exists_message;
00123   
00124 public:
00125   Fl_Native_File_Chooser(int val=BROWSE_FILE);
00126   ~Fl_Native_File_Chooser();
00127   
00128   // Public methods
00129   void type(int);
00130   int type() const;
00131   void options(int);
00132   int options() const;
00133   int count() const;
00134   const char *filename() const;
00135   const char *filename(int i) const;
00136   void directory(const char *val);
00137   const char *directory() const;
00138   void title(const char *);
00139   const char* title() const;
00140   const char *filter() const;
00141   void filter(const char *);
00142   int filters() const;
00143   void filter_value(int i);
00144   int filter_value() const;
00145   void preset_file(const char*);
00146   const char* preset_file() const;
00147   const char *errmsg() const;
00148   int show();
00149   
00150 #ifdef WIN32
00151 private:
00152   int  _btype;                  // kind-of browser to show()
00153   int  _options;                // general options
00154   OPENFILENAMEW _ofn;           // GetOpenFileName() & GetSaveFileName() struct
00155   BROWSEINFO   _binf;           // SHBrowseForFolder() struct
00156   char  **_pathnames;           // array of pathnames
00157   int     _tpathnames;          // total pathnames
00158   char   *_directory;           // default pathname to use
00159   char   *_title;               // title for window
00160   char   *_filter;              // user-side search filter
00161   char   *_parsedfilt;          // filter parsed for Windows dialog
00162   int     _nfilters;            // number of filters parse_filter counted
00163   char   *_preset_file;         // the file to preselect
00164   char   *_errmsg;              // error message
00165   
00166   // Private methods
00167   void errmsg(const char *msg);
00168   
00169   void clear_pathnames();
00170   void set_single_pathname(const char *s);
00171   void add_pathname(const char *s);
00172   
00173   void FreePIDL(LPITEMIDLIST pidl);
00174   void ClearOFN();
00175   void ClearBINF();
00176   void Win2Unix(char *s);
00177   void Unix2Win(char *s);
00178   int showfile();
00179   static int CALLBACK Dir_CB(HWND win, UINT msg, LPARAM param, LPARAM data);
00180   int showdir();
00181   
00182   void parse_filter(const char *);
00183   void clear_filters();
00184   void add_filter(const char *, const char *);
00185 #endif
00186 
00187 #ifdef __APPLE__
00188 private:
00189   int             _btype;               // kind-of browser to show()
00190   int             _options;             // general options
00191   void           *_panel;
00192   char          **_pathnames;           // array of pathnames
00193   int             _tpathnames;          // total pathnames
00194   char           *_directory;           // default pathname to use
00195   char           *_title;               // title for window
00196   char           *_preset_file;         // the 'save as' filename
00197   
00198   char           *_filter;              // user-side search filter, eg:
00199                                         // C Files\t*.[ch]\nText Files\t*.txt"
00200   
00201   char           *_filt_names;          // filter names (tab delimited)
00202                                         // eg. "C Files\tText Files"
00203   
00204   char           *_filt_patt[MAXFILTERS];
00205   // array of filter patterns, eg:
00206   //     _filt_patt[0]="*.{cxx,h}"
00207   //     _filt_patt[1]="*.txt"
00208   
00209   int             _filt_total;          // parse_filter() # of filters loaded
00210   int             _filt_value;          // index of the selected filter
00211   char           *_errmsg;              // error message
00212   
00213   // Private methods
00214   void errmsg(const char *msg);
00215   void clear_pathnames();
00216   void set_single_pathname(const char *s);
00217   int get_saveas_basename(void);
00218   void clear_filters();
00219   void add_filter(const char *, const char *);
00220   void parse_filter(const char *from);
00221   int post();
00222   int runmodal();
00223 #endif
00224 
00225 #if ! defined(__APPLE__) && !defined(WIN32)
00226 private:
00227   int   _btype;                 // kind-of browser to show()
00228   int   _options;               // general options
00229   int   _nfilters;
00230   char *_filter;                // user supplied filter
00231   char *_parsedfilt;            // parsed filter
00232   int   _filtvalue;             // selected filter
00233   char *_preset_file;
00234   char *_prevvalue;             // Returned filename
00235   char *_directory;
00236   char *_errmsg;                // error message
00237   Fl_File_Chooser *_file_chooser;
00238   
00239   // Private methods
00240   void errmsg(const char *msg);
00241   int type_fl_file(int);
00242   void parse_filter();
00243   void keeplocation();
00244   int exist_dialog();
00245 #endif
00246 };
00247 
00248 
00249 #endif /*FL_NATIVE_FILE_CHOOSER_H*/
00250 
00251 //
00252 // End of "$Id$".
00253 //