Re: Dialogs in middle of windows



Alex Buell wrote:

On Tue, 7 Dec 2004, Todd Fisher wrote:

[ snipped ]

Thanks guys, that worked a treat!

I had to make the parent window a static global so that the following code could function properly:

static void about(GtkWidget *w, gpointer data)
{
        gint x, y, pwidth, pheight, width, height;
        GtkWidget *dialog, *label, *button;

        dialog = gtk_dialog_new();
        gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
        gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(w));
        gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE);

        gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);

        label = gtk_label_new(ABOUT);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), label, TRUE, TRUE, 0);
        gtk_widget_show(label);

        button = gtk_button_new_with_label("OK");
gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(dismiss), dialog); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area), button, TRUE, TRUE, 0);
        gtk_widget_show(button);

        gtk_window_get_position(GTK_WINDOW(window), &x, &y);
        gtk_window_get_size(GTK_WINDOW(window), &pwidth, &pheight);
        gtk_window_get_size(GTK_WINDOW(dialog), &width, &height);

#ifdef DEBUG
printf("Parent position: %d, %d\n", x, y);
printf("Parent size: %d, %d\nDialog size: %d, %d\n", pwidth, pheight, width, height);
#endif /* DEBUG */

        x = (pwidth - width) / 2 + x;
        y = (pheight - height) / 2 + y;

        gtk_window_move(GTK_WINDOW(dialog), x, y);
        gtk_widget_show(dialog);
}

Is there a better way to actually get the parent window parameters without having to resort to a global GtkWindow variable?

Cheers,
Alex.

You could always use GObject properties.  So, when your app starts up
g_object_set_data( G_OBJECT( mydialogwidget ), "parent", parentwidget );

then in your dialog code to get the parent window
GtkWidget *parentwidget = (GtkWidget*)g_object_get_data( G_OBJECT( mydialogwidget ), "parent" );

-todd




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]