Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCocoa/Unified Bars Example
Required plugins for this example: MBS MacBase Plugin, MBS Main Plugin, MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/Unified Bars Example
This example is the version from Sun, 17th Mar 2012.
Project "Unified Bars Example.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control HTMLViewer1 Inherits HTMLViewer
ControlInstance HTMLViewer1 Inherits HTMLViewer
EventHandler Sub Open() Me.LoadURL("http://www.joris-vervuurt.com/") End EventHandler
End Control
EventHandler Sub Open() If not (AddUnifiedTopAndBottomBars(Self, 50, 23, True)) Then //an error occurred, failed to add the unified top and bottom bars End If End EventHandler
Function AddUnifiedTopAndBottomBars(w as Window, TopHeight as Integer, BottomHeight as Integer, MovableByTopBarUnderCocoa as Boolean = False) As Boolean If TargetCocoa Then //calculate the style mask value depending on the properties of the passed Window object Dim CustomStyleMask as Integer = NSWindowMBS.NSTexturedBackgroundWindowMask + NSWindowMBS.NSTitledWindowMask If w.CloseButton Then CustomStyleMask = CustomStyleMask + NSWindowMBS.NSClosableWindowMask End If If w.MinimizeButton Then CustomStyleMask = CustomStyleMask + NSWindowMBS.NSMiniaturizableWindowMask End If If w.Resizeable Then //note: if the Resizeable property of the passed Window object is set to True, the maximize button will be enabled (the MaximizeButton property will be ignored) CustomStyleMask = CustomStyleMask + NSWindowMBS.NSResizableWindowMask End If //apply the calculated style mask value to the window w.NSWindowMBS.styleMask = CustomStyleMask //set the title of the NSWindow object to the title of the passed Window object to make it appear w.NSWindowMBS.Title = w.Title //set whether the window should be movable by the top bar or not (default is set to False, see the optional parameter MovableByTopBarUnderCocoa) w.NSWindowMBS.isMovableByWindowBackground = MovableByTopBarUnderCocoa //disable auto-recalculating the height of the top bar w.NSWindowMBS.setAutorecalculatesContentBorderThickness(False, NSWindowMBS.NSMaxYEdge) //disable auto-recalculating the height of the bottom bar w.NSWindowMBS.setAutorecalculatesContentBorderThickness(False, NSWindowMBS.NSMinYEdge) //set the height of the top bar w.NSWindowMBS.setContentBorderThickness(TopHeight, NSWindowMBS.NSMaxYEdge) //set the height of the bottom bar w.NSWindowMBS.setContentBorderThickness(BottomHeight, NSWindowMBS.NSMinYEdge) Return True ElseIf TargetCarbon Then If w.Composite Then //the passed Window object must have it's Composite property set to true, otherwise it won't work propertly if w.SetContentBorderThicknessMBS(0, TopHeight, 0, BottomHeight) then //workaround for an issue where the background would turn white if the HasBackColor property of the passed Window object is set to False If not w.HasBackColor Then w.BackColor = RGB(237, 237, 237) w.HasBackColor = True End If //finally, add rounded corners to the bottom bar w.HasRoundBottomBarCornersMBS = true Return True End If End If End If Return False Exception Return False End Function
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"
End MenuBar
End Project

Feedback, Comments & Corrections

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

MBS Xojo tutorial videos