Update to 24f58c58bb8d22c0e8e6c5ce43c536c47b719bc6
[gnt.git] / gntutils.h
blob6aa66a13b7f4a323a00983040b2d0759e45233ae
1 /**
2 * @file gntutils.h Some utility functions
3 * @ingroup gnt
4 */
5 /*
6 * GNT - The GLib Ncurses Toolkit
8 * GNT is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This library is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
27 #include <glib.h>
29 #include "gnt.h"
30 #include "gnttextview.h"
31 #include "gntwidget.h"
33 typedef gpointer (*GDupFunc)(gconstpointer data);
35 /**
36 * Compute the width and height required to view the text on the screen.
38 * @param text The text to be displayed.
39 * @param width The width required is set here, if not @c NULL.
40 * @param height The height required is set here, if not @c NULL.
42 void gnt_util_get_text_bound(const char *text, int *width, int *height);
44 /* excluding *end */
45 /**
46 * Get the onscreen width of a string, or a substring.
48 * @param start The beginning of the string.
49 * @param end The end of the string. The width returned is the width
50 * upto (but not including) end. If end is NULL, then start
51 * is considered as a @c NULL-terminated string.
53 * @return The on-screen width of the string.
55 int gnt_util_onscreen_width(const char *start, const char *end);
57 /**
58 * Computes and returns the string after a specific number of onscreen characters.
60 * @param str The string.
61 * @param len The length to consider. If non-positive, the entire screenlength is used.
62 * @param w The actual width of the string upto the returned offset, if not @c NULL.
64 * @return The string after len offset.
66 const char *gnt_util_onscreen_width_to_pointer(const char *str, int len, int *w);
68 /**
69 * Inserts newlines in 'string' where necessary so that its onscreen width is
70 * no more than 'maxw'.
72 * @param string The string.
73 * @param maxw The width that the string should fit into. If maxw is <= 0,
74 * then the available maximum width is used.
76 * @return A newly allocated string that needs to be freed by the caller.
78 char * gnt_util_onscreen_fit_string(const char *string, int maxw);
80 /**
81 * Duplicate the contents of a hastable.
83 * @param src The source hashtable.
84 * @param hash The hash-function to use.
85 * @param equal The hash-equal function to use.
86 * @param key_d The key-destroy function to use.
87 * @param value_d The value-destroy function to use.
88 * @param key_dup The function to use to duplicate the key.
89 * @param value_dup The function to use to duplicate the value.
91 * @return The new hashtable.
93 GHashTable * g_hash_table_duplicate(GHashTable *src, GHashFunc hash, GEqualFunc equal, GDestroyNotify key_d, GDestroyNotify value_d, GDupFunc key_dup, GDupFunc value_dup);
95 /**
96 * To be used with g_signal_new. Look in the key_pressed signal-definition in
97 * gntwidget.c for usage.
99 * @param ihint NA
100 * @param return_accu NA
101 * @param handler_return NA
102 * @param dummy NA
104 * @return NA
106 gboolean gnt_boolean_handled_accumulator(GSignalInvocationHint *ihint, GValue *return_accu, const GValue *handler_return, gpointer dummy);
109 * Get a helpful display about the bindings of a widget.
111 * @param widget The widget to get bindings for.
113 * @return Returns a GntTree populated with "key" -> "binding" for the widget.
115 GntWidget * gnt_widget_bindings_view(GntWidget *widget);
118 * Parse widgets from an XML description. For example,
120 * @code
121 * GntWidget *win, *button;
122 * gnt_util_parse_widgets("\
123 * <vwindow id='0' fill='0' align='2'> \
124 * <label>This is a test</label> \
125 * <button id='1'>OK</button> \
126 * </vwindow>",
127 * 2, &win, &button);
128 * @endcode
130 * @param string The XML string.
131 * @param num The number of widgets to return, followed by 'num' GntWidget **
133 void gnt_util_parse_widgets(const char *string, int num, ...);
136 * Parse an XHTML string and add it in a GntTextView with
137 * appropriate text flags.
139 * @param string The XHTML string
140 * @param tv The GntTextView
141 * @return @c TRUE if the string was added to the textview properly, @c FALSE otherwise.
143 * @since 2.2.0
145 gboolean gnt_util_parse_xhtml_to_textview(const char *string, GntTextView *tv);
148 * Make some keypress activate a button when some key is pressed with 'wid' in focus.
150 * @param widget The widget
151 * @param key The key to trigger the button
152 * @param button The button to trigger
154 * @since 2.0.0 (gnt), 2.1.0 (pidgin)
156 void gnt_util_set_trigger_widget(GntWidget *widget, const char *key, GntWidget *button);