Cursor over NSView placed over NSTextField - macos

I have a semi-transparent NSView subclass that acts as a kind of tooltip. When the tooltip is drawn on the screen it draws on top of a form and so it covers a couple of NSTextField's.
When I hover the mouse over the tooltip at the spots where a NSTextField exists, the cursor changes to the input style cursor.
How can I prevent the cursor from changing?

Overlapping views are not really supported very well in Cocoa and the behaviour is undefined.
Instead, your tooltip view should be in its own borderless window, large enough to contain your view. The tooltip window should be a child window of the main window it's attached to. To make a window a child of another window, you use the addChildWindow:ordered: method of NSWindow.
Child windows are attached to the parent window and will move with their parent window when the parent window moves. If you just open a new window without making it a child window, it will be "left behind" if the other window is moved.
To make a borderless window, pass NSBorderlessWindowMask as the styleMask to the initWithContentRect:styleMask:backing:defer: method of NSWindow.

Related

How to disable default cursor on transparent titlebar of NSWindow?

I create a NSWindow with transparent title using:
setTitleVisibility:NSWindowTitleHidden
setTitlebarAppearsTransparent:YES
setMovable:NO
and the style includes NSWindowStyleMaskFullSizeContentView. The window becomes title-less, zoom and fullscreen modes work well. Everything is ok, except the mouse cursor. It becomes the default one when I move it to the area where titlebar would be located if it was visible.
Is it possible to override this behavior so that the mouse cursor shape will be defined by the window content (which uses addCursorRect)?
There's a difference between a transparent titlebar and no titlebar at all. It sounds like you have a window with a transparent titlebar, but you want a window with no titlebar.
If you want no titlebar at all, you need to make sure the window's styleMask does not have NSWindowStyleMaskTitled.
If you create the window in a xib or storyboard, you can turn off the “Title Bar” checkbox in the window's Attributes inspector.
If you create the window in code, you can set the styleMask using the initWithContentRect:styleMask:backing:defer: initializer, or you can set the styleMask after creation.
For example, this line will remove the NSWindowStyleMaskTitled bit from an existing window's styleMask:
self.window.styleMask &= ~NSWindowSytleMaskTitled;

How to display NSWindow within the main window in Cocoa?

I want to show a new window when an user taps on a button in the main window, but when I called the separate window using makeKeyAndOrderFront, the window popped up far away from the main window.
Here's what I wrote, in a subclass of NSViewController:
myWindow = NSWindow()
myWindow.setFrame(myView.frame, display: true)
myWindow.contentView = myView
myWindow.makeKeyAndOrderFront(self)
However, this opens a new window outside of the main window. I want to display it within the main window, possibly in the center of the main window (I set the .frame value of myView to be positioned on the center).
So how can I call the new window within the main window? In other words, can I specify where the new window shows up?
You'll need to convert the coordinates and or rect to screen space.
NSView and NSWindow provide methods that begin with "convert" take a look at those.
Sometimes you'll need to chain to convert from view space to window then window to screen.
Keep in mind that a window has an NSScreen screen method and that a window could appear on many different size screens and potentially span multiple screens.

How to autoscroll when mouse is near the edge of window

I have an (big) NSImageView embedded in an (smaller) NSScrollView. I want to automatically scroll if the mouse goes near the edge of the window, how do I do this?
You could create an NSTrackingArea to be notified when the mouse enters a particular area of a view and then use one of NSResponder's scroll.. routines to scroll the view.
Cocoa has a built in method called NSView.autoscroll(with:) which will automatically scroll the enclosing scroll view when tracking mouse events and the cursor is outside of the scroll view's clip view.

How to write an own resize corner/handle for an NSWindow?

How can I write an own resize corner/handle for an NSWindow? I'm using a subclass of an NSWindow without the default resize corner, but I need it for my window.
The basic outline:
Create a view.
Put some "drag me" indicator appropriate to your window in the view.
Have the view's drag action method respond by resizing the window so that the corner in question is now located at the current mouse position.

NSPanel parent window floats on top of full-screened NSView

I have an NS panel that is the child of an NS Window; the panel is set to floating window level. The parent window has an NSView that is in full screen mode, so the NSPanel, is floating on top of the full screened NSView. Anytime I click the panel, it brings the parent window into floating mode as well, such that it renders on top of the movie. Is there any way for me to prevent this?
Whenever you enter fullscreen mode, why don't you just remove the panel as a child window? It should still be displayed and function, but then it won't bring the other window forward. Then when you exit fullscreen mode, add it back as a child window.

Resources