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 » Community » Newbie corner » LineEdit event on click on scrollbar
LineEdit event on click on scrollbar [message #38965] Thu, 31 January 2013 01:20 Go to next message
mircerlancerous is currently offline  mircerlancerous
Messages: 4
Registered: January 2013
Junior Member
Hey I'm looking for a way to get an event to trigger on a click of the LineEdit scrollbar. The leftdown even doesn't trigger unless you're actually clicking in the main field. Maybe I'm missing something easy?

While we're at it a quick example of how to add the leftdown event to the LineEdit (through subclassing?) would help as I had to make a bit of an ugly hack to get it to go.

Thanks.
Re: LineEdit event on click on scrollbar [message #38966 is a reply to message #38965] Thu, 31 January 2013 02:04 Go to previous messageGo to next message
navi is currently offline  navi
Messages: 107
Registered: February 2012
Location: Sydney, Australia
Experienced Member
There is Virtual Method NewScrollPos() can be overloaded and which can then be used to call a callback WhenScrollChange. setting WhenScrollChange from main app can be used to trace scrollchange.

scrollclick can be implemented probably with a more elaborate derived class forwarding leftclick event of sb object member of LineEdit class.

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class LineEditExtended : public LineEdit{
	public:
		virtual void NewScrollPos(){ WhenScrollChange();}
		Callback WhenScrollChange;
		
};




regards
navi
Re: LineEdit event on click on scrollbar [message #38968 is a reply to message #38965] Fri, 01 February 2013 01:01 Go to previous messageGo to next message
mircerlancerous is currently offline  mircerlancerous
Messages: 4
Registered: January 2013
Junior Member
Thanks for the snippet Navi.

Now I'm confused. Does all that code go in the main app or in the LineEdit.cpp or TestEdit.h? I'm really unclear as to how callbacks are triggered so I might need some extra hand-holding on this one. I put the following in my public class area:

virtual void NewScrollPos(){ WhenScrollChange();}
Callback WhenScrollChange;


And then the following in my class constructor where 'output' is the name of the LineEdit widget.

output.WhenScrollChange << THISBACK(ScrollLeftDown);

I just get the compiler error that 'WhenScrollChange' is not a member of LineEdit.

Thanks for your help and patience.
Re: LineEdit event on click on scrollbar [message #38969 is a reply to message #38968] Fri, 01 February 2013 02:01 Go to previous messageGo to next message
navi is currently offline  navi
Messages: 107
Registered: February 2012
Location: Sydney, Australia
Experienced Member
mircerlancerous wrote on Fri, 01 February 2013 01:01

Now I'm confused. Does all that code go in the main app or in the LineEdit.cpp or TestEdit.h?


nothing ever goes into LineEdit.cpp or any other u++ source files in that matter. Never change U++ source files. bad idea.

What we are doing here is Extending the LineEdit Class of U++. you can either put that extended class definitional in you in a separate .h/cpp file or can even put in a separate project to use as sup-projects in multiple apps.

Quote:

output.WhenScrollChange << THISBACK(ScrollLeftDown);


you got the operator wrong. In this case "=" not "<<"
output.WhenScrollChange = THISBACK(ScrollChange);



Here is a full example. In this example we have 2 LineEditExtended ctrl. we used the 'e' ctrls callback trigger to set the scroll pos for 'f' ctrl. meaning when e scrolls, f scroll with e. but f's WhenScrollChange is not used so f can scroll independently. for 'f' we set the callback to scrollbar's left click using the function SetScrollbarLeftClickCallback() that we added in LineEditExtended. if 'f' scroll bar is clicked, it prompts a message box.

note 'e' is the one on the left and 'f' is the one on the right.

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class LineEditExtended : public LineEdit{
public:
	void SetScrollbarLeftClickCallback(Callback cb){ sb.WhenLeftClick=cb; }	
	virtual void NewScrollPos(){ WhenScrollChange();}
	Callback WhenScrollChange;		
};


class mywindow : public TopWindow{
	typedef mywindow CLASSNAME;
public:
	mywindow();
	void When_e_Scroll(){ f.SetScrollPos(e.GetScrollPos()); }
	void When_f_Scroll_click() { PromptOK("Scroll Bar click"); }	
private:
	LineEditExtended e,f;	
};

mywindow::mywindow()
{		
	String s;
	SetRect(0,0,430,200);
	e.LeftPos(10, 200).VSizePos(10,10); 
	f.RightPos(10, 200).VSizePos(10,10);
	
	for(int i=0; i<100; i++) s<<"Hello World! #"<<i<<"\n";
	
	e.Set(s);
	f.Set(s);
	
	e.WhenScrollChange=THISBACK(When_e_Scroll);
	f.SetScrollbarLeftClickCallback(THISBACK(When_f_Scroll_click));
	this<<e<<f;
}


GUI_APP_MAIN
{
	mywindow().Run();
}


see these for more example on callbacks. Basic Callbacks, callback section in overview

Attach is the same code as Upp project.

regards
navi

[Updated on: Fri, 01 February 2013 02:28]

Report message to a moderator

Re: LineEdit event on click on scrollbar [message #38971 is a reply to message #38965] Fri, 01 February 2013 17:33 Go to previous messageGo to next message
mircerlancerous is currently offline  mircerlancerous
Messages: 4
Registered: January 2013
Junior Member
Thanks for the awesome help Navi. I was able to use your example to get my event to occur. A quick note for anyone else is that I had to manually change my layout file to use LineEditExtended instead of LineEdit.

I should have been a bit more clear on my full goal as I still need a bit more help. What I've got is a LineEdit that continuously scrolls as external data is fed into it. I want to stop the field from scrolling while the user has clicked the scrollbar, and then resume scrolling once it's released. I'm thinking I need a whenleftup event but there isn't one available. There is a virtual void LeftUp but I don't know how I might make that work.

Basically I'm looking for exactly what you gave me plus an event on the leftup as well.

Thanks again.
Re: LineEdit event on click on scrollbar [message #38976 is a reply to message #38971] Sat, 02 February 2013 00:01 Go to previous messageGo to next message
navi is currently offline  navi
Messages: 107
Registered: February 2012
Location: Sydney, Australia
Experienced Member
mircerlancerous wrote on Fri, 01 February 2013 17:33

I'm thinking I need a whenleftup event but there isn't one available. There is a virtual void LeftUp but I don't know how I might make that work.


overriding virtual void leftUp of LineEditExtended will only override the virtual void leftUp of LineEdit but not of scroll bar i.e the sb object member. beside even if you do override leftUp for other reasons, you have to remember to return the even to LineEdit via calling the LineEdit::LeftUp(p, keyflags); or else your LineEditExtended will not function properly.

Quote:


Basically I'm looking for exactly what you gave me plus an event on the leftup as well.

Thanks again.


I dont think you can achieve what you trying to get just by extending LineEdit ctrl alone. as the event that you are after belongs to sb member of LineEdit. I personally will try to find a solution in other way. for example, hiding the LineEdit Scrollbars and Implementing my own.

regards
navi

Re: LineEdit event on click on scrollbar [message #38980 is a reply to message #38965] Sun, 03 February 2013 08:41 Go to previous messageGo to next message
mircerlancerous is currently offline  mircerlancerous
Messages: 4
Registered: January 2013
Junior Member
Thanks for all the help Navi. Note that the virtual void leftup I was referring to was in the scrollbar file. Perhaps an addition to the core would help afterall? Either way thanks for your effort and I look forward to any help you're willing to offer on this.
Re: LineEdit event on click on scrollbar [message #38986 is a reply to message #38965] Mon, 04 February 2013 01:02 Go to previous message
nlneilson is currently offline  nlneilson
Messages: 644
Registered: January 2010
Location: U.S. California. Mojave &...
Contributor
I am not sure what is trying to be accomplished.
I made two small boxes with '<' that when clicked is the same as pushing the Enter key. On a tablet that helps instead of pulling up an on screen keyboard to click 'Enter' with the mouse.

index.php?t=getfile&id=4049&private=0
Previous Topic: How to use StringStream?
Next Topic: Do I still need the SVO_VALUE flag the use small value optimization?
Goto Forum:
  


Current Time: Thu Mar 28 19:22:13 CET 2024

Total time taken to generate the page: 0.01391 seconds