Accessing OSX Scrollbar preferences programmatically - macos

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.

Related

Focus ring is not shown with programmatically created controls

I am working on some general dialogs for our content management system. Everything is written programmatically in Cocoa/Objective-C without using xib files.
Unfortunately the focus ring is never displayed, even though I can use TAB to move between the controls, and even though all controls are (or are inherited from) standard controls like NSButton, NSTextField and NSTextView.
On the other side, if I use xib files or storyboard files to make similar dialogs, the focus ring is shown without problems.
I expected that you only would need to draw the focus ring yourself if you are creating a custom view, which is directly inherited from NSView itself, regardless if you are using xib files or not.
Can anyone please help with this? Thank you very much in advance!

Creating NSOpenGLView inside an NSDocument (OS X)

I am creating a music-eduaction app that reads in musical scores - not audio files - and will need to present an animated graphical screen. I created a document-based app to make file access easy, and I have it now reading and parsing the files, and I have all the song data stored in my Obj-C classes. I also have a textview in my xib that I can write song attributes and other text tidbits to. Now I want a second view, which needs to be graphical and animatable, for the music. I am an Xcode novice, but have some openGL experience. My setup is latest OS and Xcode versions.
When I try to drag the OpenGL View into my window in IB, I get a weird error/warning that says "Unsupported Configuration - NSOpenGLView in One Shot memory enabled window" (so that is weird), and the openGL view does not appear when I run the app.
I can't find much reference to OpenGL Views in NSdocuments on this site, or anywhere else, which makes me think I might be trying to do something that is not meant to be done. Does anyone have any advice for me? Should I not use a document-based app? Should I use something other than openGL? Or maybe I need to build the openGL View and View Controller 100% programmatically in this case? Any advice or pointers to some applicable samples/tutorials would be a huge help.
Try disabling the "One Shot" option from the Windows's memory attributes in Interface Builder.
From NSWindow documentation:
setOneShot: Sets whether the window device that the window manages
should be freed when it’s removed from the screen list.
- (void)setOneShot:(BOOL)oneShot
Parameters
oneShot YES to free the window’s window device when it’s removed from the screen list (hidden)
and to create another one when it’s returned to the screen; NO to
reuse the window device.
Discussion
Freeing the window device when
it’s removed from the screen list can result in memory savings and
performance improvement for NSWindow objects that don’t take long to
display. It’s particularly appropriate for NSWindow objects the user
might use once or twice but not display continually.

Enable click-through without overriding NSView acceptsFirstMouse

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?

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.

Turn off OS X 10.7 Lion's "auto-correct" feature programmatically?

OS X Lion has an iPhone-like autocorrect feature as you're typing.
This feature interferes with my typing app. The people using my app would not want it turned on at all, system wide. I need to turn off all auto-correct off for all apps, not just in my own NSTextField.
Is there any way for me to check/set the global/system auto-correct feature to OFF? Or am I stuck basically providing a guided tutorial for how to turn it off?
Solution must be legal for the Mac App Store.
Is this in an NSTextView? If so, there are several methods available to alter the correction behavior:
- (void)setAutomaticSpellingCorrectionEnabled:(BOOL)flag
- (void)setAutomaticTextReplacementEnabled:(BOOL)flag
Please try those, they should be what you are looking for.
Finally, there is additional API to support the new global user preference settings for automatic text replacement and spelling correction. NSTextView now by default will keep track of and follow these settings automatically, but applications using NSTextView can override that by programmatically using existing NSTextView methods such as -setAutomaticTextReplacementEnabled: and -setAutomaticSpellingCorrectionEnabled: to control an individual text view's settings. The new API is primarily for non-text view clients who wish to keep track of the settings for themselves, using the NSSpellChecker class methods to determine their values, and optionally also notifications to determine when the settings have changed.
+ (BOOL)isAutomaticTextReplacementEnabled;
+ (BOOL)isAutomaticSpellingCorrectionEnabled;
NSString * const NSSpellCheckerDidChangeAutomaticSpellingCorrectionNotification;
NSString * const NSSpellCheckerDidChangeAutomaticTextReplacementNotification;
https://developer.apple.com/library/mac/#releasenotes/Cocoa/AppKit.html

Resources