📄 suipopupmenu.pas
字号:
////////////////////////////////////////////////////////////////////////////////
//
//
// FileName : SUIPopupMenu.pas
// Creator : Shen Min
// Date : 2002-09-01 V1
// 2006-06-14 V6
// Comment :
//
// Copyright (c) 2002-2006 Sunisoft
// http://www.sunisoft.com
// Email: support@sunisoft.com
//
////////////////////////////////////////////////////////////////////////////////
unit SUIPopupMenu;
interface
{$I SUIPack.inc}
uses Windows, Messages, SysUtils, Classes, Menus, Graphics, Forms, Controls,
SUIThemes, SUIMgr, Math, SUI2Define;
type
TsuiPopupMenu = class(TPopupMenu)
private
m_UIStyle : TsuiUIStyle;
m_Height : Integer;
m_SeparatorHeight : Integer;
m_BarColor : TColor;
m_BarToColor : TColor;
m_BarWidth : Integer;
m_Color : TColor;
m_SeparatorColor : TColor;
m_SelectedBorderColor : TColor;
m_SelectedColor : TColor;
m_SelectedFontColor : TColor;
m_FontColor : TColor;
m_BorderColor : TColor;
m_FlatMenu : Boolean;
m_FontName : TFontName;
m_FontSize : Integer;
m_FontCharset : TFontCharset;
m_UseSystemFont : Boolean;
m_FileTheme : TsuiFileTheme;
function GetOwnerDraw() : Boolean;
procedure SetOwnerDraw(const Value : Boolean);
procedure DrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
procedure MeasureItem(Sender: TObject; ACanvas: TCanvas; var Width, Height: Integer);
procedure SetUIStyle(const Value: TsuiUIStyle);
procedure SetHeight(const Value: Integer);
procedure SetSeparatorHeight(const Value: Integer);
procedure SetFileTheme(const Value: TsuiFileTheme);
protected
procedure Loaded; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
constructor Create(AOwner: TComponent); override;
procedure MenuAdded();
published
property OwnerDraw read GetOwnerDraw write SetOwnerDraw;
property FileTheme : TsuiFileTheme read m_FileTheme write SetFileTheme;
property UIStyle : TsuiUIStyle read m_UIStyle write SetUIStyle;
property MenuItemHeight : Integer read m_Height write SetHeight;
property SeparatorHeight : Integer read m_SeparatorHeight write SetSeparatorHeight;
property BarWidth : Integer read m_BarWidth write m_BarWidth;
property BarColor : TColor read m_BarColor write m_BarColor;
property BarToColor : TColor read m_BarToColor write m_BarToColor;
property Color : TColor read m_Color write m_Color;
property SeparatorColor : TColor read m_SeparatorColor write m_SeparatorColor;
property SelectedBorderColor : TColor read m_SelectedBorderColor write m_SelectedBorderColor;
property SelectedColor : TColor read m_SelectedColor write m_SelectedColor;
property SelectedFontColor : TColor read m_SelectedFontColor write m_SelectedFontColor;
property FontColor : TColor read m_FontColor write m_FontColor;
property BorderColor : TColor read m_BorderColor write m_BorderColor;
property FlatMenu : Boolean read m_FlatMenu write m_FlatMenu;
property FontName : TFontName read m_FontName write m_FontName;
property FontSize : Integer read m_FontSize write m_FontSize;
property FontCharset : TFontCharset read m_FontCharset write m_FontCharset;
property UseSystemFont : Boolean read m_UseSystemFont write m_UseSystemFont;
end;
implementation
uses SUIPublic, SUIMenu;
var
l_ImageList : TImageList;
{ TsuiPopupMenu }
constructor TsuiPopupMenu.Create(AOwner: TComponent);
begin
inherited;
inherited OwnerDraw := true;
m_Height := 21;
m_SeparatorHeight := 21;
m_BarColor := clBtnFace;
m_BarToColor := clBtnFace;
m_BarWidth := 0;
m_Color := clWhite;
m_SeparatorColor := clGray;
m_SelectedBorderColor := clHighlight;
m_SelectedColor := clHighlight;
m_SelectedFontColor := clWhite;
m_FontColor := clWhite;
m_BorderColor := clBlack;
m_FlatMenu := false;
m_FontName := 'MS Sans Serif';
m_FontSize := 8;
m_FontCharset := DEFAULT_CHARSET;
m_UseSystemFont := true;
UIStyle := GetSUIFormStyle(AOwner);
end;
procedure TsuiPopupMenu.DrawItem(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; Selected: Boolean);
var
R : TRect;
Cap : String;
ShortKey : String;
nCharLength : Integer;
nCharStart : Integer;
Item : TMenuItem;
HandleOfMenuWindow : HWND;
OutUIStyle : TsuiUIStyle;
L2R : Boolean;
Style : Integer;
X : Integer;
begin
Item := Sender as TMenuItem;
L2R := (BiDiMode = bdLeftToRight) or (not SysLocale.MiddleEast);
if m_FlatMenu then
begin
HandleOfMenuWindow := WindowFromDC(ACanvas.Handle);
if HandleOfMenuWindow <> 0 then
begin
if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
Menu_DrawWindowBorder(
HandleOfMenuWindow,
clBlack,
m_FileTheme.GetColor(SKIN2_FORMCOLOR)
)
else
Menu_DrawWindowBorder(
HandleOfMenuWindow,
clBlack,
GetInsideThemeColor(OutUIStyle, SUI_THEME_FORM_BACKGROUND_COLOR)
)
end;
end;
// draw line
if Item.Caption = '-' then
begin
{$IFDEF RES_MACOS}
if m_UIStyle = MacOS then
Menu_DrawMacOSLineItem(ACanvas, ARect)
else
{$ENDIF}
begin
// draw Left bar
if L2R then
begin
if m_BarWidth > 0 then
begin
R := Rect(ARect.Left, ARect.Top, ARect.Left + m_BarWidth, ARect.Bottom);
if m_BarColor = m_BarToColor then
Menu_DrawBackGround(ACanvas, R, m_BarColor)
else
DrawVerticalGradient(ACanvas, R, m_BarColor, m_BarToColor);
end;
// draw right non-bar
R := Rect(ARect.Left + m_BarWidth, ARect.Top, ARect.Right, ARect.Bottom);
end
else
begin
if m_BarWidth > 0 then
begin
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;
// draw right non-bar
R := Rect(ARect.Left, ARect.Top, ARect.Right - m_BarWidth, ARect.Bottom);
end;
Menu_DrawBackGround(ACanvas, R, m_Color);
// draw line
Menu_DrawLineItem(ACanvas, ARect, m_SeparatorColor, m_BarWidth, L2R);
end;
Exit;
end; // draw line
// draw background
if Selected and Item.Enabled then
begin
{$IFDEF RES_MACOS}
if m_UIStyle = MacOS then
Menu_DrawMacOSSelectedItem(ACanvas, ARect)
else
{$ENDIF}
begin
Menu_DrawBackGround(ACanvas, ARect, m_SelectedColor);
Menu_DrawBorder(ACanvas, ARect, m_SelectedBorderColor);
end;
end
else
begin
{$IFDEF RES_MACOS}
if m_UIStyle = MacOS then
Menu_DrawMacOSNonSelectedItem(ACanvas, ARect)
else
{$ENDIF}
begin
// draw left bar
if m_BarWidth > 0 then
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -