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/globals.h"
29 #include "../include/prototype.h"
31 #ifdef HAVE_LIBDMALLOC
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
)
50 /* NOTE: consider optimizing this if same label */
51 w_current
->DONT_RESIZE
=1;
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 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(TOPLEVEL
*w_current
)
72 switch ( w_current
->event_state
) {
74 case STARTROUTENET
: /*! \todo */
75 case ENDROUTENET
: /*! \todo */
81 return _("Select Mode");
84 return _("Attribute Mode"); /*EK* new */
87 return _("Component Mode"); /*EK* new */
91 return _("Text Mode"); /*EK* new */
94 return _("Copy Mode");
97 return _("Move Mode");
99 return _("Rotate Mode");
101 return _("Mirror Mode");
105 return _("Zoom Box");
109 return _("Pan Mode");
112 if (buf
) g_free(buf
);
113 buf
= g_strdup_printf(_("Paste %d Mode"), w_current
->buffer_number
+1);
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 TOPLEVEL structure
162 * \param [in] message The string to be displayed
164 void i_show_state(TOPLEVEL
*w_current
, const char *message
)
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");
177 array
[i
--] = _("Snap Off");
179 if(message
&& message
[0])
182 /* Skip over NULLs */
183 while(array
[i
] == NULL
)
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
,
196 i_update_status(w_current
, 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
217 * \par Function Description
218 * Set new state, then show state field including some
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
,
229 w_current
->event_state
= newstate
;
230 i_show_state(w_current
, message
);
233 /*! \todo Finish function documentation!!!
235 * \par Function Description
238 void i_update_middle_button(TOPLEVEL
*w_current
,
239 void (*func_ptr
)(gpointer
, guint
, GtkWidget
*),
244 if (func_ptr
== NULL
)
250 if (!w_current
->middle_label
)
253 switch(w_current
->middle_button
) {
255 /* remove this case eventually and make it a null case */
257 w_current
->DONT_RESIZE
= 1;
258 gtk_label_set(GTK_LABEL(w_current
->middle_label
),
264 w_current
->DONT_RESIZE
= 1;
266 gtk_label_set(GTK_LABEL(w_current
->middle_label
),
270 /* remove this case eventually and make it a null case */
272 w_current
->DONT_RESIZE
= 1;
273 gtk_label_set(GTK_LABEL(w_current
->middle_label
),
279 w_current
->DONT_RESIZE
= 1;
281 temp_string
= g_strconcat (_("Repeat/"), string
, NULL
);
283 gtk_label_set(GTK_LABEL(w_current
->middle_label
),
285 w_current
->last_callback
= func_ptr
;
292 /*! \todo Finish function documentation!!!
294 * \param [in] w_current TOPLEVEL structure
297 void i_update_toolbar(TOPLEVEL
*w_current
)
299 if (!w_current
->toolbars
)
302 switch(w_current
->event_state
) {
307 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
308 w_current
->toolbar_select
), TRUE
);
314 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
315 w_current
->toolbar_net
), TRUE
);
321 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
322 w_current
->toolbar_bus
), TRUE
);
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 */
366 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
367 w_current
->toolbar_select
), TRUE
);
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); */
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
);
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
);
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
);
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
);
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
);
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
)
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
),
545 g_free(print_string
);
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
;
566 if (!w_current
->grid_label
)
569 if (!w_current
->snap
)
570 snap
= g_strdup(_("OFF"));
572 snap
= g_strdup_printf("%d", w_current
->snap_size
);
574 if (!w_current
->grid
)
575 grid
= g_strdup(_("OFF"));
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
);