Recent

Author Topic: Ways to manipulate a toolbutton's paint a bit, pros and cons  (Read 2081 times)

d7_2_laz

  • Hero Member
  • *****
  • Posts: 657
Ways to manipulate a toolbutton's paint a bit, pros and cons
« on: December 30, 2024, 04:29:04 pm »
These days i'd talked a couple of times about the port of an old Notepad++ plugin to Lazarus (3.) 64bit, Windows.
With the gui part (with special regards to the dark mode as from NPP's theme layer) i'm almost done.
Remains a small particular thing. In dark mode, TToolBar's dividers/separators and a dropdown button are unrecognizably painted.
See image attached.

I asked myself how to deal best with this.  - Thoughts:
- Ignore it
- Take another (tool)button component (yes, those are)
- Inherit a "TToolButton2" via cloning the whole toolbutton code (yes, we can)
- Clone only the painting stuff within a form's "PaintButton" callback and change this one.
Some strong suggestions or recommendations here?

About the last approach i put a few toes into and noticed that mostly one is busy to replicate,  mimic or "open" some intrinsic (private or protected) properties or functions.
About this, i reached my limits here:

Code: Pascal  [Select][+][-]
  1. type
  2.   TToolButtonOpener = class(ComCtrls.TToolButton);
  3. .....
  4. procedure THelloWorldDockingForm.ToolBar1PaintButton(Sender: TToolButton; State: integer);
  5. var
  6.   Details: TThemedElementDetails;
  7. .....
  8. begin
  9. .....
  10.   Details := TToolButtonOpener(Sender).GetButtonDrawDetail;
 
===> Exception "Invalid type cast", and then SIGSEV.

Similar with
Code: Pascal  [Select][+][-]
  1.   toolbutton2 := TToolButtonOpener(Sender);    // Sender is TToolButton

==> Why invalid type cast? And how else to invoke toolbutton's GetButtonDrawDetail ?

-------
About a side thought more maybe later.
Code: Pascal  [Select][+][-]
  1.     aToolBar.OnPaintButton := nil; //ToolButton's paint asks for: if Assigned(FToolBar.OnPaintButton)
  2.     inherited;   // Hope that here the button is painted.  (But it won't).
  3.     // And now overpaint the desired parts only
  4.     // When finished, restore the OnPaintButton assignment:
  5.     aToolBar.OnPaintButton := ToolBar1PaintButton;
Lazarus 4.4  FPC 3.2.2 Win10 64bit

d7_2_laz

  • Hero Member
  • *****
  • Posts: 657
Re: Ways to manipulate a toolbutton's paint a bit, pros and cons
« Reply #1 on: December 31, 2024, 11:01:57 am »
Stop, reset, doesn't make much sense to struggle with all this protected stuff when trying to invoke existing code of toolbutton.inc.
The easier and safer way for the dark mode appears to be better here.
To paint manually the icons (with indication of focused/pressed/disabled), separator and dropdown triangle, and omit the special ThemeServices here.
Lazarus 4.4  FPC 3.2.2 Win10 64bit

 

TinyPortal © 2005-2018