From b600ed13625645eb985acf49eecd06fd111eb061 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 14 Jun 2003 13:31:49 +0000 Subject: [PATCH] wxFileDialog cleanup, extracted common code to fldlgcmn.cpp (patch 754187) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21149 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- distrib/msw/tmake/filelist.txt | 1 + include/wx/filedlg.h | 75 ++++++++- include/wx/generic/filedlgg.h | 79 +++------- include/wx/gtk/filedlg.h | 48 +----- include/wx/gtk1/filedlg.h | 48 +----- include/wx/mac/filedlg.h | 30 +--- include/wx/motif/filedlg.h | 30 +--- include/wx/msw/filedlg.h | 42 +---- include/wx/os2/filedlg.h | 56 +------ src/common/fldlgcmn.cpp | 280 +++++++++++++++++++++++++++++++++ src/generic/dirctrlg.cpp | 38 +---- src/generic/filedlgg.cpp | 255 ++++++++---------------------- src/gtk/filedlg.cpp | 81 ---------- src/gtk1/filedlg.cpp | 81 ---------- src/mac/carbon/filedlg.cpp | 96 ----------- src/mac/filedlg.cpp | 96 ----------- src/motif/filedlg.cpp | 95 ----------- src/msw/filedlg.cpp | 160 +------------------ src/os2/filedlg.cpp | 193 ----------------------- 19 files changed, 458 insertions(+), 1326 deletions(-) create mode 100644 src/common/fldlgcmn.cpp diff --git a/distrib/msw/tmake/filelist.txt b/distrib/msw/tmake/filelist.txt index b8b91ab8f9..4bb931a569 100644 --- a/distrib/msw/tmake/filelist.txt +++ b/distrib/msw/tmake/filelist.txt @@ -164,6 +164,7 @@ fileconf.cpp Common Base filefn.cpp Common Base filename.cpp Common Base filesys.cpp Common Base +fldlgcmn.cpp Common fontcmn.cpp Common fontmap.cpp Common Base framecmn.cpp Common diff --git a/include/wx/filedlg.h b/include/wx/filedlg.h index 16ef211551..929ba286a4 100644 --- a/include/wx/filedlg.h +++ b/include/wx/filedlg.h @@ -1,8 +1,27 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: filedlg.h +// Purpose: wxFileDialog base header +// Author: Robert Roebling +// Modified by: +// Created: 8/17/99 +// Copyright: (c) Robert Roebling +// RCS-ID: +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + #ifndef _WX_FILEDLG_H_BASE_ #define _WX_FILEDLG_H_BASE_ #if wxUSE_FILEDLG +#if defined(__GNUG__) && !defined(__APPLE__) +#pragma interface "filedlg.h" +#endif + +//---------------------------------------------------------------------------- +// wxFileDialog data and generic functions +//---------------------------------------------------------------------------- + enum { wxOPEN = 0x0001, @@ -14,6 +33,59 @@ enum wxCHANGE_DIR = 0x0040 }; +WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorPromptStr; +WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorDefaultWildcardStr; + +// Parses the filterStr, returning the number of filters. +// Returns 0 if none or if there's a problem, they arrays will contain an equal +// number of items found before the error. +// filterStr is in the form: +// "All files (*.*)|*.*|Image Files (*.jpeg *.png)|*.jpg;*.png" +extern int wxParseFileFilter(const wxString& filterStr, + wxArrayString& descriptions, + wxArrayString& filters); + +//---------------------------------------------------------------------------- +// wxFileDialog convenience functions +//---------------------------------------------------------------------------- + +// File selector - backward compatibility +WXDLLEXPORT wxString +wxFileSelector(const wxChar *message = wxFileSelectorPromptStr, + const wxChar *default_path = NULL, + const wxChar *default_filename = NULL, + const wxChar *default_extension = NULL, + const wxChar *wildcard = wxFileSelectorDefaultWildcardStr, + int flags = 0, + wxWindow *parent = NULL, + int x = -1, int y = -1); + +// An extended version of wxFileSelector +WXDLLEXPORT wxString +wxFileSelectorEx(const wxChar *message = wxFileSelectorPromptStr, + const wxChar *default_path = NULL, + const wxChar *default_filename = NULL, + int *indexDefaultExtension = NULL, + const wxChar *wildcard = wxFileSelectorDefaultWildcardStr, + int flags = 0, + wxWindow *parent = NULL, + int x = -1, int y = -1); + +// Ask for filename to load +WXDLLEXPORT wxString +wxLoadFileSelector(const wxChar *what, + const wxChar *extension, + const wxChar *default_name = (const wxChar *)NULL, + wxWindow *parent = (wxWindow *) NULL); + +// Ask for filename to save +WXDLLEXPORT wxString +wxSaveFileSelector(const wxChar *what, + const wxChar *extension, + const wxChar *default_name = (const wxChar *) NULL, + wxWindow *parent = (wxWindow *) NULL); + + #if defined (__WXUNIVERSAL__) #include "wx/generic/filedlgg.h" #elif defined(__WXMSW__) @@ -36,5 +108,4 @@ enum #endif // wxUSE_FILEDLG -#endif - // _WX_FILEDLG_H_BASE_ +#endif // _WX_FILEDLG_H_BASE_ diff --git a/include/wx/generic/filedlgg.h b/include/wx/generic/filedlgg.h index 95e196c06c..b6157b4d56 100644 --- a/include/wx/generic/filedlgg.h +++ b/include/wx/generic/filedlgg.h @@ -39,19 +39,8 @@ class WXDLLEXPORT wxTextCtrl; #define USE_GENERIC_FILEDIALOG #endif -#ifdef USE_GENERIC_FILEDIALOG - -//----------------------------------------------------------------------------- -// data -//----------------------------------------------------------------------------- - -WXDLLEXPORT_DATA(extern const wxChar *)wxFileSelectorPromptStr; -WXDLLEXPORT_DATA(extern const wxChar *)wxFileSelectorDefaultWildcardStr; - -#endif // USE_GENERIC_FILEDIALOG - //------------------------------------------------------------------------- -// File selector +// wxGenericFileDialog //------------------------------------------------------------------------- class WXDLLEXPORT wxGenericFileDialog: public wxDialog @@ -160,46 +149,10 @@ public: } }; -// File selector - backward compatibility -WXDLLEXPORT wxString -wxFileSelector(const wxChar *message = wxFileSelectorPromptStr, - const wxChar *default_path = NULL, - const wxChar *default_filename = NULL, - const wxChar *default_extension = NULL, - const wxChar *wildcard = wxFileSelectorDefaultWildcardStr, - int flags = 0, - wxWindow *parent = NULL, - int x = -1, int y = -1); - -// An extended version of wxFileSelector -WXDLLEXPORT wxString -wxFileSelectorEx(const wxChar *message = wxFileSelectorPromptStr, - const wxChar *default_path = NULL, - const wxChar *default_filename = NULL, - int *indexDefaultExtension = NULL, - const wxChar *wildcard = wxFileSelectorDefaultWildcardStr, - int flags = 0, - wxWindow *parent = NULL, - int x = -1, int y = -1); - -// Ask for filename to load -WXDLLEXPORT wxString -wxLoadFileSelector(const wxChar *what, - const wxChar *extension, - const wxChar *default_name = (const wxChar *)NULL, - wxWindow *parent = (wxWindow *) NULL); - -// Ask for filename to save -WXDLLEXPORT wxString -wxSaveFileSelector(const wxChar *what, - const wxChar *extension, - const wxChar *default_name = (const wxChar *) NULL, - wxWindow *parent = (wxWindow *) NULL); - #endif // USE_GENERIC_FILEDIALOG //----------------------------------------------------------------------------- -// wxFileData +// wxFileData - a class to hold the file info for the wxFileCtrl //----------------------------------------------------------------------------- class WXDLLEXPORT wxFileData @@ -214,29 +167,43 @@ public: is_drive = 0x0008 }; + // Full copy constructor + wxFileData( const wxFileData& fileData ); + // Create a filedata from this information wxFileData( const wxString &filePath, const wxString &fileName, fileType type, int image_id ); + // (re)read the extra data about the file from the system + void ReadData(); + // get the name of the file, dir, drive wxString GetFileName() const { return m_fileName; } // get the full path + name of the file, dir, path wxString GetFilePath() const { return m_filePath; } + // Set the path + name and name of the item + void SetNewName( const wxString &filePath, const wxString &fileName ); + + // Get the size of the file in bytes long GetSize() const { return m_size; } // Get the type of file, either file extension or , , - wxString GetType() const; + wxString GetFileType() const; // get the last modification time - wxDateTime GetTime() const { return m_dateTime; } + wxDateTime GetDateTime() const { return m_dateTime; } + // Get the time as a formatted string wxString GetModificationTime() const; // in UNIX get rwx for file, in MSW get attributes ARHS wxString GetPermissions() const { return m_permissions; } + // Get the id of the image used in a wxImageList int GetImageId() const { return m_image; } + bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); } bool IsDir() const { return (m_type & is_dir ) != 0; } bool IsLink() const { return (m_type & is_link ) != 0; } bool IsExe() const { return (m_type & is_exe ) != 0; } bool IsDrive() const { return (m_type & is_drive) != 0; } - int GetFileType() const { return m_type; } + // Get/Set the type of file, file/dir/drive/link + int GetType() const { return m_type; } // the wxFileCtrl fields in report view enum fileListFieldType @@ -251,12 +218,13 @@ public: FileList_Max }; + // Get the entry for report view of wxFileCtrl wxString GetEntry( fileListFieldType num ) const; // Get a string representation of the file info wxString GetHint() const; + // initialize a wxListItem attributes void MakeItem( wxListItem &item ); - void SetNewName( const wxString &filePath, const wxString &fileName ); private: wxString m_fileName; @@ -294,6 +262,7 @@ public: bool GetShowHidden() const { return m_showHidden; } virtual long Add( wxFileData *fd, wxListItem &item ); + virtual void UpdateItem(const wxListItem &item); virtual void UpdateFiles(); virtual void MakeDir(); virtual void GoToParentDir(); @@ -327,7 +296,5 @@ private: DECLARE_EVENT_TABLE() }; -#endif - // _WX_FILEDLGG_H_ - +#endif // _WX_FILEDLGG_H_ diff --git a/include/wx/gtk/filedlg.h b/include/wx/gtk/filedlg.h index db117cfe23..f944bd7c65 100644 --- a/include/wx/gtk/filedlg.h +++ b/include/wx/gtk/filedlg.h @@ -21,9 +21,6 @@ // File selector //------------------------------------------------------------------------- -extern const wxChar *wxFileSelectorPromptStr; -extern const wxChar *wxFileSelectorDefaultWildcardStr; - class wxFileDialog: public wxDialog { public: @@ -67,47 +64,4 @@ private: DECLARE_DYNAMIC_CLASS(wxFileDialog) }; -#define wxOPEN 1 -#define wxSAVE 2 -#define wxOVERWRITE_PROMPT 4 -#define wxHIDE_READONLY 8 -#define wxFILE_MUST_EXIST 16 - -// File selector - backward compatibility -WXDLLEXPORT wxString -wxFileSelector(const wxChar *message = wxFileSelectorPromptStr, - const wxChar *default_path = NULL, - const wxChar *default_filename = NULL, - const wxChar *default_extension = NULL, - const wxChar *wildcard = wxFileSelectorDefaultWildcardStr, - int flags = 0, - wxWindow *parent = NULL, - int x = -1, int y = -1); - -// An extended version of wxFileSelector -WXDLLEXPORT wxString -wxFileSelectorEx(const wxChar *message = wxFileSelectorPromptStr, - const wxChar *default_path = NULL, - const wxChar *default_filename = NULL, - int *indexDefaultExtension = NULL, - const wxChar *wildcard = wxFileSelectorDefaultWildcardStr, - int flags = 0, - wxWindow *parent = NULL, - int x = -1, int y = -1); - -// Ask for filename to load -WXDLLEXPORT wxString -wxLoadFileSelector(const wxChar *what, - const wxChar *extension, - const wxChar *default_name = (const wxChar *)NULL, - wxWindow *parent = (wxWindow *) NULL); - -// Ask for filename to save -WXDLLEXPORT wxString -wxSaveFileSelector(const wxChar *what, - const wxChar *extension, - const wxChar *default_name = (const wxChar *) NULL, - wxWindow *parent = (wxWindow *) NULL); - -#endif - // __GTKFILEDLGH__ +#endif // __GTKFILEDLGH__ diff --git a/include/wx/gtk1/filedlg.h b/include/wx/gtk1/filedlg.h index db117cfe23..f944bd7c65 100644 --- a/include/wx/gtk1/filedlg.h +++ b/include/wx/gtk1/filedlg.h @@ -21,9 +21,6 @@ // File selector //------------------------------------------------------------------------- -extern const wxChar *wxFileSelectorPromptStr; -extern const wxChar *wxFileSelectorDefaultWildcardStr; - class wxFileDialog: public wxDialog { public: @@ -67,47 +64,4 @@ private: DECLARE_DYNAMIC_CLASS(wxFileDialog) }; -#define wxOPEN 1 -#define wxSAVE 2 -#define wxOVERWRITE_PROMPT 4 -#define wxHIDE_READONLY 8 -#define wxFILE_MUST_EXIST 16 - -// File selector - backward compatibility -WXDLLEXPORT wxString -wxFileSelector(const wxChar *message = wxFileSelectorPromptStr, - const wxChar *default_path = NULL, - const wxChar *default_filename = NULL, - const wxChar *default_extension = NULL, - const wxChar *wildcard = wxFileSelectorDefaultWildcardStr, - int flags = 0, - wxWindow *parent = NULL, - int x = -1, int y = -1); - -// An extended version of wxFileSelector -WXDLLEXPORT wxString -wxFileSelectorEx(const wxChar *message = wxFileSelectorPromptStr, - const wxChar *default_path = NULL, - const wxChar *default_filename = NULL, - int *indexDefaultExtension = NULL, - const wxChar *wildcard = wxFileSelectorDefaultWildcardStr, - int flags = 0, - wxWindow *parent = NULL, - int x = -1, int y = -1); - -// Ask for filename to load -WXDLLEXPORT wxString -wxLoadFileSelector(const wxChar *what, - const wxChar *extension, - const wxChar *default_name = (const wxChar *)NULL, - wxWindow *parent = (wxWindow *) NULL); - -// Ask for filename to save -WXDLLEXPORT wxString -wxSaveFileSelector(const wxChar *what, - const wxChar *extension, - const wxChar *default_name = (const wxChar *) NULL, - wxWindow *parent = (wxWindow *) NULL); - -#endif - // __GTKFILEDLGH__ +#endif // __GTKFILEDLGH__ diff --git a/include/wx/mac/filedlg.h b/include/wx/mac/filedlg.h index 1bc0428fdb..98f06e72ca 100644 --- a/include/wx/mac/filedlg.h +++ b/include/wx/mac/filedlg.h @@ -22,9 +22,6 @@ * File selector */ -WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorPromptStr; -WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorDefaultWildcardStr; - class WXDLLEXPORT wxFileDialog: public wxDialog { DECLARE_DYNAMIC_CLASS(wxFileDialog) @@ -71,29 +68,4 @@ public: }; -#define wxOPEN 0x0001 -#define wxSAVE 0x0002 -#define wxOVERWRITE_PROMPT 0x0004 -#define wxHIDE_READONLY 0x0008 -#define wxFILE_MUST_EXIST 0x0010 - -// File selector - backward compatibility -WXDLLEXPORT wxString wxFileSelector(const wxChar *message = wxFileSelectorPromptStr, const wxChar *default_path = NULL, - const wxChar *default_filename = NULL, const wxChar *default_extension = NULL, - const wxChar *wildcard = wxFileSelectorDefaultWildcardStr, int flags = 0, - wxWindow *parent = NULL, int x = -1, int y = -1); - -// An extended version of wxFileSelector -WXDLLEXPORT wxString wxFileSelectorEx(const wxChar *message = wxFileSelectorPromptStr, const wxChar *default_path = NULL, - const wxChar *default_filename = NULL, int *indexDefaultExtension = NULL, - const wxChar *wildcard = wxFileSelectorDefaultWildcardStr, int flags = 0, - wxWindow *parent = NULL, int x = -1, int y = -1); - -// Generic file load dialog -WXDLLEXPORT wxString wxLoadFileSelector(const wxChar *what, const wxChar *extension, const wxChar *default_name = NULL, wxWindow *parent = NULL); - -// Generic file save dialog -WXDLLEXPORT wxString wxSaveFileSelector(const wxChar *what, const wxChar *extension, const wxChar *default_name = NULL, wxWindow *parent = NULL); - -#endif - // _WX_FILEDLG_H_ +#endif // _WX_FILEDLG_H_ diff --git a/include/wx/motif/filedlg.h b/include/wx/motif/filedlg.h index 0ab2851820..32734fe530 100644 --- a/include/wx/motif/filedlg.h +++ b/include/wx/motif/filedlg.h @@ -22,9 +22,6 @@ * File selector */ -WXDLLEXPORT_DATA(extern const char*) wxFileSelectorPromptStr; -WXDLLEXPORT_DATA(extern const char*) wxFileSelectorDefaultWildcardStr; - class WXDLLEXPORT wxFileDialog: public wxDialog { DECLARE_DYNAMIC_CLASS(wxFileDialog) @@ -70,29 +67,4 @@ public: int ShowModal(); }; -#define wxOPEN 0x0001 -#define wxSAVE 0x0002 -#define wxOVERWRITE_PROMPT 0x0004 -#define wxHIDE_READONLY 0x0008 -#define wxFILE_MUST_EXIST 0x0010 - -// File selector - backward compatibility -WXDLLEXPORT wxString wxFileSelector(const char *message = wxFileSelectorPromptStr, const char *default_path = NULL, - const char *default_filename = NULL, const char *default_extension = NULL, - const char *wildcard = wxFileSelectorDefaultWildcardStr, int flags = 0, - wxWindow *parent = NULL, int x = -1, int y = -1); - -// An extended version of wxFileSelector -WXDLLEXPORT wxString wxFileSelectorEx(const char *message = wxFileSelectorPromptStr, const char *default_path = NULL, - const char *default_filename = NULL, int *indexDefaultExtension = NULL, - const char *wildcard = wxFileSelectorDefaultWildcardStr, int flags = 0, - wxWindow *parent = NULL, int x = -1, int y = -1); - -// Generic file load dialog -WXDLLEXPORT wxString wxLoadFileSelector(const char *what, const char *extension, const char *default_name = NULL, wxWindow *parent = NULL); - -// Generic file save dialog -WXDLLEXPORT wxString wxSaveFileSelector(const char *what, const char *extension, const char *default_name = NULL, wxWindow *parent = NULL); - -#endif -// _WX_FILEDLG_H_ +#endif // _WX_FILEDLG_H_ diff --git a/include/wx/msw/filedlg.h b/include/wx/msw/filedlg.h index 523d75626b..9a00d2c8d6 100644 --- a/include/wx/msw/filedlg.h +++ b/include/wx/msw/filedlg.h @@ -22,9 +22,6 @@ * File selector */ -WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorPromptStr; -WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorDefaultWildcardStr; - class WXDLLEXPORT wxFileDialog: public wxDialog { public: @@ -72,42 +69,5 @@ private: DECLARE_NO_COPY_CLASS(wxFileDialog) }; -// File selector - backward compatibility -WXDLLEXPORT wxString -wxFileSelector(const wxChar *message = wxFileSelectorPromptStr, - const wxChar *default_path = NULL, - const wxChar *default_filename = NULL, - const wxChar *default_extension = NULL, - const wxChar *wildcard = wxFileSelectorDefaultWildcardStr, - int flags = 0, - wxWindow *parent = NULL, - int x = -1, int y = -1); - -// An extended version of wxFileSelector -WXDLLEXPORT wxString -wxFileSelectorEx(const wxChar *message = wxFileSelectorPromptStr, - const wxChar *default_path = NULL, - const wxChar *default_filename = NULL, - int *indexDefaultExtension = NULL, - const wxChar *wildcard = wxFileSelectorDefaultWildcardStr, - int flags = 0, - wxWindow *parent = NULL, - int x = -1, int y = -1); - -// Ask for filename to load -WXDLLEXPORT wxString -wxLoadFileSelector(const wxChar *what, - const wxChar *extension, - const wxChar *default_name = (const wxChar *)NULL, - wxWindow *parent = (wxWindow *) NULL); - -// Ask for filename to save -WXDLLEXPORT wxString -wxSaveFileSelector(const wxChar *what, - const wxChar *extension, - const wxChar *default_name = (const wxChar *) NULL, - wxWindow *parent = (wxWindow *) NULL); - -#endif - // _WX_FILEDLG_H_ +#endif // _WX_FILEDLG_H_ diff --git a/include/wx/os2/filedlg.h b/include/wx/os2/filedlg.h index 5d106c8bdc..3d1deaba5e 100644 --- a/include/wx/os2/filedlg.h +++ b/include/wx/os2/filedlg.h @@ -64,58 +64,4 @@ protected: wxPoint m_vPos; }; // end of CLASS wxFileDialog -#define wxOPEN 0x0001 -#define wxSAVE 0x0002 -#define wxOVERWRITE_PROMPT 0x0004 -#define wxHIDE_READONLY 0x0008 -#define wxFILE_MUST_EXIST 0x0010 - -// -// File selector - backward compatibility -// -WXDLLEXPORT wxString wxFileSelector( const char* pzMessage = wxFileSelectorPromptStr - ,const char* pzDefaultPath = NULL - ,const char* pzDefaultFilename = NULL - ,const char* pzDefaultExtension = NULL - ,const char* pzWildcard = wxFileSelectorDefaultWildcardStr - ,int nFlags = 0 - ,wxWindow* pParent = NULL - ,int nX = -1 - ,int nY = -1 - ); - -// -// An extended version of wxFileSelector - -WXDLLEXPORT wxString wxFileSelectorEx( const char* pzMessage = wxFileSelectorPromptStr - ,const char* pzDefaultPath = NULL - ,const char* pzDefaultFilename = NULL - ,int* pnIndexDefaultExtension = NULL - ,const char* pzWildcard = wxFileSelectorDefaultWildcardStr - ,int nFlags = 0 - ,wxWindow* pParent = NULL - ,int nX = -1 - ,int nY = -1 - ); - -// -// Generic file load dialog -// -WXDLLEXPORT wxString wxLoadFileSelector( const char* pzWhat - ,const char* pzExtension - ,const char* pzDefaultName = NULL - ,wxWindow* pParent = NULL - ); - -// -// Generic file save dialog -// -WXDLLEXPORT wxString wxSaveFileSelector( const char* pzWhat - ,const char* pzExtension - ,const char* pzDefaultName = NULL - ,wxWindow* pParent = NULL - ); - -#endif - -// _WX_FILEDLG_H_ +#endif // _WX_FILEDLG_H_ diff --git a/src/common/fldlgcmn.cpp b/src/common/fldlgcmn.cpp new file mode 100644 index 0000000000..102c036b3a --- /dev/null +++ b/src/common/fldlgcmn.cpp @@ -0,0 +1,280 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: common/fldlgcmn.cpp +// Purpose: wxFileDialog common functions +// Author: John Labenski +// Modified by: +// Created: 14.06.03 (extracted from src/*/filedlg.cpp) +// RCS-ID: +// Copyright: (c) Robert Roebling +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "filedlg.h" +#endif + +#ifdef __BORLANDC__ +#pragma hdrstop +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifndef WX_PRECOMP + #include "wx/string.h" + #include "wx/intl.h" + #include "wx/window.h" +#endif // WX_PRECOMP + +#include "wx/filedlg.h" + +#if wxUSE_FILEDLG + +wxString wxFileSelector(const wxChar *title, + const wxChar *defaultDir, + const wxChar *defaultFileName, + const wxChar *defaultExtension, + const wxChar *filter, + int flags, + wxWindow *parent, + int x, int y) +{ + // The defaultExtension, if non-NULL, is + // appended to the filename if the user fails to type an extension. The new + // implementation (taken from wxFileSelectorEx) appends the extension + // automatically, by looking at the filter specification. In fact this + // should be better than the native Microsoft implementation because + // Windows only allows *one* default extension, whereas here we do the + // right thing depending on the filter the user has chosen. + + // If there's a default extension specified but no filter, we create a + // suitable filter. + + wxString filter2; + if ( defaultExtension && !filter ) + filter2 = wxString(wxT("*.")) + defaultExtension; + else if ( filter ) + filter2 = filter; + + wxString defaultDirString; + if (defaultDir) + defaultDirString = defaultDir; + + wxString defaultFilenameString; + if (defaultFileName) + defaultFilenameString = defaultFileName; + + wxFileDialog fileDialog(parent, title, defaultDirString, + defaultFilenameString, filter2, + flags, wxPoint(x, y)); + if( wxStrlen(defaultExtension) != 0 ) + { + int filterFind = 0, + filterIndex = 0; + + for( unsigned int i = 0; i < filter2.Len(); i++ ) + { + if( filter2.GetChar(i) == wxT('|') ) + { + // save the start index of the new filter + unsigned int is = i++; + + // find the end of the filter + for( ; i < filter2.Len(); i++ ) + { + if(filter2[i] == wxT('|')) + break; + } + + if( i-is-1 > 0 && is+1 < filter2.Len() ) + { + if( filter2.Mid(is+1,i-is-1).Contains(defaultExtension) ) + { + filterFind = filterIndex; + break; + } + } + + filterIndex++; + } + } + + fileDialog.SetFilterIndex(filterFind); + } + + wxString filename; + if ( fileDialog.ShowModal() == wxID_OK ) + { + filename = fileDialog.GetPath(); + } + + return filename; +} + + +/* +wxString wxFileSelector( const wxChar *title, + const wxChar *defaultDir, + const wxChar *defaultFileName, + const wxChar *defaultExtension, + const wxChar *filter, + int flags, + wxWindow *parent, + int x, + int y ) +{ + wxString filter2; + if ( defaultExtension && !filter ) + filter2 = wxString(wxT("*.")) + wxString(defaultExtension) ; + else if ( filter ) + filter2 = filter; + + wxString defaultDirString; + if (defaultDir) + defaultDirString = defaultDir; + + wxString defaultFilenameString; + if (defaultFileName) + defaultFilenameString = defaultFileName; + + wxFileDialog fileDialog( parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y) ); + + if ( fileDialog.ShowModal() == wxID_OK ) + { + return fileDialog.GetPath(); + } + else + { + return wxEmptyString; + } +} +*/ + + +wxString wxFileSelectorEx(const wxChar *title, + const wxChar *defaultDir, + const wxChar *defaultFileName, + int* defaultFilterIndex, + const wxChar *filter, + int flags, + wxWindow* parent, + int x, + int y) + +{ + wxFileDialog fileDialog(parent, + title ? title : wxT(""), + defaultDir ? defaultDir : wxT(""), + defaultFileName ? defaultFileName : wxT(""), + filter ? filter : wxT(""), + flags, wxPoint(x, y)); + + wxString filename; + if ( fileDialog.ShowModal() == wxID_OK ) + { + if ( defaultFilterIndex ) + *defaultFilterIndex = fileDialog.GetFilterIndex(); + + filename = fileDialog.GetPath(); + } + + return filename; +} + + + +// Generic file load/save dialog (for internal use only) +// see wx[Load/Save]FileSelector +static wxString wxDefaultFileSelector(bool load, + const wxChar *what, + const wxChar *extension, + const wxChar *default_name, + wxWindow *parent) +{ + wxString prompt; + wxString str; + if (load) + str = _("Load %s file"); + else + str = _("Save %s file"); + prompt.Printf(str, what); + + wxString wild; + const wxChar *ext = extension; + if ( ext ) + { + if ( *ext == wxT('.') ) + ext++; + + wild.Printf(wxT("*.%s"), ext); + } + else // no extension specified + { + wild = wxFileSelectorDefaultWildcardStr; + } + + return wxFileSelector(prompt, NULL, default_name, ext, wild, + load ? wxOPEN : wxSAVE, parent); +} + +// Generic file load dialog +WXDLLEXPORT wxString wxLoadFileSelector(const wxChar *what, + const wxChar *extension, + const wxChar *default_name, + wxWindow *parent) +{ + return wxDefaultFileSelector(TRUE, what, extension, default_name, parent); +} + +// Generic file save dialog +WXDLLEXPORT wxString wxSaveFileSelector(const wxChar *what, + const wxChar *extension, + const wxChar *default_name, + wxWindow *parent) +{ + return wxDefaultFileSelector(FALSE, what, extension, default_name, parent); +} + + +// Parses the filterStr, returning the number of filters. +// Returns 0 if none or if there's a problem. +// filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg" + +int wxParseFileFilter(const wxString& filterStr, + wxArrayString& descriptions, + wxArrayString& filters) +{ + wxString str(filterStr); + + wxString description, filter; + int pos = -1; + bool finished = FALSE; + do + { + pos = str.Find(wxT('|')); + if (pos == -1) + return 0; // Problem + description = str.Left(pos); + str = str.Mid(pos+1); + pos = str.Find(wxT('|')); + if (pos == -1) + { + filter = str; + finished = TRUE; + } + else + { + filter = str.Left(pos); + str = str.Mid(pos+1); + } + + descriptions.Add(description); + filters.Add(filter); + } + while (!finished); + + return filters.GetCount(); +} + +#endif // wxUSE_FILEDLG + diff --git a/src/generic/dirctrlg.cpp b/src/generic/dirctrlg.cpp index 566662567f..3745b47e4b 100644 --- a/src/generic/dirctrlg.cpp +++ b/src/generic/dirctrlg.cpp @@ -99,6 +99,9 @@ extern bool wxIsDriveAvailable(const wxString& dirName); #undef GetFirstChild #endif +// declared in filedlg.h, defined in fldlgcmn.cpp +extern int wxParseFileFilter(const wxString& filterStr, wxArrayString& descriptions, wxArrayString& filters); + // ---------------------------------------------------------------------------- // wxGetAvailableDrives, for WINDOWS, DOS, WXPM, MAC, UNIX (returns "/") // ---------------------------------------------------------------------------- @@ -348,6 +351,7 @@ bool wxIsDriveAvailable(const wxString& dirName) } #endif // __WINDOWS__ || __WXPM__ + // Function which is called by quick sort. We want to override the default wxArrayString behaviour, // and sort regardless of case. static int LINKAGEMODE wxDirCtrlStringCompareFunction(const void *first, const void *second) @@ -1032,41 +1036,11 @@ bool wxGenericDirCtrl::ExtractWildcard(const wxString& filterStr, int n, wxStrin // Parses the global filter, returning the number of filters. // Returns 0 if none or if there's a problem. -// filterStr is in the form: -// -// "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg" +// filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg" int wxGenericDirCtrl::ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions) { - wxString str(filterStr); - - wxString description, filter; - int pos; - bool finished = FALSE; - do - { - pos = str.Find(wxT('|')); - if (pos == -1) - return 0; // Problem - description = str.Left(pos); - str = str.Mid(pos+1); - pos = str.Find(wxT('|')); - if (pos == -1) - { - filter = str; - finished = TRUE; - } - else - { - filter = str.Left(pos); - str = str.Mid(pos+1); - } - descriptions.Add(description); - filters.Add(filter); - } - while (!finished) ; - - return filters.Count(); + return wxParseFileFilter(filterStr, descriptions, filters ); } void wxGenericDirCtrl::DoResize() diff --git a/src/generic/filedlgg.cpp b/src/generic/filedlgg.cpp index efc8f3e290..f1fa6a4c9f 100644 --- a/src/generic/filedlgg.cpp +++ b/src/generic/filedlgg.cpp @@ -9,14 +9,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - #ifdef __GNUG__ #pragma implementation "filedlgg.h" #endif @@ -121,7 +113,7 @@ int wxFileDataTypeCompare( long data1, long data2, long data) if (fd2->IsDir() && !fd1->IsDir()) return data; if (fd1->IsLink() && !fd2->IsLink()) return -data; if (fd2->IsLink() && !fd1->IsLink()) return data; - return data*wxStrcmp( fd1->GetType(), fd2->GetType() ); + return data*wxStrcmp( fd1->GetFileType(), fd2->GetFileType() ); } static @@ -134,7 +126,7 @@ int wxFileDataTimeCompare( long data1, long data2, long data) if (fd1->IsDir() && !fd2->IsDir()) return -data; if (fd2->IsDir() && !fd1->IsDir()) return data; - return fd1->GetTime().IsLaterThan(fd2->GetTime()) ? int(data) : -int(data); + return fd1->GetDateTime().IsLaterThan(fd2->GetDateTime()) ? int(data) : -int(data); } #ifdef __UNIX__ @@ -157,6 +149,17 @@ extern size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, w // wxFileData //----------------------------------------------------------------------------- +wxFileData::wxFileData( const wxFileData& fileData ) +{ + m_fileName = fileData.GetFileName(); + m_filePath = fileData.GetFilePath(); + m_size = fileData.GetSize(); + m_dateTime = fileData.GetDateTime(); + m_permissions = fileData.GetPermissions(); + m_type = fileData.GetType(); + m_image = GetImageId(); +} + wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, fileType type, int image_id ) { m_fileName = fileName; @@ -164,6 +167,11 @@ wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, file m_type = type; m_image = image_id; + ReadData(); +} + +void wxFileData::ReadData() +{ if (IsDrive()) { m_size = 0; @@ -229,7 +237,7 @@ wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, file #endif } -wxString wxFileData::GetType() const +wxString wxFileData::GetFileType() const { if (IsDir()) return _(""); @@ -290,7 +298,7 @@ wxString wxFileData::GetEntry( fileListFieldType num ) const break; case FileList_Type: - s = GetType(); + s = GetFileType(); break; case FileList_Time: @@ -449,6 +457,23 @@ long wxFileCtrl::Add( wxFileData *fd, wxListItem &item ) return ret; } +void wxFileCtrl::UpdateItem(const wxListItem &item) +{ + wxFileData *fd = (wxFileData*)GetItemData(item); + wxCHECK_RET(fd, wxT("invalid filedata")); + + fd->ReadData(); + + SetItemText(item, fd->GetFileName()); + SetItemImage(item, fd->GetImageId(), fd->GetImageId()); + + if (GetWindowStyleFlag() & wxLC_REPORT) + { + for (int i = 1; i < wxFileData::FileList_Max; i++) + SetItem( item.m_itemId, i, fd->GetEntry((wxFileData::fileListFieldType)i) ); + } +} + void wxFileCtrl::UpdateFiles() { // don't do anything before ShowModal() call which sets m_dirName @@ -701,6 +726,7 @@ void wxFileCtrl::OnListEndLabelEdit( wxListEvent &event ) { fd->SetNewName( new_name, event.GetLabel() ); SetItemState( event.GetItem(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); + UpdateItem( event.GetItem() ); EnsureVisible( event.GetItem() ); } else @@ -853,24 +879,19 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent, if (m_wildCard.IsEmpty()) m_wildCard = _("All files (*)|*"); - wxStringTokenizer tokens( m_wildCard, wxT("|") ); - wxString firstWild; - wxString firstWildText; - if (tokens.CountTokens() == 1) - { - firstWildText = tokens.GetNextToken(); - firstWild = firstWildText; - } - else + wxArrayString wildDescriptions, wildFilters; + int wild_count = wxParseFileFilter(m_wildCard, wildDescriptions, wildFilters); + + wxASSERT_MSG(wild_count > 0, wxT("Wrong file type descripition") ); + + // if error parsing, add default back + if (wildFilters.GetCount() < 1u) { - wxASSERT_MSG( tokens.CountTokens() % 2 == 0, wxT("Wrong file type descripition") ); - firstWildText = tokens.GetNextToken(); - firstWild = tokens.GetNextToken(); + wild_count = 1; + m_wildCard = _("All files (*)|*"); + wildDescriptions.Add(_("All files (*)")); + wildFilters.Add(wxT("*")); } - if ( firstWild.Left( 2 ) == wxT("*.") ) - m_filterExtension = firstWild.Mid( 1 ); - if ( m_filterExtension == wxT(".*") ) - m_filterExtension = wxEmptyString; // layout @@ -940,7 +961,7 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent, style2 |= wxLC_SINGLE_SEL; m_list = new wxFileCtrl( this, ID_LIST_CTRL, - firstWild, ms_lastShowHidden, + wildFilters[0], ms_lastShowHidden, wxDefaultPosition, wxSize(540,200), style2); @@ -988,14 +1009,11 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent, mainsizer->Add( choicesizer, 0, wxEXPAND ); } - m_choice->Append( firstWildText, (void*) new wxString( firstWild ) ); - while (tokens.HasMoreTokens()) + for (size_t n=0; nAppend( firstWildText, (void*) new wxString( firstWild ) ); + m_choice->Append( wildDescriptions[n], (void*) new wxString( wildFilters[n] ) ); } - m_choice->SetSelection( 0 ); + SetFilterIndex( 0 ); SetAutoLayout( TRUE ); SetSizer( mainsizer ); @@ -1124,6 +1142,11 @@ void wxGenericFileDialog::HandleAction( const wxString &fn ) if (filename.IsEmpty()) return; if (filename == wxT(".")) return; + // "some/place/" means they want to chdir not try to load "place" + bool want_dir = filename.Last() == wxFILE_SEP_PATH; + if (want_dir) + filename = filename.RemoveLast(); + if (filename == wxT("..")) { m_list->GoToParentDir(); @@ -1141,13 +1164,9 @@ void wxGenericFileDialog::HandleAction( const wxString &fn ) return; } - if (filename[0u] == wxT('~')) + if (filename.BeforeFirst(wxT('/')) == wxT("~")) { - filename.Remove( 0, 1 ); - wxString tmp( wxGetUserHome() ); - tmp += wxT('/'); - tmp += filename; - filename = tmp; + filename = wxGetUserHome() + filename.Remove(0, 1); } #endif // __UNIX__ @@ -1178,6 +1197,14 @@ void wxGenericFileDialog::HandleAction( const wxString &fn ) return; } + // they really wanted a dir, but it doesn't exist + if (want_dir) + { + wxMessageBox(_("Directory doesn't exist."), _("Error"), + wxOK | wxICON_ERROR ); + return; + } + // append the default extension to the filename if it doesn't have any // // VZ: the logic of testing for !wxFileExists() only for the open file @@ -1356,152 +1383,6 @@ void wxGenericFileDialog::UpdateControls() IMPLEMENT_DYNAMIC_CLASS(wxFileDialog, wxGenericFileDialog); -// ---------------------------------------------------------------------------- -// global functions -// ---------------------------------------------------------------------------- - -// common part of both wxFileSelectorEx() and wxFileSelector() -static wxString -DoSelectFile(const wxChar *title, - const wxChar *defaultDir, - const wxChar *defaultFileName, - const wxChar *defaultExtension, - int *indexDefaultExtension, - const wxChar *filter, - int flags, - wxWindow *parent, - int x, - int y) -{ - // the filter may be either given explicitly or created automatically from - // the default extension - wxString filterReal; - if ( filter ) - { - // the user has specified the filter explicitly, use it - filterReal = filter; - } - else if ( !wxIsEmpty(defaultExtension) ) - { - // create the filter to match the given extension - filterReal << wxT("*.") << defaultExtension; - } - - wxFileDialog fileDialog(parent, - title, - defaultDir, - defaultFileName, - filterReal, - flags, - wxPoint(x, y)); - - wxString path; - if ( fileDialog.ShowModal() == wxID_OK ) - { - path = fileDialog.GetPath(); - if ( indexDefaultExtension ) - { - *indexDefaultExtension = fileDialog.GetFilterIndex(); - } - } - - return path; -} - -wxString -wxFileSelectorEx(const wxChar *title, - const wxChar *defaultDir, - const wxChar *defaultFileName, - int *indexDefaultExtension, - const wxChar *filter, - int flags, - wxWindow *parent, - int x, - int y) -{ - return DoSelectFile(title, - defaultDir, - defaultFileName, - wxT(""), // def ext determined by index - indexDefaultExtension, - filter, - flags, - parent, - x, - y); -} - -wxString -wxFileSelector(const wxChar *title, - const wxChar *defaultDir, - const wxChar *defaultFileName, - const wxChar *defaultExtension, - const wxChar *filter, - int flags, - wxWindow *parent, - int x, - int y) -{ - return DoSelectFile(title, - defaultDir, - defaultFileName, - defaultExtension, - NULL, // not interested in filter index - filter, - flags, - parent, - x, - y); -} - -static wxString GetWildcardString(const wxChar *ext) -{ - wxString wild; - if ( ext ) - { - if ( *ext == wxT('.') ) - ext++; - - wild << _T("*.") << ext; - } - else // no extension specified - { - wild = wxFileSelectorDefaultWildcardStr; - } - - return wild; -} - -wxString wxLoadFileSelector(const wxChar *what, - const wxChar *ext, - const wxChar *nameDef, - wxWindow *parent) -{ - wxString prompt; - if ( what && *what ) - prompt = wxString::Format(_("Load %s file"), what); - else - prompt = _("Load file"); - - return wxFileSelector(prompt, NULL, nameDef, ext, - GetWildcardString(ext), 0, parent); -} - -wxString wxSaveFileSelector(const wxChar *what, - const wxChar *ext, - const wxChar *nameDef, - wxWindow *parent) -{ - wxString prompt; - if ( what && *what ) - prompt = wxString::Format(_("Save %s file"), what); - else - prompt = _("Save file"); - - return wxFileSelector(prompt, NULL, nameDef, ext, - GetWildcardString(ext), 0, parent); -} - #endif // USE_GENERIC_FILEDIALOG #endif // wxUSE_FILEDLG diff --git a/src/gtk/filedlg.cpp b/src/gtk/filedlg.cpp index 946ae917c4..687e2a44b0 100644 --- a/src/gtk/filedlg.cpp +++ b/src/gtk/filedlg.cpp @@ -192,84 +192,3 @@ void wxFileDialog::SetPath(const wxString& path) } } -// ---------------------------------------------------------------------------- -// global functions -// ---------------------------------------------------------------------------- - -wxString -wxFileSelectorEx(const wxChar *message, - const wxChar *default_path, - const wxChar *default_filename, - int *indexDefaultExtension, - const wxChar *wildcard, - int flags, - wxWindow *parent, - int x, int y) -{ - // TODO: implement this somehow - return wxFileSelector(message, default_path, default_filename, wxT(""), - wildcard, flags, parent, x, y); -} - -wxString wxFileSelector( const wxChar *title, - const wxChar *defaultDir, const wxChar *defaultFileName, - const wxChar *defaultExtension, const wxChar *filter, int flags, - wxWindow *parent, int x, int y ) -{ - wxString filter2; - if ( defaultExtension && !filter ) - filter2 = wxString(wxT("*.")) + wxString(defaultExtension) ; - else if ( filter ) - filter2 = filter; - - wxString defaultDirString; - if (defaultDir) - defaultDirString = defaultDir; - - wxString defaultFilenameString; - if (defaultFileName) - defaultFilenameString = defaultFileName; - - wxFileDialog fileDialog( parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y) ); - - if ( fileDialog.ShowModal() == wxID_OK ) - { - return fileDialog.GetPath(); - } - else - { - return wxEmptyString; - } -} - -wxString wxLoadFileSelector( const wxChar *what, const wxChar *extension, const wxChar *default_name, wxWindow *parent ) -{ - wxChar *ext = (wxChar *)extension; - - wxString prompt = wxString::Format(_("Load %s file"), what); - - if (*ext == wxT('.')) - ext++; - - wxString wild = wxString::Format(_T("*.%s"), ext); - - return wxFileSelector(prompt, (const wxChar *) NULL, default_name, - ext, wild, 0, parent); -} - -wxString wxSaveFileSelector(const wxChar *what, const wxChar *extension, const wxChar *default_name, - wxWindow *parent ) -{ - wxChar *ext = (wxChar *)extension; - - wxString prompt = wxString::Format(_("Save %s file"), what); - - if (*ext == wxT('.')) - ext++; - - wxString wild = wxString::Format(_T("*.%s"), ext); - - return wxFileSelector(prompt, (const wxChar *) NULL, default_name, - ext, wild, 0, parent); -} - diff --git a/src/gtk1/filedlg.cpp b/src/gtk1/filedlg.cpp index 946ae917c4..687e2a44b0 100644 --- a/src/gtk1/filedlg.cpp +++ b/src/gtk1/filedlg.cpp @@ -192,84 +192,3 @@ void wxFileDialog::SetPath(const wxString& path) } } -// ---------------------------------------------------------------------------- -// global functions -// ---------------------------------------------------------------------------- - -wxString -wxFileSelectorEx(const wxChar *message, - const wxChar *default_path, - const wxChar *default_filename, - int *indexDefaultExtension, - const wxChar *wildcard, - int flags, - wxWindow *parent, - int x, int y) -{ - // TODO: implement this somehow - return wxFileSelector(message, default_path, default_filename, wxT(""), - wildcard, flags, parent, x, y); -} - -wxString wxFileSelector( const wxChar *title, - const wxChar *defaultDir, const wxChar *defaultFileName, - const wxChar *defaultExtension, const wxChar *filter, int flags, - wxWindow *parent, int x, int y ) -{ - wxString filter2; - if ( defaultExtension && !filter ) - filter2 = wxString(wxT("*.")) + wxString(defaultExtension) ; - else if ( filter ) - filter2 = filter; - - wxString defaultDirString; - if (defaultDir) - defaultDirString = defaultDir; - - wxString defaultFilenameString; - if (defaultFileName) - defaultFilenameString = defaultFileName; - - wxFileDialog fileDialog( parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y) ); - - if ( fileDialog.ShowModal() == wxID_OK ) - { - return fileDialog.GetPath(); - } - else - { - return wxEmptyString; - } -} - -wxString wxLoadFileSelector( const wxChar *what, const wxChar *extension, const wxChar *default_name, wxWindow *parent ) -{ - wxChar *ext = (wxChar *)extension; - - wxString prompt = wxString::Format(_("Load %s file"), what); - - if (*ext == wxT('.')) - ext++; - - wxString wild = wxString::Format(_T("*.%s"), ext); - - return wxFileSelector(prompt, (const wxChar *) NULL, default_name, - ext, wild, 0, parent); -} - -wxString wxSaveFileSelector(const wxChar *what, const wxChar *extension, const wxChar *default_name, - wxWindow *parent ) -{ - wxChar *ext = (wxChar *)extension; - - wxString prompt = wxString::Format(_("Save %s file"), what); - - if (*ext == wxT('.')) - ext++; - - wxString wild = wxString::Format(_T("*.%s"), ext); - - return wxFileSelector(prompt, (const wxChar *) NULL, default_name, - ext, wild, 0, parent); -} - diff --git a/src/mac/carbon/filedlg.cpp b/src/mac/carbon/filedlg.cpp index f2b6707baf..d7929f00cd 100644 --- a/src/mac/carbon/filedlg.cpp +++ b/src/mac/carbon/filedlg.cpp @@ -274,65 +274,6 @@ static pascal Boolean CrossPlatformFileFilter(CInfoPBPtr myCInfoPBPtr, void *dat // end wxmac -wxString wxFileSelector(const wxChar *title, - const wxChar *defaultDir, const wxChar *defaultFileName, - const wxChar *defaultExtension, const wxChar *filter, int flags, - wxWindow *parent, int x, int y) -{ - // If there's a default extension specified but no filter, we create a suitable - // filter. - - wxString filter2; - if ( defaultExtension && !filter ) - filter2 = wxString(wxT("*.")) + wxString(defaultExtension) ; - else if ( filter ) - filter2 = filter; - - wxString defaultDirString; - if (defaultDir) - defaultDirString = defaultDir; - else - defaultDirString = wxEmptyString ; - - wxString defaultFilenameString; - if (defaultFileName) - defaultFilenameString = defaultFileName; - else - defaultFilenameString = wxEmptyString; - - wxFileDialog fileDialog(parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y)); - - if ( fileDialog.ShowModal() == wxID_OK ) - { - return fileDialog.GetPath(); - } - else - return wxGetEmptyString(); -} - -WXDLLEXPORT wxString wxFileSelectorEx(const wxChar *title, - const wxChar *defaultDir, - const wxChar *defaultFileName, - int* defaultFilterIndex, - const wxChar *filter, - int flags, - wxWindow* parent, - int x, - int y) - -{ - wxFileDialog fileDialog(parent, title ? title : wxT(""), defaultDir ? defaultDir : wxT(""), - defaultFileName ? defaultFileName : wxT(""), filter ? filter : wxT(""), flags, wxPoint(x, y)); - - if ( fileDialog.ShowModal() == wxID_OK ) - { - *defaultFilterIndex = fileDialog.GetFilterIndex(); - return fileDialog.GetPath(); - } - else - return wxGetEmptyString(); -} - wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard, long style, const wxPoint& pos) @@ -526,40 +467,3 @@ int wxFileDialog::ShowModal() return wxID_CANCEL; } -// Generic file load/save dialog -static wxString -wxDefaultFileSelector(bool load, const wxChar *what, const wxChar *extension, const wxChar *default_name, wxWindow *parent) -{ - wxString prompt; - - wxString str; - if (load) - str = wxT("Load %s file"); - else - str = wxT("Save %s file"); - prompt.Printf( wxGetTranslation(str), what); - - const wxChar *ext = extension; - if (*ext == wxT('.')) - ext++; - - wxString wild; - wild.Printf(wxT("*.%s"), ext); - - return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent); -} - -// Generic file load dialog -wxString -wxLoadFileSelector(const wxChar *what, const wxChar *extension, const wxChar *default_name, wxWindow *parent) -{ - return wxDefaultFileSelector(TRUE, what, extension, default_name, parent); -} - - -// Generic file save dialog -wxString -wxSaveFileSelector(const wxChar *what, const wxChar *extension, const wxChar *default_name, wxWindow *parent) -{ - return wxDefaultFileSelector(FALSE, what, extension, default_name, parent); -} diff --git a/src/mac/filedlg.cpp b/src/mac/filedlg.cpp index f2b6707baf..d7929f00cd 100644 --- a/src/mac/filedlg.cpp +++ b/src/mac/filedlg.cpp @@ -274,65 +274,6 @@ static pascal Boolean CrossPlatformFileFilter(CInfoPBPtr myCInfoPBPtr, void *dat // end wxmac -wxString wxFileSelector(const wxChar *title, - const wxChar *defaultDir, const wxChar *defaultFileName, - const wxChar *defaultExtension, const wxChar *filter, int flags, - wxWindow *parent, int x, int y) -{ - // If there's a default extension specified but no filter, we create a suitable - // filter. - - wxString filter2; - if ( defaultExtension && !filter ) - filter2 = wxString(wxT("*.")) + wxString(defaultExtension) ; - else if ( filter ) - filter2 = filter; - - wxString defaultDirString; - if (defaultDir) - defaultDirString = defaultDir; - else - defaultDirString = wxEmptyString ; - - wxString defaultFilenameString; - if (defaultFileName) - defaultFilenameString = defaultFileName; - else - defaultFilenameString = wxEmptyString; - - wxFileDialog fileDialog(parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y)); - - if ( fileDialog.ShowModal() == wxID_OK ) - { - return fileDialog.GetPath(); - } - else - return wxGetEmptyString(); -} - -WXDLLEXPORT wxString wxFileSelectorEx(const wxChar *title, - const wxChar *defaultDir, - const wxChar *defaultFileName, - int* defaultFilterIndex, - const wxChar *filter, - int flags, - wxWindow* parent, - int x, - int y) - -{ - wxFileDialog fileDialog(parent, title ? title : wxT(""), defaultDir ? defaultDir : wxT(""), - defaultFileName ? defaultFileName : wxT(""), filter ? filter : wxT(""), flags, wxPoint(x, y)); - - if ( fileDialog.ShowModal() == wxID_OK ) - { - *defaultFilterIndex = fileDialog.GetFilterIndex(); - return fileDialog.GetPath(); - } - else - return wxGetEmptyString(); -} - wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard, long style, const wxPoint& pos) @@ -526,40 +467,3 @@ int wxFileDialog::ShowModal() return wxID_CANCEL; } -// Generic file load/save dialog -static wxString -wxDefaultFileSelector(bool load, const wxChar *what, const wxChar *extension, const wxChar *default_name, wxWindow *parent) -{ - wxString prompt; - - wxString str; - if (load) - str = wxT("Load %s file"); - else - str = wxT("Save %s file"); - prompt.Printf( wxGetTranslation(str), what); - - const wxChar *ext = extension; - if (*ext == wxT('.')) - ext++; - - wxString wild; - wild.Printf(wxT("*.%s"), ext); - - return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent); -} - -// Generic file load dialog -wxString -wxLoadFileSelector(const wxChar *what, const wxChar *extension, const wxChar *default_name, wxWindow *parent) -{ - return wxDefaultFileSelector(TRUE, what, extension, default_name, parent); -} - - -// Generic file save dialog -wxString -wxSaveFileSelector(const wxChar *what, const wxChar *extension, const wxChar *default_name, wxWindow *parent) -{ - return wxDefaultFileSelector(FALSE, what, extension, default_name, parent); -} diff --git a/src/motif/filedlg.cpp b/src/motif/filedlg.cpp index ed2ca5e9c4..f4a465e4f2 100644 --- a/src/motif/filedlg.cpp +++ b/src/motif/filedlg.cpp @@ -57,65 +57,6 @@ IMPLEMENT_CLASS(wxFileDialog, wxDialog) #define wxFSB_HEIGHT 500 -wxString wxFileSelector(const char *title, - const char *defaultDir, const char *defaultFileName, - const char *defaultExtension, const char *filter, int flags, - wxWindow *parent, int x, int y) -{ - // If there's a default extension specified but no filter, we create a suitable - // filter. - - wxString filter2(""); - if ( defaultExtension && !filter ) - filter2 = wxString("*.") + wxString(defaultExtension) ; - else if ( filter ) - filter2 = filter; - - wxString defaultDirString; - if (defaultDir) - defaultDirString = defaultDir; - else - defaultDirString = ""; - - wxString defaultFilenameString; - if (defaultFileName) - defaultFilenameString = defaultFileName; - else - defaultFilenameString = ""; - - wxFileDialog fileDialog(parent, title, defaultDirString, defaultFilenameString, filter2, flags, wxPoint(x, y)); - - if ( fileDialog.ShowModal() == wxID_OK ) - { - return fileDialog.GetPath(); - } - else - return wxEmptyString; -} - -wxString wxFileSelectorEx(const char *title, - const char *defaultDir, - const char *defaultFileName, - int* defaultFilterIndex, - const char *filter, - int flags, - wxWindow* parent, - int x, - int y) - -{ - wxFileDialog fileDialog(parent, title ? title : "", defaultDir ? defaultDir : "", - defaultFileName ? defaultFileName : "", filter ? filter : "", flags, wxPoint(x, y)); - - if ( fileDialog.ShowModal() == wxID_OK ) - { - *defaultFilterIndex = fileDialog.GetFilterIndex(); - return fileDialog.GetPath(); - } - else - return wxEmptyString; -} - wxString wxFileDialog::m_fileSelectorAnswer = ""; bool wxFileDialog::m_fileSelectorReturned = FALSE; @@ -377,39 +318,3 @@ int wxFileDialog::ShowModal() return wxID_OK; } -// Generic file load/save dialog -static wxString -wxDefaultFileSelector(bool load, const char *what, const char *extension, const char *default_name, wxWindow *parent) -{ - char *ext = wxConstCast(extension, char); - - wxString prompt; - wxString str; - if (load) - str = _("Load %s file"); - else - str = _("Save %s file"); - prompt.Printf(str, what); - - if (*ext == '.') - ext++; - wxString wild; - wild.Printf("*.%s", ext); - - return wxFileSelector (prompt, NULL, default_name, ext, wild, 0, parent); -} - -// Generic file load dialog -wxString wxLoadFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent) -{ - return wxDefaultFileSelector(TRUE, what, extension, default_name, parent); -} - - -// Generic file save dialog -wxString wxSaveFileSelector(const char *what, const char *extension, const char *default_name, wxWindow *parent) -{ - return wxDefaultFileSelector(FALSE, what, extension, default_name, parent); -} - - diff --git a/src/msw/filedlg.cpp b/src/msw/filedlg.cpp index 12d9f091e7..13ee874b53 100644 --- a/src/msw/filedlg.cpp +++ b/src/msw/filedlg.cpp @@ -83,122 +83,9 @@ IMPLEMENT_CLASS(wxFileDialog, wxDialog) // ---------------------------------------------------------------------------- -// global functions +// wxFileDialog // ---------------------------------------------------------------------------- -wxString wxFileSelector(const wxChar *title, - const wxChar *defaultDir, - const wxChar *defaultFileName, - const wxChar *defaultExtension, - const wxChar *filter, - int flags, - wxWindow *parent, - int x, int y) -{ - // In the original implementation, defaultExtension is passed to the - // lpstrDefExt member of OPENFILENAME. This extension, if non-NULL, is - // appended to the filename if the user fails to type an extension. The new - // implementation (taken from wxFileSelectorEx) appends the extension - // automatically, by looking at the filter specification. In fact this - // should be better than the native Microsoft implementation because - // Windows only allows *one* default extension, whereas here we do the - // right thing depending on the filter the user has chosen. - - // If there's a default extension specified but no filter, we create a - // suitable filter. - - wxString filter2; - if ( defaultExtension && !filter ) - filter2 = wxString(wxT("*.")) + defaultExtension; - else if ( filter ) - filter2 = filter; - - wxString defaultDirString; - if (defaultDir) - defaultDirString = defaultDir; - - wxString defaultFilenameString; - if (defaultFileName) - defaultFilenameString = defaultFileName; - - wxFileDialog fileDialog(parent, title, defaultDirString, - defaultFilenameString, filter2, - flags, wxPoint(x, y)); - if( wxStrlen(defaultExtension) != 0 ) - { - int filterFind = 0, - filterIndex = 0; - - for( unsigned int i = 0; i < filter2.Len(); i++ ) - { - if( filter2.GetChar(i) == wxT('|') ) - { - // save the start index of the new filter - unsigned int is = i++; - - // find the end of the filter - for( ; i < filter2.Len(); i++ ) - { - if(filter2[i] == wxT('|')) - break; - } - - if( i-is-1 > 0 && is+1 < filter2.Len() ) - { - if( filter2.Mid(is+1,i-is-1).Contains(defaultExtension) ) - { - filterFind = filterIndex; - break; - } - } - - filterIndex++; - } - } - - fileDialog.SetFilterIndex(filterFind); - } - - wxString filename; - if ( fileDialog.ShowModal() == wxID_OK ) - { - filename = fileDialog.GetPath(); - } - - return filename; -} - - -wxString wxFileSelectorEx(const wxChar *title, - const wxChar *defaultDir, - const wxChar *defaultFileName, - int* defaultFilterIndex, - const wxChar *filter, - int flags, - wxWindow* parent, - int x, - int y) - -{ - wxFileDialog fileDialog(parent, - title ? title : wxT(""), - defaultDir ? defaultDir : wxT(""), - defaultFileName ? defaultFileName : wxT(""), - filter ? filter : wxT(""), - flags, wxPoint(x, y)); - - wxString filename; - if ( fileDialog.ShowModal() == wxID_OK ) - { - if ( defaultFilterIndex ) - *defaultFilterIndex = fileDialog.GetFilterIndex(); - - filename = fileDialog.GetPath(); - } - - return filename; -} - wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, const wxString& defaultDir, @@ -545,50 +432,5 @@ int wxFileDialog::ShowModal() } -// Generic file load/save dialog (for internal use only) -static -wxString wxDefaultFileSelector(bool load, - const wxChar *what, - const wxChar *extension, - const wxChar *default_name, - wxWindow *parent) -{ - wxString prompt; - wxString str; - if (load) - str = _("Load %s file"); - else - str = _("Save %s file"); - prompt.Printf(str, what); - - const wxChar *ext = extension; - if (*ext == wxT('.')) - ext++; - - wxString wild; - wild.Printf(wxT("*.%s"), ext); - - return wxFileSelector(prompt, NULL, default_name, ext, wild, - load ? wxOPEN : wxSAVE, parent); -} - -// Generic file load dialog -WXDLLEXPORT wxString wxLoadFileSelector(const wxChar *what, - const wxChar *extension, - const wxChar *default_name, - wxWindow *parent) -{ - return wxDefaultFileSelector(TRUE, what, extension, default_name, parent); -} - -// Generic file save dialog -WXDLLEXPORT wxString wxSaveFileSelector(const wxChar *what, - const wxChar *extension, - const wxChar *default_name, - wxWindow *parent) -{ - return wxDefaultFileSelector(FALSE, what, extension, default_name, parent); -} - #endif // wxUSE_FILEDLG diff --git a/src/os2/filedlg.cpp b/src/os2/filedlg.cpp index cb87d850f1..6c3135b1b5 100644 --- a/src/os2/filedlg.cpp +++ b/src/os2/filedlg.cpp @@ -58,127 +58,6 @@ #endif IMPLEMENT_CLASS(wxFileDialog, wxDialog) -// ---------------------------------------------------------------------------- -// global functions -// ---------------------------------------------------------------------------- - -wxString wxFileSelector( - const char* pzTitle -, const char* pzDefaultDir -, const char* pzDefaultFileName -, const char* pzDefaultExtension -, const char* pzFilter -, int nFlags -, wxWindow* pParent -, int nX -, int nY -) -{ - wxString sFilter(""); - wxString sDefaultDirString; - wxString sDefaultFilenameString; - - // - // If there's a default extension specified but no filter, we create - // a suitable filter. - // - if (pzDefaultExtension && !pzFilter) - sFilter = wxString("*.") + wxString(pzDefaultExtension); - else if (pzFilter) - sFilter = pzFilter; - - if (pzDefaultDir) - sDefaultDirString = pzDefaultDir; - else - sDefaultDirString = ""; - - if (pzDefaultFileName) - sDefaultFilenameString = pzDefaultFileName; - else - sDefaultFilenameString = ""; - - wxFileDialog vFileDialog( pParent - ,pzTitle - ,sDefaultDirString - ,sDefaultFilenameString - ,sFilter - ,nFlags - ,wxPoint(nX, nY) - ); - - if (wxStrlen(pzDefaultExtension) != 0) - { - int nFilterFind = 0; - int nFilterIndex = 0; - - for (unsigned int i = 0; i < sFilter.Len(); i++) - { - if (sFilter.GetChar(i) == wxT('|')) - { - // - // Save the start index of the new filter - unsigned int uIs = i++; - - // - // Find the end of the filter - // - for(; i < sFilter.Len(); i++) - { - if(sFilter[i] == wxT('|')) - break; - } - - if( i - uIs - 1 > 0 && uIs + 1 < sFilter.Len() ) - { - if(sFilter.Mid(uIs + 1, i - uIs - 1).Contains(pzDefaultExtension)) - { - nFilterFind = nFilterIndex; - break; - } - } - nFilterIndex++; - } - } - vFileDialog.SetFilterIndex(nFilterFind); - } - if (vFileDialog.ShowModal() == wxID_OK) - { - return vFileDialog.GetPath(); - } - else - return wxEmptyString; -} // end of wxFileSelector - -wxString wxFileSelectorEx ( - const char* pzTitle -, const char* pzDefaultDir -, const char* pzDefaultFileName -, int* pnDefaultFilterIndex -, const char* pzFilter -, int nFlags -, wxWindow* pParent -, int nX -, int nY -) -{ - wxFileDialog vFileDialog( pParent - ,pzTitle ? pzTitle : "" - ,pzDefaultDir ? pzDefaultDir : "" - ,pzDefaultFileName ? pzDefaultFileName : "" - ,pzFilter ? pzFilter : "" - ,nFlags - ,wxPoint(nX, nY) - ); - - if (vFileDialog.ShowModal() == wxID_OK) - { - *pnDefaultFilterIndex = vFileDialog.GetFilterIndex(); - return vFileDialog.GetPath(); - } - else - return wxEmptyString; -} // end of wxFileSelectorEx - // ---------------------------------------------------------------------------- // CLASS wxFileDialog // ---------------------------------------------------------------------------- @@ -443,75 +322,3 @@ int wxFileDialog::ShowModal() return wxID_CANCEL; } // end of wxFileDialog::ShowModal -// -// Generic file load/save dialog -// -static wxString wxDefaultFileSelector ( - bool bLoad -, const char* pzWhat -, const char* pzExtension -, const char* pzDefaultName -, wxWindow* pParent -) -{ - char* pzExt = (char *)pzExtension; - char zPrompt[50]; - wxString sStr; - char zWild[60]; - - if (bLoad) - sStr = "Load %s file"; - else - sStr = "Save %s file"; - sprintf(zPrompt, wxGetTranslation(sStr), pzWhat); - - if (*pzExt == '.') - pzExt++; - sprintf(zWild, "*.%s", pzExt); - return wxFileSelector ( zPrompt - ,NULL - ,pzDefaultName - ,pzExt - ,zWild - ,0 - ,pParent - ); -} // end of wxDefaultFileSelector - -// -// Generic file load dialog -// -wxString wxLoadFileSelector ( - const char* pzWhat -, const char* pzExtension -, const char* pzDefaultName -, wxWindow* pParent -) -{ - return wxDefaultFileSelector( TRUE - ,pzWhat - ,pzExtension - ,pzDefaultName - ,pParent - ); -} // end of wxLoadFileSelector - - -// -// Generic file save dialog -// -wxString wxSaveFileSelector ( - const char* pzWhat -, const char* pzExtension -, const char* pzDefaultName -, wxWindow* pParent -) -{ - return wxDefaultFileSelector( FALSE - ,pzWhat - ,pzExtension - ,pzDefaultName - ,pParent - ); -} // end of wxSaveFileSelector - -- 2.47.2