CLIM mail archive

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

Highliting menu items



    Date: Fri, 25 Oct 1991 15:00 EDT
    From: "William M. York" <York@chuck-jones.west.dialnet.ila.com>

	Date: Thu, 17 Oct 91 15:12 MET
	From: "Berthe Y. Choueiry" <choueiry@liasun6.epfl.ch>


	My question is about how to change the background of some command
	"buttons" in the command menu in order to attract the attention of the
	user.  I have a command in the menu that when hit, displays a list.
	Basically, what I need is having the command highlighted (either by
	changing its background or "its ink") whenever the list is not empty.
	Is there a simple way for doing that with CLIM?

    Unfortunately, the short answer is no.  That is, the CLIM command
    menu displaying code doesn't have any provision for this.
    However, the command menu displaying code is just a display
    function like any other, so you can write your own command menu
    displayer to customize the appearance.  Unfortunatly (again),
    CLIM doesn't quite export enough of the command-table mechanism
    to give you access to all the information you need.

    I am enclosing a simple demo program that has
    optionally-highlighted command menu items.  It uses some CLIM
    internal functions and data structures, so it is not going to
    work in the long term (those internals will surely change from
    CLIM 1 to CLIM 2).  But for now, you might be able to make use of
    it.  The unsupported stuff is marked by the CLIM:: package
    prefixes or the use of SLOT-VALUE.

I have included a slightly less internal version of one of the functions
below, but it is still pretty clear that we need to decide if there are
some more pieces of CLIM that need to be exported here.

    (in-package :clim-user)

    ;;; Simple application with a standard command menu at the top,
    ;;; and a customized command menu below it.
    (define-application-frame test
      ()
      ()
      (:panes ((menu :command-menu)
	       (my-menu :application
			:scroll-bars nil
			:display-function 'display-my-menu)
	       (interactor :interactor)))
      (:layout
       ((default
	  (:column 1
		   (menu :compute)
		   (my-menu 1/3)
		   (interactor :rest)))))
      (:command-definer t))

    (defvar *highlight-commands* nil)

    (define-test-command (com-one :menu "One")
			 ()
      (setq *highlight-commands* t))

    (define-test-command (com-two :menu "Two")
			 ()
      (setq *highlight-commands* nil))

    ;;; The display function for the customized menu.  It puts the
    ;;; menu items in BOLD when the *highlight-commands* flag is set.
    (defmethod display-my-menu ((frame test) stream)
      (let* ((command-table
	      (find-command-table (frame-command-table frame)))
	     ;; ***INTERNALS***
	     (menu (slot-value command-table 'clim::menu)))
	(multiple-value-bind (max-width max-height)
			     (window-inside-size stream)
	  (formatting-item-list (stream
				 :n-rows 1
				 :max-width max-width :max-height max-height)
	    ;; ***INTERNALS***  (both the DOVECTOR function and the format
	    ;; of an element.
	    (clim::dovector (element menu)
			    (let ((name (first element)))
			      (when name
				(formatting-cell (stream)
				  ;; Conditional BOLD text display.
				  (with-text-face ((if *highlight-commands*
						     ':bold
						     ':roman)
						   stream)
				    ;; ***INTERNALS***
				    (present element 'clim::command-menu-element
					     :stream stream :single-box t))))))))))

The new function:

;;; The display function for the customized menu.  It puts the
;;; menu items in BOLD when the *highlight-commands* flag is set.
(defmethod display-my-menu ((frame test) stream)
  (let* ((command-table
	   (find-command-table (frame-command-table frame))))
    (multiple-value-bind (max-width max-height) (window-inside-size stream)
      (formatting-item-list (stream :n-rows 1
				    :max-width max-width :max-height max-height)
	(map-over-command-table-menu-items
	  #'(lambda (&rest item)
	      (declare (dynamic-extent item))
	      ;; ***INTERNALS*** (the format of an item)
	      (let ((name (first item)))
		(when name
		  (formatting-cell (stream)
		    ;; Conditional BOLD text display.
		    (with-text-face ((if *highlight-commands* ':bold ':roman) stream)
		      ;; ***INTERNALS*** (the presentation type)
		      (present item 'clim::command-menu-element
			       :stream stream :single-box t))))))
	  command-table)))))

0,,

References:

Main Index | Thread Index