FDOSTUI
FreeDOS Text User Interface
entry.hpp
Go to the documentation of this file.
1 /*
2  ENTRY.HPP
3 
4  License CC0 PUBLIC DOMAIN
5 
6  To the extent possible under law, Mark J. Olesen has waived all copyright
7  and related or neighboring rights to FDOSTUI Library. This work is published
8  from: United States.
9 */
10 #ifndef __entry_hpp__
11 
12 #include "widget.hpp"
13 
14 class entry : public widget
15 {
16 
17 public:
18 
19  typedef void (*signal_changed_t)(
20  entry const* i_entry,
21  void* io_user_data);
22 
23  enum purpose
24  {
30  };
31 
32  entry(
33  int const i_pos_x,
34  int const i_pos_y,
35  unsigned int const i_len_x,
36  unsigned int const i_len_y);
37 
38  virtual
39  ~entry();
40 
41  virtual void
42  draw() const;
43 
44  virtual enum event_response
45  event_key(
46  struct event_key const& i_event);
47 
48  virtual void
49  focus_enter();
50 
51  virtual void
52  focus_leave();
53 
54  unsigned char const*
55  get_text() const;
56 
57  size_t
58  get_text_length() const;
59 
60  enum purpose
61  get_purpose() const;
62 
63  void
65  bool const i_editable=true);
66 
67  void
69  enum purpose const i_purpose);
70 
71  void
72  set_text(
73  unsigned char const* i_str);
74 
75  // _mjo: fixme a signal is not emitted
76  void
78  signal_changed_t i_signal);
79 
80 protected:
81 
83  size_t m_caret;
84  size_t m_offset;
85  size_t m_slot;
86  size_t m_length;
87  size_t m_block_size;
88  unsigned char* m_block;
89  bool m_editable;
91 
92  void
93  show_cursor();
94 
95  void
96  grow(
97  size_t const i_needed);
98 
99  virtual void
100  get_bbox(
101  struct box& o_bbox) const;
102 
103  int
104  pos_inc();
105 
106  int
107  pos_dec();
108 
109  void
110  del();
111 
112  void
113  ins(
114  unsigned char const i_char);
115 
116  void
117  ovw(
118  unsigned char const i_char);
119 
120  bool
121  validate(
122  unsigned char const i_char);
123 
124  void
125  caret_set_position() const;
126 
127  void
128  emit_changed();
129 
130 private:
131 
132  entry();
133 
134  entry(
135  const entry&);
136 
137  entry&
138  operator=(entry const&);
139 
140 };
141 
142 inline unsigned char const*
144 {
145  m_block[m_length]= 0;
146  return m_block;
147 }
148 
149 inline size_t
151 {
152  return m_length;
153 }
154 
155 inline enum entry::purpose
157 {
158  return m_purpose;
159 }
160 
161 inline void
163  enum purpose const i_purpose)
164 {
165  m_purpose= i_purpose;
166  return;
167 }
168 
169 inline void
171  struct box& o_bbox) const
172 {
173  o_bbox= m_box;
174 }
175 
176 inline void
178  bool const i_editable)
179 {
180  m_editable= i_editable;
181  return;
182 }
183 
184 inline void
186  signal_changed_t i_signal)
187 {
188  m_signal_changed= i_signal;
189  return;
190 }
191 
192 inline void
194 {
195 
196  if (m_signal_changed)
197  {
198  (*m_signal_changed)(this, m_user_data);
199  }
200 
201  return;
202 }
203 
204 inline void
206 {
207  // fixme: if widget is disabled
208  if (m_editable)
209  {
211  {
212  cursor_block();
213  }
214  else
215  {
217  }
218  }
219  else
220  {
221  cursor_hide();
222  }
223 
224  return;
225 }
226 
227 #define __entry_hpp__
228 #endif
void show_cursor()
sets the cursor type/shape. Cursor shape depends on the state of the cursor (insert/overwrite) and wi...
Definition: entry.hpp:205
void set_text(unsigned char const *i_str)
set the text of the entry
Definition: entry.cpp:526
void del()
delete character at current position from the buffer
Definition: entry.cpp:153
virtual ~entry()
destructor
Definition: entry.cpp:41
contains widget class
Definition: entry.hpp:29
void cursor_block()
sets the cursor shape to a solid block
Definition: djgpp/cursor.c:60
unsigned char const * get_text() const
get text buffer
Definition: entry.hpp:143
Definition: entry.hpp:27
int pos_inc()
increments position (m_caret, m_slot, m_offset)
Definition: entry.cpp:460
struct box m_box
Definition: widget.hpp:171
virtual void draw() const
draws the widget
Definition: entry.cpp:50
void caret_set_position() const
moves the cursor to the current position (m_caret)
Definition: entry.cpp:432
int pos_dec()
decrements position (m_caret, m_slot, m_offset)
Definition: entry.cpp:500
base class for all derived widgets
Definition: widget.hpp:19
Definition: entry.hpp:28
void ins(unsigned char const i_char)
insert character at current position into the buffer
Definition: entry.cpp:192
virtual void focus_leave()
handle leaving focus
Definition: entry.cpp:426
virtual void focus_enter()
handle entering focus
Definition: entry.cpp:419
bool m_editable
Definition: entry.hpp:89
size_t m_block_size
Definition: entry.hpp:87
enum purpose get_purpose() const
get the text entry purpose
Definition: entry.hpp:156
virtual void get_bbox(struct box &o_bbox) const
get the inner bounding box param[out] o_bbox bounding box to fill
Definition: entry.hpp:170
void set_signal_changed(signal_changed_t i_signal)
set callback
Definition: entry.hpp:185
size_t m_length
Definition: entry.hpp:86
Definition: entry.hpp:26
void set_purpose(enum purpose const i_purpose)
set the input purpose
Definition: entry.hpp:162
size_t m_offset
Definition: entry.hpp:84
size_t m_slot
Definition: entry.hpp:85
Definition: entry.hpp:25
void * m_user_data
Definition: widget.hpp:173
void cursor_underline()
sets the cursor shape to underline
Definition: djgpp/cursor.c:47
Allows a user to enter text.
Definition: entry.hpp:14
void(* signal_changed_t)(entry const *i_entry, void *io_user_data)
function prototype to recieve signal
Definition: entry.hpp:19
event_response
response
Definition: event.h:14
void cursor_hide()
hide the cursor
Definition: djgpp/cursor.c:34
bool validate(unsigned char const i_char)
validates a character against the widgets purpose
Definition: entry.cpp:258
unsigned char * m_block
Definition: entry.hpp:88
size_t m_caret
Definition: entry.hpp:83
void set_editable(bool const i_editable=true)
set whether or not the entry is editable
Definition: entry.hpp:177
purpose
indicator of the type of input the entry can accept
Definition: entry.hpp:23
virtual enum event_response event_key(struct event_key const &i_event)
handle key event
Definition: entry.cpp:325
enum purpose m_purpose
Definition: entry.hpp:82
signal_changed_t m_signal_changed
Definition: entry.hpp:90
size_t get_text_length() const
get the number of characters in the text buffer
Definition: entry.hpp:150
enum cursor_mode _cursor_mode
global to hold the mode of the cursor
Definition: djgpp/cursor.c:15
void grow(size_t const i_needed)
grow internal buffer
Definition: entry.cpp:105
void ovw(unsigned char const i_char)
insert character at current position into the buffer
Definition: entry.cpp:238
Definition: cursor.h:25
defines a rectangular region
Definition: box.h:12
void emit_changed()
emit the changed signal
Definition: entry.hpp:193
container for a keyboard event
Definition: event.h:23