OpenASIP  2.0
Classes | Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
NumberControl Class Reference

#include <NumberControl.hh>

Inheritance diagram for NumberControl:
Inheritance graph
Collaboration diagram for NumberControl:
Collaboration graph

Classes

union  Value
 

Public Member Functions

 NumberControl (wxWindow *parent, wxWindowID id=-1, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=(MODE_HEXADECIMAL|MODE_BINARY|MODE_INT|MODE_UNSIGNED|MODE_FLOAT), int initial=0, const wxString &name=_T("NumberControl"))
 
virtual ~NumberControl ()
 
int intValue () const
 
unsigned int unsignedValue () const
 
float floatValue () const
 
double doubleValue () const
 
ULongWord uLongValue () const
 
long mode () const
 
void setBinMode ()
 
void setHexMode ()
 
void setIntMode ()
 
void setUnsignedMode ()
 
void setFloatMode ()
 
void setDoubleMode ()
 
void setValue (const ULongWord value)
 
void setValue (const unsigned int value)
 
void setValue (const int value)
 
void setValue (const float value)
 
void setValue (const double value)
 

Static Public Attributes

static const long MODE_BINARY = 1
 Style flag for binary mode availability. More...
 
static const long MODE_INT = 4
 Style flag for signed integer mode availablity. More...
 
static const long MODE_UNSIGNED = 8
 Style flag for unsigned integer mode availability. More...
 
static const long MODE_HEXADECIMAL = 2
 Style flag for hexadecimal mode availability. More...
 
static const long MODE_FLOAT = 16
 Style flag for float mode availability. More...
 
static const long MODE_DOUBLE = 32
 Style flag for double mode availability. More...
 
static const long NO_MODE_CHOICER = 64
 Style flag for base choicer visibility. More...
 

Private Types

enum  { ID_BASE = 20000, ID_TEXT }
 IDs for the subwidgets. More...
 

Private Member Functions

void create (const wxSize &size)
 
void update ()
 
void onModeChoice (wxCommandEvent &event)
 
void onText (wxCommandEvent &event)
 

Private Attributes

FocusTrackingTextCtrltext_
 Text field widget. More...
 
wxChoice * modeChoice_
 Mode choicer widget. More...
 
long style_
 Current style flags of the widget. More...
 
Value value_
 Current value of the widget. More...
 
wxString stringValue_
 Dummy value string for the validators. More...
 
long mode_
 Current mode of the widget. More...
 
wxTextValidator * binValidator_
 Binary input validator. More...
 
wxTextValidator * hexValidator_
 Hexadecimal input validator. More...
 
wxTextValidator * intValidator_
 Signed integer input validator. More...
 
wxTextValidator * unsignedValidator_
 Unsigned integer input validator. More...
 
wxTextValidator * floatValidator_
 Float input validator. More...
 

Static Private Attributes

static const wxString MODE_STRING_BIN = _T("bin")
 Choicer item string for the binary mode. More...
 
static const wxString MODE_STRING_HEX = _T("hex")
 Choicer item string for the hexadecimal mode. More...
 
static const wxString MODE_STRING_INT = _T("int")
 Choicer item string for the integer mode. More...
 
static const wxString MODE_STRING_UNSIGNED = _T("unsigned")
 Choicer item string for the unsigned mode. More...
 
static const wxString MODE_STRING_FLOAT = _T("float")
 Choicer item string for the float mode. More...
 
static const wxString MODE_STRING_DOUBLE = _T("double")
 Choicer item string for the double mode. More...
 
static const int CHOICER_WIDTH = 100
 Mode choicer width. More...
 

Detailed Description

Text field widget for numeric value input.

The widget value can be modified in hexadecimal, binary, int, unsigned int and floating point format. The widget value is always the same four bytes of memory, and the bit pattern is interpreted depending on the selected mode. Text field mode can be selected using an optional mode choicer. Available modes for the choicer are selected by passing the following style flags to the constructor: MODE_HEXADECIMAL, MODE_BINARY, MODE_INT, MODE_UNSIGNED, MODE_FLOAT and MODE_DOUBLE

Note that the extra bits in the double value is ignored when the mode is changed from double to any of the other modes.

The mode choicer widget can be disabled by using NO_MODE_CHOICER style flag.

Definition at line 59 of file NumberControl.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

IDs for the subwidgets.

Enumerator
ID_BASE 
ID_TEXT 

Definition at line 166 of file NumberControl.hh.

166  {
167  ID_BASE = 20000,
168  ID_TEXT
169  };

Constructor & Destructor Documentation

◆ NumberControl()

NumberControl::NumberControl ( wxWindow *  parent,
wxWindowID  id = -1,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = (MODE_HEXADECIMAL | MODE_BINARY |                      MODE_INT | MODE_UNSIGNED | MODE_FLOAT),
int  initial = 0,
const wxString &  name = _T("NumberControl") 
)

The Constructor.

Parameters
windowParent window of the widget.
idID of the widget.
posPosition of the widget.
sizeSize of the widget.
styleStyle flags for the widget, see class comment for list of available flags.
valueInitial value of the input.
nameName identifier for the widget.
Exceptions
OutOfRangeIf the value is out of the range.
InvalidDataIf the minimum value is higher than the maximum.

Definition at line 83 of file NumberControl.cc.

90  :
91  wxPanel(parent, id, pos, size, wxTAB_TRAVERSAL, name),
92  text_(NULL),
93  modeChoice_(NULL),
94  style_(style),
95  stringValue_(_T("")),
96  mode_(0),
97  binValidator_(NULL),
98  hexValidator_(NULL),
99  intValidator_(NULL),
100  unsignedValidator_(NULL),
101  floatValidator_(NULL) {
102 
103  value_.unsignedValue =initial;
104 
105  // Create subwidgets.
106  create(size);
107 }

