FROM 0 TO 01
FROM 1 TO 10
So far, I have created a dialog with two couples of one wxSpinCtrl( for setting the FROM string) and wxTextCtrl (for filling TO string). But I dont know how to store the values into a map std::map<std::string,std::string> rule;
In the console application I used a for cycle with rule.insert(make_pair(FROM,TO));
Could you please help me?
Another problem is adding additional row after clicking on Add Rule button, which doesn't work properly. I dont know how to place additional wxSpinCtrl and wxTextCtrl into the boxsizer.
Code: Select all
ParametresDialog::ParametresDialog( wxWindow* parent,wxWindowID id ,const wxString& caption,const wxPoint& pos,
const wxSize& size,long style):wxDialog(parent,id, caption, pos, size, style)
{
Init();
Create(parent, id,caption, pos, size, style);
}
void ParametresDialog::SetDialogValidators()
{
FindWindow(ID_TO)->SetValidator( wxTextValidator(wxFILTER_INCLUDE_LIST, & To));
FindWindow(ID_FROM)->SetValidator(wxGenericValidator(& From));
}
void ParametresDialog::Init()
{
From = wxEmptyString;
To = wxEmptyString;
}
bool ParametresDialog::Create( wxWindow* parent,wxWindowID id ,const wxString& caption,const wxPoint& pos,
const wxSize& size,long style)
{
if (!wxDialog::Create( parent, id, caption, pos, size, style ))
return false;
CreateControls();
SetDialogValidators();
GetSizer()->Fit(this);
GetSizer()->SetSizeHints(this);
Centre();
return true;
}
void ParametresDialog::AddRuleControls(wxCommandEvent& event)
{
wxBoxSizer* RuleBoxEVT = new wxBoxSizer(wxHORIZONTAL);
//boxSizer.Add(RuleBoxEVT, 0, wxGROW|wxALL, 5);
wxStaticText* FromLabelEVT = new wxStaticText ( this, wxID_STATIC,
_("The letter"), wxDefaultPosition, wxDefaultSize, 0 );
RuleBoxEVT->Add(FromLabelEVT, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
wxSpinCtrl* FromSpinEVT = new wxSpinCtrl ( this, ID_FROM,wxEmptyString,
wxDefaultPosition, wxSize(60, -1),
wxSP_ARROW_KEYS, 0, 9);
RuleBoxEVT->Add(FromSpinEVT, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
wxStaticText* ToLabelEVT = new wxStaticText ( this, wxID_STATIC,_("overwrite to "),
wxDefaultPosition, wxDefaultSize, 0 );
RuleBoxEVT->Add(ToLabelEVT, 0, wxALIGN_LEFT|wxALL, 5);
wxTextCtrl* ToCtrlEVT = new wxTextCtrl ( this, ID_TO, wxEmptyString,
wxDefaultPosition, wxDefaultSize, 0 );
RuleBoxEVT->Add(ToCtrlEVT, 0, wxGROW|wxALL, 5);
wxButton* AddRuleEVT = new wxButton ( this, ID_ADDRULE,
_("&Add Rule"), wxDefaultPosition, wxDefaultSize, 0 );
RuleBoxEVT->Add( AddRuleEVT, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
}
void ParametresDialog::CreateControls()
{
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); // lay out its children vertically
this->SetSizer(topSizer); //wxWindow::SetSizer(wxSizer) => topSizer is the top level sizer of this window
wxBoxSizer* boxSizer = new wxBoxSizer(wxVERTICAL); //create boxSizer
topSizer->Add(boxSizer, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
boxSizer->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
wxBoxSizer* RuleBox1 = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(RuleBox1, 0, wxGROW|wxALL, 5);//after resize grow the window and border
wxStaticText* FromLabel = new wxStaticText ( this, wxID_STATIC,
_("The letter"), wxDefaultPosition, wxDefaultSize, 0 );
RuleBox1->Add(FromLabel, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
wxSpinCtrl* FromSpin1 = new wxSpinCtrl ( this, ID_FROM,wxEmptyString,
wxDefaultPosition, wxSize(60, -1),
wxSP_ARROW_KEYS, 0, 9);
RuleBox1->Add(FromSpin1, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
wxStaticText* ToLabel = new wxStaticText ( this, wxID_STATIC,_("overwrite to "),
wxDefaultPosition, wxDefaultSize, 0 );
RuleBox1->Add(ToLabel, 0, wxALIGN_LEFT|wxALL, 5);
wxTextCtrl* ToCtrl1 = new wxTextCtrl ( this, ID_TO, wxEmptyString,
wxDefaultPosition, wxDefaultSize, 0 );
RuleBox1->Add(ToCtrl1, 0, wxGROW|wxALL, 5);
wxBoxSizer* RuleBox2 = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(RuleBox2, 0, wxGROW|wxALL, 5);
wxStaticText* FromLabel2 = new wxStaticText ( this, wxID_STATIC,
_("The letter"), wxDefaultPosition, wxDefaultSize, 0 );
RuleBox2->Add(FromLabel2, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
wxSpinCtrl* FromSpin2 = new wxSpinCtrl ( this, ID_FROM,wxEmptyString,
wxDefaultPosition, wxSize(60, -1),
wxSP_ARROW_KEYS, 0, 9);
RuleBox2->Add(FromSpin2, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
wxStaticText* ToLabel2 = new wxStaticText ( this, wxID_STATIC,_("overwrite to "),
wxDefaultPosition, wxDefaultSize, 0 );
RuleBox2->Add(ToLabel2, 0, wxALIGN_LEFT|wxALL, 5);
wxTextCtrl* ToCtrl2 = new wxTextCtrl ( this, ID_TO, wxEmptyString,
wxDefaultPosition, wxDefaultSize, 0 );
RuleBox2->Add(ToCtrl2, 0, wxGROW|wxALL, 5);
wxButton* AddRule = new wxButton ( this, ID_ADDRULE,
_("&Add Rule"), wxDefaultPosition, wxDefaultSize, 0 );
RuleBox2->Add( AddRule, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
#if wxUSE_STATLINE
wxStaticLine* line = new wxStaticLine ( this, wxID_STATIC,
wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
boxSizer->Add(line, 0, wxGROW|wxALL, 5);
#endif // wxUSE_STATLINE
wxBoxSizer* okCancelBox = new wxBoxSizer(wxHORIZONTAL);
boxSizer->Add(okCancelBox, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
wxButton* cancel = new wxButton ( this, wxID_CANCEL,
_("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
okCancelBox->Add(cancel, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
wxButton* ok = new wxButton ( this, wxID_OK, _("&OK"),
wxDefaultPosition, wxDefaultSize, 0 );
okCancelBox->Add(ok, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
Connect(ID_ADDRULE,wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler (ParametresDialog::AddRuleControls));
}