home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / drgmon.zip / dlgdragi.c < prev    next >
C/C++ Source or Header  |  1993-12-05  |  24KB  |  501 lines

  1. /*********************************************************************
  2.  *                                                                   *
  3.  * MODULE NAME :  dlgdragi.c             AUTHOR:  Rick Fishman       *
  4.  * DATE WRITTEN:  07-26-93                                           *
  5.  *                                                                   *
  6.  * MODULE DESCRIPTION:                                               *
  7.  *                                                                   *
  8.  *  Part of the 'DRGDROP' drag/drop sample program.                  *
  9.  *                                                                   *
  10.  *  Dialog box in the Settings notebook that handles all DRAGINFO    *
  11.  *  and DRAGITEM parameters except for the RMF string which is       *
  12.  *  handled in dlgrmf.c.                                             *
  13.  *                                                                   *
  14.  * NOTES:                                                            *
  15.  *                                                                   *
  16.  * FUNCTIONS CALLABLE BY OTHER MODULES:                              *
  17.  *                                                                   *
  18.  *   wpDragInfo                                                      *
  19.  *                                                                   *
  20.  *                                                                   *
  21.  * HISTORY:                                                          *
  22.  *                                                                   *
  23.  *  07-26-93 - Program coded.                                        *
  24.  *  12-05-93 - Use TYPE array to convert to proper DLGINFO.szType.   *
  25.  *                                                                   *
  26.  *  Rick Fishman                                                     *
  27.  *  Code Blazers, Inc.                                               *
  28.  *  4113 Apricot                                                     *
  29.  *  Irvine, CA. 92720                                                *
  30.  *  CIS ID: 72251,750                                                *
  31.  *                                                                   *
  32.  *                                                                   *
  33.  *********************************************************************/
  34.  
  35. #pragma strings(readonly)   // used for debug version of memory mgmt routines
  36.  
  37. /*********************************************************************/
  38. /*------- Include relevant sections of the OS/2 header files --------*/
  39. /*********************************************************************/
  40.  
  41. #define  INCL_WINBUTTONS
  42. #define  INCL_WINDIALOGS
  43. #define  INCL_WINENTRYFIELDS
  44. #define  INCL_WINERRORS
  45. #define  INCL_WINFRAMEMGR
  46. #define  INCL_WINLISTBOXES
  47. #define  INCL_WINSTDCNR
  48. #define  INCL_WINSTDDRAG
  49. #define  INCL_WINWINDOWMGR
  50.  
  51. /*********************************************************************/
  52. /*----------------------------- INCLUDES ----------------------------*/
  53. /*********************************************************************/
  54.  
  55. #include <os2.h>
  56. #include <stdio.h>
  57. #include <stdlib.h>
  58. #include <string.h>
  59. #include "drgdrop.h"
  60.  
  61. /*********************************************************************/
  62. /*------------------- APPLICATION DEFINITIONS -----------------------*/
  63. /*********************************************************************/
  64.  
  65.  
  66. /*********************************************************************/
  67. /*---------------------------- STRUCTURES ---------------------------*/
  68. /*********************************************************************/
  69.  
  70.  
  71. /*********************************************************************/
  72. /*----------------------- FUNCTION PROTOTYPES -----------------------*/
  73. /*********************************************************************/
  74.  
  75. static void InitControls( HWND hwndDlg );
  76. static BOOL wmCommand( HWND hwndDlg, USHORT idCommand );
  77. static void wmControl( HWND hwndDlg, USHORT idControl, USHORT usEvent );
  78. static void Undo( HWND hwndDlg );
  79. static void Defaults( HWND hwndDlg );
  80. static void UpdateGlobalDlgInfo( PDLGINFO pDlgInfoNew );
  81. static void UpdateControls( HWND hwndDlg );
  82. static void DumpDlgInfo( HWND hwndDlg );
  83.  
  84. /*********************************************************************/
  85. /*------------------------ GLOBAL VARIABLES -------------------------*/
  86. /*********************************************************************/
  87.  
  88.  
  89. /**********************************************************************/
  90. /*---------------------------- wpDragInfo ----------------------------*/
  91. /*                                                                    */
  92. /*  DIALOG BOX PROCEDURE FOR THE DRAGINFO DIALOG BOX                  */
  93. /*                                                                    */
  94. /*  PARMS: standard window proc parms                                 */
  95. /*                                                                    */
  96. /*  NOTES:                                                            */
  97. /*                                                                    */
  98. /*  RETURNS: message result                                           */
  99. /*                                                                    */
  100. /*--------------------------------------------------------------------*/
  101. /**********************************************************************/
  102. MRESULT EXPENTRY wpDragInfo( 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) CB_OPERATION;
  136.  
  137.         case UM_DUMP_DLGINFO:
  138.             DumpDlgInfo( hwnd );
  139.             break;
  140.     }
  141.  
  142.     return WinDefDlgProc( hwnd, msg, mp1, mp2 );
  143. }
  144.  
  145. /**********************************************************************/
  146. /*---------------------------- InitControls --------------------------*/
  147. /*                                                                    */
  148. /*  INITIALIZE ALL CONTROLS ON THE DIALOG BOX.                        */
  149. /*                                                                    */
  150. /*  PARMS: window handle of dialog box                                */
  151. /*                                                                    */
  152. /*  NOTES:                                                            */
  153. /*                                                                    */
  154. /*  RETURNS: nothing                                                  */
  155. /*                                                                    */
  156. /*--------------------------------------------------------------------*/
  157. /**********************************************************************/
  158. void InitControls( HWND hwndDlg )
  159. {
  160.     int   i;
  161.     HWND  hwndLB;
  162.  
  163.     hwndLB = WinWindowFromID( hwndDlg, CB_OPERATION );
  164.     for( i = 0; i < cOperations; i++ )
  165.         WinInsertLboxItem( hwndLB, LIT_END, dcOperation[ i ].szItem );
  166.  
  167.     hwndLB = WinWindowFromID( hwndDlg, CB_TYPE );
  168.     for( i = 0; i < cTypes; i++ )
  169.         WinInsertLboxItem( hwndLB, LIT_END, ntsType[ i ].szName );
  170.  
  171.     hwndLB = WinWindowFromID( hwndDlg, LB_CONTROL );
  172.     for( i = 0; i < cControlTypes; i++ )
  173.         WinInsertLboxItem( hwndLB, LIT_END, dcControl[ i ].szItem );
  174.  
  175.     hwndLB = WinWindowFromID( hwndDlg, LB_SUPPORTEDOPS );
  176.     for( i = 0; i < cSupportedOps; i++ )
  177.         WinInsertLboxItem( hwndLB, LIT_END, dcSupportedOp[ i ].szItem );
  178.  
  179.     SetEFTextLimit( hwndDlg, EF_ITEMID, 8 );
  180.     SetEFTextLimit( hwndDlg, CB_TYPE, TYPE_LEN );
  181.     SetEFTextLimit( hwndDlg, EF_CNR_NAME, CCHMAXPATH );
  182.     SetEFTextLimit( hwndDlg, EF_SOURCE_NAME, CCHMAXPATH );
  183.     SetEFTextLimit( hwndDlg, EF_TARGET_NAME, CCHMAXPATH );
  184.  
  185.     UpdateControls( hwndDlg );
  186. }
  187.  
  188. /**********************************************************************/
  189. /*---------------------------- wmCommand -----------------------------*/
  190. /*                                                                    */
  191. /*  THE DIALOG PROC GOT A WM_COMMAND MESSAGE.                         */
  192. /*                                                                    */
  193. /*  PARMS: dialog box window handle,                                  */
  194. /*         command id                                                 */
  195. /*                                                                    */
  196. /*  NOTES:                                                            */
  197. /*                                                                    */
  198. /*  RETURNS: TRUE or FALSE if command was processed                   */
  199. /*                                                                    */
  200. /*--------------------------------------------------------------------*/
  201. /**********************************************************************/
  202. BOOL wmCommand( HWND hwndDlg, USHORT idCommand )
  203. {
  204.     BOOL fProcessed = FALSE;
  205.  
  206.     switch( idCommand )
  207.     {
  208.         case DID_OK:
  209.         case DID_CANCEL:
  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.fUseDlgDragNames = pDlgInfoNew->fUseDlgDragNames;
  288.     dlgInfo.fUseDlgItemID    = pDlgInfoNew->fUseDlgItemID;
  289.     dlgInfo.ulItemID         = pDlgInfoNew->ulItemID;
  290.     dlgInfo.usOperation      = pDlgInfoNew->usOperation;
  291.     dlgInfo.fsControl        = pDlgInfoNew->fsControl;
  292.     dlgInfo.fsSupportedOps   = pDlgInfoNew->fsSupportedOps;
  293.  
  294.     strcpy( dlgInfo.szType, pDlgInfoNew->szType );
  295.     strcpy( dlgInfo.szContainerName, pDlgInfoNew->szContainerName );
  296.     strcpy( dlgInfo.szSourceName, pDlgInfoNew->szSourceName );
  297.     strcpy( dlgInfo.szTargetName, pDlgInfoNew->szTargetName );
  298. }
  299.  
  300. /**********************************************************************/
  301. /*----------------------------- wmControl ----------------------------*/
  302. /*                                                                    */
  303. /*  THE DIALOG PROC GOT A WM_CONTROL MESSAGE.                         */
  304. /*                                                                    */
  305. /*  PARMS: dialog box window handle,                                  */
  306. /*         control id,                                                */
  307. /*         notify code                                                */
  308. /*                                                                    */
  309. /*  NOTES:                                                            */
  310. /*                                                                    */
  311. /*  RETURNS: nothing                                                  */
  312. /*                                                                    */
  313. /*--------------------------------------------------------------------*/
  314. /**********************************************************************/
  315. void wmControl( HWND hwndDlg, USHORT idControl, USHORT usEvent )
  316. {
  317.     switch( idControl )
  318.     {
  319.         case CHK_OVERRIDE_HSTRS:
  320.             if( usEvent == BN_CLICKED )
  321.             {
  322.                 BOOL fChecked = WinQueryButtonCheckstate( hwndDlg,
  323.                                                           CHK_OVERRIDE_HSTRS );
  324.                 WinEnableControl( hwndDlg, EF_CNR_NAME, fChecked );
  325.                 WinEnableControl( hwndDlg, EF_SOURCE_NAME, fChecked );
  326.                 WinEnableControl( hwndDlg, EF_TARGET_NAME, fChecked );
  327.                 WinEnableControl( hwndDlg, ST_CNR_NAME, fChecked );
  328.                 WinEnableControl( hwndDlg, ST_SOURCE_NAME, fChecked );
  329.                 WinEnableControl( hwndDlg, ST_TARGET_NAME, fChecked );
  330.             }
  331.  
  332.             break;
  333.  
  334.         case CHK_OVERRIDE_ID:
  335.             if( usEvent == BN_CLICKED )
  336.             {
  337.                 BOOL fChecked = WinQueryButtonCheckstate( hwndDlg,
  338.                                                           CHK_OVERRIDE_ID );
  339.                 WinEnableControl( hwndDlg, EF_ITEMID, fChecked );
  340.                 WinEnableControl( hwndDlg, ST_ITEMID, fChecked );
  341.             }
  342.  
  343.             break;
  344.     }
  345. }
  346.  
  347. /**********************************************************************/
  348. /*-------------------------- UpdateControls --------------------------*/
  349. /*                                                                    */
  350. /*  UPDATE THE CONTROLS IN THE DIALOG BOX                             */
  351. /*                                                                    */
  352. /*  PARMS: dialog box window handle                                   */
  353. /*                                                                    */
  354. /*  NOTES:                                                            */
  355. /*                                                                    */
  356. /*  RETURNS: nothing                                                  */
  357. /*                                                                    */
  358. /*--------------------------------------------------------------------*/
  359. /**********************************************************************/
  360. void UpdateControls( HWND hwndDlg )
  361. {
  362.     int  i;
  363.     char szFromUl[ 9 ];
  364.     HWND hwndLB;
  365.  
  366.     hwndLB = WinWindowFromID( hwndDlg, LB_CONTROL );
  367.     WinSendMsg( hwndLB, LM_SELECTITEM, MPFROMSHORT( LIT_NONE ),
  368.                 MPFROMLONG( FALSE ) );
  369.     for( i = 0; i < cControlTypes; i++ )
  370.         if( dlgInfo.fsControl & dcControl[ i ].iItem )
  371.             WinSendMsg( hwndLB, LM_SELECTITEM, MPFROMSHORT( i ),
  372.                         MPFROMLONG( TRUE ) );
  373.  
  374.     hwndLB = WinWindowFromID( hwndDlg, LB_SUPPORTEDOPS );
  375.     WinSendMsg( hwndLB, LM_SELECTITEM, MPFROMSHORT( LIT_NONE ),
  376.                 MPFROMLONG( FALSE ) );
  377.     for( i = 0; i < cSupportedOps; i++ )
  378.         if( dlgInfo.fsSupportedOps & dcSupportedOp[ i ].iItem )
  379.             WinSendMsg( hwndLB, LM_SELECTITEM, MPFROMSHORT( i ),
  380.                         MPFROMLONG( TRUE ) );
  381.  
  382.     for( i = 0; i < cOperations; i++ )
  383.         if( dlgInfo.usOperation == dcOperation[ i ].iItem )
  384.         {
  385.             WinSetDlgItemText( hwndDlg, CB_OPERATION, dcOperation[ i ].szItem );
  386.             break;
  387.         }
  388.     if( i == cOperations )
  389.         WinSetDlgItemText( hwndDlg, CB_OPERATION,
  390.                            _ultoa( (ULONG)dlgInfo.usOperation, szFromUl, 16 ) );
  391.  
  392.     if( dlgInfo.ulItemID )
  393.         WinSetDlgItemText( hwndDlg, EF_ITEMID,
  394.                            _ultoa( dlgInfo.ulItemID, szFromUl, 16 ) );
  395.     else
  396.         WinSetDlgItemText( hwndDlg, EF_ITEMID, "" );
  397.  
  398.     WinSetDlgItemText( hwndDlg, CB_TYPE, dlgInfo.szType );
  399.     for( i = 0; i < cTypes; i++ )
  400.     {
  401.        if( !stricmp( ntsType[ i ].szString, dlgInfo.szType ) )
  402.            WinSetDlgItemText( hwndDlg, CB_TYPE, ntsType[ i ].szName );
  403.     }
  404.  
  405.     WinSetDlgItemText( hwndDlg, EF_CNR_NAME, dlgInfo.szContainerName );
  406.     WinSetDlgItemText( hwndDlg, EF_SOURCE_NAME, dlgInfo.szSourceName );
  407.     WinSetDlgItemText( hwndDlg, EF_TARGET_NAME, dlgInfo.szTargetName );
  408.  
  409.     WinCheckButton( hwndDlg, CHK_OVERRIDE_ID, dlgInfo.fUseDlgItemID );
  410.     WinCheckButton( hwndDlg, CHK_OVERRIDE_HSTRS, dlgInfo.fUseDlgDragNames );
  411.  
  412.     WinEnableControl( hwndDlg, EF_ITEMID, dlgInfo.fUseDlgItemID );
  413.     WinEnableControl( hwndDlg, ST_ITEMID, dlgInfo.fUseDlgItemID );
  414.     WinEnableControl( hwndDlg, EF_CNR_NAME, dlgInfo.fUseDlgDragNames );
  415.     WinEnableControl( hwndDlg, EF_SOURCE_NAME, dlgInfo.fUseDlgDragNames );
  416.     WinEnableControl( hwndDlg, EF_TARGET_NAME, dlgInfo.fUseDlgDragNames );
  417.     WinEnableControl( hwndDlg, ST_CNR_NAME, dlgInfo.fUseDlgDragNames );
  418.     WinEnableControl( hwndDlg, ST_SOURCE_NAME, dlgInfo.fUseDlgDragNames );
  419.     WinEnableControl( hwndDlg, ST_TARGET_NAME, dlgInfo.fUseDlgDragNames );
  420. }
  421.  
  422. /**********************************************************************/
  423. /*--------------------------- DumpDlgInfo ----------------------------*/
  424. /*                                                                    */
  425. /*  DUMP OUR CONTROL TEXT TO THE GLOBAL DLGINFO STRUCTURE             */
  426. /*                                                                    */
  427. /*  PARMS: dialog box window handle                                   */
  428. /*                                                                    */
  429. /*  NOTES:                                                            */
  430. /*                                                                    */
  431. /*  RETURNS: nothing                                                  */
  432. /*                                                                    */
  433. /*--------------------------------------------------------------------*/
  434. /**********************************************************************/
  435. void DumpDlgInfo( HWND hwndDlg )
  436. {
  437.     char  szToUl[ 50 ];
  438.     int   i;
  439.     SHORT sItemIndex;
  440.     HWND  hwndLB;
  441.  
  442.     WinQueryDlgItemText( hwndDlg, CB_OPERATION, sizeof szToUl, szToUl );
  443.     for( i = 0; i < cOperations; i++ )
  444.         if( strcmp( szToUl, dcOperation[ i ].szItem ) == 0 )
  445.         {
  446.             dlgInfo.usOperation = dcOperation[ i ].iItem;
  447.             break;
  448.         }
  449.     if( i == cOperations )
  450.         dlgInfo.usOperation = atol( szToUl );
  451.  
  452.     hwndLB = WinWindowFromID( hwndDlg, LB_CONTROL );
  453.     dlgInfo.fsControl = 0;
  454.     sItemIndex = LIT_FIRST;
  455.     do
  456.     {
  457.         sItemIndex = SHORT1FROMMR( WinSendMsg( hwndLB, LM_QUERYSELECTION,
  458.                                             MPFROMSHORT( sItemIndex ), NULL ) );
  459.         if( sItemIndex != LIT_NONE )
  460.             dlgInfo.fsControl |= dcControl[ sItemIndex ].iItem;
  461.     } while( sItemIndex != LIT_NONE );
  462.  
  463.  
  464.     hwndLB = WinWindowFromID( hwndDlg, LB_SUPPORTEDOPS );
  465.     dlgInfo.fsSupportedOps = 0;
  466.     sItemIndex = LIT_FIRST;
  467.     do
  468.     {
  469.         sItemIndex = SHORT1FROMMR( WinSendMsg( hwndLB, LM_QUERYSELECTION,
  470.                                             MPFROMSHORT( sItemIndex ), NULL ) );
  471.         if( sItemIndex != LIT_NONE )
  472.             dlgInfo.fsSupportedOps |= dcSupportedOp[ sItemIndex ].iItem;
  473.     } while( sItemIndex != LIT_NONE );
  474.  
  475.     WinQueryDlgItemText( hwndDlg, EF_ITEMID, sizeof szToUl, szToUl );
  476.     dlgInfo.ulItemID = atol( szToUl );
  477.  
  478.     WinQueryDlgItemText( hwndDlg, CB_TYPE, sizeof dlgInfo.szType,
  479.                          dlgInfo.szType );
  480.     for( i = 0; i < cTypes; i++ )
  481.     {
  482.        if( !stricmp( ntsType[ i ].szName, dlgInfo.szType ) )
  483.           strcpy( dlgInfo.szType, ntsType[ i ].szString );
  484.     }
  485.  
  486.     WinQueryDlgItemText( hwndDlg, EF_CNR_NAME, sizeof dlgInfo.szContainerName,
  487.                          dlgInfo.szContainerName );
  488.     WinQueryDlgItemText( hwndDlg, EF_SOURCE_NAME, sizeof dlgInfo.szSourceName,
  489.                          dlgInfo.szSourceName );
  490.     WinQueryDlgItemText( hwndDlg, EF_TARGET_NAME, sizeof dlgInfo.szTargetName,
  491.                          dlgInfo.szTargetName );
  492.  
  493.     dlgInfo.fUseDlgItemID = WinQueryButtonCheckstate( hwndDlg,CHK_OVERRIDE_ID );
  494.     dlgInfo.fUseDlgDragNames =
  495.         WinQueryButtonCheckstate( hwndDlg, CHK_OVERRIDE_HSTRS );
  496. }
  497.  
  498. /*********************************************************************
  499.  *                      E N D   O F   S O U R C E                    *
  500.  *********************************************************************/
  501.