FLTK 1.3.0
Fl_Native_File_Chooser.H
Go to the documentation of this file.
00001 //
00002 // "$Id: Fl_Native_File_Chooser.H 8380 2011-02-06 10:07:28Z 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; you can redistribute it and/or
00010 // modify it under the terms of the GNU Library General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2 of the License, or (at your option) any later version.
00013 //
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Library General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Library General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022 // USA.
00023 //
00024 // Please report all bugs and problems on the following page:
00025 //
00026 //     http://www.fltk.org/str.php
00027 //
00028 
00083 #ifndef FL_NATIVE_FILE_CHOOSER_H
00084 #define FL_NATIVE_FILE_CHOOSER_H
00085 
00086 /* \file
00087  Fl_Native_File_Chooser widget. */
00088 
00089 // Use Windows' chooser
00090 #ifdef WIN32
00091 // #define _WIN32_WINNT 0x0501  // needed for OPENFILENAME's 'FlagsEx'
00092 #include <stdio.h>
00093 #include <stdlib.h>             // malloc
00094 #include <windows.h>
00095 #include <commdlg.h>            // OPENFILENAME, GetOpenFileName()
00096 #include <shlobj.h>             // BROWSEINFO, SHBrowseForFolder()
00097 #endif
00098 
00099 // Use Apple's chooser
00100 #ifdef __APPLE__
00101 #include <FL/filename.H>
00102 #define MAXFILTERS      80
00103 #endif
00104 
00105 // All else falls back to FLTK's own chooser
00106 #if ! defined(__APPLE__) && !defined(WIN32)
00107 #include <FL/Fl_File_Chooser.H>
00108 #include <unistd.h>             // _POSIX_NAME_MAX
00109 #endif
00110 
00111 
00158 class FL_EXPORT Fl_Native_File_Chooser {
00159 public:
00160   enum Type {
00161     BROWSE_FILE = 0,                    
00162     BROWSE_DIRECTORY,                   
00163     BROWSE_MULTI_FILE,                  
00164     BROWSE_MULTI_DIRECTORY,             
00165     BROWSE_SAVE_FILE,                   
00166     BROWSE_SAVE_DIRECTORY               
00167   };
00168   enum Option {
00169     NO_OPTIONS     = 0x0000,            
00170     SAVEAS_CONFIRM = 0x0001,            
00171     NEW_FOLDER     = 0x0002,            
00172     PREVIEW        = 0x0004             
00173   };
00175   static const char *file_exists_message;
00176   
00177 public:
00178   Fl_Native_File_Chooser(int val=BROWSE_FILE);
00179   ~Fl_Native_File_Chooser();
00180   
00181   // Public methods
00182   void type(int);
00183   int type() const;
00184   void options(int);
00185   int options() const;
00186   int count() const;
00187   const char *filename() const;
00188   const char *filename(int i) const;
00189   void directory(const char *val);
00190   const char *directory() const;
00191   void title(const char *);
00192   const char* title() const;
00193   const char *filter() const;
00194   void filter(const char *);
00195   int filters() const;
00196   void filter_value(int i);
00197   int filter_value() const;
00198   void preset_file(const char*);
00199   const char* preset_file() const;
00200   const char *errmsg() const;
00201   int show();
00202   
00203 #ifdef WIN32
00204 private:
00205   int  _btype;                  // kind-of browser to show()
00206   int  _options;                // general options
00207   OPENFILENAMEW _ofn;           // GetOpenFileName() & GetSaveFileName() struct
00208   BROWSEINFO   _binf;           // SHBrowseForFolder() struct
00209   char  **_pathnames;           // array of pathnames
00210   int     _tpathnames;          // total pathnames
00211   char   *_directory;           // default pathname to use
00212   char   *_title;               // title for window
00213   char   *_filter;              // user-side search filter
00214   char   *_parsedfilt;          // filter parsed for Windows dialog
00215   int     _nfilters;            // number of filters parse_filter counted
00216   char   *_preset_file;         // the file to preselect
00217   char   *_errmsg;              // error message
00218   
00219   // Private methods
00220   void errmsg(const char *msg);
00221   
00222   void clear_pathnames();
00223   void set_single_pathname(const char *s);
00224   void add_pathname(const char *s);
00225   
00226   void FreePIDL(ITEMIDLIST *pidl);
00227   void ClearOFN();
00228   void ClearBINF();
00229   void Win2Unix(char *s);
00230   void Unix2Win(char *s);
00231   int showfile();
00232   static int CALLBACK Dir_CB(HWND win, UINT msg, LPARAM param, LPARAM data);
00233   int showdir();
00234   
00235   void parse_filter(const char *);
00236   void clear_filters();
00237   void add_filter(const char *, const char *);
00238 #endif
00239 
00240 #ifdef __APPLE__
00241 private:
00242   int             _btype;               // kind-of browser to show()
00243   int             _options;             // general options
00244   void           *_panel;
00245   char          **_pathnames;           // array of pathnames
00246   int             _tpathnames;          // total pathnames
00247   char           *_directory;           // default pathname to use
00248   char           *_title;               // title for window
00249   char           *_preset_file;         // the 'save as' filename
00250   
00251   char           *_filter;              // user-side search filter, eg:
00252                                         // C Files\t*.[ch]\nText Files\t*.txt"
00253   
00254   char           *_filt_names;          // filter names (tab delimited)
00255                                         // eg. "C Files\tText Files"
00256   
00257   char           *_filt_patt[MAXFILTERS];
00258   // array of filter patterns, eg:
00259   //     _filt_patt[0]="*.{cxx,h}"
00260   //     _filt_patt[1]="*.txt"
00261   
00262   int             _filt_total;          // parse_filter() # of filters loaded
00263   int             _filt_value;          // index of the selected filter
00264   char           *_errmsg;              // error message
00265   
00266   // Private methods
00267   void errmsg(const char *msg);
00268   void clear_pathnames();
00269   void set_single_pathname(const char *s);
00270   int get_saveas_basename(void);
00271   void clear_filters();
00272   void add_filter(const char *, const char *);
00273   void parse_filter(const char *from);
00274   int post();
00275 #endif
00276 
00277 #if ! defined(__APPLE__) && !defined(WIN32)
00278 private:
00279   int   _btype;                 // kind-of browser to show()
00280   int   _options;               // general options
00281   int   _nfilters;
00282   char *_filter;                // user supplied filter
00283   char *_parsedfilt;            // parsed filter
00284   int   _filtvalue;             // selected filter
00285   char *_preset_file;
00286   char *_prevvalue;             // Returned filename
00287   char *_directory;
00288   char *_errmsg;                // error message
00289   Fl_File_Chooser *_file_chooser;
00290   
00291   // Private methods
00292   void errmsg(const char *msg);
00293   int type_fl_file(int);
00294   void parse_filter();
00295   void keeplocation();
00296   int exist_dialog();
00297 #endif
00298 };
00299 
00300 
00301 #endif /*FL_NATIVE_FILE_CHOOSER_H*/
00302 
00303 //
00304 // End of "$Id: Fl_Native_File_Chooser.H 8380 2011-02-06 10:07:28Z manolo $".
00305 //