Setting spell-checker underlines

  • Is it possible to set the red wavy underline the spell checker sets,
    in an NSTextView?
    That is by not using NSSpellChecker. I want to do it in my Cocoa
    application.

    Is it set by NSAttributedString as an attribute?

    Ivan
  • On Jan 10, 2008 8:07 AM, Ivan C Myrvold <ivan...> wrote:
    > Is it possible to set the red wavy underline the spell checker sets,
    > in an NSTextView?
    > That is by not using NSSpellChecker. I want to do it in my Cocoa
    > application.

      Unless you're doing it for a misspelled word, don't use the red wavy
    line. It means *misspelled word*. Then again, if you're doing it for a
    misspelled word, just let the system do it.

    > Is it set by NSAttributedString as an attribute?

      No. Read the text system documentation. You can draw things on the
    text view itself, using the rect-for-range of the words you're
    interested in. It's not a property of the text itself, but rather
    drawing occurring behind the text on the view.

    --
    I.S.
  • On Jan 10, 2008, at 5:07 AM, Ivan C Myrvold wrote:

    > Is it possible to set the red wavy underline the spell checker sets,
    > in an NSTextView?
    > That is by not using NSSpellChecker. I want to do it in my Cocoa
    > application.
    >
    > Is it set by NSAttributedString as an attribute?

    It is a temporary attribute on the layout manager,
    NSSpellingStateAttributeName.  See the Leopard AppKit release notes
    for details.

    Douglas Davidson
  • > It is a temporary attribute on the layout manager,
    > NSSpellingStateAttributeName.  See the Leopard AppKit release notes
    > for details.

      Ah! I stand corrected, Douglas, thanks. My original point still
    remains, though - unless you're using it for misspelled words, you'll
    need to come up with your own marker. This means (unless I'm further
    mistaken), creating your own temporary attribute, setting it on the
    attributed string, then properly rendering it in the text view (which,
    IMO, is done most easily by drawing it on the text view itself via
    -drawViewBackgroundInRect:).

      If there's a better way, I welcome it.

    --
    I.S.
  • On Jan 10, 2008, at 9:45 AM, I. Savant wrote:

    > Ah! I stand corrected, Douglas, thanks. My original point still
    > remains, though - unless you're using it for misspelled words, you'll
    > need to come up with your own marker. This means (unless I'm further
    > mistaken), creating your own temporary attribute, setting it on the
    > attributed string, then properly rendering it in the text view (which,
    > IMO, is done most easily by drawing it on the text view itself via
    > -drawViewBackgroundInRect:).

    Yes, in general I would not recommend using the spelling indicator for
    purposes that diverge radically from its original signification.  If
    you need to do custom drawing of this sort that depends on the
    location of individual glyphs, it's probably easiest to do so by
    subclassing NSLayoutManager, and overriding one of its drawing
    methods.  I believe we have examples available of this technique.  The
    regions of text requiring special drawing can be indicated either by
    ordinary attributes on the text, or by temporary attributes on the
    layout manager, depending on the persistence of the attributes in
    question.

    Douglas Davidson
  • Den 10. jan.. 2008 kl. 18:37 skrev Douglas Davidson:

    >
    > On Jan 10, 2008, at 5:07 AM, Ivan C Myrvold wrote:
    >
    >> Is it possible to set the red wavy underline the spell checker
    >> sets, in an NSTextView?
    >> That is by not using NSSpellChecker. I want to do it in my Cocoa
    >> application.
    >>
    >> Is it set by NSAttributedString as an attribute?
    >
    > It is a temporary attribute on the layout manager,
    > NSSpellingStateAttributeName.  See the Leopard AppKit release notes
    > for details.
    >
    > Douglas Davidson
    >
    >
    Well, I am in fact using it for showing misspelled words.

    i found out reading more in the documentation that this worked:

    [oattributedTextView setSpellingState:1 range:elementRange];

    where oattributedTextView is the outlet of the NTextView.

    Ivan
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today