The NSTouchBar docs provide the keys for what is needed. 
The object it is defined in must be in the responder chain (i.e a window, view 
or anything  else that is in the chain),
Conform to the NSTouchBarProvider protocol,
and implement the makeTouchBar method.

I suspect the hardest one for you will be the first, attaching the toucher to 
an object that is in the responder chain. The system appears to use
that to determine when to switch in and out the touchBar - when it activates a 
window or view that has a touchbar, it displays it. When it is 
deactivated, whatever is activated gets a shot at showing its touchBar, if it 
has one.

So, you need to come up with an object that is in the responder chain, can 
become first responder (or owns the first responder),
implements the NSTouchBarProvider protocol, and implements the makeTouchBar 
method, returning the touchBar object.
Might be an interesting challenge in our environment, especially without 
windows or views available. Please let us know how you do it!

Jack Brindle




> On Dec 30, 2016, at 5:30 AM, Uli Kusterer <witness.of.teacht...@gmx.net> 
> wrote:
> 
> On 12 Dec 2016, at 07:22, David M. Cotter <m...@davecotter.com> wrote:
>> My app is mostly C++ (because it’s cross platform) with Carbon on the UI 
>> edges, and the absolute minimum required ObjectiveC++ to make it work.  
>> (please no discussion about why this is stupid / i should write a modern app 
>> etc)
>> 
>> So I need to programmatically instantiate an NSTouchBar, somehow
>> 
>> i do have a “MainController” which is just an NSObject, and a literally 
>> empty nib i COULD put something into.
>> 
>> but i do NOT have an NSView or NSViewController to connect the touch bar to, 
>> and i’d prefer not to have to use any storyboard if i can avoid it (of 
>> course i will if it can’t be avoided)
>> 
>> how do i go about just creating an NSTouchBar in objC and having it show up 
>> and respond to taps?
> 
> From a casual look at the comments in the NSTouchBar.h header, it seems as if 
> you only need an application delegate (which I assume you mean by your 
> MainController NSObject?) that implements NSTouchBarProvider to return an 
> NSTouchBar object. Of course, if you implement it all there, you'll have to 
> come up with your own way to determine from the frontmost window etc. which 
> items to show.
> 
> As to implementing the actual items, it seems like, lacking an NSCarbonView, 
> you need to use an NSView to provide those (and if you're using some standard 
> view, that will in turn need to either be subclassed or need another object 
> to talk to that knows how to dispatch messages to your Carbon code.
> 
> FWIW, in our Cocoa port, we tried just funneling everything through the app 
> delegate as fake Carbon events (and all our existing code needed minimal 
> changes to handle fake instead of real events because the structure stayed 
> the same). We eventually gave up on that as it just invites impedance 
> mismatches about who gets what message. So in the end, we changed all our C++ 
> classes to create Cocoa NSWindowController objects and load the actual 
> windows from Cocoa (but still use our fake Carbon Events to dispatch stuff 
> under the hood).
> 
> That meant all windows converted worked as part of the responder chain. It's 
> been too long for me to remember what we actually did in what order. I think 
> we first converted the menu bar to Cocoa alone, then slowly migrated windows 
> bit by bit, starting with modal windows first. Maybe that info helps you some 
> in deciding what to do.
> 
> Cheers,
> -- Uli Kusterer
> "The Witnesses of TeachText are everywhere..."
> http://www.zathras.de
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/jackbrindle%40me.com
> 
> This email sent to jackbrin...@me.com


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to