llfilepicker.h

Go to the documentation of this file.
00001 
00032 // OS specific file selection dialog. This is implemented as a
00033 // singleton class, so call the instance() method to get the working
00034 // instance. When you call getMultipleOpenFile(), it locks the picker
00035 // until you iterate to the end of the list of selected files with
00036 // getNextFile() or call reset().
00037 
00038 #ifndef LL_LLFILEPICKER_H
00039 #define LL_LLFILEPICKER_H
00040 
00041 #include "stdtypes.h"
00042 
00043 #if LL_DARWIN
00044 #include <Carbon/Carbon.h>
00045 
00046 // AssertMacros.h does bad things.
00047 #undef verify
00048 #undef check
00049 #undef require
00050 
00051 #include <vector>
00052 #include "llstring.h"
00053 
00054 #endif
00055 
00056 // Need commdlg.h for OPENFILENAMEA
00057 #ifdef LL_WINDOWS
00058 #include <commdlg.h>
00059 #endif
00060 
00061 // mostly for Linux, possible on others
00062 #if LL_GTK
00063 # include "gtk/gtk.h"
00064 #endif // LL_GTK
00065 
00066 // also mostly for Linux, for some X11-specific filepicker usability tweaks
00067 #if LL_X11
00068 #include "SDL/SDL_syswm.h"
00069 #endif
00070 
00071 #if LL_GTK
00072 // we use an aggregate structure so we can pass its pointer through a C callback
00073 typedef struct {
00074         GtkWidget *win;
00075         std::vector<LLString> fileVector;
00076         std::string contextName;
00077 } StoreFilenamesStruct;
00078 #endif // LL_GTK
00079 
00080 class LLFilePicker
00081 {
00082 #ifdef LL_GTK
00083         friend class LLDirPicker;
00084         friend void chooser_responder(GtkWidget *, gint, gpointer);
00085 #endif // LL_GTK
00086 public:
00087         // calling this before main() is undefined
00088         static LLFilePicker& instance( void ) { return sInstance; }
00089 
00090         enum ELoadFilter
00091         {
00092                 FFLOAD_ALL = 1,
00093                 FFLOAD_WAV = 2,
00094                 FFLOAD_IMAGE = 3,
00095                 FFLOAD_ANIM = 4,
00096 #ifdef _CORY_TESTING
00097                 FFLOAD_GEOMETRY = 5,
00098 #endif
00099                 FFLOAD_XML = 6,
00100                 FFLOAD_SLOBJECT = 7,
00101                 FFLOAD_RAW = 8,
00102         };
00103 
00104         enum ESaveFilter
00105         {
00106                 FFSAVE_ALL = 1,
00107                 FFSAVE_WAV = 3,
00108                 FFSAVE_TGA = 4,
00109                 FFSAVE_BMP = 5,
00110                 FFSAVE_AVI = 6,
00111                 FFSAVE_ANIM = 7,
00112 #ifdef _CORY_TESTING
00113                 FFSAVE_GEOMETRY = 8,
00114 #endif
00115                 FFSAVE_XML = 9,
00116                 FFSAVE_COLLADA = 10,
00117                 FFSAVE_RAW = 11,
00118                 FFSAVE_J2C = 12,
00119         };
00120 
00121         // open the dialog. This is a modal operation
00122         BOOL getSaveFile( ESaveFilter filter = FFSAVE_ALL, const char* filename = NULL );
00123         BOOL getOpenFile( ELoadFilter filter = FFLOAD_ALL );
00124         BOOL getMultipleOpenFiles( ELoadFilter filter = FFLOAD_ALL );
00125 
00126         // Get the filename(s) found. getFirstFile() sets the pointer to
00127         // the start of the structure and allows the start of iteration.
00128         const char* getFirstFile();
00129 
00130         // getNextFile() increments the internal representation and
00131         // returns the next file specified by the user. Returns NULL when
00132         // no more files are left. Further calls to getNextFile() are
00133         // undefined.
00134         const char* getNextFile();
00135 
00136         // This utility function extracts the directory name but doesn't
00137         // do any incrementing. This is currently only supported when
00138         // you're opening multiple files.
00139         const char* getDirname();
00140 
00141         // clear any lists of buffers or whatever, and make sure the file
00142         // picker isn't locked.
00143         void reset();
00144 
00145 private:
00146         enum
00147         {
00148                 SINGLE_FILENAME_BUFFER_SIZE = 1024,
00149                 //FILENAME_BUFFER_SIZE = 65536
00150                 FILENAME_BUFFER_SIZE = 65000
00151         };
00152         
00153         void buildFilename( void );
00154 
00155 #if LL_WINDOWS
00156         OPENFILENAMEW mOFN;                             // for open and save dialogs
00157         char *mOpenFilter;
00158         WCHAR mFilesW[FILENAME_BUFFER_SIZE];
00159 
00160         BOOL setupFilter(ELoadFilter filter);
00161 #endif
00162 
00163 #if LL_DARWIN
00164         NavDialogCreationOptions mNavOptions;
00165         std::vector<LLString> mFileVector;
00166         UInt32 mFileIndex;
00167         
00168         OSStatus doNavChooseDialog(ELoadFilter filter);
00169         OSStatus doNavSaveDialog(ESaveFilter filter, const char* filename);
00170         void getFilePath(SInt32 index);
00171         void getFileName(SInt32 index);
00172         static Boolean navOpenFilterProc(AEDesc *theItem, void *info, void *callBackUD, NavFilterModes filterMode);
00173 #endif
00174 
00175 #if LL_GTK
00176         StoreFilenamesStruct mStoreFilenames;
00177         U32 mNextFileIndex;
00178         // we remember the last path that was accessed for a particular usage
00179         static std::map <std::string, std::string> sContextToPathMap;
00180 #endif
00181 
00182         char mFiles[FILENAME_BUFFER_SIZE];      /*Flawfinder: ignore*/
00183         char mFilename[LL_MAX_PATH];    /*Flawfinder: ignore*/
00184         char* mCurrentFile;
00185         BOOL mLocked;
00186         BOOL mMultiFile;
00187 
00188         static LLFilePicker sInstance;
00189         
00190 protected:
00191 #if LL_GTK
00192         GtkWindow* buildFilePicker(bool is_save, bool is_folder,
00193                                    std::string context = "generic");
00194 #endif
00195 
00196 public:
00197         // don't call these directly please.
00198         LLFilePicker();
00199         ~LLFilePicker();
00200 };
00201 
00202 #endif

Generated on Thu Jul 1 06:08:30 2010 for Second Life Viewer by  doxygen 1.4.7