I want to capture the MouseDown event and the Mouse location within the active window, including the Windows ToolBar region.
The normal Window MouseDown event is not fireing if you click the mouse within the ToolBar or the window TitleBar.
I used a MBS Plugin in RS 2012r2, (CarbonWindowEventsMBS) but this Plugin is only working with Carbon builts.
Before I buy another MBS Plugin, I’m wondering if there are Cocoa Declares I can use?
They should capture the MouseDown event and return the Mouse location of the active window.
Thanks for any help
I can’t speak for Hanspeter, but I wanted to get right-clicks (contextual clicks) in the toolbar to implement the “Show/Hide toolbar” contextual menu - as of 10.8, apple removed the “tic tac” control in the upper-right of the window that would show/hide the toolbar. Apple’s strategy seems to be to allow right-clicks in the toolbar as an alternative way to accomplish this.
Hi Lukas,
I’m working on a custom control working and behaves simular like a ComboBox but with a lot of
features not available in the Xojo ComboBox.
To close the popup Listbox I need to capture the MousDown event anywhere on the window.
I made a custom ComboBox under RS 2012r2 / Carbon, which is working as expected - but not under Cocoa.
Then close the ComboBox in the Action events of all toolbar items. User can then drag the window with the open ComboBox but as soon as they click on a ToolItem, it will close.
Anything else will get complicated, because NSToolbar is not an NSResponder. You would have to look at NSApplication and hook into the event queue and filter out the mouse clicks for the toolbar (and only the toolbar).
Lukas - any idea how Apple gets mouse clicks in their toolbars? It seems pretty consistent that most (all?) Apple-built apps have a contextual menu to hide (or customize) the toolbar.
dim h as integer = tb1.Handle
declare sub setAllowsUserCustomization lib "Cocoa" selector "setAllowsUserCustomization:" (NSToolbar as integer, value as boolean)
setAllowsUserCustomization(h,true)
But it fails, as toolbar.handle is 0 in cocoa, which is a bug I reported over a year ago
Thanks, Joe, but I’m having trouble translating that into code, I tried this :
declare sub setAllowsUserCustomization lib "Cocoa" selector "setAllowsUserCustomization:" (NSToolbar as integer, value as boolean)
dim h as integer = tb1.Window.Handle
setAllowsUserCustomization(h,true)
declare sub setAllowsUserCustomization lib "Cocoa" selector "setAllowsUserCustomization:" (NSToolbar as integer, value as boolean)
dim h as integer = tb1.Handle
if h = 0 then
' due to bug, we get the toolbar using cocoa declares see [https://xojo.com/issue/17116](https://xojo.com/issue/17116)
dim h2 as integer = tb1.Window.handle
declare function GetNSToolbar lib "Cocoa" selector "toolbar" (NSWindow as integer) as integer
h = GetNSToolbar(h2)
setAllowsUserCustomization(h,true)
else
setAllowsUserCustomization(h,true)
end if
I’ll add that to the feedback case so others can use it
declare sub setAllowsUserCustomization lib "Cocoa" selector "setAllowsUserCustomization:" (NSToolbar as integer, value as boolean)
dim h as integer = tb1.Handle
if h = 0 then
' due to bug, we get the toolbar using cocoa declares see [https://xojo.com/issue/17116](https://xojo.com/issue/17116)
dim h2 as integer = tb1.Window.handle
declare function GetNSToolbar lib "Cocoa" selector "toolbar" (NSWindow as integer) as integer
h = GetNSToolbar(h2)
setAllowsUserCustomization(h,true)
else
setAllowsUserCustomization(h,true)
end if
I’ll add that to the feedback case so others can use it[/quote]
I’m not sure customization will work at all as you want (it’s not supported), but the way to get the handle is good.
In fact, the effect of choosing “Customize Toolbar…” is not that bad, as it gives you only one choice (which is your default set of ToolbarButtons) so it seems relatively harmless. Having the other features work a little more like other OS X cocoa apps is nice, too.
Michael, please take a look at my fork of macoslib here .
It’s a little bit outdated since I no longer have time to maintain it, but here you will find a complete implementation of the NSToolbar using declares.
declare sub setAllowsUserCustomization lib "Cocoa" selector "setAllowsUserCustomization:" (NSToolbar as integer, value as boolean)
dim h as integer = tb1.Handle
if h = 0 then
' due to bug, we get the toolbar using cocoa declares see [https://xojo.com/issue/17116](https://xojo.com/issue/17116)
dim h2 as integer = tb1.Window.handle
declare function GetNSToolbar lib "Cocoa" selector "toolbar" (NSWindow as integer) as integer
h = GetNSToolbar(h2)
setAllowsUserCustomization(h,true)
else
setAllowsUserCustomization(h,true)
end if
I’ll add that to the feedback case so others can use it[/quote]
Great!
Using this, is there a way to save the users toolbar settings and use them in the next app launch?
If the user wants only text in the toolbar for example.