re-adding .pngs as binary
[dia.git] / app / properties.c
blob337ec25ebe3f5fa3e90c710790143dcd0a024a55
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 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 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
23 #include <gtk/gtk.h>
25 #ifdef GNOME
26 #include <gnome.h>
27 #endif
29 #include "intl.h"
30 #include "properties.h"
31 #include "object_ops.h"
32 #include "connectionpoint_ops.h"
33 #include "undo.h"
34 #include "message.h"
35 #include <string.h>
37 static GtkWidget *dialog = NULL;
38 static GtkWidget *dialog_vbox = NULL;
39 static GtkWidget *object_part = NULL;
40 static Object *current_obj = NULL;
41 static Diagram *current_dia = NULL;
43 static GtkWidget *no_properties_dialog = NULL;
45 static gint properties_okay(GtkWidget *canvas, gpointer data);
46 static gint properties_apply(GtkWidget *canvas, gpointer data);
48 static void
49 properties_dialog_hide(GtkWidget *dialog)
51 current_obj = NULL;
52 gtk_widget_hide(dialog);
55 static void create_dialog()
57 #ifndef GNOME
58 GtkWidget *button;
59 #endif
61 #ifdef GNOME
62 dialog = gnome_dialog_new(_("Object properties"),
63 GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_APPLY,
64 GNOME_STOCK_BUTTON_CLOSE, NULL);
65 gnome_dialog_set_default(GNOME_DIALOG(dialog), 1);
67 dialog_vbox = GNOME_DIALOG(dialog)->vbox;
68 #else
69 dialog = gtk_dialog_new();
70 gtk_window_set_title(GTK_WINDOW (dialog), _("Object properties"));
71 gtk_container_set_border_width(GTK_CONTAINER (dialog), 2);
73 dialog_vbox = GTK_DIALOG(dialog)->vbox;
74 #endif
76 gtk_window_set_wmclass(GTK_WINDOW (dialog),
77 "properties_window", "Dia");
78 gtk_window_set_policy(GTK_WINDOW (dialog),
79 FALSE, TRUE, TRUE);
81 #ifdef GNOME
82 gnome_dialog_button_connect_object(GNOME_DIALOG(dialog), 0,
83 GTK_SIGNAL_FUNC(properties_okay),
84 GTK_OBJECT(dialog));
85 gnome_dialog_button_connect_object(GNOME_DIALOG(dialog), 1,
86 GTK_SIGNAL_FUNC(properties_apply),
87 GTK_OBJECT(dialog));
88 gnome_dialog_button_connect_object(GNOME_DIALOG(dialog), 2,
89 GTK_SIGNAL_FUNC(gtk_widget_hide),
90 GTK_OBJECT(dialog));
91 #else
92 button = gtk_button_new_with_label( _("OK") );
93 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
94 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area),
95 button, TRUE, TRUE, 0);
96 gtk_signal_connect_object(GTK_OBJECT (button), "clicked",
97 GTK_SIGNAL_FUNC(properties_okay),
98 GTK_OBJECT(dialog));
99 gtk_widget_show (button);
101 button = gtk_button_new_with_label(_("Apply"));
102 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
103 gtk_box_pack_start(GTK_BOX (GTK_DIALOG (dialog)->action_area),
104 button, TRUE, TRUE, 0);
105 gtk_signal_connect(GTK_OBJECT (button), "clicked",
106 GTK_SIGNAL_FUNC(properties_apply),
107 NULL);
108 gtk_widget_grab_default(button);
109 gtk_widget_show(button);
111 button = gtk_button_new_with_label( _("Close") );
112 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
113 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area),
114 button, TRUE, TRUE, 0);
115 gtk_signal_connect_object(GTK_OBJECT (button), "clicked",
116 GTK_SIGNAL_FUNC(properties_dialog_hide),
117 GTK_OBJECT(dialog));
118 gtk_widget_show (button);
119 #endif
121 gtk_signal_connect(GTK_OBJECT (dialog), "delete_event",
122 GTK_SIGNAL_FUNC(properties_dialog_hide), NULL);
124 no_properties_dialog = gtk_label_new(_("This object has no properties."));
125 gtk_widget_show (no_properties_dialog);
126 gtk_object_ref(GTK_OBJECT(no_properties_dialog));
127 gtk_object_sink(GTK_OBJECT(no_properties_dialog));
130 static gint
131 properties_dialog_destroyed(GtkWidget *dialog, gpointer data)
133 if (dialog == object_part) {
134 object_part = NULL;
135 current_obj = NULL;
136 current_dia = NULL;
138 return 0;
141 static gint
142 properties_okay(GtkWidget *canvas, gpointer data)
144 gint ret = properties_apply(canvas,data);
145 properties_dialog_hide(canvas);
146 return ret;
149 static gint
150 properties_apply(GtkWidget *canvas, gpointer data)
152 ObjectChange *obj_change = NULL;
154 if ( (current_obj == NULL) || (current_dia == NULL) )
155 return 0;
157 object_add_updates(current_obj, current_dia);
158 obj_change = current_obj->ops->apply_properties(current_obj, object_part);
159 object_add_updates(current_obj, current_dia);
161 diagram_update_connections_object(current_dia, current_obj, TRUE);
163 if (obj_change != NULL) {
164 undo_object_change(current_dia, current_obj, obj_change);
167 diagram_modified(current_dia);
169 diagram_object_modified(current_dia, current_obj);
171 diagram_update_extents(current_dia);
173 if (obj_change != NULL) {
174 undo_set_transactionpoint(current_dia->undo);
175 } else {
176 message_warning(_("This object doesn't support Undo/Redo.\n"
177 "Undo information erased."));
178 undo_clear(current_dia->undo);
181 diagram_flush(current_dia);
183 return 0;
186 void
187 properties_show(Diagram *dia, Object *obj)
189 GtkWidget *properties = NULL;
191 if (obj != NULL)
192 properties = obj->ops->get_properties(obj);
194 if (dialog == NULL)
195 create_dialog();
197 if ((obj==NULL) || (properties == NULL)) { /* No properties or no object */
198 properties = no_properties_dialog;
199 obj = NULL;
200 dia = NULL;
203 if (object_part != NULL) {
204 gtk_container_remove(GTK_CONTAINER(dialog_vbox), object_part);
205 object_part = NULL;
206 current_obj = NULL;
207 current_dia = NULL;
210 if (obj != NULL) {
211 ObjectType *otype;
212 gchar *buf;
214 otype = obj->type;
215 buf = g_strconcat(_("Properties: "), otype->name, NULL);
216 gtk_window_set_title(GTK_WINDOW(dialog), buf);
217 g_free(buf);
218 } else {
219 gtk_window_set_title(GTK_WINDOW(dialog), _("Object properties:"));
222 gtk_signal_connect (GTK_OBJECT (properties), "destroy",
223 GTK_SIGNAL_FUNC(properties_dialog_destroyed), NULL);
224 gtk_box_pack_start(GTK_BOX(dialog_vbox), properties, TRUE, TRUE, 0);
225 gtk_widget_show (properties);
226 gtk_widget_show (dialog);
227 object_part = properties;
228 current_obj = obj;
229 current_dia = dia;
232 void
233 properties_hide_if_shown(Diagram *dia, Object *obj)
235 if (current_obj == obj) {
236 properties_show(dia, NULL);
240 void
241 properties_update_if_shown(Diagram *dia, Object *obj)
243 if (current_obj == obj) {
244 properties_show(dia, obj);