📄 suititlebar.pas
字号:
m_RightBtnXOffset := 0;
m_DrawAppIcon := false;
m_SelfChanging := false;
Font.Color := clWhite;
Font.Name := 'Tahoma';
Font.Style := [fsBold];
UIStyle := GetSUIFormStyle(AOwner)
end;
procedure TsuiTitleBar.SetLeftBtnXOffset(const Value: Integer);
begin
m_LeftBtnXOffset := Value;
Repaint();
end;
procedure TsuiTitleBar.SetRightBtnXOffset(const Value: Integer);
begin
m_RightBtnXOffset := Value;
Repaint();
end;
procedure TsuiTitleBar.DblClick;
var
i : Integer;
ParentForm : TCustomForm;
begin
inherited;
if csDesigning in ComponentState then
Exit;
if m_InButtons <> -1 then
begin
if m_Buttons.Items[m_InButtons].ButtonType = suiControlBox then
begin
ParentForm := GetParentForm(self);
if ParentForm <> nil then
ParentForm.Close();
end;
Exit;
end;
for i := 0 to m_Buttons.Count - 1 do
begin
if (m_Buttons.Items[i].ButtonType = suiMax) and
m_Buttons.Items[i].Visible then
begin
m_Buttons.Items[i].DoClick();
Exit;
end;
end;
end;
destructor TsuiTitleBar.Destroy();
begin
m_Buttons.Free();
m_Buttons := nil;
m_Sections.Free();
m_Sections := nil;
m_DefPopupMenu.Free();
m_DefPopupMenu := nil;
inherited Destroy();
end;
procedure TsuiTitleBar.DrawButtons(Buf: TBitmap);
var
i : Integer;
Btn : TsuiTitleBarButton;
nControlBox : Integer;
BtnRect : TRect;
nLeft : Integer;
nLeft2 : Integer;
MousePoint : TPoint;
BtnBuf : TBitmap;
Cap : String;
Icon : TIcon;
CaptionHeight : Integer;
FormBorderWidth : Integer;
begin
nLeft := Buf.Width + 1 + m_RightBtnXOffset;
FormBorderWidth := SendMessage(GetParentForm(self).Handle, SUIM_GETBORDERWIDTH, 0, 0) - 1;
Inc(nLeft, FormBorderWidth);
nControlBox := -1;
BtnBuf := TBitmap.Create();
GetCursorPos(MousePoint);
MousePoint := ScreenToClient(MousePoint);
m_InButtons := -1;
for i := 0 to m_Buttons.Count - 1 do
begin
Btn := m_Buttons.Items[i];
if not Btn.Visible then
continue;
BtnBuf.Width := Btn.PicNormal.Width;
BtnBuf.Height := Btn.PicNormal.Height;
BtnBuf.Transparent := Btn.Transparent;
if Btn.ButtonType = suiControlBox then
begin
nControlBox := i;
continue;
end;
Dec(nLeft, Btn.PicNormal.Width + 1 + m_ButtonInterval);
if nLeft + Btn.PicNormal.Width + 1 > Buf.Width then
nLeft := Buf.Width - Btn.PicNormal.Width - 1;
BtnRect := Rect(nLeft, m_BtnTop, nLeft + Btn.PicNormal.Width, m_BtnTop + Btn.PicNormal.Height);
if InRect(MousePoint, BtnRect) then
begin
m_InButtons := i;
if m_MouseDown then
begin
if Btn.PicMouseDown <> nil then
BtnBuf.Canvas.Draw(0, 0, Btn.PicMouseDown.Graphic);
{$IFNDEF SUIPACK_D9UP}
if (csDesigning in ComponentState) and InForm() then
begin
if Btn.ButtonType = suiClose then
ShowWindow(GetParentForm(self).Handle, SW_HIDE);
end;
{$ENDIF}
end
else
begin
if Btn.PicMouseOn <> nil then
BtnBuf.Canvas.Draw(0, 0, Btn.PicMouseOn.Graphic);
end;
end
else
BtnBuf.Canvas.Draw(0, 0, Btn.PicNormal.Graphic);
Buf.Canvas.Draw(nLeft, m_BtnTop, BtnBuf);
end;
nLeft2 := m_LeftBtnXOffset;
Dec(nLeft2, FormBorderWidth);
if nLeft2 < 0 then
nLeft2 := 0;
if nControlBox <> -1 then
begin
Btn := m_Buttons.Items[nControlBox];
BtnRect := Rect(nLeft2, m_BtnTop, nLeft2 + Btn.PicNormal.Width, m_BtnTop + Btn.PicNormal.Height);
if not m_DrawAppIcon then
begin
BtnBuf.Width := Btn.PicNormal.Width;
BtnBuf.Height := Btn.PicNormal.Height;
BtnBuf.Transparent := Btn.Transparent;
if InRect(MousePoint, BtnRect) then
begin
m_InButtons := nControlBox;
if m_MouseDown then
BtnBuf.Canvas.Draw(0, 0, Btn.PicMouseDown.Graphic)
else
BtnBuf.Canvas.Draw(0, 0, Btn.PicMouseOn.Graphic);
end
else
BtnBuf.Canvas.Draw(0, 0, Btn.PicNormal.Graphic);
Buf.Canvas.Draw(nLeft2, m_BtnTop - 1, BtnBuf);
Inc(nLeft2, Btn.PicNormal.Width + 5);
end
else
begin
if InRect(MousePoint, BtnRect) then
m_InButtons := nControlBox;
BtnBuf.Height := 16;
BtnBuf.Width := 16;
Icon := TIcon.Create();
if Application <> nil then
Icon.Handle := CopyImage(Application.Icon.Handle, IMAGE_ICON, 16, 16, LR_COPYFROMRESOURCE)
else
Icon.Handle := LoadImage(hInstance, 'MAINICON', IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
Buf.Canvas.Draw(nLeft2 + 3, m_BtnTop, Icon);
Icon.Free();
Inc(nLeft2, 21);
end;
end;
if nLeft2 = 0 then
Inc(nLeft2, 6);
if not m_Active then
Buf.Canvas.Font.Color := clInactiveCaption;
if Buf.Canvas.TextWidth(Caption) > nLeft - nLeft2 then
begin
Cap := Caption;
while Buf.Canvas.TextWidth(Cap + '...') > nLeft - nLeft2 do
SetLength(Cap, Length(Cap) - 1);
Cap := Cap + '...'
end
else
Cap := Caption;
CaptionHeight := Buf.Canvas.TextHeight(Cap);
if (BidiMode = bdRightToLeft) and SysLocale.MiddleEast then
Buf.Canvas.TextOut(nLeft - Buf.Canvas.TextWidth(Cap) - 10, m_BtnTop + (m_BtnHeight - CaptionHeight) div 2, Cap)
else
Buf.Canvas.TextOut(nLeft2, m_BtnTop + (m_BtnHeight - CaptionHeight) div 2, Cap);
BtnBuf.Free();
end;
function TsuiTitleBar.InForm: Boolean;
begin
if (
(Parent <> nil) and
((Parent is TsuiForm) or (Owner is TsuiMDIForm))
) then
Result := true
else
Result := false;
end;
procedure TsuiTitleBar.SetDrawAppIcon(const Value: Boolean);
begin
m_DrawAppIcon := Value;
Repaint();
end;
procedure TsuiTitleBar.DrawSectionsTo(Buf: TBitmap);
var
nLeft, nRight : Integer;
TopOffset : Integer;
Offset : Integer;
Bmp : TBitmap;
begin
nRight := 0;
nLefT := 0;
if InForm() then
begin
Offset := -1 * SendMessage(GetParentForm(self).Handle, SUIM_GETBORDERWIDTH, 0, 0);
if Offset = 0 then
begin
if InMDIForm() then
Offset := -4
else
Offset := -3;
end;
TopOffset := -3
end
else
begin
Offset := 0;
TopOffset := 0;
end;
if (m_Sections.Count > 0) and (m_Sections.Items[0].Picture <> nil) then
begin
GetLeftImage(Bmp);
Buf.Canvas.Draw(Offset, TopOffset, Bmp);
nLeft := Bmp.Width + Offset;
end;
if (m_Sections.Count > 1) and (m_Sections.Items[1].Picture <> nil) then
begin
GetRightImage(Bmp);
nRight := Buf.Width - Bmp.Width - Offset;
Buf.Canvas.Draw(nRight, TopOffset, Bmp);
end;
if (m_Sections.Count > 2) and (m_Sections.Items[2].Picture <> nil) then
begin
GetCenterImage(bmp);
Buf.Canvas.StretchDraw(Rect(nLeft, TopOffset, nRight, Bmp.Height + TopOffset), Bmp);
end;
end;
procedure TsuiTitleBar.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Form : TCustomForm;
begin
inherited;
if Button = mbLeft then
begin
m_MouseDown := true;
Repaint();
Form := GetParentForm(self);
if Form = nil then
Exit;
if (
((m_InButtons = -1) and
(Form.WindowState <> wsMaximized))
{$IFDEF SUIPACK_D9UP}
and not (csDesigning in ComponentState)
{$ELSE}
or (csDesigning in ComponentState)
{$ENDIF}
) then
begin
ReleaseCapture();
SendMessage(Form.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
m_MouseDown := false;
end
end
end;
procedure TsuiTitleBar.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
inherited;
Repaint();
end;
procedure TsuiTitleBar.MouseOut(var Msg: TMessage);
begin
inherited;
Repaint();
end;
procedure TsuiTitleBar.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
var
Point : TPoint;
InButtons : Integer;
begin
inherited;
if Button <> mbLeft then
Exit;
InButtons := m_InButtons;
if InButtons <> -1 then
begin
if (
(m_Buttons.Items[InButtons].ButtonType = suiControlBox) and
(m_Buttons.Items[InButtons].ControlBoxMenu = nil)
) then
begin
Point.X := 0;
Point.Y := Height;
Point := ClientToScreen(Point);
m_DefPopupMenu.Popup(Point.X, Point.Y);
end
else
begin
m_Buttons.Items[InButtons].DoClick();
if (
Assigned(m_OnBtnClick) and
(m_Buttons.Items[InButtons].ButtonType = suiCustom)
) then
m_OnBtnClick(self, InButtons)
else if(
Assigned(m_OnHelpBtnClick) and
(m_Buttons.Items[InButtons].ButtonType = suiHelp)
) then
m_OnHelpBtnClick(self, InButtons);
end;
end;
m_MouseDown := false;
Repaint();
end;
procedure TsuiTitleBar.WMERASEBKGND(var Msg: TMessage);
begin
// do nothing
end;
procedure TsuiTitleBar.Paint;
var
Buf : TBitmap;
begin
Buf := TBitmap.Create();
Buf.Canvas.Brush.Style := bsClear;
Buf.Canvas.Font := Font;
try
Buf.Width := Width;
Buf.Height := Height;
DrawSectionsTo(Buf);
DrawButtons(Buf);
BitBlt(Canvas.Handle, 0, 0, Buf.Width, Buf.Height, Buf.Canvas.Handle, 0, 0, SRCCOPY);
finally
Buf.Free();
end;
end;
procedure TsuiTitleBar.SetActive(const Value: Boolean);
begin
m_Active := Value;
Repaint();
end;
procedure TsuiTitleBar.SetAutoSize2(Value: Boolean);
begin
m_AutoSize := Value;
if Sections.Count > 0 then
begin
if InForm() then
Height := Sections.Items[0].Picture.Height - 3
else
Height := Sections.Items[0].Picture.Height;
end
else
m_AutoSize := false;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -