Merge branch 'default-request-mode' into 'master'

Add default GtkLayoutManagerClass.get_request_mode()

See merge request GNOME/gtk!738
This commit is contained in:
Emmanuele Bassi 2019-04-12 17:59:04 +00:00
commit 1b6252ebf0
4 changed files with 40 additions and 40 deletions

View File

@ -199,42 +199,6 @@ get_spacing (GtkBoxLayout *self,
return css_spacing + self->spacing;
}
static GtkSizeRequestMode
gtk_box_layout_get_request_mode (GtkLayoutManager *layout_manager,
GtkWidget *widget)
{
GtkWidget *child;
int wfh = 0, hfw = 0;
for (child = _gtk_widget_get_first_child (widget);
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
GtkSizeRequestMode mode = gtk_widget_get_request_mode (child);
switch (mode)
{
case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH:
hfw += 1;
break;
case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT:
wfh += 1;
break;
case GTK_SIZE_REQUEST_CONSTANT_SIZE:
default:
break;
}
}
if (hfw == 0 && wfh == 0)
return GTK_SIZE_REQUEST_CONSTANT_SIZE;
else
return wfh > hfw ? GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT
: GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;
}
static void
gtk_box_layout_compute_size (GtkBoxLayout *self,
GtkWidget *widget,
@ -738,7 +702,6 @@ gtk_box_layout_class_init (GtkBoxLayoutClass *klass)
gobject_class->set_property = gtk_box_layout_set_property;
gobject_class->get_property = gtk_box_layout_get_property;
layout_manager_class->get_request_mode = gtk_box_layout_get_request_mode;
layout_manager_class->measure = gtk_box_layout_measure;
layout_manager_class->allocate = gtk_box_layout_allocate;

View File

@ -36,7 +36,7 @@ gtk_custom_layout_get_request_mode (GtkLayoutManager *manager,
if (self->request_mode_func != NULL)
return self->request_mode_func (widget);
return GTK_SIZE_REQUEST_CONSTANT_SIZE;
return GTK_LAYOUT_MANAGER_CLASS (gtk_custom_layout_parent_class)->get_request_mode (manager, widget);
}
static void

View File

@ -208,6 +208,13 @@ gtk_fixed_layout_child_get_position (GtkFixedLayoutChild *child)
G_DEFINE_TYPE (GtkFixedLayout, gtk_fixed_layout, GTK_TYPE_LAYOUT_MANAGER)
static GtkSizeRequestMode
gtk_fixed_layout_get_request_mode (GtkLayoutManager *layout_manager,
GtkWidget *widget)
{
return GTK_SIZE_REQUEST_CONSTANT_SIZE;
}
static void
gtk_fixed_layout_measure (GtkLayoutManager *layout_manager,
GtkWidget *widget,
@ -316,6 +323,7 @@ gtk_fixed_layout_class_init (GtkFixedLayoutClass *klass)
layout_class->layout_child_type = GTK_TYPE_FIXED_LAYOUT_CHILD;
layout_class->get_request_mode = gtk_fixed_layout_get_request_mode;
layout_class->measure = gtk_fixed_layout_measure;
layout_class->allocate = gtk_fixed_layout_allocate;
layout_class->create_layout_child = gtk_fixed_layout_create_layout_child;

View File

@ -75,7 +75,7 @@
#include "gtklayoutmanagerprivate.h"
#include "gtklayoutchild.h"
#include "gtkwidget.h"
#include "gtkwidgetprivate.h"
#ifdef G_ENABLE_DEBUG
#define LAYOUT_MANAGER_WARN_NOT_IMPLEMENTED(m,method) G_STMT_START { \
@ -101,7 +101,36 @@ static GtkSizeRequestMode
gtk_layout_manager_real_get_request_mode (GtkLayoutManager *manager,
GtkWidget *widget)
{
return GTK_SIZE_REQUEST_CONSTANT_SIZE;
int hfw = 0, wfh = 0;
GtkWidget *child;
for (child = _gtk_widget_get_first_child (widget);
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
GtkSizeRequestMode res = gtk_widget_get_request_mode (child);
switch (res)
{
case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH:
hfw += 1;
break;
case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT:
wfh += 1;
break;
case GTK_SIZE_REQUEST_CONSTANT_SIZE:
default:
break;
}
}
if (hfw == 0 && wfh == 0)
return GTK_SIZE_REQUEST_CONSTANT_SIZE;
return hfw > wfh ? GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH
: GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
}
static void