|
Packit |
1470ea |
|
|
Packit |
1470ea |
<page xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:xi="http://www.w3.org/2001/XInclude" type="guide" style="task" id="dialog.c" xml:lang="de">
|
|
Packit |
1470ea |
<info>
|
|
Packit |
1470ea |
<title type="text">Dialog (C)</title>
|
|
Packit |
1470ea |
<link type="guide" xref="c#windows"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="label.c"/>
|
|
Packit |
1470ea |
<link type="seealso" xref="button.c"/>
|
|
Packit |
1470ea |
<revision version="0.1" date="2012-06-14" status="draft"/>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<credit type="author copyright">
|
|
Packit |
1470ea |
<name>Monica Kochofar</name>
|
|
Packit |
1470ea |
<email its:translate="no">monicakochofar@gmail.com</email>
|
|
Packit |
1470ea |
<years>2012</years>
|
|
Packit |
1470ea |
</credit>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<desc>A popup window</desc>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
|
|
Packit |
1470ea |
<mal:name>Mario Blättermann</mal:name>
|
|
Packit |
1470ea |
<mal:email>mario.blaettermann@gmail.com</mal:email>
|
|
Packit |
1470ea |
<mal:years>2011, 2013</mal:years>
|
|
Packit |
1470ea |
</mal:credit>
|
|
Packit |
1470ea |
</info>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<title>Dialog</title>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<media type="image" mime="image/png" src="media/dialog.png"/>
|
|
Packit |
1470ea |
A dialog window that pops up when a button is pressed.
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
#include <gtk/gtk.h>
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Callback function in which reacts to the "response" signal. Be sure to place
|
|
Packit |
1470ea |
it before the function it is called in*/
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
on_response (GtkDialog *dialog,
|
|
Packit |
1470ea |
gint response_id,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
/*For demonstration purposes, this will show the int value
|
|
Packit |
1470ea |
of the response type*/
|
|
Packit |
1470ea |
g_print ("response is %d\n", response_id);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*This will cause the dialog to be destroyed*/
|
|
Packit |
1470ea |
gtk_widget_destroy (GTK_WIDGET (dialog));
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Callback function in which reacts to the "clicked" signal*/
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
show_dialog (GtkButton *button,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkWindow *window = user_data;
|
|
Packit |
1470ea |
GtkWidget *dialog;
|
|
Packit |
1470ea |
GtkWidget *content_area;
|
|
Packit |
1470ea |
GtkWidget *label;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
gint response_id;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Create the dialog window. Modal windows prevent interaction with other
|
|
Packit |
1470ea |
windows in the same application*/
|
|
Packit |
1470ea |
dialog = gtk_dialog_new_with_buttons ("A Gtk+ Dialog",
|
|
Packit |
1470ea |
window,
|
|
Packit |
1470ea |
GTK_DIALOG_MODAL,
|
|
Packit |
1470ea |
GTK_STOCK_OK,
|
|
Packit |
1470ea |
GTK_RESPONSE_OK,
|
|
Packit |
1470ea |
NULL);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Create a label and attach it to the content area of the dialog*/
|
|
Packit |
1470ea |
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
|
|
Packit |
1470ea |
label = gtk_label_new ("This demonstrates a dialog with a label");
|
|
Packit |
1470ea |
gtk_container_add (GTK_CONTAINER (content_area), label);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*The main purpose of this is to show dialog's child widget, label*/
|
|
Packit |
1470ea |
gtk_widget_show_all (dialog);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Connecting the "response" signal from the user to the associated
|
|
Packit |
1470ea |
callback function*/
|
|
Packit |
1470ea |
g_signal_connect (GTK_DIALOG (dialog),
|
|
Packit |
1470ea |
"response",
|
|
Packit |
1470ea |
G_CALLBACK (on_response),
|
|
Packit |
1470ea |
NULL);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
static void
|
|
Packit |
1470ea |
activate (GtkApplication *app,
|
|
Packit |
1470ea |
gpointer user_data)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkWidget *window;
|
|
Packit |
1470ea |
GtkWidget *button;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Create a window with a title and a default size*/
|
|
Packit |
1470ea |
window = gtk_application_window_new (app);
|
|
Packit |
1470ea |
gtk_window_set_title (GTK_WINDOW (window), "GNOME Button");
|
|
Packit |
1470ea |
gtk_window_set_default_size (GTK_WINDOW (window), 250, 50);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Create a button with a label, and add it to the window*/
|
|
Packit |
1470ea |
button = gtk_button_new_with_label ("Click Me");
|
|
Packit |
1470ea |
gtk_container_add (GTK_CONTAINER (window), button);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
/*Connecting the clicked signal to the callback*/
|
|
Packit |
1470ea |
g_signal_connect (GTK_BUTTON (button),
|
|
Packit |
1470ea |
"clicked",
|
|
Packit |
1470ea |
G_CALLBACK (show_dialog),
|
|
Packit |
1470ea |
GTK_WINDOW (window));
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
gtk_widget_show_all (window);
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
int
|
|
Packit |
1470ea |
main (int argc, char **argv)
|
|
Packit |
1470ea |
{
|
|
Packit |
1470ea |
GtkApplication *app;
|
|
Packit |
1470ea |
int status;
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
|
|
Packit |
1470ea |
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
|
Packit |
1470ea |
status = g_application_run (G_APPLICATION (app), argc, argv);
|
|
Packit |
1470ea |
g_object_unref (app);
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
return status;
|
|
Packit |
1470ea |
}
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
In this sample we used the following:
|
|
Packit |
1470ea |
|
|
Packit |
1470ea |
<list>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/3.4/GtkApplication.html">GtkApplication</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/3.4/GtkWindow.html">GtkWindow</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/stable/GtkDialog.html">GtkDialog</link> </item>
|
|
Packit |
1470ea |
<item><link href="http://developer.gnome.org/gtk3/stable/GtkLabel.html">GtkLabel</link> </item>
|
|
Packit |
1470ea |
</list>
|
|
Packit |
1470ea |
</page>
|