[Bese-devel] Question regarding container and widget-component

Mac Chan emailmac at gmail.com
Sat Oct 1 20:26:04 UTC 2005


Is there a simple way to carry a reference to the top level component
for each subcomponent?

(defcomponent level1-container (widget-component)
  (
   (level2-container :component level2-container
                     :accessor level2-container)
  ))

(defcomponent level2-container (widget-component)
  (
   (root :initarg :root :accessor root) ;; point to level1-container obj
   (level3-container :component level3-container
                     :accessor level3-container)
  ))

(defcomponent level3-container (widget-component)
  (
   (root :initarg :root :accessor root) ;; point to level1-container obj
   (level4-container :component level4-container
                     :accessor level4-container)
  ))

(defcomponent level4-container (widget-component)
  (
   (root :initarg :root :accessor root) ;; point to level1-container obj
  ))

;; ----------------------------------------------------------------
;; Approach 1 - use after method of the top level container to assign
;; the referece.  Ugly and cumbersome. Is there a better way?
;; ----------------------------------------------------------------

(defmethod shared-initialize :after ((obj level1-container) slot-names
&rest initargs)
  (declare (ignore slot-names initargs))
  (setf (root (level2-container obj)) obj)
  (setf (root (level3-container (level2-container obj))) obj)
  (setf (root (level4-container (level3-container (level2-container obj)))) obj)
)

;; ----------------------------------------------------------------
;; Approach 2 - pass SELF object to initarg, but how to refer to SELF???
;; ----------------------------------------------------------------
(defcomponent level1-container (widget-component)
  (
   (level2-container :component (level2-container :root SELF) ;; SELF
= level1-container ???
                     :accessor level2-container)
  ))

;; ----------------------------------------------------------------
;; Approach 3 - use after method of each component to find its
;; containing component or root component
;; ----------------------------------------------------------------

(defmethod shared-initialize :after ((obj level4-container) slot-names
&rest initargs)
  (declare (ignore slot-names initargs))
  (setf (root obj) (FIND-CONTAINING-COMPONENT obj))) ;; is there a way
to do this?

Maybe there's a reference to the top level window-component and we can
work our way from there?

Thanks.



More information about the bese-devel mailing list