Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
resetlabel.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2010 Bruce Guenter.
4 Copyright (C) 2010-2011 johannes hanika.
5 Copyright (C) 2011 Antony Dovgal.
6 Copyright (C) 2011, 2014, 2016 Tobias Ellinghaus.
7 Copyright (C) 2012 Richard Wonka.
8 Copyright (C) 2013 Roman Lebedev.
9 Copyright (C) 2020 Diederik Ter Rahe.
10 Copyright (C) 2020 Pascal Obry.
11 Copyright (C) 2021 Victor Forsiuk.
12 Copyright (C) 2022 Martin Bařinka.
13 Copyright (C) 2026 Aurélien PIERRE.
14
15 darktable is free software: you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation, either version 3 of the License, or
18 (at your option) any later version.
19
20 darktable is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with darktable. If not, see <http://www.gnu.org/licenses/>.
27*/
28
29#include "widgets/resetlabel.h"
30
31#include <glib/gi18n.h>
32
35
36static guint _reset_signal = 0;
37
39{
40 // The widget announces the double-click; the consumer decides what resetting means.
41 _reset_signal = g_signal_new("reset", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
42 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
43}
44
46{
47}
48
49static gboolean _reset_label_callback(GtkDarktableResetLabel *label, GdkEventButton *event, gpointer user_data)
50{
51 if(event->type == GDK_2BUTTON_PRESS)
52 {
53 g_signal_emit(label, _reset_signal, 0);
54 return TRUE;
55 }
56 return FALSE;
57}
58
59// public functions
61{
63 label = g_object_new(dtgtk_reset_label_get_type(), NULL);
64
65 label->lb = GTK_LABEL(gtk_label_new(text));
66 gtk_widget_set_halign(GTK_WIDGET(label->lb), GTK_ALIGN_START);
67 gtk_label_set_ellipsize(GTK_LABEL(label->lb), PANGO_ELLIPSIZE_END);
68 gtk_event_box_set_visible_window(GTK_EVENT_BOX(label), FALSE);
69 gtk_widget_set_tooltip_text(GTK_WIDGET(label), _("double-click to reset"));
70 gtk_container_add(GTK_CONTAINER(label), GTK_WIDGET(label->lb));
71 gtk_widget_add_events(GTK_WIDGET(label), GDK_BUTTON_PRESS_MASK);
72 g_signal_connect(G_OBJECT(label), "button-press-event", G_CALLBACK(_reset_label_callback), (gpointer)NULL);
73
74 return (GtkWidget *)label;
75}
76
78{
79 static GType dtgtk_reset_label_type = 0;
80 if(!dtgtk_reset_label_type)
81 {
82 static const GTypeInfo dtgtk_reset_label_info = {
83 sizeof(GtkDarktableResetLabelClass), (GBaseInitFunc)NULL, (GBaseFinalizeFunc)NULL,
84 (GClassInitFunc)_reset_label_class_init, NULL, /* class_finalize */
85 NULL, /* class_data */
86 sizeof(GtkDarktableResetLabel), 0, /* n_preallocs */
87 (GInstanceInitFunc)_reset_label_init,
88 };
89 dtgtk_reset_label_type
90 = g_type_register_static(GTK_TYPE_EVENT_BOX, "GtkDarktableResetLabel", &dtgtk_reset_label_info, 0);
91 }
92 return dtgtk_reset_label_type;
93}
94
96{
97 gtk_label_set_text(label->lb, str);
98}
99
100// clang-format off
101// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
102// vim: shiftwidth=2 expandtab tabstop=2 cindent
103// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
104// clang-format on
105
#define TRUE
Definition ashift_lsd.c:162
#define FALSE
Definition ashift_lsd.c:158
struct _GtkWidget GtkWidget
GtkWidget, opaque, spelled exactly as GTK spells it.
Definition colorspaces.h:98
static void _reset_label_init(GtkDarktableResetLabel *label)
Definition resetlabel.c:45
GType dtgtk_reset_label_get_type()
Definition resetlabel.c:77
static gboolean _reset_label_callback(GtkDarktableResetLabel *label, GdkEventButton *event, gpointer user_data)
Definition resetlabel.c:49
static guint _reset_signal
Definition resetlabel.c:36
GtkWidget * dtgtk_reset_label_new(const gchar *text)
Definition resetlabel.c:60
static void _reset_label_class_init(GtkDarktableResetLabelClass *klass)
Definition resetlabel.c:38
void dtgtk_reset_label_set_text(GtkDarktableResetLabel *label, const gchar *str)
Definition resetlabel.c:95
struct _GtkDarktableResetLabelClass GtkDarktableResetLabelClass
struct _GtkDarktableResetLabel GtkDarktableResetLabel