Changeset 244 for branches/highdpi/Packages/DpiControls/UDpiControls.pas
- Timestamp:
- May 21, 2020, 6:42:45 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/Packages/DpiControls/UDpiControls.pas
r216 r244 8 8 Classes, SysUtils, LCLProc, LResources, Forms, FormEditingIntf, ProjectIntf, 9 9 Controls, StdCtrls, fgl, Graphics, ComCtrls, ExtCtrls, LCLType, GraphType, 10 Types, CustApp, LMessages, LCLIntf ;10 Types, CustApp, LMessages, LCLIntf, Menus; 11 11 12 12 type … … 483 483 function GetVclForm: TForm; virtual; 484 484 procedure UpdateVclControl; override; 485 procedure AfterConstruction; override;486 485 public 487 486 VclForm: TForm; 487 procedure AfterConstruction; override; 488 488 property ModalResult: TModalResult read GetModalResult write SetModalResult; 489 489 function ShowModal: Integer; virtual; … … 796 796 end; 797 797 798 { TDpiMenuItem } 799 800 TDpiMenuItem = class(TComponent) 801 private 802 FItems: TList; 803 FParent: TDpiMenuItem; 804 FOnClick: TNotifyEvent; 805 function GetCaption: TTranslateString; 806 function GetChecked: Boolean; 807 function GetCount: Integer; 808 function GetEnabled: Boolean; 809 function GetGroupIndex: Byte; 810 function GetItem(Index: Integer): TDpiMenuItem; 811 function GetOnClick: TNotifyEvent; 812 function GetRadioItem: Boolean; 813 function GetShortCut: TShortCut; 814 function GetVisible: Boolean; 815 function IsCaptionStored: Boolean; 816 function IsCheckedStored: Boolean; 817 function IsEnabledStored: Boolean; 818 function IsShortCutStored: Boolean; 819 function IsVisibleStored: Boolean; 820 procedure SetCaption(AValue: TTranslateString); 821 procedure SetChecked(AValue: Boolean); 822 procedure SetEnabled(AValue: Boolean); 823 procedure SetGroupIndex(AValue: Byte); 824 procedure SetOnClick(AValue: TNotifyEvent); 825 procedure SetRadioItem(AValue: Boolean); 826 procedure SetShortCut(AValue: TShortCut); 827 procedure SetVisible(AValue: Boolean); 828 procedure OnClickHandler(Sender: TObject); 829 protected 830 function GetVclMenuItem: TMenuItem; virtual; 831 procedure SetParentComponent(AValue: TComponent); override; 832 public 833 VclMenuItem: TMenuItem; 834 constructor Create(AOwner: TComponent); override; 835 destructor Destroy; override; 836 procedure Delete(Index: Integer); 837 procedure Add(Item: TDpiMenuItem); 838 procedure Insert(Index: Integer; Item: TDpiMenuItem); 839 function IndexOf(Item: TDpiMenuItem): Integer; 840 procedure Remove(Item: TDpiMenuItem); 841 property Items[Index: Integer]: TDpiMenuItem read GetItem; default; 842 property Count: Integer read GetCount; 843 published 844 property RadioItem: Boolean read GetRadioItem write SetRadioItem default False; 845 property ShortCut: TShortCut read GetShortCut write SetShortCut 846 stored IsShortCutStored default 0; 847 property Enabled: Boolean read GetEnabled write SetEnabled 848 stored IsEnabledStored default True; 849 property Visible: Boolean read GetVisible write SetVisible 850 stored IsVisibleStored default True; 851 property Checked: Boolean read GetChecked write SetChecked 852 stored IsCheckedStored default False; 853 property Caption: TTranslateString read GetCaption write SetCaption 854 stored IsCaptionStored; 855 property OnClick: TNotifyEvent read GetOnClick write SetOnClick; 856 property GroupIndex: Byte read GetGroupIndex write SetGroupIndex default 0; 857 end; 858 859 TDpiMenu = class(TComponent) 860 private 861 FItems: TDpiMenuItem; 862 protected 863 function GetVclMenu: TMenu; virtual; 864 public 865 property Items: TDpiMenuItem read FItems; 866 constructor Create(AOwner: TComponent); override; 867 destructor Destroy; override; 868 end; 869 870 { TDpiPopupMenu } 871 872 TDpiPopupMenu = class(TDpiMenu) 873 private 874 function GetAutoPopup: Boolean; 875 procedure SetAutoPopup(AValue: Boolean); 876 protected 877 function GetVclMenu: TMenu; override; 878 function GetVclPopupMenu: TPopupMenu; virtual; 879 public 880 VclPopupMenu: TPopupMenu; 881 procedure PopUp; 882 procedure PopUp(X, Y: Integer); virtual; 883 constructor Create(AOwner: TComponent); override; 884 destructor Destroy; override; 885 published 886 property AutoPopup: Boolean read GetAutoPopup write SetAutoPopup default True; 887 end; 888 798 889 var 799 890 DpiFormFileDesc: TDpiFormFileDesc; … … 818 909 implementation 819 910 911 uses 912 LCLStrConsts; 913 820 914 resourcestring 821 915 SDpiFormTitle = 'DpiForm form'; … … 827 921 DpiFormFileDesc := TDpiFormFileDesc.Create; 828 922 RegisterProjectFileDescriptor(DpiFormFileDesc); 829 RegisterComponents('DpiControls', [TDpiButton, TDpiImage, TDpiPaintBox, TDpiListBox]); 923 RegisterComponents('DpiControls', [TDpiButton, TDpiImage, TDpiPaintBox, 924 TDpiListBox, TDpiPopupMenu]); 830 925 end; 831 926 … … 897 992 Result := BitBlt(DestDC, ScaleToVcl(X), ScaleToVcl(Y), ScaleToVcl(Width), 898 993 ScaleToVcl(Height), SrcDC, ScaleToVcl(XSrc), ScaleToVcl(YSrc), Rop); 994 end; 995 996 { TDpiMenu } 997 998 function TDpiMenu.GetVclMenu: TMenu; 999 begin 1000 Result := nil; 1001 end; 1002 1003 constructor TDpiMenu.Create(AOwner: TComponent); 1004 begin 1005 inherited; 1006 FItems := TDpiMenuItem.Create(Self); 1007 end; 1008 1009 destructor TDpiMenu.Destroy; 1010 begin 1011 FreeAndNil(FItems); 1012 inherited; 1013 end; 1014 1015 { TDpiMenuItem } 1016 1017 function TDpiMenuItem.GetCaption: TTranslateString; 1018 begin 1019 Result := GetVclMenuItem.Caption; 1020 end; 1021 1022 function TDpiMenuItem.GetChecked: Boolean; 1023 begin 1024 Result := GetVclMenuItem.Checked; 1025 end; 1026 1027 function TDpiMenuItem.GetCount: Integer; 1028 begin 1029 Result := FItems.Count; 1030 end; 1031 1032 function TDpiMenuItem.GetEnabled: Boolean; 1033 begin 1034 Result := GetVclMenuItem.Enabled; 1035 end; 1036 1037 function TDpiMenuItem.GetGroupIndex: Byte; 1038 begin 1039 Result := GetVclMenuItem.GroupIndex; 1040 end; 1041 1042 function TDpiMenuItem.GetItem(Index: Integer): TDpiMenuItem; 1043 begin 1044 Result := TDpiMenuItem(FItems[Index]); 1045 end; 1046 1047 function TDpiMenuItem.GetOnClick: TNotifyEvent; 1048 begin 1049 Result := FOnClick; 1050 end; 1051 1052 function TDpiMenuItem.GetRadioItem: Boolean; 1053 begin 1054 Result := GetVclMenuItem.RadioItem; 1055 end; 1056 1057 function TDpiMenuItem.GetShortCut: TShortCut; 1058 begin 1059 Result := GetVclMenuItem.ShortCut; 1060 end; 1061 1062 function TDpiMenuItem.GetVisible: Boolean; 1063 begin 1064 Result := GetVclMenuItem.Visible; 1065 end; 1066 1067 function TDpiMenuItem.IsCaptionStored: Boolean; 1068 begin 1069 Result := False; 1070 end; 1071 1072 function TDpiMenuItem.IsCheckedStored: Boolean; 1073 begin 1074 Result := False; 1075 end; 1076 1077 function TDpiMenuItem.IsEnabledStored: Boolean; 1078 begin 1079 Result := False; 1080 end; 1081 1082 function TDpiMenuItem.IsShortCutStored: Boolean; 1083 begin 1084 Result := False; 1085 end; 1086 1087 function TDpiMenuItem.IsVisibleStored: Boolean; 1088 begin 1089 Result := False; 1090 end; 1091 1092 procedure TDpiMenuItem.SetCaption(AValue: TTranslateString); 1093 begin 1094 GetVclMenuItem.Caption := AValue; 1095 end; 1096 1097 procedure TDpiMenuItem.SetChecked(AValue: Boolean); 1098 begin 1099 GetVclMenuItem.Checked := AValue; 1100 end; 1101 1102 procedure TDpiMenuItem.SetEnabled(AValue: Boolean); 1103 begin 1104 GetVclMenuItem.Enabled := AValue; 1105 end; 1106 1107 procedure TDpiMenuItem.SetGroupIndex(AValue: Byte); 1108 begin 1109 GetVclMenuItem.GroupIndex := AValue; 1110 end; 1111 1112 procedure TDpiMenuItem.SetOnClick(AValue: TNotifyEvent); 1113 begin 1114 FOnClick := AValue; 1115 end; 1116 1117 procedure TDpiMenuItem.SetRadioItem(AValue: Boolean); 1118 begin 1119 GetVclMenuItem.RadioItem := AValue; 1120 end; 1121 1122 procedure TDpiMenuItem.SetShortCut(AValue: TShortCut); 1123 begin 1124 GetVclMenuItem.ShortCut := AValue; 1125 end; 1126 1127 procedure TDpiMenuItem.SetVisible(AValue: Boolean); 1128 begin 1129 GetVclMenuItem.Visible := AValue; 1130 end; 1131 1132 procedure TDpiMenuItem.OnClickHandler(Sender: TObject); 1133 begin 1134 if Assigned(FOnClick) then 1135 FOnClick(Self); 1136 end; 1137 1138 procedure TDpiMenuItem.Delete(Index: Integer); 1139 begin 1140 FItems.Delete(Index); 1141 GetVclMenuItem.Delete(Index); 1142 end; 1143 1144 procedure TDpiMenuItem.Add(Item: TDpiMenuItem); 1145 begin 1146 Insert(GetCount, Item); 1147 end; 1148 1149 procedure TDpiMenuItem.Insert(Index: Integer; Item: TDpiMenuItem); 1150 begin 1151 FItems.Insert(Index, Item); 1152 GetVclMenuItem.Insert(Index, Item.GetVclMenuItem); 1153 end; 1154 1155 function TDpiMenuItem.IndexOf(Item: TDpiMenuItem): Integer; 1156 begin 1157 if FItems = nil then 1158 Result := -1 1159 else 1160 Result := FItems.IndexOf(Item); 1161 end; 1162 1163 procedure TDpiMenuItem.Remove(Item: TDpiMenuItem); 1164 var 1165 I: Integer; 1166 begin 1167 I := IndexOf(Item); 1168 if I < 0 then 1169 raise EMenuError.Create(SMenuNotFound); 1170 Delete(I); 1171 end; 1172 1173 function TDpiMenuItem.GetVclMenuItem: TMenuItem; 1174 begin 1175 if not Assigned(VclMenuItem) then begin 1176 VclMenuItem := TMenuItem.Create(nil); 1177 VclMenuItem.Name := 'Vcl' + Name; 1178 VclMenuItem.OnClick := @OnClickHandler; 1179 end; 1180 Result := VclMenuItem; 1181 end; 1182 1183 procedure TDpiMenuItem.SetParentComponent(AValue: TComponent); 1184 begin 1185 if (FParent = AValue) then Exit; 1186 if Assigned(FParent) then FParent.Remove(Self); 1187 if Assigned(AValue) then 1188 begin 1189 if (AValue is TDpiMenu) 1190 then TDpiMenu(AValue).Items.Add(Self) 1191 else if (AValue is TDpiMenuItem) 1192 then TDpiMenuItem(AValue).Add(Self) 1193 else 1194 raise Exception.Create('TDpiMenuItem.SetParentComponent: suggested parent not of type TDpiMenu or TDpiMenuItem'); 1195 end; 1196 end; 1197 1198 constructor TDpiMenuItem.Create(AOwner: TComponent); 1199 begin 1200 inherited; 1201 FItems := TList.Create; 1202 end; 1203 1204 destructor TDpiMenuItem.Destroy; 1205 begin 1206 FreeAndNil(FItems); 1207 inherited Destroy; 1208 end; 1209 1210 { TDpiPopupMenu } 1211 1212 procedure TDpiPopupMenu.PopUp; 1213 var 1214 Pos: TPoint; 1215 begin 1216 Pos := DpiMouse.CursorPos; 1217 Popup(Pos.X, Pos.Y); 1218 end; 1219 1220 procedure TDpiPopupMenu.PopUp(X, Y: Integer); 1221 begin 1222 GetVclPopupMenu.PopUp(ScaleToVcl(X), ScaleToVcl(Y)); 1223 end; 1224 1225 constructor TDpiPopupMenu.Create(AOwner: TComponent); 1226 begin 1227 inherited; 1228 GetVclPopupMenu; 1229 end; 1230 1231 function TDpiPopupMenu.GetAutoPopup: Boolean; 1232 begin 1233 Result := GetVclPopupMenu.AutoPopup; 1234 end; 1235 1236 procedure TDpiPopupMenu.SetAutoPopup(AValue: Boolean); 1237 begin 1238 GetVclPopupMenu.AutoPopup := AValue; 1239 end; 1240 1241 function TDpiPopupMenu.GetVclMenu: TMenu; 1242 begin 1243 Result := GetVclPopupMenu; 1244 end; 1245 1246 function TDpiPopupMenu.GetVclPopupMenu: TPopupMenu; 1247 begin 1248 if not Assigned(VclPopupMenu) then begin 1249 VclPopupMenu := TPopupMenu.Create(nil); 1250 if Assigned(Items.VclMenuItem) then Items.VclMenuItem.Free; 1251 Items.VclMenuItem := VclPopupMenu.Items; 1252 end; 1253 Result := VclPopupMenu; 1254 end; 1255 1256 destructor TDpiPopupMenu.Destroy; 1257 begin 1258 if Assigned(VclPopupMenu) then FreeAndNil(VclPopupMenu); 1259 inherited Destroy; 899 1260 end; 900 1261 … … 2213 2574 procedure TDpiScreen.UpdateScreen; 2214 2575 begin 2215 Dpi := 96 * 2; //Screen.PixelsPerInch; 2576 // Dpi := 96 * 2; 2577 Dpi := Screen.PixelsPerInch; 2216 2578 end; 2217 2579
Note:
See TracChangeset
for help on using the changeset viewer.