Changeset 6668


Ignore:
Timestamp:
Jun 3, 2007, 3:04:25 AM (17 years ago)
Author:
Gary Byers
Message:

Use negative stroke width.
"Random" insertions are enqueued to the window thread. Need to think harder
about where to insert in listener.
Don't pass command-key events to Hemlock.
Do #/paste ourselves, to get font sane and to handle embedded #\returns
(from Carbon apps.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ide-1.0/ccl/examples/cocoa-editor.lisp

    r6622 r6668  
    1 ;;-*- Mode: LISP; Package: CCL -*-
     1;;;-*- Mode: LISP; Package: CCL -*-
    22
    33
     
    5858                         (#/yellowColor color-class)))
    5959         (styles (make-array (the fixnum (* 4 (length colors)))))
    60          (bold-stroke-width 8.5f0)
     60         (bold-stroke-width -10.0f0)
    6161         (fonts (vector font (or bold-font font) (or oblique-font font) (or bold-oblique-font font)))
    6262         (real-fonts (vector font bold-font oblique-font bold-oblique-font))
     
    575575(objc:defmethod (#/replaceCharactersInRange:withString: :void)
    576576    ((self hemlock-text-storage) (r :<NSR>ange) string)
     577  #+debug 0 (#_NSLog #@"Replace in range %ld/%ld with %@"
     578                   :<NSI>nteger (pref r :<NSR>ange.location)
     579                   :<NSI>nteger (pref r :<NSR>ange.length)
     580                   :id string)
    577581  (let* ((cache (hemlock-buffer-string-cache (#/string  self)))
    578582         (buffer (if cache (buffer-cache-buffer cache)))
     
    602606            (t
    603607             (move-hemlock-mark-to-absolute-position point cache location))))
    604     (hi::insert-string point (lisp-string-from-nsstring string))))
     608    (let* ((lisp-string (lisp-string-from-nsstring string)))
     609      (hi::enqueue-buffer-operation
     610       buffer
     611       #'(lambda ()
     612           (unwind-protect
     613                (progn
     614                  (hi::buffer-document-begin-editing buffer)
     615                  (hi::insert-string point lisp-string))
     616             (hi::buffer-document-end-editing buffer)))))))
    605617
    606618
     
    784796    ((pane :foreign-type :id :accessor text-view-pane))
    785797  (:metaclass ns:+ns-object))
     798
     799
     800
     801
    786802
    787803;;; Access the underlying buffer in one swell foop.
     
    837853;;; Translate a keyDown NSEvent to a Hemlock key-event.
    838854(defun nsevent-to-key-event (nsevent)
    839   (let* ((unmodchars (#/charactersIgnoringModifiers nsevent))
    840          (n (if (%null-ptr-p unmodchars)
    841               0
    842               (#/length unmodchars)))
    843          (c (if (eql n 1)
    844               (#/characterAtIndex: unmodchars 0))))
    845     (when c
    846       (let* ((bits 0)
    847              (modifiers (#/modifierFlags nsevent))
    848              (useful-modifiers (logandc2 modifiers
    849                                          (logior #$NSShiftKeyMask
    850                                                  #$NSAlphaShiftKeyMask))))
    851         (dolist (map hemlock-ext::*modifier-translations*)
    852           (when (logtest useful-modifiers (car map))
    853             (setq bits (logior bits (hemlock-ext::key-event-modifier-mask
    854                                      (cdr map))))))
    855         (hemlock-ext::make-key-event c bits)))))
     855  (let* ((modifiers (#/modifierFlags nsevent)))
     856    (unless (logtest #$NSCommandKeyMask modifiers)
     857      (let* ((unmodchars (#/charactersIgnoringModifiers nsevent))
     858             (n (if (%null-ptr-p unmodchars)
     859                  0
     860                  (#/length unmodchars)))
     861             (c (if (eql n 1)
     862                  (#/characterAtIndex: unmodchars 0))))
     863        (when c
     864          (let* ((bits 0)
     865                 (useful-modifiers (logandc2 modifiers
     866                                             (logior #$NSShiftKeyMask
     867                                                     #$NSAlphaShiftKeyMask))))
     868            (dolist (map hemlock-ext::*modifier-translations*)
     869              (when (logtest useful-modifiers (car map))
     870                (setq bits (logior bits (hemlock-ext::key-event-modifier-mask
     871                                         (cdr map))))))
     872            (hemlock-ext::make-key-event c bits)))))))
    856873
    857874(defun pass-key-down-event-to-hemlock (self event)
     
    860877  (let* ((buffer (text-view-buffer self)))
    861878    (when buffer
    862       (let* ((q (hemlock-frame-event-queue (#/window self))))
    863         (hi::enqueue-key-event q (nsevent-to-key-event event))))))
    864 
    865 (defun enqueue-buffer-operation (buffer thunk)
     879      (let* ((hemlock-event (nsevent-to-key-event event)))
     880        (when hemlock-event
     881          (let* ((q (hemlock-frame-event-queue (#/window self))))
     882            (hi::enqueue-key-event q hemlock-event)))))))
     883
     884(defun hi::enqueue-buffer-operation (buffer thunk)
    866885  (dolist (w (hi::buffer-windows buffer))
    867886    (let* ((q (hemlock-frame-event-queue (#/window w)))
     
    11731192                (#/setBackgroundColor: tv color)
    11741193                (#/setSmartInsertDeleteEnabled: tv nil)
     1194                (#/setAllowsUndo: tv t)
    11751195                (#/setUsesFindPanel: tv t)
    11761196                (#/setWidthTracksTextView: container tracks-width)
     
    13301350  (let* ((message (#/objectAtIndex: info 0))
    13311351         (signal (#/objectAtIndex: info 1)))
    1332     (#_NSLog #@"runErrorSheet: signal = %@" :id signal)
     1352    #+debug (#_NSLog #@"runErrorSheet: signal = %@" :id signal)
    13331353    (#_NSBeginAlertSheet #@"Error in Hemlock command processing" ;title
    13341354                         (if (logbitp 0 (random 2))
     
    22032223    #+debug
    22042224    (#_NSLog #@"update Hemlock selection: charpos = %d, abspos = %d"
    2205              :int (hi::mark-charpos point) :int pos)
     2225             :int (hi::mark-charpos point) :int pointpos)
    22062226    (for-each-textview-using-storage
    22072227     self
     
    22432263     *nsapp* (@selector #/stringToPasteBoard:) (%make-nsstring string) t)))
    22442264
     2265;;; The default #/paste method seems to want to set the font to
     2266;;; something ... inappropriate.  If we can figure out why it
     2267;;; does that and persuade it not to, we wouldn't have to do
     2268;;; this here.
     2269;;; (It's likely to also be the case that Carbon applications
     2270;;; terminate lines with #\Return when writing to the clipboard;
     2271;;; we may need to continue to override this method in order to
     2272;;; fix that.)
     2273(objc:defmethod (#/paste: :void) ((self hemlock-text-view) sender)
     2274  (declare (ignorable sender))
     2275  #+debug (#_NSLog #@"Paste: sender = %@" :id sender)
     2276  (let* ((pb (general-pasteboard))
     2277         (string (progn (#/types pb) (#/stringForType: pb #&NSStringPboardType))))
     2278    (unless (%null-ptr-p string)
     2279      (unless (zerop (ns:ns-range-length (#/rangeOfString: string *ns-cr-string*)))
     2280        (setq string (#/stringByReplacingOccurrencesOfString:withString: string *ns-cr-string* *ns-lf-string*)))
     2281      (let* ((textstorage (#/textStorage self))
     2282             (selectedrange (#/selectedRange self)))
     2283        (#/replaceCharactersInRange:withString: textstorage selectedrange string)))))
     2284
    22452285           
    22462286     
Note: See TracChangeset for help on using the changeset viewer.