Lazarus

Programming => Widgetset => Cocoa => Topic started by: Clemens on June 05, 2016, 01:18:39 pm

Title: How to get the usual menu items in the first menu
Post by: Clemens on June 05, 2016, 01:18:39 pm
Hi!

Another question.  On OS X, the second menu (next to the Apple menu) always has the name of the program and contains items such as "About", "Services", "Hide" etc., "Quit".

When I add a TMainMenu, the name of the first menu is overwritten by the program name (good), but I don't get the usual menu items.  How can I get the "Hide" etc. items?

Cheers,
Clemens
Title: Re: How to get the usual menu items in the first menu
Post by: Phil on June 05, 2016, 04:47:14 pm
https://dl.dropboxusercontent.com/u/28343282/MacXPlatform/MacXPlatform_Part8.html

Title: Re: How to get the usual menu items in the first menu
Post by: Clemens on June 06, 2016, 03:46:34 pm
Great, thanks!  :)  Looks very useful, I am working through it.

By the way, how can I implement "Hide" and "Hide others"?  Is there a library function to call?

Cheers,
Clemens
Title: Re: How to get the usual menu items in the first menu
Post by: Phil on June 07, 2016, 12:31:16 am
The app menu's Hide AppName and Hide Others should already be present. See Lazarus IDE.

Title: Re: How to get the usual menu items in the first menu
Post by: Clemens on June 07, 2016, 11:14:31 am
I see.  I am using Cocoa, probably that's why I don't have the "Hide *" items.

Yes, in Lazarus the app menu looks very OS X like.
Title: Re: How to get the usual menu items in the first menu
Post by: Phil on June 07, 2016, 03:15:02 pm
Lazarus uses the Carbon widgetset. If you're using the Cocoa widgetset, the last time I checked there were quite a few things that did not work there, this is probably just one more.

Title: Re: How to get the usual menu items in the first menu
Post by: Clemens on June 07, 2016, 04:28:20 pm
Ok.  I may have to go with the Cocoa widget set because of a 64bit library I may have to use.

I guess the best way forward is to file bug reports for the Cocoa widget set.
Title: Re: How to get the usual menu items in the first menu
Post by: Phil on June 07, 2016, 04:32:06 pm
Yes, it's worth at least logging a bug report. Things posted here will not get attended to.

Note that 32-bit libraries work fine on OS X too. You can easily create "fat" .dylib files containing both 32- and 64-bit libraries. OS X system libs are all like this, as are most commercial libs.

-Phil


Title: Re: How to get the usual menu items in the first menu
Post by: Clemens on June 07, 2016, 04:52:23 pm
Ok.  I'll try to file bug reports when I have time.  It would be great to have full Cocoa support.

Thanks for your hint about the library.  I may well have been doing something wrong.  I built the stock HDF5 library and got a libhdf5.a, which I can only link with the 64bit FPC, not with the 32bit FPC.  This is what I get when I use the 32bit compiler:

Code: Pascal  [Select][+][-]
  1. ld: warning: ignoring file libhdf5.a, file was built for archive which is not the architecture being linked (i386): libhdf5.a
  2. Undefined symbols for architecture i386:
  3.   "_H5close", referenced from:
  4.       _FINALIZE$_$HDF5 in hdf5.o
  5.   "_H5garbage_collect", referenced from:
  6.       _PASCALMAIN in Reconstructor.o
  7.   "_H5open", referenced from:
  8.       _INIT$_$HDF5 in hdf5.o
  9. ld: symbol(s) not found for architecture i386
  10. An error occurred while linking
Title: Re: How to get the usual menu items in the first menu
Post by: Phil on June 07, 2016, 04:55:37 pm
Right, you built libhdf5.a for 64-bit only. Try building it for both if that's an option (don't know what hdf5 is).

For any .o, .a, .dylib, etc. use the file command to see what archs it contains.

Title: Re: How to get the usual menu items in the first menu
Post by: Clemens on June 07, 2016, 05:12:36 pm
They are indeed 64bit:

Code: Pascal  [Select][+][-]
  1. libhdf5.100.dylib: Mach-O 64-bit dynamically linked shared library x86_64
  2. libhdf5.a:         current ar archive random library
  3. libhdf5.dylib:     Mach-O 64-bit dynamically linked shared library x86_64
  4. libhdf5.la:        libtool library file
  5. libhdf5.lai:       libtool library file

I learnt about `lipo' (not what I need, but nice), still have to figure out how to compile the library with 32 bits.
Title: Re: How to get the usual menu items in the first menu
Post by: Phil on June 07, 2016, 06:24:47 pm
If that's a C library, then you probably used something like configure to prep for the make. If so, see if there's an arch switch, eg,

CFLAGS="-arch i386 -arch x86_64"

Title: Re: How to get the usual menu items in the first menu
Post by: Clemens on June 07, 2016, 08:25:33 pm
Great, thanks! This is the flag I have been looking for.  :)

I could indeed build the library with
./configure CFLAGS="-arch i386"

Unfortunately, when I link to the new i386 libhdf5.a, I get these undefined symbols:
___divdi3, ___udivdi3, ___umoddi3.

Scary, three underscores, never seen anything like this...  8-)

Funnily enough, I can link to i386 libhdf5.dylib, but then the binary doesn't work unless I patch the dylib path with install_name_tool. Still impractical.

So if I go the i386 arch route: I can't link a dylib to my program statically, can I?
Title: Re: How to get the usual menu items in the first menu
Post by: Phil on June 07, 2016, 08:43:27 pm
A search of the Web reveals similar problems. This might help you:

http://embdev.net/topic/129575


Use of install_name_tool is routine enough. I certainly would not let that stop me from using a .dylib in the app bundle. For example, see the last step here that fixes up the executable and the .dylib in Xcode:

https://dl.dropboxusercontent.com/u/28343282/MacXPlatform/PascalDynLibs_3.html#WebMaps

Title: Re: How to get the usual menu items in the first menu
Post by: Clemens on June 08, 2016, 06:18:09 pm
Great, thanks.

I cannot get the triple underscore symbols to work.  Never mind.  Generally I seem to have less success with *.a libraries than with dylibs.

Thanks for the install_name_root -change hint: works nicely.
Title: Re: How to get the usual menu items in the first menu
Post by: Phil on June 08, 2016, 09:53:17 pm
Distributing a .dylib as part of your .app bundle is not too big a deal since the bundle already consists of more files than just the executable. Look inside the .app bundles of apps installed under /Applications to see the variety of libraries included.

For example, Microsoft's excellent Remote Desktop app (free from Apple Mac App Store) includes the Qt .dylibs, as well as the SSL .dylib. Qt typically won't be installed on a user's Mac. The SSL .dylib should be, but by including their own it means they can ensure the app uses an up-to-date version.

You can also make a framework for a .dylib. Typically this is for very large libraries that might need to be used by multiple apps, or if the libraries already have a nice .dmg installer that you (and users) can use. See /Library/Frameworks for examples of what you have installed. Note that frameworks can be versioned, meaning you can install more than one version of a framework library into the same .framework bundle (ensuring that apps that use the old version are unaffected).

The old-fashioned way of putting the .dylib into /usr/lib is also supported, but I would not take that approach. It's really more of a holdover from an previous era.

Is this what you're using?

http://www.hdfgroup.org/HDF5/

If so, what sort of programs use that? I'm completely unfamiliar with it.

-Phil
Title: Re: How to get the usual menu items in the first menu
Post by: Clemens on June 09, 2016, 11:32:46 am
Got it. I still think that statically linking the library to my binary would be more straightforward and platform independent, but copying the dylib into the app bundle is no big deal. I wrote a post-build script to do that. I'll see how it works out on Windows and Linux.
TinyPortal © 2005-2018