GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Dec 22, 2014 6:27 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Dialog!!!!
PostPosted: Thu Sep 06, 2007 10:02 am 
Offline
Familiar Face

Joined: Fri May 25, 2007 8:36 am
Posts: 13
Location: Iran
I write a program in which when user click on the main window button a dialog is displayed . on the dialog is a button I want both dialogue and main window destroy when user press dialogue button I write following code but is dosent work what is the problem?

Code:
#include <gtk/gtk.h>
GtkWidget *window;
gint delete_event(GtkWidget *widget,GdkEvent *event,gpointer data)
{

gtk_main_quit();
return FALSE;
}

void hi(GtkWidget *widget , gpointer data)
{
GtkWidget *win;
GtkWidget *label;
label=gtk_label_new("MAN GTK RO DOST DARAM");
gtk_window_set_transient_for(GTK_WINDOW(win),GTK_WINDOW(window));
win=gtk_dialog_new_with_buttons("WELCOME",GTK_WINDOW(window),GTK_DIALOG_DESTROY_WITH_PARENT,"yes",-5,NULL);

gtk_container_add(GTK_CONTAINER(GTK_DIALOG(win)->vbox),label);
gtk_window_set_destroy_with_parent(GTK_WINDOW(window),TRUE);
gtk_widget_show(label);
int as=gtk_dialog_run(GTK_DIALOG(win));
if (as==-5){

gtk_widget_destroy(win);
}
}
int main(int argc , char *argv[])
{
gtk_init(&argc,&argv);

GtkWidget *button;
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
button=gtk_button_new_with_label("_SHOW DIALOG");
gtk_container_add(GTK_CONTAINER(window),button);
g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(hi),NULL);

g_signal_connect(G_OBJECT(window),"delete-event",G_CALLBACK(delete_event),NULL);

gtk_widget_show(window);
gtk_widget_show(button);
gtk_main();
return 0;
}


And the second question GTK_DIALOG_MODAL is what kind of dialogue ? is it possible for you to show a form of this dialogue for me? :( ...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 06, 2007 5:53 pm 
Offline
Familiar Face

Joined: Fri May 25, 2007 8:36 am
Posts: 13
Location: Iran
:?: :( ...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 10, 2007 5:03 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Using GTK_DIALOG_MODAL allows you to control whether or not the dialog is modal. A modal dialog stays above it's aparent window, only one instance can be created, and "disables" the user's ability to click in the parent window until they have clicked one of the dialogs buttons.

To kill you parent window, kill it in the function which is evaluating the dialog's response.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 10, 2007 5:05 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
By the way, Andrew's book Foundations of GTK+ Programming has a whole chapter on using dialogs.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 11, 2007 2:15 am 
Offline

Joined: Tue Sep 04, 2007 3:51 am
Posts: 2
Try this way!

Code:
#include <gtk/gtk.h>
GtkWidget *window;
gint delete_event(GtkWidget *widget,GdkEvent *event,gpointer data)
{
   gtk_main_quit();
   return FALSE;
}

void
re(GtkDialog *dialog, gint arg, gpointer data)
{
   gtk_widget_hide(GTK_WIDGET(dialog));
   gtk_main_quit();
}

void hi(GtkWidget *widget , gpointer data)
{
   GtkWidget *win;
   GtkWidget *label;
   label=gtk_label_new("MAN GTK RO DOST DARAM");
   win=gtk_dialog_new_with_buttons("WELCOME",GTK_WINDOW(window),GTK_DIALOG_DESTROY_WITH_PARENT,"yes",-5,NULL);
   gtk_window_set_transient_for(GTK_WINDOW(win),GTK_WINDOW(window));

   gtk_container_add(GTK_CONTAINER(GTK_DIALOG(win)->vbox),label);
   gtk_window_set_destroy_with_parent(GTK_WINDOW(win),TRUE);
   g_signal_connect(win,"response",G_CALLBACK(re), NULL);
   gtk_widget_show(label);
   gtk_widget_show(win);
}
int main(int argc , char *argv[])
{
   gtk_init(&argc,&argv);

   GtkWidget *button;
   window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
   button=gtk_button_new_with_label("_SHOW DIALOG");
   gtk_container_add(GTK_CONTAINER(window),button);
   g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(hi),NULL);

   g_signal_connect(G_OBJECT(window),"delete-event",G_CALLBACK(delete_event),NULL);

   gtk_widget_show(window);
   gtk_widget_show(button);
   gtk_main();
   return 0;
}


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] 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