]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtknotebook.c
Stop scrolling when the widget is unmapped. (#168791, Ryan Lortie)
[~andy/gtk] / gtk / gtknotebook.c
index 6a3ad39cda7a179e1c441853ab474f3ff99805d0..0c42e2003b658c2098939b47701cf8fd00b208cf 100644 (file)
@@ -24,6 +24,7 @@
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
+#include <config.h>
 #include "gtknotebook.h"
 #include "gtkmain.h"
 #include "gtkmenu.h"
@@ -34,6 +35,8 @@
 #include "gtkintl.h"
 #include "gtkmarshalers.h"
 #include "gtkbindings.h"
+#include "gtkprivate.h"
+#include "gtkalias.h"
 
 
 #define TAB_OVERLAP    2
@@ -158,6 +161,8 @@ static void gtk_notebook_size_allocate       (GtkWidget        *widget,
                                              GtkAllocation    *allocation);
 static gint gtk_notebook_expose              (GtkWidget        *widget,
                                              GdkEventExpose   *event);
+static gboolean gtk_notebook_scroll          (GtkWidget        *widget,
+                                              GdkEventScroll   *event);
 static gint gtk_notebook_button_press        (GtkWidget        *widget,
                                              GdkEventButton   *event);
 static gint gtk_notebook_button_release      (GtkWidget        *widget,
@@ -283,6 +288,9 @@ static gboolean focus_tabs_in  (GtkNotebook      *notebook);
 static gboolean focus_child_in (GtkNotebook      *notebook,
                                GtkDirectionType  direction);
 
+static void stop_scrolling (GtkNotebook *notebook);
+
+
 static GtkContainerClass *parent_class = NULL;
 static guint notebook_signals[LAST_SIGNAL] = { 0 };
 
@@ -363,6 +371,7 @@ gtk_notebook_class_init (GtkNotebookClass *class)
   widget_class->size_request = gtk_notebook_size_request;
   widget_class->size_allocate = gtk_notebook_size_allocate;
   widget_class->expose_event = gtk_notebook_expose;
+  widget_class->scroll_event = gtk_notebook_scroll;
   widget_class->button_press_event = gtk_notebook_button_press;
   widget_class->button_release_event = gtk_notebook_button_release;
   widget_class->enter_notify_event = gtk_notebook_enter_notify;
@@ -398,120 +407,120 @@ gtk_notebook_class_init (GtkNotebookClass *class)
                                                     0,
                                                     G_MAXINT,
                                                     0,
-                                                    G_PARAM_READWRITE));
+                                                    GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                   PROP_TAB_POS,
-                                  g_param_spec_enum ("tab_pos",
+                                  g_param_spec_enum ("tab-pos",
                                                      P_("Tab Position"),
                                                      P_("Which side of the notebook holds the tabs"),
                                                      GTK_TYPE_POSITION_TYPE,
                                                      GTK_POS_TOP,
-                                                     G_PARAM_READWRITE));
+                                                     GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                   PROP_TAB_BORDER,
-                                  g_param_spec_uint ("tab_border",
+                                  g_param_spec_uint ("tab-border",
                                                      P_("Tab Border"),
                                                      P_("Width of the border around the tab labels"),
                                                      0,
                                                      G_MAXUINT,
                                                      2,
-                                                     G_PARAM_WRITABLE));
+                                                     GTK_PARAM_WRITABLE));
   g_object_class_install_property (gobject_class,
                                   PROP_TAB_HBORDER,
-                                  g_param_spec_uint ("tab_hborder",
+                                  g_param_spec_uint ("tab-hborder",
                                                      P_("Horizontal Tab Border"),
                                                      P_("Width of the horizontal border of tab labels"),
                                                      0,
                                                      G_MAXUINT,
                                                      2,
-                                                     G_PARAM_READWRITE));
+                                                     GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                   PROP_TAB_VBORDER,
-                                  g_param_spec_uint ("tab_vborder",
+                                  g_param_spec_uint ("tab-vborder",
                                                      P_("Vertical Tab Border"),
                                                      P_("Width of the vertical border of tab labels"),
                                                      0,
                                                      G_MAXUINT,
                                                      2,
-                                                     G_PARAM_READWRITE));
+                                                     GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                   PROP_SHOW_TABS,
-                                  g_param_spec_boolean ("show_tabs",
+                                  g_param_spec_boolean ("show-tabs",
                                                         P_("Show Tabs"),
                                                         P_("Whether tabs should be shown or not"),
                                                         TRUE,
-                                                        G_PARAM_READWRITE));
+                                                        GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                   PROP_SHOW_BORDER,
-                                  g_param_spec_boolean ("show_border",
+                                  g_param_spec_boolean ("show-border",
                                                         P_("Show Border"),
                                                         P_("Whether the border should be shown or not"),
                                                         TRUE,
-                                                        G_PARAM_READWRITE));
+                                                        GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                   PROP_SCROLLABLE,
                                   g_param_spec_boolean ("scrollable",
                                                         P_("Scrollable"),
                                                         P_("If TRUE, scroll arrows are added if there are too many tabs to fit"),
                                                         FALSE,
-                                                        G_PARAM_READWRITE));
+                                                        GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                   PROP_ENABLE_POPUP,
-                                  g_param_spec_boolean ("enable_popup",
+                                  g_param_spec_boolean ("enable-popup",
                                                         P_("Enable Popup"),
                                                         P_("If TRUE, pressing the right mouse button on the notebook pops up a menu that you can use to go to a page"),
                                                         FALSE,
-                                                        G_PARAM_READWRITE));
+                                                        GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                   PROP_HOMOGENEOUS,
                                   g_param_spec_boolean ("homogeneous",
                                                         P_("Homogeneous"),
                                                         P_("Whether tabs should have homogeneous sizes"),
                                                         FALSE,
-                                                        G_PARAM_READWRITE));
+                                                        GTK_PARAM_READWRITE));
 
   gtk_container_class_install_child_property (container_class,
                                              CHILD_PROP_TAB_LABEL,
-                                             g_param_spec_string ("tab_label", 
+                                             g_param_spec_string ("tab-label", 
                                                                   P_("Tab label"),
-                                                                  P_("The string displayed on the childs tab label"),
+                                                                  P_("The string displayed on the child's tab label"),
                                                                   NULL,
-                                                                  G_PARAM_READWRITE));
+                                                                  GTK_PARAM_READWRITE));
   gtk_container_class_install_child_property (container_class,
                                              CHILD_PROP_MENU_LABEL,
-                                             g_param_spec_string ("menu_label", 
+                                             g_param_spec_string ("menu-label", 
                                                                   P_("Menu label"), 
-                                                                  P_("The string displayed in the childs menu entry"),
+                                                                  P_("The string displayed in the child's menu entry"),
                                                                   NULL,
-                                                                  G_PARAM_READWRITE));
+                                                                  GTK_PARAM_READWRITE));
   gtk_container_class_install_child_property (container_class,
                                              CHILD_PROP_POSITION,
                                              g_param_spec_int ("position", 
                                                                P_("Position"), 
                                                                P_("The index of the child in the parent"),
                                                                -1, G_MAXINT, 0,
-                                                               G_PARAM_READWRITE));
+                                                               GTK_PARAM_READWRITE));
   gtk_container_class_install_child_property (container_class,
                                              CHILD_PROP_TAB_EXPAND,
-                                             g_param_spec_boolean ("tab_expand", 
+                                             g_param_spec_boolean ("tab-expand", 
                                                                    P_("Tab expand"), 
-                                                                   P_("Whether to expand the childs tab or not"),
+                                                                   P_("Whether to expand the child's tab or not"),
                                                                    TRUE,
-                                                                   G_PARAM_READWRITE));
+                                                                   GTK_PARAM_READWRITE));
   gtk_container_class_install_child_property (container_class,
                                              CHILD_PROP_TAB_FILL,
-                                             g_param_spec_boolean ("tab_fill", 
+                                             g_param_spec_boolean ("tab-fill", 
                                                                    P_("Tab fill"), 
-                                                                   P_("Wheather the childs tab should fill the allocated area or not"),
+                                                                   P_("Whether the child's tab should fill the allocated area or not"),
                                                                    TRUE,
-                                                                   G_PARAM_READWRITE));
+                                                                   GTK_PARAM_READWRITE));
   gtk_container_class_install_child_property (container_class,
                                              CHILD_PROP_TAB_PACK,
-                                             g_param_spec_enum ("tab_pack", 
+                                             g_param_spec_enum ("tab-pack", 
                                                                 P_("Tab pack type"),
                                                                 P_("A GtkPackType indicating whether the child is packed with reference to the start or end of the parent"),
                                                                 GTK_TYPE_PACK_TYPE, GTK_PACK_START,
-                                                                G_PARAM_READWRITE));
+                                                                GTK_PARAM_READWRITE));
 
 /**
  * GtkNotebook:has-secondary-backward-stepper:
@@ -523,12 +532,12 @@ gtk_notebook_class_init (GtkNotebookClass *class)
  * Since: 2.4
  */  
   gtk_widget_class_install_style_property (widget_class,
-                                          g_param_spec_boolean ("has_secondary backward_stepper",
+                                          g_param_spec_boolean ("has-secondary-backward-stepper",
                                                                 P_("Secondary backward stepper"),
                                                                 P_("Display a second backward arrow button on the opposite end of the tab area"),
                                                                 FALSE,
                                                                 
-                                                                G_PARAM_READABLE));
+                                                                GTK_PARAM_READABLE));
 
 /**
  * GtkNotebook:has-secondary-forward-stepper:
@@ -540,12 +549,12 @@ gtk_notebook_class_init (GtkNotebookClass *class)
  * Since: 2.4
  */  
   gtk_widget_class_install_style_property (widget_class,
-                                          g_param_spec_boolean ("has_secondary_forward_stepper",
+                                          g_param_spec_boolean ("has-secondary-forward-stepper",
                                                                 P_("Secondary forward stepper"),
                                                                 P_("Display a second forward arrow button on the opposite end of the tab area"),
                                                                 FALSE,
                                                                 
-                                                                G_PARAM_READABLE));
+                                                                GTK_PARAM_READABLE));
 
 /**
  * GtkNotebook:has-backward-stepper:
@@ -556,12 +565,12 @@ gtk_notebook_class_init (GtkNotebookClass *class)
  * Since: 2.4
  */  
   gtk_widget_class_install_style_property (widget_class,
-                                          g_param_spec_boolean ("has_backward_stepper",
+                                          g_param_spec_boolean ("has-backward-stepper",
                                                                 P_("Backward stepper"),
                                                                 P_("Display the standard backward arrow button"),
                                                                 TRUE,
                                                                 
-                                                                   G_PARAM_READABLE));
+                                                                   GTK_PARAM_READABLE));
 
 /**
  * GtkNotebook:has-forward-stepper:
@@ -572,12 +581,12 @@ gtk_notebook_class_init (GtkNotebookClass *class)
  * Since: 2.4
  */  
   gtk_widget_class_install_style_property (widget_class,
-                                          g_param_spec_boolean ("has_forward_stepper",
+                                          g_param_spec_boolean ("has-forward-stepper",
                                                                 P_("Forward stepper"),
                                                                 P_("Display the standard forward arrow button"),
                                                                 TRUE,
                                                                 
-                                                                   G_PARAM_READABLE));
+                                                                   GTK_PARAM_READABLE));
 
   notebook_signals[SWITCH_PAGE] =
     g_signal_new ("switch_page",
@@ -997,6 +1006,7 @@ gtk_notebook_get_property (GObject         *object,
  * gtk_notebook_size_request
  * gtk_notebook_size_allocate
  * gtk_notebook_expose
+ * gtk_notebook_scroll
  * gtk_notebook_button_press
  * gtk_notebook_button_release
  * gtk_notebook_enter_notify
@@ -1112,6 +1122,8 @@ gtk_notebook_unmap (GtkWidget *widget)
 {
   g_return_if_fail (GTK_IS_NOTEBOOK (widget));
 
+  stop_scrolling (GTK_NOTEBOOK (widget));
+  
   GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
 
   gdk_window_hide (GTK_NOTEBOOK (widget)->event_window);
@@ -1145,8 +1157,8 @@ gtk_notebook_realize (GtkWidget *widget)
   attributes.wclass = GDK_INPUT_ONLY;
   attributes.event_mask = gtk_widget_get_events (widget);
   attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
-                           GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK);
-
+                           GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK |
+                           GDK_SCROLL_MASK);
   attributes_mask = GDK_WA_X | GDK_WA_Y;
 
   notebook->event_window = gdk_window_new (gtk_widget_get_parent_window (widget), 
@@ -1508,13 +1520,6 @@ gtk_notebook_size_allocate (GtkWidget     *widget,
 
       gtk_notebook_pages_allocate (notebook);
     }
-
-  if ((vis_pages != 0) != notebook->have_visible_child)
-    {
-      notebook->have_visible_child = (vis_pages != 0);
-      if (notebook->show_tabs)
-       gtk_widget_queue_draw (widget);
-    }
 }
 
 static gint
@@ -1763,6 +1768,40 @@ get_widget_coordinates (GtkWidget *widget,
     return FALSE;
 }
 
+static gboolean
+gtk_notebook_scroll (GtkWidget      *widget,
+                     GdkEventScroll *event)
+{
+  GtkNotebook *notebook = GTK_NOTEBOOK (widget);
+
+  GtkWidget* child;
+  GtkWidget* originator;
+
+  if (!notebook->cur_page)
+    return FALSE;
+
+  child = notebook->cur_page->child;
+  originator = gtk_get_event_widget ((GdkEvent *)event);
+
+  /* ignore scroll events from the content of the page */
+  if (!originator || gtk_widget_is_ancestor (originator, child))
+    return FALSE;
+  
+  switch (event->direction)
+    {
+    case GDK_SCROLL_RIGHT:
+    case GDK_SCROLL_DOWN:
+      gtk_notebook_next_page (notebook);
+      break;
+    case GDK_SCROLL_LEFT:
+    case GDK_SCROLL_UP:
+      gtk_notebook_prev_page (notebook);
+      break;
+    }
+
+  return TRUE;
+}
+
 static gboolean
 gtk_notebook_button_press (GtkWidget      *widget,
                           GdkEventButton *event)
@@ -3562,51 +3601,6 @@ gtk_notebook_page_allocate (GtkNotebook     *notebook,
   xthickness = widget->style->xthickness;
   ythickness = widget->style->ythickness;
 
-  /* If the size of the notebook tabs change, we need to queue
-   * a redraw on the tab area
-   */
-  if ((allocation->width != page->allocation.width) ||
-      (allocation->height != page->allocation.height))
-    {
-      gint x, y, width, height, border_width;
-
-      border_width = GTK_CONTAINER (notebook)->border_width;
-
-      switch (tab_pos)
-       {
-       case GTK_POS_TOP:
-         width = widget->allocation.width;
-         height = MAX (page->allocation.height, allocation->height) + ythickness;
-         x = 0;                              
-         y = border_width;
-         break;
-
-       case GTK_POS_BOTTOM:
-         width = widget->allocation.width + xthickness;
-         height = MAX (page->allocation.height, allocation->height) + ythickness;
-         x = 0;                              
-         y = widget->allocation.height - height - border_width;
-         break;
-
-       case GTK_POS_LEFT:
-         width = MAX (page->allocation.width, allocation->width) + xthickness;
-         height = widget->allocation.height;
-         x = border_width;
-         y = 0;
-         break;
-
-       case GTK_POS_RIGHT:
-       default:                /* quiet gcc */
-         width = MAX (page->allocation.width, allocation->width) + xthickness;
-         height = widget->allocation.height;
-         x = widget->allocation.width - width - border_width;
-         y = 0;
-         break;
-       }
-
-      gtk_widget_queue_draw_area (widget, x, y, width, height);
-    }
-
   page->allocation = *allocation;
   gtk_widget_get_child_requisition (page->tab_label, &tab_requisition);
 
@@ -5448,3 +5442,6 @@ gtk_notebook_reorder_child (GtkNotebook *notebook,
 
   gtk_widget_thaw_child_notify (child);
 }
+
+#define __GTK_NOTEBOOK_C__
+#include "gtkaliasdef.c"