ListBox row click selects wrong row

[quote=248579:@Eli Ott]System.Gestalt is used in NSPopover albeit being not available is OS X anymore. Solution:

Line 9 in NSPopover:

if keyboard.asyncOptionKey = false and rvalue >= 1070 then

Replace it with:

if false then

Indeed that fixes the listbox part but it messes the popup design, once i replace the line it works properly but the < part of the popup disappears, not that it`s a bad thing, in the end i need that list to be functional, but it will be nice to have it all working,

I`ll try Michel workaround as well.

Thank you all for the ideas and support.

It seems as well that it messes the location of the popup, if i keep [quote]if keyboard.asyncOptionKey = false and rvalue >= 1070 then[/quote] and i put the window on a corner of the screen to simulate a small screen then the popup goes to the left and on the base of the screen , if i put the code if false and rvalue >= 1070 then then the listbox works properly but it puts the popup on the good side as well but dont respect the bottom screen location so the popup goes under the available screen and you cannot see the bottom part anymore. I guess it is another bug or that is the downside of the keyboard part but i dont see the link between the keyboard and the location on constructor, i`ll have to do more debugging.

Thanks again.

Hello Eli,
Can you be more specific, it seems that indeed that rvalue creates the issue so the System.Gestalt call in the statement.

I should get rid of it and so far can somebody tell me what that value is ? so far i did not found anything related to it.

Thanks.

[quote=248586:@Michel Bujardet]me.selected(me.RowFromXY(x,y)) = False
me.selected(me.RowFromXY(x,y+me.RowHeight)) = True[/quote]

Thanks Michel,

It seems that the code does the job but i noticed something weird, if i select the list as multiple, that will be my case, if i want to unselect one item , i have to press on the line under it to select it , so i select the row just by clicking on it without the Command key pressed and if i want to unselect one item i have to go to the one under , while if changing the code according to Eli it works upside down, i have to press on the top row to select the desired one, if i remove the mouse up and down code it works ok but the popup location goes nuts.

[quote=248675:@Aurelian Negrea]Thanks Michel,

It seems that the code does the job but i noticed something weird, if i select the list as multiple, that will be my case, if i want to unselect one item , i have to press on the line under it to select it , so i select the row just by clicking on it without the Command key pressed and if i want to unselect one item i have to go to the one under , while if changing the code according to Eli it works upside down, i have to press on the top row to select the desired one, if i remove the mouse up and down code it works ok but the popup location goes nuts.[/quote]

The workaround was for a single select.

If you want multiselect, you must manage it yourself, for instance with an array, since what it does is to deselect the wrong select before selecting the row that was clicked.

In other words, I provided a basic principle, now you got to work on that yourself…

I am sure you will succeed, with some efforts.

we should rather not use the popup as it is as it brings to many issues. Although the thing with the workaround solves the listbox issues it doesn’t help if you put a canvas in the window of the popup as the coordinates are messed up too.

I have used for several years the solution from Bill Gookin. It also has the advantage of being cross platform, and does not present this messy coordinates shift.

See https://forum.xojo.com/7533-popovers-my-solution/0

[quote=248769:@Michel Bujardet]I have used for several years the solution from Bill Gookin. It also has the advantage of being cross platform, and does not present this messy coordinates shift.

See https://forum.xojo.com/7533-popovers-my-solution/0[/quote]

Hello Michel , Well i`ve looked as well but it seems that i cannot manage to have the popup next to the button and to properly show the popup.

i`ve put this code in the button action part [code] dim w As New winListBox

w.displayPopoverAt me.Left + me.Width , me.Top[/code]

and it shows the popup but on the wrong place .

Something like this :

I guess i`m doing something wrong there. I tried to follow the project details.

Thanks for the update.

[quote=248769:@Michel Bujardet]I have used for several years the solution from Bill Gookin. It also has the advantage of being cross platform, and does not present this messy coordinates shift.

See https://forum.xojo.com/7533-popovers-my-solution/0[/quote]

I have been using scaled custom shapes as popovers too. Bill’s popover was a goods inspriation but he stopped the project.
In general the native one is the solution I would prefer. I am confident someone is using the native cocoa popover in xojo without any issues. The popover is one of the most useful controls followed by a scollview.

[quote=248797:@Aurelian Negrea]Hello Michel , Well i`ve looked as well but it seems that i cannot manage to have the popup next to the button and to properly show the popup.
[/quote]

You did not quite understand how it works. Note the line in Label. It is not using simply me.top. You got to add self.top and y. Same thing for left. It does not seem too off because the window is at left 10. Try to adapt what Bill used :

w.displayPopoverAt self.Left + me.left + x, self.top + me.top + y, 0

I discovered Bill’s solution after creating my own that was not quite as good. I do not think the fact he stopped the project is such a problem, as he shared his code, and any good programmer can adapt it to his needs.

I will gladly take what exists and works decently today than wait for an elusive perfect future declare I am not able to come up with.

[quote=248807:@Michel Bujardet]You did not quite understand how it works. Note the line in Label. It is not using simply me.top. You got to add self.top and y. Same thing for left. It does not seem too off because the window is at left 10. Try to adapt what Bill used :

w.displayPopoverAt self.Left + me.left + x, self.top + me.top + y, 0

Well your code does not work, please note that this code is in the Action event of the push button so we don`t have x and y so by using same code without the x and y i get the popup to be close to the button but still wrong place and still cannot auto adjust if put on the left or right corner of the screen to simulate a small screen, half the popup does not show in my case .

