#include <hildon/hildon.h>

/* This is a callback function. The data arguments are ignored in this example.
 * We'll create 3 functions which will be triggered by 3 different buttons. 
 * g_print will suffice for this, just imagine debugging using `print $var` :)
 */
static void oh_kay (GtkWidget *widget,
                    gpointer data)
{
  g_print ("Oh.Kay!!\n");
}

static void oh_noes (GtkWidget *widget,
                     gpointer data)
{
 g_print ("Oh Noes~~\n");
}

static void omgwtflol (GtkWidget *widget, 
                       gpointer data )
{
 g_print ("Oh Am Gee Double You Tea Aft Lawl\n");
}

/* Main. program control starts here */
int main (int argc, char **argv)
{
  /* Declare all the necessary widgets first
   * for this example - 3 buttons, one vBox, one hBox, and the window
   */
  HildonProgram *program;
  GtkWidget *window;
  GtkBox *vBox0;
  GtkBox *hBox1;
  GtkWidget *btn_ok;
  GtkWidget *btn_oh_noes;
  GtkWidget *btn_omgwtflol;

  /* This is called in all Hildon applications. Arguments are parsed
   * from the command line and are returned to the application. */
  hildon_gtk_init (&argc, &argv);

  /* Get an instance of HildonProgram. It is an object used to represent
   * an application running in the Hildon framework.
   */
  program = hildon_program_get_instance ();
  /* create a new hildon window */
  window = hildon_window_new ();
  /* Registers a window as belonging to the program */
  hildon_program_add_window (program, HILDON_WINDOW (window));
  /* When the window is given the "delete_event" signal 
   *  (this is given by the window manager, 
   *   usually by the "close" option, or on the titlebar), 
   * we ask it to call the delete_event () function
   */
  g_signal_connect (G_OBJECT (window), "delete_event",
                    G_CALLBACK (gtk_main_quit), NULL);

  /* Create three new hildon buttons
   * set the Size of all to "auto"
   * connect each button to relevant functions above 
   */
  
  /* == create btn_ok , connect to the callback "ok_kay" ==*/
  btn_ok = hildon_button_new_with_text (HILDON_SIZE_AUTO,
                                        HILDON_BUTTON_ARRANGEMENT_VERTICAL,
                                        "Oh.Kay~",
                                        NULL);
  g_signal_connect (G_OBJECT (btn_ok),
                    "clicked",
                    G_CALLBACK (oh_kay),
                    NULL);
                    
  /* == create btn_oh_noes, connect to callback "oh_noes"==*/
  btn_oh_noes = hildon_button_new_with_text (HILDON_SIZE_AUTO,
                                             HILDON_BUTTON_ARRANGEMENT_VERTICAL,
                                             "Oh.Noes~",
                                             NULL);
  g_signal_connect (G_OBJECT (btn_oh_noes),
                    "clicked",
                    G_CALLBACK (oh_noes),
                    NULL);

  /*== create btn_omgwtflol, handled by callback 'omgwtflol' ==*/
  btn_omgwtflol = hildon_button_new_with_text (HILDON_SIZE_AUTO,
                                               HILDON_BUTTON_ARRANGEMENT_VERTICAL,
                                               "Oh.Am.Gee~",
                                               NULL);
  g_signal_connect (G_OBJECT (btn_omgwtflol) , 
                    "clicked" ,
                    G_CALLBACK (omgwtflol) ,
                    NULL );
 
  /* the buttons have been created and connected to the callbacks that 
   * will handle their "clicked" event, 
   * so now we'll arrange the button widgets into the screen 
   * There will be 2 rows.
   * 2 buttons - 'btn_oh_noes' and 'btn_omgwtflol' will be created in one row, 
   * 1 button - btn_ok will be in another one row
   * for the 2 buttons to be placed in ONE row, it has to first be placed in a hBox, 
   * the hBox and btn_ok will both be added to the vBox
   */

  /* design from the top-down, build from the bottom up.
   * since the hBox will be packed into the vBox, it is considered 'lower'
   * and therefore will be built first
   */
  hBox1 = GTK_BOX (gtk_hbox_new (FALSE , 10) ) ;
  gtk_box_pack_start (hBox1 , GTK_WIDGET(btn_oh_noes) , TRUE , TRUE , 0) ; 
  gtk_box_pack_start (hBox1 , GTK_WIDGET(btn_omgwtflol) , TRUE , TRUE , 0) ; 
  /* The hBox is conplete, now shift focus to the vBox
   * create the vBox and add the vidgets into it
   */
  vBox0 = GTK_BOX (gtk_vbox_new (FALSE , 10) ) ;
  gtk_box_pack_start (vBox0 , GTK_WIDGET(btn_ok) , TRUE , TRUE , 0) ; 
  gtk_box_pack_start (vBox0 , GTK_WIDGET(hBox1) , TRUE , TRUE , 0) ; 
  /* The widgets have been setup, now add the one widget to the window
   * Remember that you can only add ONE widget to a window
   */
  gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET(vBox0));
  
  /* The final step is to display this newly created widget
   * and all widgets it contains.
   */
  gtk_widget_show_all (GTK_WIDGET (window));

  /* All GTK+ applications must have a gtk_main(). Control ends here
   * and waits for an event to occur (like a key press or
   * mouse event).
   */
  gtk_main ();

  return 0;
}


