From 24dd3c98d170e14d743c1b8b79e4809fd8be0564 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Wed, 21 Nov 2012 17:02:52 +0000 Subject: Adds a small stand-alone test app for the RichTextView component. --- docview/components/richtext/testapp/sample01.txt | 74 ++++++++ docview/components/richtext/testapp/testapp.lpi | 89 ++++++++++ docview/components/richtext/testapp/testapp.lpr | 206 +++++++++++++++++++++++ 3 files changed, 369 insertions(+) create mode 100644 docview/components/richtext/testapp/sample01.txt create mode 100644 docview/components/richtext/testapp/testapp.lpi create mode 100644 docview/components/richtext/testapp/testapp.lpr (limited to 'docview/components') diff --git a/docview/components/richtext/testapp/sample01.txt b/docview/components/richtext/testapp/sample01.txt new file mode 100644 index 00000000..9713e63b --- /dev/null +++ b/docview/components/richtext/testapp/sample01.txt @@ -0,0 +1,74 @@ +

RichTextView formatting syntax +It has a HTML-like set of tags. Not very strict, so tag pairs don't have to match up. For example <<<< tags are often used to get you back to default (normal) text formatting. + +To display a physical tags in your text, you need to prefix the << symbol of a tag, with an extra << symbol. + +

Margins +The following text has a left margin of 10 spaces and a right margin of 5 spaces. + + 1 2 3 4 5 6 +12345678901234567890123456789012345678901234567890123456789012345 + + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam tincidunt lacinia diam, a egestas arcu bibendum sit amet. Proin erat mauris, vehicula id auctor aliquam, semper id turpis. Etiam iaculis lectus sit amet velit molestie euismod. Proin vel fermentum sem. Vivamus ut odio ligula, et egestas purus. Pellentesque eu turpis vitae ante adipiscing lacinia. Nulla dignissim, ligula id eleifend accumsan, sapien lacus condimentum nulla, eu pulvinar risus magna quis turpis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In vel semper nunc. Nulla eget justo at dolor vestibulum aliquam. Aenean commodo egestas odio, a rutrum sapien fringilla et. + + + +Note the above image is aligned to the right. We can also specify margins using pixels. This paragraph has a left margin of 100px. + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam tincidunt lacinia diam, a egestas arcu bibendum sit amet. Proin erat mauris, vehicula id auctor aliquam, semper id turpis. Etiam iaculis lectus sit amet velit molestie euismod. Proin vel fermentum sem. Vivamus ut odio ligula, et egestas purus. Pellentesque eu turpis vitae ante adipiscing lacinia. Nulla dignissim, ligula id eleifend accumsan, sapien lacus condimentum nulla, eu pulvinar risus magna quis turpis. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In vel semper nunc. Nulla eget justo at dolor vestibulum aliquam. Aenean commodo egestas odio, a rutrum sapien fringilla et. + +Now the margin is set back to 0 (default). + +

Headings +Then we have some general text texts like heading 1-3, normal text and fixed width text. + +

This is Heading 1 font +

This is Heading 2 font +

This is Heading 3 font +This is normal text +This is fixed font text + +

Text Color +We can also specify text colors like green, blue, or some RRGGBB specified color. We can also specific a text background color. + +

Alternative Fonts + +This sentence is in Courier New 8 font. + +This sentence is in 'Times New Roman' 12 font. + +This sentence is in Helvetica 18 font. + +This sentence is in the default system font. + +

Text alignment +This text is left aligned. + +This text is centre aligned. + +Images follow the same alignment as text. + +This is right aligned. + + +This is back to normal. + +

ASCII or Unicode text art +Using the << is handy to create text art. If your FixedFont supports Unicode drawing characters, then you can make your text art look even better. + ++-------------------------------------+ +|File Edit | View | Options Help | ++-------------------------------------+ + | All | + | Some . . . | + +--------------------+ + | By . . . | + +--------------------+ + + +

HyperLinks +RichTextView also supports hyperlinks. Simply use the < syntax, where "xyz" is the link text that will be sent to the OnClickLink() and OnOverLink() events. + +By default the link text will appear in the same color and styling as the surrounding text. If you want to make it more visible, use the < tags. + diff --git a/docview/components/richtext/testapp/testapp.lpi b/docview/components/richtext/testapp/testapp.lpi new file mode 100644 index 00000000..a579ec56 --- /dev/null +++ b/docview/components/richtext/testapp/testapp.lpi @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docview/components/richtext/testapp/testapp.lpr b/docview/components/richtext/testapp/testapp.lpr new file mode 100644 index 00000000..66e60de2 --- /dev/null +++ b/docview/components/richtext/testapp/testapp.lpr @@ -0,0 +1,206 @@ +{ + This is a quick and simple test app so I coud test the TRichTextView component + as a standard-alone widget. +} +program testapp; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX} + cthreads, + {$ENDIF} + Classes, fpg_base, fpg_main, fpg_form, fpg_button, fpg_memo, fpg_dialogs, + fpg_checkbox, fpg_imagelist, RichTextView; + +type + + TMainForm = class(TfpgForm) + private + {@VFD_HEAD_BEGIN: MainForm} + Button1: TfpgButton; + RichTextView1: TRichTextView; + Memo1: TfpgMemo; + CheckBox1: TfpgCheckBox; + btnLoad: TfpgButton; + {@VFD_HEAD_END: MainForm} + FImageList: TfpgImageList; + procedure Button1Click(Sender: TObject); + procedure btnLoadClicked(Sender: TObject); + procedure LinkClicked(Sender: TRichTextView; Link: string); + public + constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + procedure AfterCreate; override; + end; + +{@VFD_NEWFORM_DECL} + + + +{@VFD_NEWFORM_IMPL} + +procedure TMainForm.Button1Click(Sender: TObject); +begin + if CheckBox1.Checked then + RichTextView1.AddParagraph(PChar(Memo1.Text)) + else + RichTextView1.AddText(PChar(Memo1.Text)); +end; + +procedure TMainForm.btnLoadClicked(Sender: TObject); +var + sl: TStringList; + lFile: TfpgString; +begin + lFile := SelectFileDialog(sfdOpen, 'Text Files (*.txt)|*.txt'); + if lFile = '' then + Exit; + sl := TStringList.Create; + try + sl.LoadFromFile(lFile); + RichTextView1.Clear; + RichTextView1.AddText(PChar(sl.Text)); + finally + sl.Free; + end; +end; + +procedure TMainForm.LinkClicked(Sender: TRichTextView; Link: string); +begin + ShowMessage(Link); +end; + +constructor TMainForm.Create(AOwner: TComponent); +var + img_ref: TfpgImage; + img: TfpgImage; +begin + inherited Create(AOwner); + FImageList := TfpgImageList.Create; + + { make copies of standard fpGUI images, and add them to our imagelist } + img_ref := fpgImages.GetImage('stdimg.folderhome'); + img := img_ref.ImageFromSource; + FImageList.AddImage(img); + + img_ref := fpgImages.GetImage('stdimg.ok'); + img := img_ref.ImageFromSource; + FImageList.AddImage(img); + + img_ref := fpgImages.GetImage('stdimg.dlg.warning'); + img := img_ref.ImageFromSource; + FImageList.AddImage(img); + + img_ref := fpgImages.GetImage('stdimg.dlg.info'); + img := img_ref.ImageFromSource; + FImageList.AddImage(img); + +end; + +destructor TMainForm.Destroy; +begin + FImageList.Free; + inherited Destroy; +end; + +procedure TMainForm.AfterCreate; +begin + {%region 'Auto-generated GUI code' -fold} + {@VFD_BODY_BEGIN: MainForm} + Name := 'MainForm'; + SetPosition(397, 276, 507, 403); + WindowTitle := 'RichTextView test application'; + Hint := ''; + + Button1 := TfpgButton.Create(self); + with Button1 do + begin + Name := 'Button1'; + SetPosition(412, 12, 80, 24); + Anchors := [anRight,anTop]; + Text := 'Open'; + FontDesc := '#Label1'; + Hint := ''; + ImageName := ''; + TabOrder := 1; + OnClick := @Button1Click; + end; + + RichTextView1 := TRichTextView.Create(self); + with RichTextView1 do + begin + Name := 'RichTextView1'; + SetPosition(20, 100, 476, 288); + Anchors := [anLeft,anRight,anTop,anBottom]; + ScrollDistance := 80; + Images := FImageList; + RichTextSettings.Heading1Font := fpgGetFont('Arial-18:bold'); + RichTextSettings.Heading2Font := fpgGetFont('Arial-14:bold'); + RichTextSettings.Heading3Font := fpgGetFont('Arial-12:bold'); + RichTextSettings.NormalFont := fpgGetFont(FPG_DEFAULT_FONT_DESC); + RichTextSettings.FixedFont := fpgGetFont('Courier New-10:antialiased=true'); + OnClickLink :=@LinkClicked; + end; + + Memo1 := TfpgMemo.Create(self); + with Memo1 do + begin + Name := 'Memo1'; + SetPosition(20, 8, 384, 80); + Anchors := [anLeft,anRight,anTop]; + FontDesc := '#Edit1'; + Hint := ''; + Lines.Add('hello world. Graeme says hi.'); + TabOrder := 2; + end; + + CheckBox1 := TfpgCheckBox.Create(self); + with CheckBox1 do + begin + Name := 'CheckBox1'; + SetPosition(408, 40, 92, 20); + Anchors := [anRight,anTop]; + FontDesc := '#Label1'; + Hint := ''; + TabOrder := 3; + Text := 'Paragraph'; + end; + + btnLoad := TfpgButton.Create(self); + with btnLoad do + begin + Name := 'btnLoad'; + SetPosition(412, 64, 80, 23); + Text := 'Load...'; + FontDesc := '#Label1'; + Hint := ''; + ImageName := ''; + TabOrder := 5; + OnClick := @btnLoadClicked; + end; + + {@VFD_BODY_END: MainForm} + {%endregion} +end; + + +procedure MainProc; +var + frm: TMainForm; +begin + fpgApplication.Initialize; + frm := TMainForm.Create(nil); + try + frm.Show; + fpgApplication.Run; + finally + frm.Free; + end; +end; + +begin + MainProc; +end. + + -- cgit v1.2.3-70-g09d2