📄 jvqcaptionpanel.pas
字号:
Invalidate;
end;
procedure TJvCaptionPanel.SetCaptionColor(Value: TColor);
begin
if FCaptionColor <> Value then
begin
FCaptionColor := Value;
Invalidate;
end;
end;
procedure TJvCaptionPanel.SetFlat(Value: Boolean);
var
I: TJvCapBtnStyle;
begin
if FFlat <> Value then
begin
FFlat := Value;
for I := Low(FButtonArray) to High(FButtonArray) do
FButtonArray[I].Flat := FFlat;
end;
end;
procedure TJvCaptionPanel.SetButtons(Value: TJvCapBtnStyles);
var
I: TJvCapBtnStyle;
begin
if FButtons <> Value then
begin
FButtons := Value;
for I := Low(FButtonArray) to High(FButtonArray) do
FButtonArray[I].Visible := (I in FButtons);
Invalidate;
end;
end;
procedure TJvCaptionPanel.SetCaptionPosition(Value: TJvDrawPosition);
begin
if FCaptionPosition <> Value then
begin
FCaptionPosition := Value;
RecreateWnd;
end;
end;
procedure TJvCaptionPanel.SetIcon(Value: TIcon);
begin
FIcon.Assign(Value);
Invalidate;
end;
procedure TJvCaptionPanel.AlignControls(AControl: TControl; var Rect: TRect);
begin
case FCaptionPosition of
dpLeft:
Rect := Classes.Rect(FCaptionWidth + FCaptionOffsetSmall, 0, ClientWidth, ClientHeight);
dpTop:
Rect := Classes.Rect(0, FCaptionWidth + FCaptionOffsetSmall, ClientWidth, ClientHeight);
dpRight:
Rect := Classes.Rect(0, 0, ClientWidth - FCaptionWidth - FCaptionOffsetSmall, ClientHeight);
dpBottom:
Rect := Classes.Rect(0, 0, ClientWidth, ClientHeight - FCaptionWidth - FCaptionOffsetSmall);
end;
inherited AlignControls(AControl, Rect);
end;
procedure TJvCaptionPanel.Paint;
var
Rotation: Integer;
R: TRect;
FlatOffset: Integer;
begin
R := ClientRect;
if BorderStyle = bsSingle then
begin
DrawShadePanel(Canvas, R, False, 1, nil);
InflateRect(R, -2, -2);
end;
with Canvas do
begin
Brush.Color := Color;
FillRect(R);
Brush.Color := FCaptionColor;
end;
FBevel := FCaptionOffsetSmall;
Rotation := 0;
FlatOffset := Ord(FlatButtons);
if FOutlookLook then
begin
if CaptionPosition = dpLeft then
FCaptionWidth := GetSystemMetrics(SM_CYCAPTION) - 3 + FlatOffset
else
if CaptionPosition = dpRight then
FCaptionWidth := GetSystemMetrics(SM_CYCAPTION) - 4 + FlatOffset
else
FCaptionWidth := GetSystemMetrics(SM_CYCAPTION) - 5 + FlatOffset
end
else
FCaptionWidth := GetSystemMetrics(SM_CYCAPTION);
case FCaptionPosition of
dpLeft:
begin
FCaptionRect := Rect(FBevel, FBevel, FCaptionWidth + FBevel, ClientHeight - FBevel);
Rotation := 90;
end;
dpTop:
FCaptionRect := Rect(FBevel, FBevel, ClientWidth - FBevel, FCaptionWidth + FBevel);
dpRight:
begin
FCaptionRect := Rect(ClientWidth - FCaptionWidth - FBevel, FBevel, ClientWidth - FBevel, ClientHeight - FBevel);
Rotation := -90;
end;
dpBottom:
FCaptionRect := Rect(FBevel, ClientHeight - FCaptionWidth - FBevel, ClientWidth - FBevel, ClientHeight - FBevel);
end; //case
Canvas.FillRect(FCaptionRect);
if not FIcon.Empty then
begin
with FCaptionRect do
case FCaptionPosition of
dpRight:
Canvas.Draw( (Left + Right - FIcon.Width) div 2, Top + 1, FIcon);
dpLeft:
Canvas.Draw( (Left + Right - FIcon.Width) div 2, Bottom - 1 - FIcon.Height, FIcon);
dpBottom, dpTop:
Canvas.Draw(Left + 1, (Top + Bottom - FIcon.Height) div 2 , FIcon );
end; //case
end;
DrawRotatedText(Rotation);
DrawButtons;
end;
procedure TJvCaptionPanel.DrawRotatedText(Rotation: Integer);
var
tH: Integer;
X, Y: Integer;
R: TRect;
begin
if FCaption = '' then
Exit;
Canvas.Start;
try
QPainter_save(Canvas.Handle);
Canvas.Font.Assign(CaptionFont);
SetBkMode(Canvas.Handle, TRANSPARENT);
with Canvas do
begin
R := FCaptionRect;
tH := ((R.Bottom - R.Top) - Canvas.TextHeight(FCaption)) div 2;
X := FCaptionRect.Left;
Y := FCaptionRect.Top;
if FOutlookLook then
begin
Dec(tH);
end;
case FCaptionPosition of
dpLeft:
begin
X := R.Left + (FCaptionWidth + Canvas.TextHeight(Caption)) div 2 - FOffset;
Y := R.Bottom - 1;
if not FIcon.Empty then
Dec(Y, FIcon.Height + 3)
else
Dec(Y);
end;
dpTop, dpBottom:
begin
X := R.Left;
Y := R.Top + tH + Canvas.TextHeight(Caption) - FOffset;
if not FIcon.Empty then
Inc(X, FIcon.Width + 3)
else
Inc(X);
end;
dpRight:
begin
X := R.Left + (FCaptionWidth - Canvas.TextHeight(Caption)) div 2 + FOffset;
Y := R.Top;
if not FIcon.Empty then
Inc(Y, FIcon.Height + 3)
else
Inc(Y);
end;
end;
// ToDo: replace with DrawText(Canvas, .... , Rotation)
TextOutAngle(Canvas, Rotation, X, Y, Caption);
end;
finally
QPainter_restore(Canvas.Handle);
Canvas.Stop;
end;
end;
procedure TJvCaptionPanel.DrawButtons;
var
R: TRect;
FWidth, FHeight: Integer;
begin
if FButtons = [] then
Exit;
FWidth := FButtonArray[capClose].Width;
FHeight := FButtonArray[capClose].Height;
if FFlat then
begin
Inc(FWidth);
Inc(FHeight);
end;
case FCaptionPosition of
dpLeft:
R := Rect(FCaptionRect.Left + FCaptionOffsetSmall, FCaptionRect.Top + FCaptionOffsetSmall, 0, 0);
dpTop:
R := Rect(FCaptionRect.Right - FWidth - FCaptionOffsetSmall, FCaptionRect.Top + FCaptionOffsetLarge, 0, 0);
dpRight:
R := Rect(FCaptionRect.Left + FCaptionOffsetSmall, FCaptionRect.Bottom - FHeight - FCaptionOffsetSmall, 0, 0);
dpBottom:
R := Rect(FCaptionRect.Right - FWidth - FCaptionOffsetSmall, FCaptionRect.Top + FCaptionOffsetLarge, 0, 0);
end;
if capClose in FButtons then
begin
FButtonArray[capClose].Top := R.Top;
FButtonArray[capClose].Left := R.Left;
FButtonArray[capClose].Visible := True;
case FCaptionPosition of
dpLeft:
OffsetRect(R, 0, FHeight + FCaptionOffsetSmall);
dpTop:
OffsetRect(R, -FWidth - FCaptionOffsetSmall, 0);
dpRight:
OffsetRect(R, 0, -FHeight - FCaptionOffsetSmall);
dpBottom:
OffsetRect(R, -FWidth - FCaptionOffsetSmall, 0);
end;
end
else
FButtonArray[capClose].Visible := False;
if (capMax in FButtons) then
begin
FButtonArray[capMax].Top := R.Top;
FButtonArray[capMax].Left := R.Left;
FButtonArray[capMax].Visible := True;
case FCaptionPosition of
dpLeft:
OffsetRect(R, 0, FHeight);
dpTop:
OffsetRect(R, -FWidth, 0);
dpRight:
OffsetRect(R, 0, -FHeight);
dpBottom:
OffsetRect(R, -FWidth, 0);
end;
end
else
FButtonArray[capMax].Visible := False;
if capRestore in FButtons then
begin
FButtonArray[capRestore].Top := R.Top;
FButtonArray[capRestore].Left := R.Left;
FButtonArray[capRestore].Visible := True;
case FCaptionPosition of
dpLeft:
OffsetRect(R, 0, FHeight);
dpTop:
OffsetRect(R, -FWidth, 0);
dpRight:
OffsetRect(R, 0, -FHeight);
dpBottom:
OffsetRect(R, -FWidth, 0);
end;
end
else
FButtonArray[capRestore].Visible := False;
if capMin in FButtons then
begin
FButtonArray[capMin].Top := R.Top;
FButtonArray[capMin].Left := R.Left;
FButtonArray[capMin].Visible := True;
case FCaptionPosition of
dpLeft:
OffsetRect(R, 0, FHeight);
dpTop:
OffsetRect(R, -FWidth, 0);
dpRight:
OffsetRect(R, 0, -FHeight);
dpBottom:
OffsetRect(R, -FWidth, 0);
end;
end
else
FButtonArray[capMin].Visible := False;
if capHelp in FButtons then
begin
FButtonArray[capHelp].Top := R.Top;
FButtonArray[capHelp].Left := R.Left;
FButtonArray[capHelp].Visible := True;
end
else
FButtonArray[capHelp].Visible := False;
end;
{ this method is called only by the caption buttons }
procedure TJvCaptionPanel.ClickButton(Button: TJvCapBtnStyle);
begin
if Assigned(FButtonClick) then
FButtonClick(Self, Button);
end;
procedure TJvCaptionPanel.DoLeaveDrag;
begin
if Assigned(FEndDrag) then
FEndDrag(Self);
end;
procedure TJvCaptionPanel.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited MouseUp(Button, Shift, X, Y);
if FDragging then
DoLeaveDrag;
FDragging := False;
end;
procedure TJvCaptionPanel.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
inherited MouseMove(Shift, X, Y);
{$IFDEF JVCAPTIONPANEL_STD_BEHAVE}
if FDragging then
begin
Left := Left + X - FAnchorPos.X;
Top := Top + Y - FAnchorPos.Y;
end;
{$ENDIF JVCAPTIONPANEL_STD_BEHAVE}
end;
procedure TJvCaptionPanel.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited MouseDown(Button, Shift, X, Y);
FMouseDown := True;
if not PtInRect(FCaptionRect, Point(X, Y)) then
Exit;
if FAutoDrag and CanStartDrag then
begin
SetZOrder(True);
FDragging := True;
ReleaseCapture;
{$IFDEF JVCAPTIONPANEL_STD_BEHAVE}
SetCapture(Handle);
FAnchorPos := Point(X, Y);
{$ELSE}
Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);
{$ENDIF JVCAPTIONPANEL_STD_BEHAVE}
end;
end;
procedure TJvCaptionPanel.Resize;
begin
inherited Resize;
Repaint;
end;
function TJvCaptionPanel.CanStartDrag: Boolean;
begin
Result := True;
if Assigned(FOnStartAutoDrag) then
FOnStartAutoDrag(Self, Result);
end;
procedure TJvCaptionPanel.SetOutlookLook(const Value: Boolean);
begin
FOutlookLook := Value;
if FOutlookLook then
begin
FCaptionOffsetSmall := 0;
FCaptionOffsetLarge := 0;
end
else
begin
FCaptionOffsetSmall := 2;
FCaptionOffsetLarge := 3;
end;
Invalidate;
end;
procedure TJvCaptionPanel.DoCaptionFontChange(Sender: TObject);
begin
Invalidate;
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvQCaptionPanel.pas,v $';
Revision: '$Revision: 1.25 $';
Date: '$Date: 2004/11/06 22:08:15 $';
LogPath: 'JVCL\run'
);
initialization
RegisterUnitVersion(HInstance, UnitVersioning);
finalization
UnregisterUnitVersion(HInstance);
{$ENDIF UNITVERSIONING}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -