calendar: Fix for GTK4 changes

This commit is contained in:
Benjamin Otte 2017-11-10 14:34:12 +01:00
parent f4e1a2b849
commit 723bf44887
2 changed files with 30 additions and 63 deletions

View File

@ -1052,7 +1052,6 @@ calendar_row_height (GtkCalendar *calendar)
static void
get_component_paddings (GtkCalendar *calendar,
GtkBorder *padding,
GtkBorder *day_padding,
GtkBorder *day_name_padding,
GtkBorder *week_padding)
@ -1063,9 +1062,6 @@ get_component_paddings (GtkCalendar *calendar,
widget = GTK_WIDGET (calendar);
context = gtk_widget_get_style_context (widget);
if (padding)
gtk_style_context_get_padding (context, padding);
if (day_padding)
{
gtk_style_context_save (context);
@ -1103,11 +1099,10 @@ calendar_left_x_for_column (GtkCalendar *calendar,
gint week_width;
gint calendar_xsep = calendar_get_xsep (calendar);
gint inner_border = calendar_get_inner_border (calendar);
GtkBorder padding;
get_component_paddings (calendar, &padding, NULL, NULL, NULL);
get_component_paddings (calendar, NULL, NULL, NULL);
week_width = priv->week_width + padding.left + inner_border;
week_width = priv->week_width + inner_border;
if (gtk_widget_get_direction (GTK_WIDGET (calendar)) == GTK_TEXT_DIR_RTL)
{
@ -1157,12 +1152,9 @@ calendar_top_y_for_row (GtkCalendar *calendar,
gint row)
{
GtkCalendarPrivate *priv = calendar->priv;
GtkBorder padding;
gint inner_border = calendar_get_inner_border (calendar);
get_component_paddings (calendar, &padding, NULL, NULL, NULL);
return priv->header_h + priv->day_name_h + padding.top + inner_border
return priv->header_h + priv->day_name_h + inner_border
+ row * calendar_row_height (calendar);
}
@ -1201,12 +1193,10 @@ calendar_arrow_rectangle (GtkCalendar *calendar,
{
GtkWidget *widget = GTK_WIDGET (calendar);
GtkCalendarPrivate *priv = calendar->priv;
int width, height;
GtkBorder padding;
int width;
gboolean year_left;
get_component_paddings (calendar, &padding, NULL, NULL, NULL);
gtk_widget_get_content_size (widget, &width, &height);
width = gtk_widget_get_width (widget);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
year_left = priv->year_before;
@ -1221,39 +1211,32 @@ calendar_arrow_rectangle (GtkCalendar *calendar,
{
case ARROW_MONTH_LEFT:
if (year_left)
rect->x = (width - padding.left - padding.right
- (3 + 2 * priv->arrow_width + priv->max_month_width));
rect->x = (width - (3 + 2 * priv->arrow_width + priv->max_month_width));
else
rect->x = 3;
break;
case ARROW_MONTH_RIGHT:
if (year_left)
rect->x = (width - padding.left - padding.right
- 3 - priv->arrow_width);
rect->x = width - 3 - priv->arrow_width;
else
rect->x = (priv->arrow_width + priv->max_month_width);
rect->x = priv->arrow_width + priv->max_month_width;
break;
case ARROW_YEAR_LEFT:
if (year_left)
rect->x = 3;
else
rect->x = (width - padding.left - padding.right
- (3 + 2 * priv->arrow_width + priv->max_year_width));
rect->x = width - (3 + 2 * priv->arrow_width + priv->max_year_width);
break;
case ARROW_YEAR_RIGHT:
if (year_left)
rect->x = (priv->arrow_width + priv->max_year_width);
else
rect->x = (width - padding.left - padding.right
- 3 - priv->arrow_width);
rect->x = width - 3 - priv->arrow_width;
break;
default:
g_assert_not_reached();
}
rect->x += padding.left;
rect->y += padding.top;
}
static void
@ -1600,7 +1583,7 @@ gtk_calendar_size_request (GtkWidget *widget,
{
GtkCalendar *calendar = GTK_CALENDAR (widget);
GtkCalendarPrivate *priv = calendar->priv;
GtkBorder padding, day_padding, day_name_padding, week_padding;
GtkBorder day_padding, day_name_padding, week_padding;
PangoLayout *layout;
PangoRectangle logical_rect;
@ -1780,7 +1763,7 @@ gtk_calendar_size_request (GtkWidget *widget,
}
}
get_component_paddings (calendar, &padding, &day_padding, &day_name_padding, &week_padding);
get_component_paddings (calendar, &day_padding, &day_name_padding, &week_padding);
priv->min_day_width += day_padding.left + day_padding.right;
if (show_week_numbers)
@ -1794,7 +1777,7 @@ gtk_calendar_size_request (GtkWidget *widget,
? priv->max_week_char_width * 2 + calendar_xsep * 2
: 0));
requisition->width = MAX (header_width, main_width + inner_border * 2) + padding.left + padding.right;
requisition->width = MAX (header_width, main_width + inner_border * 2);
/*
* Calculate the requisition height for the widget.
@ -1831,7 +1814,7 @@ gtk_calendar_size_request (GtkWidget *widget,
height = priv->header_h + priv->day_name_h + priv->main_h;
requisition->height = height + padding.top + padding.bottom + (inner_border * 2);
requisition->height = height + (inner_border * 2);
g_object_unref (layout);
}
@ -1863,19 +1846,16 @@ gtk_calendar_size_allocate (GtkWidget *widget,
{
GtkCalendar *calendar = GTK_CALENDAR (widget);
GtkCalendarPrivate *priv = calendar->priv;
GtkBorder padding;
gint inner_border = calendar_get_inner_border (calendar);
gint calendar_xsep = calendar_get_xsep (calendar);
get_component_paddings (calendar, &padding, NULL, NULL, NULL);
if (priv->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
{
priv->day_width = (priv->min_day_width
* ((allocation->width - (inner_border * 2) - padding.left - padding.right
* ((allocation->width - (inner_border * 2)
- (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - calendar_xsep * 2))
/ (7 * priv->min_day_width + priv->max_week_char_width * 2));
priv->week_width = ((allocation->width - (inner_border * 2) - padding.left - padding.right
priv->week_width = ((allocation->width - (inner_border * 2)
- (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - calendar_xsep * 2 )
- priv->day_width * 7 + CALENDAR_MARGIN + calendar_xsep);
}
@ -1883,7 +1863,6 @@ gtk_calendar_size_allocate (GtkWidget *widget,
{
priv->day_width = (allocation->width
- (inner_border * 2)
- padding.left - padding.right
- (CALENDAR_MARGIN * 2)
- (DAY_XSEP * 6))/7;
priv->week_width = 0;
@ -1901,10 +1880,8 @@ calendar_snapshot_header (GtkCalendar *calendar,
{
GtkWidget *widget = GTK_WIDGET (calendar);
GtkCalendarPrivate *priv = calendar->priv;
GtkAllocation allocation;
GtkStyleContext *context;
GtkStateFlags state;
GtkBorder padding;
char buffer[255];
gint x, y;
gint header_width;
@ -1917,19 +1894,14 @@ calendar_snapshot_header (GtkCalendar *calendar,
struct tm *tm;
gchar *str;
get_component_paddings (calendar, &padding, NULL, NULL, NULL);
context = gtk_widget_get_style_context (widget);
gtk_snapshot_offset (snapshot, padding.left, padding.top);
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
year_left = priv->year_before;
else
year_left = !priv->year_before;
gtk_widget_get_allocation (widget, &allocation);
header_width = allocation.width - padding.left - padding.right;
header_width = gtk_widget_get_width (widget);
max_month_width = priv->max_month_width;
max_year_width = priv->max_year_width;
@ -2008,7 +1980,6 @@ calendar_snapshot_header (GtkCalendar *calendar,
g_object_unref (layout);
gtk_style_context_restore (context);
gtk_snapshot_offset (snapshot, -padding.left, -padding.top);
}
static void
@ -2019,8 +1990,7 @@ calendar_snapshot_day_names (GtkCalendar *calendar,
GtkCalendarPrivate *priv = calendar->priv;
GtkStyleContext *context;
GtkStateFlags state;
GtkBorder padding, day_name_padding;
GtkAllocation allocation;
GtkBorder day_name_padding;
char buffer[255];
int day,i;
int day_width, cal_width;
@ -2031,17 +2001,15 @@ calendar_snapshot_day_names (GtkCalendar *calendar,
gint calendar_xsep = calendar_get_xsep (calendar);
gint inner_border = calendar_get_inner_border (calendar);
get_component_paddings (calendar, &padding, NULL, &day_name_padding, NULL);
get_component_paddings (calendar, NULL, &day_name_padding, NULL);
context = gtk_widget_get_style_context (widget);
gtk_snapshot_offset (snapshot,
padding.left + inner_border,
priv->header_h + padding.top + inner_border);
gtk_widget_get_allocation (widget, &allocation);
inner_border,
priv->header_h + inner_border);
day_width = priv->day_width;
cal_width = allocation.width - (inner_border * 2) - padding.left - padding.right;
cal_width = gtk_widget_get_width (widget) - (inner_border * 2);
day_wid_sep = day_width + DAY_XSEP;
/*
@ -2100,8 +2068,8 @@ calendar_snapshot_day_names (GtkCalendar *calendar,
gtk_style_context_restore (context);
gtk_snapshot_offset (snapshot,
- (padding.left + inner_border),
- (priv->header_h + padding.top + inner_border));
- inner_border,
- (priv->header_h + inner_border));
}
static void
@ -2112,7 +2080,7 @@ calendar_snapshot_week_numbers (GtkCalendar *calendar,
GtkCalendarPrivate *priv = calendar->priv;
GtkStyleContext *context;
GtkStateFlags state;
GtkBorder padding, week_padding;
GtkBorder week_padding;
gint row, x_loc, y_loc;
gint day_height;
char buffer[32];
@ -2122,14 +2090,14 @@ calendar_snapshot_week_numbers (GtkCalendar *calendar,
gint inner_border = calendar_get_inner_border (calendar);
gint x, y;
get_component_paddings (calendar, &padding, NULL, NULL, &week_padding);
get_component_paddings (calendar, NULL, NULL, &week_padding);
context = gtk_widget_get_style_context (widget);
y = priv->header_h + priv->day_name_h + (padding.top + inner_border);
y = priv->header_h + priv->day_name_h + inner_border;
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
x = padding.left + inner_border;
x = inner_border;
else
x = gtk_widget_get_allocated_width (widget) - priv->week_width - (padding.right + inner_border);
x = gtk_widget_get_width (widget) - priv->week_width - inner_border;
state = gtk_style_context_get_state (context);
state &= ~GTK_STATE_FLAG_DROP_ACTIVE;

View File

@ -499,8 +499,7 @@ create_calendar(void)
size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
context = gtk_widget_get_style_context (calendar);
gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL,
GTK_STYLE_PROPERTY_FONT, &font_desc, NULL);
gtk_style_context_get (context, GTK_STYLE_PROPERTY_FONT, &font_desc, NULL);
font = pango_font_description_to_string (font_desc);
button = gtk_font_button_new_with_font (font);
g_free (font);