📄 deditor.pas
字号:
Document.BlockRoot.RemoveDesignStateToAll([dsUndoStream]);
finally
DStream.Free;
end;
TStream(FUndoList[FUndoList.Count - 1]).Free;
FUndoList.Delete(FUndoList.Count - 1);
Document := Document;
end;
end;
function TBlockEditor.CanUndo: boolean;
begin
Result := FUndoList.Count > 0;
end;
procedure TBlockEditor.SetBlockDocument(const Value: BlockDocument);
begin
inherited ;
{ Set events }
if Document <> nil then
begin
Document.BlockRoot.OnSetCursor := DoSetCursor;
Document.BlockRoot.OnEditText := DoEditText;
Document.BlockRoot.OnEditImage := DoEditImage;
Document.BlockRoot.OnChangeFocus := DoChangeFocus;
Document.BlockRoot.OnBlockAddedEvent := DoBlockAddedEvent;
Document.BlockRoot.OnBlockInsertEvent := DoBlockInsertEvent;
Document.BlockRoot.OnDrawPoint := DoDrawPoint;
Document.BlockRoot.OnGetPointRectEvent := DoGetPointRect;
Document.BlockRoot.OnUndoSaveState := DoUndoSaveState;
Document.BlockRoot.DesignState := Document.BlockRoot.DesignState + [dsDesignMode];
Document.BlockRoot.SnapToGrid := FSnapToGrid;
Document.BlockRoot.EditMode := TEditMode(FBlockEditMode);
Document.BlockRoot.Mode := ModeType(FBlockInsertMode);
Document.BlockRoot.InsertBlockClass := FBlockInsertBlockClass;
end;
end;
procedure TBlockEditor.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
var
P: FloatPoint;
begin
inherited;
P := ScreenToPaper(X, Y);
if Document <> nil then
begin
Document.BlockRoot.MouseDown(Button, Shift, P.X, P.Y);
end;
end;
procedure TBlockEditor.MouseMove(Shift: TShiftState; X, Y: Integer);
var
P: FloatPoint;
begin
inherited;
P := ScreenToPaper(X, Y);
if Document <> nil then
begin
Document.BlockRoot.MouseMove(Shift, P.X, P.Y);
end;
end;
procedure TBlockEditor.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
var
P: FloatPoint;
begin
inherited;
P := ScreenToPaper(X, Y);
if Document <> nil then
begin
Document.BlockRoot.MouseUp(Button, Shift, P.X, P.Y);
end;
end;
procedure TBlockEditor.PaintPaper;
begin
inherited;
end;
procedure TBlockEditor.SetBlockEditMode(const Value: TBlockEditMode);
begin
if Document <> nil then
Document.BlockRoot.Mode := mtSelect;
if FBlockEditMode <> Value then
begin
FBlockEditMode := Value;
if Document <> nil then
begin
Document.BlockRoot.Mode := mtSelect;
Document.BlockRoot.EditMode := TEditMode(FBlockEditMode);
end;
Invalidate;
end;
end;
procedure TBlockEditor.SetBlockInsertMode(const Value: TBlockInsertMode);
begin
if Document <> nil then
Document.BlockRoot.Mode := mtSelect;
if FBlockInsertMode <> Value then
begin
FBlockInsertMode := Value;
if Document <> nil then
begin
Document.BlockRoot.Mode := ModeType(FBlockInsertMode);
end;
Invalidate;
end;
end;
procedure TBlockEditor.SetSnapToGrid(const Value: boolean);
begin
FSnapToGrid := Value;
if Document <> nil then
Document.BlockRoot.SnapToGrid := Value;
end;
function TBlockEditor.GetFocusedBlock: Block;
begin
Result := nil;
if Document <> nil then
Result := Document.BlockRoot.Focused;
end;
procedure TBlockEditor.SetInsertBlockClass(const Value: BlockClass);
begin
FBlockInsertBlockClass := Value;
if Document <> nil then
Document.BlockRoot.InsertBlockClass := Value;
end;
function TBlockEditor.GetSelected(Index: integer): Block;
var
List: TList;
begin
if Document <> nil then
begin
List := TList.Create;
try
Document.BlockRoot.PerformNotification(deAddSelectedToList, nil, [Integer(List)]);
if (Index >= 0) and (Index < List.Count) then
Result := Block(List[Index])
else
Result := nil;
finally
List.Free;
end;
end
else
Result := nil;
end;
function TBlockEditor.GetSelectedCount: Integer;
var
List: TList;
begin
if Document <> nil then
begin
List := TList.Create;
try
Document.BlockRoot.PerformNotification(deAddSelectedToList, nil, [Integer(List)]);
Result := List.Count;
finally
List.Free;
end;
end
else
Result := 0;
end;
procedure TBlockEditor.SetGripSize(const Value: integer);
begin
FGripSize := Value;
if FGripSize < 1 then FGripSize := 1;
if FGripSize > 10 then FGripSize := 10;
Invalidate;
end;
procedure TBlockEditor.SetHotArrow(const Value: boolean);
begin
FHotArrow := Value;
Invalidate;
end;
procedure TBlockEditor.Copy;
begin
Clipboard.SetComponent(FocusedBlock);
end;
procedure TBlockEditor.Cut;
var
S: Block;
begin
SaveUndo;
S := FocusedBlock;
if S <> nil then
begin
Clipboard.SetComponent(FocusedBlock);
S.Parent.RemoveBlock(S);
S.Free;
Invalidate;
end;
end;
procedure TBlockEditor.Paste;
var
i: integer;
S: Block;
begin
if Document = nil then Exit;
SaveUndo;
if Clipboard.HasFormat(CF_COMPONENT) then
begin
S := Block(Clipboard.GetComponent(Document, nil));
if S <> nil then
begin
for i := S.ComponentCount - 1 downto 0 do
S.RemoveComponent(S.Components[i]);
Document.BlockRoot.AddBlock(S);
Invalidate;
end;
end;
end;
procedure TBlockEditor.Delete;
var
S: Block;
begin
SaveUndo;
S := FocusedBlock;
if S <> nil then
begin
S.Parent.RemoveBlock(S);
S.Free;
Invalidate;
end;
end;
procedure TBlockEditor.DragOver(Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
var
S: Block;
P: FloatPoint;
B: FloatRect;
R: TRect;
begin
inherited;
Accept := (Source is TBlockDrag);
S := TBlockDrag(Source).DragBlock;
if (X > 0) and (Y > 0) and (X < ClientWidth) and (Y < ClientHeight) then
begin
P := ScreenToPaper(X, Y);
Document.BlockRoot.AddBlock(S);
S.Left := P.X - (S.Width / 2);
S.Top := P.Y - (S.Height / 2);
R.TopLeft := PaperToScreen(0, 0);
R.BottomRight := PaperToScreen(0, 0);
SendMessage(Handle, WM_REPAINT, Cardinal(SmallPoint(R.Top, R.Left)), Cardinal(SmallPoint(R.Bottom, R.Right)));
Document.BlockRoot.RemoveBlock(S);
end
else
begin
Document.BlockRoot.AddBlock(S);
Document.BlockRoot.Repaint;
Document.BlockRoot.RemoveBlock(S);
R.TopLeft := PaperToScreen(0, 0);
R.BottomRight := PaperToScreen(0, 0);
SendMessage(Handle, WM_REPAINT, Cardinal(SmallPoint(R.Top, R.Left)), Cardinal(SmallPoint(R.Bottom, R.Right)));
end;
end;
procedure TBlockEditor.DragDrop(Source: TObject; X, Y: Integer);
var
S: Block;
begin
inherited;
{ Save undo state }
SaveUndo;
S := TBlockDrag(Source).DragBlock;
Document.BlockRoot.AddBlock(S);
S.PerformNotification(deRemoveFocus, S, []);
S.DesignState := S.DesignState + [dsFocused];
S.Repaint;
end;
procedure TBlockEditor.LoadFromFile(AFileName: string);
begin
ClearUndo;
inherited;
end;
procedure TBlockEditor.LoadFromStream(AStream: TStream);
begin
ClearUndo;
inherited;
end;
procedure TBlockEditor.LoadFromTextFile(AFileName: string);
begin
ClearUndo;
inherited;
end;
procedure TBlockEditor.AddNotification(ALib: TComponent);
begin
if FLibs = nil then
FLibs := TList.Create;
if FLibs.IndexOf(ALib) < 0 then
FLibs.Add(ALib);
end;
procedure TBlockEditor.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if (Operation = opRemove) and (FLibs <> nil) then
begin
if FLibs.IndexOf(AComponent) > 0 then
FLibs.Delete(FLibs.IndexOf(AComponent));
end;
end;
procedure TBlockEditor.SetUnitType(const Value: UnitType);
var
i: integer;
begin
inherited;
if (FLibs <> nil) then
begin
for i := 0 to FLibs.Count - 1 do
TBlockLibrary(FLibs[i]).UpdateBlocks;
end;
end;
procedure TBlockEditor.AddChangeFocusBlockNotify(AOnChangeFocus: TNotifyEvent);
begin
if FChangeFocusNotify = nil then Exit;
FChangeFocusNotify.Add(TMethod(AOnChangeFocus).Code);
FChangeFocusNotify2.Add(TMethod(AOnChangeFocus).Data);
end;
procedure TBlockEditor.RemoveChangeFocusBlockNotify(AOnChangeFocus: TNotifyEvent);
begin
if FChangeFocusNotify = nil then Exit;
FChangeFocusNotify.Remove(TMethod(AOnChangeFocus).Code);
FChangeFocusNotify2.Remove(TMethod(AOnChangeFocus).Data);
end;
initialization
DResMod := TDResMod.Create(nil);
finalization
DResMod.Free;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -