📄 suititlebar.pas
字号:
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);
{$IFDEF SUIPACK_D6UP}
if Canvas.HandleAllocated then
{$ENDIF}
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
begin
Height := Sections.Items[0].Picture.Height - 3
end
else
Height := Sections.Items[0].Picture.Height;
end
else
m_AutoSize := false;
end;
procedure TsuiTitleBar.SetButtonInterval(const Value: Integer);
begin
m_ButtonInterval := Value;
Repaint();
end;
procedure TsuiTitleBar.SetButtons(const Value: TsuiTitleBarButtons);
begin
m_Buttons.Assign(Value);
end;
procedure TsuiTitleBar.SetCaption(const Value: TCaption);
begin
m_Caption := Value;
Repaint();
end;
procedure TsuiTitleBar.SetSections(const Value: TsuiTitleBarSections);
begin
m_Sections.Assign(Value);
end;
procedure TsuiTitleBar.SetUIStyle(const Value: TsuiUIStyle);
var
i : Integer;
OutUIStyle : TsuiUIStyle;
bUsingFileTheme : Boolean;
begin
m_UIStyle := Value;
if m_Custom then
Exit;
Sections.Clear();
if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
begin
UpdateFileTheme();
bUsingFileTheme := true;
end
else
begin
UpdateInsideTheme(OutUIStyle);
bUsingFileTheme := false;
end;
for i := 0 to m_Buttons.Count - 1 do
m_Buttons.Items[i].UIStyle := OutUIStyle;
m_DefPopupMenu.UIStyle := OutUIStyle;
m_DefPopupMenu.FileTheme := m_FileTheme;
if not m_SelfChanging then
begin
{$IFDEF RES_MACOS}
if m_UIStyle = MacOS then
Font.Color := clBlack
else
{$ENDIF}
begin
if bUsingFileTheme then
Font.Color := m_FileTheme.GetColor(SKIN2_TITLEFONTCOLOR)
else
Font.Color := clWhite;
end;
end;
AutoSize := true;
Repaint();
end;
procedure TsuiTitleBar.ProcessMaxBtn;
var
i : Integer;
begin
for i := 0 to m_Buttons.Count - 1 do
if m_Buttons.Items[i].ButtonType = suiMax then
m_Buttons.Items[i].ProcessMaxBtn();
end;
procedure TsuiTitleBar.GetTitleImage(index : Integer; out Bmp: TBitmap);
begin
if index = -1 then
Bmp := m_Buf
else if index = -2 then
Bmp := m_Buf2
else if Sections.Count > 2 then
Bmp := Sections.Items[index].Picture.Bitmap;
end;
procedure TsuiTitleBar.CMDesignHitTest(var Msg: TCMDesignHitTest);
var
HitPos : TPoint;
begin
if Msg.Keys = MK_LBUTTON then
begin
HitPos := SmallPointToPoint(Msg.Pos);
MouseDown(mbLeft, [], HitPos.X, HitPos.Y);
{$IFDEF SUIPACK_D6UP}
Msg.Result := 1;
{$ENDIF}
{$IFDEF SUIPACK_D5}
if not InMDIForm() then
Msg.Result := 1
{$ENDIF}
end;
end;
function TsuiTitleBar.CanPaint: Boolean;
begin
Result := false;
if Sections = nil then
Exit;
if Sections.Count = 3 then
begin
Result := (Sections.Items[0].Picture <> nil) and
(Sections.Items[1].Picture <> nil) and
(Sections.Items[2].Picture <> nil);
end
else if Sections.Count = 5 then
begin
Result := (Sections.Items[0].Picture <> nil) and
(Sections.Items[1].Picture <> nil) and
(Sections.Items[2].Picture <> nil) and
(Sections.Items[3].Picture <> nil) and
(Sections.Items[4].Picture <> nil);
end;
end;
function TsuiTitleBar.InMDIForm: Boolean;
begin
if (
(Owner is TsuiMDIForm) and
(Parent <> nil)
) then
Result := true
else
Result := false;
end;
procedure TsuiTitleBar.SetRoundCornerBottom(const Value: Integer);
begin
m_RoundCornerBottom := Value;
end;
procedure TsuiTitleBar.ForcePaint;
begin
Paint();
end;
procedure TsuiTitleBar.SetInactiveCaptionColor(const Value: TColor);
begin
m_InactiveCaptionColor := Value;
Repaint();
end;
{ TsuiTitleBarSection }
procedure TsuiTitleBarSection.Assign(Source: TPersistent);
begin
if Source is TsuiTitleBarSection then
begin
Width := TsuiTitleBarSection(Source).m_Width;
Align := TsuiTitleBarSection(Source).m_Align;
Picture.Assign(TsuiTitleBarSection(Source).m_Picture);
Stretch := TsuiTitleBarSection(Source).m_Stretch;
AutoSize := TsuiTitleBarSection(Source).m_AutoSize;
end
else
inherited Assign(Source);
end;
constructor TsuiTitleBarSection.Create(Collection: TCollection);
begin
inherited;
m_Picture := TPicture.Create();
m_Width := 10;
m_Align := suiLeft;
m_Stretch := false;
m_AutoSize := false;
m_CapSec := false;
end;
destructor TsuiTitleBarSection.Destroy;
begin
m_Picture.Free();
m_Picture := nil;
inherited;
end;
procedure TsuiTitleBarSection.SetAlign(const Value: TsuiTitleBarAlign);
var
i : Integer;
begin
if Value = suiClient then
begin
for i := 0 to (Collection as TsuiTitleBarSections).Count - 1 do
begin
if (Collection as TsuiTitleBarSections).Items[i].Align = suiClient then
begin
MessageDlg('Sorry, only one section''s Align property can be "suiClient"', mtError, [mbOK], 0);
Exit;
end;
end;
m_Stretch := true;
end;
m_Align := Value;
(Collection as TsuiTitleBarSections).m_TitleBar.Repaint();
end;
procedure TsuiTitleBarSection.SetAutoSize(const Value: Boolean);
begin
m_AutoSize := Value;
if m_Picture.Graphic <> nil then
m_Width := m_Picture.Width;
(Collection as TsuiTitleBarSections).m_TitleBar.Repaint();
end;
procedure TsuiTitleBarSection.SetCapSec(const Value: Boolean);
begin
m_CapSec := Value;
(Collection as TsuiTitleBarSections).m_TitleBar.Repaint();
end;
procedure TsuiTitleBarSection.SetPicture(const Value: TPicture);
begin
m_Picture.Assign(Value);
if Value <> nil then
if m_AutoSize then
m_Width := m_Picture.Width;
(Collection as TsuiTitleBarSections).m_TitleBar.Repaint();
end;
procedure TsuiTitleBarSection.SetStretch(const Value: Boolean);
begin
m_Stretch := Value;
if m_Align = suiClient then
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 }
procedure TsuiTitleBarButton.Assign(Source: TPersistent);
begin
if Source is TsuiTitleBarButton then
begin
Visible := TsuiTitleBarButton(Source).m_Visible;
ButtonType := TsuiTitleBarButton(Source).m_ButtonType;
Transparent := TsuiTitleBarButton(Source).m_Transparent;
Top := TsuiTitleBarButton(Source).m_Top;
UIStyle := TsuiTitleBarButton(Source).m_UIStyle;
PicNormal.Assign(TsuiTitleBarButton(Source).m_PicNormal);
PicMouseOn.Assign(TsuiTitleBarButton(Source).m_PicMouseOn);
PicMouseDown.Assign(TsuiTitleBarButton(Source).m_PicMouseDown);
ControlBoxMenu := TsuiTitleBarButton(Source).m_ControlBoxMenu;
end
else
inherited Assign(Source);
end;
constructor TsuiTitleBarButton.Create(Collection: TCollection);
begin
inherited;
m_Visible := true;
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;
WorkAreaRect : TRect;
begin
if (Collection as TsuiTitleBarButtons).m_TitleBar = nil then
Exit;
if (csDesigning in (Collection as TsuiTitleBarButtons).m_TitleBar.ComponentState) and (m_ButtonType <> suiClose) then
Exit;
ParentForm := GetParentForm((Collection as TsuiTitleBarButtons).m_TitleBar);
if ParentForm = nil then
Exit;
case m_ButtonType of
suiMax :
begin
if ParentForm.WindowState = wsMaximized then
ParentForm.WindowState := wsNormal
else
begin
ParentForm.WindowState := wsMaximized;
if not (Collection as TsuiTitleBarButtons).m_TitleBar.InForm() then
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -