Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCF/Carbon Events/Dock Menu Events
Function:
Required plugins for this example: MBS MacCF 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: /MacCF/Carbon Events/Dock Menu Events
This example is the version from Sun, 17th Mar 2012.
Project "Dock Menu Events.rbp"
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() quit End EventHandler
End Control
EventHandler Sub Open() aevents=new MyCarbonApplicationEventsMBS aevents.List=list List.InsertRow 0,"Listening for events..." aevents.Listen End EventHandler
Property Protected aevents As mycarbonapplicationEventsMBS
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileClose = "Close"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class MyCarbonApplicationEventsMBS Inherits CarbonApplicationEventsMBS
EventHandler Function ApplicationGetDockTileMenu() As integer dim m as MenuMBS write "Create Dock Tile Menu" m=new MenuMBS if m.NewMenu(1000,"Dockmenu") then m.AppendItem "Just a little test" m.AppendItem "Item 1" m.AppendItem "Item 2" m.AppendItem "Item 3" m.AppendItem "Item 4" m.CommandID(1)=OSTypeFromStringMBS("Test") // codes must have minimum one big letter m.CommandID(2)=OSTypeFromStringMBS("Tes1") // all Lowercase commands are Apple's m.CommandID(3)=OSTypeFromStringMBS("Tes2") m.CommandID(4)=OSTypeFromStringMBS("Tes3") m.CommandID(5)=OSTypeFromStringMBS("Tes4") m.setIconSelector 2, "FNDR" dockmenu=m // save for later Return m.Handle end if End EventHandler
EventHandler Function ProcessCommand(AttributeFlags as integer, CommandId as integer, Handle as integer, Index as integer) As boolean write "Process Command with ID "+hex(CommandId)+" ("+StringFromOSTypeMBS(CommandId)+") on index "+str(Index)+" in handle "+hex(handle)+"." if dockmenu<>nil then Select case commandid case OSTypeFromStringMBS("Tes1") MsgBox "You chose my menu item 1!" Return true case OSTypeFromStringMBS("Tes2") MsgBox "You chose my menu item 2!" Return true case OSTypeFromStringMBS("Tes3") MsgBox "You chose my menu item 3!" Return true case OSTypeFromStringMBS("Tes4") MsgBox "You chose my menu item 4!" Return true case OSTypeFromStringMBS("Test") MsgBox "You chose my test menu!" Return true end Select end if End EventHandler
Property dockmenu As menumBS
Property list As listbox
End Class
Class App Inherits Application
EventHandler Sub Close() Write "App.Close" DelayMBS 0.5 End EventHandler
EventHandler Function HandleAppleEvent(theEvent As AppleEvent, eventClass As String, eventID As String) As Boolean Write "HandleAppleEvent: "+eventClass+" "+eventid End EventHandler
End Class
Module Util
Sub Write(s as string) dim i,c as integer dim w as window dim m as MainWindow c=WindowCount-1 for i=0 to c w=Window(i) if w isa MainWindow then m=MainWindow(w) m.List.InsertRow 0,s end if next System.DebugLog s End Sub
Sub speakandwrite(s as string) ' crashes sometimes 'dim i as Integer ' 'Declare Function MySpeakString lib "CarbonLib" Alias "SpeakString" (SpeakString as pstring) as Integer ' 'i=MySpeakString(s) write s End Sub
End Module
End Project

See also:

Feedback, Comments & Corrections

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




Links
MBS Xojo Chart Plugins