Menu designer: Cleanup. Move few nested functions to methods.

git-svn-id: trunk@51552 -
This commit is contained in:
juha 2016-02-09 12:52:35 +00:00
parent ad856b47a0
commit c440bfd8e0
2 changed files with 114 additions and 116 deletions

View File

@ -33,7 +33,7 @@ uses
// LazUtils // LazUtils
LazUTF8, LazUTF8,
// IdeIntf // IdeIntf
LazIDEIntf, FormEditingIntf, PropEdits, FormEditingIntf, PropEdits,
// IDE // IDE
LazarusIDEStrConsts, MenuDesignerBase, MenuShortcuts; LazarusIDEStrConsts, MenuDesignerBase, MenuShortcuts;
@ -91,7 +91,7 @@ type
procedure ScanLookupRoot(aForm: TCustomForm); procedure ScanLookupRoot(aForm: TCustomForm);
procedure SetupPopupAssignmentsDisplay; procedure SetupPopupAssignmentsDisplay;
public public
constructor Create(aDesigner: TMenuDesignerBase); constructor Create(aDesigner: TMenuDesignerBase); reintroduce;
destructor Destroy; override; destructor Destroy; override;
procedure LoadVariableButtonGlyphs(isInMenubar: boolean); procedure LoadVariableButtonGlyphs(isInMenubar: boolean);
procedure SetMenu(aMenu: TMenu; aMenuItem: TMenuItem); procedure SetMenu(aMenu: TMenu; aMenuItem: TMenuItem);

View File

