[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Heirarchical pop up menus bug?



cfry@MIT.EDU writes:

> I'm attempting to create a heirarchical pop-up menu.
> When I select an item on the submenu, the action for an item on the
> top-level menu gets run!
Using hierarchical menus in this way "violates" the user-interface
guidelines.

I've noticed the same problem. The problem is actually worse, if the
submenu contains more items than the main menu, you'll generate an
error since there is no menu-item-action-function associated with
a non-existent menu item.

The fix is very simple: replace the menu-select function in
pop-up-menus.lisp with the following:

(defmethod menu-select ((menu pop-up-menu) num
                        &aux selection
                        selected-menu
                        selected-menu-item
                        (a-rect (pop-up-menu-rect menu))
                        (pos (with-focused-view (view-container menu)
                               (%local-to-global 
                                (wptr menu)
                                (rref a-rect :rect.topleft)))))
  (declare (ignore num))
  (menu-update menu)
  (setq selection (#_PopUpMenuSelect
                   :ptr (slot-value menu 'menu-handle)
                   :word (point-v pos)
                   :word (- (point-h pos)
                            2)
                   :word (or (pop-up-menu-default-item menu) 0)
                   :long)
        ;we get the selected menu in case you want to break the rules
        ;and use heirarchical menus in a pop-up menu
        selected-menu (menu-object (ash (logand #xFFFF0000 selection) -16))
        selected-menu-item (logand #x0000FFFF selection))
  (unless (eq selected-menu-item 0)
    (when (pop-up-menu-auto-update-default menu)
      (setf (pop-up-menu-default-item selected-menu) selected-menu-item))
    (menu-item-action               #| replace menu by selected-menu #|
     (nth (- selected-menu-item 1) (menu-items selected-menu)))))