How can I embed a Gtk::Plug in a Gtk Socket?

347 Views Asked by At

I have I window. In this window I want two buttons. One will be a plug and the other is just normal.

I do the following

plug.cc

#include <gtkmm.h>
#include <gtkmm/plug.h>

class PlugButton : public Gtk::Plug{
public:
    PlugButton(){add(button); id = get_id();}
    int id;
    Gtk::Button button{"Plug Button"};
}  

main.cc

Gtk::HBox box;
Gtk::Button button{"Normal Button"};
Gtk::Socket socket;// I have included gtkmm/socket.h
PlugButton plug;
box.pack_start(button);
box.pack_end(socket);
socket.add_id(plug.id);
window.add(box);
window.show_all_children();

This compiles but I get

gtk_socket_add_id: assertion '_gtk_widget_get_anchored (GTK_WIDGET (socket))' failed

How can I embed the instance of Gtk::Plug in the socket?

1

There are 1 best solutions below

0
On

As written in documentation:

The GtkSocket must have already be added into a toplevel window before you can make this call.

So your code should be:

window.add(box);
socket.add_id(plug.id);