mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-19 09:50:06 +00:00
calendar: Port to draw vfunc
This commit is contained in:
parent
725749cd14
commit
9233a08991
@ -351,8 +351,8 @@ static void gtk_calendar_size_request (GtkWidget *widget,
|
|||||||
GtkRequisition *requisition);
|
GtkRequisition *requisition);
|
||||||
static void gtk_calendar_size_allocate (GtkWidget *widget,
|
static void gtk_calendar_size_allocate (GtkWidget *widget,
|
||||||
GtkAllocation *allocation);
|
GtkAllocation *allocation);
|
||||||
static gboolean gtk_calendar_expose (GtkWidget *widget,
|
static gboolean gtk_calendar_draw (GtkWidget *widget,
|
||||||
GdkEventExpose *event);
|
cairo_t *cr);
|
||||||
static gboolean gtk_calendar_button_press (GtkWidget *widget,
|
static gboolean gtk_calendar_button_press (GtkWidget *widget,
|
||||||
GdkEventButton *event);
|
GdkEventButton *event);
|
||||||
static gboolean gtk_calendar_button_release (GtkWidget *widget,
|
static gboolean gtk_calendar_button_release (GtkWidget *widget,
|
||||||
@ -447,7 +447,7 @@ gtk_calendar_class_init (GtkCalendarClass *class)
|
|||||||
|
|
||||||
widget_class->realize = gtk_calendar_realize;
|
widget_class->realize = gtk_calendar_realize;
|
||||||
widget_class->unrealize = gtk_calendar_unrealize;
|
widget_class->unrealize = gtk_calendar_unrealize;
|
||||||
widget_class->expose_event = gtk_calendar_expose;
|
widget_class->draw = gtk_calendar_draw;
|
||||||
widget_class->size_request = gtk_calendar_size_request;
|
widget_class->size_request = gtk_calendar_size_request;
|
||||||
widget_class->size_allocate = gtk_calendar_size_allocate;
|
widget_class->size_allocate = gtk_calendar_size_allocate;
|
||||||
widget_class->button_press_event = gtk_calendar_button_press;
|
widget_class->button_press_event = gtk_calendar_button_press;
|
||||||
@ -2326,6 +2326,10 @@ calendar_paint_header (GtkCalendar *calendar, cairo_t *cr)
|
|||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
|
cairo_save (cr);
|
||||||
|
gdk_window_get_position (priv->header_win, &x, &y);
|
||||||
|
cairo_translate (cr, x, y);
|
||||||
|
|
||||||
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
|
||||||
year_left = priv->year_before;
|
year_left = priv->year_before;
|
||||||
else
|
else
|
||||||
@ -2410,6 +2414,8 @@ calendar_paint_header (GtkCalendar *calendar, cairo_t *cr)
|
|||||||
pango_cairo_show_layout (cr, layout);
|
pango_cairo_show_layout (cr, layout);
|
||||||
|
|
||||||
g_object_unref (layout);
|
g_object_unref (layout);
|
||||||
|
|
||||||
|
cairo_restore (cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2429,6 +2435,11 @@ calendar_paint_day_names (GtkCalendar *calendar,
|
|||||||
gint focus_width;
|
gint focus_width;
|
||||||
gint calendar_ysep = calendar_get_ysep (calendar);
|
gint calendar_ysep = calendar_get_ysep (calendar);
|
||||||
gint calendar_xsep = calendar_get_xsep (calendar);
|
gint calendar_xsep = calendar_get_xsep (calendar);
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
cairo_save (cr);
|
||||||
|
gdk_window_get_position (priv->day_name_win, &x, &y);
|
||||||
|
cairo_translate (cr, x, y);
|
||||||
|
|
||||||
gtk_widget_style_get (GTK_WIDGET (widget),
|
gtk_widget_style_get (GTK_WIDGET (widget),
|
||||||
"focus-line-width", &focus_width,
|
"focus-line-width", &focus_width,
|
||||||
@ -2493,6 +2504,8 @@ calendar_paint_day_names (GtkCalendar *calendar,
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (layout);
|
g_object_unref (layout);
|
||||||
|
|
||||||
|
cairo_restore (cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2501,7 +2514,6 @@ calendar_paint_week_numbers (GtkCalendar *calendar,
|
|||||||
{
|
{
|
||||||
GtkWidget *widget = GTK_WIDGET (calendar);
|
GtkWidget *widget = GTK_WIDGET (calendar);
|
||||||
GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
|
GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
|
||||||
|
|
||||||
guint week = 0, year;
|
guint week = 0, year;
|
||||||
gint row, x_loc, y_loc;
|
gint row, x_loc, y_loc;
|
||||||
gint day_height;
|
gint day_height;
|
||||||
@ -2511,6 +2523,11 @@ calendar_paint_week_numbers (GtkCalendar *calendar,
|
|||||||
gint focus_padding;
|
gint focus_padding;
|
||||||
gint focus_width;
|
gint focus_width;
|
||||||
gint calendar_xsep = calendar_get_xsep (calendar);
|
gint calendar_xsep = calendar_get_xsep (calendar);
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
cairo_save (cr);
|
||||||
|
gdk_window_get_position (priv->week_win, &x, &y);
|
||||||
|
cairo_translate (cr, x, y);
|
||||||
|
|
||||||
gtk_widget_style_get (GTK_WIDGET (widget),
|
gtk_widget_style_get (GTK_WIDGET (widget),
|
||||||
"focus-line-width", &focus_width,
|
"focus-line-width", &focus_width,
|
||||||
@ -2582,6 +2599,8 @@ calendar_paint_week_numbers (GtkCalendar *calendar,
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (layout);
|
g_object_unref (layout);
|
||||||
|
|
||||||
|
cairo_restore (cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2814,11 +2833,17 @@ static void
|
|||||||
calendar_paint_main (GtkCalendar *calendar,
|
calendar_paint_main (GtkCalendar *calendar,
|
||||||
cairo_t *cr)
|
cairo_t *cr)
|
||||||
{
|
{
|
||||||
gint row, col;
|
gint row, col, x, y;
|
||||||
|
|
||||||
|
cairo_save (cr);
|
||||||
|
gdk_window_get_position (calendar->priv->main_win, &x, &y);
|
||||||
|
cairo_translate (cr, x, y);
|
||||||
|
|
||||||
for (col = 0; col < 7; col++)
|
for (col = 0; col < 7; col++)
|
||||||
for (row = 0; row < 6; row++)
|
for (row = 0; row < 6; row++)
|
||||||
calendar_paint_day (calendar, cr, row, col);
|
calendar_paint_day (calendar, cr, row, col);
|
||||||
|
|
||||||
|
cairo_restore (cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2841,6 +2866,13 @@ calendar_paint_arrow (GtkCalendar *calendar,
|
|||||||
GtkWidget *widget = GTK_WIDGET (calendar);
|
GtkWidget *widget = GTK_WIDGET (calendar);
|
||||||
GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
|
GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
|
||||||
GdkWindow *window;
|
GdkWindow *window;
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
cairo_save (cr);
|
||||||
|
gdk_window_get_position (priv->arrow_win[arrow], &x, &y);
|
||||||
|
cairo_translate (cr, x, y);
|
||||||
|
gdk_window_get_position (priv->header_win, &x, &y);
|
||||||
|
cairo_translate (cr, x, y);
|
||||||
|
|
||||||
window = priv->arrow_win[arrow];
|
window = priv->arrow_win[arrow];
|
||||||
if (window)
|
if (window)
|
||||||
@ -2867,24 +2899,19 @@ calendar_paint_arrow (GtkCalendar *calendar,
|
|||||||
GTK_ARROW_RIGHT, TRUE,
|
GTK_ARROW_RIGHT, TRUE,
|
||||||
width/2 - 4, height/2 - 4, 8, 8);
|
width/2 - 4, height/2 - 4, 8, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cairo_restore (cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gtk_calendar_expose (GtkWidget *widget,
|
gtk_calendar_draw (GtkWidget *widget,
|
||||||
GdkEventExpose *event)
|
cairo_t *cr)
|
||||||
{
|
{
|
||||||
GtkCalendar *calendar = GTK_CALENDAR (widget);
|
GtkCalendar *calendar = GTK_CALENDAR (widget);
|
||||||
GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
|
GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
|
||||||
cairo_t *cr;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (gtk_widget_is_drawable (widget))
|
if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
|
||||||
{
|
|
||||||
cr = gdk_cairo_create (event->window);
|
|
||||||
gdk_cairo_region (cr, event->region);
|
|
||||||
cairo_clip (cr);
|
|
||||||
|
|
||||||
if (event->window == gtk_widget_get_window (widget))
|
|
||||||
{
|
{
|
||||||
gtk_cairo_paint_shadow (gtk_widget_get_style (widget), cr,
|
gtk_cairo_paint_shadow (gtk_widget_get_style (widget), cr,
|
||||||
gtk_widget_get_state (widget), GTK_SHADOW_IN,
|
gtk_widget_get_state (widget), GTK_SHADOW_IN,
|
||||||
@ -2894,25 +2921,26 @@ gtk_calendar_expose (GtkWidget *widget,
|
|||||||
gtk_widget_get_allocated_height (widget));
|
gtk_widget_get_allocated_height (widget));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event->window == priv->main_win)
|
if (gtk_cairo_should_draw_window (cr, priv->main_win))
|
||||||
calendar_paint_main (calendar, cr);
|
calendar_paint_main (calendar, cr);
|
||||||
|
|
||||||
if (event->window == priv->header_win)
|
if (priv->header_win &&
|
||||||
|
gtk_cairo_should_draw_window (cr, priv->header_win))
|
||||||
calendar_paint_header (calendar, cr);
|
calendar_paint_header (calendar, cr);
|
||||||
|
|
||||||
for (i = 0; i < 4; i++)
|
for (i = 0; i < 4; i++)
|
||||||
if (event->window == priv->arrow_win[i])
|
if (priv->arrow_win[i] &&
|
||||||
|
gtk_cairo_should_draw_window (cr, priv->arrow_win[i]))
|
||||||
calendar_paint_arrow (calendar, cr, i);
|
calendar_paint_arrow (calendar, cr, i);
|
||||||
|
|
||||||
if (event->window == priv->day_name_win)
|
if (priv->day_name_win &&
|
||||||
|
gtk_cairo_should_draw_window (cr, priv->day_name_win))
|
||||||
calendar_paint_day_names (calendar, cr);
|
calendar_paint_day_names (calendar, cr);
|
||||||
|
|
||||||
if (event->window == priv->week_win)
|
if (priv->week_win &&
|
||||||
|
gtk_cairo_should_draw_window (cr, priv->week_win))
|
||||||
calendar_paint_week_numbers (calendar, cr);
|
calendar_paint_week_numbers (calendar, cr);
|
||||||
|
|
||||||
cairo_destroy (cr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user