2006-05-31 19:57:54 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/generic/filepickerg.h
|
|
|
|
// Purpose: wxGenericFileDirButton, wxGenericFileButton, wxGenericDirButton
|
|
|
|
// Author: Francesco Montorsi
|
|
|
|
// Modified by:
|
|
|
|
// Created: 14/4/2006
|
|
|
|
// Copyright: (c) Francesco Montorsi
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows Licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_FILEDIRPICKER_H_
|
|
|
|
#define _WX_FILEDIRPICKER_H_
|
|
|
|
|
2006-06-01 04:52:03 -04:00
|
|
|
#include "wx/button.h"
|
2006-05-31 19:57:54 -04:00
|
|
|
#include "wx/filedlg.h"
|
|
|
|
#include "wx/dirdlg.h"
|
|
|
|
|
|
|
|
|
2013-04-25 06:11:03 -04:00
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_DIRPICKER_CHANGED, wxFileDirPickerEvent );
|
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FILEPICKER_CHANGED, wxFileDirPickerEvent );
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// wxGenericFileDirButton: a button which brings up a wx{File|Dir}Dialog
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_CORE wxGenericFileDirButton : public wxButton,
|
|
|
|
public wxFileDirPickerWidgetBase
|
|
|
|
{
|
|
|
|
public:
|
2010-03-15 20:23:57 -04:00
|
|
|
wxGenericFileDirButton() { Init(); }
|
2006-05-31 19:57:54 -04:00
|
|
|
wxGenericFileDirButton(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxString& label = wxFilePickerWidgetLabel,
|
|
|
|
const wxString& path = wxEmptyString,
|
|
|
|
const wxString &message = wxFileSelectorPromptStr,
|
|
|
|
const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
|
|
|
const wxString& name = wxFilePickerWidgetNameStr)
|
|
|
|
{
|
2010-03-15 20:23:57 -04:00
|
|
|
Init();
|
2006-05-31 19:57:54 -04:00
|
|
|
Create(parent, id, label, path, message, wildcard,
|
|
|
|
pos, size, style, validator, name);
|
|
|
|
}
|
|
|
|
|
2006-07-15 11:13:04 -04:00
|
|
|
virtual wxControl *AsControl() { return this; }
|
|
|
|
|
2011-04-03 16:31:32 -04:00
|
|
|
public: // overridable
|
2006-05-31 19:57:54 -04:00
|
|
|
|
2006-06-02 08:00:30 -04:00
|
|
|
virtual wxDialog *CreateDialog() = 0;
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
virtual wxWindow *GetDialogParent()
|
2006-06-02 08:00:30 -04:00
|
|
|
{ return GetParent(); }
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
virtual wxEventType GetEventType() const = 0;
|
|
|
|
|
2011-12-18 07:34:47 -05:00
|
|
|
virtual void SetInitialDirectory(const wxString& dir);
|
|
|
|
|
2006-05-31 19:57:54 -04:00
|
|
|
public:
|
|
|
|
|
|
|
|
bool Create(wxWindow *parent, wxWindowID id,
|
|
|
|
const wxString& label = wxFilePickerWidgetLabel,
|
|
|
|
const wxString& path = wxEmptyString,
|
|
|
|
const wxString &message = wxFileSelectorPromptStr,
|
|
|
|
const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = 0,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
|
|
|
const wxString& name = wxFilePickerWidgetNameStr);
|
|
|
|
|
|
|
|
// event handler for the click
|
|
|
|
void OnButtonClick(wxCommandEvent &);
|
|
|
|
|
2006-06-02 08:00:30 -04:00
|
|
|
protected:
|
|
|
|
wxString m_message, m_wildcard;
|
2010-03-08 14:37:08 -05:00
|
|
|
|
|
|
|
// we just store the style passed to the ctor here instead of passing it to
|
|
|
|
// wxButton as some of our bits can conflict with wxButton styles and it
|
|
|
|
// just doesn't make sense to use picker styles for wxButton anyhow
|
|
|
|
long m_pickerStyle;
|
2010-03-15 20:23:57 -04:00
|
|
|
|
2011-12-18 07:34:47 -05:00
|
|
|
// Initial directory set by SetInitialDirectory() call or empty.
|
|
|
|
wxString m_initialDir;
|
|
|
|
|
2010-03-15 20:23:57 -04:00
|
|
|
private:
|
|
|
|
// common part of all ctors
|
|
|
|
void Init() { m_pickerStyle = -1; }
|
2006-05-31 19:57:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// wxGenericFileButton: a button which brings up a wxFileDialog
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2006-06-02 08:00:30 -04:00
|
|
|
#define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
class WXDLLIMPEXP_CORE wxGenericFileButton : public wxGenericFileDirButton
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxGenericFileButton() {}
|
|
|
|
wxGenericFileButton(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxString& label = wxFilePickerWidgetLabel,
|
|
|
|
const wxString& path = wxEmptyString,
|
|
|
|
const wxString &message = wxFileSelectorPromptStr,
|
|
|
|
const wxString &wildcard = wxFileSelectorDefaultWildcardStr,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxFILEBTN_DEFAULT_STYLE,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
|
|
|
const wxString& name = wxFilePickerWidgetNameStr)
|
|
|
|
{
|
|
|
|
Create(parent, id, label, path, message, wildcard,
|
|
|
|
pos, size, style, validator, name);
|
|
|
|
}
|
|
|
|
|
2011-04-03 16:31:32 -04:00
|
|
|
public: // overridable
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
virtual long GetDialogStyle() const
|
|
|
|
{
|
2010-03-15 20:23:57 -04:00
|
|
|
// the derived class must initialize it if it doesn't use the
|
|
|
|
// non-default wxGenericFileDirButton ctor
|
|
|
|
wxASSERT_MSG( m_pickerStyle != -1,
|
|
|
|
"forgot to initialize m_pickerStyle?" );
|
|
|
|
|
|
|
|
|
2006-05-31 19:57:54 -04:00
|
|
|
long filedlgstyle = 0;
|
|
|
|
|
2010-03-08 14:37:08 -05:00
|
|
|
if ( m_pickerStyle & wxFLP_OPEN )
|
2006-05-31 19:57:54 -04:00
|
|
|
filedlgstyle |= wxFD_OPEN;
|
2010-03-08 14:37:08 -05:00
|
|
|
if ( m_pickerStyle & wxFLP_SAVE )
|
2006-05-31 19:57:54 -04:00
|
|
|
filedlgstyle |= wxFD_SAVE;
|
2010-03-08 14:37:08 -05:00
|
|
|
if ( m_pickerStyle & wxFLP_OVERWRITE_PROMPT )
|
2006-05-31 19:57:54 -04:00
|
|
|
filedlgstyle |= wxFD_OVERWRITE_PROMPT;
|
2010-03-08 14:37:08 -05:00
|
|
|
if ( m_pickerStyle & wxFLP_FILE_MUST_EXIST )
|
2006-05-31 19:57:54 -04:00
|
|
|
filedlgstyle |= wxFD_FILE_MUST_EXIST;
|
2010-03-08 14:37:08 -05:00
|
|
|
if ( m_pickerStyle & wxFLP_CHANGE_DIR )
|
2006-05-31 19:57:54 -04:00
|
|
|
filedlgstyle |= wxFD_CHANGE_DIR;
|
|
|
|
|
|
|
|
return filedlgstyle;
|
|
|
|
}
|
|
|
|
|
2011-12-18 07:34:47 -05:00
|
|
|
virtual wxDialog *CreateDialog();
|
2006-05-31 19:57:54 -04:00
|
|
|
|
2006-06-03 15:20:23 -04:00
|
|
|
wxEventType GetEventType() const
|
2013-04-25 06:11:03 -04:00
|
|
|
{ return wxEVT_FILEPICKER_CHANGED; }
|
2006-06-03 15:20:23 -04:00
|
|
|
|
|
|
|
protected:
|
2006-06-02 08:00:30 -04:00
|
|
|
void UpdateDialogPath(wxDialog *p)
|
|
|
|
{ wxStaticCast(p, wxFileDialog)->SetPath(m_path); }
|
|
|
|
void UpdatePathFromDialog(wxDialog *p)
|
|
|
|
{ m_path = wxStaticCast(p, wxFileDialog)->GetPath(); }
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxGenericFileButton)
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// wxGenericDirButton: a button which brings up a wxDirDialog
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define wxDIRBTN_DEFAULT_STYLE 0
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_CORE wxGenericDirButton : public wxGenericFileDirButton
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxGenericDirButton() {}
|
|
|
|
wxGenericDirButton(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxString& label = wxDirPickerWidgetLabel,
|
|
|
|
const wxString& path = wxEmptyString,
|
|
|
|
const wxString &message = wxDirSelectorPromptStr,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxDIRBTN_DEFAULT_STYLE,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
|
|
|
const wxString& name = wxDirPickerWidgetNameStr)
|
|
|
|
{
|
|
|
|
Create(parent, id, label, path, message, wxEmptyString,
|
|
|
|
pos, size, style, validator, name);
|
|
|
|
}
|
|
|
|
|
2011-04-03 16:31:32 -04:00
|
|
|
public: // overridable
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
virtual long GetDialogStyle() const
|
|
|
|
{
|
2006-06-21 10:38:50 -04:00
|
|
|
long dirdlgstyle = wxDD_DEFAULT_STYLE;
|
2006-05-31 19:57:54 -04:00
|
|
|
|
2010-03-08 14:37:08 -05:00
|
|
|
if ( m_pickerStyle & wxDIRP_DIR_MUST_EXIST )
|
2006-05-31 19:57:54 -04:00
|
|
|
dirdlgstyle |= wxDD_DIR_MUST_EXIST;
|
2010-03-08 14:37:08 -05:00
|
|
|
if ( m_pickerStyle & wxDIRP_CHANGE_DIR )
|
2006-05-31 19:57:54 -04:00
|
|
|
dirdlgstyle |= wxDD_CHANGE_DIR;
|
|
|
|
|
|
|
|
return dirdlgstyle;
|
|
|
|
}
|
|
|
|
|
2011-12-18 07:34:47 -05:00
|
|
|
virtual wxDialog *CreateDialog();
|
2006-05-31 19:57:54 -04:00
|
|
|
|
2006-06-03 15:20:23 -04:00
|
|
|
wxEventType GetEventType() const
|
2013-04-25 06:11:03 -04:00
|
|
|
{ return wxEVT_DIRPICKER_CHANGED; }
|
2006-06-03 15:20:23 -04:00
|
|
|
|
|
|
|
protected:
|
2006-06-02 08:00:30 -04:00
|
|
|
void UpdateDialogPath(wxDialog *p)
|
|
|
|
{ wxStaticCast(p, wxDirDialog)->SetPath(m_path); }
|
|
|
|
void UpdatePathFromDialog(wxDialog *p)
|
|
|
|
{ m_path = wxStaticCast(p, wxDirDialog)->GetPath(); }
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxGenericDirButton)
|
|
|
|
};
|
|
|
|
|
2013-04-25 06:11:03 -04:00
|
|
|
// old wxEVT_COMMAND_* constants
|
|
|
|
//#define wxEVT_COMMAND_DIRPICKER_CHANGED wxEVT_DIRPICKER_CHANGED
|
|
|
|
//#define wxEVT_COMMAND_FILEPICKER_CHANGED wxEVT_FILEPICKER_CHANGED
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
#endif // _WX_FILEDIRPICKER_H_
|