📄 qreditor.pas
字号:
end;
else
Visible := false;
end;
end;
procedure TGrabHandle.Paint;
begin
if Visible then
begin
if Dim then
begin
if FPosition in [gpNE, gpNW, gpSE, gpSW] then
begin
Canvas.Brush.Color := clGray;
Canvas.Pen.Color := clGray;
Canvas.FillRect(ClientRect);
end;
end else
begin
Canvas.Brush.Color := clBlack;
Canvas.Pen.Color := clBlack;
Canvas.FillRect(ClientRect);
end;
end;
end;
constructor TFocusFrame.CreateParented(AOwner : TComponent; ParentControl : TControl);
var
Corner : TGrabPosition;
begin
Create(AOwner);
GrabHandles := TList.Create;
for Corner := gpN to gpNW do
GrabHandles.Add(TGrabHandle.CreateGrab(AOwner, ParentControl, Corner));
State := fsNormal;
FParentControl := ParentControl;
end;
destructor TFocusFrame.Destroy;
begin
while GrabHandles.Count > 0 do
begin
TObject(GrabHandles[0]).Free;
GrabHandles.Delete(0);
end;
GrabHandles.Free;
inherited Destroy;
end;
procedure TFocusFrame.UpdateGrabHandles;
var
Corner : integer;
begin
for Corner := 0 to 7 do
TGrabHandle(GrabHandles[Corner]).UpdatePosition;
end;
procedure TFocusFrame.PaintFrame;
var
AHandle : THandle;
begin
AHandle := GetDCEx(TWinControl(Owner).Handle, 0, DCX_WINDOW or DCX_PARENTCLIP);
DrawFocusRect(AHandle, CurrentRect);
ReleaseDC(TWinControl(Owner).Handle, AHandle);
end;
procedure TFocusFrame.SetState(Value : TFocusFrameState);
var
I : integer;
Ofs : TPoint;
begin
if FState = fsFrame then PaintFrame;
if Value = fsFrame then
begin
for I := 0 to GrabHandles.Count - 1 do
TGrabHandle(GrabHandles[I]).Visible := false;
FParentControl.Refresh;
CurrentRect := FParentControl.BoundsRect;
Ofs := CalcOffset(FParentControl);
OffsetRect(CurrentRect, Ofs.X - CurrentRect.Left, Ofs.Y - CurrentRect.Top);
PaintFrame;
end else
begin
for I := 0 to GrabHandles.Count - 1 do
TGrabHandle(GrabHandles[I]).Dim := Value = fsDim;
end;
FState := Value;
end;
procedure TFocusFrame.SizeFrame(ALeft, AUp, ARight, ADown : integer);
begin
if FState = fsFrame then PaintFrame;
CurrentRect.Left := CurrentRect.Left - ALeft;
CurrentRect.Top := CurrentRect.Top - AUp;
CurrentRect.Right := CurrentRect.Right + ARight;
CurrentRect.Bottom := CurrentRect.Bottom + ADown;
if FState = fsFrame then PaintFrame;
end;
procedure TFocusFrame.MoveFrame(ALeft, AUp : integer);
begin
if FState = fsFrame then PaintFrame;
OffsetRect(CurrentRect, -ALeft, -AUp);
if FState = fsFrame then PaintFrame;
end;
constructor TSelectionList.Create;
begin
ControlList := TList.Create;
FocusList := TList.Create;
FState := fsNormal;
MovedLeft := 0;
MovedUp := 0;
SizedLeft := 0;
SizedRight := 0;
SizedUp := 0;
SizedDown := 0;
end;
destructor TSelectionList.Destroy;
begin
Clear;
ControlList.Free;
FocusList.Free;
inherited Destroy;
end;
procedure TSelectionList.Add(AControl : TControl);
var
aFrame : TFocusFrame;
begin
ControlList.Add(AControl);
aFrame :=TFocusFrame.CreateParented(Editor, AControl);
aFrame.State := FState;
FocusList.Add(aFrame);
end;
procedure TSelectionList.Remove(AControl : TControl);
var
I : integer;
begin
I := ControlList.IndexOf(AControl);
if I <> - 1 then
begin
ControlList.Delete(I);
TObject(FocusList[I]).Free;
FocusList.Delete(I);
end;
end;
procedure TSelectionList.Clear;
var
I : integer;
begin
for I := 0 to FocusList.Count - 1 do
TObject(FocusList[I]).Free;
FocusList.Clear;
ControlList.Clear;
end;
function TSelectionList.IsSelected(AControl : TControl) : boolean;
begin
Result := ControlList.IndexOf(AControl) <> -1;
end;
procedure TSelectionList.SetState(Value : TFocusFrameState);
var
I : integer;
begin
for I := 0 to FocusList.Count - 1 do
TFocusFrame(FocusList[I]).State := Value;
FState := Value;
end;
function TSelectionList.GetCount : integer;
begin
Result := ControlList.Count;
end;
function TSelectionList.GetItem(Index : integer) : TControl;
begin
Result := TControl(ControlList[Index]);
end;
function TSelectionList.UpdateControls : boolean;
var
I : integer;
begin
Result := (SizedRight <> 0) or (SizedLeft <> 0) or (SizedUp <> 0) or
(SizedDown <> 0) or (MovedUp <> 0) or (MovedLeft <> 0);
for I := 0 to Count - 1 do
begin
with TControl(ControlList[I]) do
begin
Left := Left - MovedLeft - SizedLeft;
Top := Top - MovedUp - SizedUp;
Height := Height + SizedUp + SizedDown;
Width := Width + SizedLeft + SizedRight;
end;
TFocusFrame(FocusList[I]).UpdateGrabHandles;
end;
SizedRight := 0;
SizedLeft := 0;
SizedDown := 0;
SizedUp := 0;
MovedUp := 0;
MovedLeft := 0;
end;
procedure TSelectionList.UnselectChildren;
var
UnselectList : TList;
I : integer;
begin
UnselectList := TList.Create;
for I := 0 to Count - 1 do
if ControlList.IndexOf(TControl(ControlList[I]).Parent) > - 1 then
UnselectList.Add(ControlList[I]);
for I := 0 to UnselectList.Count - 1 do
Remove(TControl(UnselectList[I]));
UnselectList.Clear;
end;
procedure TSelectionList.Size(ALeft, AUp, ARight, ADown : integer);
var
I : integer;
begin
for I := 0 to Count - 1 do
TFocusFrame(FocusList[I]).SizeFrame(ALeft, AUp, ARight, ADown);
Inc(SizedRight, ARight);
Inc(SizedLeft, ALeft);
Inc(SizedDown, ADown);
Inc(SizedUp, AUp);
end;
procedure TSelectionList.Move(ALeft, AUp : integer);
var
I : integer;
begin
if (ALeft <> 0) or (AUp <> 0) then UnselectChildren;
for I := 0 to Count - 1 do
TFocusFrame(FocusList[I]).MoveFrame(ALeft, AUp);
Inc(MovedLeft, ALeft);
Inc(MovedUp, AUp);
end;
procedure TSelectionList.BringToFront;
var
I : integer;
begin
for I := 0 to ControlList.Count - 1 do
TControl(ControlList[I]).BringToFront;
end;
procedure TSelectionList.SendToBack;
var
I : integer;
begin
for I := 0 to ControlList.Count - 1 do
TControl(ControlList[I]).SendToBack;
end;
procedure TSelectionList.FindMaxValues(var ALeft, ATop, ARight, ABottom : integer);
var
I : integer;
begin
if Count > 0 then
with Items[0] do
begin
ALeft := Left;
ATop := Top;
ARight := Left + Width;
ABottom := Top + Height;
end;
if Count > 1 then
for I := 1 to Count - 1 do
with Items[I] do
begin
if Left < ALeft then ALeft := Left;
if Top < ATop then ATop := Top;
if ARight > Left + Width then ARight := Left + Width;
if ABottom > Top + Height then ABottom := Top + Height;
end;
end;
procedure TSelectionList.AlignTo(Position : TGrabPosition);
var
I : integer;
MaxLeft, MaxRight, MaxTop, MaxBottom : integer;
begin
FindMaxValues(MaxLeft, MaxTop, MaxRight, MaxBottom);
for I := 0 to Count - 1 do
with TFocusFrame(FocusList[I]) do
case Position of
gpW : Move(MaxLeft - Left, 0);
gpE : Move(MaxRight - Left - Width, 0);
gpN : Top := MaxTop;
gpS : Top := MaxBottom - Height;
end;
UpdateControls;
end;
procedure TSelectionList.AlignLefts;
begin
AlignTo(gpW);
end;
procedure TSelectionList.AlignRights;
begin
AlignTo(gpE);
end;
procedure TSelectionList.AlignTops;
begin
AlignTo(gpN);
end;
procedure TSelectionList.AlignBottoms;
begin
AlignTo(gpS);
end;
procedure TSelectionList.Copy(var Stream : TStream);
var
I, J : integer;
AComponent : TComponent;
AChild : TComponent;
begin
if Stream <> nil then Stream.Free;
Stream := TMemoryStream.Create;
Stream.Position := 0;
UnselectChildren;
for I := 0 to Count - 1 do
begin
AComponent := TComponent(ControlList[I]);
if AComponent is TWinControl then
for J := 0 to TWinControl(AComponent).ControlCount - 1 do
begin
AChild := TWinControl(AComponent).Controls[J];
AChild.Owner.RemoveComponent(AChild);
AComponent.InsertComponent(AChild);
end;
Stream.WriteComponent(TComponent(ControlList[I]));
if AComponent is TWinControl then
for J := 0 to TWinControl(AComponent).ControlCount - 1 do
begin
AChild := TWinControl(AComponent).Controls[J];
AChild.Owner.RemoveComponent(AChild);
AComponent.Owner.InsertComponent(AChild);
end;
end;
end;
constructor TCustomEditor.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
FSelectionList := TSelectionList.Create;
FSelectionList.Editor := Self;
FEditing := false;
MouseIsDown := false;
FClipboardAvailable := false;
FMainControl := nil;
FOnSelectControl := nil;
FOnUnselectControl := nil;
FOnModified := nil;
FOnClipboardStateChange := nil;
FOnAddedControl := nil;
Clipboard := nil;
BevelInner := bvNone;
BevelOuter := bvNone;
end;
destructor TCustomEditor.Destroy;
begin
FSelectionList.Free;
if Clipboard <> nil then Clipboard.Free;
inherited Destroy;
end;
procedure TCustomEditor.SetEvents(AControl : TWinControl);
var
I : integer;
begin
for I := 0 to AControl.ControlCount - 1 do with AControl do
begin
TCustomEditor(Controls[I]).OnMouseDown := MouseDownHandler;
TCustomEditor(Controls[I]).OnMouseMove := MouseMoveHandler;
TCustomEditor(Controls[I]).OnMouseUp := MouseUpHandler;
if Controls[I] is TWinControl then SetEvents(TWinControl(Controls[I]));
end;
end;
procedure TCustomEditor.SetEditing(Value : boolean);
begin
if Value then
begin
SetEvents(Self);
FModified := false;
end;
SetFocus;
FEditing := Value;
end;
procedure TCustomEditor.SetModified(Value : boolean);
begin
if (not FModified) and Value and Assigned(FOnModified) then
FOnModified(Self);
FModified := Value;
end;
procedure TCustomEditor.Add(AComponent : TComponent; AParent : TWinControl);
begin
InsertComponent(AComponent);
if AComponent is TControl then
begin
TControl(AComponent).Parent := AParent;
Select(TControl(AComponent), true);
end;
end;
procedure TCustomEditor.DoAdd(X, Y : integer);
var
AComponent : TComponent;
AParent : TWinControl;
begin
AParent := nil;
AComponent := NewComponentClass.Create(nil);
if AComponent is TControl then with TControl(AComponent) do
begin
if (SelectionList.Count = 1) and (SelectionList[0] is TWinControl) then
AParent := TWinControl(SelectionList[0])
else
AParent := Self;
Left := X;
Top := Y;
end;
SelectionList.Clear;
Add(AComponent, AParent);
SetEvents(Self);
FState := esNormal;
if Assigned(FOnAddedControl) then FOnAddedControl(AComponent);
end;
procedure TCustomEditor.DoPopup(X, Y : integer);
begin
if SelectionList.Count = 1 then;
end;
procedure TCustomEditor.AddClass(ComponentClass : TNewComponentClass);
begin
NewComponentClass := ComponentClass;
FState := esAdd;
end;
procedure TCustomEditor.Select(AControl : TControl; MultiSelect : boolean);
begin
if AControl <> MainControl then
begin
if not MultiSelect then SelectionList.Clear;
SelectionList.Add(AControl);
if SelectionList.Count > 1 then SelectionList.State := fsDim else SelectionList.State := fsNormal;
if Assigned(FOnSelectControl) then FOnSelectControl(AControl);
end;
end;
procedure TCustomEditor.Unselect(AControl : TControl);
begin
SelectionList.Remove(AControl);
if Assigned(FOnUnselectControl) then
FOnUnselectControl(AControl);
end;
procedure TCustomEditor.UnselectAll;
var
I : integer;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -