Alaska Software Inc. - XbpBrowse:itemRbDown ignores mouse position
Username: Password:
AuthorTopic: XbpBrowse:itemRbDown ignores mouse position
Itai Ben-ArtziXbpBrowse:itemRbDown ignores mouse position
on Thu, 17 Dec 2020 22:08:57 -0800
Hi Alaska,
The XbpBrowse:itemRbDown operates on the itemMarked, ignoring mouse
position.
It would be nice to be able to set the XbpBrowse behavior to change
the itemMarked to mouse position when ::itemRbDown event occurs.
I know I can rewrite this class to enforce such a behavior, but it
would be nice if Alaska enable such a feature in the native XbpBrowse.

Thanks,
-Itai
Itai Ben-ArtziRe: XbpBrowse:itemRbDown ignores mouse position
on Sat, 19 Dec 2020 12:52:12 -0800
I've tried in several ways (:Up() and :Down(), :PanUp() and
:PanDown(), :navigate(), etc.) to move the Browser-cursor and then
force ItemMarked when right-click (itemRbDown) is used, but all lead
to application crashing.

Does anyone successfully handle right-click at mouse position when
that position is not at the marked (highlighted) item?

Many thanks,
-Itai
Itai Ben-ArtziRe: XbpBrowse:itemRbDown ignores mouse position
on Sat, 19 Dec 2020 14:45:55 -0800
Further tastings reveal that programmatically navigation of XbpBrowse
where :ItemMarked is set, cause the program to crash.  Setting
:ItemMarked to Nil before the navigation starts, and restoring it when
the navigation ends does not solve the issue.  THIS SEEMS LIKE A BUG.
I suggests that Alaska turns off the :ItemMarked during
programmatically navigation and restore it only after :forceStable()
is issued.

Currently, I was able to get the following to work:  When a user
right-click an item, a popup menu FOR THAT ITEM is shown, but only if
there is no :ItemMarked.  Otherwise, a user must first mark
(left-click) the targeted item and then right-click it for the popup
menu.

-Itai
Andreas Gehrs-Pahl
Re: XbpBrowse:itemRbDown ignores mouse position
on Sun, 20 Dec 2020 19:34:24 -0500
Itai,

>The XbpBrowse:itemRbDown operates on the itemMarked, ignoring mouse
>position.

That doesn't seem to case. The XbpBrowse():ItemRbDown callback slot takes 
three parameters, which are the aMousePos, aRowCol, and oSelf. There is no 
difference between the behavior if an XbpBrowse():ItemMarked callback slot 
codeblock exists or not. And there is no xbeBRW_ItemMarked event created, 
when you right-click on any XbpBrowse cell.

>It would be nice to be able to set the XbpBrowse behavior to change
>the itemMarked to mouse position when ::itemRbDown event occurs.

You can set the XbpBrowse cell position when you right click on a cell, 
through the XbpBrowse():ItemRbDown callback slot by using the XbpBrowse():
ItemLbDown() method. You can do this no matter if an XbpBrowse():ItemMarked 
callback slot codeblock exists or not and there will be no runtime errors or 
crashes because of that.

Here is a simple example (you can modify the FBrowse.prg example):

oBrowse:ItemRbDown := {|aPos, aRowCol, oSelf| RBD(oSelf, aPos, aRowCol, oMenu)}
oBrowse:ItemMarked := {|aRowCol, uNIL, oSelf| SetTitle(oSelf, aRowCol, .t.)}
[...]
Procedure RBD(oBrowse, aPos, aRowCol, oMenu)
   SetTitle(oBrowse, aRowCol, .f.)
   oBrowse:ItemLbDown(aRowCol[1], oBrowse:GetColumn(aRowCol[2]))
   oMenu:PopUp(oBrowse, aPos)
return

Procedure SetTitle(oBrowse, aRowCol, lMarked)
LOCAL oDlg  := oBrowse:SetParent():SetParent()
LOCAL cText := iif(lMarked, 'Marked', 'Right Clicked')
   oDlg:SetTitle('Item ' + cText + ' at: ' + Var2Char(aRowCol))
return

Hope that helps, and...

Merry Christmas and a (hopefully much better) Happy New Year!

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com
[L]:   https://www.LinkedIn.com/in/AndreasGehrsPahl
[F]:   https://www.FaceBook.com/AbsoluteSoftwareLLC
Andreas Gehrs-Pahl
Re: XbpBrowse:itemRbDown ignores mouse position
on Sun, 20 Dec 2020 19:37:06 -0500
The following:

