2018-09-16 10:39:41 +02:00
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ***************************** CEF4Delphi *******************************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
//
|
2019-10-19 10:58:34 +02:00
|
|
|
|
// CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
|
2018-09-16 10:39:41 +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 12:48:10 +01:00
|
|
|
|
// Copyright <20> 2020 Salvador Diaz Fau. All rights reserved.
|
2018-09-16 10:39:41 +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.
|
|
|
|
|
*
|
|
|
|
|
*)
|
|
|
|
|
|
|
|
|
|
unit uCEFWinControl;
|
|
|
|
|
|
|
|
|
|
{$IFDEF FPC}
|
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
2018-11-22 15:02:21 +01:00
|
|
|
|
{$IFNDEF CPUX64}{$ALIGN ON}{$ENDIF}
|
|
|
|
|
{$MINENUMSIZE 4}
|
2018-09-16 10:39:41 +02:00
|
|
|
|
|
|
|
|
|
{$I cef.inc}
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
|
{$IFDEF MSWINDOWS}WinApi.Windows, {$ENDIF} System.Classes, Vcl.Controls, Vcl.Graphics,
|
|
|
|
|
{$ELSE}
|
|
|
|
|
{$IFDEF MSWINDOWS}Windows,{$ENDIF} Classes, Forms, Controls, Graphics,
|
|
|
|
|
{$IFDEF FPC}
|
|
|
|
|
LCLProc, LCLType, LCLIntf, LResources, InterfaceBase,
|
|
|
|
|
{$ENDIF}
|
|
|
|
|
{$ENDIF}
|
|
|
|
|
uCEFTypes, uCEFInterfaces;
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
TCEFWinControl = class(TWinControl)
|
|
|
|
|
protected
|
|
|
|
|
function GetChildWindowHandle : THandle; virtual;
|
|
|
|
|
procedure Resize; override;
|
|
|
|
|
|
|
|
|
|
public
|
2019-03-15 17:17:14 +01:00
|
|
|
|
function TakeSnapshot(var aBitmap : TBitmap) : boolean;
|
|
|
|
|
function DestroyChildWindow : boolean;
|
|
|
|
|
procedure CreateHandle; override;
|
|
|
|
|
procedure InvalidateChildren;
|
|
|
|
|
procedure UpdateSize;
|
2018-09-16 10:39:41 +02:00
|
|
|
|
|
2019-03-15 17:17:14 +01:00
|
|
|
|
property ChildWindowHandle : THandle read GetChildWindowHandle;
|
2018-09-16 10:39:41 +02:00
|
|
|
|
|
|
|
|
|
published
|
|
|
|
|
property Align;
|
|
|
|
|
property Anchors;
|
|
|
|
|
property Color;
|
|
|
|
|
property Constraints;
|
|
|
|
|
property TabStop;
|
|
|
|
|
property TabOrder;
|
|
|
|
|
property Visible;
|
|
|
|
|
property Enabled;
|
|
|
|
|
property ShowHint;
|
|
|
|
|
property Hint;
|
|
|
|
|
property OnResize;
|
|
|
|
|
property DoubleBuffered;
|
|
|
|
|
{$IFDEF DELPHI12_UP}
|
|
|
|
|
property ParentDoubleBuffered;
|
|
|
|
|
{$ENDIF}
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
uCEFMiscFunctions, uCEFClient, uCEFConstants;
|
|
|
|
|
|
|
|
|
|
function TCEFWinControl.GetChildWindowHandle : THandle;
|
|
|
|
|
begin
|
2019-01-08 19:15:25 +01:00
|
|
|
|
{$IFDEF MSWINDOWS}
|
2018-09-16 10:39:41 +02:00
|
|
|
|
if not(csDesigning in ComponentState) and HandleAllocated then
|
|
|
|
|
Result := GetWindow(Handle, GW_CHILD)
|
|
|
|
|
else
|
2019-01-08 19:15:25 +01:00
|
|
|
|
{$ENDIF}
|
2018-09-16 10:39:41 +02:00
|
|
|
|
Result := 0;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCEFWinControl.CreateHandle;
|
|
|
|
|
begin
|
|
|
|
|
inherited CreateHandle;
|
|
|
|
|
end;
|
|
|
|
|
|
2018-10-20 20:43:06 +02:00
|
|
|
|
procedure TCEFWinControl.InvalidateChildren;
|
|
|
|
|
begin
|
|
|
|
|
if HandleAllocated then RedrawWindow(Handle, nil, 0, RDW_INVALIDATE or RDW_ALLCHILDREN);
|
|
|
|
|
end;
|
|
|
|
|
|
2018-09-16 10:39:41 +02:00
|
|
|
|
procedure TCEFWinControl.UpdateSize;
|
|
|
|
|
var
|
|
|
|
|
TempRect : TRect;
|
|
|
|
|
TempHWND : THandle;
|
|
|
|
|
begin
|
|
|
|
|
TempHWND := ChildWindowHandle;
|
|
|
|
|
if (TempHWND = 0) then exit;
|
|
|
|
|
|
|
|
|
|
TempRect := GetClientRect;
|
|
|
|
|
|
|
|
|
|
SetWindowPos(TempHWND, 0,
|
|
|
|
|
0, 0, TempRect.right, TempRect.bottom,
|
|
|
|
|
SWP_NOZORDER);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCEFWinControl.TakeSnapshot(var aBitmap : TBitmap) : boolean;
|
2019-11-10 18:23:39 +01:00
|
|
|
|
{$IFDEF MSWINDOWS}
|
2018-09-16 10:39:41 +02:00
|
|
|
|
var
|
|
|
|
|
TempHWND : HWND;
|
|
|
|
|
TempDC : HDC;
|
|
|
|
|
TempRect : TRect;
|
|
|
|
|
TempWidth : Integer;
|
|
|
|
|
TempHeight : Integer;
|
2019-11-10 18:23:39 +01:00
|
|
|
|
{$ENDIF}
|
2018-09-16 10:39:41 +02:00
|
|
|
|
begin
|
|
|
|
|
Result := False;
|
2019-11-10 18:23:39 +01:00
|
|
|
|
{$IFDEF MSWINDOWS}
|
2018-09-16 10:39:41 +02:00
|
|
|
|
if (aBitmap = nil) then exit;
|
|
|
|
|
|
|
|
|
|
TempHWND := ChildWindowHandle;
|
|
|
|
|
if (TempHWND = 0) then exit;
|
|
|
|
|
{$IFDEF DELPHI16_UP}Winapi.{$ENDIF}Windows.GetClientRect(TempHWND, TempRect);
|
|
|
|
|
TempDC := GetDC(TempHWND);
|
|
|
|
|
TempWidth := TempRect.Right - TempRect.Left;
|
|
|
|
|
TempHeight := TempRect.Bottom - TempRect.Top;
|
|
|
|
|
|
|
|
|
|
aBitmap := TBitmap.Create;
|
|
|
|
|
aBitmap.Height := TempHeight;
|
|
|
|
|
aBitmap.Width := TempWidth;
|
|
|
|
|
|
|
|
|
|
Result := BitBlt(aBitmap.Canvas.Handle, 0, 0, TempWidth, TempHeight,
|
|
|
|
|
TempDC, 0, 0, SRCCOPY);
|
|
|
|
|
|
|
|
|
|
ReleaseDC(TempHWND, TempDC);
|
2019-01-08 19:15:25 +01:00
|
|
|
|
{$ENDIF}
|
2018-09-16 10:39:41 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TCEFWinControl.DestroyChildWindow : boolean;
|
2019-11-10 18:23:39 +01:00
|
|
|
|
{$IFDEF MSWINDOWS}
|
2018-09-16 10:39:41 +02:00
|
|
|
|
var
|
|
|
|
|
TempHWND : HWND;
|
2019-11-10 18:23:39 +01:00
|
|
|
|
{$ENDIF}
|
2018-09-16 10:39:41 +02:00
|
|
|
|
begin
|
2019-01-08 19:15:25 +01:00
|
|
|
|
{$IFDEF MSWINDOWS}
|
2018-09-16 10:39:41 +02:00
|
|
|
|
TempHWND := ChildWindowHandle;
|
|
|
|
|
Result := (TempHWND <> 0) and DestroyWindow(TempHWND);
|
2019-11-10 18:23:39 +01:00
|
|
|
|
{$ELSE}
|
|
|
|
|
Result := False;
|
2019-01-08 19:15:25 +01:00
|
|
|
|
{$ENDIF}
|
2018-09-16 10:39:41 +02:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TCEFWinControl.Resize;
|
|
|
|
|
begin
|
|
|
|
|
inherited Resize;
|
|
|
|
|
|
|
|
|
|
UpdateSize;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
end.
|