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
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
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
)
51 /* NOTE: consider optimizing this if same label */
52 gtk_label_set(GTK_LABEL(w_current
->status_label
),
57 /*! \brief Get string corresponding to the currently selected mode
59 * \par Function Description
60 * Returns a string describing the currently
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)
68 static const char *i_status_string(GSCHEM_TOPLEVEL
*w_current
)
72 switch ( w_current
->event_state
) {
74 case STARTROUTENET
: /*! \todo */
75 case ENDROUTENET
: /*! \todo */
81 return _("Select Mode");
84 return _("Component Mode"); /*EK* new */
88 return _("Text Mode"); /*EK* new */
91 return _("Copy Mode");
94 return _("Move Mode");
96 return _("Rotate Mode");
98 return _("Mirror Mode");
102 return _("Zoom Box");
106 return _("Pan Mode");
109 if (buf
) g_free(buf
);
110 buf
= g_strdup_printf(_("Paste %d Mode"), w_current
->buffer_number
+1);
115 if (w_current
->magneticnet_mode
)
116 return _("Magnetic Net Mode");
118 return _("Net Mode");
122 return _("Bus Mode");
125 return _("Line Mode");
128 return _("Box Mode");
131 return _("Picture Mode");
134 return _("Circle Mode");
137 return _("Arc Mode");
140 return _("Pin Mode");
146 return _("Multiple Copy");
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
;
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");
178 array
[i
--] = _("Snap Off");
180 if(message
&& message
[0])
183 /* Skip over NULLs */
184 while(array
[i
] == NULL
)
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
,
197 i_update_status(w_current
, 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
218 * \par Function Description
219 * Set new state, then show state field including some
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
,
230 w_current
->event_state
= newstate
;
231 i_show_state(w_current
, message
);
234 /*! \todo Finish function documentation!!!
236 * \par Function Description
239 void i_update_middle_button(GSCHEM_TOPLEVEL
*w_current
,
240 void (*func_ptr
)(gpointer
, guint
, GtkWidget
*),
245 if (func_ptr
== NULL
)
251 if (!w_current
->middle_label
)
254 switch(w_current
->middle_button
) {
256 /* remove this case eventually and make it a null case */
258 gtk_label_set(GTK_LABEL(w_current
->middle_label
),
264 gtk_label_set(GTK_LABEL(w_current
->middle_label
),
268 /* remove this case eventually and make it a null case */
270 gtk_label_set(GTK_LABEL(w_current
->middle_label
),
276 temp_string
= g_strconcat (_("Repeat/"), string
, NULL
);
278 gtk_label_set(GTK_LABEL(w_current
->middle_label
),
280 w_current
->last_callback
= func_ptr
;
287 /*! \todo Finish function documentation!!!
289 * \param [in] w_current GSCHEM_TOPLEVEL structure
292 void i_update_toolbar(GSCHEM_TOPLEVEL
*w_current
)
294 if (!w_current
->toolbars
)
297 switch(w_current
->event_state
) {
302 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
303 w_current
->toolbar_select
), TRUE
);
309 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
310 w_current
->toolbar_net
), TRUE
);
316 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
317 w_current
->toolbar_bus
), TRUE
);
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 */
359 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
360 w_current
->toolbar_select
), TRUE
);
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); */
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
)
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
),
515 g_free(print_string
);
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
;
537 if (!w_current
->grid_label
)
541 snap
= g_strdup(_("OFF"));
543 snap
= g_strdup_printf("%d", toplevel
->snap_size
);
545 if (!w_current
->grid
)
546 grid
= g_strdup(_("OFF"));
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
);