File: input.c

package info (click to toggle)
aca 0.1.6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 492 kB
  • ctags: 569
  • sloc: ansic: 4,254; sh: 2,237; makefile: 256
file content (210 lines) | stat: -rw-r--r-- 6,303 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210

/*
 *  Copyright (c) 1998 - 1999, 2001 Karel Zak "Zakkr" <zakkr@zf.jcu.cz>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  $Id: input.c,v 1.2 2001/01/02 14:16:15 zakkr Exp $
 */


#include <ctype.h>

#include "aca.h"
#include "aca_widget.h"
#include "widget_utils.h"


   void input_to_str(Winput *i, int key)
   {
      int	a;
   
   #ifdef HAVE_MOUSE
      if (key == K_MOUSE_L || key == K_MOUSE_M || key ==K_MOUSE_R || 
          key == K_STAY) 
      		return;
      else 
   #endif    
   
      if (key == XCTRL('a') || key == KEY_HOME)
         i->poz = 0;
      else if (key == KEY_END)
         i->poz = i->a_size; 
      else if (key == KEY_LEFT && i->poz > 0) 
         --i->poz;
      else if (key == KEY_RIGHT && i->poz < i->max && i->poz < i->a_size) 
         ++i->poz; 
      else if (key == KEY_BACKSPACE && i->poz > 0) {
         for(a=--i->poz; a < i->a_size; a++) 
            i->str[a] = i->str[a+1];
         --i->a_size;	
      }
      else if (key == KEY_DC && i->poz < i->a_size ) {
         for(a=i->poz; a < i->a_size; a++) 
            i->str[a] = i->str[a+1];
         --i->a_size;	
      }
      else {
         if (key == '\t') 
            return;
         if (isfunckey( key )) 
            return;
         if (aca.output_7bit_only && !isascii(key))  
            key = ' ';
         if (i->poz < i->a_size) 
            for(a=++i->a_size; a>=i->poz+1; a--) 
               i->str[a] = i->str[a-1];
         i->str[i->poz] = key;
         if (i->poz < i->max) ++i->poz;
         if (i->poz > i->a_size) i->a_size = i->poz;			
      }
      i->str[i->a_size] = '\0';
   }

   int input_fn(SessW *s, Widget *w, void *data, int key, int Msg)
   {
      Winput	*i;
      int	a=0;			
      i = (Winput *) data;
   
      _D(" input_fn()");
      DEBUG_WIDGET(w,s);
      
      if (i->flag & Wi_TOP) a=1;
   
      ubold;
   
      switch(Msg) {
      case WIDGET_DRAW:
         if (w->id == s->actual) {
            W_mvaddastr(w, w->y, w->x, i->astr, TplC->input.title_sel_astr, TplC->input.title_sel); 
            curs_set(TRUE);
            clean_hline(w->y+a, w->x +i->astr_size, i->max, TplC->input.sel);	 
            mvaddstr(w->y+a, w->x+i->astr_size, i->str);
            move(w->y+a, w->x + i->astr_size + i->poz);
            s->lock = HOTKEY_LOCK;
         } 
         else if (!(w->flag & Wf_NOTVISIBLE)) {	
            W_mvaddastr(w, w->y, w->x, i->astr, TplC->input.title_nsel_astr, TplC->input.title_nsel);
            curs_set(FALSE);
            clean_hline(w->y+a, w->x + i->astr_size, i->max, TplC->input.nsel);	 
            mvaddstr(w->y+a, w->x + i->astr_size, i->str);
         }
         return Wr_OK;
      case WIDGET_KEY:
         if (w->id == s->actual) {
            if (key==KEY_DOWN || key==KEY_UP || key=='\n' || key=='\t') {
               s->lock = UN_LOCK;
               return Wr_OK;
            } 
            else 
               s->lock = HOTKEY_LOCK;	
         
         #ifdef HAVE_MOUSE            
            if (key == K_MOUSE_L && is_mouse_in_widget(w, s)) {   
            	if (aca.mouse_x >= w->x+i->astr_size && aca.mouse_x <= i->max+i->astr_size+w->x)
            		i->poz = (aca.mouse_x - w->x - i->astr_size) > i->a_size ?
            				i->a_size : aca.mouse_x - w->x -i->astr_size;
            }
         #endif    
         
            input_to_str(i, key);
         
            clean_hline(w->y+a, w->x + i->astr_size, i->max, TplC->input.sel);	 
            mvaddstr(w->y+a, w->x + i->astr_size, i->str);
            move(w->y+a, w->x + i->poz + i->astr_size);
            return Wr_INPUT_CHANGE;
         } 
         else
            widget_keys(key, w, s);	 
         return Wr_OK;
      }
      return Wr_ERROR;
   }

/*
	Input func. for M_EDIT flag
*/	
   int input_to_line(Wmenu *m, Edata *e, Widget *w, int key)
   {
      int	a, 
      item=0;
   
   #ifdef HAVE_MOUSE
      if (key == K_MOUSE_L || key == K_MOUSE_M || key ==K_MOUSE_R || 
          key == K_STAY) 
      		return FALSE;
      else 
   #endif    
   
      if (key == KEY_BACKSPACE || key == KEY_DC)
         item = get_linepoz(e->str, m->item_act, e->c_poz);
   
      if (key == KEY_BACKSPACE && item > 0) {
         for(a=item-1; a < e->bufsiz; a++) 
            e->str[a] = e->str[a+1];
         --e->a_size;
         e->str[e->a_size] = '\0';	   
         if (e->c_poz == 0) {
            int old_len = e->line_act_len;
            menu_seek(m, w, KEY_UP, DUMMY_GO); 
            init_edit(m, e);
            clean_menu(m, w);	
            e->c_poz = e->line_act_len - old_len; 
         } 
         else {
            --e->c_poz;
            --e->line_act_len;
         } 	
      }
      else if (key == KEY_DC && e->c_poz < e->bufsiz ) {
         for(a=item; a < e->bufsiz; a++) 
            e->str[a] = e->str[a+1];
         --e->a_size;
         e->str[e->a_size] = '\0';	
         if (e->c_poz == e->line_act_len) {
            init_edit(m, e);
            clean_menu(m, w);
         } 
         else 
            --e->line_act_len;
      }
      else {
         if (e->a_size + 1 >= e->bufsiz)
            return FALSE;
         if (key == '\t') 
            return FALSE;
         if (isfunckey( key )) 
            return FALSE;
         if (aca.output_7bit_only && !isascii(key))  
            key = ' ';
      
         item = get_linepoz(e->str, m->item_act, e->c_poz);
      
         if (item < e->a_size) {
            for(a=e->a_size+1; a >= item+1; a--) 
               e->str[a] = e->str[a-1];
         }
         e->str[item] = key;
         ++e->a_size;
         e->str[e->a_size] = '\0';	
         if (key == '\n') { 
            init_edit(m, e);	
            menu_seek(m, w, KEY_HOME, DUMMY_GO); 
            menu_seek(m, w, KEY_DOWN, DUMMY_GO); 
         } 
         else {
            ++e->line_act_len;
            if (m->sht_max < e->line_act_len) 
            	m->sht_max = e->line_act_len;
            if (e->c_poz < w->cols-1)	
            	++e->c_poz;
            else if (m->sht_act <  m->sht_max - e->c_poz) 
            	++m->sht_act;	
         } 	
      }
      return TRUE;
   }