1
/* Copyright (C) 1995 Bjoern Beutel. */
3
/* Description. =============================================================*/
5
/* Read in and display Malaga Variables. */
7
/* Includes. ================================================================*/
21
#include "variables.h"
23
/* Types. ===================================================================*/
40
/* Global variables. ========================================================*/
42
rectangle_t variables_geometry;
43
string_t variables_font_name;
44
int_t variables_font_size;
46
/* Variables. ===============================================================*/
48
static list_t variables;
49
static list_t hidden_vars;
50
static canvas_t *variables_canvas;
51
static pos_string_t *equal, *dots;
53
/* Functions. ===============================================================*/
56
configure_variables( canvas_t *canvas, int_t *width_p, int_t *height_p )
60
int_t font_height = get_font_height( canvas );
61
int_t space_width = get_space_width( canvas );
62
int_t border_width = get_border_width( canvas );
64
config_pos_string( equal, canvas );
65
config_pos_string( dots, canvas );
67
width = height = border_width;
68
FOREACH( variable, variables )
70
if (variable != (variable_t *) variables.first)
71
height += font_height;
73
config_pos_string( variable->name, canvas );
74
variable->name->x = border_width;
75
variable->name->y = height;
76
equal->x = variable->name->x + variable->name->width + space_width;
77
if (variable->is_shown)
79
config_pos_value( variable->value, canvas );
80
variable->value->x = equal->x + equal->width + space_width;
81
variable->value->y = height;
82
variable->name->y += (variable->value->height - font_height) / 2;
83
width = MAX( width, variable->value->x + variable->value->width );
84
height += variable->value->height;
88
dots->x = equal->x + equal->width + space_width;
89
width = MAX( width, dots->x + dots->width );
90
height += font_height;
94
*width_p = width + border_width;
95
*height_p = height + border_width;
98
/*---------------------------------------------------------------------------*/
101
expose_variables( canvas_t *canvas, rectangle_t *area )
103
int_t space_width = get_space_width( canvas );
104
variable_t *variable;
107
FOREACH( variable, variables )
109
draw_pos_string( variable->name, canvas );
110
equal->x = variable->name->x + variable->name->width + space_width;
111
equal->y = variable->name->y;
112
draw_pos_string( equal, canvas );
113
if (variable->is_shown)
114
draw_pos_value( variable->value, canvas );
117
dots->x = equal->x + equal->width + space_width;
119
draw_pos_string( dots, canvas );
124
/*---------------------------------------------------------------------------*/
127
show_variable( variable_t *variable, bool_t do_show )
129
hidden_var_t *hidden_var;
131
if (variable->is_shown == do_show)
135
/* Remove the variable in the list of hidden variables. */
136
FOREACH( hidden_var, hidden_vars )
138
if (strcmp_no_case( hidden_var->name, variable->string ) == 0)
141
free_mem( &hidden_var->name );
142
free_node( &hidden_vars, (list_node_t *) hidden_var );
146
/* Add the variable to the list of hidden variables. */
147
hidden_var = new_node( &hidden_vars, sizeof( hidden_var_t ), LIST_END );
148
hidden_var->name = new_string( variable->string, NULL );
150
variable->is_shown = do_show;
153
/*---------------------------------------------------------------------------*/
156
mouse_event( canvas_t *canvas, int_t x, int_t y, int_t button )
157
/* Called if pointer has entered CANVAS at position (X,Y),
158
* if mouse has been moved to position (X,Y),
159
* or if BUTTON has been pressed at position (X,Y). */
161
variable_t *variable;
162
int_t font_height = get_font_height( canvas );
164
FOREACH( variable, variables )
166
if (x >= variable->name->x && x < variable->name->x + variable->name->width
167
&& y >= variable->name->y && y < variable->name->y + font_height)
171
show_variable( variable, ! variable->is_shown );
172
configure_canvas( canvas );
175
set_cursor( canvas, TRUE );
179
set_cursor( canvas, FALSE );
183
/*---------------------------------------------------------------------------*/
186
show_all_variables( canvas_t *canvas, guint do_show )
188
variable_t *variable;
190
FOREACH( variable, variables )
191
show_variable( variable, do_show );
192
configure_canvas( canvas );
195
/*---------------------------------------------------------------------------*/
197
static GtkItemFactoryEntry menu_items[] =
199
{ "/Variables", NULL, NULL, 0, "<Branch>" },
200
{ "/Variables/Show All", NULL, show_all_variables, TRUE, NULL },
201
{ "/Variables/Hide All", NULL, show_all_variables, FALSE, NULL },
204
/*---------------------------------------------------------------------------*/
206
static void free_variables( canvas_t *canvas )
208
variable_t *variable;
210
free_pos_string( &equal );
211
free_pos_string( &dots );
212
FOREACH_FREE( variable, variables )
214
free_mem( &variable->string );
215
free_pos_string( &variable->name );
216
free_pos_value( &variable->value );
220
/*---------------------------------------------------------------------------*/
223
read_variables( void )
224
/* Read new variables from STDIN. */
227
variable_t *variable;
228
hidden_var_t *hidden_var;
230
free_variables( NULL );
234
line = read_line( stdin );
236
complain( "Premature EOF." );
237
if (strcmp_no_case( line, "end" ) == 0)
240
/* Read a new variable. */
241
variable = new_node( &variables, sizeof( variable_t ), LIST_END );
242
set_scanner_input( line );
244
/* Read variable name. */
245
test_token( TOK_STRING );
246
variable->name = new_pos_string( token_string );
247
variable->string = new_string( token_string, NULL );
250
/* Read variable value. */
252
variable->value = parse_pos_value();
255
set_scanner_input( NULL );
258
/* Check if variable is to be shown. */
259
FOREACH( hidden_var, hidden_vars )
261
if (strcmp_no_case( hidden_var->name, variable->string ) == 0)
264
variable->is_shown = (hidden_var == NULL);
268
equal = new_pos_string( "=" );
269
dots = new_pos_string( "..." );
271
if (variables_canvas == NULL)
273
variables_canvas = create_canvas(
274
"Malaga Variables", "variables.eps", &variables_geometry,
275
configure_variables, expose_variables, free_variables, mouse_event,
276
TRUE, menu_items, sizeof( menu_items ) / sizeof( menu_items[0] ) );
280
configure_canvas( variables_canvas );
281
show_canvas( variables_canvas );
285
/* End of file. =============================================================*/