FLTK 1.3.x

Fl_Native_File_Chooser_WIN32.H

00001 //
00002 // "$Id: Fl_Native_File_Chooser_WIN32.H 8022 2010-12-12 23:21:03Z AlbrechtS $"
00003 //
00004 // FLTK native OS file chooser widget
00005 //
00006 // Copyright 1998-2010 by Bill Spitzak and others.
00007 // Copyright 2004 by Greg Ercolano.
00008 // April 2005 - API changes, improved filter processing by Nathan Vander Wilt
00009 //
00010 // This library is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU Library General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2 of the License, or (at your option) any later version.
00014 //
00015 // This library is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Library General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Library General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA.
00024 //
00025 // Please report all bugs and problems to:
00026 //
00027 //     http://www.fltk.org/str.php
00028 //
00029 
00030 #ifndef FL_DOXYGEN              // PREVENT DOXYGEN'S USE OF THIS FILE
00031 
00032 // #define _WIN32_WINNT 0x0501  // needed for OPENFILENAME's 'FlagsEx'
00033 #include <stdio.h>
00034 #include <stdlib.h>             // malloc
00035 #include <windows.h>
00036 #include <commdlg.h>            // OPENFILENAME, GetOpenFileName()
00037 #include <shlobj.h>             // BROWSEINFO, SHBrowseForFolder()
00038 
00039 class FL_EXPORT Fl_Native_File_Chooser {
00040 public:
00041   enum Type {
00042     BROWSE_FILE = 0,
00043     BROWSE_DIRECTORY,
00044     BROWSE_MULTI_FILE,
00045     BROWSE_MULTI_DIRECTORY,
00046     BROWSE_SAVE_FILE,
00047     BROWSE_SAVE_DIRECTORY
00048   };
00049   enum Option {
00050     NO_OPTIONS     = 0x0000,    // no options enabled
00051     SAVEAS_CONFIRM = 0x0001,    // Show native 'Save As' overwrite confirm dialog (if supported)
00052     NEW_FOLDER     = 0x0002,    // Show 'New Folder' icon (if supported)
00053     PREVIEW        = 0x0004,    // enable preview mode
00054   };
00055 private:
00056   int  _btype;                  // kind-of browser to show()
00057   int  _options;                // general options
00058   OPENFILENAMEW _ofn;           // GetOpenFileName() & GetSaveFileName() struct
00059   BROWSEINFO   _binf;           // SHBrowseForFolder() struct
00060   char  **_pathnames;           // array of pathnames
00061   int     _tpathnames;          // total pathnames
00062   char   *_directory;           // default pathname to use
00063   char   *_title;               // title for window
00064   char   *_filter;              // user-side search filter
00065   char   *_parsedfilt;          // filter parsed for Windows dialog
00066   int     _nfilters;            // number of filters parse_filter counted
00067   char   *_preset_file;         // the file to preselect
00068   char   *_errmsg;              // error message
00069 
00070   // Private methods
00071   void errmsg(const char *msg);
00072 
00073   void clear_pathnames();
00074   void set_single_pathname(const char *s);
00075   void add_pathname(const char *s);
00076 
00077   void FreePIDL(ITEMIDLIST *pidl);
00078   void ClearOFN();
00079   void ClearBINF();
00080   void Win2Unix(char *s);
00081   void Unix2Win(char *s);
00082   int showfile();
00083   static int CALLBACK Dir_CB(HWND win, UINT msg, LPARAM param, LPARAM data);
00084   int showdir();
00085 
00086   void parse_filter(const char *);
00087   void clear_filters();
00088   void add_filter(const char *, const char *);
00089 
00090 public:
00091   Fl_Native_File_Chooser(int val = BROWSE_FILE);
00092   ~Fl_Native_File_Chooser();
00093 
00094   // Public methods
00095   void type(int val);
00096   int type() const;
00097   void options(int);
00098   int options() const;
00099   int count() const;
00100   const char *filename() const;
00101   const char *filename(int i) const;
00102   void directory(const char *val);
00103   const char *directory() const;
00104   void title(const char *val);
00105   const char *title() const;
00106   const char *filter() const;
00107   void filter(const char *val);
00108   int filters() const { return _nfilters; }
00109   void filter_value(int i);
00110   int filter_value() const;
00111   void preset_file(const char *);
00112   const char *preset_file() const;
00113   const char *errmsg() const;
00114   int show();
00115 };
00116 #endif 
00118 //
00119 // End of "$Id: Fl_Native_File_Chooser_WIN32.H 8022 2010-12-12 23:21:03Z AlbrechtS $".
00120 //