Re: GtkNotebook Sloppy Focus

> Date: Thu, 4 Oct 2001 02:35:04 -0400
> From: butter <butter grendel phateds nu>
> To: gtk-list gnome org
> Subject: GtkNotebook Sloppy Focus
> How can sloppy focus be applied to GtkNotebook bookmark tabs?  This does
> not appear to be a library function as far as I can tell. I ask this
> because often a notebook widget with many tabs requires much clicking to
> view all of the pages, when simply moving the cursor over the tab would
> suffice. Thank you.

I think that one way to do this would be something like the following (this
very well may have bugs... I haven't tested it, but it's similar to some of
the code that I'm using for draggable tabs):

gtk_widget_add_events (notebook, GDK_POINTER_MOTION_MASK);
gtk_signal_connect (GTK_OBJECT (notebook), "motion_notify_event",
                    GTK_SIGNAL_FUNC (notebook_motion_cb), notebook);

notebook_motion_cb (GtkWidget *widget, GdkEventMotion *e,
                    GtkNotebook *notebook)
        GList *l;
        GtkNotebookPage *page;
        GtkWidget *tab;
        gint nb_x, nb_y, x_rel, y_rel, i, page_num = -1;

        /* get the location of the cursor, relative to the notebook (i
         * think this is only necessary if your notebook tabs have
         * widgets with windows inside of them, such as buttons */
        gdk_window_get_origin (GTK_WIDGET (notebook)->window,
                               &nb_x, &nb_y);
        x_rel = e->x_root - nb_x;
        y_rel = e->y_root - nb_y;

        /* look through the notebook to find out which tab the cursor is
         * over */
        for (l = notebook->children, i = 0; l; l = l->next, i++)
                page = l->data;
                tab = page->tab_label;

                if (GTK_WIDGET_VISIBLE (tab))
                        if (tab->allocation.x <= x_rel &&
                            tab->allocation.x + tab->allocation.width >
                                                                x_rel &&
                            tab->allocation.y <= y_rel &&
                            tab->allocation.y + tab->allocation.height >
                                page_num = i;

        /* move to that page, if necessary */
        if (page_num != -1 &&
            gtk_notebook_current_page (notebook) != page_num)
                gtk_notebook_set_page (notebook, page_num);

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]