mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-23 00:29:25 +01:00
customdrawn: Implements the close tab buttons
git-svn-id: trunk@33540 -
This commit is contained in:
parent
640c95cdcc
commit
ef82f9075b
@ -41,6 +41,8 @@ type
|
|||||||
procedure DrawTickmark(ADest: TCanvas; ADestPos: TPoint); override;
|
procedure DrawTickmark(ADest: TCanvas; ADestPos: TPoint); override;
|
||||||
procedure DrawSlider(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState); override;
|
procedure DrawSlider(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState); override;
|
||||||
procedure DrawCompactArrow(ADest: TCanvas; ADestPos: TPoint; ADirection: TCDControlState); override;
|
procedure DrawCompactArrow(ADest: TCanvas; ADestPos: TPoint; ADirection: TCDControlState); override;
|
||||||
|
// Extra buttons drawing routines
|
||||||
|
procedure DrawSmallCloseButton(ADest: TCanvas; ADestPos: TPoint); override;
|
||||||
// TCDControl
|
// TCDControl
|
||||||
procedure DrawControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
|
procedure DrawControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
|
||||||
AState: TCDControlState; AStateEx: TCDControlStateEx); override;
|
AState: TCDControlState; AStateEx: TCDControlStateEx); override;
|
||||||
@ -161,6 +163,9 @@ begin
|
|||||||
TCDLISTVIEW_COLUMN_TEXT_LEFT_SPACING: Result := 5;
|
TCDLISTVIEW_COLUMN_TEXT_LEFT_SPACING: Result := 5;
|
||||||
TCDLISTVIEW_LINE_TOP_SPACING: Result := 3;
|
TCDLISTVIEW_LINE_TOP_SPACING: Result := 3;
|
||||||
TCDLISTVIEW_LINE_BOTTOM_SPACING: Result := 3;
|
TCDLISTVIEW_LINE_BOTTOM_SPACING: Result := 3;
|
||||||
|
//
|
||||||
|
TCDCTABCONTROL_CLOSE_TAB_BUTTON_WIDTH: Result := 10;
|
||||||
|
TCDCTABCONTROL_CLOSE_TAB_BUTTON_EXTRA_SPACING: Result := 10;
|
||||||
else
|
else
|
||||||
Result := 0;
|
Result := 0;
|
||||||
end;
|
end;
|
||||||
@ -173,6 +178,8 @@ const
|
|||||||
var
|
var
|
||||||
ATabsStateEx: TCDCTabControlStateEx absolute AStateEx;
|
ATabsStateEx: TCDCTabControlStateEx absolute AStateEx;
|
||||||
lCaption: String;
|
lCaption: String;
|
||||||
|
lTabWidth, i: Integer;
|
||||||
|
IsPainting: Boolean = False;
|
||||||
begin
|
begin
|
||||||
ADest.Font.Assign(AStateEx.Font);
|
ADest.Font.Assign(AStateEx.Font);
|
||||||
|
|
||||||
@ -186,11 +193,34 @@ begin
|
|||||||
begin
|
begin
|
||||||
lCaption := ATabsStateEx.Tabs.Strings[ATabsStateEx.CurTabIndex];
|
lCaption := ATabsStateEx.Tabs.Strings[ATabsStateEx.CurTabIndex];
|
||||||
Result := ADest.TextWidth(lCaption) + TCDTabControl_Common_TabCaptionExtraWidth;
|
Result := ADest.TextWidth(lCaption) + TCDTabControl_Common_TabCaptionExtraWidth;
|
||||||
|
if (nboShowCloseButtons in ATabsStateEx.Options) then
|
||||||
|
Result := Result + GetMeasures(TCDCTABCONTROL_CLOSE_TAB_BUTTON_WIDTH)
|
||||||
|
+ GetMeasures(TCDCTABCONTROL_CLOSE_TAB_BUTTON_EXTRA_SPACING);
|
||||||
end
|
end
|
||||||
// in any other case we are referring to the aditional + button for adding a new tab
|
// in any other case we are referring to the aditional + button for adding a new tab
|
||||||
else
|
else
|
||||||
Result := ADest.TextWidth('+') + TCDTabControl_Common_TabCaptionExtraWidth;
|
Result := ADest.TextWidth('+') + TCDTabControl_Common_TabCaptionExtraWidth;
|
||||||
end
|
end;
|
||||||
|
TCDCTABCONTROL_TAB_LEFT_POS:
|
||||||
|
begin
|
||||||
|
Result := 0;
|
||||||
|
for i := 0 to ATabsStateEx.CurTabIndex-1 do
|
||||||
|
begin
|
||||||
|
if i = ATabsStateEx.LeftmostTabVisibleIndex then IsPainting := True;
|
||||||
|
|
||||||
|
if IsPainting then
|
||||||
|
Result := Result + GetMeasuresEx(ADest, TCDCTABCONTROL_TAB_WIDTH, AState, AStateEx);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
TCDCTABCONTROL_CLOSE_BUTTON_POS_X:
|
||||||
|
begin
|
||||||
|
lTabWidth := GetMeasuresEx(ADest, TCDCTABCONTROL_TAB_WIDTH, AState, AStateEx);
|
||||||
|
Result := GetMeasuresEx(ADest, TCDCTABCONTROL_TAB_LEFT_POS, AState, AStateEx)
|
||||||
|
+lTabWidth
|
||||||
|
-GetMeasures(TCDCTABCONTROL_CLOSE_TAB_BUTTON_WIDTH)
|
||||||
|
-GetMeasures(TCDCTABCONTROL_CLOSE_TAB_BUTTON_EXTRA_SPACING);
|
||||||
|
end;
|
||||||
|
TCDCTABCONTROL_CLOSE_BUTTON_POS_Y: Result := 10;
|
||||||
else
|
else
|
||||||
Result := 0;
|
Result := 0;
|
||||||
end;
|
end;
|
||||||
@ -452,6 +482,16 @@ begin
|
|||||||
ADest.Polygon(lPoints);
|
ADest.Polygon(lPoints);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCDDrawerCommon.DrawSmallCloseButton(ADest: TCanvas; ADestPos: TPoint);
|
||||||
|
begin
|
||||||
|
ADest.Pen.Style := psSolid;
|
||||||
|
ADest.Pen.Color := clGray;
|
||||||
|
ADest.Pen.Width := 4;
|
||||||
|
ADest.Line(ADestPos.X, ADestPos.Y, ADestPos.X+10, ADestPos.Y+10);
|
||||||
|
ADest.Line(ADestPos.X+10, ADestPos.Y, ADestPos.X, ADestPos.Y+10);
|
||||||
|
ADest.Pen.Width := 1;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCDDrawerCommon.DrawControl(ADest: TCanvas; ADestPos: TPoint;
|
procedure TCDDrawerCommon.DrawControl(ADest: TCanvas; ADestPos: TPoint;
|
||||||
ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx);
|
ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx);
|
||||||
var
|
var
|
||||||
@ -1310,6 +1350,7 @@ var
|
|||||||
lCaption: String;
|
lCaption: String;
|
||||||
lTabHeightCorrection: Integer = 0;
|
lTabHeightCorrection: Integer = 0;
|
||||||
lTabRightBorderExtraHeight: Integer = 0;
|
lTabRightBorderExtraHeight: Integer = 0;
|
||||||
|
lCloseButtonPos: TPoint;
|
||||||
begin
|
begin
|
||||||
IsSelected := AStateEx.TabIndex = AStateEx.CurTabIndex;
|
IsSelected := AStateEx.TabIndex = AStateEx.CurTabIndex;
|
||||||
IsAddButton := AStateEx.CurTabIndex = AStateEx.Tabs.Count;
|
IsAddButton := AStateEx.CurTabIndex = AStateEx.Tabs.Count;
|
||||||
@ -1374,6 +1415,14 @@ begin
|
|||||||
if IsAddButton then lCaption := '+'
|
if IsAddButton then lCaption := '+'
|
||||||
else lCaption := AStateEx.Tabs.Strings[AStateEx.CurTabIndex];
|
else lCaption := AStateEx.Tabs.Strings[AStateEx.CurTabIndex];
|
||||||
ADest.TextOut(AStateEx.CurStartLeftPos+5, lTabTopPos+5, lCaption);
|
ADest.TextOut(AStateEx.CurStartLeftPos+5, lTabTopPos+5, lCaption);
|
||||||
|
|
||||||
|
// Now the close button
|
||||||
|
if (not IsAddButton) and (nboShowCloseButtons in AStateEx.Options) then
|
||||||
|
begin
|
||||||
|
lCloseButtonPos.X := GetMeasuresEx(ADest, TCDCTABCONTROL_CLOSE_BUTTON_POS_X, AState, AStateEx);
|
||||||
|
lCloseButtonPos.Y := GetMeasuresEx(ADest, TCDCTABCONTROL_CLOSE_BUTTON_POS_Y, AState, AStateEx);
|
||||||
|
DrawSmallCloseButton(ADest, lCloseButtonPos);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCDListViewDrawerCommon }
|
{ TCDListViewDrawerCommon }
|
||||||
|
|||||||
@ -231,13 +231,14 @@ end;
|
|||||||
procedure TCDDrawerWinCE.DrawTab(ADest: TCanvas; ADestPos: TPoint;
|
procedure TCDDrawerWinCE.DrawTab(ADest: TCanvas; ADestPos: TPoint;
|
||||||
ASize: TSize; AState: TCDControlState; AStateEx: TCDCTabControlStateEx);
|
ASize: TSize; AState: TCDControlState; AStateEx: TCDCTabControlStateEx);
|
||||||
var
|
var
|
||||||
IsSelected: Boolean;
|
IsSelected, IsAddButton: Boolean;
|
||||||
lTabWidth, lTabHeight, lTabTopPos: Integer;
|
lTabWidth, lTabHeight, lTabTopPos: Integer;
|
||||||
Points: array of TPoint;
|
Points: array of TPoint;
|
||||||
lCaption: String;
|
lCaption: String;
|
||||||
lTabHeightCorrection: Integer = 0;
|
lTabHeightCorrection: Integer = 0;
|
||||||
begin
|
begin
|
||||||
IsSelected := AStateEx.TabIndex = AStateEx.CurTabIndex;
|
IsSelected := AStateEx.TabIndex = AStateEx.CurTabIndex;
|
||||||
|
IsAddButton := AStateEx.CurTabIndex = AStateEx.Tabs.Count;
|
||||||
|
|
||||||
if not IsSelected then lTabHeightCorrection := 3;
|
if not IsSelected then lTabHeightCorrection := 3;
|
||||||
|
|
||||||
@ -280,7 +281,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// Now the text
|
// Now the text
|
||||||
lCaption := AStateEx.Tabs.Strings[AStateEx.CurTabIndex];
|
if IsAddButton then lCaption := '+'
|
||||||
|
else lCaption := AStateEx.Tabs.Strings[AStateEx.CurTabIndex];
|
||||||
ADest.TextOut(AStateEx.CurStartLeftPos+5, lTabTopPos+5, lCaption);
|
ADest.TextOut(AStateEx.CurStartLeftPos+5, lTabTopPos+5, lCaption);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
@ -2055,13 +2055,15 @@ end;
|
|||||||
procedure TCDCustomTabControl.MouseUp(Button: TMouseButton; Shift: TShiftState;
|
procedure TCDCustomTabControl.MouseUp(Button: TMouseButton; Shift: TShiftState;
|
||||||
X, Y: integer);
|
X, Y: integer);
|
||||||
var
|
var
|
||||||
lTabIndex: Integer;
|
lTabIndex, lCloseButtonSize: Integer;
|
||||||
lNewPage: TCDTabSheet;
|
lNewPage: TCDTabSheet;
|
||||||
|
lCloseButtonPos: TPoint;
|
||||||
begin
|
begin
|
||||||
inherited MouseUp(Button, Shift, X, Y);
|
inherited MouseUp(Button, Shift, X, Y);
|
||||||
|
|
||||||
lTabIndex := MousePosToTabIndex(X, Y);
|
lTabIndex := MousePosToTabIndex(X, Y);
|
||||||
|
|
||||||
|
// Check if the add button was clicked
|
||||||
if (nboShowAddTabButton in Options) and (lTabIndex = Tabs.Count) then
|
if (nboShowAddTabButton in Options) and (lTabIndex = Tabs.Count) then
|
||||||
begin
|
begin
|
||||||
if Self is TCDPageControl then
|
if Self is TCDPageControl then
|
||||||
@ -2074,6 +2076,20 @@ begin
|
|||||||
Tabs.Add('New Tab');
|
Tabs.Add('New Tab');
|
||||||
if Assigned(OnUserAddedPage) then OnUserAddedPage(Self, nil);
|
if Assigned(OnUserAddedPage) then OnUserAddedPage(Self, nil);
|
||||||
end;
|
end;
|
||||||
|
end
|
||||||
|
// Check if a close button was clicked
|
||||||
|
else if (nboShowCloseButtons in Options) then
|
||||||
|
begin
|
||||||
|
FTabCState.CurTabIndex := lTabIndex;
|
||||||
|
lCloseButtonPos.X := FDrawer.GetMeasuresEx(Canvas, TCDCTABCONTROL_CLOSE_BUTTON_POS_X, FState, FStateEx);
|
||||||
|
lCloseButtonPos.Y := FDrawer.GetMeasuresEx(Canvas, TCDCTABCONTROL_CLOSE_BUTTON_POS_Y, FState, FStateEx);
|
||||||
|
lCloseButtonSize := FDrawer.GetMeasures(TCDCTABCONTROL_CLOSE_TAB_BUTTON_WIDTH);
|
||||||
|
if (X >= lCloseButtonPos.X) and (X <= lCloseButtonPos.X + lCloseButtonSize) and
|
||||||
|
(Y >= lCloseButtonPos.Y) and (Y <= lCloseButtonPos.Y + lCloseButtonSize) then
|
||||||
|
begin
|
||||||
|
if Self is TCDPageControl then (Self as TCDPageControl).RemovePage(lTabIndex)
|
||||||
|
else Tabs.Delete(lTabIndex);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
@ -42,12 +42,18 @@ const
|
|||||||
TCDLISTVIEW_LINE_TOP_SPACING = $1203;
|
TCDLISTVIEW_LINE_TOP_SPACING = $1203;
|
||||||
TCDLISTVIEW_LINE_BOTTOM_SPACING = $1204;
|
TCDLISTVIEW_LINE_BOTTOM_SPACING = $1204;
|
||||||
|
|
||||||
|
TCDCTABCONTROL_CLOSE_TAB_BUTTON_WIDTH = $2600;
|
||||||
|
TCDCTABCONTROL_CLOSE_TAB_BUTTON_EXTRA_SPACING = $2601;
|
||||||
|
|
||||||
// Measures Ex
|
// Measures Ex
|
||||||
TCDCONTROL_CAPTION_WIDTH = $100;
|
TCDCONTROL_CAPTION_WIDTH = $100;
|
||||||
TCDCONTROL_CAPTION_HEIGHT = $101;
|
TCDCONTROL_CAPTION_HEIGHT = $101;
|
||||||
|
|
||||||
TCDCTABCONTROL_TAB_HEIGHT = $1100;
|
TCDCTABCONTROL_TAB_HEIGHT = $2600;
|
||||||
TCDCTABCONTROL_TAB_WIDTH = $1101;
|
TCDCTABCONTROL_TAB_WIDTH = $2601;
|
||||||
|
TCDCTABCONTROL_TAB_LEFT_POS = $2602;
|
||||||
|
TCDCTABCONTROL_CLOSE_BUTTON_POS_X = $2603;
|
||||||
|
TCDCTABCONTROL_CLOSE_BUTTON_POS_Y = $2604;
|
||||||
|
|
||||||
// Colors
|
// Colors
|
||||||
TCDEDIT_BACKGROUND_COLOR = $400;
|
TCDEDIT_BACKGROUND_COLOR = $400;
|
||||||
@ -266,6 +272,8 @@ type
|
|||||||
procedure DrawTickmark(ADest: TCanvas; ADestPos: TPoint); virtual; abstract;
|
procedure DrawTickmark(ADest: TCanvas; ADestPos: TPoint); virtual; abstract;
|
||||||
procedure DrawSlider(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState); virtual; abstract;
|
procedure DrawSlider(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState); virtual; abstract;
|
||||||
procedure DrawCompactArrow(ADest: TCanvas; ADestPos: TPoint; ADirection: TCDControlState); virtual; abstract;
|
procedure DrawCompactArrow(ADest: TCanvas; ADestPos: TPoint; ADirection: TCDControlState); virtual; abstract;
|
||||||
|
// Extra buttons drawing routines
|
||||||
|
procedure DrawSmallCloseButton(ADest: TCanvas; ADestPos: TPoint); virtual; abstract;
|
||||||
// TCDControl
|
// TCDControl
|
||||||
procedure DrawControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
|
procedure DrawControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
|
||||||
AState: TCDControlState; AStateEx: TCDControlStateEx); virtual; abstract;
|
AState: TCDControlState; AStateEx: TCDControlStateEx); virtual; abstract;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user