Have NSRunAlertPanel show an alert on any space? - Objective-C/10.7+ - objective-c

I'm working on an app that is marked as LSUIElement and its main window is a NSPanel 'attached' to the status bar. Sometimes I need to display a normal alert panel (either by using NSRunAlertPanel or NSAlert). However, it's very important that the panel is always shown on the space the user is currently on (otherwise the user might not see it immediately and it's important that he does).
The problem is that alerts are always shown on the space where the user last interacted with the application's windows, NOT on the current space. So, for example, if on space number 1 I open and close my app's NSPanel, then I move to space number 2 and some time later my app shows an alert, that alert will be shown on space number 1, not 2. And thus I (or the general user) won't see the alert until I decide to switch to the first space.
Is there any way to change this behavior (= to make an alert always show on the current space)?

Not exactly what you're asking, but maybe before you show your alert window set its collection behavior to NSWindowCollectionBehaviorCanJoinAllSpaces using setCollectionBehavior:. The window should then appear on all spaces, which includes the current one...

Related

Possible to make an OS X with a window that blocks a portion screen like the system menu bar?

Is it possible to create a NSWindow that will not only is above all other windows (including other applications) but also able to block windows from going "into" that window. Basically I would like to extend the system's menu bar by having another bar below it, but it stops the user from resizing other windows to occupy that space.
For instance, if the user was to maximize a window, it would only be able to have a height of the screen size minus the system status bar minus my application's window.
I was thinking it may be possible by listening to some sort of window resizing notification and if the user tries to set the frame of that other window to a size that would go inside of my application's window then I would resize the other window, but method seems like such a pain.
I also acknowledge that this may not be possible, but was curious if it is!
Thanks in advance!
It is totally possible to make a window which is above all other windows, just set It's level to NSMainMenuWindowLevel.
But preventing other windows from resizing beyond It, I don't think so.
Even if there is a system API to limit window resizing (I don't think there is), some apps use custom code to control window resizing and would completely ignore the presence of your "special" window. I've seen apps which simply hardcode 22 (the height of the menu bar) when calculating window resizing stuff.

How do I properly move a scrollview when assigning a first responder?

I have a form in a UIView which consist of multiple textfields, couple of textviews and two fields that are interacted with by the means of an invisible button overlaid on them. When you click on a textfield, the keyboard pops up for text entry and I added a toolbar on it for navigating to the previous and next data entry (whatever the data entry is, be it a textfield, textview or one of the two special cases that are interacted with a button). Now, when I navigate with between textfields with those buttons everything works fine. My scrollview's content moves along the element that becomes the firstresponder (with the help of a piece of code from stackoverflow that scrolls the view while taking into account the height of the keyboard that hides a good portion of it). Here is a visual example.
The problem arises when I want to switch out of a specific data entry (date) that interacts with a hidden button. I'll give some context first. Those data entries show datepickers (one for the date, another for the time) in action sheets, and those action sheets also have navigating button in a toolbar, like so.
The code from stackoverflow that readjust the view do so in the didBeginEditing delegate methods of the textfields and textviews, so when I assign them first responder the scrollview adjust itself while taking into account the keyboard.
This means that, in the case that I switch into a special data entry, I manually move the scrollview's content so I can view the next element. When I switch from a special entry into a textfield I assume that the previously mentioned code from stackoverflow kicks in and adjust the view. It actually does when I move from the hour data entry (which uses a datepicker in an actionsheet) into the next element which is a textfield. However, when I'm at the date data entry (which is directly before the hour data entry) and press previous to assign the first responder to the textfield above it, the scrollview goes way ahead the text field, like so.
What's important to note is that this problem only occurs when the textfield is not in view. This makes me suspect that I'm incorrectly using the code that readjust the view. For instance, there is a constant in the code that represents the height of the keyboard. I tried changing it from 216 to 260 (so it takes into account my toolbar added on top of the keyboard) but this results in strange black artifacts near the buttom that only occasionally appears.
I'm kind of lost in this bug, and my post is already pretty long. I've prepared an example of my problem in a new project, if any of you could take a look into it I'd be very appreciative.
Here it is

Save Data Between Screens

I have an iPhone app with a form that has terms and conditions. When the user taps on the terms and conditions link, it brings them to another screen within the application that shows them.
Now, when they tap away and come back they lose all of the information they placed into the fields. Is there any way of saving this data in the forms short of storing everything in a dictionary when they leave and when the view reloads filling it back?
Can you use a UIAlertView for the terms and conditions? I've used this in a few apps. Longer text automatically creates a scroll in the alert. This will keep you from needing to leave the screen at all.
You will need to have some way of saving that data when the user leaves the screen using a dictionary or some other means. So the short answer is no.
A longer answer is that you could change how you are navigating to the new screens and prevent this screen from getting dumped when you move on.

is it possible to draw on menubar (not statusbar area)?

Is it possible to place a custom NSView on top of the menubar?
I need to have a view permanently visible, as like in the statusbar, but need more real estate. BTW is the real estate of an NSStatusbarItem limited?
A status item can be as big as it needs to be, but menus always take precedence—if the menus and the status bar overlap, the menus will temporarily hide as many status items as necessary from the status bar, to be automatically re-shown once there's space again. This is by design; there is no way for you to defeat that.
You should either only show things that are worth showing, or enable the user to decide what things are worth showing and only show the ones the user chose.
If the user switches to an application with enough menus to suppress your status item, they'll just have to deal with that on their own (either by adjusting the order in which they launch status-item applications, so that yours launches earlier and thus is farther right in the status bar, or by switching to another app with fewer menus in order to use your status item).

Keeping window of another application active while still receiving mouse events from another app's window?

Is there a way to have my app's window receive keyboard and/or mouse events (i.e. user clicking on window's buttons) while still retaining focus to another, unrelated app?
I've tried configuring my window at different levels, including [myWindow setLevel:NSPopUpMenuWindowLevel] to no avail.
You should be able to handle mouse clicks without ordering your window front by making your views (at least the ones that handle mouse clicks) respond to acceptsFirstMouse: messages by sending NSApp a preventWindowOrdering message and then returning YES.
You should not make your app handle typing without ordering itself front. The user might not realize where their typing is going if the field where it's appearing is obscured by another window.
Found it. Simple, yet elusive.
Use NSPanel and make sure panel style is Non Activating (NSNonactivatingPanelMask) or tick the same option in IB's inspector.