]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtklinkbutton.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtklinkbutton.c
index 9a6b6fa1f2c1123c74be51991ea17e0a525800ed..b5981c741f5ea55192dd40ddbeb9d8fb5e7b5f94 100644 (file)
@@ -1,12 +1,12 @@
 /* GTK - The GIMP Toolkit
  * gtklinkbutton.c - an hyperlink-enabled button
- * 
+ *
  * Copyright (C) 2006 Emmanuele Bassi <ebassi@gmail.com>
  * All rights reserved.
  *
  * Based on gnome-href code by:
- *     James Henstridge <james@daa.com.au>
- * 
+ *      James Henstridge <james@daa.com.au>
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * License as published by the Free Software Foundation; either
@@ -18,8 +18,7 @@
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Cambridge, MA 02139, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /**
 #include "gtkstock.h"
 #include "gtkshow.h"
 #include "gtktooltip.h"
-
+#include "gtkprivate.h"
 #include "gtkintl.h"
 
+#include "a11y/gtklinkbuttonaccessible.h"
 
 struct _GtkLinkButtonPrivate
 {
@@ -105,8 +105,8 @@ static gboolean gtk_link_button_button_press (GtkWidget        *widget,
                                              GdkEventButton   *event);
 static void     gtk_link_button_clicked      (GtkButton        *button);
 static gboolean gtk_link_button_popup_menu   (GtkWidget        *widget);
-static void     gtk_link_button_style_set    (GtkWidget        *widget,
-                                             GtkStyle         *old_style);
+static void     gtk_link_button_style_updated (GtkWidget        *widget);
+static void     gtk_link_button_unrealize    (GtkWidget        *widget);
 static gboolean gtk_link_button_enter_cb     (GtkWidget        *widget,
                                              GdkEventCrossing *event,
                                              gpointer          user_data);
@@ -153,7 +153,8 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass)
   
   widget_class->button_press_event = gtk_link_button_button_press;
   widget_class->popup_menu = gtk_link_button_popup_menu;
-  widget_class->style_set = gtk_link_button_style_set;
+  widget_class->style_updated = gtk_link_button_style_updated;
+  widget_class->unrealize = gtk_link_button_unrealize;
   
   container_class->add = gtk_link_button_add;
 
@@ -162,9 +163,9 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass)
   klass->activate_link = gtk_link_button_activate_link;
 
   /**
-   * GtkLinkButton:uri
-   * 
-   * The URI bound to this button. 
+   * GtkLinkButton:uri:
+   *
+   * The URI bound to this button.
    *
    * Since: 2.10
    */
@@ -176,8 +177,8 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass)
                                                        NULL,
                                                        G_PARAM_READWRITE));
   /**
-   * GtkLinkButton:visited
-   * 
+   * GtkLinkButton:visited:
+   *
    * The 'visited' state of this button. A visited link is drawn in a
    * different color.
    *
@@ -215,6 +216,8 @@ gtk_link_button_class_init (GtkLinkButtonClass *klass)
                   _gtk_boolean_handled_accumulator, NULL,
                   _gtk_marshal_BOOLEAN__VOID,
                   G_TYPE_BOOLEAN, 0);
+
+  gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_LINK_BUTTON_ACCESSIBLE);
 }
 
 static void
@@ -303,6 +306,7 @@ set_link_color (GtkLinkButton *link_button)
 {
   GdkColor *link_color = NULL;
   GtkWidget *label;
+  GdkRGBA rgba;
 
   label = gtk_bin_get_child (GTK_BIN (link_button));
   if (!GTK_IS_LABEL (label))
@@ -323,10 +327,14 @@ set_link_color (GtkLinkButton *link_button)
        link_color = (GdkColor *) &default_link_color;
     }
 
-  gtk_widget_modify_fg (label, GTK_STATE_NORMAL, link_color);
-  gtk_widget_modify_fg (label, GTK_STATE_ACTIVE, link_color);
-  gtk_widget_modify_fg (label, GTK_STATE_PRELIGHT, link_color);
-  gtk_widget_modify_fg (label, GTK_STATE_SELECTED, link_color);
+  rgba.red = link_color->red / 65535.;
+  rgba.green = link_color->green / 65535.;
+  rgba.blue = link_color->blue / 65535.;
+  rgba.alpha = 1;
+  gtk_widget_override_color (label, GTK_STATE_FLAG_NORMAL, &rgba);
+  gtk_widget_override_color (label, GTK_STATE_FLAG_ACTIVE, &rgba);
+  gtk_widget_override_color (label, GTK_STATE_FLAG_PRELIGHT, &rgba);
+  gtk_widget_override_color (label, GTK_STATE_FLAG_SELECTED, &rgba);
 
   if (link_color != &default_link_color &&
       link_color != &default_visited_link_color)
@@ -365,12 +373,11 @@ gtk_link_button_add (GtkContainer *container,
 }
 
 static void
-gtk_link_button_style_set (GtkWidget *widget,
-                          GtkStyle  *old_style)
+gtk_link_button_style_updated (GtkWidget *widget)
 {
-  GtkLinkButton *link_button = GTK_LINK_BUTTON (widget);
+  GTK_WIDGET_CLASS (gtk_link_button_parent_class)->style_updated (widget);
 
-  set_link_color (link_button);
+  set_link_color (GTK_LINK_BUTTON (widget));
 }
 
 static void
@@ -390,7 +397,15 @@ set_hand_cursor (GtkWidget *widget,
   gdk_display_flush (display);
 
   if (cursor)
-    gdk_cursor_unref (cursor);
+    g_object_unref (cursor);
+}
+
+static void
+gtk_link_button_unrealize (GtkWidget *widget)
+{
+  set_hand_cursor (widget, FALSE);
+
+  GTK_WIDGET_CLASS (gtk_link_button_parent_class)->unrealize (widget);
 }
 
 static void
@@ -430,7 +445,7 @@ popup_position_func (GtkMenu  *menu,
 
   monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
   gtk_menu_set_monitor (menu, monitor_num);
-  gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+  gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
 
   *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
   *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
@@ -511,10 +526,13 @@ gtk_link_button_button_press (GtkWidget      *widget,
   if (!gtk_widget_has_focus (widget))
     gtk_widget_grab_focus (widget);
 
-  if ((event->button == 3) && (event->type == GDK_BUTTON_PRESS))
+  /* Don't popup the menu if there's no URI set,
+   * otherwise the menu item will trigger a warning */
+  if (gdk_event_triggers_context_menu ((GdkEvent *) event) &&
+      GTK_LINK_BUTTON (widget)->priv->uri != NULL)
     {
       gtk_link_button_do_popup (GTK_LINK_BUTTON (widget), event);
-      
+
       return TRUE;
     }
 
@@ -754,7 +772,7 @@ gtk_link_button_set_uri (GtkLinkButton *link_button,
  *
  * Since: 2.10
  */
-G_CONST_RETURN gchar *
+const gchar *
 gtk_link_button_get_uri (GtkLinkButton *link_button)
 {
   g_return_val_if_fail (GTK_IS_LINK_BUTTON (link_button), NULL);