@ -72,7 +72,9 @@ type
FShowingBottomFake: boolean; FShowingBottomFake: boolean;
FShowingRightFake: boolean; FShowingRightFake: boolean;
FState: TShadowItemDisplayState; FState: TShadowItemDisplayState;
function GetBitmapLeftTop: TPoint;
function GetBottomFake: TFake; function GetBottomFake: TFake;
function GetIconTopLeft: TPoint;
function GetIsInMenuBar: boolean; function GetIsInMenuBar: boolean;
function GetIsMainMenu: boolean; function GetIsMainMenu: boolean;
function GetLevel: integer; function GetLevel: integer;
@ -80,6 +82,7 @@ type
function GetShortcutWidth: integer; function GetShortcutWidth: integer;
function GetShowingBottomFake: boolean; function GetShowingBottomFake: boolean;
function GetShowingRightFake: boolean; function GetShowingRightFake: boolean;
function GetSubImagesIconTopLeft: TPoint;
procedure SetState(AValue: TShadowItemDisplayState); procedure SetState(AValue: TShadowItemDisplayState);
protected protected
function GetHeight: integer; function GetHeight: integer;
@ -2991,6 +2994,16 @@ begin
Result:=FRealItem.IsInMenuBar; Result:=FRealItem.IsInMenuBar;
end; end;
function TShadowItem.GetIsMainMenu: boolean;
begin
Result:=FShadowMenu.IsMainMenu;
end;
function TShadowItem.GetLevel: integer;
begin
Result:=FParentBox.Level;
end;
function TShadowItem.GetBottomFake: TFake; function TShadowItem.GetBottomFake: TFake;
begin begin
Result:=nil; Result:=nil;
@ -3003,32 +3016,15 @@ begin
end; end;
end; end;
function TShadowItem.GetIsMainMenu: boolean;
begin
Result:=FShadowMenu.IsMainMenu;
end;
function TShadowItem.GetLevel: integer;
begin
Result:=FParentBox.Level;
end;
{
function TShadowItem.GetMenu: TMenu;
begin
Result:=FShadowMenu.FMenu;
end;
}
function TShadowItem.GetRightFake: TFake; function TShadowItem.GetRightFake: TFake;
begin begin
if (FShadowMenu.SelectedShadowItem <> Self) then Result:=nil;
Result:=nil if (FShadowMenu.SelectedShadowItem = Self) then
else case FRealItem.IsInMenuBar of case FRealItem.IsInMenuBar of
False: if (FShadowMenu.AddSubMenuFake.Visible) then False: if (FShadowMenu.AddSubMenuFake.Visible) then
Result:=FRightFake Result:=FRightFake;
else Result:=nil;
True: if FShadowMenu.AddItemFake.Visible then True: if FShadowMenu.AddItemFake.Visible then
Result:=FRightFake Result:=FRightFake;
else Result:=nil;
end; end;
end; end;
@ -3071,16 +3067,7 @@ begin
end; end;
end; end;
procedure TShadowItem.Paint; function TShadowItem.GetIconTopLeft: TPoint;
var
r, gutterR: TRect;
dets: TThemedElementDetails;
textFlags: integer = DT_VCENTER or DT_SINGLELINE or DT_EXPANDTABS or DT_CENTER;
tStyle: TTextStyle;
alygn: TAlignment;
s: string;
function GetIconTopLeft: TPoint;
begin begin
Result:=Point(1, 1); Result:=Point(1, 1);
if (FShadowMenu.FMenu.Images.Height < ClientHeight) then if (FShadowMenu.FMenu.Images.Height < ClientHeight) then
@ -3089,7 +3076,7 @@ var
Result.x:=(Gutter_X - FShadowMenu.FMenu.Images.Width) div 2; Result.x:=(Gutter_X - FShadowMenu.FMenu.Images.Width) div 2;
end; end;
function GetBitmapLeftTop: TPoint; function TShadowItem.GetBitmapLeftTop: TPoint;
begin begin
Result:=Point(1, 1); Result:=Point(1, 1);
if (FRealItem.Bitmap.Height < ClientHeight) then if (FRealItem.Bitmap.Height < ClientHeight) then
@ -3098,6 +3085,22 @@ var
Result.x:=(Gutter_X - FRealItem.Bitmap.Width) div 2; Result.x:=(Gutter_X - FRealItem.Bitmap.Width) div 2;
end; end;
function TShadowItem.GetSubImagesIconTopLeft: TPoint;
begin
Result:=Point(1, 1);
if (FRealItem.Parent.SubMenuImages.Height < ClientHeight) then
Result.y:=(ClientHeight - FRealItem.Parent.SubMenuImages.Height) div 2;
if (FRealItem.Parent.SubMenuImages.Width < Gutter_X) then
Result.x:=(Gutter_X - FRealItem.Parent.SubMenuImages.Width) div 2;
end;
procedure TShadowItem.Paint;
var
r, gutterR: TRect;
textFlags: integer = DT_VCENTER or DT_SINGLELINE or DT_EXPANDTABS or DT_CENTER;
tStyle: TTextStyle;
s: string;
procedure DrawMenuBarItem; procedure DrawMenuBarItem;
var var
oldFontStyle: TFontStyles; oldFontStyle: TFontStyles;
@ -3105,6 +3108,7 @@ var
x, y: integer; x, y: integer;
sz: TSize; sz: TSize;
pt: TPoint; pt: TPoint;
dets: TThemedElementDetails;
begin begin
if (FState = dsSelected) then begin if (FState = dsSelected) then begin
Canvas.Brush.Color:=clHighlight; Canvas.Brush.Color:=clHighlight;
@ -3168,7 +3172,8 @@ var
end; end;
if FRealItem.IsLine and (FState = dsSelected) then if FRealItem.IsLine and (FState = dsSelected) then
Canvas.FillRect(r.Left, r.Top+2, r.Right, r.Bottom+2) Canvas.FillRect(r.Left, r.Top+2, r.Right, r.Bottom+2)
else Canvas.FillRect(r); else
Canvas.FillRect(r);
gutterR:=Rect(Gutter_X, 0, Gutter_X+1, ClientHeight); gutterR:=Rect(Gutter_X, 0, Gutter_X+1, ClientHeight);
LCLIntf.DrawEdge(Canvas.Handle, gutterR, EDGE_ETCHED, BF_LEFT); LCLIntf.DrawEdge(Canvas.Handle, gutterR, EDGE_ETCHED, BF_LEFT);
end; end;
@ -3176,16 +3181,7 @@ var
procedure DrawCheckMarkIcon; procedure DrawCheckMarkIcon;
var var
pt: TPoint; pt: TPoint;
dets: TThemedElementDetails;
function GetSubImagesIconTopLeft: TPoint;
begin
Result:=Point(1, 1);
if (FRealItem.Parent.SubMenuImages.Height < ClientHeight) then
Result.y:=(ClientHeight - FRealItem.Parent.SubMenuImages.Height) div 2;
if (FRealItem.Parent.SubMenuImages.Width < Gutter_X) then
Result.x:=(Gutter_X - FRealItem.Parent.SubMenuImages.Width) div 2;
end;
begin begin
if FRealItem.Checked then begin if FRealItem.Checked then begin
gutterR:=r; gutterR:=r;
@ -3247,7 +3243,8 @@ var
Canvas.Brush.Style:=bsClear; Canvas.Brush.Style:=bsClear;
if FRealItem.RightJustify then if FRealItem.RightJustify then
textFlags:=textFlags or DT_RIGHT textFlags:=textFlags or DT_RIGHT
else textFlags:=textFlags or DT_LEFT; else
textFlags:=textFlags or DT_LEFT;
r.Left:=DropDown_Text_Offset; r.Left:=DropDown_Text_Offset;
oldFontStyle:=Canvas.Font.Style; oldFontStyle:=Canvas.Font.Style;
if FRealItem.Default then if FRealItem.Default then
@ -3283,7 +3280,8 @@ var
s:=s1 s:=s1
else if sc2 and not sc1 then else if sc2 and not sc1 then
s:=s2 s:=s2
else s:=s1 + ', ' + s2; else
s:=s1 + ', ' + s2;
x:=r.Right - Canvas.TextWidth(s) - DropDown_Height; x:=r.Right - Canvas.TextWidth(s) - DropDown_Height;
case FState of case FState of
dsNormal: Canvas.TextRect(r, x, y, s, tStyle); dsNormal: Canvas.TextRect(r, x, y, s, tStyle);
@ -3336,8 +3334,10 @@ var
Canvas.Pen.Color:=oldPenColor; Canvas.Pen.Color:=oldPenColor;
end; end;
var
alygn: TAlignment;
begin begin
if not FParentBox.Updating then begin if FParentBox.Updating then Exit;
r:=ClientRect; r:=ClientRect;
if FRealItem.RightJustify then if FRealItem.RightJustify then
alygn:=taRightJustify alygn:=taRightJustify
@ -3345,7 +3345,8 @@ begin
alygn:=taLeftJustify; alygn:=taLeftJustify;
if (FRealItem.Caption = '') then if (FRealItem.Caption = '') then
s:=FRealItem.Name s:=FRealItem.Name
else s:=FRealItem.Caption; else
s:=FRealItem.Caption;
FillChar(tStyle{%H-}, SizeOf(tStyle), 0); FillChar(tStyle{%H-}, SizeOf(tStyle), 0);
with tStyle do begin with tStyle do begin
Alignment:=BidiFlipAlignment(alygn, UseRightToLeftAlignment); Alignment:=BidiFlipAlignment(alygn, UseRightToLeftAlignment);
@ -3372,7 +3373,6 @@ begin
DrawChevron; DrawChevron;
end; end;
end; end;
end;
procedure TShadowItem.KeyDown(var Key: Word; Shift: TShiftState); procedure TShadowItem.KeyDown(var Key: Word; Shift: TShiftState);
begin begin
@ -3520,8 +3520,6 @@ begin
FGui.Free; FGui.Free;
if (GlobalDesignHook <> nil) then if (GlobalDesignHook <> nil) then
GlobalDesignHook.RemoveAllHandlersForObject(Self); GlobalDesignHook.RemoveAllHandlersForObject(Self);
if MenuDesignerSingleton = Self then
MenuDesignerSingleton := nil;
inherited Destroy; inherited Destroy;
end; end;