Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
6.1 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: UPDNEDIT.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 1/10/2000
  12. *
  13. * DESCRIPTION: Encapsulate the updown control and edit control
  14. *
  15. *******************************************************************************/
  16. #ifndef __UPDNEDIT_H_INCLUDED
  17. #define __UPDNEDIT_H_INCLUDED
  18. #include <windows.h>
  19. #include "vwiaset.h"
  20. class CUpDownAndEdit
  21. {
  22. private:
  23. HWND m_hWndUpDown;
  24. HWND m_hWndEdit;
  25. CValidWiaSettings *m_pValidWiaSettings;
  26. public:
  27. CUpDownAndEdit(void)
  28. : m_hWndUpDown(NULL),
  29. m_hWndEdit(NULL),
  30. m_pValidWiaSettings(NULL)
  31. {
  32. }
  33. bool Initialize( HWND hWndUpDown, HWND hWndEdit, CValidWiaSettings *pValidWiaSettings )
  34. {
  35. //
  36. // Save all of these settings
  37. //
  38. m_hWndUpDown = hWndUpDown;
  39. m_hWndEdit = hWndEdit;
  40. m_pValidWiaSettings = pValidWiaSettings;
  41. //
  42. // Make sure these are valid
  43. //
  44. if (m_hWndUpDown && m_hWndEdit && m_pValidWiaSettings)
  45. {
  46. //
  47. // Set up the slider
  48. //
  49. SendMessage( m_hWndUpDown, UDM_SETRANGE32, 0, m_pValidWiaSettings->GetItemCount()-1 );
  50. //
  51. // Get the index of the intial value and set the position of the slider
  52. //
  53. int nIndex = m_pValidWiaSettings->FindIndexOfItem( m_pValidWiaSettings->InitialValue() );
  54. if (nIndex >= 0)
  55. {
  56. SendMessage( m_hWndUpDown, UDM_SETPOS32, 0, nIndex );
  57. }
  58. //
  59. // Set up the edit control
  60. //
  61. SetDlgItemInt( GetParent(m_hWndEdit), GetWindowLong(m_hWndEdit,GWL_ID), m_pValidWiaSettings->InitialValue(), TRUE );
  62. //
  63. // Everything is OK
  64. //
  65. return true;
  66. }
  67. return false;
  68. }
  69. void SetValue( LONG nValue ) const
  70. {
  71. if (IsValid())
  72. {
  73. //
  74. // Get the index of the intial value and set the position of the up down control
  75. //
  76. int nIndex = m_pValidWiaSettings->FindIndexOfItem( nValue );
  77. if (nIndex >= 0)
  78. {
  79. SendMessage( m_hWndUpDown, UDM_SETPOS32, TRUE, nIndex );
  80. }
  81. //
  82. // Set up the edit control
  83. //
  84. SetDlgItemInt( GetParent(m_hWndEdit), GetWindowLong(m_hWndEdit,GWL_ID), nValue, TRUE );
  85. }
  86. }
  87. bool ValidateEditControl(void)
  88. {
  89. BOOL bSuccess = FALSE;
  90. if (IsValid())
  91. {
  92. //
  93. // Get the current value
  94. //
  95. LONG nValue = static_cast<LONG>(GetDlgItemInt( GetParent(m_hWndEdit), GetWindowLong(m_hWndEdit,GWL_ID), &bSuccess, TRUE ));
  96. if (bSuccess)
  97. {
  98. //
  99. // Assume it isn't a valid value
  100. //
  101. bSuccess = FALSE;
  102. //
  103. // Check to see if the edit control has a legal value in it
  104. //
  105. LONG nTestValue = nValue;
  106. if (m_pValidWiaSettings->FindClosestValue(nTestValue))
  107. {
  108. if (nValue == nTestValue)
  109. {
  110. bSuccess = TRUE;
  111. }
  112. }
  113. }
  114. }
  115. return (bSuccess != FALSE);
  116. }
  117. void Restore(void)
  118. {
  119. if (IsValid())
  120. {
  121. SetValue( m_pValidWiaSettings->InitialValue() );
  122. }
  123. }
  124. bool IsValid(void) const
  125. {
  126. return (m_hWndUpDown && m_hWndEdit && m_pValidWiaSettings);
  127. }
  128. LONG GetValueFromCurrentPos(void)
  129. {
  130. WIA_PUSH_FUNCTION((TEXT("CUpDownAndEdit::GetValueFromCurrentPos")));
  131. if (IsValid())
  132. {
  133. //
  134. // Find out what the current index is
  135. //
  136. int nIndex = static_cast<int>(SendMessage( m_hWndUpDown, UDM_GETPOS32, 0, 0 ));
  137. WIA_TRACE((TEXT("nIndex = %d"), nIndex ));
  138. //
  139. // Get the value at that index, if it is valid return it
  140. //
  141. LONG nValue;
  142. if (m_pValidWiaSettings->GetItemAtIndex(nIndex,nValue))
  143. {
  144. return nValue;
  145. }
  146. return m_pValidWiaSettings->Min();
  147. }
  148. return 0;
  149. }
  150. void HandleUpDownUpdate(void)
  151. {
  152. WIA_PUSH_FUNCTION((TEXT("CUpDownAndEdit::HandleUpDownUpdate")));
  153. if (IsValid())
  154. {
  155. //
  156. // Find out what the current index is
  157. //
  158. int nIndex = static_cast<int>(SendMessage( m_hWndUpDown, UDM_GETPOS32, 0, 0 ));
  159. WIA_TRACE((TEXT("nIndex = %d"), nIndex ));
  160. //
  161. // Get the value at that index, if it is valid set the edit control's text
  162. //
  163. LONG nValue;
  164. if (m_pValidWiaSettings->GetItemAtIndex(nIndex,nValue))
  165. {
  166. WIA_TRACE((TEXT("nValue = %d"), nValue ));
  167. SetDlgItemInt( GetParent(m_hWndEdit), GetWindowLong(m_hWndEdit,GWL_ID), nValue, TRUE );
  168. }
  169. }
  170. }
  171. void HandleEditUpdate(void)
  172. {
  173. WIA_PUSH_FUNCTION((TEXT("CUpDownAndEdit::HandleUpDownUpdate")));
  174. if (IsValid())
  175. {
  176. //
  177. // Get the current value
  178. //
  179. BOOL bSuccess = FALSE;
  180. LONG nValue = static_cast<LONG>(GetDlgItemInt( GetParent(m_hWndEdit), GetWindowLong(m_hWndEdit,GWL_ID), &bSuccess, TRUE ));
  181. if (bSuccess)
  182. {
  183. //
  184. // Round it
  185. //
  186. if (m_pValidWiaSettings->FindClosestValue(nValue))
  187. {
  188. int nIndex = m_pValidWiaSettings->FindIndexOfItem( nValue );
  189. if (nIndex >= 0)
  190. {
  191. SendMessage( m_hWndUpDown, UDM_SETPOS32, 0, nIndex );
  192. }
  193. }
  194. }
  195. }
  196. }
  197. };
  198. #endif //__UPDNEDIT_H_INCLUDED