How do I use an indeterminate status indicator as the image for an NSStatusItem? - objective-c

I have an application that is an NSStatusItem.
It has a few different modes, each of which require an external process to be launched, during which the icon is simply highlighted, and appears to be frozen.
I want to use the -setImage: method (or reasonable facsimile) to display something along the lines of a "spinner" commonly seen in web applications and all over OS X.
Is there any native method for accomplishing this (e.g. some instance of NSProgressIndicator?) or must I manually display an animation by cycling through a set of images?
In either case, how would I implement?

In order to have it be animated (and not just a static image), you'll probably need to use -setView: and give it a custom view (which then animates itself). You might be able to get away with using a suitably-configured standard NSProgressIndicator (i.e. set to NSProgressIndicatorSpinningStyle style, etc.) as that "custom view".
But, if the NSProgressIndicator standard sizes don't work well, then you can check out my YRKSpinningProgressIndicator (BSD-licensed), which is a clone of the spinning NSProgressIndicator that can be set to arbitrary size and colors.

Related

Define separate XAML layouts based on screen orientation

According to https://msdn.microsoft.com/en-us/windows/uwp/layout/layouts-with-xaml, you can set separate XAML layout pages based on device family. However, I've built my app in such a way that the family doesn't really matter (it renders well on phones, desktops, and laptops). What DOES matter is the orientation; certain things need to moved around based on whether the screen is in portrait or landscape mode.
Currently I'm using a work-around where I catch the page resized event in code, check the new orientation, and move things manually. However, it would be much easier if I could just write two separate XAML pages, one for portrait, and one for landscape. Then I wouldn't need to worry about catching the resized event.
Is this possible?
Use VisualStateTrigger, create your own custom trigger OR use this library:
https://github.com/dotMorten/WindowsStateTriggers

How to place items in a NSScrollView

When I try to place objects using the Interface Builder in Xcode into a NSScrollView, they appear fine until runtime in the application, where they do not appear at all for some reason. I want it to be so that I can place multiple buttons and labels in the view, and have the user be able to scroll down to see more.
Am I not meant to use NSScrollView for this purpose?
Is there another way to go about implementing it I am not aware of?
You need to check the where you added the UI objects.
You need to consider these :
Is your autolayout enabled?
Did you flipped the view?
Resizing mask is working good as per your requirement.
Am I not meant to use NSScrollView for this purpose?
No, you picked the correct control for the requirement. NSScrollView is indeed for same kind of use.

How to force an NSWindow to be in front of every app? Even fullscreen apps

I have an NSWindow that i would like to have it in front of everything (every app of the computer, fullscreen apps, etc..). Even if i click in a background app, the NSWindow cant go to background. And the NSWindow must follow the user screen if, for example, the user switches the desktop to desktop2, and so on...
How can i do that?
Thanks!
If you don't need to be visible with other apps' full-screen windows, it's not too hard.
First, to stay in front of everything else, just setLevel: with NSFloatingWindowLevel or higher. Experiment with the different values to see which seems appropriate to your needs.
Next, to stay in front even when the user changes Spaces, possibly including Exposé/Mission Control, setCollectionBehavior: with the appropriate pair of flags, or use the corresponding Spaces and Exposé settings in the Attributes Inspector if you're creating the window in the nib. Either Can Join All Spaces or Move to Active Space will make sure you stay visible on every space, in slightly different ways. You'll probably want Exposé set to Stationary, or possibly Transient, too. Again, try both ways and see.
However, Lion will hide both all-spaces and move-to-active-space windows when the user switches to a full-screen space or to Dashboard or Launchpad. And if you watch, you'll see that it does this in different ways for each of the three cases. And that Snow Leopard does things a little differently, and so does Mountain Lion.
If you want to solve that last problem, you need a bit of hackery—and different forms of hackery for each case and for each OS version. The basic trick is to catch the hide-related notifications and unhide yourself at the appropriate time.
You should modify your info.plist and set the Application is Agent flag to YES. An agent's window can be displayed in front of fullscreen windows.
Setting both,
"Application is agent (UIElement)" to "YES" in info.plist
&
window level :
self.view.window?.level = NSWindow.Level(rawValue: kCGMainMenuWindowLevel.hashValue - 1)
self.view.window?.collectionBehavior = [.stationary, .canJoinAllSpaces, .fullScreenAuxiliary]
helped me.

How can I remove the "blur" effect that Cocoa adds to transparent sheets?

By default, Cocoa adds a background blur effect to transparent and semitransparent modal sheets when they are applied to a window. I would like to disable the blur effect. How would I go about doing it?
I have created a custom sheet (a subclass of NSWindow with a transparent background and some controls in it). I am able to display it using the standard beginSheet method as follows:
[NSApp beginSheet:myCustomSheet
modalForWindow:mainWindow
modalDelegate:self
didEndSelector:...];
The sheet displays fine, but everything behind it is blurred.
Note 1: I am writing a completely customized user interface for a touch screen / kiosk type app, so none of the usual Apple user interface guidelines apply.
Note 2: I do want to see what is underneath the sheet. As SirRatty pointed out, it is possible to block out the blurred portion by filling in the background. In my case, I want to have the background show through, just without appearing blurred.
There's a private API call that can be used to set a CI filter on the background of a window:
http://www.mail-archive.com/cocoa-dev#lists.apple.com/msg16280.html
There's also a CGSRemoveWindowFilter:
extern CGError CGSRemoveWindowFilter(CGSConnectionID cid, CGSWindowID wid, CGSWindowFilterRef filter);
Just be aware that the usual private API caveats apply (might go away or change in the future, etc.).
What I've done:
In IB, add a window-sized custom NSView to the window, at the bottom of the content view hierarchy. Set the object's class to MySolidView (or whatever.)
In Xcode, the MySolidView class does just one thing: on -drawRect it will fill the view with a solid color. (e.g. light grey).
You could write your own sheet animation routines that display your own NSWindow and fill the background of the window with a semitransparent colour. I'm not sure whether setAlphaValue: for NSWindow will also affect the child elements' opacity. If it does affect them, you could use setBackgroundColor: and provide the default window background colour but with an alpha component, this should not affect the child elements.
I suppose one of the problems of developing/designing your own user interface is when you have to reimplement the wheel just for a minor customisation. At least, if you write it yourself, you'll have more control over its customisation in the future.

IKImageView and scroll bars

I have an NSScrollView with an IKImageView inside to display images. This seems to work.
However, if I make the window smaller than the image, the scrollbars appear as they should, but the BOTTOM of the image is locked to the bottom of the window, instead of the top of the image being locked to the top of the window. In other words, I want the image to not move on the screen when I re-size the window from the bottom right.
I understand why this is, because in All of these classes, the origin is in the lower left, not the upper left. However, It's still behaving wrong. If you look at any other product (including Preview, which I assume is written with some of these libraries) the image/content/whatever, is locked to the top not the bottom.
How do I do this?
I've looked for methods in the NSScrollView and IKImageView. I've considered capturing the scroller events and manually moving the image down or up as appropriate, but I haven't seen a way to do this (Set the selector to a method I write in the controller?) and anyway, that seems very messy...
Is there an easy way to do this?
thanks.
Solution for future reference:
Make a subclass of IKImageView with only one over-ridden method:
-isFlipped()
{
return YES;
}
This subclass will also prove useful if I find that I need to re-implement the rotate:(id) method and the setImage:(NSImage) method which exist in the class (and in the case of rotate are USED IN THE DEMO supplied by Apple) but not documented, and therefore not officially supported...