CopperSpice Overview
Mac OS X Development

Development

Software application development on Mac OS X uses Xcode, which is an IDE that provides interfaces to compilers for programming languages like C, C++, and Objective-C. Xcode is distributed in the App Store as a stand alone application. After installing Xcode the clang compiler will be available.

  • On Mac OS X 10.14 the version of Xcode should be 11.3.1

For more information and to download the current version of Xcode, refer to the following Xcode

Global Menu Bar

Mac users expect to have a menu bar at the top of the screen. A CopperSpice application accomplishes this using a QMenuBar.

Users also expect certain Mac OS X conventions to be respected. For example, the application menu should be shown to the right of the Apple menu. Some of the items in the application menu are About, Preferences, Quit, etc. CopperSpice creates the application menu automatically, although there is no way to interact directly with the this menu.

Menu Bar

CopperSpice will automatically detect your menu bars and turn them into Mac native menu bars. Fitting this into your existing application will normally be automatic. CopperSpice selects a menu bar by starting at the active window and applying the following tests:

  • If the window has a QMenuBar, then it is used as the active menu.
  • If the window is modal, then its menu bar is used. If no menu bar is specified, then a default menu bar is used.
  • If the window has no parent, then the default menu bar is used.

These tests are followed all the way up the parent window chain until one of the above rules is satisfied. If all else fails, a default menu bar will be created. The default menu bar is an empty menu bar.

You can create a different default menu bar by creating a parentless QMenuBar. The first one created will be designated the default menu bar and will be used whenever a default menu bar is needed.

Menu Actions

Actions in a QMenu with accelerators that have more than one keystroke (QKeySequence) will not display correctly. Only the first key will be displayed however, the shortcut will still be available.

QMenu objects used in the native menu bar are not able to handle events via the normal event handlers. For Cocoa, you will have to install a delegate on the menu itself to be notified of these changes. Alternatively, consider using the QMenu::aboutToShow() and QMenu::aboutToHide() signals to keep track of menu visibility. These provide a solution that should work on all platforms.

In order to modify which menu items are moved to the Application Menu, refer to the enums for QAction::MenuRole()

Right-Mouse Clicks

If you want to provide right mouse click support for Mac OS X, use the QContextMenuEvent class. This will map to a context menu event that will display a pop up selection. This is the most common use of right mouse clicks, and maps to a control click with the Mac OS X one-button mouse support.

Special Keys

To provide the expected behavior for applications on Mac OS X, the Qt::Meta, Qt::MetaModifier, and Qt::META enum values correspond to the Control keys on the standard Macintosh keyboard. The Qt::Control, Qt::ControlModifier, and Qt::CTRL enum values correspond to the Command keys.

Translations

The items in the Application Menu will be merged correctly for your localized application, however they will not show up translated until you add a localized resource folder to the application bundle. You will need to create a file called locversion.plist.

Here is an example for Norwegian. The value for LprojLocale is "no". For English this value would be "en", for French it would be "fr", etc.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LprojCompatibleVersion</key>
<string>123</string>
<key>LprojLocale</key>
<string>no</string>
<key>LprojRevisionLevel</key>
<string>1</string>
<key>LprojVersion</key>
<string>123</string>
</dict>
</plist>

For additional information refer to Bundle Programming Guide

Dock

Interaction with the dock is possible. A dock icon can be set by calling QWidget::setWindowIcon() on the main window in your application. The setWindowIcon() call can be made as often as necessary, providing an icon that can be easily updated.