Index: main/panel.lisp
===================================================================
--- main/panel.lisp	(revision main,16)
+++ main/panel.lisp	(revision main,33)
@@ -3,5 +3,5 @@
    "Panels should be considered the fundamental division of a screen.
 Doing so allows for overlapping regions to be painted correctly.")
-  (:use #:cl #:cffi)
+  (:use #:cl #:cdk #:cffi #:dso-util #:tui-window)
   (:export #:create-panel #:update-panels #:do-update #:redraw-panels
            #:client-window #:destroy-panel #:with-panel))
@@ -39,20 +39,23 @@
 
 
-(defclass panel ()
-  ((panel-ptr :initarg :panel-ptr)))
+(defclass panel (window)
+  ((panel-ptr :initarg :panel-ptr)
+   (client-window :initarg :client-window :reader client-window)))
 
 
 
-(defun create-panel (height width y x)
+(define-condition panel-construction-error (error) ())
+
+(define-condition panel-destruction-error (error) ())
+
+
+
+(defun create-panel (window)
   "Creates a new panel.  Associates a client window with it, covering
 the entire panel."
-  (let* ((window (cdk::c-new-window height width y x))
-         (panel-ptr (new-panel window)))
-    (make-instance 'panel :panel-ptr panel-ptr)))
-
-(defmethod client-window ((panel panel))
-  "Returns the client window associated with the panel."
-  (with-slots (panel-ptr) panel
-    (panel-window panel-ptr)))
+  (let ((panel-ptr (new-panel (window-pointer window))))
+    (when (null-pointer-p panel-ptr)
+      (signal 'panel-construction-error))
+    (make-instance 'panel :panel-ptr panel-ptr :client-window window)))
 
 (defun redraw-panels ()
@@ -67,16 +70,38 @@
 
 (defun destroy-panel (panel)
-  "Destroys a panel and insures that the screen is correct."
-  (let ((window (client-window panel)))
-    (with-slots (panel-ptr) panel
-      (del-panel panel-ptr))
-    (cdk::c-delete-window window))
-  (redraw-panels))
+  "Destroys a panel."
+  (with-slots (panel-ptr) panel
+    (unless (= (del-panel panel-ptr) +ok+)
+      (signal 'panel-destruction-error))))
 
 
 
+(defmethod tui-window::create-subwindow ((panel panel) height width y x)
+  (tui-window::create-subwindow (client-window panel) height width y x))
+
+(defmethod refresh ((panel panel))
+  (update-panels)
+  #|(do-update)|#)
+
+(defmethod tui-window:window-pointer ((panel panel))
+  (tui-window:window-pointer (client-window panel)))
+
+#|
+(defmethod (setf tui-output:background) (pair (panel panel))
+  (setf (tui-output:background (client-window panel)) pair))
+
+(defmethod tui-cursor:cursor-position ((panel panel))
+  (tui-cursor:cursor-position (client-window panel)))
+
+(defmethod (setf tui-cursor:cursor-position) (p (panel panel))
+  (tui-cursor:cursor-position
+|#
+
+
 (defmacro with-panel ((var height width y x) &body body)
-  `(let ((,var (create-panel ,height ,width ,y ,x)))
-     (unwind-protect
-          (progn ,@body)
-       (destroy-panel ,var))))
+  (with-gensyms (w)
+    `(with-screen-window (,w ,height ,width ,y ,x)
+       (let ((,var (create-panel ,w)))
+         (unwind-protect (progn ,@body)
+           (destroy-panel ,var)
+           (redraw-panels))))))
