User interface considerations for macOS

Cocoa is the current user interface framework supported by Macs. If you are moving an older project from Carbon (an older Mac UI framework) to Xojo, your existing applications should just work for the most part, but there are some differences to consider.

General UI differences

  • Resizable windows can be resized from any window edge.

  • Spellchecking and grammar checking are now available in TextField and TextArea controls by setting AutomaticallyCheckSpelling property to ON in the Inspector.

  • Buttons have a ButtonStyle property than can be used to change the look of the button.

  • Windows in your apps can be dragged around the screen while code is running.

  • Timers, threads and sockets continue to get events when menus or OS modal dialog boxes are displayed.

  • StyledText draws much faster.

Graphics

All drawing using a Canvas must be done from the Paint event or a method called from it. If you have older projects that use the Graphics property of a Canvas directly, you will have to update them to use the Graphics object from the DesktopCanvas event instead.

All drawing now takes place in a generic colorspace that is independent of the current output device. This means that colors will render more similarly between screens and printers.

Threads

You cannot have any code that is in a thread that modifies anything related to the user interface (which runs on what is called the main thread). If your app does this it will raise a ThreadAccessingUIException exception. If your user interface needs to be updated based on information in a thread, you should instead have the UI request the information from the thread.

One way to do this is to use the Thread method that allows you to periodically updates the UI based on information passed to it.

Font display

Mac apps can only display font styles that are available. You cannot force a font to display in bold or italic if it does not have bold or italic variations available. In this situation, the Bold or Italic properties will not affect the font.

To check if the font you wish to use has the variation you need, use the system Font Book app in the Applications folder.

Prior to 2018r4, displaying of digits used a non-proportional font even though the system font was always proportional. Apple changed this behavior starting with the macOS 10.11 SDK, which Xojo started using in 2018r4. So if you require a non-proportional font for displaying digits you will need to change your font accordingly.

Keyboard handling

Unhandled KeyDown event handlers cause a Beep instead of behaving silently. This is intentional and gives the user feedback that their action did not do anything. To eliminate the Beep, Return True from the KeyDown event handler.

Additionally, the KeyDown event handler literally means “a key was pressed” and does not attempt to interpret the key event for dead key sequences or input methods. For example, pressing Option+E and then E again results in two key presses sent to KeyDown, not a single key press with the value “é”.

Unsupported items

These older Mac features are no longer supported:

  • Drawer windows

  • ResourceFork class

  • Cursors stored in the resource fork

  • TextArea.Save method (use DesktopTextArea and RTFData instead)