home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 March / PCpro_2005_03.ISO / files / systools / speedswitchxp / sswitchxp14.exe / Typical / UserOptions.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-01-14  |  9.3 KB  |  221 lines

  1. /*
  2.    SpeedswitchXP V1.4
  3.    - Windows XP CPU Frequency Control for Notebooks -
  4.  
  5.    Copyright(c) 2002-2004 Christian Diefer
  6.  
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License version 2 as 
  9.    published by the Free Software Foundation.
  10.    
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.    
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. #include "stdafx.h"
  22. #include "SpeedswitchXP.h"
  23. #include "UserOptions.h"
  24. #include "speedswitch.h"
  25.  
  26. #define TOOLTIP_ID 1
  27.  
  28. // CUserOptions dialog
  29.  
  30. IMPLEMENT_DYNAMIC(CUserOptions, CDialog)
  31. CUserOptions::CUserOptions(CWnd* pParent /*=NULL*/)
  32.     : CDialog(CUserOptions::IDD, pParent)
  33.   , m_iThrottlePolicyAC(0)
  34.   , m_iThrottlePolicyDC(0)
  35.   , m_iIdleTimeoutAC(0)
  36.   , m_iIdleTimeoutDC(0)
  37.   , m_iIdleSensAC(0)
  38.   , m_iIdleSensDC(0)
  39.   , m_iMaxSleepStateAC(0)
  40.   , m_iMaxSleepStateDC(0)
  41.   , m_iVideoTimeoutAC(0)
  42.   , m_iVideoTimeoutDC(0)
  43.   , m_iSpindownTimeoutAC(0)
  44.   , m_iSpindownTimeoutDC(0)
  45.   , m_bOptPowerAC(0)
  46.   , m_bOptPowerDC(0)
  47.   , m_iFanThrottleTolAC(0)
  48.   , m_iFanThrottleTolDC(0)
  49.   , m_iForcedThrottleAC(0)
  50.   , m_iForcedThrottleDC(0)
  51. { }
  52.  
  53. CUserOptions::~CUserOptions()
  54. { }
  55.  
  56. void CUserOptions::DoDataExchange(CDataExchange* pDX)
  57. {
  58.   CDialog::DoDataExchange(pDX);
  59.   DDX_CBIndex(pDX, IDC_COMBO1, m_iThrottlePolicyAC);
  60.   DDX_CBIndex(pDX, IDC_COMBO2, m_iThrottlePolicyDC);
  61.   DDX_Text(pDX, IDC_EDIT1, m_iIdleTimeoutAC);
  62.   DDX_Text(pDX, IDC_EDIT2, m_iIdleTimeoutDC);
  63.   DDX_Text(pDX, IDC_EDIT3, m_iIdleSensAC);
  64.   DDX_Text(pDX, IDC_EDIT4, m_iIdleSensDC);
  65.   DDX_CBIndex(pDX, IDC_COMBO3, m_iMaxSleepStateAC);
  66.   DDX_CBIndex(pDX, IDC_COMBO4, m_iMaxSleepStateDC);
  67.   DDX_Text(pDX, IDC_EDIT5, m_iVideoTimeoutAC);
  68.   DDX_Text(pDX, IDC_EDIT7, m_iVideoTimeoutDC);
  69.   DDX_Text(pDX, IDC_EDIT8, m_iSpindownTimeoutAC);
  70.   DDX_Text(pDX, IDC_EDIT6, m_iSpindownTimeoutDC);
  71.   DDX_CBIndex(pDX, IDC_COMBO5, m_bOptPowerAC);
  72.   DDX_CBIndex(pDX, IDC_COMBO6, m_bOptPowerDC);
  73.   DDX_Text(pDX, IDC_EDIT10, m_iFanThrottleTolAC);
  74.   DDX_Text(pDX, IDC_EDIT9, m_iFanThrottleTolDC);
  75.   DDX_Text(pDX, IDC_EDIT11, m_iForcedThrottleAC);
  76.   DDX_Text(pDX, IDC_EDIT12, m_iForcedThrottleDC);
  77. }
  78.  
  79. BOOL CUserOptions::OnInitDialog()
  80. {
  81.     CDialog::OnInitDialog();
  82.  
  83.   addToolTip( 0, IDC_EDIT1, "Time that the level of system activity must remain below the idle detection threshold before the system idle timer expires" );
  84.   addToolTip( 1, IDC_EDIT2, "Time that the level of system activity must remain below the idle detection threshold before the system idle timer expires" );
  85.  
  86.   addToolTip( 2, IDC_EDIT3, "Level of system activity (%) that defines the threshold for idle detection" );
  87.   addToolTip( 3, IDC_EDIT4, "Level of system activity (%) that defines the threshold for idle detection" );
  88.  
  89.   addToolTip( 4, IDC_COMBO1, "Processor dynamic throttling policy to use" );
  90.   addToolTip( 5, IDC_COMBO2, "Processor dynamic throttling policy to use" );
  91.  
  92.   addToolTip( 6, IDC_COMBO3, "Maximum system sleep state" );
  93.   addToolTip( 7, IDC_COMBO4, "Maximum system sleep state" );
  94.  
  95.   addToolTip( 8, IDC_EDIT5, "Time before the display is turned off" );
  96.   addToolTip( 9, IDC_EDIT7, "Time before the display is turned off" );
  97.  
  98.   addToolTip( 10, IDC_EDIT8, "Time before power to fixed disk drives is turned off" );
  99.   addToolTip( 11, IDC_EDIT6, "Time before power to fixed disk drives is turned off" );
  100.  
  101.   addToolTip( 12, IDC_COMBO5, "When YES, the system will turn on cooling fans and run the processor at full speed when passive cooling is specified" );
  102.   addToolTip( 13, IDC_COMBO6, "When YES, the system will turn on cooling fans and run the processor at full speed when passive cooling is specified" );
  103.  
  104.   addToolTip( 14, IDC_EDIT10, "Lower limit (%) that the processor may be throttled down to prior to turning on system fans in response to a thermal event" );
  105.   addToolTip( 15, IDC_EDIT9, "Lower limit (%) that the processor may be throttled down to prior to turning on system fans in response to a thermal event" );
  106.  
  107.   addToolTip( 16, IDC_EDIT11, "Processor throttle level (%) to be imposed by the system" );
  108.   addToolTip( 17, IDC_EDIT12, "Processor throttle level (%) to be imposed by the system" );
  109.  
  110.   return TRUE;
  111. }
  112.  
  113. BOOL CUserOptions::PreTranslateMessage( MSG* pMsg ) 
  114. {
  115.   for( int i=0; i<18; i++ )
  116.     m_tToolTip[i].RelayEvent( pMsg );
  117.  
  118.   return CDialog::PreTranslateMessage( pMsg );
  119. }
  120.  
  121.  
  122. BEGIN_MESSAGE_MAP(CUserOptions, CDialog)
  123. END_MESSAGE_MAP()
  124.  
  125. // CUserOptions message handlers
  126. void CUserOptions::setVars()
  127. {
  128.   m_iIdleTimeoutAC = internalPolicy.user.IdleTimeoutAc;
  129.   m_iIdleTimeoutDC = internalPolicy.user.IdleTimeoutDc;
  130.   m_iIdleSensAC = internalPolicy.user.IdleSensitivityAc;
  131.   m_iIdleSensDC = internalPolicy.user.IdleSensitivityDc;
  132.   m_iThrottlePolicyAC = internalPolicy.user.ThrottlePolicyAc;
  133.   m_iThrottlePolicyDC = internalPolicy.user.ThrottlePolicyDc;
  134.   m_iMaxSleepStateAC = internalPolicy.user.MaxSleepAc;
  135.   m_iMaxSleepStateDC = internalPolicy.user.MaxSleepDc;
  136.   m_iVideoTimeoutAC = internalPolicy.user.VideoTimeoutAc;
  137.   m_iVideoTimeoutDC = internalPolicy.user.VideoTimeoutDc;
  138.   m_iSpindownTimeoutAC = internalPolicy.user.SpindownTimeoutAc;
  139.   m_iSpindownTimeoutDC = internalPolicy.user.SpindownTimeoutDc;
  140.   m_bOptPowerAC = internalPolicy.user.OptimizeForPowerAc ? 0 : 1;
  141.   m_bOptPowerDC = internalPolicy.user.OptimizeForPowerDc ? 0 : 1;
  142.   m_iFanThrottleTolAC = internalPolicy.user.FanThrottleToleranceAc;
  143.   m_iFanThrottleTolDC = internalPolicy.user.FanThrottleToleranceDc;
  144.   m_iForcedThrottleAC = internalPolicy.user.ForcedThrottleAc;
  145.   m_iForcedThrottleDC = internalPolicy.user.ForcedThrottleDc;
  146. }
  147.  
  148. void CUserOptions::getVars()
  149. {
  150.   if( m_iIdleSensAC<0 || m_iIdleSensAC>100 )
  151.     m_iIdleSensAC = internalPolicy.user.IdleSensitivityAc;
  152.  
  153.   if( m_iIdleSensDC<0 || m_iIdleSensDC>100 )
  154.     m_iIdleSensDC = internalPolicy.user.IdleSensitivityDc;
  155.  
  156.   if( m_iFanThrottleTolAC<0 || m_iFanThrottleTolAC>100 )
  157.     m_iFanThrottleTolAC = internalPolicy.user.FanThrottleToleranceAc;
  158.  
  159.   if( m_iFanThrottleTolDC<0 || m_iFanThrottleTolDC>100 )
  160.     m_iFanThrottleTolDC = internalPolicy.user.FanThrottleToleranceDc;
  161.  
  162.   if( m_iForcedThrottleAC<0 || m_iForcedThrottleAC>100 )
  163.     m_iForcedThrottleAC = internalPolicy.user.ForcedThrottleAc;
  164.  
  165.   if( m_iForcedThrottleDC<0 || m_iForcedThrottleDC>100 )
  166.     m_iForcedThrottleDC = internalPolicy.user.ForcedThrottleDc;
  167.  
  168.   if( m_iIdleTimeoutAC != internalPolicy.user.IdleTimeoutAc
  169.   ||  m_iIdleTimeoutDC != internalPolicy.user.IdleTimeoutDc
  170.   ||  m_iIdleSensAC != internalPolicy.user.IdleSensitivityAc
  171.   ||  m_iIdleSensDC != internalPolicy.user.IdleSensitivityDc
  172.   ||  m_iThrottlePolicyAC != internalPolicy.user.ThrottlePolicyAc
  173.   ||  m_iThrottlePolicyDC != internalPolicy.user.ThrottlePolicyDc
  174.   ||  ((SYSTEM_POWER_STATE)m_iMaxSleepStateAC) != internalPolicy.user.MaxSleepAc
  175.   ||  ((SYSTEM_POWER_STATE)m_iMaxSleepStateDC) != internalPolicy.user.MaxSleepDc
  176.   ||  m_iVideoTimeoutAC != internalPolicy.user.VideoTimeoutAc
  177.   ||  m_iVideoTimeoutDC != internalPolicy.user.VideoTimeoutDc
  178.   ||  m_iSpindownTimeoutAC != internalPolicy.user.SpindownTimeoutAc
  179.   ||  m_iSpindownTimeoutDC != internalPolicy.user.SpindownTimeoutDc
  180.   ||  m_bOptPowerAC != (internalPolicy.user.OptimizeForPowerAc ? 0 : 1)
  181.   ||  m_bOptPowerDC != (internalPolicy.user.OptimizeForPowerDc ? 0 : 1)
  182.   ||  m_iFanThrottleTolAC != internalPolicy.user.FanThrottleToleranceAc
  183.   ||  m_iFanThrottleTolDC != internalPolicy.user.FanThrottleToleranceDc
  184.   ||  m_iForcedThrottleAC != internalPolicy.user.ForcedThrottleAc
  185.   ||  m_iForcedThrottleDC != internalPolicy.user.ForcedThrottleDc )
  186.     power = TRUE;
  187.   else
  188.   {
  189.     power = FALSE;
  190.     return;
  191.   }
  192.  
  193.   internalPolicy.user.IdleTimeoutAc = m_iIdleTimeoutAC;
  194.   internalPolicy.user.IdleTimeoutDc = m_iIdleTimeoutDC;
  195.   internalPolicy.user.IdleSensitivityAc = m_iIdleSensAC;
  196.   internalPolicy.user.IdleSensitivityDc = m_iIdleSensDC;
  197.   internalPolicy.user.ThrottlePolicyAc = m_iThrottlePolicyAC;
  198.   internalPolicy.user.ThrottlePolicyDc = m_iThrottlePolicyDC;
  199.   internalPolicy.user.MaxSleepAc = (SYSTEM_POWER_STATE)m_iMaxSleepStateAC;
  200.   internalPolicy.user.MaxSleepDc = (SYSTEM_POWER_STATE)m_iMaxSleepStateDC;
  201.   internalPolicy.user.VideoTimeoutAc = m_iVideoTimeoutAC;
  202.   internalPolicy.user.VideoTimeoutDc = m_iVideoTimeoutDC;
  203.   internalPolicy.user.SpindownTimeoutAc = m_iSpindownTimeoutAC;
  204.   internalPolicy.user.SpindownTimeoutDc = m_iSpindownTimeoutDC;
  205.   internalPolicy.user.OptimizeForPowerAc = m_bOptPowerAC==0;
  206.   internalPolicy.user.OptimizeForPowerDc = m_bOptPowerDC==0;
  207.   internalPolicy.user.FanThrottleToleranceAc = m_iFanThrottleTolAC;
  208.   internalPolicy.user.FanThrottleToleranceDc = m_iFanThrottleTolDC;
  209.   internalPolicy.user.ForcedThrottleAc = m_iForcedThrottleAC;
  210.   internalPolicy.user.ForcedThrottleDc = m_iForcedThrottleDC;
  211. }
  212.  
  213. void CUserOptions::addToolTip( int no, int id, char* str )
  214. {
  215.   CWnd* wnd = GetDlgItem( id );
  216.   CRect rect; 
  217.   wnd->GetClientRect( rect );
  218.   m_tToolTip[no].Create( wnd );
  219.   m_tToolTip[no].AddTool( wnd, str, rect, TOOLTIP_ID );
  220. }
  221.