📄 jvqsplit.pas
字号:
if FStyle = spVerticalSecond then
begin
NewSize := ControlSecond.Width + X - FOffset.X;
if NewSize <= 0 then
NewSize := 1;
if NewSize >= W then
NewSize := W - DecSize;
ControlSecond.Width := NewSize;
end;
finally
Parent.EnableAlign;
end;
end;
procedure TJvxSplitter.MoveInverseRect(X, Y: Integer; AllowChange: Boolean);
var
P: TPoint;
NoDrop: Boolean;
begin
if not AllowChange then
begin
SetCursor(Screen.Cursors[crNoDrop]);
Exit;
end;
P := Point(X, Y);
CheckPosition(X, Y);
NoDrop := not AllowChange or (((X <> P.X) and (FStyle in [spVerticalFirst,
spVerticalSecond])) or ((Y <> P.Y) and (FStyle in [spHorizontalFirst,
spHorizontalSecond])));
if NoDrop <> FNoDropCursor then
begin
FNoDropCursor := NoDrop;
if NoDrop then
SetCursor(Screen.Cursors[crNoDrop])
else
SetCursor(Screen.Cursors[Cursor]);
end;
ShowInverseRect(X - FOffset.X + Width div 2, Y - FOffset.Y + Height div 2,
imMove);
end;
procedure TJvxSplitter.ShowInverseRect(X, Y: Integer; Mode: TInverseMode);
var
P: TPoint;
MaxRect: TRect;
Horiz: Boolean;
begin
P := Point(0, 0);
if FStyle in [spHorizontalFirst, spHorizontalSecond] then
begin
P.Y := Y;
Horiz := True;
end
else
begin
P.X := X;
Horiz := False;
end;
MaxRect := Parent.ClientRect;
P := ClientToScreen(P);
with P, MaxRect do
begin
TopLeft := Parent.ClientToScreen(TopLeft);
BottomRight := Parent.ClientToScreen(BottomRight);
if X < Left then
X := Left;
if X > Right then
X := Right;
if Y < Top then
Y := Top;
if Y > Bottom then
Y := Bottom;
end;
if Mode = imMove then
if ((P.X = FPrevOrg.X) and not Horiz) or
((P.Y = FPrevOrg.Y) and Horiz) then
Exit;
if Mode in [imClear, imMove] then
DrawSizingLine(FPrevOrg);
if Mode in [imNew, imMove] then
begin
DrawSizingLine(P);
FPrevOrg := P;
end;
end;
procedure TJvxSplitter.DrawSizingLine(Split: TPoint);
var
P: TPoint;
begin
if FForm <> nil then
begin
P := FForm.ScreenToClient(Split);
with FForm.Canvas do
begin
MoveTo(P.X, P.Y);
if FStyle in [spHorizontalFirst, spHorizontalSecond] then
LineTo(CToC(FForm, Self, Point(Width, 0)).X, P.Y)
else
LineTo(P.X, CToC(FForm, Self, Point(0, Height)).Y);
end;
end;
end;
function TJvxSplitter.GetStyle: TSplitterStyle;
begin
Result := spUnknown;
if ControlFirst <> nil then
begin
if ((ControlFirst.Align = alTop) and ((ControlSecond = nil) or
(ControlSecond.Align = alClient))) or
((ControlFirst.Align = alBottom) and ((ControlSecond = nil) or
(ControlSecond.Align = alClient))) then
Result := spHorizontalFirst
else
if ((ControlFirst.Align = alClient) and (ControlSecond <> nil) and
(ControlSecond.Align = alBottom)) or
((ControlFirst.Align = alClient) and (ControlSecond <> nil) and
(ControlSecond.Align = alTop)) then
Result := spHorizontalSecond
else
if ((ControlFirst.Align = alLeft) and ((ControlSecond = nil) or
(ControlSecond.Align = alClient))) or
((ControlFirst.Align = alRight) and ((ControlSecond = nil) or
(ControlSecond.Align = alClient))) then
Result := spVerticalFirst
else
if ((ControlFirst.Align = alClient) and (ControlSecond <> nil) and
(ControlSecond.Align = alRight)) or
((ControlFirst.Align = alClient) and (ControlSecond <> nil) and
(ControlSecond.Align = alLeft)) then
Result := spVerticalSecond;
case Result of
spHorizontalFirst, spVerticalFirst:
if Align <> FControlFirst.Align then
Result := spUnknown;
spHorizontalSecond, spVerticalSecond:
if Align <> FControlSecond.Align then
Result := spUnknown;
end;
end;
end;
procedure TJvxSplitter.SetAlign(Value: TAlign);
begin
if not (Align in [alTop, alBottom, alLeft, alRight]) then
begin
inherited Align := Value;
if not (csReading in ComponentState) then
begin
if Value in [alTop, alBottom] then
Height := DefWidth
else
if Value in [alLeft, alRight] then
Width := DefWidth;
end;
end
else
inherited Align := Value;
if (ControlFirst = nil) and (ControlSecond = nil) then
ControlFirst := FindControl;
end;
function TJvxSplitter.GetAlign: TAlign;
begin
Result := inherited Align;
end;
function TJvxSplitter.GetCursor: TCursor;
begin
Result := crDefault;
case GetStyle of
spHorizontalFirst, spHorizontalSecond:
Result := crVSplit;
spVerticalFirst, spVerticalSecond:
Result := crHSplit;
end;
end;
procedure TJvxSplitter.SetControlFirst(Value: TControl);
begin
if Value <> FControlFirst then
begin
if (Value = Self) or (Value is TForm) then
FControlFirst := nil
else
begin
FControlFirst := Value;
if Value <> nil then
Value.FreeNotification(Self);
end;
UpdateState;
end;
end;
procedure TJvxSplitter.SetControlSecond(Value: TControl);
begin
if Value <> FControlSecond then
begin
if (Value = Self) or (Value is TForm) then
FControlSecond := nil
else
begin
FControlSecond := Value;
if Value <> nil then
Value.FreeNotification(Self);
end;
UpdateState;
end;
end;
procedure TJvxSplitter.Notification(AComponent: TComponent; AOperation: TOperation);
begin
inherited Notification(AComponent, AOperation);
if AOperation = opRemove then
begin
if AComponent = ControlFirst then
ControlFirst := nil
else
if AComponent = ControlSecond then
ControlSecond := nil;
end;
end;
procedure TJvxSplitter.Changed;
begin
if Assigned(FOnPosChanged) then
FOnPosChanged(Self);
end;
procedure TJvxSplitter.Changing(X, Y: Integer; var AllowChange: Boolean);
begin
if Assigned(FOnPosChanging) then
FOnPosChanging(Self, X, Y, AllowChange);
end;
procedure TJvxSplitter.StopSizing(X, Y: Integer; Apply: Boolean);
var
AllowChange: Boolean;
begin
if FSizing then
begin
ReleaseCapture;
AllowChange := Apply;
if Apply then
Changing(X, Y, AllowChange);
EndInverseRect(X, Y, AllowChange, Apply);
FSizing := False;
Application.ShowHint := FAppShowHint;
if Assigned(FActiveControl) then
begin
TWinControlAccessProtected(FActiveControl).OnKeyDown := FOldKeyDown;
FActiveControl := nil;
end;
if Apply then
Changed;
end;
end;
procedure TJvxSplitter.ControlKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Assigned(FOldKeyDown) then
FOldKeyDown(Sender, Key, Shift);
StopSizing(0, 0, False);
end;
procedure TJvxSplitter.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
inherited MouseDown(Button, Shift, X, Y);
if not (csDesigning in ComponentState) and (Button = mbLeft) then
begin
FStyle := GetStyle;
if FStyle <> spUnknown then
begin
FSizing := True;
FAppShowHint := Application.ShowHint;
SetCapture(Handle);
with ValidParentForm(Self) do
begin
if ActiveControl <> nil then
FActiveControl := ActiveControl
else
FActiveControl := GetParentForm(Self);
FOldKeyDown := TWinControlAccessProtected(FActiveControl).OnKeyDown;
TWinControlAccessProtected(FActiveControl).OnKeyDown := ControlKeyDown;
end;
Application.ShowHint := False;
FOffset := Point(X, Y);
StartInverseRect;
end;
end;
end;
procedure TJvxSplitter.MouseMove(Shift: TShiftState; X, Y: Integer);
var
AllowChange: Boolean;
begin
inherited MouseMove(Shift, X, Y);
if (GetCapture = Handle) and FSizing then
begin
AllowChange := True;
Changing(X, Y, AllowChange);
MoveInverseRect(X, Y, AllowChange);
end;
end;
procedure TJvxSplitter.MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
StopSizing(X, Y, True);
inherited MouseUp(Button, Shift, X, Y);
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvQSplit.pas,v $';
Revision: '$Revision: 1.13 $';
Date: '$Date: 2004/09/07 23:11:35 $';
LogPath: 'JVCL\run'
);
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -