GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Dialog!!!!

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
hamid206
Familiar Face


Joined: 25 May 2007
Posts: 12

PostPosted: Thu Sep 06, 2007 10:02 am    Post subject: Dialog!!!! Reply with quote

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: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

#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? :( ...
Back to top
hamid206
Familiar Face


Joined: 25 May 2007
Posts: 12

PostPosted: Thu Sep 06, 2007 5:53 pm    Post subject: Reply with quote

:?: :( ...
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 496
Location: Portland, OR USA

PostPosted: Mon Sep 10, 2007 5:03 pm    Post subject: Reply with quote

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.
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 496
Location: Portland, OR USA

PostPosted: Mon Sep 10, 2007 5:05 pm    Post subject: Reply with quote

By the way, Andrew's book Foundations of GTK+ Programming has a whole chapter on using dialogs.
Back to top
iltgcl



Joined: 04 Sep 2007
Posts: 2

PostPosted: Tue Sep 11, 2007 2:15 am    Post subject: Reply with quote

Try this way!

Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

#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;
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP