📄 fdmain.pas.svn-base
字号:
FDefaultBrush.Free;
FDesignerBrush.Free;
FControls.Free;
FCanvas.Free;
FLockedGrab.Free;
FMultiGrab.Free;
FNormalGrab.Free;
inherited;
end;
procedure TCustomFormDesigner.Update;
var
i: Integer;
begin
UpdateGrid;
UpdateGrabs;
if ControlCount>1 then
for i:=0 to Pred(ControlCount) do DrawMultiSelect(Controls[i]);
end;
function TCustomFormDesigner.IsLocked(AControl: TControl): Boolean;
begin
if ValidControl(AControl) then
if AControl=ParentForm then Result:=True
else
begin
case FLockChildren of
cmNormal: Result:=InTheList(FLockedControls,AControl) or InTheList(FLockedControls,AControl.Parent);
cmRecurse:
repeat
Result:=InTheList(FLockedControls,AControl);
if Result then Break
else
if ValidControl(AControl) then AControl:=AControl.Parent
else AControl:=nil;
until (AControl=nil) or (AControl=ParentForm);
else Result:=InTheList(FLockedControls,AControl);
end;
Result:=Result xor FLockedInverse;
end
else Result:=False;
end;
function TCustomFormDesigner.IsProtected(AControl: TControl): Boolean;
begin
if ValidControl(AControl) then
if AControl=ParentForm then Result:=True
else
begin
case FProtectChildren of
cmNormal: Result:=InTheList(FProtectedControls,AControl) or InTheList(FProtectedControls,AControl.Parent);
cmRecurse:
repeat
Result:=InTheList(FProtectedControls,AControl);
if Result then Break
else
if ValidControl(AControl) then AControl:=AControl.Parent
else AControl:=nil;
until (AControl=nil) or (AControl=ParentForm);
else Result:=InTheList(FProtectedControls,AControl);
end;
Result:=Result xor FProtectedInverse;
end
else Result:=False;
end;
function TCustomFormDesigner.IsTransparent(AControl: TControl): Boolean;
begin
if ValidControl(AControl) then
if AControl=ParentForm then Result:=True
else
begin
case FTransparentChildren of
cmNormal: Result:=InTheList(FTransparentControls,AControl) or InTheList(FTransparentControls,AControl.Parent);
cmRecurse:
repeat
Result:=InTheList(FTransparentControls,AControl);
if Result then Break
else
if ValidControl(AControl) then AControl:=AControl.Parent
else AControl:=nil;
until (AControl=nil) or (AControl=ParentForm);
else Result:=InTheList(FTransparentControls,AControl);
end;
Result:=Result xor FTransparentInverse;
end
else Result:=False;
end;
function TCustomFormDesigner.GetControlCount: Integer;
begin
Result:=FControls.Count;
end;
function TCustomFormDesigner.GetLocked: Boolean;
begin
Result:=FLockCounter>0;
end;
function TCustomFormDesigner.GetParentForm: TCustomForm;
begin
if Assigned(Owner) and (Owner is TCustomForm) then Result:=TCustomForm(Owner)
else Result:=nil;
end;
function TCustomFormDesigner.GetFormData: string;
var
StringStream: TStringStream;
begin
StringStream:=TStringStream.Create('');
try
SaveToStream(StringStream,dfmText);
Result:=StringStream.DataString;
finally
StringStream.Free;
end;
end;
procedure TCustomFormDesigner.SetFormData(const Value: string);
var
StringStream: TStringStream;
begin
StringStream:=TStringStream.Create(Value);
try
LoadFromStream(StringStream,dfmText);
finally
StringStream.Free;
end;
end;
procedure TCustomFormDesigner.SetActive(Value: Boolean);
begin
if Value<>FActive then
begin
if Value then
begin
if Assigned(Owner) then
if Owner is TCustomForm then
begin
FGrabHandles:=TGrabHandles.Create(Self);
Control:=nil;
UpdateGrabs;
if Assigned(ParentForm) then ParentForm.ActiveControl:=nil;
end
else raise EFormDesigner.Create('Owner of TFormDesigner must be TCustomForm descendant.')
else raise EFormDesigner.Create('TFormDesigner has no parent window.');
if Assigned(Designers) then
with Designers do
if IndexOf(Self)=-1 then Add(Self);
if MessageProcessor=mpEvent then
begin
FOnApplicationMessage:=Application.OnMessage;
Application.OnMessage:=ApplicationMessage;
end
else
if HookID=0 then HookID:=SetWindowsHookEx(WH_GETMESSAGE,HookProc,HInstance,GetCurrentThreadID);
if Assigned(ParentForm) then
with ParentForm do
begin
FDefaultBrush.Assign(Brush);
Brush.Bitmap:=FDesignerBrush;
end;
Update;
CreateContainers;
if apAutoShow in FAlignmentPalette then FAPForm.Show;
end
else
begin
Designers.Remove(Self);
if MessageProcessor=mpEvent then Application.OnMessage:=FOnApplicationMessage
else
if not Assigned(Designers) or (Designers.Count=0) then
begin
UnhookWindowsHookEx(HookID);
HookID:=0;
end;
if not (csDestroying in ComponentState) then
begin
FAPForm.Hide;
LeaveMouseAction;
if Assigned(ParentForm) then ParentForm.Brush.Assign(FDefaultBrush);
Control:=nil;
if Assigned(FGrabHandles) then
begin
FGrabHandles.Free;
FGrabHandles:=nil;
end;
DestroyContainers;
end;
end;
FActive:=Value;
if Assigned(ParentForm) then
RedrawWindow(ParentForm.Handle,nil,0,RDW_ERASE or RDW_INVALIDATE);
Screen.Cursor:=crDefault;
if FActive then
begin
if Assigned(FOnActivate) then FOnActivate(Self);
end
else
if Assigned(FOnDeactivate) then FOnDeactivate(Self);
end;
end;
procedure TCustomFormDesigner.SetMessageProcessor(Value: TMessageProcessor);
begin
if FActive then EFormDesigner.Create('Cannot change message processor when TFormDesigner is active')
else
if Value<>FMessageProcessor then FMessageProcessor:=Value;
end;
procedure TCustomFormDesigner.SetGridStep(Value: Integer);
begin
if Value<2 then Value:=2;
if Value>128 then Value:=128;
if Value<>FGridStep then
begin
FGridStep:=Value;
UpdateGrid;
end;
end;
procedure TCustomFormDesigner.SetDisplayGrid(Value: Boolean);
begin
if Value<>FDisplayGrid then
begin
FDisplayGrid:=Value;
UpdateGrid;
end;
end;
procedure TCustomFormDesigner.SetDesignerColor(Value: TColor);
begin
if Value<>FDesignerColor then
begin
FDesignerColor:=Value;
UpdateGrid;
end;
end;
procedure TCustomFormDesigner.SetGridColor(Value: TColor);
begin
if Value<>FGridColor then
begin
FGridColor:=Value;
UpdateGrid;
end;
end;
procedure TCustomFormDesigner.SetMoveSizeHint(Value: Boolean);
begin
if Value<>FShowMoveSizeHint then
begin
FShowMoveSizeHint:=Value;
if not FShowMoveSizeHint then HideHint;
end;
end;
procedure TCustomFormDesigner.SetGrabSize(Value: Integer);
begin
if Value<3 then Value:=3;
if Value>32 then Value:=32;
if Value<>FGrabSize then
begin
FGrabSize:=Value;
UpdateGrabs;
end;
end;
procedure TCustomFormDesigner.SetAlignmentPalette(Value: TAlignmentPaletteOptions);
begin
FAlignmentPalette:=Value;
if Assigned(FAPForm) then
with TfrmAlignmentPalette(FAPForm) do
begin
if apStayOnTop in FAlignmentPalette then FormStyle:=fsStayOnTop
else FormStyle:=fsNormal;
ShowHint:=apShowHints in FAlignmentPalette;
SetFlatButtons(apFlatButtons in FAlignmentPalette);
end;
end;
procedure TCustomFormDesigner.SetNormalGrabBorder(Value: TColor);
begin
if Value<>FNormalGrabBorder then
begin
FNormalGrabBorder:=Value;
UpdateGrabs;
end;
end;
procedure TCustomFormDesigner.SetNormalGrabFill(Value: TColor);
begin
if Value<>FNormalGrabFill then
begin
FNormalGrabFill:=Value;
UpdateGrabs;
end;
end;
procedure TCustomFormDesigner.SetMultiGrabBorder(Value: TColor);
begin
if Value<>FMultiGrabBorder then
begin
FMultiGrabBorder:=Value;
UpdateGrabs;
end;
end;
procedure TCustomFormDesigner.SetMultiGrabFill(Value: TColor);
begin
if Value<>FMultiGrabFill then
begin
FMultiGrabFill:=Value;
UpdateGrabs;
end;
end;
procedure TCustomFormDesigner.SetLockedGrabBorder(Value: TColor);
begin
if Value<>FLockedGrabBorder then
begin
FLockedGrabBorder:=Value;
UpdateGrabs;
end;
end;
procedure TCustomFormDesigner.SetLockedGrabFill(Value: TColor);
begin
if Value<>FLockedGrabFill then
begin
FLockedGrabFill:=Value;
UpdateGrabs;
end;
end;
function TCustomFormDesigner.GetControl: TControl;
begin
with FControls do
if Count>0 then Result:=FControls[0]
else Result:=nil;
end;
procedure TCustomFormDesigner.SetControl(Value: TControl);
begin
{$IFDEF TFDTRIAL}
if ValidControl(Value) and (Value.Parent<>ParentForm) then
begin
Control:=nil;
ShowTrialWarning;
Exit;
end;
{$ENDIF}
if (Value<>Control) and not IsTransparent(Value) and not IsProtected(Value) then
begin
with FControls do
while Count>0 do DeleteControl(Controls[0]);
AddControl(Value);
if ValidControl(Control) and Assigned(ParentForm) then ParentForm.ActiveControl:=nil;
Application.ProcessMessages;
if not ValidControl(Control) and Assigned(FOnSelectControl) then FOnSelectControl(Self,Control);
end;
end;
function TCustomFormDesigner.GetControlByIndex(Index: Integer): TControl;
begin
with FControls do
if (Index>=0) and (Index<Count) then Result:=FControls[Index]
else
begin
Result:=nil;
EFormDesigner.Create('Index of Controls array is out or range.');
end;
end;
procedure TCustomFormDesigner.SetLockedControls(Value: TStrings);
begin
FLockedControls.Assign(Value);
if FActive and IsLocked(Control) then Control:=nil;
end;
procedure TCustomFormDesigner.SetLockedInverse(Value: Boolean);
begin
if Value<>FLockedInverse then
begin
FLockedInverse:=Value;
if FActive and IsLocked(Control) then Control:=nil;
end;
end;
procedure TCustomFormDesigner.SetLockChildren(Value: TChildrenMode);
begin
if Value<>FLockChildren then
begin
FLockChildren:=Value;
if FActive and IsLocked(Control) then Control:=nil;
end;
end;
procedure TCustomFormDesigner.SetProtectedControls(Value: TStrings);
begin
FProtectedControls.Assign(Value);
if FActive and IsProtected(Control) then Control:=nil;
end;
procedure TCustomFormDesigner.SetProtectedInverse(Value: Boolean);
begin
if Value<>FProtectedInverse then
begin
FProtectedInverse:=Value;
if FActive and IsProtected(Control) then Control:=nil;
end;
end;
procedure TCustomFormDesigner.SetProtectChildren(Value: TChildrenMode);
begin
if Value<>FProtectChildren then
begin
FProtectChildren:=Value;
if FActive and IsProtected(Control) then Control:=nil;
end;
end;
procedure TCustomFormDesigner.SetProtectMode(Value: TProtectMode);
begin
if Value<>FProtectMode then
begin
FProtectMode:=Value;
if FActive and (ProtectMode=pmUnselect) and
Assigned(ParentForm) and (ParentForm.ActiveControl<>nil) then Control:=nil;
end;
end;
procedure TCustomFormDesigner.SetTransparentControls(Value: TStrings);
begin
FTransparentControls.Assign(Value);
if FActive and IsTransparent(Control) then Control:=nil;
end;
procedure TCustomFormDesigner.SetTransparentInverse(Value: Boolean);
begin
if Value<>FTransparentInverse then
begin
FTransparentInverse:=Value;
if FActive and IsTransparent(Control) then Control:=nil;
end;
end;
procedure TCustomFormDesigner.SetTransparentChildren(Value: TChildrenMode);
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -