Changeset 212 for branches/highdpi/Packages/DpiControls/UDpiControls.pas
- Timestamp:
- May 9, 2020, 9:35:25 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/highdpi/Packages/DpiControls/UDpiControls.pas
r210 r212 38 38 property OnMouseUp; 39 39 property OnMouseMove; 40 property OnMouseWheel; 41 property OnMouseLeave; 42 property OnMouseEnter; 40 43 end; 41 44 … … 122 125 FLeft: Integer; 123 126 FOnChangeBounds: TNotifyEvent; 127 FOnMouseUp: TMouseEvent; 124 128 FOnMouseDown: TMouseEvent; 125 129 FOnMouseMove: TMouseMoveEvent; 126 FOnMouseUp: TMouseEvent; 130 FOnMouseEnter: TNotifyEvent; 131 FOnMouseLeave: TNotifyEvent; 127 132 FOnMouseWheel: TMouseWheelEvent; 128 133 FOnResize: TNotifyEvent; … … 161 166 procedure DoFormResize; 162 167 procedure DoChangeBounds; 168 procedure MouseDownHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState; 169 X, Y: Integer); virtual; 170 procedure MouseUpHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState; 171 X, Y: Integer); virtual; 172 procedure MouseMoveHandler(Sender: TObject; Shift: TShiftState; X, Y: Integer); virtual; 173 procedure MouseWheelHandler(Sender: TObject; Shift: TShiftState; 174 WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); virtual; 175 procedure MouseLeaveHandler(Sender: TObject); virtual; 176 procedure MouseEnterHandler(Sender: TObject); virtual; 163 177 protected 164 178 procedure UpdateBounds; virtual; … … 174 188 function GetVclControl: TControl; virtual; 175 189 procedure UpdateVclControl; virtual; 176 procedure MouseDownHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState;177 X, Y: Integer); virtual;178 procedure MouseUpHandler(Sender: TObject; Button: TMouseButton; Shift: TShiftState;179 X, Y: Integer); virtual;180 procedure MouseMoveHandler(Sender: TObject; Shift: TShiftState; X, Y: Integer); virtual;181 procedure MouseWheelHandler(Sender: TObject; Shift: TShiftState;182 WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean); virtual;183 190 procedure MouseDown(Button: TMouseButton; Shift: TShiftState; 184 191 X, Y: Integer); virtual; … … 187 194 procedure MouseMove(Shift: TShiftState; X, Y: Integer); virtual; 188 195 procedure MouseLeave; virtual; 196 procedure MouseEnter; virtual; 189 197 public 190 198 function ScreenToClient(const APoint: TPoint): TPoint; virtual; … … 333 341 function GetVclGraphicControl: TGraphicControl; virtual; 334 342 procedure UpdateVclControl; override; 335 procedure UpdateVclControlPrivate; virtual;336 343 property OnPaint: TNotifyEvent read GetOnPaint write SetOnPaint; 337 344 public … … 668 675 669 676 TDpiPaintBox = class(TDpiGraphicControl) 670 private671 procedure UpdateVclControlPrivate; override;672 677 public 673 678 VclPaintBox: TPaintBox; … … 689 694 FForms: TDpiForms; 690 695 procedure AddForm(AForm: TDpiForm); 696 procedure RemoveForm(AForm: TDpiForm); 691 697 function GetActiveForm: TDpiForm; 692 698 function GetCursor: TCursor; … … 767 773 end; 768 774 775 { TDpiMouse } 776 777 // TMouse 778 TDpiMouse = class 779 private 780 function GetCursorPos: TPoint; 781 procedure SetCursorPos(AValue: TPoint); 782 public 783 property CursorPos: TPoint read GetCursorPos write SetCursorPos; 784 end; 785 769 786 var 770 787 DpiFormFileDesc: TDpiFormFileDesc; 771 788 DpiScreen: TDpiScreen; 772 789 DpiApplication: TDpiApplication; 790 DpiMouse: TDpiMouse; 773 791 774 792 procedure Register; … … 869 887 end; 870 888 889 { TDpiMouse } 890 891 function TDpiMouse.GetCursorPos: TPoint; 892 begin 893 Result := ScalePointFromVcl(Mouse.CursorPos); 894 end; 895 896 procedure TDpiMouse.SetCursorPos(AValue: TPoint); 897 begin 898 Mouse.CursorPos := ScalePointToVcl(AValue); 899 end; 900 871 901 { TDpiSizeConstraints } 872 902 … … 1549 1579 { TDpiPaintBox } 1550 1580 1551 procedure TDpiPaintBox.UpdateVclControlPrivate;1552 begin1553 VclPaintBox.OnPaint := @PaintHandler;1554 VclPaintBox.OnMouseDown := @MouseDownHandler;1555 VclPaintBox.OnMouseUp := @MouseUpHandler;1556 VclPaintBox.OnMouseMove := @MouseMoveHandler;1557 end;1558 1559 1581 function TDpiPaintBox.GetVclGraphicControl: TGraphicControl; 1560 1582 begin … … 1796 1818 begin 1797 1819 inherited; 1798 UpdateVclControlPrivate;1799 end;1800 1801 procedure TDpiGraphicControl.UpdateVclControlPrivate;1802 begin1803 1820 TGraphicControlEx(GetVclGraphicControl).OnPaint := @PaintHandler; 1804 TControlEx(GetVclControl).OnMouseDown := @MouseDownHandler;1805 TControlEx(GetVclControl).OnMouseUp := @MouseUpHandler;1806 TControlEx(GetVclControl).OnMouseMove := @MouseMoveHandler;1807 // Some VCL component event are not accessible on TGraphicControl level.1808 // Delegate this responsibility up1809 {1810 GetVclGraphicControl.OnPaint := @PaintHandler;1811 GetVclControl.OnMouseDown := @MouseDownHandler;1812 GetVclControl.OnMouseUp := @MouseUpHandler;1813 GetVclControl.OnMouseMove := @MouseMoveHandler;1814 }1815 // raise Exception.Create('Missing inicialization of private fields for ' + ClassName);1816 1821 end; 1817 1822 … … 2134 2139 end; 2135 2140 2141 procedure TDpiScreen.RemoveForm(AForm: TDpiForm); 2142 begin 2143 FForms.Remove(AForm); 2144 if AForm = FActiveForm then FActiveForm := nil; 2145 end; 2146 2136 2147 function TDpiScreen.GetActiveForm: TDpiForm; 2137 2148 begin … … 2161 2172 FForms := TDpiForms.Create; 2162 2173 FForms.FreeObjects := False; 2163 Dpi := 150;2174 Dpi := Round(96 * 2); //Screen.PixelsPerInch; 2164 2175 end; 2165 2176 … … 2214 2225 GetVclControl.OnResize := @VclFormResize; 2215 2226 GetVclControl.OnChangeBounds := @VclChangeBounds; 2227 TControlEx(GetVclControl).OnMouseDown := @MouseDownHandler; 2228 TControlEx(GetVclControl).OnMouseUp := @MouseUpHandler; 2229 TControlEx(GetVclControl).OnMouseMove := @MouseMoveHandler; 2230 TControlEx(GetVclControl).OnMouseEnter := @MouseEnterHandler; 2231 TControlEx(GetVclControl).OnMouseLeave := @MouseLeaveHandler; 2232 TControlEx(GetVclControl).OnMouseWheel := @MouseWheelHandler; 2216 2233 end; 2217 2234 … … 2244 2261 end; 2245 2262 2263 procedure TDpiControl.MouseLeaveHandler(Sender: TObject); 2264 begin 2265 MouseLeave; 2266 if Assigned(FOnMouseLeave) then FOnMouseLeave(Self); 2267 end; 2268 2269 procedure TDpiControl.MouseEnterHandler(Sender: TObject); 2270 begin 2271 MouseEnter; 2272 if Assigned(FOnMouseEnter) then FOnMouseEnter(Self); 2273 end; 2274 2246 2275 procedure TDpiControl.MouseDown(Button: TMouseButton; Shift: TShiftState; X, 2247 2276 Y: Integer); … … 2260 2289 procedure TDpiControl.MouseLeave; 2261 2290 begin 2262 2291 end; 2292 2293 procedure TDpiControl.MouseEnter; 2294 begin 2263 2295 end; 2264 2296 … … 2817 2849 begin 2818 2850 inherited; 2819 GetVclForm.OnMouseDown := @MouseDownHandler;2820 GetVclForm.OnMouseUp := @MouseUpHandler;2821 GetVclForm.OnMouseMove := @MouseMoveHandler;2822 2851 GetVclForm.OnActivate := @ActivateHandler; 2823 2852 GetVclForm.OnDeactivate := @DeactivateHandler; … … 2847 2876 // Init the component with an IDE resource 2848 2877 constructor TDpiForm.Create(TheOwner: TComponent); 2849 var2850 C: TComponent;2851 2878 begin 2852 2879 //inherited; … … 2855 2882 try 2856 2883 CreateNew(TheOwner, 1); // this calls BeginFormUpdate, which is ended in AfterConstruction 2857 // Self2858 C := FindGlobalComponent('TListDlg');2859 2884 if (ClassType <> TDpiForm) and not (csDesigning in ComponentState) then begin 2860 2885 if not InitResourceComponent(Self, TDataModule) then begin … … 2878 2903 begin 2879 2904 FreeAndNil(VclForm); 2905 DpiScreen.RemoveForm(Self); 2880 2906 end; 2881 2907
Note:
See TracChangeset
for help on using the changeset viewer.