]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkimagemenuitem.c
spinbutton: don't override initial text in non-numeric-only spin buttons
[~andy/gtk] / gtk / gtkimagemenuitem.c
index 39cdb2e8479764495ce7235cb65358908e197ae8..28bc76ca2840ec59c19362716f157f10fbb2af7b 100644 (file)
@@ -12,9 +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., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 /*
 #include "gtkprivate.h"
 
 
+/**
+ * SECTION:gtkimagemenuitem
+ * @Short_description: A menu item with an icon
+ * @Title: GtkImageMenuItem
+ *
+ * A GtkImageMenuItem is a menu item which has an icon next to the text label.
+ *
+ * Note that the user can disable display of menu icons, so make sure to still
+ * fill in the text label.
+ */
+
 
 struct _GtkImageMenuItemPrivate
 {
@@ -82,7 +91,7 @@ static void gtk_image_menu_item_toggle_size_request  (GtkMenuItem      *menu_ite
                                                       gint             *requisition);
 static void gtk_image_menu_item_set_label            (GtkMenuItem      *menu_item,
                                                       const gchar      *label);
-static G_CONST_RETURN gchar *gtk_image_menu_item_get_label (GtkMenuItem *menu_item);
+static const gchar * gtk_image_menu_item_get_label   (GtkMenuItem *menu_item);
 
 static void gtk_image_menu_item_forall               (GtkContainer    *container,
                                                       gboolean         include_internals,
@@ -413,7 +422,7 @@ gtk_image_menu_item_set_label (GtkMenuItem      *menu_item,
     }
 }
 
-static G_CONST_RETURN gchar *
+static const gchar *
 gtk_image_menu_item_get_label (GtkMenuItem *menu_item)
 {
   GtkImageMenuItemPrivate *priv = GTK_IMAGE_MENU_ITEM (menu_item)->priv;
@@ -428,7 +437,6 @@ gtk_image_menu_item_get_preferred_width (GtkWidget        *widget,
 {
   GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
   GtkImageMenuItemPrivate *priv = image_menu_item->priv;
-  gint child_width = 0;
   GtkPackDirection pack_dir;
   GtkWidget *parent;
 
@@ -439,21 +447,18 @@ gtk_image_menu_item_get_preferred_width (GtkWidget        *widget,
   else
     pack_dir = GTK_PACK_DIRECTION_LTR;
 
-  if (priv->image && gtk_widget_get_visible (priv->image))
-    {
-      GtkRequisition child_requisition;
-
-      gtk_widget_get_preferred_size (priv->image, &child_requisition, NULL);
-
-      child_width = child_requisition.width;
-    }
-
   GTK_WIDGET_CLASS (gtk_image_menu_item_parent_class)->get_preferred_width (widget, minimum, natural);
 
-  if (pack_dir == GTK_PACK_DIRECTION_TTB || pack_dir == GTK_PACK_DIRECTION_BTT)
+  if ((pack_dir == GTK_PACK_DIRECTION_TTB || pack_dir == GTK_PACK_DIRECTION_BTT) &&
+      priv->image &&
+      gtk_widget_get_visible (priv->image))
     {
-      *minimum = MAX (*minimum, child_width);
-      *natural = MAX (*natural, child_width);
+      gint child_minimum, child_natural;
+
+      gtk_widget_get_preferred_width (priv->image, &child_minimum, &child_natural);
+
+      *minimum = MAX (*minimum, child_minimum);
+      *natural = MAX (*natural, child_natural);
     }
 }
 
@@ -554,6 +559,9 @@ gtk_image_menu_item_size_allocate (GtkWidget     *widget,
   if (priv->image && gtk_widget_get_visible (priv->image))
     {
       gint x, y, offset;
+      GtkStyleContext *context;
+      GtkStateFlags state;
+      GtkBorder padding;
       GtkRequisition child_requisition;
       GtkAllocation child_allocation;
       guint horizontal_padding, toggle_spacing;
@@ -573,18 +581,20 @@ gtk_image_menu_item_size_allocate (GtkWidget     *widget,
 
       gtk_widget_get_allocation (widget, &widget_allocation);
 
+      context = gtk_widget_get_style_context (widget);
+      state = gtk_widget_get_state_flags (widget);
+      gtk_style_context_get_padding (context, state, &padding);
+      offset = gtk_container_get_border_width (GTK_CONTAINER (image_menu_item));
+
       if (pack_dir == GTK_PACK_DIRECTION_LTR ||
           pack_dir == GTK_PACK_DIRECTION_RTL)
         {
-          offset = gtk_container_get_border_width (GTK_CONTAINER (image_menu_item)) +
-                   gtk_widget_get_style (widget)->xthickness;
-
           if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) ==
               (pack_dir == GTK_PACK_DIRECTION_LTR))
-            x = offset + horizontal_padding +
+            x = offset + horizontal_padding + padding.left +
                (toggle_size - toggle_spacing - child_requisition.width) / 2;
           else
-            x = widget_allocation.width - offset - horizontal_padding -
+            x = widget_allocation.width - offset - horizontal_padding - padding.right -
               toggle_size + toggle_spacing +
               (toggle_size - toggle_spacing - child_requisition.width) / 2;
 
@@ -592,15 +602,12 @@ gtk_image_menu_item_size_allocate (GtkWidget     *widget,
         }
       else
         {
-          offset = gtk_container_get_border_width (GTK_CONTAINER (image_menu_item)) +
-                   gtk_widget_get_style (widget)->ythickness;
-
           if ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) ==
               (pack_dir == GTK_PACK_DIRECTION_TTB))
-            y = offset + horizontal_padding +
+            y = offset + horizontal_padding + padding.top +
               (toggle_size - toggle_spacing - child_requisition.height) / 2;
           else
-            y = widget_allocation.height - offset - horizontal_padding -
+            y = widget_allocation.height - offset - horizontal_padding - padding.bottom -
               toggle_size + toggle_spacing +
               (toggle_size - toggle_spacing - child_requisition.height) / 2;
 
@@ -765,10 +772,11 @@ gtk_image_menu_item_sync_action_properties (GtkActivatable *activatable,
 
 /**
  * gtk_image_menu_item_new:
- * @returns: a new #GtkImageMenuItem.
  *
  * Creates a new #GtkImageMenuItem with an empty label.
- **/
+ *
+ * Returns: a new #GtkImageMenuItem
+ */
 GtkWidget*
 gtk_image_menu_item_new (void)
 {
@@ -778,9 +786,10 @@ gtk_image_menu_item_new (void)
 /**
  * gtk_image_menu_item_new_with_label:
  * @label: the text of the menu item.
- * @returns: a new #GtkImageMenuItem.
  *
  * Creates a new #GtkImageMenuItem containing a label.
+ *
+ * Returns: a new #GtkImageMenuItem.
  */
 GtkWidget*
 gtk_image_menu_item_new_with_label (const gchar *label)
@@ -790,16 +799,16 @@ gtk_image_menu_item_new_with_label (const gchar *label)
                        NULL);
 }
 
-
 /**
  * gtk_image_menu_item_new_with_mnemonic:
  * @label: the text of the menu item, with an underscore in front of the
  *         mnemonic character
- * @returns: a new #GtkImageMenuItem
  *
  * Creates a new #GtkImageMenuItem containing a label. The label
  * will be created using gtk_label_new_with_mnemonic(), so underscores
  * in @label indicate the mnemonic for the menu item.
+ *
+ * Returns: a new #GtkImageMenuItem
  */
 GtkWidget*
 gtk_image_menu_item_new_with_mnemonic (const gchar *label)
@@ -815,7 +824,6 @@ gtk_image_menu_item_new_with_mnemonic (const gchar *label)
  * @stock_id: the name of the stock item.
  * @accel_group: (allow-none): the #GtkAccelGroup to add the menu items
  *   accelerator to, or %NULL.
- * @returns: a new #GtkImageMenuItem.
  *
  * Creates a new #GtkImageMenuItem containing the image and text from a
  * stock item. Some stock ids have preprocessor macros like #GTK_STOCK_OK
@@ -826,6 +834,8 @@ gtk_image_menu_item_new_with_mnemonic (const gchar *label)
  * appropriate path for the menu item, use gtk_stock_lookup() to look up the
  * standard accelerator for the stock item, and if one is found, call
  * gtk_accel_map_add_entry() to register it.
+ *
+ * Returns: a new #GtkImageMenuItem.
  */
 GtkWidget*
 gtk_image_menu_item_new_from_stock (const gchar   *stock_id,