Difference between revisions of "Introduction to platform-sensitive development"

From Free Pascal wiki
Jump to navigationJump to search
Line 109: Line 109:
 
=== Windows ===
 
=== Windows ===
  
To be continued ...
+
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 or Windows 8, and Server platforms. Therefore, it may be advisable to fine-tune applications for special environments and their GUI guidelines.
 +
 
 +
==== See also ====
 +
 
 +
* [[Portal:Windows|Windows Portal]]
  
 
==== External links ====
 
==== External links ====

Revision as of 16:14, 19 May 2013

Platform-sensitive development is the next step in cross-platform development. It extends the process of porting an application by implementing platform-specific functions and user-interface style guides.

Thanks to the "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.

This article is to provide the reader with essential information and hints for platform-sensitive development.

Prelude

Most adaptations for the specific target platforms are performed automatically by the LCL, FCL, RTL and the respective widget sets. It are minor modifications that are needed to create a finished application for your target platform. To use conditional compilation by means of compiler directives helps to keep your code portable.

The following example demonstrates this technique. The procedures 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 on different locations in Mac OS than they are in Windows or Linux. Additionally, the menu shortcuts are invoked by the command key on Mac OS (in the LCL referred to as Meta key), while they are triggered with the control key on most other operating systems.

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-Mac operating systems. On the other side, it contains an Apple Menu for Mac OS X. Depending from the target platform, the code hides unneeded entries (and corresponding dividers) and shows those that are expected by the user.

procedure AdaptMenus;
{ Adapts Menus and Shortcuts to the interface style guidelines
  of the respective operating system }
var
  modifierKey: TShiftState;
begin
  {$IFDEF LCLcarbon}
  modifierKey := [ssMeta];
  MainForm.WinAboutItem.Visible := False;
  MainForm.Divider_5_1.Visible := False;
  MainForm.Divider_2_2.Visible := False;
  MainForm.WinPreferencesItem.Visible := False;
  MainForm.AppleMenu.Visible := True;
  {$ELSE}
  modifierKey := [ssCtrl];
  MainForm.WinAboutItem.Visible := True;
  MainForm.Divider_5_1.Visible := True;
  MainForm.Divider_2_2.Visible := True;
  MainForm.WinPreferencesItem.Visible := True;
  MainForm.AppleMenu.Visible := False;
  {$ENDIF}
  MainForm.NewMenuItem.ShortCut := ShortCut(VK_N, modifierKey);
  MainForm.OpenMenuItem.ShortCut := ShortCut(VK_O, modifierKey);
  MainForm.CloseMenuItem.ShortCut := ShortCut(VK_W, modifierKey);
  MainForm.SaveItem.ShortCut := ShortCut(VK_S, modifierKey);
  MainForm.PrintItem.ShortCut := ShortCut(VK_P, modifierKey);
  MainForm.QuitMenuItem.ShortCut := ShortCut(VK_Q, modifierKey);
  MainForm.UndoMenuItem.ShortCut := ShortCut(VK_Z, modifierKey);
  MainForm.CutMenuItem.ShortCut := ShortCut(VK_X, modifierKey);
  MainForm.CopyMenuItem.ShortCut := ShortCut(VK_C, modifierKey);
  MainForm.PasteMenuItem.ShortCut := ShortCut(VK_V, modifierKey);
  MainForm.SelectAllMenuItem.ShortCut := ShortCut(VK_A, modifierKey);
end;

Platform-specific hints

Android

To be continued ...

See also

External Links

iOS

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.

See also

External Links

Linux

To be continued ...

External links

Mac OS X

To be continued ...

See also

External Links

Windows

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 or Windows 8, and Server platforms. Therefore, it may be advisable to fine-tune applications for special environments and their GUI guidelines.

See also

External links

See also