1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915
|
{*****************************************************************************}
{ }
{ Tnt Delphi Unicode Controls }
{ http://tnt.ccci.org/delphi_unicode_controls/ }
{ Version: 2.1.11 }
{ }
{ Copyright (c) 2002-2004, Troy Wolbrink (troy.wolbrink@ccci.org) }
{ }
{*****************************************************************************}
unit TntButtons;
{$INCLUDE TntCompilers.inc}
interface
uses
Windows, Messages, Classes, Controls, Forms, Graphics, StdCtrls,
ExtCtrls, CommCtrl, Buttons,
TntForms, TntControls, TntStdCtrls;
type
ITntGlyphButton = interface
['{15D7E501-1E33-4293-8B45-716FB3B14504}']
function GetButtonGlyph: Pointer;
procedure UpdateInternalGlyphList;
end;
{TNT-WARN TSpeedButton}
TTntSpeedButton = class(TSpeedButton {TNT-ALLOW TSpeedButton}, ITntGlyphButton)
private
FPaintInherited: Boolean;
function GetCaption: TWideCaption;
procedure SetCaption(const Value: TWideCaption);
function GetHint: WideString;
procedure SetHint(const Value: WideString);
function IsCaptionStored: Boolean;
function IsHintStored: Boolean;
procedure CMHintShow(var Message: TMessage); message CM_HINTSHOW;
procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
protected
function GetButtonGlyph: Pointer;
procedure UpdateInternalGlyphList; dynamic;
procedure PaintButton; dynamic;
procedure Paint; override;
procedure DefineProperties(Filer: TFiler); override;
function GetActionLinkClass: TControlActionLinkClass; override;
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
published
property Caption: TWideCaption read GetCaption write SetCaption stored IsCaptionStored;
property Hint: WideString read GetHint write SetHint stored IsHintStored;
end;
{TNT-WARN TBitBtn}
TTntBitBtn = class(TBitBtn {TNT-ALLOW TBitBtn}, ITntGlyphButton)
private
FPaintInherited: Boolean;
FMouseInControl: Boolean;
function IsCaptionStored: Boolean;
function GetCaption: TWideCaption;
procedure SetCaption(const Value: TWideCaption);
function IsHintStored: Boolean;
function GetHint: WideString;
procedure SetHint(const Value: WideString);
procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
protected
function GetButtonGlyph: Pointer;
procedure UpdateInternalGlyphList; dynamic;
procedure DrawItem(const DrawItemStruct: TDrawItemStruct); dynamic;
procedure CreateWindowHandle(const Params: TCreateParams); override;
procedure DefineProperties(Filer: TFiler); override;
function GetActionLinkClass: TControlActionLinkClass; override;
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
published
property Caption: TWideCaption read GetCaption write SetCaption stored IsCaptionStored;
property Hint: WideString read GetHint write SetHint stored IsHintStored;
end;
procedure TButtonGlyph_CalcButtonLayout(Control: TControl; DC: HDC; const Client: TRect;
const Offset: TPoint; const Caption: WideString; Layout: TButtonLayout;
Margin, Spacing: Integer; var GlyphPos: TPoint; var TextBounds: TRect;
BiDiFlags: Integer {$IFDEF DELPHI_7_UP}; WordWrap: Boolean {$ENDIF});
function TButtonGlyph_Draw(Control: TControl; Canvas: TCanvas; const Client: TRect;
const Offset: TPoint; const Caption: WideString; Layout: TButtonLayout; Margin: Integer;
Spacing: Integer; State: TButtonState; Transparent: Boolean;
BiDiFlags: Longint {$IFDEF DELPHI_7_UP}; WordWrap: Boolean {$ENDIF}): TRect;
implementation
uses
SysUtils, TypInfo, {$IFDEF COMPILER_6_UP} RTLConsts, {$ELSE} Consts, {$ENDIF} TntWindows,
{$IFDEF THEME_7_UP} Themes, {$ENDIF} TntClasses, TntActnList, ActnList, TntSysUtils;
type
EAbortPaint = class(EAbort);
// Many routines in this unit are nearly the same as those found in Buttons.pas. They are
// included here because the VCL implementation of TButtonGlyph is completetly inaccessible.
type
THackButtonGlyph_D5_D6_D7_D9 = class
protected
FOriginal: TBitmap;
FGlyphList: TImageList;
FIndexs: array[TButtonState] of Integer;
FxxxxTransparentColor: TColor;
FNumGlyphs: TNumGlyphs;
end;
THackBitBtn_D5_D6_D7_D9 = class(TButton{TNT-ALLOW TButton})
protected
FCanvas: TCanvas;
FGlyph: Pointer;
FxxxxStyle: TButtonStyle;
FxxxxKind: TBitBtnKind;
FxxxxLayout: TButtonLayout;
FxxxxSpacing: Integer;
FxxxxMargin: Integer;
IsFocused: Boolean;
end;
THackSpeedButton_D5_D6_D7_D9 = class(TGraphicControl)
protected
FxxxxGroupIndex: Integer;
FGlyph: Pointer;
FxxxxDown: Boolean;
FDragging: Boolean;
end;
{$IFDEF COMPILER_5} // verified against VCL source in Delphi 5 and BCB 5
THackButtonGlyph = THackButtonGlyph_D5_D6_D7_D9;
THackBitBtn = THackBitBtn_D5_D6_D7_D9;
THackSpeedButton = THackSpeedButton_D5_D6_D7_D9;
{$ENDIF}
{$IFDEF COMPILER_6} // verified against VCL source in Delphi 6 and BCB 6
THackButtonGlyph = THackButtonGlyph_D5_D6_D7_D9;
THackBitBtn = THackBitBtn_D5_D6_D7_D9;
THackSpeedButton = THackSpeedButton_D5_D6_D7_D9;
{$ENDIF}
{$IFDEF DELPHI_7}
THackButtonGlyph = THackButtonGlyph_D5_D6_D7_D9;
THackBitBtn = THackBitBtn_D5_D6_D7_D9;
THackSpeedButton = THackSpeedButton_D5_D6_D7_D9;
{$ENDIF}
{$IFDEF DELPHI_9}
THackButtonGlyph = THackButtonGlyph_D5_D6_D7_D9;
THackBitBtn = THackBitBtn_D5_D6_D7_D9;
THackSpeedButton = THackSpeedButton_D5_D6_D7_D9;
{$ENDIF}
function GetButtonGlyph(Control: TControl): THackButtonGlyph;
var
GlyphButton: ITntGlyphButton;
begin
if Control.GetInterface(ITntGlyphButton, GlyphButton) then
Result := GlyphButton.GetButtonGlyph
else
raise ETntInternalError.Create('Internal Error: Control does not support ITntGlyphButton.');
end;
procedure UpdateInternalGlyphList(Control: TControl);
var
GlyphButton: ITntGlyphButton;
begin
if Control.GetInterface(ITntGlyphButton, GlyphButton) then
GlyphButton.UpdateInternalGlyphList
else
raise ETntInternalError.Create('Internal Error: Control does not support ITntGlyphButton.');
end;
function TButtonGlyph_CreateButtonGlyph(Control: TControl; State: TButtonState): Integer;
var
ButtonGlyph: THackButtonGlyph;
NumGlyphs: Integer;
begin
ButtonGlyph := GetButtonGlyph(Control);
NumGlyphs := ButtonGlyph.FNumGlyphs;
if (State = bsDown) and (NumGlyphs < 3) then State := bsUp;
Result := ButtonGlyph.FIndexs[State];
if (Result = -1) then begin
UpdateInternalGlyphList(Control);
Result := ButtonGlyph.FIndexs[State];
end;
end;
procedure TButtonGlyph_DrawButtonGlyph(Control: TControl; Canvas: TCanvas; const GlyphPos: TPoint;
State: TButtonState; Transparent: Boolean);
var
ButtonGlyph: THackButtonGlyph;
Glyph: TBitmap;
GlyphList: TImageList;
Index: Integer;
{$IFDEF THEME_7_UP}
Details: TThemedElementDetails;
R: TRect;
Button: TThemedButton;
{$ENDIF}
begin
ButtonGlyph := GetButtonGlyph(Control);
Glyph := ButtonGlyph.FOriginal;
GlyphList := ButtonGlyph.FGlyphList;
if Glyph = nil then Exit;
if (Glyph.Width = 0) or (Glyph.Height = 0) then Exit;
Index := TButtonGlyph_CreateButtonGlyph(Control, State);
with GlyphPos do
{$IFDEF THEME_7_UP}
if ThemeServices.ThemesEnabled then begin
R.TopLeft := GlyphPos;
R.Right := R.Left + Glyph.Width div ButtonGlyph.FNumGlyphs;
R.Bottom := R.Top + Glyph.Height;
case State of
bsDisabled:
Button := tbPushButtonDisabled;
bsDown,
bsExclusive:
Button := tbPushButtonPressed;
else
// bsUp
Button := tbPushButtonNormal;
end;
Details := ThemeServices.GetElementDetails(Button);
ThemeServices.DrawIcon(Canvas.Handle, Details, R, GlyphList.Handle, Index);
end else
{$ENDIF}
if Transparent or (State = bsExclusive) then
ImageList_DrawEx(GlyphList.Handle, Index, Canvas.Handle, X, Y, 0, 0,
clNone, clNone, ILD_Transparent)
else
ImageList_DrawEx(GlyphList.Handle, Index, Canvas.Handle, X, Y, 0, 0,
ColorToRGB(clBtnFace), clNone, ILD_Normal);
end;
procedure TButtonGlyph_DrawButtonText(Canvas: TCanvas; const Caption: WideString;
TextBounds: TRect; State: TButtonState;
BiDiFlags: LongInt {$IFDEF DELPHI_7_UP}; WordWrap: Boolean {$ENDIF});
begin
with Canvas do
begin
Brush.Style := bsClear;
if State = bsDisabled then
begin
OffsetRect(TextBounds, 1, 1);
Font.Color := clBtnHighlight;
{$IFDEF DELPHI_7_UP}
if WordWrap then
Tnt_DrawTextW(Handle, PWideChar(Caption), Length(Caption), TextBounds,
DT_CENTER or DT_WORDBREAK or BiDiFlags) { TODO: Figure out why DT_VCENTER is not used }
else
{$ENDIF}
Tnt_DrawTextW(Handle, PWideChar(Caption), Length(Caption), TextBounds,
DT_CENTER or DT_VCENTER or BiDiFlags);
OffsetRect(TextBounds, -1, -1);
Font.Color := clBtnShadow;
{$IFDEF DELPHI_7_UP}
if WordWrap then
Tnt_DrawTextW(Handle, PWideChar(Caption), Length(Caption), TextBounds,
DT_CENTER or DT_WORDBREAK or BiDiFlags) { TODO: Figure out why DT_VCENTER is not used }
else
{$ENDIF}
Tnt_DrawTextW(Handle, PWideChar(Caption), Length(Caption), TextBounds,
DT_CENTER or DT_VCENTER or BiDiFlags);
end else
begin
{$IFDEF DELPHI_7_UP}
if WordWrap then
Tnt_DrawTextW(Handle, PWideChar(Caption), Length(Caption), TextBounds,
DT_CENTER or DT_WORDBREAK or BiDiFlags) { TODO: Figure out why DT_VCENTER is not used }
else
{$ENDIF}
Tnt_DrawTextW(Handle, PWideChar(Caption), Length(Caption), TextBounds,
DT_CENTER or DT_VCENTER or BiDiFlags);
end;
end;
end;
procedure TButtonGlyph_CalcButtonLayout(Control: TControl; DC: HDC; const Client: TRect;
const Offset: TPoint; const Caption: WideString; Layout: TButtonLayout;
Margin, Spacing: Integer; var GlyphPos: TPoint; var TextBounds: TRect;
BiDiFlags: Integer {$IFDEF DELPHI_7_UP}; WordWrap: Boolean {$ENDIF});
var
TextPos: TPoint;
ClientSize,
GlyphSize,
TextSize: TPoint;
TotalSize: TPoint;
Glyph: TBitmap;
NumGlyphs: Integer;
ButtonGlyph: THackButtonGlyph;
begin
ButtonGlyph := GetButtonGlyph(Control);
Glyph := ButtonGlyph.FOriginal;
NumGlyphs := ButtonGlyph.FNumGlyphs;
if (BiDiFlags and DT_RIGHT) = DT_RIGHT then
if Layout = blGlyphLeft then
Layout := blGlyphRight
else
if Layout = blGlyphRight then
Layout := blGlyphLeft;
// Calculate the item sizes.
ClientSize := Point(Client.Right - Client.Left, Client.Bottom - Client.Top);
if Assigned(Glyph) then
GlyphSize := Point(Glyph.Width div NumGlyphs, Glyph.Height)
else
GlyphSize := Point(0, 0);
if Length(Caption) > 0 then
begin
{$IFDEF DELPHI_7_UP}
TextBounds := Rect(0, 0, Client.Right - Client.Left - GlyphSize.X - 3, 0); { TODO: Figure out why GlyphSize.X is in here. }
{$ELSE}
TextBounds := Rect(0, 0, Client.Right - Client.Left, 0);
{$ENDIF}
{$IFDEF DELPHI_7_UP}
if WordWrap then
Tnt_DrawTextW(DC, PWideChar(Caption), Length(Caption), TextBounds, DT_WORDBREAK
or DT_CALCRECT or BiDiFlags)
else
{$ENDIF}
Tnt_DrawTextW(DC, PWideChar(Caption), Length(Caption), TextBounds, DT_CALCRECT or BiDiFlags);
TextSize := Point(TextBounds.Right - TextBounds.Left, TextBounds.Bottom - TextBounds.Top);
end
else
begin
TextBounds := Rect(0, 0, 0, 0);
TextSize := Point(0, 0);
end;
// If the layout has the glyph on the right or the left, then both the text and the glyph are centered vertically.
// If the glyph is on the top or the bottom, then both the text and the glyph are centered horizontally.
if Layout in [blGlyphLeft, blGlyphRight] then
begin
GlyphPos.Y := (ClientSize.Y - GlyphSize.Y + 1) div 2;
TextPos.Y := (ClientSize.Y - TextSize.Y + 1) div 2;
end
else
begin
GlyphPos.X := (ClientSize.X - GlyphSize.X + 1) div 2;
TextPos.X := (ClientSize.X - TextSize.X + 1) div 2;
end;
// If there is no text or no bitmap, then Spacing is irrelevant.
if (TextSize.X = 0) or (GlyphSize.X = 0) then
Spacing := 0;
// Adjust Margin and Spacing.
if Margin = -1 then
begin
if Spacing = -1 then
begin
TotalSize := Point(GlyphSize.X + TextSize.X, GlyphSize.Y + TextSize.Y);
if Layout in [blGlyphLeft, blGlyphRight] then
Margin := (ClientSize.X - TotalSize.X) div 3
else
Margin := (ClientSize.Y - TotalSize.Y) div 3;
Spacing := Margin;
end
else
begin
TotalSize := Point(GlyphSize.X + Spacing + TextSize.X, GlyphSize.Y + Spacing + TextSize.Y);
if Layout in [blGlyphLeft, blGlyphRight] then
Margin := (ClientSize.X - TotalSize.X + 1) div 2
else
Margin := (ClientSize.Y - TotalSize.Y + 1) div 2;
end;
end
else
begin
if Spacing = -1 then
begin
TotalSize := Point(ClientSize.X - (Margin + GlyphSize.X), ClientSize.Y - (Margin + GlyphSize.Y));
if Layout in [blGlyphLeft, blGlyphRight] then
Spacing := (TotalSize.X - TextSize.X) div 2
else
Spacing := (TotalSize.Y - TextSize.Y) div 2;
end;
end;
case Layout of
blGlyphLeft:
begin
GlyphPos.X := Margin;
TextPos.X := GlyphPos.X + GlyphSize.X + Spacing;
end;
blGlyphRight:
begin
GlyphPos.X := ClientSize.X - Margin - GlyphSize.X;
TextPos.X := GlyphPos.X - Spacing - TextSize.X;
end;
blGlyphTop:
begin
GlyphPos.Y := Margin;
TextPos.Y := GlyphPos.Y + GlyphSize.Y + Spacing;
end;
blGlyphBottom:
begin
GlyphPos.Y := ClientSize.Y - Margin - GlyphSize.Y;
TextPos.Y := GlyphPos.Y - Spacing - TextSize.Y;
end;
end;
// Fixup the Result variables.
with GlyphPos do
begin
Inc(X, Client.Left + Offset.X);
Inc(Y, Client.Top + Offset.Y);
end;
{$IFDEF THEME_7_UP}
{ Themed text is not shifted, but gets a different color. }
if ThemeServices.ThemesEnabled then
OffsetRect(TextBounds, TextPos.X + Client.Left, TextPos.Y + Client.Top)
else
{$ENDIF}
OffsetRect(TextBounds, TextPos.X + Client.Left + Offset.X, TextPos.Y + Client.Top + Offset.Y);
end;
function TButtonGlyph_Draw(Control: TControl; Canvas: TCanvas; const Client: TRect;
const Offset: TPoint; const Caption: WideString; Layout: TButtonLayout; Margin: Integer;
Spacing: Integer; State: TButtonState; Transparent: Boolean;
BiDiFlags: Longint {$IFDEF DELPHI_7_UP}; WordWrap: Boolean {$ENDIF}): TRect;
var
GlyphPos: TPoint;
begin
TButtonGlyph_CalcButtonLayout(Control, Canvas.Handle, Client, Offset, Caption, Layout, Margin,
Spacing, GlyphPos, Result, BiDiFlags {$IFDEF DELPHI_7_UP}, WordWrap {$ENDIF});
TButtonGlyph_DrawButtonGlyph(Control, Canvas, GlyphPos, State, Transparent);
TButtonGlyph_DrawButtonText(Canvas, Caption, Result, State,
BiDiFlags {$IFDEF DELPHI_7_UP}, WordWrap {$ENDIF});
end;
{ TTntSpeedButton }
procedure TTntSpeedButton.DefineProperties(Filer: TFiler);
begin
inherited;
TntPersistent_AfterInherited_DefineProperties(Filer, Self);
end;
function TTntSpeedButton.IsCaptionStored: Boolean;
begin
Result := TntControl_IsCaptionStored(Self)
end;
function TTntSpeedButton.GetCaption: TWideCaption;
begin
Result := TntControl_GetText(Self);
end;
procedure TTntSpeedButton.SetCaption(const Value: TWideCaption);
begin
TntControl_SetText(Self, Value);
end;
function TTntSpeedButton.IsHintStored: Boolean;
begin
Result := TntControl_IsHintStored(Self)
end;
function TTntSpeedButton.GetHint: WideString;
begin
Result := TntControl_GetHint(Self)
end;
procedure TTntSpeedButton.SetHint(const Value: WideString);
begin
TntControl_SetHint(Self, Value);
end;
procedure TTntSpeedButton.CMHintShow(var Message: TMessage);
begin
ProcessCMHintShowMsg(Message);
inherited;
end;
procedure TTntSpeedButton.CMDialogChar(var Message: TCMDialogChar);
begin
with Message do
if IsWideCharAccel(CharCode, Caption) and Enabled and Visible and
(Parent <> nil) and Parent.Showing then
begin
Click;
Result := 1;
end else
inherited;
end;
function TTntSpeedButton.GetButtonGlyph: Pointer;
begin
Result := THackSpeedButton(Self).FGlyph;
end;
procedure TTntSpeedButton.UpdateInternalGlyphList;
begin
FPaintInherited := True;
try
Repaint;
finally
FPaintInherited := False;
end;
Invalidate;
raise EAbortPaint.Create('');
end;
procedure TTntSpeedButton.Paint;
begin
if FPaintInherited then
inherited
else
PaintButton;
end;
procedure TTntSpeedButton.PaintButton;
const
DownStyles: array[Boolean] of Integer = (BDR_RAISEDINNER, BDR_SUNKENOUTER);
FillStyles: array[Boolean] of Integer = (BF_MIDDLE, 0);
var
PaintRect: TRect;
DrawFlags: Integer;
Offset: TPoint;
{$IFDEF THEME_7_UP}
Button: TThemedButton;
ToolButton: TThemedToolBar;
Details: TThemedElementDetails;
{$ENDIF}
begin
try
if not Enabled then
begin
FState := bsDisabled;
THackSpeedButton(Self).FDragging := False;
end
else if FState = bsDisabled then
if Down and (GroupIndex <> 0) then
FState := bsExclusive
else
FState := bsUp;
Canvas.Font := Self.Font;
{$IFDEF THEME_7_UP}
if ThemeServices.ThemesEnabled then
begin
{$IFDEF COMPILER_7_UP}
PerformEraseBackground(Self, Canvas.Handle);
{$ENDIF}
SelectObject(Canvas.Handle, Canvas.Font.Handle); { For some reason, PerformEraseBackground sometimes messes the font up. }
if not Enabled then
Button := tbPushButtonDisabled
else
if FState in [bsDown, bsExclusive] then
Button := tbPushButtonPressed
else
if MouseInControl then
Button := tbPushButtonHot
else
Button := tbPushButtonNormal;
ToolButton := ttbToolbarDontCare;
if Flat then
begin
case Button of
tbPushButtonDisabled:
Toolbutton := ttbButtonDisabled;
tbPushButtonPressed:
Toolbutton := ttbButtonPressed;
tbPushButtonHot:
Toolbutton := ttbButtonHot;
tbPushButtonNormal:
Toolbutton := ttbButtonNormal;
end;
end;
PaintRect := ClientRect;
if ToolButton = ttbToolbarDontCare then
begin
Details := ThemeServices.GetElementDetails(Button);
ThemeServices.DrawElement(Canvas.Handle, Details, PaintRect);
PaintRect := ThemeServices.ContentRect(Canvas.Handle, Details, PaintRect);
end
else
begin
Details := ThemeServices.GetElementDetails(ToolButton);
ThemeServices.DrawElement(Canvas.Handle, Details, PaintRect);
PaintRect := ThemeServices.ContentRect(Canvas.Handle, Details, PaintRect);
end;
if Button = tbPushButtonPressed then
begin
// A pressed speed button has a white text. This applies however only to flat buttons.
if ToolButton <> ttbToolbarDontCare then
Canvas.Font.Color := clHighlightText;
Offset := Point(1, 0);
end
else
Offset := Point(0, 0);
TButtonGlyph_Draw(Self, Canvas, PaintRect, Offset, Caption, Layout, Margin, Spacing, FState,
Transparent, DrawTextBiDiModeFlags(0) {$IFDEF DELPHI_7_UP}, False {$ENDIF});
end
else
{$ENDIF}
begin
PaintRect := Rect(0, 0, Width, Height);
if not Flat then
begin
DrawFlags := DFCS_BUTTONPUSH or DFCS_ADJUSTRECT;
if FState in [bsDown, bsExclusive] then
DrawFlags := DrawFlags or DFCS_PUSHED;
DrawFrameControl(Canvas.Handle, PaintRect, DFC_BUTTON, DrawFlags);
end
else
begin
if (FState in [bsDown, bsExclusive]) or
(MouseInControl and (FState <> bsDisabled)) or
(csDesigning in ComponentState) then
DrawEdge(Canvas.Handle, PaintRect, DownStyles[FState in [bsDown, bsExclusive]],
FillStyles[Transparent] or BF_RECT)
else if not Transparent then
begin
Canvas.Brush.Color := Color;
Canvas.FillRect(PaintRect);
end;
InflateRect(PaintRect, -1, -1);
end;
if FState in [bsDown, bsExclusive] then
begin
if (FState = bsExclusive) and (not Flat or not MouseInControl) then
begin
Canvas.Brush.Bitmap := AllocPatternBitmap(clBtnFace, clBtnHighlight);
Canvas.FillRect(PaintRect);
end;
Offset.X := 1;
Offset.Y := 1;
end
else
begin
Offset.X := 0;
Offset.Y := 0;
end;
TButtonGlyph_Draw(Self, Canvas, PaintRect, Offset, Caption,
Layout, Margin, Spacing, FState, Transparent,
DrawTextBiDiModeFlags(0) {$IFDEF DELPHI_7_UP}, False {$ENDIF});
end;
except
on E: EAbortPaint do
;
else
raise;
end;
end;
function TTntSpeedButton.GetActionLinkClass: TControlActionLinkClass;
begin
Result := TntControl_GetActionLinkClass(Self, inherited GetActionLinkClass);
end;
procedure TTntSpeedButton.ActionChange(Sender: TObject; CheckDefaults: Boolean);
begin
TntControl_BeforeInherited_ActionChange(Self, Sender, CheckDefaults);
inherited;
end;
{ TTntButton }
procedure TTntBitBtn.CreateWindowHandle(const Params: TCreateParams);
begin
CreateUnicodeHandle(Self, Params, 'BUTTON');
end;
procedure TTntBitBtn.DefineProperties(Filer: TFiler);
begin
inherited;
TntPersistent_AfterInherited_DefineProperties(Filer, Self);
end;
function TTntBitBtn.IsCaptionStored: Boolean;
var
PropInfo: PPropInfo;
begin
// TTntBitBtn has it's own storage specifier, based upon the button kind
PropInfo := GetPropInfo(TBitBtn{TNT-ALLOW TBitBtn}, 'Caption');
if PropInfo = nil then
raise EPropertyError.CreateResFmt(PResStringRec(@SUnknownProperty), ['Caption']);
Result := IsStoredProp(Self, PropInfo);
end;
function TTntBitBtn.GetCaption: TWideCaption;
begin
Result := TntControl_GetText(Self)
end;
procedure TTntBitBtn.SetCaption(const Value: TWideCaption);
begin
TntControl_SetText(Self, Value);
end;
function TTntBitBtn.IsHintStored: Boolean;
begin
Result := TntControl_IsHintStored(Self)
end;
function TTntBitBtn.GetHint: WideString;
begin
Result := TntControl_GetHint(Self)
end;
procedure TTntBitBtn.SetHint(const Value: WideString);
begin
TntControl_SetHint(Self, Value);
end;
procedure TTntBitBtn.CMDialogChar(var Message: TCMDialogChar);
begin
TntButton_CMDialogChar(Self, Message);
end;
function TTntBitBtn.GetButtonGlyph: Pointer;
begin
Result := THackBitBtn(Self).FGlyph;
end;
procedure TTntBitBtn.UpdateInternalGlyphList;
begin
FPaintInherited := True;
try
Repaint;
finally
FPaintInherited := False;
end;
Invalidate;
raise EAbortPaint.Create('');
end;
procedure TTntBitBtn.CNDrawItem(var Message: TWMDrawItem);
begin
if FPaintInherited then
inherited
else
DrawItem(Message.DrawItemStruct^);
end;
procedure TTntBitBtn.DrawItem(const DrawItemStruct: TDrawItemStruct);
var
IsDown, IsDefault: Boolean;
State: TButtonState;
R: TRect;
Flags: Longint;
FCanvas: TCanvas;
IsFocused: Boolean;
{$IFDEF THEME_7_UP}
Details: TThemedElementDetails;
Button: TThemedButton;
Offset: TPoint;
{$ENDIF}
begin
try
FCanvas := THackBitBtn(Self).FCanvas;
IsFocused := THackBitBtn(Self).IsFocused;
FCanvas.Handle := DrawItemStruct.hDC;
R := ClientRect;
with DrawItemStruct do
begin
FCanvas.Handle := hDC;
FCanvas.Font := Self.Font;
IsDown := itemState and ODS_SELECTED <> 0;
IsDefault := itemState and ODS_FOCUS <> 0;
if not Enabled then State := bsDisabled
else if IsDown then State := bsDown
else State := bsUp;
end;
{$IFDEF THEME_7_UP}
if ThemeServices.ThemesEnabled then
begin
if not Enabled then
Button := tbPushButtonDisabled
else
if IsDown then
Button := tbPushButtonPressed
else
if FMouseInControl then
Button := tbPushButtonHot
else
if IsFocused or IsDefault then
Button := tbPushButtonDefaulted
else
Button := tbPushButtonNormal;
Details := ThemeServices.GetElementDetails(Button);
// Parent background.
ThemeServices.DrawParentBackground(Handle, DrawItemStruct.hDC, @Details, True);
// Button shape.
ThemeServices.DrawElement(DrawItemStruct.hDC, Details, DrawItemStruct.rcItem);
R := ThemeServices.ContentRect(FCanvas.Handle, Details, DrawItemStruct.rcItem);
if Button = tbPushButtonPressed then
Offset := Point(1, 0)
else
Offset := Point(0, 0);
TButtonGlyph_Draw(Self, FCanvas, R, Offset, Caption, Layout, Margin, Spacing, State, False,
DrawTextBiDiModeFlags(0) {$IFDEF DELPHI_7_UP}, Self.WordWrap {$ENDIF});
if IsFocused and IsDefault then
begin
FCanvas.Pen.Color := clWindowFrame;
FCanvas.Brush.Color := clBtnFace;
DrawFocusRect(FCanvas.Handle, R);
end;
end
else
{$ENDIF}
begin
R := ClientRect;
Flags := DFCS_BUTTONPUSH or DFCS_ADJUSTRECT;
if IsDown then Flags := Flags or DFCS_PUSHED;
if DrawItemStruct.itemState and ODS_DISABLED <> 0 then
Flags := Flags or DFCS_INACTIVE;
{ DrawFrameControl doesn't allow for drawing a button as the
default button, so it must be done here. }
if IsFocused or IsDefault then
begin
FCanvas.Pen.Color := clWindowFrame;
FCanvas.Pen.Width := 1;
FCanvas.Brush.Style := bsClear;
FCanvas.Rectangle(R.Left, R.Top, R.Right, R.Bottom);
{ DrawFrameControl must draw within this border }
InflateRect(R, -1, -1);
end;
{ DrawFrameControl does not draw a pressed button correctly }
if IsDown then
begin
FCanvas.Pen.Color := clBtnShadow;
FCanvas.Pen.Width := 1;
FCanvas.Brush.Color := clBtnFace;
FCanvas.Rectangle(R.Left, R.Top, R.Right, R.Bottom);
InflateRect(R, -1, -1);
end
else
DrawFrameControl(DrawItemStruct.hDC, R, DFC_BUTTON, Flags);
if IsFocused then
begin
R := ClientRect;
InflateRect(R, -1, -1);
end;
FCanvas.Font := Self.Font;
if IsDown then
OffsetRect(R, 1, 1);
TButtonGlyph_Draw(Self, FCanvas, R, Point(0, 0), Caption, Layout, Margin, Spacing, State,
False, DrawTextBiDiModeFlags(0) {$IFDEF DELPHI_7_UP}, Self.WordWrap {$ENDIF});
if IsFocused and IsDefault then
begin
R := ClientRect;
InflateRect(R, -4, -4);
FCanvas.Pen.Color := clWindowFrame;
FCanvas.Brush.Color := clBtnFace;
DrawFocusRect(FCanvas.Handle, R);
end;
end;
FCanvas.Handle := 0;
except
on E: EAbortPaint do
;
else
raise;
end;
end;
procedure TTntBitBtn.CMMouseEnter(var Message: TMessage);
begin
FMouseInControl := True;
inherited;
end;
procedure TTntBitBtn.CMMouseLeave(var Message: TMessage);
begin
FMouseInControl := False;
inherited;
end;
procedure TTntBitBtn.ActionChange(Sender: TObject; CheckDefaults: Boolean);
begin
TntControl_BeforeInherited_ActionChange(Self, Sender, CheckDefaults);
inherited;
end;
function TTntBitBtn.GetActionLinkClass: TControlActionLinkClass;
begin
Result := TntControl_GetActionLinkClass(Self, inherited GetActionLinkClass);
end;
end.
|