Initial import of gattrib 20040806
[geda-gaf/whiteaudio.git] / gattrib / src / x_dialog.c
blob7efdd9233b2233febc7521baad67b4c272ad5531
1 /* gEDA - GPL Electronic Design Automation
2 * gattrib -- gEDA component and net attribute manipulation using spreadsheet.
3 * Copyright (C) 2003 Stuart D. Brorson.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
20 /*------------------------------------------------------------------
21 * This file holds fcns used to display dialog boxes.
22 *------------------------------------------------------------------*/
25 /*------------------------------------------------------------------
26 * Includes required to run graphical widgets.
27 *------------------------------------------------------------------*/
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <gtk/gtk.h>
31 #include <gdk/gdk.h>
32 #include <gdk/gdkkeysyms.h>
34 #include <glib.h>
35 #ifdef HAS_GTK22
36 #include <glib-object.h>
37 #endif
40 #ifdef HAVE_STRING_H
41 #include <string.h>
42 #endif
45 #ifdef HAS_GTK22
46 #include "gtksheet_2_2.h"
47 #include "gtkitementry_2_2.h"
48 #else
49 #include "gtksheet_1_2.h"
50 #include "gtkitementry_1_2.h"
51 #endif
54 /*------------------------------------------------------------------
55 * Gattrib specific includes
56 *------------------------------------------------------------------*/
57 #include <config.h>
58 #include <libgeda/libgeda.h> /* geda library fcns */
59 #include "../include/struct.h" /* typdef and struct declarations */
60 #include "../include/prototype.h" /* function prototypes */
61 #include "../include/globals.h"
62 #include "../include/x_menu.h"
64 /* --------------------------------------------------------- *
65 * Help/about dialog box fcns
66 * --------------------------------------------------------- */
67 int x_dialog_about_keypress_callback(GtkWidget * widget, GdkEventKey * event,
68 GtkWidget *window)
70 if (strcmp(gdk_keyval_name(event->keyval), "Escape") == 0) {
71 #ifdef DEBUG
72 printf("In x_dialog_about_keypress, trying to close window.\n");
73 #endif
74 x_dialog_close_window(window);
75 return TRUE;
78 return FALSE;
81 /* --------------------------------------------------------- */
82 int x_dialog_about_close_callback(GtkWidget * widget, GtkWidget *window)
84 x_dialog_close_window(window);
88 /* --------------------------------------------------------- */
89 void x_dialog_about_dialog()
91 GtkWidget *about_window;
92 GtkWidget *label = NULL;
93 GtkWidget *buttonclose = NULL;
94 GtkWidget *vbox, *action_area;
95 char *string;
98 about_window = x_dialog_create_dialog_box(&vbox, &action_area);
99 /* about_window = gtk_window_new(GTK_WINDOW_POPUP); */
101 gtk_window_position(GTK_WINDOW(about_window),
102 GTK_WIN_POS_MOUSE);
104 gtk_window_set_title(GTK_WINDOW(about_window), "About...");
105 gtk_container_border_width(GTK_CONTAINER(about_window), 5);
107 gtk_signal_connect(GTK_OBJECT(about_window),
108 "destroy", GTK_SIGNAL_FUNC(x_dialog_about_close_callback),
109 GTK_WIDGET(about_window) );
111 gtk_signal_connect(GTK_OBJECT(about_window),
112 "key_press_event", GTK_SIGNAL_FUNC(x_dialog_about_keypress_callback),
113 GTK_WIDGET(about_window) );
115 /* Now create text string to place in vbox area */
116 string = g_strdup_printf("gEDA : GPL Electronic Design Automation");
117 label = gtk_label_new(string);
118 free(string);
119 gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 5);
120 gtk_widget_show(label);
122 string = g_strdup_printf("This is gattrib -- gEDA's attribute editor");
123 label = gtk_label_new(string);
124 free(string);
125 gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 5);
126 gtk_widget_show(label);
128 string = g_strdup_printf("Gattrib version: %s", VERSION);
129 label = gtk_label_new(string);
130 free(string);
131 gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 5);
132 gtk_widget_show(label);
134 string =
135 g_strdup_printf("Gattrib is written by: Stuart Brorson (sdb@cloud9.net)\n");
136 string =
137 g_strdup_printf("%swith generous helpings of code from gschem, gnetlist, \n",
138 string);
139 string =
140 g_strdup_printf("%sand gtkextra, as well as support from the gEDA community.", string);
141 label = gtk_label_new(string);
142 free(string);
143 gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 5);
144 gtk_widget_show(label);
146 /* Now create button to stick in action area */
147 buttonclose = gtk_button_new_with_label("Close");
148 GTK_WIDGET_SET_FLAGS(buttonclose, GTK_CAN_DEFAULT);
149 gtk_box_pack_start(GTK_BOX(action_area), buttonclose, TRUE, TRUE, 0);
150 gtk_signal_connect(GTK_OBJECT(buttonclose), "clicked",
151 GTK_SIGNAL_FUNC(x_dialog_about_close_callback),
152 GTK_WIDGET(about_window) );
153 gtk_widget_show(buttonclose);
155 if (!GTK_WIDGET_VISIBLE(about_window)) {
156 gtk_widget_show(about_window);
161 /* --------------------------------------------------------- *
162 * Fcns common to all dialog boxes
163 * This code also stolen from gschem & adapted for gattrib.
164 * --------------------------------------------------------- */
166 /* ---------------------------------------------------- *
167 * This creates a dialog box. It has two areas: the vbox
168 * area, and the action area. The idea is that the vbox
169 * area holds text, and the action area holds buttons or
170 * other active widgets. There is a separating line between
171 * the two area. You load one or the other areas like this (for example):
172 * gtk_box_pack_start(GTK_BOX(action_area), buttonclose, TRUE, TRUE, 0);
173 * --------------------------------------------------------- */
174 GtkWidget *x_dialog_create_dialog_box(GtkWidget ** out_vbox,
175 GtkWidget ** out_action_area)
177 GtkWidget *separator;
178 GtkWidget *vbox;
179 GtkWidget *action_area;
180 GtkWidget *dialog;
182 if (!out_vbox)
183 return (NULL);
185 if (!out_action_area)
186 return (NULL);
188 dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
190 vbox = gtk_vbox_new(FALSE, 0);
191 gtk_container_add(GTK_CONTAINER(dialog), vbox);
192 gtk_widget_show(vbox);
194 action_area = gtk_hbox_new(TRUE, 5);
195 gtk_container_set_border_width(GTK_CONTAINER(action_area), 10);
196 gtk_box_pack_end(GTK_BOX(vbox), action_area, FALSE, TRUE, 0);
197 gtk_widget_show(action_area);
199 separator = gtk_hseparator_new();
200 gtk_box_pack_end(GTK_BOX(vbox), separator, FALSE, TRUE, 0);
201 gtk_widget_show(separator);
203 *out_vbox = vbox;
204 *out_action_area = action_area;
206 return (dialog);
209 /* ---------------------------------------------------- */
210 void x_dialog_close_window(GtkWidget * window)
212 gtk_widget_destroy(window);