(define (symvar ms)
	(string->symbol (slot-ref ms 'text-variable)))

(define-class <matrix-square> (<Entry>) 
   ((value	:accessor	value
		:allocation	:virtual
		:slot-ref
			(lambda (o) 
			  (let*((m (slot-ref o 'matrix))
			        (r (slot-ref o 'rownum))
			        (c (slot-ref o 'colnum))
			        (lv (slot-ref o 'prev-value))
			        (tv (eval (symvar o)))
			        (t (number->string (matrix-ref m r c)))
			        (val (cond ((not (equal? lv t)) t) ;C++ activity
				      (#t   (matrix-set! m r c 
						   (string->number tv))
					     tv)))) ; possible GUI activity
			     ;; Do what Entry.value did
			     ((slot-ref o 'Id) 'delete 0 'end)
			     ((slot-ref o 'Id) 'insert 0 val)
			     (slot-set! o 'prev-value val)
			     val))
		:slot-set!
			(lambda (o v) 
			  (let*((m (slot-ref  o 'matrix))
			        (r (slot-ref  o 'rownum))
			        (c (slot-ref  o 'colnum))
			        (t (number->string v)))
			
			     (matrix-set! m r c v)
			     (slot-set! o 'prev-value t)
			     ;; Do what Entry.value did
			     ((slot-ref o 'Id) 'delete 0 'end)
			     ((slot-ref o 'Id) 'insert 0 t))))
     (prev-value :getter	prev-value)
     (matrix	:accessor	matrix)
     (rownum	:accessor	rownum
            	:init-keyword	:rownum)
     (colnum	:accessor	colnum
            	:init-keyword	:colnum)
    )
)
(define-method initialize ((self <matrix-square>) args)
  (next-method)
  (let* ((vcolor    (get-keyword :color args *link:default-vertex-color*))
         (rn       (get-keyword :rownum args))
         (cn       (get-keyword :colnum args))
         (mat      (get-keyword :matrix args)))
    (slot-set! self 'background vcolor)
    (slot-set! self 'text-variable (my-gensym "mstext"))
    (slot-set! self 'matrix mat)
    (slot-set! self 'value (matrix-ref mat rn cn))
    (slot-set! self 'prev-value (matrix-ref mat rn cn))
    (slot-set! self 'rownum rn)
    (slot-set! self 'colnum cn)))

;(define l '((1 2 3) (4 5 6) (7 8 9)))
;(define m (list->matrix-double l))
;(define gt (slot-ref (make <graph-view> :graph (graph)) 'graph-toplevel))
;(define ms (make <matrix-square> :matrix m :rownum 0 :colnum 0
;			:color "blue"
;			:foreground "green"
;			:relief "flat" :width 5
;			:parent gt))
;

(provide "matrix-square")
