mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-21 02:40:13 +02:00
Mattias submitted new lresources.pp and lazres.pp files.
Shane git-svn-id: trunk@79 -
This commit is contained in:
parent
c9e26ce998
commit
d5b810aeae
@ -20,7 +20,8 @@ uses Classes, SysUtils, LResources;
|
|||||||
var
|
var
|
||||||
ResourceFilename,BinFilename,BinExt,ResourceName,ResourceType:AnsiString;
|
ResourceFilename,BinFilename,BinExt,ResourceName,ResourceType:AnsiString;
|
||||||
a:integer;
|
a:integer;
|
||||||
ResStream,BinStream:TFileStream;
|
ResFileStream,BinFileStream:TFileStream;
|
||||||
|
ResMemStream,BinMemStream:TMemoryStream;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if ParamCount<2 then begin
|
if ParamCount<2 then begin
|
||||||
@ -29,29 +30,33 @@ begin
|
|||||||
end else begin
|
end else begin
|
||||||
ResourceFilename:=ParamStr(1);
|
ResourceFilename:=ParamStr(1);
|
||||||
try
|
try
|
||||||
ResStream:=TFileStream.Create(ResourceFilename,fmCreate);
|
ResFileStream:=TFileStream.Create(ResourceFilename,fmCreate);
|
||||||
except
|
except
|
||||||
writeln('ERROR: unable to create file '''+ResourceFilename+'''');
|
writeln('ERROR: unable to create file '''+ResourceFilename+'''');
|
||||||
halt(1);
|
halt(1);
|
||||||
end;
|
end;
|
||||||
|
ResMemStream:=TMemoryStream.Create;
|
||||||
try
|
try
|
||||||
for a:=2 to ParamCount do begin
|
for a:=2 to ParamCount do begin
|
||||||
BinFilename:=ParamStr(a);
|
BinFilename:=ParamStr(a);
|
||||||
write(BinFilename);
|
write(BinFilename);
|
||||||
try
|
try
|
||||||
BinStream:=TFileStream.Create(BinFilename,fmOpenRead);
|
BinFileStream:=TFileStream.Create(BinFilename,fmOpenRead);
|
||||||
|
BinMemStream:=TMemoryStream.Create;
|
||||||
try
|
try
|
||||||
|
BinMemStream.CopyFrom(BinFileStream,BinFileStream.Size);
|
||||||
|
BinMemStream.Position:=0;
|
||||||
BinExt:=uppercase(ExtractFileExt(BinFilename));
|
BinExt:=uppercase(ExtractFileExt(BinFilename));
|
||||||
if BinExt='.LFM' then begin
|
if BinExt='.LFM' then begin
|
||||||
ResourceType:='FORMDATA';
|
ResourceType:='FORMDATA';
|
||||||
ResourceName:=FindLFMClassName(BinStream);
|
ResourceName:=FindLFMClassName(BinMemStream);
|
||||||
if ResourceName='' then begin
|
if ResourceName='' then begin
|
||||||
writeln(' ERROR: no resourcename');
|
writeln(' ERROR: no resourcename');
|
||||||
halt(2);
|
halt(2);
|
||||||
end;
|
end;
|
||||||
write(
|
write(
|
||||||
' ResourceName='''+ResourceName+''' Type='''+ResourceType+'''');
|
' ResourceName='''+ResourceName+''' Type='''+ResourceType+'''');
|
||||||
LFMtoLFCstream(BinStream,ResStream);
|
LFMtoLFCstream(BinMemStream,ResMemStream);
|
||||||
end else begin
|
end else begin
|
||||||
ResourceType:=copy(BinExt,2,length(BinExt)-1);
|
ResourceType:=copy(BinExt,2,length(BinExt)-1);
|
||||||
ResourceName:=ExtractFileName(BinFilename);
|
ResourceName:=ExtractFileName(BinFilename);
|
||||||
@ -63,11 +68,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
write(
|
write(
|
||||||
' ResourceName='''+ResourceName+''' Type='''+ResourceType+'''');
|
' ResourceName='''+ResourceName+''' Type='''+ResourceType+'''');
|
||||||
BinaryToLazarusResourceCode(BinStream,ResStream
|
BinaryToLazarusResourceCode(BinMemStream,ResMemStream
|
||||||
,ResourceName,ResourceType);
|
,ResourceName,ResourceType);
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
BinStream.Free;
|
BinFileStream.Free;
|
||||||
|
BinMemStream.Free;
|
||||||
end;
|
end;
|
||||||
except
|
except
|
||||||
writeln(' ERROR: unable to read file '''+BinFilename+'''');
|
writeln(' ERROR: unable to read file '''+BinFilename+'''');
|
||||||
@ -75,8 +81,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
writeln('');
|
writeln('');
|
||||||
end;
|
end;
|
||||||
|
ResMemStream.Position:=0;
|
||||||
|
ResFileStream.CopyFrom(ResMemStream,ResMemStream.Size);
|
||||||
finally
|
finally
|
||||||
ResStream.Free;
|
ResMemStream.Free;
|
||||||
|
ResFileStream.Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end.
|
end.
|
||||||
|
@ -15,9 +15,6 @@ unit lresources;
|
|||||||
include file.
|
include file.
|
||||||
|
|
||||||
ToDo:
|
ToDo:
|
||||||
The ResourceList is currently a sorted list, which is okay for hundreds
|
|
||||||
of resources. But stringtables consist normally of thousands of entries.
|
|
||||||
Therefore a special StringTable Resource is needed.
|
|
||||||
|
|
||||||
}
|
}
|
||||||
{$mode objfpc}
|
{$mode objfpc}
|
||||||
@ -36,8 +33,14 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
TLResourceList = class(TObject)
|
TLResourceList = class(TObject)
|
||||||
FList:TList;
|
private
|
||||||
|
FList:TList; // main list with all resource pointer
|
||||||
|
FMergeList:TList; // list needed for mergesort
|
||||||
|
FSortedCount:integer; // 0 .. FSortedCount-1 resources are sorted
|
||||||
function FindPosition(Name:AnsiString):integer;
|
function FindPosition(Name:AnsiString):integer;
|
||||||
|
procedure Sort;
|
||||||
|
procedure MergeSort(List,MergeList:TList;Pos1,Pos2:integer);
|
||||||
|
procedure Merge(List,MergeList:TList;Pos1,Pos2,Pos3:integer);
|
||||||
public
|
public
|
||||||
procedure Add(Name,ValueType,Value:AnsiString);
|
procedure Add(Name,ValueType,Value:AnsiString);
|
||||||
function Find(Name:AnsiString):LResource;
|
function Find(Name:AnsiString):LResource;
|
||||||
@ -53,11 +56,10 @@ function LFMtoLFCstream(LFMStream,LFCStream:TStream):boolean;
|
|||||||
// returns true if successful
|
// returns true if successful
|
||||||
function FindLFMClassName(LFMStream:TStream):AnsiString;
|
function FindLFMClassName(LFMStream:TStream):AnsiString;
|
||||||
|
|
||||||
|
|
||||||
var LazarusResources:TLResourceList;
|
var LazarusResources:TLResourceList;
|
||||||
|
|
||||||
implementation
|
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
procedure BinaryToLazarusResourceCode(BinStream,ResStream:TStream;
|
procedure BinaryToLazarusResourceCode(BinStream,ResStream:TStream;
|
||||||
ResourceName, ResourceType:AnsiString);
|
ResourceName, ResourceType:AnsiString);
|
||||||
@ -67,9 +69,9 @@ procedure BinaryToLazarusResourceCode(BinStream,ResStream:TStream;
|
|||||||
+#83#187#6#78#83
|
+#83#187#6#78#83
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const LineEnd:string=#10;
|
const LineEnd:ShortString=#10;
|
||||||
RightMargin:integer=79;
|
RightMargin:integer=79;
|
||||||
var s,Indent:string;
|
var s,Indent:ShortString;
|
||||||
p,x:integer;
|
p,x:integer;
|
||||||
c,h:char;
|
c,h:char;
|
||||||
RangeString,NewRangeString:boolean;
|
RangeString,NewRangeString:boolean;
|
||||||
@ -153,24 +155,35 @@ end;
|
|||||||
|
|
||||||
function LFMtoLFCfile(LFMfilename:ansistring):boolean;
|
function LFMtoLFCfile(LFMfilename:ansistring):boolean;
|
||||||
// returns true if successful
|
// returns true if successful
|
||||||
var LFMStream,LFCStream:TFileStream;
|
var
|
||||||
|
LFMFileStream,LFCFileStream:TFileStream;
|
||||||
|
LFMMemStream,LFCMemStream:TMemoryStream;
|
||||||
LFCfilename,LFMfilenameExt:ansistring;
|
LFCfilename,LFMfilenameExt:ansistring;
|
||||||
begin
|
begin
|
||||||
Result:=true;
|
Result:=true;
|
||||||
try
|
try
|
||||||
LFMStream:=TFileStream.Create(LFMfilename,fmOpenRead);
|
LFMFileStream:=TFileStream.Create(LFMfilename,fmOpenRead);
|
||||||
|
LFMMemStream:=TMemoryStream.Create;
|
||||||
|
LFCMemStream:=TMemoryStream.Create;
|
||||||
try
|
try
|
||||||
|
LFMMemStream.CopyFrom(LFMFileStream,LFMFileStream.Size);
|
||||||
|
LFMMemStream.Position:=0;
|
||||||
LFMfilenameExt:=ExtractFileExt(LFMfilename);
|
LFMfilenameExt:=ExtractFileExt(LFMfilename);
|
||||||
LFCfilename:=copy(LFMfilename,1,
|
LFCfilename:=copy(LFMfilename,1,
|
||||||
length(LFMfilename)-length(LFMfilenameExt))+'.lfc';
|
length(LFMfilename)-length(LFMfilenameExt))+'.lfc';
|
||||||
LFCStream:=TFileStream.Create(LFCfilename,fmCreate);
|
Result:=LFMtoLFCstream(LFMMemStream,LFCMemStream);
|
||||||
|
if not Result then exit;
|
||||||
|
LFCMemStream.Position:=0;
|
||||||
|
LFCFileStream:=TFileStream.Create(LFCfilename,fmCreate);
|
||||||
try
|
try
|
||||||
Result:=LFMtoLFCstream(LFMStream,LFCStream);
|
LFCFileStream.CopyFrom(LFCMemStream,LFCMemStream.Size);
|
||||||
finally
|
finally
|
||||||
LFCStream.Free;
|
LFCFileStream.Free;
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
LFMStream.Free;
|
LFMMemStream.Free;
|
||||||
|
LFCMemStream.Free;
|
||||||
|
LFMFileStream.Free;
|
||||||
end;
|
end;
|
||||||
except
|
except
|
||||||
Result:=false;
|
Result:=false;
|
||||||
@ -199,11 +212,15 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
{ TLResourceList }
|
{ TLResourceList }
|
||||||
|
|
||||||
constructor TLResourceList.Create;
|
constructor TLResourceList.Create;
|
||||||
begin
|
begin
|
||||||
FList:=TList.Create;
|
FList:=TList.Create;
|
||||||
|
FMergeList:=TList.Create;
|
||||||
|
FSortedCount:=0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TLResourceList.Destroy;
|
destructor TLResourceList.Destroy;
|
||||||
@ -218,35 +235,17 @@ begin
|
|||||||
FreeMem(p);
|
FreeMem(p);
|
||||||
end;
|
end;
|
||||||
FList.Free;
|
FList.Free;
|
||||||
|
FMergeList.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLResourceList.Add(Name,ValueType,Value:AnsiString);
|
procedure TLResourceList.Add(Name,ValueType,Value:AnsiString);
|
||||||
var NewPLResource:PLResource;
|
var NewPLResource:PLResource;
|
||||||
NewPos,cmp:integer;
|
|
||||||
begin
|
begin
|
||||||
GetMem(NewPLResource,SizeOf(LResource));
|
GetMem(NewPLResource,SizeOf(LResource));
|
||||||
NewPLResource^.Name:=Name;
|
NewPLResource^.Name:=Name;
|
||||||
NewPLResource^.ValueType:=uppercase(ValueType);
|
NewPLResource^.ValueType:=uppercase(ValueType);
|
||||||
NewPLResource^.Value:=Value;
|
NewPLResource^.Value:=Value;
|
||||||
if FList.Count=0 then begin
|
FList.Add(NewPLResource);
|
||||||
FList.Add(NewPLResource);
|
|
||||||
end else begin
|
|
||||||
NewPos:=FindPosition(Name);
|
|
||||||
if (NewPos<0) then begin
|
|
||||||
NewPos:=0;
|
|
||||||
end else if (NewPos<FList.Count) then begin
|
|
||||||
cmp:=AnsiCompareText(LResource(FList[NewPos]^).Name,Name);
|
|
||||||
if cmp=0 then begin
|
|
||||||
// resource already exists
|
|
||||||
// ToDo: replace with an exception
|
|
||||||
writeln('[TLResourceList.Add] ERROR: LResource '''+Name+''' already exists.');
|
|
||||||
halt;
|
|
||||||
end else if cmp<0 then begin
|
|
||||||
inc(NewPos);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
FList.Insert(NewPos,NewPLResource);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TLResourceList.Find(Name:AnsiString):LResource;
|
function TLResourceList.Find(Name:AnsiString):LResource;
|
||||||
@ -266,6 +265,7 @@ end;
|
|||||||
function TLResourceList.FindPosition(Name:AnsiString):integer;
|
function TLResourceList.FindPosition(Name:AnsiString):integer;
|
||||||
var l,r,cmp:integer;
|
var l,r,cmp:integer;
|
||||||
begin
|
begin
|
||||||
|
if FSortedCount<FList.Count then Sort;
|
||||||
Result:=-1;
|
Result:=-1;
|
||||||
l:=0;
|
l:=0;
|
||||||
r:=FList.Count-1;
|
r:=FList.Count-1;
|
||||||
@ -281,6 +281,69 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TLResourceList.Sort;
|
||||||
|
begin
|
||||||
|
if FSortedCount=FList.Count then exit;
|
||||||
|
// sort the unsorted elements
|
||||||
|
FMergeList.Count:=FList.Count;
|
||||||
|
MergeSort(FList,FMergeList,FSortedCount,FList.Count-1);
|
||||||
|
// merge both
|
||||||
|
Merge(FList,FMergeList,0,FSortedCount,FList.Count-1);
|
||||||
|
FSortedCount:=FList.Count;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TLResourceList.MergeSort(List,MergeList:TList; Pos1,Pos2:integer);
|
||||||
|
var cmp,mid:integer;
|
||||||
|
begin
|
||||||
|
if Pos1=Pos2 then begin
|
||||||
|
end else if Pos1+1=Pos2 then begin
|
||||||
|
cmp:=AnsiCompareText(
|
||||||
|
LResource(List[Pos1]^).Name,LResource(List[Pos2]^).Name);
|
||||||
|
if cmp>0 then begin
|
||||||
|
MergeList[Pos1]:=List[Pos1];
|
||||||
|
List[Pos1]:=List[Pos2];
|
||||||
|
List[Pos2]:=MergeList[Pos1];
|
||||||
|
end;
|
||||||
|
end else begin
|
||||||
|
if Pos2>Pos1 then begin
|
||||||
|
mid:=(Pos1+Pos2) shr 1;
|
||||||
|
MergeSort(List,MergeList,Pos1,mid);
|
||||||
|
MergeSort(List,MergeList,mid+1,Pos2);
|
||||||
|
Merge(List,MergeList,Pos1,mid+1,Pos2);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TLResourceList.Merge(List,MergeList:TList;Pos1,Pos2,Pos3:integer);
|
||||||
|
// merge two sorted arrays
|
||||||
|
// the first array ranges Pos1..Pos2-1, the second ranges Pos2..Pos3
|
||||||
|
var Src1Pos,Src2Pos,DestPos,cmp,a:integer;
|
||||||
|
begin
|
||||||
|
if (Pos1>=Pos2) or (Pos2>Pos3) then exit;
|
||||||
|
Src1Pos:=Pos2-1;
|
||||||
|
Src2Pos:=Pos3;
|
||||||
|
DestPos:=Pos3;
|
||||||
|
while (Src2Pos>=Pos2) and (Src1Pos>=Pos1) do begin
|
||||||
|
cmp:=AnsiCompareText(
|
||||||
|
LResource(List[Src1Pos]^).Name,LResource(List[Src2Pos]^).Name);
|
||||||
|
if cmp>0 then begin
|
||||||
|
MergeList[DestPos]:=List[Src1Pos];
|
||||||
|
dec(Src1Pos);
|
||||||
|
end else begin
|
||||||
|
MergeList[DestPos]:=List[Src2Pos];
|
||||||
|
dec(Src2Pos);
|
||||||
|
end;
|
||||||
|
dec(DestPos);
|
||||||
|
end;
|
||||||
|
while Src2Pos>=Pos2 do begin
|
||||||
|
MergeList[DestPos]:=List[Src2Pos];
|
||||||
|
dec(Src2Pos);
|
||||||
|
dec(DestPos);
|
||||||
|
end;
|
||||||
|
for a:=DestPos+1 to Pos3 do
|
||||||
|
List[a]:=MergeList[a];
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
LazarusResources:=TLResourceList.Create;
|
LazarusResources:=TLResourceList.Create;
|
||||||
|
|
||||||
|
14
ide/main.pp
14
ide/main.pp
@ -320,13 +320,12 @@ begin
|
|||||||
Glyph := Pixmap1;
|
Glyph := Pixmap1;
|
||||||
Visible := True;
|
Visible := True;
|
||||||
Flat := True;
|
Flat := True;
|
||||||
|
Down := True;
|
||||||
Name := 'GlobalMouseSpeedButton'+inttostr(i);
|
Name := 'GlobalMouseSpeedButton'+inttostr(i);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Writeln('REGCOMPPAGE.COUNT is '+Inttostr(RegCompPage.Count));
|
for x := 0 to RegCompPage.Count-1 do //for every component on the page....
|
||||||
for x := 0 to RegCompPage.Count-1 do
|
|
||||||
begin
|
begin
|
||||||
Writeln('X = '+inttostr(x));
|
|
||||||
RegComp := RegCompPage.Items[x];
|
RegComp := RegCompPage.Items[x];
|
||||||
IDEComponent := TIDEComponent.Create;
|
IDEComponent := TIDEComponent.Create;
|
||||||
IdeComponent.RegisteredComponent := RegComp;
|
IdeComponent.RegisteredComponent := RegComp;
|
||||||
@ -1086,7 +1085,6 @@ begin
|
|||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
Temp := nil;
|
Temp := nil;
|
||||||
Writeln('1');
|
|
||||||
for i := 0 to Notebook1.Page[Notebook1.Pageindex].ControlCount-1 do
|
for i := 0 to Notebook1.Page[Notebook1.Pageindex].ControlCount-1 do
|
||||||
begin
|
begin
|
||||||
if CompareText(TControl(Notebook1.Page[Notebook1.Pageindex].Controls[I]).Name, 'GlobalMouseSpeedButton'+inttostr(Notebook1.Pageindex)) = 0 then
|
if CompareText(TControl(Notebook1.Page[Notebook1.Pageindex].Controls[I]).Name, 'GlobalMouseSpeedButton'+inttostr(Notebook1.Pageindex)) = 0 then
|
||||||
@ -1110,7 +1108,6 @@ begin
|
|||||||
begin
|
begin
|
||||||
SelectedComponent := nil;
|
SelectedComponent := nil;
|
||||||
Temp := nil;
|
Temp := nil;
|
||||||
Writeln('2');
|
|
||||||
for i := 0 to Notebook1.Page[Notebook1.Pageindex].ControlCount-1 do
|
for i := 0 to Notebook1.Page[Notebook1.Pageindex].ControlCount-1 do
|
||||||
begin
|
begin
|
||||||
if CompareText(TControl(Notebook1.Page[Notebook1.Pageindex].Controls[I]).Name, 'GlobalMouseSpeedButton'+inttostr(Notebook1.Pageindex)) = 0 then
|
if CompareText(TControl(Notebook1.Page[Notebook1.Pageindex].Controls[I]).Name, 'GlobalMouseSpeedButton'+inttostr(Notebook1.Pageindex)) = 0 then
|
||||||
@ -1132,9 +1129,7 @@ begin
|
|||||||
if SelectedComponent <> nil then
|
if SelectedComponent <> nil then
|
||||||
TIDeComponent(IdeCompList.FindCompByRegComponent(SelectedComponent)).SpeedButton.Down := False;
|
TIDeComponent(IdeCompList.FindCompByRegComponent(SelectedComponent)).SpeedButton.Down := False;
|
||||||
SelectedComponent := nil;
|
SelectedComponent := nil;
|
||||||
writeln('Setting speedbutton down');
|
|
||||||
Temp := nil;
|
Temp := nil;
|
||||||
Writeln('3');
|
|
||||||
for i := 0 to Notebook1.Page[Notebook1.Pageindex].ControlCount-1 do
|
for i := 0 to Notebook1.Page[Notebook1.Pageindex].ControlCount-1 do
|
||||||
begin
|
begin
|
||||||
if CompareText(TControl(Notebook1.Page[Notebook1.Pageindex].Controls[I]).Name, 'GlobalMouseSpeedButton'+inttostr(Notebook1.Pageindex)) = 0 then
|
if CompareText(TControl(Notebook1.Page[Notebook1.Pageindex].Controls[I]).Name, 'GlobalMouseSpeedButton'+inttostr(Notebook1.Pageindex)) = 0 then
|
||||||
@ -1736,9 +1731,8 @@ end.
|
|||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.24 2000/12/29 13:14:04 lazarus
|
Revision 1.25 2000/12/29 13:35:50 lazarus
|
||||||
Using the lresources.pp and registering components.
|
Mattias submitted new lresources.pp and lazres.pp files.
|
||||||
This is a major change but will create much more flexibility for the IDE.
|
|
||||||
Shane
|
Shane
|
||||||
|
|
||||||
Revision 1.23 2000/12/21 20:28:33 lazarus
|
Revision 1.23 2000/12/21 20:28:33 lazarus
|
||||||
|
Loading…
Reference in New Issue
Block a user