References unsignedValue().

Here is the call graph for this function:

◆ ~NumberControl()

NumberControl::~NumberControl ( )
virtual

The destructor.

Definition at line 113 of file NumberControl.cc.

113  {
114  if (binValidator_ != NULL) {
115  delete binValidator_;
116  }
117  if (hexValidator_ != NULL) {
118  delete hexValidator_;
119  }
120  if (intValidator_ != NULL) {
121  delete intValidator_;
122  }
123  if (unsignedValidator_ != NULL) {
124  delete unsignedValidator_;
125  }
126  if (floatValidator_ != NULL) {
127  delete floatValidator_;
128  }
129 }

References binValidator_, floatValidator_, hexValidator_, intValidator_, and unsignedValidator_.

Member Function Documentation

◆ create()

void NumberControl::create ( const wxSize &  size)
private

Creates the textfield and optional base choicer subwidgets for the control.

Definition at line 136 of file NumberControl.cc.

136  {
137 
138  wxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
139 
140  int textWidth = size.GetWidth();
141  if ((style_ & NO_MODE_CHOICER) == 0) {
142  textWidth = textWidth - CHOICER_WIDTH;
143  if (textWidth < 20) {
144  textWidth = 20;
145  }
146  }
147 
148  // Create text field widget.
149  text_ =
150  new FocusTrackingTextCtrl(this, ID_TEXT, _T(""), wxDefaultPosition,
151  wxSize(textWidth, -1));
152 
153  sizer->Add(text_, 0, wxALIGN_CENTER_VERTICAL);
154 
155  if ((style_ & NO_MODE_CHOICER) == 0) {
156  // Create base choicer.
157  modeChoice_ = new wxChoice(this, ID_BASE, wxDefaultPosition,
158  wxSize(CHOICER_WIDTH, -1));
159 
160  // append base choices
161  if ((style_ & MODE_BINARY) != 0) {
162  modeChoice_->Append(MODE_STRING_BIN);
163  }
164  if ((style_ & MODE_HEXADECIMAL) != 0) {
165  modeChoice_->Append(MODE_STRING_HEX);
166  }
167  if ((style_ & MODE_INT) != 0) {
168  modeChoice_->Append(MODE_STRING_INT);
169  }
170  if ((style_ & MODE_UNSIGNED) != 0) {
172  }
173  if ((style_ & MODE_FLOAT) != 0) {
175  }
176  if ((style_ & MODE_DOUBLE) != 0) {
178  }
179 
180  sizer->Add(modeChoice_, 0, wxALIGN_CENTER_VERTICAL);
181 
182  // set initial mode
183  if ((style_ & MODE_INT) != 0) {
184  setIntMode();
185  } else if ((style_ & MODE_UNSIGNED) != 0) {
186  setUnsignedMode();
187  } else if ((style_ & MODE_FLOAT) != 0) {
188  setFloatMode();
189  } else if ((style_ & MODE_HEXADECIMAL) != 0) {
190  setHexMode();
191  } else if ((style_ & MODE_BINARY) != 0) {
192  setBinMode();
193  } else if ((style_ & MODE_DOUBLE) != 0) {
194  setDoubleMode();
195  } else {
196  assert(false);
197  }
198  }
199 
200  SetSizer(sizer);
201  Fit();
202 }

References assert, CHOICER_WIDTH, ID_BASE, ID_TEXT, MODE_BINARY, MODE_DOUBLE, MODE_FLOAT, MODE_HEXADECIMAL, MODE_INT, MODE_STRING_BIN, MODE_STRING_DOUBLE, MODE_STRING_FLOAT, MODE_STRING_HEX, MODE_STRING_INT, MODE_STRING_UNSIGNED, MODE_UNSIGNED, modeChoice_, NO_MODE_CHOICER, setBinMode(), setDoubleMode(), setFloatMode(), setHexMode(), setIntMode(), setUnsignedMode(), style_, and text_.

Here is the call graph for this function:

◆ doubleValue()

double NumberControl::doubleValue ( ) const

Returns the current value.

Returns
Current value of the widget as double.

Definition at line 450 of file NumberControl.cc.

450  {
451  return value_.doubleValue;
452 }

References NumberControl::Value::doubleValue, and value_.

Referenced by MemoryValueDialog::doubleValue(), and SimulateDialog::onUpdateValue().

◆ floatValue()

float NumberControl::floatValue ( ) const

Returns the current value.

Returns
Current value of the widget as float.

Definition at line 439 of file NumberControl.cc.

439  {
440  return value_.floatValue;
441 }

References NumberControl::Value::floatValue, and value_.

◆ intValue()

int NumberControl::intValue ( ) const

Returns the current value.

Returns
Current value of the widget as int.

Definition at line 417 of file NumberControl.cc.

417  {
418  return value_.intValue;
419 }

References NumberControl::Value::intValue, and value_.

Referenced by MemoryValueDialog::intValue(), and SimulateDialog::onUpdateValue().

◆ mode()

long NumberControl::mode ( ) const

Returns the widget mode style flag.

Returns
Current mode of the widget.

Definition at line 764 of file NumberControl.cc.

764  {
765  return mode_;
766 }

References mode_.

Referenced by MemoryValueDialog::mode(), and SimulateDialog::onUpdateValue().

◆ onModeChoice()

void NumberControl::onModeChoice ( wxCommandEvent &  event)
private

Event handler for the mode choicer.

Updates text field according to the selected mode.

Definition at line 327 of file NumberControl.cc.

