📄 bsskinmenus.pas
字号:
end
else
begin
PW := AData;
SD := ParentMenu.SkinData;
with PW do
begin
if (WindowPictureIndex <> - 1) and
(WindowPictureIndex < SD.FActivePictures.Count)
then
WindowPicture := SD.FActivePictures.Items[WindowPictureIndex];
if (MaskPictureIndex <> - 1) and
(MaskPictureIndex < SD.FActivePictures.Count)
then
MaskPicture := SD.FActivePictures.Items[MaskPictureIndex];
end;
end;
ActiveItem := -1;
OldActiveItem := -1;
OMX := -1;
OMY := -1;
DSMI := nil;
ScrollCode := 0;
Scroll2 := False;
end;
destructor TbsSkinPopupWindow.Destroy;
var
i: Integer;
begin
for i := 0 to ItemList.Count - 1 do
TbsSkinMenuItem(ItemList.Items[i]).Free;
ItemList.Clear;
ItemList.Free;
MouseTimer.Free;
MorphTimer.Free;
inherited Destroy;
if FRgn <> 0 then DeleteObject(FRgn);
end;
procedure TbsSkinPopupWindow.TestMorph;
var
i: Integer;
StopMorph: Boolean;
begin
if PW = nil then Exit;
StopMorph := True;
for i := 0 to ItemList.Count - 1 do
with TbsSkinMenuItem(ItemList.Items[i]) do
begin
if EnableMorphing and CanMorphing
then
begin
DoMorphing;
StopMorph := False;
end
else
if EnableAnimation
then
begin
if Active and (CurrentFrame <= MI.FrameCount)
then
begin
Inc(CurrentFrame);
Draw(Canvas);
StopMorph := False;
end
else
if not Active and (CurrentFrame > 0)
then
begin
Dec(CurrentFrame);
Draw(Canvas);
StopMorph := False;
end;
end;
end;
if StopMorph then MorphTimer.Enabled := False;
end;
function TbsSkinPopupWindow.CanScroll;
begin
Result := False;
case AScrollCode of
1: Result := VisibleStartIndex > 0;
2: Result := VisibleStartIndex + VisibleCount - 1 < ItemList.Count - 1;
end;
end;
procedure TbsSkinPopupWindow.WMTimer;
begin
inherited;
case ScrollCode of
1: if CanScroll(1) then ScrollUp(False) else StopScroll;
2: if CanScroll(2) then ScrollDown(False) else StopScroll;
end;
end;
procedure TbsSkinPopupWindow.DrawUpMarker;
var
R: TRect;
C: TColor;
begin
if PW <> nil
then
begin
R := Rect(NewItemsRect.Left, NewItemsRect.Top,
NewItemsRect.Right, NewItemsRect.Top + MarkerItemHeight);
if ScrollCode = 1
then C := PW.ScrollMarkerActiveColor
else C := PW.ScrollMarkerColor;
end
else
begin
R := Rect(3, 3, Width - 3, 3 + MarkerItemHeight);
if ScrollCode = 1
then C := clBtnText
else C := clBtnShadow;
end;
DrawArrowImage(Cnvs, R, C, 3);
end;
procedure TbsSkinPopupWindow.DrawDownMarker;
var
R: TRect;
C: TColor;
begin
if PW <> nil
then
begin
R := Rect(NewItemsRect.Left, NewItemsRect.Bottom - MarkerItemHeight,
NewItemsRect.Right, NewItemsRect.Bottom);
if ScrollCode = 2
then C := PW.ScrollMarkerActiveColor
else C := PW.ScrollMarkerColor;
end
else
begin
R := Rect(3, Height - MarkerItemHeight, Width - 3, Height - 3);
if ScrollCode = 2
then C := clBtnText
else C := clBtnShadow;
end;
DrawArrowImage(Cnvs, R, C, 4);
end;
procedure TbsSkinPopupWindow.StartScroll;
var
i: Integer;
begin
i := ParentMenu.GetPWIndex(Self);
ParentMenu.CloseMenu(i + 1);
KillTimer(Handle, 1);
SetTimer(Handle, 1, ScrollTimerInterval, nil);
end;
procedure TbsSkinPopupWindow.StopScroll;
begin
ScrollCode := 0;
DrawUpMarker(Canvas);
DrawDownMarker(Canvas);
KillTimer(Handle, 1);
end;
procedure TbsSkinPopupWindow.ScrollUp;
begin
if VisibleStartIndex > 0
then
begin
VisibleStartIndex := VisibleStartIndex - 1;
CalcItemRects;
RePaint;
end
else
if Cycle
then
begin
VisibleStartIndex := GetEndStartVisibleIndex;
CalcItemRects;
RePaint;
end;
end;
procedure TbsSkinPopupWindow.ScrollDown(Cycle: Boolean);
begin
if VisibleStartIndex + VisibleCount - 1 < ItemList.Count - 1
then
begin
VisibleStartIndex := VisibleStartIndex + 1;
CalcItemRects;
RePaint;
end
else
if Cycle
then
begin
VisibleStartIndex := 0;
CalcItemRects;
RePaint;
end;
end;
procedure TbsSkinPopupWindow.PopupKeyDown(CharCode: Integer);
var
PW: TbsSkinPopupWindow;
procedure NextItem;
var
i, j: Integer;
begin
if Scroll and (ScrollCode = 0) and (ActiveItem = VisibleStartIndex + VisibleCount - 1)
then ScrollDown(True);
OldActiveItem := ActiveItem;
if ActiveItem < 0 then j := 0 else j := ActiveItem + 1;
if j = ItemList.Count then j := 0;
for i := j to ItemList.Count - 1 do
with TbsSkinMenuItem(ItemList.Items[i]) do
begin
if MenuItem.Enabled and (MenuItem.Caption <> '-')
then
begin
ActiveItem := i;
Break;
end
else
begin
if Scroll and (ScrollCode = 0) and (i = VisibleStartIndex + VisibleCount - 1)
then ScrollDown(True);
end;
end;
if OldActiveItem <> ActiveItem
then
begin
if ActiveItem > -1 then
with TbsSkinMenuItem(ItemList.Items[ActiveItem]) do
begin
MouseEnter(True);
end;
if OldActiveItem > -1 then
with TbsSkinMenuItem(ItemList.Items[OldActiveItem]) do
begin
MouseLeave;
end;
end;
end;
procedure PriorItem;
var
i, j: Integer;
begin
if Scroll and (ScrollCode = 0) and (ActiveItem = VisibleStartIndex)
then ScrollUp(True);
OldActiveItem := ActiveItem;
if ActiveItem < 0 then j := ItemList.Count - 1 else j := ActiveItem - 1;
if (j = -1) then j := ItemList.Count - 1;
for i := j downto 0 do
with TbsSkinMenuItem(ItemList.Items[i]) do
begin
if MenuItem.Enabled and (MenuItem.Caption <> '-')
then
begin
ActiveItem := i;
Break;
end
else
begin
if Scroll and (ScrollCode = 0) and (i = VisibleStartIndex)
then ScrollUp(True);
end;
end;
if OldActiveItem <> ActiveItem
then
begin
if ActiveItem > -1 then
with TbsSkinMenuItem(ItemList.Items[ActiveItem]) do
begin
MouseEnter(True);
end;
if OldActiveItem > -1 then
with TbsSkinMenuItem(ItemList.Items[OldActiveItem]) do
begin
MouseLeave;
end;
end;
end;
function FindHotKeyItem: Boolean;
var
i: Integer;
begin
Result := False;
for i := 0 to ItemList.Count - 1 do
with TbsSkinMenuItem(ItemList.Items[i]) do
begin
if Enabled and IsAccel(CharCode, MenuItem.Caption)
then
begin
MouseEnter(False);
OldActiveItem := ActiveItem;
ActiveItem := i;
if OldActiveItem <> -1
then
TbsSkinMenuItem(ItemList.Items[OldActiveItem]).MouseLeave;
MouseDown(0, 0);
Result := True;
Break;
end;
end
end;
begin
if not Visible then Exit;
if not FindHotKeyItem
then
case CharCode of
VK_DOWN:
NextItem;
VK_UP:
PriorItem;
VK_RIGHT:
begin
if ActiveItem <> -1
then
with TbsSkinMenuItem(ItemList.Items[ActiveItem]) do
begin
if MenuItem.Count <> 0 then MouseDown(0, 0);
end;
end;
VK_RETURN:
begin
if ActiveItem <> -1
then
with TbsSkinMenuItem(ItemList.Items[ActiveItem]) do
begin
MouseDown(0, 0);
end;
end;
VK_LEFT:
begin
if ParentMenu.FPopupList.Count > 1
then
begin
ParentMenu.CloseMenu(ParentMenu.FPopupList.Count - 1);
PW := TbsSkinPopupWindow(ParentMenu.FPopupList.Items[ParentMenu.FPopupList.Count - 1]);
if PW.ActiveItem <> -1
then
TbsSkinMenuItem(PW.ItemList.Items[PW.ActiveItem]).Down := False;
end
end;
VK_ESCAPE:
begin
ParentMenu.CloseMenu(ParentMenu.FPopupList.Count - 1);
if ParentMenu.FPopupList.Count > 0
then
begin
PW := TbsSkinPopupWindow(ParentMenu.FPopupList.Items[ParentMenu.FPopupList.Count - 1]);
if PW.ActiveItem <> -1
then
TbsSkinMenuItem(PW.ItemList.Items[PW.ActiveItem]).Down := False;
end;
end;
end;
end;
procedure TbsSkinPopupWindow.UpDatePW;
var
i: Integer;
j: Integer;
begin
j := ParentMenu.GetPWIndex(Self);
if j + 1 < ParentMenu.FPopupList.Count
then ParentMenu.CloseMenu(j + 1);
for i := 0 to ItemList.Count - 1 do
if TbsSkinMenuItem(ItemList.Items[i]).Down
then
with TbsSkinMenuItem(ItemList.Items[i]) do
begin
Down := False;
if EnableAnimation and not MI.InActiveAnimation
then
begin
CurrentFrame := 0;
Draw(Canvas);
end
else
ReDraw;
end;
end;
procedure TbsSkinPopupWindow.SetMenuWindowRegion;
var
TempRgn: HRgn;
begin
if PW = nil then Exit;
TempRgn := FRgn;
CreateSkinRegion
(FRgn, PW.LTPoint, PW.RTPoint, PW.LBPoint, PW.RBPoint, PW.ItemsRect,
NewLtPoint, NewRTPoint, NewLBPoint, NewRBPoint, NewItemsRect,
MaskPicture, Width, Height);
SetWindowRgn(Handle, FRgn, True);
if TempRgn <> 0 then DeleteObject(TempRgn);
end;
procedure TbsSkinPopupWindow.CreateRealImage;
var
R: TRect;
TextOffset: Integer;
begin
if PW <> nil
then
CreateSkinImageBS(PW.LTPoint, PW.RTPoint, PW.LBPoint, PW.RBPoint,
PW.ItemsRect, NewLTPoint, NewRTPoint, NewLBPoint, NewRBPoint,
NewItemsRect, B, WindowPicture,
Rect(0, 0, WindowPicture.Width, WindowPicture.Height),
Width, Height, Scroll, PW.LeftStretch, PW.TopStretch,
PW.RightStretch, PW.BottomStretch)
else
begin
B.Width := Width;
B.Height := Height;
with B.Canvas do
begin
if ImgL = nil
then TextOffset := 21
else TextOffset := GlyphWidth + 2;
R := Rect(0, 0, TextOffset, Height);
Brush.Color := clBtnFace;
FillRect(R);
R := Rect(TextOffset, 0, Width, Height);
Brush.Color := clWindow;
FillRect(R);
end;
R := Rect(0, 0, Width, Height);
Frame3D(B.Canvas, R, clBtnShadow, clBtnShadow, 1);
Frame3D(B.Canvas, R, clWindow, clWindow, 1);
end;
end;
procedure TbsSkinPopupWindow.CreateMenu2;
var
sw, sh: Integer;
i, j: Integer;
Menu: TMenu;
function CalcItemTextWidth(Item: TMenuItem): Integer;
var
R: TRect;
MICaption: WideString;
begin
if Item.ShortCut <> 0
then
MICaption := Item.Caption + ' ' + ShortCutToText(Item.ShortCut)
else
MICaption := Item.Caption;
R := Rect(0, 0, 0, 0);
BSDrawSkinText(Canvas, MICaption, R, DT_CALCRECT);
Result := R.Right + 2;
end;
function GetMenuWindowHeight: Integer;
var
i, j, k, ih: integer;
begin
j := 0;
k := 0;
for i := VisibleStartIndex to VisibleCount - 1 do
with TbsSkinMenuItem(ItemList.Items[i]) do
begin
if PW <> nil
then
begin
if MenuItem.Caption = '-'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -