Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacClassic/Window Test
Function:
Required plugins for this example: MBS MacCF Plugin, MBS MacOSX 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: /MacClassic/Window Test
This example is the version from Sun, 17th Mar 2012.
Project "Window Test.rbp"
FileTypes
Filetype any
End FileTypes
MenuBar Menu
MenuItem UntitledMenu8 = ""
MenuItem UntitledMenu6 = "File"
MenuItem FileNew = "New"
MenuItem FileClose = "Close"
MenuItem UntitledMenu7 = "-"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu4 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu5 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
MenuItem UntitledMenu3 = "Test"
MenuItem TestToolbarButton = "Toolbar Button"
MenuItem TestRegion = "Region"
MenuItem TestCollapse = "Collapse"
MenuItem TestDockIcon = "Dock Icon"
MenuItem TestProxyIcon = "Proxy Icon"
MenuItem UntitledMenu0 = "Window"
MenuItem WindowCollapse = "Collapse"
MenuItem UntitledMenu2 = "-"
MenuItem WindowToolbarButton = "ToolbarButton"
MenuItem UntitledMenu1 = "-"
MenuItem WindowAddProxyIcon = "Add Proxy Icon"
MenuItem WindowRemoveProxyIcon = "Remove Proxy Icon"
MenuItem WindowToggleSavedState = "Toggle Saved State"
End MenuBar
Class App Inherits Application
EventHandler Sub EnableMenuItems() FileNew.enable TestToolbarButton.enable TestRegion.enable TestCollapse.enable TestDockIcon.enable TestProxyIcon.enable End EventHandler
EventHandler Sub NewDocument() ToolbarButtonTestWindow.show End EventHandler
EventHandler Sub Open() ' The original code is from the example of the ' GUWindowExtension Plugin. So this example shows ' that everything what is in the plugin from ' Paul Mitchum can be done with the MBS Plugin. End EventHandler
Function FileNew() As Boolean NewDocument End Function
Function TestCollapse() As Boolean dim w as CollapseTestWindow w = new CollapseTestWindow w.show End Function
Function TestDockIcon() As Boolean dim w as DockIconTestWindow w = new DockIconTestWindow w.show End Function
Function TestProxyIcon() As Boolean dim w as ProxyTestWindow w = new ProxyTestWindow w.show End Function
Function TestRegion() As Boolean dim w as RegionTestWindow w = new RegionTestWindow w.show End Function
Function TestToolbarButton() As Boolean dim w as toolbarButtonTestWindow w = new ToolbarButtonTestWindow w.show End Function
End Class
Class ToolbarButtonTestWindow Inherits Window
Control HasToolbarButtonCheck Inherits CheckBox
ControlInstance HasToolbarButtonCheck Inherits CheckBox
EventHandler Sub Action() self.HasToolbarButtonMBS = me.value End EventHandler
End Control
Control FauxToolbar Inherits TextField
ControlInstance FauxToolbar Inherits TextField
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control WindowsEvents Inherits MyCarbonWindowsEventsMBS
ControlInstance WindowsEvents Inherits MyCarbonWindowsEventsMBS
EventHandler Function WindowToolbarButtonClicked() As boolean FauxToolbar.Visible = not FauxToolbar.Visible End EventHandler
End Control
EventHandler Sub Open() WindowsEvents.Listen self HasToolbarButtonCheck.Enabled = MacCanUseToolbarButton self.HasToolbarButtonMBS = true HasToolbarButtonCheck.Value = self.HasToolbarButtonMBS End EventHandler
End Class
Class RegionTestWindow Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() self.close End EventHandler
End Control
Control Canvas1 Inherits Canvas
ControlInstance Canvas1 Inherits Canvas
EventHandler Sub Paint(g As Graphics) dim x, y, w, h as integer dim c,s as IntegerRectMBS dim FrameLeftWidth as integer dim FrameTopHeight as integer dim FrameRightWidth as integer dim FrameBottomHeight as integer c=self.WindowContentRectMBS s=self.WindowStructureRectMBS FrameLeftWidth=abs(s.Left-c.Left) FrameTopHeight=abs(s.top-c.top) FrameRightWidth=abs(s.right-c.right) FrameBottomHeight=abs(s.bottom-c.bottom) g.foreColor = rgb(200,200,200) g.fillrect 0,0,g.width,g.height g.foreColor = rgb(255,255,255) x = FrameLeftWidth y = FrameTopHeight w = me.width - FrameRightWidth - x h = me.Height - FrameBottomHeight - y g.fillrect x,y,w,h End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
EventHandler Sub Moved() updateDisplay End EventHandler
EventHandler Sub Open() UpdateDisplay End EventHandler
EventHandler Sub Resized() updateDisplay End EventHandler
Sub UpdateDisplay() dim frame as IntegerRectMBS dim outside as IntegerRectMBS dim s as string frame=self.WindowContentRectMBS outside=self.WindowStructureRectMBS 's = "FrameTopHeight: " + str(self.frametopHeight) + " FrameBottomHeight: " + str(self.FrameBottomHeight) + chr(13) 's = s + "FrameLeftWidth: " + str(self.FrameLeftWidth) + " FrameRightWidth: " + str(self.frameRightWidth) + chr(13) 's = s + "Top: " + str(self.top) + " outsideTop: " + str(self.outsideTop) + chr(13) 's = s + "Left: " + str(self.left) + " outsideLeft: " + str(self.outsideLeft) + chr(13) 's = s + "Width: " + str(self.width) + " outsideWidth: "+ str(self.outsideWidth) + chr(13) 's = s + "Height: " + str(self.height) + " outsideHeight: " + str(self.outsideheight) + chr(13) 's = s + "Bottom: " + str(self.height + self.top) + " outsideBottom: " + str(self.outsideBottom) + chr(13) 's = s + "Right: " + str(self.left + self.width) + " outsideRight: " + str(self.outsideRight) 'StaticText1.text = s End Sub
End Class
Class CollapseTestWindow Inherits Window
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control Timer1 Inherits CollapseTimer
ControlInstance Timer1 Inherits CollapseTimer
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() dim w as StupidDialog w = new StupidDialog w.showModal End EventHandler
End Control
Control CollapseButton Inherits PushButton
ControlInstance CollapseButton Inherits PushButton
EventHandler Sub Action() self.CollapsedMBS = not self.CollapsedMBS End EventHandler
End Control
EventHandler Sub EnableMenuItems() WindowCollapse.enable End EventHandler
EventHandler Sub Open() // We have to call InitWindowCollapse somewhere in our program // or else REALbasic won't be able to compile the WindowCollapse // Plugin into our finished app. Send a REALbug to REALsoftware // if you don't like it. (It's the class extension plugin bug.) 'InitWindowCollapse // the timer is a CollapseTimer, which updates the title of the window // to reflect whether its collapsed or not. // Future versions of WindowCollapse plugin might include a Collapsed event // ..or they might not. Timer1.UseThisWindow(self) End EventHandler
Function WindowCollapse() As Boolean self.CollapsedMBS = not self.CollapsedMBS Return true End Function
End Class
Class CollapseTimer Inherits Timer
EventHandler Sub Action() if theWindow <> nil then if theWindow.CollapsedMBS <> isCollapsed then isCollapsed = theWindow.CollapsedMBS SetWindowTitle end if end if End EventHandler
Sub SetWindowTitle() if theWindow <> nil then if isCollapsed then theWindow.Title = "Collapsed" else theWindow.Title = "Not Collapsed" end if end if End Sub
Sub UseThisWindow(w as Window) theWindow = w if w <> nil then isCollapsed = w.CollapsedMBS SetWindowTitle me.Mode = 2 end if End Sub
Property isCollapsed As Boolean
Property theWindow As Window
End Class
Class StupidDialog Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() self.close End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() self.CollapsedMBS = true End EventHandler
End Control
EventHandler Sub Activate() if not self.CollapsableMBS then StaticText1.text = "I'm not collapsable." else StaticText1.text = "I'll collapse." end if End EventHandler
End Class
Class DockIconTestWindow Inherits Window
Control ProgressBar1 Inherits ProgressBar
ControlInstance ProgressBar1 Inherits ProgressBar
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() dim v as integer v = ProgressBar1.value v = v + 1 if v > 100 then v = 0 end if ProgressBar1.value = v self.UpdateDockWindowMBS End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
EventHandler Sub Open() ProgressBar1.Maximum = 100 ProgressBar1.Value = 0 End EventHandler
End Class
Class ToolbarButtonMenuItem Inherits MenuItem
EventHandler Function Action() As Boolean dim w as window w = window(0) if w <> nil then if MacCanUseToolbarButton then w.HasToolbarButtonMBS = not w.HasToolbarButtonMBS end if end if End EventHandler
EventHandler Sub EnableMenu() dim w as window w = window(0) if w <> nil then if MacCanUseToolbarButton then Enable end if if w.HasToolbarButtonMBS then Text = "Remove Toolbar Button" else Text = "Add Toolbar Button" end if end if End EventHandler
End Class
Class CollapseMenuItem Inherits MenuItem
EventHandler Function Action() As Boolean dim w as window w = window(0) if w <> nil then if w.CollapsableMBS then w.CollapsedMBS = not w.CollapsedMBS end if end if End EventHandler
EventHandler Sub EnableMenu() dim w as window w = window(0) if w <> nil then if w.CollapsableMBS then Enable end if if w.CollapsedMBS then Text = "Restore Window" else Text = "Collapse Window" end if end if End EventHandler
End Class
Class ProxyTestWindow Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() self.RemoveWindowProxyIconMBS self.SetWindowProxyIconMBS "TEXT","R*ch" End EventHandler
End Control
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
EventHandler Sub Action() self.ModifiedMBS = me.Value End EventHandler
EventHandler Sub Open() me.value = self.ModifiedMBS End EventHandler
End Control
EventHandler Sub DropObject(obj As DragItem, action As Integer) if obj.FolderItemAvailable then self.WindowProxyIconFileMBS=obj.FolderItem end if End EventHandler
EventHandler Sub Open() AcceptFileDrop("any") End EventHandler
End Class
Class AddProxyIconMenuItem Inherits MenuItem
EventHandler Function Action() As Boolean dim f as folderItem dim w as window w = window(0) if w <> nil then w.SetWindowProxyIconMBS "RBPl","RBv2" end if End EventHandler
EventHandler Sub EnableMenu() dim w as window w = window(0) if w <> nil then Enable end if End EventHandler
End Class
Class RemoveProxyIconMenuItem Inherits MenuItem
EventHandler Function Action() As Boolean dim w as window w = window(0) if w <> nil then w.RemoveWindowProxyIconMBS end if End EventHandler
EventHandler Sub EnableMenu() dim w as window w = window(0) if w <> nil then Enable end if End EventHandler
End Class
Class ToggleSavedProxyIconMenuItem Inherits MenuItem
EventHandler Function Action() As Boolean dim w as window w = window(0) if w <> nil then w.ModifiedMBS = not w.ModifiedMBS end if End EventHandler
EventHandler Sub EnableMenu() dim w as window w = window(0) if w <> nil then Enable end if End EventHandler
End Class
Class MyCarbonWindowsEventsMBS Inherits CarbonWindowsEventsMBS
End Class
Module Util
Function MacCanUseToolbarButton() As Boolean // not sure, maybe only with Carbon on Mac OS X? return RunningOnCarbonXMBS End Function
End Module
End Project

See also:

Feedback, Comments & Corrections

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




Links
MBS Xojo Plugins