svg text alignment
[dia.git] / app / dia-props.c
blob8b08ccee231772c39c222403db52c5192d79cd50
1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * dia-props.c - a dialog for the diagram properties
5 * Copyright (C) 2000 James Henstridge
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
26 #include "dia-props.h"
28 #ifdef GNOME
29 # include <gnome.h>
30 #else
31 # include <gtk/gtk.h>
32 #endif
33 #include "intl.h"
34 #include "display.h"
35 #include "widgets.h"
36 #include "display.h"
38 static GtkWidget *dialog = NULL;
39 static GtkWidget *width_x_entry, *width_y_entry;
40 static GtkWidget *visible_x_entry, *visible_y_entry;
41 static GtkWidget *bg_colour;
43 static void diagram_properties_okay(GtkWidget *dialog);
44 static void diagram_properties_apply(GtkWidget *dialog);
45 static void diagram_properties_hide(GtkWidget *dialog);
47 static void
48 create_diagram_properties_dialog(void)
50 GtkWidget *dialog_vbox;
51 #ifndef GNOME
52 GtkWidget *button = NULL;
53 #endif
54 GtkWidget *notebook;
55 GtkWidget *table;
56 GtkWidget *label;
57 GtkAdjustment *adj;
59 #ifdef GNOME
60 dialog = gnome_dialog_new(_("Diagram Properties"),
61 GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_APPLY,
62 GNOME_STOCK_BUTTON_CLOSE, NULL);
63 gnome_dialog_set_default(GNOME_DIALOG(dialog), 1);
64 dialog_vbox = GNOME_DIALOG(dialog)->vbox;
65 #else
66 dialog = gtk_dialog_new();
67 gtk_window_set_title(GTK_WINDOW(dialog), _("Diagram Properties"));
68 gtk_container_set_border_width(GTK_CONTAINER(dialog), 2);
69 dialog_vbox = GTK_DIALOG(dialog)->vbox;
70 #endif
72 gtk_window_set_wmclass(GTK_WINDOW(dialog), "diagram_properties", "Dia");
73 gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, TRUE, TRUE);
75 #ifdef GNOME
76 gnome_dialog_button_connect_object(GNOME_DIALOG(dialog), 0,
77 GTK_SIGNAL_FUNC(diagram_properties_okay),
78 GTK_OBJECT(dialog));
79 gnome_dialog_button_connect_object(GNOME_DIALOG(dialog), 1,
80 GTK_SIGNAL_FUNC(diagram_properties_apply),
81 GTK_OBJECT(dialog));
82 gnome_dialog_button_connect_object(GNOME_DIALOG(dialog), 2,
83 GTK_SIGNAL_FUNC(diagram_properties_hide),
84 GTK_OBJECT(dialog));
85 #else
86 button = gtk_button_new_with_label(_("OK"));
87 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
88 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area),
89 button, TRUE, TRUE, 0);
90 gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
91 GTK_SIGNAL_FUNC(diagram_properties_okay),
92 GTK_OBJECT(dialog));
93 gtk_widget_show(button);
95 button = gtk_button_new_with_label(_("Apply"));
96 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
97 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area),
98 button, TRUE, TRUE, 0);
99 gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
100 GTK_SIGNAL_FUNC(diagram_properties_apply),
101 GTK_OBJECT(dialog));
102 gtk_widget_grab_default(button);
103 gtk_widget_show(button);
105 button = gtk_button_new_with_label(_("Close"));
106 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
107 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area),
108 button, TRUE, TRUE, 0);
109 gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
110 GTK_SIGNAL_FUNC(diagram_properties_hide),
111 GTK_OBJECT(dialog));
112 gtk_widget_show(button);
113 #endif
115 gtk_signal_connect(GTK_OBJECT(dialog), "delete_event",
116 GTK_SIGNAL_FUNC(gtk_widget_hide), NULL);
118 notebook = gtk_notebook_new();
119 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);
120 gtk_box_pack_start(GTK_BOX(dialog_vbox), notebook, TRUE, TRUE, 0);
121 gtk_container_set_border_width(GTK_CONTAINER(notebook), 2);
122 gtk_widget_show(notebook);
124 /* the grid page */
125 table = gtk_table_new(3,3,FALSE);
126 gtk_container_set_border_width(GTK_CONTAINER(table), 2);
127 gtk_table_set_row_spacings(GTK_TABLE(table), 1);
128 gtk_table_set_col_spacings(GTK_TABLE(table), 2);
130 label = gtk_label_new(_("x"));
131 gtk_table_attach(GTK_TABLE(table), label, 1,2, 0,1,
132 GTK_FILL, GTK_FILL, 0, 0);
133 gtk_widget_show(label);
134 label = gtk_label_new(_("y"));
135 gtk_table_attach(GTK_TABLE(table), label, 2,3, 0,1,
136 GTK_FILL, GTK_FILL, 0, 0);
137 gtk_widget_show(label);
139 label = gtk_label_new(_("Spacing"));
140 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
141 gtk_table_attach(GTK_TABLE(table), label, 0,1, 1,2,
142 GTK_FILL, GTK_FILL, 0, 0);
143 gtk_widget_show(label);
145 adj = GTK_ADJUSTMENT(gtk_adjustment_new(1.0, 0.0, 10.0, 0.1, 10.0, 10.0));
146 width_x_entry = gtk_spin_button_new(adj, 1.0, 3);
147 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(width_x_entry), TRUE);
148 gtk_table_attach(GTK_TABLE(table), width_x_entry, 1,2, 1,2,
149 GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
150 gtk_widget_show(width_x_entry);
152 adj = GTK_ADJUSTMENT(gtk_adjustment_new(1.0, 0.0, 10.0, 0.1, 10.0, 10.0));
153 width_y_entry = gtk_spin_button_new(adj, 1.0, 3);
154 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(width_y_entry), TRUE);
155 gtk_table_attach(GTK_TABLE(table), width_y_entry, 2,3, 1,2,
156 GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
157 gtk_widget_show(width_y_entry);
159 label = gtk_label_new(_("Visible spacing"));
160 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
161 gtk_table_attach(GTK_TABLE(table), label, 0,1, 2,3,
162 GTK_FILL, GTK_FILL, 0, 0);
163 gtk_widget_show(label);
165 adj = GTK_ADJUSTMENT(gtk_adjustment_new(1.0, 0.0, 100.0, 1.0, 10.0, 10.0));
166 visible_x_entry = gtk_spin_button_new(adj, 1.0, 0);
167 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(visible_x_entry), TRUE);
168 gtk_table_attach(GTK_TABLE(table), visible_x_entry, 1,2, 2,3,
169 GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
170 gtk_widget_show(visible_x_entry);
172 adj = GTK_ADJUSTMENT(gtk_adjustment_new(1.0, 0.0, 100.0, 1.0, 10.0, 10.0));
173 visible_y_entry = gtk_spin_button_new(adj, 1.0, 0);
174 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(visible_y_entry), TRUE);
175 gtk_table_attach(GTK_TABLE(table), visible_y_entry, 2,3, 2,3,
176 GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
177 gtk_widget_show(visible_y_entry);
179 label = gtk_label_new(_("Grid"));
180 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table, label);
181 gtk_widget_show(table);
182 gtk_widget_show(label);
184 table = gtk_table_new(1,2, FALSE);
185 gtk_container_set_border_width(GTK_CONTAINER(table), 2);
186 gtk_table_set_row_spacings(GTK_TABLE(table), 1);
187 gtk_table_set_col_spacings(GTK_TABLE(table), 2);
189 label = gtk_label_new(_("Background Colour"));
190 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
191 gtk_table_attach(GTK_TABLE(table), label, 0,1, 0,1,
192 GTK_FILL, GTK_FILL, 0, 0);
193 gtk_widget_show(label);
195 bg_colour = dia_color_selector_new();
196 gtk_table_attach(GTK_TABLE(table), bg_colour, 1,2, 0,1,
197 GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
198 gtk_widget_show(bg_colour);
200 label = gtk_label_new(_("Background"));
201 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table, label);
202 gtk_widget_show(table);
203 gtk_widget_show(label);
206 /* diagram_properties_retrieve
207 * Retrieves properties of a diagram *dia and sets the values in the
208 * diagram properties dialog.
210 static void diagram_properties_retrieve(Diagram *dia)
212 g_return_if_fail(dia != NULL);
214 gtk_spin_button_set_value(GTK_SPIN_BUTTON(width_x_entry),
215 dia->data->grid.width_x);
216 gtk_spin_button_set_value(GTK_SPIN_BUTTON(width_y_entry),
217 dia->data->grid.width_y);
218 gtk_spin_button_set_value(GTK_SPIN_BUTTON(visible_x_entry),
219 dia->data->grid.visible_x);
220 gtk_spin_button_set_value(GTK_SPIN_BUTTON(visible_y_entry),
221 dia->data->grid.visible_y);
222 dia_color_selector_set_color(DIACOLORSELECTOR(bg_colour), &dia->data->bg_color);
225 void
226 diagram_properties_show(Diagram *dia)
228 if (!dialog)
229 create_diagram_properties_dialog();
231 diagram_properties_retrieve(dia);
233 gtk_widget_show(dialog);
236 static void
237 diagram_properties_apply(GtkWidget *dialog)
239 Diagram *active_diagram = ddisplay_active_diagram();
241 if (active_diagram) {
242 active_diagram->data->grid.width_x =
243 gtk_spin_button_get_value_as_float(GTK_SPIN_BUTTON(width_x_entry));
244 active_diagram->data->grid.width_y =
245 gtk_spin_button_get_value_as_float(GTK_SPIN_BUTTON(width_y_entry));
246 active_diagram->data->grid.visible_x =
247 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(visible_x_entry));
248 active_diagram->data->grid.visible_y =
249 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(visible_y_entry));
250 dia_color_selector_get_color(DIACOLORSELECTOR(bg_colour),
251 &active_diagram->data->bg_color);
252 diagram_add_update_all(active_diagram);
253 diagram_flush(active_diagram);
257 static void
258 diagram_properties_okay(GtkWidget *dialog)
260 diagram_properties_apply(dialog);
261 diagram_properties_hide(dialog);
264 static void
265 diagram_properties_hide(GtkWidget *dialog)
267 gtk_widget_hide(dialog);
270 /* diagram_properties_set_diagram
271 * Called when the active diagram is changed. It updates the contents
272 * of the diagram properties dialog
274 void
275 diagram_properties_set_diagram(Diagram *dia)
277 if (dialog && dia != NULL)
279 diagram_properties_retrieve(dia);