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

View File

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