1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2010 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");
79 return _("Component Mode"); /*EK* new */
81 return _("Text Mode"); /*EK* new */
84 return _("Copy Mode");
87 return _("Move Mode");
89 return _("Rotate Mode");
91 return _("Mirror Mode");
103 buf
= g_strdup_printf(_("Paste %d Mode"), w_current
->buffer_number
+1);
108 if (w_current
->magneticnet_mode
)
109 return _("Magnetic Net Mode");
111 return _("Net Mode");
115 return _("Bus Mode");
118 return _("Line Mode");
121 return _("Box Mode");
124 return _("Picture Mode");
127 return _("Circle Mode");
130 return _("Arc Mode");
133 return _("Pin Mode");
139 return _("Multiple Copy");
142 return _("Multiple Copy Mode");
144 g_assert_not_reached();
145 return ""; /* should not happen */
148 /*! \brief Show state field
150 * \par Function Description
151 * Show state field on screen, possibly with the
152 * addition of an extra message
154 * \param [in] w_current GSCHEM_TOPLEVEL structure
155 * \param [in] message The string to be displayed
157 void i_show_state(GSCHEM_TOPLEVEL
*w_current
, const char *message
)
159 TOPLEVEL
*toplevel
= w_current
->toplevel
;
161 const gchar
*array
[5] = { NULL
};
162 int i
= 3; /* array[4] must be NULL */
164 /* Fill in the string array */
165 array
[i
--] = i_status_string(w_current
);
167 if(toplevel
->show_hidden_text
)
168 array
[i
--] = _("Show Hidden");
170 if(toplevel
->snap
== SNAP_OFF
)
171 array
[i
--] = _("Snap Off");
172 else if (toplevel
->snap
== SNAP_RESNAP
)
173 array
[i
--] = _("Resnap Active");
175 if(message
&& message
[0])
178 /* Skip over NULLs */
179 while(array
[i
] == NULL
)
182 what_to_say
= g_strjoinv(" - ", (gchar
**) array
+ i
);
184 if(w_current
->keyaccel_string
) {
185 gchar
*p
= what_to_say
;
187 what_to_say
= g_strdup_printf("%s \t\t %s", w_current
->keyaccel_string
,
192 i_update_status(w_current
, what_to_say
);
196 /*! \brief Set new state, then show state field
198 * \par Function Description
199 * Set new state, then show state field.
201 * \param [in] w_current GSCHEM_TOPLEVEL structure
202 * \param [in] newstate The new state
203 * *EK* Egil Kvaleberg
205 void i_set_state(GSCHEM_TOPLEVEL
*w_current
, enum x_states newstate
)
207 i_set_state_msg(w_current
, newstate
, NULL
);
210 /*! \brief Set new state, then show state field including some
213 * \par Function Description
214 * Set new state, then show state field including some
217 * \param [in] w_current GSCHEM_TOPLEVEL structure
218 * \param [in] newstate The new state
219 * \param [in] message Message to be shown
220 * *EK* Egil Kvaleberg
222 void i_set_state_msg(GSCHEM_TOPLEVEL
*w_current
, enum x_states newstate
,
225 w_current
->event_state
= newstate
;
226 i_show_state(w_current
, message
);
229 /*! \todo Finish function documentation!!!
231 * \par Function Description
234 void i_update_middle_button(GSCHEM_TOPLEVEL
*w_current
,
240 if (func_ptr
== NULL
)
246 if (!w_current
->middle_label
)
249 switch(w_current
->middle_button
) {
251 /* remove this case eventually and make it a null case */
253 gtk_label_set(GTK_LABEL(w_current
->middle_label
),
257 #ifdef HAVE_LIBSTROKE
259 gtk_label_set(GTK_LABEL(w_current
->middle_label
),
263 /* remove this case eventually and make it a null case */
265 gtk_label_set(GTK_LABEL(w_current
->middle_label
),
271 temp_string
= g_strconcat (_("Repeat/"), string
, NULL
);
273 gtk_label_set(GTK_LABEL(w_current
->middle_label
),
275 w_current
->last_callback
= func_ptr
;
282 /*! \todo Finish function documentation!!!
284 * \param [in] w_current GSCHEM_TOPLEVEL structure
287 void i_update_toolbar(GSCHEM_TOPLEVEL
*w_current
)
289 if (!w_current
->toolbars
)
292 switch(w_current
->event_state
) {
296 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
297 w_current
->toolbar_select
), TRUE
);
303 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
304 w_current
->toolbar_net
), TRUE
);
310 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
311 w_current
->toolbar_bus
), TRUE
);
314 case(DRAWLINE
): /*! \todo */
315 case(DRAWBOX
): /*! \todo */
316 case(DRAWPICTURE
): /*! \todo */
317 case(DRAWPIN
): /*! \todo */
318 case(DRAWCIRCLE
): /*! \todo */
319 case(DRAWARC
): /*! \todo */
320 case(MOVE
): /*! \todo */
321 case(COPY
): /*! \todo */
322 case(ZOOM
): /*! \todo */
323 case(PAN
): /*! \todo */
324 case(STARTPAN
): /*! \todo */
325 case(STARTCOPY
): /*! \todo */
326 case(STARTMOVE
): /*! \todo */
327 case(ENDCOPY
): /*! \todo */
328 case(ENDMOVE
): /*! \todo */
329 case(ENDLINE
): /*! \todo */
330 case(ENDBOX
): /*! \todo */
331 case(ENDPICTURE
): /*! \todo */
332 case(ENDCIRCLE
): /*! \todo */
333 case(ENDARC
): /*! \todo */
334 case(ENDPIN
): /*! \todo */
335 case(ENDCOMP
): /*! \todo */
336 case(ENDTEXT
): /*! \todo */
337 case(ENDROTATEP
): /*! \todo */
338 case(ENDMIRROR
): /*! \todo */
339 case(ZOOMBOXSTART
): /*! \todo */
340 case(ZOOMBOXEND
): /*! \todo */
341 case(STARTROUTENET
): /*! \todo */
342 case(ENDROUTENET
): /*! \todo */
343 case(MOUSEPAN
): /*! \todo */
344 case(STARTPASTE
): /*! \todo */
345 case(ENDPASTE
): /*! \todo */
346 case(GRIPS
): /*! \todo */
347 case(MCOPY
): /*! \todo */
348 case(STARTMCOPY
): /*! \todo */
349 case(ENDMCOPY
): /*! \todo */
351 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(
352 w_current
->toolbar_select
), TRUE
);
358 /*! \brief Update sensitivity of the Edit/Paste menu item
360 * \par Function Description
361 * Asynchronous callback to update sensitivity of the Edit/Paste
364 static void clipboard_usable_cb (int usable
, void *userdata
)
366 GSCHEM_TOPLEVEL
*w_current
= userdata
;
367 x_menus_sensitivity (w_current
, "_Edit/_Paste", usable
);
371 /*! \brief Update sensitivity of relevant menu items
373 * \par Function Description
374 * Update sensitivity of relevant menu items.
376 * \param [in] w_current GSCHEM_TOPLEVEL structure
378 void i_update_menus(GSCHEM_TOPLEVEL
*w_current
)
380 TOPLEVEL
*toplevel
= w_current
->toplevel
;
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(toplevel
->page_current
!= NULL
);
391 x_clipboard_query_usable (w_current
, clipboard_usable_cb
, w_current
);
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/Cu_t", TRUE
);
397 x_menus_sensitivity(w_current
, "_Edit/_Copy", TRUE
);
398 x_menus_sensitivity(w_current
, "_Edit/_Delete", TRUE
);
399 x_menus_sensitivity(w_current
, "_Edit/Copy Mode", TRUE
);
400 x_menus_sensitivity(w_current
, "_Edit/Multiple Copy Mode", TRUE
);
401 x_menus_sensitivity(w_current
, "_Edit/Move Mode", 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/Edit...", TRUE
);
405 x_menus_sensitivity(w_current
, "_Edit/Edit Text...", 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
, "Hie_rarchy/_Down Schematic", TRUE
);
426 x_menus_sensitivity(w_current
, "Hie_rarchy/Down _Symbol", TRUE
);
427 x_menus_sensitivity(w_current
, "Hie_rarchy/D_ocumentation...", TRUE
);
428 x_menus_sensitivity(w_current
, "A_ttributes/_Attach", TRUE
);
429 x_menus_sensitivity(w_current
, "A_ttributes/_Detach", TRUE
);
430 x_menus_sensitivity(w_current
, "A_ttributes/Show _Value", TRUE
);
431 x_menus_sensitivity(w_current
, "A_ttributes/Show _Name", TRUE
);
432 x_menus_sensitivity(w_current
, "A_ttributes/Show _Both", TRUE
);
433 x_menus_sensitivity(w_current
, "A_ttributes/_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/Cu_t", FALSE
);
444 x_menus_sensitivity(w_current
, "_Edit/_Copy", FALSE
);
445 x_menus_sensitivity(w_current
, "_Edit/_Delete", FALSE
);
446 x_menus_sensitivity(w_current
, "_Edit/Copy Mode", FALSE
);
447 x_menus_sensitivity(w_current
, "_Edit/Multiple Copy Mode", FALSE
);
448 x_menus_sensitivity(w_current
, "_Edit/Move Mode", 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/Edit...", FALSE
);
452 x_menus_sensitivity(w_current
, "_Edit/Edit Text...", 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
, "Hie_rarchy/_Down Schematic", FALSE
);
473 x_menus_sensitivity(w_current
, "Hie_rarchy/Down _Symbol", FALSE
);
474 x_menus_sensitivity(w_current
, "Hie_rarchy/D_ocumentation...", FALSE
);
475 x_menus_sensitivity(w_current
, "A_ttributes/_Attach", FALSE
);
476 x_menus_sensitivity(w_current
, "A_ttributes/_Detach", FALSE
);
477 x_menus_sensitivity(w_current
, "A_ttributes/Show _Value", FALSE
);
478 x_menus_sensitivity(w_current
, "A_ttributes/Show _Name", FALSE
);
479 x_menus_sensitivity(w_current
, "A_ttributes/Show _Both", FALSE
);
480 x_menus_sensitivity(w_current
, "A_ttributes/_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
, "_Buffer/Paste from 1", (object_buffer
[0] != NULL
));
489 x_menus_sensitivity(w_current
, "_Buffer/Paste from 2", (object_buffer
[1] != NULL
));
490 x_menus_sensitivity(w_current
, "_Buffer/Paste from 3", (object_buffer
[2] != NULL
));
491 x_menus_sensitivity(w_current
, "_Buffer/Paste from 4", (object_buffer
[3] != NULL
));
492 x_menus_sensitivity(w_current
, "_Buffer/Paste from 5", (object_buffer
[4] != NULL
));
496 /*! \brief Set filename as gschem window title
498 * \par Function Description
499 * Set filename as gschem window title using
500 * the gnome HID format style.
502 * \param [in] w_current GSCHEM_TOPLEVEL structure
503 * \param [in] string The filename
505 void i_set_filename(GSCHEM_TOPLEVEL
*w_current
, const gchar
*string
)
507 gchar
*print_string
=NULL
;
508 gchar
*filename
=NULL
;
510 if (!w_current
->main_window
)
515 filename
= g_path_get_basename(string
);
517 print_string
= g_strdup_printf("%s - gschem", filename
);
519 gtk_window_set_title(GTK_WINDOW(w_current
->main_window
),
522 g_free(print_string
);
526 /*! \brief Write the grid settings to the gschem status bar
528 * \par Function Description
529 * Write the grid settings to the gschem status bar.
530 * The function takes the current grid paramters of gschem
531 * and prints it to the status bar.
532 * The format is "Grid([SnapGridSize],[CurrentGridSize])"
534 * \param [in] w_current GSCHEM_TOPLEVEL structure
535 * \param [in] visible_grid Visible grid size
537 void i_update_grid_info (GSCHEM_TOPLEVEL
*w_current
)
539 TOPLEVEL
*toplevel
= w_current
->toplevel
;
540 gchar
*print_string
=NULL
;
544 if (!w_current
->grid_label
)
547 switch (toplevel
->snap
) {
549 snap
= g_strdup(_("OFF"));
552 snap
= g_strdup_printf("%d", toplevel
->snap_size
);
555 snap
= g_strdup_printf("%dR", toplevel
->snap_size
);
558 g_critical("i_set_grid: toplevel->snap out of range: %d\n",
562 if (w_current
->grid
== GRID_NONE
) {
563 grid
= g_strdup(_("OFF"));
565 int visible_grid
= x_grid_query_drawn_spacing (w_current
);
566 if (visible_grid
== -1)
567 grid
= g_strdup (_("NONE"));
569 grid
= g_strdup_printf("%d", visible_grid
);
572 print_string
= g_strdup_printf(_("Grid(%s, %s)"), snap
, grid
);
573 gtk_label_set(GTK_LABEL(w_current
->grid_label
), print_string
);
575 g_free(print_string
);