Commit 1308dc95 authored by gambas's avatar gambas
Browse files

Window: Fix the initial focus of a window when it is opened.

[GB.GTK]
* BUG: Window: Fix the initial focus of a window when it is opened.
* BUG: Window: Don't raise spurious Hide or Show events.

[GB.GTK3]
* BUG: Window: Fix the initial focus of a window when it is opened.
* BUG: Window: Don't raise spurious Hide or Show events.
parent f02eae69
Pipeline #458945969 passed with stage
in 20 minutes and 55 seconds
......@@ -202,6 +202,8 @@ gMainWindow *CB_window_activate(gControl *control)
gMainWindow *active;
CWINDOW *active_ob;
//fprintf(stderr, "CB_window_activate: %s\n", control ? control->name() : "NULL");
if (control)
{
active = control->window();
......
......@@ -1362,11 +1362,14 @@ static void handle_focus_change()
void gApplication::setActiveControl(gControl *control, bool on)
{
if (control->isWindow())
if (control->isWindow() && on)
{
gControl *focus = ((gMainWindow *)control)->getInitialFocus();
if (focus != control)
{
focus->setFocus();
control = focus;
}
}
while (!control->canFocus())
......
......@@ -1266,9 +1266,9 @@ gControl *gControl::ignoreDesign()
bool gControl::canFocus() const
{
#if DEBUG_FOCUS
/*#if DEBUG_FOCUS
fprintf(stderr, "canFocus: %s -> %d\n", name(), gtk_widget_get_can_focus(widget));
#endif
#endif*/
#if GTK_CHECK_VERSION(2, 18, 0)
return gtk_widget_get_can_focus(widget);
......@@ -1290,9 +1290,9 @@ bool gControl::canFocusOnClick() const
void gControl::setCanFocus(bool vl)
{
#if DEBUG_FOCUS
/*#if DEBUG_FOCUS
fprintf(stderr, "setCanFocus: %s %d ?\n", name(), vl);
#endif
#endif*/
if (isDesign() || vl == canFocus())
return;
......@@ -1300,9 +1300,9 @@ void gControl::setCanFocus(bool vl)
_proxy->setCanFocus(vl);
else*/
{
#if DEBUG_FOCUS
/*#if DEBUG_FOCUS
fprintf(stderr, "setCanFocus: %s %p %d\n", name(), this, vl);
#endif
#endif*/
gtk_widget_set_can_focus(widget, vl);
}
......
......@@ -100,6 +100,9 @@ static gboolean cb_frame(GtkWidget *widget,GdkEventWindowState *event,gMainWindo
static gboolean cb_show(GtkWidget *widget, gMainWindow *data)
{
if (gApplication::_disable_mapping_events)
return false;
if (data->_grab_on_show)
{
data->_grab_on_show = FALSE;
......@@ -123,12 +126,18 @@ static gboolean cb_show(GtkWidget *widget, gMainWindow *data)
static gboolean cb_map(GtkWidget *widget, GdkEvent *event, gMainWindow *data)
{
if (gApplication::_disable_mapping_events)
return false;
data->_unmap = false;
return cb_show(widget, data);
}
static gboolean cb_hide(GtkWidget *widget, gMainWindow *data)
{
if (gApplication::_disable_mapping_events)
return false;
if (!data->_unmap)
{
CB_window_hide(data);
......@@ -140,6 +149,9 @@ static gboolean cb_hide(GtkWidget *widget, gMainWindow *data)
static gboolean cb_unmap(GtkWidget *widget, GdkEvent *event, gMainWindow *data)
{
if (gApplication::_disable_mapping_events)
return false;
bool ret = cb_hide(widget, data);
data->_unmap = true;
return ret;
......@@ -2100,7 +2112,7 @@ gControl *gMainWindow::getInitialFocus()
if (!ctrl)
break;
if (ctrl->isReallyVisible() && ctrl->isEnabled() && ctrl->canFocus())
if (ctrl->isReallyVisible() && ctrl->isEnabled() && !ctrl->isWindow() && ctrl->canFocus())
break;
if (ctrl == this)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment