Lazarus

Programming => Graphics and Multimedia => TAChart => Topic started by: AL on January 30, 2020, 03:54:08 pm

Title: [SOLVED] ChartListBox: Check and Radio not showing in COCOA
Post by: AL on January 30, 2020, 03:54:08 pm
The Chart listBox component does not show the checkbox in Cocoa the icon (line) is shown.
With the radio button activated.  The radio button is not shown and the icon (line) not shown.

This is with cross compiling win10-Darwin
FPC 3.3.1 Laz 2.1.0
Tested in VMWare Mac 10.14
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: wp on January 30, 2020, 04:53:49 pm
The ChartListBox is similar to a TCheckListBox (on palette "Additional"). Does is show the same issue? Or are the checkboxes drawn correctly, but the radion buttons not?

Again, could you also post the screenshot taken on Windows so that I can see what you are expecting? (Or post the entire project).
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: AL on January 30, 2020, 06:28:30 pm
The listbox is drawn correctly, only the checkbox is not shown when checkbox is selected and the radiobutton and icon are not shown when radio button is selected.

Here is a windows version for comparison.
This is an empty project just to demonstrate the behavior.
Would it be better to post this in COCOA?
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: wp on January 30, 2020, 08:01:47 pm
And is the checkbox displayed correctly for the CheckListBox? If yes I could look for the differences.
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: AL on January 30, 2020, 10:19:00 pm
The check square is not displayed but the icon is displayed.
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: wp on January 31, 2020, 01:24:34 am
Icon in the TCheckListbox? You probably don't understand what I mean. I am talking of the TCheckListbox on palette "Additional" - see screenshot. It is as standard component with similar functionality as TChartListbox but it draws the checkbox a bit differently.
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: AL on January 31, 2020, 01:45:05 am
Oh, sorry my bad, checklistbox, chartlistbox with check,... confusing.

Yes the CHECKlistbox show properly in MacOS as you can see on the attached.
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: wp on January 31, 2020, 09:47:46 am
Here's another test: Could you show me how the attached demo behaves in MacOS? It shows two more LCL controls, a TStringGrid with checkbox column, and a TCheckCombobox. In both controls, the checkboxes are drawn using the theme services, like in TChartlistbox. If checks are not displayed here again then this is an argument that theme services for checkboxes are not correctly implemented for MacOS. (TCheckListBox that you already tested passes the drawing task to the widget set).
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: AL on January 31, 2020, 03:28:24 pm
Here is the result in VM MacOS and Win64

Edit:   added new printscreen with combobox drop down.

