Logo Search packages:      
Sourcecode: inkscape version File versions

static gint sp_event_context_private_root_handler ( SPEventContext event_context,
GdkEvent *  event 
) [static]

Main event dispatch, gets called from Gdk.

Definition at line 314 of file event-context.cpp.

References accelerate_scroll(), SPDesktop::acetate, SPEventContext::desktop, get_group0_keyval(), gobble_key_events(), gobble_motion_events(), SPDesktop::point(), SPDesktop::scroll_world(), SPDesktop::set_display_area(), sp_canvas_item_grab(), sp_canvas_item_ungrab(), sp_event_root_menu_popup(), sp_toggle_selector(), SPDesktop::updateNow(), SPDesktop::w2d(), SPDesktop::zoom_grab_focus(), and SPDesktop::zoom_relative_keep_point().

Referenced by sp_event_context_class_init().

{
    static NR::Point button_w;
    static unsigned int panning = 0;
    static unsigned int zoom_rb = 0;

    SPDesktop *desktop = event_context->desktop;

    tolerance = prefs_get_int_attribute_limited(
            "options.dragtolerance","value", 0, 0, 100);
    double const zoom_inc = prefs_get_double_attribute_limited(
            "options.zoomincrement", "value", M_SQRT2, 1.01, 10);
    double const acceleration = prefs_get_double_attribute_limited(
            "options.scrollingacceleration", "value", 0, 0, 6);
    int const key_scroll = prefs_get_int_attribute_limited(
            "options.keyscroll", "value", 10, 0, 1000);
    int const wheel_scroll = prefs_get_int_attribute_limited(
            "options.wheelscroll", "value", 40, 0, 1000);

    gint ret = FALSE;

    switch (event->type) {
        case GDK_2BUTTON_PRESS:
            if (panning) {
                panning = 0;
                sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
                        event->button.time);
                ret = TRUE;
            } else {
                /* sp_desktop_dialog(); */
            }
            break;
        case GDK_BUTTON_PRESS:

            // save drag origin
            xp = (gint) event->button.x;
            yp = (gint) event->button.y;
            within_tolerance = true;

            switch (event->button.button) {
                case 2:

                    if (dontgrab)
                        // double-click, still not permitted to grab;
                        // increase the counter to guard against triple click
                    {
                        dontgrab ++;
                        gtk_timeout_add(250, (GtkFunction) grab_allow_again, NULL);
                        break;
                    }

                    button_w = NR::Point(event->button.x,
                                         event->button.y);
                    if (event->button.state == GDK_SHIFT_MASK) {
                        zoom_rb = 2;
                    } else {
                        panning = 2;
                        sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
                            GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
                            NULL, event->button.time-1);
                    }
                    ret = TRUE;
                    break;
                case 3:
                    if (event->button.state & GDK_SHIFT_MASK
                            || event->button.state & GDK_CONTROL_MASK) {
                        button_w = NR::Point(event->button.x,
                                             event->button.y);
                        panning = 3;
                        sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
                                GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
                                NULL, event->button.time);
                        ret = TRUE;
                    } else {
                        sp_event_root_menu_popup(desktop, NULL, event);
                    }
                    break;
                default:
                    break;
            }
            break;
        case GDK_MOTION_NOTIFY:
            if (panning) {
                if ((panning == 2 && !(event->motion.state & GDK_BUTTON2_MASK))
                        || (panning == 3 && !(event->motion.state & GDK_BUTTON3_MASK))) {
                    /* Gdk seems to lose button release for us sometimes :-( */
                    panning = 0;
                    dontgrab = 0;
                    sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
                            event->button.time);
                    ret = TRUE;
                } else {
                    if ( within_tolerance
                         && ( abs( (gint) event->motion.x - xp ) < tolerance )
                         && ( abs( (gint) event->motion.y - yp ) < tolerance ))
                    {
                        // do not drag if we're within tolerance from origin
                        break;
                    }
                    // Once the user has moved farther than tolerance from
                    // the original location (indicating they intend to move
                    // the object, not click), then always process the motion
                    // notify coordinates as given (no snapping back to origin)
                    within_tolerance = false;

                    // gobble subsequent motion events to prevent "sticking"
                    // when scrolling is slow
                    gobble_motion_events(panning == 2 ?
                            GDK_BUTTON2_MASK : GDK_BUTTON3_MASK);

                    NR::Point const motion_w(event->motion.x,
                                             event->motion.y);
                    NR::Point const moved_w( motion_w - button_w );
                    event_context->desktop->scroll_world(moved_w);
                    ret = TRUE;
                }
            } else if (zoom_rb) {
                NR::Point const motion_w(event->motion.x, event->motion.y);
                NR::Point const motion_dt(desktop->w2d(motion_w));

                if ( within_tolerance
                     && ( abs( (gint) event->motion.x - xp ) < tolerance )
                     && ( abs( (gint) event->motion.y - yp ) < tolerance ) ) {
                    break; // do not drag if we're within tolerance from origin
                }

                if (within_tolerance) {
                    Inkscape::Rubberband::get()->start(desktop, motion_dt);
                } else {
                    Inkscape::Rubberband::get()->move(motion_dt);
                }

                // Once the user has moved farther than tolerance from the original location
                // (indicating they intend to move the object, not click), then always process the
                // motion notify coordinates as given (no snapping back to origin)
                within_tolerance = false;
            }
            break;
        case GDK_BUTTON_RELEASE:
            xp = yp = 0;
            if (within_tolerance && (panning || zoom_rb)) {
                dontgrab ++;
                zoom_rb = 0;
                NR::Point const event_w(event->button.x, event->button.y);
                NR::Point const event_dt(desktop->w2d(event_w));
                double const zoom_power = ( (event->button.state & GDK_SHIFT_MASK)
                                            ? -dontgrab : dontgrab );
                gtk_timeout_add(250, (GtkFunction) grab_allow_again, NULL);
                desktop->zoom_relative_keep_point(event_dt,
                                                  pow(zoom_inc, zoom_power));
                desktop->updateNow();
            }
            if (panning == event->button.button) {
                panning = 0;
                ret = TRUE;
                sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate),
                                      event->button.time);
                desktop->updateNow();
            } else if (zoom_rb == event->button.button) {
                zoom_rb = 0;
                NR::Maybe<NR::Rect> const b = Inkscape::Rubberband::get()->getRectangle();
                Inkscape::Rubberband::get()->stop();
                if (b != NR::Nothing() && !within_tolerance) {
                    desktop->set_display_area(b.assume(), 10);
                }
            }
            break;
        case GDK_KEY_PRESS:
            switch (get_group0_keyval(&event->key)) {
                // GDK insists on stealing these keys (F1 for no idea what, tab for cycling widgets
                // in the editing window). So we resteal them back and run our regular shortcut
                // invoker on them.
                unsigned int shortcut;
                case GDK_Tab: 
                case GDK_ISO_Left_Tab: 
                case GDK_F1:
                    shortcut = get_group0_keyval(&event->key);
                    if (event->key.state & GDK_SHIFT_MASK)
                        shortcut |= SP_SHORTCUT_SHIFT_MASK;
                    if (event->key.state & GDK_CONTROL_MASK)
                        shortcut |= SP_SHORTCUT_CONTROL_MASK;
                    if (event->key.state & GDK_MOD1_MASK)
                        shortcut |= SP_SHORTCUT_ALT_MASK;
                    ret = sp_shortcut_invoke(shortcut, desktop);
                    break;

                case GDK_W:
                case GDK_w:
                case GDK_F4:
                    /* Close view */
                    if (MOD__CTRL_ONLY) {
                        sp_ui_close_view(NULL);
                        ret = TRUE;
                    }
                    break;
                case GDK_Left: // Ctrl Left
                case GDK_KP_Left:
                case GDK_KP_4:
                    if (MOD__CTRL_ONLY) {
                        int i = (int) floor(key_scroll * accelerate_scroll(event, acceleration));
                        gobble_key_events(get_group0_keyval(&event->key),
                                GDK_CONTROL_MASK);
                        event_context->desktop->scroll_world(i, 0);
                        ret = TRUE;
                    }
                    break;
                case GDK_Up: // Ctrl Up
                case GDK_KP_Up:
                case GDK_KP_8:
                    if (MOD__CTRL_ONLY) {
                        int i = (int) floor(key_scroll * accelerate_scroll(event, acceleration));
                        gobble_key_events(get_group0_keyval(&event->key),
                                GDK_CONTROL_MASK);
                        event_context->desktop->scroll_world(0, i);
                        ret = TRUE;
                    }
                    break;
                case GDK_Right: // Ctrl Right
                case GDK_KP_Right:
                case GDK_KP_6:
                    if (MOD__CTRL_ONLY) {
                        int i = (int) floor(key_scroll * accelerate_scroll(event, acceleration));
                        gobble_key_events(get_group0_keyval(&event->key),
                                GDK_CONTROL_MASK);
                        event_context->desktop->scroll_world(-i, 0);
                        ret = TRUE;
                    }
                    break;
                case GDK_Down: // Ctrl Down
                case GDK_KP_Down:
                case GDK_KP_2:
                    if (MOD__CTRL_ONLY) {
                        int i = (int) floor(key_scroll * accelerate_scroll(event, acceleration));
                        gobble_key_events(get_group0_keyval(&event->key),
                                GDK_CONTROL_MASK);
                        event_context->desktop->scroll_world(0, -i);
                        ret = TRUE;
                    }
                    break;
                case GDK_F10:
                    if (MOD__SHIFT_ONLY) {
                        sp_event_root_menu_popup(desktop, NULL, event);
                        ret= TRUE;
                    }
                    break;
                case GDK_space:
                    sp_toggle_selector(desktop);
                    ret= TRUE;
                    break;
                case GDK_z:
                case GDK_Z:
                    if (MOD__ALT_ONLY) {
                        desktop->zoom_grab_focus();
                        ret = TRUE;
                    }
                    break;
                default:
                    break;
            }
            break;
        case GDK_SCROLL:
            /* shift + wheel, pan left--right */
            if (event->scroll.state & GDK_SHIFT_MASK) {
                switch (event->scroll.direction) {
                    case GDK_SCROLL_UP:
                        desktop->scroll_world(wheel_scroll, 0);
                        break;
                    case GDK_SCROLL_DOWN:
                        desktop->scroll_world(-wheel_scroll, 0);
                        break;
                    default:
                        break;
                }

                /* ctrl + wheel, zoom in--out */
            } else if (event->scroll.state & GDK_CONTROL_MASK) {
                double rel_zoom;
                switch (event->scroll.direction) {
                    case GDK_SCROLL_UP:
                        rel_zoom = zoom_inc;
                        break;
                    case GDK_SCROLL_DOWN:
                        rel_zoom = 1 / zoom_inc;
                        break;
                    default:
                        rel_zoom = 0.0;
                        break;
                }
                if (rel_zoom != 0.0) {
                    NR::Point const scroll_dt = desktop->point();
                    desktop->zoom_relative_keep_point(scroll_dt, rel_zoom);
                }

                /* no modifier, pan up--down (left--right on multiwheel mice?) */
            } else {
                switch (event->scroll.direction) {
                    case GDK_SCROLL_UP:
                        desktop->scroll_world(0, wheel_scroll);
                        break;
                    case GDK_SCROLL_DOWN:
                        desktop->scroll_world(0, -wheel_scroll);
                        break;
                    case GDK_SCROLL_LEFT:
                        desktop->scroll_world(wheel_scroll, 0);
                        break;
                    case GDK_SCROLL_RIGHT:
                        desktop->scroll_world(-wheel_scroll, 0);
                        break;
                }
            }
            break;
        default:
            break;
    }

    return ret;
}


Generated by  Doxygen 1.6.0   Back to index