Recent

Author Topic: Sequence of tabsheets  (Read 1117 times)

igoddard

  • New member
  • *
  • Posts: 5
Sequence of tabsheets
« on: December 11, 2019, 01:39:47 pm »
I'm writing an application with an interface consisting of a TPageControl with a number of TTabSheets, each tab sheet having a TMemo.  The tab sheets are to be in the sequence of the sort order of the tab captions.  Then I looked at the possibility of amending a caption or of inserting a new sheet into the middle of the stack I realised that this isn't a very flexible control structure.  There's no intrinsic sort method to allow the TPageControl to look after the sequence on its own nor an insert method.  TTabSheet.TabIndex is a read-only property so the sequence can't be changed via that route.

As far as I can see the only way to handle insertion is by adding a new tab sheet at the end and then re-writing the captions and contents from the intended insertion point to the end and handle caption changes by rewriting captions and contents between the old and new positions of the caption.

Whilst it's possible to wrap all this in a couple of procedures it seems a somewhat clumsy and possibly computationally expensive way of doing it.  I wonder if anyone has come up with alternative components that maintain their tab sheets in a more flexible way.

wp

  • Hero Member
  • *****
  • Posts: 6646
Re: Sequence of tabsheets
« Reply #1 on: December 11, 2019, 02:41:19 pm »
As far as I can see the only way to handle insertion is by adding a new tab sheet at the end and then re-writing the captions and contents from the intended insertion point to the end and handle caption changes by rewriting captions and contents between the old and new positions of the caption.
No, not so complicated. Yes - you must "AddTabSheet" to add a new tab sheet to the end, but to move it to another location you simply set its PageIndex as required.

This code adds new tabs always at the begin of the tab stack:
Code: Pascal  [Select]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   tab: TTabSheet;
  4. begin
  5.   tab := PageControl1.AddTabSheet;
  6.   tab.Caption := 'Sheet ' + PageControl1.PageCount.ToString;
  7.   tab.PageIndex := 0;
  8. end;
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

igoddard

  • New member
  • *
  • Posts: 5
Re: Sequence of tabsheets
« Reply #2 on: December 11, 2019, 03:16:19 pm »
Thanks.  That works but but but ...TabIndex is defined read only!

unit ComCtrls;
....
TTabSheet = class(TCustomPage)
....
property TabIndex: Integer read GetTabIndex;

wp

  • Hero Member
  • *****
  • Posts: 6646
Re: Sequence of tabsheets
« Reply #3 on: December 11, 2019, 03:21:05 pm »
I am talking of PageIndex. And before you complain: yes, the internal structure of this group of components with tabs, pages, NBPages etc. is very complex indeed (and maybe not done in the best way...)

Code: Pascal  [Select]
  1. type
  2.   TCustomPage = class(TWinControl)  
  3.   public
  4.     property PageIndex: Integer read FPageIndex write SetPageIndex;
  5.   end;
  6.  
  7.   TTabSheet = class(TCustomPage)
  8.  
« Last Edit: December 11, 2019, 03:25:00 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

valdir.marcos

  • Hero Member
  • *****
  • Posts: 965
Re: Sequence of tabsheets
« Reply #4 on: December 11, 2019, 04:11:41 pm »
I am talking of PageIndex. And before you complain: yes, the internal structure of this group of components with tabs, pages, NBPages etc. is very complex indeed (and maybe not done in the best way...)

Code: Pascal  [Select]
  1. type
  2.   TCustomPage = class(TWinControl)  
  3.   public
  4.     property PageIndex: Integer read FPageIndex write SetPageIndex;
  5.   end;
  6.  
  7.   TTabSheet = class(TCustomPage)
Would it be too hard to insert an optional [x] like Mozilla Firefox on TTabSheet original source code to easily close that page (tabsheet)?

lucamar

  • Hero Member
  • *****
  • Posts: 2264
Re: Sequence of tabsheets
« Reply #5 on: December 11, 2019, 04:33:50 pm »
Would it be too hard to insert an optional [x] like Mozilla Firefox on TTabSheet original source code to easily close that page (tabsheet)?

Won't setting nboShowCloseButtons in the page control's Options do that?

Note that the tabs themselves and the contents of the pages (TTabSheet) are two separate things.
« Last Edit: December 11, 2019, 04:36:28 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

igoddard

  • New member
  • *
  • Posts: 5
Re: Sequence of tabsheets
« Reply #6 on: December 11, 2019, 04:50:05 pm »
I am talking of PageIndex.

Oops, sorry, so you are.  I'm getting very rusty in my old age!

valdir.marcos

  • Hero Member
  • *****
  • Posts: 965
Re: Sequence of tabsheets
« Reply #7 on: December 11, 2019, 05:00:02 pm »
Would it be too hard to insert an optional [x] like Mozilla Firefox on TTabSheet original source code to easily close that page (tabsheet)?
Won't setting nboShowCloseButtons in the page control's Options do that?
Note that the tabs themselves and the contents of the pages (TTabSheet) are two separate things.
I have tried both nboShowAddTabButton and nboShowCloseButtons, but nothing happens on Microsoft Windows 7 and 10 neither on design nor on run time.
Code: Pascal  [Select]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   PageControl1.Options := [nboShowAddTabButton, nboShowCloseButtons];
  4. end;

