Lazarus

Programming => Widgetset => Cocoa => Topic started by: bigeno on April 01, 2022, 09:14:26 pm

Title: About Buttons/ExCtrls and cocoa
Post by: bigeno on April 01, 2022, 09:14:26 pm
Hi,
I need help with exctrls @wp.
I've some problems with porting one of my projects to Mac os on cocoa. For some reasone there is no captions on buttons (same for design mode and productuion).
Can anyone advise ?
---edit

What I observed is when creating a new project the text on the button is only in design mode, after closing the project and reopening the button text is no longer there (design mode).
Looks like something is being removed from the lfm ?
Title: Re: About Buttons/ExCtrls and cocoa
Post by: AlexTP on April 01, 2022, 09:47:00 pm
Provide a simple compilable test project, please.
Title: Re: About Buttons/ExCtrls and cocoa
Post by: bigeno on April 01, 2022, 10:01:07 pm
Provide a simple compilable test project, please.
the problem is with new/empty project also.
Attached example.
Title: Re: About Buttons/ExCtrls and cocoa
Post by: wp on April 01, 2022, 11:05:22 pm
I see... It looks to me that the mac button is very strict regarding custom painting. The debugger shows me that the painting routine is entered and every command is called - but finally is not executed at all.

However, since I don't work on mac except for some occasional compilation tests and simple bug fixes I am afraid that I cannot do much about it. Maybe a more experienced user can help?

Title: Re: About Buttons/ExCtrls and cocoa
Post by: bigeno on April 02, 2022, 02:42:13 pm
I see... It looks to me that the mac button is very strict regarding custom painting. The debugger shows me that the painting routine is entered and every command is called - but finally is not executed at all.

However, since I don't work on mac except for some occasional compilation tests and simple bug fixes I am afraid that I cannot do much about it. Maybe a more experienced user can help?
yes, the problem is with caption and colors also (whole painting). For captions I found this will work:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   TCustomButton(ButtonEx1).Caption:='test';
  4. end;
Title: Re: About Buttons/ExCtrls and cocoa
Post by: wp on April 02, 2022, 07:16:13 pm
Ah I see. In the SetCaption setter method, there is this code:

Code: Pascal  [Select][+][-]
  1. procedure TButtonEx.SetCaption(const AValue: String);
  2. begin
  3.   if FCaption = AValue then
  4.     exit;
  5.   inherited Caption := '';  
  6.   FCaption := AValue;
  7.   Invalidate;
  8. end;

This erases the inherited Caption and assumes that it is replaced by the new caption (FCaption). I do remember that the control did not work with all its features when the inherited Caption was not empty. And I found an old forum post in which I reported several issues with TButtonEx: https://forum.lazarus.freepascal.org/index.php/topic,50179.msg366185.html

So, my advice: don't use TButtonEx on cocoa... Sorry.
Title: Re: About Buttons/ExCtrls and cocoa
Post by: AlexTP on April 02, 2022, 08:04:57 pm
If you attached the demo project, ppl could see you were talking about ButtonEx, not about Button.
TinyPortal © 2005-2018