vdk 2.4.0
FileDialog.h
00001 /*
00002  * ===========================
00003  * VDK Visual Develeopment Kit
00004  * Version 0.4
00005  * October 1998
00006  * ===========================
00007  *
00008  * Copyright (C) 1998, Mario Motta
00009  * Developed by Mario Motta <mmotta@guest.net>
00010  *
00011  * This library is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU Library General Public
00013  * License as published by the Free Software Foundation; either
00014  * version 2 of the License, or (at your option) any later version.
00015  *
00016  * This library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * Library General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Library General Public
00022  * License along with this library; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00024  * 02111-1307, USA.
00025  */
00026 
00027 #ifndef FILEDIALOG_H
00028 #define FILEDIALOG_H
00029 #include <vdk/vdk.h>
00030 
00031 // undef this and you can use regex library
00032 // so in dialog filter: '*\.(cc|h)$'
00033 #define _USE_FNMATCH
00034 
00035 #ifndef _USE_FNMATCH
00036 # include <regex.h>
00037 #else
00038 # include <fnmatch.h>
00039 #endif
00040 
00041 #include <dirent.h>
00042 extern "C" {
00043 #include <sys/stat.h>
00044 }
00045 
00046 //
00047 typedef VDKArray<VDKString> FileStringArray;
00048 typedef VDKValueList<VDKString> FileStringList;
00049 typedef VDKValueListIterator<VDKString> FileStringListIterator;
00078 class VDKFileDialog: public VDKForm
00079 {
00080   VDKBox* listbox;
00081   VDKString home;
00082   bool init();
00083   FileStringList* load_dir(char* dir, int mask);
00084   // mode == 0 filter dirs, 1 filters files
00085   FileStringList* filter(FileStringList* list, int mode = 0);
00086   void LoadFileList(FileStringList* list);
00087   void LoadDirList(FileStringList* list);
00088   void LoadDir(char* dir = (char*) NULL);
00089  protected:
00090   VDKString first_pcwd,pcwd;
00091   FileStringArray* selections;
00092   VDKCustomList *dirlist;
00093   VDKCustomList *filelist;
00094   VDKEntry *filetype;
00095   VDKCustomButton *open,*cancel;
00096   VDKLabel *dir_label,*filetypeLabel;
00097   VDKCheckButton *hiddenCb;
00098   bool DirListDoubleClick(VDKObject* sender);
00099   bool OpenClick(VDKObject*);
00100   bool CancelClick(VDKObject*);
00101   bool ToggleHidden(VDKObject*);
00102   bool SetFileMask(VDKObject*);
00103  public:
00107   VDKReadWriteValueProp<VDKFileDialog,VDKString> Filter;
00108   VDKFileDialog(VDKForm* owner,
00109                 FileStringArray* selections,
00110                 char* title = "",
00111                 GtkWindowType display = GTK_WINDOW_TOPLEVEL);
00112   virtual ~VDKFileDialog() {}
00113   bool CanClose();
00114   virtual void Setup(void) {}
00115   virtual void OnShow(VDKForm*);
00116   void SetFilter(VDKString f)
00117     { Filter(f); }
00118   VDKString GetFilter(void)
00119     {
00120       VDKString filter = Filter;
00121       return VDKString(filter);
00122     }
00123   DECLARE_SIGNAL_MAP(VDKFileDialog);
00124 };
00125 
00126 #endif