29 #include "../../idlib/precompiled.h"
32 #include "../../sys/win32/rc/Common_resource.h"
33 #include "../../sys/win32/rc/ScriptEditor_resource.h"
35 #include "../comafx/DialogGoToLine.h"
38 #ifdef ID_DEBUG_MEMORY
57 static UINT FindDialogMessage = ::RegisterWindowMessage( FINDMSGSTRING );
61 { IDCANCEL,
"cancel" },
77 , matchWholeWords(false)
96 CDialog::DoDataExchange(pDX);
110 if ( WM_KEYFIRST <= pMsg->message && pMsg->message <= WM_KEYLAST ) {
115 return CWnd::PreTranslateMessage(pMsg);
124 int line,
column, character;
127 statusBar.SetWindowText(
va(
"Line: %d, Column: %d, Character: %d", line, column, character ) );
142 if ( !src.
LoadFile(
"script/doom_events.script" ) ) {
146 scriptEvents.
Clear();
149 if ( token ==
"scriptEvent" ) {
152 index = whiteSpace.
Find(
"//" );
172 while( src.
ReadToken( &token ) && token !=
";" ) {
176 scriptEvents.
Append( info );
187 for (
int i = 0;
i < scriptEvents.
Num();
i++ ) {
188 listBox.AddString( scriptEvents[
i].
name );
199 for (
int i = 0;
i < scriptEvents.
Num();
i++ ) {
200 if ( scriptEvents[
i].
name.Cmp( funcName ) == 0 ) {
201 parmString = scriptEvents[
i].parms;
214 for (
int i = 0;
i < scriptEvents.
Num();
i++ ) {
215 if ( scriptEvents[
i].name.Cmp( name ) == 0 ) {
216 string = scriptEvents[
i].help + scriptEvents[
i].parms;
230 int numCharsPerLine = 0;
231 int maxCharsPerLine = 0;
232 idStr scriptText, extension;
241 if ( extension.
Icmp(
"script" ) == 0 ) {
248 }
else if ( extension.
Icmp(
"gui" ) == 0 ) {
256 scriptText = (
char *) buffer;
262 scriptText.
Replace(
"\r",
"" );
263 scriptText.
Replace(
"\n",
"\r" );
264 scriptText.
Replace(
"\v",
"\r" );
268 for(
const char *ptr = scriptText.
c_str(); *ptr; ptr++ ) {
269 if ( *ptr ==
'\r' ) {
270 if ( numCharsPerLine > maxCharsPerLine ) {
271 maxCharsPerLine = numCharsPerLine;
275 }
else if ( *ptr ==
'\t' ) {
276 numCharsPerLine += TAB_SIZE;
282 SetWindowText(
va(
"Script Editor (%s)", fileName ) );
285 rect.right = rect.left + maxCharsPerLine * FONT_WIDTH + 32;
287 rect.bottom = rect.top + numLines * (FONT_HEIGHT+8) + 24 + 56;
290 }
else if ( rect.right - rect.left > 1024 ) {
291 rect.right = rect.left + 1024;
295 }
else if ( rect.bottom - rect.top > 768 ) {
296 rect.bottom = rect.top + 768;
316 CDialog::OnInitDialog();
322 statusBar.CreateEx( SBARS_SIZEGRIP, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM,
initialRect,
this, AFX_IDW_STATUS_BAR );
328 SetWindowText(
"Script Editor" );
330 EnableToolTips(
TRUE );
341 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
342 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
349 ON_COMMAND(ID_EDIT_FIND, OnEditFind)
350 ON_COMMAND(ID_EDIT_REPLACE, OnEditReplace)
353 ON_REGISTERED_MESSAGE(FindDialogMessage, OnFindDialogMessage)
355 ON_NOTIFY(EN_MSGFILTER, IDC_SCRIPTEDITOR_EDIT_TEXT, OnEnInputEdit)
356 ON_BN_CLICKED(IDOK, OnBnClickedOk)
357 ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
368 common->
Printf(
"Cannot run the script editor in fullscreen mode.\n"
369 "Set r_fullscreen to 0 and vid_restart.\n" );
373 if ( g_ScriptDialog ==
NULL ) {
378 if ( g_ScriptDialog->GetSafeHwnd() ==
NULL) {
389 g_ScriptDialog->ShowWindow( SW_SHOW );
390 g_ScriptDialog->SetFocus();
403 MSG *msg = AfxGetCurrentMessage();
405 MSG *msg = &m_msgCur;
408 while( ::PeekMessage(msg,
NULL,
NULL,
NULL, PM_NOREMOVE) ) {
410 if ( !AfxGetApp()->PumpMessage() ) {
421 delete g_ScriptDialog;
422 g_ScriptDialog =
NULL;
423 scriptEvents.
Clear();
435 CDialog::OnActivate( nState, pWndOther, bMinimized );
453 CDialog::OnSetFocus( pOldWnd );
462 return CDialog::OnDestroy();
471 if ( GetSafeHwnd() ) {
473 GetWindowRect( rct );
476 CDialog::OnMove( x, y );
484 #define BORDER_SIZE 0
485 #define BUTTON_SPACE 4
486 #define TOOLBAR_HEIGHT 24
489 CRect clientRect, rect;
493 CDialog::OnSize( nType, cx, cy );
495 GetClientRect( clientRect );
501 rect.bottom = clientRect.Height() - 56;
502 scriptEdit.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
507 int width = rect.Width();
508 int height = rect.Height();
513 okButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
518 int width = rect.Width();
519 int height = rect.Height();
524 cancelButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
528 rect.left = clientRect.Width() - 2;
529 rect.top = clientRect.Height() - 2;
530 rect.right = clientRect.Width() - 2;
531 rect.bottom = clientRect.Height() - 2;
532 statusBar.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
535 UnlockWindowUpdate();
555 CDialog::OnSizing( nSide, lpRect );
557 if ( ( nSide - 1 ) % 3 == 0 ) {
558 if ( lpRect->right - lpRect->left <
initialRect.Width() ) {
559 lpRect->left = lpRect->right -
initialRect.Width();
561 }
else if ( ( nSide - 2 ) % 3 == 0 ) {
562 if ( lpRect->right - lpRect->left <
initialRect.Width() ) {
563 lpRect->right = lpRect->left +
initialRect.Width();
566 if ( nSide >= 3 && nSide <= 5 ) {
567 if ( lpRect->bottom - lpRect->top <
initialRect.Height() ) {
568 lpRect->top = lpRect->bottom -
initialRect.Height();
570 }
else if ( nSide >= 6 && nSide <= 9 ) {
571 if ( lpRect->bottom - lpRect->top <
initialRect.Height() ) {
572 lpRect->bottom = lpRect->top +
initialRect.Height();
586 if ( goToLineDlg.DoModal() != IDOK ) {
600 if ( selText.GetLength() ) {
606 findDlg =
new CFindReplaceDialog();
620 AfxMessageBox(
"The specified text was not found.", MB_OK | MB_ICONINFORMATION, 0 );
632 if ( selText.GetLength() ) {
638 findDlg =
new CFindReplaceDialog();
653 if (
findDlg->IsTerminating() ) {
667 if (
findDlg->ReplaceCurrent() ) {
668 long selStart, selEnd;
673 if ( selEnd > selStart ) {
685 if ( numReplaces == 0 ) {
686 AfxMessageBox(
"The specified text was not found.", MB_OK | MB_ICONINFORMATION, 0 );
688 AfxMessageBox(
va(
"Replaced %d occurances.", numReplaces ), MB_OK | MB_ICONINFORMATION, 0 );
710 MSGFILTER *msgFilter = (MSGFILTER *)pNMHDR;
712 if ( msgFilter->msg != 512 && msgFilter->msg != 33 ) {
732 scriptText.
Replace(
"\n",
"" );
733 scriptText.
Replace(
"\r",
"\r\n" );
734 scriptText.
Replace(
"\v",
"\r\n" );
751 if ( MessageBox(
"Cancel changes?",
"Cancel", MB_YESNO | MB_ICONQUESTION ) != IDYES ) {
BOOL DefaultOnToolTipNotify(const toolTip_t *toolTips, UINT id, NMHDR *pNMHDR, LRESULT *pResult)
void UpdateStatusBar(void)
afx_msg void OnEditFind()
bool GetFunctionParms(const char *funcName, CString &parmString)
afx_msg LRESULT OnFindDialogMessage(WPARAM wParam, LPARAM lParam)
CONST PIXELFORMATDESCRIPTOR UINT
void GetText(idStr &text) const
afx_msg void OnSizing(UINT nSide, LPRECT lpRect)
void SetFunctionParmCallback(toolTipCallback_t callback)
void SetStringColor(const COLORREF color, const COLORREF altColor=-1)
virtual int ReadFile(const char *relativePath, void **buffer, ID_TIME_T *timestamp=NULL)=0
virtual ~DialogScriptEditor()
void SetRange(int firstLine, int lastLine)
idRenderSystem * renderSystem
virtual void DoDataExchange(CDataExchange *pDX)
idFileSystem * fileSystem
bool FindNext(const char *find, bool matchCase, bool matchWholeWords, bool searchForward)
afx_msg void OnEditGoToLine()
#define IDD_DIALOG_SCRIPTEDITOR
int ExpectTokenString(const char *string)
CSyntaxRichEditCtrl scriptEdit
void ScriptEditorRun(void)
bool GetToolTip(const char *name, CString &string)
virtual void FreeFile(void *buffer)=0
void SetObjectMemberCallback(objectMemberCallback_t callback)
#define IDC_SCRIPTEDITOR_EDIT_TEXT
int Icmp(const char *text) const
#define ID_SCRIPTEDITOR_FIND_NEXT
virtual int WriteFile(const char *relativePath, const void *buffer, int size, const char *basePath="fs_savepath")=0
void SetToolTipCallback(toolTipCallback_t callback)
void SetText(const char *text)
afx_msg void OnEnChangeEdit(NMHDR *pNMHDR, LRESULT *pResult)
int ReadToken(idToken *token)
afx_msg void OnMove(int x, int y)
afx_msg void OnEditReplace()
void AllowPathNames(bool allow)
afx_msg void OnBnClickedOk()
virtual bool IsFullScreen(void) const =0
CFindReplaceDialog * findDlg
void GetCursorPos(int &line, int &column, int &character) const
afx_msg void OnSize(UINT nType, int cx, int cy)
afx_msg void OnBnClickedCancel()
afx_msg void OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
void InitScriptEvents(void)
const char * Right(int len, idStr &result) const
int Find(const char c, int start=0, int end=-1) const
void ScriptEditorInit(const idDict *spawnArgs)
virtual void Printf(const char *fmt,...) id_attribute((format(printf
afx_msg void OnEditFindNext()
GLenum GLsizei GLsizei height
static toolTip_t toolTips[]
struct scriptEventInfo_s scriptEventInfo_t
bool GetScriptEvents(const char *objectName, CListBox &listBox)
void OpenFile(const char *fileName)
int Append(const type &obj)
void Append(const char a)
int LoadFile(const char *filename, bool OSPath=false)
afx_msg void OnSetFocus(CWnd *pOldWnd)
#define ID_SCRIPTEDITOR_GOTOLINE
afx_msg void OnEnInputEdit(NMHDR *pNMHDR, LRESULT *pResult)
const char * c_str(void) const
virtual BOOL OnInitDialog()
void SetCaseSensitive(bool caseSensitive)
char * va(const char *fmt,...)
void ExtractFileExtension(idStr &dest) const
GLenum GLenum GLvoid GLvoid * column
virtual BOOL PreTranslateMessage(MSG *pMsg)
void Replace(const char *old, const char *nw)
afx_msg BOOL OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult)
bool LoadKeyWordsFromFile(const char *fileName)
void ScriptEditorShutdown(void)
#define IDR_ACCELERATOR_SCRIPTEDITOR
int ReplaceAll(const char *find, const char *replace, bool matchCase, bool matchWholeWords)
int ExpectTokenType(int type, int subtype, idToken *token)
int GetLastWhiteSpace(idStr &whiteSpace) const