2013-05-21 15:26:37 +00:00
|
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
|
* Copyright (C) 2013 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Authors:
|
|
|
|
|
* - Bastien Nocera <bnocera@redhat.com>
|
|
|
|
|
*
|
|
|
|
|
* 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 2013. 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2018-02-08 05:15:10 +00:00
|
|
|
|
#include "gtksearchbar.h"
|
|
|
|
|
|
2020-05-03 13:56:40 +00:00
|
|
|
|
#include "gtkbinlayout.h"
|
|
|
|
|
#include "gtkbuildable.h"
|
2018-02-04 21:24:44 +00:00
|
|
|
|
#include "gtkbutton.h"
|
2018-02-08 05:15:10 +00:00
|
|
|
|
#include "gtkcenterbox.h"
|
2013-05-21 15:26:37 +00:00
|
|
|
|
#include "gtkentryprivate.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
|
#include "gtkeventcontrollerkey.h"
|
2014-06-09 13:39:53 +00:00
|
|
|
|
#include "gtkprivate.h"
|
2018-02-08 05:15:10 +00:00
|
|
|
|
#include "gtkrevealer.h"
|
2014-12-27 23:29:07 +00:00
|
|
|
|
#include "gtksearchentryprivate.h"
|
2016-12-19 19:04:52 +00:00
|
|
|
|
#include "gtksnapshot.h"
|
2020-05-03 13:56:40 +00:00
|
|
|
|
#include "gtkwidgetprivate.h"
|
2013-05-21 15:26:37 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* GtkSearchBar:
|
2013-05-21 15:26:37 +00:00
|
|
|
|
*
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* `GtkSearchBar` is a container made to have a search entry.
|
|
|
|
|
*
|
|
|
|
|
* ![An example GtkSearchBar](search-bar.png)
|
|
|
|
|
*
|
|
|
|
|
* It can also contain additional widgets, such as drop-down menus,
|
|
|
|
|
* or buttons. The search bar would appear when a search is started
|
|
|
|
|
* through typing on the keyboard, or the application’s search mode
|
|
|
|
|
* is toggled on.
|
2013-05-21 15:26:37 +00:00
|
|
|
|
*
|
2018-03-11 12:53:17 +00:00
|
|
|
|
* For keyboard presses to start a search, the search bar must be told
|
|
|
|
|
* of a widget to capture key events from through
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* [method@Gtk.SearchBar.set_key_capture_widget]. This widget will
|
|
|
|
|
* typically be the top-level window, or a parent container of the
|
|
|
|
|
* search bar. Common shortcuts such as Ctrl+F should be handled as an
|
|
|
|
|
* application action, or through the menu items.
|
2013-05-21 15:26:37 +00:00
|
|
|
|
*
|
2013-06-30 04:50:29 +00:00
|
|
|
|
* You will also need to tell the search bar about which entry you
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* are using as your search entry using [method@Gtk.SearchBar.connect_entry].
|
2013-05-21 15:26:37 +00:00
|
|
|
|
*
|
2021-01-26 03:15:56 +00:00
|
|
|
|
* ## Creating a search bar
|
|
|
|
|
*
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* The following example shows you how to create a more complex search
|
|
|
|
|
* entry.
|
|
|
|
|
*
|
2021-11-29 22:37:49 +00:00
|
|
|
|
* [A simple example](https://gitlab.gnome.org/GNOME/gtk/tree/main/examples/search-bar.c)
|
2021-01-26 03:15:56 +00:00
|
|
|
|
*
|
2015-10-29 11:43:30 +00:00
|
|
|
|
* # CSS nodes
|
|
|
|
|
*
|
2021-02-28 01:05:44 +00:00
|
|
|
|
* ```
|
2018-02-04 21:24:44 +00:00
|
|
|
|
* searchbar
|
|
|
|
|
* ╰── revealer
|
|
|
|
|
* ╰── box
|
|
|
|
|
* ├── [child]
|
|
|
|
|
* ╰── [button.close]
|
2021-02-28 01:05:44 +00:00
|
|
|
|
* ```
|
2018-02-04 21:24:44 +00:00
|
|
|
|
*
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* `GtkSearchBar` has a main CSS node with name searchbar. It has a child
|
|
|
|
|
* node with name revealer that contains a node with name box. The box node
|
|
|
|
|
* contains both the CSS node of the child widget as well as an optional button
|
|
|
|
|
* node which gets the .close style class applied.
|
2015-10-29 11:43:30 +00:00
|
|
|
|
*
|
2020-11-12 14:54:39 +00:00
|
|
|
|
* # Accessibility
|
|
|
|
|
*
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* `GtkSearchBar` uses the %GTK_ACCESSIBLE_ROLE_SEARCH role.
|
2013-05-21 15:26:37 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2019-05-27 03:27:15 +00:00
|
|
|
|
typedef struct _GtkSearchBarClass GtkSearchBarClass;
|
|
|
|
|
|
|
|
|
|
struct _GtkSearchBar
|
|
|
|
|
{
|
2020-05-03 13:56:40 +00:00
|
|
|
|
GtkWidget parent;
|
2019-05-27 03:27:15 +00:00
|
|
|
|
|
2020-05-03 13:56:40 +00:00
|
|
|
|
GtkWidget *child;
|
2013-05-21 15:26:37 +00:00
|
|
|
|
GtkWidget *revealer;
|
|
|
|
|
GtkWidget *box_center;
|
|
|
|
|
GtkWidget *close_button;
|
|
|
|
|
|
|
|
|
|
GtkWidget *entry;
|
|
|
|
|
gboolean reveal_child;
|
2018-03-11 12:53:17 +00:00
|
|
|
|
|
|
|
|
|
GtkWidget *capture_widget;
|
|
|
|
|
GtkEventController *capture_widget_controller;
|
2020-05-05 00:09:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _GtkSearchBarClass
|
|
|
|
|
{
|
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
|
};
|
2013-06-27 19:02:52 +00:00
|
|
|
|
|
2020-05-03 13:56:40 +00:00
|
|
|
|
static void gtk_search_bar_buildable_iface_init (GtkBuildableIface *iface);
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkSearchBar, gtk_search_bar, GTK_TYPE_WIDGET,
|
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
|
|
|
|
gtk_search_bar_buildable_iface_init))
|
2013-05-21 15:26:37 +00:00
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_SEARCH_MODE_ENABLED,
|
|
|
|
|
PROP_SHOW_CLOSE_BUTTON,
|
2020-05-03 13:51:09 +00:00
|
|
|
|
PROP_CHILD,
|
2020-07-12 20:25:24 +00:00
|
|
|
|
PROP_KEY_CAPTURE_WIDGET,
|
2013-05-21 15:26:37 +00:00
|
|
|
|
LAST_PROPERTY
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static GParamSpec *widget_props[LAST_PROPERTY] = { NULL, };
|
|
|
|
|
|
2020-05-03 13:56:40 +00:00
|
|
|
|
static GtkBuildableIface *parent_buildable_iface;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_search_bar_buildable_add_child (GtkBuildable *buildable,
|
|
|
|
|
GtkBuilder *builder,
|
|
|
|
|
GObject *child,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *type)
|
2020-05-03 13:56:40 +00:00
|
|
|
|
{
|
|
|
|
|
if (GTK_IS_WIDGET (child))
|
|
|
|
|
gtk_search_bar_set_child (GTK_SEARCH_BAR (buildable), GTK_WIDGET (child));
|
|
|
|
|
else
|
|
|
|
|
parent_buildable_iface->add_child (buildable, builder, child, type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_search_bar_buildable_iface_init (GtkBuildableIface *iface)
|
|
|
|
|
{
|
|
|
|
|
parent_buildable_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
|
|
|
|
|
iface->add_child = gtk_search_bar_buildable_add_child;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-27 23:29:07 +00:00
|
|
|
|
static void
|
|
|
|
|
stop_search_cb (GtkWidget *entry,
|
|
|
|
|
GtkSearchBar *bar)
|
2013-05-21 15:26:37 +00:00
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (bar->revealer), FALSE);
|
2013-05-21 15:26:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
reveal_child_changed_cb (GObject *object,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GtkSearchBar *bar)
|
|
|
|
|
{
|
|
|
|
|
gboolean reveal_child;
|
|
|
|
|
|
|
|
|
|
g_object_get (object, "reveal-child", &reveal_child, NULL);
|
2014-10-12 22:18:04 +00:00
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (reveal_child == bar->reveal_child)
|
2013-05-21 15:26:37 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
bar->reveal_child = reveal_child;
|
2013-05-21 15:26:37 +00:00
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (bar->entry)
|
2014-06-09 13:36:47 +00:00
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (reveal_child && GTK_IS_ENTRY (bar->entry))
|
|
|
|
|
gtk_entry_grab_focus_without_selecting (GTK_ENTRY (bar->entry));
|
2020-11-12 18:04:42 +00:00
|
|
|
|
else if (reveal_child && GTK_IS_SEARCH_ENTRY (bar->entry))
|
2020-05-05 00:09:29 +00:00
|
|
|
|
gtk_widget_grab_focus (bar->entry);
|
2014-06-09 13:36:47 +00:00
|
|
|
|
else
|
2020-05-05 00:09:29 +00:00
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (bar->entry), "");
|
2014-06-09 13:36:47 +00:00
|
|
|
|
}
|
2013-05-21 15:26:37 +00:00
|
|
|
|
|
2020-01-28 12:51:04 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (bar), widget_props[PROP_SEARCH_MODE_ENABLED]);
|
2013-05-21 15:26:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
close_button_clicked_cb (GtkWidget *button,
|
|
|
|
|
GtkSearchBar *bar)
|
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (bar->revealer), FALSE);
|
2013-05-21 15:26:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-06-30 04:50:29 +00:00
|
|
|
|
gtk_search_bar_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2013-05-21 15:26:37 +00:00
|
|
|
|
{
|
|
|
|
|
GtkSearchBar *bar = GTK_SEARCH_BAR (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_SEARCH_MODE_ENABLED:
|
|
|
|
|
gtk_search_bar_set_search_mode (bar, g_value_get_boolean (value));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_SHOW_CLOSE_BUTTON:
|
|
|
|
|
gtk_search_bar_set_show_close_button (bar, g_value_get_boolean (value));
|
|
|
|
|
break;
|
2020-05-03 13:51:09 +00:00
|
|
|
|
case PROP_CHILD:
|
|
|
|
|
gtk_search_bar_set_child (bar, g_value_get_object (value));
|
|
|
|
|
break;
|
2020-07-12 20:25:24 +00:00
|
|
|
|
case PROP_KEY_CAPTURE_WIDGET:
|
|
|
|
|
gtk_search_bar_set_key_capture_widget (bar, g_value_get_object (value));
|
|
|
|
|
break;
|
2013-05-21 15:26:37 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-06-30 04:50:29 +00:00
|
|
|
|
gtk_search_bar_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2013-05-21 15:26:37 +00:00
|
|
|
|
{
|
|
|
|
|
GtkSearchBar *bar = GTK_SEARCH_BAR (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_SEARCH_MODE_ENABLED:
|
2020-01-28 12:51:56 +00:00
|
|
|
|
g_value_set_boolean (value, gtk_search_bar_get_search_mode (bar));
|
2013-05-21 15:26:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_SHOW_CLOSE_BUTTON:
|
|
|
|
|
g_value_set_boolean (value, gtk_search_bar_get_show_close_button (bar));
|
|
|
|
|
break;
|
2020-05-03 13:51:09 +00:00
|
|
|
|
case PROP_CHILD:
|
|
|
|
|
g_value_set_object (value, gtk_search_bar_get_child (bar));
|
|
|
|
|
break;
|
2020-07-12 20:25:24 +00:00
|
|
|
|
case PROP_KEY_CAPTURE_WIDGET:
|
|
|
|
|
g_value_set_object (value, gtk_search_bar_get_key_capture_widget (bar));
|
|
|
|
|
break;
|
2013-05-21 15:26:37 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-22 15:55:33 +00:00
|
|
|
|
static void gtk_search_bar_set_entry (GtkSearchBar *bar,
|
2019-02-17 04:58:06 +00:00
|
|
|
|
GtkEditable *editable);
|
2015-03-22 15:55:33 +00:00
|
|
|
|
|
2013-05-21 15:26:37 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_search_bar_dispose (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GtkSearchBar *bar = GTK_SEARCH_BAR (object);
|
2018-02-04 21:24:44 +00:00
|
|
|
|
|
2020-05-03 13:56:40 +00:00
|
|
|
|
gtk_search_bar_set_key_capture_widget (bar, NULL);
|
|
|
|
|
gtk_search_bar_set_entry (bar, NULL);
|
2018-02-04 21:24:44 +00:00
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
g_clear_pointer (&bar->revealer, gtk_widget_unparent);
|
2013-05-21 15:26:37 +00:00
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
bar->child = NULL;
|
|
|
|
|
bar->box_center = NULL;
|
|
|
|
|
bar->close_button = NULL;
|
2013-05-21 15:26:37 +00:00
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_search_bar_parent_class)->dispose (object);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-04 21:24:44 +00:00
|
|
|
|
static void
|
2020-05-03 13:56:40 +00:00
|
|
|
|
gtk_search_bar_compute_expand (GtkWidget *widget,
|
|
|
|
|
gboolean *hexpand,
|
|
|
|
|
gboolean *vexpand)
|
2018-02-04 21:24:44 +00:00
|
|
|
|
{
|
|
|
|
|
GtkSearchBar *bar = GTK_SEARCH_BAR (widget);
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (bar->child)
|
2020-05-03 13:56:40 +00:00
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
*hexpand = gtk_widget_compute_expand (bar->child, GTK_ORIENTATION_HORIZONTAL);
|
|
|
|
|
*vexpand = gtk_widget_compute_expand (bar->child, GTK_ORIENTATION_VERTICAL);
|
2020-05-03 13:56:40 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*hexpand = FALSE;
|
|
|
|
|
*vexpand = FALSE;
|
|
|
|
|
}
|
2018-02-04 21:24:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-05-21 15:26:37 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_search_bar_class_init (GtkSearchBarClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
|
|
object_class->dispose = gtk_search_bar_dispose;
|
|
|
|
|
object_class->set_property = gtk_search_bar_set_property;
|
|
|
|
|
object_class->get_property = gtk_search_bar_get_property;
|
|
|
|
|
|
2020-05-03 13:56:40 +00:00
|
|
|
|
widget_class->compute_expand = gtk_search_bar_compute_expand;
|
2020-07-13 19:06:08 +00:00
|
|
|
|
widget_class->focus = gtk_widget_focus_child;
|
2013-05-21 15:26:37 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* GtkSearchBar:search-mode-enabled: (attributes org.gtk.Property.get=gtk_search_bar_get_search_mode org.gtk.Property.set=gtk_search_bar_set_search_mode)
|
2013-05-21 15:26:37 +00:00
|
|
|
|
*
|
|
|
|
|
* Whether the search mode is on and the search bar shown.
|
2013-06-30 04:50:29 +00:00
|
|
|
|
*/
|
2022-05-11 12:19:39 +00:00
|
|
|
|
widget_props[PROP_SEARCH_MODE_ENABLED] = g_param_spec_boolean ("search-mode-enabled", NULL, NULL,
|
2013-05-21 15:26:37 +00:00
|
|
|
|
FALSE,
|
2014-06-09 13:39:53 +00:00
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
2013-06-30 04:50:29 +00:00
|
|
|
|
|
2013-05-21 15:26:37 +00:00
|
|
|
|
/**
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* GtkSearchBar:show-close-button: (attributes org.gtk.Property.get=gtk_search_bar_get_show_close_button org.gtk.Property.set=gtk_search_bar_set_show_close_button)
|
2013-05-21 15:26:37 +00:00
|
|
|
|
*
|
2017-05-07 12:02:27 +00:00
|
|
|
|
* Whether to show the close button in the search bar.
|
2013-06-30 04:50:29 +00:00
|
|
|
|
*/
|
2022-05-11 12:19:39 +00:00
|
|
|
|
widget_props[PROP_SHOW_CLOSE_BUTTON] = g_param_spec_boolean ("show-close-button", NULL, NULL,
|
2013-07-05 14:05:56 +00:00
|
|
|
|
FALSE,
|
2014-06-09 13:39:53 +00:00
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY);
|
2013-05-21 15:26:37 +00:00
|
|
|
|
|
2021-02-26 21:08:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkSearchBar:child: (attributes org.gtk.Property.get=gtk_search_bar_get_child org.gtk.Property.set=gtk_search_bar_set_child)
|
|
|
|
|
*
|
|
|
|
|
* The child widget.
|
|
|
|
|
*/
|
2022-05-11 12:19:39 +00:00
|
|
|
|
widget_props[PROP_CHILD] = g_param_spec_object ("child", NULL, NULL,
|
2020-05-03 13:51:09 +00:00
|
|
|
|
GTK_TYPE_WIDGET,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2021-02-26 21:08:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkSearchBar:key-capture-widget: (attributes org.gtk.Property.get=gtk_search_bar_get_key_capture_widget org.gtk.Property.set=gtk_search_bar_set_key_capture_widget)
|
|
|
|
|
*
|
|
|
|
|
* The key capture widget.
|
|
|
|
|
*/
|
2020-07-12 20:25:24 +00:00
|
|
|
|
widget_props[PROP_KEY_CAPTURE_WIDGET]
|
2022-05-11 12:19:39 +00:00
|
|
|
|
= g_param_spec_object ("key-capture-widget", NULL, NULL,
|
2020-07-12 20:25:24 +00:00
|
|
|
|
GTK_TYPE_WIDGET,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2013-05-21 15:26:37 +00:00
|
|
|
|
g_object_class_install_properties (object_class, LAST_PROPERTY, widget_props);
|
|
|
|
|
|
2020-05-03 13:56:40 +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_("searchbar"));
|
2020-11-12 14:54:39 +00:00
|
|
|
|
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_SEARCH);
|
2013-05-21 15:26:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_search_bar_init (GtkSearchBar *bar)
|
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
bar->revealer = gtk_revealer_new ();
|
|
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (bar->revealer), FALSE);
|
|
|
|
|
gtk_widget_set_hexpand (bar->revealer, TRUE);
|
|
|
|
|
gtk_widget_set_parent (bar->revealer, GTK_WIDGET (bar));
|
2018-02-04 21:24:44 +00:00
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
bar->box_center = gtk_center_box_new ();
|
|
|
|
|
gtk_widget_set_hexpand (bar->box_center, TRUE);
|
2018-02-04 21:24:44 +00:00
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
bar->close_button = gtk_button_new_from_icon_name ("window-close-symbolic");
|
2021-09-14 07:22:45 +00:00
|
|
|
|
gtk_widget_set_valign (bar->close_button, GTK_ALIGN_CENTER);
|
2020-05-05 00:09:29 +00:00
|
|
|
|
gtk_widget_add_css_class (bar->close_button, "close");
|
|
|
|
|
gtk_center_box_set_end_widget (GTK_CENTER_BOX (bar->box_center), bar->close_button);
|
2022-11-28 18:43:36 +00:00
|
|
|
|
gtk_widget_set_visible (bar->close_button, FALSE);
|
2018-02-04 21:24:44 +00:00
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
gtk_revealer_set_child (GTK_REVEALER (bar->revealer), bar->box_center);
|
2013-05-21 15:26:37 +00:00
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
g_signal_connect (bar->revealer, "notify::reveal-child",
|
2013-05-21 15:26:37 +00:00
|
|
|
|
G_CALLBACK (reveal_child_changed_cb), bar);
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
g_signal_connect (bar->close_button, "clicked",
|
2013-05-21 15:26:37 +00:00
|
|
|
|
G_CALLBACK (close_button_clicked_cb), bar);
|
2018-02-04 21:24:44 +00:00
|
|
|
|
}
|
2013-05-21 15:26:37 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_search_bar_new:
|
|
|
|
|
*
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* Creates a `GtkSearchBar`.
|
|
|
|
|
*
|
|
|
|
|
* You will need to tell it about which widget is going to be your text
|
|
|
|
|
* entry using [method@Gtk.SearchBar.connect_entry].
|
2013-05-21 15:26:37 +00:00
|
|
|
|
*
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* Returns: a new `GtkSearchBar`
|
2013-05-21 15:26:37 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkWidget *
|
|
|
|
|
gtk_search_bar_new (void)
|
|
|
|
|
{
|
|
|
|
|
return g_object_new (GTK_TYPE_SEARCH_BAR, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-22 15:46:16 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_search_bar_set_entry (GtkSearchBar *bar,
|
2019-02-17 04:58:06 +00:00
|
|
|
|
GtkEditable *entry)
|
2013-05-21 15:26:37 +00:00
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (bar->entry != NULL)
|
2013-05-21 15:26:37 +00:00
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (GTK_IS_SEARCH_ENTRY (bar->entry))
|
2018-03-11 12:53:17 +00:00
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (bar->entry), NULL);
|
|
|
|
|
g_signal_handlers_disconnect_by_func (bar->entry, stop_search_cb, bar);
|
2018-03-11 12:53:17 +00:00
|
|
|
|
}
|
2020-05-05 00:09:29 +00:00
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (bar->entry), (gpointer *) &bar->entry);
|
2013-05-21 15:26:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
bar->entry = GTK_WIDGET (entry);
|
2015-03-22 15:46:16 +00:00
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (bar->entry != NULL)
|
2013-05-21 15:26:37 +00:00
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (bar->entry), (gpointer *) &bar->entry);
|
|
|
|
|
if (GTK_IS_SEARCH_ENTRY (bar->entry))
|
2018-03-11 12:53:17 +00:00
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
g_signal_connect (bar->entry, "stop-search",
|
2018-03-11 12:53:17 +00:00
|
|
|
|
G_CALLBACK (stop_search_cb), bar);
|
2020-05-05 00:09:29 +00:00
|
|
|
|
gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (bar->entry),
|
2018-03-11 12:53:17 +00:00
|
|
|
|
GTK_WIDGET (bar));
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-21 15:26:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-22 15:46:16 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_search_bar_connect_entry:
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* @bar: a `GtkSearchBar`
|
|
|
|
|
* @entry: a `GtkEditable`
|
2015-03-22 15:46:16 +00:00
|
|
|
|
*
|
2022-12-23 16:01:07 +00:00
|
|
|
|
* Connects the `GtkEditable` widget passed as the one to be used in
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* this search bar.
|
|
|
|
|
*
|
|
|
|
|
* The entry should be a descendant of the search bar. Calling this
|
|
|
|
|
* function manually is only required if the entry isn’t the direct
|
|
|
|
|
* child of the search bar (as in our main example).
|
2015-03-22 15:46:16 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_search_bar_connect_entry (GtkSearchBar *bar,
|
2019-02-17 04:58:06 +00:00
|
|
|
|
GtkEditable *entry)
|
2015-03-22 15:46:16 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_SEARCH_BAR (bar));
|
2019-02-17 04:58:06 +00:00
|
|
|
|
g_return_if_fail (entry == NULL || GTK_IS_EDITABLE (entry));
|
2015-03-22 15:46:16 +00:00
|
|
|
|
|
|
|
|
|
gtk_search_bar_set_entry (bar, entry);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-21 15:26:37 +00:00
|
|
|
|
/**
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* gtk_search_bar_get_search_mode: (attributes org.gtk.Method.get_property=search-mode-enabled)
|
|
|
|
|
* @bar: a `GtkSearchBar`
|
2013-05-21 15:26:37 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns whether the search mode is on or off.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: whether search mode is toggled on
|
2013-06-30 04:50:29 +00:00
|
|
|
|
*/
|
2013-05-21 15:26:37 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gtk_search_bar_get_search_mode (GtkSearchBar *bar)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_SEARCH_BAR (bar), FALSE);
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
return bar->reveal_child;
|
2013-05-21 15:26:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* gtk_search_bar_set_search_mode: (attributes org.gtk.Method.set_property=search-mode-enabled)
|
|
|
|
|
* @bar: a `GtkSearchBar`
|
2013-05-21 15:26:37 +00:00
|
|
|
|
* @search_mode: the new state of the search mode
|
|
|
|
|
*
|
|
|
|
|
* Switches the search mode on or off.
|
2013-06-30 04:50:29 +00:00
|
|
|
|
*/
|
2013-05-21 15:26:37 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_search_bar_set_search_mode (GtkSearchBar *bar,
|
|
|
|
|
gboolean search_mode)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_SEARCH_BAR (bar));
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (bar->revealer), search_mode);
|
2013-05-21 15:26:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* gtk_search_bar_get_show_close_button: (attributes org.gtk.Method.get_property=show-close-button)
|
|
|
|
|
* @bar: a `GtkSearchBar`
|
2013-05-21 15:26:37 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns whether the close button is shown.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: whether the close button is shown
|
2013-06-30 04:50:29 +00:00
|
|
|
|
*/
|
2013-05-21 15:26:37 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gtk_search_bar_get_show_close_button (GtkSearchBar *bar)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_SEARCH_BAR (bar), FALSE);
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
return gtk_widget_get_visible (bar->close_button);
|
2013-05-21 15:26:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* gtk_search_bar_set_show_close_button: (attributes org.gtk.Method.set_property=show-close-button)
|
|
|
|
|
* @bar: a `GtkSearchBar`
|
2013-06-30 04:50:29 +00:00
|
|
|
|
* @visible: whether the close button will be shown or not
|
2013-05-21 15:26:37 +00:00
|
|
|
|
*
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* Shows or hides the close button.
|
|
|
|
|
*
|
|
|
|
|
* Applications that already have a “search” toggle button should not
|
|
|
|
|
* show a close button in their search bar, as it duplicates the role
|
|
|
|
|
* of the toggle button.
|
2013-06-30 04:50:29 +00:00
|
|
|
|
*/
|
2013-05-21 15:26:37 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_search_bar_set_show_close_button (GtkSearchBar *bar,
|
|
|
|
|
gboolean visible)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_SEARCH_BAR (bar));
|
|
|
|
|
|
2014-06-09 13:39:53 +00:00
|
|
|
|
visible = visible != FALSE;
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (gtk_widget_get_visible (bar->close_button) != visible)
|
2014-06-09 13:39:53 +00:00
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
gtk_widget_set_visible (bar->close_button, visible);
|
2020-01-28 12:51:04 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (bar), widget_props[PROP_SHOW_CLOSE_BUTTON]);
|
2014-06-09 13:39:53 +00:00
|
|
|
|
}
|
2013-05-21 15:26:37 +00:00
|
|
|
|
}
|
2018-03-11 12:53:17 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
changed_cb (gboolean *changed)
|
|
|
|
|
{
|
|
|
|
|
*changed = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
capture_widget_key_handled (GtkEventControllerKey *controller,
|
|
|
|
|
guint keyval,
|
|
|
|
|
guint keycode,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GtkSearchBar *bar)
|
|
|
|
|
{
|
|
|
|
|
gboolean handled;
|
|
|
|
|
|
2019-02-18 19:00:19 +00:00
|
|
|
|
if (!gtk_widget_get_mapped (GTK_WIDGET (bar)))
|
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (bar->reveal_child)
|
2018-03-11 12:53:17 +00:00
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (bar->entry == NULL)
|
2018-03-11 12:53:17 +00:00
|
|
|
|
{
|
|
|
|
|
g_warning ("The search bar does not have an entry connected to it. Call gtk_search_bar_connect_entry() to connect one.");
|
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (GTK_IS_SEARCH_ENTRY (bar->entry))
|
2018-03-11 12:53:17 +00:00
|
|
|
|
{
|
|
|
|
|
/* The search entry was told to listen to events from the search bar, so
|
|
|
|
|
* just forward the event to self, so the search entry has an opportunity
|
|
|
|
|
* to intercept those.
|
|
|
|
|
*/
|
|
|
|
|
handled = gtk_event_controller_key_forward (controller, GTK_WIDGET (bar));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gboolean preedit_changed, buffer_changed;
|
|
|
|
|
guint preedit_change_id, buffer_change_id;
|
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
|
|
if (gtk_search_entry_is_keynav (keyval, state) ||
|
|
|
|
|
keyval == GDK_KEY_space ||
|
|
|
|
|
keyval == GDK_KEY_Menu)
|
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
|
|
|
|
|
|
|
|
|
if (keyval == GDK_KEY_Escape)
|
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (gtk_revealer_get_reveal_child (GTK_REVEALER (bar->revealer)))
|
2018-03-11 12:53:17 +00:00
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
stop_search_cb (bar->entry, bar);
|
2018-03-11 12:53:17 +00:00
|
|
|
|
return GDK_EVENT_STOP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handled = GDK_EVENT_PROPAGATE;
|
|
|
|
|
preedit_changed = buffer_changed = FALSE;
|
2020-05-05 00:09:29 +00:00
|
|
|
|
preedit_change_id = g_signal_connect_swapped (bar->entry, "preedit-changed",
|
2018-03-11 12:53:17 +00:00
|
|
|
|
G_CALLBACK (changed_cb), &preedit_changed);
|
2020-05-05 00:09:29 +00:00
|
|
|
|
buffer_change_id = g_signal_connect_swapped (bar->entry, "changed",
|
2018-03-11 12:53:17 +00:00
|
|
|
|
G_CALLBACK (changed_cb), &buffer_changed);
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
res = gtk_event_controller_key_forward (controller, bar->entry);
|
2018-03-11 12:53:17 +00:00
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
g_signal_handler_disconnect (bar->entry, preedit_change_id);
|
|
|
|
|
g_signal_handler_disconnect (bar->entry, buffer_change_id);
|
2018-03-11 12:53:17 +00:00
|
|
|
|
|
|
|
|
|
if ((res && buffer_changed) || preedit_changed)
|
|
|
|
|
handled = GDK_EVENT_STOP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (handled == GDK_EVENT_STOP)
|
2020-05-05 00:09:29 +00:00
|
|
|
|
gtk_revealer_set_reveal_child (GTK_REVEALER (bar->revealer), TRUE);
|
2018-03-11 12:53:17 +00:00
|
|
|
|
|
|
|
|
|
return handled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* gtk_search_bar_set_key_capture_widget: (attributes org.gtk.Method.set_property=key-capture-widget)
|
|
|
|
|
* @bar: a `GtkSearchBar`
|
|
|
|
|
* @widget: (nullable) (transfer none): a `GtkWidget`
|
2018-03-11 12:53:17 +00:00
|
|
|
|
*
|
2021-01-26 03:16:29 +00:00
|
|
|
|
* Sets @widget as the widget that @bar will capture key events
|
|
|
|
|
* from.
|
2018-03-11 12:53:17 +00:00
|
|
|
|
*
|
|
|
|
|
* If key events are handled by the search bar, the bar will
|
|
|
|
|
* be shown, and the entry populated with the entered text.
|
2021-01-26 03:16:29 +00:00
|
|
|
|
*
|
|
|
|
|
* Note that despite the name of this function, the events
|
|
|
|
|
* are only 'captured' in the bubble phase, which means that
|
|
|
|
|
* editable child widgets of @widget will receive text input
|
|
|
|
|
* before it gets captured. If that is not desired, you can
|
|
|
|
|
* capture and forward the events yourself with
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* [method@Gtk.EventControllerKey.forward].
|
2021-01-26 03:16:29 +00:00
|
|
|
|
*/
|
2018-03-11 12:53:17 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_search_bar_set_key_capture_widget (GtkSearchBar *bar,
|
2020-05-05 00:09:29 +00:00
|
|
|
|
GtkWidget *widget)
|
2018-03-11 12:53:17 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_SEARCH_BAR (bar));
|
|
|
|
|
g_return_if_fail (!widget || GTK_IS_WIDGET (widget));
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (bar->capture_widget == widget)
|
2018-03-11 12:53:17 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (bar->capture_widget)
|
2018-03-11 12:53:17 +00:00
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
gtk_widget_remove_controller (bar->capture_widget,
|
|
|
|
|
bar->capture_widget_controller);
|
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (bar->capture_widget),
|
|
|
|
|
(gpointer *) &bar->capture_widget);
|
2018-03-11 12:53:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
bar->capture_widget = widget;
|
2018-03-11 12:53:17 +00:00
|
|
|
|
|
|
|
|
|
if (widget)
|
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (bar->capture_widget),
|
|
|
|
|
(gpointer *) &bar->capture_widget);
|
2018-03-11 12:53:17 +00:00
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
bar->capture_widget_controller = gtk_event_controller_key_new ();
|
|
|
|
|
gtk_event_controller_set_propagation_phase (bar->capture_widget_controller,
|
2021-01-26 03:16:29 +00:00
|
|
|
|
GTK_PHASE_BUBBLE);
|
2020-05-05 00:09:29 +00:00
|
|
|
|
g_signal_connect (bar->capture_widget_controller, "key-pressed",
|
2018-03-11 12:53:17 +00:00
|
|
|
|
G_CALLBACK (capture_widget_key_handled), bar);
|
2020-05-05 00:09:29 +00:00
|
|
|
|
g_signal_connect (bar->capture_widget_controller, "key-released",
|
2018-03-11 12:53:17 +00:00
|
|
|
|
G_CALLBACK (capture_widget_key_handled), bar);
|
2020-05-05 00:09:29 +00:00
|
|
|
|
gtk_widget_add_controller (widget, bar->capture_widget_controller);
|
2018-03-11 12:53:17 +00:00
|
|
|
|
}
|
2020-07-12 20:25:24 +00:00
|
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (bar), widget_props[PROP_KEY_CAPTURE_WIDGET]);
|
2018-03-11 12:53:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* gtk_search_bar_get_key_capture_widget: (attributes org.gtk.Method.get_property=key-capture-widget)
|
|
|
|
|
* @bar: a `GtkSearchBar`
|
2018-03-11 12:53:17 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the widget that @bar is capturing key events from.
|
|
|
|
|
*
|
2021-12-26 09:03:25 +00:00
|
|
|
|
* Returns: (nullable) (transfer none): The key capture widget.
|
2018-03-11 12:53:17 +00:00
|
|
|
|
**/
|
|
|
|
|
GtkWidget *
|
|
|
|
|
gtk_search_bar_get_key_capture_widget (GtkSearchBar *bar)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_SEARCH_BAR (bar), NULL);
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
return bar->capture_widget;
|
2018-03-11 12:53:17 +00:00
|
|
|
|
}
|
2020-05-03 13:51:09 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* gtk_search_bar_set_child: (attributes org.gtk.Method.set_property=child)
|
|
|
|
|
* @bar: a `GtkSearchBar`
|
2021-05-19 11:24:34 +00:00
|
|
|
|
* @child: (nullable): the child widget
|
2020-05-03 13:51:09 +00:00
|
|
|
|
*
|
|
|
|
|
* Sets the child widget of @bar.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_search_bar_set_child (GtkSearchBar *bar,
|
|
|
|
|
GtkWidget *child)
|
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (bar->child)
|
2020-05-03 13:56:40 +00:00
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (GTK_IS_EDITABLE (bar->child))
|
2020-05-03 13:56:40 +00:00
|
|
|
|
gtk_search_bar_connect_entry (bar, NULL);
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
gtk_center_box_set_center_widget (GTK_CENTER_BOX (bar->box_center), NULL);
|
2020-05-03 13:56:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
bar->child = child;
|
2020-05-03 13:56:40 +00:00
|
|
|
|
|
2020-05-05 00:09:29 +00:00
|
|
|
|
if (bar->child)
|
2020-05-03 13:56:40 +00:00
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
gtk_center_box_set_center_widget (GTK_CENTER_BOX (bar->box_center), child);
|
2020-05-03 13:56:40 +00:00
|
|
|
|
|
|
|
|
|
if (GTK_IS_EDITABLE (child))
|
|
|
|
|
gtk_search_bar_connect_entry (bar, GTK_EDITABLE (child));
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 13:51:09 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (bar), widget_props[PROP_CHILD]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-26 21:08:56 +00:00
|
|
|
|
* gtk_search_bar_get_child: (attributes org.gtk.Method.get_property=child)
|
|
|
|
|
* @bar: a `GtkSearchBar`
|
2020-05-03 13:51:09 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the child widget of @bar.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (nullable) (transfer none): the child widget of @bar
|
|
|
|
|
*/
|
|
|
|
|
GtkWidget *
|
|
|
|
|
gtk_search_bar_get_child (GtkSearchBar *bar)
|
|
|
|
|
{
|
2020-05-05 00:09:29 +00:00
|
|
|
|
return bar->child;
|
2020-05-03 13:56:40 +00:00
|
|
|
|
}
|