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 » What is best way to obtain button info via callback?
What is best way to obtain button info via callback? [message #13586] Tue, 15 January 2008 19:51 Go to next message
jlfranks is currently offline  jlfranks
Messages: 57
Registered: May 2007
Location: Houston, TX, USA
Member
The problem that I'm trying to solve is to have one callback handler for buttons with layout like Qwerty keyboard (we only have
a touch panel and need a keyboard device).

The alphabetic buttons can be upper or lower case, depending on
the case toggle button. I would sure be nice to service over 50
buttons (keys on keyboard) with one callback routine.

The problem is that Button only takes THISBACK and not THISBACK1, so there's no way of sending an argument identifying the key that is pressed.

Also, there is a way to set the label on the button, but not a way to get the lable. Handler could have simply used this, if it knew which key to access.

Is simple way of writing this (sure don't like writing 50 callbacks that all do just about the same thing) ?

--jlf
Re: What is best way to obtain button info via callback? [message #13588 is a reply to message #13586] Tue, 15 January 2008 20:36 Go to previous messageGo to next message
jlfranks is currently offline  jlfranks
Messages: 57
Registered: May 2007
Location: Houston, TX, USA
Member
Just found this documented on the Upp Overview page and is pretty much all I need:
----------
void MyDlg::SetEditorValue(int x)
{
editor <<= x;
}

MyDlg::MyDlg()
{
button1 <<= THISBACK1(SetEditorValue, 1);
button2 <<= THISBACK1(SetEditorValue, 2);

---------
Sorry for the wasted bandwidth.

--jlf
Re: What is best way to obtain button info via callback? [message #36714 is a reply to message #13586] Thu, 28 June 2012 16:14 Go to previous message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
Thanks for opening my eyes for this!

We can use one callback to handle all buttons and this keeps the code much more organized:

enum {btn1, btn2};

void MainWin::SetEditOutput(int n)
{
	switch (n) {
		case btn1:
			output <<= "You clicked button 1";
			break;
		case btn2:
			output <<= "You clicked button 2";
			break;	
	}
}


MainWin::MainWin()
{
	
	CtrlLayout(*this, "Window title");
	button1.WhenPush = THISBACK1(SetEditOutput, btn1);
	button2.WhenPush = THISBACK1(SetEditOutput, btn2);
}
Previous Topic: Zooming layouts and different behaviour windows/linux
Next Topic: QTF tooltip on tray icon.
Goto Forum:
  


Current Time: Sun Jun 23 01:22:44 CEST 2024

Total time taken to generate the page: 0.01760 seconds