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
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 previous 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

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
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: Tue Jun 04 01:34:04 CEST 2024

Total time taken to generate the page: 0.01857 seconds