source: release/1.5/source/contrib/krueger/InterfaceProjects/Simple Sum/simplesum.lisp

Last change on this file was 13646, checked in by R. Matthew Emerson, 15 years ago

Merge r13631, r13636 from trunk. (Paul Krueger's updated InterfaceProjects
contrib; fix for ticket:652)

File size: 3.2 KB
Line 
1;;; simplesum.lisp
2
3#|
4The MIT license.
5
6Copyright (c) 2009 Paul L. Krueger
7
8Permission is hereby granted, free of charge, to any person obtaining a copy of this software
9and associated documentation files (the "Software"), to deal in the Software without restriction,
10including without limitation the rights to use, copy, modify, merge, publish, distribute,
11sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all copies or substantial
15portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23|#
24
25;;; Sample lisp/Cocoa interface that uses a NIB file defined with interface builder;
26;;; A definition is provided for the "Foo" class that was specified to interface builder
27;;; so that when the NIB file is loaded an instance of that class will be created and
28;;; linked appropriately to the input fields, output sum text field, and Sum button.
29;;; When the Sum button is pushed the sum will be computed and placed into the sum
30;;; field in the window.
31
32(eval-when (:compile-toplevel :load-toplevel :execute)
33 (require :nib))
34
35(defpackage :simplesum
36 (:nicknames :ss)
37 (:use :iu :ccl :common-lisp)
38 (:export test-sum))
39
40(in-package :simplesum)
41
42(defvar *debug-sum* nil)
43
44(defclass sum-window-owner (ns:ns-object)
45 ((input1 :foreign-type :id
46 :accessor input1)
47 (input2 :foreign-type :id
48 :accessor input2)
49 (sum :foreign-type :id
50 :accessor sum)
51 (nib-objects :accessor nib-objects :initform nil))
52 (:metaclass ns:+ns-object))
53
54(defmethod initialize-instance :after ((self sum-window-owner)
55 &key &allow-other-keys)
56 (setf (nib-objects self)
57 (load-nibfile
58 (truename "ip:Simple Sum;sumLisp.nib")
59 :nib-owner self
60 :retain-top-objs t))
61 ;; we do the following so that ccl:terminate will be called before we are garbage
62 ;; collected and we can release the top-level objects from the NIB that we retained
63 ;; when loaded
64 (ccl:terminate-when-unreachable self))
65
66(defmethod ccl:terminate ((self sum-window-owner))
67 (dolist (top-obj (nib-objects self))
68 (unless (eql top-obj (%null-ptr))
69 (#/release top-obj))))
70
71;; methods called as a result of button actions
72
73(objc:defmethod (#/doSum: :void)
74 ((self sum-window-owner) (s :id))
75 (declare (ignore s))
76 (with-slots (input1 input2 sum) self
77 (#/setIntValue: sum (+ (#/intValue input1) (#/intValue input2)))))
78
79(objc:defmethod (#/doFirstThing :void)
80 ((self sum-window-owner) (s :id))
81 (declare (ignore s))
82 ;;; test function for menu tests
83 (#/doSum: self (%null-ptr)))
84
85;; test by
86(defun test-sum ()
87 (make-instance 'sum-window-owner))
88
89(provide :simplesum)
Note: See TracBrowser for help on using the repository browser.