📄 bsskinmenus.pas
字号:
until i >= ABV;
end;
//
MouseTimer.Enabled := True;
ActiveItem := -1;
if ItemList.Count > 0
then
for i := 0 to ItemList.Count - 1 do
with TbsSkinMenuItem(ItemList.Items[i]) do
begin
if MenuItem.Enabled
then
begin
ActiveItem := i;
MouseEnter(True);
Break;
end;
end;
end;
procedure TbsSkinPopupWindow.PaintMenu;
var
C: TCanvas;
i: Integer;
B: TBitMap;
begin
C := TCanvas.Create;
C.Handle := DC;
B := TBitMap.Create;
CreateRealImage(B);
// Draw items
for i := VisibleStartIndex to VisibleStartIndex + VisibleCount - 1 do
TbsSkinMenuItem(ItemList.Items[i]).Draw(B.Canvas);
// markers
if Scroll
then
begin
DrawUpMarker(B.Canvas);
DrawDownMarker(B.Canvas);
end;
C.Draw(0, 0, B);
B.Free;
C.Free;
end;
procedure TbsSkinPopupWindow.WMEraseBkgrnd;
begin
PaintMenu(Message.WParam);
end;
procedure TbsSkinPopupWindow.MouseUp;
begin
TestActive(X, Y);
if (ActiveItem <> -1) and (Button = mbleft) and GetActive(X, Y)
then
with TbsSkinMenuItem(ItemList.Items[ActiveItem]) do
if MenuItem.Caption <> '-' then MouseDown(X, Y);
end;
procedure TbsSkinPopupWindow.TestMouse;
var
P, P1: TPoint;
begin
GetCursorPos(P1);
P := ScreenToClient(P1);
if (OMX <> P.X) or (OMY <> P.Y)
then
if InWindow(P1)
then
TestActive(P.X, P.Y)
else
if Scroll
then
begin
ScrollCode := 0;
DrawUpMarker(Canvas);
DrawDownMarker(Canvas);
end;
OMX := P.X;
OMY := P.Y;
end;
function TbsSkinPopupWindow.GetActive;
var
i: Integer;
begin
i := -1;
if ItemList.Count = 0
then
Result := False
else
repeat
Inc(i);
with TbsSkinMenuItem(ItemList.Items[i]) do
Result := FVisible and PtInRect(ObjectRect, Point(X, Y));
until Result or (i = ItemList.Count - 1);
end;
procedure TbsSkinPopupWindow.TestActive;
var
i: Integer;
B: Boolean;
R1, R2: TRect;
begin
if Scroll
then
begin
R1 := Rect(NewItemsRect.Left, NewItemsRect.Top,
NewItemsRect.Right, NewItemsRect.Top + MarkerItemHeight);
R2 := Rect(NewItemsRect.Left, NewItemsRect.Bottom - MarkerItemHeight,
NewItemsRect.Right, NewItemsRect.Bottom);
if PtInRect(R1, Point(X, Y)) and (ScrollCode = 0) and CanScroll(1)
then
begin
ScrollCode := 1;
DrawUpMarker(Canvas);
StartScroll;
end
else
if PtInRect(R2, Point(X, Y)) and (ScrollCode = 0) and CanScroll(2)
then
begin
ScrollCode := 2;
DrawDownMarker(Canvas);
StartScroll;
end
else
if (ScrollCode <> 0) and not PtInRect(R1, Point(X, Y)) and
not PtInRect(R2, Point(X, Y))
then
StopScroll;
end;
if (ItemList.Count = 0) then Exit;
OldActiveItem := ActiveItem;
i := -1;
repeat
Inc(i);
with TbsSkinMenuItem(ItemList.Items[i]) do
begin
B := FVisible and PtInRect(ObjectRect, Point(X, Y));
end;
until B or (i = ItemList.Count - 1);
if B then ActiveItem := i;
if OldActiveItem >= ItemList.Count then OldActiveItem := -1;
if ActiveItem >= ItemList.Count then ActiveItem := -1;
if (OldActiveItem <> ActiveItem)
then
begin
if OldActiveItem <> - 1
then
with TbsSkinMenuItem(ItemList.Items[OldActiveItem]) do
begin
if MenuItem.Enabled and (MenuItem.Caption <> '-')
then
MouseLeave;
end;
if ActiveItem <> - 1
then
with TbsSkinMenuItem(ItemList.Items[ActiveItem]) do
begin
if MenuItem.Enabled and (MenuItem.Caption <> '-')
then
MouseEnter(False);
end;
end;
end;
function TbsSkinPopupWindow.InWindow;
var
H: HWND;
begin
H := WindowFromPoint(P);
Result := H = Handle;
end;
//====================TbsSkinMenu===================//
constructor TbsSkinMenu.CreateEx;
begin
inherited Create(AOwner);
AlphaBlendAnimation := False;
AlphaBlend := False;
AlphaBlendValue := 150;
FPopupList := TList.Create;
WaitTimer := TTimer.Create(Self);
WaitTimer.Enabled := False;
WaitTimer.OnTimer := WaitItem;
WaitTimer.Interval := WaitTimerInterval;
WItem := nil;
FVisible := False;
FForm := AForm;
PopupCtrl := nil;
FDefaultMenuItemHeight := 20;
FDefaultMenuItemFont := TFont.Create;
with FDefaultMenuItemFont do
begin
Name := '宋体';
Style := [];
Height := 12;
end;
end;
destructor TbsSkinMenu.Destroy;
begin
CloseMenu(0);
FPopupList.Free;
WaitTimer.Free;
FDefaultMenuItemFont.Free;
inherited Destroy;
end;
procedure TbsSkinMenu.SetDefaultMenuItemFont(Value: TFont);
begin
FDefaultMenuItemFont.Assign(Value);
end;
function TbsSkinMenu.GetWorkArea;
var
R: TRect;
begin
SystemParametersInfo(SPI_GETWORKAREA, 0, @R, 0);
Result := R;
end;
procedure TbsSkinMenu.WaitItem(Sender: TObject);
begin
if WItem <> nil then CheckItem(WItem.Parent, WItem, True, False);
WaitTimer.Enabled := False;
end;
function TbsSkinMenu.GetPWIndex;
var
i: Integer;
begin
for i := 0 to FPopupList.Count - 1 do
if PW = TbsSkinPopupWindow(FPopupList.Items[i]) then Break;
Result := i;
end;
procedure TbsSkinMenu.CheckItem;
var
Menu: TMenu;
MenuI: TMenuItem;
i: Integer;
R: TRect;
begin
if (MI.MenuItem.Count = 0) and not Down
then
begin
WaitTimer.Enabled := False;
WItem := nil;
i := GetPWIndex(PW);
if i < FPopupList.Count - 1 then CloseMenu(i + 1);
end
else
if (MI.MenuItem.Count = 0) and Down
then
begin
WaitTimer.Enabled := False;
WItem := nil;
MenuI := MI.MenuItem;
Hide;
//
Menu := MenuI.GetParentMenu;
Menu.DispatchCommand(MenuI.Command);
end
else
if (MI.MenuItem.Count <> 0) and not Down and not Kb
then
begin
WaitTimer.Enabled := False;
WItem := nil;
i := GetPWIndex(PW);
if i < FPopupList.Count - 1 then CloseMenu(i + 1);
WItem := MI;
WaitTimer.Enabled := True;
end
else
if (MI.MenuItem.Count <> 0) and Down
then
begin
//
MenuI := MI.MenuItem;
Menu := MenuI.GetParentMenu;
Menu.DispatchCommand(MenuI.Command);
//
WaitTimer.Enabled := False;
WItem := nil;
MI.Down := True;
R.Left := PW.Left + MI.ObjectRect.Left;
R.Top := PW.Top + MI.ObjectRect.Top;
R.Right := PW.Left + MI.ObjectRect.Right;
R.Bottom := PW.Top + MI.ObjectRect.Bottom;
PopupSub(R, MI.MenuItem, 0, True, False);
end
end;
procedure TbsSkinMenu.Popup;
var
BSF: TbsBusinessSkinForm;
begin
FFirst := not FVisible;
PopupCtrl := APopupCtrl;
if FPopupList.Count <> 0 then CloseMenu(0);
WorkArea := GetWorkArea;
SkinData := ASkinData;
if (AItem.Count = 0) then Exit;
FVisible := True;
PopupSub(R, AItem, StartIndex, False, PopupUp);
FFirst := False;
end;
procedure TbsSkinMenu.PopupSub;
var
P: TbsSkinPopupWindow;
begin
if (SkinData = nil) or (SkinData.Empty)
then
P := TbsSkinPopupWindow.CreateEx(Self, Self, nil)
else
P := TbsSkinPopupWindow.CreateEx(Self, Self, SkinData.PopupWindow);
FPopupList.Add(P);
with P do Show(R, AItem, StartIndex, PopupByItem, PopupUp);
end;
procedure TbsSkinMenu.CloseMenu;
var
i: Integer;
begin
for i := FPopupList.Count - 1 downto EndIndex do
begin
TbsSkinPopupWindow(FPopupList.Items[i]).Free;
FPopupList.Delete(i);
end;
if EndIndex = 0
then
begin
FVisible := False;
WaitTimer.Enabled := False;
if PopupCtrl <> nil
then
begin
if PopupCtrl is TWinControl
then
SendMessage(TWinControl(PopupCtrl).Handle, WM_CLOSESKINMENU, 0, 0)
else
PopupCtrl.Perform(WM_CLOSESKINMENU, 0, 0);
PopupCtrl := nil;
end;
end;
end;
procedure TbsSkinMenu.Hide;
begin
CloseMenu(0);
WaitTimer.Enabled := False;
WItem := nil;
if FForm <> nil then
SendMessage(FForm.Handle, WM_CLOSESKINMENU, 0, 0);
if PopupCtrl <> nil
then
begin
if PopupCtrl is TWinControl
then
SendMessage(TWinControl(PopupCtrl).Handle, WM_CLOSESKINMENU, 0, 0)
else
PopupCtrl.Perform(WM_CLOSESKINMENU, 0, 0);
PopupCtrl := nil;
end;
end;
//============= TbsSkinPopupMenu =============//
function FindBSFComponent(AForm: TForm): TbsBusinessSkinForm;
var
i: Integer;
begin
Result := nil;
for i := 0 to AForm.ComponentCount - 1 do
if AForm.Components[i] is TbsBusinessSkinForm
then
begin
Result := TbsBusinessSkinForm(AForm.Components[i]);
Break;
end;
end;
constructor TbsSkinPopupMenu.Create;
begin
inherited Create(AOwner);
FComponentForm := nil;
FSD := nil;
end;
procedure TbsSkinPopupMenu.Notification;
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FSD) then FSD := nil;
end;
procedure TbsSkinPopupMenu.PopupFromRect;
var
BSF: TbsBusinessSkinForm;
begin
if Assigned(OnPopup) then OnPopup(Self);
if FComponentForm = nil
then
begin
// BSF := FindBSFComponent(TForm(Owner))
if Owner.InheritsFrom(TForm) then
BSF := FindBSFComponent(TForm(Owner)) else
if Owner.Owner.InheritsFrom(TForm) then
BSF := FindBSFComponent(TForm(Owner.Owner)) else
BSF := nil;
end
else
BSF := FindBSFComponent(FComponentForm);
if (BSF <> nil) and (FSD = nil)
then
if BSF.MenusSkinData = nil
then
FSD := BSF.SkinData
else
FSD := BSF.MenusSkinData;
if BSF <> nil
then
begin
BSF.SkinMenuOpen;
BSF.SkinMenu.Popup(nil, FSD, 0, R, Items, APopupUp);
end;
end;
procedure TbsSkinPopupMenu.Popup;
var
BSF: TbsBusinessSkinForm;
var
R: TRect;
begin
if Assigned(OnPopup) then OnPopup(Self);
if FComponentForm = nil
then
begin
// BSF := FindBSFComponent(TForm(Owner))
if Owner.InheritsFrom(TForm) then
BSF := FindBSFComponent(TForm(Owner)) else
if Owner.Owner.InheritsFrom(TForm) then
BSF := FindBSFComponent(TForm(Owner.Owner)) else
BSF := nil;
end
else
BSF := FindBSFComponent(FComponentForm);
if (BSF <> nil) and (FSD = nil)
then
if BSF.MenusSkinData = nil
then
FSD := BSF.SkinData
else
FSD := BSF.MenusSkinData;
if BSF <> nil
then
begin
BSF.SkinMenuOpen;
R := Rect(X, Y, X, Y);
BSF.SkinMenu.Popup(nil, FSD, 0, R, Items, False);
end;
end;
procedure TbsSkinPopupMenu.PopupFromRect2;
var
BSF: TbsBusinessSkinForm;
begin
if Assigned(OnPopup) then OnPopup(Self);
if FComponentForm = nil
then
begin
// BSF := FindBSFComponent(TForm(Owner))
if Owner.InheritsFrom(TForm) then
BSF := FindBSFComponent(TForm(Owner)) else
if Owner.Owner.InheritsFrom(TForm) then
BSF := FindBSFComponent(TForm(Owner.Owner)) else
BSF := nil;
end
else
BSF := FindBSFComponent(FComponentForm);
if (BSF <> nil) and (FSD = nil)
then
if BSF.MenusSkinData = nil
then
FSD := BSF.SkinData
else
FSD := BSF.MenusSkinData;
if BSF <> nil
then
begin
BSF.SkinMenuOpen;
BSF.SkinMenu.Popup(ACtrl, FSD, 0, R, Items, APopupUp);
end;
end;
procedure TbsSkinPopupMenu.Popup2;
var
R: TRect;
BSF: TbsBusinessSkinForm;
begin
if Assigned(OnPopup) then OnPopup(Self);
if FComponentForm = nil
then
begin
// BSF := FindBSFComponent(TForm(Owner))
if Owner.InheritsFrom(TForm) then
BSF := FindBSFComponent(TForm(Owner)) else
if Owner.Owner.InheritsFrom(TForm) then
BSF := FindBSFComponent(TForm(Owner.Owner)) else
BSF := nil;
end
else
BSF := FindBSFComponent(FComponentForm);
if (BSF <> nil) and (FSD = nil)
then
if BSF.MenusSkinData = nil
then
FSD := BSF.SkinData
else
FSD := BSF.MenusSkinData;
if (BSF <> nil) and (FSD <> nil)
then
begin
BSF.SkinMenuOpen;
R := Rect(X, Y, X, Y);
BSF.SkinMenu.Popup(ACtrl, FSD, 0, R, Items, False);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -