source: trunk/source/contrib/krueger/InterfaceProjects/Loan Document/loan-window-controller.lisp @ 13390

Last change on this file since 13390 was 13390, checked in by plkrueger, 11 years ago

New contrib from Paul Krueger

File size: 4.3 KB
Line 
1;;; loan-window-controller.lisp
2
3#|
4The MIT license.
5
6Copyright (c) 2010 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 "SpeechController" class that was specified to interface builder
27;;; as the class of the NIB file owner.
28;;; We manually create an instance of SpeechController and specify it as the owner for the NIB file.
29
30(defpackage :loan-document
31  (:nicknames :lnd)
32  (:use :iu :ccl :common-lisp))
33
34(in-package :lnd)
35
36;; The loan-win-controller class
37
38(defclass loan-win-controller (ns:ns-window-controller)
39  ((loan :foreign-type :id :accessor loan)
40   (orig-date-text :foreign-type :id :accessor orig-date-text)
41   (loan-text :foreign-type :id :accessor loan-text)
42   (int-text :foreign-type :id :accessor int-text)
43   (dur-text :foreign-type :id :accessor dur-text)
44   (pay-text :foreign-type :id :accessor pay-text)
45   (int-slider :foreign-type :id :accessor int-slider)
46   (dur-slider :foreign-type :id :accessor dur-slider)
47   (pay-slider :foreign-type :id :accessor pay-slider))
48  (:metaclass ns:+ns-object))
49
50(objc:defmethod (#/initWithLoan: :id)
51                ((self loan-win-controller) (ln :id))
52  (setf (loan self) ln)
53  (let* ((nib-name (ccl::%make-nsstring 
54                    (namestring (truename "ip:Loan Document;loandoc.nib"))))
55         (init-self (#/initWithWindowNibPath:owner: self nib-name self)))
56    init-self))
57
58;; Action methods that are called when controls do something
59
60(objc:defmethod (#/buttonPushed: :void) 
61                ((self loan-win-controller) (button-matrix :id))
62  (with-slots (loan loan-text int-text dur-text pay-text int-slider 
63                    dur-slider pay-slider) self
64    (let ((cm (#/selectedRow button-matrix)))
65      (unless (eql cm (compute-mode loan))
66        (case (compute-mode loan)
67          (0 (#/setEnabled: loan-text #$YES))
68          (1 (#/setEnabled: int-text #$YES)
69             (#/setEnabled: int-slider #$YES))
70          (2 (#/setEnabled: dur-text #$YES)
71             (#/setEnabled: dur-slider #$YES))
72          (3 (#/setEnabled: pay-text #$YES)
73             (#/setEnabled: pay-slider #$YES)))
74        (setf (compute-mode loan) cm)
75        (case cm
76          (0 (#/setEnabled: loan-text #$NO))
77          (1 (#/setEnabled: int-text #$NO)
78             (#/setEnabled: int-slider #$NO))
79          (2 (#/setEnabled: dur-text #$NO)
80             (#/setEnabled: dur-slider #$NO))
81          (3 (#/setEnabled: pay-text #$NO)
82             (#/setEnabled: pay-slider #$NO)))
83        (compute-new-loan-values loan)))))
84
85(objc:defmethod (#/awakeFromNib :void) 
86                ((self loan-win-controller))
87  (#/setEnabled: (loan-text self) #$NO)
88  ;; set the sliders to update continuously so that the text boxes reflect the current value
89  ;; Note that we can set this in IB for text boxes, but not, apparently, for sliders
90  (#/setContinuous: (int-slider self) #$YES)
91  (#/setContinuous: (dur-slider self) #$YES)
92  (#/setContinuous: (pay-slider self) #$YES)
93  ;; tell the text cells not to handle undo
94  (#/setAllowsUndo: (#/cell (loan-text self)) #$NO)
95  (#/setAllowsUndo: (#/cell (int-text self)) #$NO)
96  (#/setAllowsUndo: (#/cell (dur-text self)) #$NO)
97  (#/setAllowsUndo: (#/cell (pay-text self)) #$NO)
98  (#/setAllowsUndo: (#/cell (orig-date-text self)) #$NO))
Note: See TracBrowser for help on using the repository browser.