/[cl-carbon]/CL-Carbon/window.lisp
ViewVC logotype

Contents of /CL-Carbon/window.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Fri May 6 04:41:47 2005 UTC (8 years, 11 months ago) by dsteuber
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +4 -6 lines
Added code to hopefully delete the event handler so that the associated
object can be freed.  Also removed a slot from the cl-carbon:window class.
Objects should generally not know about their containers.
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: CL-CARBON -*-
2 ;;;; ***********************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name: window.lisp
6 ;;;; Project: CL-Carbon
7 ;;;; Purpose: Carbon window proxies
8 ;;;; Programmer: David Steuber
9 ;;;; Date Started: 1/29/2005
10 ;;;;
11 ;;;; $Id: window.lisp,v 1.2 2005/05/06 04:41:47 dsteuber Exp $
12 ;;;; ***********************************************************************
13 ;;;;
14 ;;;; Copyright (c) 2005 by David Steuber
15 ;;;;
16 ;;;; Permission is hereby granted, free of charge, to any person obtaining
17 ;;;; a copy of this software and associated documentation files (the
18 ;;;; "Software"), to deal in the Software without restriction, including
19 ;;;; without limitation the rights to use, copy, modify, merge, publish,
20 ;;;; distribute, sublicense, and/or sell copies of the Software, and to
21 ;;;; permit persons to whom the Software is furnished to do so, subject to
22 ;;;; the following conditions:
23 ;;;;
24 ;;;; The above copyright notice and this permission notice shall be
25 ;;;; included in all copies or substantial portions of the Software.
26 ;;;;
27 ;;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 ;;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 ;;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 ;;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 ;;;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 ;;;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 ;;;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 ;;;;
35 ;;;; ***********************************************************************
36
37 (in-package :cl-carbon)
38
39 (defclass window (event-target)
40 ((window-ptr :accessor window-ptr :initform nil
41 :documentation "The MACPTR that holds the Carbon WindowRef"))
42 (:documentation
43 "Proxy for a Carbon window"))
44
45 (defmethod initialize-instance :around ((w window) &rest initargs)
46 (let ((m "CARBON:WINDOW.INITIALIZE-INSTANCE :AROUND") v)
47 (debug-log "~A -- called with args ~S~%" m initargs)
48 (when (next-method-p)
49 (setf v (apply #'call-next-method (push w initargs))))
50 (debug-log "~A -- owner set to ~S~%" m (slot-value w 'owner))
51 (create-window w)
52 ;;
53 ;; TODO
54 ;;
55 ;; Need code here to deal with the possibility of create-window signaling a condition
56 ;; so that the window-ptr can be disposed of properly, eg tell OS X to destroy the
57 ;; window.
58 ;;
59 (with-slots (window-ptr) w
60 (install-event-handler w (#_GetWindowEventTarget window-ptr)
61 (get-event-type-specs w)))
62 v))
63
64 (defgeneric create-window (window)
65 (:documentation "Create the actual window"))
66
67 (defgeneric show-window (window))
68 (defgeneric hide-window (window))
69
70 (defmethod show-window ((w window))
71 (with-slots (window-ptr) w
72 (when window-ptr (#_ShowWindow window-ptr))))
73
74 (defmethod hide-window ((w window))
75 (with-slots (window-ptr) w
76 (when window-ptr (#_HideWindow window-ptr))))
77
78 (defgeneric window-closing (window)
79 (:documentation "Time to cleanup. The real window is closing."))
80
81 (defmethod window-closing ((w window))
82 (remove-event-handler w))
83
84 (defgeneric window-close (window)
85 (:documentation "Return true if allowed to close, else return false."))
86
87 (defmethod window-close ((w window))
88 t)
89
90 (defgeneric handle-window-close (window))
91 (defmethod handle-window-close ((w window))
92 (let ((can-close (window-close w)))
93 (if can-close
94 (progn
95 (window-closing w)
96 nil)
97 t)))
98
99 (defmethod handle-event ((w window)
100 (class (eql #$kEventClassWindow))
101 (kind (eql #$kEventWindowClose))
102 next-handler event user-data)
103 (declare (ignore next-handler event user-data))
104 (handle-window-close w))

  ViewVC Help
Powered by ViewVC 1.1.5