libgeda
|
00001 /* gEDA - GPL Electronic Design Automation 00002 * libgeda - gEDA's library 00003 * Copyright (C) 1998, 1999, 2000 Kazu Hirata / Ales Hvezda 00004 * Copyright (C) 1998-2010 Ales Hvezda 00005 * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details) 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 #include <config.h> 00022 00023 #include <stdio.h> 00024 #ifdef HAVE_STRING_H 00025 #include <string.h> 00026 #endif 00027 #ifdef HAVE_STDLIB_H 00028 #include <stdlib.h> 00029 #endif 00030 00031 #include "libgeda_priv.h" 00032 00033 #ifdef HAVE_LIBDMALLOC 00034 #include <dmalloc.h> 00035 #endif 00036 00037 static GList *new_toplevel_hooks = NULL; 00038 00039 typedef struct { 00040 NewToplevelFunc func; 00041 void *data; 00042 } NewToplevelHook; 00043 00044 00045 void s_toplevel_append_new_hook (NewToplevelFunc func, void *data) 00046 { 00047 NewToplevelHook *new_hook; 00048 00049 new_hook = g_new0 (NewToplevelHook, 1); 00050 new_hook->func = func; 00051 new_hook->data = data; 00052 00053 new_toplevel_hooks = g_list_append (new_toplevel_hooks, new_hook); 00054 } 00055 00056 00057 static void call_new_toplevel_hook (gpointer hook, gpointer toplevel) 00058 { 00059 NewToplevelHook *h = (NewToplevelHook*) hook; 00060 TOPLEVEL *t = (TOPLEVEL*) toplevel; 00061 00062 h->func (t, h->data); 00063 } 00064 00075 TOPLEVEL *s_toplevel_new (void) 00076 { 00077 TOPLEVEL *toplevel; 00078 00079 toplevel = (TOPLEVEL*)g_new (TOPLEVEL, 1); 00080 00081 toplevel->RC_list = NULL; 00082 00083 toplevel->untitled_name = NULL; 00084 toplevel->bitmap_directory = NULL; 00085 00086 toplevel->init_left = 0; 00087 toplevel->init_top = 0; 00088 /* init_right and _bottom are set before this function is called */ 00089 00090 toplevel->width = 1; 00091 toplevel->height = 1; 00092 00093 toplevel->override_color = -1; 00094 00095 toplevel->pages = geda_list_new(); 00096 toplevel->page_current = NULL; 00097 00098 toplevel->show_hidden_text = 0; 00099 00100 toplevel->major_changed_refdes = NULL; 00101 00102 /* BLOCK SET IN GSCHEM, BUT USED IN LIBGEDA - NEEDS A RETHINK */ 00103 toplevel->background_color = 0; 00104 toplevel->override_net_color = -1; 00105 toplevel->override_bus_color = -1; 00106 toplevel->override_pin_color = -1; 00107 toplevel->pin_style = 0; 00108 toplevel->net_style = 0; 00109 toplevel->bus_style = 0; 00110 toplevel->line_style = 0; 00111 /* END BLOCK - ALTHOUGH THERE ARE MORE CASES! */ 00112 00113 toplevel->object_clipping = 0; 00114 00115 toplevel->print_orientation = 0; 00116 00117 toplevel->image_color = FALSE; 00118 00119 toplevel->print_color = FALSE; 00120 00121 toplevel->print_color_background = 0; 00122 00123 toplevel->setpagedevice_orientation = FALSE; 00124 00125 toplevel->setpagedevice_pagesize = FALSE; 00126 00127 toplevel->postscript_prolog = NULL; 00128 00129 toplevel->net_consolidate = FALSE; 00130 00131 /* The following is an attempt at getting (deterministic) defaults */ 00132 /* for the following variables */ 00133 toplevel->attribute_promotion = FALSE; 00134 toplevel->promote_invisible = FALSE; 00135 toplevel->keep_invisible = FALSE; 00136 00137 toplevel->make_backup_files = TRUE; 00138 00139 toplevel->print_output_type = 0; 00140 00141 toplevel->print_output_capstyle = BUTT_CAP; 00142 00143 toplevel->paper_width = 0; 00144 toplevel->paper_height = 0; 00145 00146 toplevel->bus_ripper_symname = NULL; 00147 00148 toplevel->force_boundingbox = FALSE; 00149 00150 toplevel->always_promote_attributes = NULL; 00151 00152 toplevel->net_naming_priority = 0; 00153 toplevel->hierarchy_traversal = 0; 00154 toplevel->hierarchy_uref_mangle = 0; 00155 toplevel->hierarchy_netname_mangle = 0; 00156 toplevel->hierarchy_netattrib_mangle = 0; 00157 toplevel->hierarchy_uref_separator = NULL; 00158 toplevel->hierarchy_netname_separator = NULL; 00159 toplevel->hierarchy_netattrib_separator = NULL; 00160 toplevel->hierarchy_netattrib_order = 0; 00161 toplevel->hierarchy_netname_order = 0; 00162 toplevel->hierarchy_uref_order = 0; 00163 toplevel->unnamed_netname = NULL; 00164 toplevel->unnamed_busname = NULL; 00165 00166 toplevel->rendered_text_bounds_func = NULL; 00167 toplevel->rendered_text_bounds_data = NULL; 00168 00169 toplevel->change_notify_funcs = NULL; 00170 00171 toplevel->attribs_changed_hooks = NULL; 00172 00173 toplevel->conns_changed_hooks = NULL; 00174 00175 toplevel->load_newer_backup_func = NULL; 00176 toplevel->load_newer_backup_data = NULL; 00177 00178 /* Auto-save interval */ 00179 toplevel->auto_save_interval = 0; 00180 toplevel->auto_save_timeout = 0; 00181 00182 toplevel->weak_refs = NULL; 00183 00184 /* Call hooks */ 00185 g_list_foreach (new_toplevel_hooks, call_new_toplevel_hook, toplevel); 00186 00187 return toplevel; 00188 } 00189 00195 void s_toplevel_delete (TOPLEVEL *toplevel) 00196 { 00197 GList *iter; 00198 00199 if (toplevel->auto_save_timeout != 0) { 00200 /* Assume this works */ 00201 g_source_remove (toplevel->auto_save_timeout); 00202 } 00203 00204 g_free (toplevel->untitled_name); 00205 g_free (toplevel->bitmap_directory); 00206 g_free (toplevel->bus_ripper_symname); 00207 00208 /* free all fonts */ 00209 /* if you close a window, then you free the font set... */ 00210 /* this is probably a bad idea... */ 00211 /* The font set can ONLY be freed when exiting!!! */ 00212 /* o_text_freeallfonts (toplevel); */ 00213 00214 /* delete all pages */ 00215 s_page_delete_list (toplevel); 00216 00217 /* Delete the page list */ 00218 g_object_unref(toplevel->pages); 00219 00220 /* Remove all change notification handlers */ 00221 for (iter = toplevel->change_notify_funcs; 00222 iter != NULL; iter = g_list_next (iter)) { 00223 g_free (iter->data); 00224 } 00225 g_list_free (toplevel->change_notify_funcs); 00226 00227 s_weakref_notify (toplevel, toplevel->weak_refs); 00228 00229 g_free (toplevel); 00230 00231 } 00232 00245 void 00246 s_toplevel_weak_ref (TOPLEVEL *toplevel, 00247 void (*notify_func)(void *, void *), 00248 void *user_data) 00249 { 00250 g_return_if_fail (toplevel != NULL); 00251 toplevel->weak_refs = s_weakref_add (toplevel->weak_refs, 00252 notify_func, user_data); 00253 } 00254 00265 void 00266 s_toplevel_weak_unref (TOPLEVEL *toplevel, 00267 void (*notify_func)(void *, void *), 00268 void *user_data) 00269 { 00270 g_return_if_fail (toplevel != NULL); 00271 toplevel->weak_refs = s_weakref_remove (toplevel->weak_refs, 00272 notify_func, user_data); 00273 } 00274 00286 void 00287 s_toplevel_add_weak_ptr (TOPLEVEL *toplevel, 00288 void *weak_pointer_loc) 00289 { 00290 g_return_if_fail (toplevel != NULL); 00291 toplevel->weak_refs = s_weakref_add_ptr (toplevel->weak_refs, 00292 weak_pointer_loc); 00293 } 00294 00304 void 00305 s_toplevel_remove_weak_ptr (TOPLEVEL *toplevel, 00306 void *weak_pointer_loc) 00307 { 00308 g_return_if_fail (toplevel != NULL); 00309 toplevel->weak_refs = s_weakref_remove_ptr (toplevel->weak_refs, 00310 weak_pointer_loc); 00311 }