00001
00002
00003
00004
00005
00006
00007 #ifndef CIO_H
00008 #define CIO_H
00009
00010 #include "enum.h"
00011 #include "externs.h"
00012 #include "defines.h"
00013 #include "directn.h"
00014
00015 #include <cctype>
00016 #include <string>
00017 #include <vector>
00018
00019 class input_history
00020 {
00021 public:
00022 input_history(size_t size);
00023
00024 void new_input(const std::string &s);
00025 void clear();
00026
00027 const std::string *prev();
00028 const std::string *next();
00029
00030 void go_end();
00031 private:
00032 typedef std::list<std::string> string_list;
00033
00034 string_list history;
00035 string_list::iterator pos;
00036 size_t maxsize;
00037 };
00038
00039 void cursorxy(int x, int y);
00040 inline void cursorxy(const coord_def& p) { cursorxy(p.x, p.y); }
00041
00042
00043
00044 int m_getch();
00045
00046
00047
00048
00049 int unmangle_direction_keys(int keyin, KeymapContext keymap = KMC_DEFAULT,
00050 bool fake_ctrl = true, bool fake_shift = true);
00051
00052 int nowrapcprintf(int wrapcol, const char *s, ...);
00053 int nowrap_eol_cprintf(const char *s, ...);
00054
00055
00056
00057
00058
00059
00060
00061 int cancelable_get_line(char *buf,
00062 int len,
00063 input_history *mh = NULL,
00064 int (*keyproc)(int &c) = NULL);
00065
00066
00067 template<int> static int cancelable_get_line_autohist_temp(char *buf, int len)
00068 {
00069 static input_history hist(10);
00070 return cancelable_get_line(buf, len, &hist);
00071 }
00072
00073
00074
00075 #define cancelable_get_line_autohist(buf, len) \
00076 cancelable_get_line_autohist_temp<__LINE__>(buf, len)
00077
00078 struct c_mouse_event
00079 {
00080 coord_def pos;
00081 int bstate;
00082
00083 enum button_state_type
00084 {
00085 BUTTON1 = 0x1,
00086 BUTTON1_DBL = 0x2,
00087 BUTTON2 = 0x4,
00088 BUTTON2_DBL = 0x8,
00089 BUTTON3 = 0x10,
00090 BUTTON3_DBL = 0x20,
00091 BUTTON4 = 0x40,
00092 BUTTON4_DBL = 0x80,
00093 BUTTON_SCRL_UP = 0x100,
00094 BUTTON_SCRL_DN = 0x200,
00095 };
00096
00097 c_mouse_event() : pos(-1, -1), bstate(0)
00098 {
00099 }
00100
00101 c_mouse_event(const coord_def &c, int state = 0) : pos(c), bstate(state)
00102 {
00103 }
00104
00105
00106 operator bool () const
00107 {
00108 return (bstate);
00109 }
00110
00111 bool left_clicked() const
00112 {
00113 return (bstate & BUTTON1);
00114 }
00115
00116 bool right_clicked() const
00117 {
00118 return (bstate & BUTTON3);
00119 }
00120
00121 bool scroll_up() const
00122 {
00123 return (bstate & (BUTTON4 | BUTTON4_DBL | BUTTON_SCRL_UP));
00124 }
00125
00126 bool scroll_down() const
00127 {
00128 return (bstate & (BUTTON2 | BUTTON2_DBL | BUTTON_SCRL_DN));
00129 }
00130 };
00131
00132 coord_def get_mouse_pos();
00133 c_mouse_event get_mouse_event();
00134 void new_mouse_event(const c_mouse_event &ce);
00135 void c_input_reset(bool enable_mouse, bool flush = false);
00136
00137
00138 enum KEYS
00139 {
00140 CK_ENTER = '\r',
00141 CK_BKSP = 8,
00142 CK_ESCAPE = ESCAPE,
00143
00144
00145 CK_DELETE = 129,
00146
00147
00148 CK_UP,
00149 CK_DOWN,
00150 CK_LEFT,
00151 CK_RIGHT,
00152
00153 CK_INSERT,
00154
00155 CK_HOME,
00156 CK_END,
00157 CK_CLEAR,
00158
00159 CK_PGUP,
00160 CK_PGDN,
00161
00162 CK_SHIFT_UP,
00163 CK_SHIFT_DOWN,
00164 CK_SHIFT_LEFT,
00165 CK_SHIFT_RIGHT,
00166
00167 CK_SHIFT_INSERT,
00168
00169 CK_SHIFT_HOME,
00170 CK_SHIFT_END,
00171 CK_SHIFT_CLEAR,
00172
00173 CK_SHIFT_PGUP,
00174 CK_SHIFT_PGDN,
00175
00176 CK_CTRL_UP,
00177 CK_CTRL_DOWN,
00178 CK_CTRL_LEFT,
00179 CK_CTRL_RIGHT,
00180
00181 CK_CTRL_INSERT,
00182
00183 CK_CTRL_HOME,
00184 CK_CTRL_END,
00185 CK_CTRL_CLEAR,
00186
00187 CK_CTRL_PGUP,
00188 CK_CTRL_PGDN,
00189
00190
00191 CK_MOUSE_MOVE = 10001,
00192 CK_MOUSE_CMD,
00193 CK_MOUSE_B1,
00194 CK_MOUSE_B2,
00195 CK_MOUSE_B3,
00196 CK_MOUSE_B4,
00197 CK_MOUSE_B5,
00198 CK_MOUSE_CLICK,
00199 };
00200
00201 class cursor_control
00202 {
00203 public:
00204 cursor_control(bool cursor_enabled)
00205 : cstate(is_cursor_enabled()), smartcstate(is_smart_cursor_enabled())
00206 {
00207 enable_smart_cursor(false);
00208 set_cursor_enabled(cursor_enabled);
00209 }
00210 ~cursor_control() {
00211 set_cursor_enabled(cstate);
00212 enable_smart_cursor(smartcstate);
00213 }
00214 private:
00215 bool cstate;
00216 bool smartcstate;
00217 };
00218
00219
00220 class line_reader
00221 {
00222 public:
00223 line_reader(char *buffer, size_t bufsz,
00224 int wrap_col = get_number_of_cols());
00225 virtual ~line_reader();
00226
00227 typedef int (*keyproc)(int &key);
00228
00229 int read_line(bool clear_previous = true);
00230
00231 std::string get_text() const;
00232
00233 void set_input_history(input_history *ih);
00234 void set_keyproc(keyproc fn);
00235
00236 protected:
00237 void cursorto(int newcpos);
00238 virtual int process_key(int ch);
00239 void backspace();
00240 void killword();
00241 void kill_to_begin();
00242
00243 bool is_wordchar(int c);
00244
00245 protected:
00246 char *buffer;
00247 size_t bufsz;
00248 input_history *history;
00249 GotoRegion region;
00250 coord_def start;
00251 keyproc keyfn;
00252 int wrapcol;
00253
00254
00255 char *cur;
00256 int length;
00257 int pos;
00258 };
00259
00260 typedef int keycode_type;
00261
00262 #endif