GtkStringList
GtkStringList — A list model for strings
Functions
| GtkStringList * | gtk_string_list_new () |
| void | gtk_string_list_append () |
| void | gtk_string_list_take () |
| void | gtk_string_list_remove () |
| void | gtk_string_list_splice () |
| const char * | gtk_string_list_get_string () |
| GtkStringObject * | gtk_string_object_new () |
| const char * | gtk_string_object_get_string () |
Properties
| char * | string | Read |
Types and Values
Object Hierarchy
GObject
├── GtkStringList
╰── GtkStringObject
Implemented Interfaces
GtkStringList implements GtkBuildable and GListModel.
Includes
#include <gtk/gtk.h>
Description
GtkStringList is a list model that wraps an array of strings.
The objects in the model have a "string" property.
GtkStringList is well-suited for any place where you would typically use a char*[], but need a list model.
GtkStringList as GtkBuildable
The GtkStringList implementation of the GtkBuildable interface supports adding items directly using the <items> element and specifying <item> elements for each item. Each <item> element supports the regular translation attributes “translatable”, “context” and “comments”.
Here is a UI definition fragment specifying a GtkStringList
Functions
gtk_string_list_new ()
GtkStringList *
gtk_string_list_new (const char * const *strings); Creates a new GtkStringList with the given strings .
Parameters
strings | The strings to put in the model. | [array zero-terminated=1][nullable] |
Returns
a new GtkStringList
gtk_string_list_append ()
void gtk_string_list_append (GtkStringList *self,const char *string);
Appends string to self .
The string will be copied. See gtk_string_list_take() for a way to avoid that.
Parameters
self | ||
string | the string to insert |
gtk_string_list_take ()
void gtk_string_list_take (GtkStringList *self,char *string);
Adds string to self at the end, and takes ownership of it.
This variant of gtk_string_list_append() is convenient for formatting strings:
<object class="GtkStringList">
<items>
<item translatable="yes">Factory</item>
<item translatable="yes">Home</item>
<item translatable="yes">Subway</item>
</items>
</object>Parameters
self | ||
string | the string to insert. | [transfer full] |
gtk_string_list_remove ()
void gtk_string_list_remove (GtkStringList *self,guint position);
Removes the string at position from self . position must be smaller than the current length of the list.
Parameters
self | ||
position | the position of the string that is to be removed |
gtk_string_list_splice ()
void gtk_string_list_splice (GtkStringList *self,guint position,guint n_removals,const char * const *additions);
Changes self by removing n_removals strings and adding additions to it.
This function is more efficient than gtk_string_list_append() and gtk_string_list_remove(), because it only emits “items-changed” once for the change.
This function copies the strings in additions .
The parameters position and n_removals must be correct (ie: position + n_removals must be less than or equal to the length of the list at the time this function is called).
Parameters
self | ||
position | the position at which to make the change | |
n_removals | the number of strings to remove | |
additions | The strings to add. | [array zero-terminated=1][nullable] |
gtk_string_list_get_string ()
const char * gtk_string_list_get_string (GtkStringList *self,guint position);
Gets the string that is at position in self . If self does not contain position items, NULL is returned.
This function returns the const char *. To get the object wrapping it, use g_list_model_get_item().
Parameters
self | ||
position | the position to get the string for |
Returns
the string at the given position.
[nullable]
gtk_string_object_new ()
GtkStringObject *
gtk_string_object_new (const char *string); Wraps a string in an object for use with GListModel
Parameters
string | The string to wrap. | [not nullable] |
Returns
a new GtkStringObject
gtk_string_object_get_string ()
const char *
gtk_string_object_get_string (GtkStringObject *self); Returns the string contained in a GtkStringObject.
Parameters
self |
Returns
the string of self
Types and Values
GtkStringList
typedef struct _GtkStringList GtkStringList;
GtkStringObject
typedef struct _GtkStringObject GtkStringObject;
Property Details
The “string” property
“string” char *
String.
Owner: GtkStringObject
Flags: Read
Default value: NULL
See Also
GListModel
© 2005–2020 The GNOME Project
Licensed under the GNU Lesser General Public License version 2.1 or later.
https://developer.gnome.org/gtk4/4.0/GtkStringList.html