Right Click on a control

BlitzMax Forums/Brucey's Modules/Right Click on a control

Glenn Dodd(Posted 2008) [#1]
I have some code that works fine till i limit the popupmenu to particular controls.
In the TestPopupsMain.bmx i have:
Type MyFrame2 Extends MyFrame2Base

	Method OnInit()
		Super.OnInit()

		
'		ConnectAny(wxEVT_CONTEXT_MENU, OnContextMenu)
		m_listBoxPopup1.ConnectAny(wxEVT_CONTEXT_MENU, OnContextMenu)', Null, Self)
		' intercept all menu events And Log them in this custom event handler
		PushEventHandler(New MyEvtHandler.Create(Self))
	End Method


If i comment out m_listBoxPopup1.ConnectAny(wxEVT_CONTEXT_MENU, OnContextMenu)', Null, Self) and uncomment ' ConnectAny(wxEVT_CONTEXT_MENU, OnContextMenu)
then it works as expected.
BUT it produces the menu on items/spaces where i don't want it.

any ideas?

Cheers
Glenn

TestPopups.bmx


TestPopupsMain.bmx



Brucey(Posted 2008) [#2]
You have two sets of Connect/Any() plugged into a right-down/context menu event.
Is that what you want?

The first thing to happen will be the Right-down, which, if you want it to get to the context menu event, you will have to Skip() - otherwise it is consumed and will not advance to be further processed.


If you remove the Connects() for Right-Down, and change your context menu connect to :
Connect(ID_lb1, wxEVT_CONTEXT_MENU, OnContextMenu)

The menu opens as expected on the first list box.

Or, you might use this instead :
m_listBoxPopup2.ConnectAny(wxEVT_CONTEXT_MENU, OnContextMenu, Null, Self)

which connects listbox2 to a context menu event. Notice here though, that you require to pass the Frame as the "sink" parameter, since you want that reference back during the callback (which you access via event.sink).
In this case, you will need to change your callback function to use the sink instead :
	Function OnContextMenu(event:wxEvent)
		Local frame:MyFrame2 = MyFrame2(event.sink)

since "parent" will be the listbox.

In normal use, sink and parent are the same object.
Parent tends to be the object that the connect belongs to. However, the sink param of Connect enables you to add another object reference to the event, which can be very useful, as is the case in the above example.


Glenn Dodd(Posted 2008) [#3]
Thanks Bruce,
Got it sorted now.
So ListBox 1 responds to the Right_Click_Down event and the menu event, ListBox 2 just responds to the Right_Click_Down event, ListBox 3 doesn't respond to anything, and finally the ListCtrl responds to both events.

The menu only displays for these specific controls.

Each control has a specific menu. I have added a case statement for lb2 even though it is not called because it isn't connected. This was just to prove it to myself.

Finished Sample.

Cheers
Glenn

TestPopups.bmx


TestPopupsMain.bmx



flytom1(Posted 2008) [#4]
Hi Glenn.

Here on my WinXP SP2 only the first and the last listbox shows the menu. the 2nd and 3rd does nothing? Any idea whats wrong?

greez
tom


Glenn Dodd(Posted 2008) [#5]
run in debug mode.
First and Last show a debuglog statement for the right_mouse_down event and then the menu for each control pops up.
Second only shows a debuglog statement for the right_mouse_down event BUT doesn't show the menu (even though i added the appropriate menu creation lines) because i didn't add a ConnectAny line for it.
Type MyFrame2 Extends MyFrame2Base

	Method OnInit()
		Super.OnInit()

		m_listBoxPopup1.ConnectAny(wxEVT_CONTEXT_MENU, OnContextMenu, Null, Self)
		m_listCtrlMainTask.ConnectAny(wxEVT_CONTEXT_MENU, OnContextMenu, Null, Self)
		' intercept all menu events And Log them in this custom event handler
		PushEventHandler(New MyEvtHandler.Create(Self))


If you want it to respond then add
m_listBoxPopup2.ConnectAny(wxEVT_CONTEXT_MENU, OnContextMenu, Null, Self)

to the OnInit method above.

I left it out just to prove to myself that i was understanding the process properly.

Cheers
Glenn


flytom1(Posted 2008) [#6]
Hi Glenn,

now it works with the second one also...

the thing is, i can't compile my programm with debug mode on. i've no idea where the error message comes from. maybe it seems like a graphic thing or so...

Linking:TestPopupsMain.debug.exe
C:/Programme/BlitzMax/mod/brl.mod/dxgraphics.mod/dxgraphics.debug.win32.x86.a(d3d7graphics.bmx.debug.win32.x86.o): undefined reference to `pub_win32_WNDCLASS'
Build Error: Failed to link D:/TestPopupsMain.debug.exe
Process complete

help requested

greez
tom


Brucey(Posted 2008) [#7]
That's strange eh? What happens if you also Import Pub.Win32 ?


flytom1(Posted 2008) [#8]
HEy Brucey,

still the same error, with Import Pub.Win32:

Linking:TestPopupsMain.debug.exe
C:/Programme/BlitzMax/mod/brl.mod/dxgraphics.mod/dxgraphics.debug.win32.x86.a(d3d7graphics.bmx.debug.win32.x86.o): undefined reference to `pub_win32_WNDCLASS'


..- strange -.......*lol*


greez
tom