29 #include "../../idlib/precompiled.h"
32 #include "../../sys/win32/rc/Common_resource.h"
33 #include "../../sys/win32/rc/DeclEditor_resource.h"
35 #include "../comafx/CPathTreeCtrl.h"
40 #ifdef ID_DEBUG_MEMORY
51 { IDOK,
"Save Decl" },
52 { IDCANCEL,
"Cancel" },
85 CDialog::DoDataExchange(pDX);
87 DDX_Control(pDX, IDC_ENTITYDEFEDITOR_EDIT_DECLNAME,
declNameEdit);
88 DDX_Control(pDX, IDC_ENTITYDEFEDITOR_COMBO_INHERIT,
inheritCombo);
89 DDX_Control(pDX, IDC_ENTITYDEFEDITOR_COMBO_SPAWNCLASS,
spawnclassCombo);
91 DDX_Control(pDX, IDC_ENTITYDEFEDITOR_LIST_KEYVALS,
keyValsList);
93 DDX_Control(pDX, IDC_ENTITYDEFEDITOR_STATIC_KEY,
keyLabel);
94 DDX_Control(pDX, IDC_ENTITYDEFEDITOR_EDIT_KEY,
keyEdit);
95 DDX_Control(pDX, IDC_ENTITYDEFEDITOR_BUTTON_ADD,
addButton);
96 DDX_Control(pDX, IDC_ENTITYDEFEDITOR_BUTTON_DELETE,
delButton);
97 DDX_Control(pDX, IDC_ENTITYDEFEDITOR_LINE,
line);
111 if ( WM_KEYFIRST <= pMsg->message && pMsg->message <= WM_KEYLAST ) {
116 return CWnd::PreTranslateMessage(pMsg);
133 if ( token ==
"{" ) {
135 }
else if ( token ==
"}" ) {
141 MessageBox(
"Missing opening brace!",
va(
"Error saving %s",
decl->
GetFileName() ), MB_OK | MB_ICONERROR );
145 MessageBox(
"Missing closing brace!",
va(
"Error saving %s",
decl->
GetFileName() ), MB_OK | MB_ICONERROR );
158 statusBar.SetWindowText(
"Editing decl" );
183 for (
int i=0;
i<numDecls;
i++) {
192 char *declText = (
char *)_alloca( ( decl->
GetTextLength() + 1 ) *
sizeof(
char ) );
200 GetWindowRect( rect );
231 if ( !token.
Icmp(
"}" ) ) {
235 src.
Warning(
"Expected quoted string, but found '%s'", token.
c_str() );
240 src.
Warning(
"Unexpected end of file" );
247 dict.
Set( token, token2 );
255 inherit = inheritKeyVal->
GetValue();
260 dict.
Delete(
"spawnclass");
265 size_t numPairs = dict.
Size();
266 for (
unsigned int i=0;
i<numPairs;
i++) {
279 if (index == CB_ERR) {
312 size_t numPairs = parent->
dict.
Size();
313 for (
unsigned int i=0;
i<numPairs;
i++) {
316 if (spawnclass.IsEmpty() && keyVal->
GetKey() ==
"spawnclass") {
320 CString key = keyVal->
GetKey();
339 CDialog::OnInitDialog();
345 statusBar.CreateEx( SBARS_SIZEGRIP, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM,
initialRect,
this, AFX_IDW_STATUS_BAR );
349 EnableToolTips(
TRUE );
362 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
363 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
370 ON_CBN_EDITCHANGE(IDC_ENTITYDEFEDITOR_COMBO_INHERIT, OnInheritChange)
371 ON_CBN_SELCHANGE(IDC_ENTITYDEFEDITOR_COMBO_INHERIT, OnInheritChange)
372 ON_CBN_EDITCHANGE(IDC_ENTITYDEFEDITOR_COMBO_SPAWNCLASS, OnEditChange)
373 ON_EN_CHANGE(IDC_ENTITYDEFEDITOR_EDIT_DECLNAME, OnEditChange)
376 ON_LBN_SELCHANGE(IDC_ENTITYDEFEDITOR_LIST_KEYVALS, OnKeyValChange)
378 ON_BN_CLICKED(IDC_ENTITYDEFEDITOR_BUTTON_ADD, OnBnClickedAdd)
379 ON_BN_CLICKED(IDC_ENTITYDEFEDITOR_BUTTON_DELETE, OnBnClickedDelete)
382 ON_BN_CLICKED(IDOK, OnBnClickedOk)
383 ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
396 CDialog::OnActivate( nState, pWndOther, bMinimized );
414 CDialog::OnSetFocus( pOldWnd );
423 return CDialog::OnDestroy();
432 if ( GetSafeHwnd() ) {
434 GetWindowRect( rct );
437 CDialog::OnMove( x, y );
445 #define BORDER_SIZE 4
446 #define BUTTON_SPACE 4
447 #define CONTROL_HEIGHT 24
448 #define TOOLBAR_HEIGHT 24
451 CRect clientRect, rect;
455 CDialog::OnSize( nType, cx, cy );
457 GetClientRect( clientRect );
465 keyValsList.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
471 int lineTop = clientRect.Height() -
TOOLBAR_HEIGHT * 3 + (CONTROL_HEIGHT / 2);
478 int width = rect.Width();
481 rect.top = keyRowTop + 8;
482 rect.bottom = keyRowBottom;
483 keyLabel.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
489 rect.right = 40 + 200;
490 rect.top = keyRowTop;
491 rect.bottom = keyRowBottom;
492 keyEdit.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
498 int width = rect.Width();
501 rect.top = keyRowTop;
502 rect.bottom = keyRowBottom;
503 addButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
508 int width = rect.Width();
511 rect.top = keyRowTop;
512 rect.bottom = keyRowBottom;
513 delButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
516 if (
line.GetSafeHwnd() ) {
517 line.GetClientRect( rect );
518 int height = rect.Height();
522 rect.bottom = lineTop + 3;
523 line.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
528 int width = rect.Width();
531 rect.top = buttonRowTop;
532 rect.bottom = buttonRowBottom;
533 testButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
538 int width = rect.Width();
541 rect.top = buttonRowTop;
542 rect.bottom = buttonRowBottom;
543 okButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
548 int width = rect.Width();
551 rect.top = buttonRowTop;
552 rect.bottom = buttonRowBottom;
553 cancelButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
557 rect.left = clientRect.Width() - 2;
558 rect.top = clientRect.Height() - 2;
559 rect.right = clientRect.Width() - 2;
560 rect.bottom = clientRect.Height() - 2;
561 statusBar.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
564 UnlockWindowUpdate();
584 CDialog::OnSizing( nSide, lpRect );
586 if ( ( nSide - 1 ) % 3 == 0 ) {
587 if ( lpRect->right - lpRect->left <
initialRect.Width() ) {
588 lpRect->left = lpRect->right -
initialRect.Width();
590 }
else if ( ( nSide - 2 ) % 3 == 0 ) {
591 if ( lpRect->right - lpRect->left <
initialRect.Width() ) {
592 lpRect->right = lpRect->left +
initialRect.Width();
595 if ( nSide >= 3 && nSide <= 5 ) {
596 if ( lpRect->bottom - lpRect->top <
initialRect.Height() ) {
597 lpRect->top = lpRect->bottom -
initialRect.Height();
599 }
else if ( nSide >= 6 && nSide <= 9 ) {
600 if ( lpRect->bottom - lpRect->top <
initialRect.Height() ) {
601 lpRect->bottom = lpRect->top +
initialRect.Height();
628 if ( sel == CB_ERR ) {
647 MSGFILTER *msgFilter = (MSGFILTER *)pNMHDR;
649 if ( msgFilter->msg != 512 && msgFilter->msg != 33 ) {
671 declText =
"entityDef " + declName +
"\r{\r";
672 declText +=
"\"inherit\"\t\t\t\"" + inherit +
"\"\r";
673 declText +=
"\"spawnclass\"\t\t\t\"" + spawnclass +
"\"\r";
686 declText.
Replace(
"\r",
"\r\n" );
687 declText.
Insert(
"\r\n\r\n", 0 );
697 idStr declText, oldDeclText;
707 char *oldDeclText = (
char *)_alloca( (
decl->
GetTextLength() + 1 ) *
sizeof(
char ) );
736 if ( MessageBox(
va(
"Declaration file %s has been modified outside of the editor.\r\nReload declarations and save?",
decl->
GetFileName() ),
737 va(
"Warning saving: %s",
decl->
GetFileName() ), MB_OKCANCEL | MB_ICONERROR ) != IDOK ) {
746 MessageBox(
va(
"Couldn't save: %s.\r\nMake sure the declaration file is not read-only.",
decl->
GetFileName() ),
763 if ( MessageBox(
"Cancel changes?",
"Cancel", MB_YESNO | MB_ICONQUESTION ) != IDYES ) {
792 int matchedInherit = -1;
812 if (matchedKey >= 0) {
813 MessageBox(
"Key " + newKey +
" already defined");
817 if (matchedInherit >= 0) {
833 int matchedInherit = -1;
853 if (matchedKey >= 0) {
857 else if (matchedInherit) {
858 MessageBox(
"Cannot delete an inherited value");
int GetLineNum(void) const
BOOL DefaultOnToolTipNotify(const toolTip_t *toolTips, UINT id, NMHDR *pNMHDR, LRESULT *pResult)
afx_msg void OnSetFocus(CWnd *pOldWnd)
virtual ~DialogEntityDefEditor()
bool ReplaceSourceFileText(void)
void Delete(const char *key)
const char * GetFileName(void) const
const int DECL_LEXER_FLAGS
CONST PIXELFORMATDESCRIPTOR UINT
bool TestDecl(const idStr &declText)
const idStr & GetKey(void) const
virtual void DoDataExchange(CDataExchange *pDX)
void StripTrailing(const char c)
#define IDR_ACCELERATOR_DECLEDITOR
void PopulateLists(idStr &declText)
bool SourceFileChanged(void) const
const char * GetName(void) const
virtual BOOL PreTranslateMessage(MSG *pMsg)
static toolTip_t toolTips[]
void DeclBrowserReloadDeclarations(void)
void Set(const char *key, const char *value)
afx_msg void OnBnClickedTest()
afx_msg void OnEnInputEdit(NMHDR *pNMHDR, LRESULT *pResult)
int Icmp(const char *text) const
void LoadDecl(idDeclEntityDef *decl)
afx_msg void OnInheritChange()
void BuildDeclText(idStr &declText)
afx_msg void OnBnClickedDelete()
declType_t GetType(void) const
const char * GetString(const char *key, const char *defaultString="") const
afx_msg void OnBnClickedCancel()
void UpdateStatusBar(void)
virtual const idDecl * FindType(declType_t type, const char *name, bool makeDefault=true)=0
virtual BOOL OnInitDialog()
afx_msg void OnEditChange()
const idStr & GetValue(void) const
void Insert(const char a, int index)
virtual void Reload(bool force)=0
#define IDC_DECLEDITOR_EDIT_TEXT
int AddPropItem(CPropertyItem *pItem)
const idKeyValue * FindKey(const char *key) const
virtual void Printf(const char *fmt,...) id_attribute((format(printf
int LoadMemory(const char *ptr, int length, const char *name, int startLine=1)
afx_msg void OnBnClickedAdd()
GLenum GLsizei GLsizei height
void SetText(const char *text)
idDeclManager * declManager
virtual int GetNumDecls(declType_t type)=0
afx_msg void OnMove(int x, int y)
#define IDC_DECLEDITOR_BUTTON_TEST
void void Warning(const char *str,...) id_attribute((format(printf
virtual const idDecl * DeclByIndex(declType_t type, int index, bool forceParse=true)=0
void SetInherit(idStr &inherit)
afx_msg void OnSize(UINT nType, int cx, int cy)
const char * c_str(void) const
int SkipUntilString(const char *string)
const idKeyValue * GetKeyVal(int index) const
afx_msg BOOL OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult)
CComboBox spawnclassCombo
afx_msg void OnBnClickedOk()
void GetText(char *text) const
char * va(const char *fmt,...)
CPropertyList keyValsList
afx_msg void OnSizing(UINT nSide, LPRECT lpRect)
void Replace(const char *old, const char *nw)
int ReadToken(idToken *token)
int GetTextLength(void) const
afx_msg void OnKeyValChange()