Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS MacFrameworks Plugin, MBS MacCocoa Plugin, MBS MacBase Plugin, MBS Main Plugin, MBS MacControls Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/TextEdit MBS
This example is the version from Mon, 9th Nov 2014.
Project "TextEdit MBS.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub EnableMenuItems()
SchriftSchrifteneinblenden.Enabled=true
End EventHandler
End Class
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
textView.selectAll
End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action()
//n.alignCenter
textView.alignLeft
End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action()
textView.copy
End EventHandler
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action()
dim u as NSUndoManagerMBS
u=textView.undoManager
u.undo
End EventHandler
End Control
Control PushButton5 Inherits PushButton
ControlInstance PushButton5 Inherits PushButton
EventHandler Sub Action()
//n.alignCenter
textView.alignCenter
End EventHandler
End Control
Control PushButton6 Inherits PushButton
ControlInstance PushButton6 Inherits PushButton
EventHandler Sub Action()
//n.alignCenter
textView.alignRight
End EventHandler
End Control
Control PushButton7 Inherits PushButton
ControlInstance PushButton7 Inherits PushButton
EventHandler Sub Action()
//n.alignCenter
dim farbe as NSColorMBS = NSColorMBS.redColor
textView.alignJustified
textView.textColor=farbe
End EventHandler
End Control
Control PushButton8 Inherits PushButton
ControlInstance PushButton8 Inherits PushButton
EventHandler Sub Action()
dim f as FolderItem = GetSaveFolderItem(FileTypes1.ApplicationRtf, "test.rtf")
if f = nil then Return
dim a as NSAttributedStringMBS = textView.textStorage
dim data as string = a.RTFFromRange(0, a.length, DocumentAttributes)
dim b as BinaryStream = BinaryStream.Create(f, true)
b.Write data
End EventHandler
End Control
Control PushButton9 Inherits PushButton
ControlInstance PushButton9 Inherits PushButton
EventHandler Sub Action()
dim f as FolderItem = GetOpenFolderItem(FileTypes1.ApplicationRtf)
if f = nil then Return
dim d as Dictionary
dim a as NSAttributedStringMBS = NSAttributedStringMBS.attributedStringWithPath(f, d)
if a<>Nil then
DocumentAttributes = d
textView.textStorage.setAttributedString a
textView.updateRuler
else
MsgBox "Failed to read file."
end if
End EventHandler
End Control
Control PushButton10 Inherits PushButton
ControlInstance PushButton10 Inherits PushButton
EventHandler Sub Action()
textView.orderFrontListPanel()
End EventHandler
End Control
Control PushButton11 Inherits PushButton
ControlInstance PushButton11 Inherits PushButton
EventHandler Sub Action()
textView.orderFrontSpacingPanel()
End EventHandler
End Control
Control PushButton12 Inherits PushButton
ControlInstance PushButton12 Inherits PushButton
EventHandler Sub Action()
textView.orderFrontTablePanel
End EventHandler
End Control
Control PushButton13 Inherits PushButton
ControlInstance PushButton13 Inherits PushButton
EventHandler Sub Action()
NSFontPanelMBS.sharedFontPanel.Show
End EventHandler
End Control
Control PushButton14 Inherits PushButton
ControlInstance PushButton14 Inherits PushButton
EventHandler Sub Action()
textView.showGuessPanel
End EventHandler
End Control
Control CocoaControlMBS1 Inherits CocoaControlMBS
ControlInstance CocoaControlMBS1 Inherits CocoaControlMBS
EventHandler Function GetView() As NSViewMBS
scrollview=new NSScrollViewMBS(0,0,me.Width,me.Height)
textView=new MyNSTextViewMBS(0,0,me.Width,me.Height)
scale_factor=1.5
textView.ContinuousSpellCheckingEnabled=true
textView.allowsUndo=true
textView.importsGraphics=true
textView.allowsImageEditing=true
textView.usesFontPanel=true
textView.usesFindPanel=true
textView.usesFindPanel=true
//textView.orderFrontTablePanel
// tell it how the resize is going
textView.autoresizingMask=textView.NSViewHeightSizable+textView.NSViewWidthSizable
scrollview.documentView=textView
scrollview.hasVerticalScroller=true
scrollview.hasHorizontalScroller=false
textView.needsDisplay=true
textView.RulerVisible=true
dim size as NSSizeMBS = NSMakeSizeMBS(scale_factor,scale_factor)
textView.scaleUnitSquareToSize(size)
Return scrollview
End EventHandler
End Control
Control PushButton15 Inherits PushButton
ControlInstance PushButton15 Inherits PushButton
EventHandler Sub Action()
scale_factor=1.25
dim size as NSSizeMBS = NSMakeSizeMBS(scale_factor,scale_factor)
textView.scaleUnitSquareToSize(size)
textView.updateRuler
Window1.Refresh
End EventHandler
End Control
Control PushButton16 Inherits PushButton
ControlInstance PushButton16 Inherits PushButton
EventHandler Sub Action()
scale_factor=0.75
dim size as NSSizeMBS = NSMakeSizeMBS(scale_factor,scale_factor)
textView.scaleUnitSquareToSize(size)
textView.updateRuler
Window1.Refresh
End EventHandler
End Control
Control PushButton17 Inherits PushButton
ControlInstance PushButton17 Inherits PushButton
EventHandler Sub Action()
textView.orderFrontLinkPanel
End EventHandler
End Control
Control PushButton18 Inherits PushButton
ControlInstance PushButton18 Inherits PushButton
EventHandler Sub Action()
textView.orderFrontSubstitutionsPanel
End EventHandler
End Control
EventHandler Sub Resized()
textView.updateRuler
End EventHandler
Function SchriftSchrifteneinblenden() As Boolean
NSFontPanelMBS.sharedFontPanel.Show
Return True
End Function
Property DocumentAttributes As Dictionary
Property scale_factor As double
Property scrollview As nsscrollViewMBS
Property textView As NSTextViewMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
MenuItem SchriftenMenu = "Format"
MenuItem Schrift(0) = "Schrift"
MenuItem SchriftSchrifteneinblenden = "Schriften einblenden"
End MenuBar
Class MyNSTextViewMBS Inherits NSTextViewMBS
EventHandler Function shouldChangeTextInRange(affectedCharRange as NSRangeMBS, replacementString as string) As boolean
if len(replacementString)=1 then
if asc(replacementString)=97 then // a
Return false
end if
end if
//window1.Title = replacementString
Return true
End EventHandler
Note "RequiredPlugins"
for this example you need Cocoa, CocoaControls, CocoaBase and Leopard plugins.
End Class
FileTypes1
Filetype application/msword
Filetype application/rtf
Filetype text/html
Filetype text/plain
End FileTypes1
Class Toolbar1 Inherits Toolbar
End Class
End Project
The items on this page are in the following plugins: MBS MacControls Plugin.