mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 14:10:30 +00:00
calendar: Fix for GTK4 changes
This commit is contained in:
parent
f4e1a2b849
commit
723bf44887
@ -1052,7 +1052,6 @@ calendar_row_height (GtkCalendar *calendar)
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
get_component_paddings (GtkCalendar *calendar,
|
get_component_paddings (GtkCalendar *calendar,
|
||||||
GtkBorder *padding,
|
|
||||||
GtkBorder *day_padding,
|
GtkBorder *day_padding,
|
||||||
GtkBorder *day_name_padding,
|
GtkBorder *day_name_padding,
|
||||||
GtkBorder *week_padding)
|
GtkBorder *week_padding)
|
||||||
@ -1063,9 +1062,6 @@ get_component_paddings (GtkCalendar *calendar,
|
|||||||
widget = GTK_WIDGET (calendar);
|
widget = GTK_WIDGET (calendar);
|
||||||
context = gtk_widget_get_style_context (widget);
|
context = gtk_widget_get_style_context (widget);
|
||||||
|
|
||||||
if (padding)
|
|
||||||
gtk_style_context_get_padding (context, padding);
|
|
||||||
|
|
||||||
if (day_padding)
|
if (day_padding)
|
||||||
{
|
{
|
||||||
gtk_style_context_save (context);
|
gtk_style_context_save (context);
|
||||||
@ -1103,11 +1099,10 @@ calendar_left_x_for_column (GtkCalendar *calendar,
|
|||||||
gint week_width;
|
gint week_width;
|
||||||
gint calendar_xsep = calendar_get_xsep (calendar);
|
gint calendar_xsep = calendar_get_xsep (calendar);
|
||||||
gint inner_border = calendar_get_inner_border (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)
|
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)
|
gint row)
|
||||||
{
|
{
|
||||||
GtkCalendarPrivate *priv = calendar->priv;
|
GtkCalendarPrivate *priv = calendar->priv;
|
||||||
GtkBorder padding;
|
|
||||||
gint inner_border = calendar_get_inner_border (calendar);
|
gint inner_border = calendar_get_inner_border (calendar);
|
||||||
|
|
||||||
get_component_paddings (calendar, &padding, NULL, NULL, NULL);
|
return priv->header_h + priv->day_name_h + inner_border
|
||||||
|
|
||||||
return priv->header_h + priv->day_name_h + padding.top + inner_border
|
|
||||||
+ row * calendar_row_height (calendar);
|
+ row * calendar_row_height (calendar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1201,12 +1193,10 @@ calendar_arrow_rectangle (GtkCalendar *calendar,
|
|||||||
{
|
{
|
||||||
GtkWidget *widget = GTK_WIDGET (calendar);
|
GtkWidget *widget = GTK_WIDGET (calendar);
|
||||||
GtkCalendarPrivate *priv = calendar->priv;
|
GtkCalendarPrivate *priv = calendar->priv;
|
||||||
int width, height;
|
int width;
|
||||||
GtkBorder padding;
|
|
||||||
gboolean year_left;
|
gboolean year_left;
|
||||||
|
|
||||||
get_component_paddings (calendar, &padding, NULL, NULL, NULL);
|
width = gtk_widget_get_width (widget);
|
||||||
gtk_widget_get_content_size (widget, &width, &height);
|
|
||||||
|
|
||||||
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;
|
||||||
@ -1221,39 +1211,32 @@ calendar_arrow_rectangle (GtkCalendar *calendar,
|
|||||||
{
|
{
|
||||||
case ARROW_MONTH_LEFT:
|
case ARROW_MONTH_LEFT:
|
||||||
if (year_left)
|
if (year_left)
|
||||||
rect->x = (width - padding.left - padding.right
|
rect->x = (width - (3 + 2 * priv->arrow_width + priv->max_month_width));
|
||||||
- (3 + 2 * priv->arrow_width + priv->max_month_width));
|
|
||||||
else
|
else
|
||||||
rect->x = 3;
|
rect->x = 3;
|
||||||
break;
|
break;
|
||||||
case ARROW_MONTH_RIGHT:
|
case ARROW_MONTH_RIGHT:
|
||||||
if (year_left)
|
if (year_left)
|
||||||
rect->x = (width - padding.left - padding.right
|
rect->x = width - 3 - priv->arrow_width;
|
||||||
- 3 - priv->arrow_width);
|
|
||||||
else
|
else
|
||||||
rect->x = (priv->arrow_width + priv->max_month_width);
|
rect->x = priv->arrow_width + priv->max_month_width;
|
||||||
break;
|
break;
|
||||||
case ARROW_YEAR_LEFT:
|
case ARROW_YEAR_LEFT:
|
||||||
if (year_left)
|
if (year_left)
|
||||||
rect->x = 3;
|
rect->x = 3;
|
||||||
else
|
else
|
||||||
rect->x = (width - padding.left - padding.right
|
rect->x = width - (3 + 2 * priv->arrow_width + priv->max_year_width);
|
||||||
- (3 + 2 * priv->arrow_width + priv->max_year_width));
|
|
||||||
break;
|
break;
|
||||||
case ARROW_YEAR_RIGHT:
|
case ARROW_YEAR_RIGHT:
|
||||||
if (year_left)
|
if (year_left)
|
||||||
rect->x = (priv->arrow_width + priv->max_year_width);
|
rect->x = (priv->arrow_width + priv->max_year_width);
|
||||||
else
|
else
|
||||||
rect->x = (width - padding.left - padding.right
|
rect->x = width - 3 - priv->arrow_width;
|
||||||
- 3 - priv->arrow_width);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
g_assert_not_reached();
|
g_assert_not_reached();
|
||||||
}
|
}
|
||||||
|
|
||||||
rect->x += padding.left;
|
|
||||||
rect->y += padding.top;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1600,7 +1583,7 @@ gtk_calendar_size_request (GtkWidget *widget,
|
|||||||
{
|
{
|
||||||
GtkCalendar *calendar = GTK_CALENDAR (widget);
|
GtkCalendar *calendar = GTK_CALENDAR (widget);
|
||||||
GtkCalendarPrivate *priv = calendar->priv;
|
GtkCalendarPrivate *priv = calendar->priv;
|
||||||
GtkBorder padding, day_padding, day_name_padding, week_padding;
|
GtkBorder day_padding, day_name_padding, week_padding;
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
PangoRectangle logical_rect;
|
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;
|
priv->min_day_width += day_padding.left + day_padding.right;
|
||||||
if (show_week_numbers)
|
if (show_week_numbers)
|
||||||
@ -1794,7 +1777,7 @@ gtk_calendar_size_request (GtkWidget *widget,
|
|||||||
? priv->max_week_char_width * 2 + calendar_xsep * 2
|
? priv->max_week_char_width * 2 + calendar_xsep * 2
|
||||||
: 0));
|
: 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.
|
* 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;
|
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);
|
g_object_unref (layout);
|
||||||
}
|
}
|
||||||
@ -1863,19 +1846,16 @@ gtk_calendar_size_allocate (GtkWidget *widget,
|
|||||||
{
|
{
|
||||||
GtkCalendar *calendar = GTK_CALENDAR (widget);
|
GtkCalendar *calendar = GTK_CALENDAR (widget);
|
||||||
GtkCalendarPrivate *priv = calendar->priv;
|
GtkCalendarPrivate *priv = calendar->priv;
|
||||||
GtkBorder padding;
|
|
||||||
gint inner_border = calendar_get_inner_border (calendar);
|
gint inner_border = calendar_get_inner_border (calendar);
|
||||||
gint calendar_xsep = calendar_get_xsep (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)
|
if (priv->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
|
||||||
{
|
{
|
||||||
priv->day_width = (priv->min_day_width
|
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))
|
- (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - calendar_xsep * 2))
|
||||||
/ (7 * priv->min_day_width + priv->max_week_char_width * 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 )
|
- (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - calendar_xsep * 2 )
|
||||||
- priv->day_width * 7 + CALENDAR_MARGIN + calendar_xsep);
|
- priv->day_width * 7 + CALENDAR_MARGIN + calendar_xsep);
|
||||||
}
|
}
|
||||||
@ -1883,7 +1863,6 @@ gtk_calendar_size_allocate (GtkWidget *widget,
|
|||||||
{
|
{
|
||||||
priv->day_width = (allocation->width
|
priv->day_width = (allocation->width
|
||||||
- (inner_border * 2)
|
- (inner_border * 2)
|
||||||
- padding.left - padding.right
|
|
||||||
- (CALENDAR_MARGIN * 2)
|
- (CALENDAR_MARGIN * 2)
|
||||||
- (DAY_XSEP * 6))/7;
|
- (DAY_XSEP * 6))/7;
|
||||||
priv->week_width = 0;
|
priv->week_width = 0;
|
||||||
@ -1901,10 +1880,8 @@ calendar_snapshot_header (GtkCalendar *calendar,
|
|||||||
{
|
{
|
||||||
GtkWidget *widget = GTK_WIDGET (calendar);
|
GtkWidget *widget = GTK_WIDGET (calendar);
|
||||||
GtkCalendarPrivate *priv = calendar->priv;
|
GtkCalendarPrivate *priv = calendar->priv;
|
||||||
GtkAllocation allocation;
|
|
||||||
GtkStyleContext *context;
|
GtkStyleContext *context;
|
||||||
GtkStateFlags state;
|
GtkStateFlags state;
|
||||||
GtkBorder padding;
|
|
||||||
char buffer[255];
|
char buffer[255];
|
||||||
gint x, y;
|
gint x, y;
|
||||||
gint header_width;
|
gint header_width;
|
||||||
@ -1917,19 +1894,14 @@ calendar_snapshot_header (GtkCalendar *calendar,
|
|||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
gchar *str;
|
gchar *str;
|
||||||
|
|
||||||
get_component_paddings (calendar, &padding, NULL, NULL, NULL);
|
|
||||||
context = gtk_widget_get_style_context (widget);
|
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)
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
|
||||||
year_left = priv->year_before;
|
year_left = priv->year_before;
|
||||||
else
|
else
|
||||||
year_left = !priv->year_before;
|
year_left = !priv->year_before;
|
||||||
|
|
||||||
gtk_widget_get_allocation (widget, &allocation);
|
header_width = gtk_widget_get_width (widget);
|
||||||
|
|
||||||
header_width = allocation.width - padding.left - padding.right;
|
|
||||||
|
|
||||||
max_month_width = priv->max_month_width;
|
max_month_width = priv->max_month_width;
|
||||||
max_year_width = priv->max_year_width;
|
max_year_width = priv->max_year_width;
|
||||||
@ -2008,7 +1980,6 @@ calendar_snapshot_header (GtkCalendar *calendar,
|
|||||||
g_object_unref (layout);
|
g_object_unref (layout);
|
||||||
|
|
||||||
gtk_style_context_restore (context);
|
gtk_style_context_restore (context);
|
||||||
gtk_snapshot_offset (snapshot, -padding.left, -padding.top);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2019,8 +1990,7 @@ calendar_snapshot_day_names (GtkCalendar *calendar,
|
|||||||
GtkCalendarPrivate *priv = calendar->priv;
|
GtkCalendarPrivate *priv = calendar->priv;
|
||||||
GtkStyleContext *context;
|
GtkStyleContext *context;
|
||||||
GtkStateFlags state;
|
GtkStateFlags state;
|
||||||
GtkBorder padding, day_name_padding;
|
GtkBorder day_name_padding;
|
||||||
GtkAllocation allocation;
|
|
||||||
char buffer[255];
|
char buffer[255];
|
||||||
int day,i;
|
int day,i;
|
||||||
int day_width, cal_width;
|
int day_width, cal_width;
|
||||||
@ -2031,17 +2001,15 @@ calendar_snapshot_day_names (GtkCalendar *calendar,
|
|||||||
gint calendar_xsep = calendar_get_xsep (calendar);
|
gint calendar_xsep = calendar_get_xsep (calendar);
|
||||||
gint inner_border = calendar_get_inner_border (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);
|
context = gtk_widget_get_style_context (widget);
|
||||||
|
|
||||||
gtk_snapshot_offset (snapshot,
|
gtk_snapshot_offset (snapshot,
|
||||||
padding.left + inner_border,
|
inner_border,
|
||||||
priv->header_h + padding.top + inner_border);
|
priv->header_h + inner_border);
|
||||||
|
|
||||||
gtk_widget_get_allocation (widget, &allocation);
|
|
||||||
|
|
||||||
day_width = priv->day_width;
|
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;
|
day_wid_sep = day_width + DAY_XSEP;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2100,8 +2068,8 @@ calendar_snapshot_day_names (GtkCalendar *calendar,
|
|||||||
|
|
||||||
gtk_style_context_restore (context);
|
gtk_style_context_restore (context);
|
||||||
gtk_snapshot_offset (snapshot,
|
gtk_snapshot_offset (snapshot,
|
||||||
- (padding.left + inner_border),
|
- inner_border,
|
||||||
- (priv->header_h + padding.top + inner_border));
|
- (priv->header_h + inner_border));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2112,7 +2080,7 @@ calendar_snapshot_week_numbers (GtkCalendar *calendar,
|
|||||||
GtkCalendarPrivate *priv = calendar->priv;
|
GtkCalendarPrivate *priv = calendar->priv;
|
||||||
GtkStyleContext *context;
|
GtkStyleContext *context;
|
||||||
GtkStateFlags state;
|
GtkStateFlags state;
|
||||||
GtkBorder padding, week_padding;
|
GtkBorder week_padding;
|
||||||
gint row, x_loc, y_loc;
|
gint row, x_loc, y_loc;
|
||||||
gint day_height;
|
gint day_height;
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
@ -2122,14 +2090,14 @@ calendar_snapshot_week_numbers (GtkCalendar *calendar,
|
|||||||
gint inner_border = calendar_get_inner_border (calendar);
|
gint inner_border = calendar_get_inner_border (calendar);
|
||||||
gint x, y;
|
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);
|
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)
|
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
|
||||||
x = padding.left + inner_border;
|
x = inner_border;
|
||||||
else
|
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_style_context_get_state (context);
|
||||||
state &= ~GTK_STATE_FLAG_DROP_ACTIVE;
|
state &= ~GTK_STATE_FLAG_DROP_ACTIVE;
|
||||||
|
@ -499,8 +499,7 @@ create_calendar(void)
|
|||||||
size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
size = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
||||||
|
|
||||||
context = gtk_widget_get_style_context (calendar);
|
context = gtk_widget_get_style_context (calendar);
|
||||||
gtk_style_context_get (context, GTK_STATE_FLAG_NORMAL,
|
gtk_style_context_get (context, GTK_STYLE_PROPERTY_FONT, &font_desc, NULL);
|
||||||
GTK_STYLE_PROPERTY_FONT, &font_desc, NULL);
|
|
||||||
font = pango_font_description_to_string (font_desc);
|
font = pango_font_description_to_string (font_desc);
|
||||||
button = gtk_font_button_new_with_font (font);
|
button = gtk_font_button_new_with_font (font);
|
||||||
g_free (font);
|
g_free (font);
|
||||||
|
Loading…
Reference in New Issue
Block a user