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"
|
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
|
|
|
*
|
2021-02-18 18:17:56 +00:00
|
|
|
* `GtkHeaderBar` is a widget for creating custom title bars for
|
|
|
|
* [class@Gtk.Window].
|
|
|
|
*
|
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-11-12 00:36:32 +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 header bar, as well as a center node that represents
|
2020-05-02 15:37:41 +00:00
|
|
|
* the title.
|
2019-09-13 08:40:26 +00:00
|
|
|
*
|
2020-11-12 00:36:32 +00:00
|
|
|
* Each of the boxes contains a `windowcontrols` subnode, see #GtkWindowControls
|
2020-04-24 15:55:43 +00:00
|
|
|
* for details, as well as other children.
|
2020-11-12 00:36:32 +00:00
|
|
|
*
|
|
|
|
* # Accessibility
|
|
|
|
*
|
|
|
|
* GtkHeaderBar uses the %GTK_ACCESSIBLE_ROLE_GROUP role.
|
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
|
|
|
struct _GtkHeaderBar
|
|
|
|
{
|
2020-05-08 13:37:52 +00:00
|
|
|
GtkWidget container;
|
2019-05-27 02:32:21 +00:00
|
|
|
|
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
|
|
|
|
2020-04-24 15:55:43 +00:00
|
|
|
GtkWidget *start_window_controls;
|
|
|
|
GtkWidget *end_window_controls;
|
2013-12-11 06:26:34 +00:00
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
char *decoration_layout;
|
|
|
|
|
|
|
|
guint show_title_buttons : 1;
|
|
|
|
guint track_default_decoration : 1;
|
2013-03-10 19:15:45 +00:00
|
|
|
};
|
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
typedef struct _GtkHeaderBarClass GtkHeaderBarClass;
|
|
|
|
|
|
|
|
struct _GtkHeaderBarClass
|
|
|
|
{
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
};
|
|
|
|
|
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-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
|
|
|
{
|
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);
|
2021-01-06 17:04:55 +00:00
|
|
|
gtk_box_prepend (GTK_BOX (bar->start_box), controls);
|
2020-07-25 11:40:24 +00:00
|
|
|
bar->start_window_controls = controls;
|
2020-04-24 15:55:43 +00:00
|
|
|
|
|
|
|
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-07-25 11:40:24 +00:00
|
|
|
gtk_box_append (GTK_BOX (bar->end_box), controls);
|
|
|
|
bar->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)
|
|
|
|
{
|
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-07-25 11:40:24 +00:00
|
|
|
if (gtk_center_box_get_center_widget (GTK_CENTER_BOX (bar->center_box)) != NULL)
|
2019-09-11 16:15:30 +00:00
|
|
|
{
|
|
|
|
have_children = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkWidget *w;
|
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
for (w = _gtk_widget_get_first_child (bar->start_box);
|
2019-09-11 16:15:30 +00:00
|
|
|
w != NULL;
|
|
|
|
w = _gtk_widget_get_next_sibling (w))
|
|
|
|
{
|
2020-07-25 11:40:24 +00:00
|
|
|
if (w != bar->start_window_controls)
|
2019-09-11 16:15:30 +00:00
|
|
|
{
|
|
|
|
have_children = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!have_children)
|
2020-07-25 11:40:24 +00:00
|
|
|
for (w = _gtk_widget_get_first_child (bar->end_box);
|
2019-09-11 16:15:30 +00:00
|
|
|
w != NULL;
|
|
|
|
w = _gtk_widget_get_next_sibling (w))
|
|
|
|
{
|
2020-07-25 11:40:24 +00:00
|
|
|
if (w != bar->end_window_controls)
|
2019-09-11 16:15:30 +00:00
|
|
|
{
|
|
|
|
have_children = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-12 09:58:22 +00:00
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
if (have_children || bar->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)
|
|
|
|
{
|
2020-07-25 11:40:24 +00:00
|
|
|
bar->track_default_decoration = TRUE;
|
2019-05-12 09:58:22 +00:00
|
|
|
|
|
|
|
update_default_decoration (bar);
|
|
|
|
}
|
|
|
|
|
2020-04-30 23:04:08 +00:00
|
|
|
static void
|
|
|
|
update_title (GtkHeaderBar *bar)
|
|
|
|
{
|
|
|
|
GtkRoot *root;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *title = NULL;
|
2020-04-30 23:04:08 +00:00
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
if (!bar->title_label)
|
2020-04-30 23:04:08 +00:00
|
|
|
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 ();
|
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL (bar->title_label), title);
|
2020-04-30 23:04:08 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2020-04-30 20:27:05 +00:00
|
|
|
GtkWidget *label;
|
2013-03-10 19:15:45 +00:00
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
g_assert (bar->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-08-13 23:49:02 +00:00
|
|
|
gtk_widget_add_css_class (label, "title");
|
2020-04-30 20:27:05 +00:00
|
|
|
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-07-25 11:40:24 +00:00
|
|
|
gtk_center_box_set_center_widget (GTK_CENTER_BOX (bar->center_box), label);
|
2020-04-30 20:27:05 +00:00
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
bar->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)
|
|
|
|
{
|
|
|
|
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 */
|
2020-07-25 11:40:24 +00:00
|
|
|
if (bar->title_widget == title_widget)
|
2013-03-10 19:15:45 +00:00
|
|
|
return;
|
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
gtk_center_box_set_center_widget (GTK_CENTER_BOX (bar->center_box), NULL);
|
|
|
|
bar->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-07-25 11:40:24 +00:00
|
|
|
bar->title_widget = title_widget;
|
2013-03-10 19:15:45 +00:00
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
gtk_center_box_set_center_widget (GTK_CENTER_BOX (bar->center_box), title_widget);
|
2013-03-20 00:52:54 +00:00
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
bar->title_label = NULL;
|
2013-03-10 19:15:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-25 11:40:24 +00:00
|
|
|
if (bar->title_label == NULL)
|
2020-04-30 20:27:05 +00:00
|
|
|
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
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_HEADER_BAR (bar), NULL);
|
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
return bar->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
|
|
|
{
|
2020-07-25 11:40:24 +00:00
|
|
|
GtkHeaderBar *bar = GTK_HEADER_BAR (object);
|
2015-12-07 16:21:51 +00:00
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
bar->title_widget = NULL;
|
|
|
|
bar->title_label = NULL;
|
|
|
|
bar->start_box = NULL;
|
|
|
|
bar->end_box = NULL;
|
2015-12-07 16:21:51 +00:00
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
g_clear_pointer (&bar->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)
|
|
|
|
{
|
2020-07-25 11:40:24 +00:00
|
|
|
GtkHeaderBar *bar = GTK_HEADER_BAR (object);
|
2013-03-20 00:35:28 +00:00
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
g_free (bar->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);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2020-04-30 23:17:27 +00:00
|
|
|
case PROP_TITLE_WIDGET:
|
2020-07-25 11:40:24 +00:00
|
|
|
g_value_set_object (value, bar->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)
|
|
|
|
{
|
|
|
|
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-07-25 11:40:24 +00:00
|
|
|
gtk_box_append (GTK_BOX (bar->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-07-25 11:40:24 +00:00
|
|
|
gtk_box_append (GTK_BOX (bar->end_box), widget);
|
|
|
|
gtk_box_reorder_child_after (GTK_BOX (bar->end_box), widget, NULL);
|
2019-09-21 07:41:53 +00:00
|
|
|
}
|
2013-03-10 19:15:45 +00:00
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
if (bar->track_default_decoration)
|
2019-05-12 09:58:22 +00:00
|
|
|
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
|
|
|
{
|
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
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
if (parent == bar->start_box)
|
2019-09-11 16:15:30 +00:00
|
|
|
{
|
2020-07-25 11:40:24 +00:00
|
|
|
gtk_box_remove (GTK_BOX (bar->start_box), child);
|
2019-09-11 16:15:30 +00:00
|
|
|
removed = TRUE;
|
|
|
|
}
|
2020-07-25 11:40:24 +00:00
|
|
|
else if (parent == bar->end_box)
|
2019-09-11 16:15:30 +00:00
|
|
|
{
|
2020-07-25 11:40:24 +00:00
|
|
|
gtk_box_remove (GTK_BOX (bar->end_box), child);
|
2019-09-11 16:15:30 +00:00
|
|
|
removed = TRUE;
|
|
|
|
}
|
2020-07-25 11:40:24 +00:00
|
|
|
else if (parent == bar->center_box)
|
2019-09-11 16:15:30 +00:00
|
|
|
{
|
2020-07-25 11:40:24 +00:00
|
|
|
gtk_center_box_set_center_widget (GTK_CENTER_BOX (bar->center_box), NULL);
|
2019-09-11 16:15:30 +00:00
|
|
|
removed = TRUE;
|
|
|
|
}
|
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
if (removed && bar->track_default_decoration)
|
2020-04-24 15:03:12 +00:00
|
|
|
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
|
|
|
|
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"));
|
2020-11-11 17:54:57 +00:00
|
|
|
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GROUP);
|
2013-03-10 19:15:45 +00:00
|
|
|
}
|
|
|
|
|
2015-12-06 04:59:38 +00:00
|
|
|
static void
|
|
|
|
gtk_header_bar_init (GtkHeaderBar *bar)
|
|
|
|
{
|
2020-07-25 11:40:24 +00:00
|
|
|
bar->title_widget = NULL;
|
|
|
|
bar->decoration_layout = NULL;
|
|
|
|
bar->show_title_buttons = TRUE;
|
2015-12-06 04:59:38 +00:00
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
bar->handle = gtk_window_handle_new ();
|
|
|
|
gtk_widget_set_parent (bar->handle, GTK_WIDGET (bar));
|
2020-05-02 15:37:41 +00:00
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
bar->center_box = gtk_center_box_new ();
|
|
|
|
gtk_window_handle_set_child (GTK_WINDOW_HANDLE (bar->handle), bar->center_box);
|
2020-05-01 22:01:12 +00:00
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
bar->start_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_widget_add_css_class (bar->start_box, "start");
|
|
|
|
gtk_center_box_set_start_widget (GTK_CENTER_BOX (bar->center_box), bar->start_box);
|
2020-05-01 22:01:12 +00:00
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
bar->end_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_widget_add_css_class (bar->end_box, "end");
|
|
|
|
gtk_center_box_set_end_widget (GTK_CENTER_BOX (bar->center_box), bar->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,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *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
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_HEADER_BAR (bar), FALSE);
|
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
return bar->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
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_HEADER_BAR (bar));
|
|
|
|
|
|
|
|
setting = setting != FALSE;
|
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
if (bar->show_title_buttons == setting)
|
2013-08-03 23:25:26 +00:00
|
|
|
return;
|
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
bar->show_title_buttons = setting;
|
2020-04-24 15:55:43 +00:00
|
|
|
|
|
|
|
if (setting)
|
|
|
|
create_window_controls (bar);
|
|
|
|
else
|
|
|
|
{
|
2021-02-08 13:46:35 +00:00
|
|
|
if (bar->start_box && bar->start_window_controls)
|
2021-02-08 12:52:10 +00:00
|
|
|
{
|
|
|
|
gtk_box_remove (GTK_BOX (bar->start_box), bar->start_window_controls);
|
|
|
|
bar->start_window_controls = NULL;
|
|
|
|
}
|
|
|
|
|
2021-02-08 13:46:35 +00:00
|
|
|
if (bar->end_box && bar->end_window_controls)
|
2021-02-08 12:52:10 +00:00
|
|
|
{
|
|
|
|
gtk_box_remove (GTK_BOX (bar->end_box), bar->end_window_controls);
|
|
|
|
bar->end_window_controls = NULL;
|
|
|
|
}
|
2020-04-24 15:55:43 +00:00
|
|
|
}
|
|
|
|
|
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,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *layout)
|
2013-12-22 02:58:24 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_HEADER_BAR (bar));
|
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
g_free (bar->decoration_layout);
|
|
|
|
bar->decoration_layout = g_strdup (layout);
|
2013-12-22 02:58:24 +00:00
|
|
|
|
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().
|
|
|
|
*
|
2020-11-24 18:27:33 +00:00
|
|
|
* Returns: (nullable): the decoration layout
|
2013-12-22 02:58:24 +00:00
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *
|
2013-12-22 02:58:24 +00:00
|
|
|
gtk_header_bar_get_decoration_layout (GtkHeaderBar *bar)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_HEADER_BAR (bar), NULL);
|
|
|
|
|
2020-07-25 11:40:24 +00:00
|
|
|
return bar->decoration_layout;
|
2013-12-22 02:58:24 +00:00
|
|
|
}
|