There is a little glitch when not dropdown but it show the checkbox correctly
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: AL on February 12, 2020, 01:35:36 am
WP, could you make sense of why this is happening?
Would it be better to make a bug report in Cocoa?
Thanks
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: wp on February 12, 2020, 04:05:32 pm
Could you try the attached project on Mac? It draws a checked and an unchecked checkbox onto two paintboxes. In the first paintbox the checkbox size is determined by the code as is done in TChartListbox, in the second it is determined by the theme services as is done by the other LCL controls. It's hard to believe that this would make a difference, but beyond that the drawing code looks fairly similar.
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: AL on February 12, 2020, 10:06:44 pm
You were right! There is no difference. None of them show a check.
Also the Mac does not show the label.
This is on a virtual Mac.  May be we need someone to try it on a real Mac.
Trev has been very helpfull in another problem, I will send a PM and ask him to try the attached.
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: trev on February 12, 2020, 10:39:27 pm
Result of the test.zip project on a 2018 Mac mini running  Mojave 10.14.6 is attached.
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: AL on February 12, 2020, 10:47:27 pm
Thank you Trev,  this give the same as in my Vm MAC.
It look like this is more work for the Cocoa team!
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: wp on February 12, 2020, 10:57:18 pm
"No themes enabled" in the title? How is that? I thought themes are always enabled nowadays... Comparing with the TCustomStringGrid code I see that the check for "ThemeServices.ThemesEnabled" is skipped. Could you please remove the line "if ThemeServices.ThemesEnabled" (and the associated "else" block) so that the entire OnPaint handler of the paintboxes is like this:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PaintBox1Paint(Sender: TObject);
  2. const
  3.   THEMED_FLAGS: array [Boolean] of TThemedButton = (
  4.     tbCheckBoxUncheckedNormal, tbCheckBoxCheckedNormal
  5.   );
  6. var
  7.   rcb: TRect;
  8.   te: TThemedElementDetails;
  9.   ch: Boolean;
  10.   sz: TSize;
  11.   paintbox: TPaintBox;
  12.   lbl: TLabel;
  13. begin
  14.   paintbox := TPaintBox(Sender);
  15.   if Sender = Paintbox1 then
  16.     lbl := Label1
  17.   else
  18.     lbl := Label2;
  19.  
  20.   paintbox.Canvas.Brush.Color := clWhite;
  21.   paintbox.Canvas.FillRect(Rect(0, 0, paintbox.Width, paintbox.Height));
  22.  
  23.   //if ThemeServices.ThemesEnabled then begin   // <---------- REMOVE THIS LINE ...
  24.     ch := true;
  25.     te := ThemeServices.GetElementDetails(THEMED_FLAGS[ch]);
  26.     if Sender = Paintbox1 then
  27.       sz := Size(30, 30)
  28.     else
  29.       sz := ThemeServices.GetDetailSize(te);;
  30.     rcb := Rect(0, 0, sz.CX, sz.CY);
  31.     lbl.Caption := Format('rcb = %d %d %d %d', [rcb.Left, rcb.Top, rcb.Right, rcb.Bottom]);
  32.     ThemeServices.DrawElement(paintbox.Canvas.Handle, te, rcb);
  33.  
  34.     OffsetRect(rcb, 40, 0);
  35.     ch := false;
  36.     te := ThemeServices.GetElementDetails(THEMED_FLAGS[ch]);
  37.     ThemeServices.DrawElement(paintbox.Canvas.Handle, te, rcb);
  38.   //end                                  // <-------------- AND THESE
  39.   //else
  40.   //  Caption := 'NO THEMES ENABLED';
  41. end;
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: trev on February 12, 2020, 11:06:01 pm
Removing the themes bypass... see attached.
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: wp on February 13, 2020, 12:13:39 am
Wow!

In r62628 I committed a version of TChartListbox in which the ThemesEnabled check has been removed, too. It should work now.

