|
| 1 | +{$I ..\Definition.Inc} |
| 2 | + |
| 3 | +unit WrapVclMenus; |
| 4 | + |
| 5 | +interface |
| 6 | + |
| 7 | +uses |
| 8 | + Vcl.Menus, |
| 9 | + PythonEngine, |
| 10 | + WrapDelphi, |
| 11 | + WrapDelphiClasses; |
| 12 | + |
| 13 | +type |
| 14 | + TMenuItemAccess = class(TContainerAccess) |
| 15 | + private |
| 16 | + function GetContainer: TMenuItem; |
| 17 | + public |
| 18 | + function GetItem(AIndex: Integer): PPyObject; override; |
| 19 | + function GetSize: Integer; override; |
| 20 | + function IndexOf(AValue: PPyObject): Integer; override; |
| 21 | + class function ExpectedContainerClass: TClass; override; |
| 22 | + class function SupportsIndexOf: Boolean; override; |
| 23 | + class function Name: string; override; |
| 24 | + property Container: TMenuItem read GetContainer; |
| 25 | + end; |
| 26 | + |
| 27 | + TPyDelphiMenuItem = class(TPyDelphiComponent) |
| 28 | + private |
| 29 | + function GetDelphiObject: TMenuItem; |
| 30 | + procedure SetDelphiObject(const Value: TMenuItem); |
| 31 | + public |
| 32 | + class function DelphiObjectClass: TClass; override; |
| 33 | + class function GetContainerAccessClass: TContainerAccessClass; override; |
| 34 | + property DelphiObject: TMenuItem read GetDelphiObject write SetDelphiObject; |
| 35 | + end; |
| 36 | + |
| 37 | + TPyDelphiMenu = class(TPyDelphiComponent) |
| 38 | + private |
| 39 | + function GetDelphiObject: TMenu; |
| 40 | + procedure SetDelphiObject(const Value: TMenu); |
| 41 | + public |
| 42 | + class function DelphiObjectClass: TClass; override; |
| 43 | + property DelphiObject: TMenu read GetDelphiObject write SetDelphiObject; |
| 44 | + end; |
| 45 | + |
| 46 | + TPyDelphiPopupMenu = class(TPyDelphiMenu) |
| 47 | + private |
| 48 | + function GetDelphiObject: TPopupMenu; |
| 49 | + procedure SetDelphiObject(const Value: TPopupMenu); |
| 50 | + public |
| 51 | + class function DelphiObjectClass: TClass; override; |
| 52 | + property DelphiObject: TPopupMenu read GetDelphiObject write SetDelphiObject; |
| 53 | + end; |
| 54 | + |
| 55 | + TPyDelphiMainMenu = class(TPyDelphiMenu) |
| 56 | + private |
| 57 | + function GetDelphiObject: TMainMenu; |
| 58 | + procedure SetDelphiObject(const Value: TMainMenu); |
| 59 | + public |
| 60 | + class function DelphiObjectClass: TClass; override; |
| 61 | + property DelphiObject: TMainMenu read GetDelphiObject write SetDelphiObject; |
| 62 | + end; |
| 63 | + |
| 64 | +implementation |
| 65 | + |
| 66 | +{ Register the wrappers, the globals and the constants } |
| 67 | +type |
| 68 | + TMenusRegistration = class(TRegisteredUnit) |
| 69 | + public |
| 70 | + function Name : string; override; |
| 71 | + procedure RegisterWrappers(APyDelphiWrapper : TPyDelphiWrapper); override; |
| 72 | + end; |
| 73 | + |
| 74 | +{ TMenusRegistration } |
| 75 | + |
| 76 | +function TMenusRegistration.Name: string; |
| 77 | +begin |
| 78 | + Result := 'Vcl.Menus'; |
| 79 | +end; |
| 80 | + |
| 81 | +procedure TMenusRegistration.RegisterWrappers( |
| 82 | + APyDelphiWrapper: TPyDelphiWrapper); |
| 83 | +begin |
| 84 | + inherited; |
| 85 | + APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiMenuItem); |
| 86 | + APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiMenu); |
| 87 | + APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiPopupMenu); |
| 88 | + APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiMainMenu); |
| 89 | +end; |
| 90 | + |
| 91 | +{ TPyDelphiMenuItem } |
| 92 | + |
| 93 | +class function TPyDelphiMenuItem.DelphiObjectClass: TClass; |
| 94 | +begin |
| 95 | + Result := TMenuItem; |
| 96 | +end; |
| 97 | + |
| 98 | +class function TPyDelphiMenuItem.GetContainerAccessClass: TContainerAccessClass; |
| 99 | +begin |
| 100 | + Result := TMenuItemAccess; |
| 101 | +end; |
| 102 | + |
| 103 | +function TPyDelphiMenuItem.GetDelphiObject: TMenuItem; |
| 104 | +begin |
| 105 | + Result := TMenuItem(inherited DelphiObject); |
| 106 | +end; |
| 107 | + |
| 108 | +procedure TPyDelphiMenuItem.SetDelphiObject(const Value: TMenuItem); |
| 109 | +begin |
| 110 | + inherited DelphiObject := Value; |
| 111 | +end; |
| 112 | + |
| 113 | +{ TPyDelphiPopupMenu } |
| 114 | + |
| 115 | +class function TPyDelphiPopupMenu.DelphiObjectClass: TClass; |
| 116 | +begin |
| 117 | + Result := TPopupMenu; |
| 118 | +end; |
| 119 | + |
| 120 | +function TPyDelphiPopupMenu.GetDelphiObject: TPopupMenu; |
| 121 | +begin |
| 122 | + Result := TPopupMenu(inherited DelphiObject); |
| 123 | +end; |
| 124 | + |
| 125 | +procedure TPyDelphiPopupMenu.SetDelphiObject(const Value: TPopupMenu); |
| 126 | +begin |
| 127 | + inherited DelphiObject := Value; |
| 128 | +end; |
| 129 | + |
| 130 | +{ TPyDelphiMenu } |
| 131 | + |
| 132 | +class function TPyDelphiMenu.DelphiObjectClass: TClass; |
| 133 | +begin |
| 134 | + Result := TMenu; |
| 135 | +end; |
| 136 | + |
| 137 | +function TPyDelphiMenu.GetDelphiObject: TMenu; |
| 138 | +begin |
| 139 | + Result := TMenu(inherited DelphiObject); |
| 140 | +end; |
| 141 | + |
| 142 | +procedure TPyDelphiMenu.SetDelphiObject(const Value: TMenu); |
| 143 | +begin |
| 144 | + inherited DelphiObject := Value; |
| 145 | +end; |
| 146 | + |
| 147 | +{ TPyDelphiMainMenu } |
| 148 | + |
| 149 | +class function TPyDelphiMainMenu.DelphiObjectClass: TClass; |
| 150 | +begin |
| 151 | + Result := TMainMenu; |
| 152 | +end; |
| 153 | + |
| 154 | +function TPyDelphiMainMenu.GetDelphiObject: TMainMenu; |
| 155 | +begin |
| 156 | + Result := TMainMenu(inherited DelphiObject); |
| 157 | +end; |
| 158 | + |
| 159 | +procedure TPyDelphiMainMenu.SetDelphiObject(const Value: TMainMenu); |
| 160 | +begin |
| 161 | + inherited DelphiObject := Value; |
| 162 | +end; |
| 163 | + |
| 164 | +{ TMenuItemAccess } |
| 165 | + |
| 166 | +class function TMenuItemAccess.ExpectedContainerClass: TClass; |
| 167 | +begin |
| 168 | + Result := TMenuItem; |
| 169 | +end; |
| 170 | + |
| 171 | +function TMenuItemAccess.GetContainer: TMenuItem; |
| 172 | +begin |
| 173 | + Result := TMenuItem(inherited Container); |
| 174 | +end; |
| 175 | + |
| 176 | +function TMenuItemAccess.GetItem(AIndex: Integer): PPyObject; |
| 177 | +begin |
| 178 | + Result := Wrap(Container.Items[AIndex]); |
| 179 | +end; |
| 180 | + |
| 181 | +function TMenuItemAccess.GetSize: Integer; |
| 182 | +begin |
| 183 | + Result := Container.Count; |
| 184 | +end; |
| 185 | + |
| 186 | +function TMenuItemAccess.IndexOf(AValue: PPyObject): Integer; |
| 187 | +var |
| 188 | + _obj: TPyObject; |
| 189 | + _item: TMenuItem; |
| 190 | +begin |
| 191 | + Result := -1; |
| 192 | + with GetPythonEngine do |
| 193 | + begin |
| 194 | + if IsDelphiObject(AValue) then |
| 195 | + begin |
| 196 | + _obj := PythonToDelphi(AValue); |
| 197 | + if (_obj is TPyDelphiObject) and |
| 198 | + (TPyDelphiObject(_obj).DelphiObject is TMenuItem) then |
| 199 | + begin |
| 200 | + _item := TMenuItem(TPyDelphiObject(_obj).DelphiObject); |
| 201 | + Result := Container.IndexOf(_item); |
| 202 | + end; |
| 203 | + end; |
| 204 | + end; |
| 205 | +end; |
| 206 | + |
| 207 | +class function TMenuItemAccess.Name: string; |
| 208 | +begin |
| 209 | + Result := 'TMenuItem.Items'; |
| 210 | +end; |
| 211 | + |
| 212 | +class function TMenuItemAccess.SupportsIndexOf: Boolean; |
| 213 | +begin |
| 214 | + Result := True; |
| 215 | +end; |
| 216 | + |
| 217 | +initialization |
| 218 | + RegisteredUnits.Add(TMenusRegistration.Create()); |
| 219 | + |
| 220 | +end. |
0 commit comments