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
+/////////////////////////////////////////////////////////////////////////////
+// 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,
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__)
#endif // wxUSE_FILEDLG
-#endif
- // _WX_FILEDLG_H_BASE_
+#endif // _WX_FILEDLG_H_BASE_
#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
}
};
-// 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
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 <DIR>, <LINK>, <DRIVE>
- 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
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;
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();
DECLARE_EVENT_TABLE()
};
-#endif
- // _WX_FILEDLGG_H_
-
+#endif // _WX_FILEDLGG_H_
// File selector
//-------------------------------------------------------------------------
-extern const wxChar *wxFileSelectorPromptStr;
-extern const wxChar *wxFileSelectorDefaultWildcardStr;
-
class wxFileDialog: public wxDialog
{
public:
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__
// File selector
//-------------------------------------------------------------------------
-extern const wxChar *wxFileSelectorPromptStr;
-extern const wxChar *wxFileSelectorDefaultWildcardStr;
-
class wxFileDialog: public wxDialog
{
public:
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__
* File selector
*/
-WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorPromptStr;
-WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorDefaultWildcardStr;
-
class WXDLLEXPORT wxFileDialog: public wxDialog
{
DECLARE_DYNAMIC_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 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_
* File selector
*/
-WXDLLEXPORT_DATA(extern const char*) wxFileSelectorPromptStr;
-WXDLLEXPORT_DATA(extern const char*) wxFileSelectorDefaultWildcardStr;
-
class WXDLLEXPORT wxFileDialog: public wxDialog
{
DECLARE_DYNAMIC_CLASS(wxFileDialog)
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_
* File selector
*/
-WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorPromptStr;
-WXDLLEXPORT_DATA(extern const wxChar*) wxFileSelectorDefaultWildcardStr;
-
class WXDLLEXPORT wxFileDialog: public wxDialog
{
public:
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_
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_
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// 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
+
#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 "/")
// ----------------------------------------------------------------------------
}
#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)
// 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()
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-// ============================================================================
-// declarations
-// ============================================================================
-
-// ----------------------------------------------------------------------------
-// headers
-// ----------------------------------------------------------------------------
-
#ifdef __GNUG__
#pragma implementation "filedlgg.h"
#endif
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
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__
// 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;
m_type = type;
m_image = image_id;
+ ReadData();
+}
+
+void wxFileData::ReadData()
+{
if (IsDrive())
{
m_size = 0;
#endif
}
-wxString wxFileData::GetType() const
+wxString wxFileData::GetFileType() const
{
if (IsDir())
return _("<DIR>");
break;
case FileList_Type:
- s = GetType();
+ s = GetFileType();
break;
case FileList_Time:
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
{
fd->SetNewName( new_name, event.GetLabel() );
SetItemState( event.GetItem(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
+ UpdateItem( event.GetItem() );
EnsureVisible( event.GetItem() );
}
else
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
style2 |= wxLC_SINGLE_SEL;
m_list = new wxFileCtrl( this, ID_LIST_CTRL,
- firstWild, ms_lastShowHidden,
+ wildFilters[0], ms_lastShowHidden,
wxDefaultPosition, wxSize(540,200),
style2);
mainsizer->Add( choicesizer, 0, wxEXPAND );
}
- m_choice->Append( firstWildText, (void*) new wxString( firstWild ) );
- while (tokens.HasMoreTokens())
+ for (size_t n=0; n<wildFilters.GetCount(); n++)
{
- firstWildText = tokens.GetNextToken();
- firstWild = tokens.GetNextToken();
- m_choice->Append( 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 );
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();
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__
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
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
}
}
-// ----------------------------------------------------------------------------
-// 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);
-}
-
}
}
-// ----------------------------------------------------------------------------
-// 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);
-}
-
// 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)
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);
-}
// 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)
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);
-}
#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;
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);
-}
-
-
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,
}
-// 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
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
// ----------------------------------------------------------------------------
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
-