home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / fonts / cw_src / altexe / dlg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  7.7 KB  |  317 lines

  1. #define        NOVIRTUALKEYCODES
  2. #define        NOMINMAX
  3. #include    "c:\windev\include\windows.h"
  4.  
  5. #include    "hello.h"
  6. #include    "c:\windev\include\string.h"
  7. #include    "c:\windev\include\stdlib.h"
  8.  
  9. extern    HANDLE    hInst;
  10. extern    HWND    hMainWnd;
  11. extern    HWND    hMainDlg;
  12. extern  int    bLAT;
  13. extern  char     szAppName[];
  14. extern  int     wasEdited;
  15.  
  16. char sk[]= "SKEYB";
  17. char lk[]= "LKEYB";
  18. char de[]= ".kbd";
  19. FARPROC lpDlgProc;
  20.  
  21. BOOL FAR PASCAL kDlg();
  22. BOOL FAR PASCAL lDlg();
  23.  
  24. void FAR PASCAL LTable(LPSTR);
  25. void         SetKeys();
  26. int        filopen(PSTR, WORD);
  27. int        filwrite(int);
  28. int        filread(int);
  29.  
  30.  
  31. #define     KTABLESIZE    (72*4)
  32. extern char    kTable[KTABLESIZE];
  33.  
  34. char vk_t[]= {
  35. VK_OEM_1,VK_OEM_PLUS,VK_OEM_COMMA,VK_OEM_MINUS,VK_OEM_PERIOD,VK_OEM_2,VK_OEM_3,
  36. VK_OEM_4,VK_OEM_5,VK_OEM_6,VK_OEM_7,VK_OEM_8,
  37.  
  38. VK_0        ,VK_1        ,VK_2        ,VK_3        ,VK_4        ,VK_5        ,
  39. VK_6        ,VK_7        ,VK_8        ,VK_9        ,
  40. VK_A        ,VK_B        ,VK_C        ,VK_D        ,VK_E        ,VK_F        ,
  41. VK_G        ,VK_H        ,VK_I        ,VK_J        ,VK_K        ,VK_L        ,
  42. VK_M        ,VK_N        ,VK_O        ,VK_P        ,VK_Q        ,VK_R        ,
  43. VK_S        ,VK_T        ,VK_U        ,VK_V        ,VK_W        ,VK_X        ,
  44. VK_Y        ,VK_Z        ,0
  45. };
  46.  
  47. char vk_names[]= {
  48. ';', '=', ',', '-', '.', '/', '`',
  49. '[', '\\', ']', '\'', '?',
  50.  
  51. '0', '1', '2', '3', '4', '5',
  52. '6', '7', '8', '9',
  53. 'A', 'B', 'C', 'D', 'E', 'F',
  54. 'G', 'H', 'I', 'J', 'K', 'L',
  55. 'M', 'N', 'O', 'P', 'Q', 'R',
  56. 'S', 'T', 'U', 'V', 'W', 'X',
  57. 'Y', 'Z', '?' };
  58.  
  59. char buff[3]= { 0, 0, 0 };
  60. extern HWND hkDlg= NULL;
  61.  
  62. void
  63. KeybSet        (void)
  64. {
  65.     lpDlgProc= MakeProcInstance(kDlg, hInst);
  66.     DialogBox(hInst, (LPSTR)sk, hMainWnd, lpDlgProc);
  67.     hMainDlg= hkDlg= NULL;
  68.     FreeProcInstance(lpDlgProc);
  69. }
  70.  
  71. char        w_path[132];
  72. char        s_path[256];
  73. char         l_name[13]= "cyrillic.kbd";
  74.  
  75. int    bNoTrs= 0;
  76. int    FAR PASCAL EnumFunc (LPLOGFONT, LPTEXTMETRIC, short, LPSTR);
  77. BOOL    FAR PASCAL SelectFont (HWND, unsigned, WORD, LONG);
  78. int    _lstrlen (LPSTR);
  79. void    _lstrncpy (LPSTR, LPSTR, int);
  80. void    _lstrcpy (LPSTR, LPSTR);
  81. BOOL    bChanged= FALSE;
  82.  
  83. #define    MAXSIZE        20
  84. #define    MAXFONT        20
  85.  
  86. extern    char FontList [MAXFONT][32];
  87. extern    char SizeList [MAXSIZE];
  88. extern    BYTE CharSet[MAXFONT];
  89. extern    BYTE PitchAndFamily[MAXFONT];
  90. extern    int FontIndex;
  91. extern    int SizeIndex;
  92. extern    int CurrentFont;
  93. extern    int CurrentSize;
  94. extern    char szFont[];
  95.  
  96. HFONT    hFont= NULL;
  97.  
  98. int shiftstate= 0;
  99. int    v= VK_Q;
  100. char vasc;
  101. int vtb;
  102.  
  103. int    dstate= 0;
  104.  
  105. BOOL FAR PASCAL
  106. lDlg        (hDlg, message, wParam, lParam)
  107. HWND        hDlg;
  108. unsigned    message;
  109. WORD        wParam;
  110. LONG        lParam;
  111. {
  112.     WORD    w;
  113.     int    i;
  114.     short    flabel;
  115.     FARPROC    lpFunc;
  116.     char    mess [10];
  117.     RECT    r;
  118.  
  119.     hMainDlg= hDlg;
  120.     switch (message) {
  121.     case WM_COMMAND:
  122.         switch (wParam) {
  123.         case IDD_HELP:
  124.             WinHelp (hDlg, "CYRWIN.HLP", HELP_CONTEXT, 100);
  125.             break;
  126.         case 1:
  127.             switch(dstate) {
  128.             case 1:
  129.                 PostMessage(hDlg, WM_COMMAND, IDL_ACCEPT, 0L);
  130.                 break;
  131.             case 2:
  132.                 PostMessage(hDlg, WM_COMMAND, IDL_OK, 0L);
  133.                 break;
  134.             }
  135.             break;
  136.         case 2:
  137.             PostMessage(hDlg, WM_COMMAND, IDL_CANCEL, 0L);
  138.             break;
  139.         case IDL_OK:
  140.             LTable(kTable);
  141.             EndDialog(hDlg, NULL);
  142.             return TRUE;
  143.         case IDL_LOAD:            // Save now !!!
  144. dook:
  145.             flabel= filopen(s_path, OF_WRITE);
  146.             if (flabel < 0)
  147.                 break;
  148.             if (filwrite(flabel))
  149.             _lclose(flabel);
  150.             LTable(kTable);
  151.             bChanged= FALSE;
  152.             break;
  153.         case IDL_CANCEL:
  154.             wasEdited--;
  155.             bChanged= FALSE;
  156.             flabel= filopen(s_path, OF_READ);
  157.             filread (flabel);
  158.             _lclose (flabel);
  159.             EndDialog(hDlg, NULL);
  160.             return TRUE;
  161.         case IDL_TRS:
  162.             CheckDlgButton (hDlg, IDL_TRS, bNoTrs);
  163.             bNoTrs ^= 1;
  164.             vasc= GetKeyName(v);
  165.             buff [0]= vasc;
  166.             SetDlgItemText(hDlg, IDL_VEDIT, buff);
  167.             SetDlgItemInt(hDlg, IDL_VINT, vasc, FALSE);
  168.             SetScrollPos(GetDlgItem(hDlg, IDL_SCROLL), SB_CTL, vasc, TRUE);
  169.             if (bNoTrs) {
  170.                 EnableWindow (GetDlgItem (hDlg, IDL_ACCEPT), FALSE);
  171.                 EnableWindow (GetDlgItem (hDlg, IDL_SCROLL), FALSE);
  172.             } else {
  173.                 EnableWindow (GetDlgItem (hDlg, IDL_ACCEPT), TRUE);
  174.                 EnableWindow (GetDlgItem (hDlg, IDL_SCROLL), TRUE);
  175.             }
  176.             SetKeys (hDlg);
  177.             break;
  178.         case IDL_SELF:
  179.             lpFunc= MakeProcInstance(SelectFont, hInst);
  180.             i= DialogBox(hInst, "SELFONT", hDlg, lpFunc);
  181.             FreeProcInstance(lpFunc);
  182. //            if (hFont != GetStockObject (SYSTEM_FIXED_FONT))
  183. //                DeleteObject (hFont);
  184.             if (i)
  185.                 {
  186.                 DeleteObject (hFont);
  187.                 GetClientRect (GetDlgItem(hDlg, VK_0), (LPRECT) &r);
  188.                 hFont= CreateFont (
  189.                     r.bottom * 2 / 3 /* SizeList [CurrentSize] */,
  190.                     0, 0, 0,
  191.                     FW_NORMAL,
  192.                     FALSE,
  193.                     FALSE,
  194.                     FALSE,
  195.                     CharSet [CurrentFont],
  196.                     OUT_DEFAULT_PRECIS,
  197.                     CLIP_DEFAULT_PRECIS,
  198.                     PROOF_QUALITY,
  199.                     PitchAndFamily [CurrentFont],
  200.                     FontList [CurrentFont]
  201.                 );
  202.                 SetDlgItemText (hDlg, IDL_FONTNAME, FontList [CurrentFont]);
  203.                 SetFonts (hDlg, hFont);
  204.                 WriteProfileString (szAppName, szFont, itoa (CurrentFont+1, mess, 10));
  205.                 }
  206. //            else
  207. //                {
  208. //                CurrentFont= 0;
  209. //                hFont= GetStockObject (SYSTEM_FIXED_FONT);
  210. //                SetDlgItemText (hDlg, IDL_FONTNAME, "System fixed");
  211. //                }
  212. //            SetFonts (hDlg, hFont);
  213.             break;
  214.         case IDL_SHIFT:
  215.             shiftstate ^= 1;
  216.             CheckDlgButton(hDlg, IDL_SHIFT, shiftstate);
  217.             SetKeys(hDlg);
  218.             /*
  219.             if (!bNoTrs) {
  220.                 vasc= CyrTrs(v, shiftstate);
  221.             } else {
  222.                 vasc= v;
  223.             }
  224.             buff[0]= vasc;
  225.             */
  226.             vasc= GetKeyName(v);
  227.             buff [0]= vasc;
  228.             SetDlgItemText(hDlg, IDL_VEDIT, buff);
  229.             SetDlgItemInt(hDlg, IDL_VINT, vasc, FALSE);
  230.             SetScrollPos(GetDlgItem(hDlg, IDL_SCROLL), SB_CTL, vasc, TRUE);
  231.             break;
  232.         case IDL_ACCEPT:
  233. acckey:
  234.             dstate= 2;
  235.             CyrWrite(v, vasc, shiftstate);
  236.             buff[0]= vasc; buff [1]= 0;
  237.             SetDlgItemText(hDlg, v, buff);
  238.             bChanged= TRUE;
  239.             break;
  240.         default:                     /* key pressed */
  241.             if ((w= mystrchr(vk_t, wParam)) >= 0) {
  242.                 dstate= 1;
  243.                 v= wParam;
  244.                 //vasc= CyrTrs(v, shiftstate);
  245.                 vasc= GetKeyName(v);
  246.                 buff[0]= vk_names[w];
  247.                 SetDlgItemText(hDlg, IDL_KNAME, buff);
  248.                 buff[0]= vasc;
  249.                 SetDlgItemText(hDlg, IDL_VEDIT, buff);
  250.                 SetDlgItemInt(hDlg, IDL_VINT, vasc, FALSE);
  251.                 SetScrollPos(GetDlgItem(hDlg, IDL_SCROLL), SB_CTL, vasc, TRUE);
  252.                 SetFocus (GetDlgItem (hDlg, IDL_SCROLL));
  253.             }
  254.         }
  255.         break;
  256.     case WM_HSCROLL:
  257.         dstate= 1;
  258.         switch (wParam) {
  259.         case SB_LINEUP:
  260.             if (vasc > 32) vasc--;         break;
  261.         case SB_LINEDOWN:
  262.             if ((int)vasc < 255) vasc++;     break;
  263.         case SB_PAGEUP:
  264.             if (vasc >= 42) vasc-= 10;     break;
  265.         case SB_PAGEDOWN:
  266.             if (vasc <= 245) vasc+= 10;     break;
  267.         case SB_THUMBTRACK:
  268.         case SB_THUMBPOSITION:
  269.             vasc= LOWORD(lParam);         break;
  270.         }
  271.         SetScrollPos(GetDlgItem(hDlg, IDL_SCROLL), SB_CTL, (int)vasc, TRUE);
  272.         buff[0]= vasc;
  273.         SetDlgItemText(hDlg, IDL_VEDIT, buff);
  274.         SetDlgItemInt(hDlg, IDL_VINT, vasc, FALSE);
  275.         break;
  276.     case WM_TIMER:
  277.         shiftstate= 0;
  278.         dstate= wasEdited= 1;
  279.         bNoTrs= FALSE;
  280.         CheckDlgButton (hDlg, IDL_TRS, TRUE);
  281.         GetFonts (hDlg);
  282. //        hFont= GetStockObject (SYSTEM_FIXED_FONT);
  283.         GetClientRect (GetDlgItem(hDlg, VK_0), (LPRECT) &r);
  284.         hFont= CreateFont (
  285.             r.bottom * 2 / 3 /* SizeList [CurrentSize] */,
  286.             0, 0, 0,
  287.             FW_NORMAL,
  288.             FALSE,
  289.             FALSE,
  290.             FALSE,
  291.             CharSet [CurrentFont],
  292.             OUT_DEFAULT_PRECIS,
  293.             CLIP_DEFAULT_PRECIS,
  294.             PROOF_QUALITY,
  295.             PitchAndFamily [CurrentFont],
  296.             FontList [CurrentFont]
  297.         );
  298.         SetDlgItemText (hDlg, IDL_FONTNAME, FontList [CurrentFont]);
  299.         SetFonts (hDlg, hFont);
  300.         EnableWindow(GetDlgItem(hDlg, VK_TAB), FALSE);
  301.         for (i= IDL_SHIFT0; i<= IDL_CAPS; i++)
  302.             EnableWindow(GetDlgItem(hDlg, i), FALSE);
  303.         SetScrollRange(GetDlgItem(hDlg, IDL_SCROLL), SB_CTL, 32, 255, 1);
  304.         SetDlgItemText(hDlg, IDL_NAME, l_name);
  305.         SetKeys(hDlg);
  306.         PostMessage(hDlg, WM_COMMAND, v, 0L);
  307.         SetFocus(GetDlgItem(hDlg, IDL_OK));
  308.         break;
  309.     case WM_INITDIALOG:
  310.         PostMessage(hDlg, WM_TIMER, 0, 0L);    // crazy Windows !
  311.         break;
  312.     }
  313.     return FALSE;
  314. }
  315.  
  316. /* *** */
  317.