Remove extra debug message
[geda-gaf.git] / gschem / src / gschem_dialog_misc.c
blob473b94b74f9e3345e2174a5b9eb1740b6f31ff63
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2019 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 /*!
21 * \file gschem_dialog_misc.c
23 * \brief Common dialog functions
26 #include <config.h>
28 #include <stdio.h>
29 #ifdef HAVE_STDLIB_H
30 #include <stdlib.h>
31 #endif
32 #ifdef HAVE_STRING_H
33 #include <string.h>
34 #endif
36 #include "gschem.h"
37 #include <gdk/gdkkeysyms.h>
41 /*! \brief Create a property label widget
43 * \param [in] label The label text for this property
44 * \return A new property label widget
46 GtkWidget*
47 gschem_dialog_misc_create_property_label (const char *label)
49 GtkWidget *widget = gtk_label_new (label);
51 gtk_misc_set_alignment (GTK_MISC (widget),
52 0.0, /* xalign */
53 0.0); /* yalign */
55 return widget;
60 /*! \brief Create a property table
62 * \param [in] label The array of label widgets
63 * \param [in] widget The array of widgets
64 * \param [in] count The number of rows in the table
65 * \return A new property table
67 GtkWidget*
68 gschem_dialog_misc_create_property_table (GtkWidget *label[], GtkWidget *widget[], int count)
70 int index;
71 GtkWidget *table = gtk_table_new (count, 2, FALSE);
73 gtk_table_set_row_spacings (GTK_TABLE (table), DIALOG_V_SPACING);
74 gtk_table_set_col_spacings (GTK_TABLE (table), DIALOG_H_SPACING);
76 for (index=0; index<count; index++) {
77 gtk_table_attach (GTK_TABLE (table),
78 label[index], /* child */
79 0, /* left_attach */
80 1, /* right_attach */
81 index, /* top_attach */
82 index+1, /* bottom_attach */
83 GTK_FILL, /* xoptions */
84 0, /* yoptions */
85 0, /* xpadding */
86 0); /* ypadding */
88 gtk_table_attach_defaults (GTK_TABLE (table),
89 widget[index], /* child */
90 1, /* left_attach */
91 2, /* right_attach */
92 index, /* top_attach */
93 index+1); /* bottom_attach */
96 return table;
100 /*! \brief Create a section widget
102 * Creates a widget to represent a section in the property editor. This
103 * function wraps the child widget with additional widgets to generate the
104 * proper layout.
106 * \param [in] label The markup text for this section
107 * \param [in] child The child widget for this section
108 * \return A new section widget
110 GtkWidget*
111 gschem_dialog_misc_create_section_widget (const char *label, GtkWidget *child)
113 GtkWidget *alignment;
114 GtkWidget *expander;
116 alignment = gtk_alignment_new (0.0, /* xalign */
117 0.0, /* yalign */
118 1.0, /* xscale */
119 1.0); /* yscale */
121 gtk_alignment_set_padding (GTK_ALIGNMENT(alignment),
122 0, /* padding_top */
123 0, /* padding_bottom */
124 DIALOG_INDENTATION, /* padding_left */
125 0); /* padding_right */
127 gtk_container_add (GTK_CONTAINER (alignment), child);
129 expander = gtk_expander_new (label);
131 gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE);
132 gtk_expander_set_spacing (GTK_EXPANDER (expander), DIALOG_V_SPACING);
133 gtk_expander_set_use_markup (GTK_EXPANDER (expander), TRUE);
135 gtk_container_add (GTK_CONTAINER (expander), alignment);
137 return expander;
142 /*! \brief A signal handler for when the user presses enter in an entry
144 * Pressing the enter key in an entry moves the focus to the next control
145 * in the column of values and applies the current value. This function
146 * moves the focus to the next control, and the focus-out-event applies the
147 * value.
149 * This signal hander operates for multiple entry widgets.
151 * \param [in] widget The widget emitting the event
152 * \param [in] dialog The dialog containing the widget
154 void
155 gschem_dialog_misc_entry_activate (GtkWidget *widget, GtkDialog *dialog)
157 g_return_if_fail (dialog != NULL);
159 gtk_widget_child_focus (GTK_WIDGET (dialog), GTK_DIR_DOWN);
164 /*! \brief Handles user responses from non-modal dialogs
166 * Destroys the non-modal dialog upon any user response.
168 * Relies on the caller using signals or weak references to know when the
169 * dialog is destroyed.
171 * \param [in,out] dialog The non-modal dialog
172 * \param [in] response The id of the user response
173 * \param [na] unused An unused parameter
175 void
176 gschem_dialog_misc_response_non_modal (GtkDialog *dialog, gint response, gpointer unused)
178 switch(response) {
179 case GTK_RESPONSE_CLOSE:
180 case GTK_RESPONSE_DELETE_EVENT:
181 break;
183 default:
184 printf("gtk_dialog_misc_response_non_modal(): strange signal %d\n", response);
187 gtk_widget_destroy (GTK_WIDGET (dialog));
192 /*! \brief Creates and/or shows a non-modal dialog
194 * \param [in,out] w_current The toplevel
195 * \param [in] widget Where the result dialog pointer is placed
196 * \param [na] create A pointer to the function that creates the dialog
198 void
199 gschem_dialog_misc_show_non_modal (GschemToplevel *w_current, GtkWidget **widget, CreateNonModalDialog create)
201 g_return_if_fail (create != NULL);
202 g_return_if_fail (w_current != NULL);
203 g_return_if_fail (widget != NULL);
205 if (*widget == NULL) {
206 *widget = GTK_WIDGET (create (w_current));
208 g_object_add_weak_pointer (G_OBJECT (*widget), (void**) widget);
210 g_signal_connect (G_OBJECT (*widget),
211 "response",
212 G_CALLBACK (gschem_dialog_misc_response_non_modal),
213 NULL);
215 gtk_window_set_transient_for (GTK_WINDOW (*widget),
216 GTK_WINDOW (w_current->main_window));
218 gtk_widget_show_all (*widget);
220 else {
221 gtk_window_present (GTK_WINDOW (*widget));