Fwd: new window from button

Ok, time to get back on the list

Brad, here's the example Matias intended to show you (the mailing list ate
the attachment it seems)

</quote who="Matias">
This is how I compile test.c
gcc -Wall `pkg-config --cflags gtk+-2.0` -o test test.c `pkg-config --libs

---------- Forwarded message ----------
From: Matí­as Alejandro Torres <torresmat gmail com>
Date: Jul 3, 2007 4:20 PM
Subject: Re: new window from button
To: Jonathan Winterflood <jonathan winterflood gmail com>

Ok, sorry about that.

#include <stdlib.h>
#include <gtk/gtk.h>

button_clicked_cb (GtkWidget *button, GtkWindow *parent)
   static GtkWidget *cbwindow = NULL;

   if (!cbwindow)
   /* Windows has not been created yet */
       GtkWidget *text_view;

       text_view = gtk_text_view_new ();
       gtk_widget_set_size_request (text_view, 200, 150);

       cbwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_window_set_title (GTK_WINDOW (cbwindow), "Callback window");
       gtk_window_set_transient_for (GTK_WINDOW (cbwindow), parent);
       gtk_container_add (GTK_CONTAINER (cbwindow), text_view);
       gtk_container_set_border_width (GTK_CONTAINER (cbwindow), 12);

   gtk_widget_show_all (cbwindow);

main (gint argc, gchar **argv)
   GtkWidget *window;
   GtkWidget *button;

   gtk_init (&argc, &argv);

   button = gtk_button_new_from_stock (GTK_STOCK_OPEN);

   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title (GTK_WINDOW (window), "Main window");
   gtk_container_add (GTK_CONTAINER (window), button);
   gtk_container_set_border_width (GTK_CONTAINER (window), 12);

   /* We connect the signal clicked to a callback function that will
create the window.
    * The Main window is passed to that function (last argument).
   g_signal_connect (G_OBJECT (button), "clicked", (GCallback)
button_clicked_cb, window);
   /* We connect the signal delete_event of the Main window so that
    * the program exits when Main window is clicked.
   g_signal_connect (G_OBJECT (window), "delete-event", (GCallback)
gtk_main_quit, NULL);

   gtk_widget_show_all (window);

   gtk_main ();

   return 0;

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]