At first you might think “Oh gee if I just implement a handful of events then things will work”.
And you quickly add “InsertText” and “DoCommand” and magic will happen !
That would be nice but its not true - at least not on macOS
There are other ancillary events that have to exist for the TextInputCanvas to do its thing.
And at some point we have to write some “text storage” routines. TextInputCanvas, or TIC, doesnt do any of that for us.
In reality we need to implement most of these events in addition to InsertText, DoCommand and Paint so you might as well add them too
BaselineAtIndex
CharacterAtPoint
DiscardIncompleteText
FontNameAtLocation
FontSizeAtLocation
IncompleteTextRange
IsEditable
KeyFallsThrough
RectForRange
SelectedRange
SetIncompleteText
TextForRange
TextLength
At this point all I want to do is figure out which events get called and work through them in order which will get us moving towards a working TIC.
So for now I’m just going to put
system.debuglog currentmethodname
in most of them, skip putting this in paint, to see what gets called when. Leave the Paint event as it was drawing the giant red square as thats nice and easy to see that it IS doing something and not generating a lot of log messages.
If you run, unsurprisingly the first event that is called is IsEditable. Since the way we have the event implemented currently returns false by default we need to change this to return some indicator when we are editable.
Add a property to track this
Private Property mEditable as boolean
and we’ll return the property value from IsEditable.
Event IsEditable() as boolean
System.debuglog currentmethodname
return mEditable
End Function
It might be useful to make this property the backing for a Public Computed Property so its settable in code, and we could event expose it in the inspector.
Add a computed property , ReadOnly, to not confused things with an event named IsEditable and a property named the same thing.
ReadOnly will set mEditable to FALSE when the value set is TRUE.
And ReadOnly will set mEditable to TRUE when the value passed is FALSE.
So we’ll set the computed property, ReadOnly. as
Public Property ReadOnly as boolean
Get
return not mEditable
End Get
Set
mEditable = not Value
End Set
End Property
And we can set the Computed Property to be visible in the Inspector Behaviour so its settable in Xojo’s inspector. Right click on the class in the navigator
and select Inspector Behaviour
Check the box next to ReadOnly and now when you drag an instance onto a layout you can set ReadOnly in the Xojo Inspector.
And you’ll notice that the way we named this and the default value of FALSE for booleans work together well. ReadOnly defaults to FALSE - the default for booleans which works out well.
So now that we have IsEditable dealt with in a way that we can extend later on with code lets try and see what happens now.
Since IsEditable is now retuning true we should be seeing other events.
And indeed there they are
CodeEditorCanvas.IsEditable True
CodeEditorCanvas.IsEditable True
CodeEditorCanvas.IncompleteTextRange
CodeEditorCanvas.InsertText
CodeEditorCanvas.IsEditable True
CodeEditorCanvas.IsEditable True
Onwards !