NSPopover

Did anyone crack the NSPopover? I could really do with it in an app. Many thanks

Haven’t seen if this works in a while but maybe this project is helpful?

https://xojo.io/1b03dc7fe603

what do you mean with ‘crack the NSPopover?’

if you need a Popover Example try Sam’s Popover

+1 for Sam’s Popover. I’m ‘Doofus’ but started getting occasional crashes with my code. Since switching to Sam’s code no more crashes :slight_smile:

I also got it in the MBS Plugins 4 years ago:
https://www.monkeybreadsoftware.net/class-nspopovermbs.shtml

[quote=209688:@Christian Schmitz]I also got it in the MBS Plugins 4 years ago:
https://www.monkeybreadsoftware.net/class-nspopovermbs.shtml[/quote]
So this is why we do not have it built-in Xojo ! [;-:)]

[quote=209688:@Christian Schmitz]I also got it in the MBS Plugins 4 years ago:
https://www.monkeybreadsoftware.net/class-nspopovermbs.shtml[/quote]

Any alternative (even simpler) solution for Windows?
So to make it cross-platform…

[quote=209609:@Jason King]Haven’t seen if this works in a while but maybe this project is helpful?

https://xojo.io/1b03dc7fe603[/quote]

This one includes macoslib – that hudge, unsplittable bunch of mysterious classes and methods :wink:

[quote=209610:@Axel Schneider]what do you mean with ‘crack the NSPopover?’

if you need a Popover Example try Sam’s Popover
[/quote]

Hmm… “BE WARNED: This messes with the Xojo view hierarchy, which is considered to be potentially unstable. So use at your own risk.”

[quote=209688:@Christian Schmitz]I also got it in the MBS Plugins 4 years ago:
https://www.monkeybreadsoftware.net/class-nspopovermbs.shtml[/quote]

That’s the MBS Lion plugin, “only available as part of the Complete package”, which means 199€ (+VAT).

I was looking for an acceptable NSPopover solution for my project and ended up displaying a ContainerControl with a fake pre-rendered shadow, drawing the “tail” and border myself. I think it looks quite OK. The drawbacks are: no standard OS X open/close animation, no translucency and no way to display it outside the window. I can live with that for now :wink:

That has a reason. I could sell it alone, but you’d also require other plugins like the Cocoa plugin.

[quote=209725:@jean-paul devulder]hi,

dtPlugins have also NsPopOver

link: [/quote]

dtPlugin/Examples/dtPopOver does not open anything for me, just tried all four example projects (OS X 10.10.5, Mid-2011 iMac) and no popover appears. How to use it?

Indeed. But it also allows you to create a popover from a window that will not mess with the Xojo view hierarchy, and can be attached to a NSStatusItem. Attaching one to an NSStatusItem is problematic for the original class in MacOSLib and likely a problem for other code here as well since normally it depends on having a window open to preserve the view but with the project in the link I posted you don’t need to have a window open at all.

The dtPlugin popover is very easy to use.
Create a container with all controls you need and link it to a popover. This way you can easily create complex native popovers.

It is also possible with MBS. But creating a popover with several controls is trivial (you have to dynamically code them). Maybe Christian can make it work with containers too.

MacOSLib Example:

What a beautiful ui you’ve made there!

Stop flirting in public Tim!

Sam, I really like your NSPopover solution and implemented it with success. Thanks.
There is only one problem, which is not from your code, but may be you have a solution.

Problem is putting a listbox in the popover: mouse clicks are shifted down by ~5 pixels. So that when I click the first row of a listbox, the header get pressed. Clicking the second row, the first row gets selected, and so on.
I believe this has to do with the fact the Xojo listbox is not a native control, and I tried some possible solutions but with no avail.

Btw, I also used the same technique using the MBS plugins and attaching a window’s content view to a NSPopover, with the same result, so I’m pretty sure there is nothing bad on your code.

May be you or someone else has a solution.

Unfortunately a known issue: https://forum.xojo.com/30036-listbox-row-click-selects-wrong-row/0/

but I am confident it’s not the code.

If you use the MacOSLib NSPopover it won’t work either either. The x,y co-ordinates are also messed up
in a canvas for example. You can’t basically use the popover for such things as far as I know, sadly.

Would be good if could find out and patch it.

Yeah listboxes don’t like to play well with anything other than standard windows.

For NSPopover, I ended up faking a listbox, by using a canvas and putting it into a scrollview.

For NSScrollView, I ended up having to reset the listbox position on mouse down by finding the listbox position within the window, then additionally calling .refresh on it.

[quote=254463:@Rob Egal]If you use the MacOSLib NSPopover it won’t work either either. The x,y co-ordinates are also messed up
in a canvas for example. You can’t basically use the popover for such things as far as I know, sadly.[/quote]
I added a function in to the “InterfaceKit” module of the Retina Kit 3.0 for grabbing and converting the location.

Below is the main function, there’s a couple of helper functions that are part of the module.

[code]Function currentMousePosition(Extends inControl as rectControl, flip as boolean = false) As realbasic.point
#if TargetCocoa then
Dim inControlRef as integer = inControl.handle

declare function getWindow lib AppKit selector "window" ( ref as integer ) as Ptr

#if target32Bit then
  declare function mouseLocationOutsideOfEventStream lib AppKit selector "mouseLocationOutsideOfEventStream" ( winHandle as Ptr ) as IkPoint32
  declare function convertPoint lib AppKit selector "convertPoint:fromView:" ( ref as integer, inPoint as IKPoint32, fromView as Ptr ) as IKPoint32
#else
  declare function mouseLocationOutsideOfEventStream lib AppKit selector "mouseLocationOutsideOfEventStream" ( winHandle as Ptr ) as IKPoint64
  declare function convertPoint lib AppKit selector "convertPoint:fromView:" ( ref as integer, inPoint as IKPoint64, fromView as Ptr ) as IkPoint64
#endif

dim mousePosition as realbasic.Point = XojoPoint( convertPoint( inControlRef, mouseLocationOutsideOfEventStream( getWindow( inControlRef ) ), nil ) )

if flip then
  Dim fRect as realbasic.Rect = frameRect( ptr( inControlRef ) )
  mousePosition.y = fRect.height - mousePosition.y
end if

return mousePosition

#endif
End Function
[/code]

Thanks Sam!

Not to resurrect an ancient post but I’ve been having the same problem with canvas based controls not having their mouse coordinates remotely correct when embedded into a popover window.

the mouse move event seems to return the correct coordinates when the container is embedded into a popover window, but the mouse down and mouse drag events are completely bizarre. They are, however, bizarre in a predictable fashion. So in every mouse move event I save off the x and y coordinates, and then in the mouse down of the canvas I create a correction factor by subtracting the previous mouse move events values for X and Y with the current mouse down coordinates for X and Y. I can then continue to add in those corrections during the mouse drag event to get some valid numbers.

This works only if you filter the completely weird values that are sometimes returned from the event that are much larger or much smaller than your width and height. It seems I get valid drag coordinates only while I”m dragging. If I stop moving the mouse it sends some arbitrarily large number continuously even though the mouse isn’t moving. So you also need to filter out values that are wider than your control or taller than your control.

Between those 2 things I now can have canvas based controls on a popover window and more or less assure myself that I’m getting the mouse down and drag event coordinates correct.

it’s still a shame this is so broken. This shouldn’t be that hard.