MG: added TGtkObject.WordWrap

git-svn-id: trunk@985 -
This commit is contained in:
lazarus 2002-02-09 01:47:34 +00:00
parent 6b0dc218cc
commit 0097aa6989

View File

@ -6279,10 +6279,12 @@ end;
procedure TGtkObject.WordWrap(AText: PChar; MaxWidthInPixel: integer; procedure TGtkObject.WordWrap(AText: PChar; MaxWidthInPixel: integer;
var Lines: PPChar; var LineCount: integer); virtual; var Lines: PPChar; var LineCount: integer); virtual;
Breaks AText into several lines and creates a list of PChar. Breaks AText into several lines and creates a list of PChar. The last entry
will be nil.
Lines break at new line chars and at spaces if a line is longer than Lines break at new line chars and at spaces if a line is longer than
MaxWidthInPixel or in a word. MaxWidthInPixel or in a word.
Lines will be one memory block. Lines will be one memory block so that you can free the list and all lines
with FreeMem(Lines).
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TGtkObject.WordWrap(DC: HDC; AText: PChar; MaxWidthInPixel: integer; procedure TGtkObject.WordWrap(DC: HDC; AText: PChar; MaxWidthInPixel: integer;
var Lines: PPChar; var LineCount: integer); var Lines: PPChar; var LineCount: integer);
@ -6378,17 +6380,18 @@ var
var var
LinesList: TList; LinesList: TList;
LineStart, LineEnd: integer; LineStart, LineEnd, LineLen: integer;
TotalSize: integer; ArraySize, TotalSize: integer;
i: integer; i: integer;
CurLineEntry: PPChar;
CurLineStart: PChar;
begin begin
writeln('MG: TGtkObject.WordWrap NOT completed !!!');
if IsEmptyText then exit; if IsEmptyText then exit;
InitFont; InitFont;
LinesList:=TList.Create; LinesList:=TList.Create;
LineStart:=0; LineStart:=0;
// find all line starts and line ends
repeat repeat
LinesList.Add(Pointer(LineStart)); LinesList.Add(Pointer(LineStart));
// find line end // find line end
@ -6409,18 +6412,43 @@ begin
end; end;
until AText[LineStart]=#0; until AText[LineStart]=#0;
// create array of PChar // create mem block for 'Lines': array of PChar + all lines
LineCount:=LinesList.Count div 2; LineCount:=LinesList.Count shr 1;
TotalSize:=(LineCount+1)*SizeOf(PChar); ArraySize:=(LineCount+1)*SizeOf(PChar);
TotalSize:=ArraySize;
i:=0; i:=0;
while i<LinesList.Count do begin while i<LinesList.Count do begin
inc(TotalSize,Cardinal(LinesList[i+1])-Cardinal(LinesList[i])+1); // add LineEnd - LineStart + 1 for the #0
LineLen:=Cardinal(LinesList[i+1])-Cardinal(LinesList[i])+1;
inc(TotalSize,LineLen);
inc(i,2); inc(i,2);
end; end;
GetMem(Lines,TotalSize); GetMem(Lines,TotalSize);
// create Lines // create Lines
// ToDo CurLineEntry:=Lines;
CurLineStart:=PChar(Lines)+ArraySize;
i:=0;
while i<LinesList.Count do begin
// set the pointer to the start of the current line
CurLineEntry[i shr 1]:=CurLineStart;
// copy the line
LineStart:=Integer(LinesList[i]);
LineEnd:=Integer(LinesList[i+1]);
LineLen:=LineEnd-LineStart;
if LineLen>0 then
Move(AText[LineStart],CurLineStart^,LineLen);
inc(CurLineStart,LineLen);
// add #0 as line end
CurLineStart^:=#0;
inc(CurLineStart);
// next line
inc(i,2);
end;
if Integer(Lines)+TotalSize<>Integer(CurLineStart) then
RaiseException('TGtkObject.WordWrap Consistency Error:'
+' Lines+TotalSize<>CurLineStart');
CurLineEntry[i shr 1]:=nil;
LinesList.Free; LinesList.Free;
CleanUpFont; CleanUpFont;
@ -6435,6 +6463,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.249 2002/10/15 14:18:29 lazarus
MG: added TGtkObject.WordWrap
Revision 1.248 2002/10/15 07:01:29 lazarus Revision 1.248 2002/10/15 07:01:29 lazarus
MG: fixed timer checking MG: fixed timer checking