Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/NSView custom focus ring
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS MacControls Plugin, MBS MacFrameworks Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSView custom focus ring
This example is the version from Sun, 4th Aug 2012.
Project "NSView custom focus ring.rbp"
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
End Project

Feedback, Comments & Corrections

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

MBS Xojo PDF Plugins