Forum > LCL
Ways to manipulate a toolbutton's paint a bit, pros and cons
(1/1)
d7_2_laz:
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type TToolButtonOpener = class(ComCtrls.TToolButton);.....procedure THelloWorldDockingForm.ToolBar1PaintButton(Sender: TToolButton; State: integer);var Details: TThemedElementDetails;.....begin..... Details := TToolButtonOpener(Sender).GetButtonDrawDetail;
===> Exception "Invalid type cast", and then SIGSEV.
Similar with
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- 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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- aToolBar.OnPaintButton := nil; //ToolButton's paint asks for: if Assigned(FToolBar.OnPaintButton) inherited; // Hope that here the button is painted. (But it won't). // And now overpaint the desired parts only // When finished, restore the OnPaintButton assignment: aToolBar.OnPaintButton := ToolBar1PaintButton;
d7_2_laz:
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.
Navigation
[0] Message Index