NSTextInputClient Protocol Question

  • Hi,

    I try to write my own text field, for cross-platform dev. reasons I don't have another choice, unfortunately...

    So, in my view, I have this:

    @interface MyOpenGLView : NSOpenGLView <NSTextInputClient>
    ...
    @end

    @implementation MyOpenGLView

    - (void) mouseDown: (NSEvent*) iEvent
    {
        if( mActiveTextButton )
        {
            [[self  inputContext]  handleEvent: iEvent];
        }
        else
        {
    // this is the crossplatform stuff...
            AddMouseEvent( self, iEvent, ::nWindowingSystem::kClass_MouseClick, ::nWindowingSystem::kClick_LeftDown );
        }
    }

    the same goes for : mouseDragged:, mouseMoved:, mouseUp:, keyDown: and keyUp: .

    I also implemented all the required methods from the NSTextInputClient protocol.

    Now I can type accented characters, like é, by typing 'Option-e' then "e'.

    But I can't select anything.

    - (NSUInteger) characterIndexForPoint: (NSPoint) iPoint
    - (NSRect) firstRectForCharacterRange: (NSRange) iRange actualRange: (NSRangePointer) oActualRange
    never get called, which I suppose are here for handling mouse events and thus the selection ?

    What am I doing wrong ?

    Thanks.

    --
    http://www.tvpaint.com
    Eric M.
  • Hello Eric,

    > - (NSUInteger) characterIndexForPoint: (NSPoint) iPoint
    > - (NSRect) firstRectForCharacterRange: (NSRange) iRange actualRange: (NSRangePointer) oActualRange
    > never get called, which I suppose are here for handling mouse events and thus the selection ?

    The methods are for the input methods showing various information near your text.  Not for general mouse event handling.

    You still need to implement the mouse handling for selection with a custom code for your view.

    To handle mouse events in a text input friendly way, you want to first pass all mouse events to -[NSTextInputContext handleEvent:].
    If the method returned NO (meaning the text system didn't swallow the event), then, you can perform your custom mouse handling logic for that event.

    Aki

    On May 21, 2012, at 2:19 AM, Eric Matecki <emlist...> wrote:

    > Hi,
    >
    > I try to write my own text field, for cross-platform dev. reasons I don't have another choice, unfortunately...
    >
    > So, in my view, I have this:
    >
    > @interface MyOpenGLView : NSOpenGLView <NSTextInputClient>
    > ...
    > @end
    >
    > @implementation MyOpenGLView
    >
    > - (void) mouseDown: (NSEvent*) iEvent
    > {
    > if( mActiveTextButton )
    > {
    > [[self  inputContext]  handleEvent: iEvent];
    > }
    > else
    > {
    > // this is the crossplatform stuff...
    > AddMouseEvent( self, iEvent, ::nWindowingSystem::kClass_MouseClick, ::nWindowingSystem::kClick_LeftDown );
    > }
    > }
    >
    > the same goes for : mouseDragged:, mouseMoved:, mouseUp:, keyDown: and keyUp: .
    >
    > I also implemented all the required methods from the NSTextInputClient protocol.
    >
    > Now I can type accented characters, like é, by typing 'Option-e' then "e'.
    >
    > But I can't select anything.
    >
    > - (NSUInteger) characterIndexForPoint: (NSPoint) iPoint
    > - (NSRect) firstRectForCharacterRange: (NSRange) iRange actualRange: (NSRangePointer) oActualRange
    > never get called, which I suppose are here for handling mouse events and thus the selection ?
    >
    > What am I doing wrong ?
    >
    > Thanks.
    >
    > --
    > http://www.tvpaint.com
    > Eric M.
  • Hi,

    thanks Aki, now I got this working.
    (Sorry Aki for the msg send directly to you, I hit "send" too fast...)

    I have still a problem.

    When implementing -doCommandBySelector:, most keys do what I expect,
    but Command-A sends a selector of noop:, not selectAll: as I expected.

    What's happeneing ?

    A+

    On 22/05/12 04:57, Aki Inoue wrote:
    > Hello Eric,
    >
    >> - (NSUInteger) characterIndexForPoint: (NSPoint) iPoint
    >> - (NSRect) firstRectForCharacterRange: (NSRange) iRange actualRange: (NSRangePointer) oActualRange
    >> never get called, which I suppose are here for handling mouse events and thus the selection ?
    >
    > The methods are for the input methods showing various information near your text.  Not for general mouse event handling.
    >
    > You still need to implement the mouse handling for selection with a custom code for your view.
    >
    > To handle mouse events in a text input friendly way, you want to first pass all mouse events to -[NSTextInputContext handleEvent:].
    > If the method returned NO (meaning the text system didn't swallow the event), then, you can perform your custom mouse handling logic for that event.
    >
    > Aki
    >
    > On May 21, 2012, at 2:19 AM, Eric Matecki<emlist...>  wrote:
    >
    >> Hi,
    >>
    >> I try to write my own text field, for cross-platform dev. reasons I don't have another choice, unfortunately...
    >>
    >> So, in my view, I have this:
    >>
    >> @interface MyOpenGLView : NSOpenGLView<NSTextInputClient>
    >> ...
    >> @end
    >>
    >> @implementation MyOpenGLView
    >>
    >> - (void) mouseDown: (NSEvent*) iEvent
    >> {
    >> if( mActiveTextButton )
    >> {
    >> [[self  inputContext]  handleEvent: iEvent];
    >> }
    >> else
    >> {
    >> // this is the crossplatform stuff...
    >> AddMouseEvent( self, iEvent, ::nWindowingSystem::kClass_MouseClick, ::nWindowingSystem::kClick_LeftDown );
    >> }
    >> }
    >>
    >> the same goes for : mouseDragged:, mouseMoved:, mouseUp:, keyDown: and keyUp: .
    >>
    >> I also implemented all the required methods from the NSTextInputClient protocol.
    >>
    >> Now I can type accented characters, like é, by typing 'Option-e' then "e'.
    >>
    >> But I can't select anything.
    >>
    >> - (NSUInteger) characterIndexForPoint: (NSPoint) iPoint
    >> - (NSRect) firstRectForCharacterRange: (NSRange) iRange actualRange: (NSRangePointer) oActualRange
    >> never get called, which I suppose are here for handling mouse events and thus the selection ?
    >>
    >> What am I doing wrong ?
    >>
    >> Thanks.

    http://www.tvpaint.com
    Eric M.

    --
    Keep intel OUTSIDE my Mac !
    Hiii !!! I can see Intel chips creeping around my G5 !

    Eric M.
  • Because the Command+ key combinations are served by menus, not by key bindings.

    You need to have a menu item with -selectAll: action reacting to Command+A.

    it's a part of the standard Edit menu.

    Aki

    On 2012/05/25, at 1:09, Eric Matecki <emlist...> wrote:

    > Hi,
    >
    > thanks Aki, now I got this working.
    > (Sorry Aki for the msg send directly to you, I hit "send" too fast...)
    >
    > I have still a problem.
    >
    > When implementing -doCommandBySelector:, most keys do what I expect,
    > but Command-A sends a selector of noop:, not selectAll: as I expected.
    >
    > What's happeneing ?
    >
    > A+
    >
    > On 22/05/12 04:57, Aki Inoue wrote:
    >> Hello Eric,
    >>
    >>> - (NSUInteger) characterIndexForPoint: (NSPoint) iPoint
    >>> - (NSRect) firstRectForCharacterRange: (NSRange) iRange actualRange: (NSRangePointer) oActualRange
    >>> never get called, which I suppose are here for handling mouse events and thus the selection ?
    >>
    >> The methods are for the input methods showing various information near your text.  Not for general mouse event handling.
    >>
    >> You still need to implement the mouse handling for selection with a custom code for your view.
    >>
    >> To handle mouse events in a text input friendly way, you want to first pass all mouse events to -[NSTextInputContext handleEvent:].
    >> If the method returned NO (meaning the text system didn't swallow the event), then, you can perform your custom mouse handling logic for that event.
    >>
    >> Aki
    >>
    >> On May 21, 2012, at 2:19 AM, Eric Matecki<emlist...>  wrote:
    >>
    >>> Hi,
    >>>
    >>> I try to write my own text field, for cross-platform dev. reasons I don't have another choice, unfortunately...
    >>>
    >>> So, in my view, I have this:
    >>>
    >>> @interface MyOpenGLView : NSOpenGLView<NSTextInputClient>
    >>> ...
    >>> @end
    >>>
    >>> @implementation MyOpenGLView
    >>>
    >>> - (void) mouseDown: (NSEvent*) iEvent
    >>> {
    >>> if( mActiveTextButton )
    >>> {
    >>> [[self  inputContext]  handleEvent: iEvent];
    >>> }
    >>> else
    >>> {
    >>> // this is the crossplatform stuff...
    >>> AddMouseEvent( self, iEvent, ::nWindowingSystem::kClass_MouseClick, ::nWindowingSystem::kClick_LeftDown );
    >>> }
    >>> }
    >>>
    >>> the same goes for : mouseDragged:, mouseMoved:, mouseUp:, keyDown: and keyUp: .
    >>>
    >>> I also implemented all the required methods from the NSTextInputClient protocol.
    >>>
    >>> Now I can type accented characters, like é, by typing 'Option-e' then "e'.
    >>>
    >>> But I can't select anything.
    >>>
    >>> - (NSUInteger) characterIndexForPoint: (NSPoint) iPoint
    >>> - (NSRect) firstRectForCharacterRange: (NSRange) iRange actualRange: (NSRangePointer) oActualRange
    >>> never get called, which I suppose are here for handling mouse events and thus the selection ?
    >>>
    >>> What am I doing wrong ?
    >>>
    >>> Thanks.
    >
    > http://www.tvpaint.com
    > Eric M.
    >
    >
    >
    > --
    > Keep intel OUTSIDE my Mac !
    > Hiii !!! I can see Intel chips creeping around my G5 !
    >
    > Eric M.
  • Hi,

    But Command+LeftArrow does send the moveToLeftEndOfLine: selector.
    So the choice of what goes to the menu, and what goes to -doCommandBySelector:
    must be more subtle than Command+key and (not Command)+key, or maybe just plain arbitrary ?

    A+

    On 26/05/12 00:42, Aki Inoue wrote:
    > Because the Command+ key combinations are served by menus, not by key bindings.
    >
    > You need to have a menu item with -selectAll: action reacting to Command+A.
    >
    > it's a part of the standard Edit menu.
    >
    > Aki
    >
    > On 2012/05/25, at 1:09, Eric Matecki<emlist...>  wrote:
    >
    >> Hi,
    >>
    >> thanks Aki, now I got this working.
    >> (Sorry Aki for the msg send directly to you, I hit "send" too fast...)
    >>
    >> I have still a problem.
    >>
    >> When implementing -doCommandBySelector:, most keys do what I expect,
    >> but Command-A sends a selector of noop:, not selectAll: as I expected.
    >>
    >> What's happeneing ?
    >>
    >> A+
    >>
    >> On 22/05/12 04:57, Aki Inoue wrote:
    >>> Hello Eric,
    >>>
    >>>> - (NSUInteger) characterIndexForPoint: (NSPoint) iPoint
    >>>> - (NSRect) firstRectForCharacterRange: (NSRange) iRange actualRange: (NSRangePointer) oActualRange
    >>>> never get called, which I suppose are here for handling mouse events and thus the selection ?
    >>>
    >>> The methods are for the input methods showing various information near your text.  Not for general mouse event handling.
    >>>
    >>> You still need to implement the mouse handling for selection with a custom code for your view.
    >>>
    >>> To handle mouse events in a text input friendly way, you want to first pass all mouse events to -[NSTextInputContext handleEvent:].
    >>> If the method returned NO (meaning the text system didn't swallow the event), then, you can perform your custom mouse handling logic for that event.
    >>>
    >>> Aki
    >>>
    >>> On May 21, 2012, at 2:19 AM, Eric Matecki<emlist...>  wrote:
    >>>
    >>>> Hi,
    >>>>
    >>>> I try to write my own text field, for cross-platform dev. reasons I don't have another choice, unfortunately...
    >>>>
    >>>> So, in my view, I have this:
    >>>>
    >>>> @interface MyOpenGLView : NSOpenGLView<NSTextInputClient>
    >>>> ...
    >>>> @end
    >>>>
    >>>> @implementation MyOpenGLView
    >>>>
    >>>> - (void) mouseDown: (NSEvent*) iEvent
    >>>> {
    >>>> if( mActiveTextButton )
    >>>> {
    >>>> [[self  inputContext]  handleEvent: iEvent];
    >>>> }
    >>>> else
    >>>> {
    >>>> // this is the crossplatform stuff...
    >>>> AddMouseEvent( self, iEvent, ::nWindowingSystem::kClass_MouseClick, ::nWindowingSystem::kClick_LeftDown );
    >>>> }
    >>>> }
    >>>>
    >>>> the same goes for : mouseDragged:, mouseMoved:, mouseUp:, keyDown: and keyUp: .
    >>>>
    >>>> I also implemented all the required methods from the NSTextInputClient protocol.
    >>>>
    >>>> Now I can type accented characters, like é, by typing 'Option-e' then "e'.
    >>>>
    >>>> But I can't select anything.
    >>>>
    >>>> - (NSUInteger) characterIndexForPoint: (NSPoint) iPoint
    >>>> - (NSRect) firstRectForCharacterRange: (NSRange) iRange actualRange: (NSRangePointer) oActualRange
    >>>> never get called, which I suppose are here for handling mouse events and thus the selection ?
    >>>>
    >>>> What am I doing wrong ?
    >>>>
    >>>> Thanks.
    >>
    >> http://www.tvpaint.com
    >> Eric M.

    --
    http://www.tvpaint.com
    Eric M.
  • Since -selectAll: is not specific to text, there should be a "physical" menu item inside the "Edit" menu.
    -moveToLeftEndOfLine: is useful only in text editing context.

    Aki

    On May 29, 2012, at 2:46 AM, Eric Matecki <emlist...> wrote:

    > Hi,
    >
    > But Command+LeftArrow does send the moveToLeftEndOfLine: selector.
    > So the choice of what goes to the menu, and what goes to -doCommandBySelector:
    > must be more subtle than Command+key and (not Command)+key, or maybe just plain arbitrary ?
    >
    > A+
    >
    > On 26/05/12 00:42, Aki Inoue wrote:
    >> Because the Command+ key combinations are served by menus, not by key bindings.
    >>
    >> You need to have a menu item with -selectAll: action reacting to Command+A.
    >>
    >> it's a part of the standard Edit menu.
    >>
    >> Aki
    >>
    >> On 2012/05/25, at 1:09, Eric Matecki<emlist...>  wrote:
    >>
    >>> Hi,
    >>>
    >>> thanks Aki, now I got this working.
    >>> (Sorry Aki for the msg send directly to you, I hit "send" too fast...)
    >>>
    >>> I have still a problem.
    >>>
    >>> When implementing -doCommandBySelector:, most keys do what I expect,
    >>> but Command-A sends a selector of noop:, not selectAll: as I expected.
    >>>
    >>> What's happeneing ?
    >>>
    >>> A+
    >>>
    >>> On 22/05/12 04:57, Aki Inoue wrote:
    >>>> Hello Eric,
    >>>>
    >>>>> - (NSUInteger) characterIndexForPoint: (NSPoint) iPoint
    >>>>> - (NSRect) firstRectForCharacterRange: (NSRange) iRange actualRange: (NSRangePointer) oActualRange
    >>>>> never get called, which I suppose are here for handling mouse events and thus the selection ?
    >>>>
    >>>> The methods are for the input methods showing various information near your text.  Not for general mouse event handling.
    >>>>
    >>>> You still need to implement the mouse handling for selection with a custom code for your view.
    >>>>
    >>>> To handle mouse events in a text input friendly way, you want to first pass all mouse events to -[NSTextInputContext handleEvent:].
    >>>> If the method returned NO (meaning the text system didn't swallow the event), then, you can perform your custom mouse handling logic for that event.
    >>>>
    >>>> Aki
    >>>>
    >>>> On May 21, 2012, at 2:19 AM, Eric Matecki<emlist...>  wrote:
    >>>>
    >>>>> Hi,
    >>>>>
    >>>>> I try to write my own text field, for cross-platform dev. reasons I don't have another choice, unfortunately...
    >>>>>
    >>>>> So, in my view, I have this:
    >>>>>
    >>>>> @interface MyOpenGLView : NSOpenGLView<NSTextInputClient>
    >>>>> ...
    >>>>> @end
    >>>>>
    >>>>> @implementation MyOpenGLView
    >>>>>
    >>>>> - (void) mouseDown: (NSEvent*) iEvent
    >>>>> {
    >>>>> if( mActiveTextButton )
    >>>>> {
    >>>>> [[self  inputContext]  handleEvent: iEvent];
    >>>>> }
    >>>>> else
    >>>>> {
    >>>>> // this is the crossplatform stuff...
    >>>>> AddMouseEvent( self, iEvent, ::nWindowingSystem::kClass_MouseClick, ::nWindowingSystem::kClick_LeftDown );
    >>>>> }
    >>>>> }
    >>>>>
    >>>>> the same goes for : mouseDragged:, mouseMoved:, mouseUp:, keyDown: and keyUp: .
    >>>>>
    >>>>> I also implemented all the required methods from the NSTextInputClient protocol.
    >>>>>
    >>>>> Now I can type accented characters, like é, by typing 'Option-e' then "e'.
    >>>>>
    >>>>> But I can't select anything.
    >>>>>
    >>>>> - (NSUInteger) characterIndexForPoint: (NSPoint) iPoint
    >>>>> - (NSRect) firstRectForCharacterRange: (NSRange) iRange actualRange: (NSRangePointer) oActualRange
    >>>>> never get called, which I suppose are here for handling mouse events and thus the selection ?
    >>>>>
    >>>>> What am I doing wrong ?
    >>>>>
    >>>>> Thanks.
    >>>
    >>> http://www.tvpaint.com
    >>> Eric M.
    >
    >
    > --
    > http://www.tvpaint.com
    > Eric M.
previous month may 2012 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