|
5 | 5 | interface |
6 | 6 |
|
7 | 7 | uses |
8 | | - Classes, SysUtils, PythonEngine, WrapDelphi, WrapDelphiClasses, |
9 | | - WrapVclControls, Windows, ComCtrls, TypInfo; |
| 8 | + Winapi.Windows, |
| 9 | + System.SysUtils, |
| 10 | + System.Classes, |
| 11 | + System.TypInfo, |
| 12 | + Vcl.ComCtrls, |
| 13 | + PythonEngine, |
| 14 | + WrapDelphi, |
| 15 | + WrapDelphiClasses, |
| 16 | + WrapVclControls; |
10 | 17 |
|
11 | 18 | type |
12 | 19 | TTabChangingEventHandler = class(TEventHandler) |
@@ -113,10 +120,50 @@ TPyDelphiTrackBar = class (TPyDelphiWinControl) |
113 | 120 | property DelphiObject: TTrackBar read GetDelphiObject write SetDelphiObject; |
114 | 121 | end; |
115 | 122 |
|
| 123 | + TPyDelphiToolButton = class(TPyDelphiGraphicControl) |
| 124 | + private |
| 125 | + function GetDelphiObject: TToolButton; |
| 126 | + procedure SetDelphiObject(const Value: TToolButton); |
| 127 | + public |
| 128 | + class function DelphiObjectClass: TClass; override; |
| 129 | + property DelphiObject: TToolButton read GetDelphiObject |
| 130 | + write SetDelphiObject; |
| 131 | + end; |
| 132 | + |
| 133 | + TToolbarAccess = class(TContainerAccess) |
| 134 | + private |
| 135 | + function GetContainer: TToolbar; |
| 136 | + public |
| 137 | + function GetItem(AIndex: Integer): PPyObject; override; |
| 138 | + function GetSize: Integer; override; |
| 139 | + function IndexOf(AValue: PPyObject): Integer; override; |
| 140 | + class function ExpectedContainerClass: TClass; override; |
| 141 | + class function SupportsIndexOf: Boolean; override; |
| 142 | + class function Name: string; override; |
| 143 | + property Container: TToolbar read GetContainer; |
| 144 | + end; |
| 145 | + |
| 146 | + TPyDelphiToolbar = class(TPyDelphiWinControl) |
| 147 | + private |
| 148 | + function GetDelphiObject: TToolbar; |
| 149 | + procedure SetDelphiObject(const Value: TToolbar); |
| 150 | + protected |
| 151 | + function Get_ButtonCount(AContext: Pointer): PPyObject; cdecl; |
| 152 | + function Get_Buttons(AContext: Pointer): PPyObject; cdecl; |
| 153 | + public |
| 154 | + class function DelphiObjectClass: TClass; override; |
| 155 | + class procedure RegisterGetSets(PythonType: TPythonType); override; |
| 156 | + class function GetContainerAccessClass: TContainerAccessClass; override; |
| 157 | + |
| 158 | + property DelphiObject: TToolbar read GetDelphiObject |
| 159 | + write SetDelphiObject; |
| 160 | + end; |
| 161 | + |
116 | 162 | implementation |
117 | 163 |
|
118 | 164 | uses |
119 | | - WrapDelphiTypes, ExtCtrls; |
| 165 | + WrapDelphiTypes, |
| 166 | + Vcl.ExtCtrls; |
120 | 167 |
|
121 | 168 | { Register the wrappers, the globals and the constants } |
122 | 169 | type |
@@ -148,6 +195,8 @@ procedure TComCtrlsRegistration.RegisterWrappers(APyDelphiWrapper: TPyDelphiWrap |
148 | 195 | APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiPageControl); |
149 | 196 | APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiTabSheet); |
150 | 197 | APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiTrackBar); |
| 198 | + APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiToolButton); |
| 199 | + APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiToolbar); |
151 | 200 |
|
152 | 201 | APyDelphiWrapper.EventHandlers.RegisterHandler(TTabChangingEventHandler); |
153 | 202 | end; |
@@ -641,9 +690,128 @@ procedure TPyDelphiTrackBar.SetDelphiObject(const Value: TTrackBar); |
641 | 690 | inherited DelphiObject := Value; |
642 | 691 | end; |
643 | 692 |
|
| 693 | +{ TPyDelphiToolButton } |
| 694 | + |
| 695 | +class function TPyDelphiToolButton.DelphiObjectClass: TClass; |
| 696 | +begin |
| 697 | + Result := TToolButton; |
| 698 | +end; |
| 699 | + |
| 700 | +function TPyDelphiToolButton.GetDelphiObject: TToolButton; |
| 701 | +begin |
| 702 | + Result := TToolButton(inherited DelphiObject); |
| 703 | +end; |
| 704 | + |
| 705 | +procedure TPyDelphiToolButton.SetDelphiObject(const Value: TToolButton); |
| 706 | +begin |
| 707 | + inherited DelphiObject := Value; |
| 708 | +end; |
| 709 | + |
| 710 | +{ TToolbarAccess } |
| 711 | + |
| 712 | +class function TToolbarAccess.ExpectedContainerClass: TClass; |
| 713 | +begin |
| 714 | + Result := TToolbar; |
| 715 | +end; |
| 716 | + |
| 717 | +function TToolbarAccess.GetContainer: TToolbar; |
| 718 | +begin |
| 719 | + Result := TToolbar(inherited Container); |
| 720 | +end; |
| 721 | + |
| 722 | +function TToolbarAccess.GetItem(AIndex: Integer): PPyObject; |
| 723 | +begin |
| 724 | + Result := Wrap( Container.Buttons[AIndex] ); |
| 725 | +end; |
| 726 | + |
| 727 | +function TToolbarAccess.GetSize: Integer; |
| 728 | +begin |
| 729 | + Result := Container.ButtonCount; |
| 730 | +end; |
| 731 | + |
| 732 | +function TToolbarAccess.IndexOf(AValue: PPyObject): Integer; |
| 733 | +var |
| 734 | + _obj: TPyObject; |
| 735 | + _item: TToolButton; |
| 736 | +begin |
| 737 | + Result := -1; |
| 738 | + with GetPythonEngine do |
| 739 | + begin |
| 740 | + if IsDelphiObject(AValue) then |
| 741 | + begin |
| 742 | + _obj := PythonToDelphi(AValue); |
| 743 | + if (_obj is TPyDelphiObject) and |
| 744 | + (TPyDelphiObject(_obj).DelphiObject is TToolButton) then |
| 745 | + begin |
| 746 | + _item := TToolButton(TPyDelphiObject(_obj).DelphiObject); |
| 747 | + Result := _item.Index; |
| 748 | + end; |
| 749 | + end; |
| 750 | + end; |
| 751 | +end; |
| 752 | + |
| 753 | +class function TToolbarAccess.Name: string; |
| 754 | +begin |
| 755 | + Result := 'Toolbar.Buttons' |
| 756 | +end; |
| 757 | + |
| 758 | +class function TToolbarAccess.SupportsIndexOf: Boolean; |
| 759 | +begin |
| 760 | + Result := True; |
| 761 | +end; |
| 762 | + |
| 763 | +{ TPyDelphiToolbar } |
| 764 | + |
| 765 | +class function TPyDelphiToolbar.DelphiObjectClass: TClass; |
| 766 | +begin |
| 767 | + Result := TToolbar; |
| 768 | +end; |
| 769 | + |
| 770 | +class function TPyDelphiToolbar.GetContainerAccessClass: TContainerAccessClass; |
| 771 | +begin |
| 772 | + Result := TToolbarAccess; |
| 773 | +end; |
| 774 | + |
| 775 | +function TPyDelphiToolbar.GetDelphiObject: TToolbar; |
| 776 | +begin |
| 777 | + Result := TToolbar(inherited DelphiObject); |
| 778 | +end; |
| 779 | + |
| 780 | +function TPyDelphiToolbar.Get_Buttons(AContext: Pointer): PPyObject; |
| 781 | +begin |
| 782 | + Adjust(@Self); |
| 783 | + Result := PyDelphiWrapper.DefaultContainerType.CreateInstance; |
| 784 | + with PythonToDelphi(Result) as TPyDelphiContainer do |
| 785 | + Setup(Self.PyDelphiWrapper, TToolbarAccess.Create(Self.PyDelphiWrapper, |
| 786 | + Self.DelphiObject)); |
| 787 | +end; |
| 788 | + |
| 789 | +function TPyDelphiToolbar.Get_ButtonCount(AContext: Pointer): PPyObject; |
| 790 | +begin |
| 791 | + Adjust(@Self); |
| 792 | + Result := GetPythonEngine.PyLong_FromLong(DelphiObject.ButtonCount); |
| 793 | +end; |
| 794 | + |
| 795 | +class procedure TPyDelphiToolbar.RegisterGetSets(PythonType: TPythonType); |
| 796 | +begin |
| 797 | + inherited; |
| 798 | + with PythonType do |
| 799 | + begin |
| 800 | + AddGetSet('ButtonCount', @TPyDelphiToolbar.Get_ButtonCount, nil, |
| 801 | + 'Indicates the number of buttons in the toolbar.', nil); |
| 802 | + AddGetSet('Actions', @TPyDelphiToolbar.Get_Buttons, nil, |
| 803 | + 'Lists the buttons of the toolbar.', nil); |
| 804 | + end; |
| 805 | +end; |
| 806 | + |
| 807 | +procedure TPyDelphiToolbar.SetDelphiObject(const Value: TToolbar); |
| 808 | +begin |
| 809 | + inherited DelphiObject := Value; |
| 810 | +end; |
| 811 | + |
644 | 812 | initialization |
645 | 813 | RegisteredUnits.Add( TComCtrlsRegistration.Create ); |
646 | 814 | {$IFNDEF FPC} |
647 | | - Classes.RegisterClasses([TDateTimePicker]); |
| 815 | + System.Classes.RegisterClasses([TDateTimePicker]); |
648 | 816 | {$ENDIF FPC} |
649 | 817 | end. |
0 commit comments