#include <gtkmm.h>
#include <iostream>

class MyWindow : public Gtk::Window
{
public:
  MyWindow()
  : Gtk::Window()
  {
    Gtk::Button* button = Gtk::manage(new Gtk::Button("Click"));
    button->signal_clicked().connect(sigc::mem_fun(*this, &MyWindow::o_s_c));
    set_border_width(10);
    add(*button);
    button->show();
  }
protected:
  void o_s_c()
  {
    const char* color_property = "link-color";
    const char* border_property = "draw-border";

    // C version
    // Getting GdkColor - returns NULL, but works anyway.
    GtkWidget* c_widget = GTK_WIDGET(gobj());
    GdkColor* c_color = NULL;
    gtk_widget_style_get(c_widget, color_property, &c_color, NULL);
    if (c_color)
    {
      gchar* str = gdk_color_to_string(c_color);
      std::cout << "C color: " << str << std::endl;
      g_free(str);
      gdk_color_free(c_color);
    }
    else
    {
      std::cout << "C color: NULL" << std::endl;
    }
    // Getting GtkBorder - returns NULL, but works anyway.
    GtkBorder* c_border = NULL;
    gtk_widget_style_get(c_widget, border_property, &c_border, NULL);
    if (c_border)
    {
      std::cout << "C border (l;r;t;b): " << c_border->left << "; " <<
        c_border->right << "; " << c_border->top << "; " << c_border->bottom <<
        std::endl;
      gtk_border_free(c_border);
    }
    else
    {
      std::cout << "C border (l;r;t;b): NULL" << std::endl;
    }
    
    // C++ version
    // Getting Gdk::Color - warns about NULL and stuff, but works anyway.
    Gdk::Color cpp_color;
    get_style_property(color_property, cpp_color);
    std::cout << "C++ color: " << cpp_color.to_string() << std::endl;
    // Getting Gtk::Border - fails.
    Gtk::Border cpp_border;
    get_style_property(border_property, cpp_border);
    std::cout << "C++ border (l;r;t;b): " << cpp_border.left << "; " <<
      cpp_border.right << "; " << cpp_border.top << "; " <<
      cpp_border.bottom << std::endl;
  }
};

int main(int argc, char** argv)
{
  Gtk::Main kit(argc, argv);
  MyWindow win;
  Gtk::Main::run(win);
}
