LCL Interface Redesign Idea

From Lazarus wiki
Jump to navigationJump to search

Why would we want this ?

This is current Idea for the structure of the interface and how it relates to handles

Overview:

  • Fork a branch of lazarus/
  • Replace TWinControl.Handle with TWinControl.LCLHandle (there should exist no Handle yet)
  • Try to get the LCL compiled and maybe the IDE so it doesn't use the (inefficient) .Handle anymore
  • Introduce .Handle again, now as WSclass call
  • Merge the branches

The change to .Handle will not break existing code.

TWSxxWinControl.CreateHandle Returns a TLCLHandle

TLCLHandle = IInterface; // interfaces as com objects

TxxPrivate = class(TPrivate, TLCLHandle);

TGtkPrivateButton = class(TGtkBin, TLCLHandle);

All TWSxx. methods should be moved to the private class. for instance:

 class procedure TWSGtkWinControl.SetText(const AWinControl; const AText: String);
 var
   PrivWinControl: TGtkPrivateWinControl;
 begin
   PrivWinControl := TGtkPrivateWinControl(AWinControl.LCLHandle);
   PrivWinControl.SetText(AText);
 end;

Other possibilities

For accessing widgetset native handles or IDs from the LCL, in the current situation, ppl have to cast the handle. In the case of gtk, to retrieve the XID, one needs the following cast:

 PGdkPrivateWindow(PGtkWidget(Handle)^.window)^.XID

When interfaces are used, one can imagine the following code

{$IFDEF GtkHasX}
TGtkPrivateWidget = class(TGtkPrivate, ILCLHandle, IX11Handle);
(AWinControl.LCLHandle as IX11Handle).XID

or maybe better:

if Supports(AWinControl.LCLHandle, IX11Handle, X11Handle) then
  ... DoSomething with X11Handle

Which leads to cleaner constructs, without the need of internal knowledge of the handle.

Note that for this we need COM interfaces and not CORBA, however we don't need reference counting, so AddRef and ReleseRef can be implemented by just returning -1