Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Menus&Toolbars » ToolBar's context menu
ToolBar's context menu [message #15083] Sat, 29 March 2008 09:44 Go to next message
Sc0rch is currently offline  Sc0rch
Messages: 99
Registered: February 2008
Location: Russia, Rubtsovsk
Member

How to get a context menu of toolbar by right-clicking on it? Like in OperaAC toolbars, for example.

Thank you,
Anton

[Updated on: Sat, 29 March 2008 09:45]

Report message to a moderator

Re: ToolBar's context menu [message #15084 is a reply to message #15083] Sat, 29 March 2008 11:10 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1135
Registered: August 2007
Senior Contributor
Quote:


How to get a context menu of toolbar by right-clicking on it? Like in OperaAC toolbars, for example.



Well there are at least 3 ways:
1: If you want to activate the context menu with right-button down in the empty area of the Bar, just override ChildFrameEvent() method BUT don't use "child" pointer, instead use child->GetParent();

2: Better Way: If you want to activate context menu even when the tool buttons are pressed with the rigth buttons (or if you want to assign different context menus to tool buttons, use:

void BarContext::ChildMouseEvent(Ctrl *child, int event, Point p, int zdelta, dword keyflags)
{
	if(toolbar.HasChildDeep(child)) // Effects tool buttons too... (just specify which button, then you'll get different menus for each button)
	{
		if(event == RIGHTDOWN) MenuBar::Execute(THISBACK(SetMenuBar));
	}
	TopWindow::ChildMouseEvent(child, event, p, zdelta, keyflags);
}



3: Derive your class from ToolBar, then override ChildMouseEvent (imho, unnecessary)

Here is the example.





[Updated on: Sat, 29 March 2008 11:14]

Report message to a moderator

Re: ToolBar's context menu [message #15086 is a reply to message #15083] Sat, 29 March 2008 16:37 Go to previous messageGo to next message
Sc0rch is currently offline  Sc0rch
Messages: 99
Registered: February 2008
Location: Russia, Rubtsovsk
Member

Nice! Thank you very much, all is working.

Anton.

[Updated on: Sat, 29 March 2008 16:37]

Report message to a moderator

Re: ToolBar's context menu [message #15090 is a reply to message #15083] Sun, 30 March 2008 08:13 Go to previous messageGo to next message
Sc0rch is currently offline  Sc0rch
Messages: 99
Registered: February 2008
Location: Russia, Rubtsovsk
Member

But what is the best way to determine which button was clicked? My code uses ctrl-descriptions for this purpose, but it is not the best way, I think.

Added: the variant below works too:

void BarContext::ChildMouseEvent(Ctrl *child, int event, Point p, int zdelta, dword keyflags)
{
	if(toolbar.HasChildDeep(child))
	{
		if(event == RIGHTDOWN)
		{
			Ctrl *c = child;
			int i = -1;
			
			while (c != NULL)
			{
				c = c->GetPrev();
				i++;
			}

			MenuBar::Execute(THISBACK1(SetMenuBar, i));
		}
	}
	Ctrl::ChildMouseEvent(child, event, p, zdelta, keyflags);
}


Anton

[Updated on: Sun, 30 March 2008 14:54]

Report message to a moderator

Re: ToolBar's context menu [message #26933 is a reply to message #15084] Thu, 10 June 2010 16:22 Go to previous message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Oblivion wrote on Sat, 29 March 2008 12:10

Quote:


How to get a context menu of toolbar by right-clicking on it? Like in OperaAC toolbars, for example.



Well there are at least 3 ways:
1: If you want to activate the context menu with right-button down in the empty area of the Bar, just override ChildFrameEvent() method BUT don't use "child" pointer, instead use child->GetParent();

2: Better Way: If you want to activate context menu even when the tool buttons are pressed with the rigth buttons (or if you want to assign different context menus to tool buttons, use:

void BarContext::ChildMouseEvent(Ctrl *child, int event, Point p, int zdelta, dword keyflags)
{
	if(toolbar.HasChildDeep(child)) // Effects tool buttons too... (just specify which button, then you'll get different menus for each button)
	{
		if(event == RIGHTDOWN) MenuBar::Execute(THISBACK(SetMenuBar));
	}
	TopWindow::ChildMouseEvent(child, event, p, zdelta, keyflags);
}



3: Derive your class from ToolBar, then override ChildMouseEvent (imho, unnecessary)

Here is the example.






Your method did not work for toolbutton!
Previous Topic: Popup menu on button click
Next Topic: ToolButton: Label Patch!
Goto Forum:
  


Current Time: Fri Nov 01 00:40:50 CET 2024

Total time taken to generate the page: 0.02314 seconds