function MenuItemSize calls MeasureItem with 0 values for Width and Height
Original Reporter info from Mantis: dmz73 @dmz73
-
Reporter name:
Original Reporter info from Mantis: dmz73 @dmz73
- Reporter name:
Description:
function MenuItemSize in lcl\interfaces\win32\win32wsmenus.pp calls AMenuItem.MeasureItem and passes 0 as initial Width and Height.
This means that user must replicate the same code that function MenuItemSize will use if AMenuItem.MeasureItem does not return true.
It would be much better to calculate default values for Width and Height and pass those to AMenuItem.MeasureItem which can then return new values if required.
This way menu items can be enlarged if required and left as default size in other cases.
Alternatively default calculation for Width and Height could be provided in separate function that user could call without having to replicate the code from MenuItemSize function.
Steps to reproduce:
Create GUI application with 1 form and place a MainMenu on the form.
Add few menu items to MainMenu.
Set MainMenu.OwnerDraw to true.
Add event handler for MainMenu.OnMeasureItem.
Do nothing in the event.
Main menu is drawn incorrectly and menu items are not drawn at all.
Additional information:
Possible change:
function MenuItemSize(AMenuItem: TMenuItem; AHDC: HDC): TSize;
var
CC: TControlCanvas;
ParentMenu: TMenu;
begin
CC := TControlCanvas.Create;
try
CC.Handle := AHDC;
Result.cx := 0;
Result.cy := 0;
if IsVistaMenu then
begin
if AMenuItem.IsInMenuBar then
Result := VistaBarMenuItemSize(AMenuItem, AHDC)
else
Result := VistaPopupMenuItemSize(AMenuItem, AHDC);
end
else
Result := ClassicMenuItemSize(AMenuItem, AHDC);
AMenuItem.MeasureItem(CC, Result.cx, Result.cy);
finally
CC.Free;
end;
end;
Mantis conversion info:
- Mantis ID: 35972
- OS: Windows
- OS Build: 10
- Platform: x86_64
- Version: 2.0.4