- Offizieller Beitrag
To download the WPTools 7 trial edition please go here: http://www.wpcubed.com/download.htm
Here is a simple editor which was created with a few lines of code.
It was compiled with Delphi XE 2 and 2 themes. You can click on the Configure button to change between the themes or configure the toolbar. The toolbar is the old TWPToolbar which has been modernized to support larger icons and runtime customization.
Using the new or open button a new tab (at the bottom) is created. You can switch between the documents easily.
This is practically the complete source for this demo:
Code
TForm1 = class(TForm)
.... // skipped
private
{ Private-Deklarationen }
public
FRTFDataCollections : TStringList;
function AddRTFData(name : string) : Integer;
procedure InitTabset;
procedure DelRTFData;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TForm1.AddRTFData(name : string) : Integer;
var element : TWPRTFDataCollection;
begin
element := TWPRTFDataCollection.Create(TWPRTFDataBlock);
element.MakeRTFProps;
Result := FRTFDataCollections.Count;
FRTFDataCollections.AddObject(name, element);
WPRichText1.RemoveRTFData;
WPRichText1.SetRTFData(element);
WPRichText1.ReformatAll(false, true);
InitTabSet;
end;
procedure TForm1.DelRTFData;
var i : Integer;
element : TWPRTFDataCollection;
bNeedClear : Boolean;
begin
bNeedClear := true;
if FRTFDataCollections.Count>1 then
begin
i := FRTFDataCollections.IndexOfObject( WPRichText1.RTFData );
if i>=0 then
begin
element := WPRichText1.RTFData;
WPRichText1.RemoveRTFData;
FRTFDataCollections.Delete(i);
if i>0 then dec(i);
element.Free;
element := TWPRTFDataCollection(FRTFDataCollections.Objects[i]);
WPRichText1.SetRTFData(element);
WPRichText1.ReformatAll(false, true);
InitTabSet;
bNeedClear := false;
end;
end;
if bNeedClear then
begin
WPRichText1.Clear;
WPRichText1.CheckHasBody;
WPRichText1.SetFocus;
end;
end;
procedure TForm1.InitTabset;
var i : Integer;
begin
TabControl1.Tabs.Clear;
for i := 0 to FRTFDataCollections.Count-1 do
TabControl1.Tabs.Add(
TWPRTFDataCollection(FRTFDataCollections.Objects[i]).LastFileName
);
i := FRTFDataCollections.IndexOfObject( WPRichText1.RTFData );
if i>=0 then TabControl1.TabIndex := i
else TabControl1.Tabs.Add('#');
end;
procedure TForm1.TabControl1Change(Sender: TObject);
begin
WPRichText1.SetRTFData(TWPRTFDataCollection(FRTFDataCollections.Objects[TabControl1.TabIndex]));
end;
// We create a new RTFData Object on OPEN or NEW
procedure TForm1.WPRichText1ChangeLastFileName(Sender: TObject);
begin
InitTabset;
end;
procedure TForm1.WPToolbar1IconSelection(Sender: TObject;
var Typ: TWpSelNr; const str: String; const group, num, index: Integer);
begin
if (typ=wptIconSel) and (group=WPI_GR_DISK) then
case num of
WPI_CO_Exit : Close;
WPI_CO_New :
begin
AddRTFData( '' );
Typ := wptIconDeSel;
end;
WPI_CO_Open :
begin
AddRTFData( '' );
if not WPRichText1.Load then DelRTFData;
Typ := wptIconDeSel;
end;
WPI_CO_Close:
begin
if WPRichText1.CanClose then
DelRTFData;
Typ := wptIconDeSel;
end;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
var i : Integer;
begin
WPPreview1.WPRichText := nil;
WPRichText1.RemoveRTFData;
for i:=0 to FRTFDataCollections.Count-1 do
FRTFDataCollections.Objects[i].Free;
FRTFDataCollections.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FRTFDataCollections := TStringList.Create;
AddRTFData('');
// 1) Basis
WPPreview1.Align := alLeft;
Splitter1.Align:=alLeft;
WPToolbar1.Align := alTop;
Panel1.Align := alClient;
Panel1.BevelInner := bvNone;
Panel1.BevelOuter := bvNone;
WPRuler1.Align := alTop;
WPVertRuler1.Align := alLeft;
WPRichText1.Align := alClient;
WPRuler1.Options := WPRuler1.Options - [wpNoVertRulerAttached];
// 2) connnect TWPRichText
WPRichText1.WPRuler := WPRuler1;
WPRichText1.VRuler := WPVertRuler1;
WPRichText1.WPToolBar := WPToolbar1;
WPPreview1.WPRichText := WPRichText1;
WPPreview1.Configuration := wpPreviewThumbnails;
// 3) further configuration
WPToolbar1.DrawOptions := [ wptDrawPageShade ];
WPToolbar1.FlatButtons := true;
WPToolbar1.MarginBottom:= 8;
WPToolbar1.BevelLines := [ wplBottomShade ];
WPRuler1.DrawOptions := WPRuler1.DrawOptions + [wpDrawPageShade, wpDrawFramelines ];
WPVertRuler1.DrawOptions := WPVertRuler1.DrawOptions + [wpDrawPageShade, wpDrawFramelines ];
WPRichText1.ViewOptionsEx := WPRichText1.ViewOptionsEx + [wpPaintPageShade];
WPPreview1.ViewOptionsEx := WPPreview1.ViewOptionsEx + [ wpPaintPageShade];
StatusBar1.SimpleText := 'WPTools Version ' + WPToolsVersion;
WPDrawRectWithBitmap_bitmap := MetroStyleImage.Picture.Bitmap;
end;
procedure TForm1.N31Click(Sender: TObject);
begin
{$IFDEF THEMED}
case (Sender as TMenuItem).Tag of
1 :
begin
WPDrawRectWithBitmap_bitmap := MetroStyleImage.Picture.Bitmap;
TStyleManager.TrySetStyle('Metro Blue');
end;
2 :
begin
WPDrawRectWithBitmap_bitmap := IcebergstyleImage.Picture.Bitmap;
TStyleManager.TrySetStyle('Iceberg Classico');
end;
3 :
begin
WPDrawRectWithBitmap_bitmap := nil;
TStyleManager.TrySetStyle('Windows');
end;
end;
{$ENDIF}
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
PopupMenu1.Popup(
Button1.ClientToScreen(Point(0, Button1.Height)).X,
Button1.ClientToScreen(Point(0, Button1.Height)).Y
);
end;
procedure TForm1.Configure1Click(Sender: TObject);
begin
WPToolbarConfigurate( WPToolbar1, Self, 'Configure Toolbar' );
end;
var bLoaded : Boolean;
procedure TForm1.FormShow(Sender: TObject);
var i : Integer;
begin
if not bLOaded then
begin
bLoaded := true;
for i := 1 to ParamCount do
if (ParamStr(i)<>'') and (FileExists(ParamStr(i))) then
begin
if i>1 then AddRTFData('');
WPRichText1.LoadFromFile( ParamStr(i) );
end;
end;
end;
end.
Alles anzeigen