fixed keymapping for irregular keys

git-svn-id: trunk@4738 -
This commit is contained in:
mattias 2003-10-30 18:25:18 +00:00
parent 7af4661240
commit d92965ff87
6 changed files with 69 additions and 53 deletions

View File

@ -13,11 +13,13 @@ The license directory tree:
| |
+- debugger (GPL2) +- debugger (GPL2)
| |
+- packager (GPL2)
|
+- tools (GPL2) +- tools (GPL2)
| |
+- examples (GPL2) +- examples (GPL2)
| |
+- lcl (modified LGPL) +- lcl (modified LGPL, see there)
| |
+- components/ +- components/
| |
@ -30,8 +32,8 @@ The license directory tree:
+- gtkglarea (modified LGPL, with one exception: nvgl.pp) +- gtkglarea (modified LGPL, with one exception: nvgl.pp)
The IDE files are the files in the <lazarus>, designer and debugger directory. The IDE files are the files in the <lazarus>, designer, packager and debugger
They are under the GPL 2, with the following exceptions: directory. They are under the GPL 2, with the following exceptions:
objectinspector.pp, propedits.pp, transfermacros.pp, wordcompletion.pp, objectinspector.pp, propedits.pp, transfermacros.pp, wordcompletion.pp,
patheditordlg.pas, outputfilter.pas, inputfiledialog.pas, findreplacedialog.pp, patheditordlg.pas, outputfilter.pas, inputfiledialog.pas, findreplacedialog.pp,
findinfilesdlg.pas findinfilesdlg.pas

View File

@ -1972,7 +1972,7 @@ var
end; end;
RestoreBrush:=true; RestoreBrush:=true;
end; end;
DC.Canvas.FillRect(Rect(RLeft,RTop,RRIght,RBottom)); DC.Canvas.FillRect(Rect(RLeft,RTop,RRight,RBottom));
end; end;
begin begin

View File

@ -2961,10 +2961,10 @@ begin
if (Key1=VK_UNKNOWN) and (Key2=VK_UNKNOWN) then if (Key1=VK_UNKNOWN) and (Key2=VK_UNKNOWN) then
Result:=Result+'none' Result:=Result+'none'
else if (Key2=VK_UNKNOWN) then else if (Key2=VK_UNKNOWN) then
Result:=Result+KeyAndShiftStateToStr(Key1,Shift1) Result:=Result+KeyAndShiftStateToEditorKeyString(Key1,Shift1)
else else
Result:=Result+KeyAndShiftStateToStr(Key1,Shift1)+' or '+ Result:=Result+KeyAndShiftStateToEditorKeyString(Key1,Shift1)+' or '+
KeyAndShiftStateToStr(Key2,Shift2); KeyAndShiftStateToEditorKeyString(Key2,Shift2);
end; end;
end; end;

View File

@ -457,8 +457,8 @@ begin
Items.BeginUpdate; Items.BeginUpdate;
Items.Add('none'); Items.Add('none');
for i:=1 to 145 do begin for i:=1 to 145 do begin
s:=KeyAndShiftStateToStr(i,[]); s:=KeyAndShiftStateToEditorKeyString(i,[]);
if lowercase(copy(s,1,5))<>'word(' then if not EditorKeyStringIsIrregular(s) then
Items.Add(s); Items.Add(s);
end; end;
Items.EndUpdate; Items.EndUpdate;
@ -552,7 +552,7 @@ begin
fOptions.Filename:=FilenameEdit.Text; fOptions.Filename:=FilenameEdit.Text;
fOptions.CmdLineParams:=ParametersEdit.Text; fOptions.CmdLineParams:=ParametersEdit.Text;
fOptions.WorkingDirectory:=WorkingDirEdit.Text; fOptions.WorkingDirectory:=WorkingDirEdit.Text;
fOptions.Key:=StrToVKCode(KeyComboBox.Text); fOptions.Key:=EditorKeyStringToVKCode(KeyComboBox.Text);
fOptions.Shift:=[]; fOptions.Shift:=[];
if fOptions.Key<>VK_UNKNOWN then begin if fOptions.Key<>VK_UNKNOWN then begin
if KeyCtrlCheckBox.Checked then include(fOptions.fShift,ssCtrl); if KeyCtrlCheckBox.Checked then include(fOptions.fShift,ssCtrl);
@ -571,7 +571,7 @@ begin
FilenameEdit.Text:=fOptions.Filename; FilenameEdit.Text:=fOptions.Filename;
ParametersEdit.Text:=fOptions.CmdLineParams; ParametersEdit.Text:=fOptions.CmdLineParams;
WorkingDirEdit.Text:=fOptions.WorkingDirectory; WorkingDirEdit.Text:=fOptions.WorkingDirectory;
SetComboBox(KeyComboBox,KeyAndShiftStateToStr(fOptions.Key,[])); SetComboBox(KeyComboBox,KeyAndShiftStateToEditorKeyString(fOptions.Key,[]));
KeyCtrlCheckBox.Checked:=(ssCtrl in fOptions.Shift); KeyCtrlCheckBox.Checked:=(ssCtrl in fOptions.Shift);
KeyShiftCheckBox.Checked:=(ssShift in fOptions.Shift); KeyShiftCheckBox.Checked:=(ssShift in fOptions.Shift);
KeyAltCheckBox.Checked:=(ssAlt in fOptions.Shift); KeyAltCheckBox.Checked:=(ssAlt in fOptions.Shift);
@ -826,7 +826,7 @@ begin
KeyCtrlCheckBox.Checked:=(ssCtrl in Shift); KeyCtrlCheckBox.Checked:=(ssCtrl in Shift);
KeyShiftCheckBox.Checked:=(ssShift in Shift); KeyShiftCheckBox.Checked:=(ssShift in Shift);
KeyAltCheckBox.Checked:=(ssAlt in Shift); KeyAltCheckBox.Checked:=(ssAlt in Shift);
SetComboBox(KeyComboBox,KeyAndShiftStateToStr(Key,[])); SetComboBox(KeyComboBox,KeyAndShiftStateToEditorKeyString(Key,[]));
end; end;
DeactivateGrabbing; DeactivateGrabbing;
end; end;

View File

@ -353,7 +353,8 @@ type
KeyIndex:integer; KeyIndex:integer;
end; end;
function KeyAndShiftStateToStr(Key:Word; ShiftState:TShiftState):AnsiString; function KeyAndShiftStateToEditorKeyString(Key:Word;
ShiftState:TShiftState):AnsiString;
function ShowKeyMappingEditForm(Index:integer; function ShowKeyMappingEditForm(Index:integer;
AKeyCommandRelationList:TKeyCommandRelationList):TModalResult; AKeyCommandRelationList:TKeyCommandRelationList):TModalResult;
function KeyStrokesConsistencyErrors(ASynEditKeyStrokes:TSynEditKeyStrokes; function KeyStrokesConsistencyErrors(ASynEditKeyStrokes:TSynEditKeyStrokes;
@ -361,7 +362,7 @@ function KeyStrokesConsistencyErrors(ASynEditKeyStrokes:TSynEditKeyStrokes;
function EditorCommandToDescriptionString(cmd: word):AnsiString; function EditorCommandToDescriptionString(cmd: word):AnsiString;
function EditorCommandLocalizedName(cmd: word; function EditorCommandLocalizedName(cmd: word;
const DefaultName: string): string; const DefaultName: string): string;
function StrToVKCode(const s: string): integer; function EditorKeyStringToVKCode(const s: string): integer;
procedure GetDefaultKeyForCommand(Command: word; procedure GetDefaultKeyForCommand(Command: word;
var Key1: word; var Shift1: TShiftState; var Key1: word; var Shift1: TShiftState;
@ -374,19 +375,20 @@ function KeySchemeNameToSchemeType(const SchemeName: string): TKeyMapScheme;
function ShiftStateToStr(Shift:TShiftState):AnsiString; function ShiftStateToStr(Shift:TShiftState):AnsiString;
function KeyValuesToStr(Key1: word; Shift1: TShiftState; function KeyValuesToStr(Key1: word; Shift1: TShiftState;
Key2: word; Shift2: TShiftState): string; Key2: word; Shift2: TShiftState): string;
function EditorKeyStringIsIrregular(const s: string): boolean;
var KeyMappingEditForm: TKeyMappingEditForm; var KeyMappingEditForm: TKeyMappingEditForm;
const const
KeyCategoryToolMenuName = 'ToolMenu'; KeyCategoryToolMenuName = 'ToolMenu';
UnknownVKPrefix = 'Word(''';
UnknownVKPostfix = ''')';
implementation implementation
const const
KeyMappingFormatVersion = 2; KeyMappingFormatVersion = 2;
UnknownVKPrefix = 'Word(''';
UnknownVKPostfix = ''')';
VirtualKeyStrings: TStringHashList = nil; VirtualKeyStrings: TStringHashList = nil;
@ -398,21 +400,22 @@ begin
Result:=DefaultName; Result:=DefaultName;
end; end;
function StrToVKCode(const s: string): integer; function EditorKeyStringToVKCode(const s: string): integer;
var var
i: integer; i: integer;
Data: Pointer; Data: Pointer;
begin begin
Result:=VK_UNKNOWN; Result:=VK_UNKNOWN;
if (length(UnknownVKPrefix)<length(s)) if EditorKeyStringIsIrregular(s) then begin
and (AnsiStrLComp(PChar(s),PChar(UnknownVKPrefix),length(UnknownVKPrefix))=0) Result:=StrToIntDef(copy(s,7,length(s)-8),VK_UNKNOWN);
then exit;
Result:=StrToIntDef(copy(s,7,length(s)-8),VK_UNKNOWN) end;
else if s<>'none' then begin if (s<>'none') and (s<>'') then begin
if VirtualKeyStrings=nil then begin if VirtualKeyStrings=nil then begin
VirtualKeyStrings:=TStringHashList.Create(true); VirtualKeyStrings:=TStringHashList.Create(true);
for i:=1 to 300 do for i:=1 to 300 do
VirtualKeyStrings.Add(KeyAndShiftStateToStr(i,[]),Pointer(i)); VirtualKeyStrings.Add(KeyAndShiftStateToEditorKeyString(i,[]),
Pointer(i));
end; end;
end else end else
exit; exit;
@ -919,6 +922,16 @@ begin
+','+IntToStr(Key2)+','+ShiftStateToStr(Shift2); +','+IntToStr(Key2)+','+ShiftStateToStr(Shift2);
end; end;
function EditorKeyStringIsIrregular(const s: string): boolean;
begin
if (length(UnknownVKPrefix)<length(s))
and (AnsiStrLComp(PChar(s),PChar(UnknownVKPrefix),length(UnknownVKPrefix))=0)
then
Result:=true
else
Result:=false;
end;
function ShowKeyMappingEditForm(Index:integer; function ShowKeyMappingEditForm(Index:integer;
AKeyCommandRelationList:TKeyCommandRelationList):TModalResult; AKeyCommandRelationList:TKeyCommandRelationList):TModalResult;
@ -926,11 +939,11 @@ function ShowKeyMappingEditForm(Index:integer;
var s: string; var s: string;
i: integer; i: integer;
begin begin
s:=KeyAndShiftStateToStr(AKey,[]); s:=KeyAndShiftStateToEditorKeyString(AKey,[]);
i:=AComboBox.Items.IndexOf(s); i:=AComboBox.Items.IndexOf(s);
if i>=0 then if i>=0 then
AComboBox.ItemIndex:=i AComboBox.ItemIndex:=i
else if lowercase(copy(s,1,5))='word(' then begin else if EditorKeyStringIsIrregular(s) then begin
AComboBox.Items.Add(s); AComboBox.Items.Add(s);
AComboBox.ItemIndex:=AComboBox.Items.IndexOf(s); AComboBox.ItemIndex:=AComboBox.Items.IndexOf(s);
end else end else
@ -1245,11 +1258,11 @@ begin
Protocol.Add(srkmConflic+IntToStr(Result)); Protocol.Add(srkmConflic+IntToStr(Result));
Protocol.Add(srkmCommand1 Protocol.Add(srkmCommand1
+EditorCommandToDescriptionString(Key1.Command)+'"' +EditorCommandToDescriptionString(Key1.Command)+'"'
+'->'+KeyAndShiftStateToStr(Key1.Key,Key1.Shift)); +'->'+KeyAndShiftStateToEditorKeyString(Key1.Key,Key1.Shift));
Protocol.Add(srkmConflicW); Protocol.Add(srkmConflicW);
Protocol.Add(srkmCommand2 Protocol.Add(srkmCommand2
+EditorCommandToDescriptionString(Key2.Command)+'"' +EditorCommandToDescriptionString(Key2.Command)+'"'
+'->'+KeyAndShiftStateToStr(Key2.Key,Key2.Shift) +'->'+KeyAndShiftStateToEditorKeyString(Key2.Key,Key2.Shift)
); );
Protocol.Add(''); Protocol.Add('');
end; end;
@ -1258,7 +1271,7 @@ begin
end; end;
end; end;
function KeyAndShiftStateToStr(Key:Word; ShiftState:TShiftState):AnsiString; function KeyAndShiftStateToEditorKeyString(Key:Word; ShiftState:TShiftState):AnsiString;
var var
p, ResultLen: integer; p, ResultLen: integer;
@ -1480,8 +1493,8 @@ begin
Items.BeginUpdate; Items.BeginUpdate;
Items.Add('none'); Items.Add('none');
for a:=1 to 145 do begin for a:=1 to 145 do begin
s:=KeyAndShiftStateToStr(a,[]); s:=KeyAndShiftStateToEditorKeyString(a,[]);
if lowercase(copy(s,1,5))<>'word(' then if not EditorKeyStringIsIrregular(s) then
Items.Add(s); Items.Add(s);
end; end;
Items.EndUpdate; Items.EndUpdate;
@ -1554,8 +1567,8 @@ begin
Items.BeginUpdate; Items.BeginUpdate;
Items.Add('none'); Items.Add('none');
for a:=1 to 145 do begin for a:=1 to 145 do begin
s:=KeyAndShiftStateToStr(a,[]); s:=KeyAndShiftStateToEditorKeyString(a,[]);
if lowercase(copy(s,1,5))<>'word(' then if not EditorKeyStringIsIrregular(s) then
Items.Add(s); Items.Add(s);
end; end;
Items.EndUpdate; Items.EndUpdate;
@ -1588,7 +1601,7 @@ begin
NewShiftState1:=[]; NewShiftState1:=[];
NewKey2:=VK_UNKNOWN; NewKey2:=VK_UNKNOWN;
NewShiftState2:=[]; NewShiftState2:=[];
NewKey1:=StrToVKCode(Key1KeyComboBox.Text); NewKey1:=EditorKeyStringToVKCode(Key1KeyComboBox.Text);
if NewKey1<>VK_UNKNOWN then if NewKey1<>VK_UNKNOWN then
begin begin
if Key1CtrlCheckBox.Checked then include(NewShiftState1,ssCtrl); if Key1CtrlCheckBox.Checked then include(NewShiftState1,ssCtrl);
@ -1602,12 +1615,13 @@ begin
if (DummyRelation<>nil) if (DummyRelation<>nil)
and (DummyRelation<>KeyCommandRelationList.Relations[KeyIndex]) then and (DummyRelation<>KeyCommandRelationList.Relations[KeyIndex]) then
begin begin
AText:=Format(srkmAlreadyConnected,[KeyAndShiftStateToStr(NewKey1,NewShiftState1),DummyRelation.Name]); AText:=Format(srkmAlreadyConnected,
[KeyAndShiftStateToEditorKeyString(NewKey1,NewShiftState1),DummyRelation.Name]);
MessageDlg(AText,mtError,[mbok],0); MessageDlg(AText,mtError,[mbok],0);
exit; exit;
end; end;
NewKey2:=StrToVKCode(Key2KeyComboBox.Text); NewKey2:=EditorKeyStringToVKCode(Key2KeyComboBox.Text);
if (NewKey1=NewKey2) and (NewShiftState1=NewShiftState2) then if (NewKey1=NewKey2) and (NewShiftState1=NewShiftState2) then
NewKey2:=VK_UNKNOWN; NewKey2:=VK_UNKNOWN;
if NewKey2<>VK_UNKNOWN then if NewKey2<>VK_UNKNOWN then
@ -1616,11 +1630,14 @@ begin
if Key2AltCheckBox.Checked then include(NewShiftState2,ssAlt); if Key2AltCheckBox.Checked then include(NewShiftState2,ssAlt);
if Key2ShiftCheckBox.Checked then include(NewShiftState2,ssShift); if Key2ShiftCheckBox.Checked then include(NewShiftState2,ssShift);
end; end;
DummyRelation:=KeyCommandRelationList.Find(NewKey2,NewShiftState2,CurRelation.Parent.Areas); DummyRelation:=KeyCommandRelationList.Find(NewKey2,NewShiftState2,
CurRelation.Parent.Areas);
if (DummyRelation<>nil) and (DummyRelation<>KeyCommandRelationList.Relations[KeyIndex]) then if (DummyRelation<>nil)
and (DummyRelation<>KeyCommandRelationList.Relations[KeyIndex]) then
begin begin
AText:=Format(srkmAlreadyConnected,[KeyAndShiftStateToStr(NewKey2,NewShiftState2),DummyRelation.Name]); AText:=Format(srkmAlreadyConnected,
[KeyAndShiftStateToEditorKeyString(NewKey2,NewShiftState2),DummyRelation.Name]);
MessageDlg(AText,mterror,[mbok],0); MessageDlg(AText,mterror,[mbok],0);
exit; exit;
end; end;
@ -1713,11 +1730,11 @@ begin
end; end;
procedure TKeyMappingEditForm.FormKeyUp(Sender: TObject; var Key: Word; procedure TKeyMappingEditForm.FormKeyUp(Sender: TObject; var Key: Word;
Shift:TShiftState); Shift: TShiftState);
begin begin
{writeln('TKeyMappingEditForm.FormKeyUp Sender=',Classname {writeln('TKeyMappingEditForm.FormKeyUp Sender=',Classname
,' Key=',Key,' Ctrl=',ssCtrl in Shift,' Shift=',ssShift in Shift ,' Key=',Key,' Ctrl=',ssCtrl in Shift,' Shift=',ssShift in Shift
,' Alt=',ssAlt in Shift,' AsString=',KeyAndShiftStateToStr(Key,Shift) ,' Alt=',ssAlt in Shift,' AsString=',KeyAndShiftStateToEditorKeyString(Key,Shift)
);} );}
if Key in [VK_CONTROL, VK_SHIFT, VK_LCONTROL, VK_RCONTROl, if Key in [VK_CONTROL, VK_SHIFT, VK_LCONTROL, VK_RCONTROl,
VK_LSHIFT, VK_RSHIFT] then exit; VK_LSHIFT, VK_RSHIFT] then exit;
@ -1728,14 +1745,14 @@ begin
Key1CtrlCheckBox.Checked:=(ssCtrl in Shift); Key1CtrlCheckBox.Checked:=(ssCtrl in Shift);
Key1ShiftCheckBox.Checked:=(ssShift in Shift); Key1ShiftCheckBox.Checked:=(ssShift in Shift);
Key1AltCheckBox.Checked:=(ssAlt in Shift); Key1AltCheckBox.Checked:=(ssAlt in Shift);
SetComboBox(Key1KeyComboBox,KeyAndShiftStateToStr(Key,[])); SetComboBox(Key1KeyComboBox,KeyAndShiftStateToEditorKeyString(Key,[]));
end end
else if GrabbingKey=2 then else if GrabbingKey=2 then
begin begin
Key2CtrlCheckBox.Checked:=(ssCtrl in Shift); Key2CtrlCheckBox.Checked:=(ssCtrl in Shift);
Key2ShiftCheckBox.Checked:=(ssShift in Shift); Key2ShiftCheckBox.Checked:=(ssShift in Shift);
Key2AltCheckBox.Checked:=(ssAlt in Shift); Key2AltCheckBox.Checked:=(ssAlt in Shift);
SetComboBox(Key2KeyComboBox,KeyAndShiftStateToStr(Key,[])); SetComboBox(Key2KeyComboBox,KeyAndShiftStateToEditorKeyString(Key,[]));
end; end;
Key:=0; Key:=0;
DeactivateGrabbing; DeactivateGrabbing;

View File

@ -505,12 +505,6 @@ PM_Remove = 1;
VK_PA1 = $FD; VK_PA1 = $FD;
VK_OEM_CLEAR = $FE; VK_OEM_CLEAR = $FE;
// all other keys with no virtual key code are mapped to
// VK_IRREGULAR + KeyCode
// MWE: Obsolete
// VK_IRREGULAR = 1000;
//============================================== //==============================================
// //
//============================================== //==============================================
@ -1881,6 +1875,9 @@ end.
{ {
$Log$ $Log$
Revision 1.47 2003/10/30 18:25:18 mattias
fixed keymapping for irregular keys
Revision 1.46 2003/10/23 19:03:13 ajgenius Revision 1.46 2003/10/23 19:03:13 ajgenius
re-add TByteArray re-add TByteArray