From 40tude Dialog Wiki
Contents |
Boxquotes are a cool way of emphasizing text in your posts/e-mails.
Marcus Mönnig made a script to automagically insert Boxquotes into a message before being sent. Thomas Barghahn has changed the script, so that you are able to decide inside the editor window what kind of Boxquotes (closed or open) you want to use.
To use closed Boxquotes, you have to insert the following tags inside the editor window (into your text):
box: Example - aslkdjl aksdj lkajsd lkjalsdkj lakj sadalksjd lkjasldkj lakjd lkqjlakjasl dlakjsd lkjaslkdj laksjdlk ajsldkj lakjsd lkajsdl asdlkja lkaj sdlkjalskjd lkajsd lkjaldskj lkajsdl kjasldkj lak -
You will get this kind of Boxquote:
,---- [ Example] ------------------------------------------------. | aslkdjl aksdj lkajsd lkjalsdkj lakj sadalksjd lkjasldkj lakjd | | lkqjlakjasl dlakjsd lkjaslkdj laksjdlk ajsldkj lakjsd lkajsdl | | asdlkja lkaj sdlkjalskjd lkajsd lkjaldskj lkajsdl kjasldkj lak | '----------------------------------------------------------------'
And if you don't want closed Boxquotes, just use box_o instead of box:
box_o: Example - aslkdjl aksdj lkajsd lkjalsdkj lakj sadalksjd lkjasldkj lakjd lkqjlakjasl dlakjsd lkjaslkdj laksjdlk ajsldkj lakjsd lkajsdl lkaj sdlkjalskjd lkajsd lkjaldskj lkajsdl kjasldkj lak -
And now you will get this open Boxquote.
,---- [Example] | aslkdjl aksdj lkajsd lkjalsdkj lakj sadalksjd lkjasldkj lakjd | lkqjlakjasl dlakjsd lkjaslkdj laksjdlk ajsldkj lakjsd lkajsdl | lkaj sdlkjalskjd lkajsd lkjaldskj lkajsdl kjasldkj lak '----
Please note that this script is an include-file!. You have to copy the following script inside a new custom script (for example "Boxquote_include") and safe it. Please don't compile this custom script! After that you have to add the following lines to your OnBeforeSending-Script:
{$I Boxquote_include.ds}
and
boxquote ( Message );
This may look like this:
program OnBeforeSendingMessage;
{$I Boxquote_include.ds}
function OnBeforeSendingMessage(var Message: TStringlist; Servername: string; IsEmail: boolean):boolean;
begin
result:=true;
boxquote ( Message );
//possibly some other calls to scripts
end;
begin
end.
Just compile this OnBeforeSending-Script now to get your include-file to work. The setup of the script is shown inside the script. Please take a look at this to customize the script to your own fits. Please note that whenever you reconfigure the Boxquote custom script, you have to recompile the OnBeforeSending-Script to apply the changes.
Setup in the script:
If you want to change the tags for the Boxquotes and the seperator, you have to edit the three lines below inside the include-file (custom script).
StartLine_close_box = 'box:'; StartLine_open_box = 'box_o:'; Separator = '-';
//
// program BoxQuote - Date: 2004/11/05
//
procedure Init_Boxquote ( var StartLine_close_box : String;
var StartLine_open_box : String;
var Separator : char;
var bq1a : char;
var bq1b : char;
var bq1c : char;
var bq2a : char;
var bq2c : char;
var bq3a : char;
var bq3b : char;
var bq3c : char;
var LineWidthTop : integer;
var LineWidthBottom : integer;
var s_no_bq : integer;
var s_bq_title : integer;
var s_bq_content : integer
);
begin
// ----------------------------------------------------
// Configuration settings
// ----------------------------------------------------
StartLine_close_box := 'box:';
StartLine_open_box := 'box_o:';
Separator := '-';
// ----------------------------------------------------
// End of configuration settings
// ----------------------------------------------------
// --------------------------------------------------------------- //
// ---- No user maintainable parts below this line -------------- //
// --------------------------------------------------------------- //
bq1a :=',';
bq1b :='-';
bq1c :='.';
bq2a :='|';
bq2c :='|';
bq3a :='''';
bq3b :='-';
bq3c :='''';
LineWidthTop := 4;
LineWidthBottom := 4;
s_no_bq :=0;
s_bq_title :=1;
s_bq_content :=2;
end;
function StringReplaceM(
S : String;
OldPattern : String;
NewPattern : String;
replaceall : Boolean;
ignorecase : Boolean
) : String;
var
SearchStr : String;
Patt : String;
NewStr : String;
Offset : Integer;
MaxInt : Integer;
begin
MaxInt := 2147483647;
if IgnoreCase then begin
SearchStr := AnsiUpperCase( S );
Patt := AnsiUpperCase( OldPattern );
end
else begin
SearchStr := S;
Patt := OldPattern;
end;
NewStr := S;
Result := '';
while SearchStr <> '' do begin
Offset := AnsiPos(Patt, SearchStr);
if Offset = 0 then begin
result := result + NewStr;
break;
end;
result := result + Copy( NewStr, 1, Offset - 1 ) + NewPattern;
NewStr := Copy( NewStr, Offset + Length(OldPattern), MaxInt );
if not ReplaceAll then begin
Result := Result + NewStr;
break;
end;
SearchStr := Copy( SearchStr, Offset + Length(Patt), MaxInt );
end;
end; // function StringReplaceM()
function RepeatChar(
c : Char;
count : Integer
) : String;
var
i : Integer;
begin
if count < 0 then count := 0;
SetLength( result, count );
for i:=1 to count do result[i] := c;
end; // function RepeatChar()
function CountChars(
s : String;
c : Char
) : Integer;
var
i : Integer;
begin
result := 0;
for i := 1 to Length( s ) do if s[i] = c then result := result + 1;
end; // function CountChars()
procedure BoxQuote(
var Message : TStringlist
);
var
i, j, k : Integer;
state : Word;
bq_startline : Integer;
bq_title : String;
bq_content : String;
maxwidth : Integer;
sl : Tstringlist;
CloseBox : Boolean;
StartLine_close_box : String;
StartLine_open_box : String;
Separator : Char;
bq1a : char;
bq1b : char;
bq1c : char;
bq2a : char;
bq2c : char;
bq3a : char;
bq3b : char;
bq3c : char;
LineWidthTop : integer;
LineWidthBottom : integer;
s_no_bq : integer;
s_bq_title : integer;
s_bq_content : integer;
begin
Init_Boxquote ( StartLine_close_box, StartLine_open_box, Separator, bq1a, bq1b, bq1c,
bq2a, bq2c, bq3a, bq3b, bq3c, LineWidthTop, LineWidthBottom, s_no_bq,
s_bq_title, s_bq_content );
state := s_no_bq;
i := 0;
bq_startline := -1;
while i <= message.count-1 do begin
case state of
s_no_bq: begin
if (message.strings[i] = StartLine_close_box)
or (message.strings[i] = StartLine_open_box)
then begin
if message.strings[i] = StartLine_close_box
then CloseBox := true
else CloseBox := false;
bq_startline := i;
bq_title := '';
bq_content := '';
maxwidth := 1;
state := s_bq_title;
end
end;
s_bq_title: begin
if message.strings[i] = Separator
then state := s_bq_content
else bq_title := trim( bq_title + ' ' + message.strings[i] );
end;
s_bq_content: begin
if message.strings[i]=Separator then begin
state:=s_no_bq;
if Length( '[' + bq_title + ']' ) > maxwidth
then maxwidth := Length( '[' + bq_title + ']' ) + 6;
//
// delete the raw BoxQuote
//
for j := bq_startline to i do message.delete( bq_startline );
//
// middle part
//
bq_content := stringreplacem( #13#10 + bq_content,
#13#10, #13#10 + bq2a + ' ',
true, false );
delete( bq_content, 1, 2 );
//
// first line
//
if bq_title <> ''
then bq_content := bq1a
+ RepeatChar( bq1b, LineWidthTop )
+ ' [' + bq_title + '] '
+ #13#10
+ bq_content
else bq_content := bq1a
+ RepeatChar( bq1b, LineWidthTop )
+ #13#10
+ bq_content;
//
// last line
//
bq_content := bq_content + #13#10 + bq3a + RepeatChar( bq3b, LineWidthBottom );
sl := Tstringlist.create;
try
sl.text := bq_content;
//
// close the box
//
if CloseBox then begin
for j:=0 to sl.count-1 do begin
k := maxwidth - length( sl.strings[j] );
if j=0
then sl.strings[j] := sl.strings[j] + repeatchar( bq1b,k + 3 ) + bq1c
else if j = sl.count-1
then sl.strings[j] := sl.strings[j] + repeatchar( bq3b,k + 3 ) + bq3c
else sl.strings[j] := sl.strings[j] + repeatchar(' ', k + 3) + bq2c;
end;
end;
message.insert( bq_startline, trim(sl.text) );
i := bq_startline;
finally
sl.free;
end;
end
else begin
if bq_content = ''
then bq_content := message.strings[i]
else bq_content := bq_content + #13#10 + message.strings[i];
if Length( message.strings[i] ) > maxwidth
then maxwidth := length( message.strings[i] );
end;
end;
end; // case
i := i + 1;
end;
end; // procedure BoxQuote()
René Fischer