procedure TCmdForm.SetKeyboard;
var StartPos,StartLength,QryPos: longint;
QryCode : WideString;
WC,W1 : WideChar;
QryChr : WideChar;
QryStr : WideString;
Str0 : WideString;
Str1 : WideString; //string;
begin
//activate keyboard language
StartLength:= PageMemo.SelLength;
StartPos:= PageMemo.SelStart;
if StartPos=0 then QryPos:= 0
else QryPos:= StartPos-1;
QryCode:= ''; W1:= #0; Str1:= '';
PageMemo.Lines.BeginUpdate; // suspend screen updates // replaces EM_HIDESELECTION
try //SendMessage(PageMemo.Handle, EM_HIDESELECTION, 1, 0); // hide selection ** unnecessary
PageMemo.SelStart:= QryPos;
PageMemo.SelLength:=1;
QryStr:= PageMemo.SelText;
Str0:= UTF8Decode(QryStr);
if Str0<>'' then W1:= Str0[1]
else W1:= #0;
if QryStr<>'' then QryChr:= QryStr[1]
else QryChr:= #0;
if (QryPos>0) then
begin
while ((QryChr=' ') or (QryChr=#9)) do
begin
QryPos:= QryPos-1;
PageMemo.SelStart:= QryPos;
PageMemo.SelLength:= 1;
QryStr:= PageMemo.SelText;
QryChr:= QryStr[1];
PageMemo.GetTextAttributes(PageMemo.SelStart, SelFontFormat);
end;
end;
QryCode:= UTF8Decode(QryStr); // gets widestring value
//SendMessage(PageMemo.Handle, EM_HIDESELECTION, 0, 0); // show selection ** unnecessary
finally
PageMemo.Lines.EndUpdate; // restore screen updates // replaces EM_HIDESELECTION
end; // end try
PageMemo.SelStart:= StartPos;
PageMemo.SelLength:= StartLength;
if (QryCode<>'')and(PageMemo.SelLength=0) then
begin
WC:=QryCode[1];
case wc of
#1424..#1535: SetHebrew; // #$0590..#$05FF:
#1792..#1871: SetSyriac; // #$0700..#$074F:
#7936..#8191: SetGreek; // #$1F00..#$1FFF, // modern greek
#0880..#1023: SetGreek; // #$0370..#$03FF: // ancient greek and coptic
#0033..#0126: SetEnglish; // #$0021..#$007E: // exclamation to tilde
//#$-8960..#$-8939: SetPhoenician; // #$10900..#$1091F // #67840..#67871 // #-10238, #-8960..#-8939
else begin
SetEnglish; // not in list
end;
(*
Since a Phoenician character occupies more than a single widechar,
you'll need to make your case statement more complex.
!!! That double character messes up cursor count. Phoenician is a NoGo. !!!
#$0590..#$05FF: SetHebrew; // lang:='hebrew';
#$0700..#$074F: SetSyriac; // lang:='syriac';
#$1F00..#$1FFF, // this is modern greek
#$0370..#$03FF: // this is greek and coptic
SetGreek; // this is either
#$0020..#$007F: SetEnglish;
else SetEnglish;
*)
end;
end else if (PageMemo.SelLength=0) then SetEnglish; // no text available or none selected
case W1 of
// non-visual and special keys
#0011: Str1:= 'Soft-Break'; // Generic Keys
#0013: Str1:= 'Hard-Break';
#0009: Str1:= 'Tab';
#0032: Str1:= 'Space';
#0160: Str1:= 'Lock-Space';
#8209: Str1:= 'Lock-Hyphen';
#8212: Str1:= 'Long-Dash';
#8226: Str1:= 'Bullet';
// Hebrew Vowels
#1456: Str1:= 'Swa';
#1457: Str1:= 'Xtf-Sgl';
#1458: Str1:= 'Xtf-Ptx';
#1459: Str1:= 'Xtf-Qmz';
#1460: Str1:= 'Xrq';
#1461: Str1:= 'Zre';
#1462: Str1:= 'Sgl';
#1463: Str1:= 'Ptx';
#1464: Str1:= 'Qmz';
#1465: Str1:= 'Xlm';
#1466: Str1:= 'Xlm-Gdl';
#1467: Str1:= 'Qbz';
#1468: Str1:= 'Dgs';
#1469: Str1:= 'Mtg';
// Syriac Vowels Western
#1840,#1841: Str1:= 'Ptx';
#1843,#1844: Str1:= 'Zqp | Qmz';
#1846,#1847: Str1:= 'Rbs | Zre';
#1850,#1851: Str1:= 'Xbz | Xrq';
#1853,#1854: Str1:= 'Eza | Qbz';
// Syriac Vowels Eastern
#1842: Str1:= 'Ptx'; // a
#1845: Str1:= 'Zqp | Qmz'; // o
#1848: Str1:= 'Zlm | Rbs | Zre'; // e
#1849: Str1:= 'Zlm | Hbs | Xrq'; // i
#1855: Str1:= 'Rwa | Eza | Xlm'; // v
#1852: Str1:= 'Qbz'; // u
// Syriac Accents
#1856: Str1:= 'Feminine Marker'; // @
#1857: Str1:= 'Hard Accent'; // #
#1858: Str1:= 'Soft Accent'; // $
#1863,#1864: Str1:= 'Silent Marker'; // ~ `
// Greek Accents
#8189: Str1:= 'Acute Accent';
#8128: Str1:= 'Flex Accent';
#8175: Str1:= 'Grave Accent';
#8127: Str1:= 'Rough Accent';
#8190: Str1:= 'Smooth Accent';
#0900: Str1:= 'Tonos Accent';
end; //else Str1:= 'U+'+IntToStr(Word(WC)); // +IntToHex(Word(WC),4); end;
//Str1:= 'U+'+IntToStr(Word(WC));
if (Str1<>'') then Str1:= ': '+Str1;
CmdForm.caption:= CmdForm.caption+Str1; // needs single font with all languages
end;