Changeset 210 for branches/highdpi/Packages/DpiControls/UDpiControls.pas
- Timestamp:
- May 9, 2020, 4:02:07 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/Packages/DpiControls/UDpiControls.pas
r193 r210 131 131 FParent: TDpiWinControl; 132 132 function GetAlign: TAlign; 133 function GetAnchors: TAnchors; 133 134 function GetBoundsRect: TRect; 134 135 function GetClientHeight: Integer; … … 141 142 function GetShowHint: Boolean; 142 143 function GetVisible: Boolean; 144 function IsAnchorsStored: Boolean; 143 145 procedure SetAlign(AValue: TAlign); 146 procedure SetAnchors(AValue: TAnchors); 144 147 procedure SetBoundsRect(AValue: TRect); 145 148 procedure SetClientHeight(AValue: Integer); … … 183 186 X, Y: Integer); virtual; 184 187 procedure MouseMove(Shift: TShiftState; X, Y: Integer); virtual; 188 procedure MouseLeave; virtual; 185 189 public 190 function ScreenToClient(const APoint: TPoint): TPoint; virtual; 191 function ClientToScreen(const APoint: TPoint): TPoint; virtual; 192 procedure AddHandlerOnVisibleChanged(const OnVisibleChangedEvent: TNotifyEvent; 193 AsFirst: boolean = false); 194 procedure RemoveHandlerOnVisibleChanged(const OnVisibleChangedEvent: TNotifyEvent); 186 195 procedure ScreenChanged; virtual; 187 196 procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); virtual; … … 196 205 property BoundsRect: TRect read GetBoundsRect write SetBoundsRect; 197 206 property Visible: Boolean read GetVisible write SetVisible; 207 property Anchors: TAnchors read GetAnchors write SetAnchors stored IsAnchorsStored default [akLeft, akTop]; 198 208 published 199 209 property ClientHeight: Integer read GetClientHeight write SetClientHeight; … … 237 247 function GetDpi: Integer; virtual; 238 248 public 239 constructor Create; 249 VclGraphicClass: TGraphicClass; 250 constructor Create; virtual; 240 251 procedure LoadFromFile(const Filename: string); virtual; 252 procedure SaveToFile(const Filename: string); virtual; 241 253 property Width: Integer read GetWidth write SetWidth; 242 254 property Height: Integer read GetHeight write SetHeight; … … 261 273 private 262 274 FFont: TDpiFont; 275 FVclCanvas: TCanvas; 263 276 function GetBrush: TBrush; 264 277 function GetHandle: HDC; … … 272 285 procedure SetPen(AValue: TPen); 273 286 procedure SetPixel(X, Y: Integer; AValue: TColor); 287 procedure SetVclCanvas(AValue: TCanvas); 274 288 protected 275 289 function GetVclCanvas: TCanvas; virtual; 276 290 public 277 VclCanvas: TCanvas;291 property VclCanvas: TCanvas read FVclCanvas write SetVclCanvas; 278 292 procedure StretchDraw(const DestRect: TRect; SrcGraphic: TDpiGraphic); virtual; 279 293 procedure FrameRect(Rect: TRect); … … 458 472 function GetVclForm: TForm; virtual; 459 473 procedure UpdateVclControl; override; 474 procedure AfterConstruction; override; 460 475 public 461 476 VclForm: TForm; … … 465 480 procedure BringToFront; 466 481 constructor Create(TheOwner: TComponent); override; 482 constructor CreateNew(AOwner: TComponent; Num: Integer = 0); virtual; 467 483 destructor Destroy; override; 468 484 published … … 547 563 property BorderStyle: TBorderStyle read GetBorderStyle write SetBorderStyle default bsNone; 548 564 property Visible; 565 property Anchors; 549 566 end; 550 567 … … 607 624 procedure EndUpdate; 608 625 procedure SetSize(AWidth, AHeight: Integer); 609 constructor Create; 626 constructor Create; override; 610 627 destructor Destroy; override; 611 628 procedure Assign(Source: TPersistent); override; … … 667 684 TDpiScreen = class 668 685 private 686 // TScreen 669 687 FDpi: Integer; 670 688 FActiveForm: TDpiForm; 689 FForms: TDpiForms; 690 procedure AddForm(AForm: TDpiForm); 671 691 function GetActiveForm: TDpiForm; 692 function GetCursor: TCursor; 693 function GetCursors(Index: Integer): HCURSOR; 672 694 function GetFormCount: Integer; 695 function GetForms(Index: Integer): TDpiForm; 673 696 function GetHeight: Integer; 674 697 function GetWidth: Integer; 675 698 procedure SetActiveForm(AValue: TDpiForm); 699 procedure SetCursor(AValue: TCursor); 700 procedure SetCursors(Index: Integer; AValue: HCURSOR); 676 701 procedure SetDpi(AValue: Integer); 677 702 procedure UpdateForms; 678 703 public 679 Forms: TDpiForms;680 704 constructor Create; 681 705 destructor Destroy; override; 682 706 property FormCount: Integer read GetFormCount; 707 property Forms[Index: Integer]: TDpiForm read GetForms; 683 708 property ActiveForm: TDpiForm read GetActiveForm write SetActiveForm; 709 property Cursor: TCursor read GetCursor write SetCursor; 710 property Cursors[Index: Integer]: HCURSOR read GetCursors write SetCursors; 684 711 published 685 712 property Dpi: Integer read FDpi write SetDpi; 713 property PixelsPerInch: Integer read FDpi; 686 714 property Width: Integer read GetWidth; 687 715 property Height: Integer read GetHeight; … … 696 724 public 697 725 VclJpeg: TJPEGImage; 698 procedure LoadFromFile(const Filename: string); override;726 constructor Create; override; 699 727 end; 700 728 … … 707 735 public 708 736 VclPng: TPortableNetworkGraphic; 709 procedure LoadFromFile(const Filename: string); override;737 constructor Create; override; 710 738 end; 711 739 … … 716 744 FMainForm: TDpiForm; 717 745 FCreatingForm: TDpiForm; 746 function GetActive: Boolean; 718 747 function GetShowMainForm: Boolean; 719 748 function GetTitle: string; … … 725 754 function GetVclApplication: TApplication; virtual; 726 755 public 756 constructor Create(AOwner: TComponent); override; 727 757 procedure Run; 728 758 procedure Initialize; … … 730 760 procedure UpdateMainForm(AForm: TDpiForm); 731 761 procedure CreateForm(InstanceClass: TComponentClass; out Reference); 762 function MessageBox(Text, Caption: PChar; Flags: Longint = MB_OK): Integer; 732 763 property MainForm: TDpiForm read GetMainForm write SetMainForm; 733 764 property ShowMainForm: Boolean read GetShowMainForm write SetShowMainForm default True; 734 765 property Title: string read GetTitle write SetTitle; 766 property Active: Boolean read GetActive; 735 767 end; 736 768 … … 934 966 end; 935 967 968 function TDpiApplication.GetActive: Boolean; 969 begin 970 Result := Application.Active; 971 end; 972 936 973 function TDpiApplication.GetMainForm: TDpiForm; 937 974 begin … … 952 989 begin 953 990 Result := Application; 991 end; 992 993 function DpiFindApplicationComponent(const ComponentName: string): TComponent; 994 // Note: this function is used by TReader to auto rename forms to unique names. 995 begin 996 Result := DpiApplication.FindComponent(ComponentName); 997 end; 998 999 constructor TDpiApplication.Create(AOwner: TComponent); 1000 begin 1001 RegisterFindGlobalComponentProc(@DpiFindApplicationComponent); 1002 inherited; 954 1003 end; 955 1004 … … 1021 1070 end; 1022 1071 1072 function TDpiApplication.MessageBox(Text, Caption: PChar; Flags: Longint 1073 ): Integer; 1074 begin 1075 Result := Application.MessageBox(Text, Caption, Flags); 1076 end; 1077 1023 1078 { TDpiJpegImage } 1024 1079 … … 1034 1089 end; 1035 1090 1036 procedure TDpiJpegImage.LoadFromFile(const Filename: string); 1037 var 1038 Bitmap: TJPEGImage; 1039 begin 1040 Bitmap := TJPEGImage.Create; 1041 Bitmap.LoadFromFile(FileName); 1042 Width := ScaleFromVcl(Bitmap.Width); 1043 Height := ScaleFromVcl(Bitmap.Height); 1044 if Self is TDpiBitmap then 1045 TBitmap(GetVclGraphic).Canvas.StretchDraw(Bounds(0, 0, Bitmap.Width, Bitmap.Height), Bitmap) 1046 else raise Exception.Create('Unsupported class ' + Self.ClassName); 1047 Bitmap.Free; 1091 constructor TDpiJpegImage.Create; 1092 begin 1093 inherited; 1094 VclGraphicClass := TJPEGImage; 1048 1095 end; 1049 1096 … … 1061 1108 end; 1062 1109 1063 procedure TDpiPortableNetworkGraphic.LoadFromFile(const Filename: string); 1064 var 1065 Bitmap: TPortableNetworkGraphic; 1066 begin 1067 Bitmap := TPortableNetworkGraphic.Create; 1068 Bitmap.LoadFromFile(FileName); 1069 Width := ScaleFromVcl(Bitmap.Width); 1070 Height := ScaleFromVcl(Bitmap.Height); 1071 if Self is TDpiBitmap then 1072 TBitmap(GetVclGraphic).Canvas.StretchDraw(Bounds(0, 0, Bitmap.Width, Bitmap.Height), Bitmap) 1073 else raise Exception.Create('Unsupported class ' + Self.ClassName); 1074 Bitmap.Free; 1110 constructor TDpiPortableNetworkGraphic.Create; 1111 begin 1112 inherited; 1113 VclGraphicClass := TPortableNetworkGraphic; 1075 1114 end; 1076 1115 … … 1246 1285 procedure TDpiGraphic.LoadFromFile(const Filename: string); 1247 1286 var 1248 Bitmap: T Bitmap;1249 begin 1250 Bitmap := TBitmap.Create;1287 Bitmap: TGraphic; 1288 begin 1289 Bitmap := VclGraphicClass.Create; 1251 1290 Bitmap.LoadFromFile(FileName); 1252 Width := ScaleFromVcl(Bitmap.Width);1253 Height := ScaleFromVcl(Bitmap.Height);1291 Width := Bitmap.Width; 1292 Height := Bitmap.Height; 1254 1293 if Self is TDpiBitmap then 1255 TBitmap(GetVclGraphic).Canvas.StretchDraw(Bounds(0, 0, Bitmap.Width, Bitmap.Height), Bitmap) 1294 TBitmap(GetVclGraphic).Canvas.StretchDraw(Bounds(0, 0, 1295 TBitmap(GetVclGraphic).Width, TBitmap(GetVclGraphic).Height), Bitmap) 1256 1296 else raise Exception.Create('Unsupported class ' + Self.ClassName); 1297 Bitmap.Free; 1298 end; 1299 1300 procedure TDpiGraphic.SaveToFile(const Filename: string); 1301 var 1302 Bitmap: TGraphic; 1303 begin 1304 Bitmap := VclGraphicClass.Create; 1305 Bitmap.Width := Width; 1306 Bitmap.Height := Height; 1307 if Self is TDpiBitmap then begin 1308 if Bitmap is TRasterImage then 1309 (Bitmap as TRasterImage).Canvas.StretchDraw(Bounds(0, 0, Bitmap.Width, Bitmap.Height), TBitmap(GetVclGraphic)) 1310 else raise Exception.Create('Expected TRasterImage but got ' + Bitmap.ClassName); 1311 end else raise Exception.Create('Unsupported class ' + Self.ClassName); 1312 Bitmap.SaveToFile(FileName); 1257 1313 Bitmap.Free; 1258 1314 end; … … 1355 1411 begin 1356 1412 inherited; 1413 VclGraphicClass := TBitmap; 1357 1414 end; 1358 1415 … … 1601 1658 } 1602 1659 GetVclCanvas.Pixels[ScaleToVcl(X), ScaleToVcl(Y)] := AValue; 1660 end; 1661 1662 procedure TDpiCanvas.SetVclCanvas(AValue: TCanvas); 1663 begin 1664 if FVclCanvas = AValue then Exit; 1665 FVclCanvas := AValue; 1666 FFont.VclFont := FVclCanvas.Font; 1603 1667 end; 1604 1668 … … 1809 1873 if FSize = AValue then Exit; 1810 1874 FSize := AValue; 1875 GetVclFont.Size := AValue; 1811 1876 DoChange; 1812 1877 end; … … 2036 2101 end; 2037 2102 2103 procedure TDpiScreen.SetCursor(AValue: TCursor); 2104 begin 2105 Screen.Cursor := AValue; 2106 end; 2107 2108 procedure TDpiScreen.SetCursors(Index: Integer; AValue: HCURSOR); 2109 begin 2110 Screen.Cursors[Index] := AValue; 2111 end; 2112 2038 2113 function TDpiScreen.GetHeight: Integer; 2039 2114 begin … … 2043 2118 function TDpiScreen.GetFormCount: Integer; 2044 2119 begin 2045 Result := Forms.Count; 2120 Result := FForms.Count; 2121 end; 2122 2123 function TDpiScreen.GetForms(Index: Integer): TDpiForm; 2124 begin 2125 Result := FForms[Index]; 2126 end; 2127 2128 procedure TDpiScreen.AddForm(AForm: TDpiForm); 2129 begin 2130 if AForm is TDpiForm then begin 2131 FForms.Add(AForm); 2132 //DpiApplication.UpdateVisible; 2133 end; 2046 2134 end; 2047 2135 … … 2049 2137 begin 2050 2138 Result := FActiveForm; 2139 end; 2140 2141 function TDpiScreen.GetCursor: TCursor; 2142 begin 2143 Result := Screen.Cursor; 2144 end; 2145 2146 function TDpiScreen.GetCursors(Index: Integer): HCURSOR; 2147 begin 2148 Result := Screen.Cursors[Index]; 2051 2149 end; 2052 2150 … … 2055 2153 I: Integer; 2056 2154 begin 2057 for I := 0 to F orms.Count - 1 do2058 F orms[I].ScreenChanged;2155 for I := 0 to FForms.Count - 1 do 2156 FForms[I].ScreenChanged; 2059 2157 end; 2060 2158 2061 2159 constructor TDpiScreen.Create; 2062 2160 begin 2063 F orms := TDpiForms.Create;2064 F orms.FreeObjects := False;2161 FForms := TDpiForms.Create; 2162 FForms.FreeObjects := False; 2065 2163 Dpi := 150; 2066 2164 end; … … 2068 2166 destructor TDpiScreen.Destroy; 2069 2167 begin 2070 FreeAndNil(F orms);2168 FreeAndNil(FForms); 2071 2169 inherited Destroy; 2072 2170 end; … … 2158 2256 procedure TDpiControl.MouseMove(Shift: TShiftState; X, Y: Integer); 2159 2257 begin 2258 end; 2259 2260 procedure TDpiControl.MouseLeave; 2261 begin 2262 2263 end; 2264 2265 function TDpiControl.ScreenToClient(const APoint: TPoint): TPoint; 2266 begin 2267 Result := ScalePointFromVcl(GetVclControl.ScreenToClient(ScalePointToVcl(APoint))); 2268 end; 2269 2270 function TDpiControl.ClientToScreen(const APoint: TPoint): TPoint; 2271 begin 2272 Result := ScalePointFromVcl(GetVclControl.ClientToScreen(ScalePointToVcl(APoint))); 2273 end; 2274 2275 procedure TDpiControl.AddHandlerOnVisibleChanged( 2276 const OnVisibleChangedEvent: TNotifyEvent; AsFirst: boolean); 2277 begin 2278 GetVclControl.AddHandlerOnVisibleChanged(OnVisibleChangedEvent, AsFirst); 2279 end; 2280 2281 procedure TDpiControl.RemoveHandlerOnVisibleChanged( 2282 const OnVisibleChangedEvent: TNotifyEvent); 2283 begin 2284 GetVclControl.RemoveHandlerOnVisibleChanged(OnVisibleChangedEvent); 2160 2285 end; 2161 2286 … … 2272 2397 end; 2273 2398 2399 function TDpiControl.GetAnchors: TAnchors; 2400 begin 2401 Result := GetVclControl.Anchors; 2402 end; 2403 2274 2404 function TDpiControl.GetClientHeight: Integer; 2275 2405 begin … … 2317 2447 end; 2318 2448 2449 function TDpiControl.IsAnchorsStored: Boolean; 2450 begin 2451 2452 end; 2453 2319 2454 procedure TDpiControl.SetAlign(AValue: TAlign); 2320 2455 begin 2321 2456 GetVclControl.Align := AValue; 2457 end; 2458 2459 procedure TDpiControl.SetAnchors(AValue: TAnchors); 2460 begin 2461 GetVclControl.Anchors := AValue; 2322 2462 end; 2323 2463 … … 2684 2824 end; 2685 2825 2826 procedure TDpiForm.AfterConstruction; 2827 begin 2828 inherited; 2829 DoOnCreate; 2830 end; 2831 2686 2832 function TDpiForm.ShowModal: Integer; 2687 2833 begin … … 2701 2847 // Init the component with an IDE resource 2702 2848 constructor TDpiForm.Create(TheOwner: TComponent); 2703 begin 2704 inherited; 2849 var 2850 C: TComponent; 2851 begin 2852 //inherited; 2705 2853 //DebugLn(['TDpiForm.Create ', DbgSName(TheOwner)]); 2706 2854 GlobalNameSpace.BeginWrite; 2707 2855 try 2856 CreateNew(TheOwner, 1); // this calls BeginFormUpdate, which is ended in AfterConstruction 2857 // Self 2858 C := FindGlobalComponent('TListDlg'); 2708 2859 if (ClassType <> TDpiForm) and not (csDesigning in ComponentState) then begin 2709 2860 if not InitResourceComponent(Self, TDataModule) then begin … … 2716 2867 ScreenChanged; 2717 2868 UpdateVclControl; 2718 DoOnCreate; 2869 end; 2870 2871 constructor TDpiForm.CreateNew(AOwner: TComponent; Num: Integer); 2872 begin 2873 inherited Create(AOwner); 2874 DpiScreen.AddForm(Self); 2719 2875 end; 2720 2876
Note:
See TracChangeset
for help on using the changeset viewer.