SHARE
TWEET

Untitled

a guest Jul 21st, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <gtk/gtk.h>
  2.  
  3. GtkWidget *scrolled_window;
  4.  
  5. void addTimer(GtkWidget *widget, gpointer data)
  6. {
  7.     GObject *mainBox;
  8.     GtkWidget *timer;
  9.     GtkWidget *btn;
  10.     timer = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3);
  11.  
  12.     btn = gtk_button_new_with_label("gtk_box_pack");
  13.  
  14.     gtk_container_add (GTK_CONTAINER (scrolled_window), (GtkWidget *)data);
  15.  
  16.     gtk_box_pack_start((GtkBox *)data, btn, TRUE, TRUE, 3);
  17.     gtk_widget_show(btn);
  18.  
  19.     g_print("New thing should be added...\n");
  20. }
  21.  
  22. int main(int argc, char **argv)
  23. {
  24.     GtkBuilder *builder;
  25.     GtkWidget *window;
  26.     GObject *button;
  27.     GtkWidget *mainBox;
  28.     GtkWidget *header;
  29.     GtkWidget *btn;
  30.     GError *error = NULL;
  31.  
  32.     gtk_init(&argc, &argv);
  33.  
  34.     // add header:
  35.     header = gtk_header_bar_new();
  36.     gtk_header_bar_set_title(GTK_HEADER_BAR(header), "Timers");
  37.  
  38.     /* Construct a GtkBuilder instance and load our UI description */
  39.     builder = gtk_builder_new();
  40.  
  41.     if (gtk_builder_add_from_file(builder, "timers.glade", &error) == 0)
  42.     {
  43.         g_printerr("Error loading file: %s\n", error->message);
  44.         g_clear_error(&error);
  45.         return 1;
  46.     }
  47.  
  48.     btn = gtk_button_new_with_label("+ New Timer");
  49.  
  50.     window = (GtkWidget *)gtk_builder_get_object(builder, "window");
  51.  
  52.     scrolled_window = gtk_scrolled_window_new(NULL, NULL);
  53.  
  54.     gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 10);
  55.  
  56.     mainBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
  57.  
  58.     /* And add it to the scrolled window */
  59.     gtk_container_add (GTK_CONTAINER (scrolled_window), mainBox);
  60.  
  61.     gtk_header_bar_pack_start(GTK_HEADER_BAR(header), btn);
  62.  
  63.     gtk_window_set_titlebar (GTK_WINDOW(window), header);
  64.  
  65.     //gtk_box_pack_start((GtkBox *)mainBox, header, FALSE, TRUE, 3);
  66.  
  67.     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
  68.                                   GTK_POLICY_AUTOMATIC,
  69.                                   GTK_POLICY_AUTOMATIC);
  70.  
  71.     gtk_container_add(GTK_CONTAINER(window), scrolled_window);
  72.  
  73.     g_signal_connect(window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
  74.  
  75.     gtk_widget_show_all(window);
  76.  
  77.     g_signal_connect(btn, "clicked", G_CALLBACK(addTimer), mainBox);
  78.  
  79.     gtk_main();
  80.  
  81.     return 0;
  82. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top