

This code is in charge of detecting the limits of the word under the cursor and finding if it is one of the active words registered for the class. SetStyleForWord(previousBoundedWord, True) If previousBoundedWord = Nil Then previousBoundedWord = mboundedWord Var check As pair = wordInDictionary( isolatedWord, boundleft, boundRight ) Var isolatedWord As String = Me.Text.Middle(boundLeft, boundRight - boundLeft) If Me.Text.Middle(n+1,1) = Chr(32) Or Me.Text.Middle(n+1,1) = EndOfLine Or n = tlen Then If Me.Text.Middle(n,1) = Chr(32) Or Me.Text.Middle(n,1) = EndOfLine or n = 0 Then If boundedWord Nil Then setStyleForWord( boundedWord, False )ĮlseIf Me.Text.Middle(startPosition,1) Chr(32) And Me.Text.Middle(startPosition,1) EndOfLine Thenįor n As Integer = startPosition DownTo 0 Var startPosition As Integer = Me.CharacterPosition(x,y) Var boundLeft, boundRight As Integer = -1 SetStyleForWord(previousBoundedWord, False) Next, select the MouseMove Event Handler and type the following code in the corresponding Code Editor: Var tlen As Integer = Me.Text.Length

We simply use this Event for assigning the Arrow cursor type that is most appropriate. Select the Open Event and add the following code in the corresponding Code Editor: Me.MouseCursor = Select Insert > Delegate with the following data: This is an Array containing all the registered observers of the type ActionDelegate yet to be defined.Īs we have seen, we need to define a Delegate type for the class. This is the Dictionary that will contain all the active words / additional data pairs. This property points to the previous matched word from the text. This is the property that will point to the current matched active word from the text. Set these properties as private because they just need to be accessed from the class itself and not from other pieces of external code or additional classes inherited from the subclass: Return Type: Boolean.Īdd some Private properties used by the added Event Handlers and other methods we have yet to define to the class. With the subclass selected in the Navigator, select Insert > Event Definition using the following signatures: Since we also want to make these events available for any instance created from the subclass, we have to create them again as Event Definitions. To call all the registered Observers when the user clicks on an active word, passing along the detected word and the associated information To detect if there is an active word under the cursor pointer to click on To assign the pointer cursor, more appropriate for the kind of functionality this subclass will provide These will be responsible for following the pointer movement and reacting to the registered active words for the instance. Next, add the following Event Handlers to the TextArea subclass. This feature will be based in the TextArea class, the first step is add a new TextArea control from the Library panel to the Navigator, change its name to LinkDetectorTextArea. Anyway, this tutorial serves as a good starting point and you’ll be able to modify and improve it to meet your own needs.ĭownload the class with the example project from here. If you want your code to react the same to the same active word or words throughout your project, well then, that’s what it will do. For example, you won’t be able to repeat the same word and assign it to take different actions. The associated data could be a link or text you want to show in another control when the user clicks on the active word.įor the sake of this tutorial, the class we are creating has some limitations. The active words will be based on the use of Pairs, so one piece of information will be the active word and the other piece of information will be the associated data, which is always a String.
#Xojo exit celledit windows
Best of all, this project is cross-platform, so you can use it for macOS, Windows and Linux! Learn to use the Object-oriented Delegate design pattern to dynamically change how your app reacts when the user clicks on those active words. This post was originally published in 2018 and has been updated to use Xojo API 2.0.įollow this tutorial to create active, aka clickable, words in the text of a TextArea control in your Xojo projects.
