Platforms to show: All Mac Windows Linux Cross-Platform

/MacExtras/Attached Window


Required plugins for this example: MBS MacBase Plugin, MBS MacExtras Plugin, MBS MacCocoa Plugin, MBS Main Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacExtras/Attached Window

This example is the version from Sun, 25th May 2013.

Project "Attached Window.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open() window1.Show End EventHandler
End Class
Class Window1 Inherits Window
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
EventHandler Sub MouseEnter() dim HelpText as String = "Use this option if your mail dates come out incorrect." myAttachedWindow = new AttachedWindow(self, me, HelpText) End EventHandler
EventHandler Sub MouseExit() myAttachedWindow.Hide End EventHandler
End Control
Property myAttachedWindow As AttachedWindow
End Class
Class AttachedWindow
Const WindowWidth = 300
Sub Constructor(hasParentWindow as Window, theControl as RectControl, theText as String) theParentWindow = hasParentWindow 'calculate string width dim tempPic as new Picture(1, 1, 32) tempPic.Graphics.DrawString(theText, 0, tempPic.Graphics.TextHeight + tempPic.Graphics.TextAscent, WindowWidth) dim StringHeight as Integer = tempPic.Graphics.StringHeight(theText, WindowWidth) dim theNSWindow as NSWindowMBS = theParentWindow.NSWindowMBS if InternalAttachedWindow <> Nil then theNSWindow.removeChildWindow InternalAttachedWindow InternalAttachedWindow.hide InternalAttachedWindow = nil end if dim side as integer = MAAttachedWindowMBS.MAPositionAutomatic dim WindowPoint as NSPointMBS WindowPoint = new NSPointMBS(theControl.TrueBoundary.left + theControl.Width/2, hasParentWindow.Height - (theControl.TrueBoundary.Top + theControl.Height)) 'create text field and style it const Border = 10 dim theTextField as new NSTextFieldMBS(Border, Border, WindowWidth, StringHeight + Border) theTextField.StringValue = theText theTextField.Editable = false theTextField.textColor = NSColorMBS.whiteColor theTextField.backgroundColor = NSColorMBS.blackColor theTextField.Bordered = true 'add text field to window dim TextFieldView as new NSViewMBS(0, 0, WindowWidth + 20, StringHeight + 30) TextFieldView.addSubview theTextField 'style window InternalAttachedWindow = MAAttachedWindowMBS.attachedWindow(TextFieldView, WindowPoint, theNSWindow, side, Border) InternalAttachedWindow.borderColor = NSColorMBS.whiteColor InternalAttachedWindow.backgroundColor = NSColorMBS.blackColor InternalAttachedWindow.viewMargin = 4 InternalAttachedWindow.borderWidth = 3 InternalAttachedWindow.cornerRadius = 8 InternalAttachedWindow.drawsRoundCornerBesideArrow = true InternalAttachedWindow.arrowBaseWidth = 20 InternalAttachedWindow.arrowHeight = 15 InternalAttachedWindow.hasArrow = true InternalAttachedWindow.alphaValue = 0.9 'create and show attached window theNSWindow.addChildWindow InternalAttachedWindow, NSWindowMBS.NSWindowAbove InternalAttachedWindow.show End Sub
Sub Hide() dim theNSWindow as NSWindowMBS = theParentWindow.NSWindowMBS if InternalAttachedWindow <> Nil then theNSWindow.removeChildWindow InternalAttachedWindow dim theAnimator as NSWindowMBS = InternalAttachedWindow.animator if theAnimator = nil then InternalAttachedWindow.hide // hide normal else theAnimator.alphaValue = 0.0 // hide with CoreAnimation end if InternalAttachedWindow = nil end if End Sub
Property Private InternalAttachedWindow As MAAttachedWindowMBS
Property Private theParentWindow As Window
End Class
Module GUIUtilities
Function TrueBoundary(extends theContainerControl As ContainerControl) As BoundaryRect 'gets the boundary of a container control in relation to the screen and not the parent dim theBoundary as new BoundaryRect theBoundary.height = theContainerControl.height theBoundary.width = theContainerControl.width theBoundary.top = theContainerControl.top theBoundary.left = theContainerControl.left 'loop up the containing chain dim theWindow as ContainerControl = theContainerControl while theWindow isa containercontrol theBoundary.top = theBoundary.top + theWindow.top theBoundary.left = theBoundary.left + theWindow.left theWindow = containercontrol(theWindow.window) wend 'add values for the window 'theBoundary.top = theBoundary.top + theWindow.top 'theBoundary.left = theBoundary.left + theWindow.left return theBoundary End Function
Function TrueBoundary(Extends theRectControl As RectControl) As BoundaryRect 'gets the boundary of a rect control in relation to the screen and not the parent dim theBoundary as new BoundaryRect theBoundary.height = theRectControl.height theBoundary.width = theRectControl.width theBoundary.top = theRectControl.top theBoundary.left = theRectControl.left 'loop up the containing chain dim theWindow as window = theRectControl.window while theWindow isa containercontrol theBoundary.top = theBoundary.top + theWindow.top theBoundary.left = theBoundary.left + theWindow.left theWindow = containercontrol(theWindow).window wend 'add values for the window 'theBoundary.top = theBoundary.top + theWindow.top 'theBoundary.left = theBoundary.left + theWindow.left return theBoundary End Function
Function TrueWindow(Extends theRectControl As RectControl) As Window 'return the uppermost window of a container control return theRectControl.window.truewindow End Function
Function TrueWindow(Extends theWindow As Window) As Window 'return the uppermost window of a container control if theWindow isa containercontrol then return containercontrol(theWindow).window.truewindow else return theWindow end End Function
End Module
Class BoundaryRect
Note "About"
Help class for getting the true boundary of a control in a container
Property Height As Integer
Property Left As Integer
Property Top As Integer
Property Width As Integer
End Class
End Project

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


The biggest plugin in space...