home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1995 March / SOFM_Mar1995.bin / pc / utility / os2 / clock / config.cpp < prev    next >
Text File  |  1995-01-27  |  18KB  |  466 lines

  1. /***************************************************************** CONFIG.CPP
  2.  *                                                                          *
  3.  *                        Clock Configuration Dialog                        *
  4.  *                                                                          *
  5.  ****************************************************************************/
  6.  
  7. #define INCL_BASE
  8. #define INCL_PM
  9. #define INCL_WINSTDSPIN
  10. #include <os2.h>
  11.  
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #include "debug.h"
  16. #include "support.h"
  17. #include "config.h"
  18.  
  19.  
  20. /****************************************************************************
  21.  *                                                                          *
  22.  *                     Definitions & Declarations                           *
  23.  *                                                                          *
  24.  ****************************************************************************/
  25.  
  26.   // Constants
  27.  
  28. enum
  29. {
  30.   IDD_ANALOG,
  31.   IDD_DIGITAL,
  32.   IDD_HOUR24,
  33.   IDD_HIDECONTROLS,
  34.   IDD_CHIME,
  35.   IDD_FLOAT,
  36.   IDD_ANIMATE,
  37.   IDD_TASKCOUNT,
  38.   IDD_CPULOAD,
  39.   IDD_TASKCOUNTRED,
  40.   IDD_TASKCOUNTYELLOW,
  41.   IDD_CPULOADRED,
  42.   IDD_CPULOADYELLOW
  43. } ;
  44.  
  45.  
  46.   // Type Definitions
  47.  
  48. typedef struct
  49. {
  50.   BOOL   Analog ;
  51.   BOOL   Hour24 ;
  52.   BOOL   HideControls ;
  53.   BOOL   Chime ;
  54.   BOOL   Float ;
  55.   BOOL   Animate ;
  56.   USHORT AlertType ;
  57.   USHORT AlertLevels [2] [2] ;
  58.   PCONFIG_PARMS Parms ;
  59. }
  60. DATA, *PDATA ;
  61.  
  62.  
  63.   // Function Prototypes
  64.  
  65. static METHODFUNCTION InitDlg ;
  66. static METHODFUNCTION Control ;
  67. static METHODFUNCTION Command ;
  68. static METHODFUNCTION OK ;
  69. static METHODFUNCTION Cancel ;
  70.  
  71.  
  72.   // Global Data (local to this module)
  73.  
  74. static DATA Data ;
  75.  
  76.  
  77. /****************************************************************************
  78.  *                                                                          *
  79.  *      "Configure" Dialog Processor                                            *
  80.  *                                                                          *
  81.  ****************************************************************************/
  82.  
  83. extern MRESULT EXPENTRY ConfigureProcessor
  84. (
  85.   HWND hwnd,
  86.   ULONG msg,
  87.   MPARAM mp1,
  88.   MPARAM mp2
  89. )
  90. {
  91.  /***************************************************************************
  92.   *                             Declarations                                *
  93.   ***************************************************************************/
  94.  
  95.   static METHOD Methods [] =
  96.   {
  97.     { WM_INITDLG, InitDlg },
  98.     { WM_CONTROL, Control },
  99.     { WM_COMMAND, Command }
  100.   } ;
  101.  
  102.  /***************************************************************************
  103.   * Dispatch the message according to the method table and return the       *
  104.   *   result.  Any messages not defined above get handled by the system     *
  105.   *   default dialog processor.                                             *
  106.   ***************************************************************************/
  107.  
  108.   return ( DispatchMessage ( hwnd, msg, mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), WinDefDlgProc ) ) ;
  109. }
  110.  
  111. /****************************************************************************
  112.  *                                                                          *
  113.  *      Initialize Dialog                                                   *
  114.  *                                                                          *
  115.  ****************************************************************************/
  116.  
  117. static MRESULT APIENTRY InitDlg
  118.   HWND hwnd, 
  119.   ULONG msg,
  120.   MPARAM mp1, 
  121.   MPARAM mp2
  122. )
  123. {
  124.  /***************************************************************************
  125.   * Local Declarations                                                      *
  126.   ***************************************************************************/
  127.  
  128.   PCONFIG_PARMS Parms ;
  129.  
  130.  /***************************************************************************
  131.   * Get initial parameters.                                                 *
  132.   ***************************************************************************/
  133.  
  134.   Parms = (PCONFIG_PARMS) ( PVOIDFROMMP ( mp2 ) ) ;
  135.  
  136.   Data.Analog       = Parms->Analog ;
  137.   Data.Hour24       = Parms->Hour24 ;
  138.   Data.HideControls = Parms->HideControls ;
  139.   Data.Chime        = Parms->Chime ;
  140.   Data.Float        = Parms->Float ;
  141.   Data.Animate      = Parms->Animate ;
  142.   Data.AlertType    = Parms->AlertType ;
  143.  
  144.   memcpy ( Data.AlertLevels, Parms->AlertLevels, sizeof(Data.AlertLevels) ) ;
  145.  
  146.   Data.Parms = Parms ;
  147.  
  148.  /***************************************************************************
  149.   * Associate the help instance.                                            *
  150.   ***************************************************************************/
  151.  
  152.   WinSetWindowUShort ( hwnd, QWS_ID, Parms->id ) ;
  153.  
  154.   if ( Parms->hwndHelp )
  155.   {
  156.     WinAssociateHelpInstance ( Parms->hwndHelp, hwnd ) ;
  157.   }
  158.  
  159.  /***************************************************************************
  160.   * Set the radio button and checkbox values.                               *
  161.   ***************************************************************************/
  162.  
  163.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_ANALOG,
  164.     BM_SETCHECK, MPFROMSHORT(Data.Analog==TRUE), 0 ) ;
  165.  
  166.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_DIGITAL,
  167.     BM_SETCHECK, MPFROMSHORT(Data.Analog==FALSE), 0 ) ;
  168.  
  169.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_HOUR24,
  170.     BM_SETCHECK, MPFROMSHORT(Data.Hour24), 0 ) ;
  171.  
  172.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_HIDECONTROLS,
  173.     BM_SETCHECK, MPFROMSHORT(Data.HideControls), 0 ) ;
  174.  
  175.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_CHIME,
  176.     BM_SETCHECK, MPFROMSHORT(Data.Chime), 0 ) ;
  177.  
  178.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_FLOAT,
  179.     BM_SETCHECK, MPFROMSHORT(Data.Float), 0 ) ;
  180.  
  181.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_ANIMATE,
  182.     BM_SETCHECK, MPFROMSHORT(Data.Animate), 0 ) ;
  183.  
  184.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_TASKCOUNT,
  185.     BM_SETCHECK, MPFROMSHORT(Data.AlertType==0), 0 ) ;
  186.  
  187.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_CPULOAD,
  188.     BM_SETCHECK, MPFROMSHORT(Data.AlertType==1), 0 ) ;
  189.  
  190.  /***************************************************************************
  191.   * Set the limits and initial values of the spin-button controls.          *
  192.   ***************************************************************************/
  193.  
  194.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_TASKCOUNTRED,
  195.     SPBM_SETLIMITS, (MPARAM)100, (MPARAM)(Data.AlertLevels[0][0]+1) ) ;
  196.  
  197.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_TASKCOUNTYELLOW,
  198.     SPBM_SETLIMITS, (MPARAM)(Data.AlertLevels[0][1]-1), (MPARAM)0 ) ;
  199.  
  200.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_CPULOADRED,
  201.     SPBM_SETLIMITS, (MPARAM)100, (MPARAM)(Data.AlertLevels[1][0]+1) ) ;
  202.  
  203.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_CPULOADYELLOW,
  204.     SPBM_SETLIMITS, (MPARAM)(Data.AlertLevels[1][1]-1), (MPARAM)0 ) ;
  205.  
  206.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_TASKCOUNTRED,
  207.     SPBM_SETCURRENTVALUE, (MPARAM)Data.AlertLevels[0][1], NULL ) ;
  208.  
  209.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_TASKCOUNTYELLOW,
  210.     SPBM_SETCURRENTVALUE, (MPARAM)Data.AlertLevels[0][0], NULL ) ;
  211.  
  212.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_CPULOADRED,
  213.     SPBM_SETCURRENTVALUE, (MPARAM)Data.AlertLevels[1][1], NULL ) ;
  214.  
  215.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_CPULOADYELLOW,
  216.     SPBM_SETCURRENTVALUE, (MPARAM)Data.AlertLevels[1][0], NULL ) ;
  217.  
  218.  /***************************************************************************
  219.   * Set input focus to the first group.                                     *
  220.   ***************************************************************************/
  221.  
  222.   if ( Data.Analog )
  223.     WinSetFocus ( HWND_DESKTOP, WinWindowFromID ( hwnd, Data.Parms->id+IDD_ANALOG ) ) ;
  224.   else
  225.     WinSetFocus ( HWND_DESKTOP, WinWindowFromID ( hwnd, Data.Parms->id+IDD_DIGITAL ) ) ;
  226.  
  227.  /***************************************************************************
  228.   * Return without error.                                                   *
  229.   ***************************************************************************/
  230.  
  231.   return ( MRFROMSHORT ( FALSE ) ) ;
  232. }
  233.  
  234. /****************************************************************************
  235.  *                                                                          *
  236.  *      Process control notifications                                       *
  237.  *                                                                          *
  238.  ****************************************************************************/
  239.  
  240. static MRESULT APIENTRY Control
  241.   HWND hwnd, 
  242.   ULONG msg,
  243.   MPARAM mp1, 
  244.   MPARAM mp2
  245. )
  246. {
  247.  /***************************************************************************
  248.   * Local Declarations                                                      *
  249.   ***************************************************************************/
  250.  
  251.   USHORT id ;
  252.   LONG   Long ;
  253.   USHORT Message ;
  254.  
  255.  /***************************************************************************
  256.   * Decode the message.  Find out what control sent it, and what the        *
  257.   *   control had to say.                                                   *
  258.   ***************************************************************************/
  259.  
  260.   id = SHORT1FROMMP ( mp1 ) ;
  261.   Message = SHORT2FROMMP ( mp1 ) ;
  262.  
  263.  /***************************************************************************
  264.   * Here we process messages from the spin buttons.                         *
  265.   ***************************************************************************/
  266.  
  267.   if ( id == (USHORT) ( Data.Parms->id+IDD_TASKCOUNTRED ) )
  268.   {
  269.     if ( ( Message == SPBN_CHANGE )
  270.       OR ( Message == SPBN_UPARROW )
  271.       OR ( Message == SPBN_DOWNARROW ) )
  272.     {
  273.       WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_TASKCOUNTRED,
  274.         SPBM_QUERYVALUE, &Long, MPFROM2SHORT(0,SPBQ_UPDATEIFVALID) ) ;
  275.       WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_TASKCOUNTYELLOW,
  276.         SPBM_SETLIMITS, (MPARAM)(Long-1), (MPARAM)0 ) ;
  277.     }
  278.   }
  279.   else if ( id == (USHORT) ( Data.Parms->id+IDD_TASKCOUNTYELLOW ) )
  280.   {
  281.     if ( ( Message == SPBN_CHANGE )
  282.       OR ( Message == SPBN_UPARROW )
  283.       OR ( Message == SPBN_DOWNARROW ) )
  284.     {
  285.       WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_TASKCOUNTYELLOW,
  286.         SPBM_QUERYVALUE, &Long, MPFROM2SHORT(0,SPBQ_UPDATEIFVALID) ) ;
  287.       WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_TASKCOUNTRED,
  288.         SPBM_SETLIMITS, (MPARAM)100, (MPARAM)(Long+1) ) ;
  289.     }
  290.   }
  291.   else if ( id == (USHORT) ( Data.Parms->id+IDD_CPULOADRED ) )
  292.   {
  293.     if ( ( Message == SPBN_CHANGE )
  294.       OR ( Message == SPBN_UPARROW )
  295.       OR ( Message == SPBN_DOWNARROW ) )
  296.     {
  297.       WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_CPULOADRED,
  298.         SPBM_QUERYVALUE, &Long, MPFROM2SHORT(0,SPBQ_UPDATEIFVALID) ) ;
  299.       WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_CPULOADYELLOW,
  300.         SPBM_SETLIMITS, (MPARAM)(Long-1), (MPARAM)0 ) ;
  301.     }
  302.   }
  303.   else if ( id == (USHORT) ( Data.Parms->id+IDD_CPULOADYELLOW ) )
  304.   {
  305.     if ( ( Message == SPBN_CHANGE )
  306.       OR ( Message == SPBN_UPARROW )
  307.       OR ( Message == SPBN_DOWNARROW ) )
  308.     {
  309.       WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_CPULOADYELLOW,
  310.         SPBM_QUERYVALUE, &Long, MPFROM2SHORT(0,SPBQ_UPDATEIFVALID) ) ;
  311.       WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_CPULOADRED,
  312.         SPBM_SETLIMITS, (MPARAM)100, (MPARAM)(Long+1) ) ;
  313.     }
  314.   }
  315.  
  316.  /***************************************************************************
  317.   * Return without error.                                                   *
  318.   ***************************************************************************/
  319.  
  320.   return ( MRFROMSHORT ( FALSE ) ) ;
  321. }
  322.  
  323. /****************************************************************************
  324.  *                                                                          *
  325.  *      Process commands received by the Configure Dialog                       *
  326.  *                                                                          *
  327.  ****************************************************************************/
  328.  
  329. static MRESULT APIENTRY Command
  330.   HWND hwnd, 
  331.   ULONG msg, 
  332.   MPARAM mp1, 
  333.   MPARAM mp2
  334. )
  335. {
  336.  /***************************************************************************
  337.   * Local Declarations                                                      *
  338.   ***************************************************************************/
  339.  
  340.   static METHOD Methods [] =
  341.   {
  342.     { DID_OK,     OK     },
  343.     { DID_CANCEL, Cancel },
  344.   } ;
  345.  
  346.  /***************************************************************************
  347.   * Dispatch the message without a default message processor.               *
  348.   ***************************************************************************/
  349.  
  350.   return ( DispatchMessage ( hwnd, SHORT1FROMMP(mp1), mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), 0 ) ) ;
  351. }
  352.  
  353. /****************************************************************************
  354.  *                                                                          *
  355.  *      Process the Configure Dialog's OK button being pressed.             *
  356.  *                                                                          *
  357.  ****************************************************************************/
  358.  
  359. static MRESULT APIENTRY OK
  360.   HWND hwnd, 
  361.   ULONG msg, 
  362.   MPARAM mp1, 
  363.   MPARAM mp2
  364. )
  365. {
  366.  /***************************************************************************
  367.   * Local Declarations                                                      *
  368.   ***************************************************************************/
  369.  
  370.   LONG Long ;
  371.  
  372.  /***************************************************************************
  373.   * Query the buttons for their new settings.                               *
  374.   ***************************************************************************/
  375.  
  376.   Data.Analog = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  377.     Data.Parms->id+IDD_ANALOG, BM_QUERYCHECK, 0L, 0L ) ) ;
  378.  
  379.   Data.Hour24 = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  380.     Data.Parms->id+IDD_HOUR24, BM_QUERYCHECK, 0L, 0L ) ) ;
  381.  
  382.   Data.HideControls = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  383.     Data.Parms->id+IDD_HIDECONTROLS, BM_QUERYCHECK, 0L, 0L ) ) ;
  384.  
  385.   Data.Chime = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  386.     Data.Parms->id+IDD_CHIME, BM_QUERYCHECK, 0L, 0L ) ) ;
  387.  
  388.   Data.Float = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  389.     Data.Parms->id+IDD_FLOAT, BM_QUERYCHECK, 0L, 0L ) ) ;
  390.  
  391.   Data.Animate = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  392.     Data.Parms->id+IDD_ANIMATE, BM_QUERYCHECK, 0L, 0L ) ) ;
  393.  
  394.   Data.AlertType = (USHORT) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  395.     Data.Parms->id+IDD_CPULOAD, BM_QUERYCHECK, 0L, 0L ) ) ;
  396.  
  397.  /***************************************************************************
  398.   * Query the spinbuttons for their new settings.                           *
  399.   ***************************************************************************/
  400.  
  401.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_TASKCOUNTRED,
  402.     SPBM_QUERYVALUE, &Long, MPFROM2SHORT(0,SPBQ_UPDATEIFVALID) ) ;
  403.   Data.AlertLevels[0][1] = (USHORT) Long ;
  404.  
  405.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_TASKCOUNTYELLOW,
  406.     SPBM_QUERYVALUE, &Long, MPFROM2SHORT(0,SPBQ_UPDATEIFVALID) ) ;
  407.   Data.AlertLevels[0][0] = (USHORT) Long ;
  408.  
  409.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_CPULOADRED,
  410.     SPBM_QUERYVALUE, &Long, MPFROM2SHORT(0,SPBQ_UPDATEIFVALID) ) ;
  411.   Data.AlertLevels[1][1] = (USHORT) Long ;
  412.  
  413.   WinSendDlgItemMsg ( hwnd, Data.Parms->id+IDD_CPULOADYELLOW,
  414.     SPBM_QUERYVALUE, &Long, MPFROM2SHORT(0,SPBQ_UPDATEIFVALID) ) ;
  415.   Data.AlertLevels[1][0] = (USHORT) Long ;
  416.  
  417.  /***************************************************************************
  418.   * Save the altered data to the original parameter block.                  *
  419.   ***************************************************************************/
  420.  
  421.   Data.Parms->Analog       = Data.Analog ;
  422.   Data.Parms->Hour24       = Data.Hour24 ;
  423.   Data.Parms->HideControls = Data.HideControls ;
  424.   Data.Parms->Chime        = Data.Chime ;
  425.   Data.Parms->Float        = Data.Float ;
  426.   Data.Parms->Animate      = Data.Animate ;
  427.   Data.Parms->AlertType    = Data.AlertType ;
  428.  
  429.   memcpy ( Data.Parms->AlertLevels, Data.AlertLevels, sizeof(Data.AlertLevels) ) ;
  430.  
  431.  /***************************************************************************
  432.   * Dismiss the dialog with a TRUE status.                                  *
  433.   ***************************************************************************/
  434.  
  435.   WinDismissDlg ( hwnd, TRUE ) ;
  436.  
  437.   return ( 0 ) ;
  438. }
  439.  
  440. /****************************************************************************
  441.  *                                                                          *
  442.  *      Process the Configure Dialog's being cancelled.                     *
  443.  *                                                                          *
  444.  ****************************************************************************/
  445.  
  446. static MRESULT APIENTRY Cancel
  447.   HWND hwnd, 
  448.   ULONG msg, 
  449.   MPARAM mp1, 
  450.   MPARAM mp2
  451. )
  452. {
  453.  /***************************************************************************
  454.   * Dismiss the dialog with a TRUE status.                                  *
  455.   ***************************************************************************/
  456.  
  457.   WinDismissDlg ( hwnd, FALSE ) ;
  458.  
  459.   return ( 0 ) ;
  460. }
  461.