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 » How to get an "OnParentOpen" in a control
How to get an "OnParentOpen" in a control [message #24091] Sat, 26 December 2009 16:56 Go to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello all

I would like to create a control that would know when it is located into a bigger control or window to resize inside properly.

Actually I get the Paint control event and I resize it into its parent window, but it has to be done in every Paint call...

Best regards
Koldo


Best regards
Iñaki
Re: How to get an "OnParentOpen" in a control [message #24092 is a reply to message #24091] Sat, 26 December 2009 17:38 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Sat, 26 December 2009 10:56

Hello all

I would like to create a control that would know when it is located into a bigger control or window to resize inside properly.

Actually I get the Paint control event and I resize it into its parent window, but it has to be done in every Paint call...

Best regards
Koldo


Layout?

Mirek
Re: How to get an "OnParentOpen" in a control [message #24100 is a reply to message #24092] Sat, 26 December 2009 21:42 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
luzr wrote on Sat, 26 December 2009 17:38

koldo wrote on Sat, 26 December 2009 10:56

Hello all

I would like to create a control that would know when it is located into a bigger control or window to resize inside properly.

Actually I get the Paint control event and I resize it into its parent window, but it has to be done in every Paint call...

Best regards
Koldo


Layout?

Mirek


Hello Mirek

I mean, I put a control in the layout designer and I would like it to resize and relocate to fill the background. There are two solutions:

- To resize it by hand in the layout designer to fill all the background

- To put in the parent window constructor a:

control.SizePos();


However, I would like the control to itself do the SizePos, but I do not know how to do it right.
If it is used the Paint to do the SizePos(), it has to be called in every Paint call, not only in the first.

Best regards
Koldo


Best regards
Iñaki
Re: How to get an "OnParentOpen" in a control [message #24105 is a reply to message #24100] Sat, 26 December 2009 23:42 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Koldo

I believe that Mirek meant virtual function Ctrl::Layout() which is called everytime when layout is computed, i.e. when resizing or when ctrl is created. If you overwrite it and put in your code it will be called once everytime you need it Wink At least I believe that is what you need...

Best regards,
Honza
Re: How to get an "OnParentOpen" in a control [message #24120 is a reply to message #24105] Sun, 27 December 2009 16:25 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
dolik.rce wrote on Sat, 26 December 2009 23:42

Hi Koldo

I believe that Mirek meant virtual function Ctrl::Layout() which is called everytime when layout is computed, i.e. when resizing or when ctrl is created. If you overwrite it and put in your code it will be called once everytime you need it Wink At least I believe that is what you need...

Best regards,
Honza


Thank you Honza

It works, but not perfectly... see:

This is to put a control as the first child
bool SetFirstChild(Ctrl *ctrl) {
	if (Ctrl *p = ctrl->GetParent()) {
		if (p->GetFirstChild() != ctrl) {
			p->RemoveChild(ctrl);
			p->AddChildBefore(ctrl, p->GetFirstChild());
		}
		return true;
	} else
		return false;
}


The goal is to set the control as the first child (to be the window background) and to fill all the window size:

This works:
void StaticImage::Paint(Draw& w) {
...
	SetFirstChild(this);
	SizePos();


This fills the background but the control is not the first child:
void StaticImage::Layout() {
	static bool resized = false;

	if (!resized) 
		resized = SetFirstChild((Ctrl *)this);
	SizePos();
	Ctrl::Layout();
}


With this the program gets hanged:
void StaticImage::Layout() {
	SetFirstChild((Ctrl *)this);
	SizePos();
	Ctrl::Layout();
}


Best regards
Koldo


Best regards
Iñaki
Re: How to get an "OnParentOpen" in a control [message #24128 is a reply to message #24091] Sun, 27 December 2009 19:53 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Sat, 26 December 2009 10:56

Hello all

I would like to create a control that would know when it is located into a bigger control or window to resize inside properly.

Actually I get the Paint control event and I resize it into its parent window, but it has to be done in every Paint call...

Best regards
Koldo


I believe you are approaching it from the wrong side.

Maybe a little bit more actual description of the problem would allow me to provide a better advice.

Mirek
Re: How to get an "OnParentOpen" in a control [message #24133 is a reply to message #24128] Sun, 27 December 2009 22:05 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
I believe you are approaching it from the wrong side.

Maybe a little bit more actual description of the problem would allow me to provide a better advice.

Hello Mirek

In StaticImage there is an option that lets an image to be the window background.

For this it is necessary that:
- the image control has to be "SizePos-ted()", so it fills all the parent canvas
- the image control has to be the first child to avoid to cover any other control

This can be made by hand:
- doing a control.SizePos() in the parent control constructor
- putting this control as the first one in the layout designer

What I was looking for is that the same child image control does it all without the need of any code in the parent.

Thank you
Koldo


Best regards
Iñaki
Re: How to get an "OnParentOpen" in a control [message #24144 is a reply to message #24133] Mon, 28 December 2009 19:46 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Koldo,

I've tried to code what I think you are doing. Your approach seems OK to me, I'm not sure why it doesn't work. I attached diffs of files I changed in Controls4U to add StaticImage::SetAsBackground() function. Diff of Controls4U_Demo is also attached so you can test it easily. Let me know if this is what you wanted...

Best regards,
Honza
Re: How to get an "OnParentOpen" in a control [message #24146 is a reply to message #24144] Tue, 29 December 2009 08:43 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Honza

Thank you for insisting. I have had a mistake in the latter post:

Quote:

With this the program gets hanged:

void StaticImage::Layout() {
	SetFirstChild((Ctrl *)this);
	SizePos();
	Ctrl::Layout();
}



This was wrong. THIS is right:

void StaticImage::Layout() {
   	if (fit == Background) {
		SetFirstChild((Ctrl *)this);
		SizePos();
	}
	Ctrl::Layout();
} 


I have not added a SetAsBackground() function as there is already a SetFit() with Background option. This way the class public side has not changed.

Thank you Honza and Mirek.

Best regards
Koldo


Best regards
Iñaki
Re: How to get an "OnParentOpen" in a control [message #24147 is a reply to message #24146] Tue, 29 December 2009 11:31 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Koldo,

I'm still not sure where's the problem Smile The code you posted just works for me. See the attached diffs. I just added BackgroundFill and BackgroundFit options.

By the way: Why don't you use Painter for this? It would give user much more possibilities if SetFit took as an argument FILL_[H|V](PAD|REPEAT|REFLECT) and actually it would simplify the code a lot (e.g. that switch in Paint() would be unnecessary).

Best regards,
Honza
Re: How to get an "OnParentOpen" in a control [message #24150 is a reply to message #24147] Tue, 29 December 2009 12:04 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Honza

Quote:

I'm still not sure where's the problem Smile The code you posted just works for me.


Look at this:

void StaticImage::Layout() {
	SetFirstChild((Ctrl *)this);
	SizePos();
	Ctrl::Layout();
}


The code was wrong because it tried to set every child in the window as the first child... so the program hangs.

Simply doing this the program goes well:

void StaticImage::Layout() {
   	if (fit == Background) {
		SetFirstChild((Ctrl *)this);
		SizePos();
	}
	Ctrl::Layout();
} 


Perhaps I should have to add some code to avoid to have more than one Background StaticImage in a window.

Quote:

By the way: Why don't you use Painter for this? It would give user much more possibilities if SetFit took as an argument FILL_[H|V](PAD|REPEAT|REFLECT) and actually it would simplify the code a lot (e.g. that switch in Paint() would be unnecessary).


Yes, it could be. In fact Painter is used in all Controls4U classes with overrided Paint(), but StaticImage as antialiasing and other Painter technology is not necessary.

Best regards
Koldo



Best regards
Iñaki
Re: How to get an "OnParentOpen" in a control [message #24154 is a reply to message #24133] Tue, 29 December 2009 17:42 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Sun, 27 December 2009 16:05

I believe you are approaching it from the wrong side.

Maybe a little bit more actual description of the problem would allow me to provide a better advice.

Hello Mirek

In StaticImage there is an option that lets an image to be the window background.

For this it is necessary that:
- the image control has to be "SizePos-ted()", so it fills all the parent canvas
- the image control has to be the first child to avoid to cover any other control

This can be made by hand:
- doing a control.SizePos() in the parent control constructor
- putting this control as the first one in the layout designer

What I was looking for is that the same child image control does it all without the need of any code in the parent.

Thank you
Koldo


I suggest this clean solution:

TopWindow& TopWindow::Background(const PaintRect& prect);

Either you can do actually two StaticImage classes (StaticImage widget and WindowBackgroundImage as Display with PaintRect operator), perhaps with some common code or ancestor, or you can even mix both, only sometimes StaticImage will act as display (again, via operator PaintRect) and sometimes as widget.

In fact, it even could act as both Smile Not that it would have any practical use, but technically it is simple.

Is not it nice:

StaticImage myimage;
....
TopWindow win;
win.Background(myimage);


?

Mirek
Re: How to get an "OnParentOpen" in a control [message #24155 is a reply to message #24154] Tue, 29 December 2009 18:11 Go to previous message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Mirek

Thank you. Yes, perhaps the better solution is to modify the window, or the StaticRect where the child StaticImage belongs.

As I did not want to change StaticRect, I think the StaticImage::Layout option is enough clean and does not force to change CtrlLib code.

Of course no problem if StaticRect is changed to add a Background(Image) method. Please care that perhaps the background image can have different fit options (as Honza has indicated).

Best regards
Koldo


Best regards
Iñaki
Previous Topic: How to mix use widgets and win32 window in u++?
Next Topic: Additon to SliderCtrl: Jump
Goto Forum:
  


Current Time: Thu Mar 28 19:38:55 CET 2024

Total time taken to generate the page: 0.02156 seconds