Undo of set editor background
Posted: Mon Oct 23, 2006 11:05 am
Is there a way to implement undo/redo for changes to the editor background?
Nick Sullivan
AHA! Software
Nick Sullivan
AHA! Software
Support forums for TRichView, ScaleRichView, Report Workshop and RVMedia components
https://textally.com/forums/
Code: Select all
uses RVUndo, RVRVData, RVERVData;
type
TRVUndoBackgroundColor = class (TRVUndoInfo)
private
FBackgroundColor: TColor;
public
function RequiresFormat: Boolean; override;
procedure Undo(RVData: TRichViewRVData); override;
end;
procedure DoChangeBackgroundColor(RVData: TRichViewRVData; Color: TColor);
var UndoItem: TRVUndoBackgroundColor;
List: TRVUndoList;
Edit: TCustomRichViewEdit;
begin
Edit := TRichViewRVData(RVData.GetAbsoluteRootData).RichView as TCustomRichViewEdit;
List := TRVEditRVData(RVData).GetUndoList;
if List<>nil then begin
UndoItem := TRVUndoBackgroundColor.Create;
UndoItem.Action := rvuMisc;
UndoItem.FBackgroundColor := Edit.Color;
List.AddInfo(UndoItem, Edit);
end;
Edit.Color := Color;
end;
procedure ChangeBackgroundColor(Edit: TCustomRichViewEdit; Color: TColor);
begin
Edit.BeginUndoCustomGroup('Change Background Color');
DoChangeBackgroundColor(Edit.RVData, Color);
while Edit<>nil do begin
Edit.Invalidate;
Edit := TCustomRichViewEdit(Edit.InplaceEditor);
end;
end;
procedure TRVUndoBackgroundColor.Undo(RVData: TRichViewRVData);
begin
DoChangeBackgroundColor(RVData, FBackgroundColor);
end;
function TRVUndoBackgroundColor.RequiresFormat: Boolean;
begin
Result := False;
end;
Code: Select all
ChangeBackgroundColor(RichViewEdit1, clRed);
Code: Select all
//---------------------------------------------------------------------------
#include "RVUndo.hpp"
#include "RVRVData.hpp"
#include "RVERVData.hpp"
//---------------------------------------------------------------------------
class TRVUndoBackgroundColor : public TRVUndoInfo
{
private:
TColor FBackgroundColor;
public:
DYNAMIC bool __fastcall RequiresFormat(void);
DYNAMIC void __fastcall Undo(Rvrvdata::TRichViewRVData* RVData);
void __fastcall DoChangeBackgroundColor(TRichViewRVData *RVData, TColor Color);
};
//---------------------------------------------------------------------------
Code: Select all
void __fastcall TRVUndoBackgroundColor::Undo(Rvrvdata::TRichViewRVData* RVData)
{
DoChangeBackgroundColor(RVData, FBackgroundColor);
}
//---------------------------------------------------------------------------
bool __fastcall TRVUndoBackgroundColor::RequiresFormat()
{
return false;
}
//---------------------------------------------------------------------------
void __fastcall TRVUndoBackgroundColor::DoChangeBackgroundColor(TRichViewRVData *RVData, TColor Color)
{
TCustomRichViewEdit *Edit = (TCustomRichViewEdit *) ((TRichViewRVData *)RVData->GetAbsoluteRootData())->RichView;
TRVUndoList *List = ((TRVEditRVData *)RVData)->GetUndoList();
if(List != NULL)
{
TRVUndoBackgroundColor *UndoItem = new TRVUndoBackgroundColor();
UndoItem->Action = rvuMisc;
UndoItem->FBackgroundColor = Edit->Color;
List->AddInfo(UndoItem, Edit);
}
Edit->Color = Color;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ChangeBackgroundColor(TCustomRichViewEdit *Edit, TColor Color)
{
Edit->BeginUndoCustomGroup("Change Background Color");
TRVUndoBackgroundColor *pUndoColor = new TRVUndoBackgroundColor();
try
{
pUndoColor->DoChangeBackgroundColor(Edit->RVData, Color);
while(Edit != NULL)
{
Edit->Invalidate();
Edit = (TCustomRichViewEdit *) Edit->InplaceEditor;
}
}
__finally
{
pUndoColor->Free();
}
}
//---------------------------------------------------------------------------
Code: Select all
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ChangeBackgroundColor(rve, clRed);
}
//---------------------------------------------------------------------------
Code: Select all
uses CRVFData, RVTypes;
var RVData: TCustomRVFormattedData;
ItemNo: Integer;
AVAlign: TRVValign;
AName: TRVAnsiString;
ATag: TRVTag;
gr := RVE.GetSelectedImage;
if gr = nil then
exit;
bmp := TBitmap.Create;
bmp.Assign(gr);
RVE.RVData.GetSingleSelectedItem(RVData, ItemNo);
// we can use TopLevelEditor, because the selected image can be only in it
RVE.TopLevelEditor.GetPictureInfo(ItemNo, AName, gr, AVAlign, ATag);
RVE.TopLevelEditor.SetPictureInfoEd(ItemNo, AName, bmp, AVAlign, ATag);
Доброго дня суток!Sergey Tkachenko wrote: ↑Tue Oct 24, 2006 9:06 am This function is not implemented, but I can show how to implement it.
How to use:Code: Select all
uses RVUndo, RVRVData, RVERVData; type TRVUndoBackgroundColor = class (TRVUndoInfo) private FBackgroundColor: TColor; public function RequiresFormat: Boolean; override; procedure Undo(RVData: TRichViewRVData); override; end; procedure DoChangeBackgroundColor(RVData: TRichViewRVData; Color: TColor); var UndoItem: TRVUndoBackgroundColor; List: TRVUndoList; Edit: TCustomRichViewEdit; begin Edit := TRichViewRVData(RVData.GetAbsoluteRootData).RichView as TCustomRichViewEdit; List := TRVEditRVData(RVData).GetUndoList; if List<>nil then begin UndoItem := TRVUndoBackgroundColor.Create; UndoItem.Action := rvuMisc; UndoItem.FBackgroundColor := Edit.Color; List.AddInfo(UndoItem, Edit); end; Edit.Color := Color; end; procedure ChangeBackgroundColor(Edit: TCustomRichViewEdit; Color: TColor); begin Edit.BeginUndoCustomGroup('Change Background Color'); DoChangeBackgroundColor(Edit.RVData, Color); while Edit<>nil do begin Edit.Invalidate; Edit := TCustomRichViewEdit(Edit.InplaceEditor); end; end; procedure TRVUndoBackgroundColor.Undo(RVData: TRichViewRVData); begin DoChangeBackgroundColor(RVData, FBackgroundColor); end; function TRVUndoBackgroundColor.RequiresFormat: Boolean; begin Result := False; end;
Assignment of other background properties (BackgroundBitmap, BackgroundStyle) can be implemented in the same way (for bitmap, do not forget to implement destructor freeing the stored bitmap)Code: Select all
ChangeBackgroundColor(RichViewEdit1, clRed);
в этом случае Redo очередь не активизируетсяSergey Tkachenko wrote: ↑Fri Jun 14, 2019 11:32 am Чтобы все было правильно, в конец DoChangeBackgroundColor нужно добавить Editor.Change.
Code: Select all
procedure DoChangeBackgroundColor(RVData: TRichViewRVData; Color: TColor);
var UndoItem: TRVUndoBackgroundColor;
List: TRVUndoList;
Edit: TCustomRichViewEdit;
begin
Edit := TRichViewRVData(RVData.GetAbsoluteRootData).RichView as TCustomRichViewEdit;
List := TRVEditRVData(RVData).GetUndoList;
if List<>nil then begin
UndoItem := TRVUndoBackgroundColor.Create;
UndoItem.Action := rvuMisc;
UndoItem.FBackgroundColor := Edit.Color;
List.AddInfo(UndoItem, Edit);
end;
Edit.Color := Color;
end;
procedure ChangeBackgroundColor(Edit: TCustomRichViewEdit; Color: TColor);
begin
if Edit.CanChange then
begin
Edit.BeginUndoCustomGroup('Change Background Color');
DoChangeBackgroundColor(Edit.RVData, Color);
Edit.Change;
Edit.RefreshAll;
end;
end;