>That doesn't seem to case.

Should have been:

That doesn't seem to be the case.

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com
[L]:   https://www.LinkedIn.com/in/AndreasGehrsPahl
[F]:   https://www.FaceBook.com/AbsoluteSoftwareLLC
Andreas Gehrs-Pahl
Re: XbpBrowse:itemRbDown ignores mouse position
on Sun, 20 Dec 2020 19:47:41 -0500
Itai,

And if you want to also execute the XbpBrowse():ItemMarked callback slot 
codeblock from inside the XbpBrowse():ItemRbDown codeblock, you can add the 
following line of code to the RBD() function from the previous example:

	Eval(oBrowse:ItemMarked, aRowCol, NIL, oBrowse)

Hope that fixes your issues.

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com
[L]:   https://www.LinkedIn.com/in/AndreasGehrsPahl
[F]:   https://www.FaceBook.com/AbsoluteSoftwareLLC
Itai Ben-ArtziRe: XbpBrowse:itemRbDown ignores mouse position
on Mon, 21 Dec 2020 01:17:26 -0800
Andreas,
Thank you for the reply.
To put things in context, I use :ItemRbDown for a popup menu, but that
menu is dynamically built on :ItemMarked (different rows get different
popup menu items).

The problem is that aRowCol returns the mouse position in the browser
regardless of the populated rows (e.g. a browser of 10 rows where only
three are populated could return row 7 which has no data).
If I post :ItemMarked event, :forceStable(), and popup the built-up
menu, the program crashes.
Inserting Sleep(30) before the call to :PopUp did not solve the
problem.

I am still working on a solution for this and your input is helping
and welcome.  It seems, I should build all available menus once and
keep them in memory instead of building a relevant menu for each item
upon :ItemMarked. 

Again, many thanks for your response.
-Itai
Andreas Gehrs-Pahl
Re: XbpBrowse:itemRbDown ignores mouse position
on Mon, 21 Dec 2020 16:52:22 -0500
Itai,

>To put things in context, I use :ItemRbDown for a popup menu, but that
>menu is dynamically built on :ItemMarked (different rows get different
>popup menu items).

Without some code, it is hard to understand what exactly you are doing.

1) If you create (or update an existing) popup menu for a specific cell 
   within the :ItemMarked codeblock, then you should be able to use the 
   existing/current popup menu, as :ItemRbDown won't call the :ItemMarked 
   codeblock, so the popup menu will be (still) valid for the marked / 
   highlighted cell, as :ItemRbDown doesn't change that cell.

2) If you, on the other hand, want to create a new (or update an existing) 
   popup menu for a specific cell in the :ItemRbDown codeblock -- which is 
   a better approach then 1) in my opinion -- then you can use the currently 
   marked/highlighted cell to create/update the popup menu without doing 
   anything with the :ItemMarked codeblock. Just ignore the aRowCol value 
   of the xbeBRW_ItemRbDown event and use instead the current (marked or 
   highlighted) position in oBrowse:RowPos and oBrowse:ColPos.

Something like this:

oBrowse:ItemRbDown := {|aMPos, aRowCol, oSelf| PopUp_Menu(oSelf ,aMPos)}

[...]

Procedure PopUp_Menu(oBrowse, aMousePos)
LOCAL aRowCol := {oBrowse:RowPos, oBrowse:ColPos}
LOCAL oMenu   := XbpMenu(oBrowse):New():Create()
   [...]
   oMenu:PopUp(oBrowse, aMousePos)
return

If you post some code that shows what you are doing, it would  be much 
easier to help you, though.

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com
[L]:   https://www.LinkedIn.com/in/AndreasGehrsPahl
[F]:   https://www.FaceBook.com/AbsoluteSoftwareLLC
Itai Ben-ArtziRe: XbpBrowse:itemRbDown ignores mouse position
on Mon, 21 Dec 2020 15:53:06 -0800
Thank you, Andreas!!!
Yap!  Deleting and adding menu-items on :ItemMarked while
programmatically navigating the browser, and then calling for
:ItemRbDown overloads the processor and cause the crash.
The solution is to build the customized menu on :ItemRbDown, not on
:ItemMarked, so the navigation is light and free from reconstructing a
menu on each move.

Again, many thanks for your input.
-Itai