2013-03-10 19:15:45 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-05-24 13:07:16 +00:00
|
|
|
#include "gtkheaderbarprivate.h"
|
2018-02-08 23:42:38 +00:00
|
|
|
|
2020-05-01 22:01:12 +00:00
|
|
|
#include "gtkbinlayout.h"
|
2018-02-08 23:42:38 +00:00
|
|
|
#include "gtkbox.h"
|
|
|
|
#include "gtkbuildable.h"
|
2020-05-01 22:01:12 +00:00
|
|
|
#include "gtkcenterbox.h"
|
2018-02-08 23:42:38 +00:00
|
|
|
#include "gtkcssnodeprivate.h"
|
2013-03-10 19:15:45 +00:00
|
|
|
#include "gtkintl.h"
|
2018-02-08 23:42:38 +00:00
|
|
|
#include "gtklabel.h"
|
2020-04-24 15:55:43 +00:00
|
|
|
#include "gtknative.h"
|
2013-03-10 19:15:45 +00:00
|
|
|
#include "gtkprivate.h"
|
2018-02-08 23:42:38 +00:00
|
|
|
#include "gtksizerequest.h"
|
2013-03-10 19:15:45 +00:00
|
|
|
#include "gtktypebuiltins.h"
|
|
|
|
#include "gtkwidgetprivate.h"
|
2020-04-24 15:55:43 +00:00
|
|
|
#include "gtkwindowcontrols.h"
|
2020-05-02 15:37:41 +00:00
|
|
|
#include "gtkwindowhandle.h"
|
2018-02-08 23:42:38 +00:00
|
|
|
|
2013-03-10 19:15:45 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gtkheaderbar
|
|
|
|
* @Short_description: A box with a centered child
|
|
|
|
* @Title: GtkHeaderBar
|
2014-01-23 16:28:17 +00:00
|
|
|
* @See_also: #GtkBox, #GtkActionBar
|
2013-03-10 19:15:45 +00:00
|
|
|
*
|
2014-01-31 10:24:18 +00:00
|
|
|
* GtkHeaderBar is similar to a horizontal #GtkBox. It allows children to
|
2020-04-30 23:04:08 +00:00
|
|
|
* be placed at the start or the end. In addition, it allows the window
|
|
|
|
* title to be displayed. The title will be centered with respect to the
|
|
|
|
* width of the box, even if the children at either side take up different
|
|
|
|
* amounts of space.
|
2013-12-22 02:58:24 +00:00
|
|
|
*
|
|
|
|
* GtkHeaderBar can add typical window frame controls, such as minimize,
|
|
|
|
* maximize and close buttons, or the window icon.
|
2018-01-12 22:56:11 +00:00
|
|
|
*
|
|
|
|
* For these reasons, GtkHeaderBar is the natural choice for use as the custom
|
|
|
|
* titlebar widget of a #GtkWindow (see gtk_window_set_titlebar()), as it gives
|
|
|
|
* features typical of titlebars while allowing the addition of child widgets.
|
2019-09-13 08:40:26 +00:00
|
|
|
*
|
2020-05-01 15:10:52 +00:00
|
|
|
* The GtkHeaderBar implementation of the #GtkBuildable interface supports
|
|
|
|
* adding children at the start or end sides by specifying “start” or “end” as
|
|
|
|
* the “type” attribute of a <child> element, or setting the title widget by
|
|
|
|
* specifying “title” value.
|
|
|
|
*
|
|
|
|
* By default the GtkHeaderBar uses a #GtkLabel displaying the title of the
|
|
|
|
* window it is contained in as the title widget, equivalent to the following
|
|
|
|
* UI definition:
|
|
|
|
*
|
|
|
|
* |[
|
|
|
|
* <object class="GtkHeaderBar">
|
|
|
|
* <property name="title-widget">
|
|
|
|
* <object class="GtkLabel">
|
|
|
|
* <property name="label" translatable="yes">Label</property>
|
|
|
|
* <property name="single-line-mode">True</property>
|
|
|
|
* <property name="ellipsize">end</property>
|
|
|
|
* <property name="width-chars">5</property>
|
|
|
|
* <style>
|
|
|
|
* <class name="title"/>
|
|
|
|
* </style>
|
|
|
|
* </object>
|
|
|
|
* </property>
|
|
|
|
* </object>
|
|
|
|
* ]|
|
|
|
|
*
|
2019-09-13 08:40:26 +00:00
|
|
|
* # CSS nodes
|
|
|
|
*
|
|
|
|
* |[<!-- language="plain" -->
|
|
|
|
* headerbar
|
2020-05-02 15:37:41 +00:00
|
|
|
* ╰── windowhandle
|
|
|
|
* ╰── box
|
|
|
|
* ├── box.start
|
|
|
|
* │ ├── windowcontrols.start
|
|
|
|
* │ ╰── [other children]
|
|
|
|
* ├── [Title Widget]
|
|
|
|
* ╰── box.end
|
|
|
|
* ├── [other children]
|
|
|
|
* ╰── windowcontrols.end
|
2019-09-13 08:40:26 +00:00
|
|
|
* ]|
|
|
|
|
*
|
2020-05-02 15:37:41 +00:00
|
|
|
* A #GtkHeaderBar's CSS node is called headerbar. It contains a windowhandle
|
|
|
|
* subnode, which contains a box subnode, which contains two box subnodes at
|
|
|
|
* the start and end of the headerbar, as well as a center node that represents
|
|
|
|
* the title.
|
2019-09-13 08:40:26 +00:00
|
|
|
*
|
2020-04-24 15:55:43 +00:00
|
|
|
* Each of the boxes contains a windowcontrols subnode, see #GtkWindowControls
|
|
|
|
* for details, as well as other children.
|
2013-03-10 19:15:45 +00:00
|
|
|
*/
|
|
|
|
|
2015-06-23 08:54:39 +00:00
|
|
|
#define MIN_TITLE_CHARS 5
|
2013-03-10 19:15:45 +00:00
|
|
|
|
2019-05-27 02:32:21 +00:00
|
|
|
typedef struct _GtkHeaderBarPrivate GtkHeaderBarPrivate;
|
|
|
|
typedef struct _GtkHeaderBarClass GtkHeaderBarClass;
|
|
|
|
|
|
|
|
struct _GtkHeaderBar
|
|
|
|
{
|
2020-05-08 13:37:52 +00:00
|
|
|
GtkWidget container;
|
2019-05-27 02:32:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkHeaderBarClass
|
|
|
|
{
|
2020-05-08 13:37:52 +00:00
|
|
|
GtkWidgetClass parent_class;
|
2019-05-27 02:32:21 +00:00
|
|
|
};
|
|
|
|
|
2013-03-10 19:15:45 +00:00
|
|
|
struct _GtkHeaderBarPrivate
|
|
|
|
{
|
2020-05-02 15:37:41 +00:00
|
|
|
GtkWidget *handle;
|
2020-05-01 22:01:12 +00:00
|
|
|
GtkWidget *center_box;
|
2019-09-11 16:15:30 +00:00
|
|
|
GtkWidget *start_box;
|
|
|
|
GtkWidget *end_box;
|
|
|
|
|
2013-03-20 02:07:26 +00:00
|
|
|
GtkWidget *title_label;
|
2020-04-30 23:17:27 +00:00
|
|
|
GtkWidget *title_widget;
|
2013-03-10 19:15:45 +00:00
|
|
|
|
2017-12-08 03:36:29 +00:00
|
|
|
gboolean show_title_buttons;
|
2013-12-22 02:58:24 +00:00
|
|
|
gchar *decoration_layout;
|
2019-05-12 09:58:22 +00:00
|
|
|
gboolean track_default_decoration;
|
2013-12-11 06:26:34 +00:00
|
|
|
|
2020-04-24 15:55:43 +00:00
|
|
|
GtkWidget *start_window_controls;
|
|
|
|
GtkWidget *end_window_controls;
|
2013-12-11 06:26:34 +00:00
|
|
|
|
2018-03-20 10:40:08 +00:00
|
|
|
GdkSurfaceState state;
|
2013-03-10 19:15:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
2020-04-30 23:17:27 +00:00
|
|
|
PROP_TITLE_WIDGET,
|
2017-12-08 03:36:29 +00:00
|
|
|
PROP_SHOW_TITLE_BUTTONS,
|
2013-12-22 02:58:24 +00:00
|
|
|
PROP_DECORATION_LAYOUT,
|
2015-09-06 14:41:43 +00:00
|
|
|
LAST_PROP
|
2013-03-10 19:15:45 +00:00
|
|
|
};
|
|
|
|
|
2015-09-06 14:41:43 +00:00
|
|
|
static GParamSpec *header_bar_props[LAST_PROP] = { NULL, };
|
|
|
|
|
2013-05-31 10:59:46 +00:00
|
|
|
static void gtk_header_bar_buildable_init (GtkBuildableIface *iface);
|
2013-03-10 19:15:45 +00:00
|
|
|
|
2020-05-08 13:37:52 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkHeaderBar, gtk_header_bar, GTK_TYPE_WIDGET,
|
2013-06-27 19:02:52 +00:00
|
|
|
G_ADD_PRIVATE (GtkHeaderBar)
|
2013-03-10 19:15:45 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
2013-05-31 10:59:46 +00:00
|
|
|
gtk_header_bar_buildable_init));
|
2013-03-10 19:15:45 +00:00
|
|
|
|
2020-04-22 17:39:40 +00:00
|
|
|
static void
|
2020-04-24 15:55:43 +00:00
|
|
|
create_window_controls (GtkHeaderBar *bar)
|
2013-11-16 06:50:39 +00:00
|
|
|
{
|
|
|
|
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
|
2020-04-24 15:55:43 +00:00
|
|
|
GtkWidget *controls;
|
|
|
|
|
|
|
|
controls = gtk_window_controls_new (GTK_PACK_START);
|
|
|
|
g_object_bind_property (bar, "decoration-layout",
|
|
|
|
controls, "decoration-layout",
|
|
|
|
G_BINDING_SYNC_CREATE);
|
|
|
|
g_object_bind_property (controls, "empty",
|
|
|
|
controls, "visible",
|
|
|
|
G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (priv->start_box), controls);
|
2020-04-24 15:55:43 +00:00
|
|
|
priv->start_window_controls = controls;
|
|
|
|
|
|
|
|
controls = gtk_window_controls_new (GTK_PACK_END);
|
|
|
|
g_object_bind_property (bar, "decoration-layout",
|
|
|
|
controls, "decoration-layout",
|
|
|
|
G_BINDING_SYNC_CREATE);
|
|
|
|
g_object_bind_property (controls, "empty",
|
|
|
|
controls, "visible",
|
|
|
|
G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (priv->end_box), controls);
|
2020-04-24 15:55:43 +00:00
|
|
|
priv->end_window_controls = controls;
|
2013-12-11 06:26:34 +00:00
|
|
|
}
|
2013-11-16 06:50:39 +00:00
|
|
|
|
2019-05-12 09:58:22 +00:00
|
|
|
static void
|
|
|
|
update_default_decoration (GtkHeaderBar *bar)
|
|
|
|
{
|
|
|
|
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
|
2019-09-11 16:15:30 +00:00
|
|
|
gboolean have_children = FALSE;
|
|
|
|
|
|
|
|
/* Check whether we have any child widgets that we didn't add ourselves */
|
2020-05-01 22:01:12 +00:00
|
|
|
if (gtk_center_box_get_center_widget (GTK_CENTER_BOX (priv->center_box)) != NULL)
|
2019-09-11 16:15:30 +00:00
|
|
|
{
|
|
|
|
have_children = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkWidget *w;
|
|
|
|
|
|
|
|
for (w = _gtk_widget_get_first_child (priv->start_box);
|
|
|
|
w != NULL;
|
|
|
|
w = _gtk_widget_get_next_sibling (w))
|
|
|
|
{
|
2020-04-24 15:55:43 +00:00
|
|
|
if (w != priv->start_window_controls)
|
2019-09-11 16:15:30 +00:00
|
|
|
{
|
|
|
|
have_children = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!have_children)
|
|
|
|
for (w = _gtk_widget_get_first_child (priv->end_box);
|
|
|
|
w != NULL;
|
|
|
|
w = _gtk_widget_get_next_sibling (w))
|
|
|
|
{
|
2020-04-24 15:55:43 +00:00
|
|
|
if (w != priv->end_window_controls)
|
2019-09-11 16:15:30 +00:00
|
|
|
{
|
|
|
|
have_children = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-12 09:58:22 +00:00
|
|
|
|
2020-04-30 23:17:27 +00:00
|
|
|
if (have_children || priv->title_widget != NULL)
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_remove_css_class (GTK_WIDGET (bar), "default-decoration");
|
2019-05-12 09:58:22 +00:00
|
|
|
else
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (bar), "default-decoration");
|
2019-05-12 09:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_header_bar_track_default_decoration (GtkHeaderBar *bar)
|
|
|
|
{
|
|
|
|
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
|
|
|
|
|
|
|
|
priv->track_default_decoration = TRUE;
|
|
|
|
|
|
|
|
update_default_decoration (bar);
|
|
|
|
}
|
|
|
|
|
2020-04-30 23:04:08 +00:00
|
|
|
static void
|
|
|
|
update_title (GtkHeaderBar *bar)
|
|
|
|
{
|
|
|
|
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
|
|
|
|
GtkRoot *root;
|
|
|
|
const gchar *title = NULL;
|
|
|
|
|
|
|
|
if (!priv->title_label)
|
|
|
|
return;
|
|
|
|
|
|
|
|
root = gtk_widget_get_root (GTK_WIDGET (bar));
|
|
|
|
|
|
|
|
if (GTK_IS_WINDOW (root))
|
|
|
|
title = gtk_window_get_title (GTK_WINDOW (root));
|
|
|
|
|
|
|
|
if (!title)
|
|
|
|
title = g_get_application_name ();
|
|
|
|
|
|
|
|
if (!title)
|
|
|
|
title = g_get_prgname ();
|
|
|
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (priv->title_label), title);
|
|
|
|
}
|
|
|
|
|
2013-03-20 02:07:26 +00:00
|
|
|
static void
|
2020-04-30 20:27:05 +00:00
|
|
|
construct_title_label (GtkHeaderBar *bar)
|
2013-03-20 02:07:26 +00:00
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
|
2020-04-30 20:27:05 +00:00
|
|
|
GtkWidget *label;
|
2013-03-10 19:15:45 +00:00
|
|
|
|
2020-04-30 20:27:05 +00:00
|
|
|
g_assert (priv->title_label == NULL);
|
2013-03-20 02:07:26 +00:00
|
|
|
|
2020-04-30 23:04:08 +00:00
|
|
|
label = gtk_label_new (NULL);
|
2020-04-30 20:27:05 +00:00
|
|
|
gtk_widget_add_css_class (label, GTK_STYLE_CLASS_TITLE);
|
|
|
|
gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
|
|
|
|
gtk_label_set_wrap (GTK_LABEL (label), FALSE);
|
|
|
|
gtk_label_set_single_line_mode (GTK_LABEL (label), TRUE);
|
|
|
|
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
|
|
|
|
gtk_label_set_width_chars (GTK_LABEL (label), MIN_TITLE_CHARS);
|
2020-05-01 22:01:12 +00:00
|
|
|
gtk_center_box_set_center_widget (GTK_CENTER_BOX (priv->center_box), label);
|
2020-04-30 20:27:05 +00:00
|
|
|
|
|
|
|
priv->title_label = label;
|
2013-03-10 19:15:45 +00:00
|
|
|
|
2020-04-30 23:04:08 +00:00
|
|
|
update_title (bar);
|
2013-03-10 19:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-04-30 23:17:27 +00:00
|
|
|
* gtk_header_bar_set_title_widget:
|
2013-03-10 19:15:45 +00:00
|
|
|
* @bar: a #GtkHeaderBar
|
2020-04-30 23:17:27 +00:00
|
|
|
* @title_widget: (allow-none): a widget to use for a title
|
2013-03-10 19:15:45 +00:00
|
|
|
*
|
2020-04-30 23:17:27 +00:00
|
|
|
* Sets the title for the #GtkHeaderBar.
|
2013-12-11 03:57:13 +00:00
|
|
|
*
|
2020-04-30 23:17:27 +00:00
|
|
|
* When set to %NULL, the headerbar will display the title of the window it is
|
|
|
|
* contained in.
|
2013-12-11 03:57:13 +00:00
|
|
|
*
|
2020-04-30 23:17:27 +00:00
|
|
|
* The title should help a user identify the current view. To achieve the same
|
|
|
|
* style as the builtin title, use the “title” style class.
|
|
|
|
*
|
|
|
|
* You should set the title widget to %NULL, for the window title label to be
|
|
|
|
* visible again.
|
2013-03-10 19:15:45 +00:00
|
|
|
*/
|
|
|
|
void
|
2020-04-30 23:17:27 +00:00
|
|
|
gtk_header_bar_set_title_widget (GtkHeaderBar *bar,
|
2013-03-10 19:15:45 +00:00
|
|
|
GtkWidget *title_widget)
|
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
|
2013-03-10 19:15:45 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_HEADER_BAR (bar));
|
|
|
|
if (title_widget)
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (title_widget));
|
|
|
|
|
2020-04-30 23:17:27 +00:00
|
|
|
/* No need to do anything if the title widget stays the same */
|
|
|
|
if (priv->title_widget == title_widget)
|
2013-03-10 19:15:45 +00:00
|
|
|
return;
|
|
|
|
|
2020-05-11 18:25:57 +00:00
|
|
|
gtk_center_box_set_center_widget (GTK_CENTER_BOX (priv->center_box), NULL);
|
|
|
|
priv->title_widget = NULL;
|
2013-03-10 19:15:45 +00:00
|
|
|
|
2013-03-20 00:52:54 +00:00
|
|
|
if (title_widget != NULL)
|
2013-03-10 19:15:45 +00:00
|
|
|
{
|
2020-04-30 23:17:27 +00:00
|
|
|
priv->title_widget = title_widget;
|
2013-03-10 19:15:45 +00:00
|
|
|
|
2020-05-01 22:01:12 +00:00
|
|
|
gtk_center_box_set_center_widget (GTK_CENTER_BOX (priv->center_box), title_widget);
|
2013-03-20 00:52:54 +00:00
|
|
|
|
2020-05-01 22:01:12 +00:00
|
|
|
priv->title_label = NULL;
|
2013-03-10 19:15:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-30 20:27:05 +00:00
|
|
|
if (priv->title_label == NULL)
|
|
|
|
construct_title_label (bar);
|
2013-03-10 19:15:45 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 23:17:27 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (bar), header_bar_props[PROP_TITLE_WIDGET]);
|
2013-03-10 19:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-04-30 23:17:27 +00:00
|
|
|
* gtk_header_bar_get_title_widget:
|
2013-03-10 19:15:45 +00:00
|
|
|
* @bar: a #GtkHeaderBar
|
|
|
|
*
|
2020-04-30 23:17:27 +00:00
|
|
|
* Retrieves the title widget of the header. See
|
|
|
|
* gtk_header_bar_set_title_widget().
|
2013-03-10 19:15:45 +00:00
|
|
|
*
|
2020-04-30 23:17:27 +00:00
|
|
|
* Returns: (nullable) (transfer none): the title widget
|
2014-01-17 15:25:30 +00:00
|
|
|
* of the header, or %NULL if none has been set explicitly.
|
2013-03-10 19:15:45 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
2020-04-30 23:17:27 +00:00
|
|
|
gtk_header_bar_get_title_widget (GtkHeaderBar *bar)
|
2013-03-10 19:15:45 +00:00
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
|
|
|
|
|
2013-03-10 19:15:45 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_HEADER_BAR (bar), NULL);
|
|
|
|
|
2020-04-30 23:17:27 +00:00
|
|
|
return priv->title_widget;
|
2013-03-10 19:15:45 +00:00
|
|
|
}
|
|
|
|
|
2020-04-30 23:04:08 +00:00
|
|
|
static void
|
|
|
|
gtk_header_bar_root (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkWidget *root;
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_header_bar_parent_class)->root (widget);
|
|
|
|
|
|
|
|
root = GTK_WIDGET (gtk_widget_get_root (widget));
|
|
|
|
|
|
|
|
if (GTK_IS_WINDOW (root))
|
|
|
|
g_signal_connect_swapped (root, "notify::title",
|
|
|
|
G_CALLBACK (update_title), widget);
|
|
|
|
|
|
|
|
update_title (GTK_HEADER_BAR (widget));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_header_bar_unroot (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (gtk_widget_get_root (widget),
|
|
|
|
update_title, widget);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_header_bar_parent_class)->unroot (widget);
|
|
|
|
}
|
|
|
|
|
2015-12-07 16:21:51 +00:00
|
|
|
static void
|
2019-09-11 16:15:30 +00:00
|
|
|
gtk_header_bar_dispose (GObject *object)
|
2015-12-07 16:21:51 +00:00
|
|
|
{
|
2019-09-11 16:15:30 +00:00
|
|
|
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (GTK_HEADER_BAR (object));
|
2015-12-07 16:21:51 +00:00
|
|
|
|
2020-05-01 22:01:12 +00:00
|
|
|
priv->title_widget = NULL;
|
|
|
|
priv->title_label = NULL;
|
|
|
|
priv->start_box = NULL;
|
|
|
|
priv->end_box = NULL;
|
2015-12-07 16:21:51 +00:00
|
|
|
|
2020-05-02 15:37:41 +00:00
|
|
|
g_clear_pointer (&priv->handle, gtk_widget_unparent);
|
2019-11-13 14:20:34 +00:00
|
|
|
|
2020-05-01 22:01:12 +00:00
|
|
|
G_OBJECT_CLASS (gtk_header_bar_parent_class)->dispose (object);
|
2015-12-07 16:21:51 +00:00
|
|
|
}
|
|
|
|
|
2013-03-20 00:35:28 +00:00
|
|
|
static void
|
|
|
|
gtk_header_bar_finalize (GObject *object)
|
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (GTK_HEADER_BAR (object));
|
2013-03-20 00:35:28 +00:00
|
|
|
|
2013-12-22 02:58:24 +00:00
|
|
|
g_free (priv->decoration_layout);
|
2013-03-20 00:35:28 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_header_bar_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2013-03-10 19:15:45 +00:00
|
|
|
static void
|
|
|
|
gtk_header_bar_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkHeaderBar *bar = GTK_HEADER_BAR (object);
|
2013-06-27 19:02:52 +00:00
|
|
|
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
|
2013-03-10 19:15:45 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2020-04-30 23:17:27 +00:00
|
|
|
case PROP_TITLE_WIDGET:
|
|
|
|
g_value_set_object (value, priv->title_widget);
|
2013-03-10 19:15:45 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-08 03:36:29 +00:00
|
|
|
case PROP_SHOW_TITLE_BUTTONS:
|
|
|
|
g_value_set_boolean (value, gtk_header_bar_get_show_title_buttons (bar));
|
2013-08-03 23:25:26 +00:00
|
|
|
break;
|
|
|
|
|
2013-12-22 02:58:24 +00:00
|
|
|
case PROP_DECORATION_LAYOUT:
|
|
|
|
g_value_set_string (value, gtk_header_bar_get_decoration_layout (bar));
|
|
|
|
break;
|
|
|
|
|
2013-03-10 19:15:45 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_header_bar_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkHeaderBar *bar = GTK_HEADER_BAR (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2020-04-30 23:17:27 +00:00
|
|
|
case PROP_TITLE_WIDGET:
|
|
|
|
gtk_header_bar_set_title_widget (bar, g_value_get_object (value));
|
2013-03-10 19:15:45 +00:00
|
|
|
break;
|
|
|
|
|
2017-12-08 03:36:29 +00:00
|
|
|
case PROP_SHOW_TITLE_BUTTONS:
|
|
|
|
gtk_header_bar_set_show_title_buttons (bar, g_value_get_boolean (value));
|
2013-08-03 23:25:26 +00:00
|
|
|
break;
|
|
|
|
|
2013-12-22 02:58:24 +00:00
|
|
|
case PROP_DECORATION_LAYOUT:
|
|
|
|
gtk_header_bar_set_decoration_layout (bar, g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
|
2013-03-10 19:15:45 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_header_bar_pack (GtkHeaderBar *bar,
|
|
|
|
GtkWidget *widget,
|
|
|
|
GtkPackType pack_type)
|
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
|
2013-03-10 19:15:45 +00:00
|
|
|
|
|
|
|
g_return_if_fail (gtk_widget_get_parent (widget) == NULL);
|
|
|
|
|
2019-09-11 16:15:30 +00:00
|
|
|
if (pack_type == GTK_PACK_START)
|
2019-09-21 07:41:53 +00:00
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (priv->start_box), widget);
|
2019-09-21 07:41:53 +00:00
|
|
|
}
|
2019-09-11 16:15:30 +00:00
|
|
|
else if (pack_type == GTK_PACK_END)
|
2019-09-21 07:41:53 +00:00
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (priv->end_box), widget);
|
2019-09-21 07:41:53 +00:00
|
|
|
gtk_box_reorder_child_after (GTK_BOX (priv->end_box), widget, NULL);
|
|
|
|
}
|
2013-03-10 19:15:45 +00:00
|
|
|
|
2019-05-12 09:58:22 +00:00
|
|
|
if (priv->track_default_decoration)
|
|
|
|
update_default_decoration (bar);
|
2013-03-10 19:15:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 13:19:21 +00:00
|
|
|
/**
|
|
|
|
* gtk_header_bar_remove:
|
|
|
|
* @bar: a #GtkHeaderBar
|
|
|
|
* @child: the child to remove
|
|
|
|
*
|
|
|
|
* Removes a child from @bar, after it has been added
|
|
|
|
* with gtk_header_bar_pack_start(), gtk_header_bar_pack_end()
|
|
|
|
* or gtk_header_bar_set_title_widget().
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_header_bar_remove (GtkHeaderBar *bar,
|
|
|
|
GtkWidget *child)
|
2013-03-10 19:15:45 +00:00
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
|
2019-09-11 16:15:30 +00:00
|
|
|
GtkWidget *parent;
|
|
|
|
gboolean removed = FALSE;
|
2013-03-10 19:15:45 +00:00
|
|
|
|
2020-05-08 13:19:21 +00:00
|
|
|
parent = gtk_widget_get_parent (child);
|
2019-09-11 16:15:30 +00:00
|
|
|
|
|
|
|
if (parent == priv->start_box)
|
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_remove (GTK_BOX (priv->start_box), child);
|
2019-09-11 16:15:30 +00:00
|
|
|
removed = TRUE;
|
|
|
|
}
|
|
|
|
else if (parent == priv->end_box)
|
|
|
|
{
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_remove (GTK_BOX (priv->end_box), child);
|
2019-09-11 16:15:30 +00:00
|
|
|
removed = TRUE;
|
|
|
|
}
|
2020-05-08 13:19:21 +00:00
|
|
|
else if (parent == priv->center_box)
|
2019-09-11 16:15:30 +00:00
|
|
|
{
|
2020-05-08 13:19:21 +00:00
|
|
|
gtk_center_box_set_center_widget (GTK_CENTER_BOX (priv->center_box), NULL);
|
2019-09-11 16:15:30 +00:00
|
|
|
removed = TRUE;
|
|
|
|
}
|
|
|
|
|
2020-04-24 15:03:12 +00:00
|
|
|
if (removed && priv->track_default_decoration)
|
|
|
|
update_default_decoration (bar);
|
2013-03-10 19:15:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 13:37:52 +00:00
|
|
|
static GtkSizeRequestMode
|
|
|
|
gtk_header_bar_get_request_mode (GtkWidget *widget)
|
2013-03-10 19:15:45 +00:00
|
|
|
{
|
2019-09-11 16:15:30 +00:00
|
|
|
GtkWidget *w;
|
2020-05-08 13:37:52 +00:00
|
|
|
int wfh = 0, hfw = 0;
|
2013-03-10 19:15:45 +00:00
|
|
|
|
2020-05-08 13:37:52 +00:00
|
|
|
for (w = gtk_widget_get_first_child (widget);
|
|
|
|
w != NULL;
|
|
|
|
w = gtk_widget_get_next_sibling (w))
|
2013-03-10 19:15:45 +00:00
|
|
|
{
|
2020-05-08 13:37:52 +00:00
|
|
|
GtkSizeRequestMode mode = gtk_widget_get_request_mode (w);
|
2013-03-20 00:52:54 +00:00
|
|
|
|
2020-05-08 13:37:52 +00:00
|
|
|
switch (mode)
|
2019-09-11 16:15:30 +00:00
|
|
|
{
|
2020-05-08 13:37:52 +00:00
|
|
|
case GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH:
|
|
|
|
hfw ++;
|
|
|
|
break;
|
|
|
|
case GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT:
|
|
|
|
wfh ++;
|
|
|
|
break;
|
|
|
|
case GTK_SIZE_REQUEST_CONSTANT_SIZE:
|
|
|
|
default:
|
|
|
|
break;
|
2019-09-11 16:15:30 +00:00
|
|
|
}
|
2013-03-10 19:15:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 13:37:52 +00:00
|
|
|
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;
|
2013-03-10 19:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_header_bar_class_init (GtkHeaderBarClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
|
|
|
|
2019-09-11 16:15:30 +00:00
|
|
|
object_class->dispose = gtk_header_bar_dispose;
|
2013-03-20 00:35:28 +00:00
|
|
|
object_class->finalize = gtk_header_bar_finalize;
|
2013-03-10 19:15:45 +00:00
|
|
|
object_class->get_property = gtk_header_bar_get_property;
|
|
|
|
object_class->set_property = gtk_header_bar_set_property;
|
|
|
|
|
2020-04-30 23:04:08 +00:00
|
|
|
widget_class->root = gtk_header_bar_root;
|
|
|
|
widget_class->unroot = gtk_header_bar_unroot;
|
2020-05-08 13:37:52 +00:00
|
|
|
widget_class->get_request_mode = gtk_header_bar_get_request_mode;
|
2013-03-10 19:15:45 +00:00
|
|
|
|
2020-04-30 23:17:27 +00:00
|
|
|
header_bar_props[PROP_TITLE_WIDGET] =
|
|
|
|
g_param_spec_object ("title-widget",
|
|
|
|
P_("Title Widget"),
|
|
|
|
P_("Title widget to display"),
|
2015-09-06 14:41:43 +00:00
|
|
|
GTK_TYPE_WIDGET,
|
2015-11-03 22:36:54 +00:00
|
|
|
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
|
2015-09-06 14:41:43 +00:00
|
|
|
|
2013-12-22 02:58:24 +00:00
|
|
|
/**
|
2017-12-08 03:36:29 +00:00
|
|
|
* GtkHeaderBar:show-title-buttons:
|
2013-12-22 02:58:24 +00:00
|
|
|
*
|
2017-12-08 03:36:29 +00:00
|
|
|
* Whether to show title buttons like close, minimize, maximize.
|
2013-12-22 02:58:24 +00:00
|
|
|
*
|
|
|
|
* Which buttons are actually shown and where is determined
|
|
|
|
* by the #GtkHeaderBar:decoration-layout property, and by
|
|
|
|
* the state of the window (e.g. a close button will not be
|
|
|
|
* shown if the window can't be closed).
|
|
|
|
*/
|
2017-12-08 03:36:29 +00:00
|
|
|
header_bar_props[PROP_SHOW_TITLE_BUTTONS] =
|
|
|
|
g_param_spec_boolean ("show-title-buttons",
|
|
|
|
P_("Show title buttons"),
|
|
|
|
P_("Whether to show title buttons"),
|
2020-05-25 15:14:58 +00:00
|
|
|
TRUE,
|
2015-09-06 14:41:43 +00:00
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
2013-08-03 23:25:26 +00:00
|
|
|
|
2013-12-22 02:58:24 +00:00
|
|
|
/**
|
|
|
|
* GtkHeaderBar:decoration-layout:
|
2015-09-06 14:41:43 +00:00
|
|
|
*
|
2013-12-22 02:58:24 +00:00
|
|
|
* The decoration layout for buttons. If this property is
|
|
|
|
* not set, the #GtkSettings:gtk-decoration-layout setting
|
|
|
|
* is used.
|
|
|
|
*
|
|
|
|
* See gtk_header_bar_set_decoration_layout() for information
|
|
|
|
* about the format of this string.
|
|
|
|
*/
|
2015-09-06 14:41:43 +00:00
|
|
|
header_bar_props[PROP_DECORATION_LAYOUT] =
|
|
|
|
g_param_spec_string ("decoration-layout",
|
|
|
|
P_("Decoration Layout"),
|
|
|
|
P_("The layout for window decorations"),
|
|
|
|
NULL,
|
|
|
|
GTK_PARAM_READWRITE);
|
2013-12-22 02:58:24 +00:00
|
|
|
|
2015-09-06 14:41:43 +00:00
|
|
|
g_object_class_install_properties (object_class, LAST_PROP, header_bar_props);
|
2013-12-11 03:57:13 +00:00
|
|
|
|
2013-09-12 13:36:10 +00:00
|
|
|
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_PANEL);
|
2020-05-01 22:01:12 +00:00
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
|
2017-11-18 03:49:57 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("headerbar"));
|
2013-03-10 19:15:45 +00:00
|
|
|
}
|
|
|
|
|
2015-12-06 04:59:38 +00:00
|
|
|
static void
|
|
|
|
gtk_header_bar_init (GtkHeaderBar *bar)
|
|
|
|
{
|
2019-09-11 16:15:30 +00:00
|
|
|
GtkHeaderBarPrivate *priv = gtk_header_bar_get_instance_private (bar);
|
2015-12-06 04:59:38 +00:00
|
|
|
|
2020-04-30 23:17:27 +00:00
|
|
|
priv->title_widget = NULL;
|
2015-12-06 04:59:38 +00:00
|
|
|
priv->decoration_layout = NULL;
|
2020-05-25 15:14:58 +00:00
|
|
|
priv->show_title_buttons = TRUE;
|
2018-03-20 10:40:08 +00:00
|
|
|
priv->state = GDK_SURFACE_STATE_WITHDRAWN;
|
2015-12-06 04:59:38 +00:00
|
|
|
|
2020-05-02 15:37:41 +00:00
|
|
|
priv->handle = gtk_window_handle_new ();
|
|
|
|
gtk_widget_set_parent (priv->handle, GTK_WIDGET (bar));
|
|
|
|
|
2020-05-01 22:01:12 +00:00
|
|
|
priv->center_box = gtk_center_box_new ();
|
2020-05-02 15:37:41 +00:00
|
|
|
gtk_window_handle_set_child (GTK_WINDOW_HANDLE (priv->handle), priv->center_box);
|
2020-05-01 22:01:12 +00:00
|
|
|
|
2019-09-11 16:15:30 +00:00
|
|
|
priv->start_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (priv->start_box, "start");
|
2020-05-01 22:01:12 +00:00
|
|
|
gtk_center_box_set_start_widget (GTK_CENTER_BOX (priv->center_box), priv->start_box);
|
|
|
|
|
2019-09-11 16:15:30 +00:00
|
|
|
priv->end_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (priv->end_box, "end");
|
2020-05-01 22:01:12 +00:00
|
|
|
gtk_center_box_set_end_widget (GTK_CENTER_BOX (priv->center_box), priv->end_box);
|
2019-09-11 16:15:30 +00:00
|
|
|
|
2020-04-30 20:27:05 +00:00
|
|
|
construct_title_label (bar);
|
2020-05-25 15:14:58 +00:00
|
|
|
create_window_controls (bar);
|
2015-12-06 04:59:38 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 02:13:57 +00:00
|
|
|
static GtkBuildableIface *parent_buildable_iface;
|
|
|
|
|
2013-03-10 19:15:45 +00:00
|
|
|
static void
|
2013-05-31 10:59:46 +00:00
|
|
|
gtk_header_bar_buildable_add_child (GtkBuildable *buildable,
|
|
|
|
GtkBuilder *builder,
|
|
|
|
GObject *child,
|
|
|
|
const gchar *type)
|
2013-03-10 19:15:45 +00:00
|
|
|
{
|
2019-03-27 17:16:49 +00:00
|
|
|
if (g_strcmp0 (type, "title") == 0)
|
2020-04-30 23:17:27 +00:00
|
|
|
gtk_header_bar_set_title_widget (GTK_HEADER_BAR (buildable), GTK_WIDGET (child));
|
2019-03-27 17:16:49 +00:00
|
|
|
else if (g_strcmp0 (type, "start") == 0)
|
|
|
|
gtk_header_bar_pack_start (GTK_HEADER_BAR (buildable), GTK_WIDGET (child));
|
|
|
|
else if (g_strcmp0 (type, "end") == 0)
|
|
|
|
gtk_header_bar_pack_end (GTK_HEADER_BAR (buildable), GTK_WIDGET (child));
|
2020-05-08 13:37:52 +00:00
|
|
|
else if (type == NULL && GTK_IS_WIDGET (child))
|
|
|
|
gtk_header_bar_pack_start (GTK_HEADER_BAR (buildable), GTK_WIDGET (child));
|
2013-03-10 19:15:45 +00:00
|
|
|
else
|
2018-03-08 02:13:57 +00:00
|
|
|
parent_buildable_iface->add_child (buildable, builder, child, type);
|
2013-03-10 19:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-31 10:59:46 +00:00
|
|
|
gtk_header_bar_buildable_init (GtkBuildableIface *iface)
|
2013-03-10 19:15:45 +00:00
|
|
|
{
|
2018-03-08 02:13:57 +00:00
|
|
|
parent_buildable_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
2013-05-31 10:59:46 +00:00
|
|
|
iface->add_child = gtk_header_bar_buildable_add_child;
|
2013-03-10 19:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_header_bar_pack_start:
|
|
|
|
* @bar: A #GtkHeaderBar
|
|
|
|
* @child: the #GtkWidget to be added to @bar
|
|
|
|
*
|
2014-04-21 20:57:35 +00:00
|
|
|
* Adds @child to @bar, packed with reference to the
|
|
|
|
* start of the @bar.
|
2013-03-10 19:15:45 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_header_bar_pack_start (GtkHeaderBar *bar,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
|
|
|
gtk_header_bar_pack (bar, child, GTK_PACK_START);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_header_bar_pack_end:
|
|
|
|
* @bar: A #GtkHeaderBar
|
|
|
|
* @child: the #GtkWidget to be added to @bar
|
|
|
|
*
|
2014-04-21 20:57:35 +00:00
|
|
|
* Adds @child to @bar, packed with reference to the
|
|
|
|
* end of the @bar.
|
2013-03-10 19:15:45 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_header_bar_pack_end (GtkHeaderBar *bar,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
|
|
|
gtk_header_bar_pack (bar, child, GTK_PACK_END);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_header_bar_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GtkHeaderBar widget.
|
|
|
|
*
|
|
|
|
* Returns: a new #GtkHeaderBar
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_header_bar_new (void)
|
|
|
|
{
|
|
|
|
return GTK_WIDGET (g_object_new (GTK_TYPE_HEADER_BAR, NULL));
|
|
|
|
}
|
2013-08-03 23:25:26 +00:00
|
|
|
|
|
|
|
/**
|
2017-12-08 03:36:29 +00:00
|
|
|
* gtk_header_bar_get_show_title_buttons:
|
2013-08-03 23:25:26 +00:00
|
|
|
* @bar: a #GtkHeaderBar
|
|
|
|
*
|
2013-12-11 06:26:34 +00:00
|
|
|
* Returns whether this header bar shows the standard window
|
2017-12-08 03:36:29 +00:00
|
|
|
* title buttons.
|
2013-08-03 23:25:26 +00:00
|
|
|
*
|
2017-12-08 03:36:29 +00:00
|
|
|
* Returns: %TRUE if title buttons are shown
|
2013-08-03 23:25:26 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2017-12-08 03:36:29 +00:00
|
|
|
gtk_header_bar_get_show_title_buttons (GtkHeaderBar *bar)
|
2013-08-03 23:25:26 +00:00
|
|
|
{
|
|
|
|
GtkHeaderBarPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_HEADER_BAR (bar), FALSE);
|
|
|
|
|
|
|
|
priv = gtk_header_bar_get_instance_private (bar);
|
|
|
|
|
2017-12-08 03:36:29 +00:00
|
|
|
return priv->show_title_buttons;
|
2013-08-03 23:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-08 03:36:29 +00:00
|
|
|
* gtk_header_bar_set_show_title_buttons:
|
2013-08-03 23:25:26 +00:00
|
|
|
* @bar: a #GtkHeaderBar
|
2017-12-08 03:36:29 +00:00
|
|
|
* @setting: %TRUE to show standard title buttons
|
2013-08-03 23:25:26 +00:00
|
|
|
*
|
2017-12-08 03:36:29 +00:00
|
|
|
* Sets whether this header bar shows the standard window
|
|
|
|
* title buttons including close, maximize, and minimize.
|
2013-08-03 23:25:26 +00:00
|
|
|
*/
|
|
|
|
void
|
2017-12-08 03:36:29 +00:00
|
|
|
gtk_header_bar_set_show_title_buttons (GtkHeaderBar *bar,
|
|
|
|
gboolean setting)
|
2013-08-03 23:25:26 +00:00
|
|
|
{
|
|
|
|
GtkHeaderBarPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_HEADER_BAR (bar));
|
|
|
|
|
|
|
|
priv = gtk_header_bar_get_instance_private (bar);
|
|
|
|
|
|
|
|
setting = setting != FALSE;
|
|
|
|
|
2017-12-08 03:36:29 +00:00
|
|
|
if (priv->show_title_buttons == setting)
|
2013-08-03 23:25:26 +00:00
|
|
|
return;
|
|
|
|
|
2017-12-08 03:36:29 +00:00
|
|
|
priv->show_title_buttons = setting;
|
2020-04-24 15:55:43 +00:00
|
|
|
|
|
|
|
if (setting)
|
|
|
|
create_window_controls (bar);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_clear_pointer (&priv->start_window_controls, gtk_widget_unparent);
|
|
|
|
g_clear_pointer (&priv->end_window_controls, gtk_widget_unparent);
|
|
|
|
}
|
|
|
|
|
2017-12-08 03:36:29 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (bar), header_bar_props[PROP_SHOW_TITLE_BUTTONS]);
|
2013-08-03 23:25:26 +00:00
|
|
|
}
|
2013-11-16 06:50:39 +00:00
|
|
|
|
2013-12-22 02:58:24 +00:00
|
|
|
/**
|
|
|
|
* gtk_header_bar_set_decoration_layout:
|
|
|
|
* @bar: a #GtkHeaderBar
|
|
|
|
* @layout: (allow-none): a decoration layout, or %NULL to
|
|
|
|
* unset the layout
|
|
|
|
*
|
|
|
|
* Sets the decoration layout for this header bar, overriding
|
|
|
|
* the #GtkSettings:gtk-decoration-layout setting.
|
|
|
|
*
|
|
|
|
* There can be valid reasons for overriding the setting, such
|
|
|
|
* as a header bar design that does not allow for buttons to take
|
|
|
|
* room on the right, or only offers room for a single close button.
|
|
|
|
* Split header bars are another example for overriding the
|
|
|
|
* setting.
|
|
|
|
*
|
|
|
|
* The format of the string is button names, separated by commas.
|
|
|
|
* A colon separates the buttons that should appear on the left
|
|
|
|
* from those on the right. Recognized button names are minimize,
|
2020-04-22 16:24:37 +00:00
|
|
|
* maximize, close and icon (the window icon).
|
2013-12-22 02:58:24 +00:00
|
|
|
*
|
2020-04-22 16:24:37 +00:00
|
|
|
* For example, “icon:minimize,maximize,close” specifies a icon
|
2013-12-22 02:58:24 +00:00
|
|
|
* on the left, and minimize, maximize and close buttons on the right.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_header_bar_set_decoration_layout (GtkHeaderBar *bar,
|
|
|
|
const gchar *layout)
|
|
|
|
{
|
|
|
|
GtkHeaderBarPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_HEADER_BAR (bar));
|
|
|
|
|
|
|
|
priv = gtk_header_bar_get_instance_private (bar);
|
|
|
|
|
2019-05-06 10:55:16 +00:00
|
|
|
g_free (priv->decoration_layout);
|
2013-12-22 02:58:24 +00:00
|
|
|
priv->decoration_layout = g_strdup (layout);
|
|
|
|
|
2015-09-06 14:41:43 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (bar), header_bar_props[PROP_DECORATION_LAYOUT]);
|
2013-12-22 02:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_header_bar_get_decoration_layout:
|
|
|
|
* @bar: a #GtkHeaderBar
|
|
|
|
*
|
|
|
|
* Gets the decoration layout set with
|
|
|
|
* gtk_header_bar_set_decoration_layout().
|
|
|
|
*
|
|
|
|
* Returns: the decoration layout
|
|
|
|
*/
|
|
|
|
const gchar *
|
|
|
|
gtk_header_bar_get_decoration_layout (GtkHeaderBar *bar)
|
|
|
|
{
|
|
|
|
GtkHeaderBarPrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_HEADER_BAR (bar), NULL);
|
|
|
|
|
|
|
|
priv = gtk_header_bar_get_instance_private (bar);
|
|
|
|
|
|
|
|
return priv->decoration_layout;
|
|
|
|
}
|