DockedFormEditor: add menu preview via TToolbar.Menu. Patch by FerDeLance See MR !393

This commit is contained in:
Martin 2024-12-18 10:47:29 +01:00
parent 2faa5bdf05
commit e63194a5f2
3 changed files with 55 additions and 50 deletions

View File

@ -40,7 +40,7 @@ uses
// RTL, FCL
Classes, SysUtils, math,
// LCL
Controls, ExtCtrls, Graphics, Menus;
Controls, ComCtrls, ExtCtrls, Graphics, Menus;
type
@ -193,7 +193,7 @@ type
private
FAnchorContainer: TWinControl;
FBoundsRect: TRect;
FFakeMenu: TCustomControl;
FFakeMenu: TToolBar;
FFormClient: TWinControl;
FFormContainer: TResizeFormContainer;
FParent: TWinControl;
@ -208,7 +208,7 @@ type
public
property AnchorContainer: TWinControl read FAnchorContainer;
property BoundsRect: TRect read FBoundsRect;
property FakeMenu: TCustomControl read FFakeMenu;
property FakeMenu: TToolBar read FFakeMenu;
property FormClient: TWinControl read FFormClient;
property FormContainer: TResizeFormContainer read FFormContainer;
property Parent: TWinControl read FParent;
@ -605,9 +605,11 @@ begin
FResizeBars := TResizeBars.Create;
FResizeBars.Parent := Parent;
FFakeMenu := TCustomControl.Create(Parent);
FFakeMenu := TToolBar.Create(Parent);
FFakeMenu.Height := 0;
FFakeMenu.Parent := Parent;
FFakeMenu.Align := alNone;
FFakeMenu.Indent := 0;
FFormClient := TWinControl.Create(Parent);
FFormClient.ControlStyle:= FFormClient.ControlStyle + [csOpaque];

View File

