Applied patch from Ivan Stankovic that displays entered characters in
[geda-gaf.git] / libgeda / src / s_toplevel.c
blob889ea0b955a39e77d2183bedc2cf1323ba3f18e9
1 /* gEDA - GPL Electronic Design Automation
2 * libgeda - gEDA's library
3 * Copyright (C) 1998, 1999, 2000 Kazu Hirata / Ales Hvezda
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program 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. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
19 #include <config.h>
21 #include <stdio.h>
22 #ifdef HAVE_STRING_H
23 #include <string.h>
24 #endif
25 #ifdef HAVE_STRARG_H
26 #include <stdarg.h>
27 #endif
28 #ifdef HAVE_STDLIB_H
29 #include <stdlib.h>
30 #endif
32 #include <gtk/gtk.h>
33 #include <libguile.h>
35 #include "defines.h"
36 #include "struct.h"
37 #include "globals.h"
38 #include "funcs.h"
40 #include "../include/prototype.h"
42 #ifdef HAVE_LIBDMALLOC
43 #include <dmalloc.h>
44 #endif
46 /* global_wid always increments, it needs to be unique per run */
47 static int global_wid = 0;
49 /* head pointer to toplevel structure, this points to all the toplevels that
50 currently exist */
51 static TOPLEVEL *toplevel_head = NULL;
53 /*! \todo Finish function documentation!!!
54 * \brief
55 * \par Function Description
58 void s_toplevel_init (void)
60 toplevel_head = (TOPLEVEL*)g_new (TOPLEVEL, 1);
61 toplevel_head->wid = -1;
62 toplevel_head->next = NULL;
63 toplevel_head->prev = NULL;
66 /*! \todo Finish function documentation!!!
67 * \brief
68 * \par Function Description
71 TOPLEVEL *s_toplevel_new (void)
73 TOPLEVEL *toplevel, *tmp;
75 toplevel = (TOPLEVEL*)g_new (TOPLEVEL, 1);
77 toplevel->wid = global_wid++;
79 toplevel->num_untitled = 0;
81 toplevel->start_x = -1;
82 toplevel->start_y = -1;
83 toplevel->save_x = -1;
84 toplevel->save_y = -1;
85 toplevel->last_x = -1;
86 toplevel->last_y = -1;
87 toplevel->loc_x = -1;
88 toplevel->loc_y = -1;
89 toplevel->distance = -1;
91 toplevel->current_attribute = NULL;
93 toplevel->current_visible = -1; /* not sure on these */
94 toplevel->current_show = -1;
96 toplevel->internal_clib = NULL;
98 toplevel->RC_list = NULL;
100 toplevel->series_name = NULL;
101 toplevel->untitled_name = NULL;
102 toplevel->font_directory = NULL;
103 toplevel->scheme_directory = NULL;
104 toplevel->bitmap_directory = NULL;
106 toplevel->event_state = -1;
108 toplevel->inside_action = 0;
109 toplevel->rotated_inside = 0;
111 toplevel->init_left = 0;
112 toplevel->init_top = 0;
113 /* init_right and _bottom are set before this function is called */
115 toplevel->win_width = 0;
116 toplevel->win_height = 0;
117 toplevel->width = 1;
118 toplevel->height = 1;
119 toplevel->image_width = 0;
120 toplevel->image_height = 0;
121 toplevel->snap = 1;
122 toplevel->grid = 1;
123 toplevel->min_zoom = 0;
124 toplevel->max_zoom = 8;
126 toplevel->starting_width = 0;
128 toplevel->text_alignment = 0;
130 toplevel->line_type = 0;
132 toplevel->fill_type = 0;
134 toplevel->override_color = -1;
135 toplevel->inside_redraw = 0;
136 toplevel->window_aspectratio = 0;
137 toplevel->display_height = 0;
138 toplevel->display_width = 0;
140 toplevel->DONT_DRAW_CONN = 0;
141 toplevel->DONT_RESIZE = 0;
142 toplevel->DONT_EXPOSE = 0;
143 toplevel->DONT_REDRAW = 0;
144 toplevel->DONT_RECALC = 0;
145 toplevel->FORCE_CONN_UPDATE = 0;
146 toplevel->ADDING_SEL = 0;
147 toplevel->REMOVING_SEL = 0;
149 toplevel->drawbounding_action_mode = FREE;
150 toplevel->last_drawb_mode = -1;
152 toplevel->CONTROLKEY = 0;
153 toplevel->SHIFTKEY = 0;
154 toplevel->ALTKEY = 0;
156 toplevel->doing_pan = 0;
158 /* Put head node on page list... */
159 toplevel->page_head = NULL;
160 s_page_init_list (toplevel);
161 toplevel->page_current = NULL;
163 toplevel->buffer_number = 0;
165 toplevel->show_hidden_text = 0;
167 toplevel->complex_rotate = 0;
169 toplevel->last_callback = NULL;
170 toplevel->cwd = NULL;
172 toplevel->major_changed_refdes = NULL;
174 toplevel->main_window = NULL;
175 toplevel->drawing_area = NULL;
176 toplevel->menubar = NULL;
177 toplevel->popup_menu = NULL;
178 toplevel->h_scrollbar = NULL;
179 toplevel->v_scrollbar = NULL;
180 toplevel->h_adjustment = NULL;
181 toplevel->v_adjustment = NULL;
182 toplevel->left_label = NULL;
183 toplevel->middle_label = NULL;
184 toplevel->right_label = NULL;
185 toplevel->filename_label = NULL;
186 toplevel->grid_label = NULL;
187 toplevel->status_label = NULL;
189 toplevel->toolbar_select = NULL;
190 toplevel->toolbar_net = NULL;
191 toplevel->toolbar_bus = NULL;
192 toplevel->toolbar_edit = NULL;
193 toplevel->toolbar_move = NULL;
194 toplevel->toolbar_copy = NULL;
195 toplevel->toolbar_delete = NULL;
196 toplevel->toolbar_rotate = NULL;
197 toplevel->toolbar_mirror = NULL;
199 toplevel->fowindow = NULL;
200 toplevel->fswindow = NULL;
201 toplevel->sowindow = NULL;
202 toplevel->saveas_flag = 0;
204 toplevel->aswindow = NULL;
205 toplevel->attr_list = NULL;
206 toplevel->asentry_name = NULL;
207 toplevel->asentry_value = NULL;
209 toplevel->cswindow = NULL;
210 toplevel->clib_list = NULL;
211 toplevel->basename_list = NULL;
212 toplevel->current_clib = NULL;
213 /* toplevel->current_basename */
215 /* toplevel->fileselect */
217 toplevel->iwindow = NULL;
218 toplevel->ifilename_entry = NULL;
220 toplevel->pswindow = NULL;
222 toplevel->tiwindow = NULL;
223 toplevel->tewindow = NULL;
224 toplevel->teentry = NULL;
225 toplevel->ltwindow = NULL;
226 toplevel->ftwindow = NULL;
227 toplevel->sewindow = NULL;
228 toplevel->seentry = NULL;
229 toplevel->exwindow = NULL;
230 toplevel->aawindow = NULL;
231 toplevel->mawindow = NULL;
232 toplevel->aewindow = NULL;
233 toplevel->aaentry_start = NULL;
234 toplevel->aaentry_sweep = NULL;
235 toplevel->trwindow = NULL;
236 toplevel->trentry = NULL;
237 toplevel->tswindow = NULL;
238 toplevel->tshowwindow = NULL;
239 toplevel->thidewindow = NULL;
240 toplevel->tfindwindow = NULL;
241 toplevel->tsentry = NULL;
243 toplevel->abwindow = NULL;
244 toplevel->hkwindow = NULL;
245 toplevel->cowindow = NULL;
246 toplevel->coord_world = NULL;
247 toplevel->coord_screen = NULL;
249 toplevel->pfswindow = NULL;
250 toplevel->pcfswindow = NULL;
252 toplevel->current_pixbuf = NULL;
253 toplevel->pixbuf_filename = NULL;
254 toplevel->pixbuf_wh_ratio = 0;
256 toplevel->clwindow = NULL;
257 toplevel->edit_color = 0;
259 toplevel->window = NULL;
261 toplevel->gc = NULL;
262 toplevel->xor_gc = NULL;
263 toplevel->outline_xor_gc = NULL;
264 toplevel->bounding_xor_gc = NULL;
265 toplevel->bus_gc = NULL;
267 toplevel->keyaccel_string = NULL;
269 toplevel->backingstore = NULL;
271 toplevel->graphic_color = 0;
272 toplevel->pin_color = 0;
273 toplevel->text_color = 0;
275 toplevel->logic_bubble_color = 0;
276 toplevel->zoom_box_color = 0;
277 toplevel->text_caps = 0;
278 toplevel->attribute_color = 0;
279 toplevel->detachedattr_color = 0;
280 toplevel->text_size = 0;
282 toplevel->snap_size = 100;
284 toplevel->grid_color = 0;
285 toplevel->background_color = 0;
286 toplevel->select_color = 0;
287 toplevel->bb_color = 0;
288 toplevel->lock_color = 0;
289 toplevel->net_endpoint_color = 0;
290 toplevel->net_color = 0;
291 toplevel->bus_color = 0;
292 toplevel->override_net_color = -1;
293 toplevel->override_bus_color = -1;
294 toplevel->override_pin_color = -1;
295 toplevel->pin_style = 0;
296 toplevel->net_style = 0;
297 toplevel->bus_style = 0;
298 toplevel->line_style = 0;
299 toplevel->zoom_with_pan = 0;
301 toplevel->actionfeedback_mode = OUTLINE;
303 toplevel->text_feedback = 0;
305 toplevel->text_display_zoomfactor = 0;
307 toplevel->net_endpoint_mode = NONE;
309 toplevel->net_midpoint_mode = NONE;
311 toplevel->object_clipping = 0;
313 toplevel->embed_complex = 0;
315 toplevel->include_complex = 0;
317 toplevel->text_output = 0;
319 toplevel->scrollbars_flag = 0;
321 toplevel->print_orientation = 0;
323 toplevel->image_color = FALSE;
325 toplevel->print_color = FALSE;
327 toplevel->print_color_background = 0;
329 toplevel->setpagedevice_orientation = FALSE;
331 toplevel->setpagedevice_pagesize = FALSE;
333 toplevel->postscript_prolog = NULL;
334 toplevel->postscript_font_scale = 1.0;
336 toplevel->stroke_color = 0;
338 toplevel->log_window = 0;
340 toplevel->log_window_type = 0;
342 toplevel->third_button = 0;
344 toplevel->middle_button = 0;
346 toplevel->net_consolidate = FALSE;
348 toplevel->file_preview = 0;
350 toplevel->enforce_hierarchy = 0;
352 toplevel->text_origin_marker = 0;
354 toplevel->fast_mousepan = 0;
356 toplevel->raise_dialog_boxes = 0;
358 /* The following is an attempt at getting (deterministic) defaults */
359 /* for the following variables */
360 toplevel->attribute_promotion = FALSE;
361 toplevel->promote_invisible = FALSE;
362 toplevel->keep_invisible = FALSE;
364 toplevel->continue_component_place = 0;
366 toplevel->undo_levels = 0;
368 toplevel->undo_control = 0;
370 toplevel->undo_type = 0;
372 toplevel->draw_grips = 0;
374 toplevel->netconn_rubberband = 0;
376 toplevel->sort_component_library = 0;
378 toplevel->warp_cursor = 0;
380 toplevel->toolbars = 0;
382 toplevel->handleboxes = 0;
384 toplevel->print_output_type = 0;
386 toplevel->print_output_capstyle = BUTT_CAP;
388 toplevel->image_output_type = 0;
390 toplevel->paper_width = 0;
391 toplevel->paper_height = 0;
393 toplevel->bus_ripper_size = 0;
395 toplevel->bus_ripper_type = 0;
397 toplevel->bus_ripper_symname = NULL;
399 toplevel->bus_ripper_rotation = 0;
401 toplevel->force_boundingbox = FALSE;
403 toplevel->grid_dot_size = 1;
404 toplevel->grid_mode = GRID_VARIABLE_MODE;
405 toplevel->grid_fixed_threshold = 10;
407 toplevel->print_vector_threshold = 3;
409 toplevel->add_attribute_offset = 50;
411 toplevel->drag_can_move = TRUE;
413 toplevel->always_promote_attributes = NULL;
415 toplevel->mousepan_gain = 5;
416 toplevel->keyboardpan_gain = 10;
418 toplevel->print_command = NULL;
420 toplevel->select_slack_pixels = 4;
422 toplevel->net_naming_priority = 0;
423 toplevel->hierarchy_traversal = 0;
424 toplevel->hierarchy_uref_mangle = 0;
425 toplevel->hierarchy_netname_mangle = 0;
426 toplevel->hierarchy_netattrib_mangle = 0;
427 toplevel->hierarchy_uref_separator = NULL;
428 toplevel->hierarchy_netname_separator = NULL;
429 toplevel->hierarchy_netattrib_separator = NULL;
430 toplevel->hierarchy_netattrib_order = 0;
431 toplevel->hierarchy_netname_order = 0;
432 toplevel->hierarchy_uref_order = 0;
433 toplevel->unnamed_netname = NULL;
435 /* Auto-save interval */
436 toplevel->auto_save_interval = 0;
437 toplevel->auto_save_timeout = 0;
439 /* set the rest of the variables */
440 if (variable_set_func) {
441 (*variable_set_func) (toplevel);
445 /* disable the events */
446 toplevel->DONT_DRAW_CONN = 1;
447 toplevel->DONT_RESIZE = 1;
448 toplevel->DONT_EXPOSE = 1;
449 toplevel->DONT_RECALC = 1;
450 toplevel->DONT_REDRAW = 1;
453 /* now append toplevel to this list: */
454 /* - find the tail of the toplevel list */
455 for (tmp = toplevel_head; tmp->next != NULL; tmp = tmp->next);
456 /* - link toplevel with tmp */
457 tmp->next = toplevel;
458 toplevel->prev = tmp;
459 toplevel->next = NULL;
461 return toplevel;
464 /*! \todo Finish function documentation!!!
465 * \brief
466 * \par Function Description
469 void s_toplevel_delete (TOPLEVEL *toplevel)
471 if (toplevel->auto_save_timeout != 0) {
472 gboolean ret;
473 ret = g_source_remove (toplevel->auto_save_timeout);
474 g_assert (ret);
477 if (toplevel->wid == -1) {
478 /* do no delete head */
479 return;
482 g_free (toplevel->series_name);
483 g_free (toplevel->untitled_name);
484 g_free (toplevel->font_directory);
485 g_free (toplevel->scheme_directory);
486 g_free (toplevel->bitmap_directory);
487 g_free (toplevel->bus_ripper_symname);
488 g_free (toplevel->print_command);
490 /* free all fonts */
491 /* if you close a window, then you free the font set... */
492 /* this is probably a bad idea... */
493 /* The font set can ONLY be freed when exiting!!! */
494 /* o_text_freeallfonts (toplevel); */
496 /* delete all pages */
497 s_page_delete_list (toplevel);
499 /* unlink toplevel from toplevel list */
500 toplevel->prev->next = toplevel->next;
501 if (toplevel->next != NULL) {
502 toplevel->next->prev = toplevel->prev;
505 g_free (toplevel);