Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

/Win/TextArea Sub and SuperScript
Function:
Required plugins for this example:
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/TextArea Sub and SuperScript
This example is the version from Wed, 17th Jan 2017.
Project "TextArea Sub and SuperScript.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control TextArea1 Inherits TextArea
ControlInstance TextArea1 Inherits TextArea
EventHandler Sub SelChange() 'SubScriptButton.Value = me.WinSelSubScriptMBS 'SuperScriptButton.Value = me.WinSelSuperScriptMBS SubScriptButton.Value = me.SelSubScript SuperScriptButton.Value = me.SelSuperScript End EventHandler
End Control
Control SubScriptButton Inherits BevelButton
ControlInstance SubScriptButton Inherits BevelButton
EventHandler Sub Action() 'TextArea1.WinSelSubScriptMBS = me.Value TextArea1.selSubScript = me.Value End EventHandler
End Control
Control SuperScriptButton Inherits BevelButton
ControlInstance SuperScriptButton Inherits BevelButton
EventHandler Sub Action() 'TextArea1.WinSelSuperScriptMBS = me.Value TextArea1.selSuperScript = me.Value End EventHandler
End Control
EventHandler Sub Open() TextArea1.AppendText "Hello " TextArea1.SelSubScript = true TextArea1.AppendText "SubScript " TextArea1.SelSubScript = false TextArea1.AppendText "World " TextArea1.SelSuperScript = true TextArea1.AppendText "SuperScript " TextArea1.SelSuperScript = false TextArea1.AppendText "ok?" End EventHandler
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Module TextAreaModule
Function SelSubScript(extends t as TextArea) As Boolean #if TargetWin32 then // for Windows return t.WinSelSubScriptMBS #elseif TargetCocoa then // for Mac dim n as NSTextViewMBS = t.NSTextViewMBS dim s as NSTextStorageMBS = n.textStorage // and for typing dim att as Dictionary = n.typingAttributes return att.lookup( NSAttributedStringMBS.NSSuperscriptAttributeName, 0) < 0 #else break // not supported #endif End Function
Sub SelSubScript(extends t as TextArea, assigns value as Boolean) #if TargetWin32 then // for Windows t.WinSelSubScriptMBS = value #elseif TargetCocoa then // for Mac dim n as NSTextViewMBS = t.NSTextViewMBS dim s as NSTextStorageMBS = n.textStorage dim range as new NSRangeMBS( t.SelStart,t.SelLength ) // change it for selection if range.length > 0 then if value then s.subscriptRange(range.location, range.length) else s.unscriptRange(range.location, range.length) end if end if // and for typing dim att as Dictionary = n.typingAttributes dim v as integer if value then v = -1 else v = 0 end if att.Value( NSAttributedStringMBS.NSSuperscriptAttributeName ) = v n.typingAttributes = att #else break // not supported #endif End Sub
Function SelSuperScript(extends t as TextArea) As Boolean #if TargetWin32 then // for Windows return t.WinSelSuperScriptMBS #elseif TargetCocoa then // for Mac dim n as NSTextViewMBS = t.NSTextViewMBS dim s as NSTextStorageMBS = n.textStorage // and for typing dim att as Dictionary = n.typingAttributes return att.lookup( NSAttributedStringMBS.NSSuperscriptAttributeName, 0) > 0 #else break // not supported #endif End Function
Sub SelSuperScript(extends t as TextArea, assigns value as Boolean) #if TargetWin32 then // for Windows t.WinSelSuperScriptMBS = value #elseif TargetCocoa then // for Mac dim n as NSTextViewMBS = t.NSTextViewMBS dim s as NSTextStorageMBS = n.textStorage dim range as new NSRangeMBS( t.SelStart,t.SelLength ) // change it for selection if range.length > 0 then if value then s.superscriptRange(range.location, range.length) else s.unscriptRange(range.location, range.length) end if end if // and for typing dim att as Dictionary = n.typingAttributes dim v as integer if value then v = 1 else v = 0 end if att.Value( NSAttributedStringMBS.NSSuperscriptAttributeName ) = v n.typingAttributes = att #else break // not supported #endif End Sub
End Module
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Win Plugin.




Links
MBS FileMaker tutorial videos