File: libgcmd-utils.h

package info (click to toggle)
gnome-commander 1.18.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,796 kB
  • sloc: cpp: 44,542; xml: 3,929; lex: 600; sh: 80; makefile: 15
file content (114 lines) | stat: -rw-r--r-- 3,665 bytes parent folder | download | duplicates (3)
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
109
110
111
112
113
114
/** 
 * @file libgcmd-utils.h
 * @copyright (C) 2001-2006 Marcus Bjurman\n
 * @copyright (C) 2007-2012 Piotr Eljasiak\n
 * @copyright (C) 2013-2024 Uwe Scholz\n
 *
 * @copyright This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * @copyright This program 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 General Public License for more details.
 *
 * @copyright You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#pragma once

gchar *get_utf8 (const gchar *unknown);

inline gchar *get_bold_text (const gchar *in)
{
    gchar *escaped_text = g_markup_escape_text (in, -1);
    gchar *result = g_strdup_printf("<span weight=\"bold\">%s</span>", escaped_text);
    g_free (escaped_text);
    return result;
}

inline gchar *get_mono_text (const gchar *in)
{
    gchar *escaped_text = g_markup_escape_text (in, -1);
    gchar *result = g_strdup_printf("<span font_family=\"monospace\">%s</span>", escaped_text);
    g_free (escaped_text);
    return result;
}

inline gchar *get_bold_mono_text (const gchar *in)
{
    gchar *escaped_text = g_markup_escape_text (in, -1);
    gchar *result = g_strdup_printf("<span font_family=\"monospace\" weight=\"bold\">%s</span>", escaped_text);
    g_free (escaped_text);
    return result;
}

inline GtkWindow *get_toplevel_window (GtkWidget *widget)
{
    return GTK_WINDOW (gtk_widget_get_toplevel (widget));
}

#if !GTK_CHECK_VERSION(4, 0, 0)
inline void gtk_window_destroy (GtkWindow* window)
{
    gtk_widget_destroy (GTK_WIDGET (window));
}

gboolean hide_on_close_handler (GtkWidget *widget, GdkEvent *event, gpointer unused);

inline void gtk_window_set_hide_on_close (GtkWindow* window, gboolean unused_assume_always_true)
{
    g_signal_connect (window, "delete-event", G_CALLBACK (hide_on_close_handler), nullptr);
}

inline void gtk_box_append (GtkBox* box, GtkWidget* child)
{
    gtk_container_add (GTK_CONTAINER (box), child);
}

inline GtkWidget* gtk_scrolled_window_new ()
{
    return gtk_scrolled_window_new (nullptr, nullptr);
}

inline void gtk_scrolled_window_set_child (GtkScrolledWindow* scrolled_window, GtkWidget* child)
{
    gtk_container_add (GTK_CONTAINER (scrolled_window), child);
}

inline GtkWidget* gtk_scrolled_window_get_child (GtkScrolledWindow* scrolled_window)
{
    return gtk_bin_get_child (GTK_BIN (scrolled_window));
}

inline void gtk_scrolled_window_set_has_frame (GtkScrolledWindow* scrolled_window, gboolean has_frame)
{
    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), has_frame ? GTK_SHADOW_IN : GTK_SHADOW_NONE);
}

inline GtkWidget* gtk_combo_box_get_child (GtkComboBox* combo_box)
{
    return gtk_bin_get_child (GTK_BIN (combo_box));
}

inline const char* gtk_editable_get_text (GtkEditable* editable)
{
    return gtk_entry_get_text (GTK_ENTRY (editable));
}

inline void gtk_editable_set_text (GtkEditable* editable, const char* text)
{
    gtk_entry_set_text (GTK_ENTRY (editable), text);
}

inline gboolean gdk_rectangle_contains_point (const GdkRectangle *rect, int x, int y)
{
    g_return_val_if_fail (rect != NULL, FALSE);
    return x >= rect->x && x < rect->x + rect->width && y >= rect->y && y < rect->y + rect->height;
}
#endif