From 0e8976c7deb832b59f1d0680332483eb2c4dc679 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Tue, 11 Aug 2015 18:18:45 +0100 Subject: ActiveTabColor/ActiveTabTextColor now defaults to clDefault The problem was that if you didn't specify ActiveTab*Color values, but did specify a Tabsheet to have a different color, when that tabsheet became the active one the color changed to clWindowBackground. This looked odd. Now the ActiveTab*Color = clDefault that tabsheet will still maintain its color, even if it is a background tab or a active tab. When you assign any other color value to ActiveTab*Color (not clDefault), then they will take preference. * Also prevent an error when calling DrawTab with the ATabSheet parameter being nil * refactored some color assignment code --- src/gui/fpg_tab.pas | 57 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/src/gui/fpg_tab.pas b/src/gui/fpg_tab.pas index dfb55ad2..f15b59fa 100644 --- a/src/gui/fpg_tab.pas +++ b/src/gui/fpg_tab.pas @@ -1,7 +1,7 @@ { fpGUI - Free Pascal GUI Toolkit - Copyright (C) 2006 - 2014 See the file AUTHORS.txt, included in this + Copyright (C) 2006 - 2015 See the file AUTHORS.txt, included in this distribution, for details of the copyright. See the file COPYING.modifiedLGPL, included in this distribution, @@ -135,8 +135,7 @@ TfpgPageControl = class(TfpgWidget) procedure SetTabPosition(const AValue: TfpgTabPosition); procedure DoPageChange(ATabSheet: TfpgTabSheet); procedure DoTabSheetClosing(ATabSheet: TfpgTabSheet); - function DrawTab(const ATabSheet: TfpgTabSheet; const rect: TfpgRect; const Selected: Boolean = False; - const Mode: Integer = 1): TfpgRect; + function DrawTab(const ATabSheet: TfpgTabSheet; const rect: TfpgRect; const Selected: Boolean = False; const Mode: Integer = 1): TfpgRect; procedure pmCloseTab(Sender: TObject); function GetActiveTabColor: TfpgColor; procedure SetActiveTabColor(AValue: TfpgColor); @@ -167,8 +166,8 @@ TfpgPageControl = class(TfpgWidget) property OnClosingTabSheet: TTabSheetClosing read FOnClosingTabSheet write FOnClosingTabSheet; published property ActivePageIndex: integer read GetActivePageIndex write SetActivePageIndex default 0; - property ActiveTabColor: TfpgColor read GetActiveTabColor write SetActiveTabColor default clWindowBackground; - property ActiveTabTextColor: TfpgColor read GetActiveTabTextColor write SetActiveTabTextColor; + property ActiveTabColor: TfpgColor read GetActiveTabColor write SetActiveTabColor default clDefault; + property ActiveTabTextColor: TfpgColor read GetActiveTabTextColor write SetActiveTabTextColor default clDefault; property Align; property BackgroundColor; property Enabled; @@ -670,7 +669,18 @@ function TfpgPageControl.DrawTab(const ATabSheet: TfpgTabSheet; const rect: Tfpg const Mode: Integer = 1): TfpgRect; var r: TfpgRect; + + procedure ApplyCorrectTabColorToCanvas; + begin + if ActiveTabColor = clDefault then + Canvas.SetColor(ATabSheet.TabColor) + else + Canvas.SetColor(ActiveTabColor); + end; + begin + if not Assigned(ATabSheet) then + raise Exception.Create('DrawTab parameter error. ATabSheet may not be nil.'); r := rect; if Selected then begin @@ -684,7 +694,7 @@ function TfpgPageControl.DrawTab(const ATabSheet: TfpgTabSheet; const rect: Tfpg r.Height -= 1; if TabPosition = tpBottom then r.Top += 1; - Canvas.SetColor(ActiveTabColor); + ApplyCorrectTabColorToCanvas; end else Canvas.SetColor(ATabSheet.TabColor); @@ -719,7 +729,7 @@ function TfpgPageControl.DrawTab(const ATabSheet: TfpgTabSheet; const rect: Tfpg Canvas.DrawLine(r.Right, r.Bottom-2, r.Right, r.Top-1); // right outer edge if Mode = 2 then { selected tab } begin - Canvas.SetColor(ActiveTabColor); + ApplyCorrectTabColorToCanvas; Canvas.DrawLine(r.Left+1, r.Top-1, r.Right-1, r.Top-1); end; end; @@ -841,6 +851,15 @@ procedure TfpgPageControl.RePaintTitles; toffset: integer; lTxtFlags: TfpgTextFlags; ActivePageVisible: Boolean; + + procedure ApplyCorrectTabTextColorToCanvas(ATab: TfpgTabSheet); + begin + if ActiveTabTextColor = clDefault then + Canvas.SetTextColor(ATab.TabTextColor) + else + Canvas.SetTextColor(ActiveTabTextColor); + end; + begin if not HasHandle then Exit; //==> @@ -848,10 +867,10 @@ procedure TfpgPageControl.RePaintTitles; if PageCount = 0 then Exit; //==> - TabW:=FixedTabWidth; - TabH:=FixedTabHeight; + TabW := FixedTabWidth; + TabH := FixedTabHeight; ActivePageVisible := false; - If TabH = 0 then + if TabH <= 1 then TabH := TAB_HEIGHT; h := TfpgTabSheet(FPages.First); if h = nil then @@ -862,7 +881,6 @@ procedure TfpgPageControl.RePaintTitles; if not Enabled then Include(lTxtFlags, txtDisabled); - if TabPosition in [tpTop, tpBottom] then begin if MaxButtonWidthSum > (Width-(FMargin*2)) then @@ -982,9 +1000,11 @@ procedure TfpgPageControl.RePaintTitles; r2.Width := Width; r2.Height := Height - TabH; Canvas.DrawButtonFace(r2, []); + // Draw text of ActivePage, because we didn't before. + h := self.ActivePage; DrawTab(h, r3, false, 2); - Canvas.SetTextColor(ActiveTabTextColor); + ApplyCorrectTabTextColorToCanvas(h); Canvas.DrawText(r3.Left+4, r3.Top+5, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; @@ -1031,8 +1051,9 @@ procedure TfpgPageControl.RePaintTitles; Canvas.DrawButtonFace(r2, []); // Draw text of ActivePage, because we didn't before. + h := self.ActivePage; DrawTab(h, r3, false, 2); - Canvas.SetTextColor(ActiveTabTextColor); + ApplyCorrectTabTextColorToCanvas(h); Canvas.DrawText(r3.Left+4, r3.Top+3, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; @@ -1080,8 +1101,9 @@ procedure TfpgPageControl.RePaintTitles; Canvas.DrawButtonFace(r2, []); // Draw text of ActivePage, because we didn't before. + h := self.ActivePage; DrawTab(h, r3, false, 2); - Canvas.SetTextColor(ActiveTabTextColor); + ApplyCorrectTabTextColorToCanvas(h); Canvas.DrawText(r3.left+toffset, r3.Top, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; @@ -1129,8 +1151,9 @@ procedure TfpgPageControl.RePaintTitles; Canvas.DrawButtonFace(r2, []); // Draw text of ActivePage, because we didn't before. + h := self.ActivePage; DrawTab(h, r3, false, 2); - Canvas.SetTextColor(ActiveTabTextColor); + ApplyCorrectTabTextColorToCanvas(h); Canvas.DrawText(r3.left+toffset, r3.Top, r3.Width, r3.Height, ActivePage.Text, lTxtFlags); end; end; { case } @@ -1263,8 +1286,8 @@ constructor TfpgPageControl.Create(AOwner: TComponent); FTextColor := Parent.TextColor; FBackgroundColor := Parent.BackgroundColor; - FActiveTabColor := FBackgroundColor; - FActiveTabTextColor := FTextColor; + FActiveTabColor := clDefault; + FActiveTabTextColor := clDefault; FFocusable := True; FOnChange := nil; FFixedTabWidth := 0; -- cgit v1.2.3-54-g00ecf