Sign in Join
Wiki copytemporary

Introduction to platform-sensitive development: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-<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" />
1+![](/wiki-images/4/40/Platform-independent_vs._platform-sensitive_applications.png)
22
33**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.
44
55Thanks 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.
66
77Platform-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.
88
99This article provides the reader with essential information and hints for platform-sensitive development.
1010
1111## Prelude
1212
1313*(Platform-sensitive development only)*
1414
1515Most 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.
1616
1717The 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.
1818
1919The 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.
2020
2121``` pascal
2222uses
2323 LCLType;
2424
2525procedure AdaptMenus;
2626{ Adapts Menus and Shortcuts to the interface style guidelines
2727 of the respective operating system }
2828var
2929 modifierKey: TShiftState;
3030begin
3131 {$IFDEF Darwin}
3232 MainForm.WinAboutItem.Visible := False;
3333 MainForm.Divider_5_1.Visible := False;
3434 MainForm.Divider_2_2.Visible := False;
3535 MainForm.WinPreferencesItem.Visible := False;
3636 MainForm.AppleMenu.Visible := True;
3737 {$ELSE}
3838 MainForm.WinAboutItem.Visible := True;
3939 MainForm.Divider_5_1.Visible := True;
4040 MainForm.Divider_2_2.Visible := True;
4141 MainForm.WinPreferencesItem.Visible := True;
4242 MainForm.AppleMenu.Visible := False;
4343 {$ENDIF}
4444 MainForm.NewMenuItem.ShortCut := ShortCut(VK_N, ssModifier); //ssModifier equals ssMeta on Mac, ssCtrl on other platforms
4545 MainForm.OpenMenuItem.ShortCut := ShortCut(VK_O, ssModifier);
4646 MainForm.CloseMenuItem.ShortCut := ShortCut(VK_W, ssModifier);
4747 MainForm.SaveItem.ShortCut := ShortCut(VK_S, ssModifier);
4848 MainForm.PrintItem.ShortCut := ShortCut(VK_P, ssModifier);
4949 MainForm.QuitMenuItem.ShortCut := ShortCut(VK_Q, ssModifier);
5050 MainForm.UndoMenuItem.ShortCut := ShortCut(VK_Z, ssModifier);
5151 MainForm.CutMenuItem.ShortCut := ShortCut(VK_X, ssModifier);
5252 MainForm.CopyMenuItem.ShortCut := ShortCut(VK_C, ssModifier);
5353 MainForm.PasteMenuItem.ShortCut := ShortCut(VK_V, ssModifier);
5454 MainForm.SelectAllMenuItem.ShortCut := ShortCut(VK_A, ssModifier);
5555end;
5656```
5757
5858In 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:
5959
6060``` pascal
6161uses
6262 LCLType;
6363
6464procedure AdaptMenus;
6565{ Adapts Menus and Shortcuts to the interface style guidelines
6666 of the respective operating system }
6767var
6868 modifierKey: TShiftState;
6969begin
7070 {$IFDEF LCLcarbon}
7171 modifierKey := [ssMeta];
7272 MainForm.WinAboutItem.Visible := False;
7373 MainForm.Divider_5_1.Visible := False;
7474 MainForm.Divider_2_2.Visible := False;
7575 MainForm.WinPreferencesItem.Visible := False;
7676 MainForm.AppleMenu.Visible := True;
7777 {$ELSE}
7878 modifierKey := [ssCtrl];
7979 MainForm.WinAboutItem.Visible := True;
8080 MainForm.Divider_5_1.Visible := True;
8181 MainForm.Divider_2_2.Visible := True;
8282 MainForm.WinPreferencesItem.Visible := True;
8383 MainForm.AppleMenu.Visible := False;
8484 {$ENDIF}
8585 MainForm.NewMenuItem.ShortCut := ShortCut(VK_N, modifierKey);
8686 MainForm.OpenMenuItem.ShortCut := ShortCut(VK_O, modifierKey);
8787 MainForm.CloseMenuItem.ShortCut := ShortCut(VK_W, modifierKey);
8888 MainForm.SaveItem.ShortCut := ShortCut(VK_S, modifierKey);
8989 MainForm.PrintItem.ShortCut := ShortCut(VK_P, modifierKey);
9090 MainForm.QuitMenuItem.ShortCut := ShortCut(VK_Q, modifierKey);
9191 MainForm.UndoMenuItem.ShortCut := ShortCut(VK_Z, modifierKey);
9292 MainForm.CutMenuItem.ShortCut := ShortCut(VK_X, modifierKey);
9393 MainForm.CopyMenuItem.ShortCut := ShortCut(VK_C, modifierKey);
9494 MainForm.PasteMenuItem.ShortCut := ShortCut(VK_V, modifierKey);
9595 MainForm.SelectAllMenuItem.ShortCut := ShortCut(VK_A, modifierKey);
9696end;
9797```
9898
9999> **Note:** To see if LCL functionality is supported on your target widgetset, you can use the Restriction Browser (menu View/Restriction Browser)
100100
101101## Platform-specific hints
102102
103103### Android
104104
105105Android 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.
106106
107107#### See also
108108
109109- [[Android Interface/Native Android GUI]]
110110- [[Portal:Android|Android Portal]]
111111
112112#### External Links
113113
114114- [Android Design](http://developer.android.com/design/index.html)
115115- [Android User Interface Guidelines](http://developer.android.com/guide/practices/ui_guidelines/index.html)
116116
117117### FreeBSD
118118
119119[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.
120120
121121#### See also
122122
123123- [[Portal:FreeBSD|FreeBSD Portal]] for comprehensive lists of links for development techniques, programming hints and tips for creating FreeBSD programs.
124124
125125#### External links
126126
127127- [FreeBSD: Developers' Handbook](https://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/).
128128- [FreeBSD: Porters Handbook](https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/).
129129- [FreeBSD: Handbook](https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/).
130130
131131### iOS
132132
133133iOS 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.
134134
135135#### See also
136136
137137- [[Portal:iOS|iOS Portal]]
138138
139139#### External Links
140140
141141- [Apple iOS Human Interface Guidelines](http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html)
142142- [Apple Style Guide](https://help.apple.com/asg/mac/)
143143- [App Distribution Guide](https://developer.apple.com/library/mac/#documentation/IDEs/Conceptual/AppDistributionGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40012582)\]
144144- [High Resolution Guidelines for macOS](https://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Introduction/Introduction.html#//apple_ref/doc/uid/TP40012302)
145145
146146### Linux
147147
148148Linux 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.
149149
150150#### See also
151151
152152- [[Portal:Linux|Linux portal]]
153153
154154#### External links
155155
156156- [GNOME human interface guidelines](https://developer.gnome.org/hig-book/stable/)
157157- [KDE human interface guidelines](http://techbase.kde.org/Projects/Usability/HIG)
158158- [Canonical Ubuntu App design guides](http://design.ubuntu.com/apps)
159159- [LXDE Design principles for software](http://wiki.lxde.org/en/Design_Principles)
160160
161161### macOS
162162
163163Among 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.
164164
165165Compared 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.
166166
167167Many 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]].
168168
169169#### See also
170170
171171- [[Portal:Mac|Mac Portal]] for comprehensive lists of links for development techniques, programming hints and tips for creating macOS applications.
172172
173173#### External Links
174174
175175- [macOS Human Interface Guidelines](https://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AppleHIGuidelines/Intro/Intro.html#//apple_ref/doc/uid/20000957)
176176- [Apple Style Guide](https://help.apple.com/asg/mac/)
177177- [App Distribution Guide](https://developer.apple.com/library/mac/#documentation/IDEs/Conceptual/AppDistributionGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40012582)\]
178178- [High Resolution Guidelines for macOS](https://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Introduction/Introduction.html#//apple_ref/doc/uid/TP40012302)
179179
180180### Windows
181181
182182Windows 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.
183183
184184#### See also
185185
186186- [[Multiplatform Programming Guide|Multiplatform Programming Guide: Windows specific issues]]
187187- [[Portal:Windows|Windows Portal]]
188188
189189#### External links
190190
191191- [Windows user experience interaction guidelines](http://msdn.microsoft.com/en-us/library/windows/desktop/aa511258.aspx)
192192
193193## See also
194194
195195- [[Multiplatform Programming Guide]]
196196- [[The LCL in various platforms]]
197197
198198---
199199*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).*

Back to history