📄 jvqxpbuttons.pas
字号:
if Value <> FWordWrap then
begin
FWordWrap := Value;
LockedInvalidate;
end;
end;
procedure TJvXPCustomButton.ImageListChange(Sender: TObject);
begin
if Assigned(Action) and (Sender is TCustomImageList) and
Assigned(TAction(Action).ActionList.Images) and
((TAction(Action).ImageIndex < (TAction(Action).ActionList.Images.Count))) then
FImageIndex := TAction(Action).ImageIndex
else
FImageIndex := -1;
LockedInvalidate;
end;
procedure TJvXPCustomButton.KeyDown(var Key: Word; Shift: TShiftState);
begin
if (Shift = []) and (Key = VK_SPACE) then
begin
DrawState := DrawState + [dsHighlight];
HookMouseDown;
end;
inherited KeyDown(Key, Shift);
end;
procedure TJvXPCustomButton.KeyUp(var Key: Word; Shift: TShiftState);
var
Pos: TPoint;
begin
//
// it's not possible to call the 'HookMouseUp' or 'HookMouseLeave' methods,
// because we don't want to call their event handlers.
//
if dsClicked in DrawState then
begin
GetCursorPos(Pos);
Pos := ScreenToClient(Pos);
if not PtInRect(Bounds(0, 0, Width, Height), Pos) then
DrawState := DrawState - [dsHighlight];
DrawState := DrawState - [dsClicked];
LockedInvalidate;
Click;
end;
inherited KeyUp(Key, Shift);
end;
function TJvXPCustomButton.IsSpecialDrawState(IgnoreDefault: Boolean = False): Boolean;
begin
if dsClicked in DrawState then
Result := not (dsHighlight in DrawState)
else
Result := (dsHighlight in DrawState) or (dsFocused in DrawState);
if not IgnoreDefault then
Result := Result or (FDefault and CanFocus) and not IsSibling;
end;
procedure TJvXPCustomButton.ActionChange(Sender: TObject; CheckDefaults: Boolean);
begin
inherited ActionChange(Sender, CheckDefaults);
if Sender is TCustomAction then
with TCustomAction(Sender) do
begin
if Assigned(TCustomAction(Sender).ActionList.Images) and
(FImageChangeLink.Sender <> TCustomAction(Sender).ActionList.Images) then
TCustomAction(Sender).ActionList.Images.RegisterChanges(FImageChangeLink);
if (ActionList <> nil) and (ActionList.Images <> nil) and
(ImageIndex >= 0) and (ImageIndex < ActionList.Images.Count) then
FImageIndex := ImageIndex;
LockedInvalidate;
end;
end;
procedure TJvXPCustomButton.HookResized;
const
ColSteps = 64;
Dithering = True;
var
Offset: Integer;
begin
inherited HookResized;
// calculate offset.
Offset := 4 * (Integer(IsSpecialDrawState(True)));
//
// create gradient rectangles for...
//
// background.
JvXPCreateGradientRect(Width - (2 + Offset), Height - (2 + Offset),
dxColor_Btn_Enb_BgFrom_WXP, dxColor_Btn_Enb_BgTo_WXP, ColSteps, gsTop, Dithering,
FBgGradient);
// clicked.
JvXPCreateGradientRect(Width - 2, Height - 2, dxColor_Btn_Enb_CkFrom_WXP,
dxColor_Btn_Enb_CkTo_WXP, ColSteps, gsTop, Dithering, FCkGradient);
// focused.
JvXPCreateGradientRect(Width - 2, Height - 2, dxColor_Btn_Enb_FcFrom_WXP,
dxColor_Btn_Enb_FcTo_WXP, ColSteps, gsTop, Dithering, FFcGradient);
// highlight.
JvXPCreateGradientRect(Width - 2, Height - 2, dxColor_Btn_Enb_HlFrom_WXP,
dxColor_Btn_Enb_HlTo_WXP, ColSteps, gsTop, Dithering, FHlGradient);
LockedInvalidate;
end;
procedure TJvXPCustomButton.Paint;
var
Rect: TRect;
Offset, Flags: Integer;
DrawPressed: Boolean;
Image: TBitmap;
Bitmap: TBitmap;
begin
with Canvas do
begin
// clear background.
Rect := GetClientRect;
Brush.Color := Self.Color;
FillRect(Rect);
// draw gradient borders.
if IsSpecialDrawState then
begin
Bitmap := TBitmap.Create;
try
if dsHighlight in DrawState then
Bitmap.Assign(FHlGradient)
else
Bitmap.Assign(FFcGradient);
BitBlt(Canvas, 1, 1, Width, Height, Bitmap.Canvas, 0, 0, SRCCOPY);
finally
Bitmap.Free;
end;
end;
// draw background gradient...
if not ((dsHighlight in DrawState) and (dsClicked in DrawState)) then
begin
Offset := 2 * Integer(IsSpecialDrawState);
BitBlt(Canvas, 1 + Offset, 1 + Offset, Width - 3 * Offset, Height - 3 * Offset,
FBgGradient.Canvas, 0, 0, SRCCOPY);
end
// ...or click gradient.
else
begin
BitBlt(Canvas, 1, 1, Width, Height, FCkGradient.Canvas, 0, 0, SRCCOPY);
end;
// draw border lines.
if Enabled then
Pen.Color := dxColor_Btn_Enb_Border_WXP
else
Pen.Color := dxColor_Btn_Dis_Border_WXP;
Brush.Style := bsClear;
RoundRect(0, 0, Width, Height, 10, 10);
// draw border edges.
if FSmoothEdges then
begin
if Enabled then
Pen.Color := dxColor_Btn_Enb_Edges_WXP
else
Pen.Color := dxColor_Btn_Dis_Edges_WXP;
JvXPDrawLine(Canvas, 0, 1, 2, 0);
JvXPDrawLine(Canvas, Width - 2, 0, Width, 2);
JvXPDrawLine(Canvas, 0, Height - 2, 2, Height);
JvXPDrawLine(Canvas, Width - 3, Height, Width, Height - 3);
end;
// set drawing flags.
Flags := {DT_VCENTER or } DT_END_ELLIPSIS;
if FWordWrap then
Flags := Flags or DT_WORDBREAK;
// draw image & caption.
Image := TBitmap.Create;
try
// get image from action or glyph property.
if Assigned(Action) and Assigned(TAction(Action).ActionList.Images) and
(FImageIndex > -1) and (FImageIndex < TAction(Action).ActionList.Images.Count) then
TAction(Action).ActionList.Images.GetBitmap(FImageIndex, Image)
else
Image.Assign(FGlyph);
// autogray image (if allowed).
if FAutoGray and not Enabled then
JvXPConvertToGray2(Image);
// assign canvas font (change HotTrack-Color, if necessary).
Font.Assign(Self.Font);
// calculate textrect.
if not Image.Empty then
case FLayout of
blGlyphLeft:
Inc(Rect.Left, Image.Width + FSpacing);
blGlyphRight:
begin
Dec(Rect.Left, Image.Width + FSpacing);
Dec(Rect.Right, (Image.Width + FSpacing) * 2);
Flags := Flags or DT_RIGHT;
end;
blGlyphTop:
Inc(Rect.Top, Image.Height + FSpacing);
blGlyphBottom:
Dec(Rect.Top, Image.Height + FSpacing);
end;
JvXPRenderText(Self, Canvas, Caption, Font, Enabled, FShowAccelChar, Rect, Flags or DT_CALCRECT);
OffsetRect(Rect, (Width - Rect.Right) div 2, (Height - Rect.Bottom) div 2);
// should we draw the pressed state?
DrawPressed := (dsHighlight in DrawState) and (dsClicked in DrawState);
if DrawPressed then
OffsetRect(Rect, 1, 1);
// draw image - if available.
if not Image.Empty then
begin
Image.Transparent := True;
case FLayout of
blGlyphLeft:
Draw(Rect.Left - (Image.Width + FSpacing), (Height - Image.Height) div 2 +
Integer(DrawPressed), Image);
blGlyphRight:
Draw(Rect.Right + FSpacing, (Height - Image.Height) div 2 +
Integer(DrawPressed), Image);
blGlyphTop:
Draw((Width - Image.Width) div 2 + Integer(DrawPressed),
Rect.Top - (Image.Height + FSpacing), Image);
blGlyphBottom:
Draw((Width - Image.Width) div 2 + Integer(DrawPressed),
Rect.Bottom + FSpacing, Image);
end;
end;
// draw focusrect (if enabled).
if (dsFocused in DrawState) and (FShowFocusRect) then
begin
Brush.Style := bsSolid;
DrawFocusRect(Bounds(3, 3, Width - 6, Height - 6));
end;
// draw caption.
SetBkMode(Handle, Transparent);
JvXPRenderText(Self, Canvas, Caption, Font, Enabled, FShowAccelChar, Rect, Flags);
finally
Image.Free;
end;
end;
end;
// TJvXPCustomToolButton =====================================================
constructor TJvXPCustomToolButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csDoubleClicks];
Color := clBlack;
FToolType := ttClose;
FChangeLink := TChangeLink.Create;
FChangeLink.OnChange := DoImagesChange;
HookResized;
end;
destructor TJvXPCustomToolButton.Destroy;
begin
FChangeLink.Free;
inherited Destroy;
end;
procedure TJvXPCustomToolButton.HookResized;
begin
if ToolType <> ttImage then
begin
Height := 15;
Width := 15;
end;
end;
procedure TJvXPCustomToolButton.SetToolType(Value: TJvXPToolType);
begin
if Value <> FToolType then
begin
FToolType := Value;
LockedInvalidate;
end;
end;
procedure TJvXPCustomToolButton.Paint;
var
Rect: TRect;
Bitmap: TBitmap;
Theme: TJvXPTheme;
Shifted: Boolean;
begin
with Canvas do
begin
Rect := GetClientRect;
Brush.Color := TJvXPWinControl(Parent).Color;
Brush.Style := bsSolid;
FillRect(Rect);
if csDesigning in ComponentState then
DrawFocusRect(Rect);
Brush.Style := bsClear;
Theme := Style.GetTheme;
if (Theme = WindowsXP) and (dsClicked in DrawState) and
not (dsHighlight in DrawState) then
JvXPFrame3d(Self.Canvas, Rect, clWhite, clBlack);
if dsHighlight in DrawState then
begin
if Theme = WindowsXP then
JvXPFrame3d(Self.Canvas, Rect, clWhite, clBlack, dsClicked in DrawState)
else
begin
Pen.Color := dxColor_BorderLineOXP;
Rectangle(Rect);
InflateRect(Rect, -1, -1);
if dsClicked in DrawState then
Brush.Color := dxColor_BgCkOXP
else
Brush.Color := dxColor_BgOXP;
FillRect(Rect);
end;
end;
Shifted := (Theme = WindowsXP) and (dsClicked in DrawState);
if ToolType = ttImage then
begin
if (Images = nil) or (ImageIndex < 0) or (ImageIndex >= Images.Count) then
Exit;
Images.Draw(Canvas,
(Width - Images.Width) div 2 + Integer(Shifted),
(Height - Images.Height) div 2 + Integer(Shifted),
ImageIndex,
itImage,
Enabled);
end
else
begin
Bitmap := TBitmap.Create;
try
Bitmap.LoadFromResourceName(HInstance, PChar('JvXPCustomToolButton' + Copy(GetEnumName(TypeInfo(TJvXPToolType),
Ord(FToolType)), 3, MaxInt)));
if (dsClicked in DrawState) and (dsHighlight in DrawState) then
JvXPColorizeBitmap(Bitmap, clWhite)
else
if not Enabled then
JvXPColorizeBitmap(Bitmap, clGray)
else
if Color <> clBlack then
JvXPColorizeBitmap(Bitmap, Color);
Bitmap.Transparent := True;
Draw((Width - Bitmap.Width) div 2 + Integer(Shifted),
(Height - Bitmap.Height) div 2 + Integer(Shifted), Bitmap);
finally
Bitmap.Free;
end;
end;
end;
end;
procedure TJvXPCustomToolButton.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if Operation = opRemove then
begin
if AComponent = DropDownMenu then
DropDownMenu := nil
else
if AComponent = Images then
Images := nil;
end;
end;
procedure TJvXPCustomToolButton.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
P: TPoint;
begin
inherited MouseDown(Button, Shift, X, Y);
if Assigned(DropDownMenu) then
begin
P := ClientToScreen(Point(0, Height));
DropDownMenu.Popup(P.X, P.Y);
repeat
Application.ProcessMessages;
until not QWidget_isVisible(DropDownMenu.Handle);
end;
end;
procedure TJvXPCustomToolButton.SetImages(const Value: TCustomImageList);
begin
if FImages <> Value then
begin
if FImages <> nil then
FImages.UnRegisterChanges(FChangeLink);
FImages := Value;
if FImages <> nil then
begin
FImages.FreeNotification(Self);
FImages.RegisterChanges(FChangeLink);
end;
LockedInvalidate;
end;
end;
procedure TJvXPCustomToolButton.SetImageIndex(const Value: TImageIndex);
begin
if FImageIndex <> Value then
begin
FImageIndex := Value;
LockedInvalidate;
end;
end;
procedure TJvXPCustomToolButton.SetDropDownMenu(const Value: TPopupMenu);
begin
if FDropDownMenu <> Value then
begin
FDropDownMenu := Value;
if FDropDownMenu <> nil then
FDropDownMenu.FreeNotification(Self);
LockedInvalidate;
end;
end;
procedure TJvXPCustomToolButton.DoImagesChange(Sender: TObject);
begin
LockedInvalidate;
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvQXPButtons.pas,v $';
Revision: '$Revision: 1.24 $';
Date: '$Date: 2005/02/07 07:51:17 $';
LogPath: 'JVCL\run'
);
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -