doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DialogDeclNew.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #include "../../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "../../sys/win32/rc/DeclEditor_resource.h"
33 
34 #include "../comafx/CPathTreeCtrl.h"
35 #include "DialogDeclBrowser.h"
36 #include "DialogDeclNew.h"
37 
38 #ifdef ID_DEBUG_MEMORY
39 #undef new
40 #undef DEBUG_NEW
41 #define DEBUG_NEW new
42 #endif
43 
44 
46  { IDC_DECLNEW_COMBO_NEW_TYPE, "select the declaration type to create" },
47  { IDC_DECLNEW_EDIT_NEW_NAME, "enter a name for the new declaration" },
48  { IDC_DECLNEW_EDIT_NEW_FILE, "enter the name of the file to add the declaration to" },
49  { IDC_DECLNEW_BUTTON_NEW_FILE, "select existing file to add the declaration to" },
50  { IDOK, "create new declaration" },
51  { IDCANCEL, "cancel" },
52  { 0, NULL }
53 };
54 
55 
56 IMPLEMENT_DYNAMIC(DialogDeclNew, CDialog)
57 
58 /*
59 ================
60 DialogDeclNew::DialogDeclNew
61 ================
62 */
63 DialogDeclNew::DialogDeclNew( CWnd* pParent /*=NULL*/ )
64  : CDialog(DialogDeclNew::IDD, pParent)
65  , declTree(NULL)
66  , newDecl(NULL)
67 {
68 }
69 
70 /*
71 ================
72 DialogDeclNew::~DialogDeclNew
73 ================
74 */
76 }
77 
78 /*
79 ================
80 DialogDeclNew::DoDataExchange
81 ================
82 */
83 void DialogDeclNew::DoDataExchange(CDataExchange* pDX) {
84  CDialog::DoDataExchange(pDX);
85  //{{AFX_DATA_MAP(DialogDeclNew)
86  DDX_Control(pDX, IDC_DECLNEW_COMBO_NEW_TYPE, typeList);
87  DDX_Control(pDX, IDC_DECLNEW_EDIT_NEW_NAME, nameEdit);
88  DDX_Control(pDX, IDC_DECLNEW_EDIT_NEW_FILE, fileEdit);
89  DDX_Control(pDX, IDC_DECLNEW_BUTTON_NEW_FILE, fileButton);
90  DDX_Control(pDX, IDOK, okButton);
91  DDX_Control(pDX, IDCANCEL, cancelButton);
92  //}}AFX_DATA_MAP
93 }
94 
95 /*
96 ================
97 DialogDeclNew::InitTypeList
98 ================
99 */
101  int i;
102 
103  typeList.ResetContent();
104  for ( i = 0; i < declManager->GetNumDeclTypes(); i++ ) {
106  }
107 }
108 
109 /*
110 ================
111 DialogDeclNew::OnInitDialog
112 ================
113 */
115 
116  CDialog::OnInitDialog();
117 
118  InitTypeList();
119 
121  nameEdit.SetWindowText( defaultName.c_str() );
122  fileEdit.SetWindowText( defaultFile.c_str() );
123 
124  EnableToolTips( TRUE );
125 
126  return TRUE; // return TRUE unless you set the focus to a control
127  // EXCEPTION: OCX Property Pages should return FALSE
128 }
129 
130 
131 BEGIN_MESSAGE_MAP(DialogDeclNew, CDialog)
132  ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
133  ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
134  ON_WM_DESTROY()
135  ON_WM_ACTIVATE()
136  ON_WM_SETFOCUS()
137  ON_BN_CLICKED(IDC_DECLNEW_BUTTON_NEW_FILE, OnBnClickedFile)
138  ON_BN_CLICKED(IDOK, OnBnClickedOk)
139  ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
140 END_MESSAGE_MAP()
141 
142 
143 // DialogDeclNew message handlers
144 
145 /*
146 ================
147 DialogDeclNew::OnActivate
148 ================
149 */
150 void DialogDeclNew::OnActivate( UINT nState, CWnd *pWndOther, BOOL bMinimized ) {
151  CDialog::OnActivate( nState, pWndOther, bMinimized );
152 }
153 
154 /*
155 ================
156 DialogDeclNew::OnToolTipNotify
157 ================
158 */
159 BOOL DialogDeclNew::OnToolTipNotify( UINT id, NMHDR *pNMHDR, LRESULT *pResult ) {
160  return DefaultOnToolTipNotify( toolTips, id, pNMHDR, pResult );
161 }
162 
163 /*
164 ================
165 DialogDeclNew::OnSetFocus
166 ================
167 */
168 void DialogDeclNew::OnSetFocus( CWnd *pOldWnd ) {
169  CDialog::OnSetFocus( pOldWnd );
170 }
171 
172 /*
173 ================
174 DialogDeclNew::OnDestroy
175 ================
176 */
178  return CDialog::OnDestroy();
179 }
180 
181 /*
182 ================
183 DialogDeclNew::OnBnClickedFile
184 ================
185 */
187  CString typeName, folder, ext;
188  idStr path;
189  const char *errorTitle = "Error selecting file.";
190 
191  if ( GetSafeComboBoxSelection( &typeList, typeName, -1 ) == -1 ) {
192  MessageBox( "Select a declaration type first.", errorTitle, MB_OK );
193  return;
194  }
195 
197  if ( type >= declManager->GetNumDeclTypes() ) {
198  MessageBox( "Unknown declaration type.", errorTitle, MB_OK | MB_ICONERROR );
199  return;
200  }
201 
202  switch( type ) {
203  case DECL_TABLE: folder = "materials"; ext = "(*.mtr)|*.mtr|(*.*)|*.*||"; break;
204  case DECL_MATERIAL: folder = "materials"; ext = "(*.mtr)|*.mtr|(*.*)|*.*||"; break;
205  case DECL_SKIN: folder = "skins"; ext = "(*.skin)|*.skin|(*.*)|*.*||"; break;
206  case DECL_SOUND: folder = "sound"; ext = "(*.sndshd|*.sndshd|(*.*)|*.*||"; break;
207  case DECL_ENTITYDEF: folder = "def"; ext = "(*.def)|*.def|(*.decl)|*.decl|(*.*)|*.*||"; break;
208  case DECL_MODELDEF: folder = "def"; ext = "(*.def)|*.def|(*.*)|*.*||"; break;
209  case DECL_FX: folder = "fx"; ext = "(*.fx)|*.fx|(*.*)|*.*||"; break;
210  case DECL_PARTICLE: folder = "particles"; ext = "(*.prt)|*.prt|(*.*)|*.*||"; break;
211  case DECL_AF: folder = "af"; ext = "(*.af)|*.af|(*.*)|*.*||"; break;
212  default: folder = "def"; ext = "(*.decl)|*.decl|(*.*)|*.*||"; break;
213  }
214 
215  path = fileSystem->RelativePathToOSPath( folder );
216  path += "\\*";
217 
218  CFileDialog dlgFile( TRUE, "decl", path, 0, ext, this );
219  if ( dlgFile.DoModal() == IDOK ) {
220  path = fileSystem->OSPathToRelativePath( dlgFile.m_ofn.lpstrFile );
221  fileEdit.SetWindowText( path );
222  }
223 }
224 
225 /*
226 ================
227 DialogDeclNew::OnBnClickedOk
228 ================
229 */
231  CString typeName, declName, fileName;
232  const char *errorTitle = "Error creating declaration.";
233 
234  if ( !declTree ) {
235  MessageBox( "No declaration tree available.", errorTitle, MB_OK | MB_ICONERROR );
236  return;
237  }
238 
239  if ( GetSafeComboBoxSelection( &typeList, typeName, -1 ) == -1 ) {
240  MessageBox( "No declaration type selected.", errorTitle, MB_OK | MB_ICONERROR );
241  return;
242  }
243 
244  nameEdit.GetWindowText( declName );
245  if ( declName.GetLength() == 0 ) {
246  MessageBox( "No declaration name specified.", errorTitle, MB_OK | MB_ICONERROR );
247  return;
248  }
249 
250  fileEdit.GetWindowText( fileName );
251  if ( fileName.GetLength() == 0 ) {
252  MessageBox( "No file name specified.", errorTitle, MB_OK | MB_ICONERROR );
253  return;
254  }
255 
256  if ( declTree->FindItem( idStr( typeName + "/" + declName ) ) ) {
257  MessageBox( "Declaration already exists.", errorTitle, MB_OK | MB_ICONERROR );
258  return;
259  }
260 
262  if ( type >= declManager->GetNumDeclTypes() ) {
263  MessageBox( "Unknown declaration type.", errorTitle, MB_OK | MB_ICONERROR );
264  return;
265  }
266 
267  newDecl = declManager->CreateNewDecl( type, declName, fileName );
268 
269  OnOK();
270 }
271 
272 /*
273 ================
274 DialogDeclNew::OnBnClickedCancel
275 ================
276 */
278  OnCancel();
279 }
BOOL DefaultOnToolTipNotify(const toolTip_t *toolTips, UINT id, NMHDR *pNMHDR, LRESULT *pResult)
Definition: StdAfx.cpp:104
afx_msg void OnDestroy()
HTREEITEM FindItem(const idStr &pathName)
int SetSafeComboBoxSelection(CComboBox *combo, const char *string, int skip)
Definition: StdAfx.cpp:319
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
CButton fileButton
Definition: DialogDeclNew.h:76
#define IDC_DECLNEW_EDIT_NEW_NAME
idFileSystem * fileSystem
Definition: FileSystem.cpp:500
declType_t
Definition: DeclManager.h:65
CButton cancelButton
Definition: DialogDeclNew.h:78
virtual idDecl * CreateNewDecl(declType_t type, const char *name, const char *fileName)=0
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
int i
Definition: process.py:33
#define BOOL
Definition: mprintf.c:71
CPathTreeCtrl * declTree
Definition: DialogDeclNew.h:83
virtual int GetNumDeclTypes(void) const =0
idDecl * newDecl
Definition: DialogDeclNew.h:87
afx_msg void OnBnClickedOk()
virtual ~DialogDeclNew()
static toolTip_t toolTips[]
Definition: DialogDeclNew.h:81
afx_msg BOOL OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult)
virtual void DoDataExchange(CDataExchange *pDX)
#define NULL
Definition: Lib.h:88
CButton okButton
Definition: DialogDeclNew.h:77
const char * path
Definition: sws.c:117
afx_msg void OnSetFocus(CWnd *pOldWnd)
virtual const char * GetDeclNameFromType(declType_t type) const =0
idDeclManager * declManager
virtual const char * RelativePathToOSPath(const char *relativePath, const char *basePath="fs_devpath")=0
#define IDC_DECLNEW_EDIT_NEW_FILE
int GetSafeComboBoxSelection(CComboBox *combo, CString &string, int skip)
Definition: StdAfx.cpp:341
#define IDC_DECLNEW_COMBO_NEW_TYPE
#define IDC_DECLNEW_BUTTON_NEW_FILE
virtual declType_t GetDeclTypeFromName(const char *typeName) const =0
Definition: Str.h:116
const char * c_str(void) const
Definition: Str.h:487
afx_msg void OnBnClickedCancel()
void InitTypeList(void)
#define TRUE
Definition: mprintf.c:69
virtual const char * OSPathToRelativePath(const char *OSPath)=0
afx_msg void OnBnClickedFile()
virtual BOOL OnInitDialog()
CComboBox typeList
Definition: DialogDeclNew.h:73