File: widget_utils.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 (132 lines) | stat: -rw-r--r-- 3,076 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

/*
 *  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: widget_utils.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"

int get_astr_size(Widget *w)
{
	_D( "get_astr_size() ");
	
	if (w->widget_fn == menu_fn) {
		Wmenu	*m;
		m = (Wmenu *) w->widget_data;
		return m->astr_size;
	} else  if (w->widget_fn == button_fn) {
		Wbutton	*b;
		b = (Wbutton *) w->widget_data;
		return b->astr_size;
	} else if (w->widget_fn == radio_fn) {
		Wradio	*r;
		r = (Wradio *) w->widget_data;
		return r->astr_size;
	} else  if (w->widget_fn == input_fn) {
		Winput	*inp;
		inp = (Winput *) w->widget_data;
		return inp->astr_size;
	}
	return FALSE;
}

/*
	Init astr or str list  (set locale strings)
	- return max width of string in list   
*/
int init_str_list(char **list, int num, int flag, char *text_domain)
{
	char 	**p;
	int	max=0, i;
	
	_D(" init_str_list() ");
	
	for(p=list; p <= list + num; p++) {
		*p = _aca(*p);
		if (flag & M_ALIST) {
			if ((i=astrlen(*p)) > max)
				max = i; 
		} else if (flag & M_SLIST) {
			if ((i=strlen(*p)) > max)
				max = i; 
		}	
	}
	return max;	
}

void W_mvaddastr(Widget *w, int m, int n, char *astr, int c, int c2) 
{	
	_D(" W_mvaddastr()");
	
	if (!(w->flag & Wf_NOTUSE_ASTR)) { 	
		mvaddastr(m, n, astr, c, c2);	
	} else {				
		aca_c(c2);			
		mvaddstr(m, n, astr);		
	}					
}

int is_mouse_in_widget(Widget *w, SessW *s) 
{   
#ifdef HAVE_MOUSE
	Wmenu	*m;
	  
	_D(" is_mouse_in_widget()");   
	   
	if (!aca.mouse) 
   		return FALSE;
	
	/* is actual widget over widget *w ? */
	if (s->actual != w->id) {
		if ((*(s->wtab+s->actual)).widget_fn == menu_fn) {
   			if (is_mouse_in_menu(s, (s->wtab+s->actual), 
   				(Wmenu *) (*(s->wtab+s->actual)).widget_data))
   				return FALSE;
		} else if (is_mouse_in_widget((s->wtab+s->actual), s)) 
			return FALSE;
	}
   	if (w->widget_fn == menu_fn) {
   		m = (Wmenu *) w->widget_data;
   		return is_mouse_in_menu(s, w, m); 
   	} else if (aca.mouse_x >= w->x && aca.mouse_x <= w->cols+w->x &&
   	    		aca.mouse_y >= w->y && aca.mouse_y <= w->lines+w->y)
   		return TRUE;
#endif   		
   	return FALSE;	
} 
   
int widget_keys(int key, Widget *w, SessW *s) 
{		
	_D(" widget_keys()");

#ifdef HAVE_MOUSE         
         if (!(w->flag & Wf_NOTVISIBLE) && 
             ((key == K_MOUSE_L) && is_mouse_in_widget(w, s))) {
         	set_widget(s->wtab, s, w->id);
         	return TRUE;
         }	
         else 
#endif         
         if (w->hotkey && s->lock != HOTKEY_LOCK) {
            	if ((w->hotkey == key) ||             	
            	    (w->hotkey == tolower(key)) ) {
            		set_widget(s->wtab, s, w->id);
            		return TRUE;
            	}	
         }	
         return FALSE;	
}