DebuggerQuickWatchDlg.cpp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "../../sys/win32/rc/debugger_resource.h"
  23. #include "DebuggerApp.h"
  24. #include "DebuggerQuickWatchDlg.h"
  25. /*
  26. ================
  27. rvDebuggerQuickWatchDlg::rvDebuggerQuickWatchDlg
  28. ================
  29. */
  30. rvDebuggerQuickWatchDlg::rvDebuggerQuickWatchDlg ( void )
  31. {
  32. }
  33. /*
  34. ================
  35. rvDebuggerQuickWatchDlg::DoModal
  36. Launch the dialog
  37. ================
  38. */
  39. bool rvDebuggerQuickWatchDlg::DoModal ( rvDebuggerWindow* window, int callstackDepth, const char* variable )
  40. {
  41. mCallstackDepth = callstackDepth;
  42. mDebuggerWindow = window;
  43. mVariable = variable?variable:"";
  44. DialogBoxParam ( window->GetInstance(), MAKEINTRESOURCE(IDD_DBG_QUICKWATCH), window->GetWindow(), DlgProc, (LONG)this );
  45. return true;
  46. }
  47. /*
  48. ================
  49. rvDebuggerQuickWatchDlg::DlgProc
  50. Dialog Procedure for the quick watch dialog
  51. ================
  52. */
  53. INT_PTR CALLBACK rvDebuggerQuickWatchDlg::DlgProc ( HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam )
  54. {
  55. rvDebuggerQuickWatchDlg* dlg = (rvDebuggerQuickWatchDlg*) GetWindowLong ( wnd, GWL_USERDATA );
  56. switch ( msg )
  57. {
  58. case WM_GETMINMAXINFO:
  59. {
  60. MINMAXINFO* mmi = (MINMAXINFO*)lparam;
  61. mmi->ptMinTrackSize.x = 300;
  62. mmi->ptMinTrackSize.y = 200;
  63. break;
  64. }
  65. case WM_CLOSE:
  66. gDebuggerApp.GetOptions().SetWindowPlacement ( "wp_quickwatch", wnd );
  67. gDebuggerApp.GetOptions().SetColumnWidths ( "cw_quickwatch", GetDlgItem ( wnd, IDC_DBG_CURVALUE ) );
  68. EndDialog ( wnd, 0 );
  69. break;
  70. case WM_SIZE:
  71. {
  72. RECT client;
  73. RECT button;
  74. GetClientRect ( wnd, &client );
  75. GetWindowRect ( GetDlgItem ( wnd, IDC_DBG_RECALC ), &button );
  76. ScreenToClient ( wnd, (POINT*)&button );
  77. ScreenToClient ( wnd, (POINT*)&button.right );
  78. MoveWindow ( GetDlgItem ( wnd, IDC_DBG_RECALC ), client.right - dlg->mButtonFromRight, button.top, button.right-button.left,button.bottom-button.top, TRUE );
  79. GetWindowRect ( GetDlgItem ( wnd, IDC_DBG_CLOSE ), &button );
  80. ScreenToClient ( wnd, (POINT*)&button );
  81. ScreenToClient ( wnd, (POINT*)&button.right );
  82. MoveWindow ( GetDlgItem ( wnd, IDC_DBG_CLOSE ), client.right - dlg->mButtonFromRight, button.top, button.right-button.left,button.bottom-button.top, TRUE );
  83. GetWindowRect ( GetDlgItem ( wnd, IDC_DBG_ADDWATCH ), &button );
  84. ScreenToClient ( wnd, (POINT*)&button );
  85. ScreenToClient ( wnd, (POINT*)&button.right );
  86. MoveWindow ( GetDlgItem ( wnd, IDC_DBG_ADDWATCH ), client.right - dlg->mButtonFromRight, button.top, button.right-button.left,button.bottom-button.top, TRUE );
  87. GetWindowRect ( GetDlgItem ( wnd, IDC_DBG_VARIABLE ), &button );
  88. ScreenToClient ( wnd, (POINT*)&button );
  89. ScreenToClient ( wnd, (POINT*)&button.right );
  90. MoveWindow ( GetDlgItem ( wnd, IDC_DBG_VARIABLE ), button.left, button.top, client.right-button.left-dlg->mEditFromRight, button.bottom-button.top, TRUE );
  91. GetWindowRect ( GetDlgItem ( wnd, IDC_DBG_CURVALUE ), &button );
  92. ScreenToClient ( wnd, (POINT*)&button );
  93. ScreenToClient ( wnd, (POINT*)&button.right );
  94. MoveWindow ( GetDlgItem ( wnd, IDC_DBG_CURVALUE ), button.left, button.top, client.right-button.left-dlg->mEditFromRight, client.bottom-button.top - dlg->mEditFromBottom, TRUE );
  95. break;
  96. }
  97. case WM_INITDIALOG:
  98. {
  99. RECT client;
  100. RECT button;
  101. // Attach the dialog class pointer to the window
  102. dlg = (rvDebuggerQuickWatchDlg*) lparam;
  103. SetWindowLong ( wnd, GWL_USERDATA, lparam );
  104. dlg->mWnd = wnd;
  105. GetClientRect ( wnd, &client );
  106. GetWindowRect ( GetDlgItem ( wnd, IDC_DBG_RECALC ), &button );
  107. ScreenToClient ( wnd, (POINT*)&button );
  108. dlg->mButtonFromRight = client.right - button.left;
  109. GetWindowRect ( GetDlgItem ( wnd, IDC_DBG_CURVALUE ), &button );
  110. ScreenToClient ( wnd, (POINT*)&button.right );
  111. dlg->mEditFromRight = client.right - button.right;
  112. dlg->mEditFromBottom = client.bottom - button.bottom;
  113. // Disable the value controls until a variable is entered
  114. EnableWindow ( GetDlgItem ( wnd, IDC_DBG_ADDWATCH ), false );
  115. EnableWindow ( GetDlgItem ( wnd, IDC_DBG_RECALC ), false );
  116. EnableWindow ( GetDlgItem ( wnd, IDC_DBG_CURVALUE ), false );
  117. EnableWindow ( GetDlgItem ( wnd, IDC_DBG_CURVALUE_STATIC ), false );
  118. // Add the columns to the list control
  119. LVCOLUMN col;
  120. col.mask = LVCF_WIDTH|LVCF_TEXT;
  121. col.cx = 100;
  122. col.pszText = "Name";
  123. ListView_InsertColumn ( GetDlgItem ( wnd, IDC_DBG_CURVALUE ), 0, &col );
  124. col.cx = 150;
  125. col.pszText = "Value";
  126. ListView_InsertColumn ( GetDlgItem ( wnd, IDC_DBG_CURVALUE ), 1, &col );
  127. // Set the initial variable if one was given
  128. if ( dlg->mVariable.Length() )
  129. {
  130. dlg->SetVariable ( dlg->mVariable, true );
  131. SetWindowText( GetDlgItem ( wnd, IDC_DBG_VARIABLE ), dlg->mVariable );
  132. }
  133. gDebuggerApp.GetOptions().GetWindowPlacement ( "wp_quickwatch", wnd );
  134. gDebuggerApp.GetOptions().GetColumnWidths ( "cw_quickwatch", GetDlgItem ( wnd, IDC_DBG_CURVALUE ) );
  135. return TRUE;
  136. }
  137. case WM_COMMAND:
  138. switch ( LOWORD(wparam) )
  139. {
  140. case IDC_DBG_CLOSE:
  141. SendMessage ( wnd, WM_CLOSE, 0, 0 );
  142. break;
  143. case IDC_DBG_VARIABLE:
  144. // When the variable text changes to something other than empty
  145. // we can enable the addwatch and recalc buttons
  146. if ( HIWORD(wparam) == EN_CHANGE )
  147. {
  148. bool enable = GetWindowTextLength ( GetDlgItem ( wnd, IDC_DBG_VARIABLE ) )?true:false;
  149. EnableWindow ( GetDlgItem ( wnd, IDC_DBG_ADDWATCH ), enable );
  150. EnableWindow ( GetDlgItem ( wnd, IDC_DBG_RECALC ), enable );
  151. }
  152. break;
  153. case IDC_DBG_ADDWATCH:
  154. {
  155. char varname[1024];
  156. GetWindowText ( GetDlgItem ( wnd, IDC_DBG_VARIABLE ), varname, 1023 );
  157. dlg->mDebuggerWindow->AddWatch ( varname );
  158. break;
  159. }
  160. case IDC_DBG_RECALC:
  161. {
  162. char varname[1024];
  163. GetWindowText ( GetDlgItem ( wnd, IDC_DBG_VARIABLE ), varname, 1023 );
  164. dlg->SetVariable ( varname );
  165. break;
  166. }
  167. }
  168. break;
  169. }
  170. return FALSE;
  171. }
  172. /*
  173. ================
  174. rvDebuggerQuickWatchDlg::SetVariable
  175. Sets the current variable being inspected
  176. ================
  177. */
  178. void rvDebuggerQuickWatchDlg::SetVariable ( const char* varname, bool force )
  179. {
  180. // See if the variable has changed
  181. if ( !force && !mVariable.Icmp ( varname ) )
  182. {
  183. return;
  184. }
  185. // Throw up a wait cursor
  186. SetCursor ( LoadCursor ( NULL, IDC_WAIT ) );
  187. // Clear the current value list control
  188. ListView_DeleteAllItems ( GetDlgItem ( mWnd, IDC_DBG_CURVALUE ) );
  189. // Get the value of the new variable
  190. gDebuggerApp.GetClient().InspectVariable ( varname, mCallstackDepth );
  191. // Wait for the variable value to be sent over from the debugger server
  192. if ( !gDebuggerApp.GetClient().WaitFor ( DBMSG_INSPECTVARIABLE, 2500 ) )
  193. {
  194. return;
  195. }
  196. // Make sure we got the value of the variable
  197. if ( !gDebuggerApp.GetClient().GetVariableValue(varname, mCallstackDepth)[0] )
  198. {
  199. return;
  200. }
  201. // Enable the windows that display the current value
  202. mVariable = varname;
  203. EnableWindow ( GetDlgItem ( mWnd, IDC_DBG_CURVALUE ), true );
  204. EnableWindow ( GetDlgItem ( mWnd, IDC_DBG_CURVALUE_STATIC ), true );
  205. // Add the variablae value to the list control
  206. LVITEM item;
  207. item.mask = LVIF_TEXT;
  208. item.pszText = (LPSTR)varname;
  209. item.iItem = 0;
  210. item.iSubItem = 0;
  211. ListView_InsertItem ( GetDlgItem ( mWnd, IDC_DBG_CURVALUE ), &item );
  212. ListView_SetItemText ( GetDlgItem ( mWnd, IDC_DBG_CURVALUE ), 0, 1, (LPSTR)gDebuggerApp.GetClient().GetVariableValue(varname,mCallstackDepth) );
  213. // Give focus back to the variable edit control and set the cursor back to an arrow
  214. SetFocus ( GetDlgItem ( mWnd, IDC_DBG_VARIABLE ) );
  215. SetCursor ( LoadCursor ( NULL, IDC_ARROW ) );
  216. }