Page 1 of 1

Can't make wxTextCtrl fit more than 10 digits.

Posted: Wed May 13, 2020 3:35 am
by Tony0945
Trying to have boxes fit fourteen digit initializers. Only 12 digits fit. using sizers.

Snippet:

Code: Select all

 wxBoxSizer *RangeBox = new wxBoxSizer(wxHORIZONTAL);
        wxTextCtrl *AssignmentRangeStart = new wxTextCtrl(this, ID_IPRANGESTART, _("000.000.000.000ABC"));    
        wxTextCtrl *AssignmentRangeEnd   = new wxTextCtrl(this, ID_IPRANGEEND   , _("000.000.000.000XYZ"));
        RangeBox->Add(AssignmentRangeStart , wxALIGN_LEFT),1;
        RangeBox->Add(new wxStaticText(this,ID_DUMMY10,_("  to  ")),wxALIGN_CENTER,1);
        RangeBox->Add(AssignmentRangeEnd , wxALIGN_LEFT,1);
In the following code ABC & XYZ are there only as experiments. The textCtrl's are intended for input and output og IPv4 ip addresses.
This code is a modeled on the DHCP Server settings on my router. It is intended as a GUI front end to DNSMasq.

Complete DialogBox cpp file

Code: Select all

#include "DHCPDlg.h"

//Do not add custom headers
//wxDev-C++ designer will remove them
////Header Include Start
////Header Include End

//----------------------------------------------------------------------------
// DHCPDlg
//----------------------------------------------------------------------------
//Add Custom Events only in the appropriate block.
//Code added in other places will be removed by wxDev-C++
////Event Table Start
BEGIN_EVENT_TABLE(DHCPDlg,wxDialog)
	////Manual Code Start
	////Manual Code End
	
	EVT_CLOSE(DHCPDlg::OnClose)
END_EVENT_TABLE()
////Event Table End

DHCPDlg::DHCPDlg(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& size, long style)
: wxDialog(parent, id, title, position, size, style)
{
	CreateGUIControls();
}

DHCPDlg::~DHCPDlg()
{
} 

