Required plugins for this example: MBS MacFrameworks Plugin, MBS MacControls Plugin, MBS MacBase Plugin, MBS Main Plugin, MBS MacCocoa Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSView custom focus ring
Class App Inherits Application
Const kEditClear = "Effacer"
Const kFileQuit = "Quitter"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control CocoaControlMBS1 Inherits CocoaControlMBS
ControlInstance CocoaControlMBS1 Inherits CocoaControlMBS
EventHandler Function GetView() As NSViewMBS
MyView = New MyCustomNSView( 0,0,Me.Width,Me.Height )
MyView.focusRingType = MyView.NSFocusRingTypeExterior
Return MyView
End EventHandler
End Control
Control TextField1 Inherits TextField
ControlInstance TextField1 Inherits TextField
End Control
Property MyView As MyCustomNSView
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Fichier"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "Edition"
MenuItem EditUndo = "Annuler"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Couper"
MenuItem EditCopy = "&Copier"
MenuItem EditPaste = "Coller"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Tout Sélectionner"
End MenuBar
Class MyCustomNSView Inherits CustomNSViewMBS
EventHandler Sub DrawRect(g as NSGraphicsMBS, left as double, top as double, width as double, height as double)
g.SetColor NSColorMBS.whiteColor
g.fillRect 0,frameheight/4,framewidth,frameheight/2
g.fillRect framewidth/4,0,framewidth/2,frameheight
End EventHandler
EventHandler Function acceptsFirstResponder() As boolean
Return True
End EventHandler
EventHandler Function drawFocusRingMask(g as NSGraphicsMBS) As boolean
// Here we draw the mask used for the focus ring.
// It can be a shape, a picture or a bezier path.
g.SetColor NSColorMBS.blackColor
g.fillRect 0,frameheight/4,framewidth,frameheight/2
g.fillRect framewidth/4,0,framewidth/2,frameheight
Return True
// Execute Self.noteFocusRingMaskChanged if you change
// the shape of the focus ring. Then it will be updated.
End EventHandler
EventHandler Function focusRingMaskBounds() As NSRectMBS
Return Self.bounds
End EventHandler
End Class