From 9d3fe73abe568e8df1f992bc6458b28904fbaeb8 Mon Sep 17 00:00:00 2001 From: John Smith Date: Tue, 25 Sep 2012 20:35:04 +0900 Subject: Fix for 172190 : Hand/Pan tool cursor on middle-drag (bzr r11703) --- src/event-context.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/event-context.cpp') diff --git a/src/event-context.cpp b/src/event-context.cpp index 2c9ed1abd..b8a2dc797 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -171,6 +171,27 @@ static void sp_event_context_dispose(GObject *object) { G_OBJECT_CLASS(parent_class)->dispose(object); } +/** + * Set the cursor to a standard GDK cursor + */ +void sp_event_context_set_cursor(SPEventContext *event_context, GdkCursorType cursor_type) { + + GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(event_context->desktop)); + GdkDisplay *display = gdk_display_get_default(); + GdkCursor *cursor = gdk_cursor_new_for_display(display, cursor_type); + +#if WITH_GTKMM_3_0 + if (cursor) { + gdk_window_set_cursor (gtk_widget_get_window (w), cursor); + g_object_unref (cursor); + } +#else + gdk_window_set_cursor (gtk_widget_get_window (w), cursor); + gdk_cursor_unref (cursor); +#endif + +} + /** * Recreates and draws cursor on desktop related to SPEventContext. */ @@ -360,6 +381,7 @@ static gint sp_event_context_private_root_handler( SPEventContext *event_context, GdkEvent *event) { static Geom::Point button_w; static unsigned int panning = 0; + static unsigned int panning_cursor = 0; static unsigned int zoom_rb = 0; SPDesktop *desktop = event_context->desktop; @@ -393,6 +415,7 @@ static gint sp_event_context_private_root_handler( switch (event->button.button) { case 1: if (event_context->space_panning) { + // When starting panning, make sure there are no snap events pending because these might disable the panning again sp_event_context_discard_delayed_snap_event(event_context); panning = 1; @@ -408,6 +431,7 @@ static gint sp_event_context_private_root_handler( if (event->button.state & GDK_SHIFT_MASK) { zoom_rb = 2; } else { + // When starting panning, make sure there are no snap events pending because these might disable the panning again sp_event_context_discard_delayed_snap_event(event_context); panning = 2; @@ -415,6 +439,7 @@ static gint sp_event_context_private_root_handler( GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK, NULL, event->button.time - 1); + } ret = TRUE; break; @@ -466,6 +491,11 @@ static gint sp_event_context_private_root_handler( gobble_motion_events(panning == 2 ? GDK_BUTTON2_MASK : (panning == 1 ? GDK_BUTTON1_MASK : GDK_BUTTON3_MASK)); + if (panning_cursor == 0) { + panning_cursor = 1; + sp_event_context_set_cursor(event_context, GDK_FLEUR); + } + Geom::Point const motion_w(event->motion.x, event->motion.y); Geom::Point const moved_w(motion_w - button_w); event_context->desktop->scroll_world(moved_w, true); // we're still scrolling, do not redraw @@ -496,6 +526,11 @@ static gint sp_event_context_private_root_handler( break; case GDK_BUTTON_RELEASE: xp = yp = 0; + if (panning_cursor == 1) { + panning_cursor = 0; + GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(event_context->desktop)); + gdk_window_set_cursor(gtk_widget_get_window (w), event_context->cursor); + } if (within_tolerance && (panning || zoom_rb)) { zoom_rb = 0; if (panning) { @@ -665,6 +700,7 @@ static gint sp_event_context_private_root_handler( if (event_context->space_panning) { event_context->space_panning = false; event_context->_message_context->clear(); + if (panning == 1) { panning = 0; sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), -- cgit v1.2.3 From 370a3f5cc9e39352a081e5d5dd8c43676547a6e6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 4 Oct 2012 11:45:44 +1000 Subject: code cleanup: add own includes to cpp files or make the functions static if they are not used elsewhere. (bzr r11735) --- src/event-context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/event-context.cpp') diff --git a/src/event-context.cpp b/src/event-context.cpp index b8a2dc797..6f89e862e 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -174,7 +174,7 @@ static void sp_event_context_dispose(GObject *object) { /** * Set the cursor to a standard GDK cursor */ -void sp_event_context_set_cursor(SPEventContext *event_context, GdkCursorType cursor_type) { +static void sp_event_context_set_cursor(SPEventContext *event_context, GdkCursorType cursor_type) { GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(event_context->desktop)); GdkDisplay *display = gdk_display_get_default(); -- cgit v1.2.3 From f8a5b66bb57495c83274218dc98530a071b10f27 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sun, 11 Nov 2012 11:20:05 +0000 Subject: cppcheck: Convert more C-style pointer casts to GObject or C++ (bzr r11867) --- src/event-context.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/event-context.cpp') diff --git a/src/event-context.cpp b/src/event-context.cpp index 6f89e862e..e9d0aa935 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -845,8 +845,8 @@ public: Inkscape::Preferences::Observer(path), _ec(ec) { } virtual void notify(Inkscape::Preferences::Entry const &val) { - if (((SPEventContextClass *) G_OBJECT_GET_CLASS(_ec))->set) { - ((SPEventContextClass *) G_OBJECT_GET_CLASS(_ec))->set(_ec, + if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(_ec)))->set) { + (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(_ec)))->set(_ec, const_cast (&val)); } } @@ -879,8 +879,8 @@ sp_event_context_new(GType type, SPDesktop *desktop, gchar const *pref_path, prefs->addObserver(*(ec->pref_observer)); } - if (((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->setup) - ((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->setup(ec); + if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->setup) + (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->setup(ec); return ec; } @@ -898,8 +898,8 @@ void sp_event_context_finish(SPEventContext *ec) { g_warning("Finishing event context with active link\n"); } - if (((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->finish) - ((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->finish(ec); + if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish) + (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish(ec); } //-------------------------------member functions @@ -955,11 +955,11 @@ void sp_event_context_read(SPEventContext *ec, gchar const *key) { g_return_if_fail(SP_IS_EVENT_CONTEXT(ec)); g_return_if_fail(key != NULL); - if (((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->set) { + if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->set) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Inkscape::Preferences::Entry val = prefs->getEntry( ec->pref_observer->observed_path + '/' + key); - ((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->set(ec, &val); + (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->set(ec, &val); } } @@ -975,8 +975,8 @@ void sp_event_context_activate(SPEventContext *ec) { // context should take care of this by itself. sp_event_context_discard_delayed_snap_event(ec); - if (((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->activate) - ((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->activate(ec); + if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->activate) + (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->activate(ec); } /** @@ -986,8 +986,8 @@ void sp_event_context_deactivate(SPEventContext *ec) { g_return_if_fail(ec != NULL); g_return_if_fail(SP_IS_EVENT_CONTEXT(ec)); - if (((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->deactivate) - ((SPEventContextClass *) G_OBJECT_GET_CLASS(ec))->deactivate(ec); + if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->deactivate) + (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->deactivate(ec); } /** @@ -1028,7 +1028,7 @@ gint sp_event_context_virtual_root_handler(SPEventContext * event_context, GdkEv gint ret = false; if (event_context) { // If no event-context is available then do nothing, otherwise Inkscape would crash // (see the comment in SPDesktop::set_event_context, and bug LP #622350) - ret = ((SPEventContextClass *) G_OBJECT_GET_CLASS(event_context))->root_handler(event_context, event); + ret = (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(event_context)))->root_handler(event_context, event); set_event_location(event_context->desktop, event); } return ret; @@ -1067,7 +1067,7 @@ gint sp_event_context_virtual_item_handler(SPEventContext * event_context, SPIte gint ret = false; if (event_context) { // If no event-context is available then do nothing, otherwise Inkscape would crash // (see the comment in SPDesktop::set_event_context, and bug LP #622350) - ret = ((SPEventContextClass *) G_OBJECT_GET_CLASS(event_context))->item_handler(event_context, item, event); + ret = (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(event_context)))->item_handler(event_context, item, event); if (!ret) { ret = sp_event_context_virtual_root_handler(event_context, event); } else { -- cgit v1.2.3 From cb1f232c390a1e0b96d140c2fdc52b526dc4573f Mon Sep 17 00:00:00 2001 From: John Smith Date: Fri, 14 Dec 2012 12:17:13 +0900 Subject: Fix for 383871 : Let space switch to selector tool even when used for panning (bzr r11954) --- src/event-context.cpp | 70 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 22 deletions(-) (limited to 'src/event-context.cpp') diff --git a/src/event-context.cpp b/src/event-context.cpp index e9d0aa935..3c1609d97 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -464,10 +464,23 @@ static gint sp_event_context_private_root_handler( break; case GDK_MOTION_NOTIFY: if (panning) { + if (panning == 4 && !xp && !yp ) { + // + mouse panning started, save location and grab canvas + xp = event->motion.x; + yp = event->motion.y; + button_w = Geom::Point(event->motion.x, event->motion.y); + + sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), + GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK + | GDK_POINTER_MOTION_MASK + | GDK_POINTER_MOTION_HINT_MASK, NULL, + event->motion.time - 1); + + + } if ((panning == 2 && !(event->motion.state & GDK_BUTTON2_MASK)) - || (panning == 1 && !(event->motion.state - & GDK_BUTTON1_MASK)) || (panning == 3 - && !(event->motion.state & GDK_BUTTON3_MASK))) { + || (panning == 1 && !(event->motion.state & GDK_BUTTON1_MASK)) + || (panning == 3 && !(event->motion.state & GDK_BUTTON3_MASK))) { /* Gdk seems to lose button release for us sometimes :-( */ panning = 0; sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), @@ -570,6 +583,7 @@ static gint sp_event_context_private_root_handler( } ret = TRUE; } + break; case GDK_KEY_PRESS: { double const acceleration = prefs->getDoubleLimited( @@ -672,15 +686,13 @@ static gint sp_event_context_private_root_handler( } break; case GDK_KEY_space: - if (prefs->getBool("/options/spacepans/value")) { - event_context->space_panning = true; - event_context->_message_context->set(Inkscape::INFORMATION_MESSAGE, - _("Space+mouse drag to pan canvas")); - ret = TRUE; - } else { - sp_toggle_selector(desktop); - ret = TRUE; - } + xp = yp = 0; + within_tolerance = true; + panning = 4; + event_context->space_panning = true; + event_context->_message_context->set(Inkscape::INFORMATION_MESSAGE, + _("Space+mouse move to pan canvas")); + ret = TRUE; break; case GDK_KEY_z: case GDK_KEY_Z: @@ -695,18 +707,32 @@ static gint sp_event_context_private_root_handler( } break; case GDK_KEY_RELEASE: + + // Stop panning on any key release + if (event_context->space_panning) { + event_context->space_panning = false; + event_context->_message_context->clear(); + } + + if (panning) { + panning = 0; + xp = yp = 0; + sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), + event->key.time); + desktop->updateNow(); + } + + if (panning_cursor == 1) { + panning_cursor = 0; + GtkWidget *w = GTK_WIDGET(sp_desktop_canvas(event_context->desktop)); + gdk_window_set_cursor(gtk_widget_get_window (w), event_context->cursor); + } + switch (get_group0_keyval(&event->key)) { case GDK_KEY_space: - if (event_context->space_panning) { - event_context->space_panning = false; - event_context->_message_context->clear(); - - if (panning == 1) { - panning = 0; - sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), - event->key.time); - desktop->updateNow(); - } + if (within_tolerance == true) { + // Space was pressed, but not panned + sp_toggle_selector(desktop); ret = TRUE; } break; -- cgit v1.2.3