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.

262 lines
9.5 KiB

  1. /****************************************************************************
  2. * TTSPropertiesDialog.cpp
  3. *
  4. * TTS Engine Advanced Properties Dialog handler
  5. *
  6. * Owner: aaronhal
  7. *
  8. * Copyright (c) 1999 Microsoft Corporation All Rights Reserved.
  9. *
  10. *****************************************************************************/
  11. #include "stdafx.h"
  12. #include "ms_entropicengine.h"
  13. #include "resource.h"
  14. #include "sphelper.h"
  15. #include "TTSPropertiesDialog.h"
  16. /*****************************************************************************
  17. * CTTSPropertiesDialog::CTTSPropertiesDialog *
  18. *--------------------------------------------*
  19. *
  20. * Description: Constructor
  21. *
  22. ***************************************************************** aaronhal ***/
  23. CTTSPropertiesDialog::CTTSPropertiesDialog( HINSTANCE hInstance, HWND hwndParent )
  24. {
  25. m_hInstance = hInstance;
  26. m_hwndParent = hwndParent;
  27. m_dwSeparatorAndDecimal = 0;
  28. m_dwShortDateOrder = 0;
  29. } /* CTTSPropertiesDialog */
  30. /*****************************************************************************
  31. * CTTSPropertiesDialog::Run *
  32. *---------------------------*
  33. *
  34. * Description: Launches the dialog associated with this object
  35. *
  36. * Return: S_OK if values accepted,
  37. * S_FALSE if cancelled,
  38. *
  39. ***************************************************************** aaronhal ***/
  40. HRESULT CTTSPropertiesDialog::Run()
  41. {
  42. HRESULT hr = S_OK;
  43. if ( SUCCEEDED( hr ) )
  44. {
  45. hr = (HRESULT) g_Unicode.DialogBoxParam( m_hInstance, (LPCWSTR) MAKEINTRESOURCE( IDD_TTS_ADV ), m_hwndParent,
  46. DlgProc, (LPARAM) this );
  47. }
  48. return hr;
  49. } /* Run */
  50. /*****************************************************************************
  51. * CTTSPropertiesDialog::InitDialog *
  52. *----------------------------------*
  53. *
  54. * Description: Static member function which handles the WM_INITDIALOG
  55. * message. Set windows up, cache this pointer, etc.
  56. *
  57. * Return: TRUE
  58. *
  59. ***************************************************************** aaronhal ***/
  60. HRESULT CTTSPropertiesDialog::InitDialog( HWND hDlg, LPARAM lParam )
  61. {
  62. HRESULT hr = S_OK;
  63. //--- Cache the 'this' pointer
  64. g_Unicode.SetWindowLongPtr(hDlg, GWLP_USERDATA, lParam);
  65. //--- Retrieve the current settings from the registry
  66. CSpDynamicString dstrTokenKeyName;
  67. hr = StringFromCLSID( CLSID_MSE_TTSEngine, &dstrTokenKeyName );
  68. if ( SUCCEEDED( hr ) )
  69. {
  70. hr = SpCreateNewToken( L"HKEY_CURRENT_USER\\Software\\Microsoft\\Speech\\Voices", dstrTokenKeyName,
  71. &This(hDlg)->m_cpEngineToken );
  72. }
  73. if ( SUCCEEDED( hr ) )
  74. {
  75. This(hDlg)->m_cpEngineToken->GetDWORD( L"SeparatorAndDecimal",
  76. &This(hDlg)->m_dwSeparatorAndDecimal );
  77. This(hDlg)->m_cpEngineToken->GetDWORD( L"ShortDateOrder", &This(hDlg)->m_dwShortDateOrder );
  78. //--- Set the state of the dialog
  79. if ( This(hDlg)->m_dwSeparatorAndDecimal & (DWORD) PERIOD_COMMA )
  80. {
  81. g_Unicode.SendDlgItemMessage( hDlg, IDC_PERIOD_COMMA, BM_SETCHECK, BST_CHECKED, 0 );
  82. g_Unicode.SendDlgItemMessage( hDlg, IDC_COMMA_PERIOD, BM_SETCHECK, BST_UNCHECKED, 0 );
  83. }
  84. else
  85. {
  86. //--- Default is comma separator, period decimal point
  87. g_Unicode.SendDlgItemMessage( hDlg, IDC_PERIOD_COMMA, BM_SETCHECK, BST_UNCHECKED, 0 );
  88. g_Unicode.SendDlgItemMessage( hDlg, IDC_COMMA_PERIOD, BM_SETCHECK, BST_CHECKED, 0 );
  89. }
  90. if ( This(hDlg)->m_dwShortDateOrder & (DWORD) YEAR_MONTH_DAY )
  91. {
  92. g_Unicode.SendDlgItemMessage( hDlg, IDC_MDY, BM_SETCHECK, BST_UNCHECKED, 0 );
  93. g_Unicode.SendDlgItemMessage( hDlg, IDC_DMY, BM_SETCHECK, BST_UNCHECKED, 0 );
  94. g_Unicode.SendDlgItemMessage( hDlg, IDC_YMD, BM_SETCHECK, BST_CHECKED, 0 );
  95. }
  96. else if ( This(hDlg)->m_dwShortDateOrder & (DWORD) DAY_MONTH_YEAR )
  97. {
  98. g_Unicode.SendDlgItemMessage( hDlg, IDC_MDY, BM_SETCHECK, BST_UNCHECKED, 0 );
  99. g_Unicode.SendDlgItemMessage( hDlg, IDC_DMY, BM_SETCHECK, BST_CHECKED, 0 );
  100. g_Unicode.SendDlgItemMessage( hDlg, IDC_YMD, BM_SETCHECK, BST_UNCHECKED, 0 );
  101. }
  102. else
  103. {
  104. //--- Default is month day year
  105. g_Unicode.SendDlgItemMessage( hDlg, IDC_MDY, BM_SETCHECK, BST_CHECKED, 0 );
  106. g_Unicode.SendDlgItemMessage( hDlg, IDC_DMY, BM_SETCHECK, BST_UNCHECKED, 0 );
  107. g_Unicode.SendDlgItemMessage( hDlg, IDC_YMD, BM_SETCHECK, BST_UNCHECKED, 0 );
  108. }
  109. }
  110. return hr;
  111. } /* InitDialog */
  112. /*****************************************************************************
  113. * CTTSPropertiesDialog::DlgProc *
  114. *-------------------------------*
  115. *
  116. * Description: Static member for Windows callback.
  117. *
  118. * Return: TRUE if message was handled, FALSE otherwise
  119. *
  120. ***************************************************************** aaronhal ***/
  121. INT_PTR CALLBACK CTTSPropertiesDialog::DlgProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  122. {
  123. BOOL fProcessed = FALSE;
  124. switch (message)
  125. {
  126. case WM_INITDIALOG:
  127. fProcessed = SUCCEEDED( InitDialog( hDlg, lParam ) );
  128. break;
  129. case WM_COMMAND:
  130. switch ( LOWORD(wParam) )
  131. {
  132. case IDC_COMMA_PERIOD:
  133. {
  134. SendDlgItemMessage( hDlg, IDC_PERIOD_COMMA, BM_SETCHECK, BST_UNCHECKED, 0 );
  135. SendDlgItemMessage( hDlg, IDC_COMMA_PERIOD, BM_SETCHECK, BST_CHECKED, 0 );
  136. fProcessed = TRUE;
  137. }
  138. break;
  139. case IDC_PERIOD_COMMA:
  140. {
  141. SendDlgItemMessage( hDlg, IDC_PERIOD_COMMA, BM_SETCHECK, BST_CHECKED, 0 );
  142. SendDlgItemMessage( hDlg, IDC_COMMA_PERIOD, BM_SETCHECK, BST_UNCHECKED, 0 );
  143. fProcessed = TRUE;
  144. }
  145. break;
  146. case IDC_MDY:
  147. {
  148. SendDlgItemMessage( hDlg, IDC_MDY, BM_SETCHECK, BST_CHECKED, 0 );
  149. SendDlgItemMessage( hDlg, IDC_DMY, BM_SETCHECK, BST_UNCHECKED, 0 );
  150. SendDlgItemMessage( hDlg, IDC_YMD, BM_SETCHECK, BST_UNCHECKED, 0 );
  151. fProcessed = TRUE;
  152. }
  153. break;
  154. case IDC_DMY:
  155. {
  156. SendDlgItemMessage( hDlg, IDC_MDY, BM_SETCHECK, BST_UNCHECKED, 0 );
  157. SendDlgItemMessage( hDlg, IDC_DMY, BM_SETCHECK, BST_CHECKED, 0 );
  158. SendDlgItemMessage( hDlg, IDC_YMD, BM_SETCHECK, BST_UNCHECKED, 0 );
  159. fProcessed = TRUE;
  160. }
  161. break;
  162. case IDC_YMD:
  163. {
  164. SendDlgItemMessage( hDlg, IDC_MDY, BM_SETCHECK, BST_UNCHECKED, 0 );
  165. SendDlgItemMessage( hDlg, IDC_DMY, BM_SETCHECK, BST_UNCHECKED, 0 );
  166. SendDlgItemMessage( hDlg, IDC_YMD, BM_SETCHECK, BST_CHECKED, 0 );
  167. fProcessed = TRUE;
  168. }
  169. break;
  170. case IDRESTORE:
  171. {
  172. //--- Default is comma separator, period decimal point
  173. SendDlgItemMessage( hDlg, IDC_PERIOD_COMMA, BM_SETCHECK, BST_UNCHECKED, 0 );
  174. SendDlgItemMessage( hDlg, IDC_COMMA_PERIOD, BM_SETCHECK, BST_CHECKED, 0 );
  175. //--- Default is month day year
  176. SendDlgItemMessage( hDlg, IDC_MDY, BM_SETCHECK, BST_CHECKED, 0 );
  177. SendDlgItemMessage( hDlg, IDC_DMY, BM_SETCHECK, BST_UNCHECKED, 0 );
  178. SendDlgItemMessage( hDlg, IDC_YMD, BM_SETCHECK, BST_UNCHECKED, 0 );
  179. }
  180. break;
  181. case IDCANCEL:
  182. EndDialog( hDlg, (int)S_FALSE );
  183. fProcessed = TRUE;
  184. break;
  185. case IDOK:
  186. This(hDlg)->UpdateValues( hDlg );
  187. EndDialog( hDlg, (int)S_OK );
  188. fProcessed = TRUE;
  189. break;
  190. }
  191. break;
  192. }
  193. return int(fProcessed);
  194. } /* DlgProc */
  195. /*****************************************************************************
  196. * CTTSPropertiesDialog::Update *
  197. *------------------------------*
  198. *
  199. * Description: Write new parameters to the registry.
  200. *
  201. * Return: Nothing.
  202. *
  203. ***************************************************************** aaronhal ***/
  204. void CTTSPropertiesDialog::UpdateValues( HWND hDlg )
  205. {
  206. LRESULT lrValue = 0;
  207. //--- Set short date format
  208. lrValue = SendDlgItemMessage( hDlg, IDC_MDY, BM_GETCHECK, 0, 0 );
  209. if ( lrValue == BST_CHECKED )
  210. {
  211. This(hDlg)->m_cpEngineToken->SetDWORD( L"ShortDateOrder", (DWORD) MONTH_DAY_YEAR );
  212. }
  213. else
  214. {
  215. lrValue = SendDlgItemMessage( hDlg, IDC_DMY, BM_GETCHECK, 0, 0 );
  216. if ( lrValue == BST_CHECKED )
  217. {
  218. This(hDlg)->m_cpEngineToken->SetDWORD( L"ShortDateOrder", (DWORD) DAY_MONTH_YEAR );
  219. }
  220. else
  221. {
  222. This(hDlg)->m_cpEngineToken->SetDWORD( L"ShortDateOrder", (DWORD) YEAR_MONTH_DAY );
  223. }
  224. }
  225. //--- Set number separator and decimal point
  226. lrValue = SendDlgItemMessage( hDlg, IDC_PERIOD_COMMA, BM_GETCHECK, 0, 0 );
  227. if ( lrValue == BST_CHECKED )
  228. {
  229. This(hDlg)->m_cpEngineToken->SetDWORD( L"SeparatorAndDecimal", (DWORD) PERIOD_COMMA );
  230. }
  231. else
  232. {
  233. This(hDlg)->m_cpEngineToken->SetDWORD( L"SeparatorAndDecimal", (DWORD) COMMA_PERIOD );
  234. }
  235. } /* Update */