📄 suimainmenu.pas
字号:
begin
if L2R then
R := Rect(ARect.Left, ARect.Top, ARect.Left + m_BarWidth, ARect.Bottom)
else
R := Rect(ARect.Right - m_BarWidth, ARect.Top, ARect.Right, ARect.Bottom);
if m_BarColor = m_BarToColor then
Menu_DrawBackGround(ACanvas, R, m_BarColor)
else
DrawVerticalGradient(ACanvas, R, m_BarColor, m_BarToColor);
end;
if L2R then
R := Rect(ARect.Left + m_BarWidth, ARect.Top, ARect.Right, ARect.Bottom)
else
R := Rect(ARect.Left, ARect.Top, ARect.Right - m_BarWidth, ARect.Bottom);
Menu_DrawBackGround(ACanvas, R, m_Color);
end
end;
// draw caption and shortkey
Cap := Item.Caption;
if m_UseSystemFont then
Menu_GetSystemFont(ACanvas.Font)
else
begin
ACanvas.Font.Name := m_FontName;
ACanvas.Font.Size := m_FontSize;
ACanvas.Font.Charset := m_FontCharset;
end;
ACanvas.Brush.Style := bsClear;
if Item.Enabled then
begin
if Selected then
ACanvas.Font.Color := m_SelectedFontColor
else
ACanvas.Font.Color := m_FontColor;
end
else
ACanvas.Font.Color := clGray;
if Item.Default then
ACanvas.Font.Style := ACanvas.Font.Style + [fsBold];
if L2R then
begin
R := Rect(ARect.Left + m_BarWidth + 4, ARect.Top, ARect.Right, ARect.Bottom);
Style := DT_LEFT;
end
else
begin
R := Rect(ARect.Left + m_BarWidth, ARect.Top, ARect.Right - 4, ARect.Bottom);
Style := DT_RIGHT;
end;
DrawText(ACanvas.Handle, PChar(Cap), -1, R, Style or DT_VCENTER or DT_SINGLELINE);
ShortKey := ShortCutToText(Item.ShortCut);
if L2R then
begin
nCharLength := ACanvas.TextWidth(ShortKey);
nCharStart := ARect.Right - nCharLength - 16;
R := Rect(nCharStart, ARect.Top, ARect.Right, ARect.Bottom);
end
else
begin
R := Rect(ARect.Left + m_BarWidth + 4, ARect.Top, ARect.Right, ARect.Bottom);
end;
DrawText(ACanvas.Handle, PChar(ShortKey), -1, R, DT_LEFT or DT_VCENTER or DT_SINGLELINE);
if L2R then
X := ARect.Left + 4
else
X := ARect.Right - 20;
// draw checked
if Item.Checked then
begin
if (
(Item.ImageIndex = -1) or
(Images = nil) or
(Item.ImageIndex >= Images.Count)
) then
m_Images.Draw(ACanvas, X, ARect.Top + 3, 0, Item.Enabled)
else
begin
ACanvas.Brush.Color := clBlack;
ACanvas.FrameRect(Rect(X - 2, ARect.Top + 1, X + 17, ARect.Top + 20));
ACanvas.Brush.Color := m_SelectedColor;
ACanvas.FillRect(Rect(X - 1, ARect.Top + 2, X + 16, ARect.Top + 19));
end;
end;
// draw images
if (Item.ImageIndex <> -1) and (Images <> nil) then
if Item.ImageIndex < Images.Count then
Images.Draw(ACanvas, X, ARect.Top + 3, Item.ImageIndex, Item.Enabled);
end;
function TsuiMainMenu.GetImages: TCustomImageList;
begin
if inherited Images = m_Images then
Result := nil
else
Result := inherited Images;
end;
function TsuiMainMenu.GetOwnerDraw: Boolean;
begin
Result := true;
end;
procedure TsuiMainMenu.Loaded;
begin
inherited;
MenuAdded();
end;
procedure TsuiMainMenu.MeasureItem(Sender: TObject; ACanvas: TCanvas;
var Width, Height: Integer);
var
Item : TMenuItem;
begin
Item := Sender as TMenuItem;
if Item.Caption = '-' then
Height := m_SeparatorHeight
else
Height := Max(ACanvas.TextHeight(Item.Caption), m_Height);
Width := ACanvas.TextWidth(Item.Caption) + ACanvas.TextWidth(ShortCutToText(Item.ShortCut)) + m_BarWidth + 40;
end;
procedure TsuiMainMenu.MenuAdded;
var
i : Integer;
begin
for i := 0 to Items.Count - 1 do
Menu_SetItemEvent(Items[i], DrawItem, MeasureItem);
if m_Form <> nil then
m_Form.UpdateMenu();
end;
procedure TsuiMainMenu.MenuChanged(Sender: TObject; Source: TMenuItem;
Rebuild: Boolean);
begin
inherited;
if not (Owner is TCustomForm) then
Exit;
if m_Form <> nil then
m_Form.UpdateTopMenu();
if (
(csLoading in ComponentState) or
(not (csDesigning in ComponentState))
) then
Exit;
if m_Form <> nil then
m_Form.UpdateMenu();
end;
procedure TsuiMainMenu.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if (
(Operation = opRemove) and
(AComponent = m_FileTheme)
)then
begin
m_FileTheme := nil;
SetUIStyle(SUI_THEME_DEFAULT);
end;
if (
(Operation = opInsert) and
(AComponent is TMenuItem)
) then
begin
Menu_SetItemEvent(AComponent as TMenuItem, DrawItem, MeasureItem);
end;
end;
procedure TsuiMainMenu.SetFileTheme(const Value: TsuiFileTheme);
begin
m_FileTheme := Value;
SetUIStyle(m_UIStyle);
end;
procedure TsuiMainMenu.SetHeight(const Value: Integer);
begin
// if {$IFDEF RES_MACOS}m_UIStyle <> MacOS {$ELSE} True {$ENDIF} then
m_Height := Value;
end;
procedure TsuiMainMenu.SetImages(const Value: TCustomImageList);
begin
if Value = nil then
inherited Images := m_Images
else
inherited Images := Value;
end;
procedure TsuiMainMenu.SetOwnerDraw(const Value: Boolean);
begin
// Do nothing
end;
procedure TsuiMainMenu.SetSeparatorHeight(const Value: Integer);
begin
if {$IFDEF RES_MACOS}m_UIStyle <> MacOS {$ELSE} True {$ENDIF} then
m_SeparatorHeight := Value;
end;
procedure TsuiMainMenu.SetUIStyle(const Value: TsuiUIStyle);
var
OutUIStyle : TsuiUIStyle;
begin
m_UIStyle := Value;
m_BarWidth := 26;
{$IFDEF RES_MACOS}
if m_UIStyle = MacOS then
begin
m_Height := 20;
m_SeparatorHeight := 12;
m_SeparatorColor := 0;
end
else
{$ENDIF}
begin
m_Height := 21;
m_SeparatorHeight := 5;
m_SeparatorColor := $00848284;
end;
if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
begin
m_BarColor := m_FileTheme.GetColor(SKIN2_LEFTBARSTARTCOLOR);
m_BarToColor := m_FileTheme.GetColor(SKIN2_LEFTBARENDCOLOR);
m_Color := m_FileTheme.GetColor(SKIN2_MENUITEMCOLOR);
m_FontColor := m_FileTheme.GetColor(SKIN2_MENUITEMFONTCOLOR);
m_SelectedBorderColor := m_FileTheme.GetColor(SKIN2_SELECTEDMENUBORDERCOLOR);
m_SelectedColor := m_FileTheme.GetColor(SKIN2_SELECTEDMENUCOLOR);
m_SelectedFontColor := m_FileTheme.GetColor(SKIN2_SELECTEDMENUFONTCOLOR);
end
else
begin
m_BarColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_MENU_LEFTBAR_COLOR);
m_BarToColor := m_BarColor;
m_Color := GetInsideThemeColor(OutUIStyle, SUI_THEME_MENU_BACKGROUND_COLOR);
m_FontColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_MENU_FONT_COLOR);
m_SelectedBorderColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_MENU_SELECTED_BORDER_COLOR);
m_SelectedColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_MENU_SELECTED_BACKGROUND_COLOR);
m_SelectedFontColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_MENU_SELECTED_FONT_COLOR);
end;
end;
procedure TsuiMainMenu.SetUseSystemFont(const Value: Boolean);
begin
m_UseSystemFont := Value;
if m_Form <> nil then
m_Form.RepaintMenuBar();
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -