Enable click-through without overriding NSView acceptsFirstMouse - macos

The proper way of enabling click-though is to override acceptsFirstMouse on an NSView to return YES. (Click-through means that you can click on and use a control even when its window is not focused. For example, the Finder toolbar buttons, and the traffic-light window controls use this.)
My problem is that my application is not based on Cocoa, but GTK. Under the hood, GTK uses some Carbon and Cocoa, and I can get a pointer to the NSView if I want - but I can't get the widget to use a different NSView subclass without editing the GTK source. What are other ways to achive click-through?
(And, if possible, "hover-through" - I'd like to have mouse-over events on the click-through controls, too, so I can highlight them, telling the user that they are clickable.)
I could call Carbon's InstallWindowEventHandler with kEventWindowGetClickActivation, but I'm not sure how to use it, and if it's going to work (I've read Carbon is deprecated and might not work on modern Macs anymore). Alternatively, there must be a low-level mechanism to enable this (the Cocoa mechanism has to be implemented somehow). Any ideas?

Related

Disable All Interaction with a Cocoa WebView

I'm having difficulty in using a WebView that is being used purely to display a preview of a website - and I want to ignore all/any interactions the user may try to make with it.
I've already tried Cocoa webView - Disable all interaction to no avail; you can still easily spam-click and it will recognise the presses. (at least there's no context menu)
This one seems overkill; Disable a WebKit WebView - there must be an easier way.
In iOS I know exactly how to solve this, but as a Cocoa newcomer I am stumped - does anyone have any suggestions or better ways to achieve this? Or dump a transparent NSView on top and gobble up interactions? (tried this as well by subclassing an NSView, also to no effect)
Whole project is in IB currently, if this makes any difference.
I think you want to implement a WebPolicy Delegate and have it deny navigation events.

Accessing OSX Scrollbar preferences programmatically

I need to programmatically access the state of some of the settings in my SystemPreferences. In particular the scrollbar settings (for 10.7 whether they're floating or not and for 10.6/10.5 the scroll button placement). I know there's these .plist files, but I'd much rather access something fast from memory if possible. I'm curious as well if there's away to be notified when they change, so that I don't have to read them so often.
Read NSScroller reference. The change in the setting is automatically communicated to all instances of NSScroller by calling the appropriate setArrowsPosition: etc. You just need to implement them in your NSScroller subclass.

How can I create an iOS-style toolbar in my Mac Cocoa application?

Several iLife '11 applications on the Mac use iOS-style black toolbars. For instance, the toolbar at the bottom of this screenshot of iPhoto:
(source: pocket-lint.com)
This sort of look is available in the iOS SDK as "UITabBar."
I am wondering if there is an easy way to achieve this in my ordinary, non-iOS Mac application. If not, what would be the best way to go about creating this effect?
There's nothing that will give you this view out of the box. You'll need to build it yourself.
The simplest method would be to create a custom view with a gradient background and place monochrome buttons in it.
Better would be to create a set of classes similar to NSToolBar that handle positioning, highlighting etc. Even better, build it and then open-source it :-)
However, you'll have to build it yourself. Apart from NSButton there's not much that will help in the pre-existing objects.

Mac OSX, Cocoa event model in NPAPI , NSView, and Out of process plugins

Well, currently chrome has out of process plugins. and firefox 4 will use same model.
That means plugin process is now seperated from browser process.
Plugin process might NOT have window at all.
My plugin is based on NSView.
Before cocoa event model, when I can access NSWindow in browser process, All I have to do is just add my_view as a subview of the contentView in the window.
[[the_window contentView] addSubview:my_view]
I do NOT need to process events myself. It worked itself.
But now, I convert NPCocoaEvents into NSEvents in event process code.
Do I have to change it myself?
Also some instance of NSEvents, I can not make them for example, wheel mouse events.
What should do I do?
Did I approach a wrong way?
Please enlighten me.
Do I have to change it myself?
If you plan to use the approach of forwarding NSEvents to your existing NSView then yes; there's no way to get access to the original NSEvents. They don't exist in the plugin process.
Another option would be to move away from trying to use native controls, and do your own drawing and event handling. This is the way most NPAPI plugins work.
A third possibility would be to open a separate window for your plugin content, and put your view in that window. This isn't technically supported by NPAPI, and it won't be perfect, but it might be a short-term way to get your plugin working while you explore long-term options.
Did I approach a wrong way?
Yes, what you were doing before was an unsupported hack, and not how NPAPI was intended to be used. Adding a view to a browser's window assumes things about the browser's view hierarchy that are implementation details, and subject to change at any time.
One option would be to use the FireBreath framework to create your plugin, as it already has a lot of the abstraction for negotiating the event and drawing models as well as an event abstraction. It's pretty straightforward to get up and going.

How does a Windows non-native user interface work?

Through experience I have found that the native windows forms/components don’t like to be changed. I know using Delphi or Visual Studio you are given native windows components to populate a form or window with and then you attach code on events that these components may do (onClick for example).
However, how do all of these programs like Word or google’s Chrome browser alter the standard windows’ window? I thought it was somehow protected?
Chrome seems to have tabs actually on the window’s frame?
I know you can also get toolkits like Swing and QT that have their own controls/components to populate a form. How do these work? (How does the operating system/computer know what a non-native button should act like? For example; Chrome's back and forward buttons, they're not native components?).
I can understand how OpenGL/DirectX window would work because you’re telling the computer exactly what to draw with polygons/quads.
I hope this question is clear!
Windows does not protect GUI elements. Windows and controls can be subclassed to handle various drawing operations in a custom way. For example, windows may override and reimplement the handling of the WM_NCPAINT message to draw a custom titlebar and frame:
http://msdn.microsoft.com/en-us/library/dd145212(VS.85).aspx
Some Windows controls have an "owner-draw" mode. If you use this, you get to draw the control (or at least vital parts of the control), while Windows takes care of responding to user input in the standard way.
Swing ant QT draw their own widgets at a low level using basic primitives, but they also have theme engines which can mimic the native controls.
Qt moved to native controls a while back. As for how swing does it, it gets a basic window from the OS. Then much like Opengl\Directx it does all of the drawing with in that window. As for where to position things that is what the layout managers do. Each manager has a layout style horizontal, vertical, grid, components it has to draw and a section of window it is expected to fill. From there it does some pretty easy math to allocate its space to its controls.
There's no magic: non native controls are simply drawn on a blank window. Or, instead of being drawn they may be represented as one of several bitmaps based on state (ie: a button may be represented as a .png for the normal state, another .png for the pressed state, etc)

Resources