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

  1. /*********************************************************************
  2.  *                                                                   *
  3.  * MODULE NAME :  dlgreply.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 Drag/Drop   *
  11.  *  message replies.                                                 *
  12.  *                                                                   *
  13.  * NOTES:                                                            *
  14.  *                                                                   *
  15.  * FUNCTIONS CALLABLE BY OTHER MODULES:                              *
  16.  *                                                                   *
  17.  *   wpReply                                                         *
  18.  *                                                                   *
  19.  *                                                                   *
  20.  * HISTORY:                                                          *
  21.  *                                                                   *
  22.  *  07-26-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_WINSTDCNR
  46. #define  INCL_WINSTDDRAG
  47. #define  INCL_WINWINDOWMGR
  48.  
  49. /*********************************************************************/
  50. /*----------------------------- INCLUDES ----------------------------*/
  51. /*********************************************************************/
  52.  
  53. #include <os2.h>
  54. #include <stdio.h>
  55. #include <stdlib.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.  
  82. /*********************************************************************/
  83. /*------------------------ GLOBAL VARIABLES -------------------------*/
  84. /*********************************************************************/
  85.  
  86.  
  87. /**********************************************************************/
  88. /*----------------------------- wpReply ------------------------------*/
  89. /*                                                                    */
  90. /*  DIALOG BOX PROCEDURE FOR THE REPLY DIALOG BOX                     */
  91. /*                                                                    */
  92. /*  PARMS: standard window proc parms                                 */
  93. /*                                                                    */
  94. /*  NOTES:                                                            */
  95. /*                                                                    */
  96. /*  RETURNS: message result                                           */
  97. /*                                                                    */
  98. /*--------------------------------------------------------------------*/
  99. /**********************************************************************/
  100. MRESULT EXPENTRY wpReply( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  101. {
  102.     switch( msg )
  103.     {
  104.         case WM_INITDLG:
  105.             InitControls( hwnd );
  106.             return (MRESULT) TRUE;  // Return TRUE to retain any changed focus
  107.  
  108.         case WM_COMMAND:
  109.             if( wmCommand( hwnd, SHORT1FROMMP( mp1 ) ) )
  110.                 return 0;
  111.             else
  112.                 break;
  113.  
  114.         case WM_SETFOCUS:
  115.             if( mp2 )
  116.                 WinPostMsg( hwnd, UM_SET_FOCUS, NULL, NULL );
  117.             break;
  118.  
  119.         case UM_SET_FOCUS:
  120.         {
  121.             PPAGEDATA pPageData = WinQueryWindowPtr( hwnd, QWL_USER );
  122.             if( pPageData )
  123.                 WinSetFocus( HWND_DESKTOP,
  124.                              WinWindowFromID( hwnd, pPageData->idFocus ) );
  125.             return 0;
  126.         }
  127.  
  128.         case UM_GET_FOCUS_ID:
  129.             return (MRESULT) CHK_OVERRIDE_DRAGOVER;
  130.  
  131.         case WM_CONTROL:
  132.             wmControl( hwnd, SHORT1FROMMP( mp1 ), SHORT2FROMMP( mp1 ) );
  133.             return 0;
  134.  
  135.         case UM_DUMP_DLGINFO:
  136.             DumpDlgInfo( hwnd );
  137.             break;
  138.     }
  139.  
  140.     return WinDefDlgProc( hwnd, msg, mp1, mp2 );
  141. }
  142.  
  143. /**********************************************************************/
  144. /*---------------------------- InitControls --------------------------*/
  145. /*                                                                    */
  146. /*  INITIALIZE ALL CONTROLS ON THE DIALOG BOX.                        */
  147. /*                                                                    */
  148. /*  PARMS: window handle of dialog box                                */
  149. /*                                                                    */
  150. /*  NOTES:                                                            */
  151. /*                                                                    */
  152. /*  RETURNS: nothing                                                  */
  153. /*                                                                    */
  154. /*--------------------------------------------------------------------*/
  155. /**********************************************************************/
  156. void InitControls( HWND hwndDlg )
  157. {
  158.     int   i;
  159.     HWND  hwndLB;
  160.  
  161.     hwndLB = WinWindowFromID( hwndDlg, CB_DROP_ACTION );
  162.     for( i = 0; i < cDragoverReplyTypes; i++ )
  163.         WinInsertLboxItem( hwndLB, LIT_END, dcDragoverReply[ i ].szItem );
  164.  
  165.     hwndLB = WinWindowFromID( hwndDlg, CB_DEFAULT_OP );
  166.     for( i = 0; i < cOperations; i++ )
  167.         WinInsertLboxItem( hwndLB, LIT_END, dcOperation[ i ].szItem );
  168.  
  169.     hwndLB = WinWindowFromID( hwndDlg, CB_PRINTER_REPLY );
  170.     for( i = 0; i < cPrintReplyTypes; i++ )
  171.         WinInsertLboxItem( hwndLB, LIT_END, dcPrintReply[ i ].szItem );
  172.  
  173.     hwndLB = WinWindowFromID( hwndDlg, CB_SHREDDER_REPLY );
  174.     for( i = 0; i < cPrintReplyTypes; i++ )
  175.         WinInsertLboxItem( hwndLB, LIT_END, dcPrintReply[ i ].szItem );
  176.  
  177.     UpdateControls( hwndDlg );
  178. }
  179.  
  180. /**********************************************************************/
  181. /*---------------------------- wmCommand -----------------------------*/
  182. /*                                                                    */
  183. /*  THE DIALOG PROC GOT A WM_COMMAND MESSAGE.                         */
  184. /*                                                                    */
  185. /*  PARMS: dialog box window handle,                                  */
  186. /*         command id                                                 */
  187. /*                                                                    */
  188. /*  NOTES:                                                            */
  189. /*                                                                    */
  190. /*  RETURNS: TRUE or FALSE if command was processed                   */
  191. /*                                                                    */
  192. /*--------------------------------------------------------------------*/
  193. /**********************************************************************/
  194. BOOL wmCommand( HWND hwndDlg, USHORT idCommand )
  195. {
  196.     BOOL fProcessed = FALSE;
  197.  
  198.     switch( idCommand )
  199.     {
  200.         case DID_OK:
  201.         case DID_CANCEL:
  202.             fProcessed = TRUE;
  203.             break;
  204.  
  205.         case PB_UNDO:
  206.             Undo( hwndDlg );
  207.             fProcessed = TRUE;
  208.             break;
  209.  
  210.         case PB_DEFAULT:
  211.             Defaults( hwndDlg );
  212.             fProcessed = TRUE;
  213.             break;
  214.     }
  215.  
  216.     return fProcessed;
  217. }
  218.  
  219. /**********************************************************************/
  220. /*------------------------------- Undo -------------------------------*/
  221. /*                                                                    */
  222. /*  UNDO (GET THE DLGINFO DATA FROM THE INI FILE)                     */
  223. /*                                                                    */
  224. /*  PARMS: dialog box window handle                                   */
  225. /*                                                                    */
  226. /*  NOTES:                                                            */
  227. /*                                                                    */
  228. /*  RETURNS: nothing                                                  */
  229. /*                                                                    */
  230. /*--------------------------------------------------------------------*/
  231. /**********************************************************************/
  232. void Undo( HWND hwndDlg )
  233. {
  234.     DLGINFO dlgInfoLocal;
  235.  
  236.     if( RetrieveDlgInfo( ANCHOR( hwndDlg ), &dlgInfoLocal ) )
  237.     {
  238.         UpdateGlobalDlgInfo( &dlgInfoLocal );
  239.         UpdateControls( hwndDlg );
  240.     }
  241.     else
  242.         Defaults( hwndDlg );
  243. }
  244.  
  245. /**********************************************************************/
  246. /*---------------------------- Defaults ------------------------------*/
  247. /*                                                                    */
  248. /*  SET THE DLGINFO STRUCTURE BACK TO DEFAULTS (ONLY OUR FIELDS)      */
  249. /*                                                                    */
  250. /*  PARMS: dialog box window handle                                   */
  251. /*                                                                    */
  252. /*  NOTES:                                                            */
  253. /*                                                                    */
  254. /*  RETURNS: nothing                                                  */
  255. /*                                                                    */
  256. /*--------------------------------------------------------------------*/
  257. /**********************************************************************/
  258. void Defaults( HWND hwndDlg )
  259. {
  260.     UpdateGlobalDlgInfo( &dlgInfoDefaults );
  261.     UpdateControls( hwndDlg );
  262. }
  263.  
  264. /**********************************************************************/
  265. /*------------------------ UpdateGlobalDlgInfo -----------------------*/
  266. /*                                                                    */
  267. /*  UPDATE OUR FIELDS IN THE GLOBAL DLGINFO STRUCTURE                 */
  268. /*                                                                    */
  269. /*  PARMS: pointer to a local DLGINFO structure                       */
  270. /*                                                                    */
  271. /*  NOTES:                                                            */
  272. /*                                                                    */
  273. /*  RETURNS: nothing                                                  */
  274. /*                                                                    */
  275. /*--------------------------------------------------------------------*/
  276. /**********************************************************************/
  277. void UpdateGlobalDlgInfo( PDLGINFO pDlgInfoNew )
  278. {
  279.     dlgInfo.fUseDlgDragOvers = pDlgInfoNew->fUseDlgDragOvers;
  280.     dlgInfo.ulPrinterReply   = pDlgInfoNew->ulPrinterReply;
  281.     dlgInfo.ulShredderReply  = pDlgInfoNew->ulShredderReply;
  282.     dlgInfo.usDragOverDrop   = pDlgInfoNew->usDragOverDrop;
  283.     dlgInfo.usDragOverDefOp  = pDlgInfoNew->usDragOverDefOp;
  284. }
  285.  
  286. /**********************************************************************/
  287. /*----------------------------- wmControl ----------------------------*/
  288. /*                                                                    */
  289. /*  THE DIALOG PROC GOT A WM_CONTROL MESSAGE.                         */
  290. /*                                                                    */
  291. /*  PARMS: dialog box window handle,                                  */
  292. /*         control id,                                                */
  293. /*         notify code                                                */
  294. /*                                                                    */
  295. /*  NOTES:                                                            */
  296. /*                                                                    */
  297. /*  RETURNS: nothing                                                  */
  298. /*                                                                    */
  299. /*--------------------------------------------------------------------*/
  300. /**********************************************************************/
  301. void wmControl( HWND hwndDlg, USHORT idControl, USHORT usEvent )
  302. {
  303.     // Since replies are needed when other processes start the drag, we need to
  304.     // always keep the dlgInfo up-to-date. So we cause a  DumpDlgInfo if
  305.     // *anything* changes.
  306.  
  307.     switch( idControl )
  308.     {
  309.         case CHK_OVERRIDE_DRAGOVER:
  310.             if( usEvent == BN_CLICKED )
  311.             {
  312.                 BOOL fChecked =
  313.                     WinQueryButtonCheckstate( hwndDlg, CHK_OVERRIDE_DRAGOVER );
  314.  
  315.                 WinEnableControl( hwndDlg, CB_DROP_ACTION, fChecked );
  316.                 WinEnableControl( hwndDlg, CB_DEFAULT_OP, fChecked );
  317.                 WinEnableControl( hwndDlg, ST_DROP_ACTION, fChecked );
  318.                 WinEnableControl( hwndDlg, ST_DEFAULT_OP, fChecked );
  319.  
  320.                 WinPostMsg( hwndDlg, UM_DUMP_DLGINFO, NULL, NULL );
  321.             }
  322.  
  323.             break;
  324.  
  325.         case CB_DROP_ACTION:
  326.         case CB_DEFAULT_OP:
  327.         case CB_PRINTER_REPLY:
  328.         case CB_SHREDDER_REPLY:
  329.             if( usEvent == CBN_EFCHANGE )
  330.                 WinPostMsg( hwndDlg, UM_DUMP_DLGINFO, NULL, NULL );
  331.  
  332.             break;
  333.     }
  334. }
  335.  
  336. /**********************************************************************/
  337. /*-------------------------- UpdateControls --------------------------*/
  338. /*                                                                    */
  339. /*  UPDATE THE CONTROLS IN THE DIALOG BOX                             */
  340. /*                                                                    */
  341. /*  PARMS: dialog box window handle                                   */
  342. /*                                                                    */
  343. /*  NOTES:                                                            */
  344. /*                                                                    */
  345. /*  RETURNS: nothing                                                  */
  346. /*                                                                    */
  347. /*--------------------------------------------------------------------*/
  348. /**********************************************************************/
  349. void UpdateControls( HWND hwndDlg )
  350. {
  351.     int i;
  352.  
  353.     for( i = 0; i < cDragoverReplyTypes; i++ )
  354.         if( dlgInfo.usDragOverDrop == dcDragoverReply[ i ].iItem )
  355.         {
  356.             WinSetDlgItemText( hwndDlg, CB_DROP_ACTION,
  357.                                dcDragoverReply[ i ].szItem );
  358.             break;
  359.         }
  360.  
  361.     for( i = 0; i < cOperations; i++ )
  362.         if( dlgInfo.usDragOverDefOp == dcOperation[ i ].iItem )
  363.         {
  364.             WinSetDlgItemText( hwndDlg, CB_DEFAULT_OP,
  365.                                dcOperation[ i ].szItem );
  366.             break;
  367.         }
  368.  
  369.     for( i = 0; i < cPrintReplyTypes; i++ )
  370.         if( dlgInfo.ulPrinterReply == dcPrintReply[ i ].iItem )
  371.         {
  372.             WinSetDlgItemText( hwndDlg, CB_PRINTER_REPLY,
  373.                                dcPrintReply[ i ].szItem );
  374.             break;
  375.         }
  376.  
  377.     for( i = 0; i < cPrintReplyTypes; i++ )
  378.         if( dlgInfo.ulShredderReply == dcPrintReply[ i ].iItem )
  379.         {
  380.             WinSetDlgItemText( hwndDlg, CB_SHREDDER_REPLY,
  381.                                dcPrintReply[ i ].szItem );
  382.             break;
  383.         }
  384.  
  385.     WinCheckButton( hwndDlg, CHK_OVERRIDE_DRAGOVER, dlgInfo.fUseDlgDragOvers );
  386.  
  387.     WinEnableControl( hwndDlg, CB_DROP_ACTION, dlgInfo.fUseDlgDragOvers );
  388.     WinEnableControl( hwndDlg, CB_DEFAULT_OP, dlgInfo.fUseDlgDragOvers );
  389.     WinEnableControl( hwndDlg, ST_DROP_ACTION, dlgInfo.fUseDlgDragOvers );
  390.     WinEnableControl( hwndDlg, ST_DEFAULT_OP, dlgInfo.fUseDlgDragOvers );
  391. }
  392.  
  393. /**********************************************************************/
  394. /*--------------------------- DumpDlgInfo ----------------------------*/
  395. /*                                                                    */
  396. /*  DUMP OUR CONTROL TEXT TO THE GLOBAL DLGINFO STRUCTURE             */
  397. /*                                                                    */
  398. /*  PARMS: dialog box window handle                                   */
  399. /*                                                                    */
  400. /*  NOTES:                                                            */
  401. /*                                                                    */
  402. /*  RETURNS: nothing                                                  */
  403. /*                                                                    */
  404. /*--------------------------------------------------------------------*/
  405. /**********************************************************************/
  406. void DumpDlgInfo( HWND hwndDlg )
  407. {
  408.     char szToUl[ 50 ];
  409.     int  i;
  410.  
  411.     WinQueryDlgItemText( hwndDlg, CB_DROP_ACTION, sizeof szToUl, szToUl );
  412.     for( i = 0; i < cDragoverReplyTypes; i++ )
  413.         if( strcmp( szToUl, dcDragoverReply[ i ].szItem ) == 0 )
  414.         {
  415.             dlgInfo.usDragOverDrop = dcDragoverReply[ i ].iItem;
  416.             break;
  417.         }
  418.  
  419.     WinQueryDlgItemText( hwndDlg, CB_DEFAULT_OP, sizeof szToUl, szToUl );
  420.     for( i = 0; i < cOperations; i++ )
  421.         if( strcmp( szToUl, dcOperation[ i ].szItem ) == 0 )
  422.         {
  423.             dlgInfo.usDragOverDefOp = dcOperation[ i ].iItem;
  424.             break;
  425.         }
  426.  
  427.     WinQueryDlgItemText( hwndDlg, CB_PRINTER_REPLY, sizeof szToUl, szToUl );
  428.     for( i = 0; i < cPrintReplyTypes; i++ )
  429.         if( strcmp( szToUl, dcPrintReply[ i ].szItem ) == 0 )
  430.         {
  431.             dlgInfo.ulPrinterReply = dcPrintReply[ i ].iItem;
  432.             break;
  433.         }
  434.  
  435.     WinQueryDlgItemText( hwndDlg, CB_SHREDDER_REPLY, sizeof szToUl, szToUl );
  436.     for( i = 0; i < cPrintReplyTypes; i++ )
  437.         if( strcmp( szToUl, dcPrintReply[ i ].szItem ) == 0 )
  438.         {
  439.             dlgInfo.ulShredderReply = dcPrintReply[ i ].iItem;
  440.             break;
  441.         }
  442.  
  443.     dlgInfo.fUseDlgDragOvers =
  444.         WinQueryButtonCheckstate( hwndDlg, CHK_OVERRIDE_DRAGOVER );
  445. }
  446.  
  447. /*********************************************************************
  448.  *                      E N D   O F   S O U R C E                    *
  449.  *********************************************************************/
  450.