-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuEditDesigner.pas
910 lines (817 loc) · 25.3 KB
/
uEditDesigner.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
unit uEditDesigner;
interface
uses
Windows, Classes, Dialogs, EmbeddedWB, MSHTML_Ewb, EditDesigner, Forms,
Controls, ExtCtrls, StdCtrls, ComCtrls, SysUtils, Vcl.OleCtrls, EwbCore,
SHDocVw_EWB, OleCtrlsFix, Vcl.ToolWin, System.ImageList, Vcl.ImgList,
Winapi.ShellAPI, Vcl.Menus, System.StrUtils, System.Actions, Vcl.ActnList,
Vcl.StdActns, Winapi.Messages, Vcl.Clipbrd, SynEdit, SynCompletionProposal,
SynHighlighterMulti, SynHighlighterHtml, SynHighlighterCSS,
SynEditHighlighter, SynEditCodeFolding, SynHighlighterJScript;
type
TForm1 = class(TForm)
EditDesigner1: TEditDesigner;
EmbeddedWB1: TEmbeddedWB;
ImageListToolBar1: TImageList;
ImageListToolBar2: TImageList;
ToolBar1: TToolBar;
ToolButtonNew: TToolButton;
ToolButtonOpen: TToolButton;
ToolButtonSave: TToolButton;
ToolButtonSeparator1: TToolButton;
ToolButtonPrint: TToolButton;
ToolButtonPreview: TToolButton;
ToolButtonSeparator2: TToolButton;
ToolButtonCut: TToolButton;
ToolButtonCopy: TToolButton;
ToolButtonPaste: TToolButton;
ToolButtonSeparator3: TToolButton;
ToolButtonUndo: TToolButton;
ToolButtonRedo: TToolButton;
ToolBar2: TToolBar;
ComboBoxFontName: TComboBox;
ToolButtonSeparator4: TToolButton;
ComboBoxFontHTMLSize: TComboBox;
ToolButtonSeparator5: TToolButton;
ToolButtonBold: TToolButton;
ToolButtonItalic: TToolButton;
ToolButtonUnderline: TToolButton;
ToolButtonSeparator6: TToolButton;
ToolButtonNumbering: TToolButton;
ToolButtonBullets: TToolButton;
ToolButtonDecInd: TToolButton;
ToolButtonIncInd: TToolButton;
ToolButtonSeparator7: TToolButton;
ToolButtonJustifyLeft: TToolButton;
ToolButtonJustifyCenter: TToolButton;
ToolButtonJustifyRight: TToolButton;
ToolButtonJustifyFull: TToolButton;
ToolButtonSeparator8: TToolButton;
ToolButtonInsertHorizontalLine: TToolButton;
ToolButtonInsertHyperlink: TToolButton;
ToolButtonInsertPicture: TToolButton;
ToolButtonSeparator9: TToolButton;
ToolButtonBackColor: TToolButton;
ToolButtonForeColor: TToolButton;
ToolButtonRadioButton: TToolButton;
ColorDialog1: TColorDialog;
ToolButtonSync: TToolButton;
MainMenu1: TMainMenu;
MenuItemFile: TMenuItem;
MenuItemFileNew: TMenuItem;
MenuItemFileOpen: TMenuItem;
MenuItemFileSeparator1: TMenuItem;
MenuItemFileSave: TMenuItem;
MenuItemFileSaveAs: TMenuItem;
MenuItemFileSeparator2: TMenuItem;
MenuItemFilePageSetup: TMenuItem;
MenuItemFilePrintPreview: TMenuItem;
MenuItemFilePrint: TMenuItem;
MenuItemFileSeparator3: TMenuItem;
MenuItemFileExit: TMenuItem;
MenuItemEdit: TMenuItem;
MenuItemEditUndo: TMenuItem;
MenuItemEditRedo: TMenuItem;
MenuItemEditSeparator1: TMenuItem;
MenuItemEditCut: TMenuItem;
MenuItemEditCopy: TMenuItem;
MenuItemEditPaste: TMenuItem;
MenuItemEditSeparator2: TMenuItem;
MenuItemEditSelectAll: TMenuItem;
MenuItemEditSeparator3: TMenuItem;
MenuItemEditFind: TMenuItem;
MenuItemView: TMenuItem;
MenuItemViewSource: TMenuItem;
MenuItemInsert: TMenuItem;
MenuItemInsertPicture: TMenuItem;
MenuItemInsertHorizontalLine: TMenuItem;
MenuItemInsertSeparator1: TMenuItem;
MenuItemInsertHyperlink: TMenuItem;
MenuItemTable: TMenuItem;
MenuItemTableInsert: TMenuItem;
MenuItemTableInsertTable: TMenuItem;
MenuItemTableInsertColumn: TMenuItem;
MenuItemTableInsertRow: TMenuItem;
MenuItemTableInsertCell: TMenuItem;
MenuItemTableDelete: TMenuItem;
MenuItemTableDeleteColumn: TMenuItem;
MenuItemTableDeleteRow: TMenuItem;
MenuItemTableDeleteCell: TMenuItem;
MenuItemTableSeparator1: TMenuItem;
MenuItemTableMergeCells: TMenuItem;
MenuItemTableSplitCell: TMenuItem;
MenuItemTableSeparator2: TMenuItem;
MenuItemTableProperties: TMenuItem;
MenuItemTableSeparator3: TMenuItem;
MenuItemTableShowBorders: TMenuItem;
ActionList1: TActionList;
aFind: TAction;
FindDialog1: TFindDialog;
ToolButtonTrack: TToolButton;
Splitter1: TSplitter;
SynCompletionProposal1: TSynCompletionProposal;
SynJScriptSyn1: TSynJScriptSyn;
SynCssSyn1: TSynCssSyn;
SynHTMLSyn1: TSynHTMLSyn;
SynMultiSyn1: TSynMultiSyn;
SynAutoComplete1: TSynAutoComplete;
SynEdit1: TSynEdit;
StatusBar1: TStatusBar;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
Pnl_LeftSide: TPanel;
function EditDesigner1PreDrag: HRESULT;
function EditDesigner1SnapRect(const pIElement: IHTMLElement; var prcNew: TRect; eHandle: TOleEnum): HRESULT;
function EditDesigner1PostEditorEventNotify(inEvtDispId: Integer; const pIEventObj: IHTMLEventObj): HRESULT;
function EditDesigner1PostHandleEvent(inEvtDispId: Integer; const pIEventObj: IHTMLEventObj): HRESULT;
function EditDesigner1PreHandleEvent(inEvtDispId: Integer; const pIEventObj: IHTMLEventObj): HRESULT;
function EditDesigner1TranslateAccelerator(inEvtDispId: Integer; const pIEventObj: IHTMLEventObj): HRESULT;
procedure Exit1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure EmbeddedWB1KeyUp(Sender: TObject; var Key: Word; ScanCode: Word; Shift: TShiftState);
procedure ToolButtonBoldClick(Sender: TObject);
procedure ToolButtonItalicClick(Sender: TObject);
procedure ToolButtonUnderlineClick(Sender: TObject);
procedure ToolButtonInsertHyperlinkClick(Sender: TObject);
procedure ToolButtonInsertPictureClick(Sender: TObject);
procedure ToolButtonRadioButtonClick(Sender: TObject);
procedure ToolButtonSaveClick(Sender: TObject);
procedure ToolButtonNewClick(Sender: TObject);
procedure ToolButtonOpenClick(Sender: TObject);
procedure ComboBoxFontNameChange(Sender: TObject);
procedure ComboBoxFontNameCloseUp(Sender: TObject);
procedure ComboBoxFontHTMLSizeChange(Sender: TObject);
procedure ToolButtonForeColorClick(Sender: TObject);
procedure ToolButtonBackColorClick(Sender: TObject);
procedure ToolButtonDecIndClick(Sender: TObject);
procedure ToolButtonIncIndClick(Sender: TObject);
procedure ToolButtonNumberingClick(Sender: TObject);
procedure ToolButtonBulletsClick(Sender: TObject);
procedure ToolButtonJustifyLeftClick(Sender: TObject);
procedure ToolButtonJustifyCenterClick(Sender: TObject);
procedure ToolButtonJustifyRightClick(Sender: TObject);
procedure ToolButtonJustifyFullClick(Sender: TObject);
procedure ToolButtonInsertHorizontalLineClick(Sender: TObject);
procedure ToolButtonCutClick(Sender: TObject);
procedure ToolButtonCopyClick(Sender: TObject);
procedure ToolButtonPasteClick(Sender: TObject);
procedure ToolButtonUndoClick(Sender: TObject);
procedure ToolButtonRedoClick(Sender: TObject);
procedure ToolButtonPrintClick(Sender: TObject);
procedure ToolButtonPreviewClick(Sender: TObject);
procedure ToolButtonSyncClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure MenuItemFileNewClick(Sender: TObject);
procedure MenuItemFileOpenClick(Sender: TObject);
procedure MenuItemFileSaveClick(Sender: TObject);
procedure MenuItemFilePageSetupClick(Sender: TObject);
procedure MenuItemFilePrintPreviewClick(Sender: TObject);
procedure MenuItemFilePrintClick(Sender: TObject);
procedure MenuItemFileExitClick(Sender: TObject);
procedure MenuItemEditUndoClick(Sender: TObject);
procedure MenuItemEditRedoClick(Sender: TObject);
procedure MenuItemEditCutClick(Sender: TObject);
procedure MenuItemEditCopyClick(Sender: TObject);
procedure MenuItemEditPasteClick(Sender: TObject);
procedure MenuItemEditSelectAllClick(Sender: TObject);
procedure MenuItemEditFindClick(Sender: TObject);
procedure MenuItemViewSourceClick(Sender: TObject);
procedure MenuItemInsertPictureClick(Sender: TObject);
procedure MenuItemInsertHorizontalLineClick(Sender: TObject);
procedure MenuItemInsertHyperlinkClick(Sender: TObject);
procedure aFindExecute(Sender: TObject);
procedure FindDialog1Find(Sender: TObject);
procedure EditDesigner1InnerHtml(const innerHtml: string);
procedure EditDesigner1TagName(const tagName: string);
procedure FormShow(Sender: TObject);
procedure ToolButtonTrackClick(Sender: TObject);
procedure SynEdit1StatusChange(Sender: TObject; Changes: TSynStatusChanges);
procedure SynEdit1Change(Sender: TObject);
procedure FormResize(Sender: TObject);
private
IsloadingTime: Boolean;
PvTempHtml: TStringList;
FSelPos: Integer;
OriginalMemoWindowProc: TWndMethod;
TrackToggle: Boolean;
TempFilePath: string;
procedure UpdateDesigner;
procedure MakeFile(APath: string);
procedure LoadFile(APath: string);
function FileIsBusy(AFileName: string): Boolean;
function WaitFile(AFileName: string; ASpeepDelay: integer): Boolean;
procedure SyncEditor;
procedure SaveAndSync;
procedure SyncDesigner;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.EditDesigner1InnerHtml(const innerHtml: string);
var
LvPos : Integer;
LvLine: Integer;
begin
// LvPos := AdvMemo_HtmlSource.FindTextInMemo(innerHtml,[fr]);
// if LvPos > 0 then begin
// AdvMemo_HtmlSource.SelStart := LvPos;
// AdvMemo_HtmlSource.SelLength := length(innerHtml);
// end;
if TrackToggle then
begin
LvPos:= Pos(innerHtml, SynEdit1.Lines.Text);
if LvPos > 0 then begin
LvLine := SendMessage(SynEdit1.Handle, EM_LINEFROMCHAR, LvPos - 1, 0);
SynEdit1.SelStart := LvPos - 1;
SynEdit1.SelLength := Length(innerHtml);
SynEdit1.SetFocus;
end;
end;
end;
function TForm1.EditDesigner1PostEditorEventNotify(inEvtDispId: Integer; const pIEventObj: IHTMLEventObj): HRESULT;
begin
Result := S_FALSE;
end;
function TForm1.EditDesigner1PostHandleEvent(inEvtDispId: Integer;
const pIEventObj: IHTMLEventObj): HRESULT;
begin
Result := S_FALSE;
end;
function TForm1.EditDesigner1PreDrag: HRESULT;
begin
Result := S_FALSE;
end;
function TForm1.EditDesigner1PreHandleEvent(inEvtDispId: Integer; const pIEventObj: IHTMLEventObj): HRESULT;
begin
Result := S_FALSE;
end;
procedure TForm1.EditDesigner1TagName(const tagName: string);
begin
//
end;
function TForm1.EditDesigner1TranslateAccelerator(inEvtDispId: Integer; const pIEventObj: IHTMLEventObj): HRESULT;
begin
Result := S_FALSE;
end;
procedure TForm1.EmbeddedWB1KeyUp(Sender: TObject; var Key: Word; ScanCode: Word; Shift: TShiftState);
begin
SyncEditor;
end;
function TForm1.EditDesigner1SnapRect(const pIElement: IHTMLElement;
var prcNew: TRect; eHandle: TOleEnum): HRESULT;
begin
case eHandle of
ELEMENT_CORNER_NONE: ; // Code for moving the element
ELEMENT_CORNER_TOP: ; // Code for resizing the element
ELEMENT_CORNER_LEFT: ; // Code for resizing the element
ELEMENT_CORNER_BOTTOM: ; // Code for resizing the element
ELEMENT_CORNER_RIGHT: ; // Code for resizing the element
ELEMENT_CORNER_TOPLEFT: ; // Code for resizing the element
ELEMENT_CORNER_TOPRIGHT: ; // Code for resizing the element
ELEMENT_CORNER_BOTTOMLEFT: ; // Code for resizing the element
ELEMENT_CORNER_BOTTOMRIGHT: ; // Code for resizing the element
end;
Result := S_OK;
end;
procedure TForm1.ToolButtonBackColorClick(Sender: TObject);
begin
if ColorDialog1.Execute then begin
EditDesigner1.SetBackColor(ColorDialog1.Color);
SyncEditor;
end;
end;
procedure TForm1.ToolButtonBoldClick(Sender: TObject);
begin
EditDesigner1.SetFontBold;
SyncEditor;
end;
procedure TForm1.ToolButtonBulletsClick(Sender: TObject);
begin
EditDesigner1.Bullets;
SyncEditor;
end;
procedure TForm1.ToolButtonCopyClick(Sender: TObject);
begin
EditDesigner1.Copy;
end;
procedure TForm1.ToolButtonCutClick(Sender: TObject);
begin
EditDesigner1.Cut;
end;
procedure TForm1.ToolButtonDecIndClick(Sender: TObject);
begin
EditDesigner1.OutDent;
SyncEditor;
end;
procedure TForm1.ToolButtonForeColorClick(Sender: TObject);
begin
if ColorDialog1.Execute then begin
EditDesigner1.SetForeColor(ColorDialog1.Color);
SyncEditor;
end;
end;
procedure TForm1.ToolButtonIncIndClick(Sender: TObject);
begin
EditDesigner1.Indent;
SyncEditor;
end;
procedure TForm1.ToolButtonInsertHorizontalLineClick(Sender: TObject);
begin
EditDesigner1.InsertHorizontalLine;
SyncEditor;
end;
procedure TForm1.ToolButtonInsertHyperlinkClick(Sender: TObject);
begin
EditDesigner1.InsertHyperlink(EditDesigner1);
SyncEditor;
end;
procedure TForm1.ToolButtonInsertPictureClick(Sender: TObject);
begin
EditDesigner1.InsertImage;
SyncEditor;
end;
procedure TForm1.ToolButtonItalicClick(Sender: TObject);
begin
EditDesigner1.SetFontItalic;
SyncEditor;
end;
procedure TForm1.ToolButtonJustifyCenterClick(Sender: TObject);
begin
EditDesigner1.JustifyCenter;
SyncEditor;
end;
procedure TForm1.ToolButtonJustifyFullClick(Sender: TObject);
begin
EditDesigner1.JustifyFull;
SyncEditor;
end;
procedure TForm1.ToolButtonJustifyLeftClick(Sender: TObject);
begin
EditDesigner1.JustifyLeft;
SyncEditor;
end;
procedure TForm1.ToolButtonJustifyRightClick(Sender: TObject);
begin
EditDesigner1.JustifyRight;
SyncEditor;
end;
procedure TForm1.ToolButtonNewClick(Sender: TObject);
begin
try
IsloadingTime := True;
// EditDesigner1.RemoveDesigner;// = S_OK
except
end;
try
if FileExists(TempFilePath) then
DeleteFile(TempFilePath);
MakeFile(TempFilePath);
EmbeddedWB1.Offline := True;
EmbeddedWB1.Navigate(TempFilePath);
UpdateDesigner;
finally
IsloadingTime := False;
end;
end;
procedure TForm1.ToolButtonNumberingClick(Sender: TObject);
begin
EditDesigner1.Numbering;
SyncEditor;
end;
procedure TForm1.ToolButtonOpenClick(Sender: TObject);
begin
try
IsloadingTime := True;
EditDesigner1.RemoveDesigner;// = S_OK
except
end;
try
if OpenDialog1.Execute then
LoadFile(OpenDialog1.FileName);
EmbeddedWB1.Offline := True;
if EmbeddedWB1.NavigateWait(OpenDialog1.FileName) then
UpdateDesigner;
finally
IsloadingTime := False;
end;
end;
procedure TForm1.ToolButtonPasteClick(Sender: TObject);
begin
EditDesigner1.Paste;
end;
procedure TForm1.ToolButtonPreviewClick(Sender: TObject);
begin
EmbeddedWB1.PrintPreview;
end;
procedure TForm1.ToolButtonPrintClick(Sender: TObject);
begin
EmbeddedWB1.Print;
end;
procedure TForm1.ToolButtonRadioButtonClick(Sender: TObject);
begin
EditDesigner1.InsertRadioButton;
SyncEditor;
end;
procedure TForm1.ToolButtonRedoClick(Sender: TObject);
begin
EditDesigner1.Redo;
end;
procedure TForm1.ToolButtonSaveClick(Sender: TObject);
var
LvFileName: string;
begin
try
if SaveDialog1.Execute then begin
LvFileName := SaveDialog1.FileName;
if EditDesigner1.RemoveDesigner = S_OK then
if EditDesigner1.SaveToFile(LvFileName) = S_OK then
ShellExecute(Forms.Application.Handle, 'explore', PChar(LvFileName), nil, nil, SW_SHOWNORMAL);
end;
except on E:Exception do
ShowMessage('Error while Saving with the following message:'+ #13 + E.Message )
end;
end;
procedure TForm1.ToolButtonUnderlineClick(Sender: TObject);
begin
EditDesigner1.SetFontUnderline;
SyncEditor;
end;
procedure TForm1.ToolButtonUndoClick(Sender: TObject);
begin
EditDesigner1.Undo;
end;
procedure TForm1.LoadFile(APath: string);
var
Val: string;
LvTempHtml: TStringList;
begin
LvTempHtml := TStringList.Create;
try
LvTempHtml.LoadFromFile(APath);
SynEdit1.Lines.Clear;
for Val in LvTempHtml do
SynEdit1.Lines.Add(Val);
finally
FreeAndNil(LvTempHtml);
end;
end;
procedure TForm1.MakeFile(APath: string);
var
Val: string;
LvTempHtml: TStringList;
begin
LvTempHtml := TStringList.Create;
try
LvTempHtml.Add('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">');
LvTempHtml.Add('<HTML><HEAD><TITLE> Hello World! </TITLE>');
LvTempHtml.Add('<META charset=utf-8>');
LvTempHtml.Add('<SCRIPT type=text/javascript>');
LvTempHtml.Add('</SCRIPT>');
LvTempHtml.Add('');
LvTempHtml.Add('<STYLE type=text/css>');
LvTempHtml.Add('</STYLE>');
LvTempHtml.Add('');
LvTempHtml.Add('<META name=GENERATOR content="MSHTML 11.00.10570.1001"></HEAD>');
LvTempHtml.Add('<BODY>');
LvTempHtml.Add('<DIV>');
LvTempHtml.Add('Hello World!');
LvTempHtml.Add('</DIV></BODY></HTML>');
LvTempHtml.SaveToFile(TempFilePath);
SynEdit1.Lines.Clear;
for Val in LvTempHtml do
SynEdit1.Lines.Add(Val);
finally
FreeAndNil(LvTempHtml);
end;
end;
procedure TForm1.MenuItemEditCopyClick(Sender: TObject);
begin
ToolButtonCopy.Click;
end;
procedure TForm1.MenuItemEditCutClick(Sender: TObject);
begin
ToolButtonCut.Click;
end;
procedure TForm1.MenuItemEditFindClick(Sender: TObject);
begin
EditDesigner1.FindDialog;
end;
procedure TForm1.MenuItemEditPasteClick(Sender: TObject);
begin
ToolButtonPaste.Click;
end;
procedure TForm1.MenuItemEditRedoClick(Sender: TObject);
begin
ToolButtonRedo.Click;
end;
procedure TForm1.MenuItemEditSelectAllClick(Sender: TObject);
begin
EmbeddedWB1.SelectAll;
end;
procedure TForm1.MenuItemEditUndoClick(Sender: TObject);
begin
ToolButtonUndo.Click;
end;
procedure TForm1.MenuItemFileExitClick(Sender: TObject);
begin
Close;
end;
procedure TForm1.MenuItemFileNewClick(Sender: TObject);
begin
ToolButtonNew.Click;
end;
procedure TForm1.MenuItemFileOpenClick(Sender: TObject);
begin
ToolButtonOpen.Click;
end;
procedure TForm1.MenuItemFilePageSetupClick(Sender: TObject);
begin
EmbeddedWB1.PageSetup;
end;
procedure TForm1.MenuItemFilePrintClick(Sender: TObject);
begin
EmbeddedWB1.Print;
end;
procedure TForm1.MenuItemFilePrintPreviewClick(Sender: TObject);
begin
EmbeddedWB1.PrintPreview;
end;
procedure TForm1.MenuItemFileSaveClick(Sender: TObject);
begin
ToolButtonSave.Click;
end;
procedure TForm1.MenuItemInsertHorizontalLineClick(Sender: TObject);
begin
ToolButtonInsertHorizontalLine.Click;
end;
procedure TForm1.MenuItemInsertHyperlinkClick(Sender: TObject);
begin
ToolButtonInsertHyperlink.Click;
end;
procedure TForm1.MenuItemInsertPictureClick(Sender: TObject);
begin
ToolButtonInsertPicture.Click;
end;
procedure TForm1.MenuItemViewSourceClick(Sender: TObject);
begin
EmbeddedWB1.ViewPageSourceHtml;
end;
procedure TForm1.SaveAndSync;
var
Val: string;
LvTempHtml: TStringList;
begin
try
LvTempHtml := TStringList.Create;
if EditDesigner1.RemoveDesigner = S_OK then
begin
IsloadingTime := True;
SynEdit1.Lines.BeginUpdate;
SynEdit1.Lines.Clear;
EditDesigner1.SaveToFile(TempFilePath);
LvTempHtml.LoadFromFile(TempFilePath);
for Val in LvTempHtml do
SynEdit1.Lines.Add(Val);
SynEdit1.Lines.EndUpdate;
end;
finally
EmbeddedWB1.Navigate(TempFilePath);
EditDesigner1.ConnectDesigner;
FreeAndNil(LvTempHtml);
IsloadingTime := False;
end;
end;
procedure TForm1.SyncDesigner;
var
LvLine: string;
LvTempHtml: TStringList;
begin
if IsloadingTime then
Exit;
LvTempHtml := TStringList.Create;
try
try
for LvLine in SynEdit1.Lines do
LvTempHtml.Add(LvLine);
LvTempHtml.WriteBOM := True;
LvTempHtml.SaveToFile(TempFilePath, TEncoding.UTF8);
if EditDesigner1.RemoveDesigner = S_OK then
begin
EmbeddedWB1.Navigate(TempFilePath);
UpdateDesigner;
end;
except
end;
finally
if EmbeddedWB1.CanFocus then //Do not Remove this line
EmbeddedWB1.SetFocusToDoc; //Do not Remove this line
if SynEdit1.CanFocus then //Do not Remove this line
SynEdit1.SetFocus; //Do not Remove this line
FreeAndNil(LvTempHtml);
end;
end;
procedure TForm1.SyncEditor;
var
LvTempHtml: TStringList;
LvVal: string;
TempVal: TStringList;
FirstStart, LastStart: Boolean;
begin
FirstStart := False;
LastStart := False;
LvTempHtml := TStringList.Create;
try
EmbeddedWB1.ViewPageSourceHtmlToStrings(LvTempHtml);
IsloadingTime := True;
SynEdit1.Lines.Clear;
SynEdit1.Lines.Add('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">');
for LvVal in LvTempHtml do
begin
if (not FirstStart) and (LeftStr(UpperCase(LvVal.Trim), 6) = UpperCase('<HEAD>')) then
begin
SynEdit1.Lines.Add('<HTML>' + LvVal);
FirstStart := True;
end
else if (not LastStart) and (RightStr(UpperCase(LvVal.Trim), 7) = UpperCase('</BODY>')) then
begin
SynEdit1.Lines.Add(LvVal + '</HTML>');
LastStart := True;
end
else
SynEdit1.Lines.Add(LvVal);
end;
IsloadingTime := False;
finally
FreeAndNil(LvTempHtml);
FreeAndNil(TempVal);
end;
end;
procedure TForm1.SynEdit1Change(Sender: TObject);
begin
SyncDesigner;
end;
procedure TForm1.SynEdit1StatusChange(Sender: TObject;
Changes: TSynStatusChanges);
begin
// caret position has changed
if Changes * [scAll, scCaretX, scCaretY] <> [] then
begin
Statusbar1.SimpleText := Format('Ln:%6d, Col:%3d',
[SynEdit1.CaretY, SynEdit1.CaretX]);
end;
end;
procedure TForm1.ToolButtonSyncClick(Sender: TObject);
begin
SaveAndSync;
end;
procedure TForm1.ToolButtonTrackClick(Sender: TObject);
begin
TrackToggle := not TrackToggle;
ToolButtonTrack.Down := TrackToggle;
end;
procedure TForm1.aFindExecute(Sender: TObject);
begin
if SynEdit1.Focused then
begin
FSelPos := 0;
FindDialog1.Execute;
end;
end;
procedure TForm1.ComboBoxFontHTMLSizeChange(Sender: TObject);
var
LvSize: String;
begin
LvSize := (Sender as TComboBox).Text;
EditDesigner1.SetFontSize(StrToInt(LvSize[1]));
SyncEditor;
end;
procedure TForm1.ComboBoxFontNameChange(Sender: TObject);
begin
EditDesigner1.SetFont(ComboBoxFontName.Text);
SyncEditor;
end;
procedure TForm1.ComboBoxFontNameCloseUp(Sender: TObject);
begin
EmbeddedWB1.SetFocus;
end;
procedure TForm1.UpdateDesigner;
begin
EditDesigner1.ConnectDesigner;// = S_OK
end;
procedure TForm1.Exit1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
try
EditDesigner1.RemoveDesigner;
except
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
ridx: integer;
DC: HDC;
function EnumFontsProc(var LogFont: TLogFont; var TextMetric: TTextMetric; FontType: Integer; Strings: TStrings): Integer; stdcall;
begin
Strings.Add(LogFont.lfFaceName);
Result := 1
end;
begin
try //Catch system installed fontnames.
DC := GetDC(0);
EnumFonts(DC, nil, @EnumFontsProc, Pointer(ComboBoxFontName.Items));
finally
ReleaseDC(0, DC);
ComboBoxFontName.Sorted := True
end;
{ The D4Demo uses this...
OpenDialog1.Filter := GetHighlightersFilter(fHighlighters) +
'All files|*.*|';
If you set SynMultiSyn1.DefalutFilter at Design time, you get a
repeat filter if it is the same as another highlighter. }
OpenDialog1.Filter := SynMultiSyn1.DefaultFilter;
SaveDialog1.Filter := SynMultiSyn1.DefaultFilter;
{ Set SynMultiSyn1 Filter to HTML because that is the example I'm
using. }
SynMultiSyn1.DefaultFilter := SynHTMLSyn1.DefaultFilter;
{ Load Completion and Autocomplete from user maintained text files }
SynCompletionProposal1.ItemList.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'SynCP.txt');
SynAutoComplete1.AutoCompleteList.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'SynAC.txt');
TempFilePath := ExtractFilePath(ParamStr(0)) + 'Test.html';
end;
procedure TForm1.FormResize(Sender: TObject);
begin
EmbeddedWB1.Constraints.MinWidth := (Self.Width div 3);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
ToolButtonNew.Click;
end;
function TForm1.FileIsBusy(AFileName: string): Boolean;
var
F: Integer;
begin
F := FileOpen(AFileName, fmShareExclusive);
Result := F = -1;
FileClose(F);
end;
function TForm1.WaitFile(AFileName: string; ASpeepDelay: integer): Boolean;
begin
while FileIsBusy(AFileName) do
Sleep(ASpeepDelay);
Result := True;
end;
procedure TForm1.FindDialog1Find(Sender: TObject);
var
I : Integer;
a,b, c : char;
s : string;
fertig : boolean;
begin
i := SynEdit1.selstart;
if ((i =1) and (not (frdown in FindDialog1.Options))) or ((i= length(SynEdit1.Lines.Text)) and (frdown in FindDialog1.Options)) then
ShowMessage('not found')
else begin
if (frdown in FindDialog1.Options) then
i := i + 1;
repeat
fertig := false;
if (frdown in FindDialog1.Options) then
i := i + 1
else i := i - 1;
s := AnsiUpperCase(SynEdit1.Lines.Text[i]);
if (s = AnsiUpperCase(FindDialog1.FindText[1])) then begin
s := copy(SynEdit1.Lines.Text, i, length(FindDialog1.FindText));
if (frMatchcase in FindDialog1.Options) then begin
if s = FindDialog1.FindText then
fertig := true;
end else begin
if AnsiUpperCase(s) = AnsiUpperCase(FindDialog1.FindText) then
fertig := true;
end;
if fertig then begin
SynEdit1.SelStart := i - 1;
SynEdit1.SelLength := length(FindDialog1.FindText);
if (frWholeWord in FindDialog1.Options) then begin
a := SynEdit1.Lines.Text[SynEdit1.SelStart];
b := SynEdit1.Lines.Text[SynEdit1.SelStart + SynEdit1.SelLength + 1];
if (a in [#48..#57, #65..#90, #97..#122]) or (b in [#48..#57, #65..#90, #97..#122]) then
fertig := false;
end;
end;
end;
if (i = 1) or (i = length(SynEdit1.Lines.Text)) then begin
fertig := true;
ShowMessage('not found');
end;
until (fertig = true);
FocusControl(SynEdit1);
end;
end;
end.