Changeset 568 for trunk/Packages/DpiControls/Dpi.StdCtrls.pas
- Timestamp:
- May 13, 2024, 6:00:06 PM (5 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/DpiControls/Dpi.StdCtrls.pas
r503 r568 4 4 5 5 uses 6 Classes, SysUtils, Controls, StdCtrls, Forms, Dpi.Controls ;6 Classes, SysUtils, Controls, StdCtrls, Forms, Dpi.Controls, Dpi.Graphics; 7 7 8 8 type … … 104 104 end; 105 105 106 TDrawItemEvent = procedure(Control: TWinControl; Index: Integer; 107 ARect: TRect; State: TOwnerDrawState) of object; 108 TListBoxStyle = StdCtrls.TListBoxStyle; 109 106 110 { TListBox } 107 111 108 112 TListBox = class(TWinControl) 109 113 private 114 FCanvas: TCanvas; 115 FOnDrawItem: TDrawItemEvent; 110 116 function GetBorderStyle: TBorderStyle; 111 117 function GetCount: Integer; … … 118 124 function GetParentFont: Boolean; 119 125 function GetScrollWidth: Integer; 126 function GetStyle: TListBoxStyle; 120 127 function GetTopIndex: Integer; 121 128 procedure SetBorderStyle(AValue: TBorderStyle); … … 125 132 procedure SetItemIndex(AValue: Integer); 126 133 procedure SetItems(AValue: TStrings); 134 procedure SetOnDrawItem(AValue: TDrawItemEvent); 127 135 procedure SetOnSelectionChange(AValue: TSelectionChangeEvent); 128 136 procedure SetParentFont(AValue: Boolean); 129 137 procedure SetScrollWidth(AValue: Integer); 138 procedure SetStyle(AValue: TListBoxStyle); 130 139 procedure SetTopIndex(AValue: Integer); 140 procedure DoDrawItemNative(Control: Controls.TWinControl; Index: Integer; 141 ARect: TRect; State: TOwnerDrawState); 131 142 protected 132 143 function GetNativeWinControl: Controls.TWinControl; override; … … 134 145 public 135 146 NativeListBox: StdCtrls.TListBox; 147 constructor Create(AOwner: TComponent); override; 136 148 destructor Destroy; override; 137 149 property ItemIndex: Integer read GetItemIndex write SetItemIndex; 138 150 property Items: TStrings read GetItems write SetItems; 139 151 property Count: Integer read GetCount; 152 property Canvas: TCanvas read FCanvas; 140 153 published 141 154 property ParentColor; … … 151 164 property OnSelectionChange: TSelectionChangeEvent read GetOnSelectionChange 152 165 write SetOnSelectionChange; 166 property Style: TListBoxStyle read GetStyle write SetStyle default lbStandard; 167 property OnDrawItem: TDrawItemEvent read FOnDrawItem write SetOnDrawItem; 153 168 end; 154 169 … … 497 512 function TListBox.GetItemHeight: Integer; 498 513 begin 499 Result := GetNativeListBox.ItemHeight;514 Result := ScaleFromNative(GetNativeListBox.ItemHeight); 500 515 end; 501 516 … … 525 540 end; 526 541 542 function TListBox.GetStyle: TListBoxStyle; 543 begin 544 Result := GetNativeListBox.Style; 545 end; 546 527 547 function TListBox.GetTopIndex: Integer; 528 548 begin … … 547 567 procedure TListBox.SetItemHeight(AValue: Integer); 548 568 begin 549 GetNativeListBox.ItemHeight := AValue;569 GetNativeListBox.ItemHeight := ScaleToNative(AValue); 550 570 end; 551 571 … … 560 580 end; 561 581 582 procedure TListBox.SetOnDrawItem(AValue: TDrawItemEvent); 583 begin 584 FOnDrawItem := AValue; 585 if Assigned(AValue) then 586 GetNativeListBox.OnDrawItem := DoDrawItemNative 587 else GetNativeListBox.OnDrawItem := nil; 588 end; 589 562 590 procedure TListBox.SetOnSelectionChange(AValue: TSelectionChangeEvent); 563 591 begin … … 575 603 end; 576 604 605 procedure TListBox.SetStyle(AValue: TListBoxStyle); 606 begin 607 GetNativeListBox.Style := AValue; 608 end; 609 577 610 procedure TListBox.SetTopIndex(AValue: Integer); 578 611 begin 579 612 GetNativeListBox.TopIndex := AValue; 613 end; 614 615 procedure TListBox.DoDrawItemNative(Control: Controls.TWinControl; 616 Index: Integer; ARect: TRect; State: TOwnerDrawState); 617 begin 618 if Assigned(FOnDrawItem) then 619 FOnDrawItem(Self, Index, ScaleRectFromNative(ARect), State); 580 620 end; 581 621 … … 591 631 end; 592 632 633 constructor TListBox.Create(AOwner: TComponent); 634 begin 635 inherited; 636 FCanvas := TCanvas.Create; 637 FCanvas.NativeCanvas := GetNativeListBox.Canvas; 638 end; 639 593 640 destructor TListBox.Destroy; 594 641 begin 642 FreeAndNil(FCanvas); 595 643 FreeAndNil(NativeListBox); 596 644 inherited;
Note:
See TracChangeset
for help on using the changeset viewer.