327  {
328 
329  // Udate the value from the textfield input.
330  wxCommandEvent dummy;
331  onText(dummy);
332 
333  // Set the selected mode.
334  if (modeChoice_->GetStringSelection() == MODE_STRING_BIN) {
335  setBinMode();
336  }else if (modeChoice_->GetStringSelection() == MODE_STRING_HEX) {
337  setHexMode();
338  } else if (modeChoice_->GetStringSelection() == MODE_STRING_INT) {
339  setIntMode();
340  } else if (modeChoice_->GetStringSelection() == MODE_STRING_UNSIGNED) {
341  setUnsignedMode();
342  } else if (modeChoice_->GetStringSelection() == MODE_STRING_FLOAT) {
343  setFloatMode();
344  } else if (modeChoice_->GetStringSelection() == MODE_STRING_DOUBLE) {
345  setDoubleMode();
346  } else {
347  assert(false);
348  }
349 }

References assert, dummy, MODE_STRING_BIN, MODE_STRING_DOUBLE, MODE_STRING_FLOAT, MODE_STRING_HEX, MODE_STRING_INT, MODE_STRING_UNSIGNED, modeChoice_, onText(), setBinMode(), setDoubleMode(), setFloatMode(), setHexMode(), setIntMode(), and setUnsignedMode().

Here is the call graph for this function:

◆ onText()

void NumberControl::onText ( wxCommandEvent &  event)
private

Event handler, which validates the text field value and transfers data from the text field to the value variable.

This event handler is called when user has input new value to the text field.

Definition at line 270 of file NumberControl.cc.

270  {
271 
272  string stringValue = WxConversion::toString(text_->GetValue());
273 
274  if (stringValue == "") {
275  value_.intValue = 0;
276  update();
277  wxCommandEvent textEvent(wxEVT_COMMAND_TEXT_UPDATED, GetId());
278  GetParent()->GetEventHandler()->AddPendingEvent(textEvent);
279 
280  return;
281  }
282 
283  try {
284  if (mode_ == MODE_INT) {
285  // int mode
286  value_.intValue = Conversion::toInt(stringValue);
287  } else if (mode_ == MODE_BINARY) {
288  // binary mode
289  stringValue = stringValue + "b";
290  value_.intValue = Conversion::toInt(stringValue);
291  } else if (mode_ == MODE_HEXADECIMAL) {
292  // hexadecimal mode
293  stringValue = "0x" + stringValue;
294  value_.intValue = Conversion::toInt(stringValue);
295  } else if (mode_ == MODE_UNSIGNED) {
296  // unsigned mode
298  } else if (mode_ == MODE_FLOAT) {
299  // float mode
300  value_.floatValue = Conversion::toFloat(stringValue);
301  } else if (mode_ == MODE_DOUBLE) {
302  // double mode
303  value_.doubleValue = Conversion::toDouble(stringValue);
304  } else {
305  assert(false);
306  }
307  } catch (NumberFormatException& e) {
308  // invalid input in the text field
309  value_.intValue = 0;
310  }
311 
312  wxCommandEvent textEvent(wxEVT_COMMAND_TEXT_UPDATED, GetId());
313  GetParent()->GetEventHandler()->AddPendingEvent(textEvent);
314 
315  if (text_->IsModified()) {
316  update();
317  }
318 }

References assert, NumberControl::Value::doubleValue, NumberControl::Value::floatValue, NumberControl::Value::intValue, mode_, MODE_BINARY, MODE_DOUBLE, MODE_FLOAT, MODE_HEXADECIMAL, MODE_INT, MODE_UNSIGNED, text_, Conversion::toDouble(), Conversion::toFloat(), Conversion::toInt(), WxConversion::toString(), Conversion::toUnsignedInt(), NumberControl::Value::unsignedValue, update(), and value_.

Referenced by onModeChoice().

Here is the call graph for this function:

◆ setBinMode()

void NumberControl::setBinMode ( )

Sets the widget to binary mode.

Exceptions
NotAvailableIf the MODE_BINARY style was not specified to the contructor.

Definition at line 493 of file NumberControl.cc.

493  {
494  // Check that the binary mode is available.
495  if ((style_ & MODE_BINARY) == 0) {
496  // Binary mode not available.
497  string procName = "NubmerControl::setBinMode";
498  throw NotAvailable(__FILE__, __LINE__, procName);
499  }
500 
501  // Create binary input validator if necessary.
502  if (binValidator_ == NULL) {
503  binValidator_ =
504  new wxTextValidator(wxFILTER_INCLUDE_CHAR_LIST, &stringValue_);
505 
506 #if wxCHECK_VERSION(2, 5, 4)
507  wxArrayString includes;
508  includes.Add(_T("0"));
509  includes.Add(_T("1"));
510  binValidator_->SetIncludes(includes);
511 #else
512  binValidator_->SetIncludeList(
513  wxStringList(_T("0"), _T("1"), NULL));
514 #endif
515 
516  }
517 
518  // Set the binary validator and update the widget.
519  text_->SetValidator(*binValidator_);
520  mode_ = MODE_BINARY;
521  if (modeChoice_ != NULL &&
522  modeChoice_->GetStringSelection() != MODE_STRING_BIN) {
523 
524  modeChoice_->SetStringSelection(MODE_STRING_BIN);
525  }
526  update();
527 }

References binValidator_, mode_, MODE_BINARY, MODE_STRING_BIN, modeChoice_, stringValue_, style_, text_, and update().

Referenced by create(), and onModeChoice().

Here is the call graph for this function:

◆ setDoubleMode()

void NumberControl::setDoubleMode ( )

Sets the widget to double mode.

Exceptions
NotAvailableIf the MODE_DOUBLE style was not specified to the constructor.

