📄 tbxd_u1.pas
字号:
posinpar: Integer;
var Abort: Boolean);
procedure UpdateView;
procedure DoSpellCheckWord(Sender: TObject;
var word: WideString;
var resultvalue: TSpellCheckResult;
var hyphen_pos: TSpellCheckHyphen;
par: TParagraph;
posinpar: Integer
);
end;
var
WPTBXForm: TWPTBXForm;
implementation
uses WPLabelFrm,
{$IFDEF WITHSPLASH}
WPSplash,
{$ENDIF}
{$IFDEF WPDFEX}
WPToPDFDlg,
{$ENDIF}
ShellAPI, Types
{$IFDEF WPPREMFORM}, WPPremiumEd{$ENDIF};
{$R *.dfm}
procedure TWPTBXForm.TBXRadioButton1Change(Sender: TObject);
begin
TBXSwitcher.FlatMenuStyle := fmsAuto;
end;
procedure TWPTBXForm.ListBox1Click(Sender: TObject);
begin
TBXSetTheme(ListBox1.Items[ListBox1.ItemIndex]);
Invalidate;
end;
procedure TWPTBXForm.FormCreate(Sender: TObject);
begin
FVisitedHyperlinks := TStringList.Create;
GetAvailableTBXThemes(ListBox1.Items); // from TBXThemes.pas
{$IFNDEF WPPREMIUM}TBXItem36.Visible := FALSE; {$ENDIF}
{$IFNDEF WPPREMIUM}TBXItem39.Visible := FALSE; {$ENDIF}
{$IFNDEF WPPREMFORM}TBItem2.Visible := FALSE; {$ENDIF}
WPRichText1.Memo.OnSpellCheckWord := DoSpellCheckWord;
WPRichText1.Memo.RTFData.WriteObjectMode := wobRTF;
WPRichText1.HyperlinkTextAttr.UseOnGetAttrColorEvent := TRUE;
// Read the default page size !
WPRichText1.ReadPrinterProperties;
end;
procedure TWPTBXForm.FormDestroy(Sender: TObject);
begin
{ WPRichText1.Parent := nil;
WPRichText1.Free; }
FVisitedHyperlinks.Free;
end;
// adapted from TBX Demo
procedure TWPTBXForm.bColorButtonDrawImage(Item: TTBCustomItem;
Viewer: TTBItemViewer; Canvas: TCanvas; ImageRect: TRect;
ImageOffset: TPoint; StateFlags: Integer);
var
DC: HDC;
Color: TColor;
ColorInd: Integer;
begin
DC := Canvas.Handle;
if not Boolean(StateFlags and ISF_DISABLED) then
begin
case Item.Tag of
1: ColorInd := WPRichText1.CurrAttr.GetColorEx(WPAT_CharColor);
2: ColorInd := WPRichText1.CurrAttr.GetColorEx(WPAT_CharBGColor);
3: ColorInd := WPRichText1.CurrAttr.GetColorEx(WPAT_FGColor);
else ColorInd := -1;
end;
OffsetRect(ImageRect, ImageOffset.X, ImageOffset.Y);
ImageRect.Top := ImageRect.Bottom - 4;
if ColorInd >= 0 then
begin
Color := WPRichText1.CurrAttr.NrToColor(ColorInd);
Canvas.Brush.Color := Color;
Canvas.FillRect(ImageRect);
end
else
begin
FrameRectEx(DC, ImageRect, clBtnShadow, True);
DitherRect(DC, ImageRect, clBtnFace, clBtnShadow);
end;
end;
end;
procedure TWPTBXForm.TBXColorPalette1Change(Sender: TObject);
var aColor: Integer;
begin
aColor := (Sender as TTBXColorPalette).Color;
case (Sender as TTBXColorPalette).Tag of
1: WPRichText1.CurrAttr.Color :=
WPRichText1.CurrAttr.ColorToNr(aColor, true);
2: WPRichText1.CurrAttr.BKColor :=
WPRichText1.CurrAttr.ColorToNr(aColor, true);
3: WPRichText1.CurrAttr.ParColor :=
WPRichText1.CurrAttr.ColorToNr(aColor, true);
end;
end;
procedure TWPTBXForm.lstFontsPopup(Sender: TTBCustomItem; FromLink: Boolean);
begin
if Sender is TTBXComboBoxItem then
TTBXComboBoxItem(Sender).Strings.Assign(Screen.Fonts);
end;
procedure TWPTBXForm.TBXItem40Click(Sender: TObject);
begin
if WPRichText1.CanClose then
WPRichText1.Clear;
end;
procedure TWPTBXForm.TBXItem44Click(Sender: TObject);
begin
WPPreviewDlg1.Execute;
end;
procedure TWPTBXForm.TBXList1Change(Sender: TObject);
var lst: TTBXStringList;
begin
{ Normal
Page Width
Full Page
Double Page
25% ... }
lst := Sender as TTBXStringList;
WPRichText1.LockScreen;
// wpAutoZoomOff, wpAutoZoomWidth, wpAutoZoomFullPage
if lst.ItemIndex = 0 then
begin
WPRichText1.LayoutMode := wplayShowManualPageBreaks;
WPRichText1.AutoZoom := wpAutoZoomOff;
end
else
if lst.ItemIndex = 1 then
begin
WPRichText1.LayoutMode := wplayFullLayout; // unit: WPRTEPaint
WPRichText1.AutoZoom := wpAutoZoomWidth;
end
else if lst.ItemIndex = 2 then
begin
WPRichText1.LayoutMode := wplayFullLayout;
WPRichText1.AutoZoom := wpAutoZoomFullPage;
end
else if lst.ItemIndex = 3 then
begin
WPRichText1.AutoZoom := wpAutoZoomWidth;
WPRichText1.LayoutMode := wpDualPageView;
end else
if lst.ItemIndex >= 0 then
begin
WPRichText1.AutoZoom := wpAutoZoomOff;
WPRichText1.LayoutMode := wplayFullLayout;
WPRichText1.SetZoom(TBXList1.Strings[TBXList1.ItemIndex]);
end;
WPRichText1.UnLockScreen(true);
end;
procedure TWPTBXForm.TBXItem16Click(Sender: TObject);
begin
WPRichText1.FontSelect;
end;
procedure TWPTBXForm.TBXItem17Click(Sender: TObject);
begin
WPParagraphPropDlg1.Execute;
end;
procedure TWPTBXForm.TBXItem19Click(Sender: TObject);
begin
WPBulletDlg1.Execute;
end;
procedure TWPTBXForm.TBXItem21Click(Sender: TObject);
begin
WPTabDlg1.Execute;
end;
procedure TWPTBXForm.TBXItem6Click(Sender: TObject);
begin
WPPagePropDlg1.Execute;
end;
procedure TWPTBXForm.ShowMailMClick(Sender: TObject);
begin
ShowMailM.Checked := not ShowMailM.Checked;
UpdateView;
end;
procedure TWPTBXForm.showBookMClick(Sender: TObject);
begin
showBookM.Checked := not showBookM.Checked;
UpdateView;
end;
procedure TWPTBXForm.ShowHyperClick(Sender: TObject);
begin
ShowHyper.Checked := not ShowHyper.Checked;
UpdateView;
end;
procedure TWPTBXForm.ShowSPANClick(Sender: TObject);
begin
ShowSPAN.Checked := not ShowSPAN.Checked;
UpdateView;
end;
procedure TWPTBXForm.ShowGridClick(Sender: TObject);
begin
ShowGrid.Checked := not ShowGrid.Checked;
UpdateView;
end;
procedure TWPTBXForm.ShowSpecialClick(Sender: TObject);
begin
ShowSpecial.Checked := not ShowSpecial.Checked;
UpdateView;
end;
procedure TWPTBXForm.BrkTablesClick(Sender: TObject);
begin
BrkTables.Checked := not BrkTables.Checked;
UpdateView;
end;
procedure TWPTBXForm.BrkRowsClick(Sender: TObject);
begin
BrkRows.Checked := not BrkRows.Checked;
UpdateView;
end;
procedure TWPTBXForm.UpdateView;
var frm: TWPFormatOptions;
view: TWPViewOptions;
begin
frm := WPRichText1.FormatOptions - [wpShowBookmarkCodes, wpShowHyperlinkCodes,
wpShowSPANCodes, wpfDontBreakTableRows, wpfDontBreakTables];
view := WPRichText1.ViewOptions - [wpShowGridlines,
wpShowCR, wpShowFF, wpShowNL, wpShowSPC, wpShowHardSPC, wpShowTAB];
if showBookM.Checked then include(frm, wpShowBookmarkCodes);
if ShowHyper.Checked then include(frm, wpShowHyperlinkCodes);
if ShowSpan.Checked then include(frm, wpShowSPANCodes);
if BrkRows.Checked then include(frm, wpfDontBreakTableRows);
if BrkTables.Checked then include(frm, wpfDontBreakTables);
WPRichText1.InsertPointAttr.Hidden := not ShowMailM.Checked;
if ShowGrid.Checked then include(view, wpShowGridlines);
if ShowSpecial.Checked then view := view +
[wpShowCR, wpShowFF, wpShowNL, wpShowSPC, wpShowHardSPC, wpShowTAB];
WPRichText1.FormatOptions := frm;
WPRichText1.ViewOptions := view;
WPRichText1.ReformatAll(false, true);
end;
procedure TWPTBXForm.TestButton1Click(Sender: TObject);
{ var
par: TParagraph;
i, l: Integer;
obj: TWPObject;
objTitleBar: TWPTextObj;
s: string;
str: TStringList;
w: WideString; }
begin
{ par := WPRichText1.FirstPar;
while par<>nil do
begin
if par.IsEmpty and (par.Cell=nil) then
par := par.DeleteParagraph
else par := par.next;
end;
WPRichText1.ReformatAll; }
{ WPRichText1.CPPosition := 0;
repeat
if (WPRichText1.CPCharAttr and cafsALL)=0 then
begin
WPRichText1.CPAttr.BeginUpdate;
WPRichText1.CPAttr.FontName := 'Courier New';
WPRichText1.CPAttr.Color := WPRichText1.GetColorNr(clRed);
WPRichText1.CPAttr.EndUpdate;
end;
until not WPRichText1.CPMoveNext;
WPRichText1.Refresh; }
{ WPRichText1.TextCursor.Finder.ToStart;
if WPRichText1.TextCursor.Finder.Next('Apple') then
WPRichText1.TextCursor.Position :=
WPRichText1.TextCursor.Finder.FoundPosition; }
{ WPRichText1.TextCursor.Find( 'Apple' );
WPRichText1.SetFocus; }
{ WPRichText1.WorkOnText := wpIsHeader;
if WPRichText1.MoveToNextField(true)='' then
ShowMessage('not found');
WPRichText1.SetFocus; }
{ par := WPRichText1.ActiveParagraph.ParentRow.CreateCopyList(false,nil);
WPRichText1.ActiveParagraph.ParentRow.NextPar := par;
for i:=0 to par.ColCount-1 do
par.Cols[i].SetText(IntToStr(i+1));
WPRichText1.ReformatAll(false,true); }
//WPRichText1.LayoutMode := wplayPageGap;
// wp2NoAutoIndentTabs
{ WPRichText1.CurrAttr.IndentLeft :=
WPRichText1.GetXPositionTw; // - WPRichText1.Header.LeftMargin;
WPRichText1.CurrAttr.IndentFirst := - WPRichText1.CurrAttr.IndentLeft ;
}
{ WPStyleCollection1.SaveToStreamFormat := wpSaveCSSFormat;
WPStyleCollection1.ReadStyles(WPRichText1);
WPStyleCollection1.SaveToFile('c:\styles.css'); }
{ s := '';
for i:=0 to WPRichText1.CurrAttr.TabCount-1 do
begin
s := s + IntToStr(WPRichText1.CurrAttr.TabPosition[i]) + #13;
end;
ShowMessage(s); }
{ WPRichText1.TextCursor.CurrAttribute.BeginUpdate;
WPRichText1.TextCursor.CurrAttribute.ClearAttr(true, true);
WPRichText1.TextCursor.CurrAttribute.EndUpdate; }
// WPRichText1.Header.Landscape := not WPRichText1.Header.Landscape;
{ s := '';
for i:=127 to 255 do
s :=s + Char(i);
w := '';
SetLength(w, 1000);
l := MultiByteToWideChar(1252, 0, PChar(s), 127, PWideChar(w), 1000);
s := '';
for i:=1 to l do
s := s + '#' + IntToStr(Integer(w[i])) + ' +';
Memo1.Text := s; }
// WPRichText1.LoadFromFile('c:\a.wpt');
{ WPRichText1.ActiveParagraph.ASetWPSS('IL:0;IR:0;TabL:450;TabFill:1;TabL:3240;TabFill:0;TabR:4770;TabL:5220;TabR:6750;',False,True)
; WPRichText1.ReformatAll(true); }
// WPRichText1.LoadFromFile('C:\Erzeugt\index.htm', true);
// WPRichText1.SaveToFile('c:\test.htm');
// WPRichText1.TableRow.ASet(WPAT_BoxMinHeight, 1440);
// WPRichText1.Refresh;
{ WPRichText1.MoveToPreviousField(true);
WPRichText1.ShowCursor;
WPRichText1.SetFocus; }
// WPRichText1.CurrAttr.AddStyle([afsProtected]);
end;
procedure TWPTBXForm.TBXItem18Click(Sender: TObject);
begin
if ManHeadFoot = nil then
begin
ManHeadFoot := TWPManageHeaderFooter.Create(Self);
ManHeadFoot.Left := Left + 50;
ManHeadFoot.Top := Top + 50;
end;
ManHeadFoot.WPRichText := WPRichText1;
ManHeadFoot.Show;
end;
procedure TWPTBXForm.TBXItem22Click(Sender: TObject);
begin
WPRichText1.InputTextField(TWPTextFieldType((Sender as TComponent).Tag));
end;
procedure TWPTBXForm.TBXItem30Click(Sender: TObject);
var i: Integer; s: string;
begin
s := 'EXTRA=<EXTRA>';
if InputQuery('Create Textfield', 'Fieldname=Value', s) then
begin
i := Pos('=', s);
if i > 0 then
WPRichText1.InputTextFieldName(Copy(s, 1, i - 1)).Params := Copy(s, i + 1, Length(s))
else WPRichText1.InputTextFieldName(s);
end;
end;
procedure TWPTBXForm.TBXItem14Click(Sender: TObject);
begin
WPRichText1.InsertGraphicDialog;
end;
procedure TWPTBXForm.TBXItem29Click(Sender: TObject);
begin
WPRichText1.InsertGraphicDialog('', true);
end;
procedure TWPTBXForm.TBXItem20Click(Sender: TObject);
var s: string;
begin
inc(FIELDCOUNT);
s := 'FIELD' + IntToStr(FIELDCOUNT);
if InputQuery('Create Mailmerge Field', 'Fieldname', s) then
WPRichText1.InputMergeField(s, s); // = Name, contents
end;
procedure TWPTBXForm.TBXItem57Click(Sender: TObject);
begin
WPRichText1.FindDialog;
end;
procedure TWPTBXForm.TBXItem58Click(Sender: TObject);
begin
WPRichText1.ReplaceDialog;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -