Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS Win Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/RTF Windows
This example is the version from Tue, 30th Jan 2023.
Project "RTF Windows.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits Window
Control TextArea1 Inherits TextArea
ControlInstance TextArea1 Inherits TextArea
End Control
Control LoadButton Inherits PushButton
ControlInstance LoadButton Inherits PushButton
EventHandler Sub Action()
Dim f As FolderItem = GetOpenFolderItem(FileTypes1.Rtf)
If f<>Nil Then
Dim b As BinaryStream = BinaryStream.Open(f)
Dim s As String = b.Read(b.Length)
#If TargetWindows Then
TextArea1.WinRTFDataMBS(False) = s
#Elseif TargetMacOS then
Dim n As NSTextViewMBS = TextArea1.NSTextViewMBS
Dim a As NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithRTF(s)
n.textStorage.setAttributedString a
#Else
#Pragma error "New platform?"
#EndIf
End If
Exception io as IOException
MsgBox "IOException!"+EndOfLine+EndOfLine+str(io.errorNumber)+" "+io.message
End EventHandler
End Control
Control SaveButton Inherits PushButton
ControlInstance SaveButton Inherits PushButton
EventHandler Sub Action()
Dim f As FolderItem = GetSaveFolderItem(FileTypes1.Rtf, "test.rtf")
If f<>Nil Then
#if TargetWindows then
Dim s As String = TextArea1.WinRTFDataMBS(False)
#ElseIf TargetMacOS Then
Dim n As NSTextViewMBS = TextArea1.NSTextViewMBS
Dim a As NSAttributedStringMBS = n.textStorage
Dim s As String = a.rtf
#Else
#Pragma error "New platform?"
#EndIf
Dim b As BinaryStream = BinaryStream.Create(f, True)
b.Write s
end if
Exception io as IOException
MsgBox "IOException!"+EndOfLine+EndOfLine+str(io.errorNumber)+" "+io.message
End EventHandler
End Control
Control InsertImageButton Inherits PushButton
ControlInstance InsertImageButton Inherits PushButton
EventHandler Sub Action()
Dim f As FolderItem = GetOpenFolderItem(FileTypes1.ImageXBmp+FileTypes1.Png+FileTypes1.Jpeg)
If f<>Nil Then
#If TargetWindows Then
dim p as Picture = Picture.Open(f)
if p<>Nil then
dim b as BinaryStream = BinaryStream.Open(f)
dim d as string = b.Read(b.Length)
TextArea1.WinInsertImageMBS(d, p.Width, p.Height)
End If
#ElseIf TargetMacOS Then
Dim image As New NSImageMBS(f)
// build attachment
Dim imageAttachment As New NSTextAttachmentMBS(image)
Dim attributedString As NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithAttachment(imageAttachment)
// insert image
Dim textView As NSTextViewMBS = TextArea1.NSTextViewMBS
textview.insertText attributedString
#Else
#Pragma error "New platform?"
#EndIf
End If
Exception io as IOException
MsgBox "IOException!"+EndOfLine+EndOfLine+str(io.errorNumber)+" "+io.message
End EventHandler
End Control
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
FileTypes1
Filetype application/rtf
Filetype image/jpeg
Filetype image/png
Filetype image/x-bmp
End FileTypes1
End Project
See also:
The items on this page are in the following plugins: MBS Win Plugin.