Definition at line 709 of file NumberControl.cc.

709  {
710  // Check that the double mode is available.
711  if ((style_ & MODE_DOUBLE) == 0) {
712  // Double mode not available.
713  string procName = "NubmerControl::setDoubleMode";
714  throw NotAvailable(__FILE__, __LINE__, procName);
715  }
716 
717  // Create float/double input validator if necessary.
718  if (floatValidator_ == NULL) {
720  new wxTextValidator(wxFILTER_INCLUDE_CHAR_LIST, &stringValue_);
721 
722 #if wxCHECK_VERSION(2, 5, 4)
723  wxArrayString includes;
724  includes.Add(_T("0"));
725  includes.Add(_T("1"));
726  includes.Add(_T("2"));
727  includes.Add(_T("3"));
728  includes.Add(_T("4"));
729  includes.Add(_T("5"));
730  includes.Add(_T("6"));
731  includes.Add(_T("7"));
732  includes.Add(_T("8"));
733  includes.Add(_T("9"));
734  includes.Add(_T("e"));
735  includes.Add(_T("."));
736  includes.Add(_T("-"));
737  includes.Add(_T("+"));
738  floatValidator_->SetIncludes(includes);
739 #else
740  floatValidator_->SetIncludeList(
741  wxStringList(_T("0"), _T("1"), _T("2"), _T("3"), _T("4"),
742  _T("5"), _T("6"), _T("7"), _T("8"), _T("9"),
743  _T("e"), _T("."), _T("-"), _T("+"), NULL));
744 #endif
745  }
746 
747  // Set the float/double validator and update the widget.
748  text_->SetValidator(*floatValidator_);
749  mode_ = MODE_DOUBLE;
750  if (modeChoice_ != NULL &&
751  modeChoice_->GetStringSelection() != MODE_STRING_DOUBLE) {
752 
753  modeChoice_->SetStringSelection(MODE_STRING_DOUBLE);
754  }
755  update();
756 }

References floatValidator_, mode_, MODE_DOUBLE, MODE_STRING_DOUBLE, modeChoice_, stringValue_, style_, text_, and update().

Referenced by create(), and onModeChoice().

Here is the call graph for this function:

◆ setFloatMode()

void NumberControl::setFloatMode ( )

Sets the widget to float mode.

Exceptions
NotAvailableIf the MODE_FLOAT style was not specified to the constructor.

Definition at line 653 of file NumberControl.cc.

653  {
654  // Check that the float mode is available.
655  if ((style_ & MODE_FLOAT) == 0) {
656  // Float mode not available.
657  string procName = "NubmerControl::setFloatMode";
658  throw NotAvailable(__FILE__, __LINE__, procName);
659  }
660 
661  // Create float input validator if necessary.
662  if (floatValidator_ == NULL) {
664  new wxTextValidator(wxFILTER_INCLUDE_CHAR_LIST, &stringValue_);
665 
666 #if wxCHECK_VERSION(2, 5, 4)
667  wxArrayString includes;
668  includes.Add(_T("0"));
669  includes.Add(_T("1"));
670  includes.Add(_T("2"));
671  includes.Add(_T("3"));
672  includes.Add(_T("4"));
673  includes.Add(_T("5"));
674  includes.Add(_T("6"));
675  includes.Add(_T("7"));
676  includes.Add(_T("8"));
677  includes.Add(_T("9"));
678  includes.Add(_T("e"));
679  includes.Add(_T("."));
680  includes.Add(_T("-"));
681  includes.Add(_T("+"));
682  floatValidator_->SetIncludes(includes);
683 #else
684  floatValidator_->SetIncludeList(
685  wxStringList(_T("0"), _T("1"), _T("2"), _T("3"), _T("4"),
686  _T("5"), _T("6"), _T("7"), _T("8"), _T("9"),
687  _T("e"), _T("."), _T("-"), _T("+"), NULL));
688 #endif
689  }
690 
691  // Set the float validator and update the widget.
692  text_->SetValidator(*floatValidator_);
693  mode_ = MODE_FLOAT;
694  if (modeChoice_ != NULL &&
695  modeChoice_->GetStringSelection() != MODE_STRING_FLOAT) {
696 
697  modeChoice_->SetStringSelection(MODE_STRING_FLOAT);
698  }
699  update();
700 }

References floatValidator_, mode_, MODE_FLOAT, MODE_STRING_FLOAT, modeChoice_, stringValue_, style_, text_, and update().

Referenced by create(), and onModeChoice().

Here is the call graph for this function:

◆ setHexMode()

void NumberControl::setHexMode ( )

Sets the widget to hexadecimal mode.

Exceptions
NotAvailableIf the MODE_HEXADECIMAL was not specified to the constructor.

Definition at line 536 of file NumberControl.cc.

536  {
537  // Check that the hexadecimal mode is available.
538  if ((style_ & MODE_HEXADECIMAL) == 0) {
539  // Hexadecimal mode not available.
540  string procName = "NubmerControl::setHexMode";
541  throw NotAvailable(__FILE__, __LINE__, procName);
542  }
543 
544  // Create hexadecimal input validator if necessary.
545  if (hexValidator_ == NULL) {
546  hexValidator_ =
547  new wxTextValidator(wxFILTER_INCLUDE_CHAR_LIST, &stringValue_);
548 
549 #if wxCHECK_VERSION(2, 5, 4)
550  wxArrayString includes;
551  includes.Add(_T("0"));
552  includes.Add(_T("1"));
553  includes.Add(_T("2"));
554  includes.Add(_T("3"));
555  includes.Add(_T("4"));
556  includes.Add(_T("5"));
557  includes.Add(_T("6"));
558  includes.Add(_T("7"));
559  includes.Add(_T("8"));
560  includes.Add(_T("9"));
561  includes.Add(_T("a"));
562  includes.Add(_T("b"));
563  includes.Add(_T("c"));
564  includes.Add(_T("d"));
565  includes.Add(_T("e"));
566  includes.Add(_T("f"));
567  includes.Add(_T("A"));
568  includes.Add(_T("B"));
569  includes.Add(_T("C"));
570  includes.Add(_T("D"));
571  includes.Add(_T("E"));
572  includes.Add(_T("F"));
573  hexValidator_->SetIncludes(includes);
574 #else
575  hexValidator_->SetIncludeList(
576  wxStringList(_T("0"), _T("1"), _T("2"), _T("3"), _T("4"), _T("5"),
577  _T("6"), _T("7"), _T("8"), _T("9"),
578  _T("a"), _T("b"), _T("c"), _T("d"), _T("e"), _T("f"),
579  _T("A"), _T("B"), _T("C"), _T("D"),
580  _T("E"), _T("F"), NULL));
581 #endif
582  }
583 
584  // Set the hexadecimal validator and update the widget.
585  text_->SetValidator(*hexValidator_);
587  if (modeChoice_ != NULL &&
588  modeChoice_->GetStringSelection() != MODE_STRING_HEX) {
589 
590  modeChoice_->SetStringSelection(MODE_STRING_HEX);
591  }
592  update();
593 }

References hexValidator_, mode_, MODE_HEXADECIMAL, MODE_STRING_HEX, modeChoice_, stringValue_, style_, text_, and update().

Referenced by create(), and onModeChoice().

Here is the call graph for this function:

◆ setIntMode()

void NumberControl::setIntMode ( )

Sets the widget to int mode.

Exceptions
NotAvailableIf the MODE_INT style was not specified to the constructor.

Definition at line 462 of file NumberControl.cc.

462  {
463  // Check that the int mode is available.
464  if ((style_ & MODE_INT) == 0) {
465  // Int mode not available.
466  string procName = "NubmerControl::setIntMode";
467  throw NotAvailable(__FILE__, __LINE__, procName);
468  }
469 
470  // Create decimal input validator if necessary.
471  if (intValidator_ == NULL) {
472  intValidator_ = new wxTextValidator(wxFILTER_NUMERIC, &stringValue_);
473  }
474 
475  // Set the decimal validator and update the widget.
476  text_->SetValidator(*intValidator_);
477  mode_ = MODE_INT;
478  if (modeChoice_ != NULL &&
479  modeChoice_->GetStringSelection() != MODE_STRING_INT) {
480 
481  modeChoice_->SetStringSelection(MODE_STRING_INT);
482  }
483  update();
484 }

References intValidator_, mode_, MODE_INT, MODE_STRING_INT, modeChoice_, stringValue_, style_, text_, and update().

Referenced by create(), and onModeChoice().

Here is the call graph for this function:

◆ setUnsignedMode()

void NumberControl::setUnsignedMode ( )

Sets the widget to unsigned int mode.

Exceptions
NotAvailableIf the MODE_UNSIGNED style was not specified to the constructor.

Definition at line 602 of file NumberControl.cc.

602  {
603  // Check that the unsigned mode is available.
604  if ((style_ & MODE_UNSIGNED) == 0) {
605  // Unsigned mode not available.
606  string procName = "NubmerControl::setUnsignedMode";
607  throw NotAvailable(__FILE__, __LINE__, procName);
608  }
609 
610  // Create decimal input validator if necessary.
611  if (unsignedValidator_ == NULL) {
613  new wxTextValidator(wxFILTER_INCLUDE_CHAR_LIST, &stringValue_);
614 
615 #if wxCHECK_VERSION(2, 5, 4)
616  wxArrayString includes;
617  includes.Add(_T("0"));
618  includes.Add(_T("1"));
619  includes.Add(_T("2"));
620  includes.Add(_T("3"));
621  includes.Add(_T("4"));
622  includes.Add(_T("5"));
623  includes.Add(_T("6"));
624  includes.Add(_T("7"));
625  includes.Add(_T("8"));
626  includes.Add(_T("9"));
627  unsignedValidator_->SetIncludes(includes);
628 #else
629  unsignedValidator_->SetIncludeList(
630  wxStringList(_T("0"), _T("1"), _T("2"), _T("3"), _T("4"), _T("5"),
631  _T("6"), _T("7"), _T("8"), _T("9"), NULL));
632 #endif
633  }
634 
635  // Set the decimal validator and update the widget.
636  text_->SetValidator(*unsignedValidator_);
638  if (modeChoice_ != NULL &&
639  modeChoice_->GetStringSelection() != MODE_STRING_UNSIGNED) {
640 
641  modeChoice_->SetStringSelection(MODE_STRING_UNSIGNED);
642  }
643  update();
644 }

References mode_, MODE_STRING_UNSIGNED, MODE_UNSIGNED, modeChoice_, stringValue_, style_, text_, unsignedValidator_, and update().

Referenced by create(), and onModeChoice().

Here is the call graph for this function:

◆ setValue() [1/5]

void NumberControl::setValue ( const double  value)

Sets the value on the widget.

Parameters
valueDouble value to set.

Definition at line 405 of file NumberControl.cc.

405  {
406  value_.doubleValue = value;
407  update();
408 }

References NumberControl::Value::doubleValue, update(), and value_.

Here is the call graph for this function:

◆ setValue() [2/5]

void NumberControl::setValue ( const float  value)

Sets the value on the widget.

Parameters
valueFloat value to set.

Definition at line 393 of file NumberControl.cc.

393  {
394  value_.floatValue = value;
395  update();
396 }

