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 Callback weirdness
ToolBar Callback weirdness [message #35273] Sat, 28 January 2012 00:48 Go to next message
Alboni is currently offline  Alboni
Messages: 214
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
I created the next example to show off a problem I'm having with my app: (project added in zipfile)

For some reason the variable 'tool' is always 1 in the function ToolBarContent (callback for filling the toolbar) while it has the correct values everywhere else.
Is there some multithreading issue going on? I tried making 'tool' volatile but that didn't help. Changing to multithreading library didn't change it either.

(I use Visual C++ 2010 Express)

------------example--------------
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

#define IMAGEFILE <bartest/bartest.iml>
#define IMAGECLASS bartest
#include <Draw/iml.h>

struct BarTest: TopWindow {
ToolBar toolbar;
int tool;

typedef BarTest CLASSNAME;

BarTest()
{
tool=1;
AddFrame(toolbar.Left());
toolbar.Set(THISBACK(ToolBarContent));
}

virtual void Paint(Draw& w)
{
char s[80];
w.DrawRect(GetSize(), Gray());
sprintf(s,"tool=%d",tool); // yeah I know
w.DrawText(200,220,s);
}

void MoveClicked()
{
tool=1;
Refresh();
}

void RotateClicked()
{
tool=2;
Refresh();
}

void ToolBarContent(Bar& bar)
{
bar.Add("Move", bartest::move(), THISBACK(MoveClicked)).Check(tool==1);
bar.Add("Rotate", bartest::rotate(), THISBACK(RotateClicked)).Check(tool==2);
}
};


GUI_APP_MAIN
{
BarTest().Run();
}

  • Attachment: bartest.zip
    (Size: 2.91KB, Downloaded 316 times)

[Updated on: Sat, 28 January 2012 00:53]

Report message to a moderator

Re: ToolBar Callback weirdness [message #35278 is a reply to message #35273] Sat, 28 January 2012 14:19 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
You have to 'refresh' toolbar explicitly by setting it again after making any changes to it:

struct BarTest: TopWindow {
	ToolBar toolbar;
	int tool;
	
	typedef BarTest CLASSNAME;
	
	void SetBar()
	{
		toolbar.Set(THISBACK(ToolBarContent));
	}
	
	BarTest()
	{
		tool = 1;
		AddFrame(toolbar.Left());
		SetBar();
	}
	
	virtual void Paint(Draw& w)
	{
		w.DrawRect(GetSize(), Gray());
		w.DrawText(200, 220, AsString(tool));
	}
	
	void SetTool(int t)
	{
		tool = t;
		Refresh();
		SetBar();
	}
	
	void ToolBarContent(Bar& bar)
	{
		bar.Add("Move", CtrlImg::reporticon(), THISBACK1(SetToool, 1))
		   .Check(tool == 1);
		bar.Add("Rotate", CtrlImg::reporticon(), THISBACK1(SetTool, 2))
		   .Check(tool == 2);
	}
};


Re: ToolBar Callback weirdness [message #35283 is a reply to message #35273] Sat, 28 January 2012 16:56 Go to previous message
Alboni is currently offline  Alboni
Messages: 214
Registered: January 2012
Location: Deventer, Netherlands
Experienced Member
Ah, thanks! Now it works.
I thought "toolbar.Refresh();" would be enough.
Previous Topic: How do I create vertical toolbars
Next Topic: Popup menu with check items
Goto Forum:
  


Current Time: Fri Mar 29 14:47:40 CET 2024

Total time taken to generate the page: 0.01516 seconds