OpenASIP  2.0
NumberControl.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file NumberControl.hh
26  *
27  * Declaration of NumberControl class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2004 (vjaaskel-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #ifndef TTA_NUMBER_CONTROL_HH
34 #define TTA_NUMBER_CONTROL_HH
35 
36 #include <wx/wx.h>
37 
38 #include "Exception.hh"
39 #include "FocusTrackingTextCtrl.hh"
40 #include "BaseType.hh"
41 
42 /**
43  * Text field widget for numeric value input.
44  *
45  * The widget value can be modified in hexadecimal, binary, int, unsigned int
46  * and floating point format. The widget value is always the same four
47  * bytes of memory, and the bit pattern is interpreted depending on the
48  * selected mode. Text field mode can be selected using an optional
49  * mode choicer. Available modes for the choicer are selected by passing the
50  * following style flags to the constructor:
51  * MODE_HEXADECIMAL, MODE_BINARY, MODE_INT, MODE_UNSIGNED, MODE_FLOAT and
52  * MODE_DOUBLE
53  *
54  * Note that the extra bits in the double value is ignored when the mode
55  * is changed from double to any of the other modes.
56  *
57  * The mode choicer widget can be disabled by using NO_MODE_CHOICER style flag.
58  */
59 class NumberControl : public wxPanel {
60 public:
62  wxWindow* parent,
63  wxWindowID id = -1,
64  const wxPoint& pos = wxDefaultPosition,
65  const wxSize& size = wxDefaultSize,
66  long style = (MODE_HEXADECIMAL | MODE_BINARY |
68  int initial = 0,
69  const wxString& name = _T("NumberControl"));
70  virtual ~NumberControl();
71 
72  int intValue() const;
73  unsigned int unsignedValue() const;
74  float floatValue() const;
75  double doubleValue() const;
76  ULongWord uLongValue() const;
77 
78  long mode() const;
79 
80  void setBinMode();
81  void setHexMode();
82  void setIntMode();
83  void setUnsignedMode();
84  void setFloatMode();
85  void setDoubleMode();
86 
87  void setValue(const ULongWord value);
88  void setValue(const unsigned int value);
89  void setValue(const int value);
90  void setValue(const float value);
91  void setValue(const double value);
92 
93  /// Style flag for binary mode availability.
94  static const long MODE_BINARY;
95  /// Style flag for signed integer mode availablity.
96  static const long MODE_INT;
97  /// Style flag for unsigned integer mode availability.
98  static const long MODE_UNSIGNED;
99  /// Style flag for hexadecimal mode availability.
100  static const long MODE_HEXADECIMAL;
101  /// Style flag for float mode availability.
102  static const long MODE_FLOAT;
103  /// Style flag for double mode availability.
104  static const long MODE_DOUBLE;
105  /// Style flag for base choicer visibility.
106  static const long NO_MODE_CHOICER;
107 
108 private:
109  void create(const wxSize& size);
110  void update();
111  void onModeChoice(wxCommandEvent& event);
112  void onText(wxCommandEvent& event);
113 
114  /// Text field widget.
116  /// Mode choicer widget.
117  wxChoice* modeChoice_;
118 
119  /// Current style flags of the widget.
120  long style_;
121 
122  union Value {
124  unsigned int unsignedValue;
125  int intValue;
126  float floatValue;
127  double doubleValue;
128  };
129 
130  /// Current value of the widget.
132 
133  /// Dummy value string for the validators.
134  wxString stringValue_;
135 
136  /// Current mode of the widget.
137  long mode_;
138 
139  /// Choicer item string for the binary mode.
140  static const wxString MODE_STRING_BIN;
141  /// Choicer item string for the hexadecimal mode.
142  static const wxString MODE_STRING_HEX;
143  /// Choicer item string for the integer mode.
144  static const wxString MODE_STRING_INT;
145  /// Choicer item string for the unsigned mode.
146  static const wxString MODE_STRING_UNSIGNED;
147  /// Choicer item string for the float mode.
148  static const wxString MODE_STRING_FLOAT;
149  /// Choicer item string for the double mode.
150  static const wxString MODE_STRING_DOUBLE;
151  /// Mode choicer width.
152  static const int CHOICER_WIDTH;
153 
154  /// Binary input validator.
155  wxTextValidator* binValidator_;
156  /// Hexadecimal input validator.
157  wxTextValidator* hexValidator_;
158  /// Signed integer input validator.
159  wxTextValidator* intValidator_;
160  /// Unsigned integer input validator.
161  wxTextValidator* unsignedValidator_;
162  /// Float input validator.
163  wxTextValidator* floatValidator_;
164 
165  /// IDs for the subwidgets.
166  enum {
167  ID_BASE = 20000,
169  };
170 
171  DECLARE_EVENT_TABLE()
172 };
173 
174 #endif
NumberControl::update
void update()
Definition: NumberControl.cc:209
NumberControl::unsignedValue
unsigned int unsignedValue() const
Definition: NumberControl.cc:428
NumberControl::value_
Value value_
Current value of the widget.
Definition: NumberControl.hh:131
BaseType.hh
NumberControl::MODE_STRING_DOUBLE
static const wxString MODE_STRING_DOUBLE
Choicer item string for the double mode.
Definition: NumberControl.hh:150
Exception.hh
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::setValue
void setValue(const ULongWord value)
Definition: NumberControl.cc:381
NumberControl::setIntMode
void setIntMode()
Definition: NumberControl.cc:462
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"))
Definition: NumberControl.cc:83
NumberControl::mode
long mode() const
Definition: NumberControl.cc:764
NumberControl::style_
long style_
Current style flags of the widget.
Definition: NumberControl.hh:120
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
NumberControl::intValue
int intValue() const
Definition: NumberControl.cc:417
NumberControl::doubleValue
double doubleValue() const
Definition: NumberControl.cc:450
NumberControl::Value
Definition: NumberControl.hh:122
NumberControl::setDoubleMode
void setDoubleMode()
Definition: NumberControl.cc:709
NumberControl::floatValue
float floatValue() const
Definition: NumberControl.cc:439
NumberControl::setBinMode
void setBinMode()
Definition: NumberControl.cc:493
NumberControl::~NumberControl
virtual ~NumberControl()
Definition: NumberControl.cc:113
NumberControl::Value::doubleValue
double doubleValue
Definition: NumberControl.hh:127
NumberControl::uLongValue
ULongWord uLongValue() const
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
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
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
FocusTrackingTextCtrl.hh
NumberControl
Definition: NumberControl.hh:59
NumberControl::ID_BASE
@ ID_BASE
Definition: NumberControl.hh:167
ULongWord
unsigned long ULongWord
Definition: BaseType.hh:51
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
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
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
NumberControl::onModeChoice
void onModeChoice(wxCommandEvent &event)
Definition: NumberControl.cc:327