gschem

i_basic.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gschem - gEDA Schematic Capture
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 #ifdef HAVE_STRING_H
00023 #include <string.h>
00024 #endif
00025 
00026 #include "gschem.h"
00027 
00028 #ifdef HAVE_LIBDMALLOC
00029 #include <dmalloc.h>
00030 #endif
00031 
00041 static void i_update_status(GSCHEM_TOPLEVEL *w_current, const char *string)
00042 {
00043   if (!w_current->status_label)
00044     return;
00045 
00046   if (string) {
00047     /* NOTE: consider optimizing this if same label */
00048     gtk_label_set(GTK_LABEL(w_current->status_label),
00049                   (char *) string);
00050   }
00051 }
00052 
00064 static const char *i_status_string(GSCHEM_TOPLEVEL *w_current)
00065 {
00066   static char *buf = 0;
00067 
00068   switch ( w_current->event_state ) {
00069     case NONE:
00070     case STARTROUTENET: 
00071     case ENDROUTENET: 
00072       return "";
00073     case STARTSELECT:
00074     case SELECT:
00075     case SBOX:
00076     case GRIPS:
00077       return _("Select Mode");
00078     case ENDCOMP:
00079       return _("Component Mode"); /*EK* new */
00080     case ENDTEXT:
00081       return _("Text Mode"); /*EK* new */
00082     case STARTCOPY:
00083     case ENDCOPY:
00084       return _("Copy Mode");
00085     case STARTMOVE:
00086     case ENDMOVE:
00087       return _("Move Mode");
00088     case ENDROTATEP:
00089       return _("Rotate Mode");
00090     case ENDMIRROR:
00091       return _("Mirror Mode");
00092     case ZOOM:
00093     case ZOOMBOXEND:
00094     case ZOOMBOXSTART:
00095       return _("Zoom Box");
00096     case STARTPAN:
00097     case PAN:
00098     case MOUSEPAN:
00099       return _("Pan Mode");
00100     case STARTPASTE:
00101     case ENDPASTE:
00102       g_free(buf);
00103       buf = g_strdup_printf(_("Paste %d Mode"), w_current->buffer_number+1);
00104       return buf;
00105     case STARTDRAWNET:
00106     case DRAWNET:
00107     case NETCONT:
00108       if (w_current->magneticnet_mode)
00109     return _("Magnetic Net Mode");
00110       else
00111     return _("Net Mode");
00112     case STARTDRAWBUS:
00113     case DRAWBUS:
00114     case BUSCONT:
00115       return _("Bus Mode");
00116     case DRAWLINE:
00117     case ENDLINE:
00118       return _("Line Mode");
00119     case DRAWBOX:
00120     case ENDBOX:
00121       return _("Box Mode");
00122     case DRAWPICTURE:
00123     case ENDPICTURE:
00124       return _("Picture Mode");
00125     case DRAWCIRCLE:
00126     case ENDCIRCLE:
00127       return _("Circle Mode");
00128     case DRAWARC:
00129     case ENDARC:
00130       return _("Arc Mode");
00131     case DRAWPIN:
00132     case ENDPIN:
00133       return _("Pin Mode");
00134     case COPY:
00135       return _("Copy");
00136     case MOVE:
00137       return _("Move");
00138     case MCOPY:
00139       return _("Multiple Copy");
00140     case STARTMCOPY:
00141     case ENDMCOPY:
00142       return _("Multiple Copy Mode");
00143   }
00144   g_assert_not_reached();
00145   return ""; /* should not happen */
00146 }
00147 
00157 void i_show_state(GSCHEM_TOPLEVEL *w_current, const char *message)
00158 {
00159   TOPLEVEL *toplevel = w_current->toplevel;
00160   gchar *what_to_say;
00161   const gchar *array[5] = { NULL };
00162   int i = 3; /* array[4] must be NULL */
00163 
00164   /* Fill in the string array */
00165   array[i--] = i_status_string(w_current);
00166   
00167   if(toplevel->show_hidden_text)
00168     array[i--] = _("Show Hidden");
00169   
00170   if(w_current->snap == SNAP_OFF)
00171     array[i--] = _("Snap Off");
00172   else if (w_current->snap == SNAP_RESNAP)
00173     array[i--] = _("Resnap Active");
00174   
00175   if(message && message[0])
00176     array[i] = message;
00177   
00178   /* Skip over NULLs */
00179   while(array[i] == NULL)
00180     i++;
00181 
00182   what_to_say = g_strjoinv(" - ", (gchar **) array + i);
00183 
00184   if(w_current->keyaccel_string) {
00185      gchar *p = what_to_say;
00186 
00187      what_to_say = g_strdup_printf("%s \t\t %s", w_current->keyaccel_string,
00188            what_to_say);
00189      g_free(p);
00190   }
00191 
00192   i_update_status(w_current, what_to_say);
00193   g_free(what_to_say);
00194 }
00195 
00205 void i_set_state(GSCHEM_TOPLEVEL *w_current, enum x_states newstate)
00206 {
00207   i_set_state_msg(w_current, newstate, NULL);
00208 }
00209 
00222 void i_set_state_msg(GSCHEM_TOPLEVEL *w_current, enum x_states newstate,
00223              const char *message)
00224 {
00225   w_current->event_state = newstate;
00226   i_show_state(w_current, message);
00227 }
00228 
00234 void i_update_middle_button(GSCHEM_TOPLEVEL *w_current,
00235                 void (*func_ptr)(),
00236                 const char *string)
00237 {
00238   char *temp_string;
00239 
00240   if (func_ptr == NULL)
00241     return;
00242 
00243   if (string == NULL)
00244     return;
00245 
00246   if (!w_current->middle_label)
00247     return;
00248 
00249   switch(w_current->middle_button) {
00250 
00251     /* remove this case eventually and make it a null case */
00252     case(ACTION):
00253     gtk_label_set(GTK_LABEL(w_current->middle_label),
00254                   _("Action"));
00255     break;
00256 
00257 #ifdef HAVE_LIBSTROKE
00258     case(STROKE):
00259     gtk_label_set(GTK_LABEL(w_current->middle_label),
00260                   _("Stroke"));
00261     break;
00262 #else 
00263     /* remove this case eventually and make it a null case */
00264     case(STROKE):
00265     gtk_label_set(GTK_LABEL(w_current->middle_label),
00266                   _("none"));
00267     break;
00268 #endif
00269         
00270     case(REPEAT):
00271     temp_string = g_strconcat (_("Repeat/"), string, NULL);
00272 
00273     gtk_label_set(GTK_LABEL(w_current->middle_label),
00274                   temp_string);
00275     w_current->last_callback = func_ptr;
00276     g_free(temp_string);
00277     break;
00278 
00279   }
00280 }
00281 
00287 void i_update_toolbar(GSCHEM_TOPLEVEL *w_current)
00288 {
00289   if (!w_current->toolbars) 
00290     return;
00291 
00292   switch(w_current->event_state) {
00293     case(NONE):
00294     case(SELECT):
00295     case(STARTSELECT): 
00296       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
00297                    w_current->toolbar_select), TRUE);
00298       break;
00299       
00300     case(DRAWNET): 
00301     case(STARTDRAWNET): 
00302     case(NETCONT): 
00303       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
00304                    w_current->toolbar_net), TRUE);
00305       break;
00306       
00307     case(DRAWBUS): 
00308     case(STARTDRAWBUS): 
00309     case(BUSCONT): 
00310       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
00311                    w_current->toolbar_bus), TRUE);
00312       break;
00313       
00314     case(DRAWLINE): 
00315     case(DRAWBOX): 
00316     case(DRAWPICTURE): 
00317     case(DRAWPIN): 
00318     case(DRAWCIRCLE): 
00319     case(DRAWARC): 
00320     case(MOVE): 
00321     case(COPY): 
00322     case(ZOOM): 
00323     case(PAN): 
00324     case(STARTPAN): 
00325     case(STARTCOPY): 
00326     case(STARTMOVE): 
00327     case(ENDCOPY): 
00328     case(ENDMOVE): 
00329     case(ENDLINE): 
00330     case(ENDBOX): 
00331     case(ENDPICTURE): 
00332     case(ENDCIRCLE): 
00333     case(ENDARC): 
00334     case(ENDPIN): 
00335     case(ENDCOMP): 
00336     case(ENDTEXT): 
00337     case(ENDROTATEP): 
00338     case(ENDMIRROR): 
00339     case(ZOOMBOXSTART): 
00340     case(ZOOMBOXEND): 
00341     case(STARTROUTENET): 
00342     case(ENDROUTENET): 
00343     case(MOUSEPAN): 
00344     case(STARTPASTE): 
00345     case(ENDPASTE): 
00346     case(GRIPS): 
00347     case(MCOPY): 
00348     case(STARTMCOPY): 
00349     case(ENDMCOPY): 
00350     default:
00351       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
00352                    w_current->toolbar_select), TRUE);
00353       break;
00354   }
00355 }
00356 
00357 
00364 static void clipboard_usable_cb (int usable, void *userdata)
00365 {
00366   GSCHEM_TOPLEVEL *w_current = userdata;
00367   x_menus_sensitivity (w_current, "_Edit/_Paste", usable);
00368 }
00369 
00370 static gboolean
00371 selected_at_least_one_text_object(GSCHEM_TOPLEVEL *w_current)
00372 {
00373   OBJECT *obj;
00374   TOPLEVEL *toplevel = w_current->toplevel;
00375   GList *list = geda_list_get_glist(toplevel->page_current->selection_list);
00376 
00377   while(list != NULL) {
00378     obj = (OBJECT *) list->data;
00379     if (obj->type == OBJ_TEXT)
00380       return TRUE;
00381     list = g_list_next(list);
00382   }
00383   return FALSE;
00384 }
00385 
00386 
00394 void i_update_menus(GSCHEM_TOPLEVEL *w_current)
00395 {
00396   gboolean have_text_selected;
00397   TOPLEVEL *toplevel = w_current->toplevel;
00398   /* 
00399    * This is very simplistic.  Right now it just disables all menu
00400    * items which get greyed out when a component is not selected.
00401    * Eventually what gets enabled/disabled
00402    * should be based on what is in the selection list 
00403    */
00404 
00405   g_assert(w_current != NULL);
00406   g_assert(toplevel->page_current != NULL);
00407 
00408   x_clipboard_query_usable (w_current, clipboard_usable_cb, w_current);
00409 
00410   if (o_select_selected (w_current)) {
00411     have_text_selected = selected_at_least_one_text_object(w_current);
00412 
00413     /* since one or more things are selected, we set these TRUE */
00414     /* These strings should NOT be internationalized */
00415     x_menus_sensitivity(w_current, "_Edit/Cu_t", TRUE);
00416     x_menus_sensitivity(w_current, "_Edit/_Copy", TRUE);
00417     x_menus_sensitivity(w_current, "_Edit/_Delete", TRUE);
00418     x_menus_sensitivity(w_current, "_Edit/Copy Mode", TRUE);
00419     x_menus_sensitivity(w_current, "_Edit/Multiple Copy Mode", TRUE);
00420     x_menus_sensitivity(w_current, "_Edit/Move Mode", TRUE);
00421     x_menus_sensitivity(w_current, "_Edit/Rotate 90 Mode", TRUE);
00422     x_menus_sensitivity(w_current, "_Edit/Mirror Mode", TRUE);
00423     x_menus_sensitivity(w_current, "_Edit/Edit...", TRUE);
00424     x_menus_sensitivity(w_current, "_Edit/Edit Text...", TRUE);
00425     x_menus_sensitivity(w_current, "_Edit/Slot...", TRUE);
00426     x_menus_sensitivity(w_current, "_Edit/Color...", TRUE);
00427     x_menus_sensitivity(w_current, "_Edit/Lock", TRUE);
00428     x_menus_sensitivity(w_current, "_Edit/Unlock", TRUE);
00429     x_menus_sensitivity(w_current, "_Edit/Line Width & Type...", TRUE);
00430     x_menus_sensitivity(w_current, "_Edit/Fill Type...", TRUE);
00431     x_menus_sensitivity(w_current, "_Edit/Embed Component/Picture", TRUE);
00432     x_menus_sensitivity(w_current, "_Edit/Unembed Component/Picture", TRUE);
00433     x_menus_sensitivity(w_current, "_Edit/Update Component", TRUE);
00434     x_menus_sensitivity(w_current, "_Buffer/Copy into 1", TRUE);
00435     x_menus_sensitivity(w_current, "_Buffer/Copy into 2", TRUE);
00436     x_menus_sensitivity(w_current, "_Buffer/Copy into 3", TRUE);
00437     x_menus_sensitivity(w_current, "_Buffer/Copy into 4", TRUE);
00438     x_menus_sensitivity(w_current, "_Buffer/Copy into 5", TRUE);
00439     x_menus_sensitivity(w_current, "_Buffer/Cut into 1", TRUE);
00440     x_menus_sensitivity(w_current, "_Buffer/Cut into 2", TRUE);
00441     x_menus_sensitivity(w_current, "_Buffer/Cut into 3", TRUE);
00442     x_menus_sensitivity(w_current, "_Buffer/Cut into 4", TRUE);
00443     x_menus_sensitivity(w_current, "_Buffer/Cut into 5", TRUE);
00444     x_menus_sensitivity(w_current, "Hie_rarchy/_Down Schematic", TRUE);
00445     x_menus_sensitivity(w_current, "Hie_rarchy/Down _Symbol", TRUE);
00446     x_menus_sensitivity(w_current, "Hie_rarchy/D_ocumentation...", TRUE);
00447     x_menus_sensitivity(w_current, "A_ttributes/_Attach", TRUE);
00448     x_menus_sensitivity(w_current, "A_ttributes/_Detach", TRUE);
00449     x_menus_sensitivity(w_current, "A_ttributes/Show _Value", have_text_selected);
00450     x_menus_sensitivity(w_current, "A_ttributes/Show _Name", have_text_selected);
00451     x_menus_sensitivity(w_current, "A_ttributes/Show _Both", have_text_selected);
00452     x_menus_sensitivity(w_current, "A_ttributes/_Toggle Visibility", have_text_selected);
00453 
00454     /*  Menu items for hierarchy added by SDB 1.9.2005.  */
00455     x_menus_popup_sensitivity(w_current, "/Down Schematic", TRUE);
00456     x_menus_popup_sensitivity(w_current, "/Down Symbol", TRUE);
00457     /* x_menus_popup_sensitivity(w_current, "/Up", TRUE); */
00458 
00459   } else {
00460     /* Nothing is selected, grey these out */
00461     /* These strings should NOT be internationalized */
00462     x_menus_sensitivity(w_current, "_Edit/Cu_t", FALSE);
00463     x_menus_sensitivity(w_current, "_Edit/_Copy", FALSE);
00464     x_menus_sensitivity(w_current, "_Edit/_Delete", FALSE);
00465     x_menus_sensitivity(w_current, "_Edit/Copy Mode", FALSE);
00466     x_menus_sensitivity(w_current, "_Edit/Multiple Copy Mode", FALSE);
00467     x_menus_sensitivity(w_current, "_Edit/Move Mode", FALSE);
00468     x_menus_sensitivity(w_current, "_Edit/Rotate 90 Mode", FALSE);
00469     x_menus_sensitivity(w_current, "_Edit/Mirror Mode", FALSE);
00470     x_menus_sensitivity(w_current, "_Edit/Edit...", FALSE);
00471     x_menus_sensitivity(w_current, "_Edit/Edit Text...", FALSE);
00472     x_menus_sensitivity(w_current, "_Edit/Slot...", FALSE);
00473     x_menus_sensitivity(w_current, "_Edit/Color...", FALSE);
00474     x_menus_sensitivity(w_current, "_Edit/Lock", FALSE);
00475     x_menus_sensitivity(w_current, "_Edit/Unlock", FALSE);
00476     x_menus_sensitivity(w_current, "_Edit/Line Width & Type...", FALSE);
00477     x_menus_sensitivity(w_current, "_Edit/Fill Type...", FALSE);
00478     x_menus_sensitivity(w_current, "_Edit/Embed Component/Picture", FALSE);
00479     x_menus_sensitivity(w_current, "_Edit/Unembed Component/Picture", FALSE);
00480     x_menus_sensitivity(w_current, "_Edit/Update Component", FALSE);
00481     x_menus_sensitivity(w_current, "_Buffer/Copy into 1", FALSE);
00482     x_menus_sensitivity(w_current, "_Buffer/Copy into 2", FALSE);
00483     x_menus_sensitivity(w_current, "_Buffer/Copy into 3", FALSE);
00484     x_menus_sensitivity(w_current, "_Buffer/Copy into 4", FALSE);
00485     x_menus_sensitivity(w_current, "_Buffer/Copy into 5", FALSE);
00486     x_menus_sensitivity(w_current, "_Buffer/Cut into 1", FALSE);
00487     x_menus_sensitivity(w_current, "_Buffer/Cut into 2", FALSE);
00488     x_menus_sensitivity(w_current, "_Buffer/Cut into 3", FALSE);
00489     x_menus_sensitivity(w_current, "_Buffer/Cut into 4", FALSE);
00490     x_menus_sensitivity(w_current, "_Buffer/Cut into 5", FALSE);
00491     x_menus_sensitivity(w_current, "Hie_rarchy/_Down Schematic", FALSE);
00492     x_menus_sensitivity(w_current, "Hie_rarchy/Down _Symbol", FALSE);
00493     x_menus_sensitivity(w_current, "Hie_rarchy/D_ocumentation...", FALSE);
00494     x_menus_sensitivity(w_current, "A_ttributes/_Attach", FALSE);
00495     x_menus_sensitivity(w_current, "A_ttributes/_Detach", FALSE);
00496     x_menus_sensitivity(w_current, "A_ttributes/Show _Value", FALSE);
00497     x_menus_sensitivity(w_current, "A_ttributes/Show _Name", FALSE);
00498     x_menus_sensitivity(w_current, "A_ttributes/Show _Both", FALSE);
00499     x_menus_sensitivity(w_current, "A_ttributes/_Toggle Visibility", FALSE);
00500 
00501     /*  Menu items for hierarchy added by SDB 1.9.2005.  */
00502     x_menus_popup_sensitivity(w_current, "/Down Schematic", FALSE);
00503     x_menus_popup_sensitivity(w_current, "/Down Symbol", FALSE);
00504     /* x_menus_popup_sensitivity(w_current, "/Up", FALSE);  */
00505   }
00506 
00507   x_menus_sensitivity(w_current, "_Buffer/Paste from 1", (object_buffer[0] != NULL));
00508   x_menus_sensitivity(w_current, "_Buffer/Paste from 2", (object_buffer[1] != NULL));
00509   x_menus_sensitivity(w_current, "_Buffer/Paste from 3", (object_buffer[2] != NULL));
00510   x_menus_sensitivity(w_current, "_Buffer/Paste from 4", (object_buffer[3] != NULL));
00511   x_menus_sensitivity(w_current, "_Buffer/Paste from 5", (object_buffer[4] != NULL));
00512 
00513 }
00514 
00524 void i_set_filename(GSCHEM_TOPLEVEL *w_current, const gchar *string)
00525 {
00526   gchar *print_string=NULL;
00527   gchar *filename=NULL;
00528 
00529   if (!w_current->main_window)
00530     return;
00531   if (string == NULL)
00532     return;
00533 
00534   filename = g_path_get_basename(string);
00535   
00536   print_string = g_strdup_printf("%s - gschem", filename);
00537   
00538   gtk_window_set_title(GTK_WINDOW(w_current->main_window),
00539                print_string);
00540   
00541   g_free(print_string);
00542   g_free(filename);
00543 }
00544 
00555 void i_update_grid_info (GSCHEM_TOPLEVEL *w_current)
00556 {
00557   gchar *print_string=NULL;
00558   gchar *snap=NULL;
00559   gchar *grid=NULL;
00560 
00561   if (!w_current->grid_label)
00562     return;
00563 
00564   switch (w_current->snap) {
00565   case SNAP_OFF:
00566     snap = g_strdup(_("OFF"));
00567     break;
00568   case SNAP_GRID:
00569     snap = g_strdup_printf("%d", w_current->snap_size);
00570     break;
00571   case SNAP_RESNAP:
00572     snap = g_strdup_printf("%dR", w_current->snap_size);
00573     break;
00574   default:
00575     g_critical("i_set_grid: w_current->snap out of range: %d\n",
00576                w_current->snap);
00577   }
00578 
00579   if (w_current->grid == GRID_NONE) {
00580     grid = g_strdup(_("OFF"));
00581   } else {
00582     int visible_grid = x_grid_query_drawn_spacing (w_current);
00583     if (visible_grid == -1)
00584       grid = g_strdup (_("NONE"));
00585     else
00586       grid = g_strdup_printf("%d", visible_grid);
00587   }
00588 
00589   print_string = g_strdup_printf(_("Grid(%s, %s)"), snap, grid);
00590   gtk_label_set(GTK_LABEL(w_current->grid_label), print_string);
00591   
00592   g_free(print_string);
00593   g_free(grid);
00594   g_free(snap);
00595 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines