Lazarus

Programming => Widgetset => Cocoa => Topic started by: dbannon on July 29, 2018, 02:05:08 pm

Title: Cocoa not reporting clipboard contents correctly
Post by: dbannon on July 29, 2018, 02:05:08 pm
Edit - Altered title as I realised its not related in any way to KControls

An issue with Cocoa on the Mac using trunk from yesterday.

I am testing Cocoa with my code that uses KMemo and find that I cannot paste into KMemo (unless, strangely, I first copy from it). I have traced to the function TClipboard.GetFormatCount:Integer  in clipbrd.inc#738. Its returning 0, that is not Formats present in Clipboard. Thats wrong.

This function returns FCount if CanReadFromCache is true (and its not) or 0. I say '0' because it sets Result to 0 and the calls ClipboardGetFormats() which calls Cocoawinapi.inc #227 f TCocoaWidgetSet.ClipboardGetFormats() but they cannot alter Result even though it is passed through them as a var.

So, I wonder if the function TCocoaWidgetSet.ClipboardGetFormats() in Cocoawinapi.inc #227 is incomplete ?

I note that pasting into a Memo on the same form works fine but does not follow the same path as KMemo does, indeed, I don't see what path it takes but it does not hit my breakpoints in GetFormatCount:Integer  in clipbrd.inc#738

Pasting into KMemo behaves fine in Linux, Windows and Carbon.

Any suggestions please ?
Title: Re: Cocoa not pasting into KMemo
Post by: dbannon on July 30, 2018, 11:00:03 am
OK, still trying to debug the above issue.

There is little doubt in my mind that the problem lies with cocoawinapi.inc #221
Code: Pascal  [Select]
  1. function TCocoaWidgetSet.ClipboardGetFormats(ClipboardType: TClipboardType;
  2.   var Count: integer; var List: PClipboardFormat): boolean;

This function, in carbon, does alter the value of Count, in Cocoa is does not. In fact, to my untrained eye, what it does do is silly. Anyway, I make any change to this file, and it triggers a compile of cocoaint.pas which fails -

Code: [Select]
cocoaint.pas(374,39) Error: identifier idents no member "lclisHandle"
and a number of similar ones.  Its refering to this -

Code: Pascal  [Select]
  1. function HandleToNSObject(AHWnd: HWND): id;
  2. begin
  3.   if (AHwnd=0) or not NSObject(AHWnd).lclisHandle then Result:=nil
  4.   else Result:=NSObject(AHwnd);
  5. end;
     

It may well be right but why does it fail now, not during initial build, not during install of kcontrols package, not during tests of dummy cocoa apps, only when I touch cocoawinapi.inc ?? 

Again, this is today's trunk I am talking about.

Hitting my head against a brick wall and starting to realise I don't enjoy it ....

Davo
Title: Re: Cocoa not pasting into KMemo
Post by: dbannon on July 30, 2018, 01:37:13 pm
OK, so I know this is nothing to do with KControls. Its all about Cocoa.

Bring a clean svn lazarus down,  trunk.
Compile - make CPU_TARGET=i386
Open the newly compiled lazarus - open ./lazarus.app --args "--pcp=~/.laz-svn"
Set it up, create a project, set that project to Cocoa widgets, x86_64
Compile and test, all OK.
Exit Lazarus and then, from commandline (in the new laz dir)-
touch lcl/interfaces/cocoa/cocoawinapi.inc
Open up lazarus, open the same project, try and build it again. You'll get -
Code: [Select]
Compile package LCL 1.9: Exit code 256, Errors: 28, Hints: 18
cocoaint.pas(137,14) Note: Virtual method "PromptUser(const AnsiString;const AnsiString;LongInt;PLongint;LongInt;LongInt;LongInt):LongInt;" has a lower visibility (protected) than parent class TWidgetSet (public)
...
cocoaint.pas(374,39) Error: identifier idents no member "lclisHandle"
cocoaint.pas(413,26) Error: identifier idents no member "lclGetCallback"
...
cocoawinapi.inc(102,22) Error: identifier idents no member "lclContentView"
cocoawinapi.inc(772,20) Error: identifier idents no member "lclSetEnabled"
and so on ....
Title: Re: Cocoa not pasting into KMemo
Post by: Phil on July 30, 2018, 02:26:00 pm
and so on ....

