TextInputCanvas

I’m attempting to build my own control based upon the TextInputCanvas, but I can’t get past how to use the commands as found in the DoCommand event; or any of the other events. I did create Event Handlers within the subclass and I raise the events accordingly that I need. None of the events fire from the TextInputCanvas to invoke mine to be raised. There are things I need to get such as the current text font at the location of the cursor, or the current selected text. Those all seems to be returned in the DoCommand event? I was expecting something by the way of a method for that, not an event.

I’ve been digging around in the source quite a bit and looked through these forums to see what documentation is available, but found nearly none. So here I am looking to see if anyone that has had any experience using the control could provide some assistance. :slight_smile:

Here is what I got to so far (using this an an example, but any EVENT would fit):

DoCommand (command as string) as boolean

This is an event that would provide a string name of a command executed. All I would need to do is determine which command was executed and properly handle that command in my code.

The part I cannot seem to get my head wrapped around is when and why this event would fire. I do not see any way to invoke it with any methods that look like they would directly affect that event being raised.

I just need to understand how the flow of events and methods work within this control. BTW: I did grab the source, reviewed it, but I seem to be missing something :confused:

Thanks in advance for any help :slight_smile:

In standard events you call your own events with Raise Event. What happens if you debug your code?

For the rest you description is a bit vague. Can you post a simple example of your code?

Which platform and which version of Xojo do you use?

[quote=98116:@Daniel Murphy]I’m attempting to build my own control based upon the TextInputCanvas, but I can’t get past how to use the commands as found in the DoCommand event; or any of the other events. I did create Event Handlers within the subclass and I raise the events accordingly that I need. None of the events fire from the TextInputCanvas to invoke mine to be raised. There are things I need to get such as the current text font at the location of the cursor, or the current selected text. Those all seems to be returned in the DoCommand event? I was expecting something by the way of a method for that, not an event.

I’ve been digging around in the source quite a bit and looked through these forums to see what documentation is available, but found nearly none. So here I am looking to see if anyone that has had any experience using the control could provide some assistance. :slight_smile:

Here is what I got to so far (using this an an example, but any EVENT would fit):

DoCommand (command as string) as boolean

This is an event that would provide a string name of a command executed. All I would need to do is determine which command was executed and properly handle that command in my code.

The part I cannot seem to get my head wrapped around is when and why this event would fire. I do not see any way to invoke it with any methods that look like they would directly affect that event being raised.

I just need to understand how the flow of events and methods work within this control. BTW: I did grab the source, reviewed it, but I seem to be missing something :confused:

Thanks in advance for any help :)[/quote]

It’s currently late-o’clock here, so I’m skimming a bit. Also, pardon me if this is information you already know.

Basically TextInputCanvas breaks down into two things: queries about state and requests to perform actions. As you’ve seen there are (fairly) decent comments in the C++ code about what the events do, so I won’t repeat much of it here.

Queries about state come in via:

  • BaselineAtIndex
  • CharacterAtPoint
  • FontNameAtLocation
  • FontSizeAtLocation
  • IncompleteTextRange
  • IsEditable
  • RectForRange
  • SelectedRange
  • TextForRange
  • TextLength

Requests to perform actions:

  • DiscardIncompleteText
  • DoCommand
  • SetIncompleteText
  • InsertText

The one that has tripped up a few people, us included, is forgetting to return True from IsEditable. Once you’re sure it’s editable, the flow of events is roughly:

  • An event comes in from the WindowServer and is processed by AppKit and sent to the NSView (see Handling Key Events).
  • The canvas sends it to the Cocoa text input system.
  • The text input system checks the event against the key bindings system. If it matches, TextInputCanvas will trigger get a DoCommand event for whatever Cocoa tells it to (see Text System Defaults and Key Bindings).
  • If it wasn’t a keyboard binding, the system passes it to the input manager. The input manager can do whatever it wants. It might immediately trigger InsertText, it might let events queue up, or it might tell tell you to show some incomplete (marked in Cocoa terms) text.

Since TextInputCanvas is a thin wrapper around NSTextInputClient on OS X, its documentation might help. There’s also some documentation about writing a custom text view in the Cocoa Text Architecture Guide. The only example I’m aware of is TextInputView.

On Windows and Linux, we emulate the Cocoa behavior so that you have one set of events to implement.

Thanks for the replies :slight_smile: I’ll have another look at what I am doing with the control.

It was really late for me as well, and apologize for making the mistake of not including the basics of what I am using and what I’m running on. With that said, I am running on Mac OS X Mavericks 10.9.3, using Xojo 2014 R1.1.