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

  1. /*********************************************************************
  2.  *                                                                   *
  3.  * MODULE NAME :  dlgmisc.c              AUTHOR:  Rick Fishman       *
  4.  * DATE WRITTEN:  07-25-93                                           *
  5.  *                                                                   *
  6.  * MODULE DESCRIPTION:                                               *
  7.  *                                                                   *
  8.  *  Part of the 'DRGDROP' drag/drop sample program.                  *
  9.  *                                                                   *
  10.  *  Dialog box handling for the Miscellaneous Options dialog box in  *
  11.  *  the Settings notebook.                                           *
  12.  *                                                                   *
  13.  * NOTES:                                                            *
  14.  *                                                                   *
  15.  * FUNCTIONS CALLABLE BY OTHER MODULES:                              *
  16.  *                                                                   *
  17.  *   wpMisc                                                          *
  18.  *                                                                   *
  19.  *                                                                   *
  20.  * HISTORY:                                                          *
  21.  *                                                                   *
  22.  *  07-25-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_WINERRORS
  42. #define  INCL_WINFRAMEMGR
  43. #define  INCL_WINSTDCNR
  44. #define  INCL_WINSTDDRAG
  45. #define  INCL_WINWINDOWMGR
  46.  
  47. /*********************************************************************/
  48. /*----------------------------- INCLUDES ----------------------------*/
  49. /*********************************************************************/
  50.  
  51. #include <os2.h>
  52. #include <stdio.h>
  53. #include <string.h>
  54. #include "drgdrop.h"
  55.  
  56. /*********************************************************************/
  57. /*------------------- APPLICATION DEFINITIONS -----------------------*/
  58. /*********************************************************************/
  59.  
  60.  
  61. /*********************************************************************/
  62. /*---------------------------- STRUCTURES ---------------------------*/
  63. /*********************************************************************/
  64.  
  65.  
  66. /*********************************************************************/
  67. /*----------------------- FUNCTION PROTOTYPES -----------------------*/
  68. /*********************************************************************/
  69.  
  70. static void InitControls( HWND hwndDlg );
  71. static BOOL wmCommand( HWND hwndDlg, USHORT idCommand );
  72. static void wmControl( HWND hwndDlg, USHORT idControl, USHORT usEvent );
  73. static void Undo( HWND hwndDlg );
  74. static void Defaults( HWND hwndDlg );
  75. static void UpdateGlobalDlgInfo( PDLGINFO pDlgInfoNew );
  76. static void UpdateControls( HWND hwndDlg );
  77. static void DumpDlgInfo( HWND hwndDlg );
  78.  
  79. /*********************************************************************/
  80. /*------------------------ GLOBAL VARIABLES -------------------------*/
  81. /*********************************************************************/
  82.  
  83. BOOL fDialogInitialized = FALSE;
  84.  
  85. /**********************************************************************/
  86. /*------------------------------ wpMisc ------------------------------*/
  87. /*                                                                    */
  88. /*  DIALOG BOX PROCEDURE FOR THE MISCELLANEOUS OPTIONS DIALOG BOX     */
  89. /*                                                                    */
  90. /*  PARMS: standard window proc parms                                 */
  91. /*                                                                    */
  92. /*  NOTES:                                                            */
  93. /*                                                                    */
  94. /*  RETURNS: message result                                           */
  95. /*                                                                    */
  96. /*--------------------------------------------------------------------*/
  97. /**********************************************************************/
  98. MRESULT EXPENTRY wpMisc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  99. {
  100.     switch( msg )
  101.     {
  102.         case WM_INITDLG:
  103.             InitControls( hwnd );
  104.             return (MRESULT) TRUE;   // Return TRUE to retain any changed focus
  105.  
  106.         case WM_COMMAND:
  107.             if( wmCommand( hwnd, SHORT1FROMMP( mp1 ) ) )
  108.                 return 0;
  109.             else
  110.                 break;
  111.  
  112.         case WM_SETFOCUS:
  113.             if( mp2 )
  114.                 WinPostMsg( hwnd, UM_SET_FOCUS, NULL, NULL );
  115.             break;
  116.  
  117.         case UM_SET_FOCUS:
  118.         {
  119.             PPAGEDATA pPageData = WinQueryWindowPtr( hwnd, QWL_USER );
  120.             if( pPageData )
  121.                 WinSetFocus( HWND_DESKTOP,
  122.                              WinWindowFromID( hwnd, pPageData->idFocus ) );
  123.             return 0;
  124.         }
  125.  
  126.         case WM_CONTROL:
  127.             wmControl( hwnd, SHORT1FROMMP( mp1 ), SHORT2FROMMP( mp1 ) );
  128.             return 0;
  129.  
  130.         case UM_GET_FOCUS_ID:
  131.             // When the notebook sends us this message we consider the dialog
  132.             // initialized.
  133.  
  134.             fDialogInitialized = TRUE;
  135.             return (MRESULT)
  136.                 (dlgInfo.fAllowAllDrops ? RB_ALL_DROPS : RB_ONLY_OS2FILE);
  137.  
  138.         case UM_DUMP_DLGINFO:
  139.             DumpDlgInfo( hwnd );
  140.             break;
  141.  
  142.         case WM_DESTROY:
  143.             fDialogInitialized = FALSE;
  144.             break;
  145.     }
  146.  
  147.     return WinDefDlgProc( hwnd, msg, mp1, mp2 );
  148. }
  149.  
  150. /**********************************************************************/
  151. /*---------------------------- InitControls --------------------------*/
  152. /*                                                                    */
  153. /*  INITIALIZE ALL CONTROLS ON THE DIALOG BOX.                        */
  154. /*                                                                    */
  155. /*  PARMS: window handle of dialog box                                */
  156. /*                                                                    */
  157. /*  NOTES:                                                            */
  158. /*                                                                    */
  159. /*  RETURNS: nothing                                                  */
  160. /*                                                                    */
  161. /*--------------------------------------------------------------------*/
  162. /**********************************************************************/
  163. void InitControls( HWND hwndDlg )
  164. {
  165.     UpdateControls( hwndDlg );
  166. }
  167.  
  168. /**********************************************************************/
  169. /*---------------------------- wmCommand -----------------------------*/
  170. /*                                                                    */
  171. /*  THE DIALOG PROC GOT A WM_COMMAND MESSAGE.                         */
  172. /*                                                                    */
  173. /*  PARMS: dialog box window handle,                                  */
  174. /*         command id                                                 */
  175. /*                                                                    */
  176. /*  NOTES:                                                            */
  177. /*                                                                    */
  178. /*  RETURNS: TRUE or FALSE if command was processed                   */
  179. /*                                                                    */
  180. /*--------------------------------------------------------------------*/
  181. /**********************************************************************/
  182. BOOL wmCommand( HWND hwndDlg, USHORT idCommand )
  183. {
  184.     BOOL fProcessed = FALSE;
  185.  
  186.     switch( idCommand )
  187.     {
  188.         case DID_OK:
  189.         case DID_CANCEL:
  190.             fProcessed = TRUE;
  191.             break;
  192.  
  193.         case PB_UNDO:
  194.             Undo( hwndDlg );
  195.             fProcessed = TRUE;
  196.             break;
  197.  
  198.         case PB_DEFAULT:
  199.             Defaults( hwndDlg );
  200.             fProcessed = TRUE;
  201.             break;
  202.     }
  203.  
  204.     return fProcessed;
  205. }
  206.  
  207. /**********************************************************************/
  208. /*------------------------------- Undo -------------------------------*/
  209. /*                                                                    */
  210. /*  UNDO (GET THE DLGINFO DATA FROM THE INI FILE)                     */
  211. /*                                                                    */
  212. /*  PARMS: dialog box window handle                                   */
  213. /*                                                                    */
  214. /*  NOTES:                                                            */
  215. /*                                                                    */
  216. /*  RETURNS: nothing                                                  */
  217. /*                                                                    */
  218. /*--------------------------------------------------------------------*/
  219. /**********************************************************************/
  220. void Undo( HWND hwndDlg )
  221. {
  222.     DLGINFO dlgInfoLocal;
  223.  
  224.     if( RetrieveDlgInfo( ANCHOR( hwndDlg ), &dlgInfoLocal ) )
  225.     {
  226.         UpdateGlobalDlgInfo( &dlgInfoLocal );
  227.         UpdateControls( hwndDlg );
  228.     }
  229.     else
  230.         Defaults( hwndDlg );
  231. }
  232.  
  233. /**********************************************************************/
  234. /*---------------------------- Defaults ------------------------------*/
  235. /*                                                                    */
  236. /*  SET THE DLGINFO STRUCTURE BACK TO DEFAULTS (ONLY OUR FIELDS)      */
  237. /*                                                                    */
  238. /*  PARMS: dialog box window handle                                   */
  239. /*                                                                    */
  240. /*  NOTES:                                                            */
  241. /*                                                                    */
  242. /*  RETURNS: nothing                                                  */
  243. /*                                                                    */
  244. /*--------------------------------------------------------------------*/
  245. /**********************************************************************/
  246. void Defaults( HWND hwndDlg )
  247. {
  248.     UpdateGlobalDlgInfo( &dlgInfoDefaults );
  249.     UpdateControls( hwndDlg );
  250. }
  251.  
  252. /**********************************************************************/
  253. /*------------------------ UpdateGlobalDlgInfo -----------------------*/
  254. /*                                                                    */
  255. /*  UPDATE OUR FIELDS IN THE GLOBAL DLGINFO STRUCTURE                 */
  256. /*                                                                    */
  257. /*  PARMS: pointer to a local DLGINFO structure                       */
  258. /*                                                                    */
  259. /*  NOTES:                                                            */
  260. /*                                                                    */
  261. /*  RETURNS: nothing                                                  */
  262. /*                                                                    */
  263. /*--------------------------------------------------------------------*/
  264. /**********************************************************************/
  265. void UpdateGlobalDlgInfo( PDLGINFO pDlgInfoNew )
  266. {
  267.     dlgInfo.fAllowAllDrops    = pDlgInfoNew->fAllowAllDrops;
  268.     dlgInfo.fOnlyMessageNames = pDlgInfoNew->fOnlyMessageNames;
  269.     dlgInfo.fOnlyFirstItem    = pDlgInfoNew->fOnlyFirstItem;
  270.     dlgInfo.fScrollToBottom   = pDlgInfoNew->fScrollToBottom;
  271. }
  272.  
  273. /**********************************************************************/
  274. /*----------------------------- wmControl ----------------------------*/
  275. /*                                                                    */
  276. /*  THE DIALOG PROC GOT A WM_CONTROL MESSAGE.                         */
  277. /*                                                                    */
  278. /*  PARMS: dialog box window handle,                                  */
  279. /*         control id,                                                */
  280. /*         notify code                                                */
  281. /*                                                                    */
  282. /*  NOTES:                                                            */
  283. /*                                                                    */
  284. /*  RETURNS: nothing                                                  */
  285. /*                                                                    */
  286. /*--------------------------------------------------------------------*/
  287. /**********************************************************************/
  288. void wmControl( HWND hwndDlg, USHORT idControl, USHORT usEvent )
  289. {
  290.     switch( idControl )
  291.     {
  292.         case RB_ALL_DROPS:
  293.         case RB_ONLY_OS2FILE:
  294.         {
  295.             PPAGEDATA pPageData = WinQueryWindowPtr( hwndDlg, QWL_USER );
  296.  
  297.             // We need to let the dialog initialize before we process click
  298.             // messages. Otherwise the click message will force our
  299.             // WinQueryButtonCheckstate to change our fAllowAllDrops flag to
  300.             // FALSE since we haven't yet set the proper state of the radio
  301.             // button.
  302.  
  303.             if( !fDialogInitialized )
  304.                 break;
  305.  
  306.             if( usEvent == BN_CLICKED )
  307.                 dlgInfo.fAllowAllDrops =
  308.                         WinQueryButtonCheckstate( hwndDlg, RB_ALL_DROPS );
  309.  
  310.             // With autoradiobuttons, we must be careful to switch the focus
  311.             // to the one that we want clicked.
  312.  
  313.             if( pPageData )
  314.                 pPageData->idFocus =
  315.                     (dlgInfo.fAllowAllDrops ? RB_ALL_DROPS : RB_ONLY_OS2FILE);
  316.         }
  317.  
  318.             break;
  319.  
  320.         case RB_ONLY_MSGNAMES:
  321.         case RB_EXPAND_STRUCTURES:
  322.             if( usEvent == BN_CLICKED )
  323.                 dlgInfo.fOnlyMessageNames =
  324.                         WinQueryButtonCheckstate( hwndDlg, RB_ONLY_MSGNAMES );
  325.             break;
  326.  
  327.         case RB_FIRST_ITEM_ONLY:
  328.         case RB_ALL_ITEMS:
  329.             if( usEvent == BN_CLICKED )
  330.                 dlgInfo.fOnlyFirstItem =
  331.                         WinQueryButtonCheckstate( hwndDlg, RB_FIRST_ITEM_ONLY );
  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.     if( dlgInfo.fAllowAllDrops )
  352.         WinCheckButton( hwndDlg, RB_ALL_DROPS, TRUE );
  353.     else
  354.         WinCheckButton( hwndDlg, RB_ONLY_OS2FILE, TRUE );
  355.  
  356.     if( dlgInfo.fOnlyMessageNames )
  357.         WinCheckButton( hwndDlg, RB_ONLY_MSGNAMES, TRUE );
  358.     else
  359.         WinCheckButton( hwndDlg, RB_EXPAND_STRUCTURES, TRUE );
  360.  
  361.     if( dlgInfo.fOnlyFirstItem )
  362.         WinCheckButton( hwndDlg, RB_FIRST_ITEM_ONLY, TRUE );
  363.     else
  364.         WinCheckButton( hwndDlg, RB_ALL_ITEMS, TRUE );
  365.  
  366.     WinCheckButton( hwndDlg, CHK_SCROLL_TO_BOTTOM, dlgInfo.fScrollToBottom );
  367. }
  368.  
  369. /**********************************************************************/
  370. /*--------------------------- DumpDlgInfo ----------------------------*/
  371. /*                                                                    */
  372. /*  DUMP OUR CONTROL TEXT TO THE GLOBAL DLGINFO STRUCTURE             */
  373. /*                                                                    */
  374. /*  PARMS: dialog box window handle                                   */
  375. /*                                                                    */
  376. /*  NOTES:                                                            */
  377. /*                                                                    */
  378. /*  RETURNS: nothing                                                  */
  379. /*                                                                    */
  380. /*--------------------------------------------------------------------*/
  381. /**********************************************************************/
  382. void DumpDlgInfo( HWND hwndDlg )
  383. {
  384.     dlgInfo.fAllowAllDrops = WinQueryButtonCheckstate( hwndDlg, RB_ALL_DROPS );
  385.     dlgInfo.fOnlyMessageNames = WinQueryButtonCheckstate( hwndDlg,
  386.                                                           RB_ONLY_MSGNAMES );
  387.     dlgInfo.fOnlyFirstItem = WinQueryButtonCheckstate( hwndDlg,
  388.                                                        RB_FIRST_ITEM_ONLY );
  389.     dlgInfo.fScrollToBottom = WinQueryButtonCheckstate( hwndDlg,
  390.                                                         CHK_SCROLL_TO_BOTTOM );
  391. }
  392.  
  393. /*********************************************************************
  394.  *                      E N D   O F   S O U R C E                    *
  395.  *********************************************************************/
  396.