mirror of
https://github.com/id-Software/DOOM-3.git
synced 2026-03-19 16:39:27 +01:00
hello world
This commit is contained in:
947
neo/tools/decl/DialogDeclBrowser.cpp
Normal file
947
neo/tools/decl/DialogDeclBrowser.cpp
Normal file
@@ -0,0 +1,947 @@
|
||||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 GPL Source Code
|
||||
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
|
||||
|
||||
Doom 3 Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#include "../../idlib/precompiled.h"
|
||||
#pragma hdrstop
|
||||
|
||||
#include "../../sys/win32/rc/DeclEditor_resource.h"
|
||||
#include "../../sys/win32/rc/ScriptEditor_resource.h"
|
||||
|
||||
#include "../comafx/CPathTreeCtrl.h"
|
||||
#include "../script/DialogScriptEditor.h"
|
||||
#include "DialogDeclBrowser.h"
|
||||
#include "DialogDeclEditor.h"
|
||||
#include "DialogDeclNew.h"
|
||||
|
||||
#ifdef ID_DEBUG_MEMORY
|
||||
#undef new
|
||||
#undef DEBUG_NEW
|
||||
#define DEBUG_NEW new
|
||||
#endif
|
||||
|
||||
const int DECLTYPE_SHIFT = 24;
|
||||
const int DECLINDEX_MASK = ( 1 << DECLTYPE_SHIFT ) - 1;
|
||||
const int DECLTYPE_SCRIPT = 126;
|
||||
const int DECLTYPE_GUI = 127;
|
||||
|
||||
#define GetIdFromTypeAndIndex( type, index ) ( ( (int)type << DECLTYPE_SHIFT ) | index )
|
||||
#define GetTypeFromId( id ) ( (declType_t) ( (int)id >> DECLTYPE_SHIFT ) )
|
||||
#define GetIndexFromId( id ) ( (int)id & DECLINDEX_MASK )
|
||||
|
||||
toolTip_t DialogDeclBrowser::toolTips[] = {
|
||||
{ IDC_DECLBROWSER_TREE, "decl browser" },
|
||||
{ IDC_DECLBROWSER_EDIT_SEARCH_NAMES, "search for declarations with matching name, use meta characters: *, ? and [abc...]" },
|
||||
{ IDC_DECLBROWSER_EDIT_SEARCH_TEXT, "search for declarations containing text" },
|
||||
{ IDC_DECLBROWSER_BUTTON_FIND, "find declarations matching the search strings" },
|
||||
{ IDC_DECLBROWSER_BUTTON_EDIT, "edit selected declaration" },
|
||||
{ IDC_DECLBROWSER_BUTTON_NEW, "create new declaration" },
|
||||
{ IDC_DECLBROWSER_BUTTON_RELOAD, "reload declarations" },
|
||||
{ IDOK, "ok" },
|
||||
{ IDCANCEL, "cancel" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
|
||||
static DialogDeclBrowser *g_DeclDialog = NULL;
|
||||
|
||||
|
||||
IMPLEMENT_DYNAMIC(DialogDeclBrowser, CDialog)
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::DialogDeclBrowser
|
||||
================
|
||||
*/
|
||||
DialogDeclBrowser::DialogDeclBrowser( CWnd* pParent /*=NULL*/ )
|
||||
: CDialog(DialogDeclBrowser::IDD, pParent)
|
||||
, m_pchTip(NULL)
|
||||
, m_pwchTip(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::~DialogDeclBrowser
|
||||
================
|
||||
*/
|
||||
DialogDeclBrowser::~DialogDeclBrowser() {
|
||||
delete m_pwchTip;
|
||||
delete m_pchTip;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::DoDataExchange
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::DoDataExchange(CDataExchange* pDX) {
|
||||
CDialog::DoDataExchange(pDX);
|
||||
//{{AFX_DATA_MAP(DialogDeclBrowser)
|
||||
DDX_Control(pDX, IDC_DECLBROWSER_TREE, declTree);
|
||||
DDX_Control(pDX, IDC_DECLBROWSER_STATIC_SEARCH_NAMES, findNameStatic);
|
||||
DDX_Control(pDX, IDC_DECLBROWSER_STATIC_SEARCH_TEXT, findTextStatic);
|
||||
DDX_Control(pDX, IDC_DECLBROWSER_EDIT_SEARCH_NAMES, findNameEdit);
|
||||
DDX_Control(pDX, IDC_DECLBROWSER_EDIT_SEARCH_TEXT, findTextEdit);
|
||||
DDX_Control(pDX, IDC_DECLBROWSER_BUTTON_FIND, findButton);
|
||||
DDX_Control(pDX, IDC_DECLBROWSER_BUTTON_EDIT, editButton);
|
||||
DDX_Control(pDX, IDC_DECLBROWSER_BUTTON_NEW, newButton);
|
||||
DDX_Control(pDX, IDC_DECLBROWSER_BUTTON_RELOAD, reloadButton);
|
||||
DDX_Control(pDX, IDCANCEL, cancelButton);
|
||||
//}}AFX_DATA_MAP
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::AddDeclTypeToTree
|
||||
================
|
||||
*/
|
||||
template< class type >
|
||||
int idListDeclSortCompare( const type *a, const type *b ) {
|
||||
return idStr::IcmpPath( (*a)->GetName(), (*b)->GetName() );
|
||||
}
|
||||
|
||||
void DialogDeclBrowser::AddDeclTypeToTree( declType_t type, const char *root, CPathTreeCtrl &tree ) {
|
||||
int i;
|
||||
idList<const idDecl*> decls;
|
||||
idPathTreeStack stack;
|
||||
idStr rootStr, declName;
|
||||
|
||||
decls.SetNum( declManager->GetNumDecls( type ) );
|
||||
for ( i = 0; i < decls.Num(); i++ ) {
|
||||
decls[i] = declManager->DeclByIndex( type, i, false );
|
||||
}
|
||||
decls.Sort( idListDeclSortCompare );
|
||||
|
||||
rootStr = root;
|
||||
rootStr += "/";
|
||||
|
||||
stack.PushRoot( NULL );
|
||||
|
||||
for ( i = 0; i < decls.Num(); i++) {
|
||||
declName = rootStr + decls[i]->GetName();
|
||||
|
||||
declName.BackSlashesToSlashes();
|
||||
declName.Strip(' ');
|
||||
|
||||
tree.AddPathToTree( declName, GetIdFromTypeAndIndex( type, decls[i]->Index() ), stack );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::AddScriptsToTree
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::AddScriptsToTree( CPathTreeCtrl &tree ) {
|
||||
int i;
|
||||
idPathTreeStack stack;
|
||||
idStr scriptName;
|
||||
idFileList *files;
|
||||
|
||||
files = fileSystem->ListFilesTree( "script", ".script", true );
|
||||
|
||||
stack.PushRoot( NULL );
|
||||
|
||||
for ( i = 0; i < files->GetNumFiles(); i++) {
|
||||
scriptName = files->GetFile( i );
|
||||
|
||||
scriptName.BackSlashesToSlashes();
|
||||
scriptName.StripFileExtension();
|
||||
|
||||
tree.AddPathToTree( scriptName, GetIdFromTypeAndIndex( DECLTYPE_SCRIPT, i ), stack );
|
||||
}
|
||||
|
||||
fileSystem->FreeFileList( files );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::AddGUIsToTree
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::AddGUIsToTree( CPathTreeCtrl &tree ) {
|
||||
int i;
|
||||
idPathTreeStack stack;
|
||||
idStr scriptName;
|
||||
idFileList *files;
|
||||
|
||||
files = fileSystem->ListFilesTree( "guis", ".gui", true );
|
||||
|
||||
stack.PushRoot( NULL );
|
||||
|
||||
for ( i = 0; i < files->GetNumFiles(); i++) {
|
||||
scriptName = files->GetFile( i );
|
||||
|
||||
scriptName.BackSlashesToSlashes();
|
||||
scriptName.StripFileExtension();
|
||||
|
||||
tree.AddPathToTree( scriptName, GetIdFromTypeAndIndex( DECLTYPE_GUI, i ), stack );
|
||||
}
|
||||
|
||||
fileSystem->FreeFileList( files );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::InitBaseDeclTree
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::InitBaseDeclTree( void ) {
|
||||
int i;
|
||||
|
||||
numListedDecls = 0;
|
||||
baseDeclTree.DeleteAllItems();
|
||||
|
||||
for ( i = 0; i < declManager->GetNumDeclTypes(); i++ ) {
|
||||
AddDeclTypeToTree( (declType_t)i, declManager->GetDeclNameFromType( (declType_t)i ), baseDeclTree );
|
||||
}
|
||||
|
||||
AddScriptsToTree( baseDeclTree );
|
||||
AddGUIsToTree( baseDeclTree );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::GetDeclName
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::GetDeclName( HTREEITEM item, idStr &typeName, idStr &declName ) const {
|
||||
HTREEITEM parent;
|
||||
idStr itemName;
|
||||
|
||||
declName.Clear();
|
||||
for( parent = declTree.GetParentItem( item ); parent; parent = declTree.GetParentItem( parent ) ) {
|
||||
itemName = declTree.GetItemText( item );
|
||||
declName = itemName + "/" + declName;
|
||||
item = parent;
|
||||
}
|
||||
declName.Strip( '/' );
|
||||
typeName = declTree.GetItemText( item );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::GetDeclFromTreeItem
|
||||
================
|
||||
*/
|
||||
const idDecl *DialogDeclBrowser::GetDeclFromTreeItem( HTREEITEM item ) const {
|
||||
int id, index;
|
||||
declType_t type;
|
||||
const idDecl *decl;
|
||||
|
||||
if ( declTree.GetChildItem( item ) ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
id = declTree.GetItemData( item );
|
||||
type = GetTypeFromId( id );
|
||||
index = GetIndexFromId( id );
|
||||
|
||||
if ( type < 0 || type >= declManager->GetNumDeclTypes() ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
decl = declManager->DeclByIndex( type, index, false );
|
||||
|
||||
return decl;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::GetSelectedDecl
|
||||
================
|
||||
*/
|
||||
const idDecl *DialogDeclBrowser::GetSelectedDecl( void ) const {
|
||||
return GetDeclFromTreeItem( declTree.GetSelectedItem() );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::EditSelected
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::EditSelected( void ) const {
|
||||
int id, index;
|
||||
idDict spawnArgs;
|
||||
const idDecl *decl;
|
||||
declType_t type;
|
||||
HTREEITEM item;
|
||||
|
||||
item = declTree.GetSelectedItem();
|
||||
|
||||
if ( declTree.GetChildItem( item ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
id = declTree.GetItemData( item );
|
||||
type = GetTypeFromId( id );
|
||||
index = GetIndexFromId( id );
|
||||
|
||||
switch( type ) {
|
||||
case DECL_AF: {
|
||||
decl = declManager->DeclByIndex( type, index, false );
|
||||
spawnArgs.Set( "articulatedFigure", decl->GetName() );
|
||||
AFEditorInit( &spawnArgs );
|
||||
break;
|
||||
}
|
||||
case DECL_PARTICLE: {
|
||||
decl = declManager->DeclByIndex( type, index, false );
|
||||
spawnArgs.Set( "model", decl->GetName() );
|
||||
ParticleEditorInit( &spawnArgs );
|
||||
break;
|
||||
}
|
||||
case DECL_PDA: {
|
||||
decl = declManager->DeclByIndex( type, index, false );
|
||||
spawnArgs.Set( "pda", decl->GetName() );
|
||||
PDAEditorInit( &spawnArgs );
|
||||
break;
|
||||
}
|
||||
case DECLTYPE_SCRIPT:
|
||||
case DECLTYPE_GUI: {
|
||||
idStr typeName, declName;
|
||||
GetDeclName( item, typeName, declName );
|
||||
DialogScriptEditor *scriptEditor;
|
||||
scriptEditor = new DialogScriptEditor;
|
||||
scriptEditor->Create( IDD_DIALOG_SCRIPTEDITOR, GetParent() );
|
||||
scriptEditor->OpenFile( typeName + "/" + declName + ( ( type == DECLTYPE_SCRIPT ) ? ".script" : ".gui" ) );
|
||||
scriptEditor->ShowWindow( SW_SHOW );
|
||||
scriptEditor->SetFocus();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
decl = declManager->DeclByIndex( type, index, false );
|
||||
DialogDeclEditor *declEditor;
|
||||
declEditor = new DialogDeclEditor;
|
||||
declEditor->Create( IDD_DIALOG_DECLEDITOR, GetParent() );
|
||||
declEditor->LoadDecl( const_cast<idDecl *>( decl ) );
|
||||
declEditor->ShowWindow( SW_SHOW );
|
||||
declEditor->SetFocus();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DeclBrowserCompareDecl
|
||||
================
|
||||
*/
|
||||
bool DeclBrowserCompareDecl( void *data, HTREEITEM item, const char *name ) {
|
||||
return reinterpret_cast<DialogDeclBrowser *>(data)->CompareDecl( item, name );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::CompareDecl
|
||||
================
|
||||
*/
|
||||
bool DialogDeclBrowser::CompareDecl( HTREEITEM item, const char *name ) const {
|
||||
if ( findNameString.Length() ) {
|
||||
if ( !idStr::Filter( findNameString, name, false ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( findTextString.Length() ) {
|
||||
int id, index;
|
||||
declType_t type;
|
||||
|
||||
id = declTree.GetItemData( item );
|
||||
type = GetTypeFromId( id );
|
||||
index = GetIndexFromId( id );
|
||||
|
||||
if ( type == DECLTYPE_SCRIPT || type == DECLTYPE_GUI ) {
|
||||
// search for the text in the script or gui
|
||||
idStr text;
|
||||
void *buffer;
|
||||
if ( fileSystem->ReadFile( idStr( name ) + ( ( type == DECLTYPE_SCRIPT ) ? ".script" : ".gui" ), &buffer ) == -1 ) {
|
||||
return false;
|
||||
}
|
||||
text = (char *) buffer;
|
||||
fileSystem->FreeFile( buffer );
|
||||
if ( text.Find( findTextString, false ) == -1 ) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// search for the text in the decl
|
||||
const idDecl *decl = declManager->DeclByIndex( type, index, false );
|
||||
char *declText = (char *)_alloca( ( decl->GetTextLength() + 1 ) * sizeof( char ) );
|
||||
decl->GetText( declText );
|
||||
if ( idStr::FindText( declText, findTextString, false ) == -1 ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnInitDialog
|
||||
================
|
||||
*/
|
||||
BOOL DialogDeclBrowser::OnInitDialog() {
|
||||
|
||||
com_editors |= EDITOR_DECL;
|
||||
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
GetClientRect( initialRect );
|
||||
|
||||
statusBar.CreateEx( SBARS_SIZEGRIP, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM, initialRect, this, AFX_IDW_STATUS_BAR );
|
||||
|
||||
baseDeclTree.Create( 0, initialRect, this, IDC_DECLBROWSER_BASE_TREE );
|
||||
|
||||
InitBaseDeclTree();
|
||||
|
||||
findNameString = "*";
|
||||
findNameEdit.SetWindowText( findNameString );
|
||||
|
||||
findTextString = "";
|
||||
findTextEdit.SetWindowText( findTextString );
|
||||
|
||||
numListedDecls = baseDeclTree.SearchTree( DeclBrowserCompareDecl, this, declTree );
|
||||
|
||||
statusBar.SetWindowText( va( "%d decls listed", numListedDecls ) );
|
||||
|
||||
EnableToolTips( TRUE );
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// EXCEPTION: OCX Property Pages should return FALSE
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DeclBrowserInit
|
||||
================
|
||||
*/
|
||||
void DeclBrowserInit( const idDict *spawnArgs ) {
|
||||
|
||||
if ( renderSystem->IsFullScreen() ) {
|
||||
common->Printf( "Cannot run the declaration editor in fullscreen mode.\n"
|
||||
"Set r_fullscreen to 0 and vid_restart.\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( g_DeclDialog == NULL ) {
|
||||
InitAfx();
|
||||
g_DeclDialog = new DialogDeclBrowser();
|
||||
}
|
||||
|
||||
if ( g_DeclDialog->GetSafeHwnd() == NULL) {
|
||||
g_DeclDialog->Create( IDD_DIALOG_DECLBROWSER );
|
||||
/*
|
||||
// FIXME: restore position
|
||||
CRect rct;
|
||||
g_DeclDialog->SetWindowPos( NULL, rct.left, rct.top, 0, 0, SWP_NOSIZE );
|
||||
*/
|
||||
}
|
||||
|
||||
idKeyInput::ClearStates();
|
||||
|
||||
g_DeclDialog->ShowWindow( SW_SHOW );
|
||||
g_DeclDialog->SetFocus();
|
||||
|
||||
if ( spawnArgs ) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DeclBrowserRun
|
||||
================
|
||||
*/
|
||||
void DeclBrowserRun( void ) {
|
||||
#if _MSC_VER >= 1300
|
||||
MSG *msg = AfxGetCurrentMessage(); // TODO Robert fix me!!
|
||||
#else
|
||||
MSG *msg = &m_msgCur;
|
||||
#endif
|
||||
|
||||
while( ::PeekMessage(msg, NULL, NULL, NULL, PM_NOREMOVE) ) {
|
||||
// pump message
|
||||
if ( !AfxGetApp()->PumpMessage() ) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DeclBrowserShutdown
|
||||
================
|
||||
*/
|
||||
void DeclBrowserShutdown( void ) {
|
||||
delete g_DeclDialog;
|
||||
g_DeclDialog = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DeclBrowserReloadDeclarations
|
||||
================
|
||||
*/
|
||||
void DeclBrowserReloadDeclarations( void ) {
|
||||
if ( g_DeclDialog ) {
|
||||
g_DeclDialog->ReloadDeclarations();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::ReloadDeclarations
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::ReloadDeclarations( void ) {
|
||||
InitBaseDeclTree();
|
||||
OnBnClickedFind();
|
||||
}
|
||||
|
||||
BEGIN_MESSAGE_MAP(DialogDeclBrowser, CDialog)
|
||||
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
|
||||
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
|
||||
ON_WM_DESTROY()
|
||||
ON_WM_ACTIVATE()
|
||||
ON_WM_MOVE()
|
||||
ON_WM_SIZE()
|
||||
ON_WM_SIZING()
|
||||
ON_WM_SETFOCUS()
|
||||
ON_NOTIFY(TVN_SELCHANGED, IDC_DECLBROWSER_TREE, OnTreeSelChanged)
|
||||
ON_NOTIFY(NM_DBLCLK, IDC_DECLBROWSER_TREE, OnTreeDblclk)
|
||||
ON_BN_CLICKED(IDC_DECLBROWSER_BUTTON_FIND, OnBnClickedFind)
|
||||
ON_BN_CLICKED(IDC_DECLBROWSER_BUTTON_EDIT, OnBnClickedEdit)
|
||||
ON_BN_CLICKED(IDC_DECLBROWSER_BUTTON_NEW, OnBnClickedNew)
|
||||
ON_BN_CLICKED(IDC_DECLBROWSER_BUTTON_RELOAD, OnBnClickedReload)
|
||||
ON_BN_CLICKED(IDOK, OnBnClickedOk)
|
||||
ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
// DialogDeclBrowser message handlers
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnActivate
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::OnActivate( UINT nState, CWnd *pWndOther, BOOL bMinimized ) {
|
||||
CDialog::OnActivate( nState, pWndOther, bMinimized );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnToolTipNotify
|
||||
================
|
||||
*/
|
||||
BOOL DialogDeclBrowser::OnToolTipNotify( UINT id, NMHDR *pNMHDR, LRESULT *pResult ) {
|
||||
// need to handle both ANSI and UNICODE versions of the message
|
||||
TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
|
||||
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
|
||||
|
||||
if ( pNMHDR->hwndFrom == declTree.GetSafeHwnd() ) {
|
||||
CString toolTip;
|
||||
const idDecl *decl = GetDeclFromTreeItem( (HTREEITEM) pNMHDR->idFrom );
|
||||
|
||||
if ( !decl ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
toolTip = va( "%s, line: %d", decl->GetFileName(), decl->GetLineNum() );
|
||||
|
||||
#ifndef _UNICODE
|
||||
if( pNMHDR->code == TTN_NEEDTEXTA ) {
|
||||
delete m_pchTip;
|
||||
m_pchTip = new TCHAR[toolTip.GetLength() + 2];
|
||||
lstrcpyn( m_pchTip, toolTip, toolTip.GetLength() + 1 );
|
||||
pTTTW->lpszText = (WCHAR*)m_pchTip;
|
||||
} else {
|
||||
delete m_pwchTip;
|
||||
m_pwchTip = new WCHAR[toolTip.GetLength() + 2];
|
||||
_mbstowcsz( m_pwchTip, toolTip, toolTip.GetLength() + 1 );
|
||||
pTTTW->lpszText = (WCHAR*)m_pwchTip;
|
||||
}
|
||||
#else
|
||||
if( pNMHDR->code == TTN_NEEDTEXTA ) {
|
||||
delete m_pchTip;
|
||||
m_pchTip = new TCHAR[toolTip.GetLength() + 2];
|
||||
_wcstombsz( m_pchTip, toolTip, toolTip.GetLength() + 1 );
|
||||
pTTTA->lpszText = (LPTSTR)m_pchTip;
|
||||
} else {
|
||||
delete m_pwchTip;
|
||||
m_pwchTip = new WCHAR[toolTip.GetLength() + 2];
|
||||
lstrcpyn( m_pwchTip, toolTip, toolTip.GetLength() + 1 );
|
||||
pTTTA->lpszText = (LPTSTR) m_pwchTip;
|
||||
}
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return DefaultOnToolTipNotify( toolTips, id, pNMHDR, pResult );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnSetFocus
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::OnSetFocus( CWnd *pOldWnd ) {
|
||||
CDialog::OnSetFocus( pOldWnd );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnDestroy
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::OnDestroy() {
|
||||
|
||||
com_editors &= ~EDITOR_DECL;
|
||||
|
||||
return CDialog::OnDestroy();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnMove
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::OnMove( int x, int y ) {
|
||||
if ( GetSafeHwnd() ) {
|
||||
CRect rct;
|
||||
GetWindowRect( rct );
|
||||
// FIXME: save position
|
||||
}
|
||||
CDialog::OnMove( x, y );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnMove
|
||||
================
|
||||
*/
|
||||
#define BORDER_SIZE 4
|
||||
#define BUTTON_SPACE 4
|
||||
#define TOOLBAR_HEIGHT 24
|
||||
|
||||
void DialogDeclBrowser::OnSize( UINT nType, int cx, int cy ) {
|
||||
CRect clientRect, rect;
|
||||
|
||||
LockWindowUpdate();
|
||||
|
||||
CDialog::OnSize( nType, cx, cy );
|
||||
|
||||
GetClientRect( clientRect );
|
||||
|
||||
if ( declTree.GetSafeHwnd() ) {
|
||||
rect.left = BORDER_SIZE;
|
||||
rect.top = BORDER_SIZE;
|
||||
rect.right = clientRect.Width() - BORDER_SIZE;
|
||||
rect.bottom = clientRect.Height() - 100;
|
||||
declTree.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( findNameStatic.GetSafeHwnd() ) {
|
||||
rect.left = BORDER_SIZE + 2;
|
||||
rect.top = clientRect.Height() - 100 + BUTTON_SPACE + 2;
|
||||
rect.right = BORDER_SIZE + 80;
|
||||
rect.bottom = clientRect.Height() - 76 + 2;
|
||||
findNameStatic.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( findTextStatic.GetSafeHwnd() ) {
|
||||
rect.left = BORDER_SIZE + 2;
|
||||
rect.top = clientRect.Height() - 78 + BUTTON_SPACE + 2;
|
||||
rect.right = BORDER_SIZE + 80;
|
||||
rect.bottom = clientRect.Height() - 54 + 2;
|
||||
findTextStatic.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( findNameEdit.GetSafeHwnd() ) {
|
||||
rect.left = BORDER_SIZE + 80;
|
||||
rect.top = clientRect.Height() - 100 + BUTTON_SPACE;
|
||||
rect.right = clientRect.Width() - BORDER_SIZE;
|
||||
rect.bottom = clientRect.Height() - 76;
|
||||
findNameEdit.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( findTextEdit.GetSafeHwnd() ) {
|
||||
rect.left = BORDER_SIZE + 80;
|
||||
rect.top = clientRect.Height() - 78 + BUTTON_SPACE;
|
||||
rect.right = clientRect.Width() - BORDER_SIZE;
|
||||
rect.bottom = clientRect.Height() - 54;
|
||||
findTextEdit.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( findButton.GetSafeHwnd() ) {
|
||||
findButton.GetClientRect( rect );
|
||||
int width = rect.Width();
|
||||
int height = rect.Height();
|
||||
rect.left = BORDER_SIZE;
|
||||
rect.top = clientRect.Height() - TOOLBAR_HEIGHT - height;
|
||||
rect.right = BORDER_SIZE + width;
|
||||
rect.bottom = clientRect.Height() - TOOLBAR_HEIGHT;
|
||||
findButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( editButton.GetSafeHwnd() ) {
|
||||
editButton.GetClientRect( rect );
|
||||
int width = rect.Width();
|
||||
int height = rect.Height();
|
||||
rect.left = BORDER_SIZE + BUTTON_SPACE + width;
|
||||
rect.top = clientRect.Height() - TOOLBAR_HEIGHT - height;
|
||||
rect.right = BORDER_SIZE + BUTTON_SPACE + 2 * width;
|
||||
rect.bottom = clientRect.Height() - TOOLBAR_HEIGHT;
|
||||
editButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( newButton.GetSafeHwnd() ) {
|
||||
newButton.GetClientRect( rect );
|
||||
int width = rect.Width();
|
||||
int height = rect.Height();
|
||||
rect.left = BORDER_SIZE + 2 * BUTTON_SPACE + 2 * width;
|
||||
rect.top = clientRect.Height() - TOOLBAR_HEIGHT - height;
|
||||
rect.right = BORDER_SIZE + 2 * BUTTON_SPACE + 3 * width;
|
||||
rect.bottom = clientRect.Height() - TOOLBAR_HEIGHT;
|
||||
newButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( reloadButton.GetSafeHwnd() ) {
|
||||
reloadButton.GetClientRect( rect );
|
||||
int width = rect.Width();
|
||||
int height = rect.Height();
|
||||
rect.left = BORDER_SIZE + 3 * BUTTON_SPACE + 3 * width;
|
||||
rect.top = clientRect.Height() - TOOLBAR_HEIGHT - height;
|
||||
rect.right = BORDER_SIZE + 3 * BUTTON_SPACE + 4 * width;
|
||||
rect.bottom = clientRect.Height() - TOOLBAR_HEIGHT;
|
||||
reloadButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( cancelButton.GetSafeHwnd() ) {
|
||||
cancelButton.GetClientRect( rect );
|
||||
int width = rect.Width();
|
||||
int height = rect.Height();
|
||||
rect.left = clientRect.Width() - BORDER_SIZE - width;
|
||||
rect.top = clientRect.Height() - TOOLBAR_HEIGHT - height;
|
||||
rect.right = clientRect.Width() - BORDER_SIZE;
|
||||
rect.bottom = clientRect.Height() - TOOLBAR_HEIGHT;
|
||||
cancelButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( statusBar.GetSafeHwnd() ) {
|
||||
rect.left = clientRect.Width() - 2;
|
||||
rect.top = clientRect.Height() - 2;
|
||||
rect.right = clientRect.Width() - 2;
|
||||
rect.bottom = clientRect.Height() - 2;
|
||||
statusBar.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
UnlockWindowUpdate();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnSizing
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::OnSizing( UINT nSide, LPRECT lpRect ) {
|
||||
/*
|
||||
1 = left
|
||||
2 = right
|
||||
3 = top
|
||||
4 = left - top
|
||||
5 = right - top
|
||||
6 = bottom
|
||||
7 = left - bottom
|
||||
8 = right - bottom
|
||||
*/
|
||||
|
||||
CDialog::OnSizing( nSide, lpRect );
|
||||
|
||||
if ( ( nSide - 1 ) % 3 == 0 ) {
|
||||
if ( lpRect->right - lpRect->left < initialRect.Width() ) {
|
||||
lpRect->left = lpRect->right - initialRect.Width();
|
||||
}
|
||||
} else if ( ( nSide - 2 ) % 3 == 0 ) {
|
||||
if ( lpRect->right - lpRect->left < initialRect.Width() ) {
|
||||
lpRect->right = lpRect->left + initialRect.Width();
|
||||
}
|
||||
}
|
||||
if ( nSide >= 3 && nSide <= 5 ) {
|
||||
if ( lpRect->bottom - lpRect->top < initialRect.Height() ) {
|
||||
lpRect->top = lpRect->bottom - initialRect.Height();
|
||||
}
|
||||
} else if ( nSide >= 6 && nSide <= 9 ) {
|
||||
if ( lpRect->bottom - lpRect->top < initialRect.Height() ) {
|
||||
lpRect->bottom = lpRect->top + initialRect.Height();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnTreeSelChanged
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::OnTreeSelChanged( NMHDR* pNMHDR, LRESULT* pResult ) {
|
||||
LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
|
||||
|
||||
const idDecl *decl = GetSelectedDecl();
|
||||
if ( decl ) {
|
||||
statusBar.SetWindowText( va( "%d decls listed - %s, line: %d", numListedDecls, decl->GetFileName(), decl->GetLineNum() ) );
|
||||
findNameEdit.SetWindowText( va( "%s/%s", declManager->GetDeclNameFromType( decl->GetType() ), decl->GetName() ) );
|
||||
} else {
|
||||
HTREEITEM item = declTree.GetSelectedItem();
|
||||
idStr typeName, declName;
|
||||
GetDeclName( item, typeName, declName );
|
||||
findNameEdit.SetWindowText( va( "%s/%s*", typeName.c_str(), declName.c_str() ) );
|
||||
statusBar.SetWindowText( va( "%d decls listed", numListedDecls ) );
|
||||
}
|
||||
|
||||
*pResult = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnTreeDblclk
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::OnTreeDblclk( NMHDR *pNMHDR, LRESULT *pResult ) {
|
||||
// post a message as if the edit button was clicked to make sure the editor gets focus
|
||||
PostMessage( WM_COMMAND, ( BN_CLICKED << 16 ) | editButton.GetDlgCtrlID(), 0 );
|
||||
|
||||
*pResult = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnBnClickedFind
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::OnBnClickedFind() {
|
||||
CString windowText;
|
||||
|
||||
findNameEdit.GetWindowText( windowText );
|
||||
findNameString = windowText;
|
||||
findNameString.Strip( ' ' );
|
||||
|
||||
findTextEdit.GetWindowText( windowText );
|
||||
findTextString = windowText;
|
||||
findTextString.Strip( ' ' );
|
||||
|
||||
numListedDecls = baseDeclTree.SearchTree( DeclBrowserCompareDecl, this, declTree );
|
||||
|
||||
statusBar.SetWindowText( va( "%d decls listed", numListedDecls ) );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnBnClickedEdit
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::OnBnClickedEdit() {
|
||||
EditSelected();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnBnClickedNew
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::OnBnClickedNew() {
|
||||
HTREEITEM item;
|
||||
idStr typeName, declName;
|
||||
const idDecl *decl;
|
||||
DialogDeclNew newDeclDlg;
|
||||
|
||||
newDeclDlg.SetDeclTree( &baseDeclTree );
|
||||
|
||||
item = declTree.GetSelectedItem();
|
||||
if ( item ) {
|
||||
GetDeclName( item, typeName, declName );
|
||||
newDeclDlg.SetDefaultType( typeName );
|
||||
newDeclDlg.SetDefaultName( declName );
|
||||
}
|
||||
|
||||
decl = GetSelectedDecl();
|
||||
if ( decl ) {
|
||||
newDeclDlg.SetDefaultFile( decl->GetFileName() );
|
||||
}
|
||||
|
||||
if ( newDeclDlg.DoModal() != IDOK ) {
|
||||
return;
|
||||
}
|
||||
|
||||
decl = newDeclDlg.GetNewDecl();
|
||||
|
||||
if ( decl ) {
|
||||
declName = declManager->GetDeclNameFromType( decl->GetType() );
|
||||
declName += "/";
|
||||
declName += decl->GetName();
|
||||
|
||||
int id = GetIdFromTypeAndIndex( decl->GetType(), decl->Index() );
|
||||
|
||||
baseDeclTree.InsertPathIntoTree( declName, id );
|
||||
item = declTree.InsertPathIntoTree( declName, id );
|
||||
declTree.SelectItem( item );
|
||||
|
||||
EditSelected();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnBnClickedReload
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::OnBnClickedReload() {
|
||||
|
||||
declManager->Reload( false );
|
||||
|
||||
ReloadDeclarations();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnBnClickedOk
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::OnBnClickedOk() {
|
||||
// with a modeless dialog once it is closed and re-activated windows seems
|
||||
// to enjoy mapping ENTER back to the default button ( OK ) even if you have
|
||||
// it NOT set as the default.. in this case use cancel button exit and ignore
|
||||
// default IDOK handling.
|
||||
// OnOK();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclBrowser::OnBnClickedCancel
|
||||
================
|
||||
*/
|
||||
void DialogDeclBrowser::OnBnClickedCancel() {
|
||||
OnCancel();
|
||||
}
|
||||
113
neo/tools/decl/DialogDeclBrowser.h
Normal file
113
neo/tools/decl/DialogDeclBrowser.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 GPL Source Code
|
||||
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
|
||||
|
||||
Doom 3 Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#ifndef __DIALOGDECLBROWSER_H__
|
||||
#define __DIALOGDECLBROWSER_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
// DialogDeclBrowser dialog
|
||||
|
||||
class DialogDeclBrowser : public CDialog {
|
||||
|
||||
DECLARE_DYNAMIC(DialogDeclBrowser)
|
||||
|
||||
public:
|
||||
DialogDeclBrowser( CWnd* pParent = NULL ); // standard constructor
|
||||
virtual ~DialogDeclBrowser();
|
||||
|
||||
void ReloadDeclarations( void );
|
||||
bool CompareDecl( HTREEITEM item, const char *name ) const;
|
||||
|
||||
//{{AFX_VIRTUAL(DialogDeclBrowser)
|
||||
virtual BOOL OnInitDialog();
|
||||
virtual void DoDataExchange( CDataExchange* pDX ); // DDX/DDV support
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
protected:
|
||||
//{{AFX_MSG(DialogDeclBrowser)
|
||||
afx_msg BOOL OnToolTipNotify( UINT id, NMHDR *pNMHDR, LRESULT *pResult );
|
||||
afx_msg void OnSetFocus( CWnd *pOldWnd );
|
||||
afx_msg void OnDestroy();
|
||||
afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
|
||||
afx_msg void OnMove( int x, int y );
|
||||
afx_msg void OnSize( UINT nType, int cx, int cy );
|
||||
afx_msg void OnSizing( UINT nSide, LPRECT lpRect );
|
||||
afx_msg void OnTreeSelChanged( NMHDR* pNMHDR, LRESULT* pResult );
|
||||
afx_msg void OnTreeDblclk( NMHDR *pNMHDR, LRESULT *pResult );
|
||||
afx_msg void OnBnClickedFind();
|
||||
afx_msg void OnBnClickedEdit();
|
||||
afx_msg void OnBnClickedNew();
|
||||
afx_msg void OnBnClickedReload();
|
||||
afx_msg void OnBnClickedOk();
|
||||
afx_msg void OnBnClickedCancel();
|
||||
//}}AFX_MSG
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
|
||||
private:
|
||||
|
||||
//{{AFX_DATA(DialogDeclBrowser)
|
||||
enum { IDD = IDD_DIALOG_DECLBROWSER };
|
||||
CStatusBarCtrl statusBar;
|
||||
CPathTreeCtrl declTree;
|
||||
CStatic findNameStatic;
|
||||
CStatic findTextStatic;
|
||||
CEdit findNameEdit;
|
||||
CEdit findTextEdit;
|
||||
CButton findButton;
|
||||
CButton editButton;
|
||||
CButton newButton;
|
||||
CButton reloadButton;
|
||||
CButton cancelButton;
|
||||
//}}AFX_DATA
|
||||
|
||||
static toolTip_t toolTips[];
|
||||
|
||||
CRect initialRect;
|
||||
CPathTreeCtrl baseDeclTree;
|
||||
int numListedDecls;
|
||||
idStr findNameString;
|
||||
idStr findTextString;
|
||||
|
||||
TCHAR * m_pchTip;
|
||||
WCHAR * m_pwchTip;
|
||||
|
||||
private:
|
||||
void AddDeclTypeToTree( declType_t type, const char *root, CPathTreeCtrl &tree );
|
||||
void AddScriptsToTree( CPathTreeCtrl &tree );
|
||||
void AddGUIsToTree( CPathTreeCtrl &tree );
|
||||
void InitBaseDeclTree( void );
|
||||
|
||||
void GetDeclName( HTREEITEM item, idStr &typeName, idStr &declName ) const;
|
||||
const idDecl * GetDeclFromTreeItem( HTREEITEM item ) const;
|
||||
const idDecl * GetSelectedDecl( void ) const;
|
||||
void EditSelected( void ) const;
|
||||
};
|
||||
|
||||
#endif /* !__DIALOGDECLBROWSER_H__ */
|
||||
715
neo/tools/decl/DialogDeclEditor.cpp
Normal file
715
neo/tools/decl/DialogDeclEditor.cpp
Normal file
@@ -0,0 +1,715 @@
|
||||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 GPL Source Code
|
||||
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
|
||||
|
||||
Doom 3 Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#include "../../idlib/precompiled.h"
|
||||
#pragma hdrstop
|
||||
|
||||
#include "../../sys/win32/rc/Common_resource.h"
|
||||
#include "../../sys/win32/rc/DeclEditor_resource.h"
|
||||
|
||||
#include "../comafx/DialogGoToLine.h"
|
||||
#include "../comafx/CPathTreeCtrl.h"
|
||||
#include "DialogDeclBrowser.h"
|
||||
#include "DialogDeclEditor.h"
|
||||
|
||||
#ifdef ID_DEBUG_MEMORY
|
||||
#undef new
|
||||
#undef DEBUG_NEW
|
||||
#define DEBUG_NEW new
|
||||
#endif
|
||||
|
||||
|
||||
// DialogDeclEditor dialog
|
||||
|
||||
static UINT FindDialogMessage = ::RegisterWindowMessage( FINDMSGSTRING );
|
||||
|
||||
toolTip_t DialogDeclEditor::toolTips[] = {
|
||||
{ IDC_DECLEDITOR_BUTTON_TEST, "test decl" },
|
||||
{ IDOK, "save decl" },
|
||||
{ IDCANCEL, "cancel" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
|
||||
IMPLEMENT_DYNAMIC(DialogDeclEditor, CDialog)
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::DialogDeclEditor
|
||||
================
|
||||
*/
|
||||
DialogDeclEditor::DialogDeclEditor( CWnd* pParent /*=NULL*/ )
|
||||
: CDialog(DialogDeclEditor::IDD, pParent)
|
||||
, findDlg(NULL)
|
||||
, matchCase(false)
|
||||
, matchWholeWords(false)
|
||||
, decl(NULL)
|
||||
, firstLine(0)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::~DialogDeclEditor
|
||||
================
|
||||
*/
|
||||
DialogDeclEditor::~DialogDeclEditor() {
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::DoDataExchange
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::DoDataExchange(CDataExchange* pDX) {
|
||||
CDialog::DoDataExchange(pDX);
|
||||
//{{AFX_DATA_MAP(DialogDeclEditor)
|
||||
DDX_Control(pDX, IDC_DECLEDITOR_EDIT_TEXT, declEdit);
|
||||
DDX_Control(pDX, IDC_DECLEDITOR_BUTTON_TEST, testButton);
|
||||
DDX_Control(pDX, IDOK, okButton);
|
||||
DDX_Control(pDX, IDCANCEL, cancelButton);
|
||||
//}}AFX_DATA_MAP
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::PreTranslateMessage
|
||||
================
|
||||
*/
|
||||
BOOL DialogDeclEditor::PreTranslateMessage( MSG* pMsg ) {
|
||||
if ( WM_KEYFIRST <= pMsg->message && pMsg->message <= WM_KEYLAST ) {
|
||||
if ( m_hAccel && ::TranslateAccelerator( m_hWnd, m_hAccel, pMsg ) ) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return CWnd::PreTranslateMessage(pMsg);
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::TestDecl
|
||||
================
|
||||
*/
|
||||
bool DialogDeclEditor::TestDecl( const idStr &declText ) {
|
||||
idLexer src( LEXFL_NOSTRINGCONCAT );
|
||||
idToken token;
|
||||
int indent;
|
||||
|
||||
src.LoadMemory( declText, declText.Length(), "decl text" );
|
||||
|
||||
indent = 0;
|
||||
while( src.ReadToken( &token ) ) {
|
||||
if ( token == "{" ) {
|
||||
indent++;
|
||||
} else if ( token == "}" ) {
|
||||
indent--;
|
||||
}
|
||||
}
|
||||
|
||||
if ( indent < 0 ) {
|
||||
MessageBox( "Missing opening brace!", va( "Error saving %s", decl->GetFileName() ), MB_OK | MB_ICONERROR );
|
||||
return false;
|
||||
}
|
||||
if ( indent > 0 ) {
|
||||
MessageBox( "Missing closing brace!", va( "Error saving %s", decl->GetFileName() ), MB_OK | MB_ICONERROR );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::UpdateStatusBar
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::UpdateStatusBar( void ) {
|
||||
int line, column, character;
|
||||
|
||||
if ( decl ) {
|
||||
declEdit.GetCursorPos( line, column, character );
|
||||
statusBar.SetWindowText( va( "Line: %d, Column: %d, Character: %d", decl->GetLineNum() + line, column, character ) );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::LoadDecl
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::LoadDecl( idDecl *decl ) {
|
||||
int numLines = 0;
|
||||
int numCharsPerLine = 0;
|
||||
int maxCharsPerLine = 0;
|
||||
idStr declText;
|
||||
CRect rect;
|
||||
|
||||
this->decl = decl;
|
||||
|
||||
switch( decl->GetType() ) {
|
||||
case DECL_ENTITYDEF:
|
||||
declEdit.SetStringColor( SRE_COLOR_BLUE, SRE_COLOR_DARK_CYAN );
|
||||
declEdit.LoadKeyWordsFromFile( "editors/entity.def" );
|
||||
break;
|
||||
case DECL_MATERIAL:
|
||||
declEdit.LoadKeyWordsFromFile( "editors/material.def" );
|
||||
break;
|
||||
case DECL_SKIN:
|
||||
declEdit.LoadKeyWordsFromFile( "editors/skin.def" );
|
||||
break;
|
||||
case DECL_SOUND:
|
||||
declEdit.LoadKeyWordsFromFile( "editors/sound.def" );
|
||||
break;
|
||||
case DECL_FX:
|
||||
declEdit.LoadKeyWordsFromFile( "editors/fx.def" );
|
||||
break;
|
||||
case DECL_PARTICLE:
|
||||
declEdit.LoadKeyWordsFromFile( "editors/particle.def" );
|
||||
break;
|
||||
case DECL_AF:
|
||||
declEdit.LoadKeyWordsFromFile( "editors/af.def" );
|
||||
break;
|
||||
case DECL_TABLE:
|
||||
declEdit.LoadKeyWordsFromFile( "editors/table.def" );
|
||||
break;
|
||||
case DECL_MODELDEF:
|
||||
declEdit.LoadKeyWordsFromFile( "editors/model.def" );
|
||||
break;
|
||||
default:
|
||||
declEdit.LoadKeyWordsFromFile( va( "editors/%s.def", declManager->GetDeclNameFromType( decl->GetType() ) ) );
|
||||
break;
|
||||
}
|
||||
|
||||
firstLine = decl->GetLineNum();
|
||||
|
||||
char *localDeclText = (char *)_alloca( ( decl->GetTextLength() + 1 ) * sizeof( char ) );
|
||||
decl->GetText( localDeclText );
|
||||
declText = localDeclText;
|
||||
|
||||
// clean up new-line crapola
|
||||
declText.Replace( "\r", "" );
|
||||
declText.Replace( "\n", "\r" );
|
||||
declText.Replace( "\v", "\r" );
|
||||
declText.StripLeading( '\r' );
|
||||
declText.Append( "\r" );
|
||||
|
||||
declEdit.SetText( declText );
|
||||
|
||||
for( const char *ptr = declText.c_str(); *ptr; ptr++ ) {
|
||||
if ( *ptr == '\r' ) {
|
||||
if ( numCharsPerLine > maxCharsPerLine ) {
|
||||
maxCharsPerLine = numCharsPerLine;
|
||||
}
|
||||
numCharsPerLine = 0;
|
||||
numLines++;
|
||||
} else if ( *ptr == '\t' ) {
|
||||
numCharsPerLine += TAB_SIZE;
|
||||
} else {
|
||||
numCharsPerLine++;
|
||||
}
|
||||
}
|
||||
|
||||
SetWindowText( va( "Declaration Editor (%s, line %d)", decl->GetFileName(), decl->GetLineNum() ) );
|
||||
|
||||
rect.left = initialRect.left;
|
||||
rect.right = rect.left + maxCharsPerLine * FONT_WIDTH + 32;
|
||||
rect.top = initialRect.top;
|
||||
rect.bottom = rect.top + numLines * (FONT_HEIGHT+8) + 24 + 56;
|
||||
if ( rect.right < initialRect.right ) {
|
||||
rect.right = initialRect.right;
|
||||
} else if ( rect.right - rect.left > 1024 ) {
|
||||
rect.right = rect.left + 1024;
|
||||
}
|
||||
if ( rect.bottom < initialRect.bottom ) {
|
||||
rect.bottom = initialRect.bottom;
|
||||
} else if ( rect.bottom - rect.top > 768 ) {
|
||||
rect.bottom = rect.top + 768;
|
||||
}
|
||||
MoveWindow( rect );
|
||||
|
||||
testButton.EnableWindow( FALSE );
|
||||
okButton.EnableWindow( FALSE );
|
||||
|
||||
UpdateStatusBar();
|
||||
|
||||
declEdit.SetFocus();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnInitDialog
|
||||
================
|
||||
*/
|
||||
BOOL DialogDeclEditor::OnInitDialog() {
|
||||
|
||||
com_editors |= EDITOR_DECL;
|
||||
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
// load accelerator table
|
||||
m_hAccel = ::LoadAccelerators( AfxGetResourceHandle(), MAKEINTRESOURCE( IDR_ACCELERATOR_DECLEDITOR ) );
|
||||
|
||||
// create status bar
|
||||
statusBar.CreateEx( SBARS_SIZEGRIP, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM, initialRect, this, AFX_IDW_STATUS_BAR );
|
||||
|
||||
declEdit.Init();
|
||||
|
||||
GetClientRect( initialRect );
|
||||
|
||||
EnableToolTips( TRUE );
|
||||
|
||||
testButton.EnableWindow( FALSE );
|
||||
okButton.EnableWindow( FALSE );
|
||||
|
||||
UpdateStatusBar();
|
||||
|
||||
return FALSE; // return TRUE unless you set the focus to a control
|
||||
// EXCEPTION: OCX Property Pages should return FALSE
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(DialogDeclEditor, CDialog)
|
||||
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
|
||||
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
|
||||
ON_WM_DESTROY()
|
||||
ON_WM_ACTIVATE()
|
||||
ON_WM_MOVE()
|
||||
ON_WM_SIZE()
|
||||
ON_WM_SIZING()
|
||||
ON_WM_SETFOCUS()
|
||||
ON_COMMAND(ID_EDIT_FIND, OnEditFind)
|
||||
ON_COMMAND(ID_EDIT_REPLACE, OnEditReplace)
|
||||
ON_COMMAND(ID_DECLEDITOR_FIND_NEXT, OnEditFindNext)
|
||||
ON_COMMAND(ID_DECLEDITOR_GOTOLINE, OnEditGoToLine)
|
||||
ON_REGISTERED_MESSAGE(FindDialogMessage, OnFindDialogMessage)
|
||||
ON_NOTIFY(EN_CHANGE, IDC_DECLEDITOR_EDIT_TEXT, OnEnChangeEdit)
|
||||
ON_NOTIFY(EN_MSGFILTER, IDC_DECLEDITOR_EDIT_TEXT, OnEnInputEdit)
|
||||
ON_BN_CLICKED(IDC_DECLEDITOR_BUTTON_TEST, OnBnClickedTest)
|
||||
ON_BN_CLICKED(IDOK, OnBnClickedOk)
|
||||
ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
// DialogDeclEditor message handlers
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnActivate
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::OnActivate( UINT nState, CWnd *pWndOther, BOOL bMinimized ) {
|
||||
CDialog::OnActivate( nState, pWndOther, bMinimized );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnToolTipNotify
|
||||
================
|
||||
*/
|
||||
BOOL DialogDeclEditor::OnToolTipNotify( UINT id, NMHDR *pNMHDR, LRESULT *pResult ) {
|
||||
return DefaultOnToolTipNotify( toolTips, id, pNMHDR, pResult );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnSetFocus
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::OnSetFocus( CWnd *pOldWnd ) {
|
||||
CDialog::OnSetFocus( pOldWnd );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnDestroy
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::OnDestroy() {
|
||||
return CDialog::OnDestroy();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnMove
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::OnMove( int x, int y ) {
|
||||
if ( GetSafeHwnd() ) {
|
||||
CRect rct;
|
||||
GetWindowRect( rct );
|
||||
// FIXME: save position
|
||||
}
|
||||
CDialog::OnMove( x, y );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnSize
|
||||
================
|
||||
*/
|
||||
#define BORDER_SIZE 0
|
||||
#define BUTTON_SPACE 4
|
||||
#define TOOLBAR_HEIGHT 24
|
||||
|
||||
void DialogDeclEditor::OnSize( UINT nType, int cx, int cy ) {
|
||||
CRect clientRect, rect;
|
||||
|
||||
LockWindowUpdate();
|
||||
|
||||
CDialog::OnSize( nType, cx, cy );
|
||||
|
||||
GetClientRect( clientRect );
|
||||
|
||||
if ( declEdit.GetSafeHwnd() ) {
|
||||
rect.left = BORDER_SIZE;
|
||||
rect.top = BORDER_SIZE;
|
||||
rect.right = clientRect.Width() - BORDER_SIZE;
|
||||
rect.bottom = clientRect.Height() - 56;
|
||||
declEdit.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( testButton.GetSafeHwnd() ) {
|
||||
testButton.GetClientRect( rect );
|
||||
int width = rect.Width();
|
||||
int height = rect.Height();
|
||||
rect.left = BORDER_SIZE;
|
||||
rect.top = clientRect.Height() - TOOLBAR_HEIGHT - height;
|
||||
rect.right = BORDER_SIZE + width;
|
||||
rect.bottom = clientRect.Height() - TOOLBAR_HEIGHT;
|
||||
testButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( okButton.GetSafeHwnd() ) {
|
||||
okButton.GetClientRect( rect );
|
||||
int width = rect.Width();
|
||||
int height = rect.Height();
|
||||
rect.left = clientRect.Width() - BORDER_SIZE - BUTTON_SPACE - 2 * width;
|
||||
rect.top = clientRect.Height() - TOOLBAR_HEIGHT - height;
|
||||
rect.right = clientRect.Width() - BORDER_SIZE - BUTTON_SPACE - width;
|
||||
rect.bottom = clientRect.Height() - TOOLBAR_HEIGHT;
|
||||
okButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( cancelButton.GetSafeHwnd() ) {
|
||||
cancelButton.GetClientRect( rect );
|
||||
int width = rect.Width();
|
||||
int height = rect.Height();
|
||||
rect.left = clientRect.Width() - BORDER_SIZE - width;
|
||||
rect.top = clientRect.Height() - TOOLBAR_HEIGHT - height;
|
||||
rect.right = clientRect.Width() - BORDER_SIZE;
|
||||
rect.bottom = clientRect.Height() - TOOLBAR_HEIGHT;
|
||||
cancelButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( statusBar.GetSafeHwnd() ) {
|
||||
rect.left = clientRect.Width() - 2;
|
||||
rect.top = clientRect.Height() - 2;
|
||||
rect.right = clientRect.Width() - 2;
|
||||
rect.bottom = clientRect.Height() - 2;
|
||||
statusBar.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
UnlockWindowUpdate();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnSizing
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::OnSizing( UINT nSide, LPRECT lpRect ) {
|
||||
/*
|
||||
1 = left
|
||||
2 = right
|
||||
3 = top
|
||||
4 = left - top
|
||||
5 = right - top
|
||||
6 = bottom
|
||||
7 = left - bottom
|
||||
8 = right - bottom
|
||||
*/
|
||||
|
||||
CDialog::OnSizing( nSide, lpRect );
|
||||
|
||||
if ( ( nSide - 1 ) % 3 == 0 ) {
|
||||
if ( lpRect->right - lpRect->left < initialRect.Width() ) {
|
||||
lpRect->left = lpRect->right - initialRect.Width();
|
||||
}
|
||||
} else if ( ( nSide - 2 ) % 3 == 0 ) {
|
||||
if ( lpRect->right - lpRect->left < initialRect.Width() ) {
|
||||
lpRect->right = lpRect->left + initialRect.Width();
|
||||
}
|
||||
}
|
||||
if ( nSide >= 3 && nSide <= 5 ) {
|
||||
if ( lpRect->bottom - lpRect->top < initialRect.Height() ) {
|
||||
lpRect->top = lpRect->bottom - initialRect.Height();
|
||||
}
|
||||
} else if ( nSide >= 6 && nSide <= 9 ) {
|
||||
if ( lpRect->bottom - lpRect->top < initialRect.Height() ) {
|
||||
lpRect->bottom = lpRect->top + initialRect.Height();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnEditGoToLine
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::OnEditGoToLine() {
|
||||
DialogGoToLine goToLineDlg;
|
||||
|
||||
goToLineDlg.SetRange( firstLine, firstLine + declEdit.GetLineCount() - 1 );
|
||||
if ( goToLineDlg.DoModal() != IDOK ) {
|
||||
return;
|
||||
}
|
||||
declEdit.GoToLine( goToLineDlg.GetLine() - firstLine );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnEditFind
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::OnEditFind() {
|
||||
|
||||
CString selText = declEdit.GetSelText();
|
||||
if ( selText.GetLength() ) {
|
||||
findStr = selText;
|
||||
}
|
||||
|
||||
if ( !findDlg ) {
|
||||
// create find/replace dialog
|
||||
findDlg = new CFindReplaceDialog(); // Must be created on the heap
|
||||
findDlg->Create( TRUE, findStr, "", FR_DOWN, this );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnEditFindNext
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::OnEditFindNext() {
|
||||
if ( declEdit.FindNext( findStr, matchCase, matchWholeWords, searchForward ) ) {
|
||||
declEdit.SetFocus();
|
||||
} else {
|
||||
AfxMessageBox( "The specified text was not found.", MB_OK | MB_ICONINFORMATION, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnEditReplace
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::OnEditReplace() {
|
||||
|
||||
CString selText = declEdit.GetSelText();
|
||||
if ( selText.GetLength() ) {
|
||||
findStr = selText;
|
||||
}
|
||||
|
||||
// create find/replace dialog
|
||||
if ( !findDlg ) {
|
||||
findDlg = new CFindReplaceDialog(); // Must be created on the heap
|
||||
findDlg->Create( FALSE, findStr, "", FR_DOWN, this );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnFindDialogMessage
|
||||
================
|
||||
*/
|
||||
LRESULT DialogDeclEditor::OnFindDialogMessage( WPARAM wParam, LPARAM lParam ) {
|
||||
if ( findDlg == NULL ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( findDlg->IsTerminating() ) {
|
||||
findDlg = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( findDlg->FindNext() ) {
|
||||
findStr = findDlg->GetFindString();
|
||||
matchCase = findDlg->MatchCase() != FALSE;
|
||||
matchWholeWords = findDlg->MatchWholeWord() != FALSE;
|
||||
searchForward = findDlg->SearchDown() != FALSE;
|
||||
|
||||
OnEditFindNext();
|
||||
}
|
||||
|
||||
if ( findDlg->ReplaceCurrent() ) {
|
||||
long selStart, selEnd;
|
||||
|
||||
replaceStr = findDlg->GetReplaceString();
|
||||
|
||||
declEdit.GetSel( selStart, selEnd );
|
||||
if ( selEnd > selStart ) {
|
||||
declEdit.ReplaceSel( replaceStr, TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
if ( findDlg->ReplaceAll() ) {
|
||||
replaceStr = findDlg->GetReplaceString();
|
||||
findStr = findDlg->GetFindString();
|
||||
matchCase = findDlg->MatchCase() != FALSE;
|
||||
matchWholeWords = findDlg->MatchWholeWord() != FALSE;
|
||||
|
||||
int numReplaces = declEdit.ReplaceAll( findStr, replaceStr, matchCase, matchWholeWords );
|
||||
if ( numReplaces == 0 ) {
|
||||
AfxMessageBox( "The specified text was not found.", MB_OK | MB_ICONINFORMATION, 0 );
|
||||
} else {
|
||||
AfxMessageBox( va( "Replaced %d occurances.", numReplaces ), MB_OK | MB_ICONINFORMATION, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnEnChangeEdit
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::OnEnChangeEdit( NMHDR *pNMHDR, LRESULT *pResult ) {
|
||||
testButton.EnableWindow( TRUE );
|
||||
okButton.EnableWindow( TRUE );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnEnInputEdit
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::OnEnInputEdit( NMHDR *pNMHDR, LRESULT *pResult ) {
|
||||
MSGFILTER *msgFilter = (MSGFILTER *)pNMHDR;
|
||||
|
||||
if ( msgFilter->msg != 512 && msgFilter->msg != 33 ) {
|
||||
UpdateStatusBar();
|
||||
}
|
||||
|
||||
*pResult = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnBnClickedTest
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::OnBnClickedTest() {
|
||||
idStr declText;
|
||||
|
||||
if ( decl ) {
|
||||
|
||||
declEdit.GetText( declText );
|
||||
|
||||
// clean up new-line crapola
|
||||
declText.Replace( "\n", "" );
|
||||
declText.Replace( "\r", "\r\n" );
|
||||
declText.Replace( "\v", "\r\n" );
|
||||
declText.StripLeading( "\r\n" );
|
||||
declText.Insert( "\r\n\r\n", 0 );
|
||||
declText.StripTrailing( "\r\n" );
|
||||
|
||||
if ( !TestDecl( declText ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
char *oldDeclText = (char *)_alloca( ( decl->GetTextLength() + 1 ) * sizeof( char ) );
|
||||
decl->GetText( oldDeclText );
|
||||
decl->SetText( declText );
|
||||
decl->Invalidate();
|
||||
declManager->DeclByIndex( decl->GetType(), decl->Index(), true );
|
||||
decl->SetText( oldDeclText );
|
||||
decl->Invalidate();
|
||||
common->Printf( "tested %s\n", decl->GetName() );
|
||||
|
||||
testButton.EnableWindow( FALSE );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnBnClickedOk
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::OnBnClickedOk() {
|
||||
idStr declText;
|
||||
|
||||
if ( decl ) {
|
||||
|
||||
declEdit.GetText( declText );
|
||||
|
||||
// clean up new-line crapola
|
||||
declText.Replace( "\n", "" );
|
||||
declText.Replace( "\r", "\r\n" );
|
||||
declText.Replace( "\v", "\r\n" );
|
||||
declText.StripLeading( "\r\n" );
|
||||
declText.Insert( "\r\n\r\n", 0 );
|
||||
declText.StripTrailing( "\r\n" );
|
||||
|
||||
if ( !TestDecl( declText ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( decl->SourceFileChanged() ) {
|
||||
if ( MessageBox( va( "Declaration file %s has been modified outside of the editor.\r\nReload declarations and save?", decl->GetFileName() ),
|
||||
va( "Warning saving: %s", decl->GetFileName() ), MB_OKCANCEL | MB_ICONERROR ) != IDOK ) {
|
||||
return;
|
||||
}
|
||||
declManager->Reload( false );
|
||||
DeclBrowserReloadDeclarations();
|
||||
}
|
||||
|
||||
decl->SetText( declText );
|
||||
if ( !decl->ReplaceSourceFileText() ) {
|
||||
MessageBox( va( "Couldn't save: %s.\r\nMake sure the declaration file is not read-only.", decl->GetFileName() ),
|
||||
va( "Error saving: %s", decl->GetFileName() ), MB_OK | MB_ICONERROR );
|
||||
return;
|
||||
}
|
||||
decl->Invalidate();
|
||||
}
|
||||
|
||||
okButton.EnableWindow( FALSE );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclEditor::OnBnClickedCancel
|
||||
================
|
||||
*/
|
||||
void DialogDeclEditor::OnBnClickedCancel() {
|
||||
if ( okButton.IsWindowEnabled() ) {
|
||||
if ( MessageBox( "Cancel changes?", "Cancel", MB_YESNO | MB_ICONQUESTION ) != IDYES ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
OnCancel();
|
||||
}
|
||||
106
neo/tools/decl/DialogDeclEditor.h
Normal file
106
neo/tools/decl/DialogDeclEditor.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 GPL Source Code
|
||||
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
|
||||
|
||||
Doom 3 Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#ifndef __DIALOGDECLEDITOR_H__
|
||||
#define __DIALOGDECLEDITOR_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../comafx/CSyntaxRichEditCtrl.h"
|
||||
|
||||
// DialogDeclEditor dialog
|
||||
|
||||
class DialogDeclEditor : public CDialog {
|
||||
|
||||
DECLARE_DYNAMIC(DialogDeclEditor)
|
||||
|
||||
public:
|
||||
DialogDeclEditor( CWnd* pParent = NULL ); // standard constructor
|
||||
virtual ~DialogDeclEditor();
|
||||
|
||||
void LoadDecl( idDecl *decl );
|
||||
|
||||
//{{AFX_VIRTUAL(DialogDeclEditor)
|
||||
virtual BOOL OnInitDialog();
|
||||
virtual void DoDataExchange( CDataExchange* pDX ); // DDX/DDV support
|
||||
virtual BOOL PreTranslateMessage( MSG* pMsg );
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
protected:
|
||||
//{{AFX_MSG(DialogDeclEditor)
|
||||
afx_msg BOOL OnToolTipNotify( UINT id, NMHDR *pNMHDR, LRESULT *pResult );
|
||||
afx_msg void OnSetFocus( CWnd *pOldWnd );
|
||||
afx_msg void OnDestroy();
|
||||
afx_msg void OnActivate( UINT nState, CWnd* pWndOther, BOOL bMinimized );
|
||||
afx_msg void OnMove( int x, int y );
|
||||
afx_msg void OnSize( UINT nType, int cx, int cy );
|
||||
afx_msg void OnSizing( UINT nSide, LPRECT lpRect );
|
||||
afx_msg void OnEditGoToLine();
|
||||
afx_msg void OnEditFind();
|
||||
afx_msg void OnEditFindNext();
|
||||
afx_msg void OnEditReplace();
|
||||
afx_msg LRESULT OnFindDialogMessage( WPARAM wParam, LPARAM lParam );
|
||||
afx_msg void OnEnChangeEdit( NMHDR *pNMHDR, LRESULT *pResult );
|
||||
afx_msg void OnEnInputEdit( NMHDR *pNMHDR, LRESULT *pResult );
|
||||
afx_msg void OnBnClickedTest();
|
||||
afx_msg void OnBnClickedOk();
|
||||
afx_msg void OnBnClickedCancel();
|
||||
//}}AFX_MSG
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
|
||||
private:
|
||||
|
||||
//{{AFX_DATA(DialogDeclEditor)
|
||||
enum { IDD = IDD_DIALOG_DECLEDITOR };
|
||||
CStatusBarCtrl statusBar;
|
||||
CSyntaxRichEditCtrl declEdit;
|
||||
CButton testButton;
|
||||
CButton okButton;
|
||||
CButton cancelButton;
|
||||
//}}AFX_DATA
|
||||
|
||||
static toolTip_t toolTips[];
|
||||
|
||||
HACCEL m_hAccel;
|
||||
CRect initialRect;
|
||||
CFindReplaceDialog *findDlg;
|
||||
CString findStr;
|
||||
CString replaceStr;
|
||||
bool matchCase;
|
||||
bool matchWholeWords;
|
||||
bool searchForward;
|
||||
idDecl * decl;
|
||||
int firstLine;
|
||||
|
||||
private:
|
||||
bool TestDecl( const idStr &declText );
|
||||
void UpdateStatusBar( void );
|
||||
};
|
||||
|
||||
#endif /* !__DIALOGDECLEDITOR_H__ */
|
||||
279
neo/tools/decl/DialogDeclNew.cpp
Normal file
279
neo/tools/decl/DialogDeclNew.cpp
Normal file
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 GPL Source Code
|
||||
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
|
||||
|
||||
Doom 3 Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#include "../../idlib/precompiled.h"
|
||||
#pragma hdrstop
|
||||
|
||||
#include "../../sys/win32/rc/DeclEditor_resource.h"
|
||||
|
||||
#include "../comafx/CPathTreeCtrl.h"
|
||||
#include "DialogDeclBrowser.h"
|
||||
#include "DialogDeclNew.h"
|
||||
|
||||
#ifdef ID_DEBUG_MEMORY
|
||||
#undef new
|
||||
#undef DEBUG_NEW
|
||||
#define DEBUG_NEW new
|
||||
#endif
|
||||
|
||||
|
||||
toolTip_t DialogDeclNew::toolTips[] = {
|
||||
{ IDC_DECLNEW_COMBO_NEW_TYPE, "select the declaration type to create" },
|
||||
{ IDC_DECLNEW_EDIT_NEW_NAME, "enter a name for the new declaration" },
|
||||
{ IDC_DECLNEW_EDIT_NEW_FILE, "enter the name of the file to add the declaration to" },
|
||||
{ IDC_DECLNEW_BUTTON_NEW_FILE, "select existing file to add the declaration to" },
|
||||
{ IDOK, "create new declaration" },
|
||||
{ IDCANCEL, "cancel" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
|
||||
IMPLEMENT_DYNAMIC(DialogDeclNew, CDialog)
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclNew::DialogDeclNew
|
||||
================
|
||||
*/
|
||||
DialogDeclNew::DialogDeclNew( CWnd* pParent /*=NULL*/ )
|
||||
: CDialog(DialogDeclNew::IDD, pParent)
|
||||
, declTree(NULL)
|
||||
, newDecl(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclNew::~DialogDeclNew
|
||||
================
|
||||
*/
|
||||
DialogDeclNew::~DialogDeclNew() {
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclNew::DoDataExchange
|
||||
================
|
||||
*/
|
||||
void DialogDeclNew::DoDataExchange(CDataExchange* pDX) {
|
||||
CDialog::DoDataExchange(pDX);
|
||||
//{{AFX_DATA_MAP(DialogDeclNew)
|
||||
DDX_Control(pDX, IDC_DECLNEW_COMBO_NEW_TYPE, typeList);
|
||||
DDX_Control(pDX, IDC_DECLNEW_EDIT_NEW_NAME, nameEdit);
|
||||
DDX_Control(pDX, IDC_DECLNEW_EDIT_NEW_FILE, fileEdit);
|
||||
DDX_Control(pDX, IDC_DECLNEW_BUTTON_NEW_FILE, fileButton);
|
||||
DDX_Control(pDX, IDOK, okButton);
|
||||
DDX_Control(pDX, IDCANCEL, cancelButton);
|
||||
//}}AFX_DATA_MAP
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclNew::InitTypeList
|
||||
================
|
||||
*/
|
||||
void DialogDeclNew::InitTypeList( void ) {
|
||||
int i;
|
||||
|
||||
typeList.ResetContent();
|
||||
for ( i = 0; i < declManager->GetNumDeclTypes(); i++ ) {
|
||||
typeList.AddString( declManager->GetDeclNameFromType( (declType_t)i ) );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclNew::OnInitDialog
|
||||
================
|
||||
*/
|
||||
BOOL DialogDeclNew::OnInitDialog() {
|
||||
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
InitTypeList();
|
||||
|
||||
SetSafeComboBoxSelection( &typeList, defaultType.c_str(), -1 );
|
||||
nameEdit.SetWindowText( defaultName.c_str() );
|
||||
fileEdit.SetWindowText( defaultFile.c_str() );
|
||||
|
||||
EnableToolTips( TRUE );
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// EXCEPTION: OCX Property Pages should return FALSE
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(DialogDeclNew, CDialog)
|
||||
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
|
||||
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
|
||||
ON_WM_DESTROY()
|
||||
ON_WM_ACTIVATE()
|
||||
ON_WM_SETFOCUS()
|
||||
ON_BN_CLICKED(IDC_DECLNEW_BUTTON_NEW_FILE, OnBnClickedFile)
|
||||
ON_BN_CLICKED(IDOK, OnBnClickedOk)
|
||||
ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
// DialogDeclNew message handlers
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclNew::OnActivate
|
||||
================
|
||||
*/
|
||||
void DialogDeclNew::OnActivate( UINT nState, CWnd *pWndOther, BOOL bMinimized ) {
|
||||
CDialog::OnActivate( nState, pWndOther, bMinimized );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclNew::OnToolTipNotify
|
||||
================
|
||||
*/
|
||||
BOOL DialogDeclNew::OnToolTipNotify( UINT id, NMHDR *pNMHDR, LRESULT *pResult ) {
|
||||
return DefaultOnToolTipNotify( toolTips, id, pNMHDR, pResult );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclNew::OnSetFocus
|
||||
================
|
||||
*/
|
||||
void DialogDeclNew::OnSetFocus( CWnd *pOldWnd ) {
|
||||
CDialog::OnSetFocus( pOldWnd );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclNew::OnDestroy
|
||||
================
|
||||
*/
|
||||
void DialogDeclNew::OnDestroy() {
|
||||
return CDialog::OnDestroy();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclNew::OnBnClickedFile
|
||||
================
|
||||
*/
|
||||
void DialogDeclNew::OnBnClickedFile() {
|
||||
CString typeName, folder, ext;
|
||||
idStr path;
|
||||
const char *errorTitle = "Error selecting file.";
|
||||
|
||||
if ( GetSafeComboBoxSelection( &typeList, typeName, -1 ) == -1 ) {
|
||||
MessageBox( "Select a declaration type first.", errorTitle, MB_OK );
|
||||
return;
|
||||
}
|
||||
|
||||
declType_t type = declManager->GetDeclTypeFromName( typeName );
|
||||
if ( type >= declManager->GetNumDeclTypes() ) {
|
||||
MessageBox( "Unknown declaration type.", errorTitle, MB_OK | MB_ICONERROR );
|
||||
return;
|
||||
}
|
||||
|
||||
switch( type ) {
|
||||
case DECL_TABLE: folder = "materials"; ext = "(*.mtr)|*.mtr|(*.*)|*.*||"; break;
|
||||
case DECL_MATERIAL: folder = "materials"; ext = "(*.mtr)|*.mtr|(*.*)|*.*||"; break;
|
||||
case DECL_SKIN: folder = "skins"; ext = "(*.skin)|*.skin|(*.*)|*.*||"; break;
|
||||
case DECL_SOUND: folder = "sound"; ext = "(*.sndshd|*.sndshd|(*.*)|*.*||"; break;
|
||||
case DECL_ENTITYDEF: folder = "def"; ext = "(*.def)|*.def|(*.decl)|*.decl|(*.*)|*.*||"; break;
|
||||
case DECL_MODELDEF: folder = "def"; ext = "(*.def)|*.def|(*.*)|*.*||"; break;
|
||||
case DECL_FX: folder = "fx"; ext = "(*.fx)|*.fx|(*.*)|*.*||"; break;
|
||||
case DECL_PARTICLE: folder = "particles"; ext = "(*.prt)|*.prt|(*.*)|*.*||"; break;
|
||||
case DECL_AF: folder = "af"; ext = "(*.af)|*.af|(*.*)|*.*||"; break;
|
||||
default: folder = "def"; ext = "(*.decl)|*.decl|(*.*)|*.*||"; break;
|
||||
}
|
||||
|
||||
path = fileSystem->RelativePathToOSPath( folder );
|
||||
path += "\\*";
|
||||
|
||||
CFileDialog dlgFile( TRUE, "decl", path, 0, ext, this );
|
||||
if ( dlgFile.DoModal() == IDOK ) {
|
||||
path = fileSystem->OSPathToRelativePath( dlgFile.m_ofn.lpstrFile );
|
||||
fileEdit.SetWindowText( path );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclNew::OnBnClickedOk
|
||||
================
|
||||
*/
|
||||
void DialogDeclNew::OnBnClickedOk() {
|
||||
CString typeName, declName, fileName;
|
||||
const char *errorTitle = "Error creating declaration.";
|
||||
|
||||
if ( !declTree ) {
|
||||
MessageBox( "No declaration tree available.", errorTitle, MB_OK | MB_ICONERROR );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( GetSafeComboBoxSelection( &typeList, typeName, -1 ) == -1 ) {
|
||||
MessageBox( "No declaration type selected.", errorTitle, MB_OK | MB_ICONERROR );
|
||||
return;
|
||||
}
|
||||
|
||||
nameEdit.GetWindowText( declName );
|
||||
if ( declName.GetLength() == 0 ) {
|
||||
MessageBox( "No declaration name specified.", errorTitle, MB_OK | MB_ICONERROR );
|
||||
return;
|
||||
}
|
||||
|
||||
fileEdit.GetWindowText( fileName );
|
||||
if ( fileName.GetLength() == 0 ) {
|
||||
MessageBox( "No file name specified.", errorTitle, MB_OK | MB_ICONERROR );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( declTree->FindItem( idStr( typeName + "/" + declName ) ) ) {
|
||||
MessageBox( "Declaration already exists.", errorTitle, MB_OK | MB_ICONERROR );
|
||||
return;
|
||||
}
|
||||
|
||||
declType_t type = declManager->GetDeclTypeFromName( typeName );
|
||||
if ( type >= declManager->GetNumDeclTypes() ) {
|
||||
MessageBox( "Unknown declaration type.", errorTitle, MB_OK | MB_ICONERROR );
|
||||
return;
|
||||
}
|
||||
|
||||
newDecl = declManager->CreateNewDecl( type, declName, fileName );
|
||||
|
||||
OnOK();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogDeclNew::OnBnClickedCancel
|
||||
================
|
||||
*/
|
||||
void DialogDeclNew::OnBnClickedCancel() {
|
||||
OnCancel();
|
||||
}
|
||||
93
neo/tools/decl/DialogDeclNew.h
Normal file
93
neo/tools/decl/DialogDeclNew.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 GPL Source Code
|
||||
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
|
||||
|
||||
Doom 3 Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#ifndef __DIALOGDECLNEW_H__
|
||||
#define __DIALOGDECLNEW_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
// DialogDeclNew dialog
|
||||
|
||||
class DialogDeclNew : public CDialog {
|
||||
|
||||
DECLARE_DYNAMIC(DialogDeclNew)
|
||||
|
||||
public:
|
||||
DialogDeclNew( CWnd* pParent = NULL ); // standard constructor
|
||||
virtual ~DialogDeclNew();
|
||||
|
||||
void SetDeclTree( CPathTreeCtrl *tree ) { declTree = tree; }
|
||||
void SetDefaultType( const char *type ) { defaultType = type; }
|
||||
void SetDefaultName( const char *name ) { defaultName = name; }
|
||||
void SetDefaultFile( const char *file ) { defaultFile = file; }
|
||||
idDecl * GetNewDecl( void ) const { return newDecl; }
|
||||
|
||||
//{{AFX_VIRTUAL(DialogDeclNew)
|
||||
virtual BOOL OnInitDialog();
|
||||
virtual void DoDataExchange( CDataExchange* pDX ); // DDX/DDV support
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
protected:
|
||||
//{{AFX_MSG(DialogDeclNew)
|
||||
afx_msg BOOL OnToolTipNotify( UINT id, NMHDR *pNMHDR, LRESULT *pResult );
|
||||
afx_msg void OnSetFocus( CWnd *pOldWnd );
|
||||
afx_msg void OnDestroy();
|
||||
afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
|
||||
afx_msg void OnBnClickedFile();
|
||||
afx_msg void OnBnClickedOk();
|
||||
afx_msg void OnBnClickedCancel();
|
||||
//}}AFX_MSG
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
|
||||
private:
|
||||
|
||||
//{{AFX_DATA(DialogDeclNew)
|
||||
enum { IDD = IDD_DIALOG_DECLNEW };
|
||||
CComboBox typeList;
|
||||
CEdit nameEdit;
|
||||
CEdit fileEdit;
|
||||
CButton fileButton;
|
||||
CButton okButton;
|
||||
CButton cancelButton;
|
||||
//}}AFX_DATA
|
||||
|
||||
static toolTip_t toolTips[];
|
||||
|
||||
CPathTreeCtrl * declTree;
|
||||
idStr defaultType;
|
||||
idStr defaultName;
|
||||
idStr defaultFile;
|
||||
idDecl * newDecl;
|
||||
|
||||
private:
|
||||
void InitTypeList( void );
|
||||
};
|
||||
|
||||
#endif /* !__DIALOGDECLNEW_H__ */
|
||||
860
neo/tools/decl/DialogEntityDefEditor.cpp
Normal file
860
neo/tools/decl/DialogEntityDefEditor.cpp
Normal file
@@ -0,0 +1,860 @@
|
||||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 GPL Source Code
|
||||
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
|
||||
|
||||
Doom 3 Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#include "../../idlib/precompiled.h"
|
||||
#pragma hdrstop
|
||||
|
||||
#include "../../sys/win32/rc/Common_resource.h"
|
||||
#include "../../sys/win32/rc/DeclEditor_resource.h"
|
||||
|
||||
#include "../comafx/CPathTreeCtrl.h"
|
||||
#include "DialogDeclBrowser.h"
|
||||
#include "DialogDeclEditor.h"
|
||||
#include "DialogEntityDefEditor.h"
|
||||
|
||||
#ifdef ID_DEBUG_MEMORY
|
||||
#undef new
|
||||
#undef DEBUG_NEW
|
||||
#define DEBUG_NEW new
|
||||
#endif
|
||||
|
||||
|
||||
// DialogEntityDefEditor dialog
|
||||
|
||||
toolTip_t DialogEntityDefEditor::toolTips[] = {
|
||||
{ IDC_DECLEDITOR_BUTTON_TEST, "Test Decl" },
|
||||
{ IDOK, "Save Decl" },
|
||||
{ IDCANCEL, "Cancel" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
|
||||
IMPLEMENT_DYNAMIC(DialogEntityDefEditor, CDialog)
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::DialogEntityDefEditor
|
||||
================
|
||||
*/
|
||||
DialogEntityDefEditor::DialogEntityDefEditor( CWnd* pParent /*=NULL*/ )
|
||||
: CDialog(DialogEntityDefEditor::IDD, pParent)
|
||||
, decl(NULL)
|
||||
, firstLine(0)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::~DialogEntityDefEditor
|
||||
================
|
||||
*/
|
||||
DialogEntityDefEditor::~DialogEntityDefEditor() {
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::DoDataExchange
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::DoDataExchange(CDataExchange* pDX) {
|
||||
CDialog::DoDataExchange(pDX);
|
||||
//{{AFX_DATA_MAP(DialogEntityDefEditor)
|
||||
DDX_Control(pDX, IDC_ENTITYDEFEDITOR_EDIT_DECLNAME, declNameEdit);
|
||||
DDX_Control(pDX, IDC_ENTITYDEFEDITOR_COMBO_INHERIT, inheritCombo);
|
||||
DDX_Control(pDX, IDC_ENTITYDEFEDITOR_COMBO_SPAWNCLASS, spawnclassCombo);
|
||||
|
||||
DDX_Control(pDX, IDC_ENTITYDEFEDITOR_LIST_KEYVALS, keyValsList);
|
||||
|
||||
DDX_Control(pDX, IDC_ENTITYDEFEDITOR_STATIC_KEY, keyLabel);
|
||||
DDX_Control(pDX, IDC_ENTITYDEFEDITOR_EDIT_KEY, keyEdit);
|
||||
DDX_Control(pDX, IDC_ENTITYDEFEDITOR_BUTTON_ADD, addButton);
|
||||
DDX_Control(pDX, IDC_ENTITYDEFEDITOR_BUTTON_DELETE, delButton);
|
||||
DDX_Control(pDX, IDC_ENTITYDEFEDITOR_LINE, line);
|
||||
|
||||
DDX_Control(pDX, IDC_DECLEDITOR_BUTTON_TEST, testButton);
|
||||
DDX_Control(pDX, IDOK, okButton);
|
||||
DDX_Control(pDX, IDCANCEL, cancelButton);
|
||||
//}}AFX_DATA_MAP
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::PreTranslateMessage
|
||||
================
|
||||
*/
|
||||
BOOL DialogEntityDefEditor::PreTranslateMessage( MSG* pMsg ) {
|
||||
if ( WM_KEYFIRST <= pMsg->message && pMsg->message <= WM_KEYLAST ) {
|
||||
if ( m_hAccel && ::TranslateAccelerator( m_hWnd, m_hAccel, pMsg ) ) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return CWnd::PreTranslateMessage(pMsg);
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::TestDecl
|
||||
================
|
||||
*/
|
||||
bool DialogEntityDefEditor::TestDecl( const idStr &declText ) {
|
||||
idLexer src( LEXFL_NOSTRINGCONCAT );
|
||||
idToken token;
|
||||
int indent;
|
||||
|
||||
src.LoadMemory( declText, declText.Length(), "decl text" );
|
||||
|
||||
indent = 0;
|
||||
while( src.ReadToken( &token ) ) {
|
||||
if ( token == "{" ) {
|
||||
indent++;
|
||||
} else if ( token == "}" ) {
|
||||
indent--;
|
||||
}
|
||||
}
|
||||
|
||||
if ( indent < 0 ) {
|
||||
MessageBox( "Missing opening brace!", va( "Error saving %s", decl->GetFileName() ), MB_OK | MB_ICONERROR );
|
||||
return false;
|
||||
}
|
||||
if ( indent > 0 ) {
|
||||
MessageBox( "Missing closing brace!", va( "Error saving %s", decl->GetFileName() ), MB_OK | MB_ICONERROR );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::UpdateStatusBar
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::UpdateStatusBar( void ) {
|
||||
if ( decl ) {
|
||||
statusBar.SetWindowText( "Editing decl" );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::LoadDecl
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::LoadDecl( idDeclEntityDef *decl ) {
|
||||
int numLines = 0;
|
||||
CRect rect;
|
||||
|
||||
this->decl = decl;
|
||||
|
||||
// Fill up the spawnclass box with all spawn classes
|
||||
/*
|
||||
idTypeInfo *c = idClass::GetClass("idClass");
|
||||
for (; c; c = c->next) {
|
||||
spawnclassCombo.AddString(c->classname);
|
||||
}
|
||||
*/
|
||||
|
||||
// Fill up the inherit box with all entitydefs
|
||||
int numDecls = declManager->GetNumDecls(DECL_ENTITYDEF);
|
||||
for (int i=0; i<numDecls; i++) {
|
||||
const idDecl *d = declManager->DeclByIndex(DECL_ENTITYDEF, i, false);
|
||||
if (d) {
|
||||
inheritCombo.AddString(d->GetName());
|
||||
}
|
||||
}
|
||||
|
||||
firstLine = decl->GetLineNum();
|
||||
|
||||
char *declText = (char *)_alloca( ( decl->GetTextLength() + 1 ) * sizeof( char ) );
|
||||
decl->GetText( declText );
|
||||
|
||||
PopulateLists( declText );
|
||||
|
||||
SetWindowText( va( "EntityDef Editor (%s, line %d)", decl->GetFileName(), decl->GetLineNum() ) );
|
||||
|
||||
// Hack to get it to reflow the window
|
||||
GetWindowRect( rect );
|
||||
rect.bottom++;
|
||||
MoveWindow( rect );
|
||||
|
||||
testButton.EnableWindow( FALSE );
|
||||
okButton.EnableWindow( FALSE );
|
||||
|
||||
UpdateStatusBar();
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
DialogEntityDefEditor::PopulateLists
|
||||
=================
|
||||
*/
|
||||
void DialogEntityDefEditor::PopulateLists( const char *declText, const int textLength )
|
||||
{
|
||||
idLexer src;
|
||||
idToken token, token2;
|
||||
|
||||
idDict dict;
|
||||
|
||||
src.LoadMemory( declText, textLength, decl->GetFileName(), firstLine);
|
||||
src.SetFlags( DECL_LEXER_FLAGS );
|
||||
src.SkipUntilString( "{" );
|
||||
|
||||
while (1) {
|
||||
if ( !src.ReadToken( &token ) ) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ( !token.Icmp( "}" ) ) {
|
||||
break;
|
||||
}
|
||||
if ( token.type != TT_STRING ) {
|
||||
src.Warning( "Expected quoted string, but found '%s'", token.c_str() );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( !src.ReadToken( &token2 ) ) {
|
||||
src.Warning( "Unexpected end of file" );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( dict.FindKey( token ) ) {
|
||||
src.Warning( "'%s' already defined", token.c_str() );
|
||||
}
|
||||
dict.Set( token, token2 );
|
||||
}
|
||||
|
||||
// Get the parent, and remove the 'inherit' key so it doesn't show up in the list
|
||||
// We currently don't support multiple inheritence properly, but nothing uses it anyway
|
||||
idStr inherit;
|
||||
const idKeyValue *inheritKeyVal = dict.FindKey("inherit");
|
||||
if (inheritKeyVal) {
|
||||
inherit = inheritKeyVal->GetValue();
|
||||
dict.Delete(inheritKeyVal->GetKey());
|
||||
}
|
||||
|
||||
idStr spawnclass = dict.GetString("spawnclass", "");
|
||||
dict.Delete("spawnclass");
|
||||
|
||||
keyValsList.ResetContent();
|
||||
|
||||
// Fill up the list with all the main info
|
||||
size_t numPairs = dict.Size();
|
||||
for (unsigned int i=0; i<numPairs; i++) {
|
||||
const idKeyValue *keyVal = dict.GetKeyVal(i);
|
||||
if (keyVal) {
|
||||
keyValsList.AddPropItem(new CPropertyItem(keyVal->GetKey().c_str(), keyVal->GetValue().c_str(), PIT_EDIT, ""));
|
||||
}
|
||||
}
|
||||
|
||||
//inheritCombo.SelectString(0, inherit);
|
||||
SetInherit(inherit);
|
||||
inheritCombo.SelectString(0, inherit);
|
||||
|
||||
declNameEdit.SetWindowText(decl->GetName());
|
||||
int index = spawnclassCombo.FindString(0, spawnclass);
|
||||
if (index == CB_ERR) {
|
||||
index = spawnclassCombo.AddString(spawnclass);
|
||||
}
|
||||
spawnclassCombo.SetCurSel(index);
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
DialogEntityDefEditor::SetInherit
|
||||
=================
|
||||
*/
|
||||
|
||||
void DialogEntityDefEditor::SetInherit(idStr &inherit)
|
||||
{
|
||||
CWaitCursor wc;
|
||||
|
||||
for (int i=0; i<keyValsList.GetCount(); i++) {
|
||||
CPropertyItem* pItem = (CPropertyItem*)keyValsList.GetItemDataPtr(i);
|
||||
if (pItem) {
|
||||
if (pItem->m_propName[0] == '*') {
|
||||
delete pItem;
|
||||
keyValsList.DeleteString(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CString spawnclass;
|
||||
// Fill up the rest of the box with inherited info
|
||||
if (!inherit.IsEmpty()) {
|
||||
const idDecl *temp = declManager->FindType(DECL_ENTITYDEF, inherit, false);
|
||||
const idDeclEntityDef *parent = static_cast<const idDeclEntityDef *>(temp);
|
||||
if (parent) {
|
||||
size_t numPairs = parent->dict.Size();
|
||||
for (unsigned int i=0; i<numPairs; i++) {
|
||||
const idKeyValue *keyVal = parent->dict.GetKeyVal(i);
|
||||
if (keyVal) {
|
||||
if (spawnclass.IsEmpty() && keyVal->GetKey() == "spawnclass") {
|
||||
spawnclass = keyVal->GetValue();
|
||||
}
|
||||
else {
|
||||
CString key = keyVal->GetKey();
|
||||
key = "*" + key;
|
||||
keyValsList.AddPropItem(new CPropertyItem(key, keyVal->GetValue().c_str(), PIT_EDIT, ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnInitDialog
|
||||
================
|
||||
*/
|
||||
BOOL DialogEntityDefEditor::OnInitDialog() {
|
||||
|
||||
com_editors |= EDITOR_ENTITYDEF;
|
||||
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
// load accelerator table
|
||||
m_hAccel = ::LoadAccelerators( AfxGetResourceHandle(), MAKEINTRESOURCE( IDR_ACCELERATOR_DECLEDITOR ) );
|
||||
|
||||
// create status bar
|
||||
statusBar.CreateEx( SBARS_SIZEGRIP, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM, initialRect, this, AFX_IDW_STATUS_BAR );
|
||||
|
||||
GetClientRect( initialRect );
|
||||
|
||||
EnableToolTips( TRUE );
|
||||
|
||||
testButton.EnableWindow( FALSE );
|
||||
okButton.EnableWindow( FALSE );
|
||||
|
||||
UpdateStatusBar();
|
||||
|
||||
return FALSE; // return TRUE unless you set the focus to a control
|
||||
// EXCEPTION: OCX Property Pages should return FALSE
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(DialogEntityDefEditor, CDialog)
|
||||
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
|
||||
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
|
||||
ON_WM_DESTROY()
|
||||
ON_WM_ACTIVATE()
|
||||
ON_WM_MOVE()
|
||||
ON_WM_SIZE()
|
||||
ON_WM_SIZING()
|
||||
ON_WM_SETFOCUS()
|
||||
ON_CBN_EDITCHANGE(IDC_ENTITYDEFEDITOR_COMBO_INHERIT, OnInheritChange)
|
||||
ON_CBN_SELCHANGE(IDC_ENTITYDEFEDITOR_COMBO_INHERIT, OnInheritChange)
|
||||
ON_CBN_EDITCHANGE(IDC_ENTITYDEFEDITOR_COMBO_SPAWNCLASS, OnEditChange)
|
||||
ON_EN_CHANGE(IDC_ENTITYDEFEDITOR_EDIT_DECLNAME, OnEditChange)
|
||||
ON_NOTIFY(EN_MSGFILTER, IDC_DECLEDITOR_EDIT_TEXT, OnEnInputEdit)
|
||||
|
||||
ON_LBN_SELCHANGE(IDC_ENTITYDEFEDITOR_LIST_KEYVALS, OnKeyValChange)
|
||||
|
||||
ON_BN_CLICKED(IDC_ENTITYDEFEDITOR_BUTTON_ADD, OnBnClickedAdd)
|
||||
ON_BN_CLICKED(IDC_ENTITYDEFEDITOR_BUTTON_DELETE, OnBnClickedDelete)
|
||||
|
||||
ON_BN_CLICKED(IDC_DECLEDITOR_BUTTON_TEST, OnBnClickedTest)
|
||||
ON_BN_CLICKED(IDOK, OnBnClickedOk)
|
||||
ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
|
||||
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
// DialogEntityDefEditor message handlers
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnActivate
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::OnActivate( UINT nState, CWnd *pWndOther, BOOL bMinimized ) {
|
||||
CDialog::OnActivate( nState, pWndOther, bMinimized );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnToolTipNotify
|
||||
================
|
||||
*/
|
||||
BOOL DialogEntityDefEditor::OnToolTipNotify( UINT id, NMHDR *pNMHDR, LRESULT *pResult ) {
|
||||
return DefaultOnToolTipNotify( toolTips, id, pNMHDR, pResult );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnSetFocus
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::OnSetFocus( CWnd *pOldWnd ) {
|
||||
CDialog::OnSetFocus( pOldWnd );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnDestroy
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::OnDestroy() {
|
||||
return CDialog::OnDestroy();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnMove
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::OnMove( int x, int y ) {
|
||||
if ( GetSafeHwnd() ) {
|
||||
CRect rct;
|
||||
GetWindowRect( rct );
|
||||
// FIXME: save position
|
||||
}
|
||||
CDialog::OnMove( x, y );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnSize
|
||||
================
|
||||
*/
|
||||
#define BORDER_SIZE 4
|
||||
#define BUTTON_SPACE 4
|
||||
#define CONTROL_HEIGHT 24
|
||||
#define TOOLBAR_HEIGHT 24
|
||||
|
||||
void DialogEntityDefEditor::OnSize( UINT nType, int cx, int cy ) {
|
||||
CRect clientRect, rect;
|
||||
|
||||
LockWindowUpdate();
|
||||
|
||||
CDialog::OnSize( nType, cx, cy );
|
||||
|
||||
GetClientRect( clientRect );
|
||||
|
||||
if ( keyValsList.GetSafeHwnd() ) {
|
||||
keyValsList.GetClientRect( rect );
|
||||
rect.left = BORDER_SIZE;
|
||||
rect.right = clientRect.right - BORDER_SIZE;
|
||||
rect.top = (TOOLBAR_HEIGHT * 2) + (BUTTON_SPACE * 3);
|
||||
rect.bottom = clientRect.bottom - (TOOLBAR_HEIGHT * 4) - BUTTON_SPACE;
|
||||
keyValsList.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
int keyRowTop = clientRect.Height() - TOOLBAR_HEIGHT * 3 - CONTROL_HEIGHT;
|
||||
int keyRowBottom = keyRowTop + CONTROL_HEIGHT;
|
||||
|
||||
int lineTop = clientRect.Height() - TOOLBAR_HEIGHT * 3 + (CONTROL_HEIGHT / 2);
|
||||
|
||||
int buttonRowTop = clientRect.Height() - TOOLBAR_HEIGHT - CONTROL_HEIGHT;
|
||||
int buttonRowBottom = buttonRowTop + CONTROL_HEIGHT;
|
||||
|
||||
if ( keyLabel.GetSafeHwnd() ) {
|
||||
keyLabel.GetClientRect( rect );
|
||||
int width = rect.Width();
|
||||
rect.left = BORDER_SIZE;
|
||||
rect.right = BORDER_SIZE + width;
|
||||
rect.top = keyRowTop + 8;
|
||||
rect.bottom = keyRowBottom;
|
||||
keyLabel.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( keyEdit.GetSafeHwnd() ) {
|
||||
keyEdit.GetClientRect( rect );
|
||||
rect.left = 40;
|
||||
rect.right = 40 + 200;
|
||||
rect.top = keyRowTop;
|
||||
rect.bottom = keyRowBottom;
|
||||
keyEdit.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
|
||||
if ( addButton.GetSafeHwnd() ) {
|
||||
addButton.GetClientRect( rect );
|
||||
int width = rect.Width();
|
||||
rect.left = clientRect.Width() - BORDER_SIZE - BUTTON_SPACE - 2 * width;
|
||||
rect.right = clientRect.Width() - BORDER_SIZE - BUTTON_SPACE - width;
|
||||
rect.top = keyRowTop;
|
||||
rect.bottom = keyRowBottom;
|
||||
addButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( delButton.GetSafeHwnd() ) {
|
||||
delButton.GetClientRect( rect );
|
||||
int width = rect.Width();
|
||||
rect.left = clientRect.Width() - BORDER_SIZE - width;
|
||||
rect.right = clientRect.Width() - BORDER_SIZE;
|
||||
rect.top = keyRowTop;
|
||||
rect.bottom = keyRowBottom;
|
||||
delButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( line.GetSafeHwnd() ) {
|
||||
line.GetClientRect( rect );
|
||||
int height = rect.Height();
|
||||
rect.left = BORDER_SIZE;
|
||||
rect.right = clientRect.Width() - BORDER_SIZE;
|
||||
rect.top = lineTop;
|
||||
rect.bottom = lineTop + 3;
|
||||
line.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( testButton.GetSafeHwnd() ) {
|
||||
testButton.GetClientRect( rect );
|
||||
int width = rect.Width();
|
||||
rect.left = BORDER_SIZE;
|
||||
rect.right = BORDER_SIZE + width;
|
||||
rect.top = buttonRowTop;
|
||||
rect.bottom = buttonRowBottom;
|
||||
testButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( okButton.GetSafeHwnd() ) {
|
||||
okButton.GetClientRect( rect );
|
||||
int width = rect.Width();
|
||||
rect.left = clientRect.Width() - BORDER_SIZE - BUTTON_SPACE - 2 * width;
|
||||
rect.right = clientRect.Width() - BORDER_SIZE - BUTTON_SPACE - width;
|
||||
rect.top = buttonRowTop;
|
||||
rect.bottom = buttonRowBottom;
|
||||
okButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( cancelButton.GetSafeHwnd() ) {
|
||||
cancelButton.GetClientRect( rect );
|
||||
int width = rect.Width();
|
||||
rect.left = clientRect.Width() - BORDER_SIZE - width;
|
||||
rect.right = clientRect.Width() - BORDER_SIZE;
|
||||
rect.top = buttonRowTop;
|
||||
rect.bottom = buttonRowBottom;
|
||||
cancelButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
if ( statusBar.GetSafeHwnd() ) {
|
||||
rect.left = clientRect.Width() - 2;
|
||||
rect.top = clientRect.Height() - 2;
|
||||
rect.right = clientRect.Width() - 2;
|
||||
rect.bottom = clientRect.Height() - 2;
|
||||
statusBar.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
|
||||
}
|
||||
|
||||
UnlockWindowUpdate();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnSizing
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::OnSizing( UINT nSide, LPRECT lpRect ) {
|
||||
/*
|
||||
1 = left
|
||||
2 = right
|
||||
3 = top
|
||||
4 = left - top
|
||||
5 = right - top
|
||||
6 = bottom
|
||||
7 = left - bottom
|
||||
8 = right - bottom
|
||||
*/
|
||||
|
||||
CDialog::OnSizing( nSide, lpRect );
|
||||
|
||||
if ( ( nSide - 1 ) % 3 == 0 ) {
|
||||
if ( lpRect->right - lpRect->left < initialRect.Width() ) {
|
||||
lpRect->left = lpRect->right - initialRect.Width();
|
||||
}
|
||||
} else if ( ( nSide - 2 ) % 3 == 0 ) {
|
||||
if ( lpRect->right - lpRect->left < initialRect.Width() ) {
|
||||
lpRect->right = lpRect->left + initialRect.Width();
|
||||
}
|
||||
}
|
||||
if ( nSide >= 3 && nSide <= 5 ) {
|
||||
if ( lpRect->bottom - lpRect->top < initialRect.Height() ) {
|
||||
lpRect->top = lpRect->bottom - initialRect.Height();
|
||||
}
|
||||
} else if ( nSide >= 6 && nSide <= 9 ) {
|
||||
if ( lpRect->bottom - lpRect->top < initialRect.Height() ) {
|
||||
lpRect->bottom = lpRect->top + initialRect.Height();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnEditChange
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::OnEditChange( ) {
|
||||
testButton.EnableWindow( TRUE );
|
||||
okButton.EnableWindow( TRUE );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnInheritChange
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::OnInheritChange( ) {
|
||||
testButton.EnableWindow( TRUE );
|
||||
okButton.EnableWindow( TRUE );
|
||||
|
||||
idStr inherit = "";
|
||||
|
||||
int sel = inheritCombo.GetCurSel();
|
||||
if ( sel == CB_ERR ) {
|
||||
CString temp;
|
||||
inheritCombo.GetWindowText( temp );
|
||||
inherit = temp;
|
||||
} else {
|
||||
CString temp;
|
||||
inheritCombo.GetLBText( sel, temp );
|
||||
inherit = temp;
|
||||
}
|
||||
SetInherit(inherit);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnEnInputEdit
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::OnEnInputEdit( NMHDR *pNMHDR, LRESULT *pResult ) {
|
||||
MSGFILTER *msgFilter = (MSGFILTER *)pNMHDR;
|
||||
|
||||
if ( msgFilter->msg != 512 && msgFilter->msg != 33 ) {
|
||||
UpdateStatusBar();
|
||||
}
|
||||
|
||||
*pResult = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::BuildDeclText
|
||||
================
|
||||
*/
|
||||
|
||||
void DialogEntityDefEditor::BuildDeclText( idStr &declText )
|
||||
{
|
||||
CString declName;
|
||||
declNameEdit.GetWindowText(declName);
|
||||
CString inherit;
|
||||
inheritCombo.GetWindowText(inherit);
|
||||
CString spawnclass;
|
||||
spawnclassCombo.GetWindowText(spawnclass);
|
||||
|
||||
declText = "entityDef " + declName + "\r{\r";
|
||||
declText += "\"inherit\"\t\t\t\"" + inherit + "\"\r";
|
||||
declText += "\"spawnclass\"\t\t\t\"" + spawnclass + "\"\r";
|
||||
for (int i=0; i<keyValsList.GetCount(); i++) {
|
||||
CPropertyItem* pItem = (CPropertyItem*)keyValsList.GetItemDataPtr(i);
|
||||
if (pItem) {
|
||||
// Items with a * in front are inherited and shouldn't be written out
|
||||
if (pItem->m_propName[0] == '*') {
|
||||
break;
|
||||
}
|
||||
declText += "\"" + pItem->m_propName + "\"\t\t\t\"" + pItem->m_curValue + "\"\r";
|
||||
}
|
||||
}
|
||||
declText += "}\r";
|
||||
|
||||
declText.Replace( "\r", "\r\n" );
|
||||
declText.Insert( "\r\n\r\n", 0 );
|
||||
declText.StripTrailing( "\r\n" );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnBnClickedTest
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::OnBnClickedTest() {
|
||||
idStr declText, oldDeclText;
|
||||
|
||||
if ( decl ) {
|
||||
|
||||
BuildDeclText(declText);
|
||||
|
||||
if ( !TestDecl( declText ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
char *oldDeclText = (char *)_alloca( ( decl->GetTextLength() + 1 ) * sizeof( char ) );
|
||||
decl->GetText( oldDeclText );
|
||||
decl->SetText( declText );
|
||||
decl->Invalidate();
|
||||
declManager->DeclByIndex( decl->GetType(), decl->Index(), true );
|
||||
decl->SetText( oldDeclText );
|
||||
decl->Invalidate();
|
||||
common->Printf( "tested %s\n", decl->GetName() );
|
||||
|
||||
testButton.EnableWindow( FALSE );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnBnClickedOk
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::OnBnClickedOk() {
|
||||
if ( decl ) {
|
||||
|
||||
idStr declText;
|
||||
BuildDeclText(declText);
|
||||
|
||||
if ( !TestDecl( declText ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( decl->SourceFileChanged() ) {
|
||||
if ( MessageBox( va( "Declaration file %s has been modified outside of the editor.\r\nReload declarations and save?", decl->GetFileName() ),
|
||||
va( "Warning saving: %s", decl->GetFileName() ), MB_OKCANCEL | MB_ICONERROR ) != IDOK ) {
|
||||
return;
|
||||
}
|
||||
declManager->Reload( false );
|
||||
DeclBrowserReloadDeclarations();
|
||||
}
|
||||
|
||||
decl->SetText( declText );
|
||||
if ( !decl->ReplaceSourceFileText() ) {
|
||||
MessageBox( va( "Couldn't save: %s.\r\nMake sure the declaration file is not read-only.", decl->GetFileName() ),
|
||||
va( "Error saving: %s", decl->GetFileName() ), MB_OK | MB_ICONERROR );
|
||||
return;
|
||||
}
|
||||
decl->Invalidate();
|
||||
}
|
||||
|
||||
okButton.EnableWindow( FALSE );
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnBnClickedCancel
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::OnBnClickedCancel() {
|
||||
if ( okButton.IsWindowEnabled() ) {
|
||||
if ( MessageBox( "Cancel changes?", "Cancel", MB_YESNO | MB_ICONQUESTION ) != IDYES ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
OnCancel();
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnKeyValChange
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::OnKeyValChange() {
|
||||
int sel = keyValsList.GetCurSel();
|
||||
if (sel >= 0) {
|
||||
CPropertyItem *pItem = (CPropertyItem *)keyValsList.GetItemDataPtr(sel);
|
||||
keyEdit.SetWindowText(pItem->m_propName);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnBnClickedAdd
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::OnBnClickedAdd() {
|
||||
CString newKey;
|
||||
keyEdit.GetWindowText(newKey);
|
||||
|
||||
int matchedInherit = -1;
|
||||
int matchedKey = -1;
|
||||
|
||||
// See if this key already exists
|
||||
for (int i=0; i<keyValsList.GetCount(); i++) {
|
||||
CPropertyItem* pItem = (CPropertyItem*)keyValsList.GetItemDataPtr(i);
|
||||
if (pItem) {
|
||||
// Items with a * in front are inherited and shouldn't be written out
|
||||
if (pItem->m_propName[0] == '*') {
|
||||
if (newKey = pItem->m_propName.Mid(1)) {
|
||||
matchedInherit = i;
|
||||
}
|
||||
}
|
||||
else if (pItem->m_propName == newKey) {
|
||||
matchedKey = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (matchedKey >= 0) {
|
||||
MessageBox("Key " + newKey + " already defined");
|
||||
return;
|
||||
}
|
||||
|
||||
if (matchedInherit >= 0) {
|
||||
delete keyValsList.GetItemDataPtr(matchedInherit);
|
||||
keyValsList.DeleteString(matchedInherit);
|
||||
}
|
||||
keyValsList.AddPropItem(new CPropertyItem(newKey, "", PIT_EDIT, ""));
|
||||
}
|
||||
|
||||
/*
|
||||
================
|
||||
DialogEntityDefEditor::OnBnClickedDelete
|
||||
================
|
||||
*/
|
||||
void DialogEntityDefEditor::OnBnClickedDelete() {
|
||||
CString delKey;
|
||||
keyEdit.GetWindowText(delKey);
|
||||
|
||||
int matchedInherit = -1;
|
||||
int matchedKey = -1;
|
||||
|
||||
// See if this key already exists
|
||||
for (int i=0; i<keyValsList.GetCount(); i++) {
|
||||
CPropertyItem* pItem = (CPropertyItem*)keyValsList.GetItemDataPtr(i);
|
||||
if (pItem) {
|
||||
// Items with a * in front are inherited and shouldn't be written out
|
||||
if (pItem->m_propName[0] == '*') {
|
||||
if (delKey = pItem->m_propName.Mid(1)) {
|
||||
matchedInherit = i;
|
||||
}
|
||||
}
|
||||
else if (pItem->m_propName == delKey) {
|
||||
matchedKey = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (matchedKey >= 0) {
|
||||
delete keyValsList.GetItemDataPtr(matchedKey);
|
||||
keyValsList.DeleteString(matchedKey);
|
||||
}
|
||||
else if (matchedInherit) {
|
||||
MessageBox("Cannot delete an inherited value");
|
||||
}
|
||||
}
|
||||
117
neo/tools/decl/DialogEntityDefEditor.h
Normal file
117
neo/tools/decl/DialogEntityDefEditor.h
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
===========================================================================
|
||||
|
||||
Doom 3 GPL Source Code
|
||||
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
|
||||
|
||||
This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
|
||||
|
||||
Doom 3 Source Code is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Doom 3 Source Code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
===========================================================================
|
||||
*/
|
||||
|
||||
#ifndef __DIALOGENTITYDEFEDITOR_H__
|
||||
#define __DIALOGENTITYDEFEDITOR_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../radiant/PropertyList.h"
|
||||
|
||||
// DialogEntityDefEditor dialog
|
||||
|
||||
class DialogEntityDefEditor : public CDialog {
|
||||
|
||||
DECLARE_DYNAMIC(DialogEntityDefEditor)
|
||||
|
||||
public:
|
||||
DialogEntityDefEditor( CWnd* pParent = NULL ); // standard constructor
|
||||
virtual ~DialogEntityDefEditor();
|
||||
|
||||
void LoadDecl( idDeclEntityDef *decl );
|
||||
|
||||
//{{AFX_VIRTUAL(DialogEntityDefEditor)
|
||||
virtual BOOL OnInitDialog();
|
||||
virtual void DoDataExchange( CDataExchange* pDX ); // DDX/DDV support
|
||||
virtual BOOL PreTranslateMessage( MSG* pMsg );
|
||||
//}}AFX_VIRTUAL
|
||||
|
||||
protected:
|
||||
//{{AFX_MSG(DialogEntityDefEditor)
|
||||
afx_msg BOOL OnToolTipNotify( UINT id, NMHDR *pNMHDR, LRESULT *pResult );
|
||||
afx_msg void OnSetFocus( CWnd *pOldWnd );
|
||||
afx_msg void OnDestroy();
|
||||
afx_msg void OnActivate( UINT nState, CWnd* pWndOther, BOOL bMinimized );
|
||||
afx_msg void OnMove( int x, int y );
|
||||
afx_msg void OnSize( UINT nType, int cx, int cy );
|
||||
afx_msg void OnSizing( UINT nSide, LPRECT lpRect );
|
||||
afx_msg LRESULT OnFindDialogMessage( WPARAM wParam, LPARAM lParam );
|
||||
afx_msg void OnEditChange();
|
||||
afx_msg void OnInheritChange();
|
||||
afx_msg void OnEnInputEdit( NMHDR *pNMHDR, LRESULT *pResult );
|
||||
|
||||
afx_msg void OnKeyValChange();
|
||||
|
||||
afx_msg void OnBnClickedAdd();
|
||||
afx_msg void OnBnClickedDelete();
|
||||
|
||||
afx_msg void OnBnClickedTest();
|
||||
afx_msg void OnBnClickedOk();
|
||||
afx_msg void OnBnClickedCancel();
|
||||
//}}AFX_MSG
|
||||
|
||||
DECLARE_MESSAGE_MAP()
|
||||
|
||||
private:
|
||||
|
||||
//{{AFX_DATA(DialogEntityDefEditor)
|
||||
enum { IDD = IDD_DIALOG_ENTITYEDITOR };
|
||||
CStatusBarCtrl statusBar;
|
||||
CEdit declNameEdit;
|
||||
CComboBox inheritCombo;
|
||||
CComboBox spawnclassCombo;
|
||||
|
||||
CPropertyList keyValsList;
|
||||
|
||||
CStatic keyLabel;
|
||||
CEdit keyEdit;
|
||||
CButton addButton;
|
||||
CButton delButton;
|
||||
CStatic line;
|
||||
|
||||
CButton testButton;
|
||||
CButton okButton;
|
||||
CButton cancelButton;
|
||||
//}}AFX_DATA
|
||||
|
||||
static toolTip_t toolTips[];
|
||||
|
||||
HACCEL m_hAccel;
|
||||
CRect initialRect;
|
||||
idDeclEntityDef * decl;
|
||||
int firstLine;
|
||||
|
||||
private:
|
||||
void PopulateLists(idStr &declText);
|
||||
void SetInherit(idStr &inherit);
|
||||
void BuildDeclText(idStr &declText);
|
||||
bool TestDecl( const idStr &declText );
|
||||
void UpdateStatusBar( void );
|
||||
};
|
||||
|
||||
#endif /* !__DIALOGENTITYDEFEDITOR_H__ */
|
||||
Reference in New Issue
Block a user