Commit e936a35d authored by Matthias Clasen's avatar Matthias Clasen

Make GtkCenterBox public

It provides functionality that GtkBox used to have,
and is generally useful.
parent e32f15be
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
<chapter id="LayoutContainers"> <chapter id="LayoutContainers">
<title>Layout Containers</title> <title>Layout Containers</title>
<xi:include href="xml/gtkbox.xml" /> <xi:include href="xml/gtkbox.xml" />
<xi:include href="xml/gtkcenterbox.xml" />
<xi:include href="xml/gtkgrid.xml" /> <xi:include href="xml/gtkgrid.xml" />
<xi:include href="xml/gtkrevealer.xml" /> <xi:include href="xml/gtkrevealer.xml" />
<xi:include href="xml/gtklistbox.xml" /> <xi:include href="xml/gtklistbox.xml" />
......
...@@ -341,6 +341,26 @@ GtkBoxPrivate ...@@ -341,6 +341,26 @@ GtkBoxPrivate
gtk_box_get_type gtk_box_get_type
</SECTION> </SECTION>
<SECTION>
<FILE>gtkcenterbox</FILE>
<TITLE>GtkCenterBox</TITLE>
GtkCenterBox
gtk_center_box_new
gtk_center_box_set_start_widget
gtk_center_box_set_center_widget
gtk_center_box_set_end_widget
gtk_center_box_get_start_widget
gtk_center_box_get_center_widget
gtk_center_box_get_end_widget
<PRIVATE>
GTK_TYPE_CENTER_BOX
GTK_CENTER_BOX
GTK_CENTER_BOX_CLASS
GTK_IS_CENTER_BOX
GTK_IS_CENTER_BOX_CLASS
GTK_CENTER_BOX_GET_CLASS
</SECTION>
<SECTION> <SECTION>
<FILE>gtklistbox</FILE> <FILE>gtklistbox</FILE>
<TITLE>GtkListBox</TITLE> <TITLE>GtkListBox</TITLE>
......
...@@ -68,6 +68,7 @@ ...@@ -68,6 +68,7 @@
#include <gtk/gtkcellrenderertext.h> #include <gtk/gtkcellrenderertext.h>
#include <gtk/gtkcellrenderertoggle.h> #include <gtk/gtkcellrenderertoggle.h>
#include <gtk/gtkcellview.h> #include <gtk/gtkcellview.h>
#include <gtk/gtkcenterbox.h>
#include <gtk/gtkcheckbutton.h> #include <gtk/gtkcheckbutton.h>
#include <gtk/gtkcheckmenuitem.h> #include <gtk/gtkcheckmenuitem.h>
#include <gtk/gtkclipboard.h> #include <gtk/gtkclipboard.h>
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "gtkwidgetprivate.h" #include "gtkwidgetprivate.h"
#include "gtkcontainerprivate.h" #include "gtkcontainerprivate.h"
#include "gtkprivate.h" #include "gtkprivate.h"
#include "gtkcenterboxprivate.h" #include "gtkcenterbox.h"
#include <string.h> #include <string.h>
......
/*
* Copyright (c) 2017 Timm Bäder <mail@baedert.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author: Timm Bäder <mail@baedert.org>
*/
/**
* SECTION:gtkcenterbox
* @Short_description: A centering container
* @Title: GtkCenterBox
* @See_also: #GtkBox
*
* The GtkCenterBox widget arranges three children in a horizontal
* or vertical arrangement, keeping the middle child centered as well
* as possible.
*
* To add children to GtkCenterBox, use gtk_center_box_set_start_widget(),
* gtk_center_box_set_center_widget() and gtk_center_box_set_end_widget().
*
* # CSS nodes
*
* GtkCenterBox uses a single CSS node with name box.
*
* In horizontal orientation, the nodes of the children are always arranged
* from left to right. So :first-child will always select the leftmost child,
* regardless of text direction.
*
* In vertical orientation, the are arranged from top to bottom.
*/
#include "config.h"
#include "gtkcenterbox.h"
#include "gtkcssnodeprivate.h"
#include "gtkwidgetprivate.h"
struct _GtkCenterBox
{
GtkWidget parent_instance;
GtkWidget *start_widget;
GtkWidget *center_widget;
GtkWidget *end_widget;
};
struct _GtkCenterBoxClass
{
GtkWidgetClass parent_class;
};
#include "gtkcenterboxprivate.h"
G_DEFINE_TYPE (GtkCenterBox, gtk_center_box, GTK_TYPE_WIDGET); G_DEFINE_TYPE (GtkCenterBox, gtk_center_box, GTK_TYPE_WIDGET);
...@@ -76,8 +138,7 @@ gtk_center_box_size_allocate (GtkWidget *widget, ...@@ -76,8 +138,7 @@ gtk_center_box_size_allocate (GtkWidget *widget,
GTK_WIDGET_CLASS (gtk_center_box_parent_class)->size_allocate (widget, allocation); GTK_WIDGET_CLASS (gtk_center_box_parent_class)->size_allocate (widget, allocation);
/* TODO: Allocate natural sizes if possible? */
// TODO: Allocate natural sizes if possible?
/* Start Box */ /* Start Box */
gtk_widget_measure (self->start_widget, GTK_ORIENTATION_HORIZONTAL, gtk_widget_measure (self->start_widget, GTK_ORIENTATION_HORIZONTAL,
...@@ -93,7 +154,6 @@ gtk_center_box_size_allocate (GtkWidget *widget, ...@@ -93,7 +154,6 @@ gtk_center_box_size_allocate (GtkWidget *widget,
gdk_rectangle_union (&clip, &clip, &child_clip); gdk_rectangle_union (&clip, &clip, &child_clip);
start_size = child_allocation.width; start_size = child_allocation.width;
/* End Box */ /* End Box */
gtk_widget_measure (self->end_widget, GTK_ORIENTATION_HORIZONTAL, gtk_widget_measure (self->end_widget, GTK_ORIENTATION_HORIZONTAL,
allocation->height, allocation->height,
...@@ -153,6 +213,9 @@ gtk_center_box_class_init (GtkCenterBoxClass *klass) ...@@ -153,6 +213,9 @@ gtk_center_box_class_init (GtkCenterBoxClass *klass)
widget_class->measure = gtk_center_box_measure; widget_class->measure = gtk_center_box_measure;
widget_class->size_allocate = gtk_center_box_size_allocate; widget_class->size_allocate = gtk_center_box_size_allocate;
widget_class->snapshot = gtk_center_box_snapshot; widget_class->snapshot = gtk_center_box_snapshot;
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_FILLER);
gtk_widget_class_set_css_name (widget_class, "box");
} }
static void static void
...@@ -165,12 +228,30 @@ gtk_center_box_init (GtkCenterBox *self) ...@@ -165,12 +228,30 @@ gtk_center_box_init (GtkCenterBox *self)
self->end_widget = NULL; self->end_widget = NULL;
} }
/**
* gtk_center_box_new:
*
* Creates a new #GtkCenterBox.
*
* Returns: the new #GtkCenterBox.
*
* Since: 3.92
*/
GtkWidget * GtkWidget *
gtk_center_box_new (void) gtk_center_box_new (void)
{ {
return GTK_WIDGET (g_object_new (GTK_TYPE_CENTER_BOX, NULL)); return GTK_WIDGET (g_object_new (GTK_TYPE_CENTER_BOX, NULL));
} }
/**
* gtk_center_box_set_start_widget:
* @self: a #GtkCenterBox
* @child: the child
*
* Sets the start widget.
*
* Since: 3.92
*/
void void
gtk_center_box_set_start_widget (GtkCenterBox *self, gtk_center_box_set_start_widget (GtkCenterBox *self,
GtkWidget *child) GtkWidget *child)
...@@ -183,6 +264,15 @@ gtk_center_box_set_start_widget (GtkCenterBox *self, ...@@ -183,6 +264,15 @@ gtk_center_box_set_start_widget (GtkCenterBox *self,
gtk_widget_set_parent (child, GTK_WIDGET (self)); gtk_widget_set_parent (child, GTK_WIDGET (self));
} }
/**
* gtk_center_box_set_center_widget:
* @self: a #GtkCenterBox
* @child: the child
*
* Sets the center widget.
*
* Since: 3.92
*/
void void
gtk_center_box_set_center_widget (GtkCenterBox *self, gtk_center_box_set_center_widget (GtkCenterBox *self,
GtkWidget *child) GtkWidget *child)
...@@ -195,6 +285,15 @@ gtk_center_box_set_center_widget (GtkCenterBox *self, ...@@ -195,6 +285,15 @@ gtk_center_box_set_center_widget (GtkCenterBox *self,
gtk_widget_set_parent (child, GTK_WIDGET (self)); gtk_widget_set_parent (child, GTK_WIDGET (self));
} }
/**
* gtk_center_box_set_end_widget:
* @self: a #GtkCenterBox
* @child: the child
*
* Sets the end widget.
*
* Since: 3.92
*/
void void
gtk_center_box_set_end_widget (GtkCenterBox *self, gtk_center_box_set_end_widget (GtkCenterBox *self,
GtkWidget *child) GtkWidget *child)
...@@ -207,18 +306,48 @@ gtk_center_box_set_end_widget (GtkCenterBox *self, ...@@ -207,18 +306,48 @@ gtk_center_box_set_end_widget (GtkCenterBox *self,
gtk_widget_set_parent (child, GTK_WIDGET (self)); gtk_widget_set_parent (child, GTK_WIDGET (self));
} }
/**
* gtk_center_box_get_start_widget:
* @self: a #GtkCenterBox
*
* Gets the start widget.
*
* Returns: the start widget.
*
* Since: 3.92
*/
GtkWidget * GtkWidget *
gtk_center_box_get_start_widget (GtkCenterBox *self) gtk_center_box_get_start_widget (GtkCenterBox *self)
{ {
return self->start_widget; return self->start_widget;
} }
/**
* gtk_center_box_get_center_widget:
* @self: a #GtkCenterBox
*
* Gets the center widget.
*
* Returns: the center widget.
*
* Since: 3.92
*/
GtkWidget * GtkWidget *
gtk_center_box_get_center_widget (GtkCenterBox *self) gtk_center_box_get_center_widget (GtkCenterBox *self)
{ {
return self->center_widget; return self->center_widget;
} }
/**
* gtk_center_box_get_end_widget:
* @self: a #GtkCenterBox
*
* Gets the end widget.
*
* Returns: the end widget.
*
* Since: 3.92
*/
GtkWidget * GtkWidget *
gtk_center_box_get_end_widget (GtkCenterBox *self) gtk_center_box_get_end_widget (GtkCenterBox *self)
{ {
......
/*
* Copyright (c) 2017 Timm Bäder <mail@baedert.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author: Timm Bäder <mail@baedert.org>
*
*/
#ifndef __GTK_CENTER_BOX_H__ #ifndef __GTK_CENTER_BOX_H__
#define __GTK_CENTER_BOX_H__ #define __GTK_CENTER_BOX_H__
...@@ -14,29 +34,26 @@ ...@@ -14,29 +34,26 @@
typedef struct _GtkCenterBox GtkCenterBox; typedef struct _GtkCenterBox GtkCenterBox;
typedef struct _GtkCenterBoxClass GtkCenterBoxClass; typedef struct _GtkCenterBoxClass GtkCenterBoxClass;
struct _GtkCenterBox GDK_AVAILABLE_IN_3_92
{
GtkWidget parent_instance;
GtkWidget *start_widget;
GtkWidget *center_widget;
GtkWidget *end_widget;
};
struct _GtkCenterBoxClass
{
GtkWidgetClass parent_class;
};
GType gtk_center_box_get_type (void) G_GNUC_CONST; GType gtk_center_box_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_3_92
GtkWidget *gtk_center_box_new (void); GtkWidget *gtk_center_box_new (void);
void gtk_center_box_set_start_widget (GtkCenterBox *self, GtkWidget *child); GDK_AVAILABLE_IN_3_92
void gtk_center_box_set_center_widget (GtkCenterBox *self, GtkWidget *child); void gtk_center_box_set_start_widget (GtkCenterBox *self,
void gtk_center_box_set_end_widget (GtkCenterBox *self, GtkWidget *child); GtkWidget *child);
GDK_AVAILABLE_IN_3_92
void gtk_center_box_set_center_widget (GtkCenterBox *self,
GtkWidget *child);
GDK_AVAILABLE_IN_3_92
void gtk_center_box_set_end_widget (GtkCenterBox *self,
GtkWidget *child);
GDK_AVAILABLE_IN_3_92
GtkWidget * gtk_center_box_get_start_widget (GtkCenterBox *self); GtkWidget * gtk_center_box_get_start_widget (GtkCenterBox *self);
GDK_AVAILABLE_IN_3_92
GtkWidget * gtk_center_box_get_center_widget (GtkCenterBox *self); GtkWidget * gtk_center_box_get_center_widget (GtkCenterBox *self);
GDK_AVAILABLE_IN_3_92
GtkWidget * gtk_center_box_get_end_widget (GtkCenterBox *self); GtkWidget * gtk_center_box_get_end_widget (GtkCenterBox *self);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment