Changeset 269 for branches/highdpi/Packages/DpiControls/UDpiControls.pas
- Timestamp:
- Jun 29, 2020, 5:53:08 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/Packages/DpiControls/UDpiControls.pas
r268 r269 129 129 130 130 TDpiWinControl = class; 131 TDpiControlBorderSpacing = class; 131 132 132 133 { TDpiControl } … … 134 135 TDpiControl = class(TComponent) 135 136 private 137 FBorderSpacing: TDpiControlBorderSpacing; 136 138 FConstraints: TDpiSizeConstraints; 137 139 FFont: TDpiFont; … … 165 167 procedure SetAlign(AValue: TAlign); 166 168 procedure SetAnchors(AValue: TAnchors); 169 procedure SetBorderSpacing(AValue: TDpiControlBorderSpacing); 167 170 procedure SetBoundsRect(AValue: TRect); 168 171 procedure SetClientHeight(AValue: Integer); … … 192 195 procedure MouseEnterHandler(Sender: TObject); virtual; 193 196 protected 197 procedure DoBorderSpacingChange(Sender: TObject; InnerSpaceChanged: Boolean); virtual; 194 198 function GetText: TCaption; virtual; 195 199 procedure SetText(AValue: TCaption); virtual; … … 235 239 property Visible: Boolean read GetVisible write SetVisible; 236 240 property Anchors: TAnchors read GetAnchors write SetAnchors stored IsAnchorsStored default [akLeft, akTop]; 241 property BorderSpacing: TDpiControlBorderSpacing read FBorderSpacing write SetBorderSpacing; 237 242 published 238 243 property ClientHeight: Integer read GetClientHeight write SetClientHeight; … … 261 266 262 267 TDpiControls = specialize TFPGObjectList<TDpiControl>; 268 269 { TDpiControlBorderSpacing } 270 271 TDpiControlBorderSpacing = class(TPersistent) 272 private 273 FAround: TSpacingSize; 274 FBottom: TSpacingSize; 275 FLeft: TSpacingSize; 276 FOnChange: TNotifyEvent; 277 FRight: TSpacingSize; 278 FTop: TSpacingSize; 279 FControl: TDpiControl; 280 FDefault: PControlBorderSpacingDefault; 281 function IsAroundStored: Boolean; 282 function IsBottomStored: Boolean; 283 function IsLeftStored: Boolean; 284 function IsRightStored: Boolean; 285 function IsTopStored: Boolean; 286 procedure SetAround(AValue: TSpacingSize); 287 procedure SetBottom(AValue: TSpacingSize); 288 procedure SetLeft(AValue: TSpacingSize); 289 procedure SetRight(AValue: TSpacingSize); 290 procedure SetTop(AValue: TSpacingSize); 291 procedure Change(InnerSpaceChanged: Boolean); virtual; 292 public 293 constructor Create(OwnerControl: TDpiControl; ADefault: PControlBorderSpacingDefault = nil); 294 published 295 property OnChange: TNotifyEvent read FOnChange write FOnChange; 296 property Around: TSpacingSize read FAround write SetAround stored IsAroundStored; 297 property Left: TSpacingSize read FLeft write SetLeft stored IsLeftStored; 298 property Top: TSpacingSize read FTop write SetTop stored IsTopStored; 299 property Right: TSpacingSize read FRight write SetRight stored IsRightStored; 300 property Bottom: TSpacingSize read FBottom write SetBottom stored IsBottomStored; 301 end; 263 302 264 303 { TDpiGraphic } … … 635 674 TDpiScrollBar = class(TDpiControl) 636 675 private 637 function GetBorderSpacing: TControlBorderSpacing;638 676 function GetKind: TScrollBarKind; 639 677 function GetMax: Integer; … … 642 680 function GetPageSize: Integer; 643 681 function GetPosition: Integer; 644 procedure SetBorderSpacing(AValue: TControlBorderSpacing);645 682 procedure SetKind(AValue: TScrollBarKind); 646 683 procedure SetMax(AValue: Integer); … … 653 690 public 654 691 NativeScrollBar: TScrollBar; 692 constructor Create(TheOwner: TComponent); override; 655 693 destructor Destroy; override; 656 694 published … … 659 697 property Max: Integer read GetMax write SetMax; 660 698 property Position: Integer read GetPosition write SetPosition; 661 property BorderSpacing: TControlBorderSpacing read GetBorderSpacing write SetBorderSpacing;662 699 property Kind: TScrollBarKind read GetKind write SetKind; 663 700 property OnChange: TNotifyEvent read GetOnChange write SetOnChange; … … 1147 1184 end; 1148 1185 1186 { TDpiControlBorderSpacing } 1187 1188 function TDpiControlBorderSpacing.IsBottomStored: Boolean; 1189 begin 1190 if FDefault = nil 1191 then Result := FBottom <> 0 1192 else Result := FBottom <> FDefault^.Bottom; 1193 end; 1194 1195 function TDpiControlBorderSpacing.IsAroundStored: Boolean; 1196 begin 1197 if FDefault = nil 1198 then Result := FAround <> 0 1199 else Result := FAround <> FDefault^.Around; 1200 end; 1201 1202 function TDpiControlBorderSpacing.IsLeftStored: Boolean; 1203 begin 1204 if FDefault = nil 1205 then Result := FLeft <> 0 1206 else Result := FLeft <> FDefault^.Left; 1207 end; 1208 1209 function TDpiControlBorderSpacing.IsRightStored: Boolean; 1210 begin 1211 if FDefault = nil 1212 then Result := FRight <> 0 1213 else Result := FRight <> FDefault^.Right; 1214 end; 1215 1216 function TDpiControlBorderSpacing.IsTopStored: Boolean; 1217 begin 1218 if FDefault = nil 1219 then Result := FTop <> 0 1220 else Result := FTop <> FDefault^.Top; 1221 end; 1222 1223 procedure TDpiControlBorderSpacing.SetAround(AValue: TSpacingSize); 1224 begin 1225 if FAround = AValue then Exit; 1226 FAround := AValue; 1227 Change(False); 1228 end; 1229 1230 procedure TDpiControlBorderSpacing.SetBottom(AValue: TSpacingSize); 1231 begin 1232 if FBottom = AValue then Exit; 1233 FBottom := AValue; 1234 Change(False); 1235 end; 1236 1237 procedure TDpiControlBorderSpacing.SetLeft(AValue: TSpacingSize); 1238 begin 1239 if FLeft = AValue then Exit; 1240 FLeft := AValue; 1241 Change(False); 1242 end; 1243 1244 procedure TDpiControlBorderSpacing.SetRight(AValue: TSpacingSize); 1245 begin 1246 if FRight = AValue then Exit; 1247 FRight := AValue; 1248 Change(False); 1249 end; 1250 1251 procedure TDpiControlBorderSpacing.SetTop(AValue: TSpacingSize); 1252 begin 1253 if FTop = AValue then Exit; 1254 FTop := AValue; 1255 Change(False); 1256 end; 1257 1258 procedure TDpiControlBorderSpacing.Change(InnerSpaceChanged: Boolean); 1259 begin 1260 if FControl <> nil then 1261 FControl.DoBorderSpacingChange(Self, InnerSpaceChanged); 1262 if Assigned(OnChange) then OnChange(Self); 1263 end; 1264 1265 constructor TDpiControlBorderSpacing.Create(OwnerControl: TDpiControl; 1266 ADefault: PControlBorderSpacingDefault); 1267 begin 1268 FControl := OwnerControl; 1269 FDefault := ADefault; 1270 if ADefault <> nil then 1271 begin 1272 FLeft := ADefault^.Left; 1273 FRight := ADefault^.Right; 1274 FTop := ADefault^.Top; 1275 FBottom := ADefault^.Bottom; 1276 FAround := ADefault^.Around; 1277 end; 1278 inherited Create; 1279 end; 1280 1149 1281 { TDpiEdit } 1150 1282 … … 1824 1956 { TDpiScrollBar } 1825 1957 1826 function TDpiScrollBar.GetBorderSpacing: TControlBorderSpacing;1827 begin1828 Result := NativeScrollBar.BorderSpacing;1829 end;1830 1831 1958 function TDpiScrollBar.GetKind: TScrollBarKind; 1832 1959 begin … … 1857 1984 begin 1858 1985 Result := NativeScrollBar.Position; 1859 end;1860 1861 procedure TDpiScrollBar.SetBorderSpacing(AValue: TControlBorderSpacing);1862 begin1863 NativeScrollBar.BorderSpacing := AValue;1864 1986 end; 1865 1987 … … 1900 2022 end; 1901 2023 2024 constructor TDpiScrollBar.Create(TheOwner: TComponent); 2025 begin 2026 inherited; 2027 end; 2028 1902 2029 destructor TDpiScrollBar.Destroy; 1903 2030 begin 1904 2031 FreeAndNil(NativeScrollBar); 1905 inherited Destroy;2032 inherited; 1906 2033 end; 1907 2034 … … 2921 3048 procedure TDpiScreen.UpdateScreen; 2922 3049 begin 2923 //Dpi := 96 * 2; //Screen.PixelsPerInch;2924 //Dpi := Round(96 * 1.35);2925 //Dpi := 144; //Round(96 * 2);2926 //Dpi := Round(96 * 1.6);2927 3050 Dpi := Screen.PixelsPerInch; 2928 3051 end; … … 3038 3161 end; 3039 3162 3163 procedure TDpiControl.DoBorderSpacingChange(Sender: TObject; 3164 InnerSpaceChanged: Boolean); 3165 begin 3166 GetNativeControl.BorderSpacing.Left := ScaleToNative(FBorderSpacing.Left); 3167 GetNativeControl.BorderSpacing.Right := ScaleToNative(FBorderSpacing.Right); 3168 GetNativeControl.BorderSpacing.Top := ScaleToNative(FBorderSpacing.Top); 3169 GetNativeControl.BorderSpacing.Bottom := ScaleToNative(FBorderSpacing.Bottom); 3170 GetNativeControl.BorderSpacing.Around := ScaleToNative(FBorderSpacing.Around); 3171 end; 3172 3040 3173 procedure TDpiControl.SetText(AValue: TCaption); 3041 3174 begin … … 3146 3279 if Assigned(TheOwner) and (TheOwner is TDpiWinControl) then 3147 3280 Parent := TDpiWinControl(TheOwner); 3281 FBorderSpacing := TDpiControlBorderSpacing.Create(Self); 3148 3282 GetNativeControl; 3149 3283 UpdateNativeControl; … … 3153 3287 destructor TDpiControl.Destroy; 3154 3288 begin 3289 FreeAndNil(FBorderSpacing); 3155 3290 FreeAndNil(FConstraints); 3156 3291 FreeAndNil(FFont); … … 3283 3418 begin 3284 3419 GetNativeControl.Anchors := AValue; 3420 end; 3421 3422 procedure TDpiControl.SetBorderSpacing(AValue: TDpiControlBorderSpacing); 3423 begin 3424 if FBorderSpacing = AValue then Exit; 3425 FBorderSpacing := AValue; 3285 3426 end; 3286 3427
Note:
See TracChangeset
for help on using the changeset viewer.