/*
 ============================================================================
 Name        : textEditorGTK.c
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in GTK+
 ============================================================================
 */

#include <gtk/gtk.h>
#include "string.h"


static void changeFontToCss(GtkButton* button,GtkWidget *clearButton){
	GtkRequisition * requisition = gtk_requisition_new();
	GtkStyleContext * context = gtk_widget_get_style_context (clearButton);
	gtk_widget_get_preferred_size (clearButton,NULL,requisition);
	printf("requisition is %d x %d\n", requisition->width, requisition->height);
	char * css = "* {font-family: Cantarell; font-size: 50pt}";
	GtkCssProvider * provider = gtk_css_provider_new();
	gtk_css_provider_load_from_data (provider, css, -1, NULL);
	gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
	GtkRequisition * requisition2 = gtk_requisition_new();
	g_object_unref(provider);
	gtk_widget_get_preferred_size (clearButton,NULL,requisition2);
	printf("new requisition is %d x %d\n", requisition2->width, requisition2->height);
}


int main(int argc, char *argv[]) {

  GtkWidget *window;
  GtkWidget *vbox;
  GtkWidget *clearButton;

  GtkWidget *textbox;
  GtkTextBuffer *buffer;
  GtkWidget *scrolledWindow;

  GtkWidget *buttons;


  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size(GTK_WINDOW(window), 600, 400);
  gtk_window_set_title(GTK_WINDOW(window), "Bug");

  vbox = gtk_vbox_new(FALSE, 0);
  gtk_container_add(GTK_CONTAINER(window), vbox);


  textbox = gtk_text_view_new();
  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textbox));
  gtk_text_buffer_set_text (buffer, "Hello", -1);
  scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
  gtk_container_add(GTK_CONTAINER(scrolledWindow), textbox);

  clearButton = gtk_button_new_with_label ("Clear Text");
  buttons = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
  gtk_button_box_set_layout (buttons,GTK_BUTTONBOX_END);
  gtk_container_add(GTK_CONTAINER(buttons), clearButton);

  gtk_box_pack_start(GTK_BOX(vbox), scrolledWindow, TRUE, TRUE, TRUE);
  gtk_box_pack_start(GTK_BOX(vbox), buttons, FALSE, FALSE, 0);


  g_signal_connect(G_OBJECT(window), "destroy",
        G_CALLBACK(gtk_main_quit), NULL);

  g_signal_connect(G_OBJECT(clearButton), "clicked",
        G_CALLBACK(changeFontToCss), clearButton);

  gtk_widget_show_all(window);
  gtk_main();
  return 0;
}



