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 » Proposal: add IsReadOnly() handling inside ButtonOption
Proposal: add IsReadOnly() handling inside ButtonOption [message #26434] Sat, 01 May 2010 16:07 Go to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Imagine a common situation: you have a number of choices and you want to make exactly one of them chosen/selected. One way to do this is to make a number of ButtonOption controls and handle switching between them. Generally it is easily done in U++.

index.php?t=getfile&id=2510&private=0

The problem is when user clicks already "selected" ButtonOption. This way it becomes unselected, which is commonly not the best idea. The better idea is to make "chosen" button irresponsible to user clicks, while other buttons are, contrary, ready to be clicked and become "chosen".

I've made a number of attempts to make "chosen" button option irresponsible to user clicks and failed. Digging into code revealed that there is no way to make it. So I propose handling Editable/ReadOnly flag for ButtonOption. This requires a little patch which IMO won't break any compatibility yet making ButtonOption more flexible:

(Button.cpp)
void  ButtonOption::LeftDown(Point, dword) {
	if (IsReadOnly())
		return;
	push = true;
	Refresh();
}

void  ButtonOption::LeftUp(Point, dword) {
	if (IsReadOnly())
		return;
	option = !option;
	push = false;
	UpdateActionRefresh();
}

void  ButtonOption::MouseMove(Point, dword flags) {
	if (IsReadOnly())
		return;
	bool p = !!(flags & K_MOUSELEFT);
	if(push != p) {
		push = p;
		Refresh();
	}
}


Re: Proposal: add IsReadOnly() handling inside ButtonOption [message #26435 is a reply to message #26434] Sat, 01 May 2010 18:01 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Mindtraveller wrote on Sat, 01 May 2010 16:07

I've made a number of attempts to make "chosen" button option irresponsible to user clicks and failed. Digging into code revealed that there is no way to make it.

Hi Pavel!

There is a way Wink Maybe not as straightforward as your patch, but it works fine too. The trick is to check the value of ButtonOption in WhenAction callback and revert the action whenever user tries to "unclick" the button:
#include "CtrlLib/CtrlLib.h"
using namespace Upp;

struct App : TopWindow {
	typedef App CLASSNAME;
	Array<ButtonOption> btns;
	void Check(int n){
		if (~btns[n]==0) btns[n].Set(true);
		else for(int i = 0; i < btns.GetCount(); i++)
			if(i!=n) btns[i].Set(false);
	}
	App(){
		btns.Add().SetLabel("Click me! :-)").SetRect(10,10,200,50);
		btns.Add().SetLabel("No, click me! (-:").SetRect(10,70,200,50);
		for(int i = 0; i < btns.GetCount(); i++){
			btns[i]<<=THISBACK1(Check,i);
			Add(btns[i]);
		}
	}
};

GUI_APP_MAIN{
	App().Run();
}
Re: Proposal: add IsReadOnly() handling inside ButtonOption [message #26437 is a reply to message #26435] Sat, 01 May 2010 22:57 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

Thanks, that does the trick. Cool
But IMO adding read-only state for ButtonOption makes it more functional after all, which could be useful and save us from additional tricks.
Re: Proposal: add IsReadOnly() handling inside ButtonOption [message #26475 is a reply to message #26437] Wed, 05 May 2010 22:35 Go to previous messageGo to next message
Mindtraveller is currently offline  Mindtraveller
Messages: 917
Registered: August 2007
Location: Russia, Moscow rgn.
Experienced Contributor

::up::

Question to U++ authors: are you agree with proposal/patch?
Re: Proposal: add IsReadOnly() handling inside ButtonOption [message #26502 is a reply to message #26475] Thu, 06 May 2010 20:31 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Yes, patch applied, thank you.

Mirek
Previous Topic: QTF with QtfRichObject as Button label causes crash
Next Topic: Moving child ctrl, runtime, by mouse and keyboard
Goto Forum:
  


Current Time: Thu Mar 28 14:40:47 CET 2024

Total time taken to generate the page: 0.01569 seconds