Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
container.c
Go to the documentation of this file.
1/*
2 * This file is part of Ansel,
3 * Copyright (C) 2026 Aurélien PIERRE.
4 *
5 * Ansel is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * Ansel is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with Ansel. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "widgets/container.h"
20
21#include "system/macros.h" // IS_NULL_PTR
22
24{
25 g_return_val_if_fail(GTK_IS_CONTAINER(container), FALSE);
26 GList *children = gtk_container_get_children(container);
27 gboolean has_children = !IS_NULL_PTR(children);
28 g_list_free(children);
29 children = NULL;
30 return has_children;
31}
32
34{
35 g_return_val_if_fail(GTK_IS_CONTAINER(container), FALSE);
36 GList *children = gtk_container_get_children(container);
37 int num_children = g_list_length(children);
38 g_list_free(children);
39 children = NULL;
40 return num_children;
41}
42
44{
45 g_return_val_if_fail(GTK_IS_CONTAINER(container), NULL);
46 GList *children = gtk_container_get_children(container);
47 GtkWidget *child = children ? (GtkWidget*)children->data : NULL;
48 g_list_free(children);
49 children = NULL;
50 return child;
51}
52
54{
55 g_return_val_if_fail(GTK_IS_CONTAINER(container), NULL);
56 GList *children = gtk_container_get_children(container);
57 GtkWidget *child = (GtkWidget*)g_list_nth_data(children, which);
58 g_list_free(children);
59 children = NULL;
60 return child;
61}
62
63static void _remove_child(GtkWidget *widget, gpointer data)
64{
65 gtk_container_remove((GtkContainer*)data, widget);
66}
67
69{
70 g_return_if_fail(GTK_IS_CONTAINER(container));
71 gtk_container_foreach(container, _remove_child, container);
72}
73
74static void _delete_child(GtkWidget *widget, gpointer data)
75{
76 (void)data; // avoid unreferenced-parameter warning
77 gtk_widget_destroy(widget);
78}
79
81{
82 g_return_if_fail(GTK_IS_CONTAINER(container));
83 gtk_container_foreach(container, _delete_child, NULL);
84}
85
86/* Typed, deliberately. The idiom this replaces was
87 * gtk_container_foreach(box, (GtkCallback)gtk_widget_set_can_focus, GINT_TO_POINTER(FALSE))
88 * which calls a function through an incompatible pointer type: gtk_widget_set_can_focus() takes
89 * a gboolean, GtkCallback passes a gpointer. It happens to work where the ABI leaves the int in
90 * the low half of the register the pointer arrived in, and this binary is built with -flto, so
91 * the two declarations meet at link time. */
92static void _child_no_focus(GtkWidget *child, gpointer data)
93{
94 (void)data; // avoid unreferenced-parameter warning
95 gtk_widget_set_can_focus(child, FALSE);
96}
97
98void dt_gui_flow_box_as_layout(GtkFlowBox *box)
99{
100 g_return_if_fail(GTK_IS_FLOW_BOX(box));
101 gtk_flow_box_set_selection_mode(box, GTK_SELECTION_NONE);
102 gtk_container_foreach(GTK_CONTAINER(box), _child_no_focus, NULL);
103}
104
106{
107 g_return_if_fail(GTK_IS_WIDGET(child));
108 // gtk_flow_box_insert() wraps the child; clearing can-focus on the CHILD would only stop the
109 // widget the user came for from being reachable at all.
110 GtkWidget *wrapper = gtk_widget_get_parent(child);
111 if(GTK_IS_FLOW_BOX_CHILD(wrapper)) gtk_widget_set_can_focus(wrapper, FALSE);
112}
113
114// clang-format off
115// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
116// vim: shiftwidth=2 expandtab tabstop=2 cindent
117// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
118// clang-format on
#define FALSE
Definition ashift_lsd.c:158
uint32_t container(dt_lib_module_t *self)
typedef void((*dt_cache_allocate_t)(void *userdata, dt_cache_entry_t *entry))
struct _GtkWidget GtkWidget
GtkWidget, opaque, spelled exactly as GTK spells it.
Definition colorspaces.h:98
void dt_gui_container_remove_children(GtkContainer *container)
Definition container.c:68
static void _delete_child(GtkWidget *widget, gpointer data)
Definition container.c:74
static void _remove_child(GtkWidget *widget, gpointer data)
Definition container.c:63
static void _child_no_focus(GtkWidget *child, gpointer data)
Definition container.c:92
int dt_gui_container_num_children(GtkContainer *container)
Definition container.c:33
GtkWidget * dt_gui_container_nth_child(GtkContainer *container, int which)
Definition container.c:53
void dt_gui_flow_box_as_layout(GtkFlowBox *box)
Definition container.c:98
void dt_gui_container_destroy_children(GtkContainer *container)
Definition container.c:80
gboolean dt_gui_container_has_children(GtkContainer *container)
Definition container.c:23
void dt_gui_flow_box_child_as_layout(GtkWidget *child)
Definition container.c:105
GtkWidget * dt_gui_container_first_child(GtkContainer *container)
Definition container.c:43
void * data
Definition geometry.h:111
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition macros.h:96
static void _remove_child(GtkWidget *child, GtkContainer *container)
Definition view.c:223