GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Oct 22, 2014 10:25 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Close window when new appears
PostPosted: Thu Apr 05, 2012 1:06 pm 
Offline
Familiar Face

Joined: Thu Feb 09, 2012 9:20 pm
Posts: 5
Hi to everyone!

I am writing an application where GUI will be presented by 1 main and several child windows. User will be able to choose program modes in the main window and then pass in new one.

Could somebody suggest me how can I make disappear parent window when child appears? I made child to appear through callback function, but I do not know how to close main window through callback.

Here is example which looks like my GUI:

Code:

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

static void begin_mode (GtkWidget *widget, gpointer data)
{
  start_child_1 ();
  return 0;
}

start_child_1 ()
{
  GtkWidget *window = NULL;
  GtkWidget *vbox = NULL;

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_size_request (window, 400, 450);
  gtk_window_set_title (GTK_WINDOW (window), "Child_1");
  gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
  gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
  gtk_widget_realize (window);
  g_signal_connect (window, "destroy", gtk_main_quit, NULL);
  gtk_widget_show (window);

  return 0;
}

int main (int argc, char *argv[])
{
  GtkWidget *button = NULL;
  GtkWidget *window = NULL;
  GtkWidget *vbox = NULL;
  GtkWidget *alignment = NULL;

   /*Initialize GTK+ */
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
  gtk_init (&argc, &argv);
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_size_request (window, 400, 450);
  gtk_window_set_title (GTK_WINDOW (window), "Parent");
  gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
  gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
  gtk_widget_realize (window);
  g_signal_connect (window, "destroy", gtk_main_quit, NULL);

  /*Create a main vertical box */
  vbox = gtk_vbox_new (TRUE, 0);
  gtk_container_add (GTK_CONTAINER (window), vbox);

  /*Creates "Next" button and connects it with select function*/

  alignment = gtk_alignment_new (0.9, 0.35, 0.11, 0.15);
  gtk_box_pack_start (GTK_BOX (vbox), alignment, TRUE, TRUE, 0);//!
  gtk_widget_show (alignment);

  button = gtk_button_new_with_label ("Next");
  g_signal_connect (button, "clicked", G_CALLBACK (begin_mode), NULL);
  gtk_container_add (GTK_CONTAINER (alignment), button);
  gtk_widget_show (button);

  gtk_widget_show (vbox);
  gtk_widget_show (window);

  /* Enter the main loop */
  gtk_main ();
  return 0;
}


Last edited by Morningstar on Thu Apr 05, 2012 5:48 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Close window when new appears
PostPosted: Thu Apr 05, 2012 5:23 pm 
Offline
Familiar Face

Joined: Thu Feb 09, 2012 9:20 pm
Posts: 5
I got answer myself:)

Code:
//I used second callback function which is launched before child window function.
static void main_close ( GtkWidget *widget,
                     gpointer   window )
{
    gtk_widget_hide (window);
}

//these strings is written after button declaration which launches child window
g_signal_connect (button, "clicked", G_CALLBACK (main_close), window);
g_signal_connect (button, "clicked", G_CALLBACK (begin_mode), NULL);


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group