Network Preflet: Implement an IPV4TextControl which only allows numbers
and use it instead of the regular BTextControl. Unfortunately it doesn't block multi-byte characters (to do that we should create a subclass of BTextView and override InsertText()).
This commit is contained in:
@@ -68,9 +68,6 @@ static const uint32 kMsgNetwork = 'netw';
|
|||||||
static void
|
static void
|
||||||
SetupTextControl(BTextControl *control)
|
SetupTextControl(BTextControl *control)
|
||||||
{
|
{
|
||||||
// TODO: Disallow characters, etc.
|
|
||||||
// Would be nice to have a real
|
|
||||||
// formatted input control
|
|
||||||
control->SetModificationMessage(new BMessage(kMsgChange));
|
control->SetModificationMessage(new BMessage(kMsgChange));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +91,15 @@ MatchPattern(const char* string, const char* pattern)
|
|||||||
#define B_TRANSLATION_CONTEXT "EthernetSettingsView"
|
#define B_TRANSLATION_CONTEXT "EthernetSettingsView"
|
||||||
|
|
||||||
|
|
||||||
|
class IPV4AddressTextControl : public BTextControl {
|
||||||
|
public:
|
||||||
|
IPV4AddressTextControl(const char* label,
|
||||||
|
const char* initialText,
|
||||||
|
BMessage* message);
|
||||||
|
virtual ~IPV4AddressTextControl();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
EthernetSettingsView::EthernetSettingsView()
|
EthernetSettingsView::EthernetSettingsView()
|
||||||
:
|
:
|
||||||
BView("EthernetSettingsView", 0, NULL),
|
BView("EthernetSettingsView", 0, NULL),
|
||||||
@@ -116,8 +122,6 @@ EthernetSettingsView::EthernetSettingsView()
|
|||||||
rootLayout->SetSpacing(inset);
|
rootLayout->SetSpacing(inset);
|
||||||
layout->SetSpacing(inset, inset);
|
layout->SetSpacing(inset, inset);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BPopUpMenu* modeMenu = new BPopUpMenu("modes");
|
BPopUpMenu* modeMenu = new BPopUpMenu("modes");
|
||||||
modeMenu->AddItem(new BMenuItem(B_TRANSLATE("Static"),
|
modeMenu->AddItem(new BMenuItem(B_TRANSLATE("Static"),
|
||||||
new BMessage(kMsgStaticMode)));
|
new BMessage(kMsgStaticMode)));
|
||||||
@@ -144,7 +148,8 @@ EthernetSettingsView::EthernetSettingsView()
|
|||||||
layout->AddItem(fTypeMenuField->CreateLabelLayoutItem(), 0, 2);
|
layout->AddItem(fTypeMenuField->CreateLabelLayoutItem(), 0, 2);
|
||||||
layout->AddItem(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 2);
|
layout->AddItem(fTypeMenuField->CreateMenuBarLayoutItem(), 1, 2);
|
||||||
|
|
||||||
fIPTextControl = new BTextControl(B_TRANSLATE("IP address:"), "", NULL);
|
fIPTextControl = new IPV4AddressTextControl(
|
||||||
|
B_TRANSLATE("IP address:"), "", NULL);
|
||||||
SetupTextControl(fIPTextControl);
|
SetupTextControl(fIPTextControl);
|
||||||
|
|
||||||
BLayoutItem* layoutItem = fIPTextControl->CreateTextViewLayoutItem();
|
BLayoutItem* layoutItem = fIPTextControl->CreateTextViewLayoutItem();
|
||||||
@@ -155,26 +160,28 @@ EthernetSettingsView::EthernetSettingsView()
|
|||||||
layout->AddItem(fIPTextControl->CreateLabelLayoutItem(), 0, 3);
|
layout->AddItem(fIPTextControl->CreateLabelLayoutItem(), 0, 3);
|
||||||
layout->AddItem(layoutItem, 1, 3);
|
layout->AddItem(layoutItem, 1, 3);
|
||||||
|
|
||||||
fNetMaskTextControl = new BTextControl(B_TRANSLATE("Netmask:"), "", NULL);
|
fNetMaskTextControl = new IPV4AddressTextControl(
|
||||||
|
B_TRANSLATE("Netmask:"), "", NULL);
|
||||||
SetupTextControl(fNetMaskTextControl);
|
SetupTextControl(fNetMaskTextControl);
|
||||||
layout->AddItem(fNetMaskTextControl->CreateLabelLayoutItem(), 0, 4);
|
layout->AddItem(fNetMaskTextControl->CreateLabelLayoutItem(), 0, 4);
|
||||||
layout->AddItem(fNetMaskTextControl->CreateTextViewLayoutItem(), 1, 4);
|
layout->AddItem(fNetMaskTextControl->CreateTextViewLayoutItem(), 1, 4);
|
||||||
|
|
||||||
fGatewayTextControl = new BTextControl(B_TRANSLATE("Gateway:"), "", NULL);
|
fGatewayTextControl = new IPV4AddressTextControl(
|
||||||
|
B_TRANSLATE("Gateway:"), "", NULL);
|
||||||
SetupTextControl(fGatewayTextControl);
|
SetupTextControl(fGatewayTextControl);
|
||||||
layout->AddItem(fGatewayTextControl->CreateLabelLayoutItem(), 0, 5);
|
layout->AddItem(fGatewayTextControl->CreateLabelLayoutItem(), 0, 5);
|
||||||
layout->AddItem(fGatewayTextControl->CreateTextViewLayoutItem(), 1, 5);
|
layout->AddItem(fGatewayTextControl->CreateTextViewLayoutItem(), 1, 5);
|
||||||
|
|
||||||
// TODO: Replace the DNS text controls by a BListView with add/remove
|
// TODO: Replace the DNS text controls by a BListView with add/remove
|
||||||
// functionality and so on...
|
// functionality and so on...
|
||||||
fPrimaryDNSTextControl = new BTextControl(B_TRANSLATE("DNS #1:"), "",
|
fPrimaryDNSTextControl = new IPV4AddressTextControl(
|
||||||
NULL);
|
B_TRANSLATE("DNS #1:"), "", NULL);
|
||||||
SetupTextControl(fPrimaryDNSTextControl);
|
SetupTextControl(fPrimaryDNSTextControl);
|
||||||
layout->AddItem(fPrimaryDNSTextControl->CreateLabelLayoutItem(), 0, 6);
|
layout->AddItem(fPrimaryDNSTextControl->CreateLabelLayoutItem(), 0, 6);
|
||||||
layout->AddItem(fPrimaryDNSTextControl->CreateTextViewLayoutItem(), 1, 6);
|
layout->AddItem(fPrimaryDNSTextControl->CreateTextViewLayoutItem(), 1, 6);
|
||||||
|
|
||||||
fSecondaryDNSTextControl = new BTextControl(B_TRANSLATE("DNS #2:"), "",
|
fSecondaryDNSTextControl = new IPV4AddressTextControl(
|
||||||
NULL);
|
B_TRANSLATE("DNS #2:"), "", NULL);
|
||||||
SetupTextControl(fSecondaryDNSTextControl);
|
SetupTextControl(fSecondaryDNSTextControl);
|
||||||
layout->AddItem(fSecondaryDNSTextControl->CreateLabelLayoutItem(), 0, 7);
|
layout->AddItem(fSecondaryDNSTextControl->CreateLabelLayoutItem(), 0, 7);
|
||||||
layout->AddItem(fSecondaryDNSTextControl->CreateTextViewLayoutItem(), 1, 7);
|
layout->AddItem(fSecondaryDNSTextControl->CreateTextViewLayoutItem(), 1, 7);
|
||||||
@@ -741,3 +748,29 @@ EthernetSettingsView::_ValidateControl(BTextControl* control)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// IPV4AddressTextControl
|
||||||
|
IPV4AddressTextControl::IPV4AddressTextControl(const char* label,
|
||||||
|
const char* initialText, BMessage* message)
|
||||||
|
:
|
||||||
|
BTextControl(label, initialText, message)
|
||||||
|
{
|
||||||
|
// TODO: Would be nice to have a formatted input control
|
||||||
|
// TODO: Would be nice to have a "DisallowAllExcept" method
|
||||||
|
// TODO: This doesn't block multi-byte characters
|
||||||
|
for (uint32 i = (uint32)0; i <= 255; i++)
|
||||||
|
TextView()->DisallowChar(i);
|
||||||
|
|
||||||
|
for (uint32 i = (uint32)'0'; i <= (uint32)'9'; i++)
|
||||||
|
TextView()->AllowChar(i);
|
||||||
|
|
||||||
|
TextView()->AllowChar((uint32)'.');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* virtual */
|
||||||
|
IPV4AddressTextControl::~IPV4AddressTextControl()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user