Re: open new window



On 7/2/07, brad smith <bradleydsmith gmail com> wrote:
I am trying to open a new window(that has a text view widget) from a
button on the main window. I have looked for examples but could not
find any.(or maybe I just do not know what I am looking for)

I had this lying around. You'll need to add the text window to the popup.

/* compile with
*      gcc try8.c `pkg-config gtk+-2.0 --cflags --libs`
*/

#include <gtk/gtk.h>

int nums[3] = { 0, 1, 2 };

void
doDialogue (GtkButton * but, int *action)
{
 static GtkWidget *dialogue;
 GtkWidget *button;

 switch (*action)
   {
   case 0:                     // make and realize dialogue widget
     if (!dialogue)
       {
         dialogue = gtk_window_new (GTK_WINDOW_TOPLEVEL);
         gtk_window_set_transient_for (GTK_WINDOW (dialogue),
           GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (but))));
         gtk_window_set_position (GTK_WINDOW (dialogue),
           GTK_WIN_POS_CENTER_ON_PARENT);
         g_signal_connect (dialogue, "destroy", G_CALLBACK (doDialogue),
                           &nums[2]);
         button = gtk_button_new_with_label ("Cancel");
         g_signal_connect ((button), "clicked", G_CALLBACK (doDialogue),
                           &nums[1]);
         gtk_container_add (GTK_CONTAINER (dialogue), button);
         gtk_widget_show_all (dialogue);
       }
     gtk_widget_show (dialogue);
     break;

   case 1:                     // hide the dialogue
     gtk_widget_hide (dialogue);
     break;

   case 2:                     // dialogue has been destroyed, record
     dialogue = NULL;
     break;
   }
}

int
main (int argc, char **argv)
{
 GtkWidget *mainWin, *button;

 gtk_init (&argc, &argv);
 mainWin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 g_signal_connect (mainWin, "destroy", G_CALLBACK (gtk_main_quit), NULL);
 button = gtk_button_new_with_label ("Dialogue");
 g_signal_connect ((button), "clicked", G_CALLBACK (doDialogue), &nums[0]);
 gtk_container_add (GTK_CONTAINER (mainWin), button);

 gtk_window_set_default_size ( GTK_WINDOW (mainWin), 250, 250);
 gtk_widget_show_all (mainWin);

 gtk_main ();
}



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