Lazarus

Programming => General => Topic started by: seany on February 05, 2023, 07:37:48 am

Title: When does Menu OnDrawItem fire?
Post by: seany on February 05, 2023, 07:37:48 am
I have already asked a similar question (https://forum.lazarus.freepascal.org/index.php/topic,62149.0.html). But, I was wondering, when does the ondrawItem event fire?

Here is my code:

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm1.MainMenu1DrawItem(Sender: TObject; ACanvas: TCanvas;
  3.   ARect: TRect; AState: TOwnerDrawState);
  4. begin
  5.   showMessage('1');
  6.   ACanvas.Brush.Color := clBlack;
  7.   ACanvas.FillRect(ARect);
  8.   ACanvas.Font.Color := clYellow;
  9.   ACanvas.TextOut(ARect.Left, ARect.Top, 'TEST');
  10. end;
  11.  
  12. procedure TForm1.MenuItem1DrawItem(Sender: TObject; ACanvas: TCanvas;
  13.   ARect: TRect; AState: TOwnerDrawState);
  14. var
  15.   s: string;
  16. begin
  17.   showMessage('2');
  18.  
  19.   ACanvas.Brush.Color := clBlack;
  20.   ACanvas.FillRect(ARect);
  21.   ACanvas.Font.Color := clYellow;
  22.   ACanvas.TextOut(ARect.Left, ARect.Top, TMenuItem(Sender).Caption);
  23.  
  24.  
  25. end;      
  26.  

It never seems to fire. I never quite get the showmessage popups.
I have made the menu ownerdrable in the form designer

I also thought to call the function TForm1.MenuItem1DrawItem from the main form load function. But what arguments can I pass there?


Project attached.

Lazarus 2.2.4 (rev Unknown) FPC 3.2.2 x86_64-linux-qt5
Title: Re: When does Menu OnDrawItem fire?
Post by: jamie on February 05, 2023, 05:30:25 pm
a Widget limitation ?

Title: Re: When does Menu OnDrawItem fire?
Post by: Slawek on February 07, 2023, 11:38:14 pm
I looked at the source code and no procedure seems to call OnDrawItem, either in TMenu or TMenuItem.
Title: Re: When does Menu OnDrawItem fire?
Post by: dsiders on February 07, 2023, 11:54:11 pm
I looked at the source code and no procedure seems to call OnDrawItem, either in TMenu or TMenuItem.

That's not correct.  See TMenuItem.DoDrawItem.
Title: Re: When does Menu OnDrawItem fire?
Post by: Sieben on February 08, 2023, 01:21:05 am
Did you try setting OwnerDraw to True for your menu to invoke the item's OnDrawItem?
Title: Re: When does Menu OnDrawItem fire?
Post by: seany on February 08, 2023, 01:58:19 pm
Did you try setting OwnerDraw to True for your menu to invoke the item's OnDrawItem?

Yes, of course
Title: Re: When does Menu OnDrawItem fire?
Post by: seany on February 08, 2023, 02:07:28 pm
I looked at the source code and no procedure seems to call OnDrawItem, either in TMenu or TMenuItem.

That's not correct.  See TMenuItem.DoDrawItem.

Is DoDrawItem een defined for Linux?

The only example i can find is this:

https://fossies.org/linux/lazarus/lcl/interfaces/win32/win32wsmenus.pp

This page does not show how to call it:

https://lazarus-ccr.sourceforge.io/docs/lcl/menus/tmenuitem.dodrawitem.html

As I said above, I am on Lazarus 2.2.4 (rev Unknown) FPC 3.2.2 x86_64-linux-qt5
Title: Re: When does Menu OnDrawItem fire?
Post by: dsiders on February 08, 2023, 07:31:07 pm
I looked at the source code and no procedure seems to call OnDrawItem, either in TMenu or TMenuItem.

That's not correct.  See TMenuItem.DoDrawItem.

Is DoDrawItem een defined for Linux?

The only example i can find is this:

https://fossies.org/linux/lazarus/lcl/interfaces/win32/win32wsmenus.pp

This page does not show how to call it:

https://lazarus-ccr.sourceforge.io/docs/lcl/menus/tmenuitem.dodrawitem.html

As I said above, I am on Lazarus 2.2.4 (rev Unknown) FPC 3.2.2 x86_64-linux-qt5

I overlooked that detail. My bad.
TinyPortal © 2005-2018