home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / rexx / library2 / gbmrexx / gbmdlg / gbmdlg.c next >
C/C++ Source or Header  |  1993-08-04  |  5KB  |  203 lines

  1. /*
  2.  
  3. GBMDLG.C  File Open / File Save as dialogs for GBM
  4.  
  5. */
  6.  
  7. /*...sinclude:0:*/
  8. #define    INCL_BASE
  9. #define    INCL_DOS
  10. #define    INCL_WIN
  11. #define    INCL_GPI
  12. #define    INCL_DEV
  13. #define    INCL_BITMAPFILEFORMAT
  14. #include <os2.h>
  15.  
  16. #include <stdio.h>
  17. #include <stddef.h>
  18. #include <stdlib.h>
  19. #include <stdarg.h>
  20. #include <string.h>
  21. #include <memory.h>
  22.  
  23. #include "standard.h"
  24. #include "gbm.h"
  25. #define    _GBMDLG_
  26. #include "gbmdlg.h"
  27. #include "gbmdlgrc.h"
  28.  
  29. /*...vgbmdlg\46\h:0:*/
  30. /*...vgbmdlgrc\46\h:0:*/
  31. /*...e*/
  32.  
  33. static CHAR szAllSupportedFiles [] = "<All GBM supported files>";
  34.  
  35. /*...sGbmDefFileDlgProc:0:*/
  36. MRESULT _System GbmDefFileDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  37.     {
  38.     switch ( (int) msg )
  39.         {
  40. /*...sWM_INITDLG \45\ set up controls:16:*/
  41. case WM_INITDLG:
  42.     {
  43.     MRESULT mr = WinDefFileDlgProc(hwnd, msg, mp1, mp2);
  44.     GBMFILEDLG *pgbmfild = (GBMFILEDLG *) WinQueryWindowULong(hwnd, QWL_USER);
  45.     FILEDLG *pfild = &(pgbmfild -> fild);
  46.     SHORT sInx = SHORT1FROMMR(WinSendDlgItemMsg(hwnd, DID_FILTER_CB, LM_SEARCHSTRING, MPFROM2SHORT(LSS_CASESENSITIVE, 0), MPFROMP(szAllSupportedFiles)));
  47.     WinSendDlgItemMsg(hwnd, DID_FILTER_CB, LM_SELECTITEM, MPFROMSHORT(sInx), MPFROMSHORT(TRUE));
  48.  
  49.     WinSendDlgItemMsg(hwnd, DID_GBM_OPTIONS_ED, EM_SETTEXTLIMIT, MPFROMSHORT(L_GBM_OPTIONS), NULL);
  50.     WinSetDlgItemText(hwnd, DID_GBM_OPTIONS_ED, pgbmfild -> szOptions);
  51.  
  52.     if ( pfild -> pszTitle != NULL )
  53.         WinSetWindowText(hwnd, pfild -> pszTitle);
  54.     else if ( pfild -> fl & FDS_OPEN_DIALOG )
  55.         WinSetWindowText(hwnd, "Open");
  56.     else if ( pfild -> fl & FDS_SAVEAS_DIALOG )
  57.         WinSetWindowText(hwnd, "Save as");
  58.  
  59.     return ( mr );
  60.     }
  61. /*...e*/
  62. /*...sWM_COMMAND \45\ respond to button presses:16:*/
  63. case WM_COMMAND:
  64.     switch ( COMMANDMSG(&msg) -> cmd )
  65.         {
  66. /*...sDID_OK \45\ accept changes:32:*/
  67. case DID_OK:
  68.     {
  69.     MRESULT mr = WinDefFileDlgProc(hwnd, msg, mp1, mp2);
  70.     GBMFILEDLG *pgbmfild = (GBMFILEDLG *) WinQueryWindowULong(hwnd, QWL_USER);
  71.  
  72.     WinQueryDlgItemText(hwnd, DID_GBM_OPTIONS_ED, L_GBM_OPTIONS, pgbmfild -> szOptions);
  73.     return ( mr );
  74.     }
  75. /*...e*/
  76.         }
  77.     break;
  78. /*...e*/
  79. /*...sWM_HELP    \45\ redirect help to our panel:16:*/
  80. case WM_HELP:
  81.     {
  82.     /* Parent is HWND_DESKTOP */
  83.     /* WinDefDlgProc() will pass this up to the parent */
  84.     /* So redirect to the owner */
  85.     /* PM Bug: (USHORT) SHORT1FROMMP(mp1) is not usCmd as it should be */
  86.     /* So fix it up to always be the same for this dialog */
  87.  
  88.     return ( WinSendMsg(WinQueryWindow(hwnd, QW_OWNER), msg, MPFROMSHORT(DID_GBM_FILEDLG), mp2) );
  89.     }
  90. /*...e*/
  91. /*...sFDM_FILTER \45\ filter which files to list:16:*/
  92. /*
  93. To be listed, the file must match the user specified filename (if present)
  94. and the filetype specification.
  95. */
  96.  
  97. #define    L_FN    500
  98.  
  99. case FDM_FILTER:
  100.     {
  101.     CHAR szFn [L_FN+1], szFnOut [L_FN+1];
  102.     WinQueryDlgItemText(hwnd, DID_FILENAME_ED, sizeof(szFn), szFn);
  103.  
  104.     if ( strlen(szFn) != 0 )
  105. /*...suser has specified a filter himself:32:*/
  106. if ( DosEditName(1, (PCH) mp1, szFn, szFnOut, sizeof(szFnOut)) == 0 )
  107.     if ( stricmp(szFn, szFnOut) && stricmp((char *) mp1, szFnOut) )
  108.         return ( (MRESULT) FALSE );
  109. /*...e*/
  110.  
  111. /*...sfilter based on file type:24:*/
  112. {
  113. HWND hwndFt = WinWindowFromID(hwnd, DID_FILTER_CB);
  114. CHAR szFt [100+1];
  115. int ft, n_ft, guess_ft;
  116. SHORT sInx;
  117.  
  118. if ( (sInx = SHORT1FROMMR(WinSendMsg(hwndFt, LM_QUERYSELECTION, NULL, NULL))) != -1 )
  119.     WinSendMsg(hwndFt, LM_QUERYITEMTEXT, MPFROM2SHORT(sInx, sizeof(szFt)), MPFROMP(szFt));
  120. else
  121.     WinQueryWindowText(hwndFt, sizeof(szFt), szFt);
  122.  
  123. /* Look up type name in GBM supported file types */
  124.  
  125. gbm_query_n_filetypes(&n_ft);
  126. for ( ft = 0; ft < n_ft; ft++ )
  127.     {
  128.     GBMFT gbmft;
  129.  
  130.     gbm_query_filetype(ft, &gbmft);
  131.     if ( !strcmp(szFt, gbmft.long_name) )
  132.         break;
  133.     }
  134.  
  135. if ( ft < n_ft )
  136.     /* Must not be <All Files> or <All GBM supported files> */
  137.     {
  138.     if ( gbm_guess_filetype((char *) mp1, &guess_ft) != GBM_ERR_OK ||
  139.          guess_ft != ft )
  140.         return ( (MRESULT) FALSE );
  141.     }
  142. else if ( !strcmp(szFt, szAllSupportedFiles) )
  143.     {
  144.     if ( gbm_guess_filetype((char *) mp1, &guess_ft) != GBM_ERR_OK ||
  145.          guess_ft == -1 )
  146.         return ( (MRESULT) FALSE );
  147.     }
  148. }
  149. /*...e*/
  150.  
  151.     return ( (MRESULT) TRUE );
  152.     }
  153. /*...e*/
  154.         }
  155.     return ( WinDefFileDlgProc(hwnd, msg, mp1, mp2) );
  156.     }
  157. /*...e*/
  158.  
  159. HWND _System GbmFileDlg(HWND hwndP, HWND hwndO, GBMFILEDLG *pgbmfild)
  160.     {
  161.     FILEDLG *pfild = &(pgbmfild -> fild);
  162.     HMODULE hmod;
  163.     int ft, n_ft;
  164.     CHAR **apsz;
  165.     HWND hwndRet;
  166.  
  167.         DosQueryModuleHandle("GBMDLG", &hmod);
  168.  
  169.     pfild -> fl |= FDS_CUSTOM;
  170.  
  171.     if ( pfild -> pfnDlgProc == (PFNWP) NULL )
  172.         pfild -> pfnDlgProc = GbmDefFileDlgProc;
  173.  
  174.     if ( pfild -> hMod == (HMODULE) NULL )
  175.         {
  176.         pfild -> hMod    = hmod;
  177.         pfild -> usDlgId = RID_GBM_FILEDLG;
  178.         }
  179.  
  180.     gbm_query_n_filetypes(&n_ft);
  181.  
  182.     if ( (apsz = malloc((n_ft + 2) * sizeof(CHAR *))) == NULL )
  183.         return ( (HWND) NULL );
  184.  
  185.     for ( ft = 0; ft < n_ft; ft++ )
  186.         {
  187.         GBMFT gbmft;
  188.  
  189.         gbm_query_filetype(ft, &gbmft);
  190.         apsz [ft] = gbmft.long_name;
  191.         }
  192.     apsz [n_ft++] = szAllSupportedFiles;
  193.     apsz [n_ft  ] = NULL;
  194.  
  195.     pfild -> papszITypeList = (PAPSZ) apsz;
  196.  
  197.     hwndRet = WinFileDlg(hwndP, hwndO, (FILEDLG *) pgbmfild);
  198.  
  199.     free(apsz);
  200.  
  201.     return ( hwndRet );
  202.     }
  203.