;;;;
;;;; meta.stk   -- GTklos Meta Classes
;;;;
;;;; Copyright © 2007-2021 Erick Gallesio - I3S-CNRS/ESSI <eg@essi.fr>
;;;;
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 2 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;;; GNU General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program; if not, write to the Free Software
;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
;;;; USA.
;;;;
;;;;           Author: Erick Gallesio [eg@essi.fr]
;;;;    Creation date: 16-Aug-2000 09:21 (eg)
;;;;

;;;;======================================================================
;;;;
;;;;                    M e t a c l a s s e s
;;;;
;;;;======================================================================

(define-class <gtk-virtual-slots-metaclass> (<class>)
  ())


(define-method compute-get-n-set ((class <gtk-virtual-slots-metaclass>) slot)
  (case (slot-definition-allocation slot)
    ((:gtk-property)
     (let ((s-name (key-get (cdr slot) #:gtk-widget 'wid))
           (name   (key-get (cdr slot) #:gtk-name (symbol->string (car slot)))))
       (list
        (lambda (o)   (%gtk-get-property  (slot-ref o s-name) name))
        (lambda (o v) (%gtk-set-property! (slot-ref o s-name) name v)))))

    ((:gtk-property-enum)
     (let ((s-name (key-get (cdr slot) #:gtk-widget 'wid))
           (name   (key-get (cdr slot) #:gtk-name (symbol->string (car slot))))
           (enum   (key-get (cdr slot) #:gtk-enum #f)))
       (unless enum
         (error "you must sepcify the enum values for ~s" name))
       (list
        (lambda (o)
          (let ((val (%gtk-get-property (slot-ref o s-name) name)))
            (if (< -1 val (length enum))
                (list-ref enum val)
                (error "value (~s) for enum ~S" val enum))))
        (lambda (o v)
          (let* ((val  (if (string? v) (string->symbol v) v))
                 (item (memq val enum)))
            (if item
                (%gtk-set-property! (slot-ref o s-name)
                                    name
                                    (- (length enum) (length item)))
                (error "value for property ~s must be in ~s. It was ~s"
                       name enum v)))))))
    (else
     (next-method))))
