aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc
diff options
context:
space:
mode:
Diffstat (limited to 'widgets/misc')
-rw-r--r--widgets/misc/ChangeLog15
-rw-r--r--widgets/misc/e-calendar-item.c96
-rw-r--r--widgets/misc/e-calendar-item.h2
-rw-r--r--widgets/misc/e-calendar.c10
4 files changed, 106 insertions, 17 deletions
diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog
index 07cae36fc8..ec70cf8de2 100644
--- a/widgets/misc/ChangeLog
+++ b/widgets/misc/ChangeLog
@@ -1,3 +1,18 @@
+2003-02-02 Hans Petter Jansson <hpj@ximian.com>
+
+ * e-calendar-item.[ch]: Use Pango to draw.
+ (e_calendar_item_class_init): Add font_desc and week_number_font_desc
+ args.
+ (e_calendar_item_get_arg): Ditto.
+ (e_calendar_item_set_arg): Ditto.
+ (e_calendar_item_draw_month): Use Pango.
+ (e_calendar_item_draw_day_numbers): Ditto.
+
+ * e-calendar.c: Use Pango to draw. Specify just the size of the small
+ font to use, instead of all aspects of it.
+ (e_calendar_init): Produce the small font description and pass it to
+ the ECalendarItem.
+
2003-02-01 Hans Petter Jansson <hpj@ximian.com>
* e-dateedit.c (create_children): Don't request combo boxes that are
diff --git a/widgets/misc/e-calendar-item.c b/widgets/misc/e-calendar-item.c
index 5431c5c24c..8d3bd80853 100644
--- a/widgets/misc/e-calendar-item.c
+++ b/widgets/misc/e-calendar-item.c
@@ -229,7 +229,9 @@ enum {
ARG_X2,
ARG_Y2,
ARG_FONT,
+ ARG_FONT_DESC,
ARG_WEEK_NUMBER_FONT,
+ ARG_WEEK_NUMBER_FONT_DESC,
ARG_ROW_HEIGHT,
ARG_COLUMN_WIDTH,
ARG_MINIMUM_ROWS,
@@ -293,9 +295,15 @@ e_calendar_item_class_init (ECalendarItemClass *class)
gtk_object_add_arg_type ("ECalendarItem::font",
GTK_TYPE_POINTER, GTK_ARG_READWRITE,
ARG_FONT);
+ gtk_object_add_arg_type ("ECalendarItem::font_desc",
+ GTK_TYPE_POINTER, GTK_ARG_READWRITE,
+ ARG_FONT_DESC);
gtk_object_add_arg_type ("ECalendarItem::week_number_font",
GTK_TYPE_POINTER, GTK_ARG_READWRITE,
ARG_WEEK_NUMBER_FONT);
+ gtk_object_add_arg_type ("ECalendarItem::week_number_font_desc",
+ GTK_TYPE_POINTER, GTK_ARG_READWRITE,
+ ARG_WEEK_NUMBER_FONT_DESC);
gtk_object_add_arg_type ("ECalendarItem::row_height",
GTK_TYPE_INT, GTK_ARG_READABLE,
ARG_ROW_HEIGHT);
@@ -484,9 +492,15 @@ e_calendar_item_get_arg (GtkObject *o, GtkArg *arg, guint arg_id)
case ARG_FONT:
GTK_VALUE_BOXED (*arg) = calitem->font;
break;
+ case ARG_FONT_DESC:
+ GTK_VALUE_BOXED (*arg) = calitem->font_desc;
+ break;
case ARG_WEEK_NUMBER_FONT:
GTK_VALUE_BOXED (*arg) = calitem->week_number_font;
break;
+ case ARG_WEEK_NUMBER_FONT_DESC:
+ GTK_VALUE_BOXED (*arg) = calitem->week_number_font_desc;
+ break;
case ARG_ROW_HEIGHT:
e_calendar_item_recalc_sizes (calitem);
GTK_VALUE_INT (*arg) = calitem->min_month_height;
@@ -540,6 +554,7 @@ e_calendar_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
GnomeCanvasItem *item;
ECalendarItem *calitem;
GdkFont *font;
+ PangoFontDescription *font_desc;
gboolean need_update = FALSE;
gdouble dvalue;
gint ivalue;
@@ -598,6 +613,13 @@ e_calendar_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
need_update = TRUE;
}
break;
+ case ARG_FONT_DESC:
+ font_desc = GTK_VALUE_BOXED (*arg);
+ if (calitem->font_desc)
+ pango_font_description_free (calitem->font_desc);
+ calitem->font_desc = pango_font_description_copy (font_desc);
+ need_update = TRUE;
+ break;
case ARG_WEEK_NUMBER_FONT:
font = GTK_VALUE_BOXED (*arg);
if (calitem->week_number_font != font) {
@@ -609,6 +631,13 @@ e_calendar_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
need_update = TRUE;
}
break;
+ case ARG_WEEK_NUMBER_FONT_DESC:
+ font_desc = GTK_VALUE_BOXED (*arg);
+ if (calitem->week_number_font_desc)
+ pango_font_description_free (calitem->week_number_font_desc);
+ calitem->week_number_font_desc = pango_font_description_copy (font_desc);
+ need_update = TRUE;
+ break;
case ARG_MINIMUM_ROWS:
ivalue = GTK_VALUE_INT (*arg);
ivalue = MAX (1, ivalue);
@@ -989,6 +1018,7 @@ e_calendar_item_draw_month (ECalendarItem *calitem,
GtkWidget *widget;
GtkStyle *style;
GdkFont *font;
+ PangoFontDescription *font_desc;
GdkGC *fg_gc;
struct tm tmp_tm;
GdkRectangle clip_rect;
@@ -999,6 +1029,7 @@ e_calendar_item_draw_month (ECalendarItem *calitem,
gint day, day_index, cells_x, cells_y, min_cell_width, text_width;
gint clip_width, clip_height;
gchar buffer[64];
+ PangoLayout *layout;
#if 0
g_print ("In e_calendar_item_draw_month: %i,%i %ix%i row:%i col:%i\n",
@@ -1010,10 +1041,14 @@ e_calendar_item_draw_month (ECalendarItem *calitem,
font = calitem->font;
if (!font)
font = gtk_style_get_font (style);
+ font_desc = calitem->font_desc;
+ if (!font_desc)
+ font_desc = style->font_desc;
char_height = font->ascent + font->descent;
xthickness = style->xthickness;
ythickness = style->ythickness;
fg_gc = style->fg_gc[GTK_STATE_NORMAL];
+ layout = gtk_widget_create_pango_layout (widget, NULL);
/* Calculate the top-left position of the entire month display. */
month_x = item->x1 + xthickness + calitem->x_offset
@@ -1074,8 +1109,12 @@ e_calendar_item_draw_month (ECalendarItem *calitem,
text_x = (calitem->month_width - text_width) / 2;
text_x = MAX (min_x, text_x);
- gdk_draw_string (drawable, font, fg_gc,
- month_x + text_x, text_y + font->ascent, buffer);
+ pango_layout_set_font_description (layout, font_desc);
+ pango_layout_set_text (layout, buffer, -1);
+ gdk_draw_layout (drawable, fg_gc,
+ month_x + text_x,
+ text_y,
+ layout);
}
/* Set the clip rectangle for the main month display. */
@@ -1114,12 +1153,15 @@ e_calendar_item_draw_month (ECalendarItem *calitem,
+ E_CALENDAR_ITEM_YPAD_BELOW_DAY_LETTERS + 1
+ E_CALENDAR_ITEM_YPAD_ABOVE_CELLS;
- text_y += font->ascent;
day_index = calitem->week_start_day;
+ pango_layout_set_font_description (layout, font_desc);
for (day = 0; day < 7; day++) {
- gdk_draw_text (drawable, font, fg_gc,
- text_x - calitem->day_widths[day_index], text_y,
- &calitem->days[day_index], 1);
+ pango_layout_set_text (layout, &calitem->days [day_index], 1);
+ gdk_draw_layout (drawable, fg_gc,
+ text_x - calitem->day_widths [day_index],
+ text_y,
+ layout);
+
text_x += calitem->cell_width;
day_index++;
if (day_index == 7)
@@ -1148,6 +1190,7 @@ e_calendar_item_draw_month (ECalendarItem *calitem,
}
gdk_gc_set_clip_rectangle (fg_gc, NULL);
+ g_object_unref (layout);
}
@@ -1168,6 +1211,7 @@ e_calendar_item_draw_day_numbers (ECalendarItem *calitem,
GtkWidget *widget;
GtkStyle *style;
GdkFont *font, *wkfont;
+ PangoFontDescription *font_desc, *wkfont_desc;
GdkGC *fg_gc;
GdkColor *bg_color, *fg_color, *box_color;
struct tm today_tm;
@@ -1183,6 +1227,7 @@ e_calendar_item_draw_day_numbers (ECalendarItem *calitem,
gint today_year, today_month, today_mday, month_offset;
gchar buffer[2];
gint day_style = 0;
+ PangoLayout *layout;
item = GNOME_CANVAS_ITEM (calitem);
widget = GTK_WIDGET (item->canvas);
@@ -1190,9 +1235,15 @@ e_calendar_item_draw_day_numbers (ECalendarItem *calitem,
font = calitem->font;
if (!font)
font = gtk_style_get_font (style);
+ font_desc = calitem->font_desc;
+ if (!font_desc)
+ font_desc = style->font_desc;
wkfont = calitem->week_number_font;
if (!wkfont)
wkfont = font;
+ wkfont_desc = calitem->week_number_font_desc;
+ if (!wkfont_desc)
+ wkfont_desc = font_desc;
fg_gc = style->fg_gc[GTK_STATE_NORMAL];
char_height = font->ascent + font->descent;
@@ -1200,6 +1251,8 @@ e_calendar_item_draw_day_numbers (ECalendarItem *calitem,
+ E_CALENDAR_ITEM_MIN_CELL_XPAD;
min_cell_height = char_height + E_CALENDAR_ITEM_MIN_CELL_YPAD;
+ layout = gtk_widget_create_pango_layout (widget, NULL);
+
/* Calculate the number of days in the previous, current, and next
months. */
years[0] = years[1] = years[2] = year;
@@ -1283,9 +1336,13 @@ e_calendar_item_draw_day_numbers (ECalendarItem *calitem,
gdk_gc_set_foreground (fg_gc,
&style->fg[GTK_STATE_NORMAL]);
- gdk_draw_text (drawable, wkfont, fg_gc,
- text_x, text_y + font->ascent,
- buffer, num_chars);
+
+ pango_layout_set_font_description (layout, wkfont_desc);
+ pango_layout_set_text (layout, buffer, num_chars);
+ gdk_draw_layout (drawable, fg_gc,
+ text_x,
+ text_y,
+ layout);
}
for (dcol = 0; dcol < 7; dcol++) {
@@ -1388,17 +1445,20 @@ e_calendar_item_draw_day_numbers (ECalendarItem *calitem,
&style->fg[GTK_STATE_NORMAL]);
}
- gdk_draw_text (drawable, font, fg_gc,
- day_x,
- day_y + font->ascent,
- buffer, num_chars);
+ pango_layout_set_font_description (layout, font_desc);
+ pango_layout_set_text (layout, buffer, num_chars);
+ gdk_draw_layout (drawable, fg_gc,
+ day_x,
+ day_y,
+ layout);
+
/* We use a stupid technique for bold. Just
draw it again 1 pixel to the left. */
if (bold)
- gdk_draw_text (drawable, font, fg_gc,
- day_x - 1,
- day_y + font->ascent,
- buffer, num_chars);
+ gdk_draw_layout (drawable, fg_gc,
+ day_x - 1,
+ day_y,
+ layout);
}
/* See if we've reached the end of a month. */
@@ -1427,6 +1487,8 @@ e_calendar_item_draw_day_numbers (ECalendarItem *calitem,
/* Reset the foreground color. */
gdk_gc_set_foreground (fg_gc, &style->fg[GTK_STATE_NORMAL]);
+
+ g_object_unref (layout);
}
diff --git a/widgets/misc/e-calendar-item.h b/widgets/misc/e-calendar-item.h
index f63282b080..a54cb2e222 100644
--- a/widgets/misc/e-calendar-item.h
+++ b/widgets/misc/e-calendar-item.h
@@ -199,7 +199,9 @@ struct _ECalendarItem
/* Fonts for drawing text. If font isn't set it uses the font from the
canvas widget. If week_number_font isn't set it uses font. */
GdkFont *font, *old_font;
+ PangoFontDescription *font_desc;
GdkFont *week_number_font, *old_week_number_font;
+ PangoFontDescription *week_number_font_desc;
ECalendarItemStyleCallback style_callback;
gpointer style_callback_data;
diff --git a/widgets/misc/e-calendar.c b/widgets/misc/e-calendar.c
index 105afc555a..dce0e05771 100644
--- a/widgets/misc/e-calendar.c
+++ b/widgets/misc/e-calendar.c
@@ -41,6 +41,8 @@
#include <libgnomecanvas/gnome-canvas-widget.h>
#include <gal/util/e-util.h>
+#define E_CALENDAR_SMALL_FONT_PTSIZE 6
+
#define E_CALENDAR_SMALL_FONT \
"-adobe-utopia-regular-r-normal-*-*-100-*-*-p-*-iso8859-*"
#define E_CALENDAR_SMALL_FONT_FALLBACK \
@@ -158,6 +160,7 @@ e_calendar_init (ECalendar *cal)
{
GnomeCanvasGroup *canvas_group;
GdkFont *small_font;
+ PangoFontDescription *small_font_desc;
GtkWidget *button, *pixmap;
GdkColormap *colormap;
GdkPixmap *gdk_pixmap;
@@ -172,16 +175,23 @@ e_calendar_init (ECalendar *cal)
if (!small_font)
g_warning ("Couldn't load font");
+ small_font_desc =
+ pango_font_description_copy (gtk_widget_get_style (GTK_WIDGET (cal))->font_desc);
+ pango_font_description_set_size (small_font_desc,
+ E_CALENDAR_SMALL_FONT_PTSIZE * PANGO_SCALE);
+
canvas_group = GNOME_CANVAS_GROUP (GNOME_CANVAS (cal)->root);
cal->calitem = E_CALENDAR_ITEM (gnome_canvas_item_new (canvas_group,
e_calendar_item_get_type (),
"week_number_font", small_font,
+ "week_number_font_desc", small_font_desc,
NULL));
if (small_font)
gdk_font_unref (small_font);
+ pango_font_description_free (small_font_desc);
/* Create the arrow buttons to move to the previous/next month. */
button = gtk_button_new ();