1 // This may look like C code, but it is really -*- C++ -*- 2 3 // ------------------------------------------------------------------ 4 // The Goldware Library 5 // Copyright (C) 1990-1999 Odinn Sorensen 6 // Copyright (C) 1999-2000 Alexander S. Aganichev 7 // ------------------------------------------------------------------ 8 // This library is free software; you can redistribute it and/or 9 // modify it under the terms of the GNU Library General Public 10 // License as published by the Free Software Foundation; either 11 // version 2 of the License, or (at your option) any later version. 12 // 13 // This library is distributed in the hope that it will be useful, 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 // Library General Public License for more details. 17 // 18 // You should have received a copy of the GNU Library General Public 19 // License along with this program; if not, write to the Free 20 // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21 // MA 02111-1307, USA 22 // ------------------------------------------------------------------ 23 // $Id: gwinput.h,v 1.1 2011/02/18 19:46:02 stas_degteff Exp $ 24 // ------------------------------------------------------------------ 25 // GCUI: Golded+ Character-oriented User Interface. 26 // Class gwinput: Input form and field editing (declarations). 27 // ------------------------------------------------------------------ 28 29 #ifndef __gwinput_h 30 #define __gwinput_h 31 32 33 // ------------------------------------------------------------------ 34 35 #include <gwindow.h> 36 37 38 // ------------------------------------------------------------------ 39 40 class gwinput { 41 42 public: 43 44 class field { 45 46 public: 47 48 gwinput* form; 49 50 int pos; 51 int max_pos; 52 vattr attr; 53 bool fill_acs; 54 vchar fill; 55 int entry; 56 57 char* buf; 58 int buf_left_pos; 59 int buf_end_pos; 60 int buf_pos; 61 int buf_len; 62 63 std::string& destination; 64 65 int id; 66 int row; 67 int column; 68 int max_column; 69 int conversion; 70 int entry_mode; 71 72 field* prev; 73 field* next; 74 75 field(gwinput* iform, int idnum, int wrow, int wcol, int field_width, std::string& dest, int dest_size, int cvt, int mode); 76 ~field(); 77 78 bool visible(); 79 80 void move_left(); 81 void move_right(); 82 83 bool left(); 84 bool right(); 85 bool left_word(); 86 bool right_word(); 87 bool delete_left(); 88 bool delete_char(); 89 bool delete_word(bool left); 90 bool insert_char(char ch); 91 bool overwrite_char(char ch); 92 bool home(); 93 bool end(); 94 95 void update(); 96 void activate(); 97 void deactivate(); 98 99 void restore(); 100 void commit(); 101 102 void convert(); 103 bool adjust_mode(); 104 void conditional(); 105 106 void move_cursor(); 107 void draw(int from_pos=0); 108 109 void clear_field(); 110 111 void clipboard_paste(); 112 void clipboard_copy(); 113 }; 114 115 field* first_field; 116 field* current; 117 118 enum { 119 entry_new, 120 entry_update, 121 entry_conditional, 122 entry_noedit 123 }; 124 125 enum { 126 cvt_none, 127 cvt_lowercase, 128 cvt_uppercase, 129 cvt_mixedcase 130 }; 131 132 vattr idle_attr; 133 vattr active_attr; 134 vattr edit_attr; 135 bool fill_acs; 136 137 vchar idle_fill; 138 vchar active_fill; 139 vchar edit_fill; 140 141 int insert_mode; 142 143 int done; 144 int dropped; 145 146 int start_id; 147 148 bool cursor_was_hidden; 149 150 gwindow &window; 151 152 gwinput(gwindow &w); 153 virtual ~gwinput(); 154 155 void setup(vattr i_attr, vattr a_attr, vattr e_attr, vchar fill, bool fill_acs); 156 157 void add_field(int idnum, int wrow, int wcol, int field_width, std::string& dest, int dest_size, int cvt=gwinput::cvt_none, int mode=gwinput::entry_conditional); 158 159 bool first(int id=0); 160 bool next(); 161 bool previous(); 162 bool last(); 163 164 bool first_visible(); 165 bool next_visible(); 166 bool previous_visible(); 167 bool last_visible(); 168 169 bool move_to(int wrow, int wcol); 170 171 field* field_at(int wrow, int wcol); 172 field* get_field(int id); 173 174 void draw_all(); 175 void reload_all(); 176 void show_cursor(); 177 178 void drop_form(); 179 void form_complete(); 180 void field_complete(); 181 void go_next_field(); 182 void go_previous_field(); 183 void go_up(); 184 void go_down(); 185 void go_left(); 186 void go_right(); 187 void delete_left(); 188 void delete_char(); 189 void go_field_begin(); 190 void go_field_end(); 191 void go_form_begin(); 192 void go_form_end(); 193 void toggle_insert(); 194 void restore_field(); 195 void delete_left_word(); 196 void delete_right_word(); 197 void go_left_word(); 198 void go_right_word(); 199 void enter_char(char ch); 200 201 void prepare_form(); 202 void finish_form(); 203 204 void clear_field(); 205 206 void clipboard_cut(); 207 void clipboard_paste(); 208 void clipboard_copy(); 209 210 bool handle_key(gkey key); 211 212 // These are supposed to be overridden by the inheriting class 213 virtual bool handle_other_keys(gkey& key); 214 virtual bool validate(); 215 virtual void before(); 216 virtual void after(); 217 }; 218 219 220 // ------------------------------------------------------------------ 221 222 class gwinput2 : public gwinput { 223 224 public: 225 gwinput2(gwindow & w)226 gwinput2(gwindow &w) : gwinput(w) { } 227 228 bool run(int helpcat); 229 }; 230 231 232 // ------------------------------------------------------------------ 233 234 #endif 235 236 // ------------------------------------------------------------------ 237