* 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
{
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,
}
}
-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;
{
GtkImageMenuItem *image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
GtkImageMenuItemPrivate *priv = image_menu_item->priv;
- gint child_width = 0;
GtkPackDirection pack_dir;
GtkWidget *parent;
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);
}
}
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;
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;
}
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;
/**
* 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)
{
/**
* 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)
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)
* @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
* 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,