View Issue Details

IDProjectCategoryView StatusLast Update
0035972LazarusLCLpublic2019-08-16 09:08
Reporterdmz73Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Platformx86_64OSWindowsOS Version10
Product Version2.0.4Product Build 
Target VersionFixed in Version 
Summary0035972: function MenuItemSize calls MeasureItem with 0 values for Width and Height
Descriptionfunction 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 ReproduceCreate 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 InformationPossible 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;
TagsNo tags attached.
Fixed in Revision
LazTarget
WidgetsetWin32/Win64
Attached Files

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2019-08-16 09:08 dmz73 New Issue
2019-08-16 09:08 dmz73 Issue generated from: 0035971