Changeset 6724


Ignore:
Timestamp:
Jun 14, 2007, 12:36:46 AM (17 years ago)
Author:
Gary Byers
Message:

Single defaults for background colors. (Not always working wrt preferences,
but that may be a Leopard bug.)
Maintain style vectors per textstorage.

File:
1 edited

Legend:

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

    r6718 r6724  
    2828(def-cocoa-default *editor-columns* :int 80 "Initial width of editor windows, in characters")
    2929
    30 ;;; Background color components: red, blue, green, alpha.
    31 ;;; All should be single-floats between 0.0f0 and 1.0f0, inclusive.
    32 (def-cocoa-default *editor-background-red-component* :float 1.0f0 "Red component of editor background color.  Should be a float between 0.0 and 1.0, inclusive.")
    33 (def-cocoa-default *editor-background-green-component* :float 1.0f0 "Green component of editor background color.  Should be a float between 0.0 and 1.0, inclusive.")
    34 (def-cocoa-default *editor-background-blue-component* :float 1.0f0 "Blue component of editor background color.  Should be a float between 0.0 and 1.0, inclusive.")
    35 (def-cocoa-default *editor-background-alpha-component* :float 1.0f0 "Alpha component of editor background color.  Should be a float between 0.0 and 1.0, inclusive.")
    36 
    37 ;;; At runtime, this'll be a vector of character attribute dictionaries.
    38 (defloadvar *styles* ())
     30(def-cocoa-default *editor-background-color* :color (#/whiteColor ns:ns-color) "Editor background color")
     31
    3932
    4033(defun make-editor-style-map ()
     
    5750                         (#/greenColor color-class)
    5851                         (#/yellowColor color-class)))
    59          (styles (make-array (the fixnum (* 4 (length colors)))))
     52         (styles (make-instance 'ns:ns-mutable-array
     53                                :with-capacity (the fixnum (* 4 (length colors)))))
    6054         (bold-stroke-width -10.0f0)
    6155         (fonts (vector font (or bold-font font) (or oblique-font font) (or bold-oblique-font font)))
     
    6660      (dotimes (i 4)
    6761        (let* ((mask (logand i 3)))
    68           (setf (svref styles s) (create-text-attributes :font (svref fonts mask)
    69                                                          :color (svref colors c)
    70                                                          :obliqueness
    71                                                          (if (logbitp 1 i)
    72                                                            (unless (svref real-fonts mask)
    73                                                              0.15f0))
    74                                                          :stroke-width
    75                                                          (if (logbitp 0 i)
    76                                                            (unless (svref real-fonts mask)
    77                                                              bold-stroke-width)))))
     62          (#/addObject: styles
     63                        (create-text-attributes :font (svref fonts mask)
     64                                                :color (svref colors c)
     65                                                :obliqueness
     66                                                (if (logbitp 1 i)
     67                                                  (unless (svref real-fonts mask)
     68                                                    0.15f0))
     69                                                :stroke-width
     70                                                (if (logbitp 0 i)
     71                                                  (unless (svref real-fonts mask)
     72                                                    bold-stroke-width)))))
    7873        (incf s)))
    79     (setq *styles* styles)))
     74    (#/retain styles)))
    8075
    8176(defun make-hemlock-buffer (&rest args)
     
    374369     (edit-count :foreign-type :int)
    375370     (append-edits :foreign-type :int)
    376      (cache :foreign-type :id))
     371     (cache :foreign-type :id)
     372     (styles :foreign-type :id))
    377373  (:metaclass ns:+ns-object))
    378374
     
    465461
    466462(objc:defmethod #/hemlockString ((self hemlock-text-storage))
    467 (slot-value self 'hemlock-string))
     463  (slot-value self 'hemlock-string))
     464
     465(objc:defmethod #/styles ((self hemlock-text-storage))
     466  (slot-value self 'styles))
    468467
    469468(objc:defmethod #/initWithString: ((self hemlock-text-storage) s)
    470469  (setq s (%inc-ptr s 0))
    471470  (let* ((newself (#/init self))
     471         (styles (make-editor-style-map))
    472472         (cache (#/retain (make-instance ns:ns-mutable-attributed-string
    473473                                   :with-string s
    474                                    :attributes (svref *styles* 0)))))
     474                                   :attributes (#/objectAtIndex: styles 0)))))
    475475    (declare (type hemlock-text-storage newself))
     476    (setf (slot-value newself 'styles) styles)
    476477    (setf (slot-value newself 'hemlock-string) s)
    477478    (setf (slot-value newself 'cache) cache)
     
    481482;;; Should generally only be called after open/revert.
    482483(objc:defmethod (#/updateCache :void) ((self hemlock-text-storage))
    483   (with-slots (hemlock-string cache) self
     484  (with-slots (hemlock-string cache styles) self
    484485    (#/replaceCharactersInRange:withString: cache (ns:make-ns-range 0 (#/length cache)) hemlock-string)
    485     (#/setAttributes:range: cache (svref *styles* 0) (ns:make-ns-range 0 (#/length cache)))))
     486    (#/setAttributes:range: cache (#/objectAtIndex: styles 0) (ns:make-ns-range 0 (#/length cache)))))
    486487
    487488;;; This is the only thing that's actually called to create a
     
    502503  #+debug
    503504  (#_NSLog #@"Attributes at index: %d storage %@" :unsigned index :id self)
    504   (with-slots (cache) self
     505  (with-slots (cache styles) self
    505506    (let* ((attrs (#/attributesAtIndex:effectiveRange: cache index rangeptr)))
    506507      (when (eql 0 (#/count attrs))
     
    509510          (#/attributesAtIndex:longestEffectiveRange:inRange:
    510511           cache index r (ns:make-ns-range 0 (#/length cache)))
    511           (setq attrs (svref *styles* 0))
     512          (setq attrs (#/objectAtIndex: styles 0))
    512513          (#/setAttributes:range: cache attrs r)))
    513514      attrs)))
     
    539540      (when textstorage
    540541        (#/endEditing textstorage)
    541         (for-each-textview-using-storage textstorage (lambda (tv)
    542                                                        (hi::disable-self-insert (hemlock-frame-event-queue (#/window tv)))))
     542        (for-each-textview-using-storage
     543         textstorage
     544         (lambda (tv)
     545           (hi::disable-self-insert
     546            (hemlock-frame-event-queue (#/window tv)))))
    543547        (#/ensureSelectionVisible textstorage)))))
    544548
     
    579583
    580584(defun close-hemlock-textstorage (ts)
     585  (declare (type hemlock-text-storage ts))
     586  (with-slots (styles) ts
     587    (#/release styles)
     588    (setq styles +null-ptr+))
    581589  (let* ((hemlock-string (slot-value ts 'hemlock-string)))
    582590    (setf (slot-value ts 'hemlock-string) +null-ptr+)
     591   
    583592    (unless (%null-ptr-p hemlock-string)
    584593      (let* ((cache (hemlock-buffer-string-cache hemlock-string))
     
    626635  (:metaclass ns:+ns-object))
    627636
     637(objc:defmethod (#/changeColor: :void) ((self hemlock-textstorage-text-view)
     638                                        sender)
     639  (#_NSLog #@"Change color to = %@" :id (#/color sender)))
    628640
    629641(def-cocoa-default *layout-text-in-background* :int 1 "When non-zero, do text layout when idle.")
     
    11531165                (#/setAutoresizingMask: tv #$NSViewWidthSizable)
    11541166                (#/setBackgroundColor: tv color)
    1155                 (#/setTypingAttributes: tv (aref *styles* style))
     1167                (#/setTypingAttributes: tv (#/objectAtIndex: (#/styles textstorage) style))
    11561168                (#/setSmartInsertDeleteEnabled: tv nil)
    11571169                (#/setAllowsUndo: tv nil) ; don't want NSTextView undo
    11581170                (#/setUsesFindPanel: tv t)
     1171                (#/setUsesFontPanel: tv t)
    11591172                (#/setWidthTracksTextView: container tracks-width)
    11601173                (#/setHeightTracksTextView: container nil)
     
    15941607    (let* ((document (hi::buffer-document buffer))
    15951608           (textstorage (if document (slot-value document 'textstorage)))
     1609           (styles (#/styles textstorage))
    15961610           (cache (#/cache textstorage))
    15971611           (pos (mark-absolute-position (hi::region-start region)))
    15981612           (n (- (mark-absolute-position (hi::region-end region)) pos)))
    15991613      #+debug
    1600       (#_NSLog #@"Setting font attributes for %d/%d to %@" :int pos :int n :id (svref *styles* font))
    1601       (#/setAttributes:range: cache (svref *styles* font) (ns:make-ns-range pos n))
     1614      (#_NSLog #@"Setting font attributes for %d/%d to %@" :int pos :int n :id (#/objectAtIndex: styles font))
     1615      (#/setAttributes:range: cache (#/objectAtIndex: styles font) (ns:make-ns-range pos n))
    16021616      (perform-edit-change-notification textstorage
    16031617                                        (@selector #/noteAttrChange:)
     
    16071621(defun buffer-active-font (buffer)
    16081622  (let* ((style 0)
    1609          (region (hi::buffer-active-font-region buffer)))
     1623         (region (hi::buffer-active-font-region buffer))
     1624         (textstorage (slot-value (hi::buffer-document buffer) 'textstorage))
     1625         (styles (#/styles textstorage)))
    16101626    (when region
    16111627      (let* ((start (hi::region-end region)))
    16121628        (setq style (hi::font-mark-font start))))
    1613     (svref *styles* style)))
     1629    (#/objectAtIndex: styles style)))
    16141630     
    16151631(defun hi::buffer-note-insertion (buffer mark n)
     
    18021818
    18031819(defmethod textview-background-color ((doc hemlock-editor-document))
    1804   (#/colorWithCalibratedRed:green:blue:alpha: ns:ns-color
    1805                                               (float *editor-background-red-component*
    1806                                                      +cgfloat-zero+)
    1807                                               (float *editor-background-green-component* +cgfloat-zero+)
    1808                                               (float *editor-background-blue-component* +cgfloat-zero+)
    1809                                               (float *editor-background-alpha-component* +cgfloat-zero+)))
     1820  *editor-background-color*)
    18101821
    18111822
     
    19841995           (buffer (hemlock-document-buffer self)))
    19851996      (case (when buffer (hi::buffer-line-termination buffer))
    1986         (:cp/m (setq string (#/stringByReplacingOccurrencesOfString:withString:
    1987                              string *ns-lf-string* *ns-crlf-string*)))
    1988         (:macos (setq string (#/stringByReplacingOccurrencesOfString:withString:
    1989                              string *ns-lf-string* *ns-cr-string*))))
     1997        (:cp/m (unless (typep string 'ns:ns-mutable-string)
     1998                 (setq string (make-instance 'ns:ns-mutable-string :with string string))
     1999               (#/replaceOccurrencesOfString:withString:options:range:
     2000                string *ns-lf-string* *ns-crlf-string* #$NSLiteralSearch (ns:make-ns-range 0 (#/length string)))))
     2001        (:macos (setq string (if (typep string 'ns:ns-mutable-string)
     2002                              string
     2003                              (make-instance 'ns:ns-mutable-string :with string string)))
     2004                (#/replaceOccurrencesOfString:withString:options:range:
     2005                string *ns-lf-string* *ns-cr-string* #$NSLiteralSearch (ns:make-ns-range 0 (#/length string)))))
    19902006      (when (#/writeToURL:atomically:encoding:error:
    19912007             string url t encoding error)
     
    21932209(defun initialize-user-interface ()
    21942210  (#/sharedDocumentController hemlock-document-controller)
    2195   (#/sharedPanel preferences-panel)
    2196   (update-cocoa-defaults)
     2211  (#/sharedPanel lisp-preferences-panel)
    21972212  (make-editor-style-map))
    21982213
     
    22712286    (unless (%null-ptr-p string)
    22722287      (unless (zerop (ns:ns-range-length (#/rangeOfString: string *ns-cr-string*)))
    2273         (setq string (#/stringByReplacingOccurrencesOfString:withString: string *ns-cr-string* *ns-lf-string*)))
     2288        (unless (typep string 'ns:ns-mutable-string)
     2289          (setq string (make-instance 'ns:ns-mutable-string :with-string string)))
     2290        (#/replaceOccurrencesOfString:withString:options:range:
     2291                string *ns-cr-string* *ns-lf-string* #$NSLiteralSearch (ns:make-ns-range 0 (#/length string))))
    22742292      (let* ((textstorage (#/textStorage self))
    22752293             (selectedrange (#/selectedRange self)))
Note: See TracChangeset for help on using the changeset viewer.