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 » U++ Widgets - General questions or Mixed problems » Toolbar clears after ESC key [solved, it`s the bug in user code]
Toolbar clears after ESC key [solved, it`s the bug in user code] [message #12082] Wed, 10 October 2007 18:33 Go to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

I have a toolbar on my topwindow and a simple test routine for adding icons for toolbar:
class MainWindow : public WithMainWindowLayout<TopWindow> {
public:
	typedef MainWindow CLASSNAME;
	MainWindow();
	
private:
	void SetToolBarState();
	void OnUpdateToolbar(Bar &bar);
	
	void OnLockUnlock();

	[COLOR=blue]ToolBar      toolbar;[/COLOR]
	ToolBarState toolbarState;
	bool         buttonClose;
};

MainWindow::MainWindow()
{
	::CtrlLayout(*this);
	AddFrame(toolbar);
	toolbar.AddFrame(BottomSeparatorFrame());
	Title(t_("Диспетчер готовой продукции 0.1"));
	Icon(DispRVPFImages::DISP_RVPF);
	LargeIcon(DispRVPFImages::DISP_RVPF);

	//Zoomable().Sizeable().
	MinimizeBox(false).Sizeable(false).SetRect(0,0,1024,768);

	[COLOR=blue]SetToolBarState();[/COLOR]
}


void MainWindow::SetToolBarState()
{
	//...
	toolbar.Set(THISBACK(OnUpdateToolbar));
}
void MainWindow::OnUpdateToolbar(Bar &bar)
{
	toolbar.Clear();
	toolbar.Add(t_("*********"), DispRVPFImages::dailyReport,THISBACK(OnLockUnlock));
	toolbar.GapRight();
	toolbar.Add(t_("*********"), DispRVPFImages::unlock,THISBACK(OnLockUnlock));
	toolbar.Separator();
	toolbar.Add(t_("*********"), DispRVPFImages::report,THISBACK(OnLockUnlock));
	toolbar.Add(t_("*********"), DispRVPFImages::archive,THISBACK(OnLockUnlock));
	toolbar.Add(t_("*********"), DispRVPFImages::options,THISBACK(OnLockUnlock));
}


It works fine on executing the application. But pressing ESC key clears toolbar icons. Is it a bug, or I`m doing something wrong?

I tried not to use toolbar.Clear(); in MainWindow::OnUpdateToolbar, but in some repainting cases toolbar just copies it`s icons twice or more times.

[Updated on: Wed, 10 October 2007 21:53]

Report message to a moderator

Re: Toolbar clears after ESC key [bug?] [message #12084 is a reply to message #12082] Wed, 10 October 2007 19:03 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Quote:

; in MainWindow::OnUpdateToolbar, but in some repainting cases toolbar just copies it`s icons twice or more times.


Hmm, do you use a key hook (InstallKeyHook())? I've encountered the very same problem, and it was only because of the wrong return value. If you use a global keyhook, make sure that it returns true. and before it, make sure that your callback passes the variables to the default ctrl. Eg.

static bool CtrlKeyHook(Ctrl* ctrl, dword key, int count) { /* your code goes here... */ ctrl->Key(key, count); return true; }

As in the above snippet.


[Updated on: Wed, 10 October 2007 19:06]

Report message to a moderator

Re: Toolbar clears after ESC key [bug?] [message #12085 is a reply to message #12084] Wed, 10 October 2007 19:35 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

No, I didn`t use any keyhooks. The code I enlisted above is almost all the code that application has.
Re: Toolbar clears after ESC key [bug?] [message #12089 is a reply to message #12085] Wed, 10 October 2007 20:21 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
I've compiled your code (with small modifications, and got the same result, strange...). But i didn't have to examine the actual process that caused trouble

Fortunately, if you use OnUpdateToolbar solely for adding adding the toolbar for once and refreshing it afterwards, this should work (a temporary/application specific solution):

void MainWindow::OnUpdateToolbar(Bar &bar)
{
if(toolbar.IsOpen() && toolbar.IsChild())
{
Refresh();
return;
}

toolbar.Add(t_("*********"), DispRVPFImages::dailyReport,THISBACK(OnLockUnlock));
toolbar.GapRight();
toolbar.Add(t_("*********"), DispRVPFImages::unlock,THISBACK(OnLockUnlock));
toolbar.Separator();
toolbar.Add(t_("*********"), DispRVPFImages::report,THISBACK(OnLockUnlock));
toolbar.Add(t_("*********"), DispRVPFImages::archive,THISBACK(OnLockUnlock));
toolbar.Add(t_("*********"), DispRVPFImages::options,THISBACK(OnLockUnlock));

}


[Updated on: Wed, 10 October 2007 20:31]

Report message to a moderator

Re: Toolbar clears after ESC key [bug?] [message #12091 is a reply to message #12089] Wed, 10 October 2007 20:49 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Thanks, this was just an inobvious solution. But I wonder if I can change states of toolbar, for the code after your condition is executed only once (I suppose).
Re: Toolbar clears after ESC key [bug?] [message #12094 is a reply to message #12091] Wed, 10 October 2007 21:06 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1091
Registered: August 2007
Senior Contributor
Oops sorry, it was my fault. Embarassed
It seems that you are adding the items to the wrong place.
Since you use toolbar.Set() to add your items to the toolbar, You should add the items to the "bar." Not explicitly to the toolbar.
Since OnUpdateToolbar is a callback, the argument passed as "bar" is implicitly the toolbar itself. That's why your code doubles the items whenever it refreshes.

void MainWindow::OnUpdateToolbar(Bar &bar)
{

bar.Add(t_("*********"), DispRVPFImages::dailyReport,THISBACK(OnLockUnlock));
bar.GapRight();
bar.Add(t_("*********"), DispRVPFImages::unlock,THISBACK(OnLockUnlock));
bar.Separator();
bar.Add(t_("*********"), DispRVPFImages::report,THISBACK(OnLockUnlock));
bar.Add(t_("*********"), DispRVPFImages::archive,THISBACK(OnLockUnlock));
bar.Add(t_("*********"), DispRVPFImages::options,THISBACK(OnLockUnlock));

}

Now you should be able to use it as you intended.


[Updated on: Wed, 10 October 2007 21:22]

Report message to a moderator

icon14.gif  Re: Toolbar clears after ESC key [bug?] [message #12096 is a reply to message #12094] Wed, 10 October 2007 21:51 Go to previous message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Thanks very much, Oblivion!
It surely was my fault - I`ve forgotten about bar argument. )
Previous Topic: ButtonOption has no disabled state? [solved w/ ::Disable()]
Next Topic: Having my HWND and eating it, too...
Goto Forum:
  


Current Time: Thu Mar 28 19:46:58 CET 2024

Total time taken to generate the page: 0.01391 seconds