SetApplicationDockTileMenu [solved]

Mac OSX specific forum
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

SetApplicationDockTileMenu [solved]

Post by lexvictory »

ive managed to use SetApplicationDockTileMenu (carbon) to add items to the dock tile, but i cant seem to find a way to receive the menu events..

anyone know how?
Last edited by lexvictory on Tue May 20, 2008 12:03 pm, edited 1 time in total.
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

As quoted in the Carbon Documentation
Before the menu is displayed, it receives the Carbon events kEventMenuPopulate, kEventMenuOpening, and kEventMenuEnableItems, so any event handlers for these events can update the menu appropriately. You can receive notifications of and handle selections from the menu using kEventCommandProcess Carbon event handlers installed in the application event target.
Source : http://developer.apple.com/documentatio ... ckTileMenu
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

i saw that, but i need to know how to receive it in PB; windowevent doesnt generate anything. not even a menu event
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

ok, managed to dig around (used finder to search for things inside files)
and so ive finally got it working!

may be a bit rough around the edges, but here goes

Code: Select all


#noErr = 0
#kEventClassCommand = 'cmds'
#kEventCommandProcess = 1
#eventNotHandledErr = -9874;return when not our event
#kEventParamDirectObject = '----'
#typeHICommand = 'hcmd'

Structure EventTypeSpec
  eventClass.l
  eventKind.l
EndStructure

Structure menu
  *menuRef
  menuItemIndex.w
EndStructure
Structure HICommand
  attributes.l
  commandID.l
  *menu
EndStructure


ProcedureDLL EventHandler(*nextHandler, theEvent, *userData)
;MessageRequester("Hello", "I got me a message!!!")
If geteventkind_(theEvent) = #kEventCommandProcess
  GetEventParameter_(theEvent, #kEventParamDirectObject, #typeHICommand, #Null, SizeOf(HICommand), @size.l, @hicommand.HICommand)
  Select hicommand\commandID
    Case 1
      Debug "menu item 1"
    Default
      Debug "menu item "+Str(hicommand\commandID)
  EndSelect
EndIf


If *nexthandler
  ProcedureReturn CallNextEventHandler_(*nextHandler, theEvent)
Else
  ProcedureReturn #eventNotHandledErr
EndIf
EndProcedure 



If OpenWindow(0, 100, 100, 195, 260, "PureBasic Window", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)

  
  CreatePopupMenu(0)
  MenuItem(1, "test")
  MenuItem(2, "test2")
  MenuItem(50, "test 50")
  setapplicationdocktilemenu_(MenuID(0))
  
  functionupp = NewEventHandlerUPP_(@eventhandler())
  eventTypes.EventTypeSpec\eventClass = #kEventClassCommand
  eventtypes\eventKind = #kEventCommandProcess
  InstallEventHandler_(GetApplicationEventTarget_(), functionupp, 1, @eventtypes, 0, @handlerref.l)
  

  Repeat
    EventID.l = WaitWindowEvent()

    If EventID = #PB_Event_CloseWindow  ; If the user has pressed on the close button
      Quit = 1
    ElseIf eventid = #PB_Event_Menu 
      Debug "menu"
      Select EventMenu()
        Case #PB_Menu_Quit
          Debug "got told to quit by dock or app menu"
        Default
          Debug EventMenu()
      EndSelect
    EndIf

  Until Quit = 1
  
EndIf
pbl file:

Code: Select all

;
-framework Carbon
GetApplicationDockTileMenu 0
SetApplicationDockTileMenu 1
OverlayApplicationDockTileImage 1
SetApplicationDockTileImage 1
RestoreApplicationDockTileImage 0
;InstallEventHandler 6
GetApplicationEventTarget 0
CallNextEventHandler 2
GetEventParameter 7
GetEventKind 1
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
Post Reply