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
28 #ifdef HAVE_LIBDMALLOC
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
)
47 /* NOTE: consider optimizing this if same label */
48 gtk_label_set(GTK_LABEL(w_current
->status_label
),
53 /*! \brief Get string corresponding to the currently selected mode
55 * \par Function Description
56 * Returns a string describing the currently
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)
64 static const char *i_status_string(GSCHEM_TOPLEVEL
*w_current
)
68 switch ( w_current
->event_state
) {
70 case STARTROUTENET
: /*! \todo */
71 case ENDROUTENET
: /*! \todo */
77 return _("Select Mode");
80 return _("Component Mode"); /*EK* new */
83 return _("Text Mode"); /*EK* new */
86 return _("Copy Mode");
89 return _("Move Mode");
91 return _("Rotate Mode");
93 return _("Mirror Mode");
101 return _("Pan Mode");
105 buf
= g_strdup_printf(_("Paste %d Mode"), w_current
->buffer_number
+1);
110 if (w_current
->magneticnet_mode
)
111 return _("Magnetic Net Mode");
113 return _("Net Mode");
117 return _("Bus Mode");
120 return _("Line Mode");
123 return _("Box Mode");
126 return _("Picture Mode");
129 return _("Circle Mode");
132 return _("Arc Mode");
135 return _("Path Mode");
138 return _("Pin Mode");
144 return _("Multiple Copy");
147 return _("Multiple Copy Mode");
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
;
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");
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
,
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 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
) {
306 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
307 w_current
->toolbar_select
), TRUE
);
313 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
314 w_current
->toolbar_net
), TRUE
);
320 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
321 w_current
->toolbar_bus
), TRUE
);
324 case(GETCOORDS
): /*! \todo */
325 /* Don't set SELECT button active, since we're in GETCOORDS. */
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 */
367 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
368 w_current
->toolbar_select
), TRUE
);
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); */
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
)
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
),
523 g_free(print_string
);
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
;
545 if (!w_current
->grid_label
)
549 snap
= g_strdup(_("OFF"));
551 snap
= g_strdup_printf("%d", toplevel
->snap_size
);
553 if (!w_current
->grid
)
554 grid
= g_strdup(_("OFF"));
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
);