// used, a textctrl next to it.
// ----------------------------------------------------------------------------
-#define wxCLRP_USE_TEXTCTRL wxPB_USE_TEXTCTRL
+#define wxCLRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
#define wxCLRP_DEFAULT_STYLE 0
class WXDLLIMPEXP_CORE wxColourPickerCtrl : public wxPickerBase
virtual ~wxFileDirPickerWidgetBase() { }
wxString GetPath() const { return m_path; }
- void SetPath(const wxString &str) { m_path=str; UpdateDialogPath(); }
+ virtual void SetPath(const wxString &str) { m_path=str; }
protected:
- virtual void UpdateDialogPath() = 0;
- virtual void UpdatePathFromDialog() = 0;
+ virtual void UpdateDialogPath(wxDialog *) = 0;
+ virtual void UpdatePathFromDialog(wxDialog *) = 0;
wxString m_path;
};
// used, a textctrl next to it.
// ----------------------------------------------------------------------------
-#define wxFLP_USE_TEXTCTRL wxPB_USE_TEXTCTRL
+#define wxFLP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
#ifdef __WXGTK__
// GTK apps usually don't have a textctrl next to the picker
- #define wxFLP_DEFAULT_STYLE wxFLP_OPEN
+ #define wxFLP_DEFAULT_STYLE (wxFLP_OPEN)
#else
- #define wxFLP_DEFAULT_STYLE wxFLP_USE_TEXTCTRL|wxFLP_OPEN
+ #define wxFLP_DEFAULT_STYLE (wxFLP_USE_TEXTCTRL|wxFLP_OPEN)
#endif
class WXDLLIMPEXP_CORE wxFilePickerCtrl : public wxFileDirPickerCtrlBase
// (see wxDIRP_USE_TEXTCTRL) next to it.
// ----------------------------------------------------------------------------
-#define wxDIRP_USE_TEXTCTRL wxPB_USE_TEXTCTRL
+#define wxDIRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
#ifdef __WXGTK__
// GTK apps usually don't have a textctrl next to the picker
#define wxDIRP_DEFAULT_STYLE 0
#else
- #define wxDIRP_DEFAULT_STYLE wxDIRP_USE_TEXTCTRL
+ #define wxDIRP_DEFAULT_STYLE (wxDIRP_USE_TEXTCTRL)
#endif
class WXDLLIMPEXP_CORE wxDirPickerCtrl : public wxFileDirPickerCtrlBase
// wxFontPickerCtrl specific flags
// ----------------------------------------------------------------------------
-#define wxFNTP_USE_TEXTCTRL wxPB_USE_TEXTCTRL
-#define wxFNTP_DEFAULT_STYLE wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL
+#define wxFNTP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
+#define wxFNTP_DEFAULT_STYLE (wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL)
// not a style but rather the default value of the maximum pointsize allowed
#define wxFNTP_MAXPOINT_SIZE 100
#define wxCLRBTN_SHOW_LABEL 100
// the default style
-#define wxCLRBTN_DEFAULT_STYLE wxCLRBTN_SHOW_LABEL
+#define wxCLRBTN_DEFAULT_STYLE (wxCLRBTN_SHOW_LABEL)
class WXDLLIMPEXP_CORE wxGenericColourButton : public wxButton,
public wxFileDirPickerWidgetBase
{
public:
- wxGenericFileDirButton() { m_dialog = NULL; }
+ wxGenericFileDirButton() { }
wxGenericFileDirButton(wxWindow *parent,
wxWindowID id,
const wxString& label = wxFilePickerWidgetLabel,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxFilePickerWidgetNameStr)
{
- m_dialog = NULL;
Create(parent, id, label, path, message, wildcard,
pos, size, style, validator, name);
}
public: // overrideable
- virtual bool CreateDialog(const wxString &message,
- const wxString &wildcard) = 0;
+ virtual wxDialog *CreateDialog() = 0;
- // NULL is because of a problem with destruction order in both generic & GTK code
virtual wxWindow *GetDialogParent()
- { return NULL; }
+ { return GetParent(); }
virtual wxEventType GetEventType() const = 0;
public:
- bool Destroy()
- {
- if (m_dialog) m_dialog->Destroy();
- return wxButton::Destroy();
- }
-
bool Create(wxWindow *parent, wxWindowID id,
const wxString& label = wxFilePickerWidgetLabel,
const wxString& path = wxEmptyString,
// event handler for the click
void OnButtonClick(wxCommandEvent &);
- wxDialog *m_dialog;
+protected:
+ wxString m_message, m_wildcard;
};
// wxGenericFileButton: a button which brings up a wxFileDialog
//-----------------------------------------------------------------------------
-#define wxFILEBTN_DEFAULT_STYLE wxFLP_OPEN
+#define wxFILEBTN_DEFAULT_STYLE (wxFLP_OPEN)
class WXDLLIMPEXP_CORE wxGenericFileButton : public wxGenericFileDirButton
{
return filedlgstyle;
}
- virtual bool CreateDialog(const wxString &message, const wxString &wildcard)
+ virtual wxDialog *CreateDialog()
{
- m_dialog = new wxFileDialog(GetDialogParent(), message,
+ wxFileDialog *p = new wxFileDialog(GetDialogParent(), m_message,
wxEmptyString, wxEmptyString,
- wildcard, GetDialogStyle());
+ m_wildcard, GetDialogStyle());
// this sets both the default folder and the default file of the dialog
- GetDialog()->SetPath(m_path);
-
- return true;
+ p->SetPath(m_path);
+ return p;
}
- wxFileDialog *GetDialog()
- { return wxStaticCast(m_dialog, wxFileDialog); }
- void UpdateDialogPath()
- { GetDialog()->SetPath(m_path); }
- void UpdatePathFromDialog()
- { m_path = GetDialog()->GetPath(); }
+ void UpdateDialogPath(wxDialog *p)
+ { wxStaticCast(p, wxFileDialog)->SetPath(m_path); }
+ void UpdatePathFromDialog(wxDialog *p)
+ { m_path = wxStaticCast(p, wxFileDialog)->GetPath(); }
wxEventType GetEventType() const
{ return wxEVT_COMMAND_FILEPICKER_CHANGED; }
return dirdlgstyle;
}
- virtual bool CreateDialog(const wxString &message, const wxString &WXUNUSED(wildcard))
+ virtual wxDialog *CreateDialog()
{
- m_dialog = new wxDirDialog(GetDialogParent(), message, m_path,
+ return new wxDirDialog(GetDialogParent(), m_message, m_path,
GetDialogStyle());
- return true;
}
- wxDirDialog *GetDialog()
- { return wxStaticCast(m_dialog, wxDirDialog); }
- void UpdateDialogPath()
- { GetDialog()->SetPath(m_path); }
- void UpdatePathFromDialog()
- { m_path = GetDialog()->GetPath(); }
+ void UpdateDialogPath(wxDialog *p)
+ { wxStaticCast(p, wxDirDialog)->SetPath(m_path); }
+ void UpdatePathFromDialog(wxDialog *p)
+ { m_path = wxStaticCast(p, wxDirDialog)->GetPath(); }
wxEventType GetEventType() const
{ return wxEVT_COMMAND_DIRPICKER_CHANGED; }
// that GTK+ < 2.4
#include "wx/generic/filepickerg.h"
+
+
+//-----------------------------------------------------------------------------
+// wxFileButton and wxDirButton shared code
+// (cannot be a base class since they need to derive from wxGenericFileButton
+// and from wxGenericDirButton classes !)
+//-----------------------------------------------------------------------------
+
+#define FILEDIRBTN_OVERRIDES \
+ /* NULL is because of a problem with destruction order which happens */ \
+ /* if we pass GetParent(): in fact, this GTK native implementation */ \
+ /* needs to create the dialog in ::Create() and not for each user request */ \
+ /* in response to the user click as the generic implementation does */ \
+ virtual wxWindow *GetDialogParent() \
+ { \
+ return NULL; \
+ } \
+ \
+ virtual bool Destroy() \
+ { \
+ m_dialog->Destroy(); \
+ return wxButton::Destroy(); \
+ } \
+ \
+ virtual void SetPath(const wxString &str) \
+ { \
+ m_path=str; \
+ UpdateDialogPath(m_dialog); \
+ }
+
+
//-----------------------------------------------------------------------------
// wxFileButton
//-----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxFileButton : public wxGenericFileButton
{
public:
- wxFileButton() {}
+ wxFileButton() { m_dialog = NULL; }
wxFileButton(wxWindow *parent,
wxWindowID id,
const wxString& label = wxFilePickerWidgetLabel,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxFilePickerWidgetNameStr)
{
+ m_dialog = NULL;
Create(parent, id, label, path, message, wildcard,
pos, size, style, validator, name);
}
- virtual ~wxFileButton() ;
+ virtual ~wxFileButton();
public: // overrides
void OnDialogOK(wxCommandEvent &);
+public: // some overrides
+
// GtkFileChooserButton does not support GTK_FILE_CHOOSER_ACTION_SAVE
- // so we replace it with GTK_FILE_CHOOSER_ACTION_OPEN
- long GetDialogStyle() const
+ // so we replace it with GTK_FILE_CHOOSER_ACTION_OPEN; since wxFD_SAVE
+ // is not supported, wxFD_OVERWRITE_PROMPT isn't too...
+ virtual long GetDialogStyle() const
{
- return (wxGenericFileButton::GetDialogStyle() & ~wxFD_SAVE) | wxFD_OPEN;
+ return (wxGenericFileButton::GetDialogStyle() &
+ ~(wxFD_SAVE | wxFD_OVERWRITE_PROMPT)) | wxFD_OPEN;
}
+ // see macro defined above
+ FILEDIRBTN_OVERRIDES
+
+protected:
+ wxDialog *m_dialog;
private:
DECLARE_DYNAMIC_CLASS(wxFileButton)
class WXDLLIMPEXP_CORE wxDirButton : public wxGenericDirButton
{
public:
- wxDirButton() {}
+ wxDirButton() { m_dialog = NULL;}
wxDirButton(wxWindow *parent,
wxWindowID id,
const wxString& label = wxFilePickerWidgetLabel,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxFilePickerWidgetNameStr)
{
+ m_dialog = NULL;
Create(parent, id, label, path, message, wxEmptyString,
pos, size, style, validator, name);
}
return (wxGenericDirButton::GetDialogStyle() | wxDD_DIR_MUST_EXIST);
}
+ // see macro defined above
+ FILEDIRBTN_OVERRIDES
+
+protected:
+ wxDialog *m_dialog;
+
private:
DECLARE_DYNAMIC_CLASS(wxDirButton)
};
+#undef FILEDIRBTN_OVERRIDES
+
#endif // _WX_GTK_FILEPICKER_H_
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/log.h"
+ #include "wx/radiobox.h"
#endif
#include "wx/artprov.h"
// constants
// ----------------------------------------------------------------------------
+enum
+{
+ FilePickerMode_Open = 0,
+ FilePickerMode_Save
+};
+
// control ids
enum
{
PickerWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist);
virtual ~PickerWidgetsPage(){};
- virtual wxControl *GetWidget() const { /*return m_fontPicker;*/ return NULL; }
+ virtual wxControl *GetWidget() const { return m_filePicker; }
virtual void RecreateWidget() { RecreateAllPickers(); }
protected:
// get the initial style for the picker of the given kind
long GetPickerStyle(PickerKind kind);
+ // update filepicker radiobox
+ void UpdateFilePickerMode();
// the pickers and the relative event handlers
#if wxUSE_COLOURPICKERCTRL
*m_chkFileOverwritePrompt,
*m_chkFileMustExist,
*m_chkFileChangeDir;
+ wxRadioBox *m_radioFilePickerMode;
wxCheckBox *m_chkDirTextCtrl,
*m_chkDirChangeDir,
#endif
EVT_CHECKBOX(wxID_ANY, PickerWidgetsPage::OnCheckBox)
+ EVT_RADIOBOX(wxID_ANY, PickerWidgetsPage::OnCheckBox)
END_EVENT_TABLE()
// ============================================================================
#endif // wxUSE_COLOURPICKERCTRL
#if wxUSE_FILEPICKERCTRL
+ static const wxString mode[] = { _T("open"), _T("save") };
+ m_radioFilePickerMode = new wxRadioBox(this, wxID_ANY, _T("wxFilePicker mode"),
+ wxDefaultPosition, wxDefaultSize,
+ WXSIZEOF(mode), mode);
+ boxleft->Add(m_radioFilePickerMode, 0, wxALL|wxGROW, 5);
+
wxStaticBoxSizer *filebox = new wxStaticBoxSizer(wxVERTICAL, this, _T("&FilePicker style"));
m_chkFileTextCtrl = CreateCheckBoxAndAddToSizer(filebox, _T("With textctrl"), false);
m_chkFileOverwritePrompt = CreateCheckBoxAndAddToSizer(filebox, _T("Overwrite prompt"), false);
if ( m_chkFileChangeDir->GetValue() )
style |= wxFLP_CHANGE_DIR;
+ if (m_radioFilePickerMode->GetSelection() == FilePickerMode_Open)
+ style |= wxFLP_OPEN;
+ else
+ style |= wxFLP_SAVE;
+
break;
#endif // wxUSE_FILEPICKERCTRL
#endif
#if wxUSE_FILEPICKERCTRL
+ m_radioFilePickerMode->SetSelection((wxFLP_DEFAULT_STYLE & wxFLP_OPEN) ?
+ FilePickerMode_Open : FilePickerMode_Save);
m_chkFileTextCtrl->SetValue((wxFLP_DEFAULT_STYLE & wxFLP_USE_TEXTCTRL) != 0);
m_chkFileOverwritePrompt->SetValue((wxFLP_DEFAULT_STYLE & wxFLP_OVERWRITE_PROMPT) != 0);
m_chkFileMustExist->SetValue((wxFLP_DEFAULT_STYLE & wxFLP_FILE_MUST_EXIST) != 0);
m_chkFileChangeDir->SetValue((wxFLP_DEFAULT_STYLE & wxFLP_CHANGE_DIR) != 0);
+
+ UpdateFilePickerMode();
#endif
#if wxUSE_DIRPICKERCTRL
#endif
}
+void PickerWidgetsPage::UpdateFilePickerMode()
+{
+ switch (m_radioFilePickerMode->GetSelection())
+ {
+ case FilePickerMode_Open:
+ m_chkFileOverwritePrompt->SetValue(false);
+ m_chkFileOverwritePrompt->Disable();
+ m_chkFileMustExist->Enable();
+ break;
+ case FilePickerMode_Save:
+ m_chkFileMustExist->SetValue(false);
+ m_chkFileMustExist->Disable();
+ m_chkFileOverwritePrompt->Enable();
+ break;
+ }
+}
+
// ----------------------------------------------------------------------------
// event handlers
event.GetEventObject() == m_chkFontDescAsLabel ||
event.GetEventObject() == m_chkFontUseFontForLabel)
RecreatePicker(Picker_Font);
+
+ if (event.GetEventObject() == m_radioFilePickerMode)
+ {
+ UpdateFilePickerMode();
+ RecreatePicker(Picker_File);
+ }
}
#endif // wxUSE_COLOURPICKERCTRL || wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL || wxUSE_FONTPICKERCTRL
style, validator, name))
return false;
+ if (!HasFlag(wxFLP_OPEN) && !HasFlag(wxFLP_SAVE))
+ m_windowStyle |= wxFLP_OPEN; // wxFD_OPEN is the default
+
+ // check that the styles are not contradictory
+ wxASSERT_MSG( !(HasFlag(wxFLP_SAVE) && HasFlag(wxFLP_OPEN)),
+ _T("can't specify both wxFLP_SAVE and wxFLP_OPEN at once") );
+
+ wxASSERT_MSG( !HasFlag(wxFLP_SAVE) || !HasFlag(wxFLP_FILE_MUST_EXIST),
+ _T("wxFLP_FILE_MUST_EXIST can't be used with wxFLP_SAVE" ) );
+
+ wxASSERT_MSG( !HasFlag(wxFLP_OPEN) || !HasFlag(wxFLP_OVERWRITE_PROMPT),
+ _T("wxFLP_OVERWRITE_PROMPT can't be used with wxFLP_OPEN") );
+
// create a wxFilePickerWidget or a wxDirPickerWidget...
if (!CreatePicker(this, path, message, wildcard))
return false;
m_windowStyle = style;
m_filterIndex = 0;
+ if (!HasFlag(wxFD_OPEN) && !HasFlag(wxFD_SAVE))
+ m_windowStyle |= wxFD_OPEN; // wxFD_OPEN is the default
+
// check that the styles are not contradictory
wxASSERT_MSG( !(HasFlag(wxFD_SAVE) && HasFlag(wxFD_OPEN)),
_T("can't specify both wxFD_SAVE and wxFD_OPEN at once") );
// create the dialog associated with this button
m_path = path;
- return CreateDialog(message, wildcard);
+ m_message = message;
+ m_wildcard = wildcard;
+
+ return true;
}
void wxGenericFileDirButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev))
{
- if (m_dialog->ShowModal() == wxID_OK)
+ wxDialog *p = CreateDialog();
+ if (p->ShowModal() == wxID_OK)
{
- // save the path
- UpdatePathFromDialog();
+ // save updated path in m_path
+ UpdatePathFromDialog(p);
// fire an event
wxFileDirPickerEvent event(GetEventType(), this, GetId(), m_path);
GetEventHandler()->ProcessEvent(event);
}
+
+ wxDELETE(p);
}
#endif // wxUSE_FILEPICKERCTRL || wxUSE_DIRPICKERCTRL
}
// create the dialog associated with this button
+ // NB: unlike generic implementation, native GTK implementation needs to create
+ // the filedialog here as it needs to use gtk_file_chooser_button_new_with_dialog()
SetWindowStyle(style);
m_path = path;
- if (!CreateDialog(message, wildcard))
+ m_message = message;
+ m_wildcard = wildcard;
+ if ((m_dialog = CreateDialog()) == NULL)
return false;
// little trick used to avoid problems when there are other GTK windows 'grabbed':
if (ev.GetId() == wxID_OK)
{
// ...update our path
- UpdatePathFromDialog();
+ UpdatePathFromDialog(m_dialog);
// ...and fire an event
wxFileDirPickerEvent event(wxEVT_COMMAND_FILEPICKER_CHANGED, this, GetId(), m_path);
// create the dialog associated with this button
SetWindowStyle(style);
- m_path = path;
- if (!CreateDialog(message, wildcard))
+ m_message = message;
+ m_wildcard = wildcard;
+ if ((m_dialog = CreateDialog()) == NULL)
return false;
// little trick used to avoid problems when there are other GTK windows 'grabbed':
#ifdef GTK_IS_FILE_CHOOSER_BUTTON
else if (GTK_IS_FILE_CHOOSER_BUTTON(m_widget))
{
+ // If we connect to the "size_request" signal of a GtkFileChooserButton
+ // then that control won't be sized properly when placed inside sizers
+ // (this can be tested removing this elseif and running XRC or WIDGETS samples)
// FIXME: what should be done here ?
}
#endif
wildCard, style, pos, sz, name)
{
- if ( ( m_windowStyle & wxFD_MULTIPLE ) && ( m_windowStyle & wxFD_SAVE ) )
- m_windowStyle &= ~wxFD_MULTIPLE;
+ // NB: all style checks are done by wxFileDialogBase::Create
m_bMovedWindow = false;
:wxFileDialogBase(pParent, rsMessage, rsDefaultDir, rsDefaultFileName, rsWildCard, lStyle, rPos, sz, name)
{
- if ((m_windowStyle & wxFD_MULTIPLE) && (m_windowStyle & wxFD_SAVE))
- m_windowStyle &= ~wxFD_MULTIPLE;
+ // NB: all style checks are done by wxFileDialogBase::Create
m_filterIndex = 1;
} // end of wxFileDialog::wxFileDialog