@ -20,8 +20,8 @@ uses
// RTL
Classes, Types, SysUtils, FPCanvas,
// LCL
Forms, ExtCtrls, StdCtrls, Controls, LCLType, Menus, Graphics, LCLIntf,
LMessages, LCLProc,
Forms, ExtCtrls, StdCtrls, Controls, ComCtrls, LCLType, Menus, Graphics, LCLIntf,
LMessages, LCLProc, Buttons,
// DockedFormEditor
DockedOptionsIDE, DockedDesignForm, DockedGrip;
@ -55,10 +55,9 @@ type
procedure FakeKeyUp(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
procedure FakeMenuEnter(Sender: TObject);
function FakeMenuNeeded: Boolean;
procedure FakeMenuPaint(Sender: TObject);
procedure FakeUTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
function GetAnchorContainer: TWinControl;
function GetFakeMenu: TCustomControl;
function GetFakeMenu: TToolBar;
function GetFormClient: TWinControl;
function GetFormContainer: TResizeFormContainer;
function GetSizerGripSize: Integer;
@ -80,7 +79,7 @@ type
public
property AnchorContainer: TWinControl read GetAnchorContainer;
property DesignForm: TDesignForm read FDesignForm write SetDesignForm;
property FakeMenu: TCustomControl read GetFakeMenu;
property FakeMenu: TToolBar read GetFakeMenu;
property FormClient: TWinControl read GetFormClient;
property FormContainer: TResizeFormContainer read GetFormContainer;
property NewFormSize: TPoint read FNewFormSize;
@ -128,7 +127,7 @@ begin
Application.NotifyUserInputHandler(Self, 0); // force repaint invisible components
end else
if LFakeMenuNeeded then
FakeMenu.Invalidate; // always repaint menu on modification
TryBoundDesignForm; // always repaint menu on modification
RefreshAnchorDesigner;
FDesignerModified := False;
end;
@ -221,33 +220,7 @@ begin
Result := False;
if not Assigned(FDesignForm) then Exit;
Result := FDesignForm.MainMenuFaked;
end;
procedure TResizeControl.FakeMenuPaint(Sender: TObject);
var
MenuRect: Types.TRect;
Menu: TMainMenu;
X, Y, I: Integer;
LCanvas: TCanvas;
begin
if not FakeMenuNeeded then Exit;
MenuRect := FakeMenu.ClientRect;
LCanvas := FakeMenu.Canvas;
LCanvas.Brush.Color := clMenuBar;
LCanvas.FillRect(MenuRect);
Menu := FDesignForm.Form.Menu;
LCanvas.Font.Color := clMenuText;
X := 5;
Y := (MenuRect.Top+MenuRect.Bottom-LCanvas.TextHeight('Hg')) div 2;
for I := 0 to Menu.Items.Count-1 do
if Menu.Items[I].Visible then
begin
LCanvas.TextOut(X, Y, Menu.Items[I].Caption);
Inc(X, LCanvas.TextWidth(Menu.Items[I].Caption) + 10);
end;
if Result then FakeMenu.Menu := FDesignForm.Form.Menu else FakeMenu.Menu := nil;
end;
procedure TResizeControl.FakeUTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
@ -265,7 +238,7 @@ begin
Result := FResizeContainer.AnchorContainer;
end;
function TResizeControl.GetFakeMenu: TCustomControl;
function TResizeControl.GetFakeMenu: TToolBar;
begin
Result := FResizeContainer.FakeMenu;
end;
@ -370,12 +343,20 @@ begin
end;
procedure TResizeControl.TryBoundDesignForm;
var
i, t: Integer;
begin
if DesignForm = nil then Exit;
if FakeMenuNeeded then
FakeMenu.Height := DesignForm.MainMenuHeight
else
FakeMenu.Height := 0;
begin
FakeMenu.ButtonHeight := DesignForm.MainMenuHeight;
t := 0;
for i := 0 to FakeMenu.ComponentCount - 1 do //For multi-line MainMenu
if FakeMenu.Components[i] is TSpeedButton then
if t < TSpeedButton(FakeMenu.Components[i]).Top then t := TSpeedButton(FakeMenu.Components[i]).Top;
FakeMenu.Height := t + FakeMenu.ButtonHeight;
FakeMenu.Update;
end else FakeMenu.Height := 0;
end;
constructor TResizeControl.Create(TheOwner: TComponent);
@ -403,7 +384,6 @@ begin
CreateBarBitmaps;
FakeMenu.OnPaint := @FakeMenuPaint;
FormClient.OnChangeBounds := @ClientChangeBounds;
AnchorContainer.OnChangeBounds := @ClientChangeBounds;
AdjustBounds(Point(0, 0));
@ -422,6 +402,7 @@ var
LWidth, LHeight: Integer;
begin
if FDesignForm = nil then Exit;
TryBoundDesignForm;
LWidth := FDesignForm.Width + 2 * SizerGripSize;
LHeight := FDesignForm.Height + 2 * SizerGripSize + FakeMenu.Height;
{$IFDEF DEBUGDOCKEDFORMEDITOR} DebugLn('TResizeControl.AdjustBounds: New ResizeControl Width:', DbgS(Width), ' Height: ', DbgS(Height)); {$ENDIF}
@ -434,6 +415,7 @@ begin
if (DesignForm = nil) then Exit;
if not DockedOptions.ForceRefreshing and Resizing then Exit;
{$IFDEF DEBUGDOCKEDFORMEDITOR} DebugLn('TResizeControl.ClientChangeBounds Form Width:', DbgS(FormClient.Width), ' Height: ', DbgS(FormClient.Height)); {$ENDIF}
TryBoundDesignForm;
if FormClient.Visible then
begin
FNewFormSize.X := FormClient.Width;

View File

@ -330,6 +330,7 @@ procedure TToolBar.MenuButtonClick(Sender: TObject);
var
MenuButton: TSpeedButton;
SubMenuPos: TPoint;
tmpMI: TMenuItem;
procedure PrepSubMenuItem(SubMenuItemIn, SubMenuItemOut: TMenuItem);
var
@ -337,20 +338,40 @@ var
begin
for i := 0 to SubMenuItemIn.Count - 1 do
begin
FSubMenuItems.Add(SubMenuItemIn.Items[i]);
SubMenuItemOut.Items[i].Tag := FSubMenuItems.Count - 1;
SubMenuItemOut.Items[i].OnClick := @SubMenuItemClick;
SubMenuItemOut.Add(NewItem(SubMenuItemIn.Items[i].Caption,
SubMenuItemIn.Items[i].ShortCut,
SubMenuItemIn.Items[i].Checked,
SubMenuItemIn.Items[i].Visible,
@SubMenuItemClick,
SubMenuItemIn.Items[i].HelpContext,
''));
SubMenuItemOut.Items[i].AutoCheck := SubMenuItemIn.Items[i].AutoCheck;
SubMenuItemOut.Items[i].AutoLineReduction := SubMenuItemIn.Items[i].AutoLineReduction;
SubMenuItemOut.Items[i].Default := SubMenuItemIn.Items[i].Default;
SubMenuItemOut.Items[i].GlyphShowMode := SubMenuItemIn.Items[i].GlyphShowMode;
SubMenuItemOut.Items[i].GroupIndex := SubMenuItemIn.Items[i].GroupIndex;
SubMenuItemOut.Items[i].Hint := SubMenuItemIn.Items[i].Hint;
SubMenuItemOut.Items[i].ImageIndex := SubMenuItemIn.Items[i].ImageIndex;
SubMenuItemOut.Items[i].RadioItem := SubMenuItemIn.Items[i].RadioItem;
SubMenuItemOut.Items[i].RightJustify := SubMenuItemIn.Items[i].RightJustify;
SubMenuItemOut.Items[i].ShortCutKey2 := SubMenuItemIn.Items[i].ShortCutKey2;
SubMenuItemOut.Items[i].ShowAlwaysCheckable := SubMenuItemIn.Items[i].ShowAlwaysCheckable;
SubMenuItemOut.Items[i].SubMenuImages := SubMenuItemIn.Items[i].SubMenuImages;
SubMenuItemOut.Items[i].SubMenuImagesWidth := SubMenuItemIn.Items[i].SubMenuImagesWidth;
SubMenuItemOut.Items[i].Tag := PtrInt(Pointer(SubMenuItemIn.Items[i]));
if SubMenuItemIn.Items[i].Count > 0 then PrepSubMenuItem(SubMenuItemIn.Items[i], SubMenuItemOut.Items[i]);
end;
end;
begin
MenuButton := TSpeedButton(Sender);
if Assigned(FMenu.Items[MenuButton.Tag].OnClick) then FMenu.Items[MenuButton.Tag].Click;
if FMenu.Items[MenuButton.Tag].Count = 0 then Exit;
FSubMenu.Items.Assign(FMenu.Items[MenuButton.Tag]);
FSubMenuItems.Clear;
PrepSubMenuItem(FMenu.Items[MenuButton.Tag], FSubMenu.Items);
tmpMI := FMenu.Items[MenuButton.Tag];
if not Assigned(tmpMI) then Exit;
tmpMI.Click;
FSubMenu.Items.Clear;
if tmpMI.Count = 0 then Exit;
FSubMenu.Images := tmpMI.GetImageList;
PrepSubMenuItem(tmpMI, FSubMenu.Items);
SubMenuPos := ClientToScreen(TPoint.Create(MenuButton.Left, MenuButton.Top + MenuButton.Height));
FSubMenu.PopUp(SubMenuPos.X, SubMenuPos.Y);
end;