From ea77de264a204add27c8a0faf82d8af2411d44b5 Mon Sep 17 00:00:00 2001 From: mattias Date: Wed, 3 Mar 2004 23:35:55 +0000 Subject: [PATCH] accelerated TActionList editor from Radek git-svn-id: trunk@5256 - --- ideintf/actionseditor.pas | 158 +++++++++++++++++++++++++------------- lcl/graphics.pp | 11 ++- lcl/include/bitmap.inc | 13 +++- lcl/include/canvas.inc | 28 ++++--- 4 files changed, 140 insertions(+), 70 deletions(-) diff --git a/ideintf/actionseditor.pas b/ideintf/actionseditor.pas index 08676da235..6332ed9a13 100644 --- a/ideintf/actionseditor.pas +++ b/ideintf/actionseditor.pas @@ -21,10 +21,18 @@ Radek Cervinka, radek.cervinka@centrum.cz contributors: - + Mattias version: 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; procedure SetActionList(AActionList:TActionList); procedure FillCategories; - procedure FillActionByCategory(const sCategory:String); + procedure FillActionByCategory(iIndex:Integer); property Designer:TComponentEditorDesigner read FDesigner write FDesigner; end; @@ -119,7 +127,7 @@ begin NewAction.Name:=FDesigner.CreateUniqueComponentName(NewAction.ClassName); 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] else NewAction.Category:=''; @@ -144,26 +152,44 @@ begin OldName:=lstActionName.Items[iNameIndex]; writeln('',OldName); lstActionName.Items.Delete(iNameIndex); - + OldAction:=FActionList.ActionByName(OldName); - if OldAction=nil then begin +{ if OldAction=nil then begin // item already deleted -> only update list exit; end; - +} // be gone - try - OldAction.Free; - except - // rebuild - FillActionByCategory(lstCategory.Items[lstCategory.ItemIndex]); + if assigned(OldAction) then + begin + try + OldAction.Free; + FDesigner.PropertyEditorHook.ComponentDeleting(OldAction); + except + // rebuild +// FillActionByCategory(lstCategory.ItemIndex); + 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; procedure TActionListEditor.lstCategoryClick(Sender: TObject); begin if lstCategory.ItemIndex<0 then Exit; - FillActionByCategory(lstCategory.Items[lstCategory.ItemIndex]); + FillActionByCategory(lstCategory.ItemIndex); end; procedure TActionListEditor.lstActionNameClick(Sender: TObject); @@ -178,10 +204,22 @@ begin end; procedure TActionListEditor.OnComponentDeleting(AComponent: TComponent); +var + xIndex:Integer; begin if (AComponent is TAction) then - // ToDo: only set update flag and do not rebuild everything on every change - FillCategories; + begin + 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; procedure TActionListEditor.OnComponentAdded(AComponent: TComponent; @@ -296,62 +334,75 @@ var xIndex:Integer; sOldCategory:String; begin - lstCategory.Clear; - lstCategory.Items.Add(cActionListEditorUnknownCategory); - lstCategory.Items.Add(cActionListEditorAllCategory); - if lstCategory.ItemIndex<0 then - lstCategory.ItemIndex:=0; - - sOldCategory:=lstCategory.Items[lstCategory.ItemIndex]; + // try remember old category + sOldCategory:=''; + if (lstCategory.Items.Count>0) and (lstCategory.ItemIndex>-1) then + sOldCategory:=lstCategory.Items[lstCategory.ItemIndex]; - for i:=0 to FActionList.ActionCount-1 do - begin - sCategory:=FActionList.Actions[i].Category; - if Trim(sCategory)='' then - Continue; - xIndex:=lstCategory.Items.IndexOf(sCategory); - if xIndex<0 then - lstCategory.Items.Add(sCategory); + lstCategory.Items.BeginUpdate; + try + lstCategory.Clear; + lstCategory.Items.Add(cActionListEditorUnknownCategory); + lstCategory.Items.Add(cActionListEditorAllCategory); + + for i:=0 to FActionList.ActionCount-1 do + begin + sCategory:=FActionList.Actions[i].Category; + if Trim(sCategory)='' then + Continue; + xIndex:=lstCategory.Items.IndexOf(sCategory); + if xIndex<0 then + lstCategory.Items.Add(sCategory); + end; + finally + lstCategory.Items.EndUpdate; end; - xIndex:=lstCategory.Items.IndexOf(sOldCategory); if xIndex<0 then xIndex:=0; lstCategory.ItemIndex:=xIndex; - FillActionByCategory(lstCategory.Items[xIndex]); + FillActionByCategory(xIndex); end; -procedure TActionListEditor.FillActionByCategory(const sCategory: String); +procedure TActionListEditor.FillActionByCategory(iIndex:Integer); var i:Integer; + sCategory:String; begin - lstActionName.Clear; - - // handle all (ToDo: fix changing languages) - 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) - if sCategory = cActionListEditorUnknownCategory then - begin + lstActionName.Items.BeginUpdate; + + try + lstActionName.Clear; + // 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 begin - if trim(FActionList.Actions[i].Category)='' then + if FActionList.Actions[i].Category = sCategory then lstActionName.Items.Add(FActionList.Actions[i].Name); end; - Exit; - end; - - // 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); + finally + lstActionName.Items.EndUpdate; end; end; @@ -398,3 +449,4 @@ initialization RegisterComponentEditor(TActionList,TActionListComponentEditor); end. + diff --git a/lcl/graphics.pp b/lcl/graphics.pp index c06bfd44aa..abbec55ff3 100644 --- a/lcl/graphics.pp +++ b/lcl/graphics.pp @@ -786,8 +786,6 @@ type Procedure CreateRegion; virtual; procedure CreateHandle; virtual; procedure RequiredState(ReqState: TCanvasState); - procedure Changed; virtual; - procedure Changing; virtual; procedure SetHandle(NewHandle: HDC); virtual; public constructor Create; @@ -795,6 +793,8 @@ type procedure Lock; procedure Unlock; procedure Refresh; + procedure Changing; virtual; + procedure Changed; virtual; procedure Arc(x,y,width,height,angle1,angle2 : 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,SX,SY,EX,EY : Integer); Procedure CopyRect(const Dest: TRect; SrcCanvas: TCanvas; const Source: TRect); - Procedure Draw(X,Y: Integer; Graphic : TGraphic); - procedure StretchDraw(const ARect: TRect; Graphic: TGraphic); + Procedure Draw(X,Y: Integer; SrcGraphic : TGraphic); + procedure StretchDraw(const DestRect: TRect; SrcGraphic: TGraphic); procedure Ellipse(const ARect: TRect); procedure Ellipse(x1, y1, x2, y2: Integer); Procedure FillRect(const ARect : TRect); @@ -1598,6 +1598,9 @@ end. { ============================================================================= $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 clean up for TBitmapImage sharing diff --git a/lcl/include/bitmap.inc b/lcl/include/bitmap.inc index dbecad28ef..045ffaa113 100644 --- a/lcl/include/bitmap.inc +++ b/lcl/include/bitmap.inc @@ -91,6 +91,8 @@ end; procedure TBitmap.Draw(DestCanvas: TCanvas; const DestRect: TRect); var UseMaskHandle: HBitmap; + SrcDC: LongWord; + DestDC: LongWord; begin if (DestRect.Right<=DestRect.Left) or (DestRect.Bottom<=DestRect.Top) or (Width=0) or (Height=0) then exit; @@ -101,10 +103,14 @@ begin UseMaskHandle:=MaskHandle else UseMaskHandle:=0; - StretchMaskBlt(DestCanvas.Handle, + SrcDC:=Canvas.GetUpdatedHandle([csHandleValid]); + DestCanvas.Changing; + DestDC:=DestCanvas.GetUpdatedHandle([csHandleValid]); + StretchMaskBlt(DestDC, DestRect.Left,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; @@ -1128,6 +1134,9 @@ end; { ============================================================================= $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 added jpeg example diff --git a/lcl/include/canvas.inc b/lcl/include/canvas.inc index 7cfed233b0..e1819cda46 100644 --- a/lcl/include/canvas.inc +++ b/lcl/include/canvas.inc @@ -31,22 +31,25 @@ end; {-----------------------------------------------} {-- TCanvas.Draw --} {-----------------------------------------------} -Procedure TCanvas.Draw(X,Y : Integer; Graphic : TGraphic); +Procedure TCanvas.Draw(X,Y : Integer; SrcGraphic : TGraphic); +var + ARect: TRect; begin - If Assigned(Graphic) then - StretchDraw(Rect(X, Y, Graphic.Width + X,Graphic.Height + Y), Graphic); + if not Assigned(SrcGraphic) then exit; + ARect:=Bounds(X,Y,SrcGraphic.Width,SrcGraphic.Height); + StretchDraw(ARect,SrcGraphic); end; {-----------------------------------------------} {-- TCanvas.StretchDraw --} {-----------------------------------------------} -procedure TCanvas.StretchDraw(const ARect: TRect; Graphic: TGraphic); +procedure TCanvas.StretchDraw(const DestRect: TRect; SrcGraphic: TGraphic); begin - if Assigned(Graphic) then - begin - RequiredState([csHandleValid, csPenValid]); - Graphic.Draw(Self, ARect); - end; + if not Assigned(SrcGraphic) then exit; + RequiredState([csHandleValid]); + Changing; + SrcGraphic.Draw(Self, DestRect); + Changed; end; {-----------------------------------------------} @@ -76,9 +79,9 @@ Begin DW := Dest.Right - Dest.Left; if (Dh=0) or (DW=0) then exit; + SrcCanvas.RequiredState([csHandleValid]); Changing; - SrcCanvas.RequiredState([csHandleValid, csBrushValid]); - RequiredState([csHandleValid, csBrushValid]); + RequiredState([csHandleValid]); //writeln('TCanvas.CopyRect ',ClassName,' SrcCanvas=',SrcCanvas.ClassName,' ', // ' Src=',Source.Left,',',Source.Top,',',SW,',',SH, @@ -1258,6 +1261,9 @@ end; { ============================================================================= $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 fixed CreateComponent for buttons, implemented basic Drag And Drop