$Macro MapKey;
{********************************************************************
  В окне KEYBOARD выводит упорядоченную информацию о клавиатурной раскладке.
  Переделка известного макроса В.Соколинского   (см. SoftPanorama 3.4)
    под Multi-Edit 5.00
  Несколько исправлений: Бунич Л.Г.  ноябрь 1991
********************************************************************}
  def_int(c, jx, im, te, res, keymap_window, mapkey_window,
                  default_window, q1, q2, perc, i, j);
  def_str(ext, key, s_str, whole_line, descrip, mf,mn,
                  prim_key, alt_key,  dir_line[61]);

  Make_Message('Построение файла KEYBOARD');
    Undo_Stat := False;
    te := Tab_Expand;    Tab_Expand := False;
    im := Insert_Mode;   Insert_Mode := True;
    res := Reg_Exp_Stat; Reg_Exp_Stat := 0;
    Refresh := False;

    { Run_Macro( 'SETUP^SETKEYS /M=2' ); }
    default_window := cur_window;

    Switch_Window(Window_Count);
    Create_Window;
    File_Name := ME_PATH + 'KEYBOARD';
    Mapkey_Window := Cur_Window;

  Put_Line('   ╔═════════════════════════════════════════════════════╗ ');
  Down;
  Put_Line('   ║ Использование клавиатуры в среде редактора ME 5.00P ║ ');
  Down;
  Put_Line('   ╚═════════════════════════════════════════════════════╝ ');
    Down;
    Down;
  Put_line('Ключ              Описание               Альтерн. ключ  МакроФайл МакроИмя ');
    EOL;  CR;  CR;  Up;


  dir_line := '──────────────────────────────────────────────────────────────────────';
  text(dir_line);
  CR;

  ext := '';
  call FUNC_DRAW;
  text(dir_line);
  cr;

  ext := 'Shft';
  call FUNC_DRAW;
  text(dir_line);
  cr;

  ext := 'Ctrl';
  call FUNC_DRAW;
  text(dir_line);
  cr;

  ext := 'Alt';
  call FUNC_DRAW;
  text(dir_line);
  cr;

  ext := '';
  call DIGIT_DRAW;
  text(dir_line);
  cr;

  ext := 'Shft';
  call DIGIT_DRAW;
  text(dir_line);
  cr;

  ext := 'Ctrl';
  call DIGIT_DRAW;
  text(dir_line);
  cr;

  ext := 'Alt';
  call DIGIT_DRAW;
  text(dir_line);
  cr;

  ext := '';       call GREY_DRAW;
  ext := 'Ctrl';   call GREY_DRAW;
  ext := 'Alt';    call GREY_DRAW;
  text(dir_line);
  cr;

  ext := '';
  key := 'ScrollLockOn';
  call DRAW;
  key := 'ScrollLockOff';
  call DRAW;
  key := 'ESC';
  call DRAW;
  ext := 'Alt';
  call DRAW;
  key := 'ENTER';
  ext := '';
  call DRAW;
  ext := 'Ctrl';
  call DRAW;
  ext := 'Alt';
  call DRAW;
  key := 'TAB';
  ext := '';
  call DRAW;
  ext := 'Shft';
  call DRAW;
  ext := 'Ctrl';
  call DRAW;
  ext := 'Alt';
  call DRAW;
  key := 'BS';
  ext := '';
  call DRAW;
  ext := 'Ctrl';
  call DRAW;
  ext := 'Alt';
  call DRAW;
  text(dir_line);
  cr;

  ext := 'Ctrl';
  key := '@';  call DRAW;
  key := '^';  call DRAW;
  key := '_';  call DRAW;
  key := '[';  call DRAW;
  key := '\';  call DRAW;
  key := ']';  call DRAW;
  CR;

  ext := 'Alt';
  jx := 0;
  while jx < 10 do
    key := str(jx);  call DRAW;
    ++jx;
  end;

  key := '''';  call DRAW;
  key := '`';   call DRAW;
  key := '-';   call DRAW;
  key := '=';   call DRAW;
  key := ';';   call DRAW;
  key := '/';   call DRAW;
  key := '<';   call DRAW;
  key := '>';   call DRAW;
  key := '?';   call DRAW;
  key := '[';   call DRAW;
  key := '\';   call DRAW;
  key := ']';   call DRAW;
  text(dir_line);
  cr;

  ext := 'Ctrl';
  jx := 65;
  while jx < 91 do
    key := char(jx);  call DRAW;
    ++jx;
  end;
  text(dir_line);
  cr;

  ext := 'Alt';
  jx := 65;
  while jx < 91 do
    key := char(jx);  call DRAW;
    ++jx;
  end;
  text(dir_line);
  cr;

  ext := '';
  key := 'MsUP';  call DRAW;
  key := 'MsDN';  call DRAW;
  key := 'MsLF';  call DRAW;
  key := 'MsRT';  call DRAW;
  key := 'Btn0';  call DRAW;
  key := 'Btn1';  call DRAW;
  key := 'Btn2';  call DRAW;

  Switch_Window(Window_Count);
  Create_Window;
  Load_file(ME_PATH + 'KEYMAP.DB');
  File_Name := ME_PATH + 'KEYMAP.ME';
  keymap_window := cur_window;
  {Switch_Window(Keymap_Window);}
  Eof;
  q2 := c_line;
  Tof;

Loop:
  whole_line := Get_Line;
  q1 := c_line;
  perc := q1 * 100 / q2 ;
  Make_Message('Построение файла KEYBOARD' + ' - ' + str(perc) + '%');

{  Tabs_To_Spaces(whole_line);}

  ext := copy(whole_line,2,4);
  if xpos('|254',ext,1)  <> 0 then
    goto while_loop;
  end;
{  --------------- это для МЕ версии 4.0 -------------
  descrip := remove_space(copy(whole_line, 20, 25));
  prim_key := remove_space(copy(whole_line, 46, 15));
  alt_key := remove_space(copy(whole_line, 62, 15));
  mode_key := remove_space(copy(whole_line, 85, 9)); }

    if xpos('MC',ext,1) > 0 then
      j := xpos('',Whole_line,5)-1;
      mn := copy(whole_line, 5, j-4);
    END;

    i := xpos('DESCR=',Whole_line,5);
    IF i = 0 THEN GoTo While_Loop; END;
    i := i+6;
    j := xpos('K',Whole_line,10);
    descrip := copy(whole_line, i, j-i);

    i := xpos('K1=',Whole_line,j-1);
    IF i = 0 THEN
        prim_key := '';
    ELSE
        ext := copy(whole_line,i+4,18);
        j := xpos('',ext,1)-1;
        prim_key :=  copy(ext, 1, j);
    END;

   i := xpos('K2=',Whole_line,j-1);
   IF (i = 0) THEN
     alt_key := '';
     ELSE
     ext := copy(whole_line,i+4,18);
     j := xpos('',ext,1)-1;
     alt_key :=  copy(ext, 1, j);
   END;

    i := xpos('MF=',Whole_line,j-1);
    IF (i = 0) THEN
        mf := '';
    ELSE
        ext := copy(whole_line,i+4,18);
        j := xpos('',ext,1)-1;
        mf :=  copy(ext, 1, j);
        IF (mf = 'NOT APPLICABLE') THEN
            mf := 'n/a';
        end;
    END;


    Switch_Window(Mapkey_Window);
    if (prim_key <> '') then
        s_str := prim_key;
        call INS_DESCRIP;
        if ( C_Line > 1 ) then
            goto_col(43);  text(alt_key);
            if (mf <> '') then
                goto_col(57);  text(mf);
                goto_col(67);  text(mn);
            end;
        end;
    end;
    if (alt_key <> '') then
        s_str := alt_key;
        call INS_DESCRIP;
        if( C_Line > 1 ) then
            goto_col(43);  text(prim_key);
            if (mf <> '') then
                goto_col(57);  text(mf);
                goto_col(67);  text(mn);
            end;
        end;
    end;
  Switch_Window(Keymap_Window);

WHILE_LOOP:
  down;
  if at_eof then
    delete_window;
    goto cancel;
  else
    goto loop;
  End;
{*****************************************************************************}


DRAW:
    text('<' + ext + key + '>');
    CR;
RET;


FUNC_DRAW:
    jx := 0;
    while jx < 12 do
        ++jx;
        key := 'F' + str(jx);
        call draw;
    end;
RET;


DIGIT_DRAW:
    key := 'LF';    call draw;
    key := 'RT';    call draw;
    key := 'UP';    call draw;
    key := 'DN';    call draw;
    key := 'PGUP';  call draw;
    key := 'PGDN';  call draw;
    key := 'HOME';  call draw;
    key := 'END';   call draw;
    key := 'INS';   call draw;
    key := 'DEL';   call draw;
    key := 'CNTR';  call draw;
RET;


GREY_DRAW:
    key := 'GREY/';     call draw;
    key := 'GREY*';     call draw;
    key := 'GREY-';     call draw;
    key := 'GREY+';     call draw;
    key := 'GREYENTER'; call draw;
RET;


INS_DESCRIP:
  TOF;
Repeat:
  if search_fwd(s_str,0) then
    if (c_col <> 1) then
      Down;  GoTo Repeat;
    end;
    if (remove_space(copy( GET_LINE, 17, 25)) <> '') then
      EOL; CR;
    end;
    goto_col(17);  text(descrip);
  end;
RET;


CANCEL:
    Undo_Stat := True;
    Tab_Expand := te;
    Insert_Mode := im;
    Reg_Exp_Stat := res;
    Refresh := True;

    Switch_Window(mapkey_Window);
    TOF;
End_Macro;
