Commit a2a04eeb authored by Benoît Minisini's avatar Benoît Minisini
Browse files

Fix popup menu behaviour.

[GB.GTK]
* BUG: Make popup menu event behave the same way as in Qt components.
* BUG: Menu.Popup() now works correctly the opened menu is not defined in the window of the click event.

[GB.GTK3]
* BUG: Make popup menu event behave the same way as in Qt components.
* BUG: Menu.Popup() now works correctly the opened menu is not defined in the window of the click event.
parent b2d0a542
Pipeline #349668698 passed with stage
in 25 minutes and 40 seconds
......@@ -556,7 +556,11 @@ __FOUND_WIDGET:
control = save_control;
bool menu = false;
#if GTK_CHECK_VERSION(3, 4, 0)
bool menu = gdk_event_triggers_context_menu(event);
#else
bool menu = (event->button.button == 3) && (event->type == GDK_BUTTON_PRESS);
#endif
if (event->type != GDK_BUTTON_RELEASE)
{
......@@ -574,74 +578,52 @@ __FOUND_WIDGET:
__BUTTON_TRY_PROXY:
if (!control->isDesign() && !control->isEnabled())
goto __HANDLE_EVENT;
cancel = false;
if (control->onMouseEvent)
if (control->isDesign() || control->isEnabled())
{
if (event->type == GDK_BUTTON_PRESS || control->canRaise(control, type))
if (control->onMouseEvent)
{
control->getScreenPos(&xc, &yc);
xs = (int)event->button.x_root;
ys = (int)event->button.y_root;
x = xs - xc;
y = ys - yc;
gMouse::validate();
gMouse::setEvent(event);
//gMouse::setValid(1,(int)event->x,(int)event->y,event->button,event->state,data->screenX(),data->screenY());
gMouse::setMouse(x, y, xs, ys, event->button.button, event->button.state);
switch ((int)event->type)
if (event->type == GDK_BUTTON_PRESS || control->canRaise(control, type))
{
case GDK_BUTTON_PRESS:
gMouse::setControl(control);
gMouse::setStart(x, y);
cancel = control->onMouseEvent(control, gEvent_MousePress);
break;
case GDK_2BUTTON_PRESS:
cancel = control->onMouseEvent(control, gEvent_MouseDblClick);
break;
case GDK_BUTTON_RELEASE:
gMouse::setControl(NULL);
cancel = control->onMouseEvent(control, gEvent_MouseRelease);
break;
control->getScreenPos(&xc, &yc);
xs = (int)event->button.x_root;
ys = (int)event->button.y_root;
x = xs - xc;
y = ys - yc;
gMouse::validate();
gMouse::setEvent(event);
//gMouse::setValid(1,(int)event->x,(int)event->y,event->button,event->state,data->screenX(),data->screenY());
gMouse::setMouse(x, y, xs, ys, event->button.button, event->button.state);
switch ((int)event->type)
{
case GDK_BUTTON_PRESS:
gMouse::setControl(control);
gMouse::setStart(x, y);
cancel = control->onMouseEvent(control, gEvent_MousePress);
break;
case GDK_2BUTTON_PRESS:
cancel = control->onMouseEvent(control, gEvent_MouseDblClick);
break;
case GDK_BUTTON_RELEASE:
gMouse::setControl(NULL);
cancel = control->onMouseEvent(control, gEvent_MouseRelease);
break;
}
gMouse::invalidate();
}
gMouse::invalidate();
}
}
/*if (type == gEvent_MousePress && control->isTopLevel())
{
gMainWindow *win = ((gMainWindow *)control);
if (win->isPopup())
{
control->getScreenPos(&xc, &yc);
xs = (int)event->button.x_root;
ys = (int)event->button.y_root;
x = xs - xc;
y = ys - yc;
if (x < 0 || y < 0 || x >= win->width() || y >= win->height())
win->close();
}
}
else*/ if (type == gEvent_MouseRelease && control->_grab)
if (type == gEvent_MouseRelease && control->_grab)
{
gApplication::exitLoop(control);
}
#if GTK_CHECK_VERSION(3, 4, 0)
if (gdk_event_triggers_context_menu(event))
#else
if (event->button.button == 3 && event->type == GDK_BUTTON_PRESS)
#endif
menu = true;
if (!cancel)
{
if (control->_proxy_for)
......
......@@ -861,13 +861,25 @@ void gMenu::doPopup(bool move, int x, int y)
GdkWindow *win;
GdkRectangle rect;
GdkEvent *event;
GdkEvent *last_event;
gt_disable_warnings(true);
event = gdk_event_new(GDK_BUTTON_PRESS);
event->button.time = gApplication::lastEventTime(); //GDK_CURRENT_TIME;
event->button.button = 1;
event->button.window = gtk_widget_get_window(window()->border);
last_event = gApplication::lastEvent();
if (last_event && last_event->type == GDK_BUTTON_PRESS)
{
event->button.button = last_event->button.button;
event->button.window = last_event->button.window;
}
else
{
event->button.button = 1;
event->button.window = gtk_widget_get_window(window()->border);
}
gdk_event_set_device(event, gMouse::getPointer());
if (move)
......
Markdown is supported
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