[Lazarus] Platform dependent modifier for common shortcut-keys?

Bart bartjunk64 at gmail.com
Sat Oct 8 14:46:24 CEST 2011


On 10/7/11, Flávio Etrusco <flavio.etrusco at gmail.com> wrote:

> That's my gut feeling too. Do you think implementing the missing
> TStandardActions and handling their default ShortCut accordingly would
> suffice?

I do not think solving this _only_ in TStandardActions is the way to go.
I specifically would use something like ssModifier (=ssCtrl, or
=ssMeta) in LCL components (e.g. TMaskEdit which by design handles all
key input by itself, and there are other LCL examples like SynEdit,
TreeView (IIRC) and DBGrid).

This is a chunk form a proposed patch for TMaskEdit:

 procedure TCustomMaskEdit.KeyDown(var Key: Word; Shift: TShiftState);
+const
+  ssModifier = {$if defined(darwin) or defined(macos)} ssMeta {$else}
ssCtrl {$endif};
 begin
   Inherited KeyDown(Key, Shift);
   // Not masked -> old procedure
@@ -1662,7 +1664,7 @@
       begin//Cut
         CutToClipBoard;
       end
-      else if (Shift = [ssCtrl]) then
+      else if (Shift = [ssModifier]) then
       begin//Clear
         DeleteSelected;
       end

This is the way I would see it being helpful for cross platform code
for built-in key shortcuts.

StandardActions then could benefit from such a ssModifier constant as well.

Another approach might be to have a widgetset function like:

function KeyCombo_IsCut(const Key: Word; const Shift: TShiftState): Boolean

or something like:

type
  TCommonShortCut = (tcsUnknown,tcsCut, tcsPaste, tcsCopy, tcsBof, tcsEof);

function KeyComboToCommonShortcut(const Key: Word; const Shift:
TShiftState): TCommonShortCut;
begin
  //default to tcsUnKnown;
  Result := tcsUnKnown;
  ...
end;

Bart




More information about the Lazarus mailing list