Changeset 6151


Ignore:
Timestamp:
Apr 7, 2007, 12:44:41 PM (13 years ago)
Author:
gb
Message:

Use ns:with-... instead of rlet/ns:init.
Translate the one struct-returning method to use objc:defmethod and
the new scheme.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/objc-gf/ccl/examples/cocoa-editor.lisp

    r6130 r6151  
    434434
    435435(defun textstorage-note-insertion-at-position (self pos n)
    436   (rlet ((r :ns-range))
    437     (ns:init-ns-range r pos 0)
     436  (ns:with-ns-range (r pos 0)
    438437    (#/edited:range:changeInLength: self #$NSTextStorageEditedAttributes r n)
    439438    (setf (ns:ns-range-length r) n)
     
    681680        ;; The blinked character should be "on" whenever the insertion
    682681        ;; point is drawn as "off"
    683         (rlet  ((char-range :ns-range))
    684           (ns:init-ns-range char-range (text-view-blink-location self) 1)
     682        (ns:with-ns-range  (char-range (text-view-blink-location self) 1)
    685683          (let* ((glyph-range (#/glyphRangeForCharacterRange:actualCharacterRange:
    686684                               layout
     
    773771  (call-next-method) s)
    774772
    775 (define-objc-method (((:struct :_<NSR>ange r)
    776                       :selection-range-for-proposed-range (:<NSR>ange proposed)
    777                       :granularity (:<NSS>election<G>ranularity g))
    778                      hemlock-textstorage-text-view)
     773(objc:defmethod (#/selectionRangeForProposedRange:granularity: :ns-range)
     774    ((self hemlock-textstorage-text-view)
     775     (proposed :ns-range)
     776     (g :<NSS>election<G>ranularity))
    779777  #+debug
    780778  (#_NSLog #@"Granularity = %d" :int g)
    781   (block HANDLED
    782     (let* ((index (pref proposed :<NSR>ange.location))
    783            (length (pref proposed :<NSR>ange.length)))
     779  (objc:returning-foreign-struct (r)
     780    (block HANDLED
     781      (let* ((index (ns:ns-range-location proposed))             
     782             (length (ns:ns-range-length proposed)))
    784783      (when (and (eql 0 length)              ; not extending existing selection
    785784                 (not (eql g #$NSSelectByCharacter)))
    786785        (let* ((textstorage (#/textStorage self))
    787                (cache (hemlock-buffer-string-cache (send textstorage 'string)))
     786               (cache (hemlock-buffer-string-cache (#/string textstorage)))
    788787               (buffer (if cache (buffer-cache-buffer cache))))
    789788          (when (and buffer (string= (hi::buffer-major-mode buffer) "Lisp"))
     
    796795                         (hi::with-mark ((m2 m1))
    797796                           (when (hemlock::list-offset m2 1)
    798                              (setf (pref r :<NSR>ange.location) index
    799                                    (pref r :<NSR>ange.length)
    800                                    (- (mark-absolute-position m2) index))
    801                              (return-from HANDLED nil))))
     797                             (ns:init-ns-range r index (- (mark-absolute-position m2) index))
     798                             (return-from HANDLED r))))
    802799                        ((eql (hi::previous-character m1) #\))
    803800                         (hi::with-mark ((m2 m1))
    804801                           (when (hemlock::list-offset m2 -1)
    805                              (setf (pref r :<NSR>ange.location)
    806                                    (mark-absolute-position m2)
    807                                    (pref r :<NSR>ange.length)
    808                                    (- index (mark-absolute-position m2)))
    809                              (return-from HANDLED nil))))))))))))
    810     (send-super/stret r
    811                       :selection-range-for-proposed-range proposed
    812                       :granularity g)
    813     #+debug
    814     (#_NSLog #@"range = %@, proposed = %@, granularity = %d"
    815              :address (#_NSStringFromRange r)
    816              :address (#_NSStringFromRange proposed)
    817              :<NSS>election<G>ranularity g)))
     802                             (ns:init-ns-range r (mark-absolute-position m2) (- index (mark-absolute-position m2)))
     803                             (return-from HANDLED r))))))))))))
     804      (call-next-method proposed g)
     805      #+debug
     806      (#_NSLog #@"range = %@, proposed = %@, granularity = %d"
     807               :address (#_NSStringFromRange r)
     808               :address (#_NSStringFromRange proposed)
     809               :<NSS>election<G>ranularity g))))
     810
     811 
     812
    818813
    819814;;; Translate a keyDown NSEvent to a Hemlock key-event.
     
    10701065;;; so that the clipview is always scrolled in character-sized increments.
    10711066#+doesnt-work-yet
    1072 (define-objc-method ((:void :scroll-clip-view clip-view :to-point (:<NSP>oint p))
    1073                      modeline-scroll-view)
     1067(objc:defmethod (#/scrollClipView:toPoint: :void)
     1068    ((self modeline-scroll-view)
     1069     clip-view
     1070     (p :ns-point))
    10741071  #+debug
    10751072  (#_NSLog #@"Scrolling to point %@" :id (#_NSStringFromPoint p))
    1076  
    10771073  (let* ((char-height (#/verticalLineScroll self)))
    1078     (slet ((proposed (ns-make-point (pref p :<NSP>oint.x)
    1079                                          (* char-height
    1080                                             (round (pref p :<NSP>oint.y)
    1081                                                     char-height)))))
     1074    (ns:with-ns-point (proposed (ns:ns-point-x p) (* char-height (round (ns:ns-point-y p) char-height)))
    10821075    #+debug
    10831076    (#_NSLog #@" Proposed point = %@" :id
    10841077             (#_NSStringFromPoint proposed)))
    1085     (send-super :scroll-clip-view clip-view
    1086                 :to-point p #+nil (ns-make-point (pref p :<NSP>oint.x)
    1087                                          (* char-height
    1088                                             (ffloor (pref p :<NSP>oint.y)
    1089                                                     char-height))))))
     1078    (call-next-method clip-view proposed)))
    10901079
    10911080
     
    11431132      (#/release layout)
    11441133      (let* ((contentsize (#/contentSize scrollview)))
    1145         (rlet ((containersize :ns-size)
    1146                (tv-frame :ns-rect))
    1147           (ns:init-ns-size containersize large-number-for-text large-number-for-text)
    1148           (ns:init-ns-rect tv-frame 0 0 (ns:ns-size-width contentsize) (ns:ns-size-height contentsize))
    1149           (let* ((container (#/autorelease (make-instance
    1150                                             'ns:ns-text-container
    1151                                             :with-container-size containersize))))
    1152             (#/addTextContainer: layout  container)
    1153             (let* ((tv (#/autorelease (make-instance 'hemlock-text-view
    1154                                                      :with-frame tv-frame
    1155                                                      :text-container container))))
    1156               (#/setDelegate: layout tv)
    1157               (#/setMinSize: tv (ns:make-ns-size 0 (ns:ns-size-height contentsize)))
    1158               (#/setMaxSize: tv (ns:make-ns-size large-number-for-text large-number-for-text))
    1159               (#/setRichText: tv nil)
    1160               (#/setHorizontallyResizable: tv t)
    1161               (#/setVerticallyResizable: tv t)
    1162               (#/setAutoresizingMask: tv #$NSViewWidthSizable)
    1163               (#/setBackgroundColor: tv color)
    1164               (#/setSmartInsertDeleteEnabled: tv nil)
    1165               (#/setWidthTracksTextView: container tracks-width)
    1166               (#/setHeightTracksTextView: container nil)
    1167               (#/setDocumentView: scrollview tv)             
    1168               (values tv scrollview))))))))
     1134        (ns:with-ns-size (containersize large-number-for-text large-number-for-text)
     1135          (ns:with-ns-rect (tv-frame 0 0 (ns:ns-size-width contentsize) (ns:ns-size-height contentsize))
     1136            (ns:init-ns-size containersize large-number-for-text large-number-for-text)
     1137            (ns:init-ns-rect tv-frame 0 0 (ns:ns-size-width contentsize) (ns:ns-size-height contentsize))
     1138            (let* ((container (#/autorelease (make-instance
     1139                                              'ns:ns-text-container
     1140                                              :with-container-size containersize))))
     1141              (#/addTextContainer: layout  container)
     1142              (let* ((tv (#/autorelease (make-instance 'hemlock-text-view
     1143                                                       :with-frame tv-frame
     1144                                                       :text-container container))))
     1145                (#/setDelegate: layout tv)
     1146                (#/setMinSize: tv (ns:make-ns-size 0 (ns:ns-size-height contentsize)))
     1147                (#/setMaxSize: tv (ns:make-ns-size large-number-for-text large-number-for-text))
     1148                (#/setRichText: tv nil)
     1149                (#/setHorizontallyResizable: tv t)
     1150                (#/setVerticallyResizable: tv t)
     1151                (#/setAutoresizingMask: tv #$NSViewWidthSizable)
     1152                (#/setBackgroundColor: tv color)
     1153                (#/setSmartInsertDeleteEnabled: tv nil)
     1154                (#/setWidthTracksTextView: container tracks-width)
     1155                (#/setHeightTracksTextView: container nil)
     1156                (#/setDocumentView: scrollview tv)           
     1157                (values tv scrollview)))))))))
    11691158
    11701159(defun make-scrolling-textview-for-pane (pane textstorage track-width color)
     
    14321421  (let* ((window-content-view (#/contentView w))
    14331422         (window-frame (#/frame window-content-view)))
    1434     (rlet ((pane-rect ns-rect))
    1435       (ns:init-ns-rect pane-rect 0 reserve-below (ns:ns-rect-width window-frame) (- (ns:ns-rect-height window-frame) (+ reserve-above reserve-below)))
     1423    (ns:with-ns-rect (pane-rect  0 reserve-below (ns:ns-rect-width window-frame) (- (ns:ns-rect-height window-frame) (+ reserve-above reserve-below)))
    14361424      (let* ((pane (make-instance 'text-pane :with-frame pane-rect)))
    14371425        (#/addSubview: window-content-view pane)
     
    17601748         (has-horizontal-scroller (#/hasHorizontalScroller scrollview))
    17611749         (has-vertical-scroller (#/hasVerticalScroller scrollview)))
    1762     (rlet ((tv-size :ns-size))
    1763       (ns:init-ns-size tv-size
    1764                        (+ width (* 2 (#/lineFragmentPadding (#/textContainer tv))))
    1765                        height)
     1750    (ns:with-ns-size (tv-size
     1751                      (+ width (* 2 (#/lineFragmentPadding (#/textContainer tv))))
     1752                      height)
    17661753      (when has-vertical-scroller
    17671754        (#/setVerticalLineScroll: scrollview char-height)
     
    19711958    (#/addWindowController: self controller)
    19721959    (#/release controller)
    1973     (rlet ((current-point :ns-point))
    1974       (ns:init-ns-point current-point
     1960    (ns:with-ns-point  (current-point
    19751961                        (or *next-editor-x-pos*
    19761962                            *initial-editor-x-pos*)
Note: See TracChangeset for help on using the changeset viewer.