customdrawn: Expands support to dropdown button

git-svn-id: trunk@48832 -
This commit is contained in:
sekelsenmat 2015-04-24 11:44:36 +00:00
parent 4a4b47c394
commit efbf75076f
4 changed files with 50 additions and 15 deletions

View File

@ -235,7 +235,7 @@ begin
TCDTOOLBAR_ITEM_ARROW_WIDTH: Result := 10;
TCDTOOLBAR_ITEM_ARROW_HEIGHT: Result := 10;
TCDTOOLBAR_ITEM_BUTTON_DEFAULT_WIDTH: Result := 23;
TCDTOOLBAR_ITEM_BUTTON_PLUS_ARROW_DEFAULT_WIDTH: Result := 35;
TCDTOOLBAR_ITEM_ARROW_RESERVED_WIDTH: Result := 35 - 23;
TCDTOOLBAR_ITEM_SEPARATOR_DEFAULT_WIDTH: Result := 8;
TCDTOOLBAR_DEFAULT_HEIGHT: Result := 26;
//
@ -1628,7 +1628,7 @@ end;
procedure TCDDrawerCommon.DrawToolBar(ADest: TCanvas; ASize: TSize;
AState: TCDControlState; AStateEx: TCDToolBarStateEx);
var
lX, lY: Integer;
lX, lY, lX2: Integer;
lItemSize: TSize;
i: Integer;
lCurItem: TCDToolBarItem;
@ -1648,8 +1648,24 @@ begin
for i := 0 to AStateEx.Items.Count-1 do
begin
lCurItem := TCDToolBarItem(AStateEx.Items[i]);
lItemSize.CX := lCurItem.Width;
// make space for the arrow if necessary
if lCurItem.Kind = tikDropDownButton then
lItemSize.CX := lCurItem.Width - GetMeasures(TCDTOOLBAR_ITEM_ARROW_RESERVED_WIDTH)
else
lItemSize.CX := lCurItem.Width;
lCurItem.SubpartKind := tiskMain;
DrawToolBarItem(ADest, lItemSize, lCurItem, lX, lY, lCurItem.State, AStateEx);
if lCurItem.Kind = tikDropDownButton then
begin
lCurItem.SubpartKind := tiskArrow;
lX2 := lX + lCurItem.Width - GetMeasures(TCDTOOLBAR_ITEM_ARROW_RESERVED_WIDTH);
lItemSize.CX := GetMeasures(TCDTOOLBAR_ITEM_ARROW_RESERVED_WIDTH);
DrawToolBarItem(ADest, lItemSize, lCurItem, lX2, lY, lCurItem.State, AStateEx);
end;
lX := lX + lCurItem.Width;
end;
end;
@ -1669,7 +1685,8 @@ var
begin
// tikDivider is centralized, tikSeparator is left-aligned
if ACurItem.Kind in [tikSeparator, tikDivider] then
case ACurItem.Kind of
tikSeparator, tikDivider:
begin
lX := AX;
if ACurItem.Kind = tikDivider then
@ -1685,9 +1702,18 @@ begin
ADest.Pen.Style := psSolid;
ADest.Pen.Color := $93979E;
ADest.Line(lX+2, lY1, lX+2, lY2);
end
else
end;
tikButton, tikCheckButton, tikDropDownButton:
begin
if ACurItem.SubpartKind = tiskArrow then
begin
// Centralize the arrow in the available space
lX := AX + ASize.CX div 2 - GetMeasures(TCDTOOLBAR_ITEM_ARROW_WIDTH) div 2;
lY1 := AY + ASize.CY div 2 - GetMeasures(TCDTOOLBAR_ITEM_ARROW_WIDTH) div 2;
DrawArrow(ADest, Point(lX, lY1), [csfDownArrow], GetMeasures(TCDTOOLBAR_ITEM_ARROW_WIDTH));
Exit;
end;
if csfSunken in AState then
begin
ADest.GradientFill(Bounds(AX, AY, ASize.CX, ASize.CY),
@ -1701,6 +1727,7 @@ begin
DrawToolBarItemBorder();
end;
end;
end;
end;
procedure TCDDrawerCommon.DrawCTabControl(ADest: TCanvas;

View File

@ -20,7 +20,6 @@ type
public
procedure DrawExpandTriangle(ADest: TCanvas; ASize: TSize;
AX, AY: Integer; AFacing: TCDControlStateFlag);
public
// ===================================
// Common Controls Tab
// ===================================
@ -118,6 +117,15 @@ begin
end;
tikButton, tikCheckButton, tikDropDownButton:
begin
if ACurItem.SubpartKind = tiskArrow then
begin
// Centralize the arrow in the available space
lX := AX - ASize.CX div 2;
lY1 := AY - ASize.CY div 2;
DrawExpandTriangle(ADest, ASize, lX, lY1, csfDownArrow);
Exit;
end;
if csfSunken in AState then
begin
ADest.GradientFill(Bounds(AX, AY, ASize.CX, ASize.CY),
@ -131,11 +139,6 @@ begin
DrawToolBarItemBorder();
end;
end;
tikDropDownArrow:
begin
// Centralize the arrow in the available space
DrawExpandTriangle(ADest, ASize, AX, AY, csfDownArrow);
end;
end;
end;

View File

@ -3009,7 +3009,9 @@ begin
PrepareCurrentDrawer();
case AKind of
tikButton, tikCheckButton: Result.Width := FDrawer.GetMeasures(TCDTOOLBAR_ITEM_BUTTON_DEFAULT_WIDTH);
tikDropDownButton: Result.Width := FDrawer.GetMeasures(TCDTOOLBAR_ITEM_BUTTON_PLUS_ARROW_DEFAULT_WIDTH);
tikDropDownButton:
Result.Width := FDrawer.GetMeasures(TCDTOOLBAR_ITEM_BUTTON_DEFAULT_WIDTH)
+ FDrawer.GetMeasures(TCDTOOLBAR_ITEM_ARROW_RESERVED_WIDTH);
tikSeparator, tikDivider: Result.Width := FDrawer.GetMeasures(TCDTOOLBAR_ITEM_SEPARATOR_DEFAULT_WIDTH);
end;
end;

View File

@ -46,7 +46,7 @@ const
TCDTOOLBAR_ITEM_ARROW_WIDTH = $1301;
TCDTOOLBAR_ITEM_ARROW_HEIGHT = $1302;
TCDTOOLBAR_ITEM_BUTTON_DEFAULT_WIDTH = $1303;
TCDTOOLBAR_ITEM_BUTTON_PLUS_ARROW_DEFAULT_WIDTH = $1304;
TCDTOOLBAR_ITEM_ARROW_RESERVED_WIDTH = $1304;
TCDTOOLBAR_ITEM_SEPARATOR_DEFAULT_WIDTH = $1305;
TCDTOOLBAR_DEFAULT_HEIGHT = $1306;
@ -221,10 +221,13 @@ type
// ToolBar Start
TCDToolbarItemKind = (tikButton, tikCheckButton, tikDropDownButton,
tikDropDownArrow, tikSeparator, tikDivider);
tikSeparator, tikDivider);
TCDToolbarItemSubpartKind = (tiskMain, tiskArrow);
TCDToolBarItem = class
Kind: TCDToolbarItemKind;
SubpartKind: TCDToolbarItemSubpartKind;
Image: TBitmap;
Caption: string;
Width: Integer;