Commit 106bcc7f authored by Matthias Clasen's avatar Matthias Clasen

Make it possible to set use-header-bar from a setting

This commit introduces a private convenience API that derived
dialogs can call in their instance init. This is necessary to
make the setting work as intended in the face of 3rd party
dialogs derived e.g. from GtkFileChooserDialog, which are
created with g_object_new.
parent 3701de14
......@@ -467,6 +467,7 @@ gtk_private_h_sources = \
gtkcsstypedvalueprivate.h \
gtkcssvalueprivate.h \
gtkcustompaperunixdialog.h \
gtkdialogprivate.h \
gtkentryprivate.h \
gtkfilechooserdefault.h \
gtkfilechooserembed.h \
......
......@@ -175,7 +175,7 @@ struct _GtkDialogPrivate
GtkWidget *headerbar;
GtkWidget *action_area;
gboolean use_header_bar;
gint use_header_bar;
gboolean constructed;
};
......@@ -235,11 +235,34 @@ G_DEFINE_TYPE_WITH_CODE (GtkDialog, gtk_dialog, GTK_TYPE_WINDOW,
static void
set_use_header_bar (GtkDialog *dialog,
gboolean use_header_bar)
gint use_header_bar)
{
GtkDialogPrivate *priv = dialog->priv;
if (use_header_bar == -1)
return;
priv->use_header_bar = use_header_bar;
}
/* A convenience helper for built-in dialogs */
void
gtk_dialog_set_use_header_bar_from_setting (GtkDialog *dialog)
{
GtkDialogPrivate *priv = dialog->priv;
g_assert (!priv->constructed);
g_object_get (gtk_widget_get_settings (GTK_WIDGET (dialog)),
"gtk-dialogs-use-header", &priv->use_header_bar,
NULL);
}
static void
apply_use_header_bar (GtkDialog *dialog)
{
GtkDialogPrivate *priv = dialog->priv;
gtk_widget_set_visible (priv->action_area, !priv->use_header_bar);
gtk_widget_set_visible (priv->headerbar, priv->use_header_bar);
if (!priv->use_header_bar)
......@@ -257,7 +280,7 @@ gtk_dialog_set_property (GObject *object,
switch (prop_id)
{
case PROP_USE_HEADER_BAR:
set_use_header_bar (dialog, g_value_get_boolean (value));
set_use_header_bar (dialog, g_value_get_int (value));
break;
default:
......@@ -278,7 +301,7 @@ gtk_dialog_get_property (GObject *object,
switch (prop_id)
{
case PROP_USE_HEADER_BAR:
g_value_set_boolean (value, priv->use_header_bar);
g_value_set_int (value, priv->use_header_bar);
break;
default:
......@@ -412,8 +435,11 @@ gtk_dialog_constructor (GType type,
priv = dialog->priv;
priv->constructed = TRUE;
if (priv->use_header_bar == -1)
priv->use_header_bar = FALSE;
add_action_widgets (dialog);
apply_use_header_bar (dialog);
return object;
}
......@@ -528,15 +554,18 @@ gtk_dialog_class_init (GtkDialogClass *class)
* %TRUE if the dialog uses a #GtkHeaderBar for action buttons
* instead of the action-area.
*
* For technical reasons, this property is declared as an integer
* property, but you should only set it to %TRUE or %FALSE.
*
* Since: 3.12
*/
g_object_class_install_property (gobject_class,
PROP_USE_HEADER_BAR,
g_param_spec_boolean ("use-header-bar",
P_("Use Header Bar"),
P_("Use Header Bar for actions."),
FALSE,
GTK_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
g_param_spec_int ("use-header-bar",
P_("Use Header Bar"),
P_("Use Header Bar for actions."),
-1, 1, -1,
GTK_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
binding_set = gtk_binding_set_by_class (class);
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0);
......@@ -585,6 +614,8 @@ gtk_dialog_init (GtkDialog *dialog)
{
dialog->priv = gtk_dialog_get_instance_private (dialog);
dialog->priv->use_header_bar = -1;
gtk_widget_init_template (GTK_WIDGET (dialog));
update_spacings (dialog);
......@@ -1448,11 +1479,12 @@ gtk_dialog_set_alternative_button_order (GtkDialog *dialog,
gint first_response_id,
...)
{
GtkDialogPrivate *priv = dialog->priv;
va_list args;
g_return_if_fail (GTK_IS_DIALOG (dialog));
if (dialog->priv->use_header_bar)
if (priv->constructed && priv->use_header_bar)
return;
if (!gtk_alt_dialog_button_order ())
......
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library 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 library 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 library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#ifndef __GTK_DIALOG_PRIVATE_H__
#define __GTK_DIALOG_PRIVATE_H__
#include "gtkdialog.h"
G_BEGIN_DECLS
void gtk_dialog_set_use_header_bar_from_setting (GtkDialog *dialog);
G_END_DECLS
#endif /* __GTK_DIALOG_PRIVATE_H__ */
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