Log name of expander function.
[geda-gaf/berndj.git] / gschem / src / i_basic.c
bloba504743ecef8b15d68ad9de966c1d7a877497c7a
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 "gschem.h"
28 #ifdef HAVE_LIBDMALLOC
29 #include <dmalloc.h>
30 #endif
32 /*! \brief Update status bar string
34 * \par Function Description
35 * This function actually updates the status bar
36 * widget with the new string.
38 * \param [in] w_current GSCHEM_TOPLEVEL structure
39 * \param [in] string The new string to be shown in the status bar
41 static void i_update_status(GSCHEM_TOPLEVEL *w_current, const char *string)
43 if (!w_current->status_label)
44 return;
46 if (string) {
47 /* NOTE: consider optimizing this if same label */
48 gtk_label_set(GTK_LABEL(w_current->status_label),
49 (char *) string);
53 /*! \brief Get string corresponding to the currently selected mode
55 * \par Function Description
56 * Returns a string describing the currently
57 * selected mode.
59 * \param [in] w_current GSCHEM_TOPLEVEL structure
60 * \returns a string that will only last until the next time
61 * the function is called (which is probably just fine, really)
62 * *EK* Egil Kvaleberg
64 static const char *i_status_string(GSCHEM_TOPLEVEL *w_current)
66 static char *buf = 0;
68 switch ( w_current->event_state ) {
69 case NONE:
70 case STARTROUTENET: /*! \todo */
71 case ENDROUTENET: /*! \todo */
72 return "";
73 case STARTSELECT:
74 case SELECT:
75 case SBOX:
76 case GRIPS:
77 return _("Select Mode");
78 case DRAWCOMP:
79 case ENDCOMP:
80 return _("Component Mode"); /*EK* new */
81 case ENDTEXT:
82 case DRAWTEXT:
83 return _("Text Mode"); /*EK* new */
84 case STARTCOPY:
85 case ENDCOPY:
86 return _("Copy Mode");
87 case STARTMOVE:
88 case ENDMOVE:
89 return _("Move Mode");
90 case ENDROTATEP:
91 return _("Rotate Mode");
92 case ENDMIRROR:
93 return _("Mirror Mode");
94 case ZOOM:
95 case ZOOMBOXEND:
96 case ZOOMBOXSTART:
97 return _("Zoom Box");
98 case STARTPAN:
99 case PAN:
100 case MOUSEPAN:
101 return _("Pan Mode");
102 case STARTPASTE:
103 case ENDPASTE:
104 g_free(buf);
105 buf = g_strdup_printf(_("Paste %d Mode"), w_current->buffer_number+1);
106 return buf;
107 case STARTDRAWNET:
108 case DRAWNET:
109 case NETCONT:
110 if (w_current->magneticnet_mode)
111 return _("Magnetic Net Mode");
112 else
113 return _("Net Mode");
114 case STARTDRAWBUS:
115 case DRAWBUS:
116 case BUSCONT:
117 return _("Bus Mode");
118 case DRAWLINE:
119 case ENDLINE:
120 return _("Line Mode");
121 case DRAWBOX:
122 case ENDBOX:
123 return _("Box Mode");
124 case DRAWPICTURE:
125 case ENDPICTURE:
126 return _("Picture Mode");
127 case DRAWCIRCLE:
128 case ENDCIRCLE:
129 return _("Circle Mode");
130 case DRAWARC:
131 case ENDARC:
132 return _("Arc Mode");
133 case DRAWPATH:
134 case ENDPATH:
135 return _("Path Mode");
136 case DRAWPIN:
137 case ENDPIN:
138 return _("Pin Mode");
139 case COPY:
140 return _("Copy");
141 case MOVE:
142 return _("Move");
143 case MCOPY:
144 return _("Multiple Copy");
145 case STARTMCOPY:
146 case ENDMCOPY:
147 return _("Multiple Copy Mode");
148 case GETCOORDS:
149 return _("Executing macro");
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_default)
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)(),
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 if (w_current->event_state != GETCOORDS) {
298 /* Forget the current prompt, user will continue later. */
299 gtk_combo_box_set_active(GTK_COMBO_BOX(w_current->scm_prompts), -1);
302 switch(w_current->event_state) {
303 case(NONE):
304 case(SELECT):
305 case(STARTSELECT):
306 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
307 w_current->toolbar_select), TRUE);
308 break;
310 case(DRAWNET):
311 case(STARTDRAWNET):
312 case(NETCONT):
313 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
314 w_current->toolbar_net), TRUE);
315 break;
317 case(DRAWBUS):
318 case(STARTDRAWBUS):
319 case(BUSCONT):
320 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
321 w_current->toolbar_bus), TRUE);
322 break;
324 case(GETCOORDS): /*! \todo */
325 /* Don't set SELECT button active, since we're in GETCOORDS. */
326 break;
328 case(DRAWCOMP): /*! \todo */
329 case(DRAWLINE): /*! \todo */
330 case(DRAWBOX): /*! \todo */
331 case(DRAWPICTURE): /*! \todo */
332 case(DRAWPIN): /*! \todo */
333 case(DRAWCIRCLE): /*! \todo */
334 case(DRAWARC): /*! \todo */
335 case(MOVE): /*! \todo */
336 case(COPY): /*! \todo */
337 case(ZOOM): /*! \todo */
338 case(PAN): /*! \todo */
339 case(STARTPAN): /*! \todo */
340 case(STARTCOPY): /*! \todo */
341 case(STARTMOVE): /*! \todo */
342 case(ENDCOPY): /*! \todo */
343 case(ENDMOVE): /*! \todo */
344 case(ENDLINE): /*! \todo */
345 case(ENDBOX): /*! \todo */
346 case(ENDPICTURE): /*! \todo */
347 case(ENDCIRCLE): /*! \todo */
348 case(ENDARC): /*! \todo */
349 case(ENDPIN): /*! \todo */
350 case(ENDCOMP): /*! \todo */
351 case(DRAWTEXT): /*! \todo */
352 case(ENDTEXT): /*! \todo */
353 case(ENDROTATEP): /*! \todo */
354 case(ENDMIRROR): /*! \todo */
355 case(ZOOMBOXSTART): /*! \todo */
356 case(ZOOMBOXEND): /*! \todo */
357 case(STARTROUTENET): /*! \todo */
358 case(ENDROUTENET): /*! \todo */
359 case(MOUSEPAN): /*! \todo */
360 case(STARTPASTE): /*! \todo */
361 case(ENDPASTE): /*! \todo */
362 case(GRIPS): /*! \todo */
363 case(MCOPY): /*! \todo */
364 case(STARTMCOPY): /*! \todo */
365 case(ENDMCOPY): /*! \todo */
366 default:
367 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
368 w_current->toolbar_select), TRUE);
369 break;
373 /*! \brief Update sensitivity of relevant menu items
375 * \par Function Description
376 * Update sensitivity of relevant menu items.
378 * \param [in] w_current GSCHEM_TOPLEVEL structure
380 void i_update_menus(GSCHEM_TOPLEVEL *w_current)
382 TOPLEVEL *toplevel = w_current->toplevel;
384 * This is very simplistic. Right now it just disables all menu
385 * items which get greyed out when a component is not selected.
386 * Eventually what gets enabled/disabled
387 * should be based on what is in the selection list
390 g_assert(w_current != NULL);
391 g_assert(toplevel->page_current != NULL);
393 if (o_select_selected (w_current)) {
394 /* since one or more things are selected, we set these TRUE */
395 /* These strings should NOT be internationalized */
396 x_menus_sensitivity(w_current, "Edit/Cut Buffer", TRUE);
397 x_menus_sensitivity(w_current, "Edit/Copy Buffer", TRUE);
398 x_menus_sensitivity(w_current, "Edit/Edit...", TRUE);
399 x_menus_sensitivity(w_current, "Edit/Edit Text...", TRUE);
400 x_menus_sensitivity(w_current, "Edit/Copy Mode", TRUE);
401 x_menus_sensitivity(w_current, "Edit/Multiple Copy Mode", TRUE);
402 x_menus_sensitivity(w_current, "Edit/Move Mode", TRUE);
403 x_menus_sensitivity(w_current, "Edit/Delete", TRUE);
404 x_menus_sensitivity(w_current, "Edit/Rotate 90 Mode", TRUE);
405 x_menus_sensitivity(w_current, "Edit/Mirror Mode", TRUE);
406 x_menus_sensitivity(w_current, "Edit/Slot...", TRUE);
407 x_menus_sensitivity(w_current, "Edit/Color...", TRUE);
408 x_menus_sensitivity(w_current, "Edit/Lock", TRUE);
409 x_menus_sensitivity(w_current, "Edit/Unlock", TRUE);
410 x_menus_sensitivity(w_current, "Edit/Line Width & Type...", TRUE);
411 x_menus_sensitivity(w_current, "Edit/Fill Type...", TRUE);
412 x_menus_sensitivity(w_current, "Edit/Embed Component/Picture", TRUE);
413 x_menus_sensitivity(w_current, "Edit/Unembed Component/Picture", TRUE);
414 x_menus_sensitivity(w_current, "Edit/Update Component", TRUE);
415 x_menus_sensitivity(w_current, "Buffer/Copy into 1", TRUE);
416 x_menus_sensitivity(w_current, "Buffer/Copy into 2", TRUE);
417 x_menus_sensitivity(w_current, "Buffer/Copy into 3", TRUE);
418 x_menus_sensitivity(w_current, "Buffer/Copy into 4", TRUE);
419 x_menus_sensitivity(w_current, "Buffer/Copy into 5", TRUE);
420 x_menus_sensitivity(w_current, "Buffer/Cut into 1", TRUE);
421 x_menus_sensitivity(w_current, "Buffer/Cut into 2", TRUE);
422 x_menus_sensitivity(w_current, "Buffer/Cut into 3", TRUE);
423 x_menus_sensitivity(w_current, "Buffer/Cut into 4", TRUE);
424 x_menus_sensitivity(w_current, "Buffer/Cut into 5", TRUE);
425 x_menus_sensitivity(w_current, "Hierarchy/Down Schematic", TRUE);
426 x_menus_sensitivity(w_current, "Hierarchy/Down Symbol", TRUE);
427 x_menus_sensitivity(w_current, "Hierarchy/Documentation...", TRUE);
428 x_menus_sensitivity(w_current, "Attributes/Attach", TRUE);
429 x_menus_sensitivity(w_current, "Attributes/Detach", TRUE);
430 x_menus_sensitivity(w_current, "Attributes/Show Value", TRUE);
431 x_menus_sensitivity(w_current, "Attributes/Show Name", TRUE);
432 x_menus_sensitivity(w_current, "Attributes/Show Both", TRUE);
433 x_menus_sensitivity(w_current, "Attributes/Toggle Visibility", TRUE);
435 /* Menu items for hierarchy added by SDB 1.9.2005. */
436 x_menus_popup_sensitivity(w_current, "/Down Schematic", TRUE);
437 x_menus_popup_sensitivity(w_current, "/Down Symbol", TRUE);
438 /* x_menus_popup_sensitivity(w_current, "/Up", TRUE); */
440 } else {
441 /* Nothing is selected, grey these out */
442 /* These strings should NOT be internationalized */
443 x_menus_sensitivity(w_current, "Edit/Cut Buffer", FALSE);
444 x_menus_sensitivity(w_current, "Edit/Copy Buffer", FALSE);
445 x_menus_sensitivity(w_current, "Edit/Edit...", FALSE);
446 x_menus_sensitivity(w_current, "Edit/Edit Text...", FALSE);
447 x_menus_sensitivity(w_current, "Edit/Copy Mode", FALSE);
448 x_menus_sensitivity(w_current, "Edit/Multiple Copy Mode", FALSE);
449 x_menus_sensitivity(w_current, "Edit/Move Mode", FALSE);
450 x_menus_sensitivity(w_current, "Edit/Delete", FALSE);
451 x_menus_sensitivity(w_current, "Edit/Rotate 90 Mode", FALSE);
452 x_menus_sensitivity(w_current, "Edit/Mirror Mode", FALSE);
453 x_menus_sensitivity(w_current, "Edit/Slot...", FALSE);
454 x_menus_sensitivity(w_current, "Edit/Color...", FALSE);
455 x_menus_sensitivity(w_current, "Edit/Lock", FALSE);
456 x_menus_sensitivity(w_current, "Edit/Unlock", FALSE);
457 x_menus_sensitivity(w_current, "Edit/Line Width & Type...", FALSE);
458 x_menus_sensitivity(w_current, "Edit/Fill Type...", FALSE);
459 x_menus_sensitivity(w_current, "Edit/Embed Component/Picture", FALSE);
460 x_menus_sensitivity(w_current, "Edit/Unembed Component/Picture", FALSE);
461 x_menus_sensitivity(w_current, "Edit/Update Component", FALSE);
462 x_menus_sensitivity(w_current, "Buffer/Copy into 1", FALSE);
463 x_menus_sensitivity(w_current, "Buffer/Copy into 2", FALSE);
464 x_menus_sensitivity(w_current, "Buffer/Copy into 3", FALSE);
465 x_menus_sensitivity(w_current, "Buffer/Copy into 4", FALSE);
466 x_menus_sensitivity(w_current, "Buffer/Copy into 5", FALSE);
467 x_menus_sensitivity(w_current, "Buffer/Cut into 1", FALSE);
468 x_menus_sensitivity(w_current, "Buffer/Cut into 2", FALSE);
469 x_menus_sensitivity(w_current, "Buffer/Cut into 3", FALSE);
470 x_menus_sensitivity(w_current, "Buffer/Cut into 4", FALSE);
471 x_menus_sensitivity(w_current, "Buffer/Cut into 5", FALSE);
472 x_menus_sensitivity(w_current, "Hierarchy/Down Schematic", FALSE);
473 x_menus_sensitivity(w_current, "Hierarchy/Down Symbol", FALSE);
474 x_menus_sensitivity(w_current, "Hierarchy/Documentation...", FALSE);
475 x_menus_sensitivity(w_current, "Attributes/Attach", FALSE);
476 x_menus_sensitivity(w_current, "Attributes/Detach", FALSE);
477 x_menus_sensitivity(w_current, "Attributes/Show Value", FALSE);
478 x_menus_sensitivity(w_current, "Attributes/Show Name", FALSE);
479 x_menus_sensitivity(w_current, "Attributes/Show Both", FALSE);
480 x_menus_sensitivity(w_current, "Attributes/Toggle Visibility", FALSE);
482 /* Menu items for hierarchy added by SDB 1.9.2005. */
483 x_menus_popup_sensitivity(w_current, "/Down Schematic", FALSE);
484 x_menus_popup_sensitivity(w_current, "/Down Symbol", FALSE);
485 /* x_menus_popup_sensitivity(w_current, "/Up", FALSE); */
488 x_menus_sensitivity(w_current, "Edit/Paste Buffer", (object_buffer[0] != NULL));
489 x_menus_sensitivity(w_current, "Buffer/Paste from 1", (object_buffer[0] != NULL));
490 x_menus_sensitivity(w_current, "Buffer/Paste from 2", (object_buffer[1] != NULL));
491 x_menus_sensitivity(w_current, "Buffer/Paste from 3", (object_buffer[2] != NULL));
492 x_menus_sensitivity(w_current, "Buffer/Paste from 4", (object_buffer[3] != NULL));
493 x_menus_sensitivity(w_current, "Buffer/Paste from 5", (object_buffer[4] != NULL));
497 /*! \brief Set filename as gschem window title
499 * \par Function Description
500 * Set filename as gschem window title using
501 * the gnome HID format style.
503 * \param [in] w_current GSCHEM_TOPLEVEL structure
504 * \param [in] string The filename
506 void i_set_filename(GSCHEM_TOPLEVEL *w_current, const gchar *string)
508 gchar *print_string=NULL;
509 gchar *filename=NULL;
511 if (!w_current->main_window)
512 return;
513 if (string == NULL)
514 return;
516 filename = g_path_get_basename(string);
518 print_string = g_strdup_printf("%s - gschem", filename);
520 gtk_window_set_title(GTK_WINDOW(w_current->main_window),
521 print_string);
523 g_free(print_string);
524 g_free(filename);
527 /*! \brief Write the grid settings to the gschem status bar
529 * \par Function Description
530 * Write the grid settings to the gschem status bar.
531 * The function takes the current grid parameters of gschem
532 * and prints it to the status bar.
533 * The format is "Grid([SnapGridSize],[CurrentGridSize])"
535 * \param [in] w_current GSCHEM_TOPLEVEL structure
536 * \param [in] visible_grid Visible grid size
538 void i_set_grid(GSCHEM_TOPLEVEL *w_current, int visible_grid)
540 TOPLEVEL *toplevel = w_current->toplevel;
541 gchar *print_string=NULL;
542 gchar *snap=NULL;
543 gchar *grid=NULL;
545 if (!w_current->grid_label)
546 return;
548 if (!toplevel->snap)
549 snap = g_strdup(_("OFF"));
550 else
551 snap = g_strdup_printf("%d", toplevel->snap_size);
553 if (!w_current->grid)
554 grid = g_strdup(_("OFF"));
555 else
556 grid = g_strdup_printf("%d", visible_grid);
558 print_string = g_strdup_printf(_("Grid(%s, %s)"), snap, grid);
559 gtk_label_set(GTK_LABEL(w_current->grid_label), print_string);
561 g_free(print_string);
562 g_free(grid);
563 g_free(snap);