]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtktoolpalette.c
Popdown the bubble window when text view is scrolled
[~andy/gtk] / gtk / gtktoolpalette.c
index e35bf813f89e47a575bedcd5f58d5a0a48105737..3d9d7f3ccca7b518a604299a5dcec9c8366836f7 100644 (file)
@@ -12,8 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  *
  * Authors:
  *      Mathias Hasselmann
@@ -29,6 +28,7 @@
 #include "gtktypebuiltins.h"
 #include "gtkprivate.h"
 #include "gtkscrollable.h"
+#include "gtkorientableprivate.h"
 #include "gtkintl.h"
 
 #define DEFAULT_ICON_SIZE       GTK_ICON_SIZE_SMALL_TOOLBAR
@@ -263,6 +263,7 @@ gtk_tool_palette_set_property (GObject      *object,
         if ((guint) g_value_get_enum (value) != palette->priv->orientation)
           {
             palette->priv->orientation = g_value_get_enum (value);
+            _gtk_orientable_set_style_classes (GTK_ORIENTABLE (palette));
             gtk_tool_palette_reconfigured (palette);
           }
         break;
@@ -382,6 +383,14 @@ gtk_tool_palette_dispose (GObject *object)
       palette->priv->text_size_group = NULL;
     }
 
+  if (palette->priv->settings_connection > 0)
+    {
+      g_signal_handler_disconnect (palette->priv->settings, palette->priv->settings_connection);
+      palette->priv->settings_connection = 0;
+    }
+
+  g_clear_object (&palette->priv->settings);
+
   G_OBJECT_CLASS (gtk_tool_palette_parent_class)->dispose (object);
 }
 
