Context menu does not appear at exact mouse position Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Nelson Joseph
Experienced Solver
Experienced Solver
Posts: 65
Joined: Sun Oct 26, 2008 5:15 am
Location: Chennai, India
Contact:

Context menu does not appear at exact mouse position

Post by Nelson Joseph »

Hi All,

I am using the following code to create context menu. It works fine but the issue is, it does not appear at the mouse position. Instead, it appears 30 pixel ablove from the mouse's Y value.

Code: Select all

void MyFrame::OnContextMenu( wxContextMenuEvent& event )
{
	 wxPoint point = event.GetPosition();
	 // If from keyboard
	 if( point.x == -1 && point.y == -1 )
	 {
		 wxSize size = GetSize();
		 point.x = size.x / 2;
		 point.y = size.y / 2;
	 }
	 else
	 {
		 point = ScreenToClient( point );
	 }

	 wxMenu menu;
	 menu.Append( wxID_ANY, _T( "Item-1" ) );
	 menu.Append( wxID_ANY, _T( "Item-2" ) );
	 menu.Append( wxID_ANY, _T( "Item-3" ) );

	 PopupMenu( &menu, point.x, point.y );
}
If I use the same code in separate small application, it works fine.

I am having wxFrame within that wxSashWindow. The right side sash window contains openGL like window. The context menu does not appear while we right click at opnGL window.

I have attached sample image.
Any suggestions, welcome.
Attachments
context menu does not appear at mouse position
context menu does not appear at mouse position
screen shot.jpg (19.66 KiB) Viewed 2869 times
Regards,
Nelson Joseph
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Context menu does not appear at exact mouse position

Post by catalin »

I'd suggest not to try to calculate and manually set the menu position when the position is known. Just calling PopupMenu with the default coordinates always worked correctly for me.
Nelson Joseph
Experienced Solver
Experienced Solver
Posts: 65
Joined: Sun Oct 26, 2008 5:15 am
Location: Chennai, India
Contact:

Re: Context menu does not appear at exact mouse position

Post by Nelson Joseph »

Catalin:

Thanks for your quick reply.
I changed the code as you said, but I cant see any changes in output. Same thing is happening.
Regards,
Nelson Joseph
Nelson Joseph
Experienced Solver
Experienced Solver
Posts: 65
Joined: Sun Oct 26, 2008 5:15 am
Location: Chennai, India
Contact:

Re: Context menu does not appear at exact mouse position

Post by Nelson Joseph »

catalin wrote:I'd suggest not to try to calculate and manually set the menu position when the position is known. Just calling PopupMenu with the default coordinates always worked correctly for me.
If I remove my toolbar, then it works perfectly. What is the relation between toolbar and context menu? Any suggestion helpful. Thanks in advance.
Regards,
Nelson Joseph
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Context menu does not appear at exact mouse position

Post by catalin »

Nelson Joseph wrote:If I remove my toolbar, then it works perfectly.
Aha! Then see ticket #13223
Nelson Joseph
Experienced Solver
Experienced Solver
Posts: 65
Joined: Sun Oct 26, 2008 5:15 am
Location: Chennai, India
Contact:

Re: Context menu does not appear at exact mouse position

Post by Nelson Joseph »

Thanks Catalin. It works fine.
Regards,
Nelson Joseph
Nelson Joseph
Experienced Solver
Experienced Solver
Posts: 65
Joined: Sun Oct 26, 2008 5:15 am
Location: Chennai, India
Contact:

Re: Context menu does not appear at exact mouse position

Post by Nelson Joseph »

catalin wrote:
Nelson Joseph wrote:If I remove my toolbar, then it works perfectly.
Aha! Then see ticket #13223
Catalin:

One more problem arise. I have made change according to your suggestion. But the context menu goes out of frame if the frame is in restore down.
I have attached the screen shot for your perusal.

Any suggestion...
Attachments
context-menu.jpg
Regards,
Nelson Joseph
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: Context menu does not appear at exact mouse position

Post by catalin »

What is "restore down" ?
I don't see it going out of the screen, so what is the problem with the menu going out of the frame? I don't think it is supposed to be contained in the frame's rectangle on any OS.
Nelson Joseph
Experienced Solver
Experienced Solver
Posts: 65
Joined: Sun Oct 26, 2008 5:15 am
Location: Chennai, India
Contact:

Re: Context menu does not appear at exact mouse position

Post by Nelson Joseph »

I have modified the code of DoPopupMenu() on window.cpp as in wxWidgets 2.9

Code: Select all

menu->UpdateUI();
wxPoint point;
if ( x == wxDefaultCoord && y == wxDefaultCoord )
	{
		point = wxGetMousePosition();
	}
	else
	{
		point = ClientToScreen( wxPoint( x, y ) );
	}
Thanks.
Regards,
Nelson Joseph
Post Reply