lucamar

  • Hero Member
  • *****
  • Posts: 2264
Re: Sequence of tabsheets
« Reply #8 on: December 11, 2019, 05:17:03 pm »
I have tried both nboShowAddTabButton and nboShowCloseButtons, but nothing happens on Microsoft Windows 7 and 10 neither on design nor on run time.

It does on Linux-GTK2 (see atached image) so it must be widgetset-dependent :(

I'll make some tests on Windows in a little while.
« Last Edit: December 11, 2019, 05:23:14 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

howardpc

  • Hero Member
  • *****
  • Posts: 3276
Re: Sequence of tabsheets
« Reply #9 on: December 11, 2019, 09:11:50 pm »
I tend to agree with wp that the Lazarus implementation of TPageControl would probably be better if it were started from scratch today. Probably it has the awkward design it has because of the very diverse widgetsets it has to accommodate while still being "based" on the Delphi VCL template with which it has to be compatible.

Attached is a simple example exercising a TPageControl descendant that provides a built-in memo per page, and tabs sorted in alphabetical order. I've provided for adding new tabs and renaming existing tabs. You could extend it for deletion of tabs without too much trouble I think.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 965
Re: Sequence of tabsheets
« Reply #10 on: December 12, 2019, 08:30:03 pm »
I have tried both nboShowAddTabButton and nboShowCloseButtons, but nothing happens on Microsoft Windows 7 and 10 neither on design nor on run time.
It does on Linux-GTK2 (see atached image) so it must be widgetset-dependent :(
I'll make some tests on Windows in a little while.
You are right, it feels like a widgetset-dependent problem.
It also seems to be an old request, maybe even before 2010:

Schließenbutton in TabSheet?
https://www.lazarusforum.de/viewtopic.php?t=3373&p=34918&mobile=off

TPageControl and nboShowCloseButtons?
https://forum.lazarus.freepascal.org/index.php/topic,13412.0.html
https://wiki.lazarus.freepascal.org/JCSV_(Jans_CSV_Components)

0036384: Add buttons in find in files results to clean tabs.
https://bugs.freepascal.org/view.php?id=36384

lucamar

  • Hero Member
  • *****
  • Posts: 2264
Re: Sequence of tabsheets
« Reply #11 on: December 12, 2019, 08:50:43 pm »
Yeah, I did test in Windows XP, 7 and 10 and it works in none of them :(
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

valdir.marcos

  • Hero Member
  • *****
  • Posts: 965
Re: Sequence of tabsheets
« Reply #12 on: December 12, 2019, 09:04:49 pm »
I am talking of PageIndex. And before you complain: yes, the internal structure of this group of components with tabs, pages, NBPages etc. is very complex indeed (and maybe not done in the best way...)
Code: Pascal  [Select]
  1. type
  2.   TCustomPage = class(TWinControl)  
  3.   public
  4.     property PageIndex: Integer read FPageIndex write SetPageIndex;
  5.   end;
  6.  
  7.   TTabSheet = class(TCustomPage)
I tend to agree with wp that the Lazarus implementation of TPageControl would probably be better if it were started from scratch today. Probably it has the awkward design it has because of the very diverse widgetsets it has to accommodate while still being "based" on the Delphi VCL template with which it has to be compatible.
I also agree with both of you, but even if TPageControl would be redone from scratch, would that be accepted by Lazarus core developers?

Quote
Attached is a simple example exercising a TPageControl descendant that provides a built-in memo per page, and tabs sorted in alphabetical order. I've provided for adding new tabs and renaming existing tabs. You could extend it for deletion of tabs without too much trouble I think.
Do you think that extending TPageControl would be the best way to implement both nboShowAddTabButton and nboShowCloseButtons behaviors on Microsoft Windows?

howardpc

  • Hero Member
  • *****
  • Posts: 3276
Re: Sequence of tabsheets
« Reply #13 on: December 12, 2019, 10:55:07 pm »
Do you think that extending TPageControl would be the best way to implement both nboShowAddTabButton and nboShowCloseButtons behaviors on Microsoft Windows?
I am not familiar with the Windows pagecontrol widget (and use Windows only when I have to, otherwise I avoid it), so I don't know if the Windows widget is capable of being "extended" to offer this functionality. If it is not so extensible, a Windows solution with closeable tabs would have to be custom-drawn, which goes against the LCL philosophy.

Usually if the underlying OS widget does not support some functionality, then a cross-platform implementation is simply unable to support that functionality on that particular platform. Hence the Restriction Browser etc.

winni

  • Hero Member
  • *****
  • Posts: 716
Re: Sequence of tabsheets
« Reply #14 on: December 13, 2019, 02:11:07 am »
Hi!

It's all there and allready done:

Code: Pascal  [Select]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.  PageControl1.Options := PageControl1.Options + [nboShowCloseButtons];
  4. end;
  5.  

and

Code: Pascal  [Select]
  1. procedure TForm1.PageControl1CloseTabClicked(Sender: TObject);
  2. begin
  3.   showMessage (TComponent(sender).name);
  4.   explode (sender); // To Do
  5. end;
  6.  

Winni
« Last Edit: December 13, 2019, 02:16:32 am by winni »