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

Problem with (setf dialog-item-text)



Hello,

I am defining a view with an icon and a text. The size of the view depends
on the text:

-------------------- beginning of lisp ------------------------

(defclass icon-and-text-dialog-item (dialog-item) 
  ((icon :accessor icon
         :initarg :icon)
   (icon-size :accessor icon-size
              :initarg :icon-size
              :initform *icon-default-size*)
   (color-p :accessor color-p
            :initarg :color-p)
   ))


(defmethod initialize-instance ((self icon-and-text-dialog-item) &rest initargs)
  (declare (ignore initargs))
  (call-next-method)
  (set-view-size self 
                 (+ (max (point-h (icon-size self)) 
                         (string-width (dialog-item-text self)
                                       (view-font self)))
                    2) 
                 (+ (point-v (icon-size self)) 
                    (font-line-height (view-font self))
                    4))

  (let ((icon (icon self)))
    (unless (or (typep icon 'fixnum) (pointerp icon))
      (error "~s is not a valid icon (not a resource-id or pointer)." icon))
    
    (if (typep icon 'fixnum)
      (let ((icon-hdl (if (color-p self)
                        (#_getCicon icon)
                        (#_geticon icon))))
        (if (%null-ptr-p icon-hdl)
          (error "no icon resource with id ~s." icon)
          (setf (icon self) icon-hdl))
        )
      )))


(defmethod view-draw-contents ((self icon-and-text-dialog-item))
  (let* ((width (point-h (view-size self)))
         (icon-topleft (make-point (truncate (- width (point-h (icon-size
self))) 2)
                                   1))
         (text-topleft (make-point (truncate (- width (string-width 
                                                       (dialog-item-text self)
                                                       (view-font self)))
                                             2)
                                   (- (point-v (view-size self)) 2))))
    (with-focused-view self
      (with-back-color (or (part-color self :background) *white-color*)
        
        (rlet ((r :rect 
                  :topleft icon-topleft
                  :bottomright (add-points icon-topleft (icon-size self))))
          (with-fore-color (or (part-color self :foreground) *black-color*)
            (if (color-p self)
              (#_plotCicon r (icon self))
              (#_ploticon r (icon self)))))
        (with-fore-color (or (part-color self :foreground) *black-color*)
          (move-to self text-topleft)
          (with-pstrs ((str (dialog-item-text self)))       
               (#_drawString str)))))
     ))

;;Then, I redefine the set-dialog-item-text function as follows:

(defmethod set-dialog-item-text ((self icon-and-text-dialog-item) text)
  (call-next-method)
  (set-view-size self 
                 (+ (max (point-h (icon-size self)) 
                         (string-width text
                                       (view-font self)))
                    2) 
                 (+ (point-v (icon-size self)) 
                    (font-line-height (view-font self))
                    4))
  (invalidate-view self t))

;;Everything works great, when I change the dialog-item-text, the size is 
;;recalculated and the dialog-item is redisplayed properly.

;;Then, I define the method for (setf dialog-item-text):

(defmethod (setf dialog-item-text) ((self icon-and-text-dialog-item) text)
  (set-dialog-item-text self text))

;;It does not work, the text is change, but the size is not recalculated and the
;;icon not redisplayed. WHY ????????

;;You can try it with:

(setf di (make-instance 'icon-and-text-dialog-item
                  :color-p nil
                  :dialog-item-text "Au revoir la compagnie"
                  :view-font '("courier" 9 :plain)
                  :icon 1
                  :icon-size #@(32 32)
                  :view-position #@(80 20)
                  ))

(setf w (make-instance 'window
          :color-p t
          :view-subviews
          (list di)))

(set-dialog-item-text di "Bonjour  tous les gens qui sont la")
(setf (dialog-item-text di) "Salut")

--------------------- end of lisp ----------------------------------

I think I missed something, but what ?

Thanx,

Gilles,
=====================================================
 L'ennemi est bete, il croit que l'ennemi c'est nous,
   alors que c'est lui.             P. Desproges
----  Gilles.Serasset@imag.fr (Gilles Serasset)  ----
GETA IMAG, UJF et CNRS, BP 53X F-38041 GRENOBLE CEDEX