home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / spezial / 20 / win_txl / winprocs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-12  |  14.3 KB  |  368 lines

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