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

checkmarks and updating menu(-items)



Hi,

Apparently I don't quite understand how the update-function for menus and
menu-items works. Is anyone willing to comment on the code below?
---

;;; Defining the menu...
;;; If I evaluate the following
(defvar *a-menu*)
(defvar *language* 'english)

(setf *a-menu* (make-instance 'menu :menu-title "Dishes"))

(add-menu-items *a-menu* 
                (make-instance 'menu-item
                  :update-function
                  #'(lambda (item) (case *language* 
                                     ((dutch) (set-menu-item-title item
"Dagschotel"))
                                     (otherwise (set-menu-item-title item
"Plat du jour"))))))

(menu-install *a-menu*)
;;; everything works as expected.
;;; The next part of code however evokes weird behaviour
(menu-deinstall *a-menu*)              ; first get rid of old menu

(setf *a-menu* (make-instance 'menu
                              :update-function
                              #'(lambda (item) (case *language* 
                                                 ((dutch) (set-menu-title
item "Schotels"))
                                                 (otherwise (set-menu-title
item "Dishes"))))))

(add-menu-items *a-menu* 
                (make-instance 'menu-item
                  :update-function
                  #'(lambda (item) (case *language* 
                                     ((dutch) (set-menu-item-title item
"Dagschotel"))
                                     (otherwise (set-menu-item-title item
"Plat du jour"))))))

(menu-install *a-menu*)
;;; I can see why *a-menu* does not have a title initially. But I fail to
see
;;; why it the update function works only while the mouse button is being
;;; pressed. As soon as you release it, "Untitled" reappears. (btw, I do
;;; understand that this approach will never satisfy: *a-menu* will only 
;;; be updated if one clicks the menu-bar. What I don't understand is why 
;;; it is only updated for as long as one clicks the menu-bar)
;;; Furthermore, the update function for the menu-item doesn't seem to do 
;;; it's job anymore. It did work all right in the previous example.

;;; Another problem pops up when I try to make a hierarchical menu. This
time
;;; I don't know if the update-function or set-menu-item-check-mark is
playing
;;; tricks on me. Anyway, the checkmark never shows up after evaluating the
;;; code below.

;;; First trash the old menu again:
(menu-deinstall *a-menu*)

;;; Defining a submenu
(defclass language-menu (menu) ())

(defclass language-menu-item (menu-item) ())

(defvar *language-menu*)

(setf *language-menu*
      (make-instance 'language-menu :update-function 
                     #'(lambda (item) (case *language* 
                                        ((dutch) (set-menu-title item
"Taalwissel"))
                                        (otherwise (set-menu-title item
"Swap Language"))))))

(add-menu-items *language-menu* 
                (make-instance 'language-menu-item
                  :menu-item-title "English"
                  :menu-item-action 
                  #'(lambda () (setf *language* 'english))
                  :update-function
                  #'(lambda (item)
                      (if (equal *language* 'english)
                        (set-menu-item-check-mark item t)
                        (set-menu-item-check-mark item nil))))
                (make-instance 'language-menu-item
                  :menu-item-title "Nederlands"
                  :menu-item-action 
                  #'(lambda () (setf *language* 'dutch))
                  :update-function
                  #'(lambda (item) 
                      (if (equal *language* 'english)
                        (set-menu-item-check-mark item t)
                        (set-menu-item-check-mark item nil)))))

;;; The old menu again:
(setf *a-menu* (make-instance 'menu :menu-title "Dishes"))

(add-menu-items *a-menu* 
                (make-instance 'menu-item
                  :update-function
                  #'(lambda (item) (case *language* 
                                     ((dutch) (set-menu-item-title item
"Dagschotel"))
                                     (otherwise (set-menu-item-title item
"Plat du jour"))))))


(menu-install *a-menu*)
(add-menu-items *a-menu* *language-menu*)

;;; Now I don't know whether the check-mark is ever set, but it is
certainly not
;;; displayed. Why not? I would appreciate any help.

-- 
Arnoud Verdwaald,
University of Nijmegen,
THE NETHERLANDS (EUROPE).
e-mail:    arnoudv@ped.kun.nl