The idea is simple, I am writing a php extension that displays a window with two buttons using gtkmm. "upload" and "cancel". Immediately make a reservation with c ++ just a few days as I met, and then the prototype code (it works)

/** * run preview window * @param param * @return string "upload" | "cancel" */ Php::Value GtkPhp::preview(Php::Parameters &param) { int argc = 0; char **argv = NULL; char *file = nullptr; std::string fileSrc = param[0]; file = new char[fileSrc.size() + 1]; std::copy(fileSrc.begin(), fileSrc.end(), file); file[fileSrc.size()] = '\0'; Php::Value srcPic = param[0]; auto app = Gtk::Application::create(argc, argv, "org.gtkmm.gtkphp7"); auto refBuilder = Gtk::Builder::create(); try { refBuilder->add_from_file("picview.glade"); } catch(const Glib::FileError& ex) { std::cerr << "FileError: " << ex.what() << std::endl; } catch(const Gtk::BuilderError& ex) { std::cerr << "BuilderError: " << ex.what() << std::endl; } refBuilder->get_widget("window1",mainWindow); // preview picture Gtk::Image *image = nullptr; refBuilder->get_widget("preview",image); // button ok click Gtk::Button *buttonUpload = nullptr; refBuilder->get_widget("upload",buttonUpload); buttonUpload->signal_clicked().connect( sigc::ptr_fun(&GtkPhp::uploadClick) ); // button cancel click Gtk::Button *buttonCancel = nullptr; refBuilder->get_widget("cancel",buttonCancel); buttonCancel->signal_clicked().connect( sigc::ptr_fun(&GtkPhp::cancelClick)); image->set(file); app->run(*mainWindow); if(statusUpload == 1) { return "upload"; } else { return "cancel"; } } 

When the button is pressed, the callback functions are processed.

 /** * callback upload button */ void GtkPhp::uploadClick() { statusUpload = 1; delete mainWindow; } /** * callback cancel button */ void GtkPhp::cancelClick() { statusCancel = 1; delete mainWindow; } 

where the variables are global

 int statusUpload = 0; int statusCancel = 0; Gtk::Window *mainWindow = nullptr; 

php test file looks like this

 <?php $gtk = new GtkPhp(); $chose = $gtk->preview("/tmp/1475441471960_screen.png"); var_dump($chose); 

This code generates a preview of the image and displays with the two buttons upload and cancel by pressing the button in the chose variable is written either 'upload' or 'chose'. Actually the question is how to avoid global variables?

    0