doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GEItemScriptsDlg.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/guied_resource.h"
33 
34 #include "GEApp.h"
35 #include "GEPropertyPage.h"
36 
37 LRESULT CALLBACK GEScriptEdit_WndProc ( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
38 {
39  WNDPROC wndproc = (WNDPROC) GetWindowLong ( hwnd, GWL_USERDATA );
40 
41  switch ( msg )
42  {
43  case WM_CHAR:
44  if ( wParam == VK_ESCAPE )
45  {
46  SendMessage ( GetParent ( hwnd ), WM_CLOSE, 0, 0 );
47  }
48  break;
49 
50  case WM_GETDLGCODE:
51  return DLGC_WANTALLKEYS;
52  }
53 
54  return CallWindowProc ( wndproc, hwnd, msg, wParam, lParam );
55 }
56 
57 bool GEItescriptsDlg_Init ( HWND hwnd )
58 {
60  rvGEWindowWrapper* wrapper;
61  HWND script;
62 
63  // Extract the window pointer from the win32 windows user data long
64  window = (idWindow*)GetWindowLong ( hwnd, GWL_USERDATA );
65  assert ( window );
66 
67  // Get the window wrapper of the script window
68  wrapper = rvGEWindowWrapper::GetWrapper ( window );
69  assert ( wrapper );
70 
71  // Get the edit box used to edit the script
72  script = GetDlgItem ( hwnd, IDC_GUIED_SCRIPT );
73 
74  UINT tabsize = 16;
75  SendMessage ( script, EM_SETTABSTOPS, 1, (LPARAM)&tabsize );
76  SetWindowLong ( script, GWL_USERDATA, GetWindowLong ( script, GWL_WNDPROC ) );
77  SetWindowLong ( script, GWL_WNDPROC, (LONG) GEScriptEdit_WndProc );
78 
79  TEXTMETRIC tm;
80  HDC dc;
81  dc = GetDC ( script );
82  GetTextMetrics ( dc, &tm );
83  ReleaseDC ( script, dc );
84 
85  LOGFONT lf;
86  ZeroMemory ( &lf, sizeof(lf) );
87  lf.lfHeight = tm.tmHeight;
88  strcpy ( lf.lfFaceName, "Courier New" );
89 
90  SendMessage ( script, WM_SETFONT, (WPARAM)CreateFontIndirect ( &lf ), 0 );
91 
92  SendMessage ( script, EM_SETMARGINS, EC_LEFTMARGIN|EC_RIGHTMARGIN, MAKELONG(10,10) );
93 
94  int i;
95 
96  for ( i = 0; i < wrapper->GetVariableDict().GetNumKeyVals ( ); i ++ )
97  {
98  const idKeyValue* key = wrapper->GetVariableDict().GetKeyVal ( i );
99 
100  SendMessage ( script, EM_SETSEL, -1, -1 );
101  SendMessage ( script, EM_REPLACESEL, FALSE, (LPARAM)key->GetKey().c_str() );
102  SendMessage ( script, EM_SETSEL, -1, -1 );
103  SendMessage ( script, EM_REPLACESEL, FALSE, (LPARAM)"\t" );
104  SendMessage ( script, EM_SETSEL, -1, -1 );
105  SendMessage ( script, EM_REPLACESEL, FALSE, (LPARAM)key->GetValue().c_str() );
106  SendMessage ( script, EM_SETSEL, -1, -1 );
107  SendMessage ( script, EM_REPLACESEL, FALSE, (LPARAM)"\r\n" );
108  }
109 
110  if ( i )
111  {
112  SendMessage ( script, EM_SETSEL, -1, -1 );
113  SendMessage ( script, EM_REPLACESEL, FALSE, (LPARAM)"\r\n" );
114  }
115 
116  for ( i = 0; i < wrapper->GetScriptDict().GetNumKeyVals ( ); i ++ )
117  {
118  const idKeyValue* key = wrapper->GetScriptDict().GetKeyVal ( i );
119 
120  SendMessage ( script, EM_SETSEL, -1, -1 );
121  SendMessage ( script, EM_REPLACESEL, FALSE, (LPARAM)va("%s\r\n", key->GetKey().c_str() ) );
122  SendMessage ( script, EM_SETSEL, -1, -1 );
123  SendMessage ( script, EM_REPLACESEL, FALSE, (LPARAM)key->GetValue().c_str() );
124  SendMessage ( script, EM_SETSEL, -1, -1 );
125  SendMessage ( script, EM_REPLACESEL, FALSE, (LPARAM)"\r\n\r\n" );
126  }
127 
128  SendMessage ( script, EM_SETSEL, 0, 0 );
129  SendMessage ( script, EM_SCROLLCARET, 0, 0 );
130 
131  return true;
132 }
133 
134 bool GEItescriptsDlg_Apply ( HWND hwnd )
135 {
136  idWindow* window;
137  rvGEWindowWrapper* wrapper;
138  HWND script;
139 
140  // Extract the window pointer from the win32 windows user data long
141  window = (idWindow*)GetWindowLong ( hwnd, GWL_USERDATA );
142  assert ( window );
143 
144  // Get the window wrapper of the script window
145  wrapper = rvGEWindowWrapper::GetWrapper ( window );
146  assert ( wrapper );
147 
148  // Get the edit box used to edit the script
149  script = GetDlgItem ( hwnd, IDC_GUIED_SCRIPT );
150 
151  GETTEXTLENGTHEX textLen;
152  int chars;
153  textLen.flags = GTL_DEFAULT|GTL_USECRLF;
154  textLen.codepage = CP_ACP;
155  chars = SendMessage ( script, EM_GETTEXTLENGTHEX, (WPARAM)&textLen, 0 );
156 
157  char* text = new char[chars+1];
158 
159  GETTEXTEX getText;
160  getText.cb = chars+1;
161  getText.codepage = CP_ACP;
162  getText.flags = GT_DEFAULT|GT_USECRLF;
163  getText.lpDefaultChar = NULL;
164  getText.lpUsedDefChar = NULL;
165  SendMessage ( script, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM)text );
166 
167  idStr parse = text;
168  delete[] text;
169 
170  try
171  {
173  idToken token;
174 
175  wrapper->GetVariableDict().Clear ( );
176  wrapper->GetScriptDict().Clear ( );
177 
178  while ( src.ReadToken ( &token ) )
179  {
180  idStr scriptName;
181  idStr out;
182 
183  if ( !token.Icmp ("definevec4") )
184  {
185  idToken token2;
186  idStr result;
187 
188  if ( !src.ReadToken ( &token2 ) )
189  {
190  src.Error ( "expected define name" );
191  return false;
192  }
193 
194  idWinVec4 var;
196  idWindow tempwin ( &ui );
197  idStr out;
198  int i;
199 
200  src.SetMarker ( );
201  for ( i = 0; i < 3; i ++ )
202  {
203  tempwin.ParseExpression ( &src, &var );
204  src.ExpectTokenString(",");
205  }
206 
207  tempwin.ParseExpression ( &src, &var );
208  src.GetStringFromMarker ( out, true );
209 
210  wrapper->GetVariableDict().Set ( token + "\t\"" + token2 + "\"", out );
211 
212  continue;
213  }
214  else if ( !token.Icmp ( "definefloat" ) || !token.Icmp ( "float" ) )
215  {
216  idToken token2;
217  idStr result;
218 
219  if ( !src.ReadToken ( &token2 ) )
220  {
221  src.Error ( "expected define name" );
222  return false;
223  }
224 
225  idWinFloat var;
227  idWindow tempwin ( &ui );
228  idStr out;
229 
230  src.SetMarker ( );
231  tempwin.ParseExpression ( &src, &var );
232  src.GetStringFromMarker ( out, true );
233 
234  wrapper->GetVariableDict().Set ( token + "\t\"" + token2 + "\"", out );
235 
236  continue;
237  }
238  // If the token is a scriptdef then just parse out the
239  // braced section and add it to the list. Right now only
240  // one scriptdef per window is supported
241  else if ( !token.Icmp ( "scriptdef" ) )
242  {
243  scriptName = "scriptDef";
244  }
245  else if ( !token.Icmp ( "ontime" ) )
246  {
247  if ( !src.ReadToken ( &token ) )
248  {
249  src.Error ( "expected time" );
250  return false;
251  }
252 
253  scriptName = "onTime ";
254  scriptName.Append ( token );
255  }
256  else if ( !token.Icmp ( "onevent" ) )
257  {
258  if ( !src.ReadToken ( &token ) )
259  {
260  src.Error ( "expected time" );
261  return false;
262  }
263 
264  scriptName = "onEvent ";
265  scriptName.Append ( token );
266  }
267  else
268  {
269  int i;
270 
271  for( i = 0; i < idWindow::SCRIPT_COUNT; i ++ )
272  {
273  if ( idStr::Icmp ( idWindow::ScriptNames[i], token ) == 0 )
274  {
275  scriptName = idWindow::ScriptNames[i];
276  break;
277  }
278  }
279 
280  if ( i >= idWindow::SCRIPT_COUNT )
281  {
282  src.Error ( "expected script name" );
283  return false;
284  }
285  }
286 
287  if ( !src.ParseBracedSectionExact ( out, 1) )
288  {
289  return false;
290  }
291 
292  wrapper->GetScriptDict().Set ( scriptName, out );
293  }
294  }
295  catch ( idException &e )
296  {
297  MessageBox ( hwnd, e.error, "Script Error", MB_OK|MB_ICONERROR);
298  return false;
299  }
300 
301  return true;
302 }
303 
304 INT_PTR CALLBACK GEItescriptsDlg_WndProc ( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
305 {
306  switch ( msg )
307  {
308  case WM_INITDIALOG:
309  SetWindowLong ( hwnd, GWL_USERDATA, lParam );
310  GEItescriptsDlg_Init ( hwnd );
311 
312  gApp.GetOptions().GetWindowPlacement ( "scripts", hwnd );
313 
314  // Let it fall through so the scripts window gets resized.
315 
316  case WM_SIZE:
317  {
318  RECT rClient;
319  GetClientRect ( hwnd, &rClient );
320  MoveWindow ( GetDlgItem ( hwnd, IDC_GUIED_SCRIPT ),
321  rClient.left, rClient.top,
322  rClient.right - rClient.left,
323  rClient.bottom - rClient.top,
324  FALSE );
325  break;
326  }
327 
328  case WM_ERASEBKGND:
329  return TRUE;
330 
331 
332  case WM_CLOSE:
333  if ( !GEItescriptsDlg_Apply ( hwnd ) )
334  {
335  return TRUE;
336  }
337  gApp.GetOptions().SetWindowPlacement ( "scripts", hwnd );
338  EndDialog ( hwnd, 1 );
339  break;
340  }
341 
342  return FALSE;
343 }
344 
345 /*
346 ================
347 GEItemScriptsDlg_DoModal
348 
349 Starts the item properties dialog
350 ================
351 */
353 {
354  LoadLibrary ( "Riched20.dll" );
355 
356  if ( DialogBoxParam ( gApp.GetInstance(), MAKEINTRESOURCE(IDD_GUIED_SCRIPTS), parent, GEItescriptsDlg_WndProc, (LPARAM) window ) )
357  {
358  return true;
359  }
360 
361  return false;
362 }
363 
CPropTreeItem LPARAM
Definition: PropTree.h:70
assert(prefInfo.fullscreenBtn)
bool GEItemScriptsDlg_DoModal(HWND parent, idWindow *window)
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
const idStr & GetKey(void) const
Definition: Dict.h:52
int Length(void) const
Definition: Str.h:702
void SetWindowPlacement(const char *name, HWND hwnd)
Definition: GEOptions.h:288
Definition: Token.h:71
bool GetWindowPlacement(const char *name, HWND hwnd)
Definition: GEOptions.h:293
GLuint src
Definition: glext.h:5390
void Set(const char *key, const char *value)
Definition: Dict.cpp:275
int i
Definition: process.py:33
HINSTANCE GetInstance(void)
Definition: GEApp.h:168
Boolean result
INT_PTR CALLBACK GEItescriptsDlg_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
int Icmp(const char *text) const
Definition: Str.h:667
rvGEApp gApp
Definition: guied.cpp:41
rvGEOptions & GetOptions(void)
Definition: GEApp.h:163
idDict & GetScriptDict(void)
#define NULL
Definition: Lib.h:88
void Clear(void)
Definition: Dict.cpp:201
idDict & GetVariableDict(void)
static const char * ScriptNames[SCRIPT_COUNT]
Definition: Window.h:199
const idStr & GetValue(void) const
Definition: Dict.h:53
typedef HDC(WINAPI *PFNWGLGETCURRENTREADDCARBPROC)(void)
#define IDD_GUIED_SCRIPTS
bool GEItescriptsDlg_Init(HWND hwnd)
prefInfo window
int ParseExpression(idParser *src, idWinVar *var=NULL, int component=0)
Definition: Window.cpp:3003
long LONG
static rvGEWindowWrapper * GetWrapper(idWindow *window)
void Append(const char a)
Definition: Str.h:729
char error[MAX_STRING_CHARS]
Definition: Lib.h:152
MFnDagNode * GetParent(MFnDagNode *joint)
Definition: maya_main.cpp:350
Definition: Str.h:116
bool GEItescriptsDlg_Apply(HWND hwnd)
const char * c_str(void) const
Definition: Str.h:487
#define FALSE
Definition: mprintf.c:70
const idKeyValue * GetKeyVal(int index) const
Definition: Dict.h:294
LRESULT CALLBACK GEScriptEdit_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
#define TRUE
Definition: mprintf.c:69
char * va(const char *fmt,...)
Definition: Str.cpp:1568
#define IDC_GUIED_SCRIPT
int GetNumKeyVals(void) const
Definition: Dict.h:290