home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / drgmon.zip / dlgrmf.c < prev    next >
C/C++ Source or Header  |  1993-07-27  |  28KB  |  638 lines

  1. /*********************************************************************
  2.  *                                                                   *
  3.  * MODULE NAME :  dlgrmf.c               AUTHOR:  Rick Fishman       *
  4.  * DATE WRITTEN:  07-21-93                                           *
  5.  *                                                                   *
  6.  * MODULE DESCRIPTION:                                               *
  7.  *                                                                   *
  8.  *  Part of the 'DRGDROP' drag/drop sample program.                  *
  9.  *                                                                   *
  10.  *  Dialog box handling for the RMF dialog box in the Settings       *
  11.  *  notebook.                                                        *
  12.  *                                                                   *
  13.  * NOTES:                                                            *
  14.  *                                                                   *
  15.  * FUNCTIONS CALLABLE BY OTHER MODULES:                              *
  16.  *                                                                   *
  17.  *   wpRMF                                                           *
  18.  *                                                                   *
  19.  *                                                                   *
  20.  * HISTORY:                                                          *
  21.  *                                                                   *
  22.  *  07-21-93 - Program coded.                                        *
  23.  *                                                                   *
  24.  *  Rick Fishman                                                     *
  25.  *  Code Blazers, Inc.                                               *
  26.  *  4113 Apricot                                                     *
  27.  *  Irvine, CA. 92720                                                *
  28.  *  CIS ID: 72251,750                                                *
  29.  *                                                                   *
  30.  *                                                                   *
  31.  *********************************************************************/
  32.  
  33. #pragma strings(readonly)   // used for debug version of memory mgmt routines
  34.  
  35. /*********************************************************************/
  36. /*------- Include relevant sections of the OS/2 header files --------*/
  37. /*********************************************************************/
  38.  
  39. #define  INCL_WINBUTTONS
  40. #define  INCL_WINDIALOGS
  41. #define  INCL_WINENTRYFIELDS
  42. #define  INCL_WINERRORS
  43. #define  INCL_WINFRAMEMGR
  44. #define  INCL_WINLISTBOXES
  45. #define  INCL_WINMLE
  46. #define  INCL_WINSTDCNR
  47. #define  INCL_WINSTDDRAG
  48. #define  INCL_WINWINDOWMGR
  49.  
  50. /*********************************************************************/
  51. /*----------------------------- INCLUDES ----------------------------*/
  52. /*********************************************************************/
  53.  
  54. #include <os2.h>
  55. #include <stdio.h>
  56. #include <string.h>
  57. #include "drgdrop.h"
  58.  
  59. /*********************************************************************/
  60. /*------------------- APPLICATION DEFINITIONS -----------------------*/
  61. /*********************************************************************/
  62.  
  63.  
  64. /*********************************************************************/
  65. /*---------------------------- STRUCTURES ---------------------------*/
  66. /*********************************************************************/
  67.  
  68.  
  69. /*********************************************************************/
  70. /*----------------------- FUNCTION PROTOTYPES -----------------------*/
  71. /*********************************************************************/
  72.  
  73. static void InitControls( HWND hwndDlg );
  74. static BOOL wmCommand( HWND hwndDlg, USHORT idCommand );
  75. static void wmControl( HWND hwndDlg, USHORT idControl, USHORT usEvent );
  76. static void Undo( HWND hwndDlg );
  77. static void Defaults( HWND hwndDlg );
  78. static void UpdateGlobalDlgInfo( PDLGINFO pDlgInfoNew );
  79. static void UpdateControls( HWND hwndDlg );
  80. static void DumpDlgInfo( HWND hwndDlg );
  81.        void GenerateRMF ( HWND hwndDlg, BOOL fUserInvoked );
  82.  
  83. /*********************************************************************/
  84. /*------------------------ GLOBAL VARIABLES -------------------------*/
  85. /*********************************************************************/
  86.  
  87. BOOL fDialogInitialized;
  88.  
  89. /**********************************************************************/
  90. /*------------------------------- wpRMF ------------------------------*/
  91. /*                                                                    */
  92. /*  DIALOG BOX PROCEDURE FOR THE RMF DIALOG BOX                       */
  93. /*                                                                    */
  94. /*  PARMS: standard window proc parms                                 */
  95. /*                                                                    */
  96. /*  NOTES:                                                            */
  97. /*                                                                    */
  98. /*  RETURNS: message result                                           */
  99. /*                                                                    */
  100. /*--------------------------------------------------------------------*/
  101. /**********************************************************************/
  102. MRESULT EXPENTRY wpRMF( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  103. {
  104.     switch( msg )
  105.     {
  106.         case WM_INITDLG:
  107.             InitControls( hwnd );
  108.             return (MRESULT) TRUE;   // Return TRUE to retain any changed focus
  109.  
  110.         case WM_COMMAND:
  111.             if( wmCommand( hwnd, SHORT1FROMMP( mp1 ) ) )
  112.                 return 0;
  113.             else
  114.                 break;
  115.  
  116.         case WM_SETFOCUS:
  117.             if( mp2 )
  118.                 WinPostMsg( hwnd, UM_SET_FOCUS, NULL, NULL );
  119.             break;
  120.  
  121.         case UM_SET_FOCUS:
  122.         {
  123.             PPAGEDATA pPageData = WinQueryWindowPtr( hwnd, QWL_USER );
  124.             if( pPageData )
  125.                 WinSetFocus( HWND_DESKTOP,
  126.                              WinWindowFromID( hwnd, pPageData->idFocus ) );
  127.             return 0;
  128.         }
  129.  
  130.         case WM_CONTROL:
  131.             wmControl( hwnd, SHORT1FROMMP( mp1 ), SHORT2FROMMP( mp1 ) );
  132.             return 0;
  133.  
  134.         case UM_GET_FOCUS_ID:
  135.             return (MRESULT) LB_MECHANISM;
  136.  
  137.         case UM_DUMP_DLGINFO:
  138.             DumpDlgInfo( hwnd );
  139.             break;
  140.  
  141.         case WM_DESTROY:
  142.             fDialogInitialized = FALSE;
  143.             break;
  144.     }
  145.  
  146.     return WinDefDlgProc( hwnd, msg, mp1, mp2 );
  147. }
  148.  
  149. /**********************************************************************/
  150. /*---------------------------- InitControls --------------------------*/
  151. /*                                                                    */
  152. /*  INITIALIZE ALL CONTROLS ON THE DIALOG BOX.                        */
  153. /*                                                                    */
  154. /*  PARMS: window handle of dialog box                                */
  155. /*                                                                    */
  156. /*  NOTES:                                                            */
  157. /*                                                                    */
  158. /*  RETURNS: nothing                                                  */
  159. /*                                                                    */
  160. /*--------------------------------------------------------------------*/
  161. /**********************************************************************/
  162. void InitControls( HWND hwndDlg )
  163. {
  164.     int   i;
  165.     HWND  hwndLB;
  166.  
  167.     hwndLB = WinWindowFromID( hwndDlg, LB_MECHANISM );
  168.     for( i = 0; i < cMechanisms; i++ )
  169.         WinInsertLboxItem( hwndLB, LIT_END, pszMechanism[ i ] );
  170.  
  171.     hwndLB = WinWindowFromID( hwndDlg, LB_FORMAT );
  172.     for( i = 0; i < cFormats; i++ )
  173.         WinInsertLboxItem( hwndLB, LIT_END, pszFormat[ i ] );
  174.  
  175.     SetEFTextLimit( hwndDlg, EF_ADDL_MECHANISM, ADDL_MECHANISM_LEN );
  176.     SetEFTextLimit( hwndDlg, EF_ADDL_FORMAT, ADDL_FORMAT_LEN );
  177.     SetMLETextLimit( hwndDlg, MLE_GENERATED_RMF, GENERATED_RMF_LEN );
  178.     SetMLETextLimit( hwndDlg, MLE_MANUAL_RMF, MANUAL_RMF_LEN );
  179.  
  180.     UpdateControls( hwndDlg );
  181. }
  182.  
  183. /**********************************************************************/
  184. /*---------------------------- wmCommand -----------------------------*/
  185. /*                                                                    */
  186. /*  THE DIALOG PROC GOT A WM_COMMAND MESSAGE.                         */
  187. /*                                                                    */
  188. /*  PARMS: dialog box window handle,                                  */
  189. /*         command id                                                 */
  190. /*                                                                    */
  191. /*  NOTES:                                                            */
  192. /*                                                                    */
  193. /*  RETURNS: TRUE or FALSE if command was processed                   */
  194. /*                                                                    */
  195. /*--------------------------------------------------------------------*/
  196. /**********************************************************************/
  197. BOOL wmCommand( HWND hwndDlg, USHORT idCommand )
  198. {
  199.     BOOL fProcessed = FALSE;
  200.  
  201.     switch( idCommand )
  202.     {
  203.         case DID_OK:
  204.         case DID_CANCEL:
  205.             fProcessed = TRUE;
  206.             break;
  207.  
  208.         case PB_GENERATE:
  209.             GenerateRMF( hwndDlg, TRUE );
  210.             fProcessed = TRUE;
  211.             break;
  212.  
  213.         case PB_UNDO:
  214.             Undo( hwndDlg );
  215.             fProcessed = TRUE;
  216.             break;
  217.  
  218.         case PB_DEFAULT:
  219.             Defaults( hwndDlg );
  220.             fProcessed = TRUE;
  221.             break;
  222.     }
  223.  
  224.     return fProcessed;
  225. }
  226.  
  227. /**********************************************************************/
  228. /*------------------------------- Undo -------------------------------*/
  229. /*                                                                    */
  230. /*  UNDO (GET THE DLGINFO DATA FROM THE INI FILE)                     */
  231. /*                                                                    */
  232. /*  PARMS: dialog box window handle                                   */
  233. /*                                                                    */
  234. /*  NOTES:                                                            */
  235. /*                                                                    */
  236. /*  RETURNS: nothing                                                  */
  237. /*                                                                    */
  238. /*--------------------------------------------------------------------*/
  239. /**********************************************************************/
  240. void Undo( HWND hwndDlg )
  241. {
  242.     DLGINFO dlgInfoLocal;
  243.  
  244.     if( RetrieveDlgInfo( ANCHOR( hwndDlg ), &dlgInfoLocal ) )
  245.     {
  246.         UpdateGlobalDlgInfo( &dlgInfoLocal );
  247.         UpdateControls( hwndDlg );
  248.     }
  249.     else
  250.         Defaults( hwndDlg );
  251. }
  252.  
  253. /**********************************************************************/
  254. /*---------------------------- Defaults ------------------------------*/
  255. /*                                                                    */
  256. /*  SET THE DLGINFO STRUCTURE BACK TO DEFAULTS (ONLY OUR FIELDS)      */
  257. /*                                                                    */
  258. /*  PARMS: dialog box window handle                                   */
  259. /*                                                                    */
  260. /*  NOTES:                                                            */
  261. /*                                                                    */
  262. /*  RETURNS: nothing                                                  */
  263. /*                                                                    */
  264. /*--------------------------------------------------------------------*/
  265. /**********************************************************************/
  266. void Defaults( HWND hwndDlg )
  267. {
  268.     UpdateGlobalDlgInfo( &dlgInfoDefaults );
  269.     UpdateControls( hwndDlg );
  270. }
  271.  
  272. /**********************************************************************/
  273. /*------------------------ UpdateGlobalDlgInfo -----------------------*/
  274. /*                                                                    */
  275. /*  UPDATE OUR FIELDS IN THE GLOBAL DLGINFO STRUCTURE                 */
  276. /*                                                                    */
  277. /*  PARMS: pointer to a local DLGINFO structure                       */
  278. /*                                                                    */
  279. /*  NOTES:                                                            */
  280. /*                                                                    */
  281. /*  RETURNS: nothing                                                  */
  282. /*                                                                    */
  283. /*--------------------------------------------------------------------*/
  284. /**********************************************************************/
  285. void UpdateGlobalDlgInfo( PDLGINFO pDlgInfoNew )
  286. {
  287.     dlgInfo.fUseManualRMF = pDlgInfoNew->fUseManualRMF;
  288.  
  289.     strcpy( dlgInfo.szAddlMechanisms, pDlgInfoNew->szAddlMechanisms );
  290.     strcpy( dlgInfo.szAddlFormats,    pDlgInfoNew->szAddlFormats );
  291.     strcpy( dlgInfo.szGeneratedRMF,   pDlgInfoNew->szGeneratedRMF );
  292.     strcpy( dlgInfo.szManualRMF,      pDlgInfoNew->szManualRMF );
  293. }
  294.  
  295. /**********************************************************************/
  296. /*----------------------------- wmControl ----------------------------*/
  297. /*                                                                    */
  298. /*  THE DIALOG PROC GOT A WM_CONTROL MESSAGE.                         */
  299. /*                                                                    */
  300. /*  PARMS: dialog box window handle,                                  */
  301. /*         control id,                                                */
  302. /*         notify code                                                */
  303. /*                                                                    */
  304. /*  NOTES:                                                            */
  305. /*                                                                    */
  306. /*  RETURNS: nothing                                                  */
  307. /*                                                                    */
  308. /*--------------------------------------------------------------------*/
  309. /**********************************************************************/
  310. void wmControl( HWND hwndDlg, USHORT idControl, USHORT usEvent )
  311. {
  312.     switch( idControl )
  313.     {
  314.         case LB_MECHANISM:
  315.         case LB_FORMAT:
  316.             switch( usEvent )
  317.             {
  318.                 case LN_SELECT:
  319.  
  320.                     // There is a problem if a LM_SELECTITEM message is sent
  321.                     // to the listbox during WM_INITDLG and we process the
  322.                     // resulting LN_SELECT here. The data segment seems to be
  323.                     // getting overwritten...We don't want to process the
  324.                     // LN_SELECT message in this case anyway.
  325.  
  326.                     if( fDialogInitialized )
  327.                         GenerateRMF( hwndDlg, FALSE );
  328.                     break;
  329.             }
  330.  
  331.             break;
  332.  
  333.         case EF_ADDL_MECHANISM:
  334.             switch( usEvent )
  335.             {
  336.                 case EN_KILLFOCUS:
  337.                 {
  338.                     char szText[ ADDL_MECHANISM_LEN ];
  339.  
  340.                     WinQueryDlgItemText( hwndDlg, EF_ADDL_MECHANISM,
  341.                                          sizeof szText, szText );
  342.                     if( strcmp( szText, dlgInfo.szAddlMechanisms ) != 0 )
  343.                         GenerateRMF( hwndDlg, FALSE );
  344.                     WinEnableControl( hwndDlg, PB_GENERATE, FALSE );
  345.                     break;
  346.                 }
  347.                 case EN_CHANGE:
  348.                     WinEnableControl( hwndDlg, PB_GENERATE, TRUE );
  349.                     break;
  350.             }
  351.  
  352.             break;
  353.  
  354.         case EF_ADDL_FORMAT:
  355.             switch( usEvent )
  356.             {
  357.                 case EN_KILLFOCUS:
  358.                 {
  359.                     char szText[ ADDL_FORMAT_LEN ];
  360.  
  361.                     WinQueryDlgItemText( hwndDlg, EF_ADDL_FORMAT,
  362.                                          sizeof szText, szText );
  363.                     if( strcmp( szText, dlgInfo.szAddlFormats ) != 0 )
  364.                         GenerateRMF( hwndDlg, FALSE );
  365.                     WinEnableControl( hwndDlg, PB_GENERATE, FALSE );
  366.                     break;
  367.                 }
  368.                 case EN_CHANGE:
  369.                     WinEnableControl( hwndDlg, PB_GENERATE, TRUE );
  370.                     break;
  371.             }
  372.  
  373.             break;
  374.     }
  375. }
  376.  
  377. /**********************************************************************/
  378. /*-------------------------- UpdateControls --------------------------*/
  379. /*                                                                    */
  380. /*  UPDATE THE CONTROLS IN THE DIALOG BOX                             */
  381. /*                                                                    */
  382. /*  PARMS: dialog box window handle                                   */
  383. /*                                                                    */
  384. /*  NOTES:                                                            */
  385. /*                                                                    */
  386. /*  RETURNS: nothing                                                  */
  387. /*                                                                    */
  388. /*--------------------------------------------------------------------*/
  389. /**********************************************************************/
  390. void UpdateControls( HWND hwndDlg )
  391. {
  392.     int  i;
  393.     HWND hwndLB;
  394.  
  395.     // There is a problem if a LM_SELECTITEM message is sent to the listbox
  396.     // during WM_INITDLG and we process the resulting LN_SELECT in the
  397.     // WM_CONTROL processing. The data segment seems to be getting overwritten.
  398.     // We don't want to process the LN_SELECT message in this case anyway. So
  399.     // we simply rely on this flag under the WM_CONTROL processing for
  400.     // LN_SELECT.
  401.  
  402.     fDialogInitialized = FALSE;
  403.  
  404.     hwndLB = WinWindowFromID( hwndDlg, LB_MECHANISM );
  405.     WinSendMsg( hwndLB, LM_SELECTITEM, MPFROMSHORT( LIT_NONE ),
  406.                 MPFROMLONG( FALSE ) );
  407.     for( i = 0; i < cMechanisms; i++ )
  408.         if( strstr( dlgInfo.szGeneratedRMF, pszMechanism[ i ] ) )
  409.             WinSendMsg( hwndLB, LM_SELECTITEM, MPFROMSHORT( i ),
  410.                         MPFROMLONG( TRUE ) );
  411.  
  412.     hwndLB = WinWindowFromID( hwndDlg, LB_FORMAT );
  413.     WinSendMsg( hwndLB, LM_SELECTITEM, MPFROMSHORT( LIT_NONE ),
  414.                 MPFROMLONG( FALSE ) );
  415.     for( i = 0; i < cFormats; i++ )
  416.         if( strstr( dlgInfo.szGeneratedRMF, pszFormat[ i ] ) )
  417.             WinSendMsg( hwndLB, LM_SELECTITEM, MPFROMSHORT( i ),
  418.                         MPFROMLONG( TRUE ) );
  419.  
  420.     WinSetDlgItemText( hwndDlg, EF_ADDL_MECHANISM, dlgInfo.szAddlMechanisms );
  421.     WinSetDlgItemText( hwndDlg, EF_ADDL_FORMAT, dlgInfo.szAddlFormats );
  422.     WinSetDlgItemText( hwndDlg, MLE_GENERATED_RMF, dlgInfo.szGeneratedRMF );
  423.     WinSetDlgItemText( hwndDlg, MLE_MANUAL_RMF, dlgInfo.szManualRMF );
  424.  
  425.     WinCheckButton( hwndDlg, CHK_MANUAL_RMF, dlgInfo.fUseManualRMF );
  426.  
  427.     WinEnableControl( hwndDlg, PB_GENERATE, FALSE );
  428.  
  429.     fDialogInitialized = TRUE;
  430. }
  431.  
  432. /**********************************************************************/
  433. /*--------------------------- DumpDlgInfo ----------------------------*/
  434. /*                                                                    */
  435. /*  DUMP OUR CONTROL TEXT TO THE GLOBAL DLGINFO STRUCTURE             */
  436. /*                                                                    */
  437. /*  PARMS: dialog box window handle                                   */
  438. /*                                                                    */
  439. /*  NOTES:                                                            */
  440. /*                                                                    */
  441. /*  RETURNS: nothing                                                  */
  442. /*                                                                    */
  443. /*--------------------------------------------------------------------*/
  444. /**********************************************************************/
  445. void DumpDlgInfo( HWND hwndDlg )
  446. {
  447.     GenerateRMF( hwndDlg, FALSE );
  448.  
  449.     WinQueryDlgItemText( hwndDlg, MLE_GENERATED_RMF,
  450.                          sizeof dlgInfo.szGeneratedRMF, dlgInfo.szGeneratedRMF);
  451.  
  452.     WinQueryDlgItemText( hwndDlg, MLE_MANUAL_RMF,
  453.                          sizeof dlgInfo.szManualRMF, dlgInfo.szManualRMF );
  454.  
  455.     dlgInfo.fUseManualRMF = WinQueryButtonCheckstate( hwndDlg, CHK_MANUAL_RMF );
  456. }
  457.  
  458. /**********************************************************************/
  459. /*--------------------------- GenerateRMF ----------------------------*/
  460. /*                                                                    */
  461. /*  AUTOMATICALLY GENERATE THE RMF BASED ON LISTBOXES AND ENTRYFIELDS */
  462. /*                                                                    */
  463. /*  PARMS: dialog box window handle,                                  */
  464. /*         TRUE or FALSE based on whether or not the user initiated   */
  465. /*               the 'generate'                                       */
  466. /*                                                                    */
  467. /*  NOTES:                                                            */
  468. /*                                                                    */
  469. /*  RETURNS: nothing                                                  */
  470. /*                                                                    */
  471. /*--------------------------------------------------------------------*/
  472. /**********************************************************************/
  473. void GenerateRMF( HWND hwndDlg, BOOL fUserInvoked )
  474. {
  475.     HWND  hwndMechanism, hwndFormat;
  476.     int   cBytesLeft, cSelectedMechanisms = 0, cSelectedFormats = 0;
  477.     SHORT sItemID;
  478.     PCH   pchLeftMechanismParen, pchRightMechanismParen, pchEnd;
  479.     char  szRMF[ GENERATED_RMF_LEN ];
  480.  
  481.     *szRMF = 0;
  482.  
  483.     hwndMechanism = WinWindowFromID( hwndDlg, LB_MECHANISM );
  484.     hwndFormat = WinWindowFromID( hwndDlg, LB_FORMAT );
  485.  
  486.     WinQueryDlgItemText( hwndDlg, EF_ADDL_MECHANISM,
  487.                          sizeof dlgInfo.szAddlMechanisms,
  488.                          dlgInfo.szAddlMechanisms );
  489.     if( dlgInfo.szAddlMechanisms[ strlen(dlgInfo.szAddlMechanisms) - 1 ] == ',')
  490.         dlgInfo.szAddlMechanisms[ strlen(dlgInfo.szAddlMechanisms) - 1 ] = 0;
  491.  
  492.     WinQueryDlgItemText( hwndDlg, EF_ADDL_FORMAT,
  493.                          sizeof dlgInfo.szAddlFormats, dlgInfo.szAddlFormats );
  494.     if( dlgInfo.szAddlFormats[ strlen( dlgInfo.szAddlFormats ) - 1 ] == ',' )
  495.         dlgInfo.szAddlFormats[ strlen( dlgInfo.szAddlFormats ) - 1 ] = 0;
  496.  
  497.     // Make sure there is at least one Mechanism and Format
  498.  
  499.     sItemID = SHORT1FROMMR( WinSendMsg( hwndMechanism, LM_QUERYSELECTION,
  500.                                         MPFROMSHORT( LIT_FIRST ), NULL ) );
  501.     if( sItemID == LIT_NONE && !(*dlgInfo.szAddlMechanisms) )
  502.     {
  503.         WinSetDlgItemText( hwndDlg, MLE_GENERATED_RMF, szRMF );
  504.         *dlgInfo.szGeneratedRMF = 0;
  505.         if( fUserInvoked )
  506.             Msg( "You must select or enter a Rendering Mechanism before an RMF"
  507.                  " can be generated" );
  508.         return;
  509.     }
  510.  
  511.     sItemID = SHORT1FROMMR( WinSendMsg( hwndFormat, LM_QUERYSELECTION,
  512.                                         MPFROMSHORT( LIT_FIRST ), NULL ) );
  513.     if( sItemID == LIT_NONE && !(*dlgInfo.szAddlFormats) )
  514.     {
  515.         WinSetDlgItemText( hwndDlg, MLE_GENERATED_RMF, szRMF );
  516.         *dlgInfo.szGeneratedRMF = 0;
  517.         if( fUserInvoked )
  518.             Msg( "You must select or enter a Rendering Format before an RMF can"
  519.                  " be generated" );
  520.         return;
  521.     }
  522.  
  523.     // If there is a comma in the 'additional' fields, that means there is more
  524.     // than one. All we are concerned about is if there is more than one because
  525.     // that determines what delimiter characters we use to build the RMF string.
  526.  
  527.     if( *dlgInfo.szAddlMechanisms )
  528.     {
  529.         cSelectedMechanisms = 1;
  530.         if( strchr( dlgInfo.szAddlMechanisms, ',' ) )
  531.             cSelectedMechanisms = 2;
  532.     }
  533.  
  534.     if( *dlgInfo.szAddlFormats )
  535.     {
  536.         cSelectedFormats = 1;
  537.         if( strchr( dlgInfo.szAddlFormats, ',' ) )
  538.             cSelectedFormats = 2;
  539.     }
  540.  
  541.     // Build the RMF string in the format "(Mech,Mech)x(Format,Format)"
  542.     // assuming that there is more than one of either the mechanism or format.
  543.     // If it turns out that there is only one of each, change the format of
  544.     // the string to "<Mech,Format>". This isn't necessary, just showing the
  545.     // different ways that the string can be built...
  546.  
  547.     pchLeftMechanismParen = szRMF;
  548.  
  549.     strcpy( szRMF, "(" );
  550.  
  551.     cBytesLeft = (sizeof szRMF) - 1;
  552.     if( cSelectedMechanisms )
  553.         strncat( szRMF, dlgInfo.szAddlMechanisms, cBytesLeft );
  554.  
  555.     cBytesLeft = sizeof szRMF - strlen( szRMF );
  556.     if( cBytesLeft < 0 ) cBytesLeft = 0;
  557.  
  558.     sItemID = LIT_FIRST;
  559.     do
  560.     {
  561.         sItemID = SHORT1FROMMR( WinSendMsg( hwndMechanism, LM_QUERYSELECTION,
  562.                                             MPFROMSHORT( sItemID ), NULL ) );
  563.         if( sItemID != LIT_NONE )
  564.         {
  565.             if( cSelectedMechanisms++ )
  566.             {
  567.                 strncat( szRMF, ",", cBytesLeft );
  568.                 cBytesLeft = cBytesLeft ? cBytesLeft-- : cBytesLeft;
  569.             }
  570.  
  571.             pchEnd = szRMF + strlen( szRMF );
  572.  
  573.             WinQueryLboxItemText( hwndMechanism, sItemID, pchEnd, cBytesLeft );
  574.  
  575.             cBytesLeft = sizeof szRMF - strlen( szRMF );
  576.             if( cBytesLeft < 0 ) cBytesLeft = 0;
  577.         }
  578.     } while( sItemID != LIT_NONE );
  579.  
  580.     pchRightMechanismParen = szRMF + strlen( szRMF );
  581.  
  582.     strcat( szRMF, ")x(" );
  583.     cBytesLeft -= 3;
  584.     if( cBytesLeft < 0 ) cBytesLeft = 0;
  585.  
  586.     if( cSelectedFormats )
  587.         strncat( szRMF, dlgInfo.szAddlFormats, cBytesLeft );
  588.     cBytesLeft = sizeof szRMF - strlen( szRMF );
  589.     if( cBytesLeft < 0 ) cBytesLeft = 0;
  590.  
  591.     sItemID = LIT_FIRST;
  592.     do
  593.     {
  594.         sItemID = SHORT1FROMMR( WinSendMsg( hwndFormat, LM_QUERYSELECTION,
  595.                                             MPFROMSHORT( sItemID ), NULL ) );
  596.         if( sItemID != LIT_NONE )
  597.         {
  598.             if( cSelectedFormats++ )
  599.             {
  600.                 strncat( szRMF, ",", cBytesLeft );
  601.                 cBytesLeft = cBytesLeft ? cBytesLeft-- : cBytesLeft;
  602.             }
  603.  
  604.             pchEnd = szRMF + strlen( szRMF );
  605.  
  606.             WinQueryLboxItemText( hwndFormat, sItemID, pchEnd, cBytesLeft );
  607.  
  608.             cBytesLeft = sizeof szRMF - strlen( szRMF );
  609.             if( cBytesLeft < 0 ) cBytesLeft = 0;
  610.         }
  611.     } while( sItemID != LIT_NONE );
  612.  
  613.     if( cSelectedMechanisms == 1 && cSelectedFormats == 1 )
  614.     {
  615.         *pchLeftMechanismParen = '<';
  616.         *pchRightMechanismParen = ',';
  617.         memmove( pchRightMechanismParen + 1, pchRightMechanismParen + 3,
  618.                  strlen( pchRightMechanismParen + 3 ) + 1 );
  619.         strncat( szRMF, ">", cBytesLeft );
  620.     }
  621.     else
  622.         strncat( szRMF, ")", cBytesLeft );
  623.  
  624.     if( strcmp( szRMF, dlgInfo.szGeneratedRMF ) != 0 )
  625.     {
  626.         WinSetDlgItemText( hwndDlg, MLE_GENERATED_RMF, szRMF );
  627.         strcpy( dlgInfo.szGeneratedRMF, szRMF );
  628.     }
  629.  
  630.     if( !cBytesLeft )
  631.         Msg( "Your RMF string may have been truncated. Boy, you sure like to"
  632.              "try every possible combination, don't you?" );
  633. }
  634.  
  635. /*********************************************************************
  636.  *                      E N D   O F   S O U R C E                    *
  637.  *********************************************************************/
  638.