root/slw/abs_text_console.h

Revision 807, 3.2 kB (checked in by jaromil, 2 years ago)

slw: fixes, cleanup and testkey example

Line 
1 /*  Abstract text console class
2  *
3  *  (C) Copyright 2004-2006 Denis Rojo <jaromil@dyne.org>
4  *
5  * This source code is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Public License as published
7  * by the Free Software Foundation; either version 2 of the License,
8  * or (at your option) any later version.
9  *
10  * This source code is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * Please refer to the GNU Public License for more details.
14  *
15  * You should have received a copy of the GNU Public License along with
16  * this source code; if not, write to:
17  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * =========
20  * This class provides abstract functionalities for a text console with
21  * full editing scrolling and history. It makes use of linked lists and
22  * it is optimized for speed. It still misses word wrapping.
23  *
24  * It is a pure virtual class and as such needs to be inherited by a
25  * class implementing init() feed(int key) and refresh().
26  *
27  */
28
29 #ifndef __TEXT_CONSOLE_H__
30 #define __TEXT_CONSOLE_H__
31
32 #include <linklist.h>
33
34 #include <keycodes.h>
35
36 #define ROWCHUNK 128
37
38
39
40
41 class Row;
42
43 class TextConsole {
44
45  public:
46   TextConsole();
47   virtual ~TextConsole();
48  
49  
50   bool feed(int key);
51  
52   bool refresh(); ///< refresh all visible rows
53   void refresh_current(); ///< refresh row at current cursor position
54  
55   // pure virtual functions to be overloaded by the implementation
56  
57   virtual void blank() =0; ///< blank the whole screeen
58   virtual void blank_row(int r) =0; ///< blank screen at row
59
60   virtual int putnch(CHAR *str, int x, int y, int nchars) =0;
61   ///< draw a string of certain length at given x,y position
62  
63   ////////////////////////
64  
65  
66   int move_string(Row *dest, Row *src, int len);
67   ///< move a string from a row to another
68  
69   bool scroll; ///< if true we have vertical scrolling
70  
71   int w, h; ///< geometry
72  
73   int cur_x, cur_y; ///< cursor positioning
74  
75   Linklist rows;
76   Row *cur_row;
77   Row *vis_row_in;
78  
79  
80   // void refresh_row(int y);
81   ///< refresh row at position y
82  
83  
84   // void refresh_below();
85   ///< refresh all lines below the current cursor position
86  
87 };
88
89
90 class Row : public Entry {
91        
92  public:
93   Row();
94   ~Row();
95  
96   /** this class implements a couple of methods to insert and
97    * delete text in each row
98    * the property 'pos' in each row is the current position,
99    * meaning that operations are executed in that point
100    * call it 'procedural pointer?'
101    * it's just a way to save an argument in functions :)
102    */
103  
104   int insert_char(CHAR ch);
105   ///< insert a single char at current pos
106  
107   int insert_string(CHAR *str, int inlen);
108   ///< instert string at pos
109  
110   int delete_string(int dlen);
111   ///< delete a string right of current pos
112  
113   int backspace(); // deletes one char left of pos
114  
115   //            clear_right(int p); // clear all chars right of pos
116   //            clear_left(int p); // clear all chars left of pos
117  
118   int len;
119   int pos;
120  
121   CHAR *text;
122  
123  
124  private:
125   bool fit(int l); ///< realloc if necess. to fit in +len
126   int max; // current allocated maximum
127 };
128
129
130  
131
132 #endif
Note: See TracBrowser for help on using the browser.