customdrawn: Implements the close tab buttons

git-svn-id: trunk@33540 -
This commit is contained in:
sekelsenmat 2011-11-15 12:57:24 +00:00
parent 640c95cdcc
commit ef82f9075b
4 changed files with 81 additions and 6 deletions

View File

@ -41,6 +41,8 @@ type
procedure DrawTickmark(ADest: TCanvas; ADestPos: TPoint); override;
procedure DrawSlider(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AState: TCDControlState); override;
procedure DrawCompactArrow(ADest: TCanvas; ADestPos: TPoint; ADirection: TCDControlState); override;
// Extra buttons drawing routines
procedure DrawSmallCloseButton(ADest: TCanvas; ADestPos: TPoint); override;
// TCDControl
procedure DrawControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDControlStateEx); override;
@ -161,6 +163,9 @@ begin
TCDLISTVIEW_COLUMN_TEXT_LEFT_SPACING: Result := 5;
TCDLISTVIEW_LINE_TOP_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
Result := 0;
end;
@ -173,6 +178,8 @@ const
var
ATabsStateEx: TCDCTabControlStateEx absolute AStateEx;
lCaption: String;
lTabWidth, i: Integer;
IsPainting: Boolean = False;
begin
ADest.Font.Assign(AStateEx.Font);
@ -186,11 +193,34 @@ begin
begin
lCaption := ATabsStateEx.Tabs.Strings[ATabsStateEx.CurTabIndex];
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
// in any other case we are referring to the aditional + button for adding a new tab
else
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
Result := 0;
end;
@ -452,6 +482,16 @@ begin
ADest.Polygon(lPoints);
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;
ASize: TSize; AState: TCDControlState; AStateEx: TCDControlStateEx);
var
@ -1310,6 +1350,7 @@ var
lCaption: String;
lTabHeightCorrection: Integer = 0;
lTabRightBorderExtraHeight: Integer = 0;
lCloseButtonPos: TPoint;
begin
IsSelected := AStateEx.TabIndex = AStateEx.CurTabIndex;
IsAddButton := AStateEx.CurTabIndex = AStateEx.Tabs.Count;
@ -1374,6 +1415,14 @@ begin
if IsAddButton then lCaption := '+'
else lCaption := AStateEx.Tabs.Strings[AStateEx.CurTabIndex];
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;
{ TCDListViewDrawerCommon }

View File

@ -231,13 +231,14 @@ end;
procedure TCDDrawerWinCE.DrawTab(ADest: TCanvas; ADestPos: TPoint;
ASize: TSize; AState: TCDControlState; AStateEx: TCDCTabControlStateEx);
var
IsSelected: Boolean;
IsSelected, IsAddButton: Boolean;
lTabWidth, lTabHeight, lTabTopPos: Integer;
Points: array of TPoint;
lCaption: String;
lTabHeightCorrection: Integer = 0;
begin
IsSelected := AStateEx.TabIndex = AStateEx.CurTabIndex;
IsAddButton := AStateEx.CurTabIndex = AStateEx.Tabs.Count;
if not IsSelected then lTabHeightCorrection := 3;
@ -280,7 +281,8 @@ begin
end;
// 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);
end;

View File

@ -2055,13 +2055,15 @@ end;
procedure TCDCustomTabControl.MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: integer);
var
lTabIndex: Integer;
lTabIndex, lCloseButtonSize: Integer;
lNewPage: TCDTabSheet;
lCloseButtonPos: TPoint;
begin
inherited MouseUp(Button, Shift, X, Y);
lTabIndex := MousePosToTabIndex(X, Y);
// Check if the add button was clicked
if (nboShowAddTabButton in Options) and (lTabIndex = Tabs.Count) then
begin
if Self is TCDPageControl then
@ -2074,6 +2076,20 @@ begin
Tabs.Add('New Tab');
if Assigned(OnUserAddedPage) then OnUserAddedPage(Self, nil);
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;

View File

@ -42,12 +42,18 @@ const
TCDLISTVIEW_LINE_TOP_SPACING = $1203;
TCDLISTVIEW_LINE_BOTTOM_SPACING = $1204;
TCDCTABCONTROL_CLOSE_TAB_BUTTON_WIDTH = $2600;
TCDCTABCONTROL_CLOSE_TAB_BUTTON_EXTRA_SPACING = $2601;
// Measures Ex
TCDCONTROL_CAPTION_WIDTH = $100;
TCDCONTROL_CAPTION_HEIGHT = $101;
TCDCTABCONTROL_TAB_HEIGHT = $1100;
TCDCTABCONTROL_TAB_WIDTH = $1101;
TCDCTABCONTROL_TAB_HEIGHT = $2600;
TCDCTABCONTROL_TAB_WIDTH = $2601;
TCDCTABCONTROL_TAB_LEFT_POS = $2602;
TCDCTABCONTROL_CLOSE_BUTTON_POS_X = $2603;
TCDCTABCONTROL_CLOSE_BUTTON_POS_Y = $2604;
// Colors
TCDEDIT_BACKGROUND_COLOR = $400;
@ -266,6 +272,8 @@ type
procedure DrawTickmark(ADest: TCanvas; ADestPos: TPoint); virtual; abstract;
procedure DrawSlider(ADest: TCanvas; ADestPos: TPoint; ASize: TSize; AState: 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
procedure DrawControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDControlStateEx); virtual; abstract;