From 12989bb0e8572c7735c4c6d05858d3721877d9f8 Mon Sep 17 00:00:00 2001 From: Mike Wey Date: Mon, 1 Mar 2021 23:23:52 +0100 Subject: [PATCH] Update the MultiCellRenderer demo. There is still an GTK error when editing a cell, not sure if it's caused by code in this demo. --- .../DemoMultiCellRenderer.d | 187 ++++++++---------- generated/gtkd/gdk/RGBA.d | 26 +++ generated/gtkd/gtk/Dialog.d | 48 ++--- generated/gtkd/gtk/Entry.d | 1 - generated/gtkd/gtk/FileChooserNative.d | 5 + generated/gtkd/gtk/ListStore.d | 20 ++ generated/gtkd/gtk/NativeDialog.d | 5 + generated/gtkd/gtk/PopoverMenu.d | 2 +- generated/gtkd/gtk/SearchBar.d | 8 +- generated/gtkd/gtk/TreeModelT.d | 11 ++ generated/gtkd/gtk/Widget.d | 31 +-- generated/gtkd/gtk/c/types.d | 6 +- generated/gtkd/pango/PgFontFace.d | 5 +- generated/gtkd/rsvg/c/types.d | 4 +- src/APILookupGdk.txt | 27 +++ src/APILookupGtk.txt | 34 ++++ 16 files changed, 268 insertions(+), 152 deletions(-) diff --git a/demos/gtkD/DemoMultiCellRenderer/DemoMultiCellRenderer.d b/demos/gtkD/DemoMultiCellRenderer/DemoMultiCellRenderer.d index 54b02288d..c8f32be8b 100644 --- a/demos/gtkD/DemoMultiCellRenderer/DemoMultiCellRenderer.d +++ b/demos/gtkD/DemoMultiCellRenderer/DemoMultiCellRenderer.d @@ -38,7 +38,8 @@ *****************************************************************************/ module DemoMultiCellRenderer; -import gtk.Main; +import gtk.Application; +import gtk.ApplicationWindow; import gdk.Event; import gtk.Window; import gtk.Widget; @@ -51,10 +52,8 @@ import gtk.CellRendererToggle; import gtk.ListStore; import gdk.RGBA; -import gdk.Color; -import pango.PgFontDescription; -import std.stdio; +import gobject.Value; enum { COLUMN_NAME, @@ -62,105 +61,93 @@ enum { COLUMN_TEXT_VISIBLE, COLUMN_BOOL, COLUMN_BOOL_VISIBLE, - COLUMN_TEXT_COLOR, COLUMN_TEXT_COLOR_RGBA, - COLUMN_TEXT_FONT_DESCRIPTION, } -void main(string[] args){ - Main.init(args); - ListStore store = new ListStore( [ - GType.STRING, - GType.STRING, - GType.INT, - GType.INT, - GType.INT, - Color.getType(), - RGBA.getType(), - PgFontDescription.getType(), - ] ); - - void appendRecord( string name, string value, bool isBoolean, RGBA rgba, Color color ){ - auto it = store.createIter(); - store.setValue( it, COLUMN_NAME, name ); - store.setValue( it, COLUMN_TEXT, value ); - store.setValue( it, COLUMN_TEXT_VISIBLE, !isBoolean ); - store.setValue( it, COLUMN_BOOL, value == "true" ); - store.setValue( it, COLUMN_BOOL_VISIBLE, isBoolean ); - store.setValue( it, COLUMN_TEXT_COLOR_RGBA, rgba ); - store.setValue( it, COLUMN_TEXT_COLOR, color ); - store.setValue( it, COLUMN_TEXT_FONT_DESCRIPTION, new PgFontDescription() ); +class DemoMultiCellRenderer : ApplicationWindow +{ + this(Application application) + { + super(application); + setTitle("Celleditor Demo"); + + ListStore store = new ListStore( [ + GType.STRING, + GType.STRING, + GType.INT, + GType.INT, + GType.INT, + RGBA.getType(), + ] ); + + void appendRecord( string name, string value, bool isBoolean, RGBA rgba){ + auto it = store.createIter(); + store.setValue( it, COLUMN_NAME, name ); + store.setValue( it, COLUMN_TEXT, value ); + store.setValue( it, COLUMN_TEXT_VISIBLE, !isBoolean ); + store.setValue( it, COLUMN_BOOL, value == "true" ); + store.setValue( it, COLUMN_BOOL_VISIBLE, isBoolean ); + store.setValue( it, COLUMN_TEXT_COLOR_RGBA, rgba ); + } + // fill store with data + appendRecord( "Loops", "10", false, new RGBA(1.0,0.0,0.0,1.0) ); + appendRecord( "Name", "keinfarbton", false, new RGBA(0.0,1.0,0.0,1.0) ); + appendRecord( "Verbose", "true", true, new RGBA(0.0,0.0,1.0,1.0) ); + + auto tv = new TreeView(); + setChild(tv); + + // create first column with text renderer + TreeViewColumn column = new TreeViewColumn(); + column.setTitle( "Name" ); + tv.appendColumn(column); + + CellRendererText cell_text = new CellRendererText(); + column.packStart(cell_text, 0 ); + column.addAttribute(cell_text, "text", COLUMN_NAME); + column.addAttribute(cell_text, "foreground-rgba", COLUMN_TEXT_COLOR_RGBA); + + // create second column with two renderers + column = new TreeViewColumn(); + column.setTitle( "Value" ); + tv.appendColumn(column); + + CellRendererToggle cell_bool = new CellRendererToggle(); + column.packStart(cell_bool, 0 ); + column.addAttribute(cell_bool, "active", COLUMN_BOOL); + column.addAttribute(cell_bool, "visible", COLUMN_BOOL_VISIBLE); + + cell_text = new CellRendererText(); + column.packStart(cell_text, 0 ); + column.addAttribute(cell_text, "text", COLUMN_TEXT); + column.addAttribute(cell_text, "visible", COLUMN_TEXT_VISIBLE); + cell_text.setProperty( "editable", 1 ); + + // change value in store on toggle event + cell_bool.addOnToggled( delegate void(string p, CellRendererToggle){ + auto path = new TreePath( p ); + TreeIter it; + store.getIter(it, path); + store.setValue(it, COLUMN_BOOL, store.getValue!int(it, COLUMN_BOOL) ? 0 : 1 ); + }); + + // change the text in the store on end of edit + cell_text.addOnEdited( delegate void(string p, string v, CellRendererText cell ){ + auto path = new TreePath( p ); + TreeIter it; + store.getIter(it, path); + store.setValue( it, COLUMN_TEXT, v ); + }); + + tv.setModel(store); + show(); } - // fill store with data - appendRecord( "Loops", "10", false, new RGBA(1.0,0.0,0.0,1.0), new Color(64,64,64) ); - appendRecord( "Name", "keinfarbton", false, new RGBA(0.0,1.0,0.0,1.0), new Color(127,127,127) ); - appendRecord( "Verbose", "true", true, new RGBA(0.0,0.0,1.0,1.0), new Color(200,200,200) ); - - auto wnd = new Window( "Celleditor Demo" ); - auto tv = new TreeView(); - wnd.add(tv); - - // create first column with text renderer - TreeViewColumn column = new TreeViewColumn(); - column.setTitle( "Name" ); - tv.appendColumn(column); - - CellRendererText cell_text = new CellRendererText(); - column.packStart(cell_text, 0 ); - column.addAttribute(cell_text, "text", COLUMN_NAME); - column.addAttribute(cell_text, "background-gdk", COLUMN_TEXT_COLOR); - column.addAttribute(cell_text, "foreground-rgba", COLUMN_TEXT_COLOR_RGBA); - - // create second column with two renderers - column = new TreeViewColumn(); - column.setTitle( "Value" ); - tv.appendColumn(column); - - CellRendererToggle cell_bool = new CellRendererToggle(); - column.packStart(cell_bool, 0 ); - column.addAttribute(cell_bool, "active", COLUMN_BOOL); - column.addAttribute(cell_bool, "visible", COLUMN_BOOL_VISIBLE); - - cell_text = new CellRendererText(); - column.packStart(cell_text, 0 ); - column.addAttribute(cell_text, "text", COLUMN_TEXT); - column.addAttribute(cell_text, "visible", COLUMN_TEXT_VISIBLE); - cell_text.setProperty( "editable", 1 ); - - // change value in store on toggle event - cell_bool.addOnToggled( delegate void(string p, CellRendererToggle){ - auto path = new TreePath( p ); - auto it = new TreeIter( store, path ); - store.setValue(it, COLUMN_BOOL, it.getValueInt( COLUMN_BOOL ) ? 0 : 1 ); - - auto val = store.getValue(it, COLUMN_TEXT_FONT_DESCRIPTION); - - import gobject.Type; - - writeln(Type.isA(PgFontDescription.getType(), GType.BOXED)); - writeln(PgFontDescription.getType(), " ", val.gType); - - auto font = val.get!PgFontDescription(); - - writeln(font.getFamily()); - }); - - // change the text in the store on end of edit - cell_text.addOnEdited( delegate void(string p, string v, CellRendererText cell ){ - auto path = new TreePath( p ); - auto it = new TreeIter( store, path ); - store.setValue( it, COLUMN_TEXT, v ); - }); - - tv.setModel(store); - wnd.showAll(); - - wnd.addOnDelete( delegate bool (Event event, Widget widget) { - widget.destroy(); - Main.quit(); - return false; - }); - - Main.run(); } + +int main(string[] args) +{ + auto application = new Application("org.gtkd.demo.multicellrenderer", GApplicationFlags.FLAGS_NONE); + application.addOnActivate(delegate void(_) { new DemoMultiCellRenderer(application); }); + return application.run(args); +} diff --git a/generated/gtkd/gdk/RGBA.d b/generated/gtkd/gdk/RGBA.d index ad1bcaf5f..dc6b84da6 100644 --- a/generated/gtkd/gdk/RGBA.d +++ b/generated/gtkd/gdk/RGBA.d @@ -71,6 +71,32 @@ public final class RGBA gdk_rgba_free(gdkRGBA); } + /** + * Creates a new RGBA Color + */ + this() + { + GdkRGBA rgba = GdkRGBA(0, 0, 0, 0); + + this(gdk_rgba_copy(&rgba), true); + } + + /** ditto */ + this(double red, double green, double blue, double alpha = 1.0) + { + GdkRGBA rgba; + + rgba.red = red; + rgba.green = green; + rgba.blue = blue; + rgba.alpha = alpha; + + this(gdk_rgba_copy(&rgba), true); + } + + + /** + */ /** * The intensity of the red channel from 0.0 to 1.0 inclusive diff --git a/generated/gtkd/gtk/Dialog.d b/generated/gtkd/gtk/Dialog.d index db0985648..40b6aa591 100644 --- a/generated/gtkd/gtk/Dialog.d +++ b/generated/gtkd/gtk/Dialog.d @@ -38,18 +38,30 @@ private import std.algorithm; /** - * Dialog boxes are a convenient way to prompt the user for a small amount + * Dialogs are a convenient way to prompt the user for a small amount * of input, e.g. to display a message, ask a question, or anything else * that does not require extensive effort on the user’s part. * - * GTK treats a dialog as a window split vertically. The top section is a - * #GtkBox, and is where widgets such as a #GtkLabel or a #GtkEntry should - * be packed. The bottom area is known as the - * “action area”. This is generally used for - * packing buttons into the dialog which may perform functions such as - * cancel, ok, or apply. + * The main area of a GtkDialog is called the "content area", and is yours + * to populate with widgets such a #GtkLabel or #GtkEntry, to present + * your information, questions, or tasks to the user. In addition, dialogs + * allow you to add "action widgets". Most commonly, action widgets are + * buttons. Depending on the platform, action widgets may be presented + * in the header bar at the top of the window, or at the bottom of the window. + * To add action widgets, use GtkDialog using gtk_dialog_new_with_buttons(), + * gtk_dialog_add_button(), gtk_dialog_add_buttons(), or + * gtk_dialog_add_action_widget(). + * + * Clicking a button that was added as an action widget will emit the + * #GtkDialog::response signal with a response ID that you specified. + * GTK will never assign a meaning to positive response IDs; these are + * entirely user-defined. But for convenience, you can use the response + * IDs in the #GtkResponseType enumeration (these all have values less + * than zero). If a dialog receives a delete event, the + * #GtkDialog::response signal will be emitted with the + * #GTK_RESPONSE_DELETE_EVENT response ID. * - * #GtkDialog boxes are created with a call to gtk_dialog_new() or + * Dialogs are created with a call to gtk_dialog_new() or * gtk_dialog_new_with_buttons(). gtk_dialog_new_with_buttons() is * recommended; it allows you to set the dialog title, some convenient * flags, and add simple buttons. @@ -60,20 +72,9 @@ private import std.algorithm; * gtk_dialog_new() into a #GtkWindow. When using gtk_dialog_new_with_buttons() * you can also pass the #GTK_DIALOG_MODAL flag to make a dialog modal. * - * If you add buttons to #GtkDialog using gtk_dialog_new_with_buttons(), - * gtk_dialog_add_button(), gtk_dialog_add_buttons(), or - * gtk_dialog_add_action_widget(), clicking the button will emit a signal - * called #GtkDialog::response with a response ID that you specified. GTK - * will never assign a meaning to positive response IDs; these are entirely - * user-defined. But for convenience, you can use the response IDs in the - * #GtkResponseType enumeration (these all have values less than zero). If - * a dialog receives a delete event, the #GtkDialog::response signal will - * be emitted with a response ID of #GTK_RESPONSE_DELETE_EVENT. - * - * For the simple dialog in the following example, in reality you’d probably - * use #GtkMessageDialog to save yourself some effort. But you’d need to - * create the dialog contents manually if you had more than a simple message - * in the dialog. + * For the simple dialog in the following example, a #GtkMessageDialog would + * save some effort. But you’d need to create the dialog contents manually if + * you had more than a simple message in the dialog. * * An example for simple GtkDialog usage: * |[ @@ -112,8 +113,7 @@ private import std.algorithm; * # GtkDialog as GtkBuildable * * The GtkDialog implementation of the #GtkBuildable interface exposes the - * @content_area and @action_area as internal children with the names - * “content_area” and “action_area”. + * @content_area as an internal child with the name “content_area”. * * GtkDialog supports a custom element, which can contain * multiple elements. The “response” attribute specifies a diff --git a/generated/gtkd/gtk/Entry.d b/generated/gtkd/gtk/Entry.d index fba81424f..712d2947a 100644 --- a/generated/gtkd/gtk/Entry.d +++ b/generated/gtkd/gtk/Entry.d @@ -942,7 +942,6 @@ public class Entry : Widget, CellEditableIF, EditableIF * * This is equivalent to getting @entry's #GtkEntryBuffer and * calling gtk_entry_buffer_set_max_length() on it. - * ]| * * Params: * max = the maximum length of the entry, or 0 for no maximum. diff --git a/generated/gtkd/gtk/FileChooserNative.d b/generated/gtkd/gtk/FileChooserNative.d index 8c3213416..b5e1c07d8 100644 --- a/generated/gtkd/gtk/FileChooserNative.d +++ b/generated/gtkd/gtk/FileChooserNative.d @@ -53,6 +53,11 @@ public import gtk.c.types; * Showing, hiding and running the dialog is handled by the #GtkNativeDialog * functions. * + * Note that unlike #GtkFileChooserDialog, #GtkFileChooserNative objects are + * not toplevel widgets, and GTK does not keep them alive. It is your + * responsibility to keep a reference until you are done with the + * object. + * * ## Typical usage ## {#gtkfilechoosernative-typical-usage} * * In the simplest of cases, you can the following code to use diff --git a/generated/gtkd/gtk/ListStore.d b/generated/gtkd/gtk/ListStore.d index 46bc6b3f3..b38dbff40 100644 --- a/generated/gtkd/gtk/ListStore.d +++ b/generated/gtkd/gtk/ListStore.d @@ -223,6 +223,26 @@ public class ListStore : ObjectG, BuildableIF, TreeDragDestIF, TreeDragSourceIF, // add the TreeSortable capabilities mixin TreeSortableT!(GtkListStore); + /** + * Creates a top level iteractor. + * I don't think lists have but the top level iteractor + */ + TreeIter createIter() + { + GtkTreeIter* iter = new GtkTreeIter; + gtk_list_store_append(getListStoreStruct(), iter); + return new TreeIter(iter); + } + + /** */ + void setValue(TYPE)(TreeIter iter, int column, TYPE value) + { + Value v = new Value(value); + gtk_list_store_set_value(gtkListStore, iter.getTreeIterStruct(), column, v.getValueStruct()); + } + + /** + */ /** */ public static GType getType() diff --git a/generated/gtkd/gtk/NativeDialog.d b/generated/gtkd/gtk/NativeDialog.d index 054352673..aea7d4e8d 100644 --- a/generated/gtkd/gtk/NativeDialog.d +++ b/generated/gtkd/gtk/NativeDialog.d @@ -45,6 +45,11 @@ private import std.algorithm; * various common properties on the dialog, as well as show and hide * it and get a #GtkNativeDialog::response signal when the user finished * with the dialog. + * + * Note that unlike #GtkDialog, #GtkNativeDialog objects are not + * toplevel widgets, and GTK does not keep them alive. It is your + * responsibility to keep a reference until you are done with the + * object. */ public class NativeDialog : ObjectG { diff --git a/generated/gtkd/gtk/PopoverMenu.d b/generated/gtkd/gtk/PopoverMenu.d index 20188788b..7ce6720a4 100644 --- a/generated/gtkd/gtk/PopoverMenu.d +++ b/generated/gtkd/gtk/PopoverMenu.d @@ -55,7 +55,7 @@ public import gtk.c.types; * ``, you can use `` or `
` * elements. * - * |[ + * |[ * *
* diff --git a/generated/gtkd/gtk/SearchBar.d b/generated/gtkd/gtk/SearchBar.d index 99968854c..7493a5c3e 100644 --- a/generated/gtkd/gtk/SearchBar.d +++ b/generated/gtkd/gtk/SearchBar.d @@ -50,6 +50,10 @@ public import gtk.c.types; * The following example shows you how to create a more complex search * entry. * + * ## Creating a search bar + * + * [A simple example](https://gitlab.gnome.org/GNOME/gtk/tree/master/examples/search-bar.c) + * * # CSS nodes * * |[ @@ -65,10 +69,6 @@ public import gtk.c.types; * CSS node of the child widget as well as an optional button node which gets the .close * style class applied. * - * ## Creating a search bar - * - * [A simple example](https://gitlab.gnome.org/GNOME/gtk/tree/master/examples/search-bar.c) - * * # Accessibility * * GtkSearchBar uses the %GTK_ACCESSIBLE_ROLE_SEARCH role. diff --git a/generated/gtkd/gtk/TreeModelT.d b/generated/gtkd/gtk/TreeModelT.d index 3a52b65a0..be4c6bcc5 100644 --- a/generated/gtkd/gtk/TreeModelT.d +++ b/generated/gtkd/gtk/TreeModelT.d @@ -243,6 +243,17 @@ public template TreeModelT(TStruct) return cast(GtkTreeModel*)getStruct(); } + /** */ + public T getValue(T)(TreeIter iter, int column) + { + Value val; + getValue(iter, column, val); + + return val.get!T(); + } + + /** + */ /** * Creates a new #GtkTreeModel, with @child_model as the child_model diff --git a/generated/gtkd/gtk/Widget.d b/generated/gtkd/gtk/Widget.d index 23a77103e..1de887992 100644 --- a/generated/gtkd/gtk/Widget.d +++ b/generated/gtkd/gtk/Widget.d @@ -228,7 +228,7 @@ private import std.algorithm; * If the parent widget uses a #GtkLayoutManager, #GtkWidget supports a * custom `` element, used to define layout properties: * - * |[ + * |[ * * * @@ -256,7 +256,8 @@ private import std.algorithm; * * GtkWidget allows style information such as style classes to * be associated with widgets, using the custom `