FLTK 1.3.2
Fl_Native_File_Chooser.H
Go to the documentation of this file.
00001 //
00002 // "$Id: Fl_Native_File_Chooser.H 9825 2013-02-19 15:19:58Z manolo $"
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     USE_FILTER_EXT = 0x0008             
00121   };
00123   static const char *file_exists_message;
00124   
00125 public:
00126   Fl_Native_File_Chooser(int val=BROWSE_FILE);
00127   ~Fl_Native_File_Chooser();
00128   
00129   // Public methods
00130   void type(int);
00131   int type() const;
00132   void options(int);
00133   int options() const;
00134   int count() const;
00135   const char *filename() const;
00136   const char *filename(int i) const;
00137   void directory(const char *val);
00138   const char *directory() const;
00139   void title(const char *);
00140   const char* title() const;
00141   const char *filter() const;
00142   void filter(const char *);
00143   int filters() const;
00144   void filter_value(int i);
00145   int filter_value() const;
00146   void preset_file(const char*);
00147   const char* preset_file() const;
00148   const char *errmsg() const;
00149   int show();
00150   
00151 #ifdef WIN32
00152 private:
00153   int  _btype;                  // kind-of browser to show()
00154   int  _options;                // general options
00155   OPENFILENAMEW _ofn;           // GetOpenFileName() & GetSaveFileName() struct
00156   BROWSEINFO   _binf;           // SHBrowseForFolder() struct
00157   char  **_pathnames;           // array of pathnames
00158   int     _tpathnames;          // total pathnames
00159   char   *_directory;           // default pathname to use
00160   char   *_title;               // title for window
00161   char   *_filter;              // user-side search filter
00162   char   *_parsedfilt;          // filter parsed for Windows dialog
00163   int     _nfilters;            // number of filters parse_filter counted
00164   char   *_preset_file;         // the file to preselect
00165   char   *_errmsg;              // error message
00166   
00167   // Private methods
00168   void errmsg(const char *msg);
00169   
00170   void clear_pathnames();
00171   void set_single_pathname(const char *s);
00172   void add_pathname(const char *s);
00173   
00174   void FreePIDL(LPITEMIDLIST pidl);
00175   void ClearOFN();
00176   void ClearBINF();
00177   void Win2Unix(char *s);
00178   void Unix2Win(char *s);
00179   int showfile();
00180   static int CALLBACK Dir_CB(HWND win, UINT msg, LPARAM param, LPARAM data);
00181   int showdir();
00182   
00183   void parse_filter(const char *);
00184   void clear_filters();
00185   void add_filter(const char *, const char *);
00186 #endif
00187 
00188 #ifdef __APPLE__
00189 private:
00190   int             _btype;               // kind-of browser to show()
00191   int             _options;             // general options
00192   void           *_panel;
00193   char          **_pathnames;           // array of pathnames
00194   int             _tpathnames;          // total pathnames
00195   char           *_directory;           // default pathname to use
00196   char           *_title;               // title for window
00197   char           *_preset_file;         // the 'save as' filename
00198   
00199   char           *_filter;              // user-side search filter, eg:
00200                                         // C Files\t*.[ch]\nText Files\t*.txt"
00201   
00202   char           *_filt_names;          // filter names (tab delimited)
00203                                         // eg. "C Files\tText Files"
00204   
00205   char           *_filt_patt[MAXFILTERS];
00206   // array of filter patterns, eg:
00207   //     _filt_patt[0]="*.{cxx,h}"
00208   //     _filt_patt[1]="*.txt"
00209   
00210   int             _filt_total;          // parse_filter() # of filters loaded
00211   int             _filt_value;          // index of the selected filter
00212   char           *_errmsg;              // error message
00213   
00214   // Private methods
00215   void errmsg(const char *msg);
00216   void clear_pathnames();
00217   void set_single_pathname(const char *s);
00218   int get_saveas_basename(void);
00219   void clear_filters();
00220   void add_filter(const char *, const char *);
00221   void parse_filter(const char *from);
00222   int post();
00223   int runmodal();
00224 #endif
00225 
00226 #if ! defined(__APPLE__) && !defined(WIN32)
00227 private:
00228   int   _btype;                 // kind-of browser to show()
00229   int   _options;               // general options
00230   int   _nfilters;
00231   char *_filter;                // user supplied filter
00232   char *_parsedfilt;            // parsed filter
00233   int   _filtvalue;             // selected filter
00234   char *_preset_file;
00235   char *_prevvalue;             // Returned filename
00236   char *_directory;
00237   char *_errmsg;                // error message
00238   Fl_File_Chooser *_file_chooser;
00239   
00240   // Private methods
00241   void errmsg(const char *msg);
00242   int type_fl_file(int);
00243   void parse_filter();
00244   void keeplocation();
00245   int exist_dialog();
00246 #endif
00247 };
00248 
00249 
00250 #endif /*FL_NATIVE_FILE_CHOOSER_H*/
00251 
00252 //
00253 // End of "$Id: Fl_Native_File_Chooser.H 9825 2013-02-19 15:19:58Z manolo $".
00254 //