home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / memsz331.zip / Source.zip / ITEMS.H < prev    next >
Text File  |  1996-11-29  |  16KB  |  436 lines

  1. /******************************************************************** ITEMS.H
  2.  *                                                                          *
  3.  *                     Display Item Class Definition                        *
  4.  *                                                                          *
  5.  ****************************************************************************/
  6.  
  7. #ifndef ITEMS_H
  8. #define ITEMS_H
  9.  
  10. #ifndef OS2_INCLUDED
  11.    #define INCL_BASE
  12.    #define INCL_PM
  13.    #include <os2.h>
  14. #endif
  15.  
  16. #include <time.h>
  17.  
  18. #include "Dde.h"
  19. #include "ReString.h"
  20.  
  21. extern void Log ( char *Message, ... ) ;
  22.  
  23. class Item {
  24.  
  25.    private:
  26.       USHORT Id ;                  // Item ID.
  27.       BOOL   Flag ;                // Flag: Show this item at this time?
  28.       char   Name [80] ;           // Text for items profile name.
  29.       char   DefaultLabel [80] ;   // Text to display on left part of line (default).
  30.       Dde_Server *pDdeServer ;     // -> DDE Server object
  31.       char Topic [80] ;            // DDE Topic name
  32.       Dde_Item *pDdeItem ;         // -> DDE Item object
  33.  
  34.    protected:
  35.       char   CurrentLabel [80] ;   // Text to display on left part of line.
  36.       ULONG  Value ;               // Current value.
  37.       int    LevelSense ;          // Flag: If +1, level sensing has Error > Warning > Normal.
  38.       ULONG  MinLevel, MaxLevel ;  //       If -1, Error < Warning < Normal.  If zero, level checks are disabled.
  39.       ULONG  WarningLevel, ErrorLevel, DefaultLevels[2] ;
  40.       COLOR  NormalColors[2], WarningColors[2], ErrorColors[2] ;
  41.  
  42.    public:
  43.       Item ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, Dde_Server *ddeserver, char *topic ) ;
  44.       virtual ~Item ( ) ;
  45.  
  46.       void GetProfile ( HINI IniHandle ) ;
  47.       void PutProfile ( HINI IniHandle ) ;
  48.  
  49.       USHORT QueryId           ( void ) { return ( Id   ) ; }
  50.       BOOL   QueryFlag         ( void ) { return ( Flag ) ; }
  51.       PCHAR  QueryName         ( void ) { return ( Name ) ; }
  52.       PCHAR  QueryCurrentLabel ( void ) { return ( CurrentLabel ) ; }
  53.       PCHAR  QueryDefaultLabel ( void ) { return ( DefaultLabel ) ; }
  54.       ULONG  QueryValue        ( void ) { return ( Value ) ; }
  55.  
  56.       void SetLabel ( char *label ) { strcpy ( CurrentLabel, label ) ;  Value = 0 ; }
  57.  
  58.       void SetNormalColors ( COLOR Background, COLOR Foreground ) {
  59.          NormalColors[0] = Background ;
  60.          NormalColors[1] = Foreground ;
  61.       } /* endmethod */
  62.  
  63.       ULONG QueryMinLevel   ( ) { return ( MinLevel ) ; }
  64.       ULONG QueryMaxLevel   ( ) { return ( MaxLevel ) ; }
  65.       int   QueryLevelSense ( ) { return ( LevelSense ) ; }
  66.  
  67.       void SetMinLevel   ( ULONG Level ) { MinLevel = Level ; }
  68.       void SetMaxLevel   ( ULONG Level ) { MaxLevel = Level ; }
  69.       void SetLevelSense ( int   Sense ) { LevelSense = Sense ; }
  70.  
  71.       void QueryDefaultLevels ( ULONG &Warning, ULONG &Error ) {
  72.          Warning = DefaultLevels [0] ;
  73.          Error = DefaultLevels [1] ;
  74.       } /* endmethod */
  75.  
  76.       ULONG QueryWarningLevel ( ) { return ( WarningLevel ) ; }
  77.       void SetWarningLevel ( ULONG Level ) { WarningLevel = Level ; }
  78.       void SetWarningColors ( COLOR Background, COLOR Foreground ) {
  79.          WarningColors[0] = Background ;
  80.          WarningColors[1] = Foreground ;
  81.       } /* endmethod */
  82.  
  83.       ULONG QueryErrorLevel ( ) { return ( ErrorLevel ) ; }
  84.       void SetErrorLevel ( ULONG Level ) { ErrorLevel = Level ; }
  85.       void SetErrorColors ( COLOR Background, COLOR Foreground ) {
  86.          ErrorColors[0] = Background ;
  87.          ErrorColors[1] = Foreground ;
  88.       } /* endmethod */
  89.  
  90.       void SetFlag   ( void ) { Flag = TRUE ; }
  91.       void ResetFlag ( void ) { Flag = FALSE ; }
  92.  
  93.       void DdeUpdate ( char *Text ) ;
  94.  
  95.       void Paint ( HPS hPS, RECTL &Rectangle, 
  96.          char *Label, char *Text, ULONG NewValue, int Scale=1 ) ;
  97.  
  98.       // The following functions must be provided by all subclasses.
  99.  
  100.       virtual int Measure ( HPS hPS, RECTL &Rectangle ) = 0 ;
  101.  
  102.       virtual ULONG NewValue ( void ) = 0 ;
  103.  
  104.       virtual void FormatText ( char *Label, char *Text, ULONG Value ) = 0 ;
  105.  
  106.       virtual void FormatLine ( char *Buffer, int MaxWidth ) ;
  107.  
  108.       virtual void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) = 0 ;
  109. } ;
  110.  
  111. class Clock : public Item {
  112.  
  113.    private:
  114.       COUNTRYINFO CountryInfo ;
  115.       char szAm [8] ;
  116.       char szPm [8] ;
  117.       ResourceString *DaysOfWeek ;
  118.       BOOL ShowSeconds ;
  119.       BOOL Hour24 ;
  120.  
  121.    public:
  122.       Clock ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  123.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo,
  124.          char *szam, char *szpm, ResourceString *daysofweek, BOOL showseconds, BOOL hour24 ) ;
  125.  
  126.       void SetShowSeconds ( BOOL showseconds ) { ShowSeconds = showseconds ; Value = 0 ; }
  127.       void SetHour24 ( BOOL hour24 ) { Hour24 = hour24 ; Value = 0 ; } 
  128.  
  129.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  130.       ULONG NewValue ( void ) ;
  131.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  132.       void FormatLine ( char *Buffer, int MaxWidth ) ;
  133.       void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) ;
  134. } ;
  135.  
  136. class ElapsedTime : public Item {
  137.  
  138.    private:
  139.       COUNTRYINFO CountryInfo ;
  140.       ResourceString *Day ;
  141.       ResourceString *Days ;
  142.       BOOL ShowSeconds ;
  143.  
  144.    public:
  145.       ElapsedTime ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  146.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo,
  147.          ResourceString *day, ResourceString *days, BOOL showseconds ) ;
  148.  
  149.       void SetShowSeconds ( BOOL showseconds ) { ShowSeconds = showseconds ;  Value = 0 ; }
  150.  
  151.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  152.       ULONG NewValue ( void ) ;
  153.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  154.       void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) ;
  155. } ;
  156.  
  157. class MemoryFree : public Item {
  158.  
  159.    private:
  160.       COUNTRYINFO CountryInfo ;
  161.       USHORT ShowK, ShowTrueK, ShowM ;
  162.  
  163.    public:
  164.       MemoryFree ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  165.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo, USHORT sk, USHORT stk, USHORT sm ) ;
  166.  
  167.       void SetShowK     ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  168.       void SetShowTrueK ( USHORT flag ) { ShowTrueK = flag ;  Value = 0 ; }
  169.       void SetShowM     ( USHORT flag ) { ShowM = flag ;  Value = 0 ; }
  170.  
  171.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  172.       ULONG NewValue ( void ) ;
  173.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  174.       void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) ;
  175. } ;
  176.  
  177. class VirtualFree : public Item {
  178.  
  179.    private:
  180.       COUNTRYINFO CountryInfo ;
  181.       USHORT ShowK, ShowTrueK, ShowM ;
  182.  
  183.    public:
  184.       VirtualFree ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  185.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo, USHORT sk, USHORT stk, USHORT sm ) ;
  186.  
  187.       void SetShowK     ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  188.       void SetShowTrueK ( USHORT flag ) { ShowTrueK = flag ;  Value = 0 ; }
  189.       void SetShowM     ( USHORT flag ) { ShowM = flag ;  Value = 0 ; }
  190.  
  191.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  192.       ULONG NewValue ( void ) ;
  193.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  194.       void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) ;
  195. } ;
  196.  
  197. class SwapSize : public Item {
  198.  
  199.    private:
  200.       COUNTRYINFO CountryInfo ;
  201.       USHORT ShowK, ShowTrueK, ShowM ;
  202.       PSZ SwapPath ;
  203.  
  204.    public:
  205.       SwapSize ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  206.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO countryinfo, 
  207.          USHORT sk, USHORT stk, USHORT sm, PSZ swappath, ULONG initialsize ) ;
  208.       ~SwapSize ( void ) ;
  209.  
  210.       void SetShowK     ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  211.       void SetShowTrueK ( USHORT flag ) { ShowTrueK = flag ;  Value = 0 ; }
  212.       void SetShowM     ( USHORT flag ) { ShowM = flag ;  Value = 0 ; }
  213.  
  214.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  215.       ULONG NewValue ( void ) ;
  216.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  217.       void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) ;
  218. } ;
  219.  
  220. class SwapFree : public Item {
  221.  
  222.    private:
  223.       COUNTRYINFO CountryInfo ;
  224.       USHORT ShowK, ShowTrueK, ShowM ;
  225.       PSZ SwapPath ;
  226.       ULONG MinFree ;
  227.  
  228.    public:
  229.       SwapFree ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  230.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo,
  231.          USHORT sk, USHORT stk, USHORT sm, PSZ swappath, ULONG minfree ) ;
  232.       ~SwapFree ( void ) ;
  233.  
  234.       void SetShowK     ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  235.       void SetShowTrueK ( USHORT flag ) { ShowTrueK = flag ;  Value = 0 ; }
  236.       void SetShowM     ( USHORT flag ) { ShowM = flag ;  Value = 0 ; }
  237.  
  238.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  239.       ULONG NewValue ( void ) ;
  240.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  241.       void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) ;
  242. } ;
  243.  
  244. class SpoolSize : public Item {
  245.  
  246.    private:
  247.       COUNTRYINFO CountryInfo ;
  248.       USHORT ShowK, ShowTrueK, ShowM ;
  249.       PSZ SpoolPath ;
  250.  
  251.    public:
  252.       SpoolSize ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  253.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo, 
  254.          USHORT sk, USHORT stk, USHORT sm, PSZ spoolpath ) ;
  255.       ~SpoolSize ( void ) ;
  256.  
  257.       void SetShowK     ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  258.       void SetShowTrueK ( USHORT flag ) { ShowTrueK = flag ;  Value = 0 ; }
  259.       void SetShowM     ( USHORT flag ) { ShowM = flag ;  Value = 0 ; }
  260.  
  261.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  262.       ULONG NewValue ( void ) ;
  263.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  264.       void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) ;
  265. } ;
  266.  
  267. class CpuLoad : public Item {
  268.  
  269.    private:
  270.       PULONG IdleCount ;
  271.       ULONG MaxCount ;
  272.       ResourceString *Error ;
  273.  
  274.    public:
  275.       CpuLoad ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  276.          Dde_Server *pDdeServer, char *Topic, ULONG maxcount, PULONG idlecount, ResourceString *error ) ;
  277.  
  278.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  279.       ULONG NewValue ( void ) ;
  280.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  281.       void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) ;
  282. } ;
  283.  
  284. class TaskCount : public Item {
  285.  
  286.    private:
  287.       HAB Anchor ;
  288.  
  289.    public:
  290.       TaskCount ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  291.          Dde_Server *pDdeServer, char *Topic, HAB anchor ) ;
  292.  
  293.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  294.       ULONG NewValue ( void ) ;
  295.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  296.       void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) ;
  297. } ;
  298.  
  299. class DriveFree : public Item {
  300.  
  301.    private:
  302.       COUNTRYINFO CountryInfo ;
  303.       USHORT ShowK, ShowTrueK, ShowM ;
  304.       ResourceString *DriveError ;
  305.       USHORT DriveNumber ;
  306.       BOOL ShowFileSystemName ;
  307.       BYTE FileSystem [80] ;
  308.       BOOL ShowDiskLabel ;
  309.       BYTE DiskLabel [12] ;
  310.       BOOL Error ;
  311.  
  312.    public:
  313.       DriveFree ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  314.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo, 
  315.          USHORT sk, USHORT stk, USHORT sm, USHORT drivenumber, ResourceString *driveerror, BOOL showfilesystemname, 
  316.          PSZ filesystem, BOOL showdisklabel, PSZ disklabel ) ;
  317.  
  318.       void SetShowK     ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  319.       void SetShowTrueK ( USHORT flag ) { ShowTrueK = flag ;  Value = 0 ; }
  320.       void SetShowM     ( USHORT flag ) { ShowM = flag ;  Value = 0 ; }
  321.       void SetShowFileSystemName ( BOOL showfilesystemname ) { ShowFileSystemName = showfilesystemname ;  Value = 0 ; }
  322.       void SetShowDiskLabel ( BOOL showdisklabel ) { ShowDiskLabel = showdisklabel ;  Value = 0 ; }
  323.       void ResetError ( ) { Error = FALSE ; } 
  324.  
  325.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  326.       ULONG NewValue ( void ) ;
  327.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  328.       void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) ;
  329. } ;
  330.  
  331. class TotalFree : public Item {
  332.  
  333.    private:
  334.       COUNTRYINFO CountryInfo ;
  335.       USHORT ShowK, ShowTrueK, ShowM ;
  336.       ULONG Drives ;
  337.  
  338.    public:
  339.       TotalFree ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  340.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo, 
  341.          USHORT sk, USHORT stk, USHORT sm, ULONG drives ) ;
  342.  
  343.       void SetShowK     ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  344.       void SetShowTrueK ( USHORT flag ) { ShowTrueK = flag ;  Value = 0 ; }
  345.       void SetShowM     ( USHORT flag ) { ShowM = flag ;  Value = 0 ; }
  346.       void ResetMask ( ULONG drives ) { Drives = drives ; }
  347.       ULONG QueryMask ( ) { return ( Drives ) ; }
  348.  
  349.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  350.       ULONG NewValue ( void ) ;
  351.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  352.       void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) ;
  353. } ;
  354.  
  355. class SwapSlack : public Item {
  356.  
  357.    private:
  358.       COUNTRYINFO  CountryInfo ;
  359.       USHORT ShowK, ShowTrueK, ShowM ;
  360.       VirtualFree *pVirtualFree ;
  361.       SwapFree    *pSwapFree ;
  362.       MemoryFree  *pMemFree ;
  363.  
  364.    public:
  365.       SwapSlack ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  366.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo, 
  367.          USHORT sk, USHORT stk, USHORT sm, VirtualFree *pvf, SwapFree *psf, MemoryFree *pmf ) ;
  368.  
  369.       void SetShowK     ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  370.       void SetShowTrueK ( USHORT flag ) { ShowTrueK = flag ;  Value = 0 ; }
  371.       void SetShowM     ( USHORT flag ) { ShowM = flag ;  Value = 0 ; }
  372.  
  373.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  374.       ULONG NewValue ( void ) ;
  375.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  376.       void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) ;
  377. } ;
  378.  
  379. class ProcessCount : public Item {
  380.  
  381.    private:
  382.       PULONG DQPS_Buffer ;
  383.  
  384.    public:
  385.       ProcessCount ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel,
  386.          Dde_Server *pDdeServer, char *Topic ) ;
  387.       ~ProcessCount ( ) ;
  388.  
  389.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  390.       ULONG NewValue ( void ) ;
  391.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  392.       void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) ;
  393. } ;
  394.  
  395. extern PSZ ScanSystemConfig ( HAB Anchor, PSZ Keyword ) ;
  396.  
  397. class ThreadCount : public Item {
  398.  
  399.    private:
  400.       PULONG DQPS_Buffer ;
  401.  
  402.    public:
  403.       ThreadCount ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel,
  404.          Dde_Server *pDdeServer, char *Topic ) ;
  405.       ~ThreadCount ( ) ;
  406.  
  407.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  408.       ULONG NewValue ( void ) ;
  409.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  410.       void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) ;
  411. } ;
  412.  
  413. class Battery : public Item {
  414.  
  415.    private:
  416.       HFILE Handle ;
  417.       ResourceString *Error ;
  418.       ResourceString *Charging ;
  419.       ResourceString *AC ;
  420.  
  421.    public:
  422.       Battery ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel,
  423.          Dde_Server *pDdeServer, char *Topic, ResourceString *error, 
  424.          ResourceString *charging, ResourceString *ac ) ;
  425.       ~Battery ( ) ;
  426.  
  427.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  428.       ULONG NewValue ( void ) ;
  429.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  430.       void Repaint ( HPS hPS, RECTL &Rectangle, BOOL Mandatory ) ;
  431.  
  432.       int Discharging ( ) ;
  433. } ;
  434.  
  435. #endif
  436.