@@ -472,7 +481,7 @@ gtk_tool_palette_size_allocate (GtkWidget     *widget,
   gint remaining_space = 0;
   gint expand_space = 0;
 
-  gint page_start, page_size = 0;
+  gint total_size, page_size;
   gint offset = 0;
   guint i;
   guint border_width;
@@ -524,6 +533,8 @@ gtk_tool_palette_size_allocate (GtkWidget     *widget,
       GtkToolItemGroupInfo *group = g_ptr_array_index (palette->priv->groups, i);
       gint size;
 
+      group_sizes[i] = 0;
+
       if (!group->widget)
         continue;
 
@@ -649,43 +660,40 @@ gtk_tool_palette_size_allocate (GtkWidget     *widget,
       child_allocation.y += border_width;
       child_allocation.y += offset;
 
-      page_start = child_allocation.y;
+      total_size = child_allocation.y;
     }
   else
     {
       x += border_width;
       x += offset;
 
-      page_start = x;
+      total_size = x;
     }
 
   /* update the scrollbar to match the displayed adjustment */
   if (adjustment)
     {
-      gdouble value, lower, upper;
+      gdouble lower, upper;
+
+      total_size = MAX (0, total_size);
+      page_size = MIN (total_size, page_size);
 
       if (GTK_ORIENTATION_VERTICAL == palette->priv->orientation ||
           GTK_TEXT_DIR_LTR == direction)
         {
           lower = 0;
-          upper = MAX (0, page_start);
-
-          value = MIN (offset, upper - page_size);
-          gtk_adjustment_clamp_page (adjustment, value, offset + page_size);
+          upper = total_size;
         }
       else
         {
-          lower = page_size - MAX (0, page_start);
+          lower = page_size - total_size;
           upper = page_size;
 
           offset = -offset;
-
-          value = MAX (offset, lower);
-          gtk_adjustment_clamp_page (adjustment, offset, value + page_size);
         }
 
       gtk_adjustment_configure (adjustment,
-                                value,
+                                offset,
                                 lower,
                                 upper,
                                 page_size * 0.1,
@@ -694,38 +702,6 @@ gtk_tool_palette_size_allocate (GtkWidget     *widget,
     }
 }
 
-static gboolean
-gtk_tool_palette_draw (GtkWidget      *widget,
-                       cairo_t        *cr)
-{
-  GtkToolPalette *palette = GTK_TOOL_PALETTE (widget);
-  GdkDisplay *display;
-  GdkWindow *window;
-  guint i;
-
-  window = gtk_widget_get_window (widget);
-
-  display = gdk_window_get_display (window);
-
-  if (!gdk_display_supports_composite (display))
-    return FALSE;
-
-  cairo_push_group (cr);
-
-  for (i = 0; i < palette->priv->groups->len; ++i)
-  {
-    GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
-    if (info->widget)
-      _gtk_tool_item_group_paint (info->widget, cr);
-  }
-
-  cairo_pop_group_to_source (cr);
-
-  cairo_paint (cr);
-
-  return FALSE;
-}
-
 static void
 gtk_tool_palette_realize (GtkWidget *widget)
 {
@@ -751,13 +727,15 @@ gtk_tool_palette_realize (GtkWidget *widget)
   attributes.event_mask = gtk_widget_get_events (widget)
                          | GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK
                          | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
-                         | GDK_BUTTON_MOTION_MASK;
+                         | GDK_BUTTON_MOTION_MASK
+                         | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK
+                         | GDK_TOUCH_MASK;
   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
 
   window = gdk_window_new (gtk_widget_get_parent_window (widget),
                            &attributes, attributes_mask);
   gtk_widget_set_window (widget, window);
-  gdk_window_set_user_data (window, widget);
+  gtk_widget_register_window (widget, window);
 
   gtk_style_context_set_background (gtk_widget_get_style_context (widget),
                                     window);
@@ -829,15 +807,21 @@ gtk_tool_palette_forall (GtkContainer *container,
                          gpointer      callback_data)
 {
   GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
-  guint i;
-
+  guint i, len;
 
   for (i = 0; i < palette->priv->groups->len; ++i)
     {
       GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
+
+      len = palette->priv->groups->len;
+
       if (info->widget)
         callback (GTK_WIDGET (info->widget),
                   callback_data);
+
+      /* At destroy time, 'callback' results in removing a widget,
+       * here we just reset the current index to account for the removed widget. */
+      i -= (len - palette->priv->groups->len);
     }
 }
 
@@ -958,6 +942,7 @@ gtk_tool_palette_screen_changed (GtkWidget *widget,
   if (old_settings)
   {
     g_signal_handler_disconnect (old_settings, priv->settings_connection);
+    priv->settings_connection = 0;
     g_object_unref (old_settings);
   }
 
@@ -991,7 +976,6 @@ gtk_tool_palette_class_init (GtkToolPaletteClass *cls)
   wclass->get_preferred_width = gtk_tool_palette_get_preferred_width;
   wclass->get_preferred_height= gtk_tool_palette_get_preferred_height;
   wclass->size_allocate       = gtk_tool_palette_size_allocate;
-  wclass->draw                = gtk_tool_palette_draw;
   wclass->realize             = gtk_tool_palette_realize;
 
   cclass->add                 = gtk_tool_palette_add;
@@ -1016,7 +1000,7 @@ gtk_tool_palette_class_init (GtkToolPaletteClass *cls)
    * GtkToolPalette:icon-size:
    *
    * The size of the icons in a tool palette is normally determined by
-   * the #GtkSettings:toolbar-icon-size setting. When this property is set,
+   * the #GtkSettings:gtk-toolbar-icon-size setting. When this property is set,
    * it overrides the setting.
    *
    * This should only be used for special-purpose tool palettes, normal
@@ -1316,9 +1300,9 @@ gtk_tool_palette_get_style (GtkToolPalette *palette)
   return palette->priv->style;
 }
 
-gint
-_gtk_tool_palette_compare_groups (gconstpointer a,
-                                  gconstpointer b)
+static gint
+gtk_tool_palette_compare_groups (gconstpointer a,
+                                 gconstpointer b)
 {
   const GtkToolItemGroupInfo *group_a = a;
   const GtkToolItemGroupInfo *group_b = b;
@@ -1369,7 +1353,7 @@ gtk_tool_palette_set_group_position (GtkToolPalette   *palette,
   group_new->pos = position;
   group_old->pos = old_position;
 
-  g_ptr_array_sort (palette->priv->groups, _gtk_tool_palette_compare_groups);
+  g_ptr_array_sort (palette->priv->groups, gtk_tool_palette_compare_groups);
 
   gtk_widget_queue_resize (GTK_WIDGET (palette));
 }
@@ -1700,7 +1684,7 @@ gtk_tool_palette_get_drag_item (GtkToolPalette         *palette,
 /**
  * gtk_tool_palette_set_drag_source:
  * @palette: a #GtkToolPalette
- * @targets: the #GtkToolPaletteDragTarget<!-- -->s
+ * @targets: the #GtkToolPaletteDragTargets
  *     which the widget should support
  *
  * Sets the tool palette as a drag source.
@@ -1739,7 +1723,7 @@ gtk_tool_palette_set_drag_source (GtkToolPalette            *palette,
  * @widget: a #GtkWidget which should be a drag destination for @palette
  * @flags: the flags that specify what actions GTK+ should take for drops
  *     on that widget
- * @targets: the #GtkToolPaletteDragTarget<!-- -->s which the widget
+ * @targets: the #GtkToolPaletteDragTargets which the widget
  *     should support
  * @actions: the #GdkDragAction<!-- -->s which the widget should suppport
  *
@@ -1906,7 +1890,7 @@ _gtk_tool_palette_child_set_drag_source (GtkWidget *child,
  *
  * Since: 2.20
  */
-G_CONST_RETURN GtkTargetEntry*
+const GtkTargetEntry*
 gtk_tool_palette_get_drag_target_item (void)
 {
   return &dnd_targets[0];
@@ -1921,7 +1905,7 @@ gtk_tool_palette_get_drag_target_item (void)
  *
  * Since: 2.20
  */
-G_CONST_RETURN GtkTargetEntry*
+const GtkTargetEntry*
 gtk_tool_palette_get_drag_target_group (void)
 {
   return &dnd_targets[1];
@@ -1980,7 +1964,7 @@ gtk_tool_palette_set_hadjustment (GtkToolPalette *palette,
                     G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
                     palette);
   priv->hadjustment = g_object_ref_sink (adjustment);
-  /* FIXME: Adjustment should probably have it's values updated now */
+  /* FIXME: Adjustment should probably have its values updated now */
   g_object_notify (G_OBJECT (palette), "hadjustment");
 }
 
@@ -2029,7 +2013,7 @@ gtk_tool_palette_set_vadjustment (GtkToolPalette *palette,
                     G_CALLBACK (gtk_tool_palette_adjustment_value_changed),
                     palette);
   priv->vadjustment = g_object_ref_sink (adjustment);
-  /* FIXME: Adjustment should probably have it's values updated now */
+  /* FIXME: Adjustment should probably have its values updated now */
   g_object_notify (G_OBJECT (palette), "vadjustment");
 }