void DHCPDlg::CreateGUIControls()
{
	//Do not add custom code between
	//GUI Items Creation Start and GUI Items Creation End.
	//wxDev-C++ designer will remove them.
	//Add the custom code before or after the blocks
	////GUI Items Creation Start

	SetTitle(_(""));
	SetIcon(wxNullIcon);
	SetSize(8,8,967,543);
	Center();
	
	////GUI Items Creation End
	
	//construct the Radio box
	wxArrayString arrayStringFor_NodeType;
	arrayStringFor_NodeType.Add(_("Broadcast only (use when no WINS servers configured)"));
	arrayStringFor_NodeType.Add(_("Point-to-Point (no broadcast)"));
	arrayStringFor_NodeType.Add(_("Mixed mode (Broadcast then Point-to-Point)"));
	arrayStringFor_NodeType.Add(_("Hybrid (Point-to-Point then Broadcast)"));
	wxRadioBox *NodeType = new wxRadioBox(this, ID_NODETYPE, _(""), wxDefaultPosition, wxDefaultSize, arrayStringFor_NodeType, 4, wxRA_SPECIFY_ROWS);
	NodeType->SetSelection(0);
	wxBoxSizer *LeftColumn = new wxBoxSizer(wxVERTICAL);
	wxBoxSizer *RightColumn = new wxBoxSizer(wxVERTICAL);
	
	
	LeftColumn->Add(new wxStaticText(this,ID_DUMMY1, _("           Enable DHCP Server:")));
	LeftColumn->Add(new wxStaticText(this,ID_DUMMY2, _("     DHCP IP Address Range:")),wxALIGN_RIGHT);
	LeftColumn->Add(new wxStaticText(this,ID_DUMMY4, _("          DHCP Lease Time: ")),wxALIGN_RIGHT);
	LeftColumn->Add(new wxStaticText(this,ID_DUMMY5, _("         Always broadcast: ")),wxALIGN_RIGHT);
	LeftColumn->Add(new wxStaticText(this,ID_DUMMY6, _("     NetBIOS announcement: ")),wxALIGN_RIGHT);
	
	LeftColumn->Add(new wxStaticText(this,ID_DUMMY7, _("                          ")),wxALIGN_RIGHT);
    LeftColumn->Add(new wxStaticText(this,ID_DUMMY7, _("        NetBIOS node type: ")),wxALIGN_RIGHT);
   
    LeftColumn->Add(new wxStaticText(this,ID_DUMMY7, _("                          ")),wxALIGN_RIGHT);
    LeftColumn->Add(new wxStaticText(this,ID_DUMMY7, _("                          ")),wxALIGN_RIGHT);
    LeftColumn->Add(new wxStaticText(this,ID_DUMMY7, _("                          ")),wxALIGN_RIGHT);
    LeftColumn->Add(new wxStaticText(this,ID_DUMMY7, _("                          ")),wxALIGN_RIGHT);
    LeftColumn->Add(new wxStaticText(this,ID_DUMMY7, _("                          ")),wxALIGN_RIGHT);
    LeftColumn->Add(new wxStaticText(this,ID_DUMMY8, _("     Primary WINS IP Address:")),wxALIGN_RIGHT);
    LeftColumn->Add(new wxStaticText(this,ID_DUMMY9, _("Secondary WINS IP Address: ")),wxALIGN_RIGHT);
    
    wxCheckBox *MasterEnable =    new wxCheckBox(this,ID_MASTERENABLE,_(""));
    wxCheckBox *AlwaysBroadcast = new wxCheckBox(this,ID_ALWAYSBROADCAST , _("(compatibility with some DHCP clients)"));
    wxCheckBox *AnnounceNetBIOS = new wxCheckBox(this,ID_NETBIOSANNOUNCE, _("hoohah"));
    
    wxBoxSizer *TimeBox = new wxBoxSizer(wxHORIZONTAL);
    wxTextCtrl *LeaseTime = new wxTextCtrl(this, ID_LEASETIME, _("         "));
    TimeBox->Add(LeaseTime,wxALIGN_LEFT,1);
    TimeBox->Add(new wxStaticText(this,ID_DUMMY10, _(" (minutes) ")),wxALIGN_LEFT,1);
    
    wxBoxSizer *RangeBox = new wxBoxSizer(wxHORIZONTAL);
        wxTextCtrl *AssignmentRangeStart = new wxTextCtrl(this, ID_IPRANGESTART, _("000.000.000.000ABC"));    
                 wxTextCtrl *AssignmentRangeEnd   = new wxTextCtrl(this, ID_IPRANGEEND   , _("000.000.000.000XYZ"));
        RangeBox->Add(AssignmentRangeStart , wxALIGN_LEFT),1;
        RangeBox->Add(new wxStaticText(this,ID_DUMMY10,_("  to  ")),wxALIGN_CENTER,1);
        RangeBox->Add(AssignmentRangeEnd , wxALIGN_LEFT,1);
        
    RightColumn->Add(MasterEnable,wxALIGN_LEFT,0);   
    RightColumn->Add(RangeBox, wxALIGN_LEFT,0);
    RightColumn->Add(TimeBox,wxALIGN_LEFT,0);
    RightColumn->Add(AlwaysBroadcast,wxALIGN_LEFT,0);
   	RightColumn->Add(AnnounceNetBIOS,wxALIGN_LEFT,0);
   	RightColumn->Add(NodeType,wxALIGN_LEFT,0);
//	RightColumn->Add(new wxStaticText(this,ID_DUMMY10,_(" RADIO BOX HERE")),wxALIGN_LEFT,0);
	RightColumn->Add(new wxTextCtrl(this, ID_PRIMARYWINS, _("000.000.000.000  ")),wxALIGN_LEFT,0);
	RightColumn->Add(new wxTextCtrl(this, ID_SECONDARYWINS, _("000.000.000.000  ")),wxALIGN_LEFT,0);
	LeftColumn->Layout();
	RightColumn->Layout();
	wxBoxSizer *Grid = new wxBoxSizer(wxHORIZONTAL);
	Grid->Add(LeftColumn,0,wxALIGN_RIGHT);
	Grid->Add(RightColumn,1,wxALIGN_LEFT);
    SetSizerAndFit(Grid);

//	this->Maximize();

//	AlwaysBroadcastcaption = new wxStaticText(this, ID_ALWAYSBROADCASTCAPTION, _("Always Broadcast"), wxPoint(17, 124), wxDefaultSize, 0, _("AlwaysBroadcastcaption"));

//	Leasetime = new wxTextCtrl(this, ID_LEASETIME, _("Leasetime"), wxPoint(117, 92), wxSize(121, 22), 0, wxDefaultValidator, _("Leasetime"));

//	LeaseTimeCaption = new wxStaticText(this, ID_LEASETIMECAPTION, _("Lease Time:"), wxPoint(10, 94), wxDefaultSize, 0, _("LeaseTimeCaption"));

//	RangeCaption = new wxStaticText(this, ID_RANGECAPTION, _("DHCP IP Address Range:"), wxPoint(-3, 61), wxDefaultSize, 0, _("RangeCaption"));

//	IPRangeEnd = new wxTextCtrl(this, ID_IPRANGEEND, _("IPRangeEnd"), wxPoint(376, 55), wxSize(131, 26), 0, wxDefaultValidator, _("IPRangeEnd"));

//	IPRangeStart = new wxTextCtrl(this, ID_IPRANGESTART, _("IPRangeStart"), wxPoint(162, 60), wxSize(121, 22), 0, wxDefaultValidator, _("IPRangeStart"));

//	MasterEnableCheckBox = new wxCheckBox(this, ID_MASTERENABLECHECKBOX, _("Enable DHCP Server"), wxPoint(-6, 37), wxSize(149, 17), wxCHK_2STATE  | wxALIGN_RIGHT, wxDefaultValidator, _("MasterEnableCheckBox"));

}

