# Dock Menu

**URL:** <https://forum.xojo.com/t/dock-menu/25361>\
**Category:** General\
**Created:** [July 7, 2015, 8:08pm UTC](https://forum.xojo.com/t/dock-menu/25361 "2015-07-07T20:08:34Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Scardingo](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@Mark\_Scardingo](https://forum.xojo.com/u/Mark_Scardingo)\
**Post date:** [July 7, 2015, 8:08pm UTC](https://forum.xojo.com/t/dock-menu/25361/1 "2015-07-07T20:08:34Z")

</div>

I was wondering if Xojo could put up some example code using declares to implement a dock menu, since isn’t this base functionality we should be getting?

Thank you

---

<div class="post-metadata">

**Author:** ![shao\_sean](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/ed8c4c/32.png) [@shao\_sean](https://forum.xojo.com/u/shao_sean)\
**Post date:** [July 7, 2015, 8:45pm UTC](https://forum.xojo.com/t/dock-menu/25361/2 "2015-07-07T20:45:54Z")

</div>

It should be doable through declares… There is nothing in macoslib, but it looks like there is something (NSApplicationDelegateMBS) in the MBS plugins to allow you to do it, hopefully Christian can direct you better through his documentation…

---

<div class="post-metadata">

**Author:** ![Jason\_King](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@Jason\_King](https://forum.xojo.com/u/Jason_King)\
**Post date:** [July 7, 2015, 8:46pm UTC](https://forum.xojo.com/t/dock-menu/25361/3 "2015-07-07T20:46:16Z")

</div>

I’m assuming this is for OSX. You will have to dynamically implement the delegate method here:  
[https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSApplicationDelegate\_Protocol/#//apple\_ref/occ/intfm/NSApplicationDelegate/applicationDockMenu:](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSApplicationDelegate_Protocol/#//apple_ref/occ/intfm/NSApplicationDelegate/applicationDockMenu:)  
And the appropriate handlers for each of the options. MacOSLib should make this easier but any solution will involve hacking the Xojo provided delegate object and will be advised against by Xojo because it could break.

---

<div class="post-metadata">

**Author:** ![Mark\_Scardingo](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@Mark\_Scardingo](https://forum.xojo.com/u/Mark_Scardingo)\
**Post date:** [July 7, 2015, 8:53pm UTC](https://forum.xojo.com/t/dock-menu/25361/4 "2015-07-07T20:53:11Z")

</div>

> [@199069:@shao sean](#):
>
> It should be doable through declares… There is nothing in macoslib, but it looks like there is something (NSApplicationDelegateMBS) in the MBS plugins to allow you to do it, hopefully Christian can direct you better through his documentation…

I really don’t think we should have to purchase a plugin for this. It’s not like we’re trying to do something nonstandard or super fancy here.

---

<div class="post-metadata">

**Author:** ![Sam\_Rowlands](https://forum.xojo.com/user_avatar/forum.xojo.com/sam_rowlands/32/265_2.png) [@Sam\_Rowlands](https://forum.xojo.com/u/Sam_Rowlands)\
**Post date:** [July 8, 2015, 12:01am UTC](https://forum.xojo.com/t/dock-menu/25361/5 "2015-07-08T00:01:52Z")

</div>

> [@199072:@Mark Scardigno](#):
>
> I really don’t think we should have to purchase a plugin for this. It’s not like we’re trying to do something nonstandard or super fancy here.

Technically if you have to replace the application delegate, then it is quite a bit of work and a PITA! It will break some of the existing application events that Xojo already handles.

---

<div class="post-metadata">

**Author:** ![Tim\_Jones](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_jones/32/8627_2.png) [@Tim\_Jones](https://forum.xojo.com/u/Tim_Jones)\
**Post date:** [July 8, 2015, 4:29am UTC](https://forum.xojo.com/t/dock-menu/25361/6 "2015-07-08T04:29:58Z")

</div>

I use Christian’s excellent MBS plugins for this (NSStatusItem family). You should also sign on to this feature request in Feedback:

\<[https://xojo.com/issue/1792](https://xojo.com/issue/1792)\>

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [July 8, 2015, 4:40am UTC](https://forum.xojo.com/t/dock-menu/25361/7 "2015-07-08T04:40:27Z")

</div>

> [@199070:@Jason King](#):
>
> … any solution will involve hacking the Xojo provided delegate object and will be advised against by Xojo because it could break.

As in “could break your app entirely and because you’ve done this its NOT a bug” kind of don’t do this warning

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [July 8, 2015, 6:52am UTC](https://forum.xojo.com/t/dock-menu/25361/8 "2015-07-08T06:52:27Z")

</div>

> [@199072:@Mark Scardigno](#):
>
> I really don’t think we should have to purchase a plugin for this. It’s not like we’re trying to do something nonstandard or super fancy here.

What do you mean exactly by “dock menu” ?

---

<div class="post-metadata">

**Author:** ![Will\_Shank](https://forum.xojo.com/letter_avatar_proxy/v4/letter/w/f475e1/32.png) [@Will\_Shank](https://forum.xojo.com/u/Will_Shank)\
**Post date:** [July 8, 2015, 9:39am UTC](https://forum.xojo.com/t/dock-menu/25361/9 "2015-07-08T09:39:40Z")

</div>

From Joe Ranieri on the old forum [http://forums.realsoftware.com/viewtopic.php?p=223109#p223109](http://forums.realsoftware.com/viewtopic.php?p=223109#p223109)

[quote]…you have to create a new Objective-C class that implements the specific NSApplication delegate methods you care about (applicationDockMenu:). Then you need to set that class as the NSApplication’s delegate. Oh, and that Objective-C class has to forward _all_ messages it doesn’t explicitly handle on to the original delegate the RB framework installed.

Also note that this isn’t explicitly supported and you might run into issues …[/quote]

This is a rare case where a Xojo employee actually mentions the hack 🙂

The built in delegate is a class named XOJApplicationController and only has these 5 methods you’d need to forward  
0) applicationDidFinishLaunching:

1. applicationOpenUntitledFile:
2. application:openFile:
3. applicationDidBecomeActive:
4. applicationDidResignActive:

Since applicationDockMenu: isn’t there I took the easier approach of simply adding it to XOJApplicationController. Then in the implementation make an NSMenu with items and return it.

I won’t post the code but here’s the messy proof of concept experiment  
[http://home.comcast.net/~trochoid/dockMenu.zip](http://home.comcast.net/~trochoid/dockMenu.zip)

This link helped: [http://cocoadevcentral.com/articles/000036.php](http://cocoadevcentral.com/articles/000036.php)

For a real implementation I’d first check if applicationDockMenu: is already present and alert yourself. Then if Xojo ever adds it you’ll see the change and have to refactor. I’d assume if it gets added you’d have access directly in Xojo and can drop the declares.

If you go the forwarding route you can implement all the methods or just the 5 with a check for them ever changing.

And use macoslib for the NSMenu.

---

<div class="post-metadata">

**Author:** ![Will\_Shank](https://forum.xojo.com/letter_avatar_proxy/v4/letter/w/f475e1/32.png) [@Will\_Shank](https://forum.xojo.com/u/Will_Shank)\
**Post date:** [July 8, 2015, 9:40am UTC](https://forum.xojo.com/t/dock-menu/25361/10 "2015-07-08T09:40:50Z")

</div>

> [@199109:@Michel Bujardet](#):
>
> What do you mean exactly by “dock menu” ?

On OS X, click down on an app in the dock for a second and a menu pops up.

---

<div class="post-metadata">

**Author:** ![Joe\_Ranieri](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@Joe\_Ranieri](https://forum.xojo.com/u/Joe_Ranieri)\
**Post date:** [July 8, 2015, 9:47am UTC](https://forum.xojo.com/t/dock-menu/25361/11 "2015-07-08T09:47:54Z")

</div>

> [@199124:@Will Shank](#):
>
> The built in delegate is a class named XOJApplicationController and only has these 5 methods you’d need to forward

You should forward everything, including messages that aren’t part of NSApplicationDelegate.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [July 8, 2015, 10:27am UTC](https://forum.xojo.com/t/dock-menu/25361/12 "2015-07-08T10:27:20Z")

</div>

> [@199125:@Will Shank](#):
>
> On OS X, click down on an app in the dock for a second and a menu pops up.

I see. I thought the said menu appeared only with Right click. Given the deep down nature of everything finder, not mentioning the highly off limit nature of anything in there, what one thinks as ‘not super fancy’ must indeed be quite a hack.

What seems possible is to display a small window containing the elements of a menu in App.HandleAppleEvent, after verifying that was a click. Since it will be displayed before the one second hold, it may do. It will work only with left click.

If one is not too cheap, though, the ideal and easiest seems to be to use NSApplicationDelegateMBS, since Christian has already suffered to produce a working solution…

---

<div class="post-metadata">

**Author:** ![Mark\_Scardingo](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@Mark\_Scardingo](https://forum.xojo.com/u/Mark_Scardingo)\
**Post date:** [July 8, 2015, 2:08pm UTC](https://forum.xojo.com/t/dock-menu/25361/13 "2015-07-08T14:08:03Z")

</div>

[quote=199131:@Michel Bujardet]I see. I thought the said menu appeared only with Right click. Given the deep down nature of everything finder, not mentioning the highly off limit nature of anything in there, what one thinks as ‘not super fancy’ must indeed be quite a hack.  
[/quote]

Indeed, and a hack it should not be.

[quote=199131:@Michel Bujardet]  
If one is not too cheap, though, the ideal and easiest seems to be to use NSApplicationDelegateMBS, since Christian has already suffered to produce a working solution…[/quote]

If one purchased Xojo instead of using Xcode and Swift for free, one is not too cheap.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [July 8, 2015, 5:15pm UTC](https://forum.xojo.com/t/dock-menu/25361/14 "2015-07-08T17:15:31Z")

</div>

I put a lot of work into my delegate classes for NSApplication and NSWindow to make sure they properly forward things and only do their own stuff if you need it.  
I want it to be compatible to all Xojo/Real Studio versions and not cause trouble.

And believe me, the way to a good implementation takes time and has a lot of pitfalls.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [July 8, 2015, 7:35pm UTC](https://forum.xojo.com/t/dock-menu/25361/15 "2015-07-08T19:35:55Z")

</div>

> [@199158:@Mark Scardigno](#):
>
> If one purchased Xojo instead of using Xcode and Swift for free, one is not too cheap.

XCode is nice, but also comes with a very steep learning curve. So in effect it is not really free : it costs a lot of time to master. Depending on how much you value your time, Xcode costs in fact at least thousands of dollars.

Xojo costs 100 dollars to start with. But one can produce a program in days.

Declares and other free developing solutions are nice. MacOSLib and declares posted in the forum are a solution, until you find something that does not exist yet (as you did). Nothing wrong about deciphering patiently the Mac developer Library and spend a few hours or weeks to make that work in Xojo. I do when I have no choice. Otherwise, it is way faster to buy MBS Complete which Christian has spent years perfecting and have an instant success.

Third party tools allows you to purchase countless hours of development and rip the result in minutes. IMHO, that is pretty cheap.

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [July 8, 2015, 8:03pm UTC](https://forum.xojo.com/t/dock-menu/25361/16 "2015-07-08T20:03:47Z")

</div>

and if you all don’t buy third party stuff, there will be no stuff…

I really would like to continue doing my plugins for another ten years instead of getting a real job.

---

<div class="post-metadata">

**Author:** ![Joost\_Rongen](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/a9a28c/32.png) [@Joost\_Rongen](https://forum.xojo.com/u/Joost_Rongen)\
**Post date:** [July 9, 2015, 12:11pm UTC](https://forum.xojo.com/t/dock-menu/25361/17 "2015-07-09T12:11:28Z")

</div>

> [@199238:@Christian Schmitz](#):
>
> getting a real job

You have one: Plugin Builder @ MBS

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [July 9, 2015, 12:20pm UTC](https://forum.xojo.com/t/dock-menu/25361/18 "2015-07-09T12:20:17Z")

</div>

[Choose a job you love, and you will never have to work a day in your life.](https://www.brainyquote.com/quotes/quotes/c/confucius134717.html)

Confucius

---

<div class="post-metadata">

**Author:** ![Mark\_Scardingo](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/bbce88/32.png) [@Mark\_Scardingo](https://forum.xojo.com/u/Mark_Scardingo)\
**Post date:** [July 9, 2015, 3:43pm UTC](https://forum.xojo.com/t/dock-menu/25361/19 "2015-07-09T15:43:26Z")

</div>

Christian, I appreciate all the support you give to this community. Thank you

[quote=199101:@Tim Jones]I use Christian’s excellent MBS plugins for this (NSStatusItem family). You should also sign on to this feature request in Feedback:

\<[https://xojo.com/issue/1792](https://xojo.com/issue/1792)\>[/quote]

Is a Dock menu part of the NSStatusItem family?

---

<div class="post-metadata">

**Author:** ![Christian\_Schmitz](https://forum.xojo.com/user_avatar/forum.xojo.com/christian_schmitz/32/158_2.png) [@Christian\_Schmitz](https://forum.xojo.com/u/Christian_Schmitz)\
**Post date:** [July 9, 2015, 4:16pm UTC](https://forum.xojo.com/t/dock-menu/25361/20 "2015-07-09T16:16:59Z")

</div>

it’s part of Cocoa plugins.  
See example projects.

And needs only a license for Cocoa plugin.

[Next page](https://forum.xojo.com/t/dock-menu/25361.md?page=2)
