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