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 » Conceptual Query: widget functions access
Conceptual Query: widget functions access [message #27441] Sat, 17 July 2010 23:46 Go to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Hi,

I have a query regarding the access to widget’s functions, once the widget is already placed within the TopWindow of an application.

For instance, I would like to change the cursor’s image when the cursor is hovering above a toolbar or any other widget.

Yes, I can “fabricate” my version of the widget in question (as derived class) and override the virtual function MouseMove; but once this is done, how to access that widget’s function from the TopWindow?

Thanks,

Javier
Re: Conceptual Query: widget functions access [message #27447 is a reply to message #27441] Sun, 18 July 2010 09:54 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
Two methods immediately suggest themselves:
- Overload ChildMouseEvent on the TopWindow to pick up MouseEnter and MouseLeave events on it's children. You can then use OverrideCursor to set the mouse cursor.

- USe a template:
template <class T>
clss WithCursorImage : public T
{
   Image cursorimage;
public:
   WithCursor() { cursorimage = Image::Arrow(); }
   T& SetCursorImage(Image img) { cursorimage = img; return *this; }
   virtual void CursorImage(Point p) {
      Image img = T::CursorImage(p);
      if (img == Image::Arrow())
         img = cursorimage;
      return img;
   }
};

(from memory, so there may be some small errors though the logic is correct)
Re: Conceptual Query: widget functions access [message #27449 is a reply to message #27447] Sun, 18 July 2010 10:36 Go to previous messageGo to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
Thanks,

I shall test it.

Another question: How images can be used in ctrls if those controls are defined in separated .h and .cpp files (i.e. if they custom controls)? How to make .iml images available?

Best wishes,

Javier
Re: Conceptual Query: widget functions access [message #27451 is a reply to message #27449] Sun, 18 July 2010 13:03 Go to previous messageGo to next message
281264 is currently offline  281264
Messages: 270
Registered: June 2010
Location: Spain
Experienced Member
I have made a version that works. What do you think? Is it "professional"? Is it well "built"?

Please your advise.

Thanks,

Javier.
Re: Conceptual Query: widget functions access [message #27468 is a reply to message #27451] Mon, 19 July 2010 13:33 Go to previous message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
There are a few things (besides coding style):

   virtual void MouseMove (Point p, dword d){
		pos_x=p.x;
		pos_y=p.y;	
		Refresh();
	}
	
	virtual void Paint(Draw& w){
		w.DrawRect(GetSize(), White());
	        w.DrawText(10, 10, AsString(pos_x));
	        w.DrawText(10, 20, AsString(pos_y));		
	}

This can be replaced by the more concise:
	virtual void Paint(Draw& w){
		w.DrawRect(GetSize(), White());
	        w.DrawText(10, 10, AsString(GetMouseViewPos()));
	}

this code contains a bug:
	virtual Image CursorImage (Point p, dword d){
		Image img=T::CursorImage(p,d);
		if(img=Image::Arrow()) <-- Should be ==
			img=Images::linguist_prev();				
		return img;
	}

and you can remove cursorimage and SetCursorImage, since you don't use them.

To use .iml files in header and source you include iml_header.h and iml_source.h in the .cpp file with the same IMAGE* defines.
Previous Topic: ToolBar mobility.
Next Topic: OpenGL example
Goto Forum:
  


Current Time: Fri Mar 29 07:14:07 CET 2024

Total time taken to generate the page: 0.01343 seconds