Problem with mouseover and context menues

Discuss any general programming issues here
Post Reply
ilbarbax
Posts: 163
Joined: Thu Apr 01, 2010 6:41 pm

Problem with mouseover and context menues

Post by ilbarbax »

I have a strange behavior that I can't avoid as follow:
I have established an event on a number of buttons when mouse is over.
Then I added a context menu to do something activated when the mouse is over a button and obviously right mouse click.
Now if a do something trough the context menu options everything continue to work as expected.
If I do a cancel option on the selected context menu function everything continue to work as expected.
If I decide to do nothing and then I click elsewhere to disable the context menu the on mouseover option works ONLY for the latest button selected and I can't return to the default situation even freeing the context menu.

Got the problem with HW11 and HW10 too. Tested on Windows 10 and Aros, same behavior.

I'm arranging a test case asap or I can supply the whole script if required at sb5@libero.it

regards
plouf
Posts: 717
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Problem with mouseover and context menues

Post by plouf »

you have use custom functions to process menu item "mouseover" AND "right click over button" ?
context menu do it them selfs

does this problem occur and in this simplified example ?
(i cant reproduce or i have not understand ?)

Code: Select all

xml$ = [[
<?xml version="1.0" encoding="iso-8859-1"?>
<application>
<menu title="Context menu" id="ctx1">
   <item id="1.1">Cut 1</item>
   <item id="1.2">Copy 1</item>
   <item id="1.3">Paste 1</item>
</menu>
<menu title="Context menu" id="ctx2">
   <item id="2.1">Cut 2</item>
   <item id="2.2">Copy 2</item>
   <item id="2.3">Paste 2</item>
</menu>
<menu title="Context menu" id="ctx3">
   <item id="3.1">Cut 3</item>
   <item id="3.2">Copy 3</item>
   <item id="3.3">Paste 3</item>
</menu>

	<window title="Test">
		<vgroup>
				<button id="b1" contextmenu="ctx1">1</button>
				<hline/><rectangle/>
				<button id="b2" contextmenu="ctx2">2</button>
				<hline/><rectangle/>
				<button id="b3" contextmenu="ctx3">3</button>
		</vgroup>
	</window>
</application>
]]

@REQUIRE "RapaGUI"


moai.CreateApp(xml$)
Function p_EventFunc(msg)
	ForEach(msg,DebugPrint)
EndFunction

InstallEventHandler({RapaGUI = p_EventFunc})

Repeat
	WaitEvent
Forever
Christos
ilbarbax
Posts: 163
Joined: Thu Apr 01, 2010 6:41 pm

Re: Problem with mouseover and context menues

Post by ilbarbax »

I'm not using rapagui but plain Hollywood code.
I have to verify... you may have given me an hint anyway
plouf
Posts: 717
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Problem with mouseover and context menues

Post by plouf »

yes i see this in this example, however EnableButton() makes this active !?

check this simplified example and comment/uncomment EnableButton()

Code: Select all

CreateMenu(1, {{"Unused", {
   {"Cut1", ID = "cut1"},
   {"Copy1", ID = "copy1"},
   {"Paste1", ID = "paste1"},
}}})
CreateMenu(2, {{"Unused", {
   {"Cut2", ID = "cut2"},
   {"Copy2", ID = "copy2"},
   {"Paste2", ID = "paste2"},
}}})

CreateMenu(3, {{"Unused", {
   {"Cut3", ID = "cut3"},
   {"Copy3", ID = "copy3"},
   {"Paste3", ID = "paste3"},
}}})


Function p_EventFunc(msg)
	ForEach(msg,DebugPrint)
	DebugPrint("--------------")
	If msg.action="OnRightMouseDown"
			PopupMenu(msg.id)
			;EnableButton(msg.id)
	EndIf
EndFunction

