Cathing values from controls

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
qarantena
In need of some credit
In need of some credit
Posts: 7
Joined: Sat Jul 11, 2009 6:08 pm

Cathing values from controls

Post by qarantena » Fri Aug 07, 2009 2:49 pm

I'm making a GUI for a program. The dialog should enable the user to give several conditions for overwriting, e.g.
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));
}

van_user
Experienced Solver
Experienced Solver
Posts: 55
Joined: Wed Jun 11, 2008 9:28 pm
Location: UA

Post by van_user » Sat Aug 08, 2009 10:12 am

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.
Simply add controls to the sizer. But for this store sizer as a member of the class ( to reuse it not from consructor). And attach it ("RuleBoxEVT") to the "topSizer".

qarantena
In need of some credit
In need of some credit
Posts: 7
Joined: Sat Jul 11, 2009 6:08 pm

Post by qarantena » Sun Aug 09, 2009 5:49 pm

I have stored the sizer as a class member

Code: Select all

class ParametresDialog : public wxDialog
{
     DECLARE_DYNAMIC_CLASS( ParametresDialog)
  public:
                 wxString From, To;
		 wxBoxSizer* topSizer; 
		 wxBoxSizer* boxSizer ; 
		 wxBoxSizer* RuleBoxEVT;
		 wxBoxSizer* RuleBox1;
		 wxBoxSizer* RuleBox2;
.
.
.
};
and attached RuleBoxEVT to topSizer

Code: Select all

void ParametresDialog::AddRuleControls(wxCommandEvent& event)
{
    RuleBoxEVT = new wxBoxSizer(wxHORIZONTAL);
    topSizer->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);
}
but nothing changes. It still does not work.

And there is still problem with saving the values into a C++ code structure (any, not necessarily a map). Does anybody know?
Attachments
overwriteDialog.JPG
overwriteDialog.JPG (11.51 KiB) Viewed 547 times

Post Reply