Skip to content

Commit

Permalink
Added type of tree model to retrieve correct type of store
Browse files Browse the repository at this point in the history
  • Loading branch information
scorninpc committed Jul 21, 2019
1 parent 6a1074e commit b23dc6e
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 1,086 deletions.
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ extern "C"
gdkpixbuf.method<&GdkPixbuf_::new_from_file>("new_from_file");
gdkpixbuf.method<&GdkPixbuf_::new_from_file_at_size>("new_from_file_at_size");
gdkpixbuf.method<&GdkPixbuf_::new_from_file_at_scale>("new_from_file_at_scale");
gdkpixbuf.method<&GdkPixbuf_::new_from_gd>("new_from_gd");
gdkpixbuf.method<&GdkPixbuf_::get_file_info>("get_file_info");
gdkpixbuf.method<&GdkPixbuf_::get_colorspace>("get_colorspace");
gdkpixbuf.method<&GdkPixbuf_::get_n_channels>("get_n_channels");
Expand Down
22 changes: 22 additions & 0 deletions src/GdkPixbuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,28 @@ Php::Value GdkPixbuf_::new_from_file(Php::Parameters &parameters)
return Php::Object("GdkPixbuf", pixbuf_);
}

Php::Value GdkPixbuf_::new_from_gd(Php::Parameters &parameters)
{
Php::Value a = parameters[0];
if (!a.instanceOf("gd")) throw Php::Exception("Not a GD resource");
Php::call("var_dump", "OK1");
Php::call("imagepng", a.implementation());
Php::call("var_dump", "OK2");
return 1;

std::string filename = parameters[0];

// Create pixbuff
GdkPixbuf *l_pixbuf = gdk_pixbuf_new_from_file(filename.c_str(), NULL);

// Create the PHP-GTK object and set GTK object
GdkPixbuf_ *pixbuf_ = new GdkPixbuf_();
pixbuf_->set_instance(l_pixbuf);

// Return PHP-GTK object
return Php::Object("GdkPixbuf", pixbuf_);
}

Php::Value GdkPixbuf_::new_from_file_at_size(Php::Parameters &parameters)
{
std::string filename = parameters[0];
Expand Down
1 change: 1 addition & 0 deletions src/GdkPixbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
* https://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-File-Loading.html#gdk-pixbuf-new-from-file
*/
static Php::Value new_from_file(Php::Parameters &parameters);
static Php::Value new_from_gd(Php::Parameters &parameters);

static Php::Value new_from_file_at_size(Php::Parameters &parameters);

Expand Down
53 changes: 40 additions & 13 deletions src/GtkComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GtkComboBox_::~GtkComboBox_() = default;
void GtkComboBox_::__construct()
{
instance = (gpointer *)gtk_combo_box_new ();

liststore_type = false;
}

Php::Value GtkComboBox_::new_with_entry()
Expand All @@ -37,15 +37,23 @@ Php::Value GtkComboBox_::new_with_model(Php::Parameters &parameters)

GtkComboBox_ *phpgtk_combobox = new GtkComboBox_();
phpgtk_combobox->set_instance((gpointer *)combobox);

// Store the Model type
phpgtk_combobox->liststore_type = false;
if(object_model.instanceOf("GtkListStore")) {
phpgtk_combobox->liststore_type = true;
}

return Php::Object("GtkComboBox", phpgtk_combobox);

}

Php::Value GtkComboBox_::new_with_model_and_entry(Php::Parameters &parameters)
{
GtkTreeModel *model;
Php::Value object_model;
if(parameters.size() > 0) {
Php::Value object_model = parameters[0];
object_model = parameters[0];
GtkTreeModel_ *phpgtk_model = (GtkTreeModel_ *)object_model.implementation();
model = phpgtk_model->get_model();
}
Expand All @@ -54,6 +62,13 @@ Php::Value GtkComboBox_::new_with_model_and_entry(Php::Parameters &parameters)

GtkComboBox_ *phpgtk_combobox = new GtkComboBox_();
phpgtk_combobox->set_instance((gpointer *)combobox);

// Store the Model type
phpgtk_combobox->liststore_type = false;
if(object_model.instanceOf("GtkListStore")) {
phpgtk_combobox->liststore_type = true;
}

return Php::Object("GtkComboBox", phpgtk_combobox);
}

Expand Down Expand Up @@ -210,18 +225,30 @@ Php::Value GtkComboBox_::get_model()

GtkTreeModel_ *return_parsed = new GtkTreeModel_();
return_parsed->set_model(ret);
return Php::Object("GtkTreeModel", return_parsed);

if(liststore_type) {
return Php::Object("GtkListStore", return_parsed);
}

return Php::Object("GtkTreeStore", return_parsed);
}

