home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1991 / 04 / txl / 1_preis / winprocs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-28  |  11.3 KB  |  404 lines

  1. /************************************************************************
  2. *                .......................................                *
  3. *                .                                     .                *
  4. *                .       TOOLBOX - INTERPRETER         .                *
  5. *                .      CALLBACK - FUNKTIONEN          .                *
  6. *                .          WINPROCS.C                 .                *
  7. *                .......................................                *
  8. *************************************************************************/
  9.  
  10. #include <windows.h>
  11. #include "kubasic.h"
  12.  
  13. BOOL FAR PASCAL TypeHelp(HWND, unsigned, WORD, LONG);
  14. BOOL FAR PASCAL SetTextBox(HWND, unsigned, WORD, LONG);
  15. BOOL FAR PASCAL HelpBox(HWND, unsigned, WORD, LONG);
  16. BOOL FAR PASCAL Input(HWND, unsigned, WORD, LONG);
  17. HANDLE FAR PASCAL OpenDlg(HWND, unsigned, WORD, LONG);
  18.  
  19. void UpdateListBox(HWND);
  20. void SeparateFile(HWND, LPSTR, LPSTR, LPSTR);
  21. void AddExt(PSTR, PSTR);
  22. void ChangeDefExt(PSTR, PSTR);
  23. int _lstrlen(LPSTR);
  24. void _lstrncpy(LPSTR, LPSTR, int);
  25. void _lstrcpy(LPSTR, LPSTR);
  26.  
  27. extern int TORIENT,TESCP,TOutP,TCliP,TQual,TFam,oem;
  28. extern unsigned char Textstr[256];
  29. extern unsigned char Questr[200];
  30. extern char FileName[FNAMLEN];
  31. extern BOOL LoadFile;
  32.  
  33. char DefPath[128];
  34. char DefSpec[13] = "*.TXL";                    /* default search spec        */
  35. char DefExt[] =     ".TXL";                    /* default extension          */
  36. char str[255];
  37.  
  38.  
  39. BOOL FAR PASCAL Input(hDlg, message, wParam, lParam)
  40. HWND hDlg;
  41. unsigned message;
  42. WORD wParam;
  43. LONG lParam;
  44. {
  45.     switch (message) {
  46.     case WM_INITDIALOG:
  47.         SendDlgItemMessage(hDlg,MN_TEXT,EM_LIMITTEXT,256,0L);
  48.         strcpy(Textstr,"?");
  49.         SetDlgItemText(hDlg,MN_QUESTION,(LPSTR)Questr);
  50.         SetDlgItemText(hDlg,MN_TEXT,(LPSTR)Textstr);
  51.         return (TRUE);
  52.     case WM_COMMAND:
  53.         if (wParam == IDOK) {
  54.         GetDlgItemText(hDlg,MN_TEXT,(LPSTR)Textstr,256);
  55.            EndDialog(hDlg, NULL);
  56.         return (TRUE);
  57.         }
  58.         break;
  59.     }
  60.     return (FALSE);                           /* Didn't process a message    */
  61. }
  62.  
  63. BOOL FAR PASCAL About( hDlg, message, wParam, lParam )
  64. HWND hDlg;
  65. unsigned message;
  66. WORD wParam;
  67. LONG lParam;
  68. {
  69.     if (message == WM_COMMAND) {
  70.     EndDialog( hDlg, TRUE );
  71.     return TRUE;
  72.     }
  73.     else if (message == WM_INITDIALOG)
  74.     return TRUE;
  75.     else return FALSE;
  76. }
  77.  
  78. BOOL FAR PASCAL TypeHelp(hDlg, message, wParam, lParam)
  79. HWND hDlg;
  80. unsigned message;
  81. WORD wParam;
  82. LONG lParam;
  83. {
  84.  HWND hCtrl;
  85.     switch (message) {
  86.     case WM_INITDIALOG:
  87.         return (TRUE);
  88.     case WM_COMMAND:
  89.         if(wParam==IDOK)
  90.          {
  91.               EndDialog(hDlg, NULL);
  92.               return (TRUE);
  93.          }
  94.         break;
  95.     }
  96.     return (FALSE);
  97. }
  98.  
  99. BOOL FAR PASCAL SetTextBox(hDlg, message, wParam, lParam)
  100. HWND hDlg;
  101. unsigned message;
  102. WORD wParam;
  103. LONG lParam;
  104. {
  105.  HWND hCtrl;
  106. int fam;
  107.     switch (message) {
  108.     case WM_INITDIALOG:
  109.                CheckDlgButton(hDlg,MW_OEM,FALSE);
  110.                CheckDlgButton(hDlg,MW_ANSI,FALSE);
  111.          (oem==255) ? (CheckDlgButton(hDlg,MW_OEM,TRUE)) :
  112.               (CheckDlgButton(hDlg,MW_ANSI,TRUE));
  113.                fam=TOutP+136;
  114.                  CheckDlgButton(hDlg,OP_DEF,FALSE);
  115.                  CheckDlgButton(hDlg,OP_CHAR,FALSE);
  116.                  CheckDlgButton(hDlg,OP_STRING,FALSE);
  117.                  CheckDlgButton(hDlg,OP_STROKE,FALSE);
  118.                  CheckDlgButton(hDlg,fam,TRUE);
  119.               fam=TCliP+140;
  120.                  CheckDlgButton(hDlg,CL_DEF,FALSE);
  121.                  CheckDlgButton(hDlg,CL_CHAR,FALSE);
  122.                  CheckDlgButton(hDlg,CL_STROKE,FALSE);
  123.                  CheckDlgButton(hDlg,fam,TRUE);
  124.                fam=TQual+143;
  125.                  CheckDlgButton(hDlg,QU_DEF,FALSE);
  126.                  CheckDlgButton(hDlg,QU_DRAFT,FALSE);
  127.                  CheckDlgButton(hDlg,QU_PROOF,FALSE);
  128.                  CheckDlgButton(hDlg,fam,TRUE);
  129.                fam=TFam/10+145;
  130.                  CheckDlgButton(hDlg,FA_DEF,FALSE);
  131.                  CheckDlgButton(hDlg,FA_FIX,FALSE);
  132.                  CheckDlgButton(hDlg,FA_VAR,FALSE);
  133.                  CheckDlgButton(hDlg,fam,TRUE);
  134.                fam=TFam % 10;
  135.                fam+=149;
  136.                  CheckDlgButton(hDlg,FA_SWS,FALSE);
  137.                  CheckDlgButton(hDlg,FA_SCR,FALSE);
  138.                  CheckDlgButton(hDlg,FA_ROM,FALSE);
  139.                  CheckDlgButton(hDlg,FA_MOD,FALSE);
  140.                  CheckDlgButton(hDlg,FA_DEC,FALSE);
  141.                  CheckDlgButton(hDlg,FA_DNTC,FALSE);
  142.                  CheckDlgButton(hDlg,fam,TRUE);
  143.               fam=0;
  144.  
  145.         return (TRUE);
  146.         break;
  147.     case WM_COMMAND:
  148.         switch(wParam)
  149.          {
  150.          case IDOK:
  151.               EndDialog(hDlg, NULL);
  152.               return (TRUE);
  153.           break;
  154.          case OP_DEF:    TOutP=0;
  155.          case OP_CHAR:   if(wParam==OP_CHAR)   TOutP=1;
  156.          case OP_STRING: if(wParam==OP_STRING) TOutP=2;
  157.          case OP_STROKE: if(wParam==OP_STROKE) TOutP=3;
  158.                fam=TOutP+136;
  159.                  CheckDlgButton(hDlg,OP_DEF,FALSE);
  160.                  CheckDlgButton(hDlg,OP_CHAR,FALSE);
  161.                  CheckDlgButton(hDlg,OP_STRING,FALSE);
  162.                  CheckDlgButton(hDlg,OP_STROKE,FALSE);
  163.                  CheckDlgButton(hDlg,fam,TRUE);
  164.               fam=0;
  165.              break;
  166.          case CL_DEF:   TCliP=0;
  167.          case CL_CHAR:   if(wParam==CL_CHAR)   TCliP=1;
  168.          case CL_STROKE: if(wParam==CL_STROKE) TCliP=2;
  169.               fam=TCliP+140;
  170.                  CheckDlgButton(hDlg,CL_DEF,FALSE);
  171.                  CheckDlgButton(hDlg,CL_CHAR,FALSE);
  172.                  CheckDlgButton(hDlg,CL_STROKE,FALSE);
  173.                  CheckDlgButton(hDlg,fam,TRUE);
  174.               fam=0;
  175.              break;
  176.          case QU_DEF:    TQual=0;
  177.          case QU_DRAFT:  if(wParam==QU_DRAFT) TQual=1;
  178.          case QU_PROOF:  if(wParam==QU_PROOF) TQual=2;
  179.                fam=TQual+143;
  180.                  CheckDlgButton(hDlg,QU_DEF,FALSE);
  181.                  CheckDlgButton(hDlg,QU_DRAFT,FALSE);
  182.                  CheckDlgButton(hDlg,QU_PROOF,FALSE);
  183.                  CheckDlgButton(hDlg,fam,TRUE);
  184.                 fam=0;
  185.              break;
  186.          case FA_DEF:   TFam=10;
  187.          case FA_FIX:   if(wParam==FA_FIX) TFam=20;
  188.          case FA_VAR:   if(wParam==FA_VAR) TFam=30;
  189.                  fam=(TFam/10)+145;
  190.                  CheckDlgButton(hDlg,FA_DEF,FALSE);
  191.                  CheckDlgButton(hDlg,FA_FIX,FALSE);
  192.                  CheckDlgButton(hDlg,FA_VAR,FALSE);
  193.                  CheckDlgButton(hDlg,fam,TRUE);
  194.          case FA_DNTC: fam=0;
  195.          case FA_DEC: if(wParam==FA_DEC) fam=1;
  196.          case FA_MOD: if(wParam==FA_MOD) fam=2;
  197.          case FA_ROM: if(wParam==FA_ROM) fam=3;
  198.          case FA_SCR: if(wParam==FA_SCR) fam=4;
  199.          case FA_SWS: if(wParam==FA_SWS) fam=5;
  200.             TFam /= 10;
  201.             TFam *= 10;
  202.             TFam += fam;
  203.             fam+=149;
  204.                  CheckDlgButton(hDlg,FA_SWS,FALSE);
  205.                  CheckDlgButton(hDlg,FA_SCR,FALSE);
  206.                  CheckDlgButton(hDlg,FA_ROM,FALSE);
  207.                  CheckDlgButton(hDlg,FA_MOD,FALSE);
  208.                  CheckDlgButton(hDlg,FA_DEC,FALSE);
  209.                  CheckDlgButton(hDlg,FA_DNTC,FALSE);
  210.                  CheckDlgButton(hDlg,fam,TRUE);
  211.             fam=0;
  212.           break;
  213.          case MW_OEM: oem=255;
  214.          case MW_ANSI:if(wParam==MW_ANSI) oem=0;
  215.                  CheckDlgButton(hDlg,MW_OEM,FALSE);
  216.                  CheckDlgButton(hDlg,MW_ANSI,FALSE);
  217.          (oem==255) ? (CheckDlgButton(hDlg,MW_OEM,TRUE)) :
  218.               (CheckDlgButton(hDlg,MW_ANSI,TRUE));
  219.           break;
  220.          }
  221.         break;
  222.     }
  223.     return (FALSE);
  224. }
  225.  
  226.  
  227. BOOL FAR PASCAL HelpBox(hDlg, message, wParam, lParam)
  228. HWND hDlg;
  229. unsigned message;
  230. WORD wParam;
  231. LONG lParam;
  232. {
  233.  HWND hCtrl;
  234.     switch (message) {
  235.     case WM_INITDIALOG:
  236.         return (TRUE);
  237.     case WM_COMMAND:
  238.         if(wParam==IDOK)
  239.          {
  240.               EndDialog(hDlg, NULL);
  241.               return (TRUE);
  242.          }
  243.         break;
  244.     }
  245.     return (FALSE);
  246. }
  247.  
  248. HANDLE FAR PASCAL OpenDlg(hDlg, message, wParam, lParam)
  249. HWND hDlg;
  250. unsigned message;
  251. WORD wParam;
  252. LONG lParam;
  253. {
  254.     WORD index;                    /* index to the filenames in the list box */
  255.     PSTR pTptr;                    /* temporary pointer                      */
  256.     HANDLE hFile;                  /* handle to the opened file              */
  257.  
  258.     switch (message) {
  259.     case WM_COMMAND:
  260.         switch (wParam) {
  261.  
  262.         case ID_LISTBOX:
  263.             switch (HIWORD(lParam)) {
  264.             case LBN_SELCHANGE:
  265.                 if (!DlgDirSelect(hDlg, str, ID_LISTBOX)) {
  266.                 SetDlgItemText(hDlg, ID_EDIT, str);
  267.                 SendDlgItemMessage(hDlg, ID_EDIT, EM_SETSEL,
  268.                     NULL, MAKELONG(0, 0x7fff));
  269.                 }
  270.                 else {
  271.                 strcat(str, DefSpec);
  272.                 DlgDirList(hDlg, str, ID_LISTBOX,
  273.                     ID_PATH, 0x4010);
  274.                 }
  275.                 break;
  276.             case LBN_DBLCLK:
  277.                 goto openfile;
  278.             }                                /* Ends ID_LISTBOX case */
  279.             return(TRUE);
  280.  
  281.         case IDOK:
  282. openfile:
  283.             GetDlgItemText(hDlg, ID_EDIT, FileName, 128);
  284.             if (strchr(FileName, '*') || strchr(FileName, '?')) {
  285.             SeparateFile(hDlg, (LPSTR) str, (LPSTR) DefSpec,
  286.                 (LPSTR) FileName);
  287.             if (str[0])
  288.                 strcpy(DefPath, str);
  289.             ChangeDefExt(DefExt, DefSpec);
  290.             UpdateListBox(hDlg);
  291.             return(TRUE);
  292.             }
  293.             if (!FileName[0]) {
  294.             PRINTF ("# no Filename #");
  295.             LoadFile = FALSE;
  296.             return(TRUE);
  297.             } else LoadFile = TRUE;
  298.  
  299.             AddExt(FileName, DefExt);
  300.  
  301.             EndDialog(hDlg, NULL);
  302.             return(TRUE);
  303.  
  304.         case IDCANCEL:
  305.             LoadFile = FALSE;
  306.             EndDialog(hDlg, NULL);
  307.             return(TRUE);
  308.         }
  309.         break;
  310.  
  311.     case WM_INITDIALOG:                        /* Request to initalize   */
  312.         UpdateListBox(hDlg);
  313.         SetDlgItemText(hDlg, ID_EDIT, DefSpec);
  314.         SendDlgItemMessage(hDlg,               /* dialog handle          */
  315.         ID_EDIT,                           /* where to send message  */
  316.         EM_SETSEL,                         /* select characters      */
  317.         NULL,                              /* additional information */
  318.         MAKELONG(0, 0x7fff));              /* Accept entire contents */
  319.  
  320.         SetFocus(GetDlgItem(hDlg, ID_EDIT));
  321.         return (FALSE);       /* Indicates the focus is set to a control */
  322.     }
  323.     return FALSE;
  324. }
  325.  
  326. void UpdateListBox(hDlg)
  327. HWND hDlg;
  328. {
  329.     strcpy(str, DefPath);
  330.     strcat(str, DefSpec);
  331.     DlgDirList(hDlg, str, ID_LISTBOX, ID_PATH, 0x4010);
  332.     SetDlgItemText(hDlg, ID_EDIT, DefSpec);
  333. }
  334.  
  335. void ChangeDefExt(Ext, Name)
  336. PSTR Ext, Name;
  337. {
  338.     PSTR pTptr;
  339.  
  340.     pTptr = Name;
  341.     while (*pTptr && *pTptr != '.')
  342.     pTptr++;
  343.     if (*pTptr)                              /* true if this is an extension */
  344.     if (!strchr(pTptr, '*') && !strchr(pTptr, '?'))
  345.         strcpy(Ext, pTptr);              /* Copies the extension         */
  346. }
  347.  
  348. void SeparateFile(hDlg, lpDestPath, lpDestFileName, lpSrcFileName)
  349. HWND hDlg;
  350. LPSTR lpDestPath, lpDestFileName, lpSrcFileName;
  351. {
  352.     LPSTR lpTmp;
  353.  
  354.     lpTmp = lpSrcFileName + (long) _lstrlen(lpSrcFileName);
  355.  
  356.     while (*lpTmp != ':' && *lpTmp != '\\' && lpTmp > lpSrcFileName)
  357.     lpTmp = AnsiPrev(lpSrcFileName, lpTmp);
  358.  
  359.     if (*lpTmp != ':' && *lpTmp != '\\') {
  360.     _lstrcpy(lpDestFileName, lpSrcFileName);
  361.     lpDestPath[0] = 0;
  362.     return;
  363.     }
  364.  
  365.     _lstrcpy(lpDestFileName, lpTmp + 1L);
  366.     _lstrncpy(lpDestPath, lpSrcFileName, (int) (lpTmp - lpSrcFileName) + 1);
  367.     lpDestPath[(lpTmp - lpSrcFileName) + 1] = 0;
  368. }
  369.  
  370. void AddExt(Name, Ext)
  371. PSTR Name, Ext;
  372. {
  373.     PSTR pTptr;
  374.  
  375.     pTptr = Name;
  376.     while (*pTptr && *pTptr != '.')
  377.     pTptr++;
  378.     if (*pTptr != '.')                   /* If no extension, add the default */
  379.     strcat(Name, Ext);
  380. }
  381.  
  382. int _lstrlen(lpString)
  383. LPSTR lpString;
  384. {
  385.     int i;
  386.     for (i=0; *lpString++; ++i);
  387.     return (i);
  388. }
  389.  
  390. void _lstrncpy(lpDest, lpSrc, n)
  391. LPSTR lpDest, lpSrc;
  392. int n;
  393. {
  394.     while (n--)
  395.     if (!(*lpDest++ = *lpSrc++))
  396.         return;
  397. }
  398.  
  399. void _lstrcpy(lpDestination, lpSource)
  400. LPSTR lpDestination, lpSource;
  401. {
  402.     while (*lpDestination++ = *lpSource++);
  403. }
  404.