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