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
This commit is contained in:
Vadim Zeitlin
2003-06-14 13:31:49 +00:00
parent 30e671a59f
commit b600ed1362
19 changed files with 458 additions and 1326 deletions

View File

@@ -164,6 +164,7 @@ fileconf.cpp Common Base
filefn.cpp Common Base filefn.cpp Common Base
filename.cpp Common Base filename.cpp Common Base
filesys.cpp Common Base filesys.cpp Common Base
fldlgcmn.cpp Common
fontcmn.cpp Common fontcmn.cpp Common
fontmap.cpp Common Base fontmap.cpp Common Base
framecmn.cpp Common framecmn.cpp Common

View File

@@ -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_ #ifndef _WX_FILEDLG_H_BASE_
#define _WX_FILEDLG_H_BASE_ #define _WX_FILEDLG_H_BASE_
#if wxUSE_FILEDLG #if wxUSE_FILEDLG
#if defined(__GNUG__) && !defined(__APPLE__)
#pragma interface "filedlg.h"
#endif
//----------------------------------------------------------------------------
// wxFileDialog data and generic functions
//----------------------------------------------------------------------------
enum enum
{ {
wxOPEN = 0x0001, wxOPEN = 0x0001,
@@ -14,6 +33,59 @@ enum
wxCHANGE_DIR = 0x0040 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__) #if defined (__WXUNIVERSAL__)
#include "wx/generic/filedlgg.h" #include "wx/generic/filedlgg.h"
#elif defined(__WXMSW__) #elif defined(__WXMSW__)
@@ -36,5 +108,4 @@ enum
#endif // wxUSE_FILEDLG #endif // wxUSE_FILEDLG
#endif #endif // _WX_FILEDLG_H_BASE_
// _WX_FILEDLG_H_BASE_

View File

@@ -39,19 +39,8 @@ class WXDLLEXPORT wxTextCtrl;
#define USE_GENERIC_FILEDIALOG #define USE_GENERIC_FILEDIALOG
#endif #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 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 #endif // USE_GENERIC_FILEDIALOG
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxFileData // wxFileData - a class to hold the file info for the wxFileCtrl
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class WXDLLEXPORT wxFileData class WXDLLEXPORT wxFileData
@@ -214,29 +167,43 @@ public:
is_drive = 0x0008 is_drive = 0x0008
}; };
// Full copy constructor
wxFileData( const wxFileData& fileData );
// Create a filedata from this information
wxFileData( const wxString &filePath, const wxString &fileName, wxFileData( const wxString &filePath, const wxString &fileName,
fileType type, int image_id ); 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 // get the name of the file, dir, drive
wxString GetFileName() const { return m_fileName; } wxString GetFileName() const { return m_fileName; }
// get the full path + name of the file, dir, path // get the full path + name of the file, dir, path
wxString GetFilePath() const { return m_filePath; } 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; } long GetSize() const { return m_size; }
// Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE> // Get the type of file, either file extension or <DIR>, <LINK>, <DRIVE>
wxString GetType() const; wxString GetFileType() const;
// get the last modification time // 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; wxString GetModificationTime() const;
// in UNIX get rwx for file, in MSW get attributes ARHS // in UNIX get rwx for file, in MSW get attributes ARHS
wxString GetPermissions() const { return m_permissions; } wxString GetPermissions() const { return m_permissions; }
// Get the id of the image used in a wxImageList
int GetImageId() const { return m_image; } int GetImageId() const { return m_image; }
bool IsFile() const { return !IsDir() && !IsLink() && !IsDrive(); }
bool IsDir() const { return (m_type & is_dir ) != 0; } bool IsDir() const { return (m_type & is_dir ) != 0; }
bool IsLink() const { return (m_type & is_link ) != 0; } bool IsLink() const { return (m_type & is_link ) != 0; }
bool IsExe() const { return (m_type & is_exe ) != 0; } bool IsExe() const { return (m_type & is_exe ) != 0; }
bool IsDrive() const { return (m_type & is_drive) != 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 // the wxFileCtrl fields in report view
enum fileListFieldType enum fileListFieldType
@@ -251,12 +218,13 @@ public:
FileList_Max FileList_Max
}; };
// Get the entry for report view of wxFileCtrl
wxString GetEntry( fileListFieldType num ) const; wxString GetEntry( fileListFieldType num ) const;
// Get a string representation of the file info // Get a string representation of the file info
wxString GetHint() const; wxString GetHint() const;
// initialize a wxListItem attributes
void MakeItem( wxListItem &item ); void MakeItem( wxListItem &item );
void SetNewName( const wxString &filePath, const wxString &fileName );
private: private:
wxString m_fileName; wxString m_fileName;
@@ -294,6 +262,7 @@ public:
bool GetShowHidden() const { return m_showHidden; } bool GetShowHidden() const { return m_showHidden; }
virtual long Add( wxFileData *fd, wxListItem &item ); virtual long Add( wxFileData *fd, wxListItem &item );
virtual void UpdateItem(const wxListItem &item);
virtual void UpdateFiles(); virtual void UpdateFiles();
virtual void MakeDir(); virtual void MakeDir();
virtual void GoToParentDir(); virtual void GoToParentDir();
@@ -327,7 +296,5 @@ private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
#endif #endif // _WX_FILEDLGG_H_
// _WX_FILEDLGG_H_