void GtkComboBox_::set_model(Php::Parameters &parameters)
{
GtkTreeModel *model;
Php::Value object_model;
if(parameters.size() > 0) {
Php::Value object_model = parameters[0];
object_model = parameters[0];
GtkTreeModel_ *phpgtk_model = (GtkTreeModel_ *)object_model.implementation();
model = phpgtk_model->get_model();
}

// Store the Model type
liststore_type = false;
if(object_model.instanceOf("GtkListStore")) {
liststore_type = true;
}

gtk_combo_box_set_model (GTK_COMBO_BOX(instance), model);

}
Expand Down Expand Up @@ -348,9 +375,9 @@ void GtkComboBox_::set_popup_fixed_width(Php::Parameters &parameters)
void GtkComboBox_::pack_start(Php::Parameters &parameters)
{
Php::Value object = parameters[0];
GtkCellRenderer_ *passedRenderer = (GtkCellRenderer_ *)object.implementation();
GtkCellRenderer_ *passedRenderer = (GtkCellRenderer_ *)object.implementation();

gboolean expand = parameters[1];
gboolean expand = parameters[1];

gtk_cell_layout_pack_start (GTK_CELL_LAYOUT(instance), GTK_CELL_RENDERER(passedRenderer->get_instance()), expand);

Expand All @@ -359,9 +386,9 @@ void GtkComboBox_::pack_start(Php::Parameters &parameters)
void GtkComboBox_::pack_end(Php::Parameters &parameters)
{
Php::Value object = parameters[0];
GtkCellRenderer_ *passedRenderer = (GtkCellRenderer_ *)object.implementation();
GtkCellRenderer_ *passedRenderer = (GtkCellRenderer_ *)object.implementation();

gboolean expand = parameters[1];
gboolean expand = parameters[1];

gtk_cell_layout_pack_end (GTK_CELL_LAYOUT(instance), GTK_CELL_RENDERER(passedRenderer->get_instance()), expand);

Expand All @@ -370,9 +397,9 @@ void GtkComboBox_::pack_end(Php::Parameters &parameters)
void GtkComboBox_::reorder(Php::Parameters &parameters)
{
Php::Value object = parameters[0];
GtkCellRenderer_ *passedRenderer = (GtkCellRenderer_ *)object.implementation();
GtkCellRenderer_ *passedRenderer = (GtkCellRenderer_ *)object.implementation();

gint position = parameters[1];
gint position = parameters[1];

gtk_cell_layout_reorder (GTK_CELL_LAYOUT(instance), GTK_CELL_RENDERER(passedRenderer->get_instance()), position);
}
Expand All @@ -385,11 +412,11 @@ void GtkComboBox_::clear(Php::Parameters &parameters)
void GtkComboBox_::add_attribute(Php::Parameters &parameters)
{
Php::Value object = parameters[0];
GtkCellRenderer_ *passedRenderer = (GtkCellRenderer_ *)object.implementation();
GtkCellRenderer_ *passedRenderer = (GtkCellRenderer_ *)object.implementation();

std::string atribute = parameters[1];
std::string atribute = parameters[1];

gint column = (int)parameters[2];
gint column = (int)parameters[2];

gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT(instance), GTK_CELL_RENDERER(passedRenderer->get_instance()), atribute.c_str(), column);
}
2 changes: 2 additions & 0 deletions src/GtkComboBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
public:

bool liststore_type;

/**
* C++ constructor and destructor
*/
Expand Down
23 changes: 17 additions & 6 deletions src/GtkEntryCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ void GtkEntryCompletion_::__construct()
{
instance = (gpointer *)gtk_entry_completion_new ();

liststore_type = false;

}

Php::Value GtkEntryCompletion_::new_with_area()
Expand All @@ -39,11 +41,15 @@ Php::Value GtkEntryCompletion_::get_entry()
void GtkEntryCompletion_::set_model(Php::Parameters &parameters)
{
GtkTreeModel *model;
if(parameters.size() > 0) {
Php::Value object_model = parameters[0];
GtkTreeModel_ *phpgtk_model = (GtkTreeModel_ *)object_model.implementation();
model = phpgtk_model->get_model();
}
Php::Value object_model = parameters[0];
GtkTreeModel_ *phpgtk_model = (GtkTreeModel_ *)object_model.implementation();
model = phpgtk_model->get_model();

// Store the Model type
liststore_type = false;
if(object_model.instanceOf("GtkListStore")) {
liststore_type = true;
}

gtk_entry_completion_set_model (GTK_ENTRY_COMPLETION(instance), model);

Expand All @@ -55,7 +61,12 @@ Php::Value GtkEntryCompletion_::get_model()

GtkTreeModel_ *return_parsed = new GtkTreeModel_();
return_parsed->set_model(ret);
return Php::Object("GtkTreeModel", return_parsed);

if(liststore_type) {
return Php::Object("GtkListStore", return_parsed);
}

return Php::Object("GtkTreeStore", return_parsed);
}

void GtkEntryCompletion_::set_match_func(Php::Parameters &parameters)
Expand Down
2 changes: 2 additions & 0 deletions src/GtkEntryCompletion.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/
public:

bool liststore_type;

/**
* C++ constructor and destructor
*/
Expand Down
Loading

0 comments on commit b23dc6e

Please sign in to comment.