1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/*
* Copyright (C) 2020 Alexander Mikhaylenko <alexm@gnome.org>
*
* SPDX-License-Identifier: LGPL-2.1+
*
* Based on
* glade-gtk-searchbar.c - GladeWidgetAdaptor for GtkSearchBar
* Copyright (C) 2014 Red Hat, Inc.
*/
#include <config.h>
#include <glib/gi18n-lib.h>
#include "glade-hdy-window.h"
#include <gladeui/glade.h>
#define ALREADY_HAS_A_CHILD_MSG _("%s cannot have more than one child.")
static GtkWidget *
get_child (GtkContainer *window)
{
g_autoptr (GList) children = gtk_container_get_children (window);
if (!children)
return NULL;
return children->data;
}
void
glade_hdy_window_post_create (GladeWidgetAdaptor *adaptor,
GObject *object,
GladeCreateReason reason)
{
if (reason != GLADE_CREATE_USER)
return;
gtk_container_add (GTK_CONTAINER (object), glade_placeholder_new ());
}
void
glade_hdy_window_add_child (GladeWidgetAdaptor *adaptor,
GObject *object,
GObject *child)
{
GtkWidget *window_child = get_child (GTK_CONTAINER (object));
if (window_child) {
if (GLADE_IS_PLACEHOLDER (window_child)) {
gtk_container_remove (GTK_CONTAINER (object), window_child);
} else {
g_critical ("Can't add more than one widget to a HdyWindow");
return;
}
}
gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child));
}
void
glade_hdy_window_remove_child (GladeWidgetAdaptor *adaptor,
GObject *object,
GObject *child)
{
gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child));
gtk_container_add (GTK_CONTAINER (object), glade_placeholder_new ());
}
void
glade_hdy_window_replace_child (GladeWidgetAdaptor *adaptor,
GtkWidget *object,
GtkWidget *current,
GtkWidget *new_widget)
{
gtk_container_remove (GTK_CONTAINER (object), current);
gtk_container_add (GTK_CONTAINER (object), new_widget);
}
GList *
glade_hdy_window_get_children (GladeWidgetAdaptor *adaptor,
GObject *object)
{
return gtk_container_get_children (GTK_CONTAINER (object));
}
gboolean
glade_hdy_window_add_verify (GladeWidgetAdaptor *adaptor,
GtkWidget *object,
GtkWidget *child,
gboolean user_feedback)
{
GtkWidget *window_child = get_child (GTK_CONTAINER (object));
if (window_child && !GLADE_IS_PLACEHOLDER (window_child)) {
if (user_feedback)
glade_util_ui_message (glade_app_get_window (),
GLADE_UI_INFO, NULL,
ALREADY_HAS_A_CHILD_MSG,
glade_widget_adaptor_get_title (adaptor));
return FALSE;
}
return TRUE;
}
|