gntutils.h File Reference
GNT (GLib Ncurses Toolkit)
`#include <glib.h>`
`#include "gnt.h"`
`#include "gnttextview.h"`
`#include "gntwidget.h"`

Go to the source code of this file.

## Typedefs

typedef gpointer(* | GDupFunc) (gconstpointer data)

## Functions

void | gnt_util_get_text_bound (const char *text, int *width, int *height)
| Compute the width and height required to view the text on the screen. More...
int | gnt_util_onscreen_width (const char *start, const char *end)
| Get the onscreen width of a string, or a substring. More...
const char * | gnt_util_onscreen_width_to_pointer (const char *str, int len, int *w)
| Computes and returns the string after a specific number of onscreen characters. More...
char * | gnt_util_onscreen_fit_string (const char *string, int maxw)
| Inserts newlines in 'string' where necessary so that its onscreen width is no more than 'maxw'. More...
GHashTable * | g_hash_table_duplicate (GHashTable *src, GHashFunc hash, GEqualFunc equal, GDestroyNotify key_d, GDestroyNotify value_d, GDupFunc key_dup, GDupFunc value_dup)
| Duplicate the contents of a hastable. More...
gboolean | gnt_boolean_handled_accumulator (GSignalInvocationHint *ihint, GValue *return_accu, const GValue *handler_return, gpointer dummy)
| To be used with g_signal_new. More...
GntWidget * | gnt_widget_bindings_view (GntWidget *widget)
| Get a helpful display about the bindings of a widget. More...
void | gnt_util_parse_widgets (const char *string, int num,...)
| Parse widgets from an XML description. More...
gboolean | gnt_util_parse_xhtml_to_textview (const char *string, GntTextView *tv)
| Parse an XHTML string and add it in a GntTextView with appropriate text flags. More...
void | gnt_util_set_trigger_widget (GntWidget *widget, const char *key, GntWidget *button)
| Make some keypress activate a button when some key is pressed with 'wid' in focus. More...

## Detailed Description

Some utility functions

Definition in file gntutils.h.

## Function Documentation

## g_hash_table_duplicate()

GHashTable* g_hash_table_duplicate | ( | GHashTable * | src,
|  | GHashFunc | hash,
|  | GEqualFunc | equal,
|  | GDestroyNotify | key_d,
|  | GDestroyNotify | value_d,
|  | GDupFunc | key_dup,
|  | GDupFunc | value_dup
| ) |  |

Duplicate the contents of a hastable.

Parameters

  src | The source hashtable.
  hash | The hash-function to use.
  equal | The hash-equal function to use.
  key_d | The key-destroy function to use.
  value_d | The value-destroy function to use.
  key_dup | The function to use to duplicate the key.
  value_dup | The function to use to duplicate the value.

Returns
  The new hashtable.

## gnt_boolean_handled_accumulator()

gboolean gnt_boolean_handled_accumulator | ( | GSignalInvocationHint * | ihint,
|  | GValue * | return_accu,
|  | const GValue * | handler_return,
|  | gpointer | dummy
| ) |  |

To be used with g_signal_new.

Look in the key_pressed signal-definition in gntwidget.c for usage.

Parameters

  ihint | NA
  return_accu | NA
  handler_return | NA
  dummy | NA

Returns
  NA

## gnt_util_get_text_bound()

void gnt_util_get_text_bound | ( | const char * | text,
|  | int * | width,
|  | int * | height
| ) |  |

Compute the width and height required to view the text on the screen.

Parameters

  text | The text to be displayed.
  width | The width required is set here, if not `NULL`.
  height | The height required is set here, if not `NULL`.

## gnt_util_onscreen_fit_string()

char* gnt_util_onscreen_fit_string | ( | const char * | string,
|  | int | maxw
| ) |  |

Inserts newlines in 'string' where necessary so that its onscreen width is no more than 'maxw'.

Parameters

  string | The string.
  maxw | The width that the string should fit into. If maxw is <= 0, then the available maximum width is used.

Returns
  A newly allocated string that needs to be freed by the caller.

## gnt_util_onscreen_width()

int gnt_util_onscreen_width | ( | const char * | start,
|  | const char * | end
| ) |  |

Get the onscreen width of a string, or a substring.

Parameters

  start | The beginning of the string.
  end | The end of the string. The width returned is the width upto (but not including) end. If end is NULL, then start is considered as a `NULL-terminated` string.

Returns
  The on-screen width of the string.

## gnt_util_onscreen_width_to_pointer()

const char* gnt_util_onscreen_width_to_pointer | ( | const char * | str,
|  | int | len,
|  | int * | w
| ) |  |

Computes and returns the string after a specific number of onscreen characters.

Parameters

  str | The string.
  len | The length to consider. If non-positive, the entire screenlength is used.
  w | The actual width of the string upto the returned offset, if not `NULL`.

Returns
  The string after len offset.

## gnt_util_parse_widgets()

void gnt_util_parse_widgets | ( | const char * | string,
|  | int | num,
|  |  | ...
| ) |  |

Parse widgets from an XML description.

For example,

GntWidget *win, *button;
gnt_util_parse_widgets("\
<vwindow id='0' fill='0' align='2'> \
<label>This is a test</label> \
<button id='1'>OK</button> \
</vwindow>",
2, &win, &button);

Parameters

  string | The XML string.
  num | The number of widgets to return, followed by 'num' GntWidget **

## gnt_util_parse_xhtml_to_textview()

gboolean gnt_util_parse_xhtml_to_textview | ( | const char * | string,
|  | GntTextView * | tv
| ) |  |

Parse an XHTML string and add it in a GntTextView with appropriate text flags.

Parameters

  string | The XHTML string
  tv | The GntTextView

Returns
  `TRUE` if the string was added to the textview properly, `FALSE` otherwise.

Since
  2.2.0

## gnt_util_set_trigger_widget()

void gnt_util_set_trigger_widget | ( | GntWidget * | widget,
|  | const char * | key,
|  | GntWidget * | button
| ) |  |

Make some keypress activate a button when some key is pressed with 'wid' in focus.

Parameters

  widget | The widget
  key | The key to trigger the button
  button | The button to trigger

Since
  2.0.0 (gnt), 2.1.0 (pidgin)

## gnt_widget_bindings_view()

GntWidget* gnt_widget_bindings_view | ( | GntWidget * | widget | ) |

Get a helpful display about the bindings of a widget.

Parameters

  widget | The widget to get bindings for.

Returns
  Returns a GntTree populated with "key" -> "binding" for the widget.

_GntWidget
Definition: gntwidget.h:98
gnt_util_parse_widgets
void gnt_util_parse_widgets(const char *string, int num,...)
Parse widgets from an XML description.