2018-04-18 10:25:38 +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-04-18 10:25:38 +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
|
|
|
|
//
|
2022-01-01 11:41:21 +02:00
|
|
|
// Copyright � 2022 Salvador Diaz Fau. All rights reserved.
|
2018-04-18 10:25:38 +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 uCEFFMXWindowParent;
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 19:56:41 +02:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2018-04-18 10:25:38 +02:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.Classes, System.Types, System.UITypes,
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
WinApi.Windows,
|
|
|
|
{$ENDIF}
|
2022-10-14 16:35:50 +02:00
|
|
|
FMX.Controls, FMX.Types, FMX.Forms,
|
|
|
|
uCEFConstants;
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
type
|
2022-10-14 16:35:50 +02:00
|
|
|
{$IFNDEF FPC}{$IFDEF DELPHI16_UP}[ComponentPlatformsAttribute(pfidWindows or pfidOSX or pfidLinux)]{$ENDIF}{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
TFMXWindowParent = class(TCommonCustomForm)
|
|
|
|
protected
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
function GetChildWindowHandle : HWND;
|
|
|
|
procedure UpdateSize;
|
|
|
|
{$ENDIF}
|
2022-12-09 11:32:46 +02:00
|
|
|
{$IFDEF DELPHI17_UP}
|
2018-04-18 10:25:38 +02:00
|
|
|
procedure Resize; override;
|
2022-12-09 11:32:46 +02:00
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
public
|
|
|
|
{$IFDEF MSWINDOWS}
|
2021-12-08 18:45:03 +02:00
|
|
|
procedure Reparent(const aNewParentHandle : {$IFDEF DELPHI18_UP}TWindowHandle{$ELSE}TFmxHandle{$ENDIF});
|
2018-04-18 10:25:38 +02:00
|
|
|
property ChildWindowHandle : HWND read GetChildWindowHandle;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
published
|
|
|
|
property Visible;
|
|
|
|
property Height;
|
|
|
|
property Width;
|
2020-02-03 13:02:30 +02:00
|
|
|
property Touch;
|
|
|
|
property OnGesture;
|
2018-04-18 10:25:38 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
// This class inherits from TCommonCustomForm because CEF needs a Windows handle
|
|
|
|
// to create the browser in normal mode.
|
|
|
|
|
|
|
|
// TFMXWindowParent has to be created and resized at runtime.
|
|
|
|
// It's also necessary to call "Reparent" to add this component as a child component to your form.
|
|
|
|
|
|
|
|
uses
|
|
|
|
System.SysUtils, FMX.Platform, FMX.Platform.Win;
|
|
|
|
|
2022-12-09 11:32:46 +02:00
|
|
|
{$IFDEF DELPHI17_UP}
|
2018-04-18 10:25:38 +02:00
|
|
|
procedure TFMXWindowParent.Resize;
|
|
|
|
begin
|
|
|
|
inherited Resize;
|
|
|
|
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
UpdateSize;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
2022-12-09 11:32:46 +02:00
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
|
|
|
|
{$IFDEF MSWINDOWS}
|
|
|
|
function TFMXWindowParent.GetChildWindowHandle : HWND;
|
|
|
|
var
|
|
|
|
TempHWND : HWND;
|
|
|
|
begin
|
|
|
|
TempHWND := FmxHandleToHWND(Handle);
|
|
|
|
Result := WinApi.Windows.GetWindow(TempHWND, GW_CHILD);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TFMXWindowParent.UpdateSize;
|
|
|
|
var
|
|
|
|
TempHWND, TempChildHWND : HWND;
|
|
|
|
TempRect : System.Types.TRect;
|
|
|
|
TempClientRect : TRectF;
|
|
|
|
begin
|
|
|
|
TempChildHWND := ChildWindowHandle;
|
|
|
|
if (TempChildHWND = 0) then exit;
|
|
|
|
|
|
|
|
TempHWND := BeginDeferWindowPos(1);
|
|
|
|
|
|
|
|
try
|
|
|
|
TempClientRect := ClientRect;
|
|
|
|
TempRect.Left := round(TempClientRect.Left);
|
|
|
|
TempRect.Top := round(TempClientRect.Top);
|
|
|
|
TempRect.Right := round(TempClientRect.Right);
|
|
|
|
TempRect.Bottom := round(TempClientRect.Bottom);
|
|
|
|
|
|
|
|
TempHWND := DeferWindowPos(TempHWND, TempChildHWND, HWND_TOP,
|
|
|
|
TempRect.left, TempRect.top, TempRect.right - TempRect.left, TempRect.bottom - TempRect.top,
|
|
|
|
SWP_NOZORDER);
|
|
|
|
finally
|
|
|
|
EndDeferWindowPos(TempHWND);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2021-12-08 18:45:03 +02:00
|
|
|
procedure TFMXWindowParent.Reparent(const aNewParentHandle : {$IFDEF DELPHI18_UP}TWindowHandle{$ELSE}TFmxHandle{$ENDIF});
|
2018-04-18 10:25:38 +02:00
|
|
|
var
|
|
|
|
TempChildHandle, TempParentHandle : HWND;
|
|
|
|
begin
|
2021-12-08 18:45:03 +02:00
|
|
|
{$IFDEF DELPHI18_UP}
|
2018-04-18 10:25:38 +02:00
|
|
|
if (aNewParentHandle <> nil) then
|
2021-12-08 18:45:03 +02:00
|
|
|
{$ELSE}
|
|
|
|
if (aNewParentHandle <> 0) then
|
|
|
|
{$ENDIF}
|
2018-04-18 10:25:38 +02:00
|
|
|
begin
|
|
|
|
TempChildHandle := FmxHandleToHWND(Handle);
|
|
|
|
TempParentHandle := FmxHandleToHWND(aNewParentHandle);
|
|
|
|
|
|
|
|
if (TempChildHandle <> 0) and (TempParentHandle <> 0) then
|
|
|
|
begin
|
|
|
|
SetWindowLong(TempChildHandle, GWL_STYLE, WS_CHILDWINDOW);
|
|
|
|
WinApi.Windows.SetParent(TempChildHandle, TempParentHandle);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
|
|
|
|
end.
|