wxWidgets: wxFileDialogCustomizeHook Class Reference

| Version: 3.2.6

Public Member Functions | List of all members
wxFileDialogCustomizeHook Class Referenceabstract
Class List by Category » Common Dialogs

`#include <wx/filedlgcustomize.h>`

## Detailed Description

Base class for customization hooks used with wxFileDialog.

wxFileDialogCustomizeHook is an abstract base class, i.e. in order to use a concrete class inheriting from it and implementing its pure virtual AddCustomControls() function must be defined. Then an object of this class should be passed to wxFileDialog::SetCustomizeHook(), which will result in its AddCustomControls() being called before the dialog is shown, UpdateCustomControls() being called whenever something changes in the dialog while it is shown and, finally, TransferDataFromCustomControls() being called when the user accepts their choice in the dialog.

Putting all this together, here is an example of customizing the file dialog using this class:

class EncryptHook : public wxFileDialogCustomizeHook
{
public:
// Override to add custom controls using the provided customizer object.
void AddCustomControls(wxFileDialogCustomize& customizer) override
{
// Suppose we can encrypt files when saving them.
m_checkbox = customizer.AddCheckBox("Encrypt");
// While m_checkbox is not a wxCheckBox, it looks almost like one
// and, in particular, we can bind to custom control events as usual.
m_checkbox->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& event) {
// We can also call wxWindow-like functions on them.
m_button->Enable(event.IsChecked());
});
// The encryption parameters can be edited in a dedicated dialog.
m_button = customizer.AddButton("Parameters...");
m_button->Bind(wxEVT_BUTTON, [](wxCommandEvent&) {
... show the encryption parameters dialog here ...
});
}
// Override to save the values of the custom controls.
void TransferDataFromCustomControls() override
{
// Save the checkbox value, as we won't be able to use it any more
// once this function returns.
m_encrypt = m_checkbox->GetValue();
}
// Just a simple accessor to get the results.
bool Encrypt() const { return m_encrypt; }
private:
wxFileDialogButton* m_button;
wxFileDialogCheckBox* m_checkbox;
bool m_encrypt = false;
};
void SomeFunc()
{
wxFileDialog dialog(NULL, "Save document", wxString(), "file.my",
"My files (*.my)|*.my",
wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
// This object may be destroyed before the dialog, but must remain
// alive until ShowModal() returns.
EncryptHook customizeHook;
dialog.SetCustomizeHook(customHook);
if ( dialog.ShowModal() == wxID_OK )
{
if ( customizeHook.Encrypt() )
... save with encryption ...
else
... save without encryption ...
}
}
wxCommandEvent
This event class contains information about command events, which originate from a variety of simple ...
Definition: event.h:2042
wxCommandEvent::IsChecked
bool IsChecked() const
This method can be used with checkbox and menu events: for the checkboxes, the method returns true fo...
wxEvtHandler::Bind
void Bind(const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
Binds the given function, functor or method dynamically with the event.
wxFileDialogButton
Represents a custom button inside wxFileDialog.
Definition: filedlgcustomize.h:60
wxFileDialogCheckBox
Represents a custom checkbox inside wxFileDialog.
Definition: filedlgcustomize.h:77
wxFileDialogCustomizeHook
Base class for customization hooks used with wxFileDialog.
Definition: filedlgcustomize.h:354
wxFileDialogCustomizeHook::AddCustomControls
virtual void AddCustomControls(wxFileDialogCustomize &customizer)=0
Must be overridden to add custom controls to the dialog using the provided customizer object.
wxFileDialogCustomizeHook::TransferDataFromCustomControls
virtual void TransferDataFromCustomControls()
Should typically be overridden to save the values of the custom controls when the dialog is accepted.
wxFileDialogCustomize
Used with wxFileDialogCustomizeHook to add custom controls to wxFileDialog.
Definition: filedlgcustomize.h:207
wxFileDialogCustomize::AddButton
wxFileDialogButton * AddButton(const wxString &label)
Add a button with the specified label.
wxFileDialogCustomize::AddCheckBox
wxFileDialogCheckBox * AddCheckBox(const wxString &label)
Add a checkbox with the specified label.
wxFileDialog
This class represents the file chooser dialog.
Definition: filedlg.h:200
wxString
String class for passing textual data to or receiving it from wxWidgets.
Definition: string.h:315
wxID_OK
@ wxID_OK
Standard button and menu IDs.
Definition: defs.h:664
wxFD_OVERWRITE_PROMPT
@ wxFD_OVERWRITE_PROMPT
Definition: filedlg.h:12
wxFD_SAVE
@ wxFD_SAVE
Definition: filedlg.h:11
wxEVT_BUTTON
wxEventType wxEVT_BUTTON
Definition: event.h:5143
wxEVT_CHECKBOX
wxEventType wxEVT_CHECKBOX
Definition: event.h:5144

##

Library: wxCore
Category: Common Dialogs

See also
  wxFileDialog

Since
  3.1.7

## Public Member Functions
virtual void | AddCustomControls (wxFileDialogCustomize &customizer)=0
| Must be overridden to add custom controls to the dialog using the provided customizer object. More...
virtual void | UpdateCustomControls ()
| May be overridden to update the custom controls whenever something changes in the dialog. More...
virtual void | TransferDataFromCustomControls ()
| Should typically be overridden to save the values of the custom controls when the dialog is accepted. More...

## Member Function Documentation

## ◆ AddCustomControls()

virtual void wxFileDialogCustomizeHook::AddCustomControls | ( | wxFileDialogCustomize & | customizer | ) |
| pure virtual

Must be overridden to add custom controls to the dialog using the provided customizer object.

Call wxFileDialogCustomize functions to add controls and possibly bind to their events.

Note that there is no possibility to define the custom controls layout, they will appear more or less consecutively, but the exact layout is determined by the current platform.

## ◆ TransferDataFromCustomControls()

virtual void wxFileDialogCustomizeHook::TransferDataFromCustomControls | ( |  | ) |
| virtual

Should typically be overridden to save the values of the custom controls when the dialog is accepted.

Custom controls are destroyed and cannot be used any longer once wxFileDialog::ShowModal() returns, so their values must be retrieved in this function, which is called just before this happens.

This function is not called if the user cancels the dialog.

Base class version does nothing.

## ◆ UpdateCustomControls()

virtual void wxFileDialogCustomizeHook::UpdateCustomControls | ( |  | ) |
| virtual

May be overridden to update the custom controls whenever something changes in the dialog.

This function is called when the user selects a file, changes the directory or changes the current filter in the dialog, for example. It can be used to update the custom controls state depending on the currently selected file, for example.

Note that it is not necessarily called when the value of a custom control changes.

Base class version does nothing.