*/
#include <math.h>
+#include <stdlib.h>
#include <string.h>
#include "gtkgc.h"
#include "gtkrc.h"
+#include "gtkspinbutton.h"
#include "gtkstyle.h"
#include "gtkwidget.h"
#include "gtkthemes.h"
#include "gtkiconfactory.h"
+#include "gtksettings.h" /* _gtk_settings_parse_convert() */
#define LIGHTNESS_MULT 1.3
#define DARKNESS_MULT 0.7
-
/* --- typedefs & structures --- */
typedef struct {
GType widget_type;
GtkPositionType gap_side);
static void gtk_default_draw_focus (GtkStyle *style,
GdkWindow *window,
+ GtkStateType state_type,
GdkRectangle *area,
GtkWidget *widget,
const gchar *detail,
const gchar *detail,
gint x,
gint y,
- gboolean is_open);
+ GtkExpanderStyle expander_style);
static void gtk_default_draw_layout (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
+ gboolean use_text,
GdkRectangle *area,
GtkWidget *widget,
const gchar *detail,
gdouble *s);
+/*
+ * Data for default check and radio buttons
+ */
+
+static GtkRequisition default_option_indicator_size = { 7, 13 };
+static GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
+
+#define INDICATOR_PART_SIZE 13
+
+typedef enum {
+ CHECK_AA,
+ CHECK_BASE,
+ CHECK_BLACK,
+ CHECK_DARK,
+ CHECK_LIGHT,
+ CHECK_MID,
+ CHECK_TEXT,
+ RADIO_BASE,
+ RADIO_BLACK,
+ RADIO_DARK,
+ RADIO_LIGHT,
+ RADIO_MID,
+ RADIO_TEXT
+} IndicatorPart;
+
+static char check_aa_bits[] = {
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x58,0x00,0xa0,
+ 0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
+static char check_base_bits[] = {
+ 0x00,0x00,0x00,0x00,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
+ 0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0x00,0x00,0x00,0x00};
+static char check_black_bits[] = {
+ 0x00,0x00,0xfe,0x0f,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
+ 0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00};
+static char check_dark_bits[] = {
+ 0xff,0x1f,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
+ 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00};
+static char check_light_bits[] = {
+ 0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
+ 0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0xfe,0x1f};
+static char check_mid_bits[] = {
+ 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
+ 0x08,0x00,0x08,0x00,0x08,0x00,0x08,0xfc,0x0f,0x00,0x00};
+static char check_text_bits[] = {
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x03,0x80,0x01,0x80,0x00,0xd8,
+ 0x00,0x60,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
+static char radio_base_bits[] = {
+ 0x00,0x00,0x00,0x00,0xf0,0x01,0xf8,0x03,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
+ 0x07,0xfc,0x07,0xf8,0x03,0xf0,0x01,0x00,0x00,0x00,0x00};
+static char radio_black_bits[] = {
+ 0x00,0x00,0xf0,0x01,0x08,0x02,0x04,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
+ 0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
+static char radio_dark_bits[] = {
+ 0xf0,0x01,0x08,0x02,0x04,0x04,0x02,0x04,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
+ 0x00,0x01,0x00,0x02,0x00,0x0c,0x00,0x00,0x00,0x00,0x00};
+static char radio_light_bits[] = {
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
+ 0x10,0x00,0x10,0x00,0x08,0x00,0x04,0x08,0x02,0xf0,0x01};
+static char radio_mid_bits[] = {
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
+ 0x08,0x00,0x08,0x00,0x04,0x00,0x02,0xf0,0x01,0x00,0x00};
+static char radio_text_bits[] = {
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0xf0,0x01,0xf0,0x01,0xf0,
+ 0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
+
+static struct {
+ char *bits;
+ GdkBitmap *bmap;
+} indicator_parts[] = {
+ { check_aa_bits, NULL },
+ { check_base_bits, NULL },
+ { check_black_bits, NULL },
+ { check_dark_bits, NULL },
+ { check_light_bits, NULL },
+ { check_mid_bits, NULL },
+ { check_text_bits, NULL },
+ { radio_base_bits, NULL },
+ { radio_black_bits, NULL },
+ { radio_dark_bits, NULL },
+ { radio_light_bits, NULL },
+ { radio_mid_bits, NULL },
+ { radio_text_bits, NULL }
+};
+
/* --- variables --- */
static GdkColor gtk_default_normal_fg = { 0, 0, 0, 0 };
static GdkColor gtk_default_active_fg = { 0, 0, 0, 0 };
static GdkColor gtk_default_prelight_bg = { 0, 0xea60, 0xea60, 0xea60 };
static GdkColor gtk_default_selected_bg = { 0, 0, 0, 0x9c40 };
static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
+static GdkColor gtk_default_selected_base = { 0, 0xa4a4, 0xdfdf, 0xffff };
+static GdkColor gtk_default_active_base = { 0, 0xbcbc, 0xd2d2, 0xeeee };
static gpointer parent_class = NULL;
-static GdkFont *static_default_font = NULL;
/* --- functions --- */
style->font_desc = pango_font_description_from_string ("Sans 10");
- if (!static_default_font)
- {
- static_default_font = gdk_font_from_description (style->font_desc);
-
- if (!static_default_font)
- static_default_font = gdk_font_load ("fixed");
-
- if (!static_default_font)
- g_error ("Unable to load \"fixed\" font");
- }
-
- style->font = static_default_font;
- gdk_font_ref (style->font);
-
style->attach_count = 0;
style->colormap = NULL;
style->depth = -1;
style->text[i] = style->fg[i];
style->base[i] = style->white;
}
-
+
+ style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
+ style->text[GTK_STATE_SELECTED] = style->black;
+ style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
+ style->text[GTK_STATE_ACTIVE] = style->black;
style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
style->mid_gc[i] = NULL;
style->text_gc[i] = NULL;
style->base_gc[i] = NULL;
+ style->text_aa_gc[i] = NULL;
}
style->xthickness = 2;
}
static void
-gtk_style_finalize (GObject *object)
+clear_property_cache (GtkStyle *style)
{
- GtkStyle *style = GTK_STYLE (object);
-
- g_return_if_fail (style->attach_count == 0);
-
if (style->property_cache)
{
guint i;
- for (i = 0; i < style->property_cache->n_nodes; i++)
+ for (i = 0; i < style->property_cache->len; i++)
{
- PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
+ PropertyValue *node = &g_array_index (style->property_cache, PropertyValue, i);
g_param_spec_unref (node->pspec);
g_value_unset (&node->value);
}
- g_bsearch_array_destroy (style->property_cache);
+ g_array_free (style->property_cache, TRUE);
style->property_cache = NULL;
}
+}
+
+static void
+gtk_style_finalize (GObject *object)
+{
+ GtkStyle *style = GTK_STYLE (object);
+
+ g_return_if_fail (style->attach_count == 0);
+
+ clear_property_cache (style);
if (style->styles)
{
g_slist_free_1 (style->styles);
}
}
-
- gdk_font_unref (style->font);
+
pango_font_description_free (style->font_desc);
+ if (style->private_font)
+ gdk_font_unref (style->private_font);
+
+ if (style->private_font_desc)
+ pango_font_description_free (style->private_font_desc);
+
if (style->rc_style)
gtk_rc_style_unref (style->rc_style);
return new_style;
}
+/**
+ * gtk_style_new:
+ * @returns: a new #GtkStyle.
+ *
+ * Creates a new #GtkStyle.
+ **/
GtkStyle*
gtk_style_new (void)
{
return style;
}
-/*************************************************************
+/**
* gtk_style_attach:
- * Attach a style to a window; this process allocates the
- * colors and creates the GC's for the style - it specializes
- * it to a particular visual and colormap. The process
- * may involve the creation of a new style if the style
- * has already been attached to a window with a different
- * style and colormap.
- * arguments:
- * style:
- * window:
- * results:
- * Either the style parameter, or a newly created style.
- * If the style is newly created, the style parameter
- * will be dereferenced, and the new style will have
- * a reference count belonging to the caller.
+ * @style: a #GtkStyle.
+ * @window: a #GtkWindow.
+ * @returns: Either @style, or a newly-created #GtkStyle.
+ * If the style is newly created, the style parameter
+ * will be dereferenced, and the new style will have
+ * a reference count belonging to the caller.
*
+ * Attaches a style to a window; this process allocates the
+ * colors and creates the GC's for the style - it specializes
+ * it to a particular visual and colormap. The process may
+ * involve the creation of a new style if the style has already
+ * been attached to a window with a different style and colormap.
+ **/
+ /*
* FIXME: The sequence -
* create a style => s1
* attach s1 to v1, c1 => s1
* passes through the linked list when attaching (one to check for
* matching styles, one to look for empty unattached styles - but
* it will almost never be longer than 2 elements.
- *************************************************************/
-
+ */
GtkStyle*
gtk_style_attach (GtkStyle *style,
GdkWindow *window)
/* A style gets a refcount from being attached */
if (new_style->attach_count == 0)
- gtk_style_ref (new_style);
+ g_object_ref (new_style);
/* Another refcount belongs to the parent */
if (style != new_style)
{
- gtk_style_unref (style);
- gtk_style_ref (new_style);
+ g_object_unref (style);
+ g_object_ref (new_style);
}
new_style->attach_count++;
gdk_colormap_unref (style->colormap);
style->colormap = NULL;
- gtk_style_unref (style);
+ g_object_unref (style);
}
}
+/**
+ * gtk_style_ref:
+ * @style: a #GtkStyle.
+ * @returns: @style.
+ *
+ * Deprecated equivalent of g_object_ref().
+ **/
GtkStyle*
gtk_style_ref (GtkStyle *style)
{
return (GtkStyle *) g_object_ref (G_OBJECT (style));
}
+/**
+ * gtk_style_unref:
+ * @style: a #GtkStyle.
+ *
+ * Deprecated equivalent of g_object_unref().
+ **/
void
gtk_style_unref (GtkStyle *style)
{
return gtk_icon_factory_lookup_default (stock_id);
}
+/**
+ * gtk_draw_hline:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @x1: the starting x coordinate
+ * @x2: the ending x coordinate
+ * @y: the y coordinate
+ *
+ * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
+ * using the given style and state.
+ *
+ * This function is deprecated, use gtk_paint_hline() instead.
+ **/
void
gtk_draw_hline (GtkStyle *style,
GdkWindow *window,
}
+/**
+ * gtk_draw_vline:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @y1: the starting y coordinate
+ * @y2: the ending y coordinate
+ * @x: the x coordinate
+ *
+ * Draws a vertical line from (@x, @y1) to (@x, @y2) in @window
+ * using the given style and state.
+ *
+ * This function is deprecated, use gtk_paint_vline() instead.
+ **/
void
gtk_draw_vline (GtkStyle *style,
GdkWindow *window,
GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
}
-
+/**
+ * gtk_draw_shadow:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: type of shadow to draw
+ * @x: x origin of the rectangle
+ * @y: y origin of the rectangle
+ * @width: width of the rectangle
+ * @height: width of the rectangle
+ *
+ * Draws a shadow around the given rectangle in @window
+ * using the given style and state and shadow type.
+ *
+ * This function is deprecated, use gtk_paint_shadow() instead.
+ */
void
gtk_draw_shadow (GtkStyle *style,
GdkWindow *window,
GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
}
+/**
+ * gtk_draw_polygon:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: type of shadow to draw
+ * @points: an array of #GdkPoint<!>s
+ * @npoints: length of @points
+ * @fill: %TRUE if the polygon should be filled
+ *
+ * Draws a polygon on @window with the given parameters.
+ *
+ * This function is deprecated, use gtk_paint_polygon() instead.
+ */
void
gtk_draw_polygon (GtkStyle *style,
GdkWindow *window,
GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
}
+/**
+ * gtk_draw_arrow:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @arrow_type: the type of arrow to draw
+ * @fill: %TRUE if the arrow tip should be filled
+ * @x: x origin of the rectangle to draw the arrow in
+ * @y: y origin of the rectangle to draw the arrow in
+ * @width: width of the rectangle to draw the arrow in
+ * @height: height of the rectangle to draw the arrow in
+ *
+ * Draws an arrow in the given rectangle on @window using the given
+ * parameters. @arrow_type determines the direction of the arrow.
+ *
+ * This function is deprecated, use gtk_paint_arrow() instead.
+ */
void
gtk_draw_arrow (GtkStyle *style,
GdkWindow *window,
GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
}
-
+/**
+ * gtk_draw_diamond:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @x: x origin of the rectangle to draw the diamond in
+ * @y: y origin of the rectangle to draw the diamond in
+ * @width: width of the rectangle to draw the diamond in
+ * @height: height of the rectangle to draw the diamond in
+ *
+ * Draws a diamond in the given rectangle on @window using the given parameters.
+ *
+ * This function is deprecated, use gtk_paint_diamond() instead.
+ */
void
gtk_draw_diamond (GtkStyle *style,
GdkWindow *window,
GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
}
-
+/**
+ * gtk_draw_string:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @x: x origin
+ * @y: y origin
+ * @string: the string to draw
+ *
+ * Draws a text string on @window with the given parameters.
+ *
+ * This function is deprecated, use gtk_paint_layout() instead.
+ */
void
gtk_draw_string (GtkStyle *style,
GdkWindow *window,
GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
}
+/**
+ * gtk_draw_box:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @x: x origin of the box
+ * @y: y origin of the box
+ * @width: the width of the box
+ * @height: the height of the box
+ *
+ * Draws a box on @window with the given parameters.
+ *
+ * This function is deprecated, use gtk_paint_box() instead.
+ */
void
gtk_draw_box (GtkStyle *style,
GdkWindow *window,
GTK_STYLE_GET_CLASS (style)->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
}
+/**
+ * gtk_draw_flat_box:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @x: x origin of the box
+ * @y: y origin of the box
+ * @width: the width of the box
+ * @height: the height of the box
+ *
+ * Draws a flat box on @window with the given parameters.
+ *
+ * This function is deprecated, use gtk_paint_flat_box() instead.
+ */
void
gtk_draw_flat_box (GtkStyle *style,
GdkWindow *window,
GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
}
+/**
+ * gtk_draw_check:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @x: x origin of the rectangle to draw the check in
+ * @y: y origin of the rectangle to draw the check in
+ * @width: the width of the rectangle to draw the check in
+ * @height: the height of the rectangle to draw the check in
+ *
+ * Draws a check button indicator in the given rectangle on @window with
+ * the given parameters.
+ *
+ * This function is deprecated, use gtk_paint_check() instead.
+ */
void
gtk_draw_check (GtkStyle *style,
GdkWindow *window,
GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
}
+/**
+ * gtk_draw_option:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @x: x origin of the rectangle to draw the option in
+ * @y: y origin of the rectangle to draw the option in
+ * @width: the width of the rectangle to draw the option in
+ * @height: the height of the rectangle to draw the option in
+ *
+ * Draws a radio button indicator in the given rectangle on @window with
+ * the given parameters.
+ *
+ * This function is deprecated, use gtk_paint_option() instead.
+ */
void
gtk_draw_option (GtkStyle *style,
GdkWindow *window,
GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
}
+/**
+ * gtk_draw_tab:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @x: x origin of the rectangle to draw the tab in
+ * @y: y origin of the rectangle to draw the tab in
+ * @width: the width of the rectangle to draw the tab in
+ * @height: the height of the rectangle to draw the tab in
+ *
+ * Draws an option menu tab (i.e. the up and down pointing arrows)
+ * in the given rectangle on @window using the given parameters.
+ *
+ * This function is deprecated, use gtk_paint_tab() instead.
+ */
void
gtk_draw_tab (GtkStyle *style,
GdkWindow *window,
GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
}
+/**
+ * gtk_draw_focus:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @x: the x origin of the rectangle around which to draw a focus indicator
+ * @y: the y origin of the rectangle around which to draw a focus indicator
+ * @width: the width of the rectangle around which to draw a focus indicator
+ * @height: the height of the rectangle around which to draw a focus indicator
+ *
+ * Draws a focus indicator around the given rectangle on @window using the
+ * given style.
+ *
+ * This function is deprecated, use gtk_paint_focus() instead.
+ */
void
gtk_draw_focus (GtkStyle *style,
GdkWindow *window,
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
- GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, NULL, NULL, NULL, x, y, width, height);
+ GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, GTK_STATE_NORMAL, NULL, NULL, NULL, x, y, width, height);
}
void
GtkStateType state_type,
gint x,
gint y,
- gboolean is_open)
+ GtkExpanderStyle expander_style)
{
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
NULL, NULL, NULL,
- x, y, is_open);
+ x, y, expander_style);
}
void
gtk_draw_layout (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
+ gboolean use_text,
gint x,
gint y,
PangoLayout *layout)
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
- GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type,
+ GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
NULL, NULL, NULL,
x, y, layout);
}
+/**
+ * gtk_draw_resize_grip:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @edge: the edge in which to draw the resize grip, currently only
+ * %GTK_WINDOW_EDGE_SOUTH_EAST is implemented
+ * @x: the x origin of the rectangle in which to draw the resize grip
+ * @y: the y origin of the rectangle in which to draw the resize grip
+ * @width: the width of the rectangle in which to draw the resize grip
+ * @height: the height of the rectangle in which to draw the resize grip
+ *
+ * Draws a resize grip in the given rectangle on @window using the given
+ * parameters.
+ *
+ * This function is deprecated, use gtk_paint_resize_grip() instead.
+ */
void
gtk_draw_resize_grip (GtkStyle *style,
GdkWindow *window,
}
+/**
+ * gtk_style_set_background:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ *
+ * Sets the background of @window to the background color or pixmap
+ * specified by @style for the given state.
+ */
void
gtk_style_set_background (GtkStyle *style,
GdkWindow *window,
style->bg_pixmap[i] = src->bg_pixmap[i];
}
- if (style->font)
- gdk_font_unref (style->font);
- style->font = src->font;
- if (style->font)
- gdk_font_ref (style->font);
+ if (style->private_font)
+ gdk_font_unref (style->private_font);
+ style->private_font = src->private_font;
+ if (style->private_font)
+ gdk_font_ref (style->private_font);
if (style->font_desc)
pango_font_description_free (style->font_desc);
gtk_rc_style_ref (src->rc_style);
/* don't copy, just clear cache */
- if (style->property_cache)
- {
- guint i;
-
- for (i = 0; i < style->property_cache->n_nodes; i++)
- {
- PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
-
- g_param_spec_unref (node->pspec);
- g_value_unset (&node->value);
- }
- g_bsearch_array_destroy (style->property_cache);
- style->property_cache = NULL;
- }
+ clear_property_cache (style);
}
static void
gtk_style_real_init_from_rc (GtkStyle *style,
GtkRcStyle *rc_style)
{
- GdkFont *old_font;
gint i;
/* cache _should_ be still empty */
- if (style->property_cache)
- {
- guint i;
-
- for (i = 0; i < style->property_cache->n_nodes; i++)
- {
- PropertyValue *node = g_bsearch_array_get_nth (style->property_cache, i);
-
- g_param_spec_unref (node->pspec);
- g_value_unset (&node->value);
- }
- g_bsearch_array_destroy (style->property_cache);
- style->property_cache = NULL;
- }
+ clear_property_cache (style);
if (rc_style->font_desc)
- {
- pango_font_description_free (style->font_desc);
- style->font_desc = pango_font_description_copy (rc_style->font_desc);
-
- old_font = style->font;
- style->font = gdk_font_from_description (style->font_desc);
- if (style->font)
- gdk_font_unref (old_font);
- else
- style->font = old_font;
- }
+ pango_font_description_merge (style->font_desc, rc_style->font_desc, TRUE);
for (i = 0; i < 5; i++)
{
{
const PropertyValue *val1 = bsearch_node1;
const PropertyValue *val2 = bsearch_node2;
- gint cmp;
- cmp = G_BSEARCH_ARRAY_CMP (val1->widget_type, val2->widget_type);
- if (cmp == 0)
- cmp = G_BSEARCH_ARRAY_CMP (val1->pspec, val2->pspec);
-
- return cmp;
+ if (val1->widget_type == val2->widget_type)
+ return val1->pspec < val2->pspec ? -1 : val1->pspec == val2->pspec ? 0 : 1;
+ else
+ return val1->widget_type < val2->widget_type ? -1 : 1;
}
const GValue*
{
PropertyValue *pcache, key = { 0, NULL, { 0, } };
const GtkRcProperty *rcprop = NULL;
+ guint i;
g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), NULL);
g_return_val_if_fail (g_type_is_a (pspec->owner_type, GTK_TYPE_WIDGET), NULL);
g_return_val_if_fail (g_type_is_a (widget_type, pspec->owner_type), NULL);
- /* need value cache array */
- if (!style->property_cache)
- style->property_cache = g_bsearch_array_new (sizeof (PropertyValue),
- style_property_values_cmp,
- 0);
- /* lookup, or insert value if not yet present */
key.widget_type = widget_type;
key.pspec = pspec;
- pcache = g_bsearch_array_insert (style->property_cache, &key, FALSE);
- if (G_VALUE_TYPE (&pcache->value))
- return &pcache->value;
+
+ /* need value cache array */
+ if (!style->property_cache)
+ style->property_cache = g_array_new (FALSE, FALSE, sizeof (PropertyValue));
+ else
+ {
+ pcache = bsearch (&key,
+ style->property_cache->data, style->property_cache->len,
+ sizeof (PropertyValue), style_property_values_cmp);
+ if (pcache)
+ return &pcache->value;
+ }
+
+ i = 0;
+ while (i < style->property_cache->len &&
+ style_property_values_cmp (&key, &g_array_index (style->property_cache, PropertyValue, i)) >= 0)
+ i++;
+
+ g_array_insert_val (style->property_cache, i, key);
+ pcache = &g_array_index (style->property_cache, PropertyValue, i);
/* cache miss, initialize value type, then set contents */
+ g_param_spec_ref (pcache->pspec);
g_value_init (&pcache->value, G_PARAM_SPEC_VALUE_TYPE (pspec));
/* value provided by rc style? */
}
/* when supplied by rc style, we need to convert */
- if (rcprop)
+ if (rcprop && !_gtk_settings_parse_convert (parser, &rcprop->value,
+ pspec, &pcache->value))
{
- if (G_VALUE_TYPE (&rcprop->value) == G_TYPE_GSTRING)
- {
- GString *gstring;
-
- /* value still unparsed, need to revert to user supplied parser function */
-
- gstring = g_value_get_boxed (&rcprop->value);
-
- if (!parser || !parser (pspec, gstring, &pcache->value) ||
- g_param_value_validate (pspec, &pcache->value))
- {
- gchar *contents = g_strescape (gstring->str, NULL);
-
- g_message ("%s: failed to parse property `%s::%s' of type `%s' from rc file value \"%s\"",
- rcprop->origin,
- g_type_name (pspec->owner_type), pspec->name,
- g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
- gstring->str);
- g_free (contents);
- rcprop = NULL;
- }
- }
- else
- {
- /* we use the normal conversion functionality of param specs */
- if (!g_param_value_convert (pspec, &rcprop->value, &pcache->value, TRUE))
- {
- gchar *contents = g_strdup_value_contents (&rcprop->value);
-
- g_message ("%s: failed to retrive property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
- rcprop->origin,
- g_type_name (pspec->owner_type), pspec->name,
- g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
- contents,
- G_VALUE_TYPE_NAME (&rcprop->value));
- g_free (contents);
- rcprop = NULL;
- }
- }
+ gchar *contents = g_strdup_value_contents (&rcprop->value);
+
+ g_message ("%s: failed to retrieve property `%s::%s' of type `%s' from rc file value \"%s\" of type `%s'",
+ rcprop->origin,
+ g_type_name (pspec->owner_type), pspec->name,
+ g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
+ contents,
+ G_VALUE_TYPE_NAME (&rcprop->value));
+ g_free (contents);
+ rcprop = NULL; /* needs default */
}
/* not supplied by rc style (or conversion failed), revert to default */
if (!rcprop)
g_param_value_set_default (pspec, &pcache->value);
- g_param_spec_ref (pcache->pspec);
-
return &pcache->value;
}
+static GdkPixmap *
+load_bg_image (GdkColormap *colormap,
+ GdkColor *bg_color,
+ const gchar *filename)
+{
+ if (strcmp (filename, "<parent>") == 0)
+ return (GdkPixmap*) GDK_PARENT_RELATIVE;
+ else
+ {
+ return gdk_pixmap_colormap_create_from_xpm (NULL, colormap, NULL,
+ bg_color,
+ filename);
+ }
+}
+
static void
gtk_style_real_realize (GtkStyle *style)
{
style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
+
+ style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
+ style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
+ style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
}
gdk_color_black (style->colormap, &style->black);
gdk_color_white (style->colormap, &style->white);
- gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_FONT;
- if (style->font->type == GDK_FONT_FONT)
- {
- gc_values.font = style->font;
- }
- else if (style->font->type == GDK_FONT_FONTSET)
- {
- gc_values.font = static_default_font;
- }
+ gc_values_mask = GDK_GC_FOREGROUND;
gc_values.foreground = style->black;
style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
for (i = 0; i < 5; i++)
{
if (style->rc_style && style->rc_style->bg_pixmap_name[i])
- style->bg_pixmap[i] = gtk_rc_load_image (style->colormap,
- &style->bg[i],
- style->rc_style->bg_pixmap_name[i]);
+ style->bg_pixmap[i] = load_bg_image (style->colormap,
+ &style->bg[i],
+ style->rc_style->bg_pixmap_name[i]);
if (!gdk_color_alloc (style->colormap, &style->fg[i]))
g_warning ("unable to allocate color: ( %d %d %d )",
if (!gdk_color_alloc (style->colormap, &style->base[i]))
g_warning ("unable to allocate color: ( %d %d %d )",
style->base[i].red, style->base[i].green, style->base[i].blue);
+ if (!gdk_color_alloc (style->colormap, &style->text_aa[i]))
+ g_warning ("unable to allocate color: ( %d %d %d )",
+ style->text_aa[i].red, style->text_aa[i].green, style->text_aa[i].blue);
gc_values.foreground = style->fg[i];
style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
gc_values.foreground = style->base[i];
style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
+
+ gc_values.foreground = style->text_aa[i];
+ style->text_aa_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
}
}
gtk_gc_release (style->mid_gc[i]);
gtk_gc_release (style->text_gc[i]);
gtk_gc_release (style->base_gc[i]);
+ gtk_gc_release (style->text_aa_gc[i]);
if (style->bg_pixmap[i] && style->bg_pixmap[i] != (GdkPixmap*) GDK_PARENT_RELATIVE)
gdk_pixmap_unref (style->bg_pixmap[i]);
gdk_colormap_free_colors (style->colormap, style->mid, 5);
gdk_colormap_free_colors (style->colormap, style->text, 5);
gdk_colormap_free_colors (style->colormap, style->base, 5);
+ gdk_colormap_free_colors (style->colormap, style->text_aa, 5);
}
static void
gdk_window_set_background (window, &style->bg[state_type]);
}
+/**
+ * gtk_style_render_icon:
+ * @style: a #GtkStyle
+ * @source: the #GtkIconSource specifying the icon to render
+ * @direction: a text direction
+ * @state: a state
+ * @size: the size to render the icon at
+ * @widget: the widget
+ * @detail: a style detail
+ * @returns: a newly-created #GdkPixbuf containing the rendered icon
+ *
+ * Renders the icon specified by @source at the given @size
+ * according to the given parameters and returns the result in a
+ * pixbuf.
+ */
GdkPixbuf *
gtk_style_render_icon (GtkStyle *style,
const GtkIconSource *source,
return stated;
}
+static void
+sanitize_size (GdkWindow *window,
+ gint *width,
+ gint *height)
+{
+ if ((*width == -1) && (*height == -1))
+ gdk_window_get_size (window, width, height);
+ else if (*width == -1)
+ gdk_window_get_size (window, width, NULL);
+ else if (*height == -1)
+ gdk_window_get_size (window, NULL, height);
+}
+
+static void
+draw_part (GdkDrawable *drawable,
+ GdkGC *gc,
+ GdkRectangle *area,
+ gint x,
+ gint y,
+ IndicatorPart part)
+{
+ if (area)
+ gdk_gc_set_clip_rectangle (gc, area);
+
+ if (!indicator_parts[part].bmap)
+ indicator_parts[part].bmap = gdk_bitmap_create_from_data (drawable,
+ indicator_parts[part].bits,
+ INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
+
+ gdk_gc_set_ts_origin (gc, x, y);
+ gdk_gc_set_stipple (gc, indicator_parts[part].bmap);
+ gdk_gc_set_fill (gc, GDK_STIPPLED);
+
+ gdk_draw_rectangle (drawable, gc, TRUE, x, y, INDICATOR_PART_SIZE, INDICATOR_PART_SIZE);
+
+ gdk_gc_set_fill (gc, GDK_SOLID);
+
+ if (area)
+ gdk_gc_set_clip_rectangle (gc, NULL);
+}
+
static void
gtk_default_draw_hline (GtkStyle *style,
GdkWindow *window,
}
+void
+draw_thin_shadow (GtkStyle *style,
+ GdkWindow *window,
+ GtkStateType state,
+ GdkRectangle *area,
+ gint x,
+ gint y,
+ gint width,
+ gint height)
+{
+ GdkGC *gc1, *gc2;
+
+ sanitize_size (window, &width, &height);
+
+ gc1 = style->light_gc[state];
+ gc2 = style->dark_gc[state];
+
+ if (area)
+ {
+ gdk_gc_set_clip_rectangle (gc1, area);
+ gdk_gc_set_clip_rectangle (gc2, area);
+ }
+
+ gdk_draw_line (window, gc1,
+ x, y + height - 1, x + width - 1, y + height - 1);
+ gdk_draw_line (window, gc1,
+ x + width - 1, y, x + width - 1, y + height - 1);
+
+ gdk_draw_line (window, gc2,
+ x, y, x + width - 1, y);
+ gdk_draw_line (window, gc2,
+ x, y, x, y + height - 1);
+
+ if (area)
+ {
+ gdk_gc_set_clip_rectangle (gc1, NULL);
+ gdk_gc_set_clip_rectangle (gc2, NULL);
+ }
+}
+
+void
+draw_spin_entry_shadow (GtkStyle *style,
+ GdkWindow *window,
+ GtkStateType state,
+ GdkRectangle *area,
+ gint x,
+ gint y,
+ gint width,
+ gint height)
+{
+ gint window_width, window_height;
+ gboolean focus_inset;
+
+ gdk_window_get_size (window, &window_width, &window_height);
+
+ if (width == -1)
+ width = window_width;
+ if (height == 1)
+ height = window_height;
+
+ focus_inset = (width < window_width && height < window_height);
+
+ if (area)
+ {
+ gdk_gc_set_clip_rectangle (style->light_gc[state], area);
+ gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
+ gdk_gc_set_clip_rectangle (style->black_gc, area);
+ gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
+ gdk_gc_set_clip_rectangle (style->base_gc[state], area);
+ }
+
+ gdk_draw_line (window, style->light_gc[state],
+ x, y + height - 1, x + width - 1, y + height - 1);
+
+ gdk_draw_line (window,
+ style->base_gc[state],
+ x + width - 1, y + 1, x + width - 1, y + height - 3);
+
+ if (!focus_inset)
+ {
+ gdk_draw_line (window, style->bg_gc[state],
+ x + 1, y + height - 2, x + width - 1, y + height - 2);
+ gdk_draw_line (window,
+ style->base_gc[state],
+ x + width - 2, y + 1, x + width - 2, y + height - 3);
+
+ gdk_draw_line (window, style->black_gc,
+ x + 1, y + 1, x + width - 1, y + 1);
+ gdk_draw_line (window, style->black_gc,
+ x + 1, y + 1, x + 1, y + height - 2);
+ }
+
+ gdk_draw_line (window, style->dark_gc[state],
+ x, y, x + width - 1, y);
+ gdk_draw_line (window, style->dark_gc[state],
+ x, y, x, y + height - 1);
+
+ if (area)
+ {
+ gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
+ gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
+ gdk_gc_set_clip_rectangle (style->black_gc, NULL);
+ gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
+ gdk_gc_set_clip_rectangle (style->base_gc[state], NULL);
+ }
+}
+
+static void
+draw_spinbutton_shadow (GtkStyle *style,
+ GdkWindow *window,
+ GtkStateType state,
+ GdkRectangle *area,
+ gint x,
+ gint y,
+ gint width,
+ gint height)
+{
+ gint y_middle = y + height / 2;
+
+ sanitize_size (window, &width, &height);
+
+ if (area)
+ {
+ gdk_gc_set_clip_rectangle (style->black_gc, area);
+ gdk_gc_set_clip_rectangle (style->bg_gc[state], area);
+ gdk_gc_set_clip_rectangle (style->dark_gc[state], area);
+ gdk_gc_set_clip_rectangle (style->light_gc[state], area);
+ }
+
+ gdk_draw_line (window, style->black_gc,
+ x, y + 2, x, y + height - 3);
+ gdk_draw_line (window, style->black_gc,
+ x, y + 1, x + width - 2, y + 1);
+ gdk_draw_line (window, style->black_gc,
+ x + width - 2, y + 2, x + width - 2, y + height - 3);
+
+ gdk_draw_line (window, style->bg_gc[state],
+ x, y + height - 2, x + width - 2, y + height - 2);
+
+ gdk_draw_line (window, style->dark_gc[state],
+ x, y, x + width - 1, y);
+ gdk_draw_line (window, style->dark_gc[state],
+ x + 1, y_middle - 1, x + width - 3, y_middle - 1);
+ gdk_draw_line (window, style->dark_gc[state],
+ x + 1, y + height - 3, x + width - 3, y + height - 3);
+
+ gdk_draw_line (window, style->light_gc[state],
+ x + 1, y + 2, x + width - 3, y + 2);
+ gdk_draw_line (window, style->light_gc[state],
+ x + 1, y_middle, x + width - 3, y_middle);
+ gdk_draw_line (window, style->light_gc[state],
+ x + width - 1, y + 1, x + width - 1, y + height - 1);
+ gdk_draw_line (window, style->light_gc[state],
+ x, y + height - 1, x + width - 2, y + height - 1);
+
+ if (area)
+ {
+ gdk_gc_set_clip_rectangle (style->black_gc, NULL);
+ gdk_gc_set_clip_rectangle (style->bg_gc[state], NULL);
+ gdk_gc_set_clip_rectangle (style->dark_gc[state], NULL);
+ gdk_gc_set_clip_rectangle (style->light_gc[state], NULL);
+ }
+}
+
static void
gtk_default_draw_shadow (GtkStyle *style,
GdkWindow *window,
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (window != NULL);
+
+ if (shadow_type == GTK_SHADOW_IN)
+ {
+ if (detail && (strcmp (detail, "buttondefault") == 0))
+ {
+ sanitize_size (window, &width, &height);
+
+ gdk_draw_rectangle (window, style->black_gc, FALSE,
+ x, y, width - 1, height - 1);
+
+ return;
+ }
+ if (detail && strcmp (detail, "trough") == 0)
+ {
+ draw_thin_shadow (style, window, state_type, area,
+ x, y, width, height);
+ return;
+ }
+ else if (widget && GTK_IS_SPIN_BUTTON (widget) &&
+ detail && strcmp (detail, "entry") == 0)
+ {
+ draw_spin_entry_shadow (style, window, state_type, area,
+ x, y, width, height);
+ return;
+ }
+ else if (widget && GTK_IS_SPIN_BUTTON (widget) &&
+ detail && strcmp (detail, "spinbutton") == 0)
+ {
+ draw_spinbutton_shadow (style, window, state_type,
+ area, x, y, width, height);
+ return;
+ }
+ }
- if ((width == -1) && (height == -1))
- gdk_window_get_size (window, &width, &height);
- else if (width == -1)
- gdk_window_get_size (window, &width, NULL);
- else if (height == -1)
- gdk_window_get_size (window, NULL, &height);
+ sanitize_size (window, &width, &height);
switch (shadow_type)
{
break;
case GTK_SHADOW_IN:
- gdk_draw_line (window, gc1,
- x, y + height - 1, x + width - 1, y + height - 1);
- gdk_draw_line (window, gc1,
- x + width - 1, y, x + width - 1, y + height - 1);
-
- gdk_draw_line (window, style->bg_gc[state_type],
- x + 1, y + height - 2, x + width - 2, y + height - 2);
- gdk_draw_line (window, style->bg_gc[state_type],
- x + width - 2, y + 1, x + width - 2, y + height - 2);
-
- gdk_draw_line (window, style->black_gc,
- x + 1, y + 1, x + width - 2, y + 1);
- gdk_draw_line (window, style->black_gc,
- x + 1, y + 1, x + 1, y + height - 2);
-
- gdk_draw_line (window, gc2,
- x, y, x + width - 1, y);
- gdk_draw_line (window, gc2,
- x, y, x, y + height - 1);
+ /* Light around right and bottom edge */
+
+ if (style->ythickness > 0)
+ gdk_draw_line (window, gc1,
+ x, y + height - 1, x + width - 1, y + height - 1);
+ if (style->xthickness > 0)
+ gdk_draw_line (window, gc1,
+ x + width - 1, y, x + width - 1, y + height - 1);
+
+ if (style->ythickness > 1)
+ gdk_draw_line (window, style->bg_gc[state_type],
+ x + 1, y + height - 2, x + width - 2, y + height - 2);
+ if (style->xthickness > 1)
+ gdk_draw_line (window, style->bg_gc[state_type],
+ x + width - 2, y + 1, x + width - 2, y + height - 2);
+
+ /* Dark around left and top */
+
+ if (style->ythickness > 1)
+ gdk_draw_line (window, style->black_gc,
+ x + 1, y + 1, x + width - 2, y + 1);
+ if (style->xthickness > 1)
+ gdk_draw_line (window, style->black_gc,
+ x + 1, y + 1, x + 1, y + height - 2);
+
+ if (style->ythickness > 0)
+ gdk_draw_line (window, gc2,
+ x, y, x + width - 1, y);
+ if (style->xthickness > 0)
+ gdk_draw_line (window, gc2,
+ x, y, x, y + height - 1);
break;
case GTK_SHADOW_OUT:
- gdk_draw_line (window, gc1,
- x + 1, y + height - 2, x + width - 2, y + height - 2);
- gdk_draw_line (window, gc1,
- x + width - 2, y + 1, x + width - 2, y + height - 2);
-
- gdk_draw_line (window, gc2,
- x, y, x + width - 1, y);
- gdk_draw_line (window, gc2,
- x, y, x, y + height - 1);
-
- gdk_draw_line (window, style->bg_gc[state_type],
- x + 1, y + 1, x + width - 2, y + 1);
- gdk_draw_line (window, style->bg_gc[state_type],
- x + 1, y + 1, x + 1, y + height - 2);
+ /* Dark around right and bottom edge */
+
+ if (style->ythickness > 0)
+ {
+ if (style->ythickness > 1)
+ {
+ gdk_draw_line (window, gc1,
+ x + 1, y + height - 2, x + width - 2, y + height - 2);
+ gdk_draw_line (window, style->black_gc,
+ x, y + height - 1, x + width - 1, y + height - 1);
+ }
+ else
+ {
+ gdk_draw_line (window, gc1,
+ x + 1, y + height - 1, x + width - 1, y + height - 1);
+ }
+ }
+
+ if (style->xthickness > 0)
+ {
+ if (style->xthickness > 1)
+ {
+ gdk_draw_line (window, gc1,
+ x + width - 2, y + 1, x + width - 2, y + height - 2);
+
+ gdk_draw_line (window, style->black_gc,
+ x + width - 1, y, x + width - 1, y + height - 1);
+ }
+ else
+ {
+ gdk_draw_line (window, gc1,
+ x + width - 1, y + 1, x + width - 1, y + height - 1);
+ }
+ }
- gdk_draw_line (window, style->black_gc,
- x, y + height - 1, x + width - 1, y + height - 1);
- gdk_draw_line (window, style->black_gc,
- x + width - 1, y, x + width - 1, y + height - 1);
+ /* Light around top and left */
+
+ if (style->ythickness > 0)
+ gdk_draw_line (window, gc2,
+ x, y, x + width - 1, y);
+ if (style->xthickness > 0)
+ gdk_draw_line (window, gc2,
+ x, y, x, y + height - 1);
+
+ if (style->ythickness > 1)
+ gdk_draw_line (window, style->bg_gc[state_type],
+ x + 1, y + 1, x + width - 2, y + 1);
+ if (style->xthickness > 1)
+ gdk_draw_line (window, style->bg_gc[state_type],
+ x + 1, y + 1, x + 1, y + height - 2);
break;
case GTK_SHADOW_ETCHED_IN:
case GTK_SHADOW_ETCHED_OUT:
- thickness_light = 1;
- thickness_dark = 1;
+ if (style->xthickness > 0)
+ {
+ if (style->xthickness > 1)
+ {
+ thickness_light = 1;
+ thickness_dark = 1;
- for (i = 0; i < thickness_dark; i++)
+ for (i = 0; i < thickness_dark; i++)
+ {
+ gdk_draw_line (window, gc1,
+ x + width - i - 1,
+ y + i,
+ x + width - i - 1,
+ y + height - i - 1);
+ gdk_draw_line (window, gc2,
+ x + i,
+ y + i,
+ x + i,
+ y + height - i - 2);
+ }
+
+ for (i = 0; i < thickness_light; i++)
+ {
+ gdk_draw_line (window, gc1,
+ x + thickness_dark + i,
+ y + thickness_dark + i,
+ x + thickness_dark + i,
+ y + height - thickness_dark - i - 1);
+ gdk_draw_line (window, gc2,
+ x + width - thickness_light - i - 1,
+ y + thickness_dark + i,
+ x + width - thickness_light - i - 1,
+ y + height - thickness_light - 1);
+ }
+ }
+ else
+ {
+ gdk_draw_line (window,
+ style->dark_gc[state_type],
+ x, y, x, y + height);
+ gdk_draw_line (window,
+ style->dark_gc[state_type],
+ x + width, y, x + width, y + height);
+ }
+ }
+
+ if (style->ythickness > 0)
{
- gdk_draw_line (window, gc1,
- x + i,
- y + height - i - 1,
- x + width - i - 1,
- y + height - i - 1);
- gdk_draw_line (window, gc1,
- x + width - i - 1,
- y + i,
- x + width - i - 1,
- y + height - i - 1);
+ if (style->ythickness > 1)
+ {
+ thickness_light = 1;
+ thickness_dark = 1;
+
+ for (i = 0; i < thickness_dark; i++)
+ {
+ gdk_draw_line (window, gc1,
+ x + i,
+ y + height - i - 1,
+ x + width - i - 1,
+ y + height - i - 1);
- gdk_draw_line (window, gc2,
- x + i,
- y + i,
- x + width - i - 2,
- y + i);
- gdk_draw_line (window, gc2,
- x + i,
- y + i,
- x + i,
- y + height - i - 2);
- }
+ gdk_draw_line (window, gc2,
+ x + i,
+ y + i,
+ x + width - i - 2,
+ y + i);
+ }
- for (i = 0; i < thickness_light; i++)
- {
- gdk_draw_line (window, gc1,
- x + thickness_dark + i,
- y + thickness_dark + i,
- x + width - thickness_dark - i - 1,
- y + thickness_dark + i);
- gdk_draw_line (window, gc1,
- x + thickness_dark + i,
- y + thickness_dark + i,
- x + thickness_dark + i,
- y + height - thickness_dark - i - 1);
+ for (i = 0; i < thickness_light; i++)
+ {
+ gdk_draw_line (window, gc1,
+ x + thickness_dark + i,
+ y + thickness_dark + i,
+ x + width - thickness_dark - i - 1,
+ y + thickness_dark + i);
- gdk_draw_line (window, gc2,
- x + thickness_dark + i,
- y + height - thickness_light - i - 1,
- x + width - thickness_light - 1,
- y + height - thickness_light - i - 1);
- gdk_draw_line (window, gc2,
- x + width - thickness_light - i - 1,
- y + thickness_dark + i,
- x + width - thickness_light - i - 1,
- y + height - thickness_light - 1);
+ gdk_draw_line (window, gc2,
+ x + thickness_dark + i,
+ y + height - thickness_light - i - 1,
+ x + width - thickness_light - 1,
+ y + height - thickness_light - i - 1);
+ }
+ }
+ else
+ {
+ gdk_draw_line (window,
+ style->dark_gc[state_type],
+ x, y, x + width, y);
+ gdk_draw_line (window,
+ style->dark_gc[state_type],
+ x, y + height, x + width, y + height);
+ }
}
+
break;
}
if (area)
}
static void
-gtk_default_draw_arrow (GtkStyle *style,
- GdkWindow *window,
- GtkStateType state_type,
- GtkShadowType shadow_type,
- GdkRectangle *area,
- GtkWidget *widget,
- const gchar *detail,
- GtkArrowType arrow_type,
- gboolean fill,
- gint x,
- gint y,
- gint width,
- gint height)
+draw_varrow (GdkWindow *window,
+ GdkGC *gc,
+ GtkShadowType shadow_type,
+ GdkRectangle *area,
+ GtkArrowType arrow_type,
+ gint x,
+ gint y,
+ gint width,
+ gint height)
{
- GdkGC *gc1;
- GdkGC *gc2;
- GdkGC *gc3;
- GdkGC *gc4;
- gint half_width;
- gint half_height;
- GdkPoint points[3];
+ gint steps, extra;
+ gint y_start, y_increment;
+ gint i;
+
+ if (area)
+ gdk_gc_set_clip_rectangle (gc, area);
- g_return_if_fail (GTK_IS_STYLE (style));
- g_return_if_fail (window != NULL);
+ width = width + width % 2 - 1; /* Force odd */
- switch (shadow_type)
+ steps = 1 + width / 2;
+
+ extra = height - steps;
+
+ if (arrow_type == GTK_ARROW_DOWN)
{
- case GTK_SHADOW_IN:
- gc1 = style->bg_gc[state_type];
- gc2 = style->dark_gc[state_type];
- gc3 = style->light_gc[state_type];
- gc4 = style->black_gc;
- break;
- case GTK_SHADOW_OUT:
- gc1 = style->dark_gc[state_type];
- gc2 = style->light_gc[state_type];
- gc3 = style->black_gc;
- gc4 = style->bg_gc[state_type];
- break;
- case GTK_SHADOW_ETCHED_IN:
- gc1 = style->light_gc[state_type];
- gc2 = style->dark_gc[state_type];
- gc3 = NULL;
- gc4 = NULL;
- break;
- case GTK_SHADOW_ETCHED_OUT:
- gc1 = style->dark_gc[state_type];
- gc2 = style->light_gc[state_type];
- gc3 = NULL;
- gc4 = NULL;
- break;
- default:
- return;
+ y_start = y;
+ y_increment = 1;
+ }
+ else
+ {
+ y_start = y + height - 1;
+ y_increment = -1;
+ }
+
+ for (i = 0; i < extra; i++)
+ {
+ gdk_draw_line (window, gc,
+ x, y_start + i * y_increment,
+ x + width - 1, y_start + i * y_increment);
+ }
+ for (; i < height; i++)
+ {
+ gdk_draw_line (window, gc,
+ x + (i - extra), y_start + i * y_increment,
+ x + width - (i - extra) - 1, y_start + i * y_increment);
}
- if ((width == -1) && (height == -1))
- gdk_window_get_size (window, &width, &height);
- else if (width == -1)
- gdk_window_get_size (window, &width, NULL);
- else if (height == -1)
- gdk_window_get_size (window, NULL, &height);
+
+ if (area)
+ gdk_gc_set_clip_rectangle (gc, NULL);
+}
+
+static void
+draw_harrow (GdkWindow *window,
+ GdkGC *gc,
+ GtkShadowType shadow_type,
+ GdkRectangle *area,
+ GtkArrowType arrow_type,
+ gint x,
+ gint y,
+ gint width,
+ gint height)
+{
+ gint steps, extra;
+ gint x_start, x_increment;
+ gint i;
+
+ if (area)
+ gdk_gc_set_clip_rectangle (gc, area);
- half_width = width / 2;
- half_height = height / 2;
+ height = height + height % 2 - 1; /* Force odd */
- if (area)
+ steps = 1 + height / 2;
+
+ extra = width - steps;
+
+ if (arrow_type == GTK_ARROW_RIGHT)
{
- gdk_gc_set_clip_rectangle (gc1, area);
- gdk_gc_set_clip_rectangle (gc2, area);
- if ((gc3) && (gc4))
- {
- gdk_gc_set_clip_rectangle (gc3, area);
- gdk_gc_set_clip_rectangle (gc4, area);
- }
+ x_start = x;
+ x_increment = 1;
}
-
- switch (arrow_type)
+ else
{
- case GTK_ARROW_UP:
- if (fill)
- {
- points[0].x = x + half_width;
- points[0].y = y;
- points[1].x = x;
- points[1].y = y + height - 1;
- points[2].x = x + width - 1;
- points[2].y = y + height - 1;
-
- gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
- }
-
- switch (shadow_type)
- {
- case GTK_SHADOW_IN:
- case GTK_SHADOW_OUT:
-
- gdk_draw_line (window, gc1,
- x + 1, y + height - 2,
- x + width - 2, y + height - 2);
- gdk_draw_line (window, gc3,
- x + 0, y + height - 1,
- x + width - 1, y + height - 1);
-
- gdk_draw_line (window, gc1,
- x + width - 2, y + height - 1,
- x + half_width, y + 1);
- gdk_draw_line (window, gc3,
- x + width - 1, y + height - 1,
- x + half_width, y);
-
- gdk_draw_line (window, gc4,
- x + half_width, y + 1,
- x + 1, y + height - 1);
- gdk_draw_line (window, gc2,
- x + half_width, y,
- x, y + height - 1);
- break;
-
- case GTK_SHADOW_ETCHED_IN:
- case GTK_SHADOW_ETCHED_OUT:
- gdk_draw_line (window, gc1,
- x + half_width, y + 1,
- x + 1, y + height - 1);
- gdk_draw_line (window, gc1,
- x + 1, y + height - 1,
- x + width - 1, y + height - 1);
- gdk_draw_line (window, gc1,
- x + width - 1, y + height - 1,
- x + half_width + 1, y + 1);
-
- points[0].x = x + half_width;
- points[0].y = y;
- points[1].x = x;
- points[1].y = y + height - 2;
- points[2].x = x + width - 2;
- points[2].y = y + height - 2;
-
- gdk_draw_polygon (window, gc2, FALSE, points, 3);
- break;
-
- default:
- break;
- }
- break;
-
- case GTK_ARROW_DOWN:
- if (fill)
- {
- points[0].x = x + width - 1;
- points[0].y = y;
- points[1].x = x;
- points[1].y = y;
- points[2].x = x + half_width;
- points[2].y = y + height - 1;
-
- gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
- }
- switch (shadow_type)
- {
- case GTK_SHADOW_IN:
- case GTK_SHADOW_OUT:
- gdk_draw_line (window, gc4,
- x + width - 2,
- y + 1, x + 1, y + 1);
- gdk_draw_line (window, gc2,
- x + width - 1, y,
- x, y);
-
- gdk_draw_line (window, gc4,
- x + 1, y,
- x + half_width, y + height - 2);
- gdk_draw_line (window, gc2,
- x, y,
- x + half_width, y + height - 1);
-
- gdk_draw_line (window, gc1,
- x + half_width, y + height - 2,
- x + width - 2, y);
- gdk_draw_line (window, gc3,
- x + half_width, y + height - 1,
- x + width - 1, y);
- break;
-
- case GTK_SHADOW_ETCHED_IN:
- case GTK_SHADOW_ETCHED_OUT:
- gdk_draw_line (window, gc1,
- x + width - 1, y + 1,
- x + 1, y + 1);
- gdk_draw_line (window, gc1,
- x + 1, y + 1,
- x + half_width + 1, y + height - 1);
- gdk_draw_line (window, gc1,
- x + half_width + 1, y + height - 2,
- x + width - 1, y);
-
- points[0].x = x + width - 2;
- points[0].y = y;
- points[1].x = x;
- points[1].y = y;
- points[2].x = x + half_width;
- points[2].y = y + height - 2;
-
- gdk_draw_polygon (window, gc2, FALSE, points, 3);
- break;
-
- default:
- break;
- }
- break;
- case GTK_ARROW_LEFT:
- if (fill)
- {
- points[0].x = x;
- points[0].y = y + half_height;
- points[1].x = x + width - 1;
- points[1].y = y + height - 1;
- points[2].x = x + width - 1;
- points[2].y = y;
-
- gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
- }
-
- switch (shadow_type)
- {
- case GTK_SHADOW_IN:
- case GTK_SHADOW_OUT:
- gdk_draw_line (window, gc1,
- x + 1, y + half_height,
- x + width - 1, y + height - 1);
- gdk_draw_line (window, gc3,
- x, y + half_height,
- x + width - 1, y + height - 1);
-
- gdk_draw_line (window, gc1,
- x + width - 2, y + height - 1,
- x + width - 2, y + 1);
- gdk_draw_line (window, gc3,
- x + width - 1, y + height - 1,
- x + width - 1, y);
-
- gdk_draw_line (window, gc4,
- x + width - 1, y + 1,
- x + 1, y + half_height);
- gdk_draw_line (window, gc2,
- x + width - 1, y,
- x, y + half_height);
- break;
-
- case GTK_SHADOW_ETCHED_IN:
- case GTK_SHADOW_ETCHED_OUT:
- gdk_draw_line (window, gc1,
- x + width - 1, y + 1,
- x + 1, y + half_height);
- gdk_draw_line (window, gc1,
- x + 1, y + half_height + 1,
- x + width - 1, y + height - 1);
- gdk_draw_line (window, gc1,
- x + width - 1, y + height - 1,
- x + width - 1, y + 1);
-
- points[0].x = x + width - 2;
- points[0].y = y;
- points[1].x = x;
- points[1].y = y + half_height;
- points[2].x = x + width - 2;
- points[2].y = y + height - 2;
-
- gdk_draw_polygon (window, gc2, FALSE, points, 3);
- break;
-
- default:
- break;
- }
- break;
- case GTK_ARROW_RIGHT:
- if (fill)
- {
- points[0].x = x + width - 1;
- points[0].y = y + half_height;
- points[1].x = x;
- points[1].y = y;
- points[2].x = x;
- points[2].y = y + height - 1;
-
- gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, 3);
- }
-
- switch (shadow_type)
- {
- case GTK_SHADOW_IN:
- case GTK_SHADOW_OUT:
- gdk_draw_line (window, gc4,
- x + width - 1, y + half_height,
- x + 1, y + 1);
- gdk_draw_line (window, gc2,
- x + width - 1, y + half_height,
- x, y);
- gdk_draw_line (window, gc4,
- x + 1, y + 1,
- x + 1, y + height - 2);
- gdk_draw_line (window, gc2,
- x, y,
- x, y + height - 1);
-
- gdk_draw_line (window, gc1,
- x + 1, y + height - 2,
- x + width - 1, y + half_height);
- gdk_draw_line (window, gc3,
- x, y + height - 1,
- x + width - 1, y + half_height);
- break;
-
- case GTK_SHADOW_ETCHED_IN:
- case GTK_SHADOW_ETCHED_OUT:
- gdk_draw_line (window, gc1,
- x + width - 1, y + half_height + 1,
- x + 1, y + 1);
- gdk_draw_line (window, gc1,
- x + 1, y + 1,
- x + 1, y + height - 1);
- gdk_draw_line (window, gc1,
- x + 1, y + height - 1,
- x + width - 1, y + half_height + 1);
-
- points[0].x = x + width - 2;
- points[0].y = y + half_height;
- points[1].x = x;
- points[1].y = y;
- points[2].x = x;
- points[2].y = y + height - 1;
-
- gdk_draw_polygon (window, gc2, FALSE, points, 3);
- break;
-
- default:
- break;
- }
- break;
+ x_start = x + width - 1;
+ x_increment = -1;
}
+ for (i = 0; i < extra; i++)
+ {
+ gdk_draw_line (window, gc,
+ x_start + i * x_increment, y,
+ x_start + i * x_increment, y + height - 1);
+ }
+ for (; i < width; i++)
+ {
+ gdk_draw_line (window, gc,
+ x_start + i * x_increment, y + (i - extra),
+ x_start + i * x_increment, y + height - (i - extra) - 1);
+ }
+
+
if (area)
+ gdk_gc_set_clip_rectangle (gc, NULL);
+}
+
+static void
+gtk_default_draw_arrow (GtkStyle *style,
+ GdkWindow *window,
+ GtkStateType state,
+ GtkShadowType shadow,
+ GdkRectangle *area,
+ GtkWidget *widget,
+ const gchar *detail,
+ GtkArrowType arrow_type,
+ gboolean fill,
+ gint x,
+ gint y,
+ gint width,
+ gint height)
+{
+ sanitize_size (window, &width, &height);
+
+ if (detail && strcmp (detail, "spinbutton") == 0)
{
- gdk_gc_set_clip_rectangle (gc1, NULL);
- gdk_gc_set_clip_rectangle (gc2, NULL);
- if (gc3)
- {
- gdk_gc_set_clip_rectangle (gc3, NULL);
- gdk_gc_set_clip_rectangle (gc4, NULL);
- }
+ int hpad, vpad;
+ int my_height = height;
+ int my_width = width;
+ int vpad_add = 0;
+
+ if (my_height > my_width)
+ {
+ vpad_add = (my_height - my_width) / 2;
+ my_height = my_width;
+ }
+
+ hpad = my_width / 4;
+
+ if (hpad < 4)
+ hpad = 4;
+
+ vpad = 2 * hpad - 1;
+
+ x += hpad / 2;
+ y += vpad / 2;
+
+ y += vpad_add;
+
+ draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
+ x, y, my_width - hpad, my_height - vpad);
+ }
+ else if (detail && strcmp (detail, "vscrollbar") == 0)
+ {
+ gtk_paint_box (style, window, state, shadow, area,
+ widget, detail, x, y, width, height);
+
+ x += (width - 7) / 2;
+ y += (height - 5) / 2;
+
+ draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
+ x, y, 7, 5);
+ }
+ else if (detail && strcmp (detail, "hscrollbar") == 0)
+ {
+ gtk_paint_box (style, window, state, shadow, area,
+ widget, detail, x, y, width, height);
+
+ y += (height - 7) / 2;
+ x += (width - 5) / 2;
+
+ draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
+ x, y, 5, 7);
+ }
+ else
+ {
+ if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
+ {
+ x += (width - 7) / 2;
+ y += (height - 5) / 2;
+
+ draw_varrow (window, style->fg_gc[state], shadow, area, arrow_type,
+ x, y, 7, 5);
+ }
+ else
+ {
+ x += (width - 5) / 2;
+ y += (height - 7) / 2;
+
+ draw_harrow (window, style->fg_gc[state], shadow, area, arrow_type,
+ x, y, 5, 7);
+ }
}
}
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (window != NULL);
- if ((width == -1) && (height == -1))
- gdk_window_get_size (window, &width, &height);
- else if (width == -1)
- gdk_window_get_size (window, &width, NULL);
- else if (height == -1)
- gdk_window_get_size (window, NULL, &height);
+ sanitize_size (window, &width, &height);
half_width = width / 2;
half_height = height / 2;
}
if (state_type == GTK_STATE_INSENSITIVE)
- gdk_draw_string (window, style->font, style->white_gc, x + 1, y + 1, string);
+ gdk_draw_string (window, gtk_style_get_font (style), style->white_gc, x + 1, y + 1, string);
- gdk_draw_string (window, style->font, style->fg_gc[state_type], x, y, string);
+ gdk_draw_string (window, gtk_style_get_font (style), style->fg_gc[state_type], x, y, string);
if (area)
{
}
}
+static void
+option_menu_get_props (GtkWidget *widget,
+ GtkRequisition *indicator_size,
+ GtkBorder *indicator_spacing)
+{
+ GtkRequisition *tmp_size = NULL;
+ GtkBorder *tmp_spacing = NULL;
+
+ if (widget)
+ gtk_widget_style_get (widget,
+ "indicator_size", &tmp_size,
+ "indicator_spacing", &tmp_spacing,
+ NULL);
+
+ if (tmp_size)
+ {
+ *indicator_size = *tmp_size;
+ g_free (tmp_size);
+ }
+ else
+ *indicator_size = default_option_indicator_size;
+
+ if (tmp_spacing)
+ {
+ *indicator_spacing = *tmp_spacing;
+ g_free (tmp_spacing);
+ }
+ else
+ *indicator_spacing = default_option_indicator_spacing;
+}
+
static void
gtk_default_draw_box (GtkStyle *style,
GdkWindow *window,
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (window != NULL);
- if (width == -1 && height == -1)
- gdk_window_get_size (window, &width, &height);
- else if (width == -1)
- gdk_window_get_size (window, &width, NULL);
- else if (height == -1)
- gdk_window_get_size (window, NULL, &height);
+ sanitize_size (window, &width, &height);
if (!style->bg_pixmap[state_type] ||
GDK_IS_PIXMAP (window))
gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
x, y, width, height);
+
+ if (detail && strcmp (detail, "optionmenu") == 0)
+ {
+ GtkRequisition indicator_size;
+ GtkBorder indicator_spacing;
+
+ option_menu_get_props (widget, &indicator_size, &indicator_spacing);
+
+ sanitize_size (window, &width, &height);
+
+ gtk_paint_vline (style, window, state_type, area, widget,
+ detail,
+ y + style->ythickness + 1,
+ y + height - style->ythickness - 3,
+ x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness);
+ }
}
static GdkGC*
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (window != NULL);
- if (width == -1 && height == -1)
- gdk_window_get_size (window, &width, &height);
- else if (width == -1)
- gdk_window_get_size (window, &width, NULL);
- else if (height == -1)
- gdk_window_get_size (window, NULL, &height);
+ sanitize_size (window, &width, &height);
if (detail)
{
{
if (!strcmp ("text", detail))
gc1 = style->bg_gc[GTK_STATE_SELECTED];
- else if (!strcmp ("cell_even_sorted", detail) ||
- !strcmp ("cell_odd_sorted", detail) ||
- !strcmp ("cell_even_ruled_sorted", detail) ||
- !strcmp ("cell_odd_ruled_sorted", detail))
+ else if (!strncmp ("cell_even", detail, strlen ("cell_even")) ||
+ !strncmp ("cell_odd", detail, strlen ("cell_odd")))
{
- freeme = get_darkened_gc (window, &style->bg[state_type], 1);
- gc1 = freeme;
+ /* This has to be really broken; alex made me do it. -jrb */
+ if (GTK_WIDGET_HAS_FOCUS (widget))
+ gc1 = style->base_gc[state_type];
+ else
+ gc1 = style->base_gc[GTK_STATE_ACTIVE];
}
else
{
!strcmp ("cell_odd", detail) ||
!strcmp ("cell_even_ruled", detail))
{
- gc1 = style->base_gc[state_type];
+ gc1 = style->base_gc[state_type];
}
else if (!strcmp ("cell_even_sorted", detail) ||
!strcmp ("cell_odd_sorted", detail) ||
!strcmp ("cell_odd_ruled", detail) ||
!strcmp ("cell_even_ruled_sorted", detail))
{
- freeme = get_darkened_gc (window, &style->base[state_type], 1);
+ freeme = get_darkened_gc (window, &style->base[state_type], 1);
gc1 = freeme;
}
else if (!strcmp ("cell_odd_ruled_sorted", detail))
if (detail && strcmp (detail, "cellcheck") == 0)
{
gdk_draw_rectangle (window,
- widget->style->fg_gc[state_type],
+ widget->style->base_gc[state_type],
+ TRUE,
+ x, y,
+ width, height);
+ gdk_draw_rectangle (window,
+ widget->style->text_gc[state_type],
FALSE,
x, y,
width, height);
+ x -= (1 + INDICATOR_PART_SIZE - width) / 2;
+ y -= (((1 + INDICATOR_PART_SIZE - height) / 2) - 1);
if (shadow_type == GTK_SHADOW_IN)
{
- gdk_draw_line (window,
- widget->style->fg_gc[state_type],
- x, y,
- x + width,
- y + height);
- gdk_draw_line (window,
- widget->style->fg_gc[state_type],
- x + width,
- y,
- x,
- y + height);
+ draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
+ draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
}
}
else
{
- gtk_paint_box (style, window, state_type, shadow_type, area, widget, detail,
- x, y, width, height);
+ x -= (1 + INDICATOR_PART_SIZE - width) / 2;
+ y -= (1 + INDICATOR_PART_SIZE - height) / 2;
+
+ if (strcmp (detail, "check") == 0) /* Menu item */
+ {
+ if (shadow_type == GTK_SHADOW_IN)
+ {
+ draw_part (window, style->black_gc, area, x, y, CHECK_TEXT);
+ draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_AA);
+ }
+ }
+ else
+ {
+ draw_part (window, style->black_gc, area, x, y, CHECK_BLACK);
+ draw_part (window, style->dark_gc[state_type], area, x, y, CHECK_DARK);
+ draw_part (window, style->mid_gc[state_type], area, x, y, CHECK_MID);
+ draw_part (window, style->light_gc[state_type], area, x, y, CHECK_LIGHT);
+ draw_part (window, style->base_gc[state_type], area, x, y, CHECK_BASE);
+
+ if (shadow_type == GTK_SHADOW_IN)
+ {
+ draw_part (window, style->text_gc[state_type], area, x, y, CHECK_TEXT);
+ draw_part (window, style->text_aa_gc[state_type], area, x, y, CHECK_AA);
+ }
+ }
}
+
}
static void
}
else
{
- gtk_paint_diamond (style, window, state_type, shadow_type, area, widget,
- detail, x, y, width, height);
+ x -= (1 + INDICATOR_PART_SIZE - width) / 2;
+ y -= (1 + INDICATOR_PART_SIZE - height) / 2;
+
+ if (strcmp (detail, "option") == 0) /* Menu item */
+ {
+ if (shadow_type == GTK_SHADOW_IN)
+ draw_part (window, style->fg_gc[state_type], area, x, y, RADIO_TEXT);
+ }
+ else
+ {
+ draw_part (window, style->black_gc, area, x, y, RADIO_BLACK);
+ draw_part (window, style->dark_gc[state_type], area, x, y, RADIO_DARK);
+ draw_part (window, style->mid_gc[state_type], area, x, y, RADIO_MID);
+ draw_part (window, style->light_gc[state_type], area, x, y, RADIO_LIGHT);
+ draw_part (window, style->base_gc[state_type], area, x, y, RADIO_BASE);
+
+ if (shadow_type == GTK_SHADOW_IN)
+ draw_part (window, style->text_gc[state_type], area, x, y, RADIO_TEXT);
+ }
}
}
gint width,
gint height)
{
- g_return_if_fail (GTK_IS_STYLE (style));
- g_return_if_fail (window != NULL);
+ GtkRequisition indicator_size;
+ GtkBorder indicator_spacing;
- gtk_paint_box (style, window, state_type, shadow_type, area, widget, detail,
- x, y, width, height);
+ option_menu_get_props (widget, &indicator_size, &indicator_spacing);
+
+ x += (width - indicator_size.width) / 2;
+ y += (height - indicator_size.height) / 2 - 1;
+
+ draw_varrow (window, style->black_gc, shadow_type, area, GTK_ARROW_UP,
+ x, y, indicator_size.width, 5);
+ draw_varrow (window, style->black_gc, shadow_type, area, GTK_ARROW_DOWN,
+ x, y + 8, indicator_size.width, 5);
}
static void
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (window != NULL);
- if (width == -1 && height == -1)
- gdk_window_get_size (window, &width, &height);
- else if (width == -1)
- gdk_window_get_size (window, &width, NULL);
- else if (height == -1)
- gdk_window_get_size (window, NULL, &height);
+ sanitize_size (window, &width, &height);
switch (shadow_type)
{
gdk_draw_line (window, gc1,
x + gap_x + gap_width, y, x + width - 2, y);
gdk_draw_line (window, gc2,
- x + gap_x + gap_width, y + 1, x + width - 2, y + 1);
+ x + gap_x + gap_width, y + 1, x + width - 3, y + 1);
gdk_draw_line (window, gc2,
x + gap_x + gap_width - 1, y, x + gap_x + gap_width - 1, y);
}
widget && !GTK_WIDGET_NO_WINDOW (widget),
state_type, area, x, y, width, height);
- if (width == -1 && height == -1)
- gdk_window_get_size (window, &width, &height);
- else if (width == -1)
- gdk_window_get_size (window, &width, NULL);
- else if (height == -1)
- gdk_window_get_size (window, NULL, &height);
+ sanitize_size (window, &width, &height);
switch (shadow_type)
{
widget && !GTK_WIDGET_NO_WINDOW (widget),
GTK_STATE_NORMAL, area, x, y, width, height);
- if (width == -1 && height == -1)
- gdk_window_get_size (window, &width, &height);
- else if (width == -1)
- gdk_window_get_size (window, &width, NULL);
- else if (height == -1)
- gdk_window_get_size (window, NULL, &height);
+ sanitize_size (window, &width, &height);
switch (shadow_type)
{
static void
gtk_default_draw_focus (GtkStyle *style,
- GdkWindow *window,
- GdkRectangle *area,
- GtkWidget *widget,
- const gchar *detail,
- gint x,
- gint y,
- gint width,
- gint height)
+ GdkWindow *window,
+ GtkStateType state_type,
+ GdkRectangle *area,
+ GtkWidget *widget,
+ const gchar *detail,
+ gint x,
+ gint y,
+ gint width,
+ gint height)
{
- g_return_if_fail (GTK_IS_STYLE (style));
- g_return_if_fail (window != NULL);
-
- if (width == -1 && height == -1)
- {
- gdk_window_get_size (window, &width, &height);
- width -= 1;
- height -= 1;
- }
- else if (width == -1)
- {
- gdk_window_get_size (window, &width, NULL);
- width -= 1;
- }
- else if (height == -1)
+ GdkPoint points[5];
+ GdkGC *gc;
+ gboolean free_dash_list = FALSE;
+ gint line_width = 1;
+ gchar *dash_list = "\1\1";
+ gint dash_len;
+
+ gc = style->fg_gc[state_type];
+
+ if (widget)
{
- gdk_window_get_size (window, NULL, &height);
- height -= 1;
- }
+ gtk_widget_style_get (widget,
+ "focus-line-width", &line_width,
+ "focus-line-pattern", (gchar *)&dash_list,
+ NULL);
+ free_dash_list = TRUE;
+ }
+
+ sanitize_size (window, &width, &height);
+
if (area)
- gdk_gc_set_clip_rectangle (style->black_gc, area);
+ gdk_gc_set_clip_rectangle (gc, area);
+
+ gdk_gc_set_line_attributes (gc, line_width,
+ dash_list[0] ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID,
+ GDK_CAP_BUTT, GDK_JOIN_MITER);
+
if (detail && !strcmp (detail, "add-mode"))
{
- gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_ON_OFF_DASH, 0, 0);
- gdk_gc_set_dashes (style->black_gc, 0, "\4\4", 2);
-
- gdk_draw_rectangle (window,
- style->black_gc, FALSE,
- x, y, width, height);
+ if (free_dash_list)
+ g_free (dash_list);
- gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_SOLID, 0, 0);
+ dash_list = "\4\4";
+ free_dash_list = FALSE;
}
- else if (detail && strcmp (detail, "treeview") == 0)
+
+ points[0].x = x + line_width / 2;
+ points[0].y = y + line_width / 2;
+ points[1].x = x + width - line_width + line_width / 2;
+ points[1].y = y + line_width / 2;
+ points[2].x = x + width - line_width + line_width / 2;
+ points[2].y = y + height - line_width + line_width / 2;
+ points[3].x = x + line_width / 2;
+ points[3].y = y + height - line_width + line_width / 2;
+ points[4] = points[0];
+
+ if (!dash_list[0])
{
-
- gdk_gc_set_background (style->black_gc, &style->white);
- gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_DOUBLE_DASH, 0, 0);
- gdk_gc_set_dashes (style->black_gc, 0, "\4\4", 2);
-
- gdk_draw_rectangle (window,
- style->black_gc, FALSE,
- x, y, width, height);
-
- gdk_gc_set_line_attributes (style->black_gc, 1, GDK_LINE_SOLID, 0, 0);
+ gdk_draw_lines (window, gc, points, 5);
}
else
{
- gdk_draw_rectangle (window,
- style->black_gc, FALSE,
- x, y, width, height);
+ /* We go through all the pain below because the X rasterization
+ * rules don't really work right for dashed lines if you
+ * want continuity in segments that go between top/right
+ * and left/bottom. For instance, a top left corner
+ * with a 1-1 dash is drawn as:
+ *
+ * X X X
+ * X
+ *
+ * X
+ *
+ * This is because pixels on the top and left boundaries
+ * of polygons are drawn, but not on the bottom and right.
+ * So, if you have a line going up that turns the corner
+ * and goes right, there is a one pixel shift in the pattern.
+ *
+ * So, to fix this, we drawn the top and right in one call,
+ * then the left and bottom in another call, fixing up
+ * the dash offset for the second call ourselves to get
+ * continuity at the upper left.
+ *
+ * It's not perfect since we really should have a join at
+ * the upper left and lower right instead of two intersecting
+ * lines but that's only really apparent for no-dashes,
+ * which (for this reason) are done as one polygon and
+ * don't to through this code path.
+ */
+
+ dash_len = strlen (dash_list);
+
+ if (dash_list[0])
+ gdk_gc_set_dashes (gc, 0, dash_list, dash_len);
+
+ gdk_draw_lines (window, gc, points, 3);
+
+ /* We draw this line one farther over than it is "supposed" to
+ * because of another rasterization problem ... if two 1 pixel
+ * unjoined lines meet at the lower right, there will be a missing
+ * pixel.
+ */
+ points[2].x += 1;
+
+ if (dash_list[0])
+ {
+ gint dash_pixels = 0;
+ gint i;
+
+ /* Adjust the dash offset for the bottom and left so we
+ * match up at the upper left.
+ */
+ for (i = 0; i < dash_len; i++)
+ dash_pixels += dash_list[i];
+
+ if (dash_len % 2 == 1)
+ dash_pixels *= 2;
+
+ gdk_gc_set_dashes (gc, dash_pixels - (width + height - 2 * line_width) % dash_pixels, dash_list, dash_len);
+ }
+
+ gdk_draw_lines (window, gc, points + 2, 3);
}
+ gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
+
if (area)
- gdk_gc_set_clip_rectangle (style->black_gc, NULL);
+ gdk_gc_set_clip_rectangle (gc, NULL);
+
+ if (free_dash_list)
+ g_free (dash_list);
}
static void
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (window != NULL);
- if (width == -1 && height == -1)
- gdk_window_get_size (window, &width, &height);
- else if (width == -1)
- gdk_window_get_size (window, &width, NULL);
- else if (height == -1)
- gdk_window_get_size (window, NULL, &height);
+ sanitize_size (window, &width, &height);
gtk_paint_box (style, window, state_type, shadow_type,
area, widget, detail, x, y, width, height);
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- gtk_paint_vline (style, window, state_type, area, widget, detail,
- style->ythickness,
- height - style->ythickness - 1, width / 2);
- else
- gtk_paint_hline (style, window, state_type, area, widget, detail,
- style->xthickness,
- width - style->xthickness - 1, height / 2);
+ if (detail &&
+ (strcmp ("hscale", detail) == 0 ||
+ strcmp ("vscale", detail) == 0))
+ {
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ gtk_paint_vline (style, window, state_type, area, widget, detail,
+ y + style->ythickness,
+ y + height - style->ythickness - 1, x + width / 2);
+ else
+ gtk_paint_hline (style, window, state_type, area, widget, detail,
+ x + style->xthickness,
+ x + width - style->xthickness - 1, y + height / 2);
+ }
}
static void
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (window != NULL);
- if (width == -1 && height == -1)
- gdk_window_get_size (window, &width, &height);
- else if (width == -1)
- gdk_window_get_size (window, &width, NULL);
- else if (height == -1)
- gdk_window_get_size (window, NULL, &height);
+ sanitize_size (window, &width, &height);
gtk_paint_box (style, window, state_type, shadow_type, area, widget,
detail, x, y, width, height);
if (!strcmp (detail, "paned"))
{
- gint window_width;
- gint window_height;
-
- gdk_window_get_size (window, &window_width, &window_height);
-
if (orientation == GTK_ORIENTATION_HORIZONTAL)
- for (xx = window_width/2 - 15; xx <= window_width/2 + 15; xx += 5)
- draw_dot (window, light_gc, dark_gc, xx, window_height/2 - 1, 3);
+ for (xx = x + width/2 - 15; xx <= x + width/2 + 15; xx += 5)
+ draw_dot (window, light_gc, dark_gc, xx, y + height/2 - 1, 3);
else
- for (yy = window_height/2 - 15; yy <= window_height/2 + 15; yy += 5)
- draw_dot (window, light_gc, dark_gc, window_width/2 - 1, yy, 3);
+ for (yy = y + height/2 - 15; yy <= y + height/2 + 15; yy += 5)
+ draw_dot (window, light_gc, dark_gc, x + width/2 - 1, yy, 3);
}
else
{
gdk_gc_set_clip_rectangle (dark_gc, NULL);
}
+static void
+create_expander_affine (gdouble affine[6],
+ gint degrees,
+ gint expander_size,
+ gint x,
+ gint y)
+{
+ gdouble s, c;
+ gdouble width;
+ gdouble height;
+
+ width = expander_size / 4.0;
+ height = expander_size / 2.0;
+
+ s = sin (degrees * G_PI / 180.0);
+ c = cos (degrees * G_PI / 180.0);
+
+ affine[0] = c;
+ affine[1] = s;
+ affine[2] = -s;
+ affine[3] = c;
+ affine[4] = -width * c - height * -s + x;
+ affine[5] = -width * s - height * c + y;
+}
+
+static void
+apply_affine_on_point (double affine[6], GdkPoint *point)
+{
+ gdouble x, y;
+
+ x = point->x * affine[0] + point->y * affine[2] + affine[4];
+ y = point->x * affine[1] + point->y * affine[3] + affine[5];
+
+ point->x = x;
+ point->y = y;
+}
+
static void
gtk_default_draw_expander (GtkStyle *style,
GdkWindow *window,
const gchar *detail,
gint x,
gint y,
- gboolean is_open)
+ GtkExpanderStyle expander_style)
{
- /* FIXME replace macro with a style property */
-#define PM_SIZE 8
-
+ gint expander_size;
GdkPoint points[3];
+ gint i;
+ gdouble affine[6];
+ gint degrees = 0;
+
+ gtk_widget_style_get (widget,
+ "expander_size", &expander_size,
+ NULL);
if (area)
{
gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
}
- if (is_open)
+ points[0].x = 0;
+ points[0].y = 0;
+ points[1].x = expander_size / 2;
+ points[1].y = expander_size / 2;
+ points[2].x = 0;
+ points[2].y = expander_size;
+
+ switch (expander_style)
+ {
+ case GTK_EXPANDER_COLLAPSED:
+ degrees = 0;
+ break;
+ case GTK_EXPANDER_SEMI_COLLAPSED:
+ degrees = 30;
+ break;
+ case GTK_EXPANDER_SEMI_EXPANDED:
+ degrees = 60;
+ break;
+ case GTK_EXPANDER_EXPANDED:
+ degrees = 90;
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ create_expander_affine (affine, degrees, expander_size, x, y);
+
+ for (i = 0; i < 3; i++)
+ apply_affine_on_point (affine, &points[i]);
+
+ if (state_type == GTK_STATE_PRELIGHT)
+ {
+ gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
+ TRUE, points, 3);
+ }
+ else if (state_type == GTK_STATE_ACTIVE)
{
- points[0].x = x;
- points[0].y = y + (PM_SIZE + 2) / 6;
- points[1].x = points[0].x + 1 * (PM_SIZE + 2);
- points[1].y = points[0].y;
- points[2].x = (points[0].x + 1 * (PM_SIZE + 2) / 2);
- points[2].y = y + 2 * (PM_SIZE + 2) / 3;
+ gdk_draw_polygon (window, style->light_gc[GTK_STATE_ACTIVE],
+ TRUE, points, 3);
+ gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
+ FALSE, points, 3);
}
else
{
- points[0].x = x + 1 * ((PM_SIZE + 2) / 6 + 2);
- points[0].y = y - 1;
- points[1].x = points[0].x;
- points[1].y = points[0].y + (PM_SIZE + 2);
- points[2].x = (points[0].x + 1 * (2 * (PM_SIZE + 2) / 3 - 1));
- points[2].y = points[0].y + (PM_SIZE + 2) / 2;
+ gdk_draw_polygon (window, style->base_gc[GTK_STATE_NORMAL],
+ TRUE, points, 3);
+ gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
+ FALSE, points, 3);
}
-
- gdk_draw_polygon (window, style->base_gc[GTK_STATE_NORMAL],
- TRUE, points, 3);
- gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
- FALSE, points, 3);
-
-
if (area)
{
gdk_gc_set_clip_rectangle (style->fg_gc[GTK_STATE_NORMAL], NULL);
gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], NULL);
}
-
-#undef PM_SIZE
}
typedef struct _ByteRange ByteRange;
if (run)
{
- tmp_list = run->item->extra_attrs;
+ tmp_list = run->item->analysis.extra_attrs;
while (tmp_list != NULL)
{
gtk_default_draw_layout (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
+ gboolean use_text,
GdkRectangle *area,
GtkWidget *widget,
const gchar *detail,
gint y,
PangoLayout *layout)
{
+ GdkGC *gc;
+
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (window != NULL);
+
+ gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
if (area)
- gdk_gc_set_clip_rectangle (style->fg_gc[state_type], area);
+ gdk_gc_set_clip_rectangle (gc, area);
if (state_type == GTK_STATE_INSENSITIVE)
{
ins = get_insensitive_layout (layout);
- gdk_draw_layout (window, style->fg_gc[state_type], x, y, ins);
+ gdk_draw_layout (window, gc, x, y, ins);
g_object_unref (G_OBJECT (ins));
}
else
{
- gdk_draw_layout (window, style->fg_gc[state_type], x, y, layout);
+ gdk_draw_layout (window, gc, x, y, layout);
}
if (area)
- gdk_gc_set_clip_rectangle (style->fg_gc[state_type], NULL);
+ gdk_gc_set_clip_rectangle (gc, NULL);
}
static void
{
gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
+ gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
+ }
+
+ /* make it square, aligning to bottom right */
+ if (width < height)
+ {
+ y += (height - width);
+ height = width;
+ }
+ else if (height < width)
+ {
+ x += (width - height);
+ width = height;
}
- /* make it square */
- if (width != height)
- width = height = MIN (width, height);
+ /* Clear background */
+ gdk_draw_rectangle (window,
+ style->bg_gc[state_type],
+ TRUE,
+ x, y, width, height);
switch (edge)
{
}
}
break;
-
+ default:
+ g_assert_not_reached ();
+ break;
}
if (area)
{
gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
+ gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
}
}
}
}
+
+/**
+ * gtk_paint_hline:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @area: rectangle to which the output is clipped
+ * @widget:
+ * @detail:
+ * @x1: the starting x coordinate
+ * @x2: the ending x coordinate
+ * @y: the y coordinate
+ *
+ * Draws a horizontal line from (@x1, @y) to (@x2, @y) in @window
+ * using the given style and state.
+ **/
void
gtk_paint_hline (GtkStyle *style,
GdkWindow *window,
GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, area, widget, detail, x1, x2, y);
}
+/**
+ * gtk_paint_vline:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @area: rectangle to which the output is clipped
+ * @widget:
+ * @detail:
+ * @y1: the starting y coordinate
+ * @y2: the ending y coordinate
+ * @x: the x coordinate
+ *
+ * Draws a vertical line from (@x, @y1) to (@x, @y1) in @window
+ * using the given style and state.
+ */
void
gtk_paint_vline (GtkStyle *style,
GdkWindow *window,
GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
}
+/**
+ * gtk_paint_string:
+ * @style: a #GtkStyle
+ * @window: a #GdkWindow
+ * @state_type: a state
+ * @area: clip rectangle
+ * @widget: the widget
+ * @detail: a style detail
+ * @x: x origin
+ * @y: y origin
+ * @string: the string to draw
+ *
+ * Draws a text string on @window with the given parameters.
+ *
+ * This function is deprecated, use gtk_paint_layout() instead.
+ */
void
gtk_paint_string (GtkStyle *style,
GdkWindow *window,
void
gtk_paint_focus (GtkStyle *style,
GdkWindow *window,
+ GtkStateType state_type,
GdkRectangle *area,
GtkWidget *widget,
const gchar *detail,
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
- GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, area, widget, detail, x, y, width, height);
+ GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type, area, widget, detail, x, y, width, height);
}
void
const gchar *detail,
gint x,
gint y,
- gboolean is_open)
+ GtkExpanderStyle expander_style)
{
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type, area,
- widget, detail, x, y, is_open);
+ widget, detail, x, y, expander_style);
}
void
gtk_paint_layout (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type,
+ gboolean use_text,
GdkRectangle *area,
GtkWidget *widget,
const gchar *detail,
g_return_if_fail (GTK_IS_STYLE (style));
g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
- GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, area,
+ GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text, area,
widget, detail, x, y, layout);
}
edge, x, y, width, height);
}
+/**
+ * gtk_border_copy:
+ * @border: a #GtkBorder.
+ * @returns: a copy of @border.
+ *
+ * Copies a #GtkBorder structure.
+ **/
GtkBorder *
gtk_border_copy (const GtkBorder *border)
{
return (GtkBorder *)g_memdup (border, sizeof (GtkBorder));
}
+/**
+ * gtk_border_free:
+ * @border: a #GtkBorder.
+ *
+ * Frees a #GtkBorder structure.
+ **/
void
gtk_border_free (GtkBorder *border)
{
g_free (border);
}
+/**
+ * gtk_style_get_font:
+ * @style: a #GtkStyle
+ *
+ * Gets the #GdkFont to use for the given style. This is
+ * meant only as a replacement for direct access to @style->font
+ * and should not be used in new code. New code should
+ * use @style->font_desc instead.
+ *
+ * Return value: the #GdkFont for the style. This font is owned
+ * by the style; if you want to keep around a copy, you must
+ * call gdk_font_ref().
+ **/
+GdkFont *
+gtk_style_get_font (GtkStyle *style)
+{
+ g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
+
+ if (style->private_font && style->private_font_desc)
+ {
+ if (!style->font_desc ||
+ !pango_font_description_equal (style->private_font_desc, style->font_desc))
+ {
+ gdk_font_unref (style->private_font);
+ style->private_font = NULL;
+
+ if (style->private_font_desc)
+ {
+ pango_font_description_free (style->private_font_desc);
+ style->private_font_desc = NULL;
+ }
+ }
+ }
+
+ if (!style->private_font)
+ {
+ if (style->font_desc)
+ {
+ style->private_font = gdk_font_from_description (style->font_desc);
+ style->private_font_desc = pango_font_description_copy (style->font_desc);
+ }
+
+ if (!style->private_font)
+ style->private_font = gdk_font_load ("fixed");
+
+ if (!style->private_font)
+ g_error ("Unable to load \"fixed\" font");
+ }
+
+ return style->private_font;
+}
+
+/**
+ * gtk_style_set_font:
+ * @style: a #GtkStyle.
+ * @font: a #GdkFont, or %NULL to use the #GdkFont corresponding
+ * to style->font_desc.
+ *
+ * Sets the #GdkFont to use for a given style. This is
+ * meant only as a replacement for direct access to style->font
+ * and should not be used in new code. New code should
+ * use style->font_desc instead.
+ **/
+void
+gtk_style_set_font (GtkStyle *style,
+ GdkFont *font)
+{
+ GdkFont *old_font;
+
+ g_return_if_fail (GTK_IS_STYLE (style));
+
+ old_font = style->private_font;
+
+ style->private_font = font;
+ if (font)
+ gdk_font_ref (font);
+
+ if (old_font)
+ gdk_font_unref (old_font);
+
+ if (style->private_font_desc)
+ {
+ pango_font_description_free (style->private_font_desc);
+ style->private_font_desc = NULL;
+ }
+}
+
+/**
+ * _gtk_draw_insertion_cursor:
+ * @drawable: a #GdkDrawable
+ * @gc: a #GdkGC
+ * @location: location where to draw the cursor (@location->width is ignored)
+ * @dir: text direction for the cursor, used to decide whether to draw a
+ * directional arrow on the cursor and in what direction. Unless both
+ * strong and weak cursors are displayed, this should be %GTK_TEXT_DIR_NONE.
+ *
+ * Draws a text caret on @drawable at @location. This is not a style function
+ * but merely a convenience function for drawing the standard cursor shape.
+ **/
+void
+_gtk_draw_insertion_cursor (GdkDrawable *drawable,
+ GdkGC *gc,
+ GdkRectangle *location,
+ GtkTextDirection dir)
+{
+ gint stem_width = location->height / 30 + 1;
+ gint arrow_width = stem_width + 1;
+ gint x, y;
+ gint i;
+
+ for (i = 0; i < stem_width; i++)
+ gdk_draw_line (drawable, gc,
+ location->x + i - stem_width / 2, location->y,
+ location->x + i - stem_width / 2, location->y + location->height);
+
+ if (dir == GTK_TEXT_DIR_RTL)
+ {
+ x = location->x - stem_width / 2 - 1;
+ y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
+
+ for (i = 0; i < arrow_width; i++)
+ {
+ gdk_draw_line (drawable, gc,
+ x, y + i + 1,
+ x, y + 2 * arrow_width - i - 1);
+ x --;
+ }
+ }
+ else if (dir == GTK_TEXT_DIR_LTR)
+ {
+ x = location->x + stem_width - stem_width / 2;
+ y = location->y + location->height - arrow_width * 2 - arrow_width + 1;
+
+ for (i = 0; i < arrow_width; i++)
+ {
+ gdk_draw_line (drawable, gc,
+ x, y + i + 1,
+ x, y + 2 * arrow_width - i - 1);
+ x++;
+ }
+ }
+}