References NumberControl::Value::floatValue, update(), and value_.

Here is the call graph for this function:

◆ setValue() [3/5]

void NumberControl::setValue ( const int  value)

Sets the value on the widget.

Parameters
valueUnsigned value to set.

Definition at line 358 of file NumberControl.cc.

358  {
359  value_.intValue = value;
360  update();
361 }

References NumberControl::Value::intValue, update(), and value_.

Here is the call graph for this function:

◆ setValue() [4/5]

void NumberControl::setValue ( const ULongWord  value)

Sets the value on the widget.

Parameters
valueInteger value to set.

Definition at line 381 of file NumberControl.cc.

381  {
382  value_.uLongValue = value;
383  update();
384 }

References NumberControl::Value::uLongValue, update(), and value_.

Referenced by MemoryValueDialog::setValue().

Here is the call graph for this function:

◆ setValue() [5/5]

void NumberControl::setValue ( const unsigned int  value)

Sets the value on the widget.

Parameters
valueInteger value to set.

Definition at line 370 of file NumberControl.cc.

370  {
371  value_.unsignedValue = value;
372  update();
373 }

References NumberControl::Value::unsignedValue, update(), and value_.

Here is the call graph for this function:

◆ uLongValue()

ULongWord NumberControl::uLongValue ( ) const

◆ unsignedValue()

unsigned int NumberControl::unsignedValue ( ) const

Returns the current value.

Returns
Current value of the widget as unsigned int

Definition at line 428 of file NumberControl.cc.

428  {
429  return value_.unsignedValue;
430 }

References NumberControl::Value::unsignedValue, and value_.

Referenced by NumberControl().

◆ update()

void NumberControl::update ( )
private

Updates the value on the text field according to the selected mode.

Definition at line 209 of file NumberControl.cc.

209  {
210 
211  // binary mode
212  if (mode_ == MODE_BINARY) {
213  string binString = Conversion::toBinString(value_.intValue);
214  // Strip trailing 'b' from the binary string.
215  binString = binString.substr(0, binString.length() - 1);
216  text_->SetValue(WxConversion::toWxString(binString));
217  return;
218  }
219 
220  // hexadecimal mode
221  if (mode_ == MODE_HEXADECIMAL) {
222  string hexString = Conversion::toHexString(value_.intValue);
223  // Strip '0x' from the begining of the hexstring.
224  hexString = hexString.substr(2, hexString.length() - 2);
225  text_->SetValue(WxConversion::toWxString(hexString));
226  return;
227  }
228 
229  // int mode
230  if (mode_ == MODE_INT) {
231  string intString = Conversion::toString(value_.intValue);
232  text_->SetValue(WxConversion::toWxString(intString));
233  return;
234  }
235 
236  // unsigned mode
237  if (mode_ == MODE_UNSIGNED) {
238  string unsignedString = Conversion::toString(value_.unsignedValue);
239  text_->SetValue(WxConversion::toWxString(unsignedString));
240  return;
241  }
242 
243  // float mode
244  if (mode_ == MODE_FLOAT) {
245  string floatString = Conversion::toString(value_.floatValue);
246  text_->SetValue(WxConversion::toWxString(floatString));
247  return;
248  }
249 
250  // float mode
251  if (mode_ == MODE_DOUBLE) {
252  string doubleString = Conversion::toString(value_.doubleValue);
253  text_->SetValue(WxConversion::toWxString(doubleString));
254  return;
255  }
256 
257  // Error: no mode selected.
258  assert(false);
259 }

References assert, NumberControl::Value::doubleValue, NumberControl::Value::floatValue, NumberControl::Value::intValue, mode_, MODE_BINARY, MODE_DOUBLE, MODE_FLOAT, MODE_HEXADECIMAL, MODE_INT, MODE_UNSIGNED, text_, Conversion::toBinString(), Conversion::toHexString(), Conversion::toString(), WxConversion::toWxString(), NumberControl::Value::unsignedValue, and value_.

Referenced by onText(), setBinMode(), setDoubleMode(), setFloatMode(), setHexMode(), setIntMode(), setUnsignedMode(), and setValue().

Here is the call graph for this function:

Member Data Documentation

◆ binValidator_

wxTextValidator* NumberControl::binValidator_
private

Binary input validator.

Definition at line 155 of file NumberControl.hh.

Referenced by setBinMode(), and ~NumberControl().

◆ CHOICER_WIDTH

const int NumberControl::CHOICER_WIDTH = 100
staticprivate

Mode choicer width.

Definition at line 152 of file NumberControl.hh.

Referenced by create().

◆ floatValidator_

wxTextValidator* NumberControl::floatValidator_
private

Float input validator.

Definition at line 163 of file NumberControl.hh.

Referenced by setDoubleMode(), setFloatMode(), and ~NumberControl().

◆ hexValidator_

wxTextValidator* NumberControl::hexValidator_
private

Hexadecimal input validator.

Definition at line 157 of file NumberControl.hh.

Referenced by setHexMode(), and ~NumberControl().

◆ intValidator_

wxTextValidator* NumberControl::intValidator_
private

Signed integer input validator.

Definition at line 159 of file NumberControl.hh.

Referenced by setIntMode(), and ~NumberControl().

◆ mode_

long NumberControl::mode_
private

Current mode of the widget.

Definition at line 137 of file NumberControl.hh.

Referenced by mode(), onText(), setBinMode(), setDoubleMode(), setFloatMode(), setHexMode(), setIntMode(), setUnsignedMode(), and update().

◆ MODE_BINARY

const long NumberControl::MODE_BINARY = 1
static

Style flag for binary mode availability.

Definition at line 94 of file NumberControl.hh.

Referenced by create(), MemoryValueDialog::createContents(), SimulateDialog::createContents(), onText(), setBinMode(), and update().

◆ MODE_DOUBLE

const long NumberControl::MODE_DOUBLE = 32
static

Style flag for double mode availability.

Definition at line 104 of file NumberControl.hh.

Referenced by create(), SimulateDialog::createContents(), onText(), SimulateDialog::onUpdateValue(), MemoryControl::onWriteMemory(), setDoubleMode(), and update().

◆ MODE_FLOAT

const long NumberControl::MODE_FLOAT = 16
static

Style flag for float mode availability.

Definition at line 102 of file NumberControl.hh.

Referenced by create(), MemoryValueDialog::createContents(), SimulateDialog::createContents(), onText(), setFloatMode(), and update().

◆ MODE_HEXADECIMAL

const long NumberControl::MODE_HEXADECIMAL = 2
static

Style flag for hexadecimal mode availability.

Definition at line 100 of file NumberControl.hh.

Referenced by create(), MemoryValueDialog::createContents(), AddressSpaceDialog::createContents(), SimulateDialog::createContents(), onText(), setHexMode(), and update().

◆ MODE_INT

const long NumberControl::MODE_INT = 4
static

Style flag for signed integer mode availablity.

Definition at line 96 of file NumberControl.hh.

Referenced by create(), SimulateDialog::createContents(), onText(), setIntMode(), and update().

◆ MODE_STRING_BIN

const wxString NumberControl::MODE_STRING_BIN = _T("bin")
staticprivate

Choicer item string for the binary mode.

Definition at line 140 of file NumberControl.hh.

Referenced by create(), onModeChoice(), and setBinMode().

◆ MODE_STRING_DOUBLE

const wxString NumberControl::MODE_STRING_DOUBLE = _T("double")
staticprivate

Choicer item string for the double mode.

Definition at line 150 of file NumberControl.hh.

Referenced by create(), onModeChoice(), and setDoubleMode().

◆ MODE_STRING_FLOAT

const wxString NumberControl::MODE_STRING_FLOAT = _T("float")
staticprivate

Choicer item string for the float mode.

Definition at line 148 of file NumberControl.hh.

Referenced by create(), onModeChoice(), and setFloatMode().

◆ MODE_STRING_HEX

const wxString NumberControl::MODE_STRING_HEX = _T("hex")
staticprivate

Choicer item string for the hexadecimal mode.

Definition at line 142 of file NumberControl.hh.

Referenced by create(), onModeChoice(), and setHexMode().

◆ MODE_STRING_INT

const wxString NumberControl::MODE_STRING_INT = _T("int")
staticprivate

Choicer item string for the integer mode.

Definition at line 144 of file NumberControl.hh.

Referenced by create(), onModeChoice(), and setIntMode().

◆ MODE_STRING_UNSIGNED

const wxString NumberControl::MODE_STRING_UNSIGNED = _T("unsigned")
staticprivate

Choicer item string for the unsigned mode.

Definition at line 146 of file NumberControl.hh.

Referenced by create(), onModeChoice(), and setUnsignedMode().

◆ MODE_UNSIGNED

const long NumberControl::MODE_UNSIGNED = 8
static

Style flag for unsigned integer mode availability.

Definition at line 98 of file NumberControl.hh.

Referenced by create(), MemoryValueDialog::createContents(), AddressSpaceDialog::createContents(), SimulateDialog::createContents(), onText(), setUnsignedMode(), and update().

◆ modeChoice_

wxChoice* NumberControl::modeChoice_
private

Mode choicer widget.

Definition at line 117 of file NumberControl.hh.

Referenced by create(), onModeChoice(), setBinMode(), setDoubleMode(), setFloatMode(), setHexMode(), setIntMode(), and setUnsignedMode().

◆ NO_MODE_CHOICER

const long NumberControl::NO_MODE_CHOICER = 64
static

Style flag for base choicer visibility.

Definition at line 106 of file NumberControl.hh.

Referenced by create().

◆ stringValue_

wxString NumberControl::stringValue_
private

Dummy value string for the validators.

Definition at line 134 of file NumberControl.hh.

Referenced by setBinMode(), setDoubleMode(), setFloatMode(), setHexMode(), setIntMode(), and setUnsignedMode().

◆ style_

long NumberControl::style_
private

Current style flags of the widget.

Definition at line 120 of file NumberControl.hh.

Referenced by create(), setBinMode(), setDoubleMode(), setFloatMode(), setHexMode(), setIntMode(), and setUnsignedMode().

◆ text_

FocusTrackingTextCtrl* NumberControl::text_
private

Text field widget.

Definition at line 115 of file NumberControl.hh.

Referenced by create(), onText(), setBinMode(), setDoubleMode(), setFloatMode(), setHexMode(), setIntMode(), setUnsignedMode(), and update().

◆ unsignedValidator_

wxTextValidator* NumberControl::unsignedValidator_
private

Unsigned integer input validator.

Definition at line 161 of file NumberControl.hh.

Referenced by setUnsignedMode(), and ~NumberControl().

◆ value_

Value NumberControl::value_
private

Current value of the widget.

Definition at line 131 of file NumberControl.hh.

Referenced by doubleValue(), floatValue(), intValue(), onText(), setValue(), unsignedValue(), and update().


