#include <gtk/gtk.h>

GQuark quark_test = 0;

void initialize_quark()
{
  if(!quark_test)
  {
    g_warning("initializing quark.");
    quark_test = g_quark_from_static_string("quarktestmurrayc");
  }
}

class VBox
{
private:
  GtkVBox* myVBox;

public:
  VBox(GtkVBox* inVBox)
    : myVBox(inVBox)
  {
    //Set a quark and a callback:
    initialize_quark();
    int a = 0;
    g_object_set_qdata_full((GObject*)inVBox, quark_test, &a, &on_object_qdata_destroyed);
    
    g_warning("refcount: %d\n", ((GObject*)inVBox)->ref_count);
    
    //Set a normal destroy notification callback.
    g_signal_connect(G_OBJECT(inVBox), "destroy",
		     G_CALLBACK(on_object_destroyed), 0);
    
    g_warning("refcount: %d\n", ((GObject*)inVBox)->ref_count);
    g_object_ref(inVBox);
  }

  ~VBox()
  {
  }

  static void on_object_destroyed(GObject* object, gpointer data)
  {
    g_warning("on_object_destroyed():  c instance=%10X", object);
    g_warning("refcount: %d\n", ((GObject*)object)->ref_count);
    g_object_unref(object);
  }
  
  static void on_object_qdata_destroyed(gpointer data)
  {
    g_warning("on_object_qdata_destroyed():  c instance=%10X", data);
  }
};

int main(int argc, char**argv)
{
  gtk_init(&argc, &argv);

  GtkDialog* object = (GtkDialog*) gtk_dialog_new();

  VBox *pVBox = new VBox( (GtkVBox*) object->vbox);

  //This causes on_object_destroyed() to be called
  gtk_widget_destroy( (GtkWidget*)object );

  return 0;
}



