📄 suititlebar.pas
字号:
m_Stretch := true;
(Collection as TsuiTitleBarSections).m_TitleBar.Repaint();
end;
procedure TsuiTitleBarSection.SetWidth(const Value: Integer);
begin
m_Width := Value;
(Collection as TsuiTitleBarSections).m_TitleBar.Repaint();
end;
{ TsuiTitleBarSections }
function TsuiTitleBarSections.Add: TsuiTitleBarSection;
begin
Result := inherited Add() as TsuiTitleBarSection;
end;
constructor TsuiTitleBarSections.Create(TitleBar: TsuiTitleBar);
begin
Inherited Create(TsuiTitleBarSection);
m_TitleBar := TitleBar;
end;
destructor TsuiTitleBarSections.Destroy;
begin
m_TitleBar := nil;
inherited;
end;
function TsuiTitleBarSections.GetItem(Index: Integer): TsuiTitleBarSection;
begin
Result := inherited GetItem(Index) as TsuiTitleBarSection;
end;
function TsuiTitleBarSections.GetOwner: TPersistent;
begin
Result := m_TitleBar;
end;
procedure TsuiTitleBarSections.SetItem(Index: Integer;
Value: TsuiTitleBarSection);
begin
inherited SetItem(Index, Value);
end;
procedure TsuiTitleBarSections.Update(Item: TCollectionItem);
begin
inherited;
m_TitleBar.Repaint();
end;
{ TsuiTitleBarButtons }
function TsuiTitleBarButtons.Add: TsuiTitleBarButton;
begin
Result := inherited Add() as TsuiTitleBarButton;
end;
constructor TsuiTitleBarButtons.Create(TitleBar: TsuiTitleBar);
begin
Inherited Create(TsuiTitleBarButton);
m_TitleBar := TitleBar;
end;
function TsuiTitleBarButtons.GetItem(Index: Integer): TsuiTitleBarButton;
begin
Result := inherited GetItem(Index) as TsuiTitleBarButton;
end;
function TsuiTitleBarButtons.GetOwner: TPersistent;
begin
Result := m_TitleBar;
end;
procedure TsuiTitleBarButtons.SetItem(Index: Integer;
Value: TsuiTitleBarButton);
begin
inherited SetItem(Index, Value);
end;
procedure TsuiTitleBarButtons.Update(Item: TCollectionItem);
begin
inherited;
m_TitleBar.Repaint()
end;
{ TsuiTitleBarButton }
constructor TsuiTitleBarButton.Create(Collection: TCollection);
begin
inherited;
m_ButtonType := suiCustom;
m_Transparent := false;
m_Top := 2;
m_PicNormal := TPicture.Create();
m_PicMouseOn := TPicture.Create();
m_PicMouseDown := TPicture.Create();
UIStyle := SUI_THEME_DEFAULT;
ControlBoxMenu := nil;
end;
destructor TsuiTitleBarButton.Destroy;
begin
m_PicMouseDown.Free();
m_PicMouseDown := nil;
m_PicMouseOn.Free();
m_PicMouseOn := nil;
m_PicNormal.Free();
m_PicNormal := nil;
inherited;
end;
procedure TsuiTitleBarButton.DoClick;
var
ParentForm : TCustomForm;
Point : TPoint;
Rect : TRect;
begin
if (Collection as TsuiTitleBarButtons).m_TitleBar = nil then
Exit;
ParentForm := GetParentForm((Collection as TsuiTitleBarButtons).m_TitleBar);
if ParentForm = nil then
Exit;
Rect := GetWorkAreaRect();
TForm(ParentForm).Constraints.MaxHeight := Rect.Bottom - Rect.Top;
TForm(ParentForm).Constraints.MaxWidth := Rect.Right - Rect.Left;
case m_ButtonType of
suiMax :
begin
if ParentForm.WindowState = wsMaximized then
ParentForm.WindowState := wsNormal
else
begin
ParentForm.WindowState := wsMaximized;
if (Collection as TsuiTitleBarButtons).m_TitleBar.InForm() then
begin
TForm(ParentForm).Left := Rect.Left;
TForm(ParentForm).Top := Rect.Top;
end;
end;
if m_UIStyle = WinXP then
ProcessMaxBtn();
(Collection as TsuiTitleBarButtons).m_TitleBar.OnFormReSize();
end;
suiMin :
begin
if ParentForm = Application.MainForm then
SendMessage(Application.MainForm.Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0)
else
ShowWindow(ParentForm.Handle, SW_SHOWMINIMIZED);
end;
suiClose :
begin
ParentForm.Close();
end;
suiControlBox :
begin
if Assigned(m_ControlBoxMenu) then
begin
Point.X := 0;
Point.Y := (Collection as TsuiTitleBarButtons).m_TitleBar.Height;
Point := (Collection as TsuiTitleBarButtons).m_TitleBar.ClientToScreen(Point);
m_ControlBoxMenu.Popup(Point.X, Point.Y);
end;
end;
suiCustom :
begin
end;
end; // case
end;
procedure TsuiTitleBarButton.ProcessMaxBtn;
procedure InMAX();
begin
PicNormal.Bitmap.LoadFromResourceName(
hInstance,
GetThemeString(m_UIStyle, SUI_TITLEBUTTON_RST_NORMAL_IMAGE)
);
PicMouseOn.Bitmap.LoadFromResourceName(
hInstance,
GetThemeString(m_UIStyle, SUI_TITLEBUTTON_RST_MOUSEON_IMAGE)
);
PicMouseDown.Bitmap.LoadFromResourceName(
hInstance,
GetThemeString(m_UIStyle, SUI_TITLEBUTTON_RST_MOUSEDOWN_IMAGE)
);
end;
procedure InNormal();
begin
PicNormal.Bitmap.LoadFromResourceName(
hInstance,
GetThemeString(m_UIStyle, SUI_TITLEBUTTON_MAX_NORMAL_IMAGE)
);
PicMouseOn.Bitmap.LoadFromResourceName(
hInstance,
GetThemeString(m_UIStyle, SUI_TITLEBUTTON_MAX_MOUSEON_IMAGE)
);
PicMouseDown.Bitmap.LoadFromResourceName(
hInstance,
GetThemeString(m_UIStyle, SUI_TITLEBUTTON_MAX_MOUSEDOWN_IMAGE)
);
end;
var
ParentForm : TCustomForm;
begin
if ButtonType <> suiMax then
Exit;
ParentForm := GetParentForm((Collection as TsuiTitleBarButtons).m_TitleBar);
if ParentForm = nil then
begin
InNormal();
Exit;
end;
if ParentForm.WindowState = wsMaximized then
InMax()
else
InNormal();
end;
procedure TsuiTitleBarButton.SetButtonType(const Value: TsuiTitleBarBtnType);
var
i : Integer;
begin
if Value = suiControlBox then
begin
for i := 0 to (Collection as TsuiTitleBarButtons).Count - 1 do
begin
if (Collection as TsuiTitleBarButtons).Items[i].ButtonType = suiControlBox then
begin
MessageDlg('Sorry, only one button''s ButtonType property can be "suiControlBox"', mtError, [mbOK], 0);
Exit;
end;
end;
end;
m_ButtonType := Value;
UpdateUIStyle();
(Collection as TsuiTitleBarButtons).m_TitleBar.Repaint();
end;
procedure TsuiTitleBarButton.SetPicMouseDown(const Value: TPicture);
begin
if (m_ButtonType <> suiCustom) and (m_ButtonType <> suiControlBox) then
begin
MessageDlg('Sorry, this button is not a "suiCustom" or "suiControlBox"(ButtonType property) button!', mtError, [mbOK], 0);
Exit;
end;
m_PicMouseDown.Assign(Value);
(Collection as TsuiTitleBarButtons).m_TitleBar.Repaint();
end;
procedure TsuiTitleBarButton.SetPicMouseOn(const Value: TPicture);
begin
if (m_ButtonType <> suiCustom) and (m_ButtonType <> suiControlBox) then
begin
MessageDlg('Sorry, this button is not a "suiCustom" or "suiControlBox"(ButtonType property) button!', mtError, [mbOK], 0);
Exit;
end;
m_PicMouseOn.Assign(Value);
(Collection as TsuiTitleBarButtons).m_TitleBar.Repaint();
end;
procedure TsuiTitleBarButton.SetPicNormal(const Value: TPicture);
begin
if (m_ButtonType <> suiCustom) and (m_ButtonType <> suiControlBox) then
begin
MessageDlg('Sorry, this button is not a "suiCustom" or "suiControlBox"(ButtonType property) button!', mtError, [mbOK], 0);
Exit;
end;
m_PicNormal.Assign(Value);
(Collection as TsuiTitleBarButtons).m_TitleBar.Repaint();
end;
procedure TsuiTitleBarButton.SetTop(const Value: Integer);
begin
m_Top := Value;
(Collection as TsuiTitleBarButtons).m_TitleBar.Repaint();
end;
procedure TsuiTitleBarButton.SetTransparent(const Value: Boolean);
begin
m_Transparent := Value;
(Collection as TsuiTitleBarButtons).m_TitleBar.Repaint();
end;
procedure TsuiTitleBarButton.SetUIStyle(const Value: TsuiUIStyle);
begin
m_UIStyle := Value;
UpdateUIStyle();
end;
procedure TsuiTitleBarButton.UpdateUIStyle;
var
nNormal : Integer;
nMouseOn : Integer;
nMouseDown : Integer;
begin
if m_UIStyle = Custom then
Exit;
Transparent := GetThemeBool(m_UIStyle, SUI_TITLEBUTTON_TRANSPARENT_BOOL);
case m_ButtonType of
suiMax :
begin
nNormal := SUI_TITLEBUTTON_MAX_NORMAL_IMAGE;
nMouseOn := SUI_TITLEBUTTON_MAX_MOUSEON_IMAGE;
nMouseDown := SUI_TITLEBUTTON_MAX_MOUSEDOWN_IMAGE;
end;
suiMin :
begin
nNormal := SUI_TITLEBUTTON_MIN_NORMAL_IMAGE;
nMouseOn := SUI_TITLEBUTTON_MIN_MOUSEON_IMAGE;
nMouseDown := SUI_TITLEBUTTON_MIN_MOUSEDOWN_IMAGE;
end;
suiClose :
begin
nNormal := SUI_TITLEBUTTON_CLOSE_NORMAL_IMAGE;
nMouseOn := SUI_TITLEBUTTON_CLOSE_MOUSEON_IMAGE;
nMouseDown := SUI_TITLEBUTTON_CLOSE_MOUSEDOWN_IMAGE;
end;
suiHelp :
begin
nNormal := SUI_TITLEBUTTON_HELP_NORMAL_IMAGE;
nMouseOn := SUI_TITLEBUTTON_HELP_MOUSEON_IMAGE;
nMouseDown := SUI_TITLEBUTTON_HELP_MOUSEDOWN_IMAGE;
end;
suiControlBox :
begin
nNormal := SUI_TITLEBUTTON_CTLBOX_NORMAL_IMAGE;
nMouseOn := SUI_TITLEBUTTON_CTLBOX_MOUSEON_IMAGE;
nMouseDown := SUI_TITLEBUTTON_CTLBOX_MOUSEDOWN_IMAGE;
end;
else Exit;
end; // case
PicNormal.Bitmap.LoadFromResourceName(
hInstance,
GetThemeString(m_UIStyle, nNormal)
);
PicMouseOn.Bitmap.LoadFromResourceName(
hInstance,
GetThemeString(m_UIStyle, nMouseOn)
);
PicMouseDown.Bitmap.LoadFromResourceName(
hInstance,
GetThemeString(m_UIStyle, nMouseDown)
);
Top := GetThemeInt(m_UIStyle, SUI_TITLEBUTTON_TOP);
if m_ButtonType = suiMax then
ProcessMaxBtn();
end;
procedure TsuiTitleBar.CMFONTCHANGED(var Msg: TMessage);
begin
Repaint();
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -