accelerated TActionList editor from Radek

git-svn-id: trunk@5256 -
This commit is contained in:
mattias 2004-03-03 23:35:55 +00:00
parent efdb296b4b
commit ea77de264a
4 changed files with 140 additions and 70 deletions

View File

@ -21,10 +21,18 @@
Radek Cervinka, radek.cervinka@centrum.cz Radek Cervinka, radek.cervinka@centrum.cz
contributors: contributors:
Mattias
version: version:
0.1 - 26-27.2.2004 - write all from scratch 0.1 - 26-27.2.2004 - write all from scratch
0.2 - 3.3.2004 - speed up filling listboxes
some ergonomic fixes (like stay in category after ADD)
fixed possible language problems
TODO:- after changing action category in Object Inspector
need sort category to listbox
- sometimes click in listbox causes selecting last item
(maybe listbox error)
} }
@ -64,7 +72,7 @@ type
destructor Destroy; override; destructor Destroy; override;
procedure SetActionList(AActionList:TActionList); procedure SetActionList(AActionList:TActionList);
procedure FillCategories; procedure FillCategories;
procedure FillActionByCategory(const sCategory:String); procedure FillActionByCategory(iIndex:Integer);
property Designer:TComponentEditorDesigner read FDesigner write FDesigner; property Designer:TComponentEditorDesigner read FDesigner write FDesigner;
end; end;
@ -119,7 +127,7 @@ begin
NewAction.Name:=FDesigner.CreateUniqueComponentName(NewAction.ClassName); NewAction.Name:=FDesigner.CreateUniqueComponentName(NewAction.ClassName);
writeln(NewAction.Name); writeln(NewAction.Name);
if lstCategory.ItemIndex>-1 then if lstCategory.ItemIndex>1 then // ignore first two items (virtual categories)
NewAction.Category:=lstCategory.Items[lstCategory.ItemIndex] NewAction.Category:=lstCategory.Items[lstCategory.ItemIndex]
else else
NewAction.Category:=''; NewAction.Category:='';
@ -146,24 +154,42 @@ begin
lstActionName.Items.Delete(iNameIndex); lstActionName.Items.Delete(iNameIndex);
OldAction:=FActionList.ActionByName(OldName); OldAction:=FActionList.ActionByName(OldName);
if OldAction=nil then begin { if OldAction=nil then begin
// item already deleted -> only update list // item already deleted -> only update list
exit; exit;
end; end;
}
// be gone // be gone
try if assigned(OldAction) then
OldAction.Free; begin
except try
// rebuild OldAction.Free;
FillActionByCategory(lstCategory.Items[lstCategory.ItemIndex]); FDesigner.PropertyEditorHook.ComponentDeleting(OldAction);
except
// rebuild
// FillActionByCategory(lstCategory.ItemIndex);
end;
end; end;
if lstActionName.Items.Count=0 then // last act in category > rebuild
FillCategories
else
begin
if iNameIndex>=lstActionName.Items.Count then
lstActionName.ItemIndex:=lstActionName.Items.Count -1
else
lstActionName.ItemIndex:=iNameIndex;
FDesigner.SelectOnlyThisComponent(
FActionList.ActionByName(lstActionName.Items[lstActionName.ItemIndex]));
end;
// FDesigner.Modified; // inform object inspector
end; end;
procedure TActionListEditor.lstCategoryClick(Sender: TObject); procedure TActionListEditor.lstCategoryClick(Sender: TObject);
begin begin
if lstCategory.ItemIndex<0 then Exit; if lstCategory.ItemIndex<0 then Exit;
FillActionByCategory(lstCategory.Items[lstCategory.ItemIndex]); FillActionByCategory(lstCategory.ItemIndex);
end; end;
procedure TActionListEditor.lstActionNameClick(Sender: TObject); procedure TActionListEditor.lstActionNameClick(Sender: TObject);
@ -178,10 +204,22 @@ begin
end; end;
procedure TActionListEditor.OnComponentDeleting(AComponent: TComponent); procedure TActionListEditor.OnComponentDeleting(AComponent: TComponent);
var
xIndex:Integer;
begin begin
if (AComponent is TAction) then if (AComponent is TAction) then
// ToDo: only set update flag and do not rebuild everything on every change begin
FillCategories; xIndex:=lstActionName.Items.IndexOf(AComponent.Name);
if xIndex<0 then Exit; // action not showed in listbox (other category)
lstActionName.Items.Delete(xIndex);
if lstActionName.Items.Count=0 then
FillCategories //last action in category is deleted, rebuild category list
else
if xIndex>=lstActionName.Items.Count then
lstActionName.ItemIndex:=lstActionName.Items.Count-1
else
lstActionName.ItemIndex:=xIndex;
end;
end; end;
procedure TActionListEditor.OnComponentAdded(AComponent: TComponent; procedure TActionListEditor.OnComponentAdded(AComponent: TComponent;
@ -296,62 +334,75 @@ var
xIndex:Integer; xIndex:Integer;
sOldCategory:String; sOldCategory:String;
begin begin
lstCategory.Clear; // try remember old category
lstCategory.Items.Add(cActionListEditorUnknownCategory); sOldCategory:='';
lstCategory.Items.Add(cActionListEditorAllCategory); if (lstCategory.Items.Count>0) and (lstCategory.ItemIndex>-1) then
if lstCategory.ItemIndex<0 then sOldCategory:=lstCategory.Items[lstCategory.ItemIndex];
lstCategory.ItemIndex:=0;
sOldCategory:=lstCategory.Items[lstCategory.ItemIndex]; lstCategory.Items.BeginUpdate;
try
lstCategory.Clear;
lstCategory.Items.Add(cActionListEditorUnknownCategory);
lstCategory.Items.Add(cActionListEditorAllCategory);
for i:=0 to FActionList.ActionCount-1 do for i:=0 to FActionList.ActionCount-1 do
begin begin
sCategory:=FActionList.Actions[i].Category; sCategory:=FActionList.Actions[i].Category;
if Trim(sCategory)='' then if Trim(sCategory)='' then
Continue; Continue;
xIndex:=lstCategory.Items.IndexOf(sCategory); xIndex:=lstCategory.Items.IndexOf(sCategory);
if xIndex<0 then if xIndex<0 then
lstCategory.Items.Add(sCategory); lstCategory.Items.Add(sCategory);
end;
finally
lstCategory.Items.EndUpdate;
end; end;
xIndex:=lstCategory.Items.IndexOf(sOldCategory); xIndex:=lstCategory.Items.IndexOf(sOldCategory);
if xIndex<0 then if xIndex<0 then
xIndex:=0; xIndex:=0;
lstCategory.ItemIndex:=xIndex; lstCategory.ItemIndex:=xIndex;
FillActionByCategory(lstCategory.Items[xIndex]); FillActionByCategory(xIndex);
end; end;
procedure TActionListEditor.FillActionByCategory(const sCategory: String); procedure TActionListEditor.FillActionByCategory(iIndex:Integer);
var var
i:Integer; i:Integer;
sCategory:String;
begin begin
lstActionName.Clear;
// handle all (ToDo: fix changing languages) lstActionName.Items.BeginUpdate;
if sCategory = cActionListEditorAllCategory then
begin
for i:=0 to FActionList.ActionCount-1 do
lstActionName.Items.Add(FActionList.Actions[i].Name);
Exit;
end;
// handle unknown (ToDo: fix changing languages) try
if sCategory = cActionListEditorUnknownCategory then lstActionName.Clear;
begin // handle all
if iIndex = 1 then
begin
for i:=0 to FActionList.ActionCount-1 do
lstActionName.Items.Add(FActionList.Actions[i].Name);
Exit; //throught finally
end;
// handle unknown
if iIndex = 0 then
begin
for i:=0 to FActionList.ActionCount-1 do
begin
if Trim(FActionList.Actions[i].Category)='' then
lstActionName.Items.Add(FActionList.Actions[i].Name);
end;
Exit; //throught finally
end;
// else sort to categories
sCategory:=lstCategory.Items[iIndex];
for i:=0 to FActionList.ActionCount-1 do for i:=0 to FActionList.ActionCount-1 do
begin begin
if trim(FActionList.Actions[i].Category)='' then if FActionList.Actions[i].Category = sCategory then
lstActionName.Items.Add(FActionList.Actions[i].Name); lstActionName.Items.Add(FActionList.Actions[i].Name);
end; end;
Exit; finally
end; lstActionName.Items.EndUpdate;
// else sort to categories
for i:=0 to FActionList.ActionCount-1 do
begin
if FActionList.Actions[i].Category = sCategory then
lstActionName.Items.Add(FActionList.Actions[i].Name);
end; end;
end; end;
@ -398,3 +449,4 @@ initialization
RegisterComponentEditor(TActionList,TActionListComponentEditor); RegisterComponentEditor(TActionList,TActionListComponentEditor);
end. end.

View File

@ -786,8 +786,6 @@ type
Procedure CreateRegion; virtual; Procedure CreateRegion; virtual;
procedure CreateHandle; virtual; procedure CreateHandle; virtual;
procedure RequiredState(ReqState: TCanvasState); procedure RequiredState(ReqState: TCanvasState);
procedure Changed; virtual;
procedure Changing; virtual;
procedure SetHandle(NewHandle: HDC); virtual; procedure SetHandle(NewHandle: HDC); virtual;
public public
constructor Create; constructor Create;
@ -795,6 +793,8 @@ type
procedure Lock; procedure Lock;
procedure Unlock; procedure Unlock;
procedure Refresh; procedure Refresh;
procedure Changing; virtual;
procedure Changed; virtual;
procedure Arc(x,y,width,height,angle1,angle2 : Integer); procedure Arc(x,y,width,height,angle1,angle2 : Integer);
procedure Arc(x,y,width,height,SX,SY,EX,EY : Integer); procedure Arc(x,y,width,height,SX,SY,EX,EY : Integer);
@ -803,8 +803,8 @@ type
procedure Chord(x,y,width,height,angle1,angle2 : Integer); procedure Chord(x,y,width,height,angle1,angle2 : Integer);
procedure Chord(x,y,width,height,SX,SY,EX,EY : Integer); procedure Chord(x,y,width,height,SX,SY,EX,EY : Integer);
Procedure CopyRect(const Dest: TRect; SrcCanvas: TCanvas; const Source: TRect); Procedure CopyRect(const Dest: TRect; SrcCanvas: TCanvas; const Source: TRect);
Procedure Draw(X,Y: Integer; Graphic : TGraphic); Procedure Draw(X,Y: Integer; SrcGraphic : TGraphic);
procedure StretchDraw(const ARect: TRect; Graphic: TGraphic); procedure StretchDraw(const DestRect: TRect; SrcGraphic: TGraphic);
procedure Ellipse(const ARect: TRect); procedure Ellipse(const ARect: TRect);
procedure Ellipse(x1, y1, x2, y2: Integer); procedure Ellipse(x1, y1, x2, y2: Integer);
Procedure FillRect(const ARect : TRect); Procedure FillRect(const ARect : TRect);
@ -1598,6 +1598,9 @@ end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.126 2004/03/03 23:35:55 mattias
accelerated TActionList editor from Radek
Revision 1.125 2004/03/02 22:37:36 mattias Revision 1.125 2004/03/02 22:37:36 mattias
clean up for TBitmapImage sharing clean up for TBitmapImage sharing

View File

@ -91,6 +91,8 @@ end;
procedure TBitmap.Draw(DestCanvas: TCanvas; const DestRect: TRect); procedure TBitmap.Draw(DestCanvas: TCanvas; const DestRect: TRect);
var var
UseMaskHandle: HBitmap; UseMaskHandle: HBitmap;
SrcDC: LongWord;
DestDC: LongWord;
begin begin
if (DestRect.Right<=DestRect.Left) or (DestRect.Bottom<=DestRect.Top) if (DestRect.Right<=DestRect.Left) or (DestRect.Bottom<=DestRect.Top)
or (Width=0) or (Height=0) then exit; or (Width=0) or (Height=0) then exit;
@ -101,10 +103,14 @@ begin
UseMaskHandle:=MaskHandle UseMaskHandle:=MaskHandle
else else
UseMaskHandle:=0; UseMaskHandle:=0;
StretchMaskBlt(DestCanvas.Handle, SrcDC:=Canvas.GetUpdatedHandle([csHandleValid]);
DestCanvas.Changing;
DestDC:=DestCanvas.GetUpdatedHandle([csHandleValid]);
StretchMaskBlt(DestDC,
DestRect.Left,DestRect.Top, DestRect.Left,DestRect.Top,
DestRect.Right-DestRect.Left,DestRect.Bottom-DestRect.Top, DestRect.Right-DestRect.Left,DestRect.Bottom-DestRect.Top,
Canvas.Handle,0,0,Width,Height, UseMaskHandle,0,0,SRCCOPY); SrcDC,0,0,Width,Height, UseMaskHandle,0,0,SRCCOPY);
DestCanvas.Changed;
end; end;
end; end;
@ -1128,6 +1134,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.77 2004/03/03 23:35:55 mattias
accelerated TActionList editor from Radek
Revision 1.76 2004/02/29 22:51:54 mattias Revision 1.76 2004/02/29 22:51:54 mattias
added jpeg example added jpeg example

View File

@ -31,22 +31,25 @@ end;
{-----------------------------------------------} {-----------------------------------------------}
{-- TCanvas.Draw --} {-- TCanvas.Draw --}
{-----------------------------------------------} {-----------------------------------------------}
Procedure TCanvas.Draw(X,Y : Integer; Graphic : TGraphic); Procedure TCanvas.Draw(X,Y : Integer; SrcGraphic : TGraphic);
var
ARect: TRect;
begin begin
If Assigned(Graphic) then if not Assigned(SrcGraphic) then exit;
StretchDraw(Rect(X, Y, Graphic.Width + X,Graphic.Height + Y), Graphic); ARect:=Bounds(X,Y,SrcGraphic.Width,SrcGraphic.Height);
StretchDraw(ARect,SrcGraphic);
end; end;
{-----------------------------------------------} {-----------------------------------------------}
{-- TCanvas.StretchDraw --} {-- TCanvas.StretchDraw --}
{-----------------------------------------------} {-----------------------------------------------}
procedure TCanvas.StretchDraw(const ARect: TRect; Graphic: TGraphic); procedure TCanvas.StretchDraw(const DestRect: TRect; SrcGraphic: TGraphic);
begin begin
if Assigned(Graphic) then if not Assigned(SrcGraphic) then exit;
begin RequiredState([csHandleValid]);
RequiredState([csHandleValid, csPenValid]); Changing;
Graphic.Draw(Self, ARect); SrcGraphic.Draw(Self, DestRect);
end; Changed;
end; end;
{-----------------------------------------------} {-----------------------------------------------}
@ -76,9 +79,9 @@ Begin
DW := Dest.Right - Dest.Left; DW := Dest.Right - Dest.Left;
if (Dh=0) or (DW=0) then exit; if (Dh=0) or (DW=0) then exit;
SrcCanvas.RequiredState([csHandleValid]);
Changing; Changing;
SrcCanvas.RequiredState([csHandleValid, csBrushValid]); RequiredState([csHandleValid]);
RequiredState([csHandleValid, csBrushValid]);
//writeln('TCanvas.CopyRect ',ClassName,' SrcCanvas=',SrcCanvas.ClassName,' ', //writeln('TCanvas.CopyRect ',ClassName,' SrcCanvas=',SrcCanvas.ClassName,' ',
// ' Src=',Source.Left,',',Source.Top,',',SW,',',SH, // ' Src=',Source.Left,',',Source.Top,',',SW,',',SH,
@ -1258,6 +1261,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.70 2004/03/03 23:35:55 mattias
accelerated TActionList editor from Radek
Revision 1.69 2004/02/28 00:34:35 mattias Revision 1.69 2004/02/28 00:34:35 mattias
fixed CreateComponent for buttons, implemented basic Drag And Drop fixed CreateComponent for buttons, implemented basic Drag And Drop