Sequence of tabsheets lazarus / 31-LCL ---------------------------------------------------------------------- igoddard · 2019-12-11 12:39 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 · 2019-12-11 13:41 Quote from: igoddard on December 11, 2019, 01:39:47 pmAs 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  tab: TTabSheet;begin  tab := PageControl1.AddTabSheet;  tab.Caption := 'Sheet ' + PageControl1.PageCount.ToString;  tab.PageIndex := 0;end; ---------------------------------------------------------------------- igoddard · 2019-12-11 14:16 Thanks.  That works but but but ...TabIndex is defined read only! unit ComCtrls; .... TTabSheet = class(TCustomPage) .... property TabIndex: Integer read GetTabIndex; ---------------------------------------------------------------------- wp · 2019-12-11 14:21 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TCustomPage = class(TWinControl)     public    property PageIndex: Integer read FPageIndex write SetPageIndex;  end;   TTabSheet = class(TCustomPage) ---------------------------------------------------------------------- valdir.marcos · 2019-12-11 15:11 Quote from: wp on December 11, 2019, 03:21:05 pmI 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TCustomPage = class(TWinControl)     public    property PageIndex: Integer read FPageIndex write SetPageIndex;  end;   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 · 2019-12-11 15:33 Quote from: valdir.marcos on December 11, 2019, 04:11:41 pmWould 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. ---------------------------------------------------------------------- igoddard · 2019-12-11 15:50 Quote from: wp on December 11, 2019, 03:21:05 pmI am talking of PageIndex. Oops, sorry, so you are.  I'm getting very rusty in my old age! ---------------------------------------------------------------------- valdir.marcos · 2019-12-11 16:00 Quote from: lucamar on December 11, 2019, 04:33:50 pmQuote from: valdir.marcos on December 11, 2019, 04:11:41 pmWould 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);begin  PageControl1.Options := [nboShowAddTabButton, nboShowCloseButtons];end; ---------------------------------------------------------------------- lucamar · 2019-12-11 16:17 Quote from: valdir.marcos on December 11, 2019, 05:00:02 pmI 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. ---------------------------------------------------------------------- howardpc · 2019-12-11 20:11 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 · 2019-12-12 19:30 Quote from: lucamar on December 11, 2019, 05:17:03 pmQuote from: valdir.marcos on December 11, 2019, 05:00:02 pmI 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 · 2019-12-12 19:50 Yeah, I did test in Windows XP, 7 and 10 and it works in none of them ---------------------------------------------------------------------- valdir.marcos · 2019-12-12 20:04 Quote from: wp on December 11, 2019, 03:21:05 pmI 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TCustomPage = class(TWinControl)     public    property PageIndex: Integer read FPageIndex write SetPageIndex;  end;   TTabSheet = class(TCustomPage)Quote from: howardpc on December 11, 2019, 09:11:50 pmI 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? QuoteAttached 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 · 2019-12-12 21:55 Quote from: valdir.marcos on December 12, 2019, 09:04:49 pmDo 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 · 2019-12-13 01:11 Hi! It's all there and allready done: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject); begin PageControl1.Options := PageControl1.Options + [nboShowCloseButtons];end; and Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.PageControl1CloseTabClicked(Sender: TObject);begin  showMessage (TComponent(sender).name);  explode (sender); // To Doend;  Winni ---------------------------------------------------------------------- lucamar · 2019-12-13 12:57 Quote from: winni on December 13, 2019, 02:11:07 amIt's all there and allready done: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject); begin PageControl1.Options := PageControl1.Options + [nboShowCloseButtons];end; [... etc ...] Yes, its there ... but it doesn't work on Windows. Thas's the problem. ---------------------------------------------------------------------- sash · 2019-12-13 15:02 Quote from: lucamar on December 13, 2019, 01:57:57 pmit 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. ---------------------------------------------------------------------- zeljko · 2019-12-13 15:48 Quote from: sash on December 13, 2019, 04:02:54 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. ---------------------------------------------------------------------- valdir.marcos · 2019-12-13 18:18 Quote from: sash on December 13, 2019, 04:02:54 pmQuote from: lucamar on December 13, 2019, 01:57:57 pmit 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 ---------------------------------------------------------------------- sash · 2019-12-13 20:43 Quote from: zeljko on December 13, 2019, 04:48:11 pmActually, 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. ---------------------------------------------------------------------- sash · 2019-12-13 21:04 Quote from: valdir.marcos on December 13, 2019, 07:18:45 pmIs 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), thanks to him, he fixed it in a few days, so it works for me.