RE: Dialogs always on top in Windows?



> -----Original Message-----
> From: Ari Jolma
> 
> I have a piece of code (Perl but that shouldn't be the issue) below,
> which opens a transient dialog. The dialog is transient in X but not in
> my experience in Windows. Am I doing something wrong, or what?
> 
> sub a {
>     my $dialog =
> Gtk2::MessageDialog->new($parent,'modal','info','close','foo');
>     $dialog->set_transient_for($parent);
>     $dialog->run;
>     $dialog->destroy;
> }
> 8<------------

I submitted a bug not long ago against the GTK_DIALOG_MODAL flag not working
with message dialogs in win32. I worked around it by changing my app to use
gtk_dialog_new_with_buttons instead in a win32 build since that does work
reasonable well with GTK_DIALOG_MODAL flag (at least its "modal" dialogs do
stay on top).

For reference, my message dialog function which manages to closely mimic
gtk_message_dialog_new is:

/*==========================================================================
==*/
/*
 * Show a message in a pop-up dialog window
 */
gint msgBox(char *msgText, GtkMessageType msgType, GtkButtonsType btnType)
{
    GtkWidget   *dlgWin = NULL;
    gint        result;

#ifdef _WIN32
    /* GTK's WIN32 message dialog currently has problems with being modal
     * - http://bugzilla.gnome.org/show_bug.cgi?id=405178 */
    GtkWidget   *vBox;
    GtkWidget   *hBox;
    GtkWidget   *label;
    GtkWidget   *image = NULL;
    const gchar *stockId = NULL;

    switch (btnType)
    {
    case GTK_BUTTONS_NONE:
        dlgWin = gtk_dialog_new_with_buttons("", GTK_WINDOW(mainWin),
                                             GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
                                             NULL);
        break;
    case GTK_BUTTONS_OK:
        dlgWin = gtk_dialog_new_with_buttons("", GTK_WINDOW(mainWin),
                                             GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
                                             GTK_STOCK_OK, GTK_RESPONSE_OK,
                                             NULL);
        break;
    case GTK_BUTTONS_CLOSE:
        dlgWin = gtk_dialog_new_with_buttons("", GTK_WINDOW(mainWin),
                                             GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
                                             GTK_STOCK_CLOSE,
GTK_RESPONSE_CLOSE,
                                             NULL);
        break;
    case GTK_BUTTONS_CANCEL:
        dlgWin = gtk_dialog_new_with_buttons("", GTK_WINDOW(mainWin),
                                             GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
                                             GTK_STOCK_OK, GTK_RESPONSE_OK,
                                             NULL);
        break;
    case GTK_BUTTONS_OK_CANCEL:
        dlgWin = gtk_dialog_new_with_buttons("", GTK_WINDOW(mainWin),
                                             GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
                                             GTK_STOCK_OK, GTK_RESPONSE_OK,
                                             GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
                                             NULL);
        break;
    case GTK_BUTTONS_YES_NO:
        dlgWin = gtk_dialog_new_with_buttons("", GTK_WINDOW(mainWin),
                                             GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
                                             GTK_STOCK_YES,
GTK_RESPONSE_YES,
                                             GTK_STOCK_NO, GTK_RESPONSE_NO,
                                             NULL);
        break;
    }

    if (!dlgWin) return (GTK_RESPONSE_NONE);

    vBox = gtk_vbox_new(FALSE, 10);
    gtk_container_set_border_width(GTK_CONTAINER(vBox), 10);
    placeWidgetCenteredAndFill(GTK_DIALOG(dlgWin)->vbox, vBox, 0);

    hBox = gtk_hbox_new(FALSE, 0);
    placeWidgetCenteredAndFill(vBox, hBox, 0);

 
    switch (msgType)
    {
    case GTK_MESSAGE_INFO:
        stockId = GTK_STOCK_DIALOG_INFO;
        break;
    case GTK_MESSAGE_QUESTION:
        stockId = GTK_STOCK_DIALOG_QUESTION;
        break;
    case GTK_MESSAGE_WARNING:
        stockId = GTK_STOCK_DIALOG_WARNING;
        break;
    case GTK_MESSAGE_ERROR:
        stockId = GTK_STOCK_DIALOG_ERROR;
        break;
    case GTK_MESSAGE_OTHER:
        break;
    default:
        g_warning ("Unknown GtkMessageType %d", msgType);
        break;
    }

    if (stockId)
    {
        image = gtk_image_new_from_stock(stockId, GTK_ICON_SIZE_DIALOG);
        if (image) placeWidgetCenteredAndFill(hBox, image, 0);
    }
      
    insertSpacing(hBox, 10);

    vBox = gtk_vbox_new(FALSE, 0);
    placeWidgetCenteredAndFill(hBox, vBox, 0);
    label = gtk_label_new(msgText);
    placeWidgetTopJustified(vBox, label, 0);

    gtk_dialog_set_has_separator(GTK_DIALOG(dlgWin), FALSE);

#else /* !_WIN32 */
    dlgWin = gtk_message_dialog_new(GTK_WINDOW(mainWin),
                                    GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
                                    msgType,
                                    btnType,
                                    msgText);
#endif /* !_WIN32 */

    result = gtk_dialog_run(GTK_DIALOG(dlgWin));
    gtk_widget_destroy(dlgWin);

    return (result);
}

void insertSpacing(GtkWidget *box, gint spacing)
{
    GtkWidget *spBox;

    if (GTK_IS_HBOX(box))
    {
        spBox = gtk_vbox_new(FALSE, 0);
        placeWidgetLeftJustified(box, spBox, 0);
        gtk_widget_set_size_request(spBox, spacing, -1);
    }
    else if (GTK_IS_VBOX(box))
    {
        spBox = gtk_hbox_new(FALSE, 0);
        placeWidgetTopJustified(box, spBox, 0);
        gtk_widget_set_size_request(spBox, -1, spacing);
    }
    else
    {
        g_assert(FALSE);
        return;
    }
    gtk_widget_show(spBox);
}


The "placeWidget" functions are just wrappers for
gtk_box_pack_start/get_wdiget_show.







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