forked from AuroraMiddleware/gtk
Add default GtkLayoutManagerClass.get_request_mode()
Just like GtkContainer provides a default implementation of GtkWidgetClass.get_request_mode(), we can do the same inside GtkLayoutManager. A default implementation preserves the behavior of existing widgets that moved, or will move, to a GtkLayoutManager.
This commit is contained in:
parent
bd2d07e671
commit
a27737b04e
@ -199,42 +199,6 @@ get_spacing (GtkBoxLayout *self,
|
|||||||
return css_spacing + self->spacing;
|
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
|
static void
|
||||||
gtk_box_layout_compute_size (GtkBoxLayout *self,
|
gtk_box_layout_compute_size (GtkBoxLayout *self,
|
||||||
GtkWidget *widget,
|
GtkWidget *widget,
|
||||||
@ -738,7 +702,6 @@ gtk_box_layout_class_init (GtkBoxLayoutClass *klass)
|
|||||||
gobject_class->set_property = gtk_box_layout_set_property;
|
gobject_class->set_property = gtk_box_layout_set_property;
|
||||||
gobject_class->get_property = gtk_box_layout_get_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->measure = gtk_box_layout_measure;
|
||||||
layout_manager_class->allocate = gtk_box_layout_allocate;
|
layout_manager_class->allocate = gtk_box_layout_allocate;
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ gtk_custom_layout_get_request_mode (GtkLayoutManager *manager,
|
|||||||
if (self->request_mode_func != NULL)
|
if (self->request_mode_func != NULL)
|
||||||
return self->request_mode_func (widget);
|
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
|
static void
|
||||||
|
@ -208,6 +208,13 @@ gtk_fixed_layout_child_get_position (GtkFixedLayoutChild *child)
|
|||||||
|
|
||||||
G_DEFINE_TYPE (GtkFixedLayout, gtk_fixed_layout, GTK_TYPE_LAYOUT_MANAGER)
|
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
|
static void
|
||||||
gtk_fixed_layout_measure (GtkLayoutManager *layout_manager,
|
gtk_fixed_layout_measure (GtkLayoutManager *layout_manager,
|
||||||
GtkWidget *widget,
|
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->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->measure = gtk_fixed_layout_measure;
|
||||||
layout_class->allocate = gtk_fixed_layout_allocate;
|
layout_class->allocate = gtk_fixed_layout_allocate;
|
||||||
layout_class->create_layout_child = gtk_fixed_layout_create_layout_child;
|
layout_class->create_layout_child = gtk_fixed_layout_create_layout_child;
|
||||||
|
@ -75,7 +75,7 @@
|
|||||||
|
|
||||||
#include "gtklayoutmanagerprivate.h"
|
#include "gtklayoutmanagerprivate.h"
|
||||||
#include "gtklayoutchild.h"
|
#include "gtklayoutchild.h"
|
||||||
#include "gtkwidget.h"
|
#include "gtkwidgetprivate.h"
|
||||||
|
|
||||||
#ifdef G_ENABLE_DEBUG
|
#ifdef G_ENABLE_DEBUG
|
||||||
#define LAYOUT_MANAGER_WARN_NOT_IMPLEMENTED(m,method) G_STMT_START { \
|
#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,
|
gtk_layout_manager_real_get_request_mode (GtkLayoutManager *manager,
|
||||||
GtkWidget *widget)
|
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
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user