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.

315 lines
10 KiB

  1. //===========================================================================
  2. // SETTINGS.CPP
  3. //
  4. // Functions:
  5. // Settings_DlgProc()
  6. // DisplayJoystickState()
  7. //
  8. //===========================================================================
  9. // Uncomment if we decide to calibrate the POV!
  10. #define WE_SUPPORT_CALIBRATING_POVS 1
  11. #include <malloc.h> // for _alloca
  12. #include "cplsvr1.h"
  13. #include "dicputil.h"
  14. #include "resource.h"
  15. #include "assert.h"
  16. #include "cal.h"
  17. // Flag to stop centering of DLG if it's already happend!
  18. // This is needed because of the args that allow any page to be the first!
  19. BOOL bDlgCentered = FALSE;
  20. // This is global because Test.cpp needs it to determine
  21. // if the ranges need to be updated!
  22. BYTE nStatic;
  23. LPMYJOYRANGE lpCurrentRanges = NULL;
  24. extern CDIGameCntrlPropSheet_X *pdiCpl;
  25. //===========================================================================
  26. // Settings_DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  27. //
  28. // Callback proceedure for Settings Page
  29. //
  30. // Parameters:
  31. // HWND hWnd - handle to dialog window
  32. // UINT uMsg - dialog message
  33. // WPARAM wParam - message specific data
  34. // LPARAM lParam - message specific data
  35. //
  36. // Returns: BOOL
  37. //
  38. //===========================================================================
  39. BOOL CALLBACK Settings_DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  40. {
  41. // static LPDIJOYCONFIG_DX5 pDIJoyConfig;
  42. switch( uMsg ) {
  43. case WM_LBUTTONDOWN:
  44. // Click Drag service for PropSheets!
  45. PostMessage(GetParent(hWnd), WM_NCLBUTTONDOWN, (WPARAM)HTCAPTION, lParam);
  46. break;
  47. // OnHelp
  48. case WM_HELP:
  49. OnHelp(lParam);
  50. return(TRUE);
  51. // OnContextMenu
  52. case WM_CONTEXTMENU:
  53. OnContextMenu(wParam);
  54. return(TRUE);
  55. // OnDestroy
  56. case WM_DESTROY:
  57. bDlgCentered = FALSE;
  58. // if (pDIJoyConfig)
  59. // delete (pDIJoyConfig);
  60. break;
  61. // OnInitDialog
  62. case WM_INITDIALOG:
  63. // get ptr to our object
  64. if( !pdiCpl )
  65. pdiCpl = (CDIGameCntrlPropSheet_X*)((LPPROPSHEETPAGE)lParam)->lParam;
  66. // initialize DirectInput
  67. if( FAILED(InitDInput(GetParent(hWnd), pdiCpl)) ) {
  68. #ifdef _DEBUG
  69. OutputDebugString(TEXT("GCDEF.DLL: Settings.cpp: WM_INITDIALOG: InitDInput FAILED!\n"));
  70. #endif
  71. Error(hWnd, (short)IDS_INTERNAL_ERROR, (short)IDS_NO_DIJOYCONFIG);
  72. PostMessage(GetParent(hWnd), WM_SYSCOMMAND, SC_CLOSE, 0);
  73. return(FALSE);
  74. }
  75. {
  76. // Enable/Disable the calibrate buttons if the device is present
  77. LPDIRECTINPUTJOYCONFIG pdiJoyConfig;
  78. pdiCpl->GetJoyConfig(&pdiJoyConfig);
  79. // Acquire and check for USER mode!
  80. // If you're not logged in as a user, you can't use calibrate either!
  81. if( pdiJoyConfig->Acquire() == DIERR_INSUFFICIENTPRIVS ) {
  82. const USHORT nIDs[] = { IDC_SETTINGSGRP,
  83. IDC_RESETCALIBRATION,
  84. IDC_JOYCALIBRATE,
  85. IDC_TEXT_CALHELP};
  86. BYTE nSize = sizeof(nIDs)/sizeof(USHORT);
  87. while( nSize-- )
  88. PostDlgItemEnableWindow(hWnd, nIDs[nSize], FALSE);
  89. pdiCpl->SetUser(TRUE);
  90. }
  91. // Center the Dialog!
  92. // If it's not been centered!
  93. if( !bDlgCentered ) {
  94. // Set the title bar!
  95. SetTitle(hWnd);
  96. CenterDialog(hWnd);
  97. bDlgCentered = TRUE;
  98. }
  99. // Disable the Calibration button if they don't have any axis!!!
  100. // Leave the Reset to default...
  101. if( pdiCpl->GetStateFlags()->nAxis == 0 )
  102. PostDlgItemEnableWindow(hWnd, IDC_JOYCALIBRATE, FALSE);
  103. }
  104. break;
  105. // OnNotify
  106. case WM_NOTIFY:
  107. // perform any WM_NOTIFY processing, but there is none...
  108. // return TRUE if you handled the notification (and have set
  109. // the result code in SetWindowLong(hWnd, DWL_MSGRESULT, lResult)
  110. // if you want to return a nonzero notify result)
  111. // or FALSE if you want default processing of the notification.
  112. switch( ((NMHDR*)lParam)->code ) {
  113. case PSN_APPLY:
  114. // Kill the memory allocated for the Ranges struct
  115. Sleep(100);
  116. if( lpCurrentRanges ) {
  117. delete (lpCurrentRanges);
  118. lpCurrentRanges = NULL;
  119. }
  120. /* We've removed the rudder stuff... but just in case it comes back...
  121. if (nStatic & RUDDER_HIT)
  122. {
  123. LPDIRECTINPUTJOYCONFIG pdiJoyConfig;
  124. pdiCpl->GetJoyConfig(&pdiJoyConfig);
  125. // get the status of the Rudder checkbox and assign it!
  126. // THEN Add the rudder to the Axis mask!
  127. if (pDIJoyConfig->hwc.dwUsageSettings & JOY_US_HASRUDDER)
  128. {
  129. pDIJoyConfig->hwc.dwUsageSettings &= ~JOY_US_HASRUDDER;
  130. pdiCpl->GetStateFlags()->nAxis &= ~HAS_RX;
  131. }
  132. else
  133. {
  134. pDIJoyConfig->hwc.dwUsageSettings |= JOY_US_HASRUDDER;
  135. pdiCpl->GetStateFlags()->nAxis |= HAS_RX;
  136. }
  137. if (FAILED(pdiJoyConfig->Acquire()))
  138. {
  139. #ifdef _DEBUG
  140. OutputDebugString(TEXT("GCDEF.DLL: Settings.cpp: Settings_DlgProc: PSN_APPLY: Acquire FAILED!\n"));
  141. #endif
  142. break;
  143. }
  144. // Set the GUID to NULL to ask DINPUT to recreate!
  145. pDIJoyConfig->guidInstance = NULL_GUID;
  146. if (FAILED(pdiJoyConfig->SetConfig(pdiCpl->GetID(), (LPDIJOYCONFIG)pDIJoyConfig, DIJC_REGHWCONFIGTYPE)))
  147. {
  148. #ifdef _DEBUG
  149. OutputDebugString(TEXT("GCDEF.DLL: Settings.cpp: Settings_DlgProc: PSN_APPLY: SetConfig FAILED!\n"));
  150. #endif
  151. break;
  152. }
  153. // Remove the mask from nStatic
  154. nStatic &= ~RUDDER_HIT;
  155. if (FAILED(pdiJoyConfig->SendNotify()))
  156. {
  157. #ifdef _DEBUG
  158. OutputDebugString(TEXT("GCDEF.DLL: Settings.cpp: Settings_DlgProc: PSN_APPLY: SendNotify FAILED!\n"));
  159. #endif
  160. }
  161. pdiJoyConfig->Unacquire();
  162. }
  163. */
  164. break;
  165. case PSN_RESET:
  166. // if the user has changed the calibration... Set it back!
  167. if( lpCurrentRanges ) {
  168. LPDIRECTINPUTDEVICE2 pdiDevice2;
  169. pdiCpl->GetDevice(&pdiDevice2);
  170. SetMyRanges(pdiDevice2, lpCurrentRanges, pdiCpl->GetStateFlags()->nAxis);
  171. // Set POV possitions!
  172. //if (pdiCpl->GetStateFlags()->nPOVs)
  173. // SetMyPOVRanges(pdiDevice2, lpCurrentRanges->dwPOV);
  174. LPDIRECTINPUTJOYCONFIG pdiJoyConfig;
  175. pdiCpl->GetJoyConfig(&pdiJoyConfig);
  176. pdiJoyConfig->Acquire();
  177. pdiJoyConfig->SendNotify();
  178. delete (lpCurrentRanges);
  179. lpCurrentRanges = NULL;
  180. }
  181. break;
  182. default:
  183. break;
  184. }
  185. return(FALSE);
  186. // OnCommand
  187. case WM_COMMAND:
  188. switch( LOWORD(wParam) ) {
  189. /*
  190. case IDC_JOY1HASRUDDER:
  191. if (nStatic & RUDDER_HIT)
  192. nStatic &= ~RUDDER_HIT;
  193. else
  194. nStatic |= RUDDER_HIT;
  195. // Update the ApplyNow button!
  196. PostMessage(GetParent(hWnd), (nStatic & RUDDER_HIT) ? PSM_CHANGED : PSM_UNCHANGED,
  197. (WPARAM)hWnd, 0);
  198. break;
  199. */
  200. // Set to Default button!!!
  201. case IDC_RESETCALIBRATION:
  202. {
  203. LPMYJOYRANGE lpResetRanges = (LPMYJOYRANGE)_alloca(sizeof(MYJOYRANGE));
  204. ASSERT (lpResetRanges);
  205. ZeroMemory(lpResetRanges, sizeof(MYJOYRANGE));
  206. LPDIRECTINPUTDEVICE2 pdiDevice2;
  207. pdiCpl->GetDevice(&pdiDevice2);
  208. SetMyRanges(pdiDevice2, lpResetRanges, pdiCpl->GetStateFlags()->nAxis);
  209. //if (pdiCpl->GetStateFlags()->nPOVs)
  210. // SetMyPOVRanges(pdiDevice2, lpResetRanges->dwPOV);
  211. LPDIRECTINPUTJOYCONFIG pdiJoyConfig;
  212. pdiCpl->GetJoyConfig(&pdiJoyConfig);
  213. pdiJoyConfig->Acquire();
  214. pdiJoyConfig->SendNotify();
  215. }
  216. break;
  217. case IDC_JOYCALIBRATE:
  218. nStatic |= CALIBRATING;
  219. if( !lpCurrentRanges ) {
  220. lpCurrentRanges = new (MYJOYRANGE);
  221. assert (lpCurrentRanges);
  222. ZeroMemory (lpCurrentRanges, sizeof(MYJOYRANGE));
  223. LPDIRECTINPUTDEVICE2 pdiDevice2;
  224. pdiCpl->GetDevice(&pdiDevice2);
  225. // Get Current Ranges!
  226. GetMyRanges(pdiDevice2, lpCurrentRanges, pdiCpl->GetStateFlags()->nAxis);
  227. }
  228. if( CreateWizard(hWnd, (LPARAM)pdiCpl) ) {
  229. // Set the flags
  230. nStatic |= CAL_HIT;
  231. HWND hSheet = GetParent(hWnd);
  232. // take care of the Apply Now Button...
  233. ::SendMessage(hSheet, PSM_CHANGED, (WPARAM)hWnd, 0L);
  234. // Bug #179010 NT - Move to Test sheet after calibration!
  235. ::PostMessage(hSheet, PSM_SETCURSELID, 0, (LPARAM)IDD_TEST);
  236. } else {
  237. // if you canceled and it's your first time Kill the struct...
  238. // then Reset the flag
  239. if( !(nStatic & CAL_HIT) ) {
  240. // Kill the memory allocated for the Ranges struct
  241. if( lpCurrentRanges ) {
  242. delete (lpCurrentRanges);
  243. lpCurrentRanges = NULL;
  244. }
  245. }
  246. }
  247. nStatic &= ~CALIBRATING;
  248. break;
  249. }
  250. }
  251. return(FALSE);
  252. } //*** end Settings_DlgProc()