From f9d84a710d7133e95d345cdea4d943bf46dc6fbe Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 17 Aug 2002 23:41:27 +0000 Subject: [PATCH] localized gtk interface git-svn-id: trunk@2536 - --- lcl/lclproc.pas | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/lcl/lclproc.pas b/lcl/lclproc.pas index db78042c02..3a29d77f42 100644 --- a/lcl/lclproc.pas +++ b/lcl/lclproc.pas @@ -79,6 +79,8 @@ procedure RaiseGDBException(const Msg: string); procedure MakeMinMax(var i1, i2: integer); procedure CalculateLeftTopWidthHeight(X1,Y1,X2,Y2: integer; var Left,Top,Width,Height: integer); + +function BreakString(const s: string; MaxLineLength, Indent: integer): string; implementation @@ -399,6 +401,56 @@ begin end; end; +function BreakString(const s: string; MaxLineLength, Indent: integer): string; +const + NewLine = {$IfDef win32}#13+{$EndIf}#10; +var + SrcLen: Integer; + APos: Integer; + Src: String; + SplitPos: Integer; + CurMaxLineLength: Integer; +begin + Result:=''; + Src:=s; + CurMaxLineLength:=MaxLineLength; + if Indent>MaxLineLength-2 then Indent:=MaxLineLength-2; + if Indent<0 then MaxLineLength:=0; + repeat + SrcLen:=length(Src); + if SrcLen<=CurMaxLineLength then begin + Result:=Result+Src; + break; + end; + // split line + // search a word boundary + APos:=CurMaxLineLength; + if APos>SrcLen then APos:=SrcLen; + SplitPos:=0; + while APos>1 do begin + if (Src[APos] in ['A'..'Z','a'..'z']) + and (not (Src[APos-1] in ['A'..'Z','a'..'z'])) then begin + SplitPos:=APos; + break; + end; + dec(APos); + end; + if SplitPos=0 then begin + // no word boundary found -> split chars + SplitPos:=CurMaxLineLength; + end; + // append part and newline + Result:=Result+copy(Src,1,SplitPos-1)+NewLine; + // append indent + if Indent>0 then + Result:=Result+StringOfChar(' ',Indent); + // calculate new LineLength + CurMaxLineLength:=MaxLineLength-Indent; + // cut string + Src:=copy(Src,SplitPos,length(Src)-SplitPos+1); + until false; +end; + initialization SendApplicationMessageFunction:=nil; OwnerFormDesignerModifiedProc:=nil;