summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorculler <culler>2019-01-28 16:39:02 (GMT)
committerculler <culler>2019-01-28 16:39:02 (GMT)
commite087bb7d89526c82c0c0fb1e1bf5a6f21cf6d2ab (patch)
tree625e8e0c6268b203a46d8f8de00bd840f66ecea3 /macosx
parent8d1aa0f36abad1148d39757b1f9f23b6ea6a5ace (diff)
downloadtk-e087bb7d89526c82c0c0fb1e1bf5a6f21cf6d2ab.zip
tk-e087bb7d89526c82c0c0fb1e1bf5a6f21cf6d2ab.tar.gz
tk-e087bb7d89526c82c0c0fb1e1bf5a6f21cf6d2ab.tar.bz2
Reverting TkpPostTearoffMenu to the unix function, which is equally useless but
allows the tests to run without user intervention.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/tkMacOSXMenu.c91
1 files changed, 82 insertions, 9 deletions
diff --git a/macosx/tkMacOSXMenu.c b/macosx/tkMacOSXMenu.c
index ef32738..d261add 100644
--- a/macosx/tkMacOSXMenu.c
+++ b/macosx/tkMacOSXMenu.c
@@ -779,7 +779,7 @@ TkpPostMenu(
* entry, will be located. */
int index)
{
- int result, oldMode;
+ int result;
Tk_Window root = Tk_MainWindow(interp);
if (root == NULL) {
@@ -807,11 +807,19 @@ TkpPostMenu(
if (itemIndex >= 0) {
item = [menu itemAtIndex:itemIndex];
}
- if (menu != nil && !(menuPtr->menuFlags & MENU_DELETION_PENDING)) {
- [menu popUpMenuPositioningItem:item
- atLocation:[win tkConvertPointFromScreen:location]
- inView:view];
+
+ /*
+ * The post commands could have deleted the menu, which means we are dead
+ * and should go away.
+ */
+
+ if (menuPtr->tkwin == NULL) {
+ return TCL_OK;
}
+
+ [menu popUpMenuPositioningItem:item
+ atLocation:[win tkConvertPointFromScreen:location]
+ inView:view];
inPostMenu = 0;
return TCL_OK;
}
@@ -820,13 +828,78 @@ int
TkpPostTearoffMenu(
Tcl_Interp *interp, /* The interpreter this menu lives in */
TkMenu *menuPtr, /* The menu we are posting */
- int x, int y, /* The screen coordinates where the top left
+ int x, int y, int index) /* The screen coordinates where the top left
* corner of the menu, or of the specified
* entry, will be located. */
- int index)
{
- menuPtr->active = -1;
- return TkpPostMenu(interp, menuPtr, x, y, index);
+ int vRootX, vRootY, vRootWidth, vRootHeight;
+ int result;
+
+ if (index >= menuPtr->numEntries) {
+ index = menuPtr->numEntries - 1;
+ }
+ if (index >= 0) {
+ y -= menuPtr->entries[index]->y;
+ }
+
+ TkActivateMenuEntry(menuPtr, -1);
+ TkRecomputeMenu(menuPtr);
+ result = TkPostCommand(menuPtr);
+ if (result != TCL_OK) {
+ return result;
+ }
+
+ /*
+ * The post commands could have deleted the menu, which means we are dead
+ * and should go away.
+ */
+
+ if (menuPtr->tkwin == NULL) {
+ return TCL_OK;
+ }
+
+ /*
+ * Adjust the position of the menu if necessary to keep it visible on the
+ * screen. There are two special tricks to make this work right:
+ *
+ * 1. If a virtual root window manager is being used then the coordinates
+ * are in the virtual root window of menuPtr's parent; since the menu
+ * uses override-redirect mode it will be in the *real* root window for
+ * the screen, so we have to map the coordinates from the virtual root
+ * (if any) to the real root. Can't get the virtual root from the menu
+ * itself (it will never be seen by the wm) so use its parent instead
+ * (it would be better to have an an option that names a window to use
+ * for this...).
+ * 2. The menu may not have been mapped yet, so its current size might be
+ * the default 1x1. To compute how much space it needs, use its
+ * requested size, not its actual size.
+ */
+
+ Tk_GetVRootGeometry(Tk_Parent(menuPtr->tkwin), &vRootX, &vRootY,
+ &vRootWidth, &vRootHeight);
+ vRootWidth -= Tk_ReqWidth(menuPtr->tkwin);
+ if (x > vRootX + vRootWidth) {
+ x = vRootX + vRootWidth;
+ }
+ if (x < vRootX) {
+ x = vRootX;
+ }
+ vRootHeight -= Tk_ReqHeight(menuPtr->tkwin);
+ if (y > vRootY + vRootHeight) {
+ y = vRootY + vRootHeight;
+ }
+ if (y < vRootY) {
+ y = vRootY;
+ }
+ Tk_MoveToplevelWindow(menuPtr->tkwin, x, y);
+ if (!Tk_IsMapped(menuPtr->tkwin)) {
+ Tk_MapWindow(menuPtr->tkwin);
+ }
+ TkWmRestackToplevel((TkWindow *) menuPtr->tkwin, Above, NULL);
+ return TCL_OK;
+
+ // menuPtr->active = -1;
+ // return TkpPostMenu(interp, menuPtr, x, y, index);
}
/*