开发者

Remove scroll ability from GtkSpinButton

I find that GtkSpinButton can be useful for controlled input numbers on GTK GUI. But here are some nice features of GTK button which can开发者_开发问答 be unwanted in many cases. If we have GtkSpinButton inside scrolledwindow then user can accidentally change value, or GtkSpinButton can take scroll behaviour from scrolledwindow.

Question: Is here any possibility to make GtkScrollButton insensible to mouse wheel, at way like is GtkEntry. Or better, could GtkSpinButton be shown without up/down buttons. If not, how to redirect scroll signal from GtkSpinButton to scrolledwindow?

I try this:

SCROLL_numgreen (GtkObject *object, GdkEvent *event, gpointer user_data)
{
switch (((GdkEventScroll *)event)->direction)
{
case GDK_SCROLL_UP:
    return TRUE;
    break;

case GDK_SCROLL_DOWN:
    return TRUE;
    break;

... etc...

but this only "eats" scroll signal from GtkSpinButton and block scrolledwindow at place. I would most like some general solution without intervention to events of every GtkSpinButton.


Here a few pointers to your queries:

Is here any possibility to make GtkScrollButton insensible to mouse wheel, at way like is GtkEntry?
Mouse wheel scroll, mouse click are events. The events can be masked. This can be done at two levels.

  1. At GtkWidget level: you can use gtk_widget_get_events() which will return the event mask in the form of GdkEventMask. You can modify this as per your need & set it using gtk_widget_set_events()
  2. At GdkWindow level: GtkWidget which has its own drawing/eventing area has a GdkWindow associated with it. You can get the event mask of this window using gdk_window_get_events() and change returned GdkEventMask as per your need & set it to the GdkWindow using gdk_window_set_events(). You can modify event mask through bit-wise operations. If GdkWindow is shared between more than one widget then this mask will effect all the widgets. For masking scroll events you can look into GDK_SCROLL_MASK, GDK_BUTTON_PRESS_MASK & GDK_BUTTON_RELEASE_MASK. You can always check the mask for the event which you are looking for is already set or not. Note: GdkWindow related calls will succeed only after GdkWindow is created for GtkWidget. You can make these calls after gtk_widget_show() of the widget or gtk_widget_show_all of the window which contains these widgets.

Or better, could GtkSpinButton be shown without up/down buttons.
AFAIK GtkSpinButton is implemented to have up/down button indicative of the functionality it provides. If you don't want this, then you can choose another widget say GtkEntry (from which GtkSpinButton is "derived") or GtkLabel. Of course you can create your own widget (from scratch or "derive" from an existing GtkWidget) as per your need & use that same; there is no one stopping you from doing this :)

How to redirect scroll signal from GtkSpinButton to scrolledwindow?
It is possible to do this in the "scroll-event" callback of GtkSpinButton. You can stop the emission of the signal on GtkSpinButton & return FALSE to propagate the event.

...
/* Event callback */
gboolean spinbutton_scroll_handler(GtkWidget *widget, GdkEvent  *event,  gpointer   user_data)
{
    /* Stop emission on current widget. Default handler also not called */
    /* Refer http://developer.gnome.org/gobject/stable/gobject-Signals.html#g-signal-stop-emission-by-name */
    g_signal_stop_emission_by_name(widget, "scroll-event");
    /* Return FALSE to propagate the event further; thus scroll window will scroll
       If TRUE returned other handlers not invoked for this event, 
       thus no scroll on scroll window  */
    return FALSE;
}
...
/* Connect scroll-event to the callback */
g_signal_connect(spinbutton, "scroll-event", 
                 G_CALLBACK(spinbutton_scroll_handler),
                 (gpointer)0);
...

Hope this helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