View File

@@ -21,9 +21,6 @@
// File selector // File selector
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
extern const wxChar *wxFileSelectorPromptStr;
extern const wxChar *wxFileSelectorDefaultWildcardStr;
class wxFileDialog: public wxDialog class wxFileDialog: public wxDialog
{ {
public: public:
@@ -67,47 +64,4 @@ private:
DECLARE_DYNAMIC_CLASS(wxFileDialog) DECLARE_DYNAMIC_CLASS(wxFileDialog)
}; };
#define wxOPEN 1 #endif // __GTKFILEDLGH__
#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__

View File

@@ -21,9 +21,6 @@
// File selector // File selector
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
extern const wxChar *wxFileSelectorPromptStr;
extern const wxChar *wxFileSelectorDefaultWildcardStr;
class wxFileDialog: public wxDialog class wxFileDialog: public wxDialog
{ {
public: public:
@@ -67,47 +64,4 @@ private:
DECLARE_DYNAMIC_CLASS(wxFileDialog) DECLARE_DYNAMIC_CLASS(wxFileDialog)
}; };
#define wxOPEN 1 #endif // __GTKFILEDLGH__
#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__

View File

@@ -22,9 +22,6 @@
* File selector * File selector
*/ */
WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorPromptStr;
WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorDefaultWildcardStr;
class WXDLLEXPORT wxFileDialog: public wxDialog class WXDLLEXPORT wxFileDialog: public wxDialog
{ {
DECLARE_DYNAMIC_CLASS(wxFileDialog) DECLARE_DYNAMIC_CLASS(wxFileDialog)
@@ -71,29 +68,4 @@ public:
}; };
#define wxOPEN 0x0001 #endif // _WX_FILEDLG_H_
#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_

View File

@@ -22,9 +22,6 @@
* File selector * File selector
*/ */
WXDLLEXPORT_DATA(extern const char*) wxFileSelectorPromptStr;
WXDLLEXPORT_DATA(extern const char*) wxFileSelectorDefaultWildcardStr;
class WXDLLEXPORT wxFileDialog: public wxDialog class WXDLLEXPORT wxFileDialog: public wxDialog
{ {
DECLARE_DYNAMIC_CLASS(wxFileDialog) DECLARE_DYNAMIC_CLASS(wxFileDialog)
@@ -70,29 +67,4 @@ public:
int ShowModal(); int ShowModal();
}; };
#define wxOPEN 0x0001 #endif // _WX_FILEDLG_H_
#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_

View File

@@ -22,9 +22,6 @@
* File selector * File selector
*/ */
WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorPromptStr;
WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorDefaultWildcardStr;
class WXDLLEXPORT wxFileDialog: public wxDialog class WXDLLEXPORT wxFileDialog: public wxDialog
{ {
public: public:
@@ -72,42 +69,5 @@ private:
DECLARE_NO_COPY_CLASS(wxFileDialog) DECLARE_NO_COPY_CLASS(wxFileDialog)
}; };
// File selector - backward compatibility #endif // _WX_FILEDLG_H_
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_

View File

@@ -64,58 +64,4 @@ protected:
wxPoint m_vPos; wxPoint m_vPos;
}; // end of CLASS wxFileDialog }; // end of CLASS wxFileDialog
#define wxOPEN 0x0001 #endif // _WX_FILEDLG_H_
#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_

280
src/common/fldlgcmn.cpp Normal file
View File

@@ -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

View File

@@ -99,6 +99,9 @@ extern bool wxIsDriveAvailable(const wxString& dirName);
#undef GetFirstChild #undef GetFirstChild
#endif #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 "/") // wxGetAvailableDrives, for WINDOWS, DOS, WXPM, MAC, UNIX (returns "/")
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -348,6 +351,7 @@ bool wxIsDriveAvailable(const wxString& dirName)
} }
#endif // __WINDOWS__ || __WXPM__ #endif // __WINDOWS__ || __WXPM__
// Function which is called by quick sort. We want to override the default wxArrayString behaviour, // Function which is called by quick sort. We want to override the default wxArrayString behaviour,
// and sort regardless of case. // and sort regardless of case.
static int LINKAGEMODE wxDirCtrlStringCompareFunction(const void *first, const void *second) 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. // Parses the global filter, returning the number of filters.
// Returns 0 if none or if there's a problem. // Returns 0 if none or if there's a problem.
// filterStr is in the form: // filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
//
// "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg"
int wxGenericDirCtrl::ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions) int wxGenericDirCtrl::ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions)
{ {
wxString str(filterStr); return wxParseFileFilter(filterStr, descriptions, filters );
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();
} }
void wxGenericDirCtrl::DoResize() void wxGenericDirCtrl::DoResize()

View File

@@ -9,14 +9,6 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "filedlgg.h" #pragma implementation "filedlgg.h"
#endif #endif
@@ -121,7 +113,7 @@ int wxFileDataTypeCompare( long data1, long data2, long data)
if (fd2->IsDir() && !fd1->IsDir()) return data; if (fd2->IsDir() && !fd1->IsDir()) return data;
if (fd1->IsLink() && !fd2->IsLink()) return -data; if (fd1->IsLink() && !fd2->IsLink()) return -data;
if (fd2->IsLink() && !fd1->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 static
@@ -134,7 +126,7 @@ int wxFileDataTimeCompare( long data1, long data2, long data)
if (fd1->IsDir() && !fd2->IsDir()) return -data; if (fd1->IsDir() && !fd2->IsDir()) return -data;
if (fd2->IsDir() && !fd1->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__ #ifdef __UNIX__
@@ -157,6 +149,17 @@ extern size_t wxGetAvailableDrives(wxArrayString &paths, wxArrayString &names, w
// wxFileData // 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 ) wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, fileType type, int image_id )
{ {
m_fileName = fileName; m_fileName = fileName;
@@ -164,6 +167,11 @@ wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, file
m_type = type; m_type = type;
m_image = image_id; m_image = image_id;
ReadData();
}
void wxFileData::ReadData()
{
if (IsDrive()) if (IsDrive())
{ {
m_size = 0; m_size = 0;
@@ -229,7 +237,7 @@ wxFileData::wxFileData( const wxString &filePath, const wxString &fileName, file
#endif #endif
} }
wxString wxFileData::GetType() const wxString wxFileData::GetFileType() const
{ {
if (IsDir()) if (IsDir())
return _("<DIR>"); return _("<DIR>");
@@ -290,7 +298,7 @@ wxString wxFileData::GetEntry( fileListFieldType num ) const
break; break;
case FileList_Type: case FileList_Type:
s = GetType(); s = GetFileType();
break; break;
case FileList_Time: case FileList_Time:
@@ -449,6 +457,23 @@ long wxFileCtrl::Add( wxFileData *fd, wxListItem &item )
return ret; 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() void wxFileCtrl::UpdateFiles()
{ {
// don't do anything before ShowModal() call which sets m_dirName // 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() ); fd->SetNewName( new_name, event.GetLabel() );
SetItemState( event.GetItem(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); SetItemState( event.GetItem(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
UpdateItem( event.GetItem() );
EnsureVisible( event.GetItem() ); EnsureVisible( event.GetItem() );
} }
else else
@@ -853,24 +879,19 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
if (m_wildCard.IsEmpty()) if (m_wildCard.IsEmpty())
m_wildCard = _("All files (*)|*"); m_wildCard = _("All files (*)|*");
wxStringTokenizer tokens( m_wildCard, wxT("|") ); wxArrayString wildDescriptions, wildFilters;
wxString firstWild; int wild_count = wxParseFileFilter(m_wildCard, wildDescriptions, wildFilters);
wxString firstWildText;
if (tokens.CountTokens() == 1) wxASSERT_MSG(wild_count > 0, wxT("Wrong file type descripition") );
// if error parsing, add default back
if (wildFilters.GetCount() < 1u)
{ {
firstWildText = tokens.GetNextToken(); wild_count = 1;
firstWild = firstWildText; m_wildCard = _("All files (*)|*");
wildDescriptions.Add(_("All files (*)"));
wildFilters.Add(wxT("*"));
} }
else
{
wxASSERT_MSG( tokens.CountTokens() % 2 == 0, wxT("Wrong file type descripition") );
firstWildText = tokens.GetNextToken();
firstWild = tokens.GetNextToken();
}
if ( firstWild.Left( 2 ) == wxT("*.") )
m_filterExtension = firstWild.Mid( 1 );
if ( m_filterExtension == wxT(".*") )
m_filterExtension = wxEmptyString;
// layout // layout
@@ -940,7 +961,7 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
style2 |= wxLC_SINGLE_SEL; style2 |= wxLC_SINGLE_SEL;
m_list = new wxFileCtrl( this, ID_LIST_CTRL, m_list = new wxFileCtrl( this, ID_LIST_CTRL,
firstWild, ms_lastShowHidden, wildFilters[0], ms_lastShowHidden,
wxDefaultPosition, wxSize(540,200), wxDefaultPosition, wxSize(540,200),
style2); style2);
@@ -988,14 +1009,11 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent,
mainsizer->Add( choicesizer, 0, wxEXPAND ); mainsizer->Add( choicesizer, 0, wxEXPAND );
} }
m_choice->Append( firstWildText, (void*) new wxString( firstWild ) ); for (size_t n=0; n<wildFilters.GetCount(); n++)
while (tokens.HasMoreTokens())
{ {
firstWildText = tokens.GetNextToken(); m_choice->Append( wildDescriptions[n], (void*) new wxString( wildFilters[n] ) );
firstWild = tokens.GetNextToken();
m_choice->Append( firstWildText, (void*) new wxString( firstWild ) );
} }
m_choice->SetSelection( 0 ); SetFilterIndex( 0 );
SetAutoLayout( TRUE ); SetAutoLayout( TRUE );
SetSizer( mainsizer ); SetSizer( mainsizer );
@@ -1124,6 +1142,11 @@ void wxGenericFileDialog::HandleAction( const wxString &fn )
if (filename.IsEmpty()) return; if (filename.IsEmpty()) return;
if (filename == wxT(".")) 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("..")) if (filename == wxT(".."))
{ {
m_list->GoToParentDir(); m_list->GoToParentDir();
@@ -1141,13 +1164,9 @@ void wxGenericFileDialog::HandleAction( const wxString &fn )
return; return;
} }
if (filename[0u] == wxT('~')) if (filename.BeforeFirst(wxT('/')) == wxT("~"))
{ {
filename.Remove( 0, 1 ); filename = wxGetUserHome() + filename.Remove(0, 1);
wxString tmp( wxGetUserHome() );
tmp += wxT('/');
tmp += filename;
filename = tmp;
} }
#endif // __UNIX__ #endif // __UNIX__
@@ -1178,6 +1197,14 @@ void wxGenericFileDialog::HandleAction( const wxString &fn )
return; 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 // 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 // VZ: the logic of testing for !wxFileExists() only for the open file
@@ -1356,152 +1383,6 @@ void wxGenericFileDialog::UpdateControls()
IMPLEMENT_DYNAMIC_CLASS(wxFileDialog, wxGenericFileDialog); 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 // USE_GENERIC_FILEDIALOG
#endif // wxUSE_FILEDLG #endif // wxUSE_FILEDLG

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -274,65 +274,6 @@ static pascal Boolean CrossPlatformFileFilter(CInfoPBPtr myCInfoPBPtr, void *dat
// end wxmac // 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, wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard, const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard,
long style, const wxPoint& pos) long style, const wxPoint& pos)
@@ -526,40 +467,3 @@ int wxFileDialog::ShowModal()
return wxID_CANCEL; 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);
}

View File

@@ -274,65 +274,6 @@ static pascal Boolean CrossPlatformFileFilter(CInfoPBPtr myCInfoPBPtr, void *dat
// end wxmac // 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, wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard, const wxString& defaultDir, const wxString& defaultFileName, const wxString& wildCard,
long style, const wxPoint& pos) long style, const wxPoint& pos)
@@ -526,40 +467,3 @@ int wxFileDialog::ShowModal()
return wxID_CANCEL; 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);
}

View File

@@ -57,65 +57,6 @@ IMPLEMENT_CLASS(wxFileDialog, wxDialog)
#define wxFSB_HEIGHT 500 #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 = ""; wxString wxFileDialog::m_fileSelectorAnswer = "";
bool wxFileDialog::m_fileSelectorReturned = FALSE; bool wxFileDialog::m_fileSelectorReturned = FALSE;
@@ -377,39 +318,3 @@ int wxFileDialog::ShowModal()
return wxID_OK; 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);
}

View File

@@ -83,122 +83,9 @@
IMPLEMENT_CLASS(wxFileDialog, wxDialog) 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, wxFileDialog::wxFileDialog(wxWindow *parent,
const wxString& message, const wxString& message,
const wxString& defaultDir, 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 #endif // wxUSE_FILEDLG

View File

@@ -58,127 +58,6 @@
#endif #endif
IMPLEMENT_CLASS(wxFileDialog, wxDialog) 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 // CLASS wxFileDialog
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -443,75 +322,3 @@ int wxFileDialog::ShowModal()
return wxID_CANCEL; return wxID_CANCEL;
} // end of wxFileDialog::ShowModal } // 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