Forum > Linux

TCheckListBox custom OnDrawItem when form disabled

(1/1)

andyH:
Note sure whether this should be in the linux or LCL area?

I have a TCheckListBox with a custom OnDrawItem, relevant definition for the TCheckListBox:

--- 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";}};} ---Box2.Style:= lbOwnerDrawFixed;Box2.OnDrawItem:= @BoldOS;With BoldOS as

--- 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";}};} ---procedure TBasePanel.BoldOS(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState);const  AdjustL = 5;  AdjustT = 3;begin  with (Control as TCheckListBox) do       begin         if MyDrives.isOS(Items[Index]) then Canvas.Font.Bold:= true;         Canvas.TextOut(ARect.Left + AdjustL,ARect.Top + AdjustT,Items[Index]);       end;end;When an operating system is detected on a partition it displays the text in bold. It works. But...

* Enabled.png is the mainform enabled, display as wanted.
* Disabled.png is the mainform disabled (which I need to do when child forms are displayed).When the main form is disabled I want Box2 to look the same as Box1 (which has no custom OnDrawItem defined - uses the defaults), i.e. grey background with greyed text and I've not been able to find out how to do it.

First issue was detecting that the main form has been disabled, if not MainFm.Enabled seems clumsy given that it is automatically detected in Box1. Then there is what colours to use, given that I don't want to use specific colours, I want the theme defaults?

andyH:
Well I got there, but it was like pulling teeth. Along the way I found out that:

* While disabling the main form disables all the embedded objects it does not set enabled:= false on them, it has to be done explicitly.
* Canvas.TextOut redraws the background while using Canvas.TextRect with the property Opaque set false does not.
* Canvas.TextRect ignores Canvas.Font.Bold:= true.
* On a disabled TCheckListBox/ListBox using Canvas.TextRect with the font colour clGrayText sets the font colour correctly, but a default disabled TCheckListBox/ListBox appears to have a white outline around the text. This was achieved by using TextRect twice, once with white text shifted one pixel down and right, and then again with clGrayText text not shifted.

The resultant code:

--- 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";}};} ---procedure TBasePanel.BoldOS(Control: TWinControl; Index: Integer; ARect: TRect; State: TOwnerDrawState);const  AdjustL = 5;  AdjustT = 3;var  BoxStyle : TTextStyle;begin  with (Control as TCheckListBox) do       if enabled then          begin            if MyDrives.isOS(Items[Index]) then Canvas.Font.Bold:= true;            Canvas.TextOut(ARect.Left + AdjustL,ARect.Top + AdjustT,Items[Index]);          end       else          begin            BoxStyle.Opaque:= false;            BoxStyle.Layout:= tlTop;            Canvas.Font.color:= clWhite;            Canvas.TextRect(ARect, ARect.Left+AdjustL+1,ARect.Top+AdjustT+1,Items[Index], BoxStyle);            Canvas.Font.color:= clGrayText;            Canvas.TextRect(ARect, ARect.Left+AdjustL,ARect.Top+AdjustT,Items[Index], BoxStyle);          end;end; //end procedure TBasePanel.BoldOSThe end effect as the screenshot where the TCheckListBox on the right has the custom OnDrawItem.

If there is a better way of doing this I'd like to know  ::)

Navigation

[0] Message Index

Go to full version