The documentation for this class was generated from the following files:
NumberControl::update
void update()
Definition: NumberControl.cc:209
NumberControl::value_
Value value_
Current value of the widget.
Definition: NumberControl.hh:131
WxConversion::toWxString
static wxString toWxString(const std::string &source)
NumberFormatException
Definition: Exception.hh:421
NumberControl::MODE_STRING_DOUBLE
static const wxString MODE_STRING_DOUBLE
Choicer item string for the double mode.
Definition: NumberControl.hh:150
NumberControl::CHOICER_WIDTH
static const int CHOICER_WIDTH
Mode choicer width.
Definition: NumberControl.hh:152
NumberControl::MODE_STRING_INT
static const wxString MODE_STRING_INT
Choicer item string for the integer mode.
Definition: NumberControl.hh:144
NumberControl::setUnsignedMode
void setUnsignedMode()
Definition: NumberControl.cc:602
NumberControl::floatValidator_
wxTextValidator * floatValidator_
Float input validator.
Definition: NumberControl.hh:163
NumberControl::MODE_STRING_HEX
static const wxString MODE_STRING_HEX
Choicer item string for the hexadecimal mode.
Definition: NumberControl.hh:142
NumberControl::setIntMode
void setIntMode()
Definition: NumberControl.cc:462
Conversion::toString
static std::string toString(const T &source)
NotAvailable
Definition: Exception.hh:728
NumberControl::style_
long style_
Current style flags of the widget.
Definition: NumberControl.hh:120
assert
#define assert(condition)
Definition: Application.hh:86
Conversion::toDouble
static double toDouble(const T &source)
NumberControl::Value::intValue
int intValue
Definition: NumberControl.hh:125
NumberControl::onText
void onText(wxCommandEvent &event)
Definition: NumberControl.cc:270
NumberControl::Value::unsignedValue
unsigned int unsignedValue
Definition: NumberControl.hh:124
dummy
SimValue dummy(32)
a dummy simvalue which is given for operands that are not bound
NumberControl::setDoubleMode
void setDoubleMode()
Definition: NumberControl.cc:709
NumberControl::setBinMode
void setBinMode()
Definition: NumberControl.cc:493
NumberControl::Value::doubleValue
double doubleValue
Definition: NumberControl.hh:127
NumberControl::MODE_STRING_UNSIGNED
static const wxString MODE_STRING_UNSIGNED
Choicer item string for the unsigned mode.
Definition: NumberControl.hh:146
NumberControl::text_
FocusTrackingTextCtrl * text_
Text field widget.
Definition: NumberControl.hh:115
NumberControl::MODE_INT
static const long MODE_INT
Style flag for signed integer mode availablity.
Definition: NumberControl.hh:96
Conversion::toHexString
static std::string toHexString(T source, std::size_t digits=0, bool include0x=true)
NumberControl::MODE_STRING_FLOAT
static const wxString MODE_STRING_FLOAT
Choicer item string for the float mode.
Definition: NumberControl.hh:148
NumberControl::NO_MODE_CHOICER
static const long NO_MODE_CHOICER
Style flag for base choicer visibility.
Definition: NumberControl.hh:106
NumberControl::MODE_UNSIGNED
static const long MODE_UNSIGNED
Style flag for unsigned integer mode availability.
Definition: NumberControl.hh:98
NumberControl::hexValidator_
wxTextValidator * hexValidator_
Hexadecimal input validator.
Definition: NumberControl.hh:157
Conversion::toUnsignedInt
static unsigned int toUnsignedInt(const T &source)
NumberControl::MODE_STRING_BIN
static const wxString MODE_STRING_BIN
Choicer item string for the binary mode.
Definition: NumberControl.hh:140
NumberControl::MODE_HEXADECIMAL
static const long MODE_HEXADECIMAL
Style flag for hexadecimal mode availability.
Definition: NumberControl.hh:100
NumberControl::modeChoice_
wxChoice * modeChoice_
Mode choicer widget.
Definition: NumberControl.hh:117
NumberControl::mode_
long mode_
Current mode of the widget.
Definition: NumberControl.hh:137
NumberControl::MODE_BINARY
static const long MODE_BINARY
Style flag for binary mode availability.
Definition: NumberControl.hh:94
NumberControl::Value::floatValue
float floatValue
Definition: NumberControl.hh:126
Conversion::toBinString
static std::string toBinString(int source)
Definition: Conversion.cc:81
NumberControl::ID_BASE
@ ID_BASE
Definition: NumberControl.hh:167
NumberControl::unsignedValidator_
wxTextValidator * unsignedValidator_
Unsigned integer input validator.
Definition: NumberControl.hh:161
NumberControl::setHexMode
void setHexMode()
Definition: NumberControl.cc:536
NumberControl::Value::uLongValue
ULongWord uLongValue
Definition: NumberControl.hh:123
Conversion::toInt
static int toInt(const T &source)
NumberControl::intValidator_
wxTextValidator * intValidator_
Signed integer input validator.
Definition: NumberControl.hh:159
FocusTrackingTextCtrl
Definition: FocusTrackingTextCtrl.hh:47
NumberControl::binValidator_
wxTextValidator * binValidator_
Binary input validator.
Definition: NumberControl.hh:155
NumberControl::ID_TEXT
@ ID_TEXT
Definition: NumberControl.hh:168
WxConversion::toString
static std::string toString(const wxString &source)
NumberControl::setFloatMode
void setFloatMode()
Definition: NumberControl.cc:653
NumberControl::MODE_FLOAT
static const long MODE_FLOAT
Style flag for float mode availability.
Definition: NumberControl.hh:102
NumberControl::stringValue_
wxString stringValue_
Dummy value string for the validators.
Definition: NumberControl.hh:134
NumberControl::create
void create(const wxSize &size)
Definition: NumberControl.cc:136
NumberControl::MODE_DOUBLE
static const long MODE_DOUBLE
Style flag for double mode availability.
Definition: NumberControl.hh:104
Conversion::toFloat
static float toFloat(const T &source)