Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/TextArea Strikeout
This example is the version from Thu, 30th Aug 2017.
Project "TextArea Strikeout.xojo_binary_project"
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()
'StrikeOutButton.Value = me.WinSelStrikeOutMBS
StrikeOutButton.Value = me.SelStrikeOut
End EventHandler
End Control
Control StrikeOutButton Inherits BevelButton
ControlInstance StrikeOutButton Inherits BevelButton
EventHandler Sub Action()
'TextArea1.WinSelStrikeoutMBS = me.Value
TextArea1.selStrikeout = me.Value
End EventHandler
End Control
EventHandler Sub Open()
TextArea1.AppendText "Hello "
TextArea1.SelStrikeOut = true
TextArea1.AppendText "StrikeOut "
TextArea1.SelStrikeOut = false
TextArea1.AppendText "World "
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 SelStrikeOut(extends t as TextArea) As Boolean
#if TargetWin32 then
// for Windows
return t.WinSelStrikeOutMBS
#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.NSStrikethroughStyleAttributeName, 0) <> 0
#else
break // not supported
#endif
End Function
Sub SelStrikeOut(extends t as TextArea, assigns value as Boolean)
#if TargetWin32 then
// for Windows
t.WinSelStrikeOutMBS = 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.addAttribute(NSAttributedStringMBS.NSStrikethroughStyleAttributeName, 1, range)
else
s.addAttribute(NSAttributedStringMBS.NSStrikethroughStyleAttributeName, 0, range)
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.NSStrikethroughStyleAttributeName ) = v
n.typingAttributes = att
#else
break // not supported
#endif
End Sub
End Module
End Project
See also:
The items on this page are in the following plugins: MBS Win Plugin.