evtmatch= {onMouseover = p_EventFunc,OnRightMouseDown= p_EventFunc}
MakeButton(1, #SIMPLEBUTTON, 10, 10, 50, 50,evtmatch)
MakeButton(2, #SIMPLEBUTTON, 100, 10,50, 50,evtmatch)
MakeButton(3, #SIMPLEBUTTON, 200, 10,50, 50,evtmatch)

Box(10, 10, 50, 50,#RED)
Box(100, 10,50, 50,#RED)
Box(200, 10,50, 50,#RED)

Repeat
	WaitEvent
Forever
Christos
ilbarbax
Posts: 163
Joined: Thu Apr 01, 2010 6:41 pm

Re: Problem with mouseover and context menues

Post by ilbarbax »

Here you have my text case replicating the actual structure and behaviour of my program.
if you go over the red boxes they will change to yellow.
if you click right mouse the popup menu appear. Choose one option and then pass over the red boxes and they will change to yellow.
Now if you click right mouse the popup menu appear then click on the gray area, the popup menu disappear but only one red box will change to yellow.

Code: Select all

@DISPLAY 1,{Title = "Test", Width=600, Height=420, Color = #SILVER}

Function p_Btn_event_handler(btn_msg)
	  Switch btn_msg.action
		
		  Case "OnMouseOver":
					act_icon=btn_msg.id
					DisplayBrush(act_icon+10,30+act_icon*60,30,{AnchorY = 0.5, AnchorX = 0.5})	
		  Case "OnMouseOut":
					DisplayBrush(act_icon,30+act_icon*60,30,{AnchorY = 0.5, AnchorX = 0.5})	
					act_icon=999
	  EndSwitch
EndFunction

Function p_Menu_Define()
	; Context menu definition
		CreateMenu(3, {{"Links", {
			{"option 1", ID = "opt1"},
			{"End", ID = "quit"}
			}}})
EndFunction

Function p_MenuOn(mn_msg)
		If act_icon=999 Then Return
		PopupMenu(3)
EndFunction 

Function p_MenuFunc(mnu_msg)
	Switch mnu_msg.action
		Case "OnMenuSelect":
			Switch mnu_msg.item
				Case "opt1"
					ret=SystemRequest("Test","Select cancel ","Yes|Cancel")
					If ret>0 Then Return
				Case "quit"
					End
			EndSwitch
	EndSwitch

EndFunction

; ================================================================================================0000

EscapeQuit(True)

CreateBrush(1,40,40,#RED)
CreateBrush(11,40,40,#YELLOW)
For k=2 To 5
 CopyBrush(1,k)
 CopyBrush(11,k+10)
Next
For k=1 To 5
	Box(k*60,0,60,60,#WHITE)
	MakeButton(k,#SIMPLEBUTTON,k*60,0,60,60,{OnMouseOver = p_Btn_event_handler,OnMouseOut = p_Btn_event_handler})	
	DisplayBrush(k,30+k*60,30,{AnchorY = 0.5, AnchorX = 0.5})	
Next

p_Menu_Define()

InstallEventHandler({OnRightMouseDown=p_MenuOn, OnMenuSelect = p_MenuFunc})

Repeat
  WaitEvent 
Forever
plouf
Posts: 717
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Problem with mouseover and context menues

Post by plouf »

the problem i saw it in you example, also in my second example appears
in both cases using EnableButton() in eventhandler seems like a working workaround (or maybe its the correct way ?)

in my example is ready , you can uncomment it ot see it happens

in your example add enablebutton in OnMouseOut OR in OnMouseOver OR in both and works

Code: Select all

		  Case "OnMouseOut":
					DisplayBrush(act_icon,30+act_icon*60,30,{AnchorY = 0.5, AnchorX = 0.5})	
					act_icon=999
					EnableButton(btn_msg.id)  ;<- this line added in onouseout only
Christos
ilbarbax
Posts: 163
Joined: Thu Apr 01, 2010 6:41 pm

Re: Problem with mouseover and context menues

Post by ilbarbax »

Thanks plouf it worked!!! I would never thought to the fact that buttons would may be disabled without an intentional action.
Post Reply