📄 rm_tb97tlbr.pas
字号:
end
else begin
if Height > ASize then ASize := Height;
end;
end;
end;
end;
procedure TCustomToolbar97.GetParams (var Params: TToolWindowParams);
begin
inherited;
with Params do begin
CallAlignControls := False;
ResizeEightCorner := False;
ResizeClipCursor := False;
end;
end;
procedure TCustomToolbar97.GetToolbarParams (var Params: TToolbarParams);
begin
with Params do begin
InitializeOrderByPosition := True;
DesignOrderByPosition := True;
end;
end;
procedure TCustomToolbar97.Paint;
var
S: Integer;
begin
inherited;
{ Long separators when not docked }
if not Docked then
for S := 0 to LineSeps.Count-1 do begin
with TLineSep(LineSeps[S]) do begin
if Blank then Continue;
Canvas.Pen.Color := clBtnShadow;
Canvas.MoveTo (1, Y-4); Canvas.LineTo (ClientWidth-1, Y-4);
Canvas.Pen.Color := clBtnHighlight;
Canvas.MoveTo (1, Y-3); Canvas.LineTo (ClientWidth-1, Y-3);
end;
end;
end;
function ControlVisibleOrDesigning (AControl: TControl): Boolean;
begin
Result := AControl.Visible or (csDesigning in AControl.ComponentState);
end;
procedure TCustomToolbar97.SetControlVisible (const Control: TControl;
const LeftOrRight: Boolean);
{ If Control is a master or slave control, it automatically adjusts the
Visible properties of both the master and slave control based on the value
of LeftOrRight }
var
I: Integer;
begin
for I := 0 to SlaveInfo.Count-1 do
with PSlaveInfo(SlaveInfo[I])^ do
if (TopBottom = Control) or (LeftRight = Control) then begin
if Assigned(TopBottom) then TopBottom.Visible := not LeftOrRight;
if Assigned(LeftRight) then LeftRight.Visible := LeftOrRight;
Exit;
end;
end;
function TCustomToolbar97.ShouldControlBeVisible (const Control: TControl;
const LeftOrRight: Boolean): Boolean;
{ If Control is a master or slave control, it returns the appropriate visibility
setting based on the value of LeftOrRight, otherwise it simply returns the
current Visible setting }
var
I: Integer;
begin
for I := 0 to SlaveInfo.Count-1 do
with PSlaveInfo(SlaveInfo[I])^ do
if TopBottom = Control then begin
Result := not LeftOrRight;
Exit;
end
else
if LeftRight = Control then begin
Result := LeftOrRight;
Exit;
end;
Result := ControlVisibleOrDesigning(Control);
end;
procedure TCustomToolbar97.FreeGroupInfo (const List: TList);
var
I: Integer;
L: PGroupInfo;
begin
if List = nil then Exit;
for I := List.Count-1 downto 0 do begin
L := List.Items[I];
if Assigned(L) then begin
L^.Members.Free;
FreeMem (L);
end;
List.Delete (I);
end;
end;
procedure TCustomToolbar97.BuildGroupInfo (const List: TList;
const TranslateSlave: Boolean; const OldDockType, NewDockType: TDockType);
var
I: Integer;
GI: PGroupInfo;
Children: TList; {items casted into TControls}
C: TControl;
NewGroup: Boolean;
Extra: TCompareExtra;
begin
FreeGroupInfo (List);
if ControlCount = 0 then Exit;
Children := TList.Create;
try
for I := 0 to ControlCount-1 do
if (not TranslateSlave and ControlVisibleOrDesigning(Controls[I])) or
(TranslateSlave and ShouldControlBeVisible(Controls[I], NewDockType = dtLeftRight)) then
Children.Add (Controls[I]);
with Extra do begin
Toolbar := Self;
CurDockType := OldDockType;
ComparePositions := (csDesigning in ComponentState) and
ToolbarParams.DesignOrderByPosition;
end;
if Extra.ComparePositions then begin
CleanOrderList;
ListSortEx (OrderList, CompareControls, @Extra);
end;
ListSortEx (Children, CompareControls, @Extra);
GI := nil;
NewGroup := True;
for I := 0 to Children.Count-1 do begin
if NewGroup then begin
NewGroup := False;
GI := AllocMem(SizeOf(TGroupInfo));
{ Note: AllocMem initializes the newly allocated data to zero }
GI^.Members := TList.Create;
List.Add (GI);
end;
C := Children[I];
GI^.Members.Add (C);
if C is TToolbarSep97 then
NewGroup := True
else begin
with C do begin
Inc (GI^.GroupWidth, Width);
Inc (GI^.GroupHeight, Height);
end;
end;
end;
finally
Children.Free;
end;
end;
function TCustomToolbar97.OrderControls (CanMoveControls: Boolean;
PreviousDockType: TDockType; DockingTo: TDock97): TPoint;
{ This arranges the controls on the toolbar }
var
NewDockType: TDockType;
NewDocked: Boolean;
RightX, I: Integer;
CurBarSize, DockRowSize: Integer;
GInfo: TList;
AllowWrap: Boolean;
MinPosPixels, MinRowPixels, CurPosPixel, CurLinePixel, G: Integer;
GoToNewLine: Boolean;
GI: PGroupInfo;
Member: TControl;
MemberIsSep: Boolean;
GroupPosSize, MemberPosSize: Integer;
PreviousSep: TToolbarSep97; PrevMinPosPixels: Integer;
NewLineSep: TLineSep;
label 1;
begin
NewDockType := GetDockTypeOf(DockingTo);
NewDocked := Assigned(DockingTo);
RightX := FFloatingRightX;
if (NewDockType <> dtNotDocked) or (RightX = 0) then
RightX := High(RightX)
else begin
{ Make sure RightX isn't less than the smallest sized control + margins,
in case one of the *LoadToolbarPositions functions happened to read
a value too small. }
for I := 0 to ControlCount-1 do
if not(Controls[I] is TToolbarSep97) then
with Controls[I] do
if Width + (tb97LeftMarginFloating+tb97RightMarginFloating) > RightX then
RightX := Width + (tb97LeftMarginFloating+tb97RightMarginFloating);
end;
if CanMoveControls and (SlaveInfo.Count <> 0) then
for I := 0 to ControlCount-1 do
if not(Controls[I] is TToolbarSep97) then
SetControlVisible (Controls[I], NewDockType = dtLeftRight);
GetBarSize (CurBarSize, NewDockType);
if (DockingTo <> nil) and (DockingTo = DockedTo) then
GetDockRowSize (DockRowSize)
else
DockRowSize := CurBarSize;
if CanMoveControls then
GInfo := GroupInfo
else
GInfo := TList.Create;
try
BuildGroupInfo (GInfo, not CanMoveControls, PreviousDockType, NewDockType);
if CanMoveControls then
LineSeps.Clear;
CurLinePixel := tb97TopMargin[NewDocked];
MinPosPixels := tb97LeftMargin[NewDocked];
if GInfo.Count <> 0 then begin
AllowWrap := not NewDocked;
CurPosPixel := MinPosPixels;
GoToNewLine := False;
PreviousSep := nil; PrevMinPosPixels := 0;
for G := 0 to GInfo.Count-1 do begin
GI := PGroupInfo(GInfo[G]);
if NewDockType <> dtLeftRight then
GroupPosSize := GI^.GroupWidth
else
GroupPosSize := GI^.GroupHeight;
if AllowWrap and
(GoToNewLine or (CurPosPixel+GroupPosSize+tb97RightMargin[NewDocked] > RightX)) then begin
GoToNewLine := False;
CurPosPixel := tb97LeftMargin[NewDocked];
if (G <> 0) and (PGroupInfo(GInfo[G-1])^.Members.Count <> 0) then begin
Inc (CurLinePixel, CurBarSize + tb97LineSpacing);
if Assigned(PreviousSep) then begin
MinPosPixels := PrevMinPosPixels;
if CanMoveControls then begin
PreviousSep.Width := 0;
LongInt(NewLineSep) := 0;
NewLineSep.Y := CurLinePixel;
NewLineSep.Blank := PreviousSep.Blank;
LineSeps.Add (Pointer(NewLineSep));
end;
end;
end;
end;
if CurPosPixel > MinPosPixels then MinPosPixels := CurPosPixel;
for I := 0 to GI^.Members.Count-1 do begin
Member := TControl(GI^.Members[I]);
MemberIsSep := Member is TToolbarSep97;
with Member do begin
if not MemberIsSep then begin
if NewDockType <> dtLeftRight then
MemberPosSize := Width
else
MemberPosSize := Height;
end
else begin
if NewDockType <> dtLeftRight then
MemberPosSize := TToolbarSep97(Member).SizeHorz
else
MemberPosSize := TToolbarSep97(Member).SizeVert;
end;
{ If RightX is passed, proceed to next line }
if AllowWrap and not MemberIsSep and
(CurPosPixel+MemberPosSize+tb97RightMargin[NewDocked] > RightX) then begin
CurPosPixel := tb97LeftMargin[NewDocked];
Inc (CurLinePixel, CurBarSize);
GoToNewLine := True;
end;
if NewDockType <> dtLeftRight then begin
if not MemberIsSep then begin
if CanMoveControls then
SetBounds (CurPosPixel, CurLinePixel+((DockRowSize-Height) div 2), Width, Height);
Inc (CurPosPixel, Width);
end
else begin
if CanMoveControls then
SetBounds (CurPosPixel, CurLinePixel, TToolbarSep97(Member).SizeHorz, DockRowSize);
Inc (CurPosPixel, TToolbarSep97(Member).SizeHorz);
end;
end
else begin
if not MemberIsSep then begin
if CanMoveControls then
SetBounds (CurLinePixel+((DockRowSize-Width) div 2), CurPosPixel, Width, Height);
Inc (CurPosPixel, Height);
end
else begin
if CanMoveControls then
SetBounds (CurLinePixel, CurPosPixel, DockRowSize, TToolbarSep97(Member).SizeVert);
Inc (CurPosPixel, TToolbarSep97(Member).SizeVert);
end;
end;
PrevMinPosPixels := MinPosPixels;
if not MemberIsSep then
PreviousSep := nil
else
PreviousSep := TToolbarSep97(Member);
if CurPosPixel > MinPosPixels then MinPosPixels := CurPosPixel;
end;
end;
end;
end
else
Inc (MinPosPixels, tb97DefaultBarWidthHeight);
if csDesigning in ComponentState then
Invalidate;
finally
if not CanMoveControls then begin
FreeGroupInfo (GInfo);
GInfo.Free;
end;
end;
Inc (MinPosPixels, tb97RightMargin[NewDocked]);
MinRowPixels := CurLinePixel + CurBarSize + tb97BottomMargin[NewDocked];
if NewDockType <> dtLeftRight then begin
Result.X := MinPosPixels;
Result.Y := MinRowPixels;
end
else begin
Result.X := MinRowPixels;
Result.Y := MinPosPixels;
end;
end;
procedure TCustomToolbar97.CMControlListChange (var Message: TCMControlListChange);
{ The VCL sends this message is sent whenever a child control is inserted into
or deleted from the toolbar }
var
I: Integer;
begin
inherited;
with Message, OrderList do begin
{ Delete any previous occurances of Control in OrderList. There shouldn't
be any if Inserting=True, but just to be safe, check anyway. }
while True do begin
I := IndexOf(Control);
if I = -1 then Break;
Delete (I);
end;
if Inserting then begin
Add (Control);
FOrderListDirty := True;
end;
end;
end;
function CompareNewSizes (const Item1, Item2, ExtraData: Pointer): Integer; far;
begin
{ Sorts in descending order }
if ExtraData = nil then
Result := TSmallPoint(Item2).X - TSmallPoint(Item1).X
else
Result := TSmallPoint(Item2).Y - TSmallPoint(Item1).Y;
end;
procedure TCustomToolbar97.BuildPotentialSizesList (SizesList: TList);
var
MinX, SaveFloatingRightX: Integer;
X, LastY: Integer;
S: TPoint;
S2: TSmallPoint;
begin
MinX := tb97LeftMarginFloating + tb97RightMarginFloating;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -