Updated copyright text/header in most source files.
[geda-gaf.git] / gschem / src / i_basic.c
blob254e5f6d9de15f8217262088ef07e75f6ef9c2ea
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/globals.h"
29 #include "../include/prototype.h"
31 #ifdef HAVE_LIBDMALLOC
32 #include <dmalloc.h>
33 #endif
35 /*! \brief Update status bar string
37 * \par Function Description
38 * This function actually updates the status bar
39 * widget with the new string.
41 * \param [in] w_current TOPLEVEL structure
42 * \param [in] string The new string to be shown in the status bar
44 static void i_update_status(TOPLEVEL *w_current, const char *string)
46 if (!w_current->status_label)
47 return;
49 if (string) {
50 /* NOTE: consider optimizing this if same label */
51 w_current->DONT_RESIZE=1;
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 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(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 DRAWATTRIB:
83 case ENDATTRIB:
84 return _("Attribute Mode"); /*EK* new */
85 case DRAWCOMP:
86 case ENDCOMP:
87 return _("Component Mode"); /*EK* new */
88 case TEXTENTRY:
89 case ENDTEXT:
90 case DRAWTEXT:
91 return _("Text Mode"); /*EK* new */
92 case STARTCOPY:
93 case ENDCOPY:
94 return _("Copy Mode");
95 case STARTMOVE:
96 case ENDMOVE:
97 return _("Move Mode");
98 case ENDROTATEP:
99 return _("Rotate Mode");
100 case ENDMIRROR:
101 return _("Mirror Mode");
102 case ZOOM:
103 case ZOOMBOXEND:
104 case ZOOMBOXSTART:
105 return _("Zoom Box");
106 case STARTPAN:
107 case PAN:
108 case MOUSEPAN:
109 return _("Pan Mode");
110 case STARTPASTE:
111 case ENDPASTE:
112 if (buf) g_free(buf);
113 buf = g_strdup_printf(_("Paste %d Mode"), w_current->buffer_number+1);
114 return buf;
115 case STARTDRAWNET:
116 case DRAWNET:
117 case NETCONT:
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 TOPLEVEL structure
162 * \param [in] message The string to be displayed
164 void i_show_state(TOPLEVEL *w_current, const char *message)
166 gchar *what_to_say;
167 const gchar *array[5] = { NULL };
168 int i = 3; /* array[4] must be NULL */
170 /* Fill in the string array */
171 array[i--] = i_status_string(w_current);
173 if(w_current->show_hidden_text)
174 array[i--] = _("Show Hidden");
176 if(!w_current->snap)
177 array[i--] = _("Snap Off");
179 if(message && message[0])
180 array[i] = message;
182 /* Skip over NULLs */
183 while(array[i] == NULL)
184 i++;
186 what_to_say = g_strjoinv(" - ", (gchar **) array + i);
188 if(w_current->keyaccel_string) {
189 gchar *p = what_to_say;
191 what_to_say = g_strdup_printf("%s \t\t %s", w_current->keyaccel_string,
192 what_to_say);
193 g_free(p);
196 i_update_status(w_current, what_to_say);
197 g_free(what_to_say);
200 /*! \brief Set new state, then show state field
202 * \par Function Description
203 * Set new state, then show state field.
205 * \param [in] w_current TOPLEVEL structure
206 * \param [in] newstate The new state
207 * *EK* Egil Kvaleberg
209 void i_set_state(TOPLEVEL *w_current, enum x_states newstate)
211 i_set_state_msg(w_current, newstate, NULL);
214 /*! \brief Set new state, then show state field including some
215 * message
217 * \par Function Description
218 * Set new state, then show state field including some
219 * message.
221 * \param [in] w_current TOPLEVEL structure
222 * \param [in] newstate The new state
223 * \param [in] message Message to be shown
224 * *EK* Egil Kvaleberg
226 void i_set_state_msg(TOPLEVEL *w_current, enum x_states newstate,
227 const char *message)
229 w_current->event_state = newstate;
230 i_show_state(w_current, message);
233 /*! \todo Finish function documentation!!!
234 * \brief
235 * \par Function Description
238 void i_update_middle_button(TOPLEVEL *w_current,
239 void (*func_ptr)(gpointer, guint, GtkWidget*),
240 const char *string)
242 char *temp_string;
244 if (func_ptr == NULL)
245 return;
247 if (string == NULL)
248 return;
250 if (!w_current->middle_label)
251 return;
253 switch(w_current->middle_button) {
255 /* remove this case eventually and make it a null case */
256 case(ACTION):
257 w_current->DONT_RESIZE = 1;
258 gtk_label_set(GTK_LABEL(w_current->middle_label),
259 _("Action"));
260 break;
262 #ifdef HAS_LIBSTROKE
263 case(STROKE):
264 w_current->DONT_RESIZE = 1;
266 gtk_label_set(GTK_LABEL(w_current->middle_label),
267 _("Stroke"));
268 break;
269 #else
270 /* remove this case eventually and make it a null case */
271 case(STROKE):
272 w_current->DONT_RESIZE = 1;
273 gtk_label_set(GTK_LABEL(w_current->middle_label),
274 _("none"));
275 break;
276 #endif
278 case(REPEAT):
279 w_current->DONT_RESIZE = 1;
281 temp_string = g_strconcat (_("Repeat/"), string, NULL);
283 gtk_label_set(GTK_LABEL(w_current->middle_label),
284 temp_string);
285 w_current->last_callback = func_ptr;
286 g_free(temp_string);
287 break;
292 /*! \todo Finish function documentation!!!
293 * \brief
294 * \param [in] w_current TOPLEVEL structure
297 void i_update_toolbar(TOPLEVEL *w_current)
299 if (!w_current->toolbars)
300 return;
302 switch(w_current->event_state) {
303 case(NONE):
304 case(SELECT):
305 case(STARTSELECT):
306 case(TEXTENTRY):
307 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
308 w_current->toolbar_select), TRUE);
309 break;
311 case(DRAWNET):
312 case(STARTDRAWNET):
313 case(NETCONT):
314 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
315 w_current->toolbar_net), TRUE);
316 break;
318 case(DRAWBUS):
319 case(STARTDRAWBUS):
320 case(BUSCONT):
321 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
322 w_current->toolbar_bus), TRUE);
323 break;
325 case(DRAWCOMP): /*! \todo */
326 case(DRAWLINE): /*! \todo */
327 case(DRAWBOX): /*! \todo */
328 case(DRAWPICTURE): /*! \todo */
329 case(DRAWPIN): /*! \todo */
330 case(DRAWCIRCLE): /*! \todo */
331 case(DRAWARC): /*! \todo */
332 case(MOVE): /*! \todo */
333 case(COPY): /*! \todo */
334 case(ZOOM): /*! \todo */
335 case(PAN): /*! \todo */
336 case(STARTPAN): /*! \todo */
337 case(STARTCOPY): /*! \todo */
338 case(STARTMOVE): /*! \todo */
339 case(ENDCOPY): /*! \todo */
340 case(ENDMOVE): /*! \todo */
341 case(ENDLINE): /*! \todo */
342 case(ENDBOX): /*! \todo */
343 case(ENDPICTURE): /*! \todo */
344 case(ENDCIRCLE): /*! \todo */
345 case(ENDARC): /*! \todo */
346 case(ENDPIN): /*! \todo */
347 case(ENDCOMP): /*! \todo */
348 case(DRAWATTRIB): /*! \todo */
349 case(ENDATTRIB): /*! \todo */
350 case(DRAWTEXT): /*! \todo */
351 case(ENDTEXT): /*! \todo */
352 case(ENDROTATEP): /*! \todo */
353 case(ENDMIRROR): /*! \todo */
354 case(ZOOMBOXSTART): /*! \todo */
355 case(ZOOMBOXEND): /*! \todo */
356 case(STARTROUTENET): /*! \todo */
357 case(ENDROUTENET): /*! \todo */
358 case(MOUSEPAN): /*! \todo */
359 case(STARTPASTE): /*! \todo */
360 case(ENDPASTE): /*! \todo */
361 case(GRIPS): /*! \todo */
362 case(MCOPY): /*! \todo */
363 case(STARTMCOPY): /*! \todo */
364 case(ENDMCOPY): /*! \todo */
365 default:
366 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
367 w_current->toolbar_select), TRUE);
368 break;
372 /*! \brief Update sensitivity of relevant menu items
374 * \par Function Description
375 * Update sensitivity of relevant menu items.
377 * \param [in] w_current TOPLEVEL structure
379 void i_update_menus(TOPLEVEL *w_current)
382 * This is very simplistic. Right now it just disables all menu
383 * items which get greyed out when a component is not selected.
384 * Eventually what gets enabled/disabled
385 * should be based on what is in the selection list
388 g_assert(w_current != NULL);
389 g_assert(w_current->page_current != NULL);
391 if (w_current->page_current->selection_list != NULL) {
392 /* since one or more things are selected, we set these TRUE */
393 /* These strings should NOT be internationalized */
394 x_menus_sensitivity(w_current, "Edit/Cut Buffer", TRUE);
395 x_menus_sensitivity(w_current, "Edit/Copy Buffer", TRUE);
396 x_menus_sensitivity(w_current, "Edit/Edit...", TRUE);
397 x_menus_sensitivity(w_current, "Edit/Edit Text...", TRUE);
398 x_menus_sensitivity(w_current, "Edit/Copy Mode", TRUE);
399 x_menus_sensitivity(w_current, "Edit/Multiple Copy Mode", TRUE);
400 x_menus_sensitivity(w_current, "Edit/Move Mode", TRUE);
401 x_menus_sensitivity(w_current, "Edit/Delete", TRUE);
402 x_menus_sensitivity(w_current, "Edit/Rotate 90 Mode", TRUE);
403 x_menus_sensitivity(w_current, "Edit/Mirror Mode", TRUE);
404 x_menus_sensitivity(w_current, "Edit/Slot...", TRUE);
405 x_menus_sensitivity(w_current, "Edit/Color...", TRUE);
406 x_menus_sensitivity(w_current, "Edit/Lock", TRUE);
407 x_menus_sensitivity(w_current, "Edit/Unlock", TRUE);
408 x_menus_sensitivity(w_current, "Edit/Line Width & Type...", TRUE);
409 x_menus_sensitivity(w_current, "Edit/Fill Type...", TRUE);
410 x_menus_sensitivity(w_current, "Edit/Embed Component/Picture", TRUE);
411 x_menus_sensitivity(w_current, "Edit/Unembed Component/Picture", TRUE);
412 x_menus_sensitivity(w_current, "Edit/Update Component", TRUE);
413 x_menus_sensitivity(w_current, "Buffer/Copy into 1", TRUE);
414 x_menus_sensitivity(w_current, "Buffer/Copy into 2", TRUE);
415 x_menus_sensitivity(w_current, "Buffer/Copy into 3", TRUE);
416 x_menus_sensitivity(w_current, "Buffer/Copy into 4", TRUE);
417 x_menus_sensitivity(w_current, "Buffer/Copy into 5", TRUE);
418 x_menus_sensitivity(w_current, "Buffer/Cut into 1", TRUE);
419 x_menus_sensitivity(w_current, "Buffer/Cut into 2", TRUE);
420 x_menus_sensitivity(w_current, "Buffer/Cut into 3", TRUE);
421 x_menus_sensitivity(w_current, "Buffer/Cut into 4", TRUE);
422 x_menus_sensitivity(w_current, "Buffer/Cut into 5", TRUE);
423 x_menus_sensitivity(w_current, "Hierarchy/Down Schematic", TRUE);
424 x_menus_sensitivity(w_current, "Hierarchy/Down Symbol", TRUE);
425 x_menus_sensitivity(w_current, "Hierarchy/Documentation", TRUE);
426 x_menus_sensitivity(w_current, "Attributes/Attach", TRUE);
427 x_menus_sensitivity(w_current, "Attributes/Detach", TRUE);
428 x_menus_sensitivity(w_current, "Attributes/Show Value", TRUE);
429 x_menus_sensitivity(w_current, "Attributes/Show Name", TRUE);
430 x_menus_sensitivity(w_current, "Attributes/Show Both", TRUE);
431 x_menus_sensitivity(w_current, "Attributes/Toggle Visibility", TRUE);
433 /* Menu items for hierarchy added by SDB 1.9.2005. */
434 x_menus_popup_sensitivity(w_current, "/Down Schematic", TRUE);
435 x_menus_popup_sensitivity(w_current, "/Down Symbol", TRUE);
436 /* x_menus_popup_sensitivity(w_current, "/Up", TRUE); */
438 } else {
439 /* Nothing is selected, grey these out */
440 /* These strings should NOT be internationalized */
441 x_menus_sensitivity(w_current, "Edit/Cut Buffer", FALSE);
442 x_menus_sensitivity(w_current, "Edit/Copy Buffer", FALSE);
443 x_menus_sensitivity(w_current, "Edit/Edit...", FALSE);
444 x_menus_sensitivity(w_current, "Edit/Edit Text...", FALSE);
445 x_menus_sensitivity(w_current, "Edit/Copy Mode", FALSE);
446 x_menus_sensitivity(w_current, "Edit/Multiple Copy Mode", FALSE);
447 x_menus_sensitivity(w_current, "Edit/Move Mode", FALSE);
448 x_menus_sensitivity(w_current, "Edit/Delete", FALSE);
449 x_menus_sensitivity(w_current, "Edit/Rotate 90 Mode", FALSE);
450 x_menus_sensitivity(w_current, "Edit/Mirror Mode", FALSE);
451 x_menus_sensitivity(w_current, "Edit/Slot...", FALSE);
452 x_menus_sensitivity(w_current, "Edit/Color...", FALSE);
453 x_menus_sensitivity(w_current, "Edit/Lock", FALSE);
454 x_menus_sensitivity(w_current, "Edit/Unlock", FALSE);
455 x_menus_sensitivity(w_current, "Edit/Line Width & Type...", FALSE);
456 x_menus_sensitivity(w_current, "Edit/Fill Type...", FALSE);
457 x_menus_sensitivity(w_current, "Edit/Embed Component/Picture", FALSE);
458 x_menus_sensitivity(w_current, "Edit/Unembed Component/Picture", FALSE);
459 x_menus_sensitivity(w_current, "Edit/Update Component", FALSE);
460 x_menus_sensitivity(w_current, "Buffer/Copy into 1", FALSE);
461 x_menus_sensitivity(w_current, "Buffer/Copy into 2", FALSE);
462 x_menus_sensitivity(w_current, "Buffer/Copy into 3", FALSE);
463 x_menus_sensitivity(w_current, "Buffer/Copy into 4", FALSE);
464 x_menus_sensitivity(w_current, "Buffer/Copy into 5", FALSE);
465 x_menus_sensitivity(w_current, "Buffer/Cut into 1", FALSE);
466 x_menus_sensitivity(w_current, "Buffer/Cut into 2", FALSE);
467 x_menus_sensitivity(w_current, "Buffer/Cut into 3", FALSE);
468 x_menus_sensitivity(w_current, "Buffer/Cut into 4", FALSE);
469 x_menus_sensitivity(w_current, "Buffer/Cut into 5", FALSE);
470 x_menus_sensitivity(w_current, "Hierarchy/Down Schematic", FALSE);
471 x_menus_sensitivity(w_current, "Hierarchy/Down Symbol", FALSE);
472 x_menus_sensitivity(w_current, "Hierarchy/Documentation", FALSE);
473 x_menus_sensitivity(w_current, "Attributes/Attach", FALSE);
474 x_menus_sensitivity(w_current, "Attributes/Detach", FALSE);
475 x_menus_sensitivity(w_current, "Attributes/Show Value", FALSE);
476 x_menus_sensitivity(w_current, "Attributes/Show Name", FALSE);
477 x_menus_sensitivity(w_current, "Attributes/Show Both", FALSE);
478 x_menus_sensitivity(w_current, "Attributes/Toggle Visibility", FALSE);
480 /* Menu items for hierarchy added by SDB 1.9.2005. */
481 x_menus_popup_sensitivity(w_current, "/Down Schematic", FALSE);
482 x_menus_popup_sensitivity(w_current, "/Down Symbol", FALSE);
483 /* x_menus_popup_sensitivity(w_current, "/Up", FALSE); */
486 if ((object_buffer[0] != NULL) && (object_buffer[0]->next != NULL)) {
487 x_menus_sensitivity(w_current, "Edit/Paste Buffer", TRUE);
488 x_menus_sensitivity(w_current, "Buffer/Paste from 1", TRUE);
489 } else {
490 x_menus_sensitivity(w_current, "Edit/Paste Buffer", FALSE);
491 x_menus_sensitivity(w_current, "Buffer/Paste from 1", FALSE);
494 if ((object_buffer[1] != NULL) && (object_buffer[1]->next != NULL)) {
495 x_menus_sensitivity(w_current, "Buffer/Paste from 2", TRUE);
496 } else {
497 x_menus_sensitivity(w_current, "Buffer/Paste from 2", FALSE);
500 if ((object_buffer[2] != NULL) && (object_buffer[2]->next != NULL)) {
501 x_menus_sensitivity(w_current, "Buffer/Paste from 3", TRUE);
502 } else {
503 x_menus_sensitivity(w_current, "Buffer/Paste from 3", FALSE);
506 if ((object_buffer[3] != NULL) && (object_buffer[3]->next != NULL)) {
507 x_menus_sensitivity(w_current, "Buffer/Paste from 4", TRUE);
508 } else {
509 x_menus_sensitivity(w_current, "Buffer/Paste from 4", FALSE);
512 if ((object_buffer[4] != NULL) && (object_buffer[4]->next != NULL)) {
513 x_menus_sensitivity(w_current, "Buffer/Paste from 5", TRUE);
514 } else {
515 x_menus_sensitivity(w_current, "Buffer/Paste from 5", FALSE);
519 /*! \brief Set filename as gschem window title
521 * \par Function Description
522 * Set filename as gschem window title using
523 * the gnome HID format style.
525 * \param [in] w_current TOPLEVEL structure
526 * \param [in] string The filename
528 void i_set_filename(TOPLEVEL *w_current, const gchar *string)
530 gchar *print_string=NULL;
531 gchar *filename=NULL;
533 if (!w_current->main_window)
534 return;
535 if (string == NULL)
536 return;
538 filename = g_path_get_basename(string);
540 print_string = g_strdup_printf("%s - gschem", filename);
542 gtk_window_set_title(GTK_WINDOW(w_current->main_window),
543 print_string);
545 g_free(print_string);
546 g_free(filename);
549 /*! \brief Write the grid settings to the gschem status bar
551 * \par Function Description
552 * Write the grid settings to the gschem status bar.
553 * The function takes the current grid paramters of gschem
554 * and prints it to the status bar.
555 * The format is "Grid([SnapGridSize],[CurrentGridSize])"
557 * \param [in] w_current TOPLEVEL structure
558 * \param [in] visible_grid Visible grid size
560 void i_set_grid(TOPLEVEL *w_current, int visible_grid)
562 gchar *print_string=NULL;
563 gchar *snap=NULL;
564 gchar *grid=NULL;
566 if (!w_current->grid_label)
567 return;
569 if (!w_current->snap)
570 snap = g_strdup(_("OFF"));
571 else
572 snap = g_strdup_printf("%d", w_current->snap_size);
574 if (!w_current->grid)
575 grid = g_strdup(_("OFF"));
576 else
577 grid = g_strdup_printf("%d", visible_grid);
579 print_string = g_strdup_printf(_("Grid(%s, %s)"), snap, grid);
580 gtk_label_set(GTK_LABEL(w_current->grid_label), print_string);
582 g_free(print_string);
583 g_free(grid);
584 g_free(snap);