Could you finally test also the attached modified demo in which two paintboxes with checkboxes are compared again: in the left paintbox the ThemesEnabled is NOT checked while it IS checked in the right paintbox. On Windows, the checkboxes are painted in both, but on the Mac only the left checkbox should appear with the current bug.
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: trev on February 13, 2020, 12:55:23 am
No attachment  :(
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: wp on February 13, 2020, 01:02:26 am
Grrrrh...
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: trev on February 13, 2020, 01:23:05 am
Results attached.
Title: [SOLVED] Re: ChartListBox: Check and Radio not showing in COCOA
Post by: AL on February 13, 2020, 03:42:21 am
Wow!

In r62628 I committed a version of TChartListbox in which the ThemesEnabled check has been removed, too. It should work now.
Thank you Werner,  what is the best way to get this update.  FpcUpDeluxe does not list the "r",  should I get the trunk?
I tried downloading the TChartlistbox.pas and adding to the component/tachart directory and recompile, but that does not make any difference, the checkbox are still not showing.
 
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: wp on February 13, 2020, 09:52:02 am
The "r" is just the svn revision numbers, changes are always found in trunk. So when you install Lazarus trunk via fpcupdeluxe, or use svn to update your trunk, you will get the change.

Alternatively, if you have the current or an older release version, you can patch the unit easily yourself:
Code: Pascal  [Select][+][-]
  1. procedure TChartListbox.DrawItem(
  2.   AIndex: Integer; ARect: TRect; AState: TOwnerDrawState);
  3. { draws the listbox item }
  4. const
  5.   THEMED_FLAGS: array [TCheckboxesStyle, Boolean] of TThemedButton = (
  6.     (tbCheckBoxUncheckedNormal, tbCheckBoxCheckedNormal),
  7.     (tbRadioButtonUnCheckedNormal, tbRadioButtonCheckedNormal)
  8.   );
  9. var
  10.   id: IChartDrawer;
  11.   rcb, ricon: TRect;
  12.   te: TThemedElementDetails;
  13.   x: Integer;
  14.   ch: Boolean;
  15. begin
  16.   if Assigned(OnDrawItem) then begin
  17.     OnDrawItem(Self, AIndex, ARect, AState);
  18.     exit;
  19.   end;
  20.   if (FChart = nil) or not InRange(AIndex, 0, Count - 1) then
  21.     exit;
  22.  
  23.   Canvas.FillRect(ARect);
  24.   CalcRects(ARect, rcb, ricon);
  25.  
  26.   if cloShowCheckboxes in Options then begin
  27.     ch := Checked[AIndex];
  28.     te := ThemeServices.GetElementDetails(THEMED_FLAGS[FCheckStyle, ch]);
  29.     ThemeServices.DrawElement(Canvas.Handle, te, rcb);
  30.     x := rcb.Right;
  31.   end
  32.   else
  33.     x := ARect.Left;
  34.  
  35.   Canvas.Brush.Style := bsClear;
  36.   if cloShowIcons in Options then begin
  37.     id := TCanvasDrawer.Create(Canvas);
  38.     id.Pen := Chart.Legend.SymbolFrame;
  39.     FLegendItems[AIndex].Draw(id, ricon);
  40.   end
  41.   else
  42.     Canvas.TextOut(x + 2, ARect.Top, FLegendItems.Items[AIndex].Text);
  43. end;
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: AL on February 13, 2020, 05:49:34 pm
Not sure if I am doing something wrong, I did follow the instructions and recompile the package  but the check boxes still do not show!
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: wp on February 13, 2020, 06:04:15 pm
Just to make sure: Create a new form. Add a TChartListbox. Find the ChartListbox1 in the declaration section of the form. Hold the CTRL key down and left-click on the identifier "TChartlistbox" in the editor. This opens the unit TAChartListbox which is used by your program. Scroll down and find the "DrawItem" method. Is it the same as in my post?

If yes make sure that the editor has this unit in its active window. Go to "Package" > "Open package of current unit". This opens the TAChart package used by your program. In the package editor do a clean compilation of the package now: Click "More" > "Recompile clean". Then do "Use" > "Install" to rebuild the IDE.

If it still does not work my fix was useless. I wonder then why checkboxes were displayed in the simple demo as seen by trev because it used the same code.
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: AL on February 13, 2020, 08:15:08 pm
Used the instructions, except I used my actual program. The link goes to the new drawitem method.  I had not made a use / install  which I did this time.  But no luck I still get the same (see attached )
Now, I said may be it is my program. 
So I created a new project with one chart with 2 series (empties).  Put a chart listbox.
It compile fine in Windows.  But when cross compiling to Darwin I get a strange error.
See attached screen capture.
I tried clean and rebuild with same result.
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: trev on February 14, 2020, 12:43:01 am
From the Free Pascal ref docs (https://www.freepascal.org/docs-html/3.0.0/user/usersu7.html):

Quote
Also, unit names that are longer than 8 characters will first be looked for with their full length. If the unit is not found with this name, the name will be truncated to 8 characters, and the compiler will look again in the same directories, but with the truncated name.

I think this explains your issue.
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: wp on February 14, 2020, 01:02:44 am
Maybe it was not enough to just do a clean recompilation of TAChart. Do a clean recompilation of the IDE, too: "Tools" > "Configure Build Lazarus" > in the "Clean up" box check "Clean all" and "Switch after building to automatically". Then click "Build".
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: AL on February 14, 2020, 01:33:36 am
From the Free Pascal ref docs (https://www.freepascal.org/docs-html/3.0.0/user/usersu7.html):

Quote
I think this explains your issue.
Possibly, it does not do that error in my regular program.
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: AL on February 14, 2020, 02:04:21 am
Did try the IDe recompilation.
Also got rid of my new problem by shortening the names.

Still the same also in a new simple program.
Title: Re: ChartListBox: Check and Radio not showing in COCOA
Post by: wp on February 18, 2020, 12:44:43 am
The issue should be fixed now in the trunk version.
Title: Re: [SOLVED] ChartListBox: Check and Radio not showing in COCOA
Post by: AL on March 05, 2020, 04:31:00 am
Sure it is, Thank you
TinyPortal © 2005-2018