Skip to content

Commit

Permalink
Added TWVBrowserBase.SimulateEditingCommand
Browse files Browse the repository at this point in the history
Modified the EditorBrowser demos to use the new TWVBrowserBase.SimulateEditingCommand function instead of executing JavaScript.
Added EditingCommandToString to uWVMiscFunctions
  • Loading branch information
salvadordf committed Jan 8, 2022
1 parent 10af040 commit 1747211
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 784 deletions.
5 changes: 3 additions & 2 deletions demos/Delphi_VCL/EditorBrowser/uMainForm.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ object MainForm: TMainForm
Left = 0
Top = 0
Caption = 'VirtualHostBrowser - Initializing...'
ClientHeight = 701
ClientHeight = 733
ClientWidth = 995
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Expand All @@ -18,10 +18,11 @@ object MainForm: TMainForm
Left = 0
Top = 23
Width = 995
Height = 678
Height = 710
Align = alClient
TabOrder = 0
Browser = WVBrowser1
ExplicitHeight = 691
end
object ToolBar1: TToolBar
Left = 0
Expand Down
91 changes: 26 additions & 65 deletions demos/Delphi_VCL/EditorBrowser/uMainForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -226,66 +226,45 @@ procedure TMainForm.TextColorBtnClick(Sender: TObject);
end;

procedure TMainForm.AlignCenterBtnClick(Sender: TObject);
var
TempCode : string;
begin
TempCode := 'document.execCommand("justifyCenter", false, null);';

WVBrowser1.ExecuteScript(TempCode);
WVWindowParent1.SetFocus;
WVBrowser1.SimulateEditingCommand(ecJustifyCenter);
end;

procedure TMainForm.AlignJustifyBtnClick(Sender: TObject);
var
TempCode : string;
begin
TempCode := 'document.execCommand("justifyFull", false, null);';

WVBrowser1.ExecuteScript(TempCode);
WVWindowParent1.SetFocus;
WVBrowser1.SimulateEditingCommand(ecJustifyFull);
end;

procedure TMainForm.AlignLeftBtnClick(Sender: TObject);
var
TempCode : string;
begin
TempCode := 'document.execCommand("justifyLeft", false, null);';

WVBrowser1.ExecuteScript(TempCode);
WVWindowParent1.SetFocus;
WVBrowser1.SimulateEditingCommand(ecJustifyLeft);
end;

procedure TMainForm.AlignRightBtnClick(Sender: TObject);
var
TempCode : string;
begin
TempCode := 'document.execCommand("justifyRight", false, null);';

WVBrowser1.ExecuteScript(TempCode);
WVWindowParent1.SetFocus;
WVBrowser1.SimulateEditingCommand(ecJustifyRight);
end;

procedure TMainForm.BoldBtnClick(Sender: TObject);
var
TempCode : string;
begin
TempCode := 'document.execCommand("bold", false, null);';

WVBrowser1.ExecuteScript(TempCode);
WVWindowParent1.SetFocus;
WVBrowser1.SimulateEditingCommand(ecBold);
end;

procedure TMainForm.IndentBtnClick(Sender: TObject);
var
TempCode : string;
begin
TempCode := 'document.execCommand("indent", false, null);';

WVBrowser1.ExecuteScript(TempCode);
WVWindowParent1.SetFocus;
WVBrowser1.SimulateEditingCommand(ecIndent);
end;

procedure TMainForm.ItalicBtnClick(Sender: TObject);
var
TempCode : string;
begin
TempCode := 'document.execCommand("italic", false, null);';

WVBrowser1.ExecuteScript(TempCode);
WVWindowParent1.SetFocus;
WVBrowser1.SimulateEditingCommand(ecItalic);
end;

procedure TMainForm.LinkBtnClick(Sender: TObject);
Expand All @@ -305,30 +284,21 @@ procedure TMainForm.SaveBtnClick(Sender: TObject);
end;

procedure TMainForm.StrikethroughBtnClick(Sender: TObject);
var
TempCode : string;
begin
TempCode := 'document.execCommand("strikeThrough", false, null);';

WVBrowser1.ExecuteScript(TempCode);
WVWindowParent1.SetFocus;
WVBrowser1.SimulateEditingCommand(ecStrikethrough);
end;

procedure TMainForm.UnderlineBtnClick(Sender: TObject);
var
TempCode : string;
begin
TempCode := 'document.execCommand("underline", false, null);';

WVBrowser1.ExecuteScript(TempCode);
WVWindowParent1.SetFocus;
WVBrowser1.SimulateEditingCommand(ecUnderline);
end;

procedure TMainForm.UnorderedListBtnClick(Sender: TObject);
var
TempCode : string;
begin
TempCode := 'document.execCommand("insertUnorderedList", false, null);';

WVBrowser1.ExecuteScript(TempCode);
WVWindowParent1.SetFocus;
WVBrowser1.SimulateEditingCommand(ecInsertUnorderedList);
end;

procedure TMainForm.OpenBtnClick(Sender: TObject);
Expand All @@ -340,30 +310,21 @@ procedure TMainForm.OpenBtnClick(Sender: TObject);
end;

procedure TMainForm.OrderedListBtnClick(Sender: TObject);
var
TempCode : string;
begin
TempCode := 'document.execCommand("insertOrderedList", false, null);';

WVBrowser1.ExecuteScript(TempCode);
WVWindowParent1.SetFocus;
WVBrowser1.SimulateEditingCommand(ecInsertOrderedList);
end;

procedure TMainForm.OutdentBtnClick(Sender: TObject);
var
TempCode : string;
begin
TempCode := 'document.execCommand("outdent", false, null);';

WVBrowser1.ExecuteScript(TempCode);
WVWindowParent1.SetFocus;
WVBrowser1.SimulateEditingCommand(ecOutdent);
end;

procedure TMainForm.RemoveFormatBtnClick(Sender: TObject);
var
TempCode : string;
begin
TempCode := 'document.execCommand("removeFormat", false, null);';

WVBrowser1.ExecuteScript(TempCode);
WVWindowParent1.SetFocus;
WVBrowser1.SimulateEditingCommand(ecRemoveFormat);
end;

procedure TMainForm.NewBtnClick(Sender: TObject);
Expand Down
5 changes: 2 additions & 3 deletions demos/Lazarus/EditorBrowser/EditorBrowser.lpi
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasUsesSectionForAllUnits Value="False"/>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="EditorBrowser"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
Expand All @@ -25,7 +25,6 @@
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0"/>
</RunParams>
<RequiredPackages Count="2">
<Item1>
Expand Down
10 changes: 4 additions & 6 deletions demos/Lazarus/EditorBrowser/EditorBrowser.lps
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
<CONFIG>
<ProjectSession>
<PathDelim Value="\"/>
<Version Value="11"/>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units Count="14">
<Unit0>
<Filename Value="EditorBrowser.lpr"/>
<IsPartOfProject Value="True"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
<DefaultSyntaxHighlighter Value="Delphi"/>
</Unit0>
<Unit1>
<Filename Value="uMainForm.pas"/>
Expand All @@ -20,12 +19,11 @@
<ResourceBaseClass Value="Form"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="1"/>
<TopLine Value="139"/>
<CursorPos X="50" Y="163"/>
<TopLine Value="263"/>
<CursorPos X="5" Y="330"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
<DefaultSyntaxHighlighter Value="Delphi"/>
</Unit1>
<Unit2>
<Filename Value="..\..\..\source\uWVBrowser.pas"/>
Expand Down Expand Up @@ -143,7 +141,7 @@
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0" ActiveMode=""/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>
Loading

0 comments on commit 1747211

Please sign in to comment.