Modeless, parentless wxDialog still always above wxFrame window in z-order?

喜欢而已 提交于 2019-12-05 19:57:20

It seems that this behavior comes from a difference in how Gnome handles windows with different "type hints"...it puts them into their own z-index groupings:

https://developer.gnome.org/gdk3/stable/gdk3-Windows.html#GdkWindowTypeHint

The dialog is created with GDK_WINDOW_TYPE_HINT_DIALOG while your other window is most likely created with GDK_WINDOW_TYPE_HINT_NORMAL. The point where this decision is made is in gtk/toplevel.cpp and it's being cued by the fact that the "extra" style flags contain wxTOPLEVEL_EX_DIALOG:

toplevel.cpp#L594

Those are the only two calls to gtk_window_set_type_hint in the wxWidgets GTK codebase, except for in the splash screen code. So changing the "extra" style bits after the fact isn't going to help. (The "correct" solution would be to patch wxWidgets so that adjusting wxTOPLEVEL_EX_DIALOG in the extra styles would do the proper adjustment to the window type hint.)

You can't use the wxDialog class without running through its constructor, which calls the non-virtual method wxDialog::Create, which sets the extra style to wxTOPLEVEL_EX_DIALOG and then goes directly to top level window creation:

dialog.cpp#L54

So I guess you have the option of trying this, which works if you haven't shown the dialog window yet:

#ifdef __WXGTK__
gtk_window_set_type_hint(
    GTK_WINDOW(iShouldBeUsingQtDialog->GetHandle()),
    GDK_WINDOW_TYPE_HINT_NORMAL);
#endif

...and if you have shown the dialog already, you need to use this for it to work:

#ifdef __WXGTK__
gdk_window_set_type_hint(
    iShouldBeUsingQtDialog->GetHandle()->window,
    GDK_WINDOW_TYPE_HINT_NORMAL);
#endif

Both cases will require you to add an include file into your source:

#ifdef __WXGTK__
#include "gtk/gtkwindow.h"
#endif

...and you'll have to update your build to find the GTK includes. On the command line for G++ I tried this and it worked:

pkg-config --cflags --libs gtk+-2.0
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!