Lazarus

Programming => LCL => Topic started by: igoddard on December 11, 2019, 01:39:47 pm

Title: Sequence of tabsheets
Post by: igoddard 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.
Title: Re: Sequence of tabsheets
Post by: wp 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;
Title: Re: Sequence of tabsheets
Post by: igoddard 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;
Title: Re: Sequence of tabsheets
Post by: wp 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.  
Title: Re: Sequence of tabsheets
Post by: valdir.marcos 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)?
Title: Re: Sequence of tabsheets
Post by: lucamar 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.
Title: Re: Sequence of tabsheets
Post by: igoddard 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!
Title: Re: Sequence of tabsheets
Post by: valdir.marcos 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;
Title: Re: Sequence of tabsheets
Post by: lucamar 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.
Title: Re: Sequence of tabsheets
Post by: howardpc 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.
Title: Re: Sequence of tabsheets
Post by: valdir.marcos 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
Title: Re: Sequence of tabsheets
Post by: lucamar 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 :(
Title: Re: Sequence of tabsheets
Post by: valdir.marcos 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?
Title: Re: Sequence of tabsheets
Post by: howardpc 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.
Title: Re: Sequence of tabsheets
Post by: winni 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
Title: Re: Sequence of tabsheets
Post by: lucamar on December 13, 2019, 01:57:57 pm
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.  

[... etc ...]

Yes, its there ... but it doesn't work on Windows. Thas's the problem.
Title: Re: Sequence of tabsheets
Post by: sash on December 13, 2019, 04:02:54 pm
it doesn't work on Windows. Thas's the problem.

Yes, a couple of years ago I was unpleasantly surprised (being a linux-gtk user while most of my user audience were on windows) by this fact.
IIRC, QT doesn't support close button too.

After all I ended with my own tabbed-page-control based on EyeCandy Controls' tabs.
Title: Re: Sequence of tabsheets
Post by: zeljko on December 13, 2019, 04:48:11 pm

Yes, a couple of years ago I was unpleasantly surprised (being a linux-gtk user while most of my user audience were on windows) by this fact.
IIRC, QT doesn't support close button too.

After all I ended with my own tabbed-page-control based on EyeCandy Controls' tabs.

Actually, Qt and Qt5 supports close buttons on tabs on all supported platforms by Qt/Qt5.
Title: Re: Sequence of tabsheets
Post by: valdir.marcos on December 13, 2019, 07:18:45 pm
it doesn't work on Windows. Thas's the problem.
Yes, a couple of years ago I was unpleasantly surprised (being a linux-gtk user while most of my user audience were on windows) by this fact.
IIRC, QT doesn't support close button too.
After all I ended with my own tabbed-page-control based on EyeCandy Controls' tabs.
Is Eye Candy Controls still actively maintained?
Does Eye Candy Controls TECTabCtrl work on Microsoft Windows?
Why have you created your own tabbed-page-control instead of using standard Eye Candy Controls TECTabCtrl?

https://wiki.freepascal.org/Eye-Candy_Controls#TECTabCtrl
https://wiki.freepascal.org/TECTabCtrl
https://sourceforge.net/projects/eccontrols/
https://github.com/cutec-chris/Eye-Candy_Controls
Title: Re: Sequence of tabsheets
Post by: sash on December 13, 2019, 09:43:50 pm
Actually, Qt and Qt5 supports close buttons on tabs on all supported platforms by Qt/Qt5.

Maybe, I don't remember well. But I went by non-qt way, because it means no external (runtime) dependencies. Which was essential to my app, as being remotely developed on linux (and crossbuilt to win), it was hard for me to perform onsite maintenance.

@valdir.marcos
> Does Eye Candy Controls TECTabCtrl work on Microsoft Windows?

Yes. It should work anywhere, as it seems of owner-drawn kind.

> Why have you created your own tabbed-page-control instead of using standard Eye Candy Controls TECTabCtrl?

TECTabCtrl is a tabs-only control, without container for pages, like TTabControl, not TPageControl.
Title: Re: Sequence of tabsheets
Post by: sash on December 13, 2019, 10:04:25 pm
Is Eye Candy Controls still actively maintained?
Don't know. To me, it's relatively stable (currently I use tabs only).
Initially, there was a bug, I contacted author (Blaazen (https://forum.lazarus.freepascal.org/index.php?action=profile;u=39483)), thanks to him, he fixed it in a few days, so it works for me.
TinyPortal © 2005-2018