Thanks for the idea, i`ll dig more.

So by putting this in the Action handler i have the image in the snapshot.

w.displayPopoverAt self.Left + me.Left + me.Width, self.Top + me.Top + me.Height/2, 0

I guess i did got it how it works, just needs more tweaking, if you see the image , the window is on the left down side of the screen, the popup shows but 30 % is cut and you cannot see it on the screen , i guess i have to find a way to get max of the screen and then to minus the distance between the button and the bottom of the screen and shift it but so far i have to see where i set the position of that < triangle that comes on the middle of the button.

[quote=249265:@Aurelian Negrea]Well your code does not work, please note that this code is in the Action event of the push button so we don`t have x and y so by using same code without the x and y i get the popup to be close to the button but still wrong place and still cannot auto adjust if put on the left or right corner of the screen to simulate a small screen, half the popup does not show in my case .

Thanks for the idea, i`ll dig more.[/quote]

x and y is the nudge to make the arrow show where you want. What you ended up doing apparently.

Remember, the popover in this instance is a window. That explains why the coordinates are relative to the screen, and not the app window. Likewise, it falls on your responsibility to position it and dimension it so it does not get cut.

Thanks Michel , it seems that i found some workarounds but still the top part does not get as it should be , on the code i tried to change what i could based on my understanding.

So far in the sample project the right down list works properly when you enlarge the main window as well but the top left it goes nuts and it`s like it does not care about the screen .

Any ideas?

Thanks .

it seems that i got the locations of code handling the position, its in the setWindowShape, ill have to dig more into that

In CustomListBox.bbDropList.Action the coordinates you supply only accidentally appear to work. MouseX is the cursor position relative to the Window, and Self.Left is the position of the CustomListBox on the Window. These happen to line up with the default placement of the window, but not in general.

Forget the mouse position, what you want is the top left corner of bbDropList in screen coordinates.

The top/left of bbDropList is it’s position in CustomListbox. The top/left of CustomListbox is it’s position in the Window, and the Windows top/left is it’s position on screen. From this place in code, bbDropList.Action, you refer to each of those with Me, Self, and Self.Window, respectively.

With the following bbDropList.Action code the Popup arrow is always touching the top/left corner. Use these screen coordinates to test which side to show on and x+Me.Width is the right side and y+Me.Height/2 is halfway down.

[code]Sub Action()

dim w As New winListBox

dim x, y As integer
x = Me.Left + Self.Left + Self.Window.Left
y = Me.Top + Self.Top + Self.Window.Top

w.displayPopoverAt(x, y, 1)

End Sub[/code]

Note, this sum will stop working if the CustomListbox is nested inside other ContainerControls. You’d need to loop up the parents or something.

[quote=250853:@Will Shank]In CustomListBox.bbDropList.Action the coordinates you supply only accidentally appear to work. MouseX is the cursor position relative to the Window, and Self.Left is the position of the CustomListBox on the Window. These happen to line up with the default placement of the window, but not in general.

Forget the mouse position, what you want is the top left corner of bbDropList in screen coordinates.

The top/left of bbDropList is it’s position in CustomListbox. The top/left of CustomListbox is it’s position in the Window, and the Windows top/left is it’s position on screen. From this place in code, bbDropList.Action, you refer to each of those with Me, Self, and Self.Window, respectively.

With the following bbDropList.Action code the Popup arrow is always touching the top/left corner. Use these screen coordinates to test which side to show on and x+Me.Width is the right side and y+Me.Height/2 is halfway down.

[code]Sub Action()

dim w As New winListBox

dim x, y As integer
x = Me.Left + Self.Left + Self.Window.Left
y = Me.Top + Self.Top + Self.Window.Top

w.displayPopoverAt(x, y, 1)

End Sub[/code]

Note, this sum will stop working if the CustomListbox is nested inside other ContainerControls. You’d need to loop up the parents or something.[/quote]

Thank Will but it seems that the issue is still there .

So to explain.

On the top listbox when you press the blue button the popover goes outside the screen, down listbox works properly, if you enlarge the window to the whole screen it readjusts properly

i did put some code in the button according to your recommendations and i added some lines so that it shifts on left or right according to the position of the listbox on the screen.

[code]dim w As New winListBox

dim x, y As Integer

x = me.Left + self.Left + self.Window.Left
y = me.Top + Self.Top + Self.Window.Top

dim location As Integer

If Screen(0).Width /2 < x Then
location = 1
Else
location = 3
End If[/code]

i`ll have to tune it more.

As said the down right one works always perfectly, but the upper left one even with our code changes still goes outside the screen area.

As for the CustomListBox that will be placed on a window so normally that should be the final control on the window, i hope it will not affect anything , same as the current setup.

I have to see this issue,

Now , i know that i have top and bottom options on the popup but i want just the left/right options and the popup to shift up/down according to the location, so that nudge should mode as the one in the right down, but the problem is that it is not moving and i don`t know why, i guess it is something related to the offset i have to see where exactly.

And the idea will be so that it does not cover the main one for reference so it should be something like that :

[code]dim w As New winListBox

dim x, y As Integer

x = me.Left + self.Left + self.Window.Left
y = me.Top + Self.Top + Self.Window.Top

dim location As Integer

If Screen(0).Width /2 < x Then
location = 1
w.displayPopoverAt(x - self.Width + me.Width ,y + me.Height/2,location)
Else
location = 3
w.displayPopoverAt(x + me.Width,y + me.Height/2,location)
End If[/code]

The issue on the top one still remains that it goes outside the visible screen area .

Thanks again.

Well it seems that im using container in container so as expected the position is messed up , ill have to see this part as well.