Recent

Author Topic: Does RecreateWnd do anything?  (Read 8155 times)

Phil

  • Hero Member
  • *****
  • Posts: 2750
Does RecreateWnd do anything?
« on: February 23, 2006, 12:34:53 am »
I'm porting some controls that call RecreateWnd, for example when setting the border style (bsNone, bsSingle). Nothing happens when RecreateWnd is called when compiled with Laz, but it works when compiled with Delphi. The control's Style value is the same with both Laz and Delphi (set in CreateParams).

Note I changed the call to RecreateWnd(Self).

I notice that RecreateWnd isn't called in very many places in the LCL and the few places where it is called it's marked "//TODO: Remove RecreateWnd".

Is there something else to use instead of RecreateWnd when control properties change? Or is there something I don't know about how this differs from Delphi's?

Thanks.

mattias

  • Administrator
  • Full Member
  • *
  • Posts: 154
    • http://www.lazarus.freepascal.org
RE: Does RecreateWnd do anything?
« Reply #1 on: February 23, 2006, 12:58:00 am »
See the note in RecreateWnd.

In other words: RecreatWnd destroys and creates a handle, which is a quite expensive action. Most widgetssets do not need that, but can change nearly any property without recreating. That's why the LCL avoids calling RecreateWnd and instead calls the widgetset, which can do that if needed. This is hardly done.

BorderStyle is a special property. I guess, this is one of the special properties, that needs a RecreateWnd under gtk and carbon and maybe under win32 too. Keep in mind, that not all BorderStyle FormStyle combinations are available under all platforms. Please give a small example, so we know, from what combination you are switching to what.

Vincent Snijders

  • Administrator
  • Hero Member
  • *
  • Posts: 2661
    • My Lazarus wiki user page
RE: Does RecreateWnd do anything?
« Reply #2 on: February 23, 2006, 12:59:20 am »
RecreateWnd should be called from the WidgetSet interface implementors (i.e. the sources below lcl\interfaces). Recreating a windows is a costly process, and if setting a property requires recreating its handle may be different depending on the widgetset.

I don't think (but I am not sure), that anything is done with CreateParams call.

So, if you set the border style of a control, but it is not updated, then that is a bug in the interface.

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2506
RE: Does RecreateWnd do anything?
« Reply #3 on: February 23, 2006, 11:08:27 am »
A nice example of why the decision to recreate a window has to be made by the widgetset are the columns of a listview.
On win32 you have to add/remove the columns after you have created the listview widget.
On gtk you need to specify the amount of columns when creating a widget.

So in this case in one situation the widget needs to be recreated and in the other not. The LCL cannot know this, the widgetset does. That is why RecreateWnd is "removed", to trigger "bad" delphi based behaviour.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Phil

  • Hero Member
  • *****
  • Posts: 2750
Re: RE: Does RecreateWnd do anything?
« Reply #4 on: February 24, 2006, 11:19:50 pm »
Thanks for the discussion. That got me looking elsewhere for a way to draw a border.

The control I'm porting introduces a BorderStyle property and implements it by OR-ing WS_BORDER with the Style parameter in its CreateParams method. CreateParams is apparently called as a result of RecreateWnd, but if the interface code isn't doing anything with Style, then that would explain why no border.

I discovered that LCL's TWinControl includes a BorderStyle property, whereas VCL's does not. Calling inherited SetBorderStyle in the control's CreateParams method adds the border.

Here's another question: The control's Anchors settings include akRight, but resizing the form horizontally doesn't resize the control. I assume the anchoring behavior is implemented at the TControl level as in Delphi, but something isn't working here. Any ideas?

Thanks again.

mattias

  • Administrator
  • Full Member
  • *
  • Posts: 154
    • http://www.lazarus.freepascal.org
RE: Re: RE: Does RecreateWnd do anything?
« Reply #5 on: February 28, 2006, 11:53:53 am »
Anchors work. Please provide an example.