Skip to content

Commit

Permalink
Disallow non-digits in size test (issue #64)
Browse files Browse the repository at this point in the history
	Only allow decimal digits in text control for size test.
  • Loading branch information
owenca authored and humdinger committed Jul 19, 2017
1 parent 4432990 commit 3e99669
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
20 changes: 20 additions & 0 deletions sources/AutoTextControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ AutoTextControl::AutoTextControl(const char* name, const char* label,
:
BTextControl(name, label, text, msg, flags),
fEmpty(false),
fOnlyDigits(false),
fFilter(NULL),
fCharLimit(0)
{
Expand Down Expand Up @@ -195,6 +196,25 @@ AutoTextControl::GetCharacterLimit(const uint32& limit)
}


void
AutoTextControl::OnlyAllowDigits(bool turnOn)
{
if (fOnlyDigits == turnOn)
return;

fOnlyDigits = turnOn;
BTextView* view = TextView();
void (BTextView::*f)(uint32 byte) = turnOn ? &BTextView::DisallowChar
: &BTextView::AllowChar;

for (uint32 i = 0; i < '0'; i++)
(view->*f)(i);

for (uint32 i = '9' + 1; i < 256; i++)
(view->*f)(i);
}


void
AutoTextControl::SetFilter(AutoTextControlFilter* filter)
{
Expand Down
3 changes: 3 additions & 0 deletions sources/AutoTextControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ class AutoTextControl : public BTextControl

void SetCharacterLimit(const uint32& limit);
uint32 GetCharacterLimit(const uint32& limit);

void OnlyAllowDigits(bool turnOn);

private:
friend AutoTextControlFilter;

AutoTextControlFilter* fFilter;
uint32 fCharLimit;
bool fEmpty;
bool fOnlyDigits;
};

/*
Expand Down
6 changes: 5 additions & 1 deletion sources/TestView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,14 @@ TestView::SetTest()
STRACE(("-------------------------\n"));

if (fDataType == TEST_TYPE_NUMBER) {
fValueBox->OnlyAllowDigits(true);
if (fUnitField->IsHidden())
fUnitField->Show();
} else if (!fUnitField->IsHidden())
} else {
fValueBox->OnlyAllowDigits(false);
if (!fUnitField->IsHidden())
fUnitField->Hide();
}
}


Expand Down

0 comments on commit 3e99669

Please sign in to comment.