HandlingAccentedCharacters
last edited February 9, 2007 19:32:19 (144.134.225.244)
| |
|---|---|
| Edit / History / New / Search | Quick Links: Home / Recent Changes / Glossary / Jobs / Forums / Help |
|
My app needs to store individual letters for which I'm using NSStrings?. This works great for single character letters but doesn't handle accented characters correctly. Is there an easy way to treat accented characters as single entities? I looked at NSString's -precomposedStringWithCanonicalMapping which appears to convert the decomposed form to the composed form, but it wasn't that simple (is it ever ;-).
Basically I have an -insertText: method in my class which receives the typed input from the user via the usual route (keyDown, which calls interpretKeyEvents). Accented characters arrive as separate events... so I guess my question is how do I correctly coalesce these events into a single precomposed string for accented characters? (GrahamCox) here's what I tried first - this is part of my -keyDown: method where <evt> is the event parameter I'm passed. (It doesn't help, though it's a slight improvement in that it at least ignores the dead key event):
OK, more digging... seems this falls into the category of a custom view that isn't a text view but which needs to support the NSTextInput? protocol. According to the Cocoa docs this seems to be classified as a "very advanced topic". That's pretty sucky - surely it shouldn't be this hard :( This protocol seems to assume that the text is stored in a block and that the view will be doing some layout on it. Neither of these things is true in my case (it's a crossword puzzle grid for the curious - naturally it stores "text" as individual letters in cells). Whether I can bend the protocol to my will without a major redesign I don't know... if I come up with anything I'll post it here. Depressed.
If you use
The problem is I don't have a composed string to begin with. Each typing event arrives separately, so e.g. option-e, e arrive as two events. -
Ah, I see the problem now. Maybe you can just grab the window's field editor and let it do all of the hard stuff?
As the above poster says, use the window's field editor. We had a custom view that needed text input from the user, and what we ended up doing was using a 100% transparent window's field editor to accept the text input, and using the NSText(View)'s delegate methods to send the resulting text over to our view. It worked great. See -[NSWindow fieldEditor:forObject:] for a starting point. -AndrePang?
Cunning! :) Sounds like a good way forward - I'll let you know how it works out. Many thanks! | |
| Edit / History / New / Search | Quick Links: Home / Recent Changes / Glossary / Jobs / Forums / Help |