1 #define __OBJECT_PROPERTIES_C__
3 /**
4 * \brief Fill, stroke, and stroke style dialog
5 *
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * Frank Felfe <innerspace@iname.com>
9 * bulia byak <buliabyak@users.sf.net>
10 *
11 * Copyright (C) 1999-2005 authors
12 * Copyright (C) 2001-2002 Ximian, Inc.
13 *
14 * Released under GNU GPL, read the file 'COPYING' for more information
15 */
17 #ifdef HAVE_CONFIG_H
18 # include "config.h"
19 #endif
21 #include <gtk/gtk.h>
23 #include <glibmm/i18n.h>
24 #include "helper/window.h"
25 #include "widgets/sp-widget.h"
26 #include "widgets/icon.h"
27 #include "macros.h"
28 #include "inkscape.h"
29 #include "fill-style.h"
30 #include "stroke-style.h"
31 #include "dialog-events.h"
32 #include "verbs.h"
33 #include "interface.h"
34 #include "style.h"
35 #include "inkscape-stock.h"
36 #include "prefs-utils.h"
37 #include "svg/css-ostringstream.h"
38 #include "desktop-handles.h"
39 #include "desktop-style.h"
40 #include "document.h"
41 #include "xml/repr.h"
43 static GtkWidget *dlg = NULL;
44 static win_data wd;
46 // impossible original values to make sure they are read from prefs
47 static gint x = -1000, y = -1000, w = 0, h = 0;
48 static gchar *prefs_path = "dialogs.fillstroke";
50 static void sp_fillstroke_selection_modified ( Inkscape::Application *inkscape, Inkscape::Selection *selection, guint flags, GtkObject *base );
51 static void sp_fillstroke_selection_changed ( Inkscape::Application *inkscape, Inkscape::Selection *selection, GtkObject *base );
52 static void sp_fillstroke_opacity_changed (GtkAdjustment *a, SPWidget *dlg);
54 static void
55 sp_object_properties_dialog_destroy (GtkObject *object, gpointer data)
56 {
57 sp_signal_disconnect_by_data (INKSCAPE, dlg);
58 wd.win = dlg = NULL;
59 wd.stop = 0;
60 }
62 static gboolean
63 sp_object_properties_dialog_delete ( GtkObject *object,
64 GdkEvent *event,
65 gpointer data )
66 {
68 gtk_window_get_position ((GtkWindow *) dlg, &x, &y);
69 gtk_window_get_size ((GtkWindow *) dlg, &w, &h);
71 if (x<0) x=0;
72 if (y<0) y=0;
74 prefs_set_int_attribute (prefs_path, "x", x);
75 prefs_set_int_attribute (prefs_path, "y", y);
76 prefs_set_int_attribute (prefs_path, "w", w);
77 prefs_set_int_attribute (prefs_path, "h", h);
79 return FALSE; // which means, go ahead and destroy it
81 }
84 void
85 sp_object_properties_page( GtkWidget *nb,
86 GtkWidget *page,
87 char *label,
88 char *dlg_name,
89 char *label_image )
90 {
91 GtkWidget *hb, *l, *px;
93 hb = gtk_hbox_new (FALSE, 0);
94 gtk_widget_show (hb);
96 px = sp_icon_new( Inkscape::ICON_SIZE_DECORATION, label_image );
97 gtk_widget_show (px);
98 gtk_box_pack_start (GTK_BOX (hb), px, FALSE, FALSE, 2);
100 l = gtk_label_new_with_mnemonic (label);
101 gtk_widget_show (l);
102 gtk_box_pack_start (GTK_BOX (hb), l, FALSE, FALSE, 0);
104 gtk_widget_show (page);
105 gtk_notebook_append_page (GTK_NOTEBOOK (nb), page, hb);
106 gtk_object_set_data (GTK_OBJECT (dlg), dlg_name, page);
107 }
109 void
110 sp_object_properties_dialog (void)
111 {
112 if (!dlg) {
113 gchar title[500];
114 sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_FILL_STROKE), title);
116 dlg = sp_window_new (title, TRUE);
117 if (x == -1000 || y == -1000) {
118 x = prefs_get_int_attribute (prefs_path, "x", 0);
119 y = prefs_get_int_attribute (prefs_path, "y", 0);
120 }
121 if (w ==0 || h == 0) {
122 w = prefs_get_int_attribute (prefs_path, "w", 0);
123 h = prefs_get_int_attribute (prefs_path, "h", 0);
124 }
126 if (x<0) x=0;
127 if (y<0) y=0;
129 if (x != 0 || y != 0)
130 gtk_window_move ((GtkWindow *) dlg, x, y);
131 else
132 gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
133 if (w && h) gtk_window_resize ((GtkWindow *) dlg, w, h);
134 sp_transientize (dlg);
135 wd.win = dlg;
136 wd.stop = 0;
138 g_signal_connect ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_transientize_callback), &wd );
140 gtk_signal_connect ( GTK_OBJECT (dlg), "event", GTK_SIGNAL_FUNC (sp_dialog_event_handler), dlg );
142 gtk_signal_connect ( GTK_OBJECT (dlg), "destroy", G_CALLBACK (sp_object_properties_dialog_destroy), dlg );
143 gtk_signal_connect ( GTK_OBJECT (dlg), "delete_event", G_CALLBACK (sp_object_properties_dialog_delete), dlg );
144 g_signal_connect ( G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (sp_object_properties_dialog_delete), dlg );
146 g_signal_connect ( G_OBJECT (INKSCAPE), "dialogs_hide", G_CALLBACK (sp_dialog_hide), dlg );
147 g_signal_connect ( G_OBJECT (INKSCAPE), "dialogs_unhide", G_CALLBACK (sp_dialog_unhide), dlg );
149 GtkWidget *vb = gtk_vbox_new (FALSE, 0);
150 gtk_widget_show (vb);
151 gtk_container_add (GTK_CONTAINER (dlg), vb);
153 GtkWidget *nb = gtk_notebook_new ();
154 gtk_widget_show (nb);
155 gtk_box_pack_start (GTK_BOX (vb), nb, TRUE, TRUE, 0);
156 gtk_object_set_data (GTK_OBJECT (dlg), "notebook", nb);
158 /* Fill page */
159 {
160 GtkWidget *page = sp_fill_style_widget_new ();
161 sp_object_properties_page(nb, page, _("_Fill"), "fill",
162 INKSCAPE_STOCK_PROPERTIES_FILL_PAGE);
163 }
165 /* Stroke paint page */
166 {
167 GtkWidget *page = sp_stroke_style_paint_widget_new ();
168 sp_object_properties_page(nb, page, _("Stroke _paint"), "stroke-paint",
169 INKSCAPE_STOCK_PROPERTIES_STROKE_PAINT_PAGE);
170 }
172 /* Stroke style page */
173 {
174 GtkWidget *page = sp_stroke_style_line_widget_new ();
175 sp_object_properties_page(nb, page, _("Stroke st_yle"), "stroke-line",
176 INKSCAPE_STOCK_PROPERTIES_STROKE_PAGE);
177 }
179 /* Opacity */
181 GtkWidget *o_vb = gtk_vbox_new (FALSE, 0);
182 gtk_box_pack_start (GTK_BOX (vb), o_vb, FALSE, FALSE, 2);
183 gtk_object_set_data (GTK_OBJECT (dlg), "master_opacity", o_vb);
185 GtkWidget *l_hb = gtk_hbox_new (FALSE, 4);
186 GtkWidget *l = gtk_label_new_with_mnemonic (_("Master _opacity"));
187 gtk_misc_set_alignment (GTK_MISC (l), 0.0, 1.0);
188 gtk_box_pack_start (GTK_BOX (l_hb), l, FALSE, FALSE, 4);
189 gtk_box_pack_start (GTK_BOX (o_vb), l_hb, FALSE, FALSE, 0);
191 GtkWidget *hb = gtk_hbox_new (FALSE, 4);
192 gtk_box_pack_start (GTK_BOX (o_vb), hb, FALSE, FALSE, 0);
194 GtkObject *a = gtk_adjustment_new (1.0, 0.0, 1.0, 0.01, 0.1, 0.0);
195 gtk_object_set_data(GTK_OBJECT(dlg), "master_opacity_adjustment", a);
197 GtkWidget *s = gtk_hscale_new (GTK_ADJUSTMENT (a));
198 gtk_scale_set_draw_value (GTK_SCALE (s), FALSE);
199 gtk_box_pack_start (GTK_BOX (hb), s, TRUE, TRUE, 4);
200 gtk_label_set_mnemonic_widget (GTK_LABEL(l), s);
202 GtkWidget *sb = gtk_spin_button_new (GTK_ADJUSTMENT (a), 0.01, 3);
203 gtk_box_pack_start (GTK_BOX (hb), sb, FALSE, FALSE, 0);
205 gtk_signal_connect ( a, "value_changed",
206 GTK_SIGNAL_FUNC (sp_fillstroke_opacity_changed),
207 dlg );
209 gtk_widget_show_all (o_vb);
211 // these callbacks are only for the master opacity update; the tabs above take care of themselves
212 g_signal_connect ( G_OBJECT (INKSCAPE), "change_selection", G_CALLBACK (sp_fillstroke_selection_changed), dlg );
213 g_signal_connect ( G_OBJECT (INKSCAPE), "modify_selection", G_CALLBACK (sp_fillstroke_selection_modified), dlg );
214 g_signal_connect ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_fillstroke_selection_changed), dlg );
216 sp_fillstroke_selection_changed(NULL, NULL, NULL);
218 gtk_widget_show (dlg);
220 } else {
221 gtk_window_present (GTK_WINDOW (dlg));
222 }
224 } // end of sp_object_properties_dialog()
226 void sp_object_properties_fill (void)
227 {
228 sp_object_properties_dialog ();
229 GtkWidget *nb = (GtkWidget *)gtk_object_get_data (GTK_OBJECT (dlg), "notebook");
230 gtk_notebook_set_page (GTK_NOTEBOOK (nb), 0);
231 }
233 void sp_object_properties_stroke (void)
234 {
235 sp_object_properties_dialog ();
236 GtkWidget *nb = (GtkWidget *)gtk_object_get_data (GTK_OBJECT (dlg), "notebook");
237 gtk_notebook_set_page (GTK_NOTEBOOK (nb), 1);
238 }
240 void sp_object_properties_stroke_style (void)
241 {
242 sp_object_properties_dialog ();
243 GtkWidget *nb = (GtkWidget *)gtk_object_get_data (GTK_OBJECT (dlg), "notebook");
244 gtk_notebook_set_page (GTK_NOTEBOOK (nb), 2);
245 }
249 static void
250 sp_fillstroke_selection_modified ( Inkscape::Application *inkscape,
251 Inkscape::Selection *selection,
252 guint flags,
253 GtkObject *base )
254 {
255 sp_fillstroke_selection_changed ( inkscape, selection, base );
256 }
259 static void
260 sp_fillstroke_selection_changed ( Inkscape::Application *inkscape,
261 Inkscape::Selection *selection,
262 GtkObject *base )
263 {
264 if (gtk_object_get_data (GTK_OBJECT (dlg), "blocked"))
265 return;
266 gtk_object_set_data (GTK_OBJECT (dlg), "blocked", GUINT_TO_POINTER (TRUE));
268 GtkWidget *opa = GTK_WIDGET (gtk_object_get_data (GTK_OBJECT (dlg), "master_opacity"));
269 GtkAdjustment *a = GTK_ADJUSTMENT(gtk_object_get_data(GTK_OBJECT(dlg), "master_opacity_adjustment"));
271 // create temporary style
272 SPStyle *query = sp_style_new ();
273 // query style from desktop into it. This returns a result flag and fills query with the style of subselection, if any, or selection
274 int result = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_MASTEROPACITY);
276 switch (result) {
277 case QUERY_STYLE_NOTHING:
278 gtk_widget_set_sensitive (opa, FALSE);
279 break;
280 case QUERY_STYLE_SINGLE:
281 case QUERY_STYLE_MULTIPLE_AVERAGED: // TODO: treat this slightly differently
282 case QUERY_STYLE_MULTIPLE_SAME:
283 gtk_widget_set_sensitive (opa, TRUE);
284 gtk_adjustment_set_value(a, SP_SCALE24_TO_FLOAT(query->opacity.value));
285 break;
286 }
288 g_free (query);
289 gtk_object_set_data (GTK_OBJECT (dlg), "blocked", GUINT_TO_POINTER (FALSE));
290 }
292 static void
293 sp_fillstroke_opacity_changed (GtkAdjustment *a, SPWidget *dlg)
294 {
295 if (gtk_object_get_data (GTK_OBJECT (dlg), "blocked"))
296 return;
298 gtk_object_set_data (GTK_OBJECT (dlg), "blocked", GUINT_TO_POINTER (TRUE));
300 SPCSSAttr *css = sp_repr_css_attr_new ();
302 Inkscape::CSSOStringStream os;
303 os << CLAMP (a->value, 0.0, 1.0);
304 sp_repr_css_set_property (css, "opacity", os.str().c_str());
306 sp_desktop_set_style (SP_ACTIVE_DESKTOP, css);
308 sp_repr_css_attr_unref (css);
310 sp_document_maybe_done (SP_DT_DOCUMENT (SP_ACTIVE_DESKTOP), "fillstroke:opacity");
312 gtk_object_set_data (GTK_OBJECT (dlg), "blocked", GUINT_TO_POINTER (FALSE));
313 }
316 /*
317 Local Variables:
318 mode:c++
319 c-file-style:"stroustrup"
320 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
321 indent-tabs-mode:nil
322 fill-column:99
323 End:
324 */
325 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :