DO NOT REPLY TO THIS MESSAGE. INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.
[STR New]
Link: http://www.fltk.org/str.php?L2009
Version: 2.0-current
When a popup menu has no parent it is not always placed correctly on the
screen.
I was using a context menu on a tray icon (no top-level windows, hence no
parent for the context popup menu). When the system tray is at the bottom
of the screen (i.e. KDE's default) things are mostly okay. However, when
the system tray is at the top of the screen, the PopupMenu object made no
attempt to keep the menu within the bounds of the screen.
Also, in the try_popup() method, instead of simply using the absolute
screeen position to show the menu, it offset the position by event_x() and
event_y(). It does this in the case that parent() returns NULL. So given
that this menu is not to have a parent, I'm not sure why it should offset
the position. For my purposes, it places the menu incorrectly when that
offset is performed.
The attached patch file addresses these two issues.
I ran and successfully tested: clock, list, menu, menubar, subwindow. All
worked fine with regards to menu placement.
Link: http://www.fltk.org/str.php?L2009
Version: 2.0-current
Index: src/Menu_popup.cxx
===================================================================
--- src/Menu_popup.cxx (revision 6148)
+++ src/Menu_popup.cxx (working copy)
@@ -542,6 +542,31 @@
} else {
Y += Hp;
}
+
+ // Restrict to monitor area: (we're possibly abandoning the caller's desire
for a selected item in this case)
+ if ((Y - Htitle) < MENUAREA.y()) {
+ if(rectangle.y() > 0) {
+ // put the menu just below the mouse
+ Y = rectangle.y() + Htitle;
+ }
+
+ // if it's still out of range, put it just inside the MENUAREA
+ if ((Y - Htitle) < MENUAREA.y()) {
+ Y = MENUAREA.y() + Htitle;
+ }
+ }
+ if (Y > MENUAREA.b()-h()) {
+ if(rectangle.y() > 0) {
+ // put the menu just above the mouse
+ Y = rectangle.y() - h();
+ }
+
+ // if it's still out of range, put it just inside the MENUAREA
+ if (Y > MENUAREA.b()-h()) {
+ Y = MENUAREA.b()-h();
+ }
+ }
+
y(Y); // if !group: else {y(Y-2); w(1); h(1);}
if (title) title->position(X,Y-title->h()-dh/2);
}
@@ -888,8 +913,7 @@
for (Widget* w = this; w; w = w->parent())
rectangle.move(w->x(), w->y());
} else {
- rectangle.move(event_x_root()-event_x(),
- event_y_root()-event_y());
+ rectangle.move(event_x_root(), event_y_root());
}
if (fltk::event() == fltk::PUSH)
monitor = &Monitor::find(event_x_root(), event_y_root());
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs