Search code examples
delphidelphi-xe2jvcl

JvTreeView and JvCheckTreeView checkbox notification


I have set a JvTreeView.CheckBoxes to True, and the check boxes are displayed and working as expected, but on Windows XP SP3 and below, the OnNodeCheckedChange event is not fired. I googled a little, and found this issue on JVCL issue tracker, but I can not apply it to the latest JVCL release (Version 3.47). Has anyone any fix for the check box event?


Update: The event is fired when I change the check box using space bar, but is not fired when I click on the check box.


Solution

  • From a discussion we've had I know you've used RTL reading for your JvTreeView and I've added that you should include also the TVS_RTLREADING style to the control styles. So, here is how to do it in a late control styling (which you have used):

    procedure TForm1.FormShow(Sender: TObject);
    begin
      SetWindowLong(JvTreeView1.Handle, GWL_STYLE, GetWindowLong(
        JvTreeView1.Handle, GWL_STYLE) or TVS_RTLREADING);
      SetWindowLong(JvTreeView1.Handle, GWL_EXSTYLE, GetWindowLong(
        JvTreeView1.Handle, GWL_EXSTYLE) or WS_EX_LAYOUTRTL or WS_EX_RIGHT);
    end;
    

    The problem with the control notification is in coordinates mapping (see this answer why it happens). As a fix to the JvComCtrls.pas source you can replace the ScreenToClient point mapping on line 3094 with the following:

    MapWindowPoints(0, Handle, Point, 1);
    

    in the JvComCtrls.pas unit in the CNNotify method it will look like:

    3071  procedure TJvTreeView.CNNotify(var Msg: TWMNotify);
    ....  ...
    3091    inherited;
    3092    if Windows.GetCursorPos(Point) then
    3093    begin
    3094      MapWindowPoints(0, Handle, Point, 1);
    3095      case Msg.NMHdr.code of
    ....  ...