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.

520 lines
15 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: DBGMASK.H
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 9/13/1999
  12. *
  13. * DESCRIPTION: Debug mask dialog
  14. *
  15. *******************************************************************************/
  16. #ifndef __DGBMASK_H_INCLUDED
  17. #define __DGBMASK_H_INCLUDED
  18. #include <windows.h>
  19. #include <uicommon.h>
  20. #include <simstr.h>
  21. #include <simreg.h>
  22. #include <simrect.h>
  23. #include <wiadebug.h>
  24. class CAddModuleDialog
  25. {
  26. public:
  27. struct CData
  28. {
  29. CSimpleString strTitle;
  30. CSimpleString strName;
  31. };
  32. private:
  33. HWND m_hWnd;
  34. CData *m_pData;
  35. private:
  36. // Not implemented
  37. CAddModuleDialog(void);
  38. CAddModuleDialog( const CAddModuleDialog & );
  39. CAddModuleDialog &operator=( const CAddModuleDialog & );
  40. private:
  41. explicit CAddModuleDialog( HWND hWnd )
  42. : m_hWnd(hWnd),
  43. m_pData(NULL)
  44. {
  45. }
  46. ~CAddModuleDialog(void)
  47. {
  48. }
  49. void OnOK( WPARAM, LPARAM )
  50. {
  51. m_pData->strName.GetWindowText( GetDlgItem( m_hWnd, IDC_MODULE_NAME ) );
  52. EndDialog( m_hWnd, IDOK );
  53. }
  54. void OnCancel( WPARAM, LPARAM )
  55. {
  56. EndDialog( m_hWnd, IDCANCEL );
  57. }
  58. LRESULT OnInitDialog( WPARAM wParam, LPARAM lParam )
  59. {
  60. m_pData = reinterpret_cast<CData*>(lParam);
  61. if (!m_pData)
  62. {
  63. EndDialog( m_hWnd, -1 );
  64. return -1;
  65. }
  66. m_pData->strName.SetWindowText( GetDlgItem( m_hWnd, IDC_MODULE_NAME ) );
  67. if (m_pData->strTitle.Length())
  68. m_pData->strTitle.SetWindowText( m_hWnd );
  69. WiaUiUtil::CenterWindow( m_hWnd, GetParent(m_hWnd) );
  70. return 0;
  71. }
  72. LRESULT OnCommand( WPARAM wParam, LPARAM lParam )
  73. {
  74. SC_BEGIN_COMMAND_HANDLERS()
  75. {
  76. SC_HANDLE_COMMAND(IDOK,OnOK);
  77. SC_HANDLE_COMMAND(IDCANCEL,OnCancel);
  78. }
  79. SC_END_COMMAND_HANDLERS();
  80. }
  81. public:
  82. static INT_PTR WINAPI DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  83. {
  84. SC_BEGIN_DIALOG_MESSAGE_HANDLERS(CAddModuleDialog)
  85. {
  86. SC_HANDLE_DIALOG_MESSAGE( WM_INITDIALOG, OnInitDialog );
  87. SC_HANDLE_DIALOG_MESSAGE( WM_COMMAND, OnCommand );
  88. }
  89. SC_END_DIALOG_MESSAGE_HANDLERS();
  90. }
  91. };
  92. template <class T_NUMBERTYPE>
  93. static HRESULT DigitToNumber( WCHAR cDigit, int nRadix, T_NUMBERTYPE *pnValue )
  94. {
  95. if (!pnValue)
  96. return E_POINTER;
  97. if (nRadix > 36)
  98. return E_INVALIDARG;
  99. static const WCHAR *pszUpperDigits = L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  100. static const WCHAR *pszLowerDigits = L"0123456789abcdefghijklmnopqrstuvwxyz";
  101. for (int i=0;i<nRadix;i++)
  102. {
  103. if (cDigit == pszUpperDigits[i])
  104. {
  105. *pnValue = static_cast<T_NUMBERTYPE>(i);
  106. return S_OK;
  107. }
  108. else if (cDigit == pszLowerDigits[i])
  109. {
  110. *pnValue = static_cast<T_NUMBERTYPE>(i);
  111. return S_OK;
  112. }
  113. }
  114. return E_FAIL;
  115. }
  116. template <class T_NUMBERTYPE>
  117. static HRESULT StringToNumber( LPCWSTR strwNumber, int nRadix, T_NUMBERTYPE *pnNumber )
  118. {
  119. // Assume this is not a base 10 negative number
  120. bool bNegate = false;
  121. // Check all of the arguments
  122. if (!strwNumber)
  123. return E_INVALIDARG;
  124. if (!pnNumber)
  125. return E_POINTER;
  126. if (nRadix > 36)
  127. return E_INVALIDARG;
  128. LPCWSTR pszCurr = strwNumber;
  129. // If this is a negative number, store it
  130. if (nRadix == 10 && lstrlenW(pszCurr) >= 1 && pszCurr[0] == TEXT('-'))
  131. {
  132. pszCurr++;
  133. bNegate = true;
  134. }
  135. // Skip the optional 0x or 0X that can prefix hex numbers
  136. if (nRadix == 16 && lstrlenW(pszCurr) >= 2 && pszCurr[0] == L'0' && (pszCurr[1] == L'x' || pszCurr[1] == L'X'))
  137. {
  138. pszCurr += 2;
  139. }
  140. *pnNumber = 0;
  141. while (*pszCurr)
  142. {
  143. T_NUMBERTYPE nCurrDigit;
  144. if (!SUCCEEDED(DigitToNumber<T_NUMBERTYPE>( *pszCurr, nRadix, &nCurrDigit )))
  145. {
  146. return E_FAIL;
  147. }
  148. *pnNumber *= nRadix;
  149. *pnNumber += nCurrDigit;
  150. pszCurr++;
  151. }
  152. if (bNegate)
  153. *pnNumber = static_cast<T_NUMBERTYPE>(-static_cast<__int64>(*pnNumber));
  154. return S_OK;
  155. }
  156. template <class T_NUMBERTYPE>
  157. static HRESULT StringToNumber( LPCSTR strNumber, int nRadix, T_NUMBERTYPE *pnNumber )
  158. {
  159. return StringToNumber<T_NUMBERTYPE>( CSimpleStringConvert::WideString(CSimpleStringAnsi(strNumber)), nRadix, pnNumber );
  160. }
  161. class CDebugMaskDialog
  162. {
  163. private:
  164. class CDebugModule
  165. {
  166. private:
  167. CSimpleString m_strName;
  168. DWORD m_dwMask;
  169. public:
  170. CDebugModule( LPCTSTR pszName = TEXT(""), DWORD dwMask = 0)
  171. : m_strName(pszName),
  172. m_dwMask(dwMask)
  173. {
  174. }
  175. CDebugModule( const CDebugModule &other )
  176. : m_strName(other.Name()),
  177. m_dwMask(other.Mask())
  178. {
  179. }
  180. CDebugModule &operator=( const CDebugModule &other )
  181. {
  182. if (&other != this)
  183. {
  184. m_strName = other.Name();
  185. m_dwMask = other.Mask();
  186. }
  187. return *this;
  188. }
  189. CSimpleString Name(void) const
  190. {
  191. return m_strName;
  192. }
  193. DWORD Mask(void) const
  194. {
  195. return m_dwMask;
  196. }
  197. void Mask( DWORD dwMask )
  198. {
  199. m_dwMask = dwMask;
  200. }
  201. };
  202. private:
  203. HWND m_hWnd;
  204. private:
  205. // Not implemented
  206. CDebugMaskDialog(void);
  207. CDebugMaskDialog( const CDebugMaskDialog & );
  208. CDebugMaskDialog &operator=( const CDebugMaskDialog & );
  209. private:
  210. explicit CDebugMaskDialog( HWND hWnd )
  211. : m_hWnd(hWnd)
  212. {
  213. }
  214. ~CDebugMaskDialog(void)
  215. {
  216. }
  217. CDebugModule *GetDebugModule( int nItem )
  218. {
  219. LVITEM LvItem;
  220. ZeroMemory( &LvItem, sizeof(LvItem) );
  221. LvItem.mask = LVIF_PARAM;
  222. LvItem.iItem = nItem;
  223. if (ListView_GetItem( GetDlgItem( m_hWnd, IDC_MODULE_LIST ), &LvItem ))
  224. {
  225. return reinterpret_cast<CDebugModule*>(LvItem.lParam);
  226. }
  227. return NULL;
  228. }
  229. int GetCurrentSelectionIndex(void)
  230. {
  231. int nResult = -1;
  232. int nSelectedCount = ListView_GetSelectedCount(GetDlgItem( m_hWnd, IDC_MODULE_LIST ));
  233. if (nSelectedCount == 1)
  234. {
  235. nResult = ListView_GetNextItem( GetDlgItem( m_hWnd, IDC_MODULE_LIST ), -1, LVNI_SELECTED );
  236. }
  237. return nResult;
  238. }
  239. void SelectItem( int nIndex )
  240. {
  241. for (int i=0;i<ListView_GetItemCount(GetDlgItem( m_hWnd, IDC_MODULE_LIST ));i++)
  242. {
  243. int nFlags = (i == nIndex) ? LVIS_SELECTED|LVIS_FOCUSED : 0;
  244. ListView_SetItemState( GetDlgItem( m_hWnd, IDC_MODULE_LIST ), i, nFlags, LVIS_SELECTED|LVIS_FOCUSED );
  245. }
  246. }
  247. void OnOK( WPARAM, LPARAM )
  248. {
  249. // Update the value for the currently selected item
  250. int nItem = GetCurrentSelectionIndex();
  251. if (nItem >= 0)
  252. {
  253. CDebugModule *pCurrSel = GetDebugModule(nItem);
  254. if (pCurrSel)
  255. {
  256. UpdateCurrentFlagsFromEdit( *pCurrSel, nItem );
  257. }
  258. }
  259. // Delete all of the old values
  260. CSimpleReg reg( HKEY_LOCAL_MACHINE, DEBUG_REGISTRY_PATH_FLAGS, true, KEY_WRITE );
  261. reg.EnumValues( DeleteValuesEnumProc, reinterpret_cast<LPARAM>(this) );
  262. // Save all the new ones
  263. for (int i=0;i<ListView_GetItemCount(GetDlgItem( m_hWnd, IDC_MODULE_LIST ));i++)
  264. {
  265. CDebugModule *pDebugModule = GetDebugModule(i);
  266. if (pDebugModule)
  267. {
  268. reg.Set( pDebugModule->Name(), pDebugModule->Mask() );
  269. }
  270. }
  271. EndDialog( m_hWnd, IDOK );
  272. }
  273. void OnCancel( WPARAM, LPARAM )
  274. {
  275. EndDialog( m_hWnd, IDCANCEL );
  276. }
  277. static bool ReadValuesEnumProc( CSimpleReg::CValueEnumInfo &enumInfo )
  278. {
  279. if (enumInfo.nType == REG_DWORD)
  280. {
  281. CDebugMaskDialog *This = reinterpret_cast<CDebugMaskDialog*>(enumInfo.lParam);
  282. if (This)
  283. {
  284. This->AddNewEntry( enumInfo.strName, enumInfo.reg.Query( enumInfo.strName, 0 ) );
  285. }
  286. }
  287. return true;
  288. }
  289. static bool DeleteValuesEnumProc( CSimpleReg::CValueEnumInfo &enumInfo )
  290. {
  291. bool bRes = enumInfo.reg.Delete( enumInfo.strName );
  292. return true;
  293. }
  294. int AddNewEntry( LPCTSTR pszName, DWORD dwMask )
  295. {
  296. int nIndex = -1;
  297. CDebugModule *pDebugModule = new CDebugModule( pszName, dwMask );
  298. if (pDebugModule)
  299. {
  300. LVITEM LvItem;
  301. ZeroMemory( &LvItem, sizeof(LvItem) );
  302. LvItem.mask = LVIF_TEXT | LVIF_PARAM;
  303. LvItem.pszText = const_cast<LPTSTR>(pszName);
  304. LvItem.lParam = reinterpret_cast<LPARAM>(pDebugModule);
  305. LvItem.iItem = 0;
  306. LvItem.iSubItem = 0;
  307. nIndex = ListView_InsertItem( GetDlgItem( m_hWnd, IDC_MODULE_LIST ), &LvItem );
  308. CSimpleString strMask;
  309. strMask.Format( TEXT("0x%08X"), dwMask );
  310. LvItem.mask = LVIF_TEXT;
  311. LvItem.pszText = const_cast<LPTSTR>(strMask.String());
  312. LvItem.iItem = nIndex;
  313. LvItem.iSubItem = 1;
  314. ListView_SetItem( GetDlgItem( m_hWnd, IDC_MODULE_LIST ), &LvItem );
  315. }
  316. return nIndex;
  317. }
  318. LRESULT OnInitDialog( WPARAM wParam, LPARAM lParam )
  319. {
  320. LVCOLUMN LvColumn;
  321. ZeroMemory( &LvColumn, sizeof(LvColumn) );
  322. LvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_TEXT;
  323. LvColumn.fmt = LVCFMT_LEFT;
  324. LvColumn.pszText = TEXT("Module");
  325. LvColumn.iSubItem = 0;
  326. LvColumn.iOrder = 0;
  327. LvColumn.cx = CSimpleRect( GetDlgItem( m_hWnd, IDC_MODULE_LIST ) ).Width() * 3 / 5;
  328. ListView_InsertColumn( GetDlgItem( m_hWnd, IDC_MODULE_LIST ), 0, &LvColumn );
  329. ZeroMemory( &LvColumn, sizeof(LvColumn) );
  330. LvColumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_TEXT;
  331. LvColumn.fmt = LVCFMT_LEFT;
  332. LvColumn.pszText = TEXT("Mask");
  333. LvColumn.iSubItem = 1;
  334. LvColumn.iOrder = 1;
  335. LvColumn.cx = CSimpleRect( GetDlgItem( m_hWnd, IDC_MODULE_LIST ) ).Width() * 2 / 5;
  336. ListView_InsertColumn( GetDlgItem( m_hWnd, IDC_MODULE_LIST ), 1, &LvColumn );
  337. CSimpleReg reg( HKEY_LOCAL_MACHINE, DEBUG_REGISTRY_PATH_FLAGS, false, KEY_READ );
  338. reg.EnumValues( ReadValuesEnumProc, reinterpret_cast<LPARAM>(this) );
  339. SelectItem(0);
  340. WiaUiUtil::CenterWindow( m_hWnd, GetParent(m_hWnd) );
  341. return 0;
  342. }
  343. LRESULT OnListDeleteItem( WPARAM, LPARAM lParam )
  344. {
  345. NMLISTVIEW *pNmListView = reinterpret_cast<NMLISTVIEW *>(lParam);
  346. if (pNmListView)
  347. {
  348. if (pNmListView->iItem >= 0 && pNmListView->iSubItem == 0)
  349. {
  350. CDebugModule *pDebugModule = reinterpret_cast<CDebugModule *>(pNmListView->lParam);
  351. if (pDebugModule)
  352. {
  353. delete pDebugModule;
  354. }
  355. }
  356. }
  357. return 0;
  358. }
  359. void UpdateCurrentFlagsFromEdit( CDebugModule &DebugModule, int nItem )
  360. {
  361. CSimpleString strMask;
  362. strMask.GetWindowText( GetDlgItem( m_hWnd, IDC_MASK ) );
  363. DWORD dwMask;
  364. if (SUCCEEDED(StringToNumber( strMask, 16, &dwMask )))
  365. {
  366. DebugModule.Mask(dwMask);
  367. }
  368. strMask.Format( TEXT("0x%08X"), DebugModule.Mask() );
  369. ListView_SetItemText( GetDlgItem( m_hWnd, IDC_MODULE_LIST ), nItem, 1, const_cast<LPTSTR>(strMask.String()) );
  370. }
  371. LRESULT OnListItemChanged( WPARAM, LPARAM lParam )
  372. {
  373. NMLISTVIEW *pNmListView = reinterpret_cast<NMLISTVIEW *>(lParam);
  374. if (pNmListView)
  375. {
  376. if (pNmListView->iItem >= 0 && (LVIF_STATE & pNmListView->uChanged) && ((pNmListView->uOldState & LVIS_SELECTED) ^ (pNmListView->uNewState & LVIS_SELECTED)))
  377. {
  378. CDebugModule *pDebugModule = reinterpret_cast<CDebugModule *>(pNmListView->lParam);
  379. if (pDebugModule)
  380. {
  381. if (LVIS_SELECTED & pNmListView->uNewState)
  382. {
  383. CSimpleString strMask;
  384. strMask.Format( TEXT("0x%08X"), pDebugModule->Mask() );
  385. SetDlgItemText( m_hWnd, IDC_MASK, strMask );
  386. }
  387. else
  388. {
  389. UpdateCurrentFlagsFromEdit( *pDebugModule, pNmListView->iItem );
  390. }
  391. }
  392. }
  393. }
  394. return 0;
  395. }
  396. void OnDeleteModule( WPARAM, LPARAM )
  397. {
  398. int nCurSel = GetCurrentSelectionIndex();
  399. if (nCurSel >= 0)
  400. {
  401. ListView_DeleteItem( GetDlgItem( m_hWnd, IDC_MODULE_LIST ), nCurSel );
  402. int nCount = ListView_GetItemCount( GetDlgItem( m_hWnd, IDC_MODULE_LIST ) );
  403. if (nCount)
  404. {
  405. SelectItem(nCurSel >= nCount ? nCount-1 : nCurSel );
  406. }
  407. }
  408. }
  409. void OnAddModule( WPARAM, LPARAM )
  410. {
  411. CAddModuleDialog::CData AddModuleData;
  412. AddModuleData.strName = TEXT("");
  413. AddModuleData.strTitle = TEXT("Add New Module");
  414. extern HINSTANCE g_hInstance;
  415. if (IDOK==DialogBoxParam( g_hInstance, MAKEINTRESOURCE(IDD_MODULENAME), m_hWnd, CAddModuleDialog::DialogProc, reinterpret_cast<LPARAM>(&AddModuleData)))
  416. {
  417. if (AddModuleData.strName.Length())
  418. {
  419. int nIndex = AddNewEntry( AddModuleData.strName, 0xFFFFFFFF );
  420. if (nIndex >= 0)
  421. {
  422. SelectItem( nIndex );
  423. SetFocus( GetDlgItem( m_hWnd, IDC_MASK ) );
  424. SendDlgItemMessage( m_hWnd, IDC_MASK, EM_SETSEL, 0, static_cast<LPARAM>(-1) );
  425. }
  426. }
  427. }
  428. }
  429. LRESULT OnNotify( WPARAM wParam, LPARAM lParam )
  430. {
  431. SC_BEGIN_NOTIFY_MESSAGE_HANDLERS()
  432. {
  433. SC_HANDLE_NOTIFY_MESSAGE_CONTROL(LVN_DELETEITEM,IDC_MODULE_LIST,OnListDeleteItem);
  434. SC_HANDLE_NOTIFY_MESSAGE_CONTROL(LVN_ITEMCHANGED,IDC_MODULE_LIST,OnListItemChanged);
  435. }
  436. SC_END_NOTIFY_MESSAGE_HANDLERS();
  437. }
  438. LRESULT OnCommand( WPARAM wParam, LPARAM lParam )
  439. {
  440. SC_BEGIN_COMMAND_HANDLERS()
  441. {
  442. SC_HANDLE_COMMAND(IDOK,OnOK);
  443. SC_HANDLE_COMMAND(IDCANCEL,OnCancel);
  444. SC_HANDLE_COMMAND(IDC_DELETE_MODULE,OnDeleteModule);
  445. SC_HANDLE_COMMAND(IDC_ADD_MODULE,OnAddModule);
  446. }
  447. SC_END_COMMAND_HANDLERS();
  448. }
  449. public:
  450. static INT_PTR WINAPI DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  451. {
  452. SC_BEGIN_DIALOG_MESSAGE_HANDLERS(CDebugMaskDialog)
  453. {
  454. SC_HANDLE_DIALOG_MESSAGE( WM_INITDIALOG, OnInitDialog );
  455. SC_HANDLE_DIALOG_MESSAGE( WM_COMMAND, OnCommand );
  456. SC_HANDLE_DIALOG_MESSAGE( WM_NOTIFY, OnNotify );
  457. }
  458. SC_END_DIALOG_MESSAGE_HANDLERS();
  459. }
  460. };
  461. #endif