re-adding .pngs as binary
[dia.git] / app / defaults.c
blobf8901624efb93a0b965402b06887d03919a00638
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1999 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include <config.h>
21 #ifdef GNOME
22 # include <gnome.h>
23 #else
24 # include <gtk/gtk.h>
25 #endif
27 #include "defaults.h"
28 #include "intl.h"
29 #include "properties.h"
30 #include "object_ops.h"
31 #include "connectionpoint_ops.h"
33 static GtkWidget *dialog = NULL;
34 static GtkWidget *dialog_vbox = NULL;
35 static GtkWidget *object_part = NULL;
36 static ObjectType *current_objtype = NULL;
38 static GtkWidget *no_defaults_dialog = NULL;
40 static gint defaults_apply(GtkWidget *canvas, gpointer data);
41 static gint defaults_close(GtkWidget *canvas, gpointer data);
43 static void create_dialog()
45 #ifndef GNOME
46 GtkWidget *button;
47 #endif
49 #ifdef GNOME
50 dialog = gnome_dialog_new(_("Object defaults"),
51 GNOME_STOCK_BUTTON_APPLY,
52 GNOME_STOCK_BUTTON_CLOSE, NULL);
53 gnome_dialog_set_default(GNOME_DIALOG(dialog), 0);
55 dialog_vbox = GNOME_DIALOG(dialog)->vbox;
56 #else
57 dialog = gtk_dialog_new();
58 gtk_window_set_title (GTK_WINDOW (dialog), _("Object defaults"));
59 gtk_container_set_border_width (GTK_CONTAINER (dialog), 2);
61 dialog_vbox = GTK_DIALOG (dialog)->vbox;
62 #endif
64 gtk_window_set_wmclass (GTK_WINDOW (dialog),
65 "defaults_window", "Dia");
66 gtk_window_set_policy (GTK_WINDOW (dialog),
67 FALSE, TRUE, TRUE);
69 #ifdef GNOME
70 gnome_dialog_button_connect(GNOME_DIALOG(dialog), 0,
71 GTK_SIGNAL_FUNC(defaults_apply), NULL);
72 gnome_dialog_button_connect(GNOME_DIALOG(dialog), 1,
73 GTK_SIGNAL_FUNC(defaults_close), NULL);
74 #else
75 button = gtk_button_new_with_label (_("Apply"));
76 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
77 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
78 button, TRUE, TRUE, 0);
79 gtk_signal_connect (GTK_OBJECT (button), "clicked",
80 GTK_SIGNAL_FUNC(defaults_apply),
81 NULL);
82 gtk_widget_grab_default (button);
83 gtk_widget_show (button);
85 button = gtk_button_new_with_label (_("Close"));
86 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
87 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area),
88 button, TRUE, TRUE, 0);
89 gtk_signal_connect (GTK_OBJECT (button), "clicked",
90 GTK_SIGNAL_FUNC(defaults_close),
91 NULL);
92 gtk_widget_show (button);
93 #endif
95 gtk_signal_connect (GTK_OBJECT (dialog), "delete_event",
96 GTK_SIGNAL_FUNC(gtk_widget_hide), NULL);
98 no_defaults_dialog = gtk_label_new(_("This object has no defaults."));
99 gtk_widget_show (no_defaults_dialog);
101 gtk_widget_ref(no_defaults_dialog);
102 gtk_object_sink(GTK_OBJECT(no_defaults_dialog));
105 static gint
106 defaults_dialog_destroyed(GtkWidget *dialog, gpointer data)
108 if (dialog == object_part) {
109 object_part = NULL;
110 current_objtype = NULL;
112 return 0;
115 static gint
116 defaults_apply(GtkWidget *canvas, gpointer data)
118 if (current_objtype != NULL) {
119 current_objtype->ops->apply_defaults();
121 return 0;
124 static gint
125 defaults_close(GtkWidget *canvas, gpointer data)
127 gtk_widget_hide(dialog);
128 return 0;
131 void
132 defaults_show(ObjectType *objtype)
134 GtkWidget *defaults;
136 if ((objtype != NULL) && (objtype->ops->get_defaults != NULL)) {
137 defaults = objtype->ops->get_defaults();
138 } else {
139 defaults = NULL;
142 if (dialog == NULL)
143 create_dialog();
145 if ((objtype==NULL) || (defaults == NULL)) {
146 /* No defaults or no object */
147 defaults = no_defaults_dialog;
148 objtype = NULL;
151 if (object_part != NULL) {
152 gtk_container_remove(GTK_CONTAINER(dialog_vbox), object_part);
153 object_part = NULL;
155 gtk_signal_connect (GTK_OBJECT (defaults), "destroy",
156 GTK_SIGNAL_FUNC(defaults_dialog_destroyed), NULL);
157 gtk_box_pack_start(GTK_BOX(dialog_vbox), defaults, TRUE, TRUE, 0);
158 gtk_widget_show (defaults);
159 gtk_widget_show (dialog);
160 object_part = defaults;
161 current_objtype = objtype;