|
|
|
@ -34,6 +34,8 @@ |
|
|
|
#include <html_messagebox.h>
|
|
|
|
#include <dialog_exit_base.h>
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
|
|
|
|
class DIALOG_EXIT: public DIALOG_EXIT_BASE |
|
|
|
{ |
|
|
|
@ -175,3 +177,156 @@ int YesNoCancelDialog( wxWindow* aParent, |
|
|
|
|
|
|
|
return dlg.ShowModal(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int SelectSingleOption( wxWindow* aParent, const wxString& aTitle, const wxString& aMessage, const wxArrayString& aOptions ) |
|
|
|
{ |
|
|
|
int ret = -1; |
|
|
|
wxDialog* dlg = new DIALOG_SHIM( aParent, wxID_ANY, aTitle ); |
|
|
|
dlg->SetSizeHints( wxDefaultSize, wxDefaultSize ); |
|
|
|
|
|
|
|
wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL ); |
|
|
|
|
|
|
|
if( !aMessage.IsEmpty() ) |
|
|
|
boxSizer->Add( new wxStaticText( dlg, wxID_ANY, aMessage ), 0, wxEXPAND | wxALL, 5 ); |
|
|
|
|
|
|
|
std::vector<wxRadioButton*> radioButtons; |
|
|
|
radioButtons.reserve( aOptions.Count() ); |
|
|
|
|
|
|
|
for( const wxString& option : aOptions ) |
|
|
|
{ |
|
|
|
radioButtons.emplace_back( new wxRadioButton( dlg, wxID_ANY, _( option ) ) ); |
|
|
|
boxSizer->Add( radioButtons.back(), 0, wxEXPAND | wxALL, 5 ); |
|
|
|
} |
|
|
|
|
|
|
|
wxStdDialogButtonSizer* m_sdboxSizer = new wxStdDialogButtonSizer(); |
|
|
|
m_sdboxSizer->AddButton( new wxButton( dlg, wxID_OK ) ); |
|
|
|
m_sdboxSizer->AddButton( new wxButton( dlg, wxID_CANCEL ) ); |
|
|
|
m_sdboxSizer->Realize(); |
|
|
|
boxSizer->Add( m_sdboxSizer, 1, wxEXPAND | wxALL, 5 ); |
|
|
|
|
|
|
|
dlg->SetSizer( boxSizer ); |
|
|
|
dlg->Layout(); |
|
|
|
boxSizer->Fit( dlg ); |
|
|
|
dlg->Centre( wxBOTH ); |
|
|
|
|
|
|
|
if( dlg->ShowModal() == wxID_OK ) |
|
|
|
{ |
|
|
|
for( int i = 0; i < radioButtons.size(); ++i ) |
|
|
|
{ |
|
|
|
if( radioButtons[i]->GetValue() ) |
|
|
|
{ |
|
|
|
ret = i; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
ret = -1; |
|
|
|
} |
|
|
|
|
|
|
|
dlg->Destroy(); |
|
|
|
|
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class DIALOG_MULTI_OPTIONS : public DIALOG_SHIM |
|
|
|
{ |
|
|
|
public: |
|
|
|
DIALOG_MULTI_OPTIONS( wxWindow* aParent, const wxString& aTitle, const wxString& aMessage, |
|
|
|
const wxArrayString& aOptions ) |
|
|
|
: DIALOG_SHIM( aParent, wxID_ANY, aTitle ) |
|
|
|
{ |
|
|
|
SetSizeHints( wxDefaultSize, wxDefaultSize ); |
|
|
|
|
|
|
|
wxBoxSizer* boxSizer = new wxBoxSizer( wxVERTICAL ); |
|
|
|
|
|
|
|
if( !aMessage.IsEmpty() ) |
|
|
|
boxSizer->Add( new wxStaticText( this, wxID_ANY, aMessage ), 0, wxEXPAND | wxALL, 5 ); |
|
|
|
|
|
|
|
m_checkBoxes.reserve( aOptions.Count() ); |
|
|
|
|
|
|
|
for( const wxString& option : aOptions ) |
|
|
|
{ |
|
|
|
m_checkBoxes.emplace_back( new wxCheckBox( this, wxID_ANY, _( option ) ) ); |
|
|
|
boxSizer->Add( m_checkBoxes.back(), 0, wxEXPAND | wxALL, 5 ); |
|
|
|
} |
|
|
|
|
|
|
|
wxBoxSizer* btnSizer = new wxBoxSizer( wxHORIZONTAL ); |
|
|
|
wxButton* selectAll = new wxButton( this, wxID_ANY, "Select All" ); |
|
|
|
btnSizer->Add( selectAll, 0, wxEXPAND | wxALL, 5 ); |
|
|
|
wxButton* unselectAll = new wxButton( this, wxID_ANY, "Unselect All" ); |
|
|
|
btnSizer->Add( unselectAll, 0, wxEXPAND | wxALL, 5 ); |
|
|
|
boxSizer->Add( btnSizer, 0, wxEXPAND | wxALL, 5 ); |
|
|
|
|
|
|
|
wxStdDialogButtonSizer* m_sdboxSizer = new wxStdDialogButtonSizer(); |
|
|
|
m_sdboxSizer->AddButton( new wxButton( this, wxID_OK ) ); |
|
|
|
m_sdboxSizer->AddButton( new wxButton( this, wxID_CANCEL ) ); |
|
|
|
m_sdboxSizer->Realize(); |
|
|
|
boxSizer->Add( m_sdboxSizer, 0, wxEXPAND | wxALL, 5 ); |
|
|
|
|
|
|
|
SetSizer( boxSizer ); |
|
|
|
Layout(); |
|
|
|
boxSizer->Fit( this ); |
|
|
|
Centre( wxBOTH ); |
|
|
|
|
|
|
|
selectAll->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_MULTI_OPTIONS::selectAll, this ); |
|
|
|
unselectAll->Bind( wxEVT_COMMAND_BUTTON_CLICKED, &DIALOG_MULTI_OPTIONS::unselectAll, this ); |
|
|
|
} |
|
|
|
|
|
|
|
std::vector<int> GetSelection() const |
|
|
|
{ |
|
|
|
std::vector<int> ret; |
|
|
|
|
|
|
|
for( int i = 0; i < m_checkBoxes.size(); ++i ) |
|
|
|
{ |
|
|
|
if( m_checkBoxes[i]->IsChecked() ) |
|
|
|
ret.push_back( i ); |
|
|
|
} |
|
|
|
|
|
|
|
return ret; |
|
|
|
} |
|
|
|
|
|
|
|
void SetCheckboxes( bool aValue ) |
|
|
|
{ |
|
|
|
for( auto& cb : m_checkBoxes ) |
|
|
|
cb->SetValue( aValue ); |
|
|
|
} |
|
|
|
|
|
|
|
protected: |
|
|
|
std::vector<wxCheckBox*> m_checkBoxes; |
|
|
|
|
|
|
|
void selectAll( wxCommandEvent& aEvent ) |
|
|
|
{ |
|
|
|
SetCheckboxes( true ); |
|
|
|
} |
|
|
|
|
|
|
|
void unselectAll( wxCommandEvent& aEvent ) |
|
|
|
{ |
|
|
|
SetCheckboxes( false ); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
std::pair<bool, std::vector<int>> SelectMultipleOptions( wxWindow* aParent, const wxString& aTitle, |
|
|
|
const wxString& aMessage, const wxArrayString& aOptions, bool aDefaultState ) |
|
|
|
{ |
|
|
|
std::vector<int> ret; |
|
|
|
bool clickedOk; |
|
|
|
DIALOG_MULTI_OPTIONS dlg( aParent, aTitle, aMessage, aOptions ); |
|
|
|
dlg.SetCheckboxes( aDefaultState ); |
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK ) |
|
|
|
{ |
|
|
|
ret = dlg.GetSelection(); |
|
|
|
clickedOk = true; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
clickedOk = false; |
|
|
|
} |
|
|
|
|
|
|
|
return std::make_pair( clickedOk, ret ); |
|
|
|
} |