summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/amunits/src/coreunits/keymap.pas
blob: 1688b985a16a3f7f9eda6e192a74f279d5e77617 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
{
    This file is part of the Free Pascal run time library.

    A file in Amiga system run time library.
    Copyright (c) 1998-2003 by Nils Sjoholm
    member of the Amiga RTL development team.

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}

{
        keymap.resource definitions and console.device key map definitions
}

{
    History:

    Added the defines use_amiga_smartlink and
    use_auto_openlib. Implemented autoopening
    of the library.
    14 Jan 2003.

    Changed integer > smallint,
            cardinal > longword.
    09 Feb 2003.

    nils.sjoholm@mailbox.swipnet.se Nils Sjoholm
}

{$I useamigasmartlink.inc}
{$ifdef use_amiga_smartlink}
   {$smartlink on}
{$endif use_amiga_smartlink}

unit keymap;

INTERFACE

uses exec, inputevent;

Type

    pKeyMap = ^tKeyMap;
    tKeyMap = record
        km_LoKeyMapTypes        : Pointer;
        km_LoKeyMap             : Pointer;
        km_LoCapsable           : Pointer;
        km_LoRepeatable         : Pointer;
        km_HiKeyMapTypes        : Pointer;
        km_HiKeyMap             : Pointer;
        km_HiCapsable           : Pointer;
        km_HiRepeatable         : Pointer;
    end;


    pKeymapNode = ^tKeyMapNode;
    tKeyMapNode = record
        kn_Node         : tNode;         { including name of keymap }
        kn_KeyMap       : tKeyMap;
    end;

{ the structure of keymap.resource }

    pKeyMapResource = ^tKeyMapResource;
    tKeyMapResource = record
        kr_Node         : tNode;
        kr_List         : tList;         { a list of KeyMapNodes }
    end;


Const

{ Key Map Types }

    KC_NOQUAL           = 0;
    KC_VANILLA          = 7;    { note that SHIFT+ALT+CTRL is VANILLA }
    KCB_SHIFT           = 0;
    KCF_SHIFT           = $01;
    KCB_ALT             = 1;
    KCF_ALT             = $02;
    KCB_CONTROL         = 2;
    KCF_CONTROL         = $04;
    KCB_DOWNUP          = 3;
    KCF_DOWNUP          = $08;

    KCB_DEAD            = 5;    { may be dead or modified by dead key:  }
    KCF_DEAD            = $20;  {   use dead prefix bytes               }

    KCB_STRING          = 6;
    KCF_STRING          = $40;

    KCB_NOP             = 7;
    KCF_NOP             = $80;


{ Dead Prefix Bytes }

    DPB_MOD             = 0;
    DPF_MOD             = $01;
    DPB_DEAD            = 3;
    DPF_DEAD            = $08;

    DP_2DINDEXMASK      = $0f;  { mask for index for 1st of two dead keys }
    DP_2DFACSHIFT       = 4;    { shift for factor for 1st of two dead keys }

VAR KeymapBase : pLibrary;

const
    KEYMAPNAME : PChar = 'keymap.library';

FUNCTION AskKeyMapDefault : pKeyMap;
FUNCTION MapANSI(thestring : pCHAR; count : LONGINT; buffer : pCHAR; length : LONGINT; keyMap : pKeyMap) : LONGINT;
FUNCTION MapRawKey(event : pInputEvent; buffer : pCHAR; length : LONGINT; keyMap : pKeyMap) : smallint;
PROCEDURE SetKeyMapDefault(keyMap : pKeyMap);

IMPLEMENTATION

uses msgbox;

FUNCTION AskKeyMapDefault : pKeyMap;
BEGIN
  ASM
    MOVE.L  A6,-(A7)
    MOVEA.L KeymapBase,A6
    JSR -036(A6)
    MOVEA.L (A7)+,A6
    MOVE.L  D0,@RESULT
  END;
END;

FUNCTION MapANSI(thestring : pCHAR; count : LONGINT; buffer : pCHAR; length : LONGINT; keyMap : pKeyMap) : LONGINT;
BEGIN
  ASM
    MOVE.L  A6,-(A7)
    MOVEA.L thestring,A0
    MOVE.L  count,D0
    MOVEA.L buffer,A1
    MOVE.L  length,D1
    MOVEA.L keyMap,A2
    MOVEA.L KeymapBase,A6
    JSR -048(A6)
    MOVEA.L (A7)+,A6
    MOVE.L  D0,@RESULT
  END;
END;

FUNCTION MapRawKey(event : pInputEvent; buffer : pCHAR; length : LONGINT; keyMap : pKeyMap) : smallint;
BEGIN
  ASM
    MOVE.L  A6,-(A7)
    MOVEA.L event,A0
    MOVEA.L buffer,A1
    MOVE.L  length,D1
    MOVEA.L keyMap,A2
    MOVEA.L KeymapBase,A6
    JSR -042(A6)
    MOVEA.L (A7)+,A6
    MOVE.L  D0,@RESULT
  END;
END;

PROCEDURE SetKeyMapDefault(keyMap : pKeyMap);
BEGIN
  ASM
    MOVE.L  A6,-(A7)
    MOVEA.L keyMap,A0
    MOVEA.L KeymapBase,A6
    JSR -030(A6)
    MOVEA.L (A7)+,A6
  END;
END;

{$I useautoopenlib.inc}
{$ifdef use_auto_openlib}
  {$Info Compiling autoopening of keymap.library}

var
    keymap_exit : Pointer;

procedure ClosekeymapLibrary;
begin
    ExitProc := keymap_exit;
    if KeymapBase <> nil then begin
        CloseLibrary(KeymapBase);
        KeymapBase := nil;
    end;
end;

const
    { Change VERSION and LIBVERSION to proper values }

    VERSION : string[2] = '0';
    LIBVERSION : longword = 0;

begin
    KeymapBase := nil;
    KeymapBase := OpenLibrary(KEYMAPNAME,LIBVERSION);
    if KeymapBase <> nil then begin
        keymap_exit := ExitProc;
        ExitProc := @ClosekeymapLibrary
    end else begin
        MessageBox('FPC Pascal Error',
        'Can''t open keymap.library version ' + VERSION + #10 +
        'Deallocating resources and closing down',
        'Oops');
        halt(20);
    end;

{$else}
   {$Warning No autoopening of keymap.library compiled}
   {$Info Make sure you open keymap.library yourself}
{$endif use_auto_openlib}


END. (* UNIT KEYMAP *)