2020-05-05 18:10:33 +02:00
|
|
|
unit uCEFLabelButtonComponent;
|
|
|
|
|
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 18:56:41 +01:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2020-05-05 18:10:33 +02:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
{$IFDEF MSWINDOWS}WinApi.Windows,{$ENDIF} System.Classes,
|
|
|
|
{$ELSE}
|
|
|
|
{$IFDEF MSWINDOWS}Windows,{$ENDIF} Classes,
|
|
|
|
{$IFDEF FPC}
|
|
|
|
LCLProc, LCLType, LCLIntf, LResources, InterfaceBase,
|
|
|
|
{$ENDIF}
|
|
|
|
{$ENDIF}
|
2022-10-14 16:35:50 +02:00
|
|
|
uCEFTypes, uCEFInterfaces, uCEFConstants, uCEFViewsFrameworkEvents, uCEFButtonComponent;
|
2020-05-05 18:10:33 +02:00
|
|
|
|
|
|
|
type
|
2022-10-14 16:35:50 +02:00
|
|
|
{$IFNDEF FPC}{$IFDEF DELPHI16_UP}[ComponentPlatformsAttribute(pfidWindows or pfidOSX or pfidLinux)]{$ENDIF}{$ENDIF}
|
2020-05-05 18:10:33 +02:00
|
|
|
TCEFLabelButtonComponent = class(TCEFButtonComponent)
|
|
|
|
protected
|
|
|
|
FLabelButton : ICefLabelButton;
|
|
|
|
FText : ustring;
|
|
|
|
|
|
|
|
procedure DestroyView; override;
|
|
|
|
procedure Initialize; override;
|
|
|
|
|
|
|
|
function GetInitialized : boolean; override;
|
|
|
|
function GetAsView : ICefView; override;
|
|
|
|
function GetAsButton : ICefButton; override;
|
|
|
|
function GetAsLabelButton : ICefLabelButton; override;
|
|
|
|
function GetAsMenuButton : ICefMenuButton; virtual;
|
|
|
|
function GetText : ustring;
|
|
|
|
function GetImage(button_state: TCefButtonState): ICefImage;
|
|
|
|
|
|
|
|
procedure SetText(const text_: ustring);
|
|
|
|
procedure SetImage(button_state: TCefButtonState; const image: ICefImage);
|
|
|
|
|
|
|
|
// ICefViewDelegateEvents
|
|
|
|
procedure doCreateCustomView; override;
|
|
|
|
|
|
|
|
public
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Create a new LabelButton. |aText| will be shown on the LabelButton and used as the default
|
|
|
|
/// accessible name.
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
procedure CreateLabelButton(const aText : ustring);
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Sets the text color shown for the specified button |for_state| to |color|.
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
procedure SetTextColor(for_state: TCefButtonState; color: TCefColor);
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Sets the text colors shown for the non-disabled states to |color|.
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
procedure SetEnabledTextColors(color: TCefColor);
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// <para>Sets the font list. The format is "<FONT_FAMILY_LIST>,[STYLES] <SIZE>",
|
|
|
|
/// where:</para>
|
|
|
|
/// <code>
|
|
|
|
/// - FONT_FAMILY_LIST is a comma-separated list of font family names,
|
|
|
|
/// - STYLES is an optional space-separated list of style names (case-sensitive
|
|
|
|
/// "Bold" and "Italic" are supported), and
|
|
|
|
/// - SIZE is an integer font size in pixels with the suffix "px".
|
|
|
|
/// </code>
|
|
|
|
/// <para>Here are examples of valid font description strings:</para>
|
|
|
|
/// <code>
|
|
|
|
/// - "Arial, Helvetica, Bold Italic 14px"
|
|
|
|
/// - "Arial, 14px"
|
|
|
|
/// </code>
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
procedure SetFontList(const font_list: ustring);
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Sets the horizontal alignment; reversed in RTL. Default is
|
|
|
|
/// CEF_HORIZONTAL_ALIGNMENT_CENTER.
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
procedure SetHorizontalAlignment(alignment: TCefHorizontalAlignment);
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Reset the minimum size of this LabelButton to |size|.
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
procedure SetMinimumSize(const size_: TCefSize);
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Reset the maximum size of this LabelButton to |size|.
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
procedure SetMaximumSize(const size_: TCefSize);
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Gets and sets the text shown on the LabelButton. By default |text| will also be
|
|
|
|
/// used as the accessible name.
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
property Text : ustring read GetText write SetText;
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns the image shown for |button_state|. If no image exists for that
|
|
|
|
/// state then the image for CEF_BUTTON_STATE_NORMAL will be returned.
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
property Image[button_state : TCefButtonState] : ICefImage read GetImage write SetImage;
|
2023-09-29 19:23:38 +02:00
|
|
|
/// <summary>
|
|
|
|
/// Returns this LabelButton as a MenuButton or NULL if this is not a
|
|
|
|
/// MenuButton.
|
|
|
|
/// </summary>
|
2020-05-05 18:10:33 +02:00
|
|
|
property AsMenuButton : ICefMenuButton read GetAsMenuButton;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{$IFDEF FPC}
|
|
|
|
procedure Register;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
// *********************************************************
|
|
|
|
// ********************** ATTENTION ! **********************
|
|
|
|
// *********************************************************
|
|
|
|
// ** **
|
|
|
|
// ** MANY OF THE EVENTS IN CEF4DELPHI COMPONENTS LIKE **
|
|
|
|
// ** TCHROMIUM, TFMXCHROMIUM OR TCEFAPPLICATION ARE **
|
|
|
|
// ** EXECUTED IN A CEF THREAD BY DEFAULT. **
|
|
|
|
// ** **
|
|
|
|
// ** WINDOWS CONTROLS MUST BE CREATED AND DESTROYED IN **
|
|
|
|
// ** THE SAME THREAD TO AVOID ERRORS. **
|
|
|
|
// ** SOME OF THEM RECREATE THE HANDLERS IF THEY ARE **
|
|
|
|
// ** MODIFIED AND CAN CAUSE THE SAME ERRORS. **
|
|
|
|
// ** **
|
|
|
|
// ** DON'T CREATE, MODIFY OR DESTROY WINDOWS CONTROLS **
|
|
|
|
// ** INSIDE THE CEF4DELPHI EVENTS AND USE **
|
|
|
|
// ** SYNCHRONIZATION OBJECTS TO PROTECT VARIABLES AND **
|
|
|
|
// ** FIELDS IF THEY ARE ALSO USED IN THE MAIN THREAD. **
|
|
|
|
// ** **
|
|
|
|
// ** READ THIS FOR MORE INFORMATION : **
|
|
|
|
// ** https://www.briskbard.com/index.php?pageid=cef **
|
|
|
|
// ** **
|
|
|
|
// ** USE OUR FORUMS FOR MORE QUESTIONS : **
|
|
|
|
// ** https://www.briskbard.com/forum/ **
|
|
|
|
// ** **
|
|
|
|
// *********************************************************
|
|
|
|
// *********************************************************
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFLabelButton, uCEFMiscFunctions, uCEFButtonDelegate;
|
|
|
|
|
|
|
|
procedure TCEFLabelButtonComponent.CreateLabelButton(const aText : ustring);
|
|
|
|
begin
|
|
|
|
FText := aText;
|
|
|
|
CreateView;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFLabelButtonComponent.doCreateCustomView;
|
|
|
|
var
|
|
|
|
TempDelegate : ICefButtonDelegate;
|
|
|
|
begin
|
|
|
|
if (FLabelButton = nil) then
|
|
|
|
try
|
|
|
|
TempDelegate := TCustomButtonDelegate.Create(self);
|
|
|
|
FLabelButton := TCefLabelButtonRef.CreateLabelButton(TempDelegate, FText);
|
|
|
|
finally
|
|
|
|
TempDelegate := nil;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFLabelButtonComponent.DestroyView;
|
|
|
|
begin
|
|
|
|
inherited DestroyView;
|
|
|
|
|
|
|
|
FLabelButton := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFLabelButtonComponent.Initialize;
|
|
|
|
begin
|
|
|
|
inherited Initialize;
|
|
|
|
|
|
|
|
FLabelButton := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFLabelButtonComponent.GetInitialized : boolean;
|
|
|
|
begin
|
|
|
|
Result := (FLabelButton <> nil);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFLabelButtonComponent.GetAsView : ICefView;
|
|
|
|
begin
|
|
|
|
if Initialized then
|
|
|
|
Result := FLabelButton as ICefView
|
|
|
|
else
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFLabelButtonComponent.GetAsButton : ICefButton;
|
|
|
|
begin
|
|
|
|
if Initialized then
|
|
|
|
Result := FLabelButton as ICefButton
|
|
|
|
else
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFLabelButtonComponent.GetAsLabelButton : ICefLabelButton;
|
|
|
|
begin
|
|
|
|
Result := FLabelButton;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFLabelButtonComponent.GetAsMenuButton : ICefMenuButton;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFLabelButtonComponent.SetText(const text_: ustring);
|
|
|
|
begin
|
|
|
|
FText := text_;
|
|
|
|
|
|
|
|
if Initialized then
|
|
|
|
AsLabelButton.SetText(FText);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFLabelButtonComponent.GetText : ustring;
|
|
|
|
begin
|
|
|
|
if Initialized then
|
|
|
|
FText := AsLabelButton.GetText;
|
|
|
|
|
|
|
|
Result := FText;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFLabelButtonComponent.SetImage(button_state: TCefButtonState; const image: ICefImage);
|
|
|
|
begin
|
|
|
|
if Initialized then AsLabelButton.SetImage(button_state, image);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TCEFLabelButtonComponent.GetImage(button_state: TCefButtonState): ICefImage;
|
|
|
|
begin
|
|
|
|
if Initialized then
|
|
|
|
Result := AsLabelButton.GetImage(button_state)
|
|
|
|
else
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFLabelButtonComponent.SetTextColor(for_state: TCefButtonState; color: TCefColor);
|
|
|
|
begin
|
|
|
|
if Initialized then AsLabelButton.SetTextColor(for_state, color);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFLabelButtonComponent.SetEnabledTextColors(color: TCefColor);
|
|
|
|
begin
|
|
|
|
if Initialized then AsLabelButton.SetEnabledTextColors(color);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFLabelButtonComponent.SetFontList(const font_list: ustring);
|
|
|
|
begin
|
|
|
|
if Initialized then AsLabelButton.SetFontList(font_list);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFLabelButtonComponent.SetHorizontalAlignment(alignment: TCefHorizontalAlignment);
|
|
|
|
begin
|
|
|
|
if Initialized then AsLabelButton.SetHorizontalAlignment(alignment);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFLabelButtonComponent.SetMinimumSize(const size_: TCefSize);
|
|
|
|
begin
|
|
|
|
if Initialized then AsLabelButton.SetMinimumSize(size_);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TCEFLabelButtonComponent.SetMaximumSize(const size_: TCefSize);
|
|
|
|
begin
|
|
|
|
if Initialized then AsLabelButton.SetMaximumSize(size_);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{$IFDEF FPC}
|
|
|
|
procedure Register;
|
|
|
|
begin
|
|
|
|
{$I res/tceflabelbuttoncomponent.lrs}
|
|
|
|
RegisterComponents('Chromium Views Framework', [TCEFLabelButtonComponent]);
|
|
|
|
end;
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
end.
|