void DHCPDlg::OnClose(wxCloseEvent& /*event*/)
{
	Destroy();
}

/*
 * MasterEnableCheckBoxClick
 */
void DHCPDlg::MasterEnableCheckBoxClick(wxCommandEvent& event)
{
	// insert your code here
}

Re: Can't make wxTextCtrl fit more than 10 digits.

Posted: Wed May 13, 2020 7:12 am
by PB
Tony0945 wrote:
Wed May 13, 2020 3:35 am
Trying to have boxes fit fourteen digit initializers. Only 12 digits fit. using sizers.
... The textCtrl's are intended for input and output og IPv4 ip addresses.
I thought IPv4 has 12 (4 groups of 3) digits?

Anyway, if you want to size the text control to fit around the IP address, did you try setting the initial size? I.e., something like

Code: Select all

textCtrl->SetInitialSize(textCtrl->GetSizeFromTextSize(textCtrl->GetTextExtent(" 000.000.000.000 ")));

Re: Can't make wxTextCtrl fit more than 10 digits.

Posted: Wed May 13, 2020 3:03 pm
by Tony0945
I want space for the dots too.

This did indeed work. I'm surprised that a custom box for ip addresses, allowing only legal addresses has not been developed before.

I have four in this project and undoubtedly more down the road. A custom control sounds like a good idea.

Re: Can't make wxTextCtrl fit more than 10 digits.

Posted: Wed May 13, 2020 4:25 pm
by Manolo
I'm surprised that a custom box for ip addresses, allowing only legal addresses has not been developed before.
There is a proposal, wxMaskedEdit, at http://trac.wxwidgets.org/ticket/14535 that never become accepted. A matter of more people testing it.

While it's quite old, you may try it. Perhaps it works in your environment.

Re: Can't make wxTextCtrl fit more than 10 digits.

Posted: Wed May 20, 2020 3:58 pm
by Tony0945
Thanks! I will try it