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 /*! \todo STILL NEED to clean up line lengths in aa and tr
34 #ifdef HAVE_LIBDMALLOC
38 /***************** Start of Attrib Edit dialog box ********************/
39 /*! \section attrib-edit-dialog-box Atrib Edit Dialog Box */
41 /*! \todo Finish function documentation!!!
43 * \par Function Documentation
46 gint
option_menu_get_history (GtkOptionMenu
*option_menu
)
48 GtkWidget
*active_widget
;
50 g_return_val_if_fail (GTK_IS_OPTION_MENU (option_menu
), -1);
52 active_widget
= gtk_menu_get_active (GTK_MENU (option_menu
->menu
));
55 return g_list_index (GTK_MENU_SHELL (option_menu
->menu
)->children
,
61 /*! \todo Finish function documentation!!!
63 * \par Function Documentation
66 void attrib_edit_dialog_ok(GtkWidget
* w
, GSCHEM_TOPLEVEL
*w_current
)
68 TOPLEVEL
*toplevel
= w_current
->toplevel
;
69 const char *value
, *label
;
71 GtkEntry
*value_entry
, *name_entry
;
72 GtkWidget
*visbutton
, *show_options
;
73 GtkWidget
*addtocompsbutton
, *addtonetsbutton
, *addtoallbutton
;
74 GtkWidget
*overwritebutton
;
77 GList
*s_current
= NULL
;
82 int nsel
=0, addto
=0, replace
=0, addmask
=0;
86 i_set_state(w_current
, SELECT
);
89 gtk_object_get_data(GTK_OBJECT(w_current
->aewindow
), "value_entry");
91 gtk_object_get_data(GTK_OBJECT(w_current
->aewindow
), "attrib_combo_entry");
93 gtk_object_get_data(GTK_OBJECT(w_current
->aewindow
), "visbutton");
95 gtk_object_get_data(GTK_OBJECT(w_current
->aewindow
), "show_options");
97 value
= gtk_entry_get_text(value_entry
);
98 label
= gtk_entry_get_text(name_entry
);
99 newtext
= g_strconcat (label
, "=", value
, NULL
);
101 if (!x_dialog_validate_attribute(GTK_WINDOW(w_current
->aewindow
), newtext
))
107 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(visbutton
)))
112 option_index
= option_menu_get_history(GTK_OPTION_MENU (show_options
));
113 switch(option_index
) {
123 show
= SHOW_NAME_VALUE
;
127 fprintf(stderr
, _("Got invalid show option; defaulting to show both\n"));
128 show
= SHOW_NAME_VALUE
;
133 gtk_object_get_data(GTK_OBJECT(w_current
->aewindow
), "attrib");
137 s_current
= geda_list_get_glist( toplevel
->page_current
->selection_list
);
138 while (s_current
!= NULL
) {
139 object
= s_current
->data
;
140 if (object
== NULL
) {
141 fprintf(stderr
, _("ERROR: NULL object!\n"));
144 if (!object
->attached_to
) {
147 s_current
= g_list_next(s_current
);
149 s_current
= geda_list_get_glist( toplevel
->page_current
->selection_list
);
153 gtk_object_get_data(GTK_OBJECT(w_current
->aewindow
),
157 gtk_object_get_data(GTK_OBJECT(w_current
->aewindow
),
161 gtk_object_get_data(GTK_OBJECT(w_current
->aewindow
),
165 gtk_object_get_data(GTK_OBJECT(w_current
->aewindow
),
168 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(overwritebutton
))) {
174 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(addtoallbutton
))) {
177 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(addtocompsbutton
))) {
180 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(addtonetsbutton
))) {
184 while (s_current
!= NULL
) {
187 object
= s_current
->data
;
188 if (object
&& !object
->attached_to
&& object
->type
!= OBJ_TEXT
) {
190 if (object
->type
== OBJ_COMPLEX
|| object
->type
== OBJ_PLACEHOLDER
) {
193 if (object
->type
== OBJ_NET
) {
197 if (addmask
& addto
) {
198 a_iter
= object
->attribs
;
200 while (a_iter
!= NULL
) {
201 a_current
= a_iter
->data
;
202 const gchar
*str
= o_text_get_string(a_current
);
204 if (!strncmp (str
, newtext
, strchr (newtext
, '=') - newtext
)) {
205 o_text_change(a_current
, newtext
, vis
, show
);
207 toplevel
->page_current
->CHANGED
= 1;
210 a_iter
= g_list_next (a_iter
);
214 new = o_attrib_add_attrib(w_current
, newtext
, vis
, show
, object
);
218 s_current
= g_list_next (s_current
);
220 o_undo_savestate(w_current
, UNDO_ALL
);
222 object
= o_select_return_first_object(w_current
);
223 new = o_attrib_add_attrib(w_current
, newtext
, vis
, show
, object
);
226 GPOINTER_TO_INT( gtk_object_get_data(GTK_OBJECT(w_current
->aewindow
),
227 "invocation_flag") );
228 wx
= GPOINTER_TO_INT( gtk_object_get_data(GTK_OBJECT(w_current
->aewindow
),
230 wy
= GPOINTER_TO_INT( gtk_object_get_data(GTK_OBJECT(w_current
->aewindow
),
234 printf("invocation flag: %d\n", invocation_flag
);
236 if (invocation_flag
== FROM_HOTKEY
237 && wx
!= -1 && wy
!= -1) {
238 o_erase_single(w_current
, new);
241 o_text_recreate(new);
242 o_text_draw(w_current
, new);
243 toplevel
->page_current
->CHANGED
= 1;
244 o_undo_savestate(w_current
, UNDO_ALL
);
248 o_text_change(attribptr
, newtext
, vis
, show
);
249 toplevel
->page_current
->CHANGED
= 1;
250 o_undo_savestate(w_current
, UNDO_ALL
);
252 gtk_grab_remove(w_current
->aewindow
);
253 gtk_widget_destroy(w_current
->aewindow
);
254 w_current
->aewindow
= NULL
;
258 /*! \brief Response function for the attribute add/edit dialog
259 * \par Function Description
260 * This function catches the user response for the add and edit
263 void attribute_edit_dialog_response(GtkWidget
*w
, gint response
,
264 GSCHEM_TOPLEVEL
*w_current
)
267 case GTK_RESPONSE_APPLY
:
268 attrib_edit_dialog_ok(NULL
, w_current
);
270 case GTK_RESPONSE_REJECT
:
271 case GTK_RESPONSE_DELETE_EVENT
:
272 i_set_state(w_current
, SELECT
);
273 gtk_grab_remove(w_current
->aewindow
);
274 gtk_widget_destroy(w_current
->aewindow
);
275 w_current
->aewindow
= NULL
;
278 printf("attrib_edit_dialog_response(): strange signal %d\n", response
);
285 /*! \brief Create the attribute add/edit dialog
286 * \par Function Description
287 * This function creates the single attribute edit dialog.
289 void attrib_edit_dialog(GSCHEM_TOPLEVEL
*w_current
, OBJECT
* list
, int flag
)
291 TOPLEVEL
*toplevel
= w_current
->toplevel
;
293 GtkWidget
*vbox
, *label
, *table
, *alignment
;
294 GtkWidget
*show_options
;
295 GtkWidget
*show_options_menu
;
296 GtkWidget
*glade_menuitem
;
297 GtkWidget
*attrib_combo
;
298 GtkWidget
*attrib_combo_entry
;
299 GtkWidget
*value_entry
;
300 GtkWidget
*visbutton
;
301 GSList
*hbox2_group
= NULL
;
302 GtkWidget
*addtoallbutton
;
303 GtkWidget
*addtocompsbutton
;
304 GtkWidget
*addtonetsbutton
;
305 GtkWidget
*overwritebutton
;
307 /* gschem specific */
308 GList
*s_current
= NULL
;
309 GList
*combo_items
= NULL
;
314 OBJECT
*attrib
= NULL
;
317 /* gschem specific */
318 if (w_current
->aewindow
)
321 /* gschem specific: What do we count here? (Werner) */
322 for (s_current
= geda_list_get_glist( toplevel
->page_current
->selection_list
);
324 s_current
= g_list_next(s_current
)) {
325 if (!((OBJECT
*) s_current
->data
)->attached_to
) {
330 aewindow
= gschem_dialog_new_with_buttons(_("Single Attribute Editor"),
331 GTK_WINDOW(w_current
->main_window
),
333 "singleattrib", w_current
,
339 /* Set the alternative button order (ok, cancel, help) for other systems */
340 gtk_dialog_set_alternative_button_order(GTK_DIALOG(aewindow
),
345 gtk_signal_connect(GTK_OBJECT(aewindow
), "response",
346 GTK_SIGNAL_FUNC(attribute_edit_dialog_response
), w_current
);
348 gtk_window_set_position (GTK_WINDOW (aewindow
), GTK_WIN_POS_MOUSE
);
350 gtk_dialog_set_default_response(GTK_DIALOG(aewindow
),
353 vbox
= GTK_DIALOG(aewindow
)->vbox
;
354 gtk_container_set_border_width(GTK_CONTAINER(aewindow
),
355 DIALOG_BORDER_SPACING
);
356 gtk_box_set_spacing(GTK_BOX(vbox
), DIALOG_V_SPACING
);
359 label
= gtk_label_new(_("<b>Edit Attribute</b>"));
361 label
= gtk_label_new(_("<b>Add Attribute</b>"));
362 gtk_label_set_use_markup (GTK_LABEL (label
), TRUE
);
363 gtk_misc_set_alignment(GTK_MISC(label
),0,0);
364 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 0);
366 alignment
= gtk_alignment_new(0,0,1,1);
367 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment
), 0, 0,
368 DIALOG_INDENTATION
, 0);
369 gtk_box_pack_start(GTK_BOX(vbox
), alignment
, TRUE
, TRUE
, 0);
371 table
= gtk_table_new (3, 2, FALSE
);
372 gtk_table_set_row_spacings(GTK_TABLE(table
), DIALOG_V_SPACING
);
373 gtk_table_set_col_spacings(GTK_TABLE(table
), DIALOG_H_SPACING
);
374 gtk_container_add (GTK_CONTAINER (alignment
), table
);
377 label
= gtk_label_new (_("Name:"));
378 gtk_misc_set_alignment (GTK_MISC (label
), 0, 0.5);
379 gtk_table_attach (GTK_TABLE (table
), label
, 0, 1, 0, 1,
380 (GtkAttachOptions
) (GTK_FILL
),
381 (GtkAttachOptions
) (GTK_FILL
), 0, 0);
383 attrib_combo
= gtk_combo_new ();
384 gtk_table_attach (GTK_TABLE (table
), attrib_combo
, 1, 2, 0, 1,
385 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
386 (GtkAttachOptions
) (0), 0, 0);
387 attrib_combo_entry
= GTK_COMBO (attrib_combo
)->entry
;
388 gtk_widget_ref (attrib_combo_entry
);
389 gtk_object_set_data_full (GTK_OBJECT (aewindow
), "attrib_combo_entry", attrib_combo_entry
,
390 (GtkDestroyNotify
) gtk_widget_unref
);
393 label
= gtk_label_new (_("Value:"));
394 gtk_misc_set_alignment (GTK_MISC (label
), 0, 0.5);
395 gtk_table_attach (GTK_TABLE (table
), label
, 0, 1, 1, 2,
396 (GtkAttachOptions
) (GTK_FILL
),
397 (GtkAttachOptions
) (0), 0, 0);
399 value_entry
= gtk_entry_new ();
400 gtk_widget_ref (value_entry
);
401 gtk_object_set_data_full (GTK_OBJECT (aewindow
), "value_entry", value_entry
,
402 (GtkDestroyNotify
) gtk_widget_unref
);
403 gtk_table_attach (GTK_TABLE (table
), value_entry
, 1, 2, 1, 2,
404 (GtkAttachOptions
) (GTK_EXPAND
| GTK_FILL
),
405 (GtkAttachOptions
) (0), 0, 0);
406 gtk_entry_set_activates_default(GTK_ENTRY(value_entry
), TRUE
);
409 visbutton
= gtk_check_button_new_with_label (_("Visible"));
410 gtk_widget_ref (visbutton
);
411 gtk_object_set_data_full (GTK_OBJECT (aewindow
), "visbutton", visbutton
,
412 (GtkDestroyNotify
) gtk_widget_unref
);
414 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (visbutton
), TRUE
);
415 gtk_table_attach (GTK_TABLE (table
), visbutton
, 0, 1, 2, 3,
416 (GtkAttachOptions
) (GTK_FILL
),
417 (GtkAttachOptions
) (0), 0, 0);
419 show_options
= gtk_option_menu_new ();
420 gtk_widget_ref (show_options
);
421 gtk_object_set_data_full (GTK_OBJECT (aewindow
), "show_options",
423 (GtkDestroyNotify
) gtk_widget_unref
);
424 gtk_widget_show (show_options
);
425 gtk_table_attach (GTK_TABLE (table
), show_options
, 1, 2, 2, 3,
426 (GtkAttachOptions
) (GTK_FILL
| GTK_EXPAND
),
427 (GtkAttachOptions
) (0), 0, 0);
428 show_options_menu
= gtk_menu_new ();
429 glade_menuitem
= gtk_menu_item_new_with_label (_("Show Value Only"));
430 gtk_menu_append (GTK_MENU (show_options_menu
), glade_menuitem
);
431 glade_menuitem
= gtk_menu_item_new_with_label (_("Show Name Only"));
432 gtk_menu_append (GTK_MENU (show_options_menu
), glade_menuitem
);
433 glade_menuitem
= gtk_menu_item_new_with_label (_("Show Name & Value"));
434 gtk_menu_append (GTK_MENU (show_options_menu
), glade_menuitem
);
435 gtk_option_menu_set_menu (GTK_OPTION_MENU (show_options
), show_options_menu
);
436 gtk_option_menu_set_history (GTK_OPTION_MENU (show_options
), 0);
438 if (nsel
> 1) { /* gschem specific */
440 label
= gtk_label_new(_("<b>Attach Options</b>"));
441 gtk_label_set_use_markup (GTK_LABEL (label
), TRUE
);
442 gtk_misc_set_alignment(GTK_MISC(label
),0,0);
443 gtk_box_pack_start(GTK_BOX(vbox
), label
, FALSE
, FALSE
, 0);
445 alignment
= gtk_alignment_new(0,0,1,1);
446 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment
), 0, 0,
447 DIALOG_INDENTATION
, 0);
448 gtk_box_pack_start(GTK_BOX(vbox
), alignment
, TRUE
, TRUE
, 0);
450 table
= gtk_table_new (2, 3, FALSE
);
451 gtk_table_set_row_spacings(GTK_TABLE(table
), DIALOG_V_SPACING
);
452 gtk_table_set_col_spacings(GTK_TABLE(table
), DIALOG_H_SPACING
);
453 gtk_container_add (GTK_CONTAINER (alignment
), table
);
455 addtoallbutton
= gtk_radio_button_new_with_label (hbox2_group
, _("All"));
456 hbox2_group
= gtk_radio_button_group (GTK_RADIO_BUTTON (addtoallbutton
));
457 gtk_widget_ref (addtoallbutton
);
458 gtk_object_set_data_full (GTK_OBJECT (aewindow
), "addtoallbutton", addtoallbutton
,
459 (GtkDestroyNotify
) gtk_widget_unref
);
460 gtk_table_attach(GTK_TABLE(table
), addtoallbutton
, 0, 1, 0, 1,
461 (GtkAttachOptions
) (GTK_FILL
), 0, 0, 0);
463 addtocompsbutton
= gtk_radio_button_new_with_label (hbox2_group
, _("Components"));
464 hbox2_group
= gtk_radio_button_group (GTK_RADIO_BUTTON (addtocompsbutton
));
465 gtk_widget_ref (addtocompsbutton
);
466 gtk_object_set_data_full (GTK_OBJECT (aewindow
), "addtocompsbutton", addtocompsbutton
,
467 (GtkDestroyNotify
) gtk_widget_unref
);
468 gtk_table_attach(GTK_TABLE(table
), addtocompsbutton
, 1, 2, 0, 1,
469 (GtkAttachOptions
) (GTK_FILL
), 0, 0, 0);
471 addtonetsbutton
= gtk_radio_button_new_with_label (hbox2_group
, _("Nets"));
472 hbox2_group
= gtk_radio_button_group (GTK_RADIO_BUTTON (addtonetsbutton
));
473 gtk_widget_ref (addtonetsbutton
);
474 gtk_object_set_data_full (GTK_OBJECT (aewindow
), "addtonetsbutton", addtonetsbutton
,
475 (GtkDestroyNotify
) gtk_widget_unref
);
476 gtk_table_attach(GTK_TABLE(table
), addtonetsbutton
, 2, 3, 0, 1,
477 (GtkAttachOptions
) (GTK_FILL
), 0, 0, 0);
479 overwritebutton
= gtk_check_button_new_with_label (_("Replace existing attributes"));
480 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(overwritebutton
), TRUE
);
481 gtk_widget_ref (overwritebutton
);
482 gtk_object_set_data_full (GTK_OBJECT (aewindow
), "overwritebutton", overwritebutton
,
483 (GtkDestroyNotify
) gtk_widget_unref
);
484 gtk_table_attach(GTK_TABLE(table
), overwritebutton
, 0, 3, 1, 2,
485 (GtkAttachOptions
) (GTK_FILL
), 0, 0, 0);
488 /* gschem specific */
490 o_attrib_get_name_value(o_text_get_string(list
), &name
, &val
);
492 if (attrib
->visibility
== VISIBLE
) {
493 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(visbutton
), TRUE
);
495 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(visbutton
), FALSE
);
498 if (attrib
->show_name_value
== SHOW_VALUE
) {
499 gtk_option_menu_set_history (GTK_OPTION_MENU (show_options
), 0);
500 } else if (attrib
->show_name_value
== SHOW_NAME
) {
501 gtk_option_menu_set_history (GTK_OPTION_MENU (show_options
), 1);
503 gtk_option_menu_set_history (GTK_OPTION_MENU (show_options
), 2);
510 if ((object
= o_select_return_first_object(w_current
))) {
511 if (object
->type
== OBJ_NET
)
512 name
= g_strdup("netname");
515 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(visbutton
), TRUE
);
516 /* show value only */
517 gtk_option_menu_set_history (GTK_OPTION_MENU (show_options
), 0);
519 gtk_object_set_data(GTK_OBJECT(aewindow
), "attrib", attrib
);
521 gtk_entry_set_text(GTK_ENTRY(attrib_combo_entry
), name
);
524 gtk_entry_set_text(GTK_ENTRY(value_entry
), val
);
526 gtk_entry_select_region(GTK_ENTRY(value_entry
), 0, len
);
528 gtk_object_set_data(GTK_OBJECT(aewindow
), "invocation_flag",
529 GINT_TO_POINTER(flag
));
531 if (!x_event_get_pointer_position(w_current
, TRUE
, &wx
, &wy
)) {
534 gtk_object_set_data(GTK_OBJECT(aewindow
), "position_wx",
535 GINT_TO_POINTER(wx
));
536 gtk_object_set_data(GTK_OBJECT(aewindow
), "position_wy",
537 GINT_TO_POINTER(wy
));
539 /* gschem specific */
541 string
= (char *) s_attrib_get(i
);
542 while (string
!= NULL
) {
543 combo_items
= g_list_append(combo_items
, string
);
545 string
= (char *) s_attrib_get(i
);
547 combo_items
= g_list_prepend(combo_items
, name
);
548 gtk_combo_set_popdown_strings(GTK_COMBO(attrib_combo
), combo_items
);
549 g_list_free(combo_items
);
551 /* gschem specific */
552 gtk_widget_show_all(aewindow
);
553 w_current
->aewindow
= aewindow
;
555 gtk_grab_add(w_current
->aewindow
);
557 if (attrib
|| (name
&& strcmp(name
, "netname") == 0)) {
558 gtk_widget_grab_focus(value_entry
);
560 gtk_widget_grab_focus(attrib_combo_entry
);
567 /***************** End of Attrib Edit dialog box **********************/