Changeset 216 for branches/highdpi/Packages/DpiControls/UDpiControls.pas
- Timestamp:
- May 10, 2020, 11:45:09 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/Packages/DpiControls/UDpiControls.pas
r214 r216 208 208 procedure Repaint; 209 209 procedure Update; 210 function IsParentOf(AControl: TDpiControl): boolean; virtual; 210 211 constructor Create(TheOwner: TComponent); override; 211 212 destructor Destroy; override; … … 435 436 private 436 437 FOnActivate: TNotifyEvent; 438 FOnClose: TCloseEvent; 439 FOnCloseQuery: TCloseQueryEvent; 437 440 FOnDeactivate: TNotifyEvent; 438 441 function GetBorderIcons: TBorderIcons; … … 444 447 function GetLCLVersion: string; 445 448 function GetModalResult: TModalResult; 446 function GetOnClose: TCloseEvent;447 449 function GetOnCloseQuery: TCloseQueryEvent; 448 450 function GetOnCreate: TNotifyEvent; … … 460 462 procedure SetLCLVersion(AValue: string); 461 463 procedure SetModalResult(AValue: TModalResult); 462 procedure SetOnClose(AValue: TCloseEvent);463 464 procedure SetOnCloseQuery(AValue: TCloseQueryEvent); 464 465 procedure SetOnCreate(AValue: TNotifyEvent); … … 473 474 procedure ActivateHandler(Sender: TObject); 474 475 procedure DeactivateHandler(Sender: TObject); 476 procedure DoClose(var CloseAction: TCloseAction); virtual; 477 procedure CloseHandler(Sender: TObject; var CloseAction: TCloseAction); 478 procedure CloseQueryHandler(Sender : TObject; var CanClose : boolean); 475 479 protected 476 480 procedure CreateParams(var p: TCreateParams); virtual; … … 485 489 function ShowModal: Integer; virtual; 486 490 procedure Close; 491 function CloseQuery: boolean; virtual; 487 492 procedure BringToFront; 493 procedure Release; 488 494 constructor Create(TheOwner: TComponent); override; 489 495 constructor CreateNew(AOwner: TComponent; Num: Integer = 0); virtual; … … 505 511 property OnActivate: TNotifyEvent read FOnActivate write FOnActivate; 506 512 property OnDeactivate: TNotifyEvent read FOnDeactivate write FOnDeactivate; 507 property OnClose: TCloseEvent read GetOnClose write SetOnClose;508 property OnCloseQuery: TCloseQueryEvent read GetOnCloseQuery write SetOnCloseQuery;513 property OnClose: TCloseEvent read FOnClose write FOnClose; 514 property OnCloseQuery: TCloseQueryEvent read FOnCloseQuery write FOnCloseQuery; 509 515 property ClientHeight; 510 516 property ClientWidth; … … 691 697 // TScreen 692 698 FDpi: Integer; 699 FActiveFormPrev: TDpiForm; 693 700 FActiveForm: TDpiForm; 701 FPrevActiveForms: TDpiForms; 694 702 FForms: TDpiForms; 695 703 procedure AddForm(AForm: TDpiForm); … … 702 710 function GetHeight: Integer; 703 711 function GetWidth: Integer; 704 procedure SetActiveForm(AValue: TDpiForm);705 712 procedure SetCursor(AValue: TCursor); 706 713 procedure SetCursors(Index: Integer; AValue: HCURSOR); … … 711 718 destructor Destroy; override; 712 719 procedure UpdateScreen; 720 procedure UpdateActiveFormFromVclScreen; 713 721 property FormCount: Integer read GetFormCount; 714 722 property Forms[Index: Integer]: TDpiForm read GetForms; 715 property ActiveForm: TDpiForm read GetActiveForm write SetActiveForm;723 property ActiveForm: TDpiForm read GetActiveForm; 716 724 property Cursor: TCursor read GetCursor write SetCursor; 717 725 property Cursors[Index: Integer]: HCURSOR read GetCursors write SetCursors; … … 762 770 public 763 771 constructor Create(AOwner: TComponent); override; 772 destructor Destroy; override; 764 773 procedure Run; 765 774 procedure Initialize; 775 procedure Terminate; 766 776 procedure ProcessMessages; 767 777 procedure UpdateMainForm(AForm: TDpiForm); … … 782 792 procedure SetCursorPos(AValue: TPoint); 783 793 public 794 constructor Create; 784 795 property CursorPos: TPoint read GetCursorPos write SetCursorPos; 785 796 end; … … 900 911 end; 901 912 913 constructor TDpiMouse.Create; 914 begin 915 916 end; 917 902 918 { TDpiSizeConstraints } 903 919 … … 1034 1050 end; 1035 1051 1052 destructor TDpiApplication.Destroy; 1053 begin 1054 inherited Destroy; 1055 end; 1056 1036 1057 procedure TDpiApplication.Run; 1037 1058 begin … … 1044 1065 GetVclApplication.Initialize; 1045 1066 DpiScreen.UpdateScreen; 1067 end; 1068 1069 procedure TDpiApplication.Terminate; 1070 begin 1071 Application.Terminate; 1046 1072 end; 1047 1073 … … 2103 2129 end; 2104 2130 2105 procedure TDpiScreen.SetActiveForm(AValue: TDpiForm);2106 begin2107 FActiveForm := AValue;2108 end;2109 2110 2131 procedure TDpiScreen.SetCursor(AValue: TCursor); 2111 2132 begin … … 2144 2165 begin 2145 2166 FForms.Remove(AForm); 2146 if AForm = FActiveForm then FActiveForm := nil; 2167 if AForm = FActiveForm then begin 2168 FActiveFormPrev := FActiveForm; 2169 FActiveForm := nil; 2170 end; 2147 2171 end; 2148 2172 … … 2174 2198 FForms := TDpiForms.Create; 2175 2199 FForms.FreeObjects := False; 2200 FPrevActiveForms := TDpiForms.Create; 2201 FPrevActiveForms.FreeObjects := False; 2176 2202 // Screen.PixelsPerInch is not initialized at this point 2177 2203 Dpi := 96; … … 2181 2207 begin 2182 2208 FreeAndNil(FForms); 2209 FreeAndNil(FPrevActiveForms); 2183 2210 inherited Destroy; 2184 2211 end; … … 2186 2213 procedure TDpiScreen.UpdateScreen; 2187 2214 begin 2188 Dpi := Screen.PixelsPerInch; 2215 Dpi := 96 * 2; //Screen.PixelsPerInch; 2216 end; 2217 2218 procedure TDpiScreen.UpdateActiveFormFromVclScreen; 2219 var 2220 I: Integer; 2221 F: TDpiForm; 2222 begin 2223 if Screen.ActiveForm = nil then FActiveForm := nil 2224 else begin 2225 for I := 0 to FormCount - 1 do begin 2226 F := Forms[I]; 2227 if F.GetVclForm = Screen.ActiveForm then begin 2228 FActiveForm := F; 2229 Break; 2230 end; 2231 end; 2232 end; 2189 2233 end; 2190 2234 … … 2366 2410 end; 2367 2411 2412 function TDpiControl.IsParentOf(AControl: TDpiControl): boolean; 2413 begin 2414 Result := False; 2415 while Assigned(AControl) do 2416 begin 2417 AControl := AControl.Parent; 2418 if Self = AControl then 2419 Exit(True); 2420 end; 2421 end; 2422 2368 2423 constructor TDpiControl.Create(TheOwner: TComponent); 2369 2424 begin … … 2672 2727 end; 2673 2728 2674 function TDpiForm.GetOnClose: TCloseEvent;2675 begin2676 Result := GetVclForm.OnClose;2677 end;2678 2679 2729 function TDpiForm.GetOnCloseQuery: TCloseQueryEvent; 2680 2730 begin … … 2750 2800 begin 2751 2801 GetVclForm.ModalResult := AValue; 2752 end;2753 2754 procedure TDpiForm.SetOnClose(AValue: TCloseEvent);2755 begin2756 GetVclForm.OnClose := AValue;2757 2802 end; 2758 2803 … … 2810 2855 procedure TDpiForm.ActivateHandler(Sender: TObject); 2811 2856 begin 2812 DpiScreen.ActiveForm := Self; 2857 DpiScreen.FActiveFormPrev := DpiScreen.FActiveForm; 2858 DpiScreen.FActiveForm := Self; 2813 2859 if Assigned(FOnActivate) then FOnActivate(Sender); 2814 2860 end; … … 2816 2862 procedure TDpiForm.DeactivateHandler(Sender: TObject); 2817 2863 begin 2864 DpiScreen.FActiveForm := DpiScreen.FActiveFormPrev; 2865 //DpiScreen.UpdateActiveFormFromVclScreen; 2818 2866 if Assigned(FOnDeactivate) then FOnDeactivate(Sender); 2867 end; 2868 2869 procedure TDpiForm.DoClose(var CloseAction: TCloseAction); 2870 begin 2871 if Assigned(FOnClose) then FOnClose(Self, CloseAction); 2872 end; 2873 2874 procedure TDpiForm.CloseHandler(Sender: TObject; var CloseAction: TCloseAction); 2875 begin 2876 DoClose(CloseAction); 2877 end; 2878 2879 procedure TDpiForm.CloseQueryHandler(Sender : TObject; var CanClose : boolean); 2880 begin 2881 if Assigned(FOnCloseQuery) then FOnCloseQuery(Self, CanClose); 2819 2882 end; 2820 2883 … … 2860 2923 GetVclForm.OnActivate := @ActivateHandler; 2861 2924 GetVclForm.OnDeactivate := @DeactivateHandler; 2925 GetVclForm.OnClose := @CloseHandler; 2926 GetVclForm.OnCloseQuery := @CloseQueryHandler; 2927 GetVclForm.Name := Name + 'Vcl'; 2862 2928 end; 2863 2929 … … 2874 2940 2875 2941 procedure TDpiForm.Close; 2876 begin 2877 GetVclForm.Close; 2942 var 2943 CloseAction: TCloseAction; 2944 IsMainForm: Boolean; 2945 begin 2946 if fsModal in FormState then 2947 ModalResult := mrCancel 2948 else 2949 begin 2950 if CloseQuery then 2951 begin 2952 // IsMainForm flag set if we are closing MainForm or its parent 2953 IsMainForm := (DpiApplication.MainForm = Self) or (Self.IsParentOf(DpiApplication.MainForm)); 2954 // Prepare default close action 2955 if FormStyle = fsMDIChild then 2956 begin 2957 CloseAction := caNone; 2958 // TODO: mdi logic 2959 end 2960 else 2961 begin 2962 if IsMainForm then 2963 CloseAction := caFree 2964 else 2965 CloseAction := caHide; 2966 end; 2967 // call event handler and let user modify CloseAction 2968 DoClose(CloseAction); 2969 // execute action according to close action 2970 case CloseAction of 2971 caHide: Hide; 2972 caMinimize: WindowState := wsMinimized; 2973 caFree: 2974 begin 2975 // if form is MainForm, then terminate the application 2976 // the owner of the MainForm is the application, 2977 // so the Application will take care of free-ing the form 2978 // and Release is not necessary 2979 if IsMainForm then 2980 DpiApplication.Terminate 2981 else 2982 Release; 2983 end; 2984 end; 2985 end; 2986 end; 2987 end; 2988 2989 function TDpiForm.CloseQuery: boolean; 2990 begin 2991 Result := True; 2992 if Assigned(FOnCloseQuery) then 2993 FOnCloseQuery(Self, Result); 2878 2994 end; 2879 2995 … … 2881 2997 begin 2882 2998 GetVclForm.BringToFront; 2999 end; 3000 3001 procedure TDpiForm.Release; 3002 begin 3003 Free; 2883 3004 end; 2884 3005 … … 2911 3032 destructor TDpiForm.Destroy; 2912 3033 begin 2913 FreeAndNil(VclForm); 3034 // TODO: Can't destroy directly? 3035 //FreeAndNil(VclForm); 2914 3036 DpiScreen.RemoveForm(Self); 2915 3037 end; … … 2923 3045 DpiScreen := TDpiScreen.Create; 2924 3046 DpiApplication := TDpiApplication.Create(nil); 3047 DpiMouse := TDpiMouse.Create; 2925 3048 RegisterClasses([TDpiButton, TDpiImage, TDpiPaintBox, TDpiListBox]); 2926 3049 … … 2929 3052 FreeAndNil(DpiApplication); 2930 3053 FreeAndNil(DpiScreen); 3054 FreeAndNil(DpiMouse); 2931 3055 2932 3056 end.
Note:
See TracChangeset
for help on using the changeset viewer.