libgeda

o_selection.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * libgeda - gEDA's library
00003  * Copyright (C) 1998-2010 Ales Hvezda
00004  * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 #include <config.h>
00021 
00022 #include <stdio.h>
00023 #include <ctype.h>
00024 #ifdef HAVE_STDLIB_H
00025 #include <stdlib.h>
00026 #endif
00027 
00028 #include "libgeda_priv.h"
00029 
00030 #ifdef HAVE_LIBDMALLOC
00031 #include <dmalloc.h>
00032 #endif
00033 
00038 SELECTION *o_selection_new( void )
00039 {
00040   return (SELECTION*)geda_list_new();
00041 }
00042 
00052 void o_selection_add (TOPLEVEL *toplevel, SELECTION *selection, OBJECT *o_selected)
00053 {
00054   if (o_selected->selected == FALSE)
00055   {
00056     o_selection_select (toplevel, o_selected);
00057     geda_list_add( (GedaList *)selection, o_selected );
00058   }
00059 }
00060 
00071 void o_selection_remove (TOPLEVEL *toplevel, SELECTION *selection, OBJECT *o_selected)
00072 {
00073   if (o_selected == NULL) {
00074     fprintf(stderr, "Got NULL for o_selected in o_selection_remove\n");
00075     return;
00076   }
00077 
00078   if (g_list_find( geda_list_get_glist( selection ), o_selected ) != NULL) {
00079     o_selection_unselect (toplevel, o_selected);
00080     geda_list_remove( (GedaList *)selection, o_selected );
00081   }
00082 }
00083 
00084 
00090 void o_selection_print_all(const SELECTION *selection)
00091 {
00092   const GList *s_current;
00093 
00094   s_current = geda_list_get_glist( selection );
00095 
00096   printf("START printing selection ********************\n");
00097   while(s_current != NULL) {
00098     if (s_current->data) {
00099       printf("Selected object: %d\n", ((OBJECT *)s_current->data)->sid );
00100     }
00101     s_current = g_list_next( s_current );
00102   }
00103   printf("DONE printing selection ********************\n");
00104   printf("\n");
00105 }
00106 
00114 void o_selection_select(TOPLEVEL *toplevel, OBJECT *object)
00115 {
00116   if (object->selected == TRUE)
00117     return;
00118 
00119   o_emit_pre_change_notify (toplevel, object);
00120   object->selected = TRUE;
00121   o_emit_change_notify (toplevel, object);
00122 }
00123 
00132 void o_selection_unselect (TOPLEVEL *toplevel, OBJECT *object)
00133 {
00134   if (object->selected == FALSE)
00135     return;
00136 
00137   o_emit_pre_change_notify (toplevel, object);
00138   object->selected = FALSE;
00139   o_emit_change_notify (toplevel, object);
00140 }
00141 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines