Introduction to platform-sensitive development: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Introduction to platform-sensitive development
| Old | New | Line | |
|---|---|---|---|
| 1 | + | <figure> | |
| 2 | + | <img src="platform-independent_vs._platform-sensitive_applications.png" title="Comparison of platform-independent with platform-sensitive applications on Mac Leopard. All shown applications are platform-independent, but only the programs in the right half of the screen are platform-sensitive. Note that the platform-insensitive X Window programs in the left half of the screen have an alien look. They tend to confuse the users with atypical behaviour and ambiguous elements like a double menu bar." width="300" /> | |
| 3 | + | <figcaption>Comparison of platform-independent with platform-sensitive applications on Mac Leopard. All shown applications are platform-independent, but only the programs in the right half of the screen are platform-sensitive. Note that the platform-insensitive X Window programs in the left half of the screen have an alien look. They tend to confuse the users with atypical behaviour and ambiguous elements like a double menu bar.</figcaption> | |
| 4 | + | </figure> | |
| 5 | + | ||
| 6 | + | **Platform-sensitive development** is the next step in [[Multiplatform Programming Guide|cross-platform development]]. It extends the process of porting an application by implementing platform-specific functions and user-interface style guides. | |
| 7 | + | ||
| 8 | + | Thanks to the "[[Write once compile anywhere|Write Once - Compile Anywhere]]" principle of Lazarus and Free Pascal it is very easy to develop a program that runs out of the box on multiple platforms. To make a finished application that adheres to the respective GUI style guidelines (and even the requirements of app stores) warrants additional steps, however. | |
| 9 | + | ||
| 10 | + | Platform-sensitive development is more than adherence to user-interface style guides. It also addresses aspects that are as different as memory management, file handling and interprocess communication. | |
| 11 | + | ||
| 12 | + | This article provides the reader with essential information and hints for platform-sensitive development. | |
| 13 | + | ||
| 14 | + | ## Prelude | |
| 15 | + | ||
| 16 | + | *(Platform-sensitive development only)* | |
| 17 | + | ||
| 18 | + | Most adaptations for specific target platforms are performed automatically by the [[LCL]], [[FCL]], [[RTL]] and the respective [[Widgetset|widgetsets]]. Often, only minor modifications are needed to create a finished application. Using conditional compilation by means of [compiler directives](/wiki-category/Compiler%20directives) helps to keep your code portable. | |
| 19 | + | ||
| 20 | + | The following example demonstrates this technique. The procedure `AdaptMenus` adjusts the display of the menu bar according to the target platform. This is necessary as the positions of the "About" and "Preferences" items are in different locations in macOS than they are in Windows, Linux or FreeBSD. Additionally, the menu shortcuts are invoked by the command key on macOS (in the LCL referred to as Meta key), while they are triggered with the control key on most other operating systems. | |
| 21 | + | ||
| 22 | + | The main menu of the form contains some platform-specific items, `WinAboutItem` (it opens an info box) and `WinPreferencesItem` (for program settings). They are intended for use on non-macOS operating systems. On the other side, it contains an Apple Menu for macOS. Depending from the target platform, the code hides unneeded entries (and corresponding dividers) and shows those that are expected by the users of the respective platform. | |
| 23 | + | ||
| 24 | + | ``` pascal | |
| 25 | + | uses | |
| 26 | + | LCLType; | |
| 27 | + | ||
| 28 | + | procedure AdaptMenus; | |
| 29 | + | { Adapts Menus and Shortcuts to the interface style guidelines | |
| 30 | + | of the respective operating system } | |
| 31 | + | var | |
| 32 | + | modifierKey: TShiftState; | |
| 33 | + | begin | |
| 34 | + | {$IFDEF Darwin} | |
| 35 | + | MainForm.WinAboutItem.Visible := False; | |
| 36 | + | MainForm.Divider_5_1.Visible := False; | |
| 37 | + | MainForm.Divider_2_2.Visible := False; | |
| 38 | + | MainForm.WinPreferencesItem.Visible := False; | |
| 39 | + | MainForm.AppleMenu.Visible := True; | |
| 40 | + | {$ELSE} | |
| 41 | + | MainForm.WinAboutItem.Visible := True; | |
| 42 | + | MainForm.Divider_5_1.Visible := True; | |
| 43 | + | MainForm.Divider_2_2.Visible := True; | |
| 44 | + | MainForm.WinPreferencesItem.Visible := True; | |
| 45 | + | MainForm.AppleMenu.Visible := False; | |
| 46 | + | {$ENDIF} | |
| 47 | + | MainForm.NewMenuItem.ShortCut := ShortCut(VK_N, ssModifier); //ssModifier equals ssMeta on Mac, ssCtrl on other platforms | |
| 48 | + | MainForm.OpenMenuItem.ShortCut := ShortCut(VK_O, ssModifier); | |
| 49 | + | MainForm.CloseMenuItem.ShortCut := ShortCut(VK_W, ssModifier); | |
| 50 | + | MainForm.SaveItem.ShortCut := ShortCut(VK_S, ssModifier); | |
| 51 | + | MainForm.PrintItem.ShortCut := ShortCut(VK_P, ssModifier); | |
| 52 | + | MainForm.QuitMenuItem.ShortCut := ShortCut(VK_Q, ssModifier); | |
| 53 | + | MainForm.UndoMenuItem.ShortCut := ShortCut(VK_Z, ssModifier); | |
| 54 | + | MainForm.CutMenuItem.ShortCut := ShortCut(VK_X, ssModifier); | |
| 55 | + | MainForm.CopyMenuItem.ShortCut := ShortCut(VK_C, ssModifier); | |
| 56 | + | MainForm.PasteMenuItem.ShortCut := ShortCut(VK_V, ssModifier); | |
| 57 | + | MainForm.SelectAllMenuItem.ShortCut := ShortCut(VK_A, ssModifier); | |
| 58 | + | end; | |
| 59 | + | ``` | |
| 60 | + | ||
| 61 | + | In older Lazarus versions (before 1.0) ssModifier is not supported. The following code is compatible with Lazarus 0.9.x, albeit more complex than the example above: | |
| 62 | + | ||
| 63 | + | ``` pascal | |
| 64 | + | uses | |
| 65 | + | LCLType; | |
| 66 | + | ||
| 67 | + | procedure AdaptMenus; | |
| 68 | + | { Adapts Menus and Shortcuts to the interface style guidelines | |
| 69 | + | of the respective operating system } | |
| 70 | + | var | |
| 71 | + | modifierKey: TShiftState; | |
| 72 | + | begin | |
| 73 | + | {$IFDEF LCLcarbon} | |
| 74 | + | modifierKey := [ssMeta]; | |
| 75 | + | MainForm.WinAboutItem.Visible := False; | |
| 76 | + | MainForm.Divider_5_1.Visible := False; | |
| 77 | + | MainForm.Divider_2_2.Visible := False; | |
| 78 | + | MainForm.WinPreferencesItem.Visible := False; | |
| 79 | + | MainForm.AppleMenu.Visible := True; | |
| 80 | + | {$ELSE} | |
| 81 | + | modifierKey := [ssCtrl]; | |
| 82 | + | MainForm.WinAboutItem.Visible := True; | |
| 83 | + | MainForm.Divider_5_1.Visible := True; | |
| 84 | + | MainForm.Divider_2_2.Visible := True; | |
| 85 | + | MainForm.WinPreferencesItem.Visible := True; | |
| 86 | + | MainForm.AppleMenu.Visible := False; | |
| 87 | + | {$ENDIF} | |
| 88 | + | MainForm.NewMenuItem.ShortCut := ShortCut(VK_N, modifierKey); | |
| 89 | + | MainForm.OpenMenuItem.ShortCut := ShortCut(VK_O, modifierKey); | |
| 90 | + | MainForm.CloseMenuItem.ShortCut := ShortCut(VK_W, modifierKey); | |
| 91 | + | MainForm.SaveItem.ShortCut := ShortCut(VK_S, modifierKey); | |
| 92 | + | MainForm.PrintItem.ShortCut := ShortCut(VK_P, modifierKey); | |
| 93 | + | MainForm.QuitMenuItem.ShortCut := ShortCut(VK_Q, modifierKey); | |
| 94 | + | MainForm.UndoMenuItem.ShortCut := ShortCut(VK_Z, modifierKey); | |
| 95 | + | MainForm.CutMenuItem.ShortCut := ShortCut(VK_X, modifierKey); | |
| 96 | + | MainForm.CopyMenuItem.ShortCut := ShortCut(VK_C, modifierKey); | |
| 97 | + | MainForm.PasteMenuItem.ShortCut := ShortCut(VK_V, modifierKey); | |
| 98 | + | MainForm.SelectAllMenuItem.ShortCut := ShortCut(VK_A, modifierKey); | |
| 99 | + | end; | |
| 100 | + | ``` | |
| 101 | + | ||
| 102 | + | > **Note:** To see if LCL functionality is supported on your target widgetset, you can use the Restriction Browser (menu View/Restriction Browser) | |
| 103 | + | ||
| 104 | + | ## Platform-specific hints | |
| 105 | + | ||
| 106 | + | ### Android | |
| 107 | + | ||
| 108 | + | Android is an atypical Linux variant, therefore many considerations for usual Linux distributions do not apply. Furthermore, development for Android is faced by the challenge that the software landscape is fragmented in a large field of different system versions and by a considerable heterogeneity of hardware among supported devices. | |
| 109 | + | ||
| 110 | + | #### See also | |
| 111 | + | ||
| 112 | + | - [[Android Interface/Native Android GUI]] | |
| 113 | + | - [[Portal:Android|Android Portal]] | |
| 114 | + | ||
| 115 | + | #### External Links | |
| 116 | + | ||
| 117 | + | - [Android Design](http://developer.android.com/design/index.html) | |
| 118 | + | - [Android User Interface Guidelines](http://developer.android.com/guide/practices/ui_guidelines/index.html) | |
| 119 | + | ||
| 120 | + | ### FreeBSD | |
| 121 | + | ||
| 122 | + | [FreeBSD](https://www.freebsd.org) is an operating system for a variety of platforms which focuses on features, speed, and stability. It is derived from BSD, the version of UNIX® developed at the University of California, Berkeley. It is developed and maintained by a large community. It is used to power modern servers, desktops, and embedded platforms. A large community has continually developed it for more than thirty years. Its advanced networking, security, and storage features have made FreeBSD the platform of choice for many of the busiest web sites and most pervasive embedded networking and storage devices. | |
| 123 | + | ||
| 124 | + | #### See also | |
| 125 | + | ||
| 126 | + | - [[Portal:FreeBSD|FreeBSD Portal]] for comprehensive lists of links for development techniques, programming hints and tips for creating FreeBSD programs. | |
| 127 | + | ||
| 128 | + | #### External links | |
| 129 | + | ||
| 130 | + | - [FreeBSD: Developers' Handbook](https://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/). | |
| 131 | + | - [FreeBSD: Porters Handbook](https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/). | |
| 132 | + | - [FreeBSD: Handbook](https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/). | |
| 133 | + | ||
| 134 | + | ### iOS | |
| 135 | + | ||
| 136 | + | iOS is a pruned variant of macOS for mobile devices. Recent additions to the Lazarus evironment help to develop applications with [[Free Pascal]] for iOS now. The development for iOS differs in some sense from that for other platforms, however thanks to the [[iOS Designer]] it is possible to graphically design the GUI. For submission to Apple's App Store it is mandatory to implement the iOS Human Interface Guidelines. | |
| 137 | + | ||
| 138 | + | #### See also | |
| 139 | + | ||
| 140 | + | - [[Portal:iOS|iOS Portal]] | |
| 141 | + | ||
| 142 | + | #### External Links | |
| 143 | + | ||
| 144 | + | - [Apple iOS Human Interface Guidelines](http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html) | |
| 145 | + | - [Apple Style Guide](https://help.apple.com/asg/mac/) | |
| 146 | + | - [App Distribution Guide](https://developer.apple.com/library/mac/#documentation/IDEs/Conceptual/AppDistributionGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40012582)\] | |
| 147 | + | - [High Resolution Guidelines for macOS](https://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Introduction/Introduction.html#//apple_ref/doc/uid/TP40012302) | |
| 148 | + | ||
| 149 | + | ### Linux | |
| 150 | + | ||
| 151 | + | Linux is less standardized than other operating systems. This is a consequence of both heterogeneity of distributions and the fact that there is no "standard" desktop environment for Linux. GNOME, KDE, LXDE and other desktop environments differ in their recommendations for GUI design. | |
| 152 | + | ||
| 153 | + | #### See also | |
| 154 | + | ||
| 155 | + | - [[Portal:Linux|Linux portal]] | |
| 156 | + | ||
| 157 | + | #### External links | |
| 158 | + | ||
| 159 | + | - [GNOME human interface guidelines](https://developer.gnome.org/hig-book/stable/) | |
| 160 | + | - [KDE human interface guidelines](http://techbase.kde.org/Projects/Usability/HIG) | |
| 161 | + | - [Canonical Ubuntu App design guides](http://design.ubuntu.com/apps) | |
| 162 | + | - [LXDE Design principles for software](http://wiki.lxde.org/en/Design_Principles) | |
| 163 | + | ||
| 164 | + | ### macOS | |
| 165 | + | ||
| 166 | + | Among all operating systems the GUI of the Mac operating system relies on the richest tradition. It dates back to classical Mac OS from 1984 and its less successful predecessors Lisa OS (1983), Xerox Star (1981) and Xerox Alto (1973). Many regard the Mac operating system GUI as delivering the best user experience of all platforms. This is balanced by a more complex development process, however. | |
| 167 | + | ||
| 168 | + | Compared with other operating systems many issues have been differently implemented on Mac computers. This covers design and location of the menu bar, the position of some standard menus and the style of buttons and icons. Also Mac computer non-GUI features differ, e.g. the architecture of programs, the location of preferences files and interprocess communication. | |
| 169 | + | ||
| 170 | + | Many of these issues are automatically taken care of by the [[Carbon Interface|Carbon]] (32 bit only and now eliminated by Apple in the macOS 10.15 Catalina release in late 2019) and [[Cocoa Interface|Cocoa]] (64 bit only) widgetsets, so that it is easy to develop a simple program for macOS, often without any change to the source code. Some fine-tuning is still necessary to develop a finished Mac application, however. In particular, see [[Apple-specific UI elements]]. | |
| 171 | + | ||
| 172 | + | #### See also | |
| 173 | + | ||
| 174 | + | - [[Portal:Mac|Mac Portal]] for comprehensive lists of links for development techniques, programming hints and tips for creating macOS applications. | |
| 175 | + | ||
| 176 | + | #### External Links | |
| 177 | + | ||
| 178 | + | - [macOS Human Interface Guidelines](https://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AppleHIGuidelines/Intro/Intro.html#//apple_ref/doc/uid/20000957) | |
| 179 | + | - [Apple Style Guide](https://help.apple.com/asg/mac/) | |
| 180 | + | - [App Distribution Guide](https://developer.apple.com/library/mac/#documentation/IDEs/Conceptual/AppDistributionGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40012582)\] | |
| 181 | + | - [High Resolution Guidelines for macOS](https://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Introduction/Introduction.html#//apple_ref/doc/uid/TP40012302) | |
| 182 | + | ||
| 183 | + | ### Windows | |
| 184 | + | ||
| 185 | + | Windows is one of the oldest platforms supported by Lazarus. Therefore, most applications generated by the IDE are automatically in good agreement with the requirements of usability engineering. However, the spectrum of Windows implementations is very wide today, covering mobile operating systems like Windows CE or Windows mobile, desktop environments like Windows 2000, Windows 7 and Windows 10, plus server platforms. Therefore, it may be advisable to fine-tune applications for special environments and their GUI guidelines. | |
| 186 | + | ||
| 187 | + | #### See also | |
| 188 | + | ||
| 189 | + | - [[Multiplatform Programming Guide|Multiplatform Programming Guide: Windows specific issues]] | |
| 190 | + | - [[Portal:Windows|Windows Portal]] | |
| 191 | + | ||
| 192 | + | #### External links | |
| 193 | + | ||
| 194 | + | - [Windows user experience interaction guidelines](http://msdn.microsoft.com/en-us/library/windows/desktop/aa511258.aspx) | |
| 195 | + | ||
| 196 | + | ## See also | |
| 197 | + | ||
| 198 | + | - [[Multiplatform Programming Guide]] | |
| 199 | + | - [[The LCL in various platforms]] | |
| 200 | + | ||
| 201 | + | --- | |
| 202 | + | *From the Free Pascal wiki, page "Introduction to platform-sensitive development", as it stood on 2021-02-23 after a change by Jwdietrich, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
