Sign in Join
Wiki copytemporary

Introduction to platform-sensitive development: what changed

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

OldNewLine
1-<figure>
21<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>
52
63**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.
74
85Thanks 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.
96
107Platform-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.
118
129This article provides the reader with essential information and hints for platform-sensitive development.
1310
1411## Prelude
1512
1613*(Platform-sensitive development only)*
1714
1815Most 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.
1916
2017The 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.
2118
2219The 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.
2320
2421``` pascal
2522uses
2623 LCLType;
2724
2825procedure AdaptMenus;
2926{ Adapts Menus and Shortcuts to the interface style guidelines
3027 of the respective operating system }
3128var
3229 modifierKey: TShiftState;
3330begin
3431 {$IFDEF Darwin}
3532 MainForm.WinAboutItem.Visible := False;
3633 MainForm.Divider_5_1.Visible := False;
3734 MainForm.Divider_2_2.Visible := False;
3835 MainForm.WinPreferencesItem.Visible := False;
3936 MainForm.AppleMenu.Visible := True;
4037 {$ELSE}
4138 MainForm.WinAboutItem.Visible := True;
4239 MainForm.Divider_5_1.Visible := True;
4340 MainForm.Divider_2_2.Visible := True;
4441 MainForm.WinPreferencesItem.Visible := True;
4542 MainForm.AppleMenu.Visible := False;
4643 {$ENDIF}
4744 MainForm.NewMenuItem.ShortCut := ShortCut(VK_N, ssModifier); //ssModifier equals ssMeta on Mac, ssCtrl on other platforms
4845 MainForm.OpenMenuItem.ShortCut := ShortCut(VK_O, ssModifier);
4946 MainForm.CloseMenuItem.ShortCut := ShortCut(VK_W, ssModifier);
5047 MainForm.SaveItem.ShortCut := ShortCut(VK_S, ssModifier);
5148 MainForm.PrintItem.ShortCut := ShortCut(VK_P, ssModifier);
5249 MainForm.QuitMenuItem.ShortCut := ShortCut(VK_Q, ssModifier);
5350 MainForm.UndoMenuItem.ShortCut := ShortCut(VK_Z, ssModifier);
5451 MainForm.CutMenuItem.ShortCut := ShortCut(VK_X, ssModifier);
5552 MainForm.CopyMenuItem.ShortCut := ShortCut(VK_C, ssModifier);
5653 MainForm.PasteMenuItem.ShortCut := ShortCut(VK_V, ssModifier);
5754 MainForm.SelectAllMenuItem.ShortCut := ShortCut(VK_A, ssModifier);
5855end;
5956```
6057
6158In 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:
6259
6360``` pascal
6461uses
6562 LCLType;
6663
6764procedure AdaptMenus;
6865{ Adapts Menus and Shortcuts to the interface style guidelines
6966 of the respective operating system }
7067var
7168 modifierKey: TShiftState;
7269begin
7370 {$IFDEF LCLcarbon}
7471 modifierKey := [ssMeta];
7572 MainForm.WinAboutItem.Visible := False;
7673 MainForm.Divider_5_1.Visible := False;
7774 MainForm.Divider_2_2.Visible := False;
7875 MainForm.WinPreferencesItem.Visible := False;
7976 MainForm.AppleMenu.Visible := True;
8077 {$ELSE}
8178 modifierKey := [ssCtrl];
8279 MainForm.WinAboutItem.Visible := True;
8380 MainForm.Divider_5_1.Visible := True;
8481 MainForm.Divider_2_2.Visible := True;
8582 MainForm.WinPreferencesItem.Visible := True;
8683 MainForm.AppleMenu.Visible := False;
8784 {$ENDIF}
8885 MainForm.NewMenuItem.ShortCut := ShortCut(VK_N, modifierKey);
8986 MainForm.OpenMenuItem.ShortCut := ShortCut(VK_O, modifierKey);
9087 MainForm.CloseMenuItem.ShortCut := ShortCut(VK_W, modifierKey);
9188 MainForm.SaveItem.ShortCut := ShortCut(VK_S, modifierKey);
9289 MainForm.PrintItem.ShortCut := ShortCut(VK_P, modifierKey);
9390 MainForm.QuitMenuItem.ShortCut := ShortCut(VK_Q, modifierKey);
9491 MainForm.UndoMenuItem.ShortCut := ShortCut(VK_Z, modifierKey);
9592 MainForm.CutMenuItem.ShortCut := ShortCut(VK_X, modifierKey);
9693 MainForm.CopyMenuItem.ShortCut := ShortCut(VK_C, modifierKey);
9794 MainForm.PasteMenuItem.ShortCut := ShortCut(VK_V, modifierKey);
9895 MainForm.SelectAllMenuItem.ShortCut := ShortCut(VK_A, modifierKey);
9996end;
10097```
10198
10299> **Note:** To see if LCL functionality is supported on your target widgetset, you can use the Restriction Browser (menu View/Restriction Browser)
103100
104101## Platform-specific hints
105102
106103### Android
107104
108105Android 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.
109106
110107#### See also
111108
112109- [[Android Interface/Native Android GUI]]
113110- [[Portal:Android|Android Portal]]
114111
115112#### External Links
116113
117114- [Android Design](http://developer.android.com/design/index.html)
118115- [Android User Interface Guidelines](http://developer.android.com/guide/practices/ui_guidelines/index.html)
119116
120117### FreeBSD
121118
122119[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.
123120
124121#### See also
125122
126123- [[Portal:FreeBSD|FreeBSD Portal]] for comprehensive lists of links for development techniques, programming hints and tips for creating FreeBSD programs.
127124
128125#### External links
129126
130127- [FreeBSD: Developers' Handbook](https://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/).
131128- [FreeBSD: Porters Handbook](https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/).
132129- [FreeBSD: Handbook](https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/).
133130
134131### iOS
135132
136133iOS 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.
137134
138135#### See also
139136
140137- [[Portal:iOS|iOS Portal]]
141138
142139#### External Links
143140
144141- [Apple iOS Human Interface Guidelines](http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html)
145142- [Apple Style Guide](https://help.apple.com/asg/mac/)
146143- [App Distribution Guide](https://developer.apple.com/library/mac/#documentation/IDEs/Conceptual/AppDistributionGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40012582)\]
147144- [High Resolution Guidelines for macOS](https://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Introduction/Introduction.html#//apple_ref/doc/uid/TP40012302)
148145
149146### Linux
150147
151148Linux 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.
152149
153150#### See also
154151
155152- [[Portal:Linux|Linux portal]]
156153
157154#### External links
158155
159156- [GNOME human interface guidelines](https://developer.gnome.org/hig-book/stable/)
160157- [KDE human interface guidelines](http://techbase.kde.org/Projects/Usability/HIG)
161158- [Canonical Ubuntu App design guides](http://design.ubuntu.com/apps)
162159- [LXDE Design principles for software](http://wiki.lxde.org/en/Design_Principles)
163160
164161### macOS
165162
166163Among 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.
167164
168165Compared 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.
169166
170167Many 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]].
171168
172169#### See also
173170
174171- [[Portal:Mac|Mac Portal]] for comprehensive lists of links for development techniques, programming hints and tips for creating macOS applications.
175172
176173#### External Links
177174
178175- [macOS Human Interface Guidelines](https://developer.apple.com/library/mac/#documentation/UserExperience/Conceptual/AppleHIGuidelines/Intro/Intro.html#//apple_ref/doc/uid/20000957)
179176- [Apple Style Guide](https://help.apple.com/asg/mac/)
180177- [App Distribution Guide](https://developer.apple.com/library/mac/#documentation/IDEs/Conceptual/AppDistributionGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40012582)\]
181178- [High Resolution Guidelines for macOS](https://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Introduction/Introduction.html#//apple_ref/doc/uid/TP40012302)
182179
183180### Windows
184181
185182Windows 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.
186183
187184#### See also
188185
189186- [[Multiplatform Programming Guide|Multiplatform Programming Guide: Windows specific issues]]
190187- [[Portal:Windows|Windows Portal]]
191188
192189#### External links
193190
194191- [Windows user experience interaction guidelines](http://msdn.microsoft.com/en-us/library/windows/desktop/aa511258.aspx)
195192
196193## See also
197194
198195- [[Multiplatform Programming Guide]]
199196- [[The LCL in various platforms]]
200197
201198---
202199*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