2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: filedlg.h
|
2008-03-10 15:24:38 +00:00
|
|
|
// Purpose: interface of wxFileDialog
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxFileDialog
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
This class represents the file chooser dialog.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-01 13:55:38 +00:00
|
|
|
It pops up a file selector box (native for Windows and GTK2.4+).
|
|
|
|
|
|
|
|
The path and filename are distinct elements of a full file pathname.
|
|
|
|
If path is "", the current directory will be used. If filename is "", no default
|
|
|
|
filename will be supplied. The wildcard determines what files are displayed in the
|
|
|
|
file selector, and file extension supplies a type extension for the required filename.
|
|
|
|
|
|
|
|
@remarks
|
|
|
|
All implementations of the wxFileDialog provide a wildcard filter. Typing a filename
|
|
|
|
containing wildcards (*, ?) in the filename text item, and clicking on Ok, will
|
|
|
|
result in only those files matching the pattern being displayed.
|
|
|
|
The wildcard may be a specification for multiple types of file with a description
|
|
|
|
for each, such as:
|
2008-09-25 19:15:28 +00:00
|
|
|
@code
|
2008-04-01 13:55:38 +00:00
|
|
|
"BMP and GIF files (*.bmp;*.gif)|*.bmp;*.gif|PNG files (*.png)|*.png"
|
2008-09-25 19:15:28 +00:00
|
|
|
@endcode
|
2008-04-01 13:55:38 +00:00
|
|
|
It must be noted that wildcard support in the native Motif file dialog is quite
|
|
|
|
limited: only one alternative is supported, and it is displayed without the
|
|
|
|
descriptive test; "BMP files (*.bmp)|*.bmp" is displayed as "*.bmp", and both
|
|
|
|
"BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif" and "Image files|*.bmp;*.gif"
|
|
|
|
are errors.
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@beginStyleTable
|
2008-04-06 14:43:04 +00:00
|
|
|
@style{wxFD_DEFAULT_STYLE}
|
2008-03-08 13:52:38 +00:00
|
|
|
Equivalent to wxFD_OPEN.
|
2008-04-06 14:43:04 +00:00
|
|
|
@style{wxFD_OPEN}
|
2008-03-08 13:52:38 +00:00
|
|
|
This is an open dialog; usually this means that the default
|
2008-04-01 13:55:38 +00:00
|
|
|
button's label of the dialog is "Open". Cannot be combined with wxFD_SAVE.
|
2008-04-06 14:43:04 +00:00
|
|
|
@style{wxFD_SAVE}
|
2008-03-08 13:52:38 +00:00
|
|
|
This is a save dialog; usually this means that the default button's
|
|
|
|
label of the dialog is "Save". Cannot be combined with wxFD_OPEN.
|
2008-04-06 14:43:04 +00:00
|
|
|
@style{wxFD_OVERWRITE_PROMPT}
|
2008-03-08 13:52:38 +00:00
|
|
|
For save dialog only: prompt for a confirmation if a file will be
|
|
|
|
overwritten.
|
2008-04-06 14:43:04 +00:00
|
|
|
@style{wxFD_FILE_MUST_EXIST}
|
2008-04-01 13:55:38 +00:00
|
|
|
For open dialog only: the user may only select files that actually exist.
|
2008-04-06 14:43:04 +00:00
|
|
|
@style{wxFD_MULTIPLE}
|
2008-03-08 13:52:38 +00:00
|
|
|
For open dialog only: allows selecting multiple files.
|
2008-04-06 14:43:04 +00:00
|
|
|
@style{wxFD_CHANGE_DIR}
|
2008-03-08 13:52:38 +00:00
|
|
|
Change the current working directory to the directory where the
|
|
|
|
file(s) chosen by the user are.
|
2008-04-06 14:43:04 +00:00
|
|
|
@style{wxFD_PREVIEW}
|
2008-03-08 13:52:38 +00:00
|
|
|
Show the preview of the selected files (currently only supported by
|
|
|
|
wxGTK using GTK+ 2.4 or later).
|
|
|
|
@endStyleTable
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxcore}
|
|
|
|
@category{cmndlg}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-09-25 14:03:38 +00:00
|
|
|
@see @ref overview_cmndlg_file, ::wxFileSelector()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxFileDialog : public wxDialog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor. Use ShowModal() to show the dialog.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param parent
|
2008-03-09 12:33:59 +00:00
|
|
|
Parent window.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param message
|
2008-03-09 12:33:59 +00:00
|
|
|
Message to show on the dialog.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param defaultDir
|
2008-03-09 12:33:59 +00:00
|
|
|
The default directory, or the empty string.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param defaultFile
|
2008-03-09 12:33:59 +00:00
|
|
|
The default filename, or the empty string.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param wildcard
|
2008-04-01 13:55:38 +00:00
|
|
|
A wildcard, such as "*.*" or "BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif".
|
2008-03-09 12:33:59 +00:00
|
|
|
Note that the native Motif dialog has some limitations with respect to
|
|
|
|
wildcards; see the Remarks section above.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param style
|
2008-03-09 12:33:59 +00:00
|
|
|
A dialog style. See wxFD_* styles for more info.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param pos
|
2008-03-09 12:33:59 +00:00
|
|
|
Dialog position. Not implemented.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param size
|
2008-03-09 12:33:59 +00:00
|
|
|
Dialog size. Not implemented.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param name
|
2008-03-09 12:33:59 +00:00
|
|
|
Dialog name. Not implemented.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
wxFileDialog(wxWindow* parent,
|
|
|
|
const wxString& message = "Choose a file",
|
|
|
|
const wxString& defaultDir = "",
|
|
|
|
const wxString& defaultFile = "",
|
|
|
|
const wxString& wildcard = ".",
|
|
|
|
long style = wxFD_DEFAULT_STYLE,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& sz = wxDefaultSize,
|
|
|
|
const wxString& name = "filedlg");
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual ~wxFileDialog();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the default directory.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual wxString GetDirectory() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-01 13:55:38 +00:00
|
|
|
If functions SetExtraControlCreator() and ShowModal() were called,
|
2008-03-08 13:52:38 +00:00
|
|
|
returns the extra window. Otherwise returns @NULL.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxWindow* GetExtraControl() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the default filename.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual wxString GetFilename() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-01 13:55:38 +00:00
|
|
|
Fills the array @a filenames with the names of the files chosen.
|
|
|
|
|
|
|
|
This function should only be used with the dialogs which have @c wxFD_MULTIPLE style,
|
2008-03-08 13:52:38 +00:00
|
|
|
use GetFilename() for the others.
|
2008-04-01 13:55:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Note that under Windows, if the user selects shortcuts, the filenames
|
|
|
|
include paths, since the application cannot determine the full path
|
|
|
|
of each referenced file by appending the directory containing the shortcuts
|
|
|
|
to the filename.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual void GetFilenames(wxArrayString& filenames) const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the index into the list of filters supplied, optionally, in the
|
|
|
|
wildcard parameter.
|
2008-04-01 13:55:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Before the dialog is shown, this is the index which will be used when the
|
|
|
|
dialog is first displayed.
|
2008-04-01 13:55:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
After the dialog is shown, this is the index selected by the user.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual int GetFilterIndex() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the message that will be displayed on the dialog.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual wxString GetMessage() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the full path (directory and filename) of the selected file.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual wxString GetPath() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-01 13:55:38 +00:00
|
|
|
Fills the array @a paths with the full paths of the files chosen.
|
|
|
|
|
|
|
|
This function should only be used with the dialogs which have @c wxFD_MULTIPLE style,
|
2008-03-08 13:52:38 +00:00
|
|
|
use GetPath() for the others.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual void GetPaths(wxArrayString& paths) const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the file dialog wildcard.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual wxString GetWildcard() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the default directory.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual void SetDirectory(const wxString& directory);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Customize file dialog by adding extra window, which is typically placed
|
|
|
|
below the list of files and above the buttons.
|
2008-04-01 13:55:38 +00:00
|
|
|
|
|
|
|
SetExtraControlCreator() can be called only once, before calling ShowModal().
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The @c creator function should take pointer to parent window (file dialog)
|
|
|
|
and should return a window allocated with operator new.
|
2008-04-01 13:55:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Supported platforms: wxGTK, wxUniv.
|
|
|
|
*/
|
|
|
|
bool SetExtraControlCreator(t_extraControlCreator creator);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the default filename.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual void SetFilename(const wxString& setfilename);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the default filter index, starting from zero.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual void SetFilterIndex(int filterIndex);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the message that will be displayed on the dialog.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual void SetMessage(const wxString& message);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the path (the combined directory and filename that will be returned when
|
|
|
|
the dialog is dismissed).
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual void SetPath(const wxString& path);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the wildcard, which can contain multiple file types, for example:
|
2008-04-01 13:55:38 +00:00
|
|
|
"BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif".
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Note that the native Motif dialog has some limitations with respect to
|
|
|
|
wildcards; see the Remarks section above.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual void SetWildcard(const wxString& wildCard);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Shows the dialog, returning wxID_OK if the user pressed OK, and wxID_CANCEL
|
|
|
|
otherwise.
|
|
|
|
*/
|
2008-09-27 11:21:10 +00:00
|
|
|
virtual int ShowModal();
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
// ============================================================================
|
|
|
|
// Global functions/macros
|
|
|
|
// ============================================================================
|
|
|
|
|
2008-03-18 19:30:01 +00:00
|
|
|
/** @ingroup group_funcmacro_dialog */
|
|
|
|
//@{
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
Pops up a file selector box. In Windows, this is the common file selector
|
2008-03-18 19:30:01 +00:00
|
|
|
dialog. In X, this is a file selector box with the same functionality. The
|
|
|
|
path and filename are distinct elements of a full file pathname. If path
|
|
|
|
is empty, the current directory will be used. If filename is empty, no
|
|
|
|
default filename will be supplied. The wildcard determines what files are
|
|
|
|
displayed in the file selector, and file extension supplies a type
|
|
|
|
extension for the required filename. Flags may be a combination of
|
|
|
|
wxFD_OPEN, wxFD_SAVE, wxFD_OVERWRITE_PROMPT or wxFD_FILE_MUST_EXIST.
|
|
|
|
|
|
|
|
@note wxFD_MULTIPLE can only be used with wxFileDialog and not here since
|
|
|
|
this function only returns a single file name.
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
Both the Unix and Windows versions implement a wildcard filter. Typing a
|
|
|
|
filename containing wildcards (*, ?) in the filename text item, and
|
|
|
|
clicking on Ok, will result in only those files matching the pattern being
|
|
|
|
displayed.
|
2008-03-18 19:30:01 +00:00
|
|
|
|
|
|
|
The wildcard may be a specification for multiple types of file with a
|
|
|
|
description for each, such as:
|
2008-03-09 12:33:59 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@code
|
|
|
|
"BMP files (*.bmp)|*.bmp|GIF files (*.gif)|*.gif"
|
|
|
|
@endcode
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The application must check for an empty return value (the user pressed
|
|
|
|
Cancel). For example:
|
2008-03-09 12:33:59 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@code
|
|
|
|
wxString filename = wxFileSelector("Choose a file to open");
|
|
|
|
if ( !filename.empty() )
|
|
|
|
{
|
|
|
|
// work with the file
|
|
|
|
...
|
|
|
|
}
|
|
|
|
//else: cancelled by user
|
|
|
|
@endcode
|
2008-03-18 19:30:01 +00:00
|
|
|
|
|
|
|
@header{wx/filedlg.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
wxString wxFileSelector(const wxString& message,
|
|
|
|
const wxString& default_path = "",
|
|
|
|
const wxString& default_filename = "",
|
|
|
|
const wxString& default_extension = "",
|
|
|
|
const wxString& wildcard = ".",
|
|
|
|
int flags = 0,
|
2008-03-09 12:33:59 +00:00
|
|
|
wxWindow* parent = NULL,
|
2008-03-08 13:52:38 +00:00
|
|
|
int x = -1,
|
|
|
|
int y = -1);
|
|
|
|
|
2008-03-18 19:30:01 +00:00
|
|
|
//@}
|
|
|
|
|