2017-11-16 13:49:15 +02:00
|
|
|
// ************************************************************************
|
|
|
|
// ***************************** CEF4Delphi *******************************
|
|
|
|
// ************************************************************************
|
|
|
|
//
|
2019-10-19 10:58:34 +02:00
|
|
|
// CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
|
2017-11-16 13:49:15 +02:00
|
|
|
// browser in Delphi applications.
|
|
|
|
//
|
|
|
|
// The original license of DCEF3 still applies to CEF4Delphi.
|
|
|
|
//
|
|
|
|
// For more information about CEF4Delphi visit :
|
|
|
|
// https://www.briskbard.com/index.php?lang=en&pageid=cef
|
|
|
|
//
|
2020-01-01 13:48:10 +02:00
|
|
|
// Copyright � 2020 Salvador Diaz Fau. All rights reserved.
|
2017-11-16 13:49:15 +02:00
|
|
|
//
|
|
|
|
// ************************************************************************
|
|
|
|
// ************ vvvv Original license and comments below vvvv *************
|
|
|
|
// ************************************************************************
|
|
|
|
(*
|
|
|
|
* Delphi Chromium Embedded 3
|
|
|
|
*
|
|
|
|
* Usage allowed under the restrictions of the Lesser GNU General Public License
|
|
|
|
* or alternatively the restrictions of the Mozilla Public License 1.1
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
|
|
|
* the specific language governing rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
|
|
|
|
* Web site : http://www.progdigy.com
|
|
|
|
* Repository : http://code.google.com/p/delphichromiumembedded/
|
|
|
|
* Group : http://groups.google.com/group/delphichromiumembedded
|
|
|
|
*
|
|
|
|
* Embarcadero Technologies, Inc is not permitted to use or redistribute
|
|
|
|
* this source code without explicit permission.
|
|
|
|
*
|
|
|
|
*)
|
|
|
|
|
2019-04-04 10:26:44 +02:00
|
|
|
unit uCEFBufferPanel;
|
2017-11-16 13:49:15 +02:00
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-11-16 13:49:15 +02: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 13:49:15 +02:00
|
|
|
{$ELSE}
|
2019-01-08 20:15:25 +02: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 13:49:15 +02:00
|
|
|
{$ENDIF}
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}uCEFOSRIMEHandler,{$ENDIF} uCEFConstants, uCEFTypes;
|
2017-11-16 13:49:15 +02:00
|
|
|
|
|
|
|
type
|
2019-01-08 20:15:25 +02: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 12:50:38 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2020-02-03 13:02:30 +02:00
|
|
|
TOnHandledMessageEvent = procedure(Sender: TObject; var aMessage: TMessage; var aHandled : boolean) of object;
|
2020-02-04 12:50:38 +02:00
|
|
|
{$ENDIF}
|
2019-01-08 20:15:25 +02:00
|
|
|
|
2018-12-09 12:11:59 +02:00
|
|
|
{$IFNDEF FPC}{$IFDEF DELPHI16_UP}[ComponentPlatformsAttribute(pidWin32 or pidWin64)]{$ENDIF}{$ENDIF}
|
2017-11-16 13:49:15 +02:00
|
|
|
TBufferPanel = class(TCustomPanel)
|
|
|
|
protected
|
2019-01-08 20:15:25 +02:00
|
|
|
FMutex : THandle;
|
|
|
|
FBuffer : TBitmap;
|
|
|
|
FScanlineSize : integer;
|
2019-02-20 13:44:07 +02:00
|
|
|
FTransparent : boolean;
|
|
|
|
FOnPaintParentBkg : TNotifyEvent;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
FIMEHandler : TCEFOSRIMEHandler;
|
|
|
|
FOnIMECancelComposition : TNotifyEvent;
|
|
|
|
FOnIMECommitText : TOnIMECommitTextEvent;
|
|
|
|
FOnIMESetComposition : TOnIMESetCompositionEvent;
|
2020-02-03 13:02:30 +02:00
|
|
|
FOnCustomTouch : TOnHandledMessageEvent;
|
|
|
|
FOnPointerDown : TOnHandledMessageEvent;
|
|
|
|
FOnPointerUp : TOnHandledMessageEvent;
|
|
|
|
FOnPointerUpdate : TOnHandledMessageEvent;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ENDIF}
|
2017-11-16 13:49:15 +02:00
|
|
|
|
2018-01-25 22:34:04 +02:00
|
|
|
procedure CreateSyncObj;
|
2017-12-27 15:05:33 +02:00
|
|
|
|
2018-01-25 22:34:04 +02:00
|
|
|
procedure DestroySyncObj;
|
2017-12-27 15:05:33 +02:00
|
|
|
procedure DestroyBuffer;
|
|
|
|
|
2017-11-16 13:49:15 +02:00
|
|
|
function GetBufferBits : pointer;
|
|
|
|
function GetBufferWidth : integer;
|
|
|
|
function GetBufferHeight : integer;
|
2020-03-31 12:44:10 +02:00
|
|
|
function GetScreenScale : single;
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
function GetParentFormHandle : TCefWindowHandle;
|
|
|
|
function GetParentForm : TCustomForm;
|
|
|
|
{$ENDIF}
|
2017-11-16 13:49:15 +02:00
|
|
|
|
2019-02-20 13:44:07 +02:00
|
|
|
procedure SetTransparent(aValue : boolean);
|
|
|
|
|
2017-12-27 15:05:33 +02:00
|
|
|
function CopyBuffer : boolean;
|
2017-11-16 13:49:15 +02:00
|
|
|
function SaveBufferToFile(const aFilename : string) : boolean;
|
|
|
|
|
2017-12-27 15:05:33 +02:00
|
|
|
procedure Paint; override;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2019-02-20 13:44:07 +02:00
|
|
|
procedure CreateParams(var Params: TCreateParams); override;
|
2019-01-08 20:15:25 +02:00
|
|
|
procedure WndProc(var aMessage: TMessage); override;
|
2017-11-16 13:49:15 +02:00
|
|
|
procedure WMEraseBkgnd(var aMessage : TWMEraseBkgnd); message WM_ERASEBKGND;
|
2020-02-03 13:02:30 +02: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 20:15:25 +02:00
|
|
|
procedure WMIMEStartComp(var aMessage: TMessage);
|
|
|
|
procedure WMIMEEndComp(var aMessage: TMessage);
|
|
|
|
procedure WMIMESetContext(var aMessage: TMessage);
|
|
|
|
procedure WMIMEComposition(var aMessage: TMessage);
|
|
|
|
{$ENDIF}
|
2017-11-16 13:49:15 +02:00
|
|
|
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure AfterConstruction; override;
|
|
|
|
function SaveToFile(const aFilename : string) : boolean;
|
2017-12-27 15:05:33 +02:00
|
|
|
function InvalidatePanel : boolean;
|
2017-11-16 13:49:15 +02:00
|
|
|
function BeginBufferDraw : boolean;
|
|
|
|
procedure EndBufferDraw;
|
2020-03-18 19:37:55 +02:00
|
|
|
procedure BufferDraw(x, y : integer; const aBitmap : TBitmap); overload;
|
|
|
|
procedure BufferDraw(const aBitmap : TBitmap; const aSrcRect, aDstRect : TRect); overload;
|
2017-11-19 12:30:26 +02:00
|
|
|
function UpdateBufferDimensions(aWidth, aHeight : integer) : boolean;
|
|
|
|
function BufferIsResized(aUseMutex : boolean = True) : boolean;
|
2019-01-08 20:15:25 +02:00
|
|
|
procedure CreateIMEHandler;
|
|
|
|
procedure ChangeCompositionRange(const selection_range : TCefRange; const character_bounds : TCefRectDynArray);
|
2017-11-16 13:49:15 +02:00
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
property Buffer : TBitmap read FBuffer;
|
|
|
|
property ScanlineSize : integer read FScanlineSize;
|
|
|
|
property BufferWidth : integer read GetBufferWidth;
|
|
|
|
property BufferHeight : integer read GetBufferHeight;
|
|
|
|
property BufferBits : pointer read GetBufferBits;
|
|
|
|
property ScreenScale : single read GetScreenScale;
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
property ParentFormHandle : TCefWindowHandle read GetParentFormHandle;
|
|
|
|
property ParentForm : TCustomForm read GetParentForm;
|
|
|
|
{$ENDIF}
|
2017-11-16 13:49:15 +02:00
|
|
|
|
|
|
|
property DockManager;
|
2019-02-20 13:44:07 +02:00
|
|
|
property Canvas;
|
2017-11-16 13:49:15 +02:00
|
|
|
|
|
|
|
published
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
property OnIMECancelComposition : TNotifyEvent read FOnIMECancelComposition write FOnIMECancelComposition;
|
|
|
|
property OnIMECommitText : TOnIMECommitTextEvent read FOnIMECommitText write FOnIMECommitText;
|
|
|
|
property OnIMESetComposition : TOnIMESetCompositionEvent read FOnIMESetComposition write FOnIMESetComposition;
|
2020-02-03 13:02:30 +02:00
|
|
|
property OnCustomTouch : TOnHandledMessageEvent read FOnCustomTouch write FOnCustomTouch;
|
|
|
|
property OnPointerDown : TOnHandledMessageEvent read FOnPointerDown write FOnPointerDown;
|
|
|
|
property OnPointerUp : TOnHandledMessageEvent read FOnPointerUp write FOnPointerUp;
|
|
|
|
property OnPointerUpdate : TOnHandledMessageEvent read FOnPointerUpdate write FOnPointerUpdate;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ENDIF}
|
2019-02-20 13:44:07 +02:00
|
|
|
property OnPaintParentBkg : TNotifyEvent read FOnPaintParentBkg write FOnPaintParentBkg;
|
|
|
|
|
|
|
|
property Transparent : boolean read FTransparent write SetTransparent default False;
|
2019-01-08 20:15:25 +02:00
|
|
|
|
2017-11-16 13:49:15 +02: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 13:49:15 +02:00
|
|
|
property BevelEdges;
|
2018-06-18 21:57:18 +02:00
|
|
|
property BevelKind;
|
|
|
|
property Ctl3D;
|
|
|
|
property Locked;
|
|
|
|
property ParentBackground;
|
|
|
|
property ParentCtl3D;
|
2018-05-12 14:50:54 +02:00
|
|
|
property OnCanResize;
|
|
|
|
{$ENDIF}
|
2017-11-16 13:49:15 +02: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 14:35:01 +02:00
|
|
|
property OnKeyDown;
|
|
|
|
property OnKeyPress;
|
|
|
|
property OnKeyUp;
|
2017-11-16 13:49:15 +02: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}
|
|
|
|
{$IFDEF DELPHI12_UP}
|
2017-11-27 21:53:54 +02:00
|
|
|
property ShowCaption;
|
2017-11-16 13:49:15 +02: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 13:49:15 +02:00
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2019-11-09 00:15:53 +02:00
|
|
|
uCEFMiscFunctions, uCEFApplicationCore;
|
2017-11-16 13:49:15 +02:00
|
|
|
|
|
|
|
constructor TBufferPanel.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner);
|
|
|
|
|
2020-02-08 13:59:59 +02:00
|
|
|
FMutex := 0;
|
|
|
|
FBuffer := nil;
|
|
|
|
FTransparent := False;
|
|
|
|
FOnPaintParentBkg := nil;
|
2019-01-08 20:15:25 +02:00
|
|
|
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
FIMEHandler := nil;
|
|
|
|
FOnIMECancelComposition := nil;
|
|
|
|
FOnIMECommitText := nil;
|
|
|
|
FOnIMESetComposition := nil;
|
2020-02-03 13:02:30 +02:00
|
|
|
FOnCustomTouch := nil;
|
|
|
|
FOnPointerDown := nil;
|
|
|
|
FOnPointerUp := nil;
|
|
|
|
FOnPointerUpdate := nil;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ENDIF}
|
2017-11-16 13:49:15 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TBufferPanel.Destroy;
|
|
|
|
begin
|
|
|
|
DestroyBuffer;
|
2018-01-25 22:34:04 +02:00
|
|
|
DestroySyncObj;
|
2017-11-16 13:49:15 +02:00
|
|
|
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
if (FIMEHandler <> nil) then FreeAndNil(FIMEHandler);
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-11-16 13:49:15 +02:00
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBufferPanel.AfterConstruction;
|
|
|
|
begin
|
|
|
|
inherited AfterConstruction;
|
|
|
|
|
2018-01-25 22:34:04 +02:00
|
|
|
CreateSyncObj;
|
2019-01-08 20:15:25 +02: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 15:05:33 +02:00
|
|
|
end;
|
|
|
|
|
2018-01-25 22:34:04 +02:00
|
|
|
procedure TBufferPanel.CreateSyncObj;
|
2017-12-27 15:05:33 +02:00
|
|
|
begin
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2017-11-16 13:49:15 +02:00
|
|
|
FMutex := CreateMutex(nil, False, nil);
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ENDIF}
|
2017-11-16 13:49:15 +02:00
|
|
|
end;
|
|
|
|
|
2018-01-25 22:34:04 +02:00
|
|
|
procedure TBufferPanel.DestroySyncObj;
|
2017-12-27 15:05:33 +02:00
|
|
|
begin
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2017-12-27 15:05:33 +02:00
|
|
|
if (FMutex <> 0) then
|
|
|
|
begin
|
|
|
|
CloseHandle(FMutex);
|
|
|
|
FMutex := 0;
|
|
|
|
end;
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ENDIF}
|
2017-12-27 15:05:33 +02:00
|
|
|
end;
|
|
|
|
|
2017-11-16 13:49:15 +02:00
|
|
|
procedure TBufferPanel.DestroyBuffer;
|
|
|
|
begin
|
|
|
|
if BeginBufferDraw then
|
|
|
|
begin
|
|
|
|
if (FBuffer <> nil) then FreeAndNil(FBuffer);
|
|
|
|
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 15:05:33 +02:00
|
|
|
Result := False;
|
|
|
|
|
2017-11-16 13:49:15 +02:00
|
|
|
if BeginBufferDraw then
|
|
|
|
begin
|
|
|
|
Result := SaveBufferToFile(aFilename);
|
|
|
|
EndBufferDraw;
|
2017-12-27 15:05:33 +02:00
|
|
|
end;
|
2017-11-16 13:49:15 +02:00
|
|
|
end;
|
|
|
|
|
2017-12-27 15:05:33 +02:00
|
|
|
function TBufferPanel.InvalidatePanel : boolean;
|
2017-11-16 13:49:15 +02:00
|
|
|
begin
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2017-12-27 15:05:33 +02:00
|
|
|
Result := HandleAllocated and PostMessage(Handle, CM_INVALIDATE, 0, 0);
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ENDIF}
|
2017-11-16 13:49:15 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TBufferPanel.BeginBufferDraw : boolean;
|
|
|
|
begin
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2017-11-16 13:49:15 +02:00
|
|
|
Result := (FMutex <> 0) and (WaitForSingleObject(FMutex, 5000) = WAIT_OBJECT_0);
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ENDIF}
|
2017-11-16 13:49:15 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TBufferPanel.EndBufferDraw;
|
|
|
|
begin
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2017-11-16 13:49:15 +02:00
|
|
|
if (FMutex <> 0) then ReleaseMutex(FMutex);
|
2019-01-08 20:15:25 +02:00
|
|
|
{$ENDIF}
|
2017-11-16 13:49:15 +02:00
|
|
|
end;
|
|
|
|
|
2017-12-27 15:05:33 +02:00
|
|
|
function TBufferPanel.CopyBuffer : boolean;
|
2020-04-03 17:57:52 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2019-02-20 13:44:07 +02:00
|
|
|
var
|
2020-02-08 13:59:59 +02:00
|
|
|
TempFunction : TBlendFunction;
|
2020-04-03 17:57:52 +02:00
|
|
|
{$ENDIF}
|
2017-11-16 13:49:15 +02:00
|
|
|
begin
|
2020-03-29 17:31:42 +02:00
|
|
|
Result := False;
|
2020-02-08 13:59:59 +02:00
|
|
|
|
2019-05-04 09:53:50 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2017-11-16 13:49:15 +02:00
|
|
|
if BeginBufferDraw then
|
2019-02-20 13:44:07 +02:00
|
|
|
try
|
|
|
|
if (FBuffer <> nil) then
|
|
|
|
begin
|
|
|
|
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);
|
|
|
|
end;
|
|
|
|
finally
|
2017-11-16 13:49:15 +02:00
|
|
|
EndBufferDraw;
|
|
|
|
end;
|
2019-05-04 09:53:50 +02:00
|
|
|
{$ENDIF}
|
2017-11-16 13:49:15 +02:00
|
|
|
end;
|
|
|
|
|
2017-12-27 15:05:33 +02:00
|
|
|
procedure TBufferPanel.Paint;
|
2017-11-16 13:49:15 +02:00
|
|
|
begin
|
2017-12-27 15:05:33 +02: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 13:49:15 +02:00
|
|
|
|
2017-12-27 15:05:33 +02:00
|
|
|
Canvas.Rectangle(0, 0, Width, Height);
|
|
|
|
end
|
|
|
|
else
|
2019-02-20 13:44:07 +02:00
|
|
|
if not(CopyBuffer) and not(FTransparent) then
|
2017-11-16 13:49:15 +02:00
|
|
|
begin
|
|
|
|
Canvas.Brush.Color := Color;
|
|
|
|
Canvas.Brush.Style := bsSolid;
|
2017-12-27 15:05:33 +02:00
|
|
|
Canvas.FillRect(rect(0, 0, Width, Height));
|
|
|
|
end;
|
2017-11-16 13:49:15 +02:00
|
|
|
end;
|
|
|
|
|
2019-01-08 20:15:25 +02:00
|
|
|
{$IFDEF MSWINDOWS}
|
2019-02-20 13:44:07 +02: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 20:15:25 +02: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;
|
|
|
|
|
2017-11-16 13:49:15 +02:00
|
|
|
procedure TBufferPanel.WMEraseBkgnd(var aMessage : TWMEraseBkgnd);
|
|
|
|
begin
|
|
|
|
aMessage.Result := 1;
|
|
|
|
end;
|
|
|
|
|
2020-02-03 13:02:30 +02: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 20:15:25 +02: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
|
|
|
|
if assigned(FOnIMECancelComposition) then FOnIMECancelComposition(self);
|
|
|
|
|
|
|
|
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);
|
|
|
|
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
|
|
|
|
TempRange.from := high(Integer);
|
|
|
|
TempRange.to_ := high(Integer);
|
|
|
|
|
|
|
|
FOnIMECommitText(self, TempText, @TempRange, 0);
|
|
|
|
end;
|
|
|
|
|
|
|
|
FIMEHandler.ResetComposition;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if FIMEHandler.GetComposition(aMessage.LParam, TempText, TempUnderlines, TempCompStart) then
|
|
|
|
begin
|
|
|
|
if assigned(FOnIMESetComposition) then
|
|
|
|
begin
|
|
|
|
TempRange.from := high(Integer);
|
|
|
|
TempRange.to_ := high(Integer);
|
|
|
|
|
|
|
|
TempSelection.from := TempCompStart;
|
|
|
|
TempSelection.to_ := TempCompStart + length(TempText);
|
|
|
|
|
|
|
|
FOnIMESetComposition(self, TempText, TempUnderlines, TempRange, TempSelection);
|
|
|
|
end;
|
|
|
|
|
|
|
|
FIMEHandler.UpdateCaretPosition(pred(TempCompStart));
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
if assigned(FOnIMECancelComposition) then FOnIMECancelComposition(self);
|
|
|
|
|
|
|
|
FIMEHandler.ResetComposition;
|
|
|
|
FIMEHandler.DestroyImeWindow;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
if (TempUnderlines <> nil) then
|
|
|
|
begin
|
|
|
|
Finalize(TempUnderlines);
|
|
|
|
TempUnderlines := nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-11-16 13:49:15 +02:00
|
|
|
function TBufferPanel.GetBufferBits : pointer;
|
|
|
|
begin
|
|
|
|
if (FBuffer <> nil) then
|
|
|
|
Result := FBuffer.Scanline[pred(FBuffer.Height)]
|
|
|
|
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;
|
|
|
|
end;
|
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
function TBufferPanel.GetScreenScale : single;
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
var
|
|
|
|
TempHandle : TCefWindowHandle;
|
|
|
|
TempDC : HDC;
|
|
|
|
{$ENDIF}
|
|
|
|
begin
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
TempHandle := ParentFormHandle;
|
|
|
|
|
|
|
|
if (TempHandle <> 0) then
|
|
|
|
begin
|
|
|
|
TempDC := GetWindowDC(TempHandle);
|
|
|
|
Result := GetDeviceCaps(TempDC, LOGPIXELSX) / USER_DEFAULT_SCREEN_DPI;
|
|
|
|
ReleaseDC(TempHandle, TempDC);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
{$ENDIF}
|
|
|
|
if (GlobalCEFApp <> nil) then
|
|
|
|
Result := GlobalCEFApp.DeviceScaleFactor
|
|
|
|
else
|
|
|
|
Result := 1;
|
|
|
|
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 13:44:07 +02: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 13:49:15 +02: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 19:37:55 +02:00
|
|
|
procedure TBufferPanel.BufferDraw(const aBitmap : TBitmap; const aSrcRect, aDstRect : TRect);
|
|
|
|
begin
|
|
|
|
if (FBuffer <> nil) then FBuffer.Canvas.CopyRect(aDstRect, aBitmap.Canvas, aSrcRect);
|
|
|
|
end;
|
|
|
|
|
2017-11-19 12:30:26 +02:00
|
|
|
function TBufferPanel.UpdateBufferDimensions(aWidth, aHeight : integer) : boolean;
|
|
|
|
begin
|
2017-12-27 15:05:33 +02:00
|
|
|
Result := False;
|
|
|
|
|
2017-11-19 12:30:26 +02:00
|
|
|
if ((FBuffer = nil) or
|
|
|
|
(FBuffer.Width <> aWidth) or
|
|
|
|
(FBuffer.Height <> aHeight)) then
|
|
|
|
begin
|
|
|
|
if (FBuffer <> nil) then FreeAndNil(FBuffer);
|
|
|
|
|
|
|
|
FBuffer := TBitmap.Create;
|
|
|
|
FBuffer.PixelFormat := pf32bit;
|
|
|
|
FBuffer.HandleType := bmDIB;
|
|
|
|
FBuffer.Width := aWidth;
|
|
|
|
FBuffer.Height := aHeight;
|
2019-02-20 13:44:07 +02:00
|
|
|
|
|
|
|
FScanlineSize := FBuffer.Width * SizeOf(TRGBQuad);
|
|
|
|
Result := True;
|
2017-12-27 15:05:33 +02:00
|
|
|
end;
|
2017-11-19 12:30:26 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TBufferPanel.BufferIsResized(aUseMutex : boolean) : boolean;
|
2018-01-25 22:34:04 +02:00
|
|
|
var
|
|
|
|
TempDevWidth, TempLogWidth, TempDevHeight, TempLogHeight : integer;
|
2020-03-31 12:44:10 +02:00
|
|
|
TempScale : single;
|
2017-11-19 12:30:26 +02:00
|
|
|
begin
|
|
|
|
Result := False;
|
2018-05-24 19:15:41 +02:00
|
|
|
if (GlobalCEFApp = nil) then exit;
|
2017-11-19 12:30:26 +02: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 22:34:04 +02:00
|
|
|
begin
|
|
|
|
Result := (FBuffer <> nil) and
|
|
|
|
(FBuffer.Width = Width) and
|
|
|
|
(FBuffer.Height = Height);
|
|
|
|
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 22:34:04 +02:00
|
|
|
|
2020-03-31 12:44:10 +02:00
|
|
|
TempDevWidth := LogicalToDevice(TempLogWidth, TempScale);
|
|
|
|
TempDevHeight := LogicalToDevice(TempLogHeight, TempScale);
|
|
|
|
|
2018-01-25 22:34:04 +02:00
|
|
|
Result := (FBuffer <> nil) and
|
|
|
|
(FBuffer.Width = TempDevWidth) and
|
|
|
|
(FBuffer.Height = TempDevHeight);
|
|
|
|
end;
|
2017-11-19 12:30:26 +02: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 13:49:15 +02:00
|
|
|
end.
|