summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2012-11-21 17:02:52 +0000
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2012-11-21 17:02:52 +0000
commit24dd3c98d170e14d743c1b8b79e4809fd8be0564 (patch)
tree371519c3c0cac37189392970cf4ae926e410b89a
parenta904897b6f618022e66d9a3e7ac6804f9ceb12f7 (diff)
downloadfpGUI-24dd3c98d170e14d743c1b8b79e4809fd8be0564.tar.xz
Adds a small stand-alone test app for the RichTextView component.
-rw-r--r--docview/components/richtext/testapp/sample01.txt74
-rw-r--r--docview/components/richtext/testapp/testapp.lpi89
-rw-r--r--docview/components/richtext/testapp/testapp.lpr206
3 files changed, 369 insertions, 0 deletions
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 @@
+<h1>RichTextView formatting syntax</h>
+It has a HTML-like set of tags. Not very strict, so tag pairs don't have to match up. For example <</i><</b><</u><</color> 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.
+
+<h2>Margins</h>
+The following text has a left margin of 10 spaces and a right margin of 5 spaces.
+<tt><wrap no>
+ 1 2 3 4 5 6
+12345678901234567890123456789012345678901234567890123456789012345
+</tt><wrap yes>
+<rightmargin 5>
+<leftmargin 10>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.
+
+
+<align right><image 3><align left>
+<leftmargin 0><b>Note the above image is aligned to the right.</b> We can also specify margins using <b>pixels</b>. This paragraph has a left margin of 100px.
+
+<leftmargin 100 pixels>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.
+
+<leftmargin 0>Now the margin is set back to 0 (default).
+
+<h2>Headings</h>
+Then we have some general text texts like heading 1-3, normal text and fixed width text.
+<leftmargin 5>
+<h1>This is Heading 1 font</h>
+<h2>This is Heading 2 font</h>
+<h3>This is Heading 3 font</h>
+This is normal text
+<tt>This is fixed font text</tt>
+
+<leftmargin 0><h2>Text Color</h>
+We can also specify text colors like <green>green</color>, <blue>blue</color>, or <color #969229>some RRGGBB specified color</color>. <backcolor yellow>We can also specific a text background color.</backcolor>
+
+<h2>Alternative Fonts</h><image 1>
+<leftmargin 55 pixels>
+<font "Courier New" 8>This sentence is in Courier New 8 font.
+
+<font "Times New Roman" 12>This sentence is in 'Times New Roman' 12 font.
+
+<font "Helvetica" 18>This sentence is in Helvetica 18 font.</font>
+
+This sentence is in the default system font. <leftmargin 0>
+
+<h2>Text alignment</h>
+<align left>This text is left aligned.
+
+<align center>This text is centre aligned.
+<image 2>
+Images follow the same alignment as text.
+
+<align right>This is right aligned.
+<align left>
+
+This is back to normal.
+
+<h2>ASCII or Unicode text art</h>
+Using the <<tt><<wrap no> is handy to create text art. If your FixedFont supports Unicode drawing characters, then you can make your text art look even better.
+<tt><wrap no>
++-------------------------------------+
+|File Edit | View | Options Help |
++-------------------------------------+
+ | All |
+ | Some . . . |
+ +--------------------+
+ | By . . . |
+ +--------------------+
+</tt><wrap yes></tt><wrap yes>
+
+<h2>HyperLinks</h>
+RichTextView also supports hyperlinks. Simply use the <<link xyz> syntax, where "xyz" is the link text that will be sent to the <blue><link 1>OnClickLink()</link></color> and <green><link onoverlink>OnOverLink()</link></color> 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 <<color> 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 @@
+<?xml version="1.0"?>
+<CONFIG>
+ <ProjectOptions>
+ <Version Value="9"/>
+ <General>
+ <Flags>
+ <SaveOnlyProjectUnits Value="True"/>
+ <MainUnitHasCreateFormStatements Value="False"/>
+ <MainUnitHasTitleStatement Value="False"/>
+ </Flags>
+ <SessionStorage Value="InProjectDir"/>
+ <MainUnit Value="0"/>
+ <ResourceType Value="res"/>
+ </General>
+ <VersionInfo>
+ <Language Value=""/>
+ <CharSet Value=""/>
+ <StringTable ProductVersion=""/>
+ </VersionInfo>
+ <BuildModes Count="1">
+ <Item1 Name="default" Default="True"/>
+ </BuildModes>
+ <PublishOptions>
+ <Version Value="2"/>
+ <IgnoreBinaries Value="False"/>
+ <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
+ <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
+ </PublishOptions>
+ <RunParams>
+ <local>
+ <FormatVersion Value="1"/>
+ <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
+ </local>
+ </RunParams>
+ <RequiredPackages Count="2">
+ <Item1>
+ <PackageName Value="fpgui_richtext"/>
+ </Item1>
+ <Item2>
+ <PackageName Value="fpgui_toolkit"/>
+ </Item2>
+ </RequiredPackages>
+ <Units Count="1">
+ <Unit0>
+ <Filename Value="testapp.lpr"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="testapp"/>
+ </Unit0>
+ </Units>
+ </ProjectOptions>
+ <CompilerOptions>
+ <Version Value="9"/>
+ <Target>
+ <Filename Value="testapp"/>
+ </Target>
+ <SearchPaths>
+ <IncludeFiles Value="$(ProjOutDir)"/>
+ </SearchPaths>
+ <Parsing>
+ <SyntaxOptions>
+ <UseAnsiStrings Value="False"/>
+ </SyntaxOptions>
+ </Parsing>
+ <Linking>
+ <Debugging>
+ <UseHeaptrc Value="True"/>
+ </Debugging>
+ </Linking>
+ <Other>
+ <CompilerMessages>
+ <UseMsgFile Value="True"/>
+ </CompilerMessages>
+ <CompilerPath Value="$(CompPath)"/>
+ </Other>
+ </CompilerOptions>
+ <Debugging>
+ <Exceptions Count="3">
+ <Item1>
+ <Name Value="EAbort"/>
+ </Item1>
+ <Item2>
+ <Name Value="ECodetoolError"/>
+ </Item2>
+ <Item3>
+ <Name Value="EFOpenError"/>
+ </Item3>
+ </Exceptions>
+ </Debugging>
+</CONFIG>
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('<red>hello<black> <u>world</u>. <b>Graeme</b> 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.
+
+