Recent

Author Topic: SOLVED: ChartListBox click area not aligned on icon or checkbox in COCOA  (Read 5537 times)

AL

  • Sr. Member
  • ****
  • Posts: 264
Re: ChartListBox click area not aligned on icon or checkbox in COCOA
« Reply #15 on: November 02, 2022, 03:48:17 pm »
You are right, CalcRects is called several time before mouse down.

I set a break in MouseDown just before CalcRects.
I then took a screen shot of the variables and then step in Calcrects

As this was captured in MacOS , I made a PDF of it as I do not know how to convert it to Windows to post here.  I hope this is OK
 

X get changed to 20 in this line:

x := IfThen(isRTL, AItemRect.Right - MARGIN, AItemRect.Left + MARGIN);
                   false             190-          4                  16 + 4

After Offsetrect X is at 42
« Last Edit: November 02, 2022, 04:07:47 pm by AL »
Laz 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

wp

  • Hero Member
  • *****
  • Posts: 13268
Re: ChartListBox click area not aligned on icon or checkbox in COCOA
« Reply #16 on: November 02, 2022, 06:30:48 pm »
Thank you. The problem seems to be that MouseDown and DrawItem get different information on the location of the item to be handled. MouseDown queries the method ItemRect(index), and this gets the data from calling the corresponding cocoa widgetset function. DrawItem, on the other hand, gets the rectangle for painting as a parameter -- some other function must have determined it. I don't have enough knowledge of cocoa to be able to say which one it is, and I don't see anything obvious in the cocoa widgetset units (which are in folder lcl/interfaces/cocoa, by the way). But fact is that both procedures pass a different rectangle information to CalcRect, and so DrawItem paints the checkbox at a location different from what Mousedown assumes (shifted by 16 pixels).

Anyway, I think I can show you a workaround: Let's ignore the left and right borders of the rectangle returned by the ItemRect function and replace them by 0 and ClientWidth respectively (the vertical coordinates do not seem to be a problem). And if we put this into an IFDEF directive even the other widgetsets can live with it.

So, please replace your MouseDown procedure (the one from the Laz-main version in my previous zip, not the original one of Laz 2.2.5) by the following code and test again:
Code: Pascal  [Select][+][-]
  1. procedure TChartListbox.MouseDown(
  2.   AButton: TMouseButton; AShift: TShiftState; AX, AY: Integer);
  3. var
  4.   R, rcb, ricon: TRect;
  5.   index: Integer;
  6.   p: TPoint;
  7. begin
  8.   FDown := true;
  9.   FSeriesIconClicked := -1;
  10.   try
  11.     if AButton <> mbLeft then exit;
  12.     p := Point(AX, AY);
  13.     index := GetIndexAtXY(AX, AY);
  14.     if index < 0 then exit;
  15.     R := ItemRect(index);
  16.     {$IFDEF DARWIN}
  17.     R.Left := 0;
  18.     R.Right := ClientWidth;
  19.     {$ENDIF}
  20.     CalcRects(R, rcb, ricon);
  21.     if (cloShowCheckboxes in Options) and IsPointInRect(p, rcb) then
  22.       ClickedCheckbox(index)
  23.     else if (cloShowIcons in Options) and IsPointInRect(p, ricon) then
  24.       // Remember clicked index for the double click event.
  25.       FSeriesIconClicked := index
  26.     else
  27.       ClickedItem(index);
  28.   finally
  29.     inherited MouseDown(AButton, AShift, AX, AY);
  30.   end;
  31. end;      

There is one disadvantage doing it this way: it is not possible to set the listbox into a multi-column mode (i.e. Columns property > 1). But I tested it and found that it does not seem to work on cocoa anyway. But please verify this with your macOS version: Drop a standard listbox on a form, add some items and set Columns to 2. Does the display change to two columns? If not we can keep above work-around.

AL

  • Sr. Member
  • ****
  • Posts: 264
Re: ChartListBox click area not aligned on icon or checkbox in COCOA
« Reply #17 on: November 02, 2022, 08:01:33 pm »
This work perfectly.  Thank you.
The multi column does not work as expected.

Will this mod be merged in the current version?  If not I will loose it  whenever I update Lazarus.

I assume this work also in Mojave.
Thank you very much for this long debug session, I have learned a lot! 
Laz 3.1, fpc 3.2.2, Win10
Laz 3.1  fpc 3.2.2, MacOS Monterey running on VMWare/Win 10
Laz 3.1  fpc 3.2.2 Ubuntu 20.04

wp

  • Hero Member
  • *****
  • Posts: 13268
Re: ChartListBox click area not aligned on icon or checkbox in COCOA
« Reply #18 on: November 02, 2022, 10:21:37 pm »
Committed to Lazarus/main and requested back-porting to Laz/fixes (2.2.5).

 

TinyPortal © 2005-2018