2019-04-04 10:26:44 +02:00
|
|
|
unit uCEFBufferPanel;
|
2017-11-16 12:49:15 +01:00
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
{$I cef.inc}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF DELPHI16_UP}
|
2020-03-31 12:44:10 +02:00
|
|
|
{$IFDEF MSWINDOWS}Winapi.Windows, Winapi.Messages, Vcl.ExtCtrls, Vcl.Controls, Vcl.Graphics, WinApi.Imm, {$ENDIF}
|
|
|
|
System.Classes, System.SyncObjs, System.SysUtils, Vcl.Forms,
|
2017-11-16 12:49:15 +01:00
|
|
|
{$ELSE}
|
2019-01-08 19:15:25 +01:00
|
|
|
{$IFDEF MSWINDOWS}Windows, imm, {$ENDIF} Classes, Forms, Controls, Graphics,
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
2019-05-04 09:53:50 +02:00
|
|
|
LCLProc, LCLType, LCLIntf, LResources, LMessages, InterfaceBase, {$IFDEF MSWINDOWS}Win32Extra,{$ENDIF}
|
2018-05-12 14:50:54 +02:00
|
|
|
{$ELSE}
|
|
|
|
Messages,
|
|
|
|
{$ENDIF}
|
2018-06-17 14:18:11 +02:00
|
|
|
ExtCtrls, SyncObjs, SysUtils,
|
2017-11-16 12:49:15 +01:00
|
|
|
{$ENDIF}
|
2020-12-28 18:11:27 +01:00
|
|
|
{$IFDEF MSWINDOWS}uCEFOSRIMEHandler,{$ENDIF} uCEFConstants, uCEFTypes, uCEFBitmapBitBuffer;
|
2017-11-16 12:49:15 +01:00
|
|
|
|
|
|
|
type
|
2019-01-08 19:15:25 +01:00
|
|
|
TOnIMECommitTextEvent = procedure(Sender: TObject; const aText : ustring; const replacement_range : PCefRange; relative_cursor_pos : integer) of object;
|
|
|
|
TOnIMESetCompositionEvent = procedure(Sender: TObject; const aText : ustring; const underlines : TCefCompositionUnderlineDynArray; const replacement_range, selection_range : TCefRange) of object;
|
2020-02-04 11:50:38 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2020-02-03 12:02:30 +01:00
|
|
|
TOnHandledMessageEvent = procedure(Sender: TObject; var aMessage: TMessage; var aHandled : boolean) of object;
|
2020-02-04 11:50:38 +01:00
|
|
|
{$ENDIF}
|
2019-01-08 19:15:25 +01:00
|
|
|
|
2022-10-14 16:35:50 +02:00
|
|
|
{$IFNDEF FPC}{$IFDEF DELPHI16_UP}[ComponentPlatformsAttribute(pfidWindows)]{$ENDIF}{$ENDIF}
|
2023-08-08 20:19:19 +02:00
|
|
|
/// <summary>
|
|
|
|
/// TBufferPanel is used by VCL and LCL applications with browsers in OSR mode
|
|
|
|
/// to draw the browser contents. See the SimpleOSRBrowser demo for more details.
|
|
|
|
/// </summary>
|
2017-11-16 12:49:15 +01:00
|
|
|
TBufferPanel = class(TCustomPanel)
|
|
|
|
protected
|
2020-12-20 12:28:56 +01:00
|
|
|
FScanlineSize : integer;
|
|
|
|
FTransparent : boolean;
|
|
|
|
FOnPaintParentBkg : TNotifyEvent;
|
|
|
|
FForcedDeviceScaleFactor : single;
|
2021-02-16 12:47:22 +01:00
|
|
|
FDeviceScaleFactor : single;
|
2021-01-12 17:06:31 +01:00
|
|
|
FCopyOriginalBuffer : boolean;
|
|
|
|
FMustInitBuffer : boolean;
|
2020-12-28 18:11:27 +01:00
|
|
|
FBuffer : TBitmap;
|
2021-01-12 17:06:31 +01:00
|
|
|
FOrigBuffer : TCEFBitmapBitBuffer;
|
|
|
|
FOrigPopupBuffer : TCEFBitmapBitBuffer;
|
|
|
|
FOrigPopupScanlineSize : integer;
|
|
|
|
{$IFDEF MSWINDOWS}
|
2020-12-28 18:11:27 +01:00
|
|
|
FSyncObj : THandle;
|
2020-12-20 12:28:56 +01:00
|
|
|
FIMEHandler : TCEFOSRIMEHandler;
|
|
|
|
FOnIMECancelComposition : TNotifyEvent;
|
|
|
|
FOnIMECommitText : TOnIMECommitTextEvent;
|
|
|
|
FOnIMESetComposition : TOnIMESetCompositionEvent;
|
|
|
|
FOnCustomTouch : TOnHandledMessageEvent;
|
|
|
|
FOnPointerDown : TOnHandledMessageEvent;
|
|
|
|
FOnPointerUp : TOnHandledMessageEvent;
|
|
|
|
FOnPointerUpdate : TOnHandledMessageEvent;
|
2020-12-28 18:11:27 +01:00
|
|
|
{$ELSE}
|
|
|
|
FSyncObj : TCriticalSection;
|
2019-01-08 19:15:25 +01:00
|
|
|
{$ENDIF}
|
2017-11-16 12:49:15 +01:00
|
|
|
|
2018-01-25 21:34:04 +01:00
|
|
|
procedure CreateSyncObj;
|
2017-12-27 14:05:33 +01:00
|
|
|
|
2018-01-25 21:34:04 +01:00
|
|
|
procedure DestroySyncObj;
|
2017-12-27 14:05:33 +01:00
|
|
|
procedure DestroyBuffer;
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
function GetBufferBits : pointer;
|
|
|
|
function GetBufferWidth : integer;
|
2021-01-12 17:06:31 +01:00
|
|
|
function GetBufferHeight : integer;
|
|
|
|
function GetOrigBufferWidth : integer;
|
|
|
|
function GetOrigBufferHeight : integer;
|
2020-12-13 18:36:10 +01:00
|
|
|
function GetScreenScale : single; virtual;
|
2020-12-20 12:28:56 +01:00
|
|
|
function GetRealScreenScale(var aResultScale : single) : boolean; virtual;
|
2021-01-12 17:06:31 +01:00
|
|
|
function GetOrigPopupBufferBits : pointer;
|
|
|
|
function GetOrigPopupBufferWidth : integer;
|
|
|
|
function GetOrigPopupBufferHeight : integer;
|
2020-03-31 12:44:10 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
function GetParentFormHandle : TCefWindowHandle;
|
|
|
|
function GetParentForm : TCustomForm;
|
|
|
|
{$ENDIF}
|
2017-11-16 12:49:15 +01:00
|
|
|
|
2019-02-20 12:44:07 +01:00
|
|
|
procedure SetTransparent(aValue : boolean);
|
|
|
|
|
2017-12-27 14:05:33 +01:00
|
|
|
function CopyBuffer : boolean;
|
2017-11-16 12:49:15 +01:00
|
|
|
function SaveBufferToFile(const aFilename : string) : boolean;
|
|
|
|
|
2017-12-27 14:05:33 +01:00
|
|
|
procedure Paint; override;
|
2019-01-08 19:15:25 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2019-02-20 12:44:07 +01:00
|
|
|
procedure CreateParams(var Params: TCreateParams); override;
|
2019-01-08 19:15:25 +01:00
|
|
|
procedure WndProc(var aMessage: TMessage); override;
|
2022-04-23 16:49:11 +02:00
|
|
|
procedure WMCEFInvalidate(var aMessage: TMessage); message CEF_INVALIDATE;
|
2017-11-16 12:49:15 +01:00
|
|
|
procedure WMEraseBkgnd(var aMessage : TWMEraseBkgnd); message WM_ERASEBKGND;
|
2020-02-03 12:02:30 +01:00
|
|
|
procedure WMTouch(var aMessage: TMessage); message WM_TOUCH;
|
|
|
|
procedure WMPointerDown(var aMessage: TMessage); message WM_POINTERDOWN;
|
|
|
|
procedure WMPointerUpdate(var aMessage: TMessage); message WM_POINTERUPDATE;
|
|
|
|
procedure WMPointerUp(var aMessage: TMessage); message WM_POINTERUP;
|
2019-01-08 19:15:25 +01:00
|
|
|
procedure WMIMEStartComp(var aMessage: TMessage);
|
|
|
|
procedure WMIMEEndComp(var aMessage: TMessage);
|
|
|
|
procedure WMIMESetContext(var aMessage: TMessage);
|
|
|
|
procedure WMIMEComposition(var aMessage: TMessage);
|
2021-03-10 00:09:18 +01:00
|
|
|
|
|
|
|
procedure DoOnIMECancelComposition; virtual;
|
|
|
|
procedure DoOnIMECommitText(const aText : ustring; const replacement_range : PCefRange; relative_cursor_pos : integer); virtual;
|
|
|
|
procedure DoOnIMESetComposition(const aText : ustring; const underlines : TCefCompositionUnderlineDynArray; const replacement_range, selection_range : TCefRange); virtual;
|
2019-01-08 19:15:25 +01:00
|
|
|
{$ENDIF}
|
2017-11-16 12:49:15 +01:00
|
|
|
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure AfterConstruction; override;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Save the visible web contents as a bitmap file.
|
|
|
|
/// </summary>
|
2017-11-16 12:49:15 +01:00
|
|
|
function SaveToFile(const aFilename : string) : boolean;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Invalidate this panel.
|
|
|
|
/// </summary>
|
2017-12-27 14:05:33 +01:00
|
|
|
function InvalidatePanel : boolean;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Acquires the synchronization object before drawing into the background bitmap.
|
|
|
|
/// </summary>
|
2017-11-16 12:49:15 +01:00
|
|
|
function BeginBufferDraw : boolean;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Releases the synchronization object after drawing into the background bitmap.
|
|
|
|
/// </summary>
|
2017-11-16 12:49:15 +01:00
|
|
|
procedure EndBufferDraw;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Draws aBitmap into the background bitmap buffer at the specified coordinates.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="x">x coordinate where the bitmap will be drawn.</param>
|
|
|
|
/// <param name="y">y coordinate where the bitmap will be drawn.</param>
|
|
|
|
/// <param name="aBitmap">Bitmap that will be drawn into the background bitmap.</param>
|
2020-03-18 18:37:55 +01:00
|
|
|
procedure BufferDraw(x, y : integer; const aBitmap : TBitmap); overload;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Draws a part of aBitmap into the background bitmap buffer at the specified rectangle.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="aBitmap">Bitmap that will be drawn into the background bitmap.</param>
|
|
|
|
/// <param name="aSrcRect">Rectangle that defines the area of aBitmap that will be drawn into the background bitmap.</param>
|
|
|
|
/// <param name="aDstRect">Rectangle that defines the area of the background bitmap where aBitmap will be drawn.</param>
|
2020-03-18 18:37:55 +01:00
|
|
|
procedure BufferDraw(const aBitmap : TBitmap; const aSrcRect, aDstRect : TRect); overload;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Update the background bitmap size.
|
|
|
|
/// </summary>
|
|
|
|
function UpdateBufferDimensions(aWidth, aHeight : integer) : boolean;
|
|
|
|
/// <summary>
|
|
|
|
/// Update the image size of the original buffer copy.
|
|
|
|
/// </summary>
|
2021-01-12 17:06:31 +01:00
|
|
|
function UpdateOrigBufferDimensions(aWidth, aHeight : integer) : boolean;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Update the popup image size of the original buffer copy.
|
|
|
|
/// </summary>
|
2021-01-12 17:06:31 +01:00
|
|
|
function UpdateOrigPopupBufferDimensions(aWidth, aHeight : integer) : boolean;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Update the FDeviceScaleFactor value with the current scale.
|
|
|
|
/// </summary>
|
2021-02-16 12:47:22 +01:00
|
|
|
procedure UpdateDeviceScaleFactor;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Check if the background image buffers have the same dimensions as this panel. Returns true if they have the same size.
|
|
|
|
/// </summary>
|
2017-11-19 11:30:26 +01:00
|
|
|
function BufferIsResized(aUseMutex : boolean = True) : boolean;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Creates the IME handler.
|
|
|
|
/// </summary>
|
2019-01-08 19:15:25 +01:00
|
|
|
procedure CreateIMEHandler;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Calls ChangeCompositionRange in the IME handler.
|
|
|
|
/// </summary>
|
2019-01-08 19:15:25 +01:00
|
|
|
procedure ChangeCompositionRange(const selection_range : TCefRange; const character_bounds : TCefRectDynArray);
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Copy the contents from the original popup buffer copy to the main buffer copy.
|
|
|
|
/// </summary>
|
2021-01-12 17:06:31 +01:00
|
|
|
procedure DrawOrigPopupBuffer(const aSrcRect, aDstRect : TRect);
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the scanline size.
|
|
|
|
/// </summary>
|
2020-12-20 12:28:56 +01:00
|
|
|
property ScanlineSize : integer read FScanlineSize;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Image width.
|
|
|
|
/// </summary>
|
2020-12-20 12:28:56 +01:00
|
|
|
property BufferWidth : integer read GetBufferWidth;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Image height.
|
|
|
|
/// </summary>
|
2020-12-20 12:28:56 +01:00
|
|
|
property BufferHeight : integer read GetBufferHeight;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a pointer to the buffer that stores the image.
|
|
|
|
/// </summary>
|
2020-12-20 12:28:56 +01:00
|
|
|
property BufferBits : pointer read GetBufferBits;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the screen scale.
|
|
|
|
/// </summary>
|
2020-12-20 12:28:56 +01:00
|
|
|
property ScreenScale : single read GetScreenScale;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Screen scale value used instead of the real one.
|
|
|
|
/// </summary>
|
2020-12-20 12:28:56 +01:00
|
|
|
property ForcedDeviceScaleFactor : single read FForcedDeviceScaleFactor write FForcedDeviceScaleFactor;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Clear the background image before copying the original buffer contents.
|
|
|
|
/// </summary>
|
2021-01-12 17:06:31 +01:00
|
|
|
property MustInitBuffer : boolean read FMustInitBuffer write FMustInitBuffer;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Background bitmap.
|
|
|
|
/// </summary>
|
2020-12-28 18:11:27 +01:00
|
|
|
property Buffer : TBitmap read FBuffer;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Copy of the raw main bitmap buffer sent by CEF in the TChromiumCore.OnPaint event.
|
2023-09-26 12:20:22 +02:00
|
|
|
/// OrigBuffer will be transferred to the bitmap buffer before copying the bitmap buffer
|
|
|
|
/// to the panel.
|
2023-09-24 11:21:05 +02:00
|
|
|
/// </summary>
|
2021-01-12 17:06:31 +01:00
|
|
|
property OrigBuffer : TCEFBitmapBitBuffer read FOrigBuffer;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Image width of the raw main bitmap buffer copy.
|
|
|
|
/// </summary>
|
2021-01-12 17:06:31 +01:00
|
|
|
property OrigBufferWidth : integer read GetOrigBufferWidth;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Image height of the raw main bitmap buffer copy.
|
|
|
|
/// </summary>
|
2021-01-12 17:06:31 +01:00
|
|
|
property OrigBufferHeight : integer read GetOrigBufferHeight;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Copy of the raw popup bitmap buffer sent by CEF in the TChromiumCore.OnPaint event.
|
|
|
|
/// </summary>
|
2021-01-12 17:06:31 +01:00
|
|
|
property OrigPopupBuffer : TCEFBitmapBitBuffer read FOrigPopupBuffer;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Image width of the raw popup bitmap buffer copy.
|
|
|
|
/// </summary>
|
2021-01-12 17:06:31 +01:00
|
|
|
property OrigPopupBufferWidth : integer read GetOrigPopupBufferWidth;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Image height of the raw popup bitmap buffer copy.
|
|
|
|
/// </summary>
|
2021-01-12 17:06:31 +01:00
|
|
|
property OrigPopupBufferHeight : integer read GetOrigPopupBufferHeight;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns a pointer to the raw popup bitmap buffer copye.
|
|
|
|
/// </summary>
|
2021-01-12 17:06:31 +01:00
|
|
|
property OrigPopupBufferBits : pointer read GetOrigPopupBufferBits;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the scanline size of the raw popup bitmap buffer copy.
|
|
|
|
/// </summary>
|
2021-01-12 17:06:31 +01:00
|
|
|
property OrigPopupScanlineSize : integer read FOrigPopupScanlineSize;
|
|
|
|
|
|
|
|
{$IFDEF MSWINDOWS}
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the handle of the parent form.
|
|
|
|
/// </summary>
|
2020-12-20 12:28:56 +01:00
|
|
|
property ParentFormHandle : TCefWindowHandle read GetParentFormHandle;
|
2023-09-24 11:21:05 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the parent form.
|
|
|
|
/// </summary>
|
2020-12-20 12:28:56 +01:00
|
|
|
property ParentForm : TCustomForm read GetParentForm;
|
2020-03-31 12:44:10 +02:00
|
|
|
{$ENDIF}
|
2017-11-16 12:49:15 +01:00
|
|
|
|
|
|
|
property DockManager;
|
2019-02-20 12:44:07 +01:00
|
|
|
property Canvas;
|
2017-11-16 12:49:15 +01:00
|
|
|
|
|
|
|
published
|
2019-01-08 19:15:25 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Event triggered when a WM_IME_ENDCOMPOSITION message is received because
|
|
|
|
/// the IME ended composition.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// <para><see href="https://learn.microsoft.com/en-us/windows/win32/intl/wm-ime-endcomposition">See the WM_IME_ENDCOMPOSITION article.</see></para>
|
|
|
|
/// </remarks>
|
2019-01-08 19:15:25 +01:00
|
|
|
property OnIMECancelComposition : TNotifyEvent read FOnIMECancelComposition write FOnIMECancelComposition;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Event triggered when a WM_IME_COMPOSITION message is received because
|
|
|
|
/// the IME changed composition status as a result of a keystroke. This
|
|
|
|
/// event is triggered after retrieving a composition result of the ongoing
|
|
|
|
/// composition if it exists.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// <para><see href="https://learn.microsoft.com/en-us/windows/win32/intl/wm-ime-composition">See the WM_IME_COMPOSITION article.</see></para>
|
|
|
|
/// </remarks>
|
2019-01-08 19:15:25 +01:00
|
|
|
property OnIMECommitText : TOnIMECommitTextEvent read FOnIMECommitText write FOnIMECommitText;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Event triggered when a WM_IME_COMPOSITION message is received because
|
|
|
|
/// the IME changed composition status as a result of a keystroke.
|
|
|
|
/// This event is triggered after retrieving the current composition
|
|
|
|
/// status of the ongoing composition.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// <para><see href="https://learn.microsoft.com/en-us/windows/win32/intl/wm-ime-composition">See the WM_IME_COMPOSITION article.</see></para>
|
|
|
|
/// </remarks>
|
2019-01-08 19:15:25 +01:00
|
|
|
property OnIMESetComposition : TOnIMESetCompositionEvent read FOnIMESetComposition write FOnIMESetComposition;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Event triggered when a WM_TOUCH message is received. It notifies the
|
|
|
|
/// window when one or more touch points, such as a finger or pen,
|
|
|
|
/// touches a touch-sensitive digitizer surface.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// <para><see href="https://learn.microsoft.com/en-us/windows/win32/wintouch/wm-touchdown">See the WM_TOUCH article.</see></para>
|
|
|
|
/// </remarks>
|
2020-02-03 12:02:30 +01:00
|
|
|
property OnCustomTouch : TOnHandledMessageEvent read FOnCustomTouch write FOnCustomTouch;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Event triggered when a WM_POINTERDOWN message is received.
|
|
|
|
/// Posted when a pointer makes contact over the client area of a window.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// <para><see href="https://learn.microsoft.com/en-us/windows/win32/inputmsg/wm-pointerdown">See the WM_POINTERDOWN article.</see></para>
|
|
|
|
/// </remarks>
|
2020-02-03 12:02:30 +01:00
|
|
|
property OnPointerDown : TOnHandledMessageEvent read FOnPointerDown write FOnPointerDown;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Event triggered when a WM_POINTERUP message is received.
|
|
|
|
/// Posted when a pointer that made contact over the client area of a window breaks contact.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// <para><see href="https://learn.microsoft.com/en-us/windows/win32/inputmsg/wm-pointerup">See the WM_POINTERUP article.</see></para>
|
|
|
|
/// </remarks>
|
2020-02-03 12:02:30 +01:00
|
|
|
property OnPointerUp : TOnHandledMessageEvent read FOnPointerUp write FOnPointerUp;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Event triggered when a WM_POINTERUPDATE message is received.
|
|
|
|
/// Posted to provide an update on a pointer that made contact over the client area of a
|
|
|
|
/// window or on a hovering uncaptured pointer over the client area of a window.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// <para><see href="https://learn.microsoft.com/en-us/windows/win32/inputmsg/wm-pointerupdate">See the WM_POINTERUPDATE article.</see></para>
|
|
|
|
/// </remarks>
|
2020-02-03 12:02:30 +01:00
|
|
|
property OnPointerUpdate : TOnHandledMessageEvent read FOnPointerUpdate write FOnPointerUpdate;
|
2019-01-08 19:15:25 +01:00
|
|
|
{$ENDIF}
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Event triggered before the AlphaBlend call that transfer the web contents from the
|
|
|
|
/// bitmap buffer to the panel when the Transparent property is True.
|
|
|
|
/// </summary>
|
2019-02-20 12:44:07 +01:00
|
|
|
property OnPaintParentBkg : TNotifyEvent read FOnPaintParentBkg write FOnPaintParentBkg;
|
|
|
|
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Set Transparent to True to use a WS_EX_TRANSPARENT window style in the panel
|
|
|
|
/// and to call AlphaBlend in order to transfer the web contents from the bitmap
|
|
|
|
/// buffer to the panel.
|
|
|
|
/// If this property is False then BitBlt is used to transfer the web contents
|
|
|
|
/// from the bitmap buffer to the panel.
|
|
|
|
/// </summary>
|
2021-01-12 17:06:31 +01:00
|
|
|
property Transparent : boolean read FTransparent write SetTransparent default False;
|
2023-09-26 12:20:22 +02:00
|
|
|
/// <summary>
|
|
|
|
/// When CopyOriginalBuffer is True then OrigBuffer will be used internally to copy of
|
|
|
|
/// the raw main bitmap buffer sent by CEF in the TChromiumCore.OnPaint event.
|
|
|
|
/// OrigBuffer will be transferred to the bitmap buffer before copying the buffer to the panel.
|
|
|
|
/// This is necessary in GTK applications in order to avoid handling bitmaps in background
|
|
|
|
/// threads.
|
|
|
|
/// </summary>
|
2021-01-12 17:06:31 +01:00
|
|
|
property CopyOriginalBuffer : boolean read FCopyOriginalBuffer write FCopyOriginalBuffer default False;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
property Align;
|
|
|
|
property Alignment;
|
|
|
|
property Anchors;
|
|
|
|
property AutoSize;
|
2018-06-18 21:57:18 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
property OnUTF8KeyPress;
|
|
|
|
{$ELSE}
|
2017-11-16 12:49:15 +01:00
|
|
|
property BevelEdges;
|
2018-06-18 21:57:18 +02:00
|
|
|
property BevelKind;
|
|
|
|
property Ctl3D;
|
|
|
|
property Locked;
|
2024-03-23 18:21:32 +01:00
|
|
|
{$IFDEF DELPHI7_UP}
|
2018-06-18 21:57:18 +02:00
|
|
|
property ParentBackground;
|
2024-03-23 18:21:32 +01:00
|
|
|
{$ENDIF}
|
2018-06-18 21:57:18 +02:00
|
|
|
property ParentCtl3D;
|
2018-05-12 14:50:54 +02:00
|
|
|
property OnCanResize;
|
|
|
|
{$ENDIF}
|
2017-11-16 12:49:15 +01:00
|
|
|
property BevelInner;
|
|
|
|
property BevelOuter;
|
|
|
|
property BevelWidth;
|
|
|
|
property BiDiMode;
|
|
|
|
property BorderWidth;
|
|
|
|
property BorderStyle;
|
|
|
|
property Caption;
|
|
|
|
property Color;
|
|
|
|
property Constraints;
|
|
|
|
property UseDockManager default True;
|
|
|
|
property DockSite;
|
|
|
|
property DoubleBuffered;
|
|
|
|
property DragCursor;
|
|
|
|
property DragKind;
|
|
|
|
property DragMode;
|
|
|
|
property Enabled;
|
|
|
|
property FullRepaint;
|
|
|
|
property Font;
|
|
|
|
property ParentBiDiMode;
|
|
|
|
property ParentColor;
|
|
|
|
property ParentFont;
|
|
|
|
property ParentShowHint;
|
|
|
|
property PopupMenu;
|
|
|
|
property ShowHint;
|
|
|
|
property TabOrder;
|
|
|
|
property TabStop;
|
|
|
|
property Visible;
|
|
|
|
property OnClick;
|
|
|
|
property OnConstrainedResize;
|
|
|
|
property OnContextPopup;
|
|
|
|
property OnDockDrop;
|
|
|
|
property OnDockOver;
|
|
|
|
property OnDblClick;
|
|
|
|
property OnDragDrop;
|
|
|
|
property OnDragOver;
|
|
|
|
property OnEndDock;
|
|
|
|
property OnEndDrag;
|
|
|
|
property OnEnter;
|
|
|
|
property OnExit;
|
|
|
|
property OnGetSiteInfo;
|
|
|
|
property OnMouseDown;
|
|
|
|
property OnMouseMove;
|
2018-06-17 14:18:11 +02:00
|
|
|
property OnMouseUp;
|
|
|
|
property OnMouseWheel;
|
2018-02-19 13:35:01 +01:00
|
|
|
property OnKeyDown;
|
|
|
|
property OnKeyPress;
|
|
|
|
property OnKeyUp;
|
2017-11-16 12:49:15 +01:00
|
|
|
property OnResize;
|
|
|
|
property OnStartDock;
|
|
|
|
property OnStartDrag;
|
|
|
|
property OnUnDock;
|
|
|
|
{$IFDEF DELPHI9_UP}
|
|
|
|
property VerticalAlignment;
|
|
|
|
property OnAlignInsertBefore;
|
|
|
|
property OnAlignPosition;
|
|
|
|
{$ENDIF}
|
|
|
|
{$IFDEF DELPHI10_UP}
|
|
|
|
property Padding;
|
|
|
|
property OnMouseActivate;
|
|
|
|
property OnMouseEnter;
|
|
|
|
property OnMouseLeave;
|
|
|
|
{$ENDIF}
|
2021-02-08 10:28:36 +01:00
|
|
|
{$IFDEF FPC}
|
|
|
|
property OnMouseEnter;
|
|
|
|
property OnMouseLeave;
|
|
|
|
{$ENDIF}
|
2017-11-16 12:49:15 +01:00
|
|
|
{$IFDEF DELPHI12_UP}
|
2017-11-27 20:53:54 +01:00
|
|
|
property ShowCaption;
|
2017-11-16 12:49:15 +01:00
|
|
|
property ParentDoubleBuffered;
|
|
|
|
{$ENDIF}
|
|
|
|
{$IFDEF DELPHI14_UP}
|
|
|
|
property Touch;
|
|
|
|
property OnGesture;
|
|
|
|
{$ENDIF}
|
|
|
|
{$IFDEF DELPHI17_UP}
|
|
|
|
property StyleElements;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
procedure Register;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2020-12-28 18:11:27 +01:00
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
System.Math,
|
|
|
|
{$ELSE}
|
|
|
|
Math,
|
|
|
|
{$ENDIF}
|
2019-11-08 23:15:53 +01:00
|
|
|
uCEFMiscFunctions, uCEFApplicationCore;
|
2017-11-16 12:49:15 +01:00
|
|
|
|
|
|
|
constructor TBufferPanel.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner);
|
|
|
|
|
2021-01-12 17:06:31 +01:00
|
|
|
FBuffer := nil;
|
|
|
|
FTransparent := False;
|
|
|
|
FOnPaintParentBkg := nil;
|
|
|
|
FScanlineSize := 0;
|
|
|
|
FCopyOriginalBuffer := False;
|
|
|
|
FOrigBuffer := nil;
|
|
|
|
FOrigPopupBuffer := nil;
|
|
|
|
FOrigPopupScanlineSize := 0;
|
2021-02-16 12:47:22 +01:00
|
|
|
FDeviceScaleFactor := 0;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
2020-12-20 12:28:56 +01:00
|
|
|
if (GlobalCEFApp <> nil) and (GlobalCEFApp.ForcedDeviceScaleFactor <> 0) then
|
|
|
|
FForcedDeviceScaleFactor := GlobalCEFApp.ForcedDeviceScaleFactor
|
|
|
|
else
|
|
|
|
FForcedDeviceScaleFactor := 0;
|
|
|
|
|
2020-12-28 18:11:27 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
FSyncObj := 0;
|
2019-01-08 19:15:25 +01:00
|
|
|
FIMEHandler := nil;
|
|
|
|
FOnIMECancelComposition := nil;
|
|
|
|
FOnIMECommitText := nil;
|
|
|
|
FOnIMESetComposition := nil;
|
2020-02-03 12:02:30 +01:00
|
|
|
FOnCustomTouch := nil;
|
|
|
|
FOnPointerDown := nil;
|
|
|
|
FOnPointerUp := nil;
|
|
|
|
FOnPointerUpdate := nil;
|
2021-01-12 17:06:31 +01:00
|
|
|
FMustInitBuffer := False;
|
2020-12-28 18:11:27 +01:00
|
|
|
{$ELSE}
|
|
|
|
FSyncObj := nil;
|
2021-01-12 17:06:31 +01:00
|
|
|
FMustInitBuffer := True;
|
2019-01-08 19:15:25 +01:00
|
|
|
{$ENDIF}
|
2017-11-16 12:49:15 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TBufferPanel.Destroy;
|
|
|
|
begin
|
|
|
|
DestroyBuffer;
|
2018-01-25 21:34:04 +01:00
|
|
|
DestroySyncObj;
|
2017-11-16 12:49:15 +01:00
|
|
|
|
2019-01-08 19:15:25 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
if (FIMEHandler <> nil) then FreeAndNil(FIMEHandler);
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBufferPanel.AfterConstruction;
|
|
|
|
begin
|
|
|
|
inherited AfterConstruction;
|
|
|
|
|
2018-01-25 21:34:04 +01:00
|
|
|
CreateSyncObj;
|
2021-02-16 12:47:22 +01:00
|
|
|
UpdateDeviceScaleFactor;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
{$IFNDEF FPC}
|
|
|
|
ImeMode := imDontCare;
|
|
|
|
ImeName := '';
|
|
|
|
{$ENDIF}
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBufferPanel.CreateIMEHandler;
|
|
|
|
begin
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
if (FIMEHandler = nil) and HandleAllocated then
|
|
|
|
FIMEHandler := TCEFOSRIMEHandler.Create(Handle);
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBufferPanel.ChangeCompositionRange(const selection_range : TCefRange;
|
|
|
|
const character_bounds : TCefRectDynArray);
|
|
|
|
begin
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
if (FIMEHandler <> nil) then
|
|
|
|
FIMEHandler.ChangeCompositionRange(selection_range, character_bounds);
|
|
|
|
{$ENDIF}
|
2017-12-27 14:05:33 +01:00
|
|
|
end;
|
|
|
|
|
2021-01-12 17:06:31 +01:00
|
|
|
procedure TBufferPanel.DrawOrigPopupBuffer(const aSrcRect, aDstRect : TRect);
|
2020-12-28 18:11:27 +01:00
|
|
|
var
|
|
|
|
src_y, dst_y, TempWidth : integer;
|
2021-01-12 17:06:31 +01:00
|
|
|
src, dst : PByte;
|
2020-12-28 18:11:27 +01:00
|
|
|
begin
|
2021-01-12 17:06:31 +01:00
|
|
|
if (FOrigBuffer = nil) or (FOrigPopupBuffer = nil) then exit;
|
2020-12-28 18:11:27 +01:00
|
|
|
|
|
|
|
src_y := aSrcRect.Top;
|
|
|
|
dst_y := aDstRect.Top;
|
|
|
|
|
|
|
|
TempWidth := min(aSrcRect.Right - aSrcRect.Left + 1,
|
|
|
|
aDstRect.Right - aDstRect.Left + 1);
|
|
|
|
|
2021-01-12 17:06:31 +01:00
|
|
|
if (aSrcRect.Left + TempWidth >= FOrigPopupBuffer.Width) then
|
|
|
|
TempWidth := FOrigPopupBuffer.Width - aSrcRect.Left;
|
2020-12-28 18:11:27 +01:00
|
|
|
|
2021-01-12 17:06:31 +01:00
|
|
|
if (aDstRect.Left + TempWidth >= FOrigBuffer.Width) then
|
|
|
|
TempWidth := FOrigBuffer.Width - aDstRect.Left;
|
2020-12-28 18:11:27 +01:00
|
|
|
|
2021-01-12 17:06:31 +01:00
|
|
|
while (src_y <= aSrcRect.Bottom) and (src_y < FOrigPopupBuffer.Height) and
|
|
|
|
(dst_y <= aDstRect.Bottom) and (dst_y < FOrigBuffer.Height) do
|
2020-12-28 18:11:27 +01:00
|
|
|
begin
|
2021-01-12 17:06:31 +01:00
|
|
|
src := FOrigPopupBuffer.ScanLine[src_y];
|
|
|
|
dst := FOrigBuffer.ScanLine[dst_y];
|
2020-12-28 18:11:27 +01:00
|
|
|
|
|
|
|
if (aSrcRect.Left > 0) then
|
|
|
|
inc(src, aSrcRect.Left * SizeOf(TRGBQuad));
|
|
|
|
|
|
|
|
if (aDstRect.Left > 0) then
|
|
|
|
inc(dst, aDstRect.Left * SizeOf(TRGBQuad));
|
|
|
|
|
|
|
|
move(src^, dst^, TempWidth * SizeOf(TRGBQuad));
|
|
|
|
|
|
|
|
inc(src_y);
|
|
|
|
inc(dst_y);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-01-25 21:34:04 +01:00
|
|
|
procedure TBufferPanel.CreateSyncObj;
|
2017-12-27 14:05:33 +01:00
|
|
|
begin
|
2019-01-08 19:15:25 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2020-12-28 18:11:27 +01:00
|
|
|
FSyncObj := CreateMutex(nil, False, nil);
|
|
|
|
{$ELSE}
|
|
|
|
FSyncObj := TCriticalSection.Create;
|
2019-01-08 19:15:25 +01:00
|
|
|
{$ENDIF}
|
2017-11-16 12:49:15 +01:00
|
|
|
end;
|
|
|
|
|
2018-01-25 21:34:04 +01:00
|
|
|
procedure TBufferPanel.DestroySyncObj;
|
2017-12-27 14:05:33 +01:00
|
|
|
begin
|
2019-01-08 19:15:25 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2020-12-28 18:11:27 +01:00
|
|
|
if (FSyncObj <> 0) then
|
2017-12-27 14:05:33 +01:00
|
|
|
begin
|
2020-12-28 18:11:27 +01:00
|
|
|
CloseHandle(FSyncObj);
|
|
|
|
FSyncObj := 0;
|
2017-12-27 14:05:33 +01:00
|
|
|
end;
|
2020-12-28 18:11:27 +01:00
|
|
|
{$ELSE}
|
|
|
|
if (FSyncObj <> nil) then FreeAndNil(FSyncObj);
|
2019-01-08 19:15:25 +01:00
|
|
|
{$ENDIF}
|
2017-12-27 14:05:33 +01:00
|
|
|
end;
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
procedure TBufferPanel.DestroyBuffer;
|
|
|
|
begin
|
|
|
|
if BeginBufferDraw then
|
|
|
|
begin
|
2021-01-12 17:06:31 +01:00
|
|
|
if (FBuffer <> nil) then FreeAndNil(FBuffer);
|
|
|
|
if (FOrigBuffer <> nil) then FreeAndNil(FOrigBuffer);
|
|
|
|
if (FOrigPopupBuffer <> nil) then FreeAndNil(FOrigPopupBuffer);
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
EndBufferDraw;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TBufferPanel.SaveBufferToFile(const aFilename : string) : boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
try
|
|
|
|
if (FBuffer <> nil) then
|
|
|
|
begin
|
|
|
|
FBuffer.SaveToFile(aFilename);
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TBufferPanel.SaveBufferToFile', e) then raise;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TBufferPanel.SaveToFile(const aFilename : string) : boolean;
|
|
|
|
begin
|
2017-12-27 14:05:33 +01:00
|
|
|
Result := False;
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
if BeginBufferDraw then
|
|
|
|
begin
|
|
|
|
Result := SaveBufferToFile(aFilename);
|
|
|
|
EndBufferDraw;
|
2017-12-27 14:05:33 +01:00
|
|
|
end;
|
2017-11-16 12:49:15 +01:00
|
|
|
end;
|
|
|
|
|
2017-12-27 14:05:33 +01:00
|
|
|
function TBufferPanel.InvalidatePanel : boolean;
|
2017-11-16 12:49:15 +01:00
|
|
|
begin
|
2019-01-08 19:15:25 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2022-04-23 16:49:11 +02:00
|
|
|
Result := HandleAllocated and PostMessage(Handle, CEF_INVALIDATE, 0, 0);
|
2020-12-28 18:11:27 +01:00
|
|
|
{$ELSE}
|
|
|
|
Result := True;
|
2021-05-26 19:32:10 +02:00
|
|
|
TThread.ForceQueue(nil, @Invalidate);
|
2019-01-08 19:15:25 +01:00
|
|
|
{$ENDIF}
|
2017-11-16 12:49:15 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TBufferPanel.BeginBufferDraw : boolean;
|
|
|
|
begin
|
2019-01-08 19:15:25 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2020-12-28 18:11:27 +01:00
|
|
|
Result := (FSyncObj <> 0) and (WaitForSingleObject(FSyncObj, 5000) = WAIT_OBJECT_0);
|
|
|
|
{$ELSE}
|
|
|
|
if (FSyncObj <> nil) then
|
|
|
|
begin
|
|
|
|
FSyncObj.Acquire;
|
|
|
|
Result := True;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := False;
|
2019-01-08 19:15:25 +01:00
|
|
|
{$ENDIF}
|
2017-11-16 12:49:15 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBufferPanel.EndBufferDraw;
|
|
|
|
begin
|
2019-01-08 19:15:25 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2020-12-28 18:11:27 +01:00
|
|
|
if (FSyncObj <> 0) then ReleaseMutex(FSyncObj);
|
|
|
|
{$ELSE}
|
|
|
|
if (FSyncObj <> nil) then FSyncObj.Release;
|
2019-01-08 19:15:25 +01:00
|
|
|
{$ENDIF}
|
2017-11-16 12:49:15 +01:00
|
|
|
end;
|
|
|
|
|
2017-12-27 14:05:33 +01:00
|
|
|
function TBufferPanel.CopyBuffer : boolean;
|
2019-02-20 12:44:07 +01:00
|
|
|
var
|
2020-12-28 18:11:27 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2020-02-08 12:59:59 +01:00
|
|
|
TempFunction : TBlendFunction;
|
2021-01-12 17:06:31 +01:00
|
|
|
{$ENDIF}
|
2020-12-28 18:11:27 +01:00
|
|
|
y : integer;
|
|
|
|
src, dst : pointer;
|
2017-11-16 12:49:15 +01:00
|
|
|
begin
|
2020-03-29 17:31:42 +02:00
|
|
|
Result := False;
|
2020-02-08 12:59:59 +01:00
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
if BeginBufferDraw then
|
2019-02-20 12:44:07 +01:00
|
|
|
try
|
2021-01-12 17:06:31 +01:00
|
|
|
if FCopyOriginalBuffer then
|
|
|
|
begin
|
|
|
|
if (FBuffer = nil) then
|
|
|
|
begin
|
|
|
|
FBuffer := TBitmap.Create;
|
|
|
|
FBuffer.PixelFormat := pf32bit;
|
|
|
|
FBuffer.HandleType := bmDIB;
|
|
|
|
FBuffer.Width := 1001;
|
|
|
|
FBuffer.Height := 600;
|
|
|
|
|
|
|
|
if FMustInitBuffer then
|
|
|
|
begin
|
|
|
|
FBuffer.Canvas.Brush.Color := clWhite;
|
|
|
|
FBuffer.Canvas.FillRect(rect(0, 0, FBuffer.Width, FBuffer.Height));
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if (FOrigBuffer <> nil) and not(FOrigBuffer.Empty) then
|
|
|
|
begin
|
|
|
|
if (FBuffer.Width <> FOrigBuffer.Width) or
|
|
|
|
(FBuffer.Height <> FOrigBuffer.Height) then
|
|
|
|
begin
|
|
|
|
FBuffer.Width := FOrigBuffer.Width;
|
|
|
|
FBuffer.Height := FOrigBuffer.Height;
|
|
|
|
|
|
|
|
if FMustInitBuffer then
|
|
|
|
begin
|
|
|
|
FBuffer.Canvas.Brush.Color := clWhite;
|
|
|
|
FBuffer.Canvas.FillRect(rect(0, 0, FBuffer.Width, FBuffer.Height));
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
try
|
|
|
|
{$IFDEF FPC}
|
|
|
|
FBuffer.BeginUpdate;
|
|
|
|
{$ENDIF}
|
|
|
|
y := 0;
|
|
|
|
while (y < FBuffer.Height) do
|
|
|
|
begin
|
|
|
|
src := FOrigBuffer.ScanLine[y];
|
|
|
|
dst := FBuffer.ScanLine[y];
|
|
|
|
move(src^, dst^, FOrigBuffer.ScanLineSize);
|
|
|
|
inc(y);
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
{$IFDEF FPC}
|
|
|
|
FBuffer.EndUpdate;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2020-12-28 18:11:27 +01:00
|
|
|
if (FBuffer <> nil) and (FBuffer.Width <> 0) and (FBuffer.Height <> 0) then
|
2019-02-20 12:44:07 +01:00
|
|
|
begin
|
2020-12-28 18:11:27 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
if FTransparent then
|
|
|
|
begin
|
|
|
|
// TODO : To avoid flickering we should be using another bitmap
|
|
|
|
// for the background image. We should blend "FBuffer" with the
|
|
|
|
// "background bitmap" and then blit the result to the canvas.
|
|
|
|
|
|
|
|
if assigned(FOnPaintParentBkg) then FOnPaintParentBkg(self);
|
|
|
|
|
|
|
|
TempFunction.BlendOp := AC_SRC_OVER;
|
|
|
|
TempFunction.BlendFlags := 0;
|
|
|
|
TempFunction.SourceConstantAlpha := 255;
|
|
|
|
TempFunction.AlphaFormat := AC_SRC_ALPHA;
|
|
|
|
|
|
|
|
Result := AlphaBlend(Canvas.Handle, 0, 0, Width, Height,
|
|
|
|
FBuffer.Canvas.Handle, 0, 0, FBuffer.Width, FBuffer.Height,
|
|
|
|
TempFunction);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result := BitBlt(Canvas.Handle, 0, 0, Width, Height,
|
|
|
|
FBuffer.Canvas.Handle, 0, 0,
|
|
|
|
SrcCopy);
|
|
|
|
{$ELSE}
|
|
|
|
try
|
|
|
|
Canvas.Lock;
|
2021-01-12 17:06:31 +01:00
|
|
|
Canvas.Draw(0, 0, FBuffer);
|
2020-12-28 18:11:27 +01:00
|
|
|
Result := True;
|
|
|
|
finally
|
|
|
|
Canvas.Unlock;
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
2019-02-20 12:44:07 +01:00
|
|
|
end;
|
|
|
|
finally
|
2017-11-16 12:49:15 +01:00
|
|
|
EndBufferDraw;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2017-12-27 14:05:33 +01:00
|
|
|
procedure TBufferPanel.Paint;
|
2017-11-16 12:49:15 +01:00
|
|
|
begin
|
2017-12-27 14:05:33 +01:00
|
|
|
if csDesigning in ComponentState then
|
|
|
|
begin
|
|
|
|
Canvas.Font.Assign(Font);
|
|
|
|
Canvas.Brush.Color := Color;
|
|
|
|
Canvas.Brush.Style := bsSolid;
|
|
|
|
Canvas.Pen.Style := psDash;
|
2017-11-16 12:49:15 +01:00
|
|
|
|
2017-12-27 14:05:33 +01:00
|
|
|
Canvas.Rectangle(0, 0, Width, Height);
|
|
|
|
end
|
|
|
|
else
|
2019-02-20 12:44:07 +01:00
|
|
|
if not(CopyBuffer) and not(FTransparent) then
|
2017-11-16 12:49:15 +01:00
|
|
|
begin
|
|
|
|
Canvas.Brush.Color := Color;
|
|
|
|
Canvas.Brush.Style := bsSolid;
|
2017-12-27 14:05:33 +01:00
|
|
|
Canvas.FillRect(rect(0, 0, Width, Height));
|
|
|
|
end;
|
2021-03-10 02:04:18 +01:00
|
|
|
|
2021-03-14 11:54:24 +01:00
|
|
|
{$IFDEF FPC}
|
|
|
|
if assigned(OnPaint) then OnPaint(Self);
|
|
|
|
{$ENDIF}
|
2017-11-16 12:49:15 +01:00
|
|
|
end;
|
|
|
|
|
2019-01-08 19:15:25 +01:00
|
|
|
{$IFDEF MSWINDOWS}
|
2019-02-20 12:44:07 +01:00
|
|
|
procedure TBufferPanel.CreateParams(var Params: TCreateParams);
|
|
|
|
begin
|
|
|
|
inherited CreateParams(Params);
|
|
|
|
|
|
|
|
if FTransparent then
|
|
|
|
Params.ExStyle := Params.ExStyle and not WS_EX_TRANSPARENT;
|
|
|
|
end;
|
|
|
|
|
2019-01-08 19:15:25 +01:00
|
|
|
procedure TBufferPanel.WndProc(var aMessage: TMessage);
|
|
|
|
begin
|
|
|
|
case aMessage.Msg of
|
|
|
|
WM_IME_STARTCOMPOSITION : WMIMEStartComp(aMessage);
|
|
|
|
WM_IME_COMPOSITION : WMIMEComposition(aMessage);
|
|
|
|
|
|
|
|
WM_IME_ENDCOMPOSITION :
|
|
|
|
begin
|
|
|
|
WMIMEEndComp(aMessage);
|
|
|
|
inherited WndProc(aMessage);
|
|
|
|
end;
|
|
|
|
|
|
|
|
WM_IME_SETCONTEXT :
|
|
|
|
begin
|
|
|
|
aMessage.LParam := aMessage.LParam and not(ISC_SHOWUICOMPOSITIONWINDOW);
|
|
|
|
inherited WndProc(aMessage);
|
|
|
|
WMIMESetContext(aMessage);
|
|
|
|
end;
|
|
|
|
|
|
|
|
else inherited WndProc(aMessage);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2022-04-23 16:49:11 +02:00
|
|
|
procedure TBufferPanel.WMCEFInvalidate(var aMessage: TMessage);
|
|
|
|
begin
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
procedure TBufferPanel.WMEraseBkgnd(var aMessage : TWMEraseBkgnd);
|
|
|
|
begin
|
|
|
|
aMessage.Result := 1;
|
|
|
|
end;
|
|
|
|
|
2020-02-03 12:02:30 +01:00
|
|
|
procedure TBufferPanel.WMTouch(var aMessage: TMessage);
|
|
|
|
var
|
|
|
|
TempHandled : boolean;
|
|
|
|
begin
|
|
|
|
TempHandled := False;
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
if assigned(FOnCustomTouch) then FOnCustomTouch(self, aMessage, TempHandled);
|
|
|
|
{$ENDIF}
|
|
|
|
if not(TempHandled) then inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBufferPanel.WMPointerDown(var aMessage: TMessage);
|
|
|
|
var
|
|
|
|
TempHandled : boolean;
|
|
|
|
begin
|
|
|
|
TempHandled := False;
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
if assigned(FOnPointerDown) then FOnPointerDown(self, aMessage, TempHandled);
|
|
|
|
{$ENDIF}
|
|
|
|
if not(TempHandled) then inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBufferPanel.WMPointerUpdate(var aMessage: TMessage);
|
|
|
|
var
|
|
|
|
TempHandled : boolean;
|
|
|
|
begin
|
|
|
|
TempHandled := False;
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
if assigned(FOnPointerUpdate) then FOnPointerUpdate(self, aMessage, TempHandled);
|
|
|
|
{$ENDIF}
|
|
|
|
if not(TempHandled) then inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBufferPanel.WMPointerUp(var aMessage: TMessage);
|
|
|
|
var
|
|
|
|
TempHandled : boolean;
|
|
|
|
begin
|
|
|
|
TempHandled := False;
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
if assigned(FOnPointerUp) then FOnPointerUp(self, aMessage, TempHandled);
|
|
|
|
{$ENDIF}
|
|
|
|
if not(TempHandled) then inherited;
|
|
|
|
end;
|
|
|
|
|
2019-01-08 19:15:25 +01:00
|
|
|
procedure TBufferPanel.WMIMEStartComp(var aMessage: TMessage);
|
|
|
|
begin
|
|
|
|
if (FIMEHandler <> nil) then
|
|
|
|
begin
|
|
|
|
{$IFNDEF FPC}
|
|
|
|
FInImeComposition := False;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
FIMEHandler.CreateImeWindow;
|
|
|
|
FIMEHandler.MoveImeWindow;
|
|
|
|
FIMEHandler.ResetComposition;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBufferPanel.WMIMEEndComp(var aMessage: TMessage);
|
|
|
|
begin
|
2021-03-10 00:09:18 +01:00
|
|
|
DoOnIMECancelComposition;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
|
|
|
if (FIMEHandler <> nil) then
|
|
|
|
begin
|
|
|
|
FIMEHandler.ResetComposition;
|
|
|
|
FIMEHandler.DestroyImeWindow;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBufferPanel.WMIMESetContext(var aMessage: TMessage);
|
|
|
|
begin
|
|
|
|
if (FIMEHandler <> nil) then
|
|
|
|
begin
|
|
|
|
FIMEHandler.CreateImeWindow;
|
|
|
|
FIMEHandler.MoveImeWindow;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBufferPanel.WMIMEComposition(var aMessage: TMessage);
|
2022-04-23 16:49:11 +02:00
|
|
|
const
|
2023-05-29 17:20:32 +02:00
|
|
|
UINT32_MAX = high(cardinal);
|
2019-01-08 19:15:25 +01:00
|
|
|
var
|
|
|
|
TempText : ustring;
|
|
|
|
TempRange : TCefRange;
|
|
|
|
TempCompStart : integer;
|
|
|
|
TempUnderlines : TCefCompositionUnderlineDynArray;
|
|
|
|
TempSelection : TCefRange;
|
|
|
|
begin
|
|
|
|
TempText := '';
|
|
|
|
TempCompStart := 0;
|
|
|
|
TempUnderlines := nil;
|
|
|
|
|
|
|
|
try
|
|
|
|
if (FIMEHandler <> nil) then
|
|
|
|
begin
|
|
|
|
if FIMEHandler.GetResult(aMessage.LParam, TempText) then
|
|
|
|
begin
|
|
|
|
if assigned(FOnIMECommitText) then
|
|
|
|
begin
|
2022-04-23 16:49:11 +02:00
|
|
|
TempRange.from := UINT32_MAX;
|
|
|
|
TempRange.to_ := UINT32_MAX;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
2021-03-10 00:09:18 +01:00
|
|
|
DoOnIMECommitText(TempText, @TempRange, 0);
|
2019-01-08 19:15:25 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
FIMEHandler.ResetComposition;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if FIMEHandler.GetComposition(aMessage.LParam, TempText, TempUnderlines, TempCompStart) then
|
|
|
|
begin
|
|
|
|
if assigned(FOnIMESetComposition) then
|
|
|
|
begin
|
2022-04-23 16:49:11 +02:00
|
|
|
TempRange.from := UINT32_MAX;
|
|
|
|
TempRange.to_ := UINT32_MAX;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
|
|
|
TempSelection.from := TempCompStart;
|
|
|
|
TempSelection.to_ := TempCompStart + length(TempText);
|
|
|
|
|
2021-03-10 00:09:18 +01:00
|
|
|
DoOnIMESetComposition(TempText, TempUnderlines, TempRange, TempSelection);
|
2019-01-08 19:15:25 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
FIMEHandler.UpdateCaretPosition(pred(TempCompStart));
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
2021-03-10 00:09:18 +01:00
|
|
|
DoOnIMECancelComposition;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
|
|
|
FIMEHandler.ResetComposition;
|
|
|
|
FIMEHandler.DestroyImeWindow;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
if (TempUnderlines <> nil) then
|
|
|
|
begin
|
|
|
|
Finalize(TempUnderlines);
|
|
|
|
TempUnderlines := nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
2021-03-10 00:09:18 +01:00
|
|
|
|
|
|
|
procedure TBufferPanel.DoOnIMECancelComposition;
|
|
|
|
begin
|
2021-03-14 11:54:24 +01:00
|
|
|
if assigned(FOnIMECancelComposition) then
|
2021-03-10 00:09:18 +01:00
|
|
|
FOnIMECancelComposition(Self);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBufferPanel.DoOnIMECommitText(const aText: ustring;
|
|
|
|
const replacement_range: PCefRange; relative_cursor_pos: integer);
|
|
|
|
begin
|
2021-03-14 11:54:24 +01:00
|
|
|
if assigned(FOnIMECommitText) then
|
2021-03-10 00:09:18 +01:00
|
|
|
FOnIMECommitText(Self, aText, replacement_range, relative_cursor_pos);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBufferPanel.DoOnIMESetComposition(const aText: ustring;
|
|
|
|
const underlines: TCefCompositionUnderlineDynArray; const replacement_range,
|
|
|
|
selection_range: TCefRange);
|
|
|
|
begin
|
2021-03-14 11:54:24 +01:00
|
|
|
if assigned(FOnIMESetComposition) then
|
2021-03-10 00:09:18 +01:00
|
|
|
FOnIMESetComposition(Self, aText, underlines, replacement_range, selection_range);
|
|
|
|
end;
|
2019-01-08 19:15:25 +01:00
|
|
|
{$ENDIF}
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
function TBufferPanel.GetBufferBits : pointer;
|
|
|
|
begin
|
2021-01-12 17:06:31 +01:00
|
|
|
if (FBuffer <> nil) and (FBuffer.Height <> 0) then
|
|
|
|
Result := FBuffer.Scanline[pred(FBuffer.Height)]
|
2017-11-16 12:49:15 +01:00
|
|
|
else
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TBufferPanel.GetBufferWidth : integer;
|
|
|
|
begin
|
|
|
|
if (FBuffer <> nil) then
|
|
|
|
Result := FBuffer.Width
|
|
|
|
else
|
|
|
|
Result := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TBufferPanel.GetBufferHeight : integer;
|
|
|
|
begin
|
|
|
|
if (FBuffer <> nil) then
|
|
|
|
Result := FBuffer.Height
|
|
|
|
else
|
|
|
|
Result := 0;
|
2021-01-12 17:06:31 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TBufferPanel.GetOrigBufferWidth : integer;
|
|
|
|
begin
|
|
|
|
if (FOrigBuffer <> nil) then
|
|
|
|
Result := FOrigBuffer.Width
|
|
|
|
else
|
|
|
|
Result := 0;
|
2017-11-16 12:49:15 +01:00
|
|
|
end;
|
|
|
|
|
2021-01-12 17:06:31 +01:00
|
|
|
function TBufferPanel.GetOrigBufferHeight : integer;
|
2020-12-28 18:11:27 +01:00
|
|
|
begin
|
2021-01-12 17:06:31 +01:00
|
|
|
if (FOrigBuffer <> nil) then
|
|
|
|
Result := FOrigBuffer.Height
|
|
|
|
else
|
|
|
|
Result := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TBufferPanel.GetOrigPopupBufferBits : pointer;
|
|
|
|
begin
|
|
|
|
if (FOrigPopupBuffer <> nil) then
|
|
|
|
Result := FOrigPopupBuffer.BufferBits
|
2020-12-28 18:11:27 +01:00
|
|
|
else
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
2021-01-12 17:06:31 +01:00
|
|
|
function TBufferPanel.GetOrigPopupBufferWidth : integer;
|
2020-12-28 18:11:27 +01:00
|
|
|
begin
|
2021-01-12 17:06:31 +01:00
|
|
|
if (FOrigPopupBuffer <> nil) then
|
|
|
|
Result := FOrigPopupBuffer.Width
|
2020-12-28 18:11:27 +01:00
|
|
|
else
|
|
|
|
Result := 0;
|
|
|
|
end;
|
|
|
|
|
2021-01-12 17:06:31 +01:00
|
|
|
function TBufferPanel.GetOrigPopupBufferHeight : integer;
|
2020-12-28 18:11:27 +01:00
|
|
|
begin
|
2021-01-12 17:06:31 +01:00
|
|
|
if (FOrigPopupBuffer <> nil) then
|
|
|
|
Result := FOrigPopupBuffer.Height
|
2020-12-28 18:11:27 +01:00
|
|
|
else
|
|
|
|
Result := 0;
|
|
|
|
end;
|
|
|
|
|
2021-02-16 12:47:22 +01:00
|
|
|
procedure TBufferPanel.UpdateDeviceScaleFactor;
|
|
|
|
var
|
|
|
|
TempScale : single;
|
|
|
|
begin
|
|
|
|
if GetRealScreenScale(TempScale) then
|
|
|
|
FDeviceScaleFactor := TempScale;
|
|
|
|
end;
|
|
|
|
|
2020-12-20 12:28:56 +01:00
|
|
|
function TBufferPanel.GetRealScreenScale(var aResultScale : single) : boolean;
|
2021-06-24 17:47:22 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2021-02-07 17:46:58 +01:00
|
|
|
var
|
2020-03-31 12:44:10 +02:00
|
|
|
TempHandle : TCefWindowHandle;
|
|
|
|
TempDC : HDC;
|
2020-10-31 14:23:06 +01:00
|
|
|
TempDPI : UINT;
|
2021-06-24 17:47:22 +02:00
|
|
|
{$ENDIF}
|
|
|
|
{$IFDEF LINUX}{$IFDEF FPC}
|
2021-02-07 17:46:58 +01:00
|
|
|
var
|
2021-06-24 17:47:22 +02:00
|
|
|
TempForm : TCustomForm;
|
|
|
|
TempMonitor : TMonitor;
|
|
|
|
{$ENDIF}{$ENDIF}
|
|
|
|
{$IFDEF MACOSX}{$IFDEF FPC}
|
|
|
|
var
|
|
|
|
TempForm : TCustomForm;
|
|
|
|
TempMonitor : TMonitor;
|
|
|
|
{$ENDIF}{$ENDIF}
|
2020-03-31 12:44:10 +02:00
|
|
|
begin
|
2020-12-20 12:28:56 +01:00
|
|
|
Result := False;
|
|
|
|
aResultScale := 1;
|
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
TempHandle := ParentFormHandle;
|
|
|
|
|
|
|
|
if (TempHandle <> 0) then
|
|
|
|
begin
|
2020-12-20 12:28:56 +01:00
|
|
|
Result := True;
|
|
|
|
|
2020-10-31 14:23:06 +01:00
|
|
|
if RunningWindows10OrNewer and GetDPIForHandle(TempHandle, TempDPI) then
|
2020-12-20 12:28:56 +01:00
|
|
|
aResultScale := TempDPI / USER_DEFAULT_SCREEN_DPI
|
2020-10-31 14:23:06 +01:00
|
|
|
else
|
|
|
|
begin
|
2020-12-20 12:28:56 +01:00
|
|
|
TempDC := GetWindowDC(TempHandle);
|
|
|
|
aResultScale := GetDeviceCaps(TempDC, LOGPIXELSX) / USER_DEFAULT_SCREEN_DPI;
|
2020-10-31 14:23:06 +01:00
|
|
|
ReleaseDC(TempHandle, TempDC);
|
|
|
|
end;
|
2020-12-20 12:28:56 +01:00
|
|
|
end;
|
2021-02-16 12:47:22 +01:00
|
|
|
{$ENDIF}
|
2020-12-28 18:11:27 +01:00
|
|
|
|
2021-02-16 12:47:22 +01:00
|
|
|
{$IFDEF LINUX}
|
|
|
|
{$IFDEF FPC}
|
|
|
|
TempForm := GetParentForm(self, True);
|
2020-12-28 18:11:27 +01:00
|
|
|
|
2021-02-16 12:47:22 +01:00
|
|
|
if (TempForm <> nil) then
|
|
|
|
begin
|
|
|
|
TempMonitor := TempForm.Monitor;
|
|
|
|
|
|
|
|
if (TempMonitor <> nil) and (TempMonitor.PixelsPerInch > 0) then
|
|
|
|
begin
|
|
|
|
aResultScale := TempMonitor.PixelsPerInch / USER_DEFAULT_SCREEN_DPI;
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{$ELSE}
|
2021-06-24 17:47:22 +02:00
|
|
|
// TODO: Get the scale of the screen where the parent form is located in FMXLinux
|
2021-02-16 12:47:22 +01:00
|
|
|
{$ENDIF}
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF MACOSX}
|
|
|
|
{$IFDEF FPC}
|
2021-06-24 17:47:22 +02:00
|
|
|
TempForm := GetParentForm(self, True);
|
|
|
|
|
|
|
|
if (TempForm <> nil) then
|
|
|
|
begin
|
|
|
|
TempMonitor := TempForm.Monitor;
|
|
|
|
|
|
|
|
if (TempMonitor <> nil) and (TempMonitor.PixelsPerInch > 0) then
|
|
|
|
begin
|
|
|
|
aResultScale := TempMonitor.PixelsPerInch / USER_DEFAULT_SCREEN_DPI;
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
end;
|
2021-02-16 12:47:22 +01:00
|
|
|
{$ELSE}
|
2021-06-24 17:47:22 +02:00
|
|
|
Result := True;
|
|
|
|
aResultScale := TMacWindowHandle(GetParentForm.Handle).Wnd.backingScaleFactor;
|
2020-12-28 18:11:27 +01:00
|
|
|
{$ENDIF}
|
2020-03-31 12:44:10 +02:00
|
|
|
{$ENDIF}
|
2020-12-20 12:28:56 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TBufferPanel.GetScreenScale : single;
|
|
|
|
begin
|
|
|
|
if (FForcedDeviceScaleFactor <> 0) then
|
|
|
|
Result := FForcedDeviceScaleFactor
|
|
|
|
else
|
2021-02-16 12:47:22 +01:00
|
|
|
if (FDeviceScaleFactor <> 0) then
|
|
|
|
Result := FDeviceScaleFactor
|
2020-03-31 12:44:10 +02:00
|
|
|
else
|
2020-12-20 12:28:56 +01:00
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
Result := GlobalCEFApp.DeviceScaleFactor
|
|
|
|
else
|
|
|
|
Result := 1;
|
2020-03-31 12:44:10 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
function TBufferPanel.GetParentForm : TCustomForm;
|
|
|
|
var
|
|
|
|
TempComp : TComponent;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
TempComp := Owner;
|
|
|
|
|
|
|
|
while (TempComp <> nil) do
|
|
|
|
if (TempComp is TCustomForm) then
|
|
|
|
begin
|
|
|
|
Result := TCustomForm(TempComp);
|
|
|
|
exit;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
TempComp := TempComp.owner;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TBufferPanel.GetParentFormHandle : TCefWindowHandle;
|
|
|
|
var
|
|
|
|
TempForm : TCustomForm;
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
TempForm := GetParentForm;
|
|
|
|
|
|
|
|
if (TempForm <> nil) then
|
|
|
|
Result := TempForm.Handle
|
|
|
|
else
|
|
|
|
if (Application <> nil) and
|
|
|
|
(Application.MainForm <> nil) then
|
|
|
|
Result := Application.MainForm.Handle;
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2019-02-20 12:44:07 +01:00
|
|
|
procedure TBufferPanel.SetTransparent(aValue : boolean);
|
|
|
|
begin
|
|
|
|
if (FTransparent <> aValue) then
|
|
|
|
begin
|
|
|
|
FTransparent := aValue;
|
|
|
|
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
RecreateWnd{$IFDEF FPC}(self){$ENDIF};
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
procedure TBufferPanel.BufferDraw(x, y : integer; const aBitmap : TBitmap);
|
|
|
|
begin
|
|
|
|
if (FBuffer <> nil) then FBuffer.Canvas.Draw(x, y, aBitmap);
|
|
|
|
end;
|
|
|
|
|
2020-03-18 18:37:55 +01:00
|
|
|
procedure TBufferPanel.BufferDraw(const aBitmap : TBitmap; const aSrcRect, aDstRect : TRect);
|
|
|
|
begin
|
2021-01-21 19:32:43 +01:00
|
|
|
if (FBuffer <> nil) and (aBitmap <> nil) then
|
|
|
|
begin
|
|
|
|
FBuffer.Canvas.Lock;
|
|
|
|
aBitmap.Canvas.Lock;
|
|
|
|
FBuffer.Canvas.CopyRect(aDstRect, aBitmap.Canvas, aSrcRect);
|
|
|
|
aBitmap.Canvas.UnLock;
|
|
|
|
FBuffer.Canvas.UnLock;
|
|
|
|
end;
|
2020-03-18 18:37:55 +01:00
|
|
|
end;
|
|
|
|
|
2017-11-19 11:30:26 +01:00
|
|
|
function TBufferPanel.UpdateBufferDimensions(aWidth, aHeight : integer) : boolean;
|
|
|
|
begin
|
2017-12-27 14:05:33 +01:00
|
|
|
Result := False;
|
|
|
|
|
2021-01-03 18:36:17 +01:00
|
|
|
if (FBuffer = nil) then
|
2017-11-19 11:30:26 +01:00
|
|
|
begin
|
|
|
|
FBuffer := TBitmap.Create;
|
|
|
|
FBuffer.PixelFormat := pf32bit;
|
2021-01-03 18:36:17 +01:00
|
|
|
FBuffer.HandleType := bmDIB;
|
2017-11-19 11:30:26 +01:00
|
|
|
FBuffer.Width := aWidth;
|
|
|
|
FBuffer.Height := aHeight;
|
2020-12-28 18:11:27 +01:00
|
|
|
FScanlineSize := aWidth * SizeOf(TRGBQuad);
|
2021-01-12 17:06:31 +01:00
|
|
|
|
|
|
|
if FMustInitBuffer then
|
|
|
|
begin
|
|
|
|
FBuffer.Canvas.Brush.Color := clWhite;
|
|
|
|
FBuffer.Canvas.FillRect(rect(0, 0, FBuffer.Width, FBuffer.Height));
|
|
|
|
end;
|
2019-02-20 12:44:07 +01:00
|
|
|
|
2020-12-28 18:11:27 +01:00
|
|
|
Result := True;
|
2021-01-03 18:36:17 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
if (FBuffer.Width <> aWidth) or
|
|
|
|
(FBuffer.Height <> aHeight) then
|
|
|
|
begin
|
|
|
|
FBuffer.Width := aWidth;
|
|
|
|
FBuffer.Height := aHeight;
|
|
|
|
FScanlineSize := aWidth * SizeOf(TRGBQuad);
|
2021-01-12 17:06:31 +01:00
|
|
|
|
|
|
|
if FMustInitBuffer then
|
|
|
|
begin
|
|
|
|
FBuffer.Canvas.Brush.Color := clWhite;
|
|
|
|
FBuffer.Canvas.FillRect(rect(0, 0, FBuffer.Width, FBuffer.Height));
|
|
|
|
end;
|
2021-01-03 18:36:17 +01:00
|
|
|
|
|
|
|
Result := True;
|
|
|
|
end;
|
2021-01-12 17:06:31 +01:00
|
|
|
end;
|
2020-12-28 18:11:27 +01:00
|
|
|
|
2021-01-12 17:06:31 +01:00
|
|
|
function TBufferPanel.UpdateOrigBufferDimensions(aWidth, aHeight : integer) : boolean;
|
2020-12-28 18:11:27 +01:00
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
2021-01-12 17:06:31 +01:00
|
|
|
if (FOrigBuffer = nil) then
|
2020-12-28 18:11:27 +01:00
|
|
|
begin
|
2021-01-12 17:06:31 +01:00
|
|
|
FOrigBuffer := TCEFBitmapBitBuffer.Create(aWidth, aHeight);
|
|
|
|
FScanlineSize := FOrigBuffer.ScanlineSize;
|
|
|
|
Result := True;
|
2021-01-03 18:36:17 +01:00
|
|
|
end
|
|
|
|
else
|
2021-01-12 17:06:31 +01:00
|
|
|
if (FOrigBuffer.Width <> aWidth) or
|
|
|
|
(FOrigBuffer.Height <> aHeight) then
|
2021-01-03 18:36:17 +01:00
|
|
|
begin
|
2021-01-12 17:06:31 +01:00
|
|
|
FOrigBuffer.UpdateSize(aWidth, aHeight);
|
|
|
|
FScanlineSize := FOrigBuffer.ScanlineSize;
|
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TBufferPanel.UpdateOrigPopupBufferDimensions(aWidth, aHeight : integer) : boolean;
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
if (FOrigPopupBuffer = nil) then
|
|
|
|
begin
|
|
|
|
FOrigPopupBuffer := TCEFBitmapBitBuffer.Create(aWidth, aHeight);
|
|
|
|
FOrigPopupScanlineSize := FOrigPopupBuffer.ScanlineSize;
|
|
|
|
Result := True;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if (FOrigPopupBuffer.Width <> aWidth) or
|
|
|
|
(FOrigPopupBuffer.Height <> aHeight) then
|
|
|
|
begin
|
|
|
|
FOrigPopupBuffer.UpdateSize(aWidth, aHeight);
|
|
|
|
FOrigPopupScanlineSize := FOrigPopupBuffer.ScanlineSize;
|
|
|
|
Result := True;
|
2021-01-03 18:36:17 +01:00
|
|
|
end;
|
2017-11-19 11:30:26 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TBufferPanel.BufferIsResized(aUseMutex : boolean) : boolean;
|
2018-01-25 21:34:04 +01:00
|
|
|
var
|
|
|
|
TempDevWidth, TempLogWidth, TempDevHeight, TempLogHeight : integer;
|
2020-03-31 12:44:10 +02:00
|
|
|
TempScale : single;
|
2017-11-19 11:30:26 +01:00
|
|
|
begin
|
|
|
|
Result := False;
|
2018-05-24 19:15:41 +02:00
|
|
|
if (GlobalCEFApp = nil) then exit;
|
2017-11-19 11:30:26 +01:00
|
|
|
|
|
|
|
if not(aUseMutex) or BeginBufferDraw then
|
|
|
|
begin
|
2020-03-31 12:44:10 +02:00
|
|
|
TempScale := ScreenScale;
|
|
|
|
|
|
|
|
if (TempScale = 1) then
|
2018-01-25 21:34:04 +01:00
|
|
|
begin
|
2021-01-12 17:06:31 +01:00
|
|
|
if FCopyOriginalBuffer then
|
|
|
|
Result := (FOrigBuffer <> nil) and
|
|
|
|
(FOrigBuffer.Width = Width) and
|
|
|
|
(FOrigBuffer.Height = Height)
|
|
|
|
else
|
|
|
|
Result := (FBuffer <> nil) and
|
|
|
|
(FBuffer.Width = Width) and
|
|
|
|
(FBuffer.Height = Height);
|
2018-01-25 21:34:04 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
// CEF and Chromium use 'floor' to round the float values in Device <-> Logical unit conversions
|
|
|
|
// and Delphi uses MulDiv, which uses the bankers rounding, to resize the components in high DPI mode.
|
|
|
|
// This is the cause of slight differences in size between the buffer and the panel in some occasions.
|
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
TempLogWidth := DeviceToLogical(Width, TempScale);
|
|
|
|
TempLogHeight := DeviceToLogical(Height, TempScale);
|
2018-01-25 21:34:04 +01:00
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
TempDevWidth := LogicalToDevice(TempLogWidth, TempScale);
|
|
|
|
TempDevHeight := LogicalToDevice(TempLogHeight, TempScale);
|
|
|
|
|
2021-01-12 17:06:31 +01:00
|
|
|
if FCopyOriginalBuffer then
|
|
|
|
Result := (FOrigBuffer <> nil) and
|
|
|
|
(FOrigBuffer.Width = TempDevWidth) and
|
|
|
|
(FOrigBuffer.Height = TempDevHeight)
|
|
|
|
else
|
|
|
|
Result := (FBuffer <> nil) and
|
|
|
|
(FBuffer.Width = TempDevWidth) and
|
|
|
|
(FBuffer.Height = TempDevHeight);
|
2018-01-25 21:34:04 +01:00
|
|
|
end;
|
2017-11-19 11:30:26 +01:00
|
|
|
|
|
|
|
if aUseMutex then EndBufferDraw;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
procedure Register;
|
|
|
|
begin
|
2018-06-03 17:18:54 +02:00
|
|
|
{$I res/tbufferpanel.lrs}
|
2018-05-12 14:50:54 +02:00
|
|
|
RegisterComponents('Chromium', [TBufferPanel]);
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-11-16 12:49:15 +01:00
|
|
|
end.
|