Did you try deleting the .o/.ppu files in lcl/units/x86_64-darwin/cocoa first?
Title: Re: Cocoa not reporting clipboard contents correctly
Post by: dbannon on July 30, 2018, 02:44:29 pm
Not sure what you mean Phil, delete the object files before what ?

Touching the source invalidates the object file, requiring a recompile. My concern is that the recompile fails ! Even with no change to the source.

Its like it arrived, via svn, with those object file and they don't, somehow, match the source that arrived at the same time. But there cannot be any object file in svn, is there ???

Davo
Title: Re: Cocoa not reporting clipboard contents correctly
Post by: Phil on July 30, 2018, 02:50:49 pm
Not sure what you mean Phil, delete the object files before what ?

Before compiling.
Title: Re: Cocoa not reporting clipboard contents correctly
Post by: skalogryz on July 30, 2018, 03:06:29 pm
Not sure what you mean Phil, delete the object files before what ?
http://wiki.freepascal.org/Cocoa_Internals#Recompilation
Title: Re: Cocoa not reporting clipboard contents correctly
Post by: dbannon on July 31, 2018, 12:50:48 am
http://wiki.freepascal.org/Cocoa_Internals#Recompilation

Oh, thats an interesting read !  I'll try that approach later today.

Thanks Phil /  skalogryz - without that hint I would have given up I suspect ....

Davo
Title: Re: Cocoa not reporting clipboard contents correctly
Post by: dbannon on July 31, 2018, 02:16:55 am
Yep, thats a fix. Its a pretty strange bug, I guess its been logged ?

I'll now get on with the original purpose of this thread.

Thanks guys !
Title: Re: Cocoa not reporting clipboard contents correctly
Post by: dbannon on August 01, 2018, 03:27:30 am
The issue is the function TCocoaWidgetSet.ClipboardGetFormats(ClipboardType: TClipboardType; var Count: integer; var List: PClipboardFormat): boolean; in cocoawinapi.inc does not behave as it should.

That function should return with firstly, the list containing the formats that can be provided by the current data in clipboard. Secondly, Count set to the number of those formats.  An application will typically call this function to see if any formats are available, a Count=Zero will be taken as meaning Clipboard is empty. If it gets a non zero Count, then it will try for its preferred format (ie Rich Text or html etc) and failing that, will use the plain text.

I have confirmed this is what it does under Linux and Carbon.

However, on Cocoa, ClipboardGetFormats() returns with the Count unchanged and the array either empty or, depending on the value of Count passed to it, a list of up to four image formats that do not represent the data available. If called via TClipboard.GetFormatCount for example, ClipboardGetFormats() will cause an application to believe there is nothing in the clipboard.

And of course, it does not paste.

A lazy application that does not look for a special format, just grabs whatever text is there, ironically will work OK !
Title: Re: Cocoa not reporting clipboard contents correctly
Post by: MISV on August 05, 2018, 05:40:54 pm
Have you reported the issue in bug tracker? Usually issues seem to get fixed quickly
Title: Re: Cocoa not reporting clipboard contents correctly
Post by: dbannon on August 11, 2018, 03:14:55 pm
No, I have not reported this issue in bug  tracker. My experience is that bug reports without attached patches dont get a lot of attention.

So, my plan, when time permits, was to try and find a bit more about whats missing.

But maybe you are right, my time not looking good right now ....

Davo
Title: Re: Cocoa not reporting clipboard contents correctly
Post by: MISV on August 11, 2018, 04:02:37 pm
I have issues fixed just I can create a demo. And under all circumstances, logging an error allows other to pitch in. At least that is my philosophy :)
Title: Re: Cocoa not reporting clipboard contents correctly
Post by: dbannon on August 12, 2018, 06:15:09 am
MISV, you are right of course !
I have logged https://bugs.freepascal.org/view.php?id=34121

(and noted a couple of other things I have logged have been fixed. Great !)

Davo
Title: Re: Cocoa not reporting clipboard contents correctly
Post by: dbannon on August 18, 2018, 01:43:02 pm
And 34121 has been fixed !
How good is thats ?
Davo