show the magnetic net mode in the status bar
[geda-gaf.git] / gschem / src / i_basic.c
blob66857365f57629033c17c96870aa81d48dc2702c
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2007 Ales Hvezda
4 * Copyright (C) 1998-2007 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
20 #include <config.h>
22 #ifdef HAVE_STRING_H
23 #include <string.h>
24 #endif
26 #include <libgeda/libgeda.h>
28 #include "../include/gschem_struct.h"
29 #include "../include/globals.h"
30 #include "../include/prototype.h"
32 #ifdef HAVE_LIBDMALLOC
33 #include <dmalloc.h>
34 #endif
36 /*! \brief Update status bar string
38 * \par Function Description
39 * This function actually updates the status bar
40 * widget with the new string.
42 * \param [in] w_current GSCHEM_TOPLEVEL structure
43 * \param [in] string The new string to be shown in the status bar
45 static void i_update_status(GSCHEM_TOPLEVEL *w_current, const char *string)
47 if (!w_current->status_label)
48 return;
50 if (string) {
51 /* NOTE: consider optimizing this if same label */
52 gtk_label_set(GTK_LABEL(w_current->status_label),
53 (char *) string);
57 /*! \brief Get string corresponding to the currently selected mode
59 * \par Function Description
60 * Returns a string describing the currently
61 * selected mode.
63 * \param [in] w_current GSCHEM_TOPLEVEL structure
64 * \returns a string that will only last until the next time
65 * the function is called (which is probably just fine, really)
66 * *EK* Egil Kvaleberg
68 static const char *i_status_string(GSCHEM_TOPLEVEL *w_current)
70 static char *buf = 0;
72 switch ( w_current->event_state ) {
73 case NONE:
74 case STARTROUTENET: /*! \todo */
75 case ENDROUTENET: /*! \todo */
76 return "";
77 case STARTSELECT:
78 case SELECT:
79 case SBOX:
80 case GRIPS:
81 return _("Select Mode");
82 case DRAWCOMP:
83 case ENDCOMP:
84 return _("Component Mode"); /*EK* new */
85 case TEXTENTRY:
86 case ENDTEXT:
87 case DRAWTEXT:
88 return _("Text Mode"); /*EK* new */
89 case STARTCOPY:
90 case ENDCOPY:
91 return _("Copy Mode");
92 case STARTMOVE:
93 case ENDMOVE:
94 return _("Move Mode");
95 case ENDROTATEP:
96 return _("Rotate Mode");
97 case ENDMIRROR:
98 return _("Mirror Mode");
99 case ZOOM:
100 case ZOOMBOXEND:
101 case ZOOMBOXSTART:
102 return _("Zoom Box");
103 case STARTPAN:
104 case PAN:
105 case MOUSEPAN:
106 return _("Pan Mode");
107 case STARTPASTE:
108 case ENDPASTE:
109 if (buf) g_free(buf);
110 buf = g_strdup_printf(_("Paste %d Mode"), w_current->buffer_number+1);
111 return buf;
112 case STARTDRAWNET:
113 case DRAWNET:
114 case NETCONT:
115 if (w_current->magneticnet_mode)
116 return _("Magnetic Net Mode");
117 else
118 return _("Net Mode");
119 case STARTDRAWBUS:
120 case DRAWBUS:
121 case BUSCONT:
122 return _("Bus Mode");
123 case DRAWLINE:
124 case ENDLINE:
125 return _("Line Mode");
126 case DRAWBOX:
127 case ENDBOX:
128 return _("Box Mode");
129 case DRAWPICTURE:
130 case ENDPICTURE:
131 return _("Picture Mode");
132 case DRAWCIRCLE:
133 case ENDCIRCLE:
134 return _("Circle Mode");
135 case DRAWARC:
136 case ENDARC:
137 return _("Arc Mode");
138 case DRAWPIN:
139 case ENDPIN:
140 return _("Pin Mode");
141 case COPY:
142 return _("Copy");
143 case MOVE:
144 return _("Move");
145 case MCOPY:
146 return _("Multiple Copy");
147 case STARTMCOPY:
148 case ENDMCOPY:
149 return _("Multiple Copy Mode");
151 g_assert_not_reached();
152 return ""; /* should not happen */
155 /*! \brief Show state field
157 * \par Function Description
158 * Show state field on screen, possibly with the
159 * addition of an extra message
161 * \param [in] w_current GSCHEM_TOPLEVEL structure
162 * \param [in] message The string to be displayed
164 void i_show_state(GSCHEM_TOPLEVEL *w_current, const char *message)
166 TOPLEVEL *toplevel = w_current->toplevel;
167 gchar *what_to_say;
168 const gchar *array[5] = { NULL };
169 int i = 3; /* array[4] must be NULL */
171 /* Fill in the string array */
172 array[i--] = i_status_string(w_current);
174 if(toplevel->show_hidden_text)
175 array[i--] = _("Show Hidden");
177 if(!toplevel->snap)
178 array[i--] = _("Snap Off");
180 if(message && message[0])
181 array[i] = message;
183 /* Skip over NULLs */
184 while(array[i] == NULL)
185 i++;
187 what_to_say = g_strjoinv(" - ", (gchar **) array + i);
189 if(w_current->keyaccel_string) {
190 gchar *p = what_to_say;
192 what_to_say = g_strdup_printf("%s \t\t %s", w_current->keyaccel_string,
193 what_to_say);
194 g_free(p);
197 i_update_status(w_current, what_to_say);
198 g_free(what_to_say);
201 /*! \brief Set new state, then show state field
203 * \par Function Description
204 * Set new state, then show state field.
206 * \param [in] w_current GSCHEM_TOPLEVEL structure
207 * \param [in] newstate The new state
208 * *EK* Egil Kvaleberg
210 void i_set_state(GSCHEM_TOPLEVEL *w_current, enum x_states newstate)
212 i_set_state_msg(w_current, newstate, NULL);
215 /*! \brief Set new state, then show state field including some
216 * message
218 * \par Function Description
219 * Set new state, then show state field including some
220 * message.
222 * \param [in] w_current GSCHEM_TOPLEVEL structure
223 * \param [in] newstate The new state
224 * \param [in] message Message to be shown
225 * *EK* Egil Kvaleberg
227 void i_set_state_msg(GSCHEM_TOPLEVEL *w_current, enum x_states newstate,
228 const char *message)
230 w_current->event_state = newstate;
231 i_show_state(w_current, message);
234 /*! \todo Finish function documentation!!!
235 * \brief
236 * \par Function Description
239 void i_update_middle_button(GSCHEM_TOPLEVEL *w_current,
240 void (*func_ptr)(gpointer, guint, GtkWidget*),
241 const char *string)
243 char *temp_string;
245 if (func_ptr == NULL)
246 return;
248 if (string == NULL)
249 return;
251 if (!w_current->middle_label)
252 return;
254 switch(w_current->middle_button) {
256 /* remove this case eventually and make it a null case */
257 case(ACTION):
258 gtk_label_set(GTK_LABEL(w_current->middle_label),
259 _("Action"));
260 break;
262 #ifdef HAS_LIBSTROKE
263 case(STROKE):
264 gtk_label_set(GTK_LABEL(w_current->middle_label),
265 _("Stroke"));
266 break;
267 #else
268 /* remove this case eventually and make it a null case */
269 case(STROKE):
270 gtk_label_set(GTK_LABEL(w_current->middle_label),
271 _("none"));
272 break;
273 #endif
275 case(REPEAT):
276 temp_string = g_strconcat (_("Repeat/"), string, NULL);
278 gtk_label_set(GTK_LABEL(w_current->middle_label),
279 temp_string);
280 w_current->last_callback = func_ptr;
281 g_free(temp_string);
282 break;
287 /*! \todo Finish function documentation!!!
288 * \brief
289 * \param [in] w_current GSCHEM_TOPLEVEL structure
292 void i_update_toolbar(GSCHEM_TOPLEVEL *w_current)
294 if (!w_current->toolbars)
295 return;
297 switch(w_current->event_state) {
298 case(NONE):
299 case(SELECT):
300 case(STARTSELECT):
301 case(TEXTENTRY):
302 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
303 w_current->toolbar_select), TRUE);
304 break;
306 case(DRAWNET):
307 case(STARTDRAWNET):
308 case(NETCONT):
309 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
310 w_current->toolbar_net), TRUE);
311 break;
313 case(DRAWBUS):
314 case(STARTDRAWBUS):
315 case(BUSCONT):
316 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
317 w_current->toolbar_bus), TRUE);
318 break;
320 case(DRAWCOMP): /*! \todo */
321 case(DRAWLINE): /*! \todo */
322 case(DRAWBOX): /*! \todo */
323 case(DRAWPICTURE): /*! \todo */
324 case(DRAWPIN): /*! \todo */
325 case(DRAWCIRCLE): /*! \todo */
326 case(DRAWARC): /*! \todo */
327 case(MOVE): /*! \todo */
328 case(COPY): /*! \todo */
329 case(ZOOM): /*! \todo */
330 case(PAN): /*! \todo */
331 case(STARTPAN): /*! \todo */
332 case(STARTCOPY): /*! \todo */
333 case(STARTMOVE): /*! \todo */
334 case(ENDCOPY): /*! \todo */
335 case(ENDMOVE): /*! \todo */
336 case(ENDLINE): /*! \todo */
337 case(ENDBOX): /*! \todo */
338 case(ENDPICTURE): /*! \todo */
339 case(ENDCIRCLE): /*! \todo */
340 case(ENDARC): /*! \todo */
341 case(ENDPIN): /*! \todo */
342 case(ENDCOMP): /*! \todo */
343 case(DRAWTEXT): /*! \todo */
344 case(ENDTEXT): /*! \todo */
345 case(ENDROTATEP): /*! \todo */
346 case(ENDMIRROR): /*! \todo */
347 case(ZOOMBOXSTART): /*! \todo */
348 case(ZOOMBOXEND): /*! \todo */
349 case(STARTROUTENET): /*! \todo */
350 case(ENDROUTENET): /*! \todo */
351 case(MOUSEPAN): /*! \todo */
352 case(STARTPASTE): /*! \todo */
353 case(ENDPASTE): /*! \todo */
354 case(GRIPS): /*! \todo */
355 case(MCOPY): /*! \todo */
356 case(STARTMCOPY): /*! \todo */
357 case(ENDMCOPY): /*! \todo */
358 default:
359 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
360 w_current->toolbar_select), TRUE);
361 break;
365 /*! \brief Update sensitivity of relevant menu items
367 * \par Function Description
368 * Update sensitivity of relevant menu items.
370 * \param [in] w_current GSCHEM_TOPLEVEL structure
372 void i_update_menus(GSCHEM_TOPLEVEL *w_current)
374 TOPLEVEL *toplevel = w_current->toplevel;
376 * This is very simplistic. Right now it just disables all menu
377 * items which get greyed out when a component is not selected.
378 * Eventually what gets enabled/disabled
379 * should be based on what is in the selection list
382 g_assert(w_current != NULL);
383 g_assert(toplevel->page_current != NULL);
385 if ( geda_list_get_glist( toplevel->page_current->selection_list ) != NULL ) {
386 /* since one or more things are selected, we set these TRUE */
387 /* These strings should NOT be internationalized */
388 x_menus_sensitivity(w_current, "Edit/Cut Buffer", TRUE);
389 x_menus_sensitivity(w_current, "Edit/Copy Buffer", TRUE);
390 x_menus_sensitivity(w_current, "Edit/Edit...", TRUE);
391 x_menus_sensitivity(w_current, "Edit/Edit Text...", TRUE);
392 x_menus_sensitivity(w_current, "Edit/Copy Mode", TRUE);
393 x_menus_sensitivity(w_current, "Edit/Multiple Copy Mode", TRUE);
394 x_menus_sensitivity(w_current, "Edit/Move Mode", TRUE);
395 x_menus_sensitivity(w_current, "Edit/Delete", TRUE);
396 x_menus_sensitivity(w_current, "Edit/Rotate 90 Mode", TRUE);
397 x_menus_sensitivity(w_current, "Edit/Mirror Mode", TRUE);
398 x_menus_sensitivity(w_current, "Edit/Slot...", TRUE);
399 x_menus_sensitivity(w_current, "Edit/Color...", TRUE);
400 x_menus_sensitivity(w_current, "Edit/Lock", TRUE);
401 x_menus_sensitivity(w_current, "Edit/Unlock", TRUE);
402 x_menus_sensitivity(w_current, "Edit/Line Width & Type...", TRUE);
403 x_menus_sensitivity(w_current, "Edit/Fill Type...", TRUE);
404 x_menus_sensitivity(w_current, "Edit/Embed Component/Picture", TRUE);
405 x_menus_sensitivity(w_current, "Edit/Unembed Component/Picture", TRUE);
406 x_menus_sensitivity(w_current, "Edit/Update Component", TRUE);
407 x_menus_sensitivity(w_current, "Buffer/Copy into 1", TRUE);
408 x_menus_sensitivity(w_current, "Buffer/Copy into 2", TRUE);
409 x_menus_sensitivity(w_current, "Buffer/Copy into 3", TRUE);
410 x_menus_sensitivity(w_current, "Buffer/Copy into 4", TRUE);
411 x_menus_sensitivity(w_current, "Buffer/Copy into 5", TRUE);
412 x_menus_sensitivity(w_current, "Buffer/Cut into 1", TRUE);
413 x_menus_sensitivity(w_current, "Buffer/Cut into 2", TRUE);
414 x_menus_sensitivity(w_current, "Buffer/Cut into 3", TRUE);
415 x_menus_sensitivity(w_current, "Buffer/Cut into 4", TRUE);
416 x_menus_sensitivity(w_current, "Buffer/Cut into 5", TRUE);
417 x_menus_sensitivity(w_current, "Hierarchy/Down Schematic", TRUE);
418 x_menus_sensitivity(w_current, "Hierarchy/Down Symbol", TRUE);
419 x_menus_sensitivity(w_current, "Hierarchy/Documentation...", TRUE);
420 x_menus_sensitivity(w_current, "Attributes/Attach", TRUE);
421 x_menus_sensitivity(w_current, "Attributes/Detach", TRUE);
422 x_menus_sensitivity(w_current, "Attributes/Show Value", TRUE);
423 x_menus_sensitivity(w_current, "Attributes/Show Name", TRUE);
424 x_menus_sensitivity(w_current, "Attributes/Show Both", TRUE);
425 x_menus_sensitivity(w_current, "Attributes/Toggle Visibility", TRUE);
427 /* Menu items for hierarchy added by SDB 1.9.2005. */
428 x_menus_popup_sensitivity(w_current, "/Down Schematic", TRUE);
429 x_menus_popup_sensitivity(w_current, "/Down Symbol", TRUE);
430 /* x_menus_popup_sensitivity(w_current, "/Up", TRUE); */
432 } else {
433 /* Nothing is selected, grey these out */
434 /* These strings should NOT be internationalized */
435 x_menus_sensitivity(w_current, "Edit/Cut Buffer", FALSE);
436 x_menus_sensitivity(w_current, "Edit/Copy Buffer", FALSE);
437 x_menus_sensitivity(w_current, "Edit/Edit...", FALSE);
438 x_menus_sensitivity(w_current, "Edit/Edit Text...", FALSE);
439 x_menus_sensitivity(w_current, "Edit/Copy Mode", FALSE);
440 x_menus_sensitivity(w_current, "Edit/Multiple Copy Mode", FALSE);
441 x_menus_sensitivity(w_current, "Edit/Move Mode", FALSE);
442 x_menus_sensitivity(w_current, "Edit/Delete", FALSE);
443 x_menus_sensitivity(w_current, "Edit/Rotate 90 Mode", FALSE);
444 x_menus_sensitivity(w_current, "Edit/Mirror Mode", FALSE);
445 x_menus_sensitivity(w_current, "Edit/Slot...", FALSE);
446 x_menus_sensitivity(w_current, "Edit/Color...", FALSE);
447 x_menus_sensitivity(w_current, "Edit/Lock", FALSE);
448 x_menus_sensitivity(w_current, "Edit/Unlock", FALSE);
449 x_menus_sensitivity(w_current, "Edit/Line Width & Type...", FALSE);
450 x_menus_sensitivity(w_current, "Edit/Fill Type...", FALSE);
451 x_menus_sensitivity(w_current, "Edit/Embed Component/Picture", FALSE);
452 x_menus_sensitivity(w_current, "Edit/Unembed Component/Picture", FALSE);
453 x_menus_sensitivity(w_current, "Edit/Update Component", FALSE);
454 x_menus_sensitivity(w_current, "Buffer/Copy into 1", FALSE);
455 x_menus_sensitivity(w_current, "Buffer/Copy into 2", FALSE);
456 x_menus_sensitivity(w_current, "Buffer/Copy into 3", FALSE);
457 x_menus_sensitivity(w_current, "Buffer/Copy into 4", FALSE);
458 x_menus_sensitivity(w_current, "Buffer/Copy into 5", FALSE);
459 x_menus_sensitivity(w_current, "Buffer/Cut into 1", FALSE);
460 x_menus_sensitivity(w_current, "Buffer/Cut into 2", FALSE);
461 x_menus_sensitivity(w_current, "Buffer/Cut into 3", FALSE);
462 x_menus_sensitivity(w_current, "Buffer/Cut into 4", FALSE);
463 x_menus_sensitivity(w_current, "Buffer/Cut into 5", FALSE);
464 x_menus_sensitivity(w_current, "Hierarchy/Down Schematic", FALSE);
465 x_menus_sensitivity(w_current, "Hierarchy/Down Symbol", FALSE);
466 x_menus_sensitivity(w_current, "Hierarchy/Documentation...", FALSE);
467 x_menus_sensitivity(w_current, "Attributes/Attach", FALSE);
468 x_menus_sensitivity(w_current, "Attributes/Detach", FALSE);
469 x_menus_sensitivity(w_current, "Attributes/Show Value", FALSE);
470 x_menus_sensitivity(w_current, "Attributes/Show Name", FALSE);
471 x_menus_sensitivity(w_current, "Attributes/Show Both", FALSE);
472 x_menus_sensitivity(w_current, "Attributes/Toggle Visibility", FALSE);
474 /* Menu items for hierarchy added by SDB 1.9.2005. */
475 x_menus_popup_sensitivity(w_current, "/Down Schematic", FALSE);
476 x_menus_popup_sensitivity(w_current, "/Down Symbol", FALSE);
477 /* x_menus_popup_sensitivity(w_current, "/Up", FALSE); */
480 x_menus_sensitivity(w_current, "Edit/Paste Buffer", (object_buffer[0] != NULL));
481 x_menus_sensitivity(w_current, "Buffer/Paste from 1", (object_buffer[0] != NULL));
482 x_menus_sensitivity(w_current, "Buffer/Paste from 2", (object_buffer[1] != NULL));
483 x_menus_sensitivity(w_current, "Buffer/Paste from 3", (object_buffer[2] != NULL));
484 x_menus_sensitivity(w_current, "Buffer/Paste from 4", (object_buffer[3] != NULL));
485 x_menus_sensitivity(w_current, "Buffer/Paste from 5", (object_buffer[4] != NULL));
489 /*! \brief Set filename as gschem window title
491 * \par Function Description
492 * Set filename as gschem window title using
493 * the gnome HID format style.
495 * \param [in] w_current GSCHEM_TOPLEVEL structure
496 * \param [in] string The filename
498 void i_set_filename(GSCHEM_TOPLEVEL *w_current, const gchar *string)
500 gchar *print_string=NULL;
501 gchar *filename=NULL;
503 if (!w_current->main_window)
504 return;
505 if (string == NULL)
506 return;
508 filename = g_path_get_basename(string);
510 print_string = g_strdup_printf("%s - gschem", filename);
512 gtk_window_set_title(GTK_WINDOW(w_current->main_window),
513 print_string);
515 g_free(print_string);
516 g_free(filename);
519 /*! \brief Write the grid settings to the gschem status bar
521 * \par Function Description
522 * Write the grid settings to the gschem status bar.
523 * The function takes the current grid paramters of gschem
524 * and prints it to the status bar.
525 * The format is "Grid([SnapGridSize],[CurrentGridSize])"
527 * \param [in] w_current GSCHEM_TOPLEVEL structure
528 * \param [in] visible_grid Visible grid size
530 void i_set_grid(GSCHEM_TOPLEVEL *w_current, int visible_grid)
532 TOPLEVEL *toplevel = w_current->toplevel;
533 gchar *print_string=NULL;
534 gchar *snap=NULL;
535 gchar *grid=NULL;
537 if (!w_current->grid_label)
538 return;
540 if (!toplevel->snap)
541 snap = g_strdup(_("OFF"));
542 else
543 snap = g_strdup_printf("%d", toplevel->snap_size);
545 if (!w_current->grid)
546 grid = g_strdup(_("OFF"));
547 else
548 grid = g_strdup_printf("%d", visible_grid);
550 print_string = g_strdup_printf(_("Grid(%s, %s)"), snap, grid);
551 gtk_label_set(GTK_LABEL(w_current->grid_label), print_string);
553 g_free(print_string);
554 g_free(grid);
555 g_free(snap);