FDOSTUI
FreeDOS Text User Interface
edit.hpp
Go to the documentation of this file.
1 /*
2  EDIT.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 __edit_hpp__
11 
12 #include "cursor.h"
13 #include "scrllbar.hpp"
14 #include "gapbuf.h"
15 
16 class edit : public widget
17 {
18 
19 public:
20 
21  edit(
22  int const i_pos_x,
23  int const i_pos_y,
24  unsigned int const i_len_x,
25  unsigned int const i_len_y);
26 
27  virtual
28  ~edit();
29 
30  virtual void
31  draw() const;
32 
33  virtual enum event_response
34  event_key(
35  struct event_key const& i_event);
36 
37  void
38  focus_enter();
39 
40  void
41  focus_leave();
42 
43  unsigned char const __FAR*
44  get_text();
45 
46  size_t
47  get_text_length() const;
48 
49 protected:
50 
51  size_t m_caret_x;
52  size_t m_caret_y;
54  size_t m_cursor;
55  size_t m_offset_x;
56  size_t m_line_top;
58  size_t m_lines;
59  struct gapbuf m_gap;
60 
61 private:
62 
63  edit();
64 
65  edit(
66  const edit&);
67 
68  edit&
69  operator=(edit const&);
70 
71  void
72  caret_set_position() const;
73 
74  bool
76 
77  bool
78  char_delete();
79 
80  bool
82  unsigned char const i_char,
83  enum cursor_mode const i_cursor_mode);
84  bool
86 
87  bool
88  cursor_down();
89 
90  bool
91  cursor_end();
92 
93  bool
94  cursor_home();
95 
96  bool
97  cursor_left();
98 
99  bool
100  cursor_right();
101 
102  void
103  cursor_show();
104 
105  bool
106  cursor_up();
107 
108  bool
110  unsigned char __FAR*& io_ptr,
111  size_t& io_offset,
112  int& io_pos_y) const;
113 };
114 
115 inline void
117 {
118 
120  {
121  cursor_block();
122  }
123  else
124  {
126  }
127 
128  return;
129 }
130 
131 inline unsigned char const __FAR*
133 {
134  unsigned char const __FAR* l_ptr;
135 
136  l_ptr= gapbuf_text(&m_gap);
137 
138  return l_ptr;
139 }
140 
141 inline size_t
143 {
144  size_t l_size;
145 
146  l_size= m_gap.m_block_size - (m_gap.m_end - m_gap.m_start);
147 
148  return l_size;
149 }
150 
151 #define __edit_hpp__
152 #endif
cursor_mode
mode of cursor such as overwrite or insert
Definition: cursor.h:23
size_t m_start
Definition: gapbuf.h:26
A dynamic text buffer implementing the gap buffer algorithm.
void cursor_block()
sets the cursor shape to a solid block
Definition: djgpp/cursor.c:60
void focus_enter()
handle entering focus
Definition: edit.cpp:678
manipulation of the screens cursor
void caret_set_position() const
moves the cursor to the current position (m_caret)
Definition: edit.cpp:48
Definition: gapbuf.h:22
size_t get_text_length() const
get the number of used bytes in the buffer
Definition: edit.hpp:142
contains scrollbar class
virtual void draw() const
draws the widget
Definition: edit.cpp:739
size_t m_offset_x
Definition: edit.hpp:55
bool char_backspace()
backspace
Definition: edit.cpp:69
bool cursor_down()
move cursor down a line
Definition: edit.cpp:284
base class for all derived widgets
Definition: widget.hpp:19
size_t m_end
Definition: gapbuf.h:27
virtual enum event_response event_key(struct event_key const &i_event)
handle key event
Definition: edit.cpp:841
bool cursor_left()
move cursor left
Definition: edit.cpp:472
bool cursor_end()
move cursor to end of line
Definition: edit.cpp:390
bool move_to_offset_x(unsigned char __FAR *&io_ptr, size_t &io_offset, int &io_pos_y) const
move to m_offset_x cursor position
Definition: edit.cpp:691
size_t m_caret_x
Definition: edit.hpp:51
Multi-line edit widget.
Definition: edit.hpp:16
void focus_leave()
handle leaving focus
Definition: edit.cpp:685
struct gapbuf m_gap
Definition: edit.hpp:59
void cursor_underline()
sets the cursor shape to underline
Definition: djgpp/cursor.c:47
size_t m_lines
Definition: edit.hpp:58
event_response
response
Definition: event.h:14
size_t m_line_top_offset
Definition: edit.hpp:57
size_t m_cursor
Definition: edit.hpp:54
bool char_delete()
delete character
Definition: edit.cpp:174
bool cursor_home()
move cursor to end of line
Definition: edit.cpp:444
size_t m_sticky_caret_x
Definition: edit.hpp:53
virtual ~edit()
destructor
Definition: edit.cpp:39
size_t m_block_size
Definition: gapbuf.h:25
size_t m_caret_y
Definition: edit.hpp:52
bool cursor_up()
move cursor up a line
Definition: edit.cpp:548
enum cursor_mode _cursor_mode
global to hold the mode of the cursor
Definition: djgpp/cursor.c:15
unsigned char const __FAR * get_text()
get the text buffer
Definition: edit.hpp:132
void cursor_show()
sets the cursor type/shape. Cursor shape depends on the state of the cursor (insert/overwrite) and wi...
Definition: edit.hpp:116
unsigned char const __FAR * gapbuf_text(struct gapbuf *const io_gap)
get the text buffer
Definition: gapbuf.c:403
bool char_insert_newline()
insert new line character
Definition: edit.cpp:247
bool char_insert(unsigned char const i_char, enum cursor_mode const i_cursor_mode)
insert character
Definition: edit.cpp:204
Definition: cursor.h:25
size_t m_line_top
Definition: edit.hpp:56
container for a keyboard event
Definition: event.h:23
bool cursor_right()
move cursor right
Definition: edit.cpp:506