Text character under the mouse cursor in an NSTextView

  • In my application, I have a NSTextView that contains both japanese
    characters and english ones. I would like to know if there was a way
    to get only the japanese character (not an english one, or
    punctuation) that is under the mouse cursor, and for it to update
    when the cursor is moved, in that one NSTextView, so I can show it in
    big in another window, kind of like the dictionary app does.
    Is it also possible to get the location of that character?
    --
    The world's biggest Apple fan,
    Dimitri Bouniol
    <dimitri008...>
  • Good day!
    You can get the location of the character under mouse cursor with
    NSTextView's characterIndexForPoint:[NSEvent mouseLocation].
    Just subclass it to catch mouse events. And after getting the character
    you may check whether it is English of Hiragana/Katakana/CJK Unified
    Ideograms, but I do not know whether Cocoa has any convenient ways to
    do it. Anyhow, you may use Unicode ranges. For example, CJK Unified
    ideographs (most Chinese/Japanese/Korean characters) are 4e00 to 9fa5
    as I can see in the Character Palette.

    Yours sincerely,
    Three-eyed Fish

    On Oct 22, 2006, at 01:09, Dimitri Bouniol wrote:

    > In my application, I have a NSTextView that contains both japanese
    > characters and english ones. I would like to know if there was a way
    > to get only the japanese character (not an english one, or
    > punctuation) that is under the mouse cursor, and for it to update when
    > the cursor is moved, in that one NSTextView, so I can show it in big
    > in another window, kind of like the dictionary app does.
    > Is it also possible to get the location of that character?
    > --
    > The world's biggest Apple fan,
    > Dimitri Bouniol
    > <dimitri008...>
    >
    >
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/
    > <threeeyedfish...>
    >
    > This email sent to <threeeyedfish...>
    >
  • On Oct 22, 2006, at 12:10 AM, Damian Terentyev wrote:

    > You can get the location of the character under mouse cursor with
    > NSTextView's characterIndexForPoint:[NSEvent mouseLocation].
    > Just subclass it to catch mouse events. And after getting the
    > character you may check whether it is English of Hiragana/Katakana/
    > CJK Unified Ideograms, but I do not know whether Cocoa has any
    > convenient ways to do it. Anyhow, you may use Unicode ranges. For
    > example, CJK Unified ideographs (most Chinese/Japanese/Korean
    > characters) are 4e00 to 9fa5 as I can see in the Character Palette.

    I generally recommend not using characterIndexForPoint: for anything
    other than the input method purposes it is intended for.  Take a look
    at the MouseOverTextView class in the LayoutManagerDemo sample code;
    I believe that should be pretty much directly on point here.

    Douglas Davidson
  • Good day!
    I wanted to see the mentioned example, but is seems to be absent in my
    examples folder (On 10.3).
    If it doesn't use any 10.4-specific features, maybe you could probably
    send it to me, if you don't mind?

    Yours sincerely,
    Damian/Three-eyed Fish

    On Oct 23, 2006, at 20:22, Douglas Davidson wrote:

    >
    > On Oct 22, 2006, at 12:10 AM, Damian Terentyev wrote:
    >
    >> You can get the location of the character under mouse cursor with
    >> NSTextView's characterIndexForPoint:[NSEvent mouseLocation].
    >> Just subclass it to catch mouse events. And after getting the
    >> character you may check whether it is English of
    >> Hiragana/Katakana/CJK Unified Ideograms, but I do not know whether
    >> Cocoa has any convenient ways to do it. Anyhow, you may use Unicode
    >> ranges. For example, CJK Unified ideographs (most
    >> Chinese/Japanese/Korean characters) are 4e00 to 9fa5 as I can see in
    >> the Character Palette.
    >
    > I generally recommend not using characterIndexForPoint: for anything
    > other than the input method purposes it is intended for.  Take a look
    > at the MouseOverTextView class in the LayoutManagerDemo sample code; I
    > believe that should be pretty much directly on point here.
    >
    > Douglas Davidson
    >
  • The reason you couldn't find it is because it's online. :)

    http://developer.apple.com/samplecode/LayoutManagerDemo/index.html

    That is the second place I look when trying to locate sample code. on
    Apple site.

    Cheers, Alan

    --
    // Quotes from yours truly -------------------------
    "You don't forget, you just don't remember."
    "Maturity resides in the mind."
    "Silence is the Universe's greatest gift."
    "When the World realizes that religion really is unimportant, then it
    shall evolve."
  • On Oct 24, 2006, at 12:33 AM, Damian Terentyev wrote:

    > I wanted to see the mentioned example, but is seems to be absent in
    > my examples folder (On 10.3).
    > If it doesn't use any 10.4-specific features, maybe you could
    > probably send it to me, if you don't mind?

    This is one of the samples available at developer.apple.com.

    Douglas Davidson
previous month october 2006 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