Do not crash if expanded widgets change during arrangement. Fix GTK+ window centering method.

[GB.GTK]
* BUG: Do not crash if expanded widgets change during arrangement.

[GB.GTK3]
* BUG: Remove platform-specific window centering method.
* BUG: Do not crash if expanded widgets change during arrangement.

[GB.QT4]
* BUG: Do not crash if expanded widgets change during arrangement.

[GB.QT5]
* BUG: Do not crash if expanded widgets change during arrangement.
This commit is contained in:
gambas 2021-01-18 22:27:33 +01:00
parent cf8abc4639
commit ab307322bf
5 changed files with 35 additions and 46 deletions

View file

@ -958,19 +958,22 @@ void gMainWindow::center()
{
if (!isTopLevel()) return;
GdkRectangle rect;
int x, y;
if (!isTopLevel()) return;
#ifdef GTK3
PLATFORM.Window.Center(GTK_WINDOW(border));
#else
GdkRectangle rect;
int x, y;
gDesktop::availableGeometry(screen(), &rect);
x = rect.x + (rect.width - width()) / 2;
y = rect.y + (rect.height - height()) / 2;
move(x, y);
if (MAIN_platform_is_wayland)
gtk_window_set_position(GTK_WINDOW(border), GTK_WIN_POS_CENTER_ON_PARENT);
#endif
gDesktop::availableGeometry(screen(), &rect);
x = rect.x + (rect.width - width()) / 2;
y = rect.y + (rect.height - height()) / 2;
move(x, y);
}
bool gMainWindow::isModal() const
@ -991,13 +994,13 @@ void gMainWindow::showModal()
setType(GTK_WINDOW_TOPLEVEL);
gtk_window_set_modal(GTK_WINDOW(border), true);
center();
setTransientFor();
save = _current;
_current = this;
show();
center();
gtk_grab_add(border);
gApplication::enterLoop(this);

View file

@ -42,7 +42,6 @@ typedef
struct {
long (*GetId)(GdkWindow *);
void (*Center)(GtkWindow *);
} Window;
struct {

View file

@ -47,12 +47,6 @@ static long window_get_id(GdkWindow *window)
return 0;
}
static void window_center(GtkWindow *window)
{
fprintf(stderr, "window_center\n");
gtk_window_set_position(window, GTK_WIN_POS_CENTER_ON_PARENT);
}
//-------------------------------------------------------------------------
bool desktop_has_system_tray()

View file

@ -58,26 +58,6 @@ static long window_get_id(GdkWindow *window)
return window ? GDK_WINDOW_XID(window) : 0;
}
static void window_center(GtkWindow *window)
{
GdkRectangle rect;
int x, y;
int screen;
screen = gdk_screen_get_number(gtk_window_get_screen(window));
#if GTK_CHECK_VERSION(3, 22, 0)
gdk_monitor_get_workarea(gdk_display_get_monitor(gdk_display_get_default(), screen), &rect);
#else
gdk_screen_get_monitor_workarea(gdk_screen_get_default(), screen, &rect);
#endif
x = rect.x + (rect.width - width()) / 2;
y = rect.y + (rect.height - height()) / 2;
gtk_window_move(window, x, y);
}
//-------------------------------------------------------------------------
static bool desktop_has_system_tray()
@ -134,7 +114,6 @@ void *GB_GTK3_X11_1[] EXPORT = {
(void *)platform_create_plug,
(void *)window_get_id,
(void *)window_center,
(void *)desktop_has_system_tray,
(void *)desktop_show_tray_icon,

View file

@ -393,9 +393,15 @@ void FUNCTION_NAME(void *_object) //(QFrame *cont)
{
if (IS_EXPAND(ob)) // && !autoresize)
{
h = sexp / nexp;
sexp -= h;
nexp--;
if (nexp == 0) // the list of expanded widget may change
h = 0;
else
{
h = sexp / nexp;
sexp -= h;
nexp--;
}
if (h <= 0)
MOVE_WIDGET(ob, wid, -GET_WIDGET_W(wid), GET_WIDGET_Y(wid));
}
@ -426,9 +432,17 @@ void FUNCTION_NAME(void *_object) //(QFrame *cont)
{
if (IS_EXPAND(ob)) // && !autoresize)
{
w = sexp / nexp;
sexp -= w;
nexp--;
if (nexp == 0) // the list of expanded widget may change
{
w = 0;
}
else
{
w = sexp / nexp;
sexp -= w;
nexp--;
}
if (w <= 0)
MOVE_WIDGET(ob, wid, GET_WIDGET_X(wid), -GET_WIDGET_H(wid));
}