[Lazarus] TTabControl (d)evolution

Hans-Peter Diettrich DrDiettrich1 at aol.com
Tue Aug 2 23:29:39 CEST 2011


Felipe Monteiro de Carvalho schrieb:
> On Tue, Aug 2, 2011 at 7:11 PM, Hans-Peter Diettrich
> <DrDiettrich1 at aol.com> wrote:
>> Only the frame is drawn by the TTabControl, the tabs most probably still are
>> painted by the TCustomTabControl.
> 
> Indeed, you are correct:
> 
> constructor TTabControlNoteBookStrings.Create(TheTabControl: TTabControl);
> begin
>   inherited Create(TheTabControl);
>   FNoteBook := TCustomTabControl{%H-}.Create(nil);
>   FNoteBook.ControlStyle := FNoteBook.ControlStyle + [csNoDesignSelectable];
>   FNoteBook.Parent := TabControl;
> 
> What a mess ...
> 
> But I wonder how dropping client controls keeps working if it is done
> like that. I would think that the TCustomTabControl uses the client
> space, so it would not be possible to drop client controls.

I just tested a raw TCustomTabControl, and it worked immediately as a 
TTabControl with the Win32 widgetset. After moving ChildClassAllowed 
into TPageControl, it allows to add components of any type to its client 
area. If you can verify this for the other widgetsets[1], the whole 
implementation of TTabControl reduces to the handling (almost 
publishing) of the properties.

If this doesn't work, the TTabControl implementation still can be 
simplified. No properties have to be duplicated in the TTabControl, when 
above FNoteBook is moved into TTabControl, and all properties are 
delegated to that FNoteBook. I already tried to implement this in 
TNewTabControl, but I must have done something wrong, it didn't show any 
tabs :-(

Another annoying issue is the lack of tab "decoration" (images, buttons, 
menu) in the Win32 widgetset. E.g. the source editor windows have no 
page menu and Style with this widgetset - this may be the reason for the 
Paint routine, but if so, it never was finished. The menu for the tabs 
is the same as for the source code client, images and close buttons are 
not shown, despite the option in Tools > Options.


[1] Short test with an empty form:

procedure TForm1.FormCreate(Sender: TObject);
var
   btn: TButton;
begin
//declare Tabs:TCustomTabControl in the form!
   Tabs := TCustomTabControl.Create(self);
   Tabs.Height := 50; //for now
   Tabs.Parent := self;
   Tabs.Align := alTop;
//add some tabs
   Tabs.Pages.Add('tab 1');
   Tabs.Pages.Add('tab 2');
//add something to the client area
   btn := TButton.Create(self);
   btn.Caption := 'test';
   btn.Parent := Tabs; //move ChildClassAllowed into TPageControl!
   btn.Align := alRight;
end;

Depending on the outcome of your test, I can rewrite TNewTabControl with 
the simplified implementation. I also can try to fix GetHitTestInfo, so 
that the showing of the popup menu can be delegated to the proper 
control or client.

More properties are missing, at least from the Win32 widgetset. The 
problem is that in the current implementation all properties are passed 
to the widgetsets in TCustomPage parameters, so that this class must be 
extended with all currently unhandled properties, or dedicated methods 
have to be added to TWSCustomTabControl. This can be done later, once we 
know how to make TTabControl work at all, with all widgetsets.

DoDi





More information about the Lazarus mailing list