1 #define __SP_DESKTOP_WIDGET_C__
3 /** \file
4 * Desktop widget implementation
5 *
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * MenTaLguY <mental@rydia.net>
9 * bulia byak <buliabyak@users.sf.net>
10 * Ralf Stephan <ralf@ark.in-berlin.de>
11 * John Bintz <jcoswell@coswellproductions.org>
12 * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
13 *
14 * Copyright (C) 2007 Johan Engelen
15 * Copyright (C) 2006 John Bintz
16 * Copyright (C) 2004 MenTaLguY
17 * Copyright (C) 1999-2002 Lauris Kaplinski
18 * Copyright (C) 2000-2001 Ximian, Inc.
19 *
20 * Released under GNU GPL, read the file 'COPYING' for more information
21 */
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <gtkmm/paned.h>
28 #include <gtk/gtk.h>
30 #include "macros.h"
31 #include "inkscape-private.h"
32 #include "desktop-handles.h"
33 #include "desktop-events.h"
34 #include "document.h"
35 #include "desktop-widget.h"
36 #include "sp-namedview.h"
37 #include "interface.h"
38 #include "toolbox.h"
39 #include "prefs-utils.h"
40 #include "preferences.h"
41 #include "file.h"
42 #include "display/canvas-arena.h"
43 #include "display/nr-arena.h"
44 #include <extension/db.h>
45 #include "helper/units.h"
46 #include "widgets/button.h"
47 #include "widgets/ruler.h"
48 #include "widgets/widget-sizes.h"
49 #include "widgets/spw-utilities.h"
50 #include "widgets/spinbutton-events.h"
51 #include "widgets/layer-selector.h"
52 #include "ui/dialog/dialog-manager.h"
53 #include "ui/widget/dock.h"
54 #include "ui/widget/selected-style.h"
55 #include "sp-item.h"
56 #include "dialogs/swatches.h"
57 #include "conn-avoid-ref.h"
58 #include "ege-select-one-action.h"
59 #include "ege-color-prof-tracker.h"
60 #include "color-profile-fns.h"
61 #include "xml/node-observer.h"
63 #if defined (SOLARIS_2_8)
64 #include "round.h"
65 using Inkscape::round;
66 #endif
68 #ifdef WITH_INKBOARD
69 #endif
73 enum {
74 ACTIVATE,
75 DEACTIVATE,
76 MODIFIED,
77 EVENT_CONTEXT_CHANGED,
78 LAST_SIGNAL
79 };
82 //---------------------------------------------------------------------
83 /* SPDesktopWidget */
85 static void sp_desktop_widget_class_init (SPDesktopWidgetClass *klass);
86 static void sp_desktop_widget_init (SPDesktopWidget *widget);
87 static void sp_desktop_widget_destroy (GtkObject *object);
89 static void sp_desktop_widget_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
90 static void sp_desktop_widget_realize (GtkWidget *widget);
92 static gint sp_desktop_widget_event (GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dtw);
94 static void sp_dtw_color_profile_event(EgeColorProfTracker *widget, SPDesktopWidget *dtw);
95 static void cms_adjust_toggled( GtkWidget *button, gpointer data );
96 static void cms_adjust_set_sensitive( SPDesktopWidget *dtw, bool enabled );
97 static void sp_desktop_widget_adjustment_value_changed (GtkAdjustment *adj, SPDesktopWidget *dtw);
98 static void sp_desktop_widget_namedview_modified (SPObject *obj, guint flags, SPDesktopWidget *dtw);
100 static gdouble sp_dtw_zoom_value_to_display (gdouble value);
101 static gdouble sp_dtw_zoom_display_to_value (gdouble value);
102 static gint sp_dtw_zoom_input (GtkSpinButton *spin, gdouble *new_val, gpointer data);
103 static bool sp_dtw_zoom_output (GtkSpinButton *spin, gpointer data);
104 static void sp_dtw_zoom_value_changed (GtkSpinButton *spin, gpointer data);
105 static void sp_dtw_zoom_populate_popup (GtkEntry *entry, GtkMenu *menu, gpointer data);
106 static void sp_dtw_zoom_menu_handler (SPDesktop *dt, gdouble factor);
107 static void sp_dtw_zoom_50 (GtkMenuItem *item, gpointer data);
108 static void sp_dtw_zoom_100 (GtkMenuItem *item, gpointer data);
109 static void sp_dtw_zoom_200 (GtkMenuItem *item, gpointer data);
110 static void sp_dtw_zoom_page (GtkMenuItem *item, gpointer data);
111 static void sp_dtw_zoom_drawing (GtkMenuItem *item, gpointer data);
112 static void sp_dtw_zoom_selection (GtkMenuItem *item, gpointer data);
114 SPViewWidgetClass *dtw_parent_class;
116 using Inkscape::XML::Node;
118 class PrefWatcher : public Inkscape::XML::NodeObserver {
119 public:
120 PrefWatcher();
121 virtual ~PrefWatcher();
124 virtual void notifyChildAdded( Node &/*node*/, Node &/*child*/, Node */*prev*/ ) {}
125 virtual void notifyChildRemoved( Node &/*node*/, Node &/*child*/, Node */*prev*/ ) {}
126 virtual void notifyChildOrderChanged( Node &/*node*/, Node &/*child*/,
127 Node */*old_prev*/, Node */*new_prev*/ ) {}
128 virtual void notifyContentChanged( Node &/*node*/,
129 Inkscape::Util::ptr_shared<char> /*old_content*/,
130 Inkscape::Util::ptr_shared<char> /*new_content*/ ) {}
131 virtual void notifyAttributeChanged( Node &node, GQuark name,
132 Inkscape::Util::ptr_shared<char> old_value,
133 Inkscape::Util::ptr_shared<char> new_value );
134 void add( SPDesktopWidget* dtw );
135 void remove( SPDesktopWidget* dtw );
137 private:
138 static void hook(EgeColorProfTracker *tracker, gint a, gint b, PrefWatcher *watcher);
140 std::list<SPDesktopWidget*> dtws;
141 EgeColorProfTracker *_tracker;
142 };
144 PrefWatcher::PrefWatcher() :
145 NodeObserver(),
146 dtws(),
147 _tracker(0)
148 {
149 _tracker = ege_color_prof_tracker_new(0);
150 g_signal_connect( G_OBJECT(_tracker), "modified", G_CALLBACK(hook), this );
151 }
153 PrefWatcher::~PrefWatcher()
154 {
155 }
157 void PrefWatcher::hook(EgeColorProfTracker */*tracker*/, gint screen, gint monitor, PrefWatcher */*watcher*/)
158 {
159 unsigned char* buf = 0;
160 guint len = 0;
162 ege_color_prof_tracker_get_profile_for( screen, monitor, reinterpret_cast<gpointer*>(&buf), &len );
163 Glib::ustring id = Inkscape::colorprofile_set_display_per( buf, len, screen, monitor );
164 }
166 void PrefWatcher::add( SPDesktopWidget* dtw )
167 {
168 dtws.push_back(dtw);
169 }
171 void PrefWatcher::remove( SPDesktopWidget* dtw )
172 {
173 dtws.remove(dtw);
174 }
176 void PrefWatcher::notifyAttributeChanged( Node &node, GQuark name,
177 Inkscape::Util::ptr_shared<char> /*old_value*/,
178 Inkscape::Util::ptr_shared<char> /*new_value*/ )
179 {
180 #if ENABLE_LCMS
181 (void)name;
182 if ( strcmp("group", node.name()) == 0 ) {
183 gchar const* id = node.attribute("id");
184 bool refresh = false;
185 if ( !id ) {
186 // bad
187 } else if (strcmp("displayprofile", id) == 0) {
188 Glib::ustring current = prefs_get_string_attribute( "options.displayprofile", "uri" );
189 bool enabled = current.length() > 0;
191 for ( std::list<SPDesktopWidget*>::iterator it = dtws.begin(); it != dtws.end(); ++it ) {
192 SPDesktopWidget* dtw = *it;
193 if ( GTK_WIDGET_SENSITIVE( dtw->cms_adjust ) != enabled ) {
194 cms_adjust_set_sensitive( dtw, enabled );
195 }
196 }
197 refresh = true;
198 } else if (strcmp("softproof", id) == 0) {
199 refresh = true;
200 }
202 if ( refresh ) {
203 for ( std::list<SPDesktopWidget*>::iterator it = dtws.begin(); it != dtws.end(); ++it ) {
204 (*it)->requestCanvasUpdate();
205 }
206 }
207 #else
208 (void)node;
209 (void)name;
210 (void)new_value;
211 #endif // ENABLE_LCMS
212 }
213 }
215 static PrefWatcher* watcher = 0;
217 void
218 SPDesktopWidget::setMessage (Inkscape::MessageType type, const gchar *message)
219 {
220 GtkLabel *sb=GTK_LABEL(this->select_status);
221 gtk_label_set_markup (sb, message ? message : "");
223 // make sure the important messages are displayed immediately!
224 if (type == Inkscape::IMMEDIATE_MESSAGE && GTK_WIDGET_DRAWABLE (GTK_WIDGET(sb))) {
225 gtk_widget_queue_draw(GTK_WIDGET(sb));
226 gdk_window_process_updates(GTK_WIDGET(sb)->window, TRUE);
227 }
229 // FIXME: TODO: remove <b></b> before displaying as tooltip
230 gtk_tooltips_set_tip (this->tt, this->select_status_eventbox, message ? message : "", NULL);
231 }
233 NR::Point
234 SPDesktopWidget::window_get_pointer()
235 {
236 gint x,y;
237 gdk_window_get_pointer (GTK_WIDGET (canvas)->window, &x, &y, NULL);
238 return NR::Point(x,y);
239 }
241 /**
242 * Registers SPDesktopWidget class and returns its type number.
243 */
244 GtkType
245 sp_desktop_widget_get_type (void)
246 {
247 static GtkType type = 0;
248 if (!type) {
249 static const GtkTypeInfo info = {
250 "SPDesktopWidget",
251 sizeof (SPDesktopWidget),
252 sizeof (SPDesktopWidgetClass),
253 (GtkClassInitFunc) sp_desktop_widget_class_init,
254 (GtkObjectInitFunc) sp_desktop_widget_init,
255 NULL, NULL, NULL
256 };
257 type = gtk_type_unique (SP_TYPE_VIEW_WIDGET, &info);
258 }
259 return type;
260 }
262 /**
263 * SPDesktopWidget vtable initialization
264 */
265 static void
266 sp_desktop_widget_class_init (SPDesktopWidgetClass *klass)
267 {
268 dtw_parent_class = (SPViewWidgetClass*)gtk_type_class (SP_TYPE_VIEW_WIDGET);
270 GtkObjectClass *object_class = (GtkObjectClass *) klass;
271 GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
273 object_class->destroy = sp_desktop_widget_destroy;
275 widget_class->size_allocate = sp_desktop_widget_size_allocate;
276 widget_class->realize = sp_desktop_widget_realize;
277 }
279 /**
280 * Callback for SPDesktopWidget object initialization.
281 */
282 static void
283 sp_desktop_widget_init (SPDesktopWidget *dtw)
284 {
285 GtkWidget *widget;
286 GtkWidget *tbl;
287 GtkWidget *canvas_tbl;
289 GtkWidget *hbox;
290 GtkWidget *eventbox;
291 GtkStyle *style;
293 new (&dtw->modified_connection) sigc::connection();
295 widget = GTK_WIDGET (dtw);
297 dtw->window = 0;
299 dtw->desktop = NULL;
301 dtw->_interaction_disabled_counter = 0;
303 dtw->tt = gtk_tooltips_new ();
305 /* Main table */
306 dtw->vbox = gtk_vbox_new (FALSE, 0);
307 gtk_container_add( GTK_CONTAINER(dtw), GTK_WIDGET(dtw->vbox) );
309 dtw->statusbar = gtk_hbox_new (FALSE, 0);
310 //gtk_widget_set_usize (dtw->statusbar, -1, BOTTOM_BAR_HEIGHT);
311 gtk_box_pack_end (GTK_BOX (dtw->vbox), dtw->statusbar, FALSE, TRUE, 0);
313 {
314 using Inkscape::UI::Dialogs::SwatchesPanel;
316 SwatchesPanel* swatches = new SwatchesPanel("embedded.swatches");
317 swatches->setOrientation( Gtk::ANCHOR_SOUTH );
318 dtw->panels = GTK_WIDGET(swatches->gobj());
319 gtk_box_pack_end( GTK_BOX( dtw->vbox ), dtw->panels, FALSE, TRUE, 0 );
320 }
322 hbox = gtk_hbox_new (FALSE, 0);
323 gtk_box_pack_end (GTK_BOX (dtw->vbox), hbox, TRUE, TRUE, 0);
324 gtk_widget_show (hbox);
326 dtw->aux_toolbox = sp_aux_toolbox_new ();
327 gtk_box_pack_end (GTK_BOX (dtw->vbox), dtw->aux_toolbox, FALSE, TRUE, 0);
329 dtw->commands_toolbox = sp_commands_toolbox_new ();
330 gtk_box_pack_end (GTK_BOX (dtw->vbox), dtw->commands_toolbox, FALSE, TRUE, 0);
332 dtw->tool_toolbox = sp_tool_toolbox_new ();
333 gtk_box_pack_start (GTK_BOX (hbox), dtw->tool_toolbox, FALSE, TRUE, 0);
335 tbl = gtk_table_new (2, 3, FALSE);
336 gtk_box_pack_start (GTK_BOX (hbox), tbl, TRUE, TRUE, 1);
338 canvas_tbl = gtk_table_new (3, 3, FALSE);
340 /* Horizontal ruler */
341 eventbox = gtk_event_box_new ();
342 dtw->hruler = sp_hruler_new ();
343 dtw->hruler_box = eventbox;
344 sp_ruler_set_metric (GTK_RULER (dtw->hruler), SP_PT);
345 gtk_tooltips_set_tip (dtw->tt, dtw->hruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT))), NULL);
346 gtk_container_add (GTK_CONTAINER (eventbox), dtw->hruler);
347 gtk_table_attach (GTK_TABLE (canvas_tbl), eventbox, 1, 2, 0, 1, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_FILL), widget->style->xthickness, 0);
348 g_signal_connect (G_OBJECT (eventbox), "button_press_event", G_CALLBACK (sp_dt_hruler_event), dtw);
349 g_signal_connect (G_OBJECT (eventbox), "button_release_event", G_CALLBACK (sp_dt_hruler_event), dtw);
350 g_signal_connect (G_OBJECT (eventbox), "motion_notify_event", G_CALLBACK (sp_dt_hruler_event), dtw);
352 /* Vertical ruler */
353 eventbox = gtk_event_box_new ();
354 dtw->vruler = sp_vruler_new ();
355 dtw->vruler_box = eventbox;
356 sp_ruler_set_metric (GTK_RULER (dtw->vruler), SP_PT);
357 gtk_tooltips_set_tip (dtw->tt, dtw->vruler_box, gettext(sp_unit_get_plural (&sp_unit_get_by_id(SP_UNIT_PT))), NULL);
358 gtk_container_add (GTK_CONTAINER (eventbox), GTK_WIDGET (dtw->vruler));
359 gtk_table_attach (GTK_TABLE (canvas_tbl), eventbox, 0, 1, 1, 2, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_FILL), 0, widget->style->ythickness);
360 g_signal_connect (G_OBJECT (eventbox), "button_press_event", G_CALLBACK (sp_dt_vruler_event), dtw);
361 g_signal_connect (G_OBJECT (eventbox), "button_release_event", G_CALLBACK (sp_dt_vruler_event), dtw);
362 g_signal_connect (G_OBJECT (eventbox), "motion_notify_event", G_CALLBACK (sp_dt_vruler_event), dtw);
364 /* Horizontal scrollbar */
365 dtw->hadj = (GtkAdjustment *) gtk_adjustment_new (0.0, -4000.0, 4000.0, 10.0, 100.0, 4.0);
366 dtw->hscrollbar = gtk_hscrollbar_new (GTK_ADJUSTMENT (dtw->hadj));
367 gtk_table_attach (GTK_TABLE (canvas_tbl), dtw->hscrollbar, 1, 2, 2, 3, (GtkAttachOptions)(GTK_FILL), (GtkAttachOptions)(GTK_SHRINK), 0, 0);
369 /* Vertical scrollbar and the sticky zoom button */
370 dtw->vscrollbar_box = gtk_vbox_new (FALSE, 0);
371 dtw->sticky_zoom = sp_button_new_from_data ( Inkscape::ICON_SIZE_DECORATION,
372 SP_BUTTON_TYPE_TOGGLE,
373 NULL,
374 "sticky_zoom",
375 _("Zoom drawing if window size changes"),
376 dtw->tt);
377 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dtw->sticky_zoom), prefs_get_int_attribute ("options.stickyzoom", "value", 0));
378 gtk_box_pack_start (GTK_BOX (dtw->vscrollbar_box), dtw->sticky_zoom, FALSE, FALSE, 0);
379 dtw->vadj = (GtkAdjustment *) gtk_adjustment_new (0.0, -4000.0, 4000.0, 10.0, 100.0, 4.0);
380 dtw->vscrollbar = gtk_vscrollbar_new (GTK_ADJUSTMENT (dtw->vadj));
381 gtk_box_pack_start (GTK_BOX (dtw->vscrollbar_box), dtw->vscrollbar, TRUE, TRUE, 0);
382 gtk_table_attach (GTK_TABLE (canvas_tbl), dtw->vscrollbar_box, 2, 3, 0, 2, (GtkAttachOptions)(GTK_SHRINK), (GtkAttachOptions)(GTK_FILL), 0, 0);
385 gchar const* tip = "";
386 Inkscape::Verb* verb = Inkscape::Verb::get( SP_VERB_VIEW_CMS_TOGGLE );
387 if ( verb ) {
388 SPAction *act = verb->get_action( dtw->viewwidget.view );
389 if ( act && act->tip ) {
390 tip = act->tip;
391 }
392 }
393 dtw->cms_adjust = sp_button_new_from_data( Inkscape::ICON_SIZE_DECORATION,
394 SP_BUTTON_TYPE_TOGGLE,
395 NULL,
396 "color_management",
397 tip,
398 dtw->tt );
399 #if ENABLE_LCMS
400 {
401 Glib::ustring current = prefs_get_string_attribute( "options.displayprofile", "uri" );
402 bool enabled = current.length() > 0;
403 cms_adjust_set_sensitive( dtw, enabled );
404 if ( enabled ) {
405 long long int active = prefs_get_int_attribute_limited( "options.displayprofile", "enable", 0, 0, 1 );
406 if ( active ) {
407 sp_button_toggle_set_down( SP_BUTTON(dtw->cms_adjust), TRUE );
408 }
409 }
410 }
411 g_signal_connect_after( G_OBJECT(dtw->cms_adjust), "clicked", G_CALLBACK(cms_adjust_toggled), dtw );
412 #else
413 cms_adjust_set_sensitive(dtw, FALSE);
414 #endif // ENABLE_LCMS
415 gtk_table_attach( GTK_TABLE(canvas_tbl), dtw->cms_adjust, 2, 3, 2, 3, (GtkAttachOptions)(GTK_SHRINK), (GtkAttachOptions)(GTK_SHRINK), 0, 0);
416 {
417 Inkscape::XML::Node* prefs = Inkscape::Preferences::get();
418 if ( prefs ) {
419 if (!watcher) {
420 watcher = new PrefWatcher();
421 prefs->addSubtreeObserver( *watcher );
422 }
423 watcher->add(dtw);
424 } else {
425 g_warning("NULL preferences instance encountered");
426 }
427 }
429 /* Canvas */
430 dtw->canvas = SP_CANVAS (sp_canvas_new_aa ());
431 #if ENABLE_LCMS
432 dtw->canvas->enable_cms_display_adj = prefs_get_int_attribute_limited( "options.displayprofile", "enable", 0, 0, 1 ) != 0;
433 #endif // ENABLE_LCMS
434 GTK_WIDGET_SET_FLAGS (GTK_WIDGET (dtw->canvas), GTK_CAN_FOCUS);
435 style = gtk_style_copy (GTK_WIDGET (dtw->canvas)->style);
436 style->bg[GTK_STATE_NORMAL] = style->white;
437 gtk_widget_set_style (GTK_WIDGET (dtw->canvas), style);
438 gtk_widget_set_extension_events(GTK_WIDGET (dtw->canvas) , GDK_EXTENSION_EVENTS_ALL);
439 g_signal_connect (G_OBJECT (dtw->canvas), "event", G_CALLBACK (sp_desktop_widget_event), dtw);
440 gtk_table_attach (GTK_TABLE (canvas_tbl), GTK_WIDGET(dtw->canvas), 1, 2, 1, 2, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), 0, 0);
442 /* Dock */
443 bool create_dock =
444 prefs_get_int_attribute_limited ("options.dialogtype", "value", Inkscape::UI::Dialog::FLOATING, 0, 1) ==
445 Inkscape::UI::Dialog::DOCK;
447 if (create_dock) {
448 dtw->dock = new Inkscape::UI::Widget::Dock();
450 Gtk::HPaned *paned = new Gtk::HPaned();
451 paned->pack1(*Glib::wrap(canvas_tbl));
452 paned->pack2(dtw->dock->getWidget(), Gtk::FILL);
454 /* Prevent the paned from catching F6 and F8 by unsetting the default callbacks */
455 if (GtkPanedClass *paned_class = GTK_PANED_CLASS (G_OBJECT_GET_CLASS (paned->gobj()))) {
456 paned_class->cycle_child_focus = NULL;
457 paned_class->cycle_handle_focus = NULL;
458 }
460 gtk_table_attach (GTK_TABLE (tbl), GTK_WIDGET (paned->gobj()), 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
461 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0);
463 } else {
464 gtk_table_attach (GTK_TABLE (tbl), GTK_WIDGET (canvas_tbl), 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL),
465 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0);
466 }
468 dtw->selected_style = new Inkscape::UI::Widget::SelectedStyle(true);
469 GtkHBox *ss_ = dtw->selected_style->gobj();
470 gtk_box_pack_start (GTK_BOX (dtw->statusbar), GTK_WIDGET(ss_), FALSE, FALSE, 0);
471 gtk_box_pack_start (GTK_BOX (dtw->statusbar), gtk_vseparator_new(), FALSE, FALSE, 0);
473 // connect scrollbar signals
474 g_signal_connect (G_OBJECT (dtw->hadj), "value-changed", G_CALLBACK (sp_desktop_widget_adjustment_value_changed), dtw);
475 g_signal_connect (G_OBJECT (dtw->vadj), "value-changed", G_CALLBACK (sp_desktop_widget_adjustment_value_changed), dtw);
477 GtkWidget *statusbar_tail=gtk_statusbar_new();
478 gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(statusbar_tail), TRUE);
479 gtk_box_pack_end (GTK_BOX (dtw->statusbar), statusbar_tail, FALSE, FALSE, 0);
481 // zoom status spinbutton
482 dtw->zoom_status = gtk_spin_button_new_with_range (log(SP_DESKTOP_ZOOM_MIN)/log(2), log(SP_DESKTOP_ZOOM_MAX)/log(2), 0.1);
483 gtk_tooltips_set_tip (dtw->tt, dtw->zoom_status, _("Zoom"), NULL);
484 gtk_widget_set_size_request (dtw->zoom_status, STATUS_ZOOM_WIDTH, -1);
485 gtk_entry_set_width_chars (GTK_ENTRY (dtw->zoom_status), 6);
486 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (dtw->zoom_status), FALSE);
487 gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (dtw->zoom_status), GTK_UPDATE_ALWAYS);
488 g_signal_connect (G_OBJECT (dtw->zoom_status), "input", G_CALLBACK (sp_dtw_zoom_input), dtw);
489 g_signal_connect (G_OBJECT (dtw->zoom_status), "output", G_CALLBACK (sp_dtw_zoom_output), dtw);
490 gtk_object_set_data (GTK_OBJECT (dtw->zoom_status), "dtw", dtw->canvas);
491 gtk_signal_connect (GTK_OBJECT (dtw->zoom_status), "focus-in-event", GTK_SIGNAL_FUNC (spinbutton_focus_in), dtw->zoom_status);
492 gtk_signal_connect (GTK_OBJECT (dtw->zoom_status), "key-press-event", GTK_SIGNAL_FUNC (spinbutton_keypress), dtw->zoom_status);
493 dtw->zoom_update = g_signal_connect (G_OBJECT (dtw->zoom_status), "value_changed", G_CALLBACK (sp_dtw_zoom_value_changed), dtw);
494 dtw->zoom_update = g_signal_connect (G_OBJECT (dtw->zoom_status), "populate_popup", G_CALLBACK (sp_dtw_zoom_populate_popup), dtw);
496 // cursor coordinates
497 dtw->coord_status = gtk_table_new (5, 2, FALSE);
498 gtk_table_set_row_spacings(GTK_TABLE(dtw->coord_status), 0);
499 gtk_table_set_col_spacings(GTK_TABLE(dtw->coord_status), 2);
500 gtk_table_attach(GTK_TABLE(dtw->coord_status), gtk_vseparator_new(), 0,1, 0,2, GTK_FILL, GTK_FILL, 0, 0);
501 eventbox = gtk_event_box_new ();
502 gtk_container_add (GTK_CONTAINER (eventbox), dtw->coord_status);
503 gtk_tooltips_set_tip (dtw->tt, eventbox, _("Cursor coordinates"), NULL);
504 GtkWidget *label_x = gtk_label_new("X:");
505 gtk_misc_set_alignment (GTK_MISC(label_x), 0.0, 0.5);
506 gtk_table_attach(GTK_TABLE(dtw->coord_status), label_x, 1,2, 0,1, GTK_FILL, GTK_FILL, 0, 0);
507 GtkWidget *label_y = gtk_label_new("Y:");
508 gtk_misc_set_alignment (GTK_MISC(label_y), 0.0, 0.5);
509 gtk_table_attach(GTK_TABLE(dtw->coord_status), label_y, 1,2, 1,2, GTK_FILL, GTK_FILL, 0, 0);
510 dtw->coord_status_x = gtk_label_new(NULL);
511 gtk_label_set_markup( GTK_LABEL(dtw->coord_status_x), "<tt> 0.00 </tt>" );
512 gtk_misc_set_alignment (GTK_MISC(dtw->coord_status_x), 1.0, 0.5);
513 dtw->coord_status_y = gtk_label_new(NULL);
514 gtk_label_set_markup( GTK_LABEL(dtw->coord_status_y), "<tt> 0.00 </tt>" );
515 gtk_misc_set_alignment (GTK_MISC(dtw->coord_status_y), 1.0, 0.5);
516 gtk_table_attach(GTK_TABLE(dtw->coord_status), dtw->coord_status_x, 2,3, 0,1, GTK_FILL, GTK_FILL, 0, 0);
517 gtk_table_attach(GTK_TABLE(dtw->coord_status), dtw->coord_status_y, 2,3, 1,2, GTK_FILL, GTK_FILL, 0, 0);
518 gtk_table_attach(GTK_TABLE(dtw->coord_status), gtk_label_new("Z:"), 3,4, 0,2, GTK_FILL, GTK_FILL, 0, 0);
519 gtk_table_attach(GTK_TABLE(dtw->coord_status), dtw->zoom_status, 4,5, 0,2, GTK_FILL, GTK_FILL, 0, 0);
520 sp_set_font_size_smaller (dtw->coord_status);
521 gtk_box_pack_end (GTK_BOX (statusbar_tail), eventbox, FALSE, FALSE, 1);
523 dtw->layer_selector = new Inkscape::Widgets::LayerSelector(NULL);
524 // FIXME: need to unreference on container destruction to avoid leak
525 dtw->layer_selector->reference();
526 //dtw->layer_selector->set_size_request(-1, SP_ICON_SIZE_BUTTON);
527 gtk_box_pack_start(GTK_BOX(dtw->statusbar), GTK_WIDGET(dtw->layer_selector->gobj()), FALSE, FALSE, 1);
529 dtw->_tracker = ege_color_prof_tracker_new(GTK_WIDGET(dtw->layer_selector->gobj()));
530 {
531 Glib::ustring id = Inkscape::colorprofile_get_display_id( 0, 0 );
532 bool enabled = false;
533 if ( dtw->canvas->cms_key ) {
534 *(dtw->canvas->cms_key) = id;
535 enabled = !dtw->canvas->cms_key->empty();
536 }
537 cms_adjust_set_sensitive( dtw, enabled );
538 }
539 g_signal_connect( G_OBJECT(dtw->_tracker), "changed", G_CALLBACK(sp_dtw_color_profile_event), dtw );
541 dtw->select_status_eventbox = gtk_event_box_new ();
542 dtw->select_status = gtk_label_new (NULL);
543 #if GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 6
544 gtk_label_set_ellipsize (GTK_LABEL(dtw->select_status), PANGO_ELLIPSIZE_END);
545 #endif
546 gtk_misc_set_alignment (GTK_MISC (dtw->select_status), 0.0, 0.5);
547 gtk_widget_set_size_request (dtw->select_status, 1, -1);
548 // display the initial welcome message in the statusbar
549 gtk_label_set_markup (GTK_LABEL (dtw->select_status), _("<b>Welcome to Inkscape!</b> Use shape or freehand tools to create objects; use selector (arrow) to move or transform them."));
550 // space label 2 pixels from left edge
551 gtk_container_add (GTK_CONTAINER (dtw->select_status_eventbox), dtw->select_status);
552 gtk_box_pack_start (GTK_BOX (dtw->statusbar), gtk_hbox_new(FALSE, 0), FALSE, FALSE, 2);
553 gtk_box_pack_start (GTK_BOX (dtw->statusbar), dtw->select_status_eventbox, TRUE, TRUE, 0);
555 gtk_widget_show_all (dtw->vbox);
556 }
558 /**
559 * Called before SPDesktopWidget destruction.
560 */
561 static void
562 sp_desktop_widget_destroy (GtkObject *object)
563 {
564 SPDesktopWidget *dtw = SP_DESKTOP_WIDGET (object);
566 if (dtw->desktop) {
567 if ( watcher ) {
568 watcher->remove(dtw);
569 }
570 g_signal_handlers_disconnect_by_func(G_OBJECT (dtw->zoom_status), (gpointer) G_CALLBACK(sp_dtw_zoom_input), dtw);
571 g_signal_handlers_disconnect_by_func(G_OBJECT (dtw->zoom_status), (gpointer) G_CALLBACK(sp_dtw_zoom_output), dtw);
572 gtk_signal_disconnect_by_data (GTK_OBJECT (dtw->zoom_status), dtw->zoom_status);
573 g_signal_handlers_disconnect_by_func (G_OBJECT (dtw->zoom_status), (gpointer) G_CALLBACK (sp_dtw_zoom_value_changed), dtw);
574 g_signal_handlers_disconnect_by_func (G_OBJECT (dtw->zoom_status), (gpointer) G_CALLBACK (sp_dtw_zoom_populate_popup), dtw);
575 g_signal_handlers_disconnect_by_func (G_OBJECT (dtw->canvas), (gpointer) G_CALLBACK (sp_desktop_widget_event), dtw);
577 dtw->layer_selector->unreference();
578 inkscape_remove_desktop (dtw->desktop); // clears selection too
579 dtw->modified_connection.disconnect();
580 dtw->desktop->destroy();
581 Inkscape::GC::release (dtw->desktop);
582 dtw->desktop = NULL;
583 }
585 dtw->modified_connection.~connection();
587 if (GTK_OBJECT_CLASS (dtw_parent_class)->destroy) {
588 (* GTK_OBJECT_CLASS (dtw_parent_class)->destroy) (object);
589 }
590 }
593 /**
594 * Set the title in the desktop-window (if desktop has an own window).
595 *
596 * The title has form file name: desktop number - Inkscape.
597 * The desktop number is only shown if it's 2 or higher,
598 */
599 void
600 SPDesktopWidget::updateTitle(gchar const* uri)
601 {
602 Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
604 if (window) {
605 gchar const *fname = ( TRUE
606 ? uri
607 : g_basename(uri) );
608 GString *name = g_string_new ("");
609 if (this->desktop->number > 1) {
610 if (this->desktop->getMode() == RENDERMODE_OUTLINE) {
611 g_string_printf (name, _("%s: %d (outline) - Inkscape"), fname, this->desktop->number);
612 } else {
613 g_string_printf (name, _("%s: %d - Inkscape"), fname, this->desktop->number);
614 }
615 } else {
616 if (this->desktop->getMode() == RENDERMODE_OUTLINE) {
617 g_string_printf (name, _("%s (outline) - Inkscape"), fname);
618 } else {
619 g_string_printf (name, _("%s - Inkscape"), fname);
620 }
621 }
622 window->set_title (name->str);
623 g_string_free (name, TRUE);
624 }
625 }
627 Inkscape::UI::Widget::Dock*
628 SPDesktopWidget::getDock()
629 {
630 return dock;
631 }
633 /**
634 * Callback to allocate space for desktop widget.
635 */
636 static void
637 sp_desktop_widget_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
638 {
639 SPDesktopWidget *dtw = SP_DESKTOP_WIDGET (widget);
641 if ((allocation->x == widget->allocation.x) &&
642 (allocation->y == widget->allocation.y) &&
643 (allocation->width == widget->allocation.width) &&
644 (allocation->height == widget->allocation.height)) {
645 if (GTK_WIDGET_CLASS (dtw_parent_class)->size_allocate)
646 GTK_WIDGET_CLASS (dtw_parent_class)->size_allocate (widget, allocation);
647 return;
648 }
650 if (GTK_WIDGET_REALIZED (widget)) {
651 NR::Rect const area = dtw->desktop->get_display_area();
652 double zoom = dtw->desktop->current_zoom();
654 if (GTK_WIDGET_CLASS(dtw_parent_class)->size_allocate) {
655 GTK_WIDGET_CLASS(dtw_parent_class)->size_allocate (widget, allocation);
656 }
658 if (SP_BUTTON_IS_DOWN(dtw->sticky_zoom)) {
659 /* Calculate zoom per pixel */
660 double const zpsp = zoom / hypot (area.dimensions()[NR::X], area.dimensions()[NR::Y]);
661 /* Find new visible area */
662 NR::Rect newarea = dtw->desktop->get_display_area();
663 /* Calculate adjusted zoom */
664 zoom = zpsp * hypot(newarea.dimensions()[NR::X], newarea.dimensions()[NR::Y]);
665 dtw->desktop->zoom_absolute(newarea.midpoint()[NR::X], newarea.midpoint()[NR::Y], zoom);
666 } else {
667 dtw->desktop->zoom_absolute(area.midpoint()[NR::X], area.midpoint()[NR::Y], zoom);
668 }
670 } else {
671 if (GTK_WIDGET_CLASS (dtw_parent_class)->size_allocate) {
672 GTK_WIDGET_CLASS (dtw_parent_class)->size_allocate (widget, allocation);
673 }
674 // this->size_allocate (widget, allocation);
675 }
676 }
678 /**
679 * Callback to realize desktop widget.
680 */
681 static void
682 sp_desktop_widget_realize (GtkWidget *widget)
683 {
685 SPDesktopWidget *dtw = SP_DESKTOP_WIDGET (widget);
687 if (GTK_WIDGET_CLASS (dtw_parent_class)->realize)
688 (* GTK_WIDGET_CLASS (dtw_parent_class)->realize) (widget);
690 NRRect d;
691 d.x0 = 0.0;
692 d.y0 = 0.0;
693 d.x1 = sp_document_width (dtw->desktop->doc());
694 d.y1 = sp_document_height (dtw->desktop->doc());
696 if ((fabs (d.x1 - d.x0) < 1.0) || (fabs (d.y1 - d.y0) < 1.0)) return;
698 dtw->desktop->set_display_area (d.x0, d.y0, d.x1, d.y1, 10);
700 /* Listen on namedview modification */
701 // originally (prior to the sigc++ conversion) the signal was simply
702 // connected twice rather than disconnecting the first connection
703 dtw->modified_connection.disconnect();
704 dtw->modified_connection = dtw->desktop->namedview->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_desktop_widget_namedview_modified), dtw));
705 sp_desktop_widget_namedview_modified (dtw->desktop->namedview, SP_OBJECT_MODIFIED_FLAG, dtw);
707 dtw->updateTitle(SP_DOCUMENT_NAME (dtw->desktop->doc()));
708 }
710 /**
711 * Callback to handle desktop widget event.
712 */
713 static gint
714 sp_desktop_widget_event (GtkWidget *widget, GdkEvent *event, SPDesktopWidget *dtw)
715 {
716 if (event->type == GDK_BUTTON_PRESS) {
717 // defocus any spinbuttons
718 gtk_widget_grab_focus (GTK_WIDGET(dtw->canvas));
719 }
721 if ((event->type == GDK_BUTTON_PRESS) && (event->button.button == 3)) {
722 if (event->button.state & GDK_SHIFT_MASK) {
723 sp_canvas_arena_set_sticky (SP_CANVAS_ARENA (dtw->desktop->drawing), TRUE);
724 } else {
725 sp_canvas_arena_set_sticky (SP_CANVAS_ARENA (dtw->desktop->drawing), FALSE);
726 }
727 }
729 if (GTK_WIDGET_CLASS (dtw_parent_class)->event) {
730 return (* GTK_WIDGET_CLASS (dtw_parent_class)->event) (widget, event);
731 } else {
732 // The keypress events need to be passed to desktop handler explicitly,
733 // because otherwise the event contexts only receive keypresses when the mouse cursor
734 // is over the canvas. This redirection is only done for keypresses and only if there's no
735 // current item on the canvas, because item events and all mouse events are caught
736 // and passed on by the canvas acetate (I think). --bb
737 if (event->type == GDK_KEY_PRESS && !dtw->canvas->current_item) {
738 return sp_desktop_root_handler (NULL, event, dtw->desktop);
739 }
740 }
742 return FALSE;
743 }
745 void sp_dtw_color_profile_event(EgeColorProfTracker */*tracker*/, SPDesktopWidget *dtw)
746 {
747 // Handle profile changes
748 GdkScreen* screen = gtk_widget_get_screen(GTK_WIDGET(dtw));
749 gint screenNum = gdk_screen_get_number(screen);
750 gint monitor = gdk_screen_get_monitor_at_window(screen, gtk_widget_get_toplevel(GTK_WIDGET(dtw))->window);
751 Glib::ustring id = Inkscape::colorprofile_get_display_id( screenNum, monitor );
752 bool enabled = false;
753 if ( dtw->canvas->cms_key ) {
754 *(dtw->canvas->cms_key) = id;
755 dtw->requestCanvasUpdate();
756 enabled = !dtw->canvas->cms_key->empty();
757 }
758 cms_adjust_set_sensitive( dtw, enabled );
759 }
761 void cms_adjust_toggled( GtkWidget */*button*/, gpointer data )
762 {
763 SPDesktopWidget *dtw = SP_DESKTOP_WIDGET(data);
765 bool down = SP_BUTTON_IS_DOWN(dtw->cms_adjust);
766 if ( down != dtw->canvas->enable_cms_display_adj ) {
767 dtw->canvas->enable_cms_display_adj = down;
768 dtw->requestCanvasUpdate();
769 prefs_set_int_attribute( "options.displayprofile", "enable", down ? 1 : 0 );
770 }
771 }
773 void cms_adjust_set_sensitive( SPDesktopWidget *dtw, bool enabled )
774 {
775 Inkscape::Verb* verb = Inkscape::Verb::get( SP_VERB_VIEW_CMS_TOGGLE );
776 if ( verb ) {
777 SPAction *act = verb->get_action( dtw->viewwidget.view );
778 if ( act ) {
779 sp_action_set_sensitive( act, enabled );
780 }
781 }
782 gtk_widget_set_sensitive( dtw->cms_adjust, enabled );
783 }
785 void
786 sp_dtw_desktop_activate (SPDesktopWidget */*dtw*/)
787 {
788 /* update active desktop indicator */
789 }
791 void
792 sp_dtw_desktop_deactivate (SPDesktopWidget */*dtw*/)
793 {
794 /* update inactive desktop indicator */
795 }
797 /**
798 * Shuts down the desktop object for the view being closed. It checks
799 * to see if the document has been edited, and if so prompts the user
800 * to save, discard, or cancel. Returns TRUE if the shutdown operation
801 * is cancelled or if the save is cancelled or fails, FALSE otherwise.
802 */
803 bool
804 SPDesktopWidget::shutdown()
805 {
806 g_assert(desktop != NULL);
808 if (inkscape_is_sole_desktop_for_document(*desktop)) {
809 SPDocument *doc = desktop->doc();
810 if (sp_document_repr_root(doc)->attribute("sodipodi:modified") != NULL) {
811 GtkWidget *dialog;
813 /** \todo
814 * FIXME !!! obviously this will have problems if the document
815 * name contains markup characters
816 */
817 dialog = gtk_message_dialog_new_with_markup(
818 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(this))),
819 GTK_DIALOG_DESTROY_WITH_PARENT,
820 GTK_MESSAGE_WARNING,
821 GTK_BUTTONS_NONE,
822 _("<span weight=\"bold\" size=\"larger\">Save changes to document \"%s\" before closing?</span>\n\n"
823 "If you close without saving, your changes will be discarded."),
824 SP_DOCUMENT_NAME(doc));
825 // fix for bug 1767940:
826 GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(GTK_MESSAGE_DIALOG(dialog)->label), GTK_CAN_FOCUS);
828 GtkWidget *close_button;
829 close_button = gtk_button_new_with_mnemonic(_("Close _without saving"));
830 gtk_widget_show(close_button);
831 gtk_dialog_add_action_widget(GTK_DIALOG(dialog), close_button, GTK_RESPONSE_NO);
833 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
834 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_SAVE, GTK_RESPONSE_YES);
835 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_YES);
837 gint response;
838 response = gtk_dialog_run(GTK_DIALOG(dialog));
839 gtk_widget_destroy(dialog);
841 switch (response) {
842 case GTK_RESPONSE_YES:
843 {
844 Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
846 sp_document_ref(doc);
847 if (sp_file_save_document(*window, doc)) {
848 sp_document_unref(doc);
849 } else { // save dialog cancelled or save failed
850 sp_document_unref(doc);
851 return TRUE;
852 }
854 break;
855 }
856 case GTK_RESPONSE_NO:
857 break;
858 default: // cancel pressed, or dialog was closed
859 return TRUE;
860 break;
861 }
862 }
863 /* Code to check data loss */
864 bool allow_data_loss = FALSE;
865 while (sp_document_repr_root(doc)->attribute("inkscape:dataloss") != NULL && allow_data_loss == FALSE) {
866 GtkWidget *dialog;
868 /** \todo
869 * FIXME !!! obviously this will have problems if the document
870 * name contains markup characters
871 */
872 dialog = gtk_message_dialog_new_with_markup(
873 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(this))),
874 GTK_DIALOG_DESTROY_WITH_PARENT,
875 GTK_MESSAGE_WARNING,
876 GTK_BUTTONS_NONE,
877 _("<span weight=\"bold\" size=\"larger\">The file \"%s\" was saved with a format (%s) that may cause data loss!</span>\n\n"
878 "Do you want to save this file in another format?"),
879 SP_DOCUMENT_NAME(doc),
880 Inkscape::Extension::db.get(sp_document_repr_root(doc)->attribute("inkscape:output_extension"))->get_name());
881 // fix for bug 1767940:
882 GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(GTK_MESSAGE_DIALOG(dialog)->label), GTK_CAN_FOCUS);
884 GtkWidget *close_button;
885 close_button = gtk_button_new_with_mnemonic(_("Close _without saving"));
886 gtk_widget_show(close_button);
887 gtk_dialog_add_action_widget(GTK_DIALOG(dialog), close_button, GTK_RESPONSE_NO);
889 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
890 gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_SAVE, GTK_RESPONSE_YES);
891 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_YES);
893 gint response;
894 response = gtk_dialog_run(GTK_DIALOG(dialog));
895 gtk_widget_destroy(dialog);
897 switch (response) {
898 case GTK_RESPONSE_YES:
899 {
900 sp_document_ref(doc);
902 Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
904 if (sp_file_save_dialog(*window, doc)) {
905 sp_document_unref(doc);
906 } else { // save dialog cancelled or save failed
907 sp_document_unref(doc);
908 return TRUE;
909 }
911 break;
912 }
913 case GTK_RESPONSE_NO:
914 allow_data_loss = TRUE;
915 break;
916 default: // cancel pressed, or dialog was closed
917 return TRUE;
918 break;
919 }
920 }
921 }
923 /* Save window geometry to prefs for use as a default.
924 * Use depends on setting of "options.savewindowgeometry".
925 * But we save the info here regardless of the setting.
926 */
927 {
928 gint full = desktop->is_fullscreen() ? 1 : 0;
929 gint maxed = desktop->is_maximized() ? 1 : 0;
930 prefs_set_int_attribute("desktop.geometry", "fullscreen", full);
931 prefs_set_int_attribute("desktop.geometry", "maximized", maxed);
932 gint w, h, x, y;
933 desktop->getWindowGeometry(x, y, w, h);
934 // Don't save geom for maximized windows. It
935 // just tells you the current maximized size, which is not
936 // as useful as whatever value it had previously.
937 if (!maxed && !full) {
938 prefs_set_int_attribute("desktop.geometry", "width", w);
939 prefs_set_int_attribute("desktop.geometry", "height", h);
940 prefs_set_int_attribute("desktop.geometry", "x", x);
941 prefs_set_int_attribute("desktop.geometry", "y", y);
942 }
943 }
945 return FALSE;
946 }
948 /**
949 * \pre this->desktop->main != 0
950 */
951 void
952 SPDesktopWidget::requestCanvasUpdate() {
953 gtk_widget_queue_draw (GTK_WIDGET (SP_CANVAS_ITEM (this->desktop->main)->canvas));
954 }
956 void
957 SPDesktopWidget::requestCanvasUpdateAndWait() {
958 requestCanvasUpdate();
960 while (gtk_events_pending())
961 gtk_main_iteration_do(FALSE);
963 }
965 void
966 SPDesktopWidget::enableInteraction()
967 {
968 g_return_if_fail(_interaction_disabled_counter > 0);
970 _interaction_disabled_counter--;
972 if (_interaction_disabled_counter == 0) {
973 gtk_widget_set_sensitive(GTK_WIDGET(this), TRUE);
974 }
975 }
977 void
978 SPDesktopWidget::disableInteraction()
979 {
980 if (_interaction_disabled_counter == 0) {
981 gtk_widget_set_sensitive(GTK_WIDGET(this), FALSE);
982 }
984 _interaction_disabled_counter++;
985 }
987 void
988 SPDesktopWidget::setCoordinateStatus(NR::Point p)
989 {
990 gchar *cstr;
991 cstr = g_strdup_printf("<tt>%7.2f </tt>", dt2r * p[NR::X]);
992 gtk_label_set_markup( GTK_LABEL(this->coord_status_x), cstr );
993 g_free(cstr);
995 cstr = g_strdup_printf("<tt>%7.2f </tt>", dt2r * p[NR::Y]);
996 gtk_label_set_markup( GTK_LABEL(this->coord_status_y), cstr );
997 g_free(cstr);
998 }
1000 void
1001 SPDesktopWidget::letZoomGrabFocus()
1002 {
1003 if (zoom_status)
1004 gtk_widget_grab_focus (zoom_status);
1005 }
1007 void
1008 SPDesktopWidget::getWindowGeometry (gint &x, gint &y, gint &w, gint &h)
1009 {
1010 gboolean vis = GTK_WIDGET_VISIBLE (this);
1011 (void)vis; // TODO figure out why it is here but not used.
1013 Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
1015 if (window)
1016 {
1017 window->get_size (w, h);
1018 window->get_position (x, y);
1019 }
1020 }
1022 void
1023 SPDesktopWidget::setWindowPosition (NR::Point p)
1024 {
1025 Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
1027 if (window)
1028 {
1029 window->move (gint(round(p[NR::X])), gint(round(p[NR::Y])));
1030 }
1031 }
1033 void
1034 SPDesktopWidget::setWindowSize (gint w, gint h)
1035 {
1036 Gtk::Window *window = (Gtk::Window*)gtk_object_get_data (GTK_OBJECT(this), "window");
1038 if (window)
1039 {
1040 window->set_default_size (w, h);
1041 window->reshow_with_initial_size ();
1042 }
1043 }
1045 /**
1046 * \note transientizing does not work on windows; when you minimize a document
1047 * and then open it back, only its transient emerges and you cannot access
1048 * the document window. The document window must be restored by rightclicking
1049 * the taskbar button and pressing "Restore"
1050 */
1051 void
1052 SPDesktopWidget::setWindowTransient (void *p, int transient_policy)
1053 {
1054 GtkWindow *w =GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(this)));
1055 if (w)
1056 {
1057 gtk_window_set_transient_for (GTK_WINDOW(p), w);
1059 /*
1060 * This enables "aggressive" transientization,
1061 * i.e. dialogs always emerging on top when you switch documents. Note
1062 * however that this breaks "click to raise" policy of a window
1063 * manager because the switched-to document will be raised at once
1064 * (so that its transients also could raise)
1065 */
1066 if (transient_policy == 2)
1068 // without this, a transient window not always emerges on top
1069 gtk_window_present (w);
1070 }
1071 }
1073 void
1074 SPDesktopWidget::presentWindow()
1075 {
1076 GtkWindow *w =GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(this)));
1077 if (w)
1078 gtk_window_present (w);
1079 }
1081 bool
1082 SPDesktopWidget::warnDialog (gchar* text)
1083 {
1084 GtkWindow *w =GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(this)));
1085 if (w)
1086 {
1087 GtkWidget *dialog = gtk_message_dialog_new(
1088 w,
1089 GTK_DIALOG_DESTROY_WITH_PARENT,
1090 GTK_MESSAGE_WARNING,
1091 GTK_BUTTONS_YES_NO,
1092 "%s", text);
1093 gint response = gtk_dialog_run(GTK_DIALOG(dialog));
1094 gtk_widget_destroy(dialog);
1095 if (response == GTK_RESPONSE_YES)
1096 return true;
1097 }
1098 return false;
1099 }
1101 void
1102 sp_desktop_widget_iconify(SPDesktopWidget *dtw)
1103 {
1104 GtkWindow *topw = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(dtw->canvas)));
1105 if (GTK_IS_WINDOW(topw)) {
1106 if (dtw->desktop->is_iconified()) {
1107 gtk_window_deiconify(topw);
1108 } else {
1109 gtk_window_iconify(topw);
1110 }
1111 }
1112 }
1114 void
1115 sp_desktop_widget_maximize(SPDesktopWidget *dtw)
1116 {
1117 GtkWindow *topw = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(dtw->canvas)));
1118 if (GTK_IS_WINDOW(topw)) {
1119 if (dtw->desktop->is_maximized()) {
1120 gtk_window_unmaximize(topw);
1121 } else {
1122 // Save geometry to prefs before maximizing so that
1123 // something useful is stored there, because GTK doesn't maintain
1124 // a separate non-maximized size.
1125 if (!dtw->desktop->is_iconified() && !dtw->desktop->is_fullscreen())
1126 {
1127 gint w, h, x, y;
1128 dtw->getWindowGeometry(x, y, w, h);
1129 prefs_set_int_attribute("desktop.geometry", "width", w);
1130 prefs_set_int_attribute("desktop.geometry", "height", h);
1131 prefs_set_int_attribute("desktop.geometry", "x", x);
1132 prefs_set_int_attribute("desktop.geometry", "y", y);
1133 }
1134 gtk_window_maximize(topw);
1135 }
1136 }
1137 }
1139 void
1140 sp_desktop_widget_fullscreen(SPDesktopWidget *dtw)
1141 {
1142 #ifdef HAVE_GTK_WINDOW_FULLSCREEN
1143 GtkWindow *topw = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(dtw->canvas)));
1144 if (GTK_IS_WINDOW(topw)) {
1145 if (dtw->desktop->is_fullscreen()) {
1146 gtk_window_unfullscreen(topw);
1147 // widget layout is triggered by the resulting window_state_event
1148 } else {
1149 // Save geometry to prefs before maximizing so that
1150 // something useful is stored there, because GTK doesn't maintain
1151 // a separate non-maximized size.
1152 if (!dtw->desktop->is_iconified() && !dtw->desktop->is_maximized())
1153 {
1154 gint w, h, x, y;
1155 dtw->getWindowGeometry(x, y, w, h);
1156 prefs_set_int_attribute("desktop.geometry", "width", w);
1157 prefs_set_int_attribute("desktop.geometry", "height", h);
1158 prefs_set_int_attribute("desktop.geometry", "x", x);
1159 prefs_set_int_attribute("desktop.geometry", "y", y);
1160 }
1161 gtk_window_fullscreen(topw);
1162 // widget layout is triggered by the resulting window_state_event
1163 }
1164 }
1165 #endif /* HAVE_GTK_WINDOW_FULLSCREEN */
1166 }
1168 /**
1169 * Hide whatever the user does not want to see in the window
1170 */
1171 void
1172 sp_desktop_widget_layout (SPDesktopWidget *dtw)
1173 {
1174 bool fullscreen = dtw->desktop->is_fullscreen();
1176 if (prefs_get_int_attribute (fullscreen ? "fullscreen.menu" : "window.menu", "state", 1) == 0) {
1177 gtk_widget_hide_all (dtw->menubar);
1178 } else {
1179 gtk_widget_show_all (dtw->menubar);
1180 }
1182 if (prefs_get_int_attribute (fullscreen ? "fullscreen.commands" : "window.commands", "state", 1) == 0) {
1183 gtk_widget_hide_all (dtw->commands_toolbox);
1184 } else {
1185 gtk_widget_show_all (dtw->commands_toolbox);
1186 }
1188 if (prefs_get_int_attribute (fullscreen ? "fullscreen.toppanel" : "window.toppanel", "state", 1) == 0) {
1189 gtk_widget_hide_all (dtw->aux_toolbox);
1190 } else {
1191 // we cannot just show_all because that will show all tools' panels;
1192 // this is a function from toolbox.cpp that shows only the current tool's panel
1193 show_aux_toolbox (dtw->aux_toolbox);
1194 }
1196 if (prefs_get_int_attribute (fullscreen ? "fullscreen.toolbox" : "window.toolbox", "state", 1) == 0) {
1197 gtk_widget_hide_all (dtw->tool_toolbox);
1198 } else {
1199 gtk_widget_show_all (dtw->tool_toolbox);
1200 }
1202 if (prefs_get_int_attribute (fullscreen ? "fullscreen.statusbar" : "window.statusbar", "state", 1) == 0) {
1203 gtk_widget_hide_all (dtw->statusbar);
1204 } else {
1205 gtk_widget_show_all (dtw->statusbar);
1206 }
1208 if (prefs_get_int_attribute (fullscreen ? "fullscreen.panels" : "window.panels", "state", 1) == 0) {
1209 gtk_widget_hide_all( dtw->panels );
1210 } else {
1211 gtk_widget_show_all( dtw->panels );
1212 }
1214 if (prefs_get_int_attribute (fullscreen ? "fullscreen.scrollbars" : "window.scrollbars", "state", 1) == 0) {
1215 gtk_widget_hide_all (dtw->hscrollbar);
1216 gtk_widget_hide_all (dtw->vscrollbar_box);
1217 gtk_widget_hide_all( dtw->cms_adjust );
1218 } else {
1219 gtk_widget_show_all (dtw->hscrollbar);
1220 gtk_widget_show_all (dtw->vscrollbar_box);
1221 gtk_widget_show_all( dtw->cms_adjust );
1222 }
1224 if (prefs_get_int_attribute (fullscreen ? "fullscreen.rulers" : "window.rulers", "state", 1) == 0) {
1225 gtk_widget_hide_all (dtw->hruler);
1226 gtk_widget_hide_all (dtw->vruler);
1227 } else {
1228 gtk_widget_show_all (dtw->hruler);
1229 gtk_widget_show_all (dtw->vruler);
1230 }
1231 }
1233 void
1234 SPDesktopWidget::setToolboxFocusTo (const gchar* label)
1235 {
1236 gpointer hb = sp_search_by_data_recursive(aux_toolbox, (gpointer) label);
1237 if (hb && GTK_IS_WIDGET(hb))
1238 {
1239 gtk_widget_grab_focus(GTK_WIDGET(hb));
1240 }
1241 }
1243 void
1244 SPDesktopWidget::setToolboxAdjustmentValue (gchar const *id, double value)
1245 {
1246 gpointer hb = sp_search_by_data_recursive (aux_toolbox, (gpointer) id);
1247 if (hb && GTK_IS_WIDGET(hb) && GTK_IS_SPIN_BUTTON(hb)) {
1248 GtkAdjustment *a = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON(hb));
1249 gtk_adjustment_set_value (a, value);
1250 }
1251 }
1253 void
1254 SPDesktopWidget::setToolboxSelectOneValue (gchar const *id, int value)
1255 {
1256 gpointer hb = sp_search_by_data_recursive(aux_toolbox, (gpointer) id);
1257 if (hb) {
1258 ege_select_one_action_set_active((EgeSelectOneAction*) hb, value);
1259 }
1260 }
1263 bool
1264 SPDesktopWidget::isToolboxButtonActive (const gchar* id)
1265 {
1266 bool isActive = false;
1267 gpointer thing = sp_search_by_data_recursive(aux_toolbox, (gpointer) id);
1268 if ( !thing ) {
1269 //g_message( "Unable to locate item for {%s}", id );
1270 } else if ( GTK_IS_TOGGLE_BUTTON(thing) ) {
1271 GtkToggleButton *b = GTK_TOGGLE_BUTTON(thing);
1272 isActive = gtk_toggle_button_get_active( b ) != 0;
1273 } else if ( GTK_IS_TOGGLE_ACTION(thing) ) {
1274 GtkToggleAction* act = GTK_TOGGLE_ACTION(thing);
1275 isActive = gtk_toggle_action_get_active( act ) != 0;
1276 } else {
1277 //g_message( "Item for {%s} is of an unsupported type", id );
1278 }
1280 return isActive;
1281 }
1283 SPViewWidget *
1284 sp_desktop_widget_new (SPNamedView *namedview)
1285 {
1286 SPDesktopWidget *dtw = (SPDesktopWidget*)gtk_type_new (SP_TYPE_DESKTOP_WIDGET);
1288 dtw->dt2r = 1.0 / namedview->doc_units->unittobase;
1290 dtw->ruler_origin = NR::Point(0,0); //namedview->gridorigin; Why was the grid origin used here?
1292 dtw->desktop = new SPDesktop();
1293 dtw->stub = new SPDesktopWidget::WidgetStub (dtw);
1294 dtw->desktop->registerEditWidget (dtw->stub);
1295 dtw->desktop->init (namedview, dtw->canvas);
1296 inkscape_add_desktop (dtw->desktop);
1298 // Add the shape geometry to libavoid for autorouting connectors.
1299 // This needs desktop set for its spacing preferences.
1300 init_avoided_shape_geometry(dtw->desktop);
1302 dtw->selected_style->setDesktop(dtw->desktop);
1304 /* Once desktop is set, we can update rulers */
1305 sp_desktop_widget_update_rulers (dtw);
1307 sp_view_widget_set_view (SP_VIEW_WIDGET (dtw), dtw->desktop);
1309 /* Listen on namedview modification */
1310 dtw->modified_connection = namedview->connectModified(sigc::bind<2>(sigc::ptr_fun(&sp_desktop_widget_namedview_modified), dtw));
1312 dtw->layer_selector->setDesktop(dtw->desktop);
1314 dtw->menubar = sp_ui_main_menubar (dtw->desktop);
1315 gtk_widget_show_all (dtw->menubar);
1316 gtk_box_pack_start (GTK_BOX (dtw->vbox), dtw->menubar, FALSE, FALSE, 0);
1318 sp_desktop_widget_layout (dtw);
1320 sp_tool_toolbox_set_desktop (dtw->tool_toolbox, dtw->desktop);
1321 sp_aux_toolbox_set_desktop (dtw->aux_toolbox, dtw->desktop);
1322 sp_commands_toolbox_set_desktop (dtw->commands_toolbox, dtw->desktop);
1324 return SP_VIEW_WIDGET (dtw);
1325 }
1327 void
1328 SPDesktopWidget::viewSetPosition (NR::Point p)
1329 {
1330 NR::Point const origin = ( p - ruler_origin );
1332 /// \todo fixme:
1333 GTK_RULER(hruler)->position = origin[NR::X];
1334 gtk_ruler_draw_pos (GTK_RULER (hruler));
1335 GTK_RULER(vruler)->position = origin[NR::Y];
1336 gtk_ruler_draw_pos (GTK_RULER (vruler));
1337 }
1339 void
1340 sp_desktop_widget_update_rulers (SPDesktopWidget *dtw)
1341 {
1342 NR::Rect const viewbox = dtw->canvas->getViewbox();
1343 double const scale = dtw->desktop->current_zoom();
1344 double s = viewbox.min()[NR::X] / scale - dtw->ruler_origin[NR::X];
1345 double e = viewbox.max()[NR::X] / scale - dtw->ruler_origin[NR::X];
1346 gtk_ruler_set_range(GTK_RULER(dtw->hruler), s, e, GTK_RULER(dtw->hruler)->position, (e - s));
1347 s = viewbox.min()[NR::Y] / -scale - dtw->ruler_origin[NR::Y];
1348 e = viewbox.max()[NR::Y] / -scale - dtw->ruler_origin[NR::Y];
1349 gtk_ruler_set_range(GTK_RULER(dtw->vruler), s, e, GTK_RULER(dtw->vruler)->position, (e - s));
1350 }
1353 static void
1354 sp_desktop_widget_namedview_modified (SPObject *obj, guint flags, SPDesktopWidget *dtw)
1355 {
1356 SPNamedView *nv=SP_NAMEDVIEW(obj);
1357 if (flags & SP_OBJECT_MODIFIED_FLAG) {
1358 dtw->dt2r = 1.0 / nv->doc_units->unittobase;
1359 dtw->ruler_origin = NR::Point(0,0); //nv->gridorigin; Why was the grid origin used here?
1361 sp_ruler_set_metric (GTK_RULER (dtw->vruler), nv->getDefaultMetric());
1362 sp_ruler_set_metric (GTK_RULER (dtw->hruler), nv->getDefaultMetric());
1364 gtk_tooltips_set_tip (dtw->tt, dtw->hruler_box, gettext(sp_unit_get_plural (nv->doc_units)), NULL);
1365 gtk_tooltips_set_tip (dtw->tt, dtw->vruler_box, gettext(sp_unit_get_plural (nv->doc_units)), NULL);
1367 sp_desktop_widget_update_rulers (dtw);
1368 }
1369 }
1371 static void
1372 sp_desktop_widget_adjustment_value_changed (GtkAdjustment */*adj*/, SPDesktopWidget *dtw)
1373 {
1374 if (dtw->update)
1375 return;
1377 dtw->update = 1;
1379 sp_canvas_scroll_to (dtw->canvas, dtw->hadj->value, dtw->vadj->value, FALSE);
1380 sp_desktop_widget_update_rulers (dtw);
1382 dtw->update = 0;
1383 }
1385 /* we make the desktop window with focus active, signal is connected in interface.c */
1386 bool SPDesktopWidget::onFocusInEvent(GdkEventFocus*)
1387 {
1388 inkscape_activate_desktop (desktop);
1390 return false;
1391 }
1393 static gdouble
1394 sp_dtw_zoom_value_to_display (gdouble value)
1395 {
1396 return floor (10 * (pow (2, value) * 100.0 + 0.05)) / 10;
1397 }
1399 static gdouble
1400 sp_dtw_zoom_display_to_value (gdouble value)
1401 {
1402 return log (value / 100.0) / log (2);
1403 }
1405 static gint
1406 sp_dtw_zoom_input (GtkSpinButton *spin, gdouble *new_val, gpointer /*data*/)
1407 {
1408 gdouble new_scrolled = gtk_spin_button_get_value (spin);
1409 const gchar *b = gtk_entry_get_text (GTK_ENTRY (spin));
1410 gdouble new_typed = atof (b);
1412 if (sp_dtw_zoom_value_to_display (new_scrolled) == new_typed) { // the new value is set by scrolling
1413 *new_val = new_scrolled;
1414 } else { // the new value is typed in
1415 *new_val = sp_dtw_zoom_display_to_value (new_typed);
1416 }
1418 return TRUE;
1419 }
1421 static bool
1422 sp_dtw_zoom_output (GtkSpinButton *spin, gpointer /*data*/)
1423 {
1424 gchar b[64];
1425 double val = sp_dtw_zoom_value_to_display (gtk_spin_button_get_value (spin));
1426 if (val < 10) {
1427 g_snprintf (b, 64, "%4.1f%%", val);
1428 } else {
1429 g_snprintf (b, 64, "%4.0f%%", val);
1430 }
1431 gtk_entry_set_text (GTK_ENTRY (spin), b);
1432 return TRUE;
1433 }
1435 static void
1436 sp_dtw_zoom_value_changed (GtkSpinButton *spin, gpointer data)
1437 {
1438 double const zoom_factor = pow (2, gtk_spin_button_get_value (spin));
1440 SPDesktopWidget *dtw = SP_DESKTOP_WIDGET (data);
1441 SPDesktop *desktop = dtw->desktop;
1443 NR::Rect const d = desktop->get_display_area();
1444 g_signal_handler_block (spin, dtw->zoom_update);
1445 desktop->zoom_absolute (d.midpoint()[NR::X], d.midpoint()[NR::Y], zoom_factor);
1446 g_signal_handler_unblock (spin, dtw->zoom_update);
1448 spinbutton_defocus (GTK_OBJECT (spin));
1449 }
1451 static void
1452 sp_dtw_zoom_populate_popup (GtkEntry */*entry*/, GtkMenu *menu, gpointer data)
1453 {
1454 GList *children, *iter;
1455 GtkWidget *item;
1456 SPDesktop *dt = SP_DESKTOP_WIDGET (data)->desktop;
1458 children = gtk_container_get_children (GTK_CONTAINER (menu));
1459 for ( iter = children ; iter ; iter = g_list_next (iter)) {
1460 gtk_container_remove (GTK_CONTAINER (menu), GTK_WIDGET (iter->data));
1461 }
1462 g_list_free (children);
1464 item = gtk_menu_item_new_with_label ("200%");
1465 g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (sp_dtw_zoom_200), dt);
1466 gtk_widget_show (item);
1467 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1468 item = gtk_menu_item_new_with_label ("100%");
1469 g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (sp_dtw_zoom_100), dt);
1470 gtk_widget_show (item);
1471 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1472 item = gtk_menu_item_new_with_label ("50%");
1473 g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (sp_dtw_zoom_50), dt);
1474 gtk_widget_show (item);
1475 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1477 item = gtk_separator_menu_item_new ();
1478 gtk_widget_show (item);
1479 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1481 item = gtk_menu_item_new_with_label (_("Page"));
1482 g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (sp_dtw_zoom_page), dt);
1483 gtk_widget_show (item);
1484 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1485 item = gtk_menu_item_new_with_label (_("Drawing"));
1486 g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (sp_dtw_zoom_drawing), dt);
1487 gtk_widget_show (item);
1488 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1489 item = gtk_menu_item_new_with_label (_("Selection"));
1490 g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (sp_dtw_zoom_selection), dt);
1491 gtk_widget_show (item);
1492 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1493 }
1495 static void
1496 sp_dtw_zoom_menu_handler (SPDesktop *dt, gdouble factor)
1497 {
1498 NR::Rect const d = dt->get_display_area();
1499 dt->zoom_absolute(d.midpoint()[NR::X], d.midpoint()[NR::Y], factor);
1500 }
1502 static void
1503 sp_dtw_zoom_50 (GtkMenuItem */*item*/, gpointer data)
1504 {
1505 sp_dtw_zoom_menu_handler (static_cast<SPDesktop*>(data), 0.5);
1506 }
1508 static void
1509 sp_dtw_zoom_100 (GtkMenuItem */*item*/, gpointer data)
1510 {
1511 sp_dtw_zoom_menu_handler (static_cast<SPDesktop*>(data), 1.0);
1512 }
1514 static void
1515 sp_dtw_zoom_200 (GtkMenuItem */*item*/, gpointer data)
1516 {
1517 sp_dtw_zoom_menu_handler (static_cast<SPDesktop*>(data), 2.0);
1518 }
1520 static void
1521 sp_dtw_zoom_page (GtkMenuItem */*item*/, gpointer data)
1522 {
1523 static_cast<SPDesktop*>(data)->zoom_page();
1524 }
1526 static void
1527 sp_dtw_zoom_drawing (GtkMenuItem */*item*/, gpointer data)
1528 {
1529 static_cast<SPDesktop*>(data)->zoom_drawing();
1530 }
1532 static void
1533 sp_dtw_zoom_selection (GtkMenuItem */*item*/, gpointer data)
1534 {
1535 static_cast<SPDesktop*>(data)->zoom_selection();
1536 }
1540 void
1541 sp_desktop_widget_update_zoom (SPDesktopWidget *dtw)
1542 {
1543 g_signal_handlers_block_by_func (G_OBJECT (dtw->zoom_status), (gpointer)G_CALLBACK (sp_dtw_zoom_value_changed), dtw);
1544 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dtw->zoom_status), log(dtw->desktop->current_zoom()) / log(2));
1545 gtk_widget_queue_draw(GTK_WIDGET(dtw->zoom_status));
1546 if (GTK_WIDGET(dtw->zoom_status)->window)
1547 gdk_window_process_updates(GTK_WIDGET(dtw->zoom_status)->window, TRUE);
1548 g_signal_handlers_unblock_by_func (G_OBJECT (dtw->zoom_status), (gpointer)G_CALLBACK (sp_dtw_zoom_value_changed), dtw);
1549 }
1551 void
1552 sp_desktop_widget_toggle_rulers (SPDesktopWidget *dtw)
1553 {
1554 if (GTK_WIDGET_VISIBLE (dtw->hruler)) {
1555 gtk_widget_hide_all (dtw->hruler);
1556 gtk_widget_hide_all (dtw->vruler);
1557 prefs_set_int_attribute (dtw->desktop->is_fullscreen() ? "fullscreen.rulers" : "window.rulers", "state", 0);
1558 } else {
1559 gtk_widget_show_all (dtw->hruler);
1560 gtk_widget_show_all (dtw->vruler);
1561 prefs_set_int_attribute (dtw->desktop->is_fullscreen() ? "fullscreen.rulers" : "window.rulers", "state", 1);
1562 }
1563 }
1565 void
1566 sp_desktop_widget_toggle_scrollbars (SPDesktopWidget *dtw)
1567 {
1568 if (GTK_WIDGET_VISIBLE (dtw->hscrollbar)) {
1569 gtk_widget_hide_all (dtw->hscrollbar);
1570 gtk_widget_hide_all (dtw->vscrollbar_box);
1571 gtk_widget_hide_all( dtw->cms_adjust );
1572 prefs_set_int_attribute (dtw->desktop->is_fullscreen() ? "fullscreen.scrollbars" : "window.scrollbars", "state", 0);
1573 } else {
1574 gtk_widget_show_all (dtw->hscrollbar);
1575 gtk_widget_show_all (dtw->vscrollbar_box);
1576 gtk_widget_show_all( dtw->cms_adjust );
1577 prefs_set_int_attribute (dtw->desktop->is_fullscreen() ? "fullscreen.scrollbars" : "window.scrollbars", "state", 1);
1578 }
1579 }
1581 void sp_desktop_widget_toggle_color_prof_adj( SPDesktopWidget *dtw )
1582 {
1584 if ( GTK_WIDGET_SENSITIVE( dtw->cms_adjust ) ) {
1585 if ( SP_BUTTON_IS_DOWN(dtw->cms_adjust) ) {
1586 sp_button_toggle_set_down( SP_BUTTON(dtw->cms_adjust), FALSE );
1587 } else {
1588 sp_button_toggle_set_down( SP_BUTTON(dtw->cms_adjust), TRUE );
1589 }
1590 }
1591 }
1593 /* Unused
1594 void
1595 sp_spw_toggle_menubar (SPDesktopWidget *dtw, bool is_fullscreen)
1596 {
1597 if (GTK_WIDGET_VISIBLE (dtw->menubar)) {
1598 gtk_widget_hide_all (dtw->menubar);
1599 prefs_set_int_attribute (is_fullscreen ? "fullscreen.menu" : "window.menu", "state", 0);
1600 } else {
1601 gtk_widget_show_all (dtw->menubar);
1602 prefs_set_int_attribute (is_fullscreen ? "fullscreen.menu" : "window.menu", "state", 1);
1603 }
1604 }
1605 */
1607 static void
1608 set_adjustment (GtkAdjustment *adj, double l, double u, double ps, double si, double pi)
1609 {
1610 if ((l != adj->lower) ||
1611 (u != adj->upper) ||
1612 (ps != adj->page_size) ||
1613 (si != adj->step_increment) ||
1614 (pi != adj->page_increment)) {
1615 adj->lower = l;
1616 adj->upper = u;
1617 adj->page_size = ps;
1618 adj->step_increment = si;
1619 adj->page_increment = pi;
1620 gtk_adjustment_changed (adj);
1621 }
1622 }
1624 void
1625 sp_desktop_widget_update_scrollbars (SPDesktopWidget *dtw, double scale)
1626 {
1627 if (!dtw) return;
1628 if (dtw->update) return;
1629 dtw->update = 1;
1631 /* The desktop region we always show unconditionally */
1632 SPDocument *doc = dtw->desktop->doc();
1633 NR::Rect darea(NR::Point(-sp_document_width(doc), -sp_document_height(doc)),
1634 NR::Point(2 * sp_document_width(doc), 2 * sp_document_height(doc)));
1635 darea = NR::union_bounds(darea, sp_item_bbox_desktop(SP_ITEM(SP_DOCUMENT_ROOT(doc))));
1637 /* Canvas region we always show unconditionally */
1638 NR::Rect carea(NR::Point(darea.min()[NR::X] * scale - 64,
1639 darea.max()[NR::Y] * -scale - 64),
1640 NR::Point(darea.max()[NR::X] * scale + 64,
1641 darea.min()[NR::Y] * -scale + 64));
1643 NR::Rect viewbox = dtw->canvas->getViewbox();
1645 /* Viewbox is always included into scrollable region */
1646 carea = NR::union_bounds(carea, viewbox);
1648 set_adjustment(dtw->hadj, carea.min()[NR::X], carea.max()[NR::X],
1649 viewbox.dimensions()[NR::X],
1650 0.1 * viewbox.dimensions()[NR::X],
1651 viewbox.dimensions()[NR::X]);
1652 gtk_adjustment_set_value(dtw->hadj, viewbox.min()[NR::X]);
1654 set_adjustment(dtw->vadj, carea.min()[NR::Y], carea.max()[NR::Y],
1655 viewbox.dimensions()[NR::Y],
1656 0.1 * viewbox.dimensions()[NR::Y],
1657 viewbox.dimensions()[NR::Y]);
1658 gtk_adjustment_set_value(dtw->vadj, viewbox.min()[NR::Y]);
1660 dtw->update = 0;
1661 }
1664 /*
1665 Local Variables:
1666 mode:c++
1667 c-file-style:"stroustrup"
1668 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
1669 indent-tabs-mode:nil
1670 fill-column:99
1671 End:
1672 */
1673 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :