Re: Dialogue Screen Placement
- From: Richard Boaz <riboaz xs4all nl>
- To: "John Cupitt" <jcupitt gmail com>
- Cc: GTK dev list <gtk-list gnome org>
- Subject: Re: Dialogue Screen Placement
- Date: Wed, 27 Sep 2006 14:01:20 +0200
Thanks, John, that works great!
cheers,
richard
On Sep 27, 2006, at 1:01 PM, John Cupitt wrote:
On 9/27/06, Richard Boaz <riboaz xs4all nl> wrote:
Below is a small program demonstrating my problem.
Here's a working version of your prog. The main problem was that you
were setting the position hint after showing the dialog. So when the
WM was selecting a position, there was no position hint set by you.
I noticed a couple of other minor things, though I guess you know
these anyway and this is just a test prog:
- use gtk_window_set_default_size() to set the start size for your
main window
- best to let the WM position the main window for you, rather than
setting the CENTER hint (that's mostly for things like splash screens
I think)
- the dialog should be positioned with GTK_WIN_POS_CENTER_ON_PARENT
- you need to use gtk_window_set_transient_for() to get the WM to
preserve your main window / dialog stacking order ... this is
especially important on win32
-----------------
#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]