Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-08

TTrayIcon on Cocoa

17 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Tobias Giesen

Hello,

I've installed the Cocoa package and recompiled the LCL with the CarbonUseCocoa compiler define, and now the TrayIcon appears nicely in the status bar. But I can't click it and it doesn't show any menu.

I'm trying the latest snapshot on Leopard.

Any ideas?

Cheers,
Tobias

Reply by email

Tobias Giesen
to dmitry boyarintsev

Hello,

starting the program from terminal gives nothing as debug output except for the usual SetKeyboardFocus messages.

In Felipe's implementation, the scarcely documented function NSLoadApplication is used which is supposed to set up event handlers. However, I believe that it won't do anything because it does not find any Cocoa stuff in the bundle. So maybe we just need to add some resources to the bundle or edit the plist file?

Felipe, did the menu work for you?

Cheers,
Tobias

Reply by email

Tobias Giesen
to dmitry boyarintsev
NSLoadApplication must be called from Carbon application using Cocoa, no matter what stuff is placed in Bundle.

Great. Still the icon does not respond to clicks.

I tried my own adaptation of the StatusItem, bypassing the LCL. This works fine as long as I use NSApp.run instead of Application.Run. The icon responds to clicks and shows its menu just fine, except for when a modal dialog is shown. I assume that Felipe's solution has the same problem? Can the modal dialog event loop be extended somehow so that it doesn't block Cocoa events?

I think I'm looking for something like NSApp.processevents but this doesn't exist.

Cheers,
Tobias

Reply by email

Tobias Giesen
to dmitry boyarintsev
> Great. Still the icon does not respond to clicks. Are using some kind of mix of Cocoa and Carbon widgetset?

No, I made a totally clean installation of the latest snapshot and created a new minimal test application for this purpose. If you like I can send you the test application. Or does anybody have a working demo of this?

Cheers,
Tobias

Reply by email

dmitry boyarintsev
to Tobias Giesen
No, I made a totally clean installation of the latest snapshot and created a new minimal test application for this purpose. If you like I can send you the test application. Or does anybody have a working demo of this?

I'm wondering what are you trying to achieve.

Even if you make Cocoa-widgetset application to make a create a tray icon, you won't be able to create a proper application with it, because Cocoa widgetset is incomplete.

Or do you want to use TrayIcon with Carbon application?

thanks,
dmitry

Reply by email

Tobias Giesen
to dmitry boyarintsev

Hi Dmitry,

I am sorry I didn't describe the case properly. I mistyped the subject.

I am building a Carbon application and I am trying to get the TrayIcon with menu to work, that's all.

It shows up but does not respond to clicks and does not show the menu. I wonder when did anybody use or test this the last time?

Cheers,
Tobias

Reply by email

Felipe Monteiro de Carvalho
to Tobias Giesen: starting the program from terminal gives nothing as debug output except for the usual…
Tobias Giesen wrote
Felipe, did the menu work for you?

Yes, it did work. Maybe something changed in the mean time in the Carbon interface and broke it.

to dmitry: Maybe we could add PasCocoa to Lazarus until a stable FPC is released with native Cocoa support, what do you think? PasCocoa wont be changing much now because the new native FPC support for objective-c is under development. On the other hand this development may take many years to come in a stable release and when it comes out we can delete PasCocoa from lazarus

Felipe Monteiro de Carvalho

Reply by email

dmitry boyarintsev
to Felipe Monteiro de Carvalho
Show quoted text 5 lines
to dmitry: Maybe we could add PasCocoa to Lazarus until a stable FPC is released with native Cocoa support, what do you think? On the other hand this development may take many years to come in a stable release and when it comes out we can delete PasCocoa from lazarus

I'll make an article in the wiki on "How to make PasCocoa work with Carbon".

Currently FPC support is already quite advanced. There only 1 major features left unimplemented: deriving own classes. I think we'll be able to restart Cocoa widgetset with the compiler support before the end of the year.

thanks,
dmitry

Reply by email

Felipe Monteiro de Carvalho
to dmitry boyarintsev
dmitry boyarintsev wrote
Currently FPC support is already quite advanced.

Lazarus development has always been based in stable compilers and all releases are made with stable compilers. You can't base development on an unstable compiler which isn't even in trunk, but on a separate experimental branch.

Historically the solution for needing something from unstable compilers was copying the needed files or, if you need features, just wait for it.

Felipe Monteiro de Carvalho

Reply by email

dmitry boyarintsev
to Felipe Monteiro de Carvalho
You can't base development on an unstable compiler which isn't even in trunk, but on a separate experimental branch.

If you put things in that way, then I can agree with you. Including PasCocoa to Lazarus, would make a lot of things easier. But how should it be added? As part of Cocoa widgetset?

thanks,
dmitry

Reply by email

dmitry boyarintsev
to Tobias Giesen: I am sorry I didn't describe the case properly. I mistyped the subject. I am building a…

Hello Tobias

please read this article:

http://wiki.lazarus.freepascal.org/Carbon_Interface#Cocoa_controls_in_Carbon_applications

If you mange to do this steps successfully and you have Carbon LCL recompiled with Cocoa support, then you can use TTrayIcon component.

One more note. If you mark TTrayIcon.Visible = True in Object Inspector, this will show the icon, but sub-menu won't appear (for some reason).
To fix this, you need to change TTrayIcon visibility in run-time, for example in FormCreate event:

procedure TForm1.FormCreate(Sender: TObject);
begin
  TrayIcon1.Visible:=true;
end;

this will make both: Tray icon visible in OSX Status Bar, and sub menu working.

thanks,
dmitry

Reply by email

Tobias Giesen
to dmitry boyarintsev: Hello Tobias please read this article: http://wiki.lazarus.freepascal.org/Carbon_Interface…
If you mark TTrayIcon.Visible = True in Object Inspector, this will show the icon, but sub-menu won't appear (for some reason). To fix this, you need to change TTrayIcon visibility in run-time

Wow, that was it! I can confirm that it's working perfectly! Even while a modal dialog is shown. Very good. This means a lot to me. Thanks so much for your help and to Felipe for this implementation!

Cheers,
Tobias

Reply by email

dmitry boyarintsev
to Felipe Monteiro de Carvalho: In a directory above Cocoa directory. Then we would need to alter the Makefiles in both…
In a directory above Cocoa directory. Then we would need to alter the Makefiles in both Carbon and Cocoa interfaces to see them ... I always have trouble with these makefiles.

needs to be discussed in lazarus-dev

Do you think we should keep the define? I mean, is it a problem to have all Carbon software depend on Cocoa too?

imho, defines should be removed long time ago.
We won't make Carbon 100% LCL compatible without using Cocoa anyway.

thanks,
dmitry

Reply by email