Skip to content

Commit

Permalink
Fixes issue HaikuArchives#64:
Browse files Browse the repository at this point in the history
Only allow decimal digits 0-9 in the text control for the Size test.
  • Loading branch information
owenca committed Jul 18, 2017
1 parent 4432990 commit 19844cc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
22 changes: 22 additions & 0 deletions sources/AutoTextControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,28 @@ AutoTextControl::GetCharacterLimit(const uint32& limit)
}


void
AutoTextControl::OnlyAllowDigits(bool turnOn) const
{
static bool turnedOn = false;

if (turnedOn == turnOn)
return;

turnedOn = 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
2 changes: 2 additions & 0 deletions sources/AutoTextControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class AutoTextControl : public BTextControl

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

void OnlyAllowDigits(bool turnOn) const;

private:
friend AutoTextControlFilter;
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 19844cc

Please sign in to comment.