Difference between revisions of "Cocoa Interface"
Line 17: | Line 17: | ||
===macOS 10.10 and earlier=== | ===macOS 10.10 and earlier=== | ||
The precompiled CocoaAll header | The precompiled CocoaAll header | ||
+ | make rtl | ||
+ | make pacakges | ||
+ | for version prior to 10.8 (see the note below | ||
+ | make rtl OPT="-Aas-darwin -WM10.4" | ||
+ | make packages OPT="-Aas-darwin -WM10.4" | ||
===macOS 10.7 and earlier=== | ===macOS 10.7 and earlier=== |
Revision as of 06:32, 21 June 2020
│
English (en) │
This article applies to macOS only.
See also: Multiplatform Programming Guide
Other Interfaces
- Lazarus known issues (things that will never be fixed) - A list of interface compatibility issues
- Win32/64 Interface - The Windows API (formerly Win32 API) interface for Windows 95/98/Me/2000/XP/Vista/10, but not CE
- Windows CE Interface - For Pocket PC and Smartphones
- Carbon Interface - The Carbon 32 bit interface for macOS (deprecated; removed from macOS 10.15)
- Cocoa Interface - The Cocoa 64 bit interface for macOS
- Qt Interface - The Qt4 interface for Unixes, macOS, Windows, and Linux-based PDAs
- Qt5 Interface - The Qt5 interface for Unixes, macOS, Windows, and Linux-based PDAs
- GTK1 Interface - The gtk1 interface for Unixes, macOS (X11), Windows
- GTK2 Interface - The gtk2 interface for Unixes, macOS (X11), Windows
- GTK3 Interface - The gtk3 interface for Unixes, macOS (X11), Windows
- fpGUI Interface - Based on the fpGUI library, which is a cross-platform toolkit completely written in Object Pascal
- Custom Drawn Interface - A cross-platform LCL backend written completely in Object Pascal inside Lazarus. The Lazarus interface to Android.
Platform specific Tips
- Android Programming - For Android smartphones and tablets
- iPhone/iPod development - About using Objective Pascal to develop iOS applications
- FreeBSD Programming Tips - FreeBSD programming tips
- Linux Programming Tips - How to execute particular programming tasks in Linux
- macOS Programming Tips - Lazarus tips, useful tools, Unix commands, and more...
- WinCE Programming Tips - Using the telephone API, sending SMSes, and more...
- Windows Programming Tips - Desktop Windows programming tips
Interface Development Articles
- Carbon interface internals - If you want to help improving the Carbon interface
- Windows CE Development Notes - For Pocket PC and Smartphones
- Adding a new interface - How to add a new widget set interface
- LCL Defines - Choosing the right options to recompile LCL
- LCL Internals - Some info about the inner workings of the LCL
- Cocoa Internals - Some info about the inner workings of the Cocoa widgetset
Cocoa bindings
The Cocoa interface uses the native support in Free Pascal for direct communication with Objective-C which was added through the Objective Pascal dialect.
Compiling
Use FPC 3.0.4a
For macOS 10.14 Mojave and later you should be installing FPC 3.0.4a available at the official site.
FPC 3.2.0 for older macOS
It's likely you will not encounter ANY problems using FPC 3.2.0 on macOS 10.11 and later.
macOS 10.10 and earlier
The precompiled CocoaAll header
make rtl make pacakges
for version prior to 10.8 (see the note below
make rtl OPT="-Aas-darwin -WM10.4" make packages OPT="-Aas-darwin -WM10.4"
macOS 10.7 and earlier
If after updating to FPC 3.2. update, you're getting following error during compilation:
Error: Assembler clang not found, switching to external assembling
You need to add the following options to the compilation
-Aas-darwin -MW10.4
(where -MW10.x can match your hosting system. It doesn't have to be 10.4)
However, if you don't want to each of your project compilation settings, you can simply update /etc/fpc.cfg file, by adding the following lines to the beginning of the configuration file
## this is new for FPC 3.2.0 ## it's default target changed to macOS 10.8 ## thus clang is used by default and some extra CRT is used -Aas-darwin ## the actual -WM version might vary -WM10.4
Considerations:
- editing /etc/fpc.cfg requires admin privileges.
- if you're not using default /etc/fpc.cfg you might want to edit the configuration file your compiler relies on
Prepare your Lazarus project for using Cocoa
You may need to set the Target to the 64bit processor and select the Cocoa Widget set:
- Open your project with Lazarus and click Project/Project Options
- In the "Config and Target" panel set the "Target CPU family" to be "x86_64"
- In the "Additions and Overrides" panel click on "Set LCLWidgetType" pulldown and set the value to "Cocoa"
- In the past, for some reason Lazarus kept setting the compiler to "/usr/local/bin/ppc386" - which results in 32 bit apps. Make sure under Tools->Options that "Compiler Executable" is set to "/usr/local/bin/fpc" to get 64 bit apps.
- Now compile your project - with any luck it will work OK.
Error ATSUFindFontFromName
If you're getting the error:
carbonproc.pp(563,13) Error: Identifier not found "ATSUFindFontFromName"
when compiling a project for macOS using FPC 3.0.4, you either:
- set the CPU target explicitly to i386. (FPC 3.0.4 compiles to x86_64 for the Darwin target by default. This is done due Apple having dropped support for 32-bit target in macOS 10.15 Catalina released in October 2019.)
- by setting the target in Project options (switching it from default to i386)
- by setting the CPU_TARGET=i386 parameter for the make command if compiling from the command line.
- or set the LCL target (widgetset) to "Cocoa".
Cocoa Debugging
See the Cocoa Debugging article.
Cocoa FAQ
DPI and scaling issues
See the Cocoa DPI article.
TButton looks too small!
If you design a button in another widgetset with Autosize=False it might happen that the button looks too small in Cocoa, and a number of people have complained about this, such as in this bug report.
If you don't care about the button size, just set AutoSize=True. If you want to have a custom width for the button, but want to allow the LCL to choose the right Height so that the button will look good in Cocoa, then the solution in this case is to set the following properties in the Object Inspector:
- AutoSize=True
- Constrains.MinWidth = Constrains.MaxWidth = your desired width.
Overlapping Widgets
Lazarus allows you to set the depth of different widgets, such that when two widgets overlap, the "closer" object blocks the view of the more "distant" object. You can do this at design time (right-click on object and click "Z-order") or at run time with functions like "BringToFront" and "SendToBack". Be aware that this may not always work with Cocoa. This is a 'feature' of Cocoa, as clipping is optimized for performance. Therefore, if you plan to compile your projects for Cocoa it is a good strategy to avoid overlapping widgets or to place them on different panels to provide explicit control of Z-order. For more details see this bug report.