Recent

Author Topic: When does Menu OnDrawItem fire?  (Read 914 times)

seany

  • Jr. Member
  • **
  • Posts: 99
When does Menu OnDrawItem fire?
« on: February 05, 2023, 07:37:48 am »
I have already asked a similar question. 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

jamie

  • Hero Member
  • *****
  • Posts: 5347
Re: When does Menu OnDrawItem fire?
« Reply #1 on: February 05, 2023, 05:30:25 pm »
a Widget limitation ?

The only true wisdom is knowing you know nothing

Slawek

  • New Member
  • *
  • Posts: 31
Re: When does Menu OnDrawItem fire?
« Reply #2 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.

dsiders

  • Hero Member
  • *****
  • Posts: 870
Re: When does Menu OnDrawItem fire?
« Reply #3 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.
Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

Sieben

  • Sr. Member
  • ****
  • Posts: 310
Re: When does Menu OnDrawItem fire?
« Reply #4 on: February 08, 2023, 01:21:05 am »
Did you try setting OwnerDraw to True for your menu to invoke the item's OnDrawItem?
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

seany

  • Jr. Member
  • **
  • Posts: 99
Re: When does Menu OnDrawItem fire?
« Reply #5 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

seany

  • Jr. Member
  • **
  • Posts: 99
Re: When does Menu OnDrawItem fire?
« Reply #6 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

dsiders

  • Hero Member
  • *****
  • Posts: 870
Re: When does Menu OnDrawItem fire?
« Reply #7 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.
Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

 

TinyPortal © 2005-2018