Commit 2cbfa191 authored by gambas's avatar gambas
Browse files

Fix window initial focus management.

[GB.GTK3]
* BUG: Fix window initial focus management.
parent 2707e006
Pipeline #438797462 failed with stage
in 21 minutes and 42 seconds
......@@ -1292,6 +1292,10 @@ static void post_focus_change(void *)
{
gControl *current, *control, *next;
#if DEBUG_FOCUS
fprintf(stderr, "post_focus_change...\n");
#endif
if (!_focus_change || _doing_focus_change)
return;
......@@ -1341,6 +1345,10 @@ static void post_focus_change(void *)
_doing_focus_change = false;
_focus_change = false;
#if DEBUG_FOCUS
fprintf(stderr, "post_focus_change: END\n");
#endif
}
void gApplication::handleFocusNow()
......@@ -1359,6 +1367,13 @@ static void handle_focus_change()
void gApplication::setActiveControl(gControl *control, bool on)
{
if (control->isWindow())
{
gControl *focus = ((gMainWindow *)control)->getInitialFocus();
if (focus != control)
focus->setFocus();
}
while (!control->canFocus())
{
control = control->parent();
......
......@@ -1265,12 +1265,6 @@ gControl *gControl::ignoreDesign()
bool gControl::canFocus() const
{
#if DEBUG_FOCUS
fprintf(stderr, "canFocus: %s ?\n", name());
#endif
/*if (_proxy)
return _proxy->canFocus();*/
#if DEBUG_FOCUS
fprintf(stderr, "canFocus: %s -> %d\n", name(), gtk_widget_get_can_focus(widget));
#endif
......@@ -1349,7 +1343,7 @@ void gControl::setFocus()
{
//if (isVisible() && bufW > 0 && bufH > 0)
#if DEBUG_FOCUS
fprintf(stderr, "setFocus now %s\n", name());
fprintf(stderr, "setFocus now %s %p\n", name(), widget);
#endif
//win->activate();
......
......@@ -323,6 +323,7 @@ static gboolean my_key_press_event(GtkWidget *widget, GdkEventKey *event)
GtkWidget *focus;
focus = gtk_window_get_focus(window);
//fprintf(stderr, "focus %p = %p\n", window, focus);
if (focus && gtk_widget_get_realized(focus))
{
if (GTK_IS_ENTRY(focus) || GTK_IS_TEXT_VIEW(focus))
......@@ -428,6 +429,7 @@ void gMainWindow::initialize()
_is_window = true;
_no_background = true;
_frame_init = false;
_set_focus = false;
onOpen = NULL;
onShow = NULL;
......@@ -904,34 +906,9 @@ void gMainWindow::setVisible(bool vl)
}
drawMask();
_set_focus = true;
if (focus)
{
//fprintf(stderr, "focus = %s\n", focus->name());
focus->setFocus();
focus = NULL;
}
else
{
gControl *ctrl = this;
for(;;)
{
ctrl = ctrl->nextFocus();
if (!ctrl)
break;
if (ctrl->isReallyVisible() && ctrl->isEnabled() && ctrl->canFocus())
{
ctrl->setFocus();
break;
}
if (ctrl == this)
break;
}
}
if (isSkipTaskBar())
_activate = true;
......@@ -2107,3 +2084,41 @@ void gMainWindow::getCustomMinimumSize(int *w, int *h) const
*h = _min_h;
}
gControl *gMainWindow::getInitialFocus()
{
gControl *ctrl;
if (!_set_focus)
return this;
_set_focus = false;
if (focus)
{
ctrl = focus;
focus = NULL;
//fprintf(stderr, "focus = %p %s\n", focus->border, focus->name());
//focus->setFocus();
//fprintf(stderr, "focus of window %p -> %p\n", border, gtk_window_get_focus(GTK_WINDOW(border)));
//focus = NULL;
}
else
{
ctrl = this;
for(;;)
{
ctrl = ctrl->nextFocus();
if (!ctrl)
break;
if (ctrl->isReallyVisible() && ctrl->isEnabled() && ctrl->canFocus())
break;
if (ctrl == this)
break;
}
}
return ctrl;
}
......@@ -165,6 +165,7 @@ public:
void calcCsdSize();
void createWindow(GtkWidget *new_border);
void updateSize();
gControl *getInitialFocus();
GtkWindowGroup *group;
GtkAccelGroup *accel;
......@@ -218,6 +219,7 @@ public:
unsigned _initMenuBar : 1;
unsigned _grab_on_show : 1;
unsigned _frame_init : 1;
unsigned _set_focus : 1;
};
#endif
......@@ -547,7 +547,10 @@ void gTextBox::onEnterEvent()
return;
if (_text_area_visible)
{
//fprintf(stderr, "gTextBox::onEnterEvent: show\n");
gdk_window_show(TEXT_AREA(entry));
}
}
void gTextBox::onLeaveEvent()
......@@ -557,7 +560,10 @@ void gTextBox::onLeaveEvent()
_text_area_visible = !hasFocus() && gdk_window_is_visible(TEXT_AREA(entry));
if (_text_area_visible)
{
//fprintf(stderr, "gTextBox::onEnterEvent: hide\n");
gdk_window_hide(TEXT_AREA(entry));
}
}
#endif
......
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