From 3139e8ec61e086e9b864652f4631027988624a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20P=2E=20Gon=C3=A7alves?= Date: Tue, 11 Jun 2019 22:41:53 -0300 Subject: [PATCH] Added GtkComboBoxText and GtkAppChooserButton. Some changes with parent NULL on dialogs --- Objects.md | 4 +- main.cpp | 33 ++++++++++ main.h | 3 + src/GtkAppChooserButton.cpp | 97 +++++++++++++++++++++++++++++ src/GtkAppChooserButton.h | 49 +++++++++++++++ src/GtkComboBoxText.cpp | 116 +++++++++++++++++++++++++++++++++++ src/GtkComboBoxText.h | 52 ++++++++++++++++ src/GtkDialog.cpp | 4 +- src/GtkFileChooserDialog.cpp | 2 +- src/GtkMessageDialog.cpp | 4 +- 10 files changed, 357 insertions(+), 7 deletions(-) create mode 100644 src/GtkAppChooserButton.cpp create mode 100644 src/GtkAppChooserButton.h create mode 100644 src/GtkComboBoxText.cpp create mode 100644 src/GtkComboBoxText.h diff --git a/Objects.md b/Objects.md index 1bb6557..25e9fa7 100644 --- a/Objects.md +++ b/Objects.md @@ -31,8 +31,8 @@ _GObject │ │ │ │ ├── *GtkActionBar │ │ │ │ ├── GtkAlignment │ │ │ │ ├── #GtkComboBox - │ │ │ │ │ ├── GtkAppChooserButton - │ │ │ │ │ ╰── GtkComboBoxText + │ │ │ │ │ ├── #GtkAppChooserButton + │ │ │ │ │ ╰── *GtkComboBoxText │ │ │ │ ├── *GtkFrame │ │ │ │ │ ╰── *GtkAspectFrame │ │ │ │ ├── #GtkButton diff --git a/main.cpp b/main.cpp index aa2d463..b4f236e 100644 --- a/main.cpp +++ b/main.cpp @@ -1772,6 +1772,37 @@ extern "C" gtkcombobox.method<&GtkComboBox_::add_attribute>("add_attribute"); + // GtkComboBoxText + Php::Class gtkcomboboxtext("GtkComboBoxText"); + gtkcomboboxtext.extends(gtkcombobox); + gtkcomboboxtext.method<&GtkComboBoxText_::__construct>("__construct"); + gtkcomboboxtext.method<&GtkComboBoxText_::new_with_entry>("new_with_entry"); + gtkcomboboxtext.method<&GtkComboBoxText_::append>("append"); + gtkcomboboxtext.method<&GtkComboBoxText_::prepend>("prepend"); + gtkcomboboxtext.method<&GtkComboBoxText_::insert>("insert"); + gtkcomboboxtext.method<&GtkComboBoxText_::append_text>("append_text"); + gtkcomboboxtext.method<&GtkComboBoxText_::prepend_text>("prepend_text"); + gtkcomboboxtext.method<&GtkComboBoxText_::insert_text>("insert_text"); + gtkcomboboxtext.method<&GtkComboBoxText_::remove>("remove"); + gtkcomboboxtext.method<&GtkComboBoxText_::remove_all>("remove_all"); + gtkcomboboxtext.method<&GtkComboBoxText_::get_active_text>("get_active_text"); + + + // GtkAppChooserButton + Php::Class gtkappchooserbutton("GtkAppChooserButton"); + gtkappchooserbutton.extends(gtkcombobox); + gtkappchooserbutton.method<&GtkAppChooserButton_::__construct>("__construct"); + gtkappchooserbutton.method<&GtkAppChooserButton_::append_custom_item>("append_custom_item"); + gtkappchooserbutton.method<&GtkAppChooserButton_::append_separator>("append_separator"); + gtkappchooserbutton.method<&GtkAppChooserButton_::set_active_custom_item>("set_active_custom_item"); + gtkappchooserbutton.method<&GtkAppChooserButton_::get_show_default_item>("get_show_default_item"); + gtkappchooserbutton.method<&GtkAppChooserButton_::set_show_default_item>("set_show_default_item"); + gtkappchooserbutton.method<&GtkAppChooserButton_::get_show_dialog_item>("get_show_dialog_item"); + gtkappchooserbutton.method<&GtkAppChooserButton_::set_show_dialog_item>("set_show_dialog_item"); + gtkappchooserbutton.method<&GtkAppChooserButton_::get_heading>("get_heading"); + gtkappchooserbutton.method<&GtkAppChooserButton_::set_heading>("set_heading"); + + // GtkBuilder Php::Class gtkbuilder("GtkBuilder"); gtkbuilder.extends(gobject); @@ -2413,6 +2444,8 @@ extern "C" extension.add(std::move(gtksensitivitytype)); extension.add(std::move(gtkcombobox)); + extension.add(std::move(gtkcomboboxtext)); + extension.add(std::move(gtkappchooserbutton)); extension.add(std::move(gtkbuilder)); diff --git a/main.h b/main.h index 4761660..1e0da0f 100644 --- a/main.h +++ b/main.h @@ -133,6 +133,8 @@ #include "src/GtkSensitivityType.h" #include "src/GtkComboBox.h" + #include "src/GtkComboBoxText.h" + #include "src/GtkAppChooserButton.h" #include "src/GtkBuilder.h" @@ -184,6 +186,7 @@ #include "src/GtkCalendarDisplayOptions.h" #include "src/GtkCalendar.h" + GValue phpgtk_get_gvalue(Php::Value phpgtk_value, GType type_column); diff --git a/src/GtkAppChooserButton.cpp b/src/GtkAppChooserButton.cpp new file mode 100644 index 0000000..77a256c --- /dev/null +++ b/src/GtkAppChooserButton.cpp @@ -0,0 +1,97 @@ + +#include "GtkAppChooserButton.h" + +/** + * Constructor + */ +GtkAppChooserButton_::GtkAppChooserButton_() = default; + +/** + * Destructor + */ +GtkAppChooserButton_::~GtkAppChooserButton_() = default; + +void GtkAppChooserButton_::__construct(Php::Parameters ¶meters) +{ + std::string s_content_type = parameters[0]; + gchar *content_type = (gchar *)s_content_type.c_str(); + + instance = (gpointer *)gtk_app_chooser_button_new (content_type); +} + +void GtkAppChooserButton_::append_custom_item(Php::Parameters ¶meters) +{ + // std::string s_name = parameters[0]; + // gchar *name = (gchar *)s_name.c_str(); + + // std::string s_label = parameters[1]; + // gchar *label = (gchar *)s_label.c_str(); + + + // gtk_app_chooser_button_append_custom_item (GTK_APP_CHOOSER_BUTTON(instance), name, label, icon); + + throw Php::Exception("GtkAppChooserButton_::append_custom_item not implemented"); + +} + +void GtkAppChooserButton_::append_separator() +{ + gtk_app_chooser_button_append_separator (GTK_APP_CHOOSER_BUTTON(instance)); + +} + +void GtkAppChooserButton_::set_active_custom_item(Php::Parameters ¶meters) +{ + std::string s_name = parameters[0]; + gchar *name = (gchar *)s_name.c_str(); + + gtk_app_chooser_button_set_active_custom_item (GTK_APP_CHOOSER_BUTTON(instance), name); + +} + +Php::Value GtkAppChooserButton_::get_show_default_item() +{ + gboolean ret = gtk_app_chooser_button_get_show_default_item (GTK_APP_CHOOSER_BUTTON(instance)); + + return ret; +} + +void GtkAppChooserButton_::set_show_default_item(Php::Parameters ¶meters) +{ + gboolean setting = (gboolean)parameters[0]; + + gtk_app_chooser_button_set_show_default_item (GTK_APP_CHOOSER_BUTTON(instance), setting); + +} + +Php::Value GtkAppChooserButton_::get_show_dialog_item() +{ + gboolean ret = gtk_app_chooser_button_get_show_dialog_item (GTK_APP_CHOOSER_BUTTON(instance)); + + return ret; +} + +void GtkAppChooserButton_::set_show_dialog_item(Php::Parameters ¶meters) +{ + gboolean setting = (gboolean)parameters[0]; + + gtk_app_chooser_button_set_show_dialog_item (GTK_APP_CHOOSER_BUTTON(instance), setting); + +} + +Php::Value GtkAppChooserButton_::get_heading() +{ + std::string ret = gtk_app_chooser_button_get_heading (GTK_APP_CHOOSER_BUTTON(instance)); + + return ret; +} + +void GtkAppChooserButton_::set_heading(Php::Parameters ¶meters) +{ + std::string s_heading = parameters[0]; + gchar *heading = (gchar *)s_heading.c_str(); + + gtk_app_chooser_button_set_heading (GTK_APP_CHOOSER_BUTTON(instance), heading); + +} + diff --git a/src/GtkAppChooserButton.h b/src/GtkAppChooserButton.h new file mode 100644 index 0000000..fa62b3c --- /dev/null +++ b/src/GtkAppChooserButton.h @@ -0,0 +1,49 @@ + +#ifndef _PHPGTK_GTKAPPCHOOSERBUTTON_H_ +#define _PHPGTK_GTKAPPCHOOSERBUTTON_H_ + + #include + #include + + #include "GtkComboBox.h" + + /** + * GtkAppChooserButton_ + * + * https://developer.gnome.org/gtk3/stable/GtkAppChooserButton.html + */ + class GtkAppChooserButton_ : public GtkComboBox_ + { + /** + * Publics + */ + public: + + /** + * C++ constructor and destructor + */ + GtkAppChooserButton_(); + ~GtkAppChooserButton_(); + + void __construct(Php::Parameters ¶meters); + + void append_custom_item(Php::Parameters ¶meters); + + void append_separator(); + + void set_active_custom_item(Php::Parameters ¶meters); + + Php::Value get_show_default_item(); + + void set_show_default_item(Php::Parameters ¶meters); + + Php::Value get_show_dialog_item(); + + void set_show_dialog_item(Php::Parameters ¶meters); + + Php::Value get_heading(); + + void set_heading(Php::Parameters ¶meters); + }; + +#endif diff --git a/src/GtkComboBoxText.cpp b/src/GtkComboBoxText.cpp new file mode 100644 index 0000000..7287d8f --- /dev/null +++ b/src/GtkComboBoxText.cpp @@ -0,0 +1,116 @@ + +#include "GtkComboBoxText.h" + +/** + * Constructor + */ +GtkComboBoxText_::GtkComboBoxText_() = default; + +/** + * Destructor + */ +GtkComboBoxText_::~GtkComboBoxText_() = default; + +void GtkComboBoxText_::__construct() +{ + instance = (gpointer *)gtk_combo_box_text_new (); + +} + +Php::Value GtkComboBoxText_::new_with_entry() +{ + GtkWidget *ret = gtk_combo_box_text_new_with_entry (); + + GtkComboBoxText_ *return_parsed = new GtkComboBoxText_(); + return_parsed->set_instance((gpointer *)ret); + return Php::Object("GtkComboBoxText", return_parsed); +} + +void GtkComboBoxText_::append(Php::Parameters ¶meters) +{ + std::string s_id = parameters[0]; + gchar *id = (gchar *)s_id.c_str(); + + std::string s_text = parameters[1]; + gchar *text = (gchar *)s_text.c_str(); + + gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(instance), id, text); + +} + +void GtkComboBoxText_::prepend(Php::Parameters ¶meters) +{ + std::string s_id = parameters[0]; + gchar *id = (gchar *)s_id.c_str(); + + std::string s_text = parameters[1]; + gchar *text = (gchar *)s_text.c_str(); + + gtk_combo_box_text_prepend (GTK_COMBO_BOX_TEXT(instance), id, text); + +} + +void GtkComboBoxText_::insert(Php::Parameters ¶meters) +{ + gint position = (gint)parameters[0]; + + std::string s_id = parameters[1]; + gchar *id = (gchar *)s_id.c_str(); + + std::string s_text = parameters[2]; + gchar *text = (gchar *)s_text.c_str(); + + gtk_combo_box_text_insert (GTK_COMBO_BOX_TEXT(instance), position, id, text); + +} + +void GtkComboBoxText_::append_text(Php::Parameters ¶meters) +{ + std::string s_text = parameters[0]; + gchar *text = (gchar *)s_text.c_str(); + + gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT(instance), text); + +} + +void GtkComboBoxText_::prepend_text(Php::Parameters ¶meters) +{ + std::string s_text = parameters[0]; + gchar *text = (gchar *)s_text.c_str(); + + gtk_combo_box_text_prepend_text (GTK_COMBO_BOX_TEXT(instance), text); + +} + +void GtkComboBoxText_::insert_text(Php::Parameters ¶meters) +{ + gint position = (gint)parameters[0]; + + std::string s_text = parameters[1]; + gchar *text = (gchar *)s_text.c_str(); + + gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT(instance), position, text); + +} + +void GtkComboBoxText_::remove(Php::Parameters ¶meters) +{ + gint position = (gint)parameters[0]; + + gtk_combo_box_text_remove (GTK_COMBO_BOX_TEXT(instance), position); + +} + +void GtkComboBoxText_::remove_all() +{ + gtk_combo_box_text_remove_all (GTK_COMBO_BOX_TEXT(instance)); + +} + +Php::Value GtkComboBoxText_::get_active_text() +{ + std::string ret = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT(instance)); + + return ret; +} + diff --git a/src/GtkComboBoxText.h b/src/GtkComboBoxText.h new file mode 100644 index 0000000..7f090ef --- /dev/null +++ b/src/GtkComboBoxText.h @@ -0,0 +1,52 @@ + +#ifndef _PHPGTK_GTKCOMBOBOXTEXT_H_ +#define _PHPGTK_GTKCOMBOBOXTEXT_H_ + + #include + #include + + #include "GtkComboBox.h" + #include "GtkWidget.h" + + /** + * GtkComboBoxText_ + * + * https://developer.gnome.org/gtk3/stable/GtkComboBoxText.html + */ + class GtkComboBoxText_ : public GtkComboBox_ + { + /** + * Publics + */ + public: + + /** + * C++ constructor and destructor + */ + GtkComboBoxText_(); + ~GtkComboBoxText_(); + + void __construct(); + + static Php::Value new_with_entry(); + + void append(Php::Parameters ¶meters); + + void prepend(Php::Parameters ¶meters); + + void insert(Php::Parameters ¶meters); + + void append_text(Php::Parameters ¶meters); + + void prepend_text(Php::Parameters ¶meters); + + void insert_text(Php::Parameters ¶meters); + + void remove(Php::Parameters ¶meters); + + void remove_all(); + + Php::Value get_active_text(); + }; + +#endif diff --git a/src/GtkDialog.cpp b/src/GtkDialog.cpp index 3850095..6b853f3 100644 --- a/src/GtkDialog.cpp +++ b/src/GtkDialog.cpp @@ -25,7 +25,7 @@ Php::Value GtkDialog_::new_with_buttons(Php::Parameters ¶meters) gchar *title = (gchar *)s_title.c_str(); Php::Value object_parent = parameters[1]; - GtkWindow *parent; + GtkWindow *parent = NULL; if (object_parent.instanceOf("GtkWindow")) { GtkWindow_ *phpgtk_parent = (GtkWindow_ *)object_parent.implementation(); parent = GTK_WINDOW(phpgtk_parent->get_instance()); @@ -39,7 +39,7 @@ Php::Value GtkDialog_::new_with_buttons(Php::Parameters ¶meters) throw Php::Exception("parameters expect one button with response"); } - GtkWidget *instance_dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(parent), flags, arr[0], (int)arr[1], NULL); + GtkWidget *instance_dialog = gtk_dialog_new_with_buttons(title, parent, flags, arr[0], (int)arr[1], NULL); // Add buttons for(int index=2; index < (int)arr.size(); index+=2) { diff --git a/src/GtkFileChooserDialog.cpp b/src/GtkFileChooserDialog.cpp index 4930652..8d73547 100644 --- a/src/GtkFileChooserDialog.cpp +++ b/src/GtkFileChooserDialog.cpp @@ -17,7 +17,7 @@ void GtkFileChooserDialog_::__construct(Php::Parameters ¶meters) gchar *title = (gchar *)s_title.c_str(); Php::Value object_parent = parameters[1]; - GtkWindow *parent; + GtkWindow *parent = NULL; if (object_parent.instanceOf("GtkWindow")) { GtkWindow_ *phpgtk_parent = (GtkWindow_ *)object_parent.implementation(); parent = GTK_WINDOW(phpgtk_parent->get_instance()); diff --git a/src/GtkMessageDialog.cpp b/src/GtkMessageDialog.cpp index c599417..d9c419e 100644 --- a/src/GtkMessageDialog.cpp +++ b/src/GtkMessageDialog.cpp @@ -14,7 +14,7 @@ GtkMessageDialog_::~GtkMessageDialog_() = default; void GtkMessageDialog_::__construct(Php::Parameters ¶meters) { Php::Value object_parent = parameters[0]; - GtkWindow *parent; + GtkWindow *parent = NULL; if (object_parent.instanceOf("GtkWindow")) { GtkWindow_ *phpgtk_parent = (GtkWindow_ *)object_parent.implementation(); parent = GTK_WINDOW(phpgtk_parent->get_instance()); @@ -48,7 +48,7 @@ Php::Value GtkMessageDialog_::new_with_markup(Php::Parameters ¶meters) GtkMessageDialog_ *messagedialog = new GtkMessageDialog_(); Php::Value object_parent = parameters[0]; - GtkWindow *parent; + GtkWindow *parent = NULL; if (object_parent.instanceOf("GtkWindow")) { GtkWindow_ *phpgtk_parent = (GtkWindow_ *)object_parent.implementation(); parent = GTK_WINDOW(phpgtk_parent->get_instance());