home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / os2 / clock / config.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-08  |  15.1 KB  |  455 lines

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