MEMainFrame.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "MaterialEditor.h"
  23. #include "MEMainFrame.h"
  24. #include "MaterialDef.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #endif
  28. #define TAB_CONTROL 0x1006
  29. IMPLEMENT_DYNAMIC(MEMainFrame, CFrameWnd)
  30. BEGIN_MESSAGE_MAP(MEMainFrame, CFrameWnd)
  31. ON_WM_CREATE()
  32. ON_WM_SETFOCUS()
  33. ON_WM_DESTROY()
  34. ON_WM_SIZE()
  35. ON_NOTIFY(TCN_SELCHANGE, TAB_CONTROL, OnTcnSelChange)
  36. ON_COMMAND(ID_ME_FILE_EXIT, OnFileExit)
  37. ON_COMMAND(ID_ME_FILE_SAVEMATERIAL, OnFileSaveMaterial)
  38. ON_COMMAND(ID_ME_FILE_SAVEFILE, OnFileSaveFile)
  39. ON_COMMAND(ID_ME_FILE_SAVE, OnFileSaveAll)
  40. ON_UPDATE_COMMAND_UI(ID_ME_FILE_SAVEMATERIAL, OnFileSaveMaterialUpdate )
  41. ON_UPDATE_COMMAND_UI(ID_ME_FILE_SAVEFILE, OnFileSaveFileUpdate )
  42. ON_UPDATE_COMMAND_UI(ID_ME_FILE_SAVE, OnFileSaveAllUpdate )
  43. ON_COMMAND(ID_ME_PREVIEW_APPLYCHANGES, OnApplyMaterial)
  44. ON_COMMAND(ID_ME_PREVIEW_APPLYFILE, OnApplyFile)
  45. ON_COMMAND(ID_ME_PREVIEW_APPLYALL, OnApplyAll)
  46. ON_UPDATE_COMMAND_UI(ID_ME_PREVIEW_APPLYCHANGES, OnApplyMaterialUpdate )
  47. ON_UPDATE_COMMAND_UI(ID_ME_PREVIEW_APPLYFILE, OnApplyFileUpdate )
  48. ON_UPDATE_COMMAND_UI(ID_ME_PREVIEW_APPLYALL, OnApplyAllUpdate )
  49. ON_COMMAND(ID_ME_EDIT_CUT, OnEditCut)
  50. ON_COMMAND(ID_ME_EDIT_COPY, OnEditCopy)
  51. ON_COMMAND(ID_ME_EDIT_PASTE, OnEditPaste)
  52. ON_COMMAND(ID_ME_EDIT_DELETE, OnEditDelete)
  53. ON_COMMAND(ID_ME_EDIT_RENAME, OnEditRename)
  54. ON_UPDATE_COMMAND_UI(ID_ME_EDIT_CUT, OnEditCutUpdate)
  55. ON_UPDATE_COMMAND_UI(ID_ME_EDIT_COPY, OnEditCopyUpdate)
  56. ON_UPDATE_COMMAND_UI(ID_ME_EDIT_PASTE, OnEditPasteUpdate)
  57. ON_UPDATE_COMMAND_UI(ID_ME_EDIT_DELETE, OnEditDeleteUpdate)
  58. ON_UPDATE_COMMAND_UI(ID_ME_EDIT_RENAME, OnEditRenameUpdate)
  59. ON_COMMAND(ID_ME_EDIT_FIND, OnEditFind)
  60. ON_COMMAND(ID_ME_EDIT_FIND_NEXT, OnEditFindNext)
  61. ON_COMMAND(ID_ME_EDIT_UNDO, OnEditUndo)
  62. ON_COMMAND(ID_ME_EDIT_REDO, OnEditRedo)
  63. ON_UPDATE_COMMAND_UI(ID_ME_EDIT_UNDO, OnEditUndoUpdate )
  64. ON_UPDATE_COMMAND_UI(ID_ME_EDIT_REDO, OnEditRedoUpdate )
  65. ON_COMMAND(ID_VIEW_INCLUDEFILENAME, OnViewIncludeFile)
  66. ON_COMMAND(ID_PREVIEW_RELOADARBPROGRAMS, OnReloadArbPrograms)
  67. ON_COMMAND(ID_PREVIEW_RELOADIMAGES, OnReloadImages )
  68. END_MESSAGE_MAP()
  69. static UINT indicators[] =
  70. {
  71. ID_SEPARATOR, // status line indicator
  72. ID_INDICATOR_CAPS,
  73. ID_INDICATOR_NUM,
  74. ID_INDICATOR_SCRL,
  75. };
  76. /**
  77. * Constructor for MEMainFrame. Initialize some member data and load the options.
  78. */
  79. MEMainFrame::MEMainFrame() {
  80. currentDoc = NULL;
  81. m_find = NULL;
  82. searchData.searched = false;
  83. options.Load();
  84. }
  85. /**
  86. * Destructor for MEMainFrame.
  87. */
  88. MEMainFrame::~MEMainFrame() {
  89. }
  90. /**
  91. * Called to add console text to the console view.
  92. * @param msg The text that is to be added to the console.
  93. */
  94. void MEMainFrame::PrintConsoleMessage(const char *msg) {
  95. m_consoleView->AddText(msg);
  96. }
  97. /**
  98. * Sets a few window styles for the main window during the creation process.
  99. */
  100. BOOL MEMainFrame::PreCreateWindow(CREATESTRUCT& cs) {
  101. if( !CFrameWnd::PreCreateWindow(cs) )
  102. return FALSE;
  103. cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
  104. cs.lpszClass = AfxRegisterWndClass(0);
  105. return TRUE;
  106. }
  107. /**
  108. * Called by the MFC framework to allow the window to create any client windows. This method
  109. * creates all of the spliter windows and registers all of the views with the document manager.
  110. */
  111. BOOL MEMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) {
  112. CCreateContext consoleContext;
  113. consoleContext.m_pNewViewClass = RUNTIME_CLASS(ConsoleView);
  114. m_consoleView = (ConsoleView*)CreateView(&consoleContext);
  115. m_consoleView->ShowWindow(SW_HIDE);
  116. m_tabs.Create(TCS_BOTTOM | TCS_FLATBUTTONS | WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0), this, TAB_CONTROL);
  117. m_tabs.InsertItem(0, "Editor");
  118. m_tabs.InsertItem(1, "Console");
  119. m_tabs.SetFont(materialEditorFont);
  120. m_splitterWnd.CreateStatic(this, 2, 1);
  121. m_editSplitter.CreateStatic(&m_splitterWnd, 1, 2, WS_CHILD | WS_VISIBLE | WS_BORDER, m_splitterWnd.IdFromRowCol(0, 0));
  122. if(!m_editSplitter.CreateView(0, 0, RUNTIME_CLASS(MaterialTreeView), CSize(300, 200), pContext)) {
  123. TRACE0("Failed to create material list pane\n");
  124. return FALSE;
  125. }
  126. if(!m_editSplitter.CreateView(0, 1, RUNTIME_CLASS(MaterialEditView), CSize(200, 200), pContext)) {
  127. TRACE0("Failed to create stage property pane\n");
  128. return FALSE;
  129. }
  130. m_previewSplitter.CreateStatic(&m_splitterWnd, 1, 2, WS_CHILD | WS_VISIBLE | WS_BORDER, m_splitterWnd.IdFromRowCol(1, 0));
  131. if(!m_previewSplitter.CreateView(0, 0, RUNTIME_CLASS(MaterialPreviewPropView), CSize(300, 200), pContext)) {
  132. TRACE0("Failed to create preview property pane\n");
  133. return FALSE;
  134. }
  135. if(!m_previewSplitter.CreateView(0, 1, RUNTIME_CLASS(MaterialPreviewView), CSize(100, 200), pContext)) {
  136. TRACE0("Failed to create preview pane\n");
  137. return FALSE;
  138. }
  139. //Get references to all of the views
  140. m_materialTreeView = (MaterialTreeView*)m_editSplitter.GetPane(0, 0);
  141. m_previewPropertyView = (MaterialPreviewPropView*)m_previewSplitter.GetPane(0, 0);
  142. m_materialPreviewView = (MaterialPreviewView*)m_previewSplitter.GetPane(0, 1);
  143. m_materialEditView = (MaterialEditView*)m_editSplitter.GetPane(0, 1);
  144. m_stageView = m_materialEditView->m_stageView;
  145. m_materialPropertyView = m_materialEditView->m_materialPropertyView;
  146. m_materialEditSplitter = &m_materialEditView->m_editSplitter;
  147. //Load the splitter positions from the registry
  148. int val = options.GetMaterialEditHeight();
  149. if(val <= 0)
  150. val = 300;
  151. m_splitterWnd.SetRowInfo(0, val, 0);
  152. val = options.GetMaterialTreeWidth();
  153. if(val <= 0)
  154. val = 300;
  155. m_editSplitter.SetColumnInfo(0, val, 0);
  156. val = options.GetStageWidth();
  157. if(val <= 0)
  158. val = 200;
  159. m_materialEditSplitter->SetColumnInfo(0, val, 0);
  160. val = options.GetPreviewPropertiesWidth();
  161. if(val <= 0)
  162. val = 300;
  163. m_previewSplitter.SetColumnInfo(0, val, 0);
  164. //Register the views with the document manager
  165. materialDocManager.RegisterMaterialView(this);
  166. materialDocManager.RegisterMaterialView(m_materialTreeView);
  167. materialDocManager.RegisterMaterialView(m_stageView);
  168. materialDocManager.RegisterMaterialView(m_materialPropertyView);
  169. materialDocManager.RegisterMaterialView(m_materialPreviewView);
  170. materialDocManager.RegisterMaterialView(m_materialEditView);
  171. //Let the stage window know about the prop window
  172. m_stageView->SetMaterialPropertyView(m_materialPropertyView);
  173. //Let the preview props now about the preview window
  174. m_previewPropertyView->RegisterPreviewView(m_materialPreviewView);
  175. m_previewPropertyView->InitializePropTree();
  176. m_previewPropertyView->GetPropertyTreeCtrl().SetColumn(120);
  177. MaterialDefManager::InitializeMaterialDefLists();
  178. //Some prop tree initialization
  179. //m_materialPropertyView->InitializePropTreeDefs();
  180. val = options.GetMaterialPropHeadingWidth();
  181. if(val <= 0)
  182. val = 200;
  183. m_materialPropertyView->GetPropertyTreeCtrl().SetColumn(val);
  184. m_materialPropertyView->LoadSettings();
  185. val = options.GetPreviewPropHeadingWidth();
  186. if(val <= 0)
  187. val = 120;
  188. m_previewPropertyView->GetPropertyTreeCtrl().SetColumn(val);
  189. //Build the material list
  190. m_materialTreeView->InitializeMaterialList(true);
  191. SetActiveView(m_materialTreeView);
  192. return CFrameWnd::OnCreateClient(lpcs, pContext);
  193. }
  194. /**
  195. * Called by the framework while the window is being created. This methods
  196. * creates the tool bars and status bars
  197. * /todo Bmatt Nerve: Need to get the toolbars to work correctly.
  198. */
  199. int MEMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) {
  200. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  201. return -1;
  202. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  203. !m_wndToolBar.LoadToolBar(IDR_ME_MAINFRAME))
  204. {
  205. TRACE0("Failed to create toolbar\n");
  206. return -1; // fail to create
  207. }
  208. if (!m_wndStatusBar.Create(this) ||
  209. !m_wndStatusBar.SetIndicators(indicators,
  210. sizeof(indicators)/sizeof(UINT)))
  211. {
  212. TRACE0("Failed to create status bar\n");
  213. return -1; // fail to create
  214. }
  215. //Load the window placement from the options
  216. options.GetWindowPlacement ( "mainframe", m_hWnd );
  217. return 0;
  218. }
  219. /**
  220. * Called by the MFC framework while the window is being destroyed. This method
  221. * saves the splitter and window positions.
  222. */
  223. void MEMainFrame::OnDestroy() {
  224. CFrameWnd::OnDestroy();
  225. int cur;
  226. int min;
  227. m_splitterWnd.GetRowInfo(0, cur, min);
  228. options.SetMaterialEditHeight(cur);
  229. m_editSplitter.GetColumnInfo(0, cur, min);
  230. options.SetMaterialTreeWidth(cur);
  231. m_materialEditSplitter->GetColumnInfo(0, cur, min);
  232. options.SetStageWidth(cur);
  233. m_previewSplitter.GetColumnInfo(0, cur, min);
  234. options.SetPreviewPropertiesWidth(cur);
  235. cur = m_materialPropertyView->GetPropertyTreeCtrl().GetColumn();
  236. options.SetMaterialPropHeadingWidth(cur);
  237. cur = m_previewPropertyView->GetPropertyTreeCtrl().GetColumn();
  238. options.SetPreviewPropHeadingWidth(cur);
  239. options.SetWindowPlacement ( "mainframe", m_hWnd );
  240. options.Save();
  241. m_materialPropertyView->SaveSettings();
  242. MaterialDefManager::DestroyMaterialDefLists();
  243. AfxGetApp()->ExitInstance();
  244. }
  245. /**
  246. * Called by the MFC framework when the window size is changed. This method adjusts the console view
  247. * so that it is always at the bottom of the window and resizes the splitter window to fit
  248. * the remaining space.
  249. */
  250. void MEMainFrame::OnSize(UINT nType, int cx, int cy)
  251. {
  252. CFrameWnd::OnSize(nType, cx, cy);
  253. CRect statusRect;
  254. m_wndStatusBar.GetWindowRect(statusRect);
  255. CRect toolbarRect;
  256. m_wndToolBar.GetWindowRect(toolbarRect);
  257. CRect tabRect;
  258. m_tabs.GetItemRect(0, tabRect);
  259. int tabHeight = tabRect.Height()+5;
  260. m_splitterWnd.MoveWindow(0, toolbarRect.Height(), cx, cy-statusRect.Height()-toolbarRect.Height()-tabHeight);
  261. m_tabs.MoveWindow(0, cy-statusRect.Height()-tabHeight, cx, tabHeight);
  262. m_consoleView->MoveWindow(0, toolbarRect.Height(), cx, cy-statusRect.Height()-toolbarRect.Height()-tabHeight);
  263. }
  264. /**
  265. * Called when the user changes the editor/console tab selection. This methods shows and hides
  266. * the appropriate windows.
  267. */
  268. void MEMainFrame::OnTcnSelChange(NMHDR *pNMHDR, LRESULT *pResult) {
  269. int sel = m_tabs.GetCurSel();
  270. switch(sel) {
  271. case 0:
  272. m_splitterWnd.ShowWindow(SW_SHOW);
  273. m_consoleView->ShowWindow(SW_HIDE);
  274. break;
  275. case 1:
  276. m_splitterWnd.ShowWindow(SW_HIDE);
  277. m_consoleView->ShowWindow(SW_SHOW);
  278. CRect rect;
  279. GetWindowRect(rect);
  280. MoveWindow(rect);
  281. break;
  282. }
  283. }
  284. /**
  285. * Shuts down the material editor.
  286. * /todo BMatt Nerve: Need to warn the user if a file is modified.
  287. */
  288. void MEMainFrame::OnFileExit() {
  289. PostMessage(WM_DESTROY, 0, 0);
  290. }
  291. /**
  292. * Saves the selected material.
  293. */
  294. void MEMainFrame::OnFileSaveMaterial() {
  295. MaterialDoc* material = materialDocManager.GetCurrentMaterialDoc();
  296. if(material) {
  297. materialDocManager.SaveMaterial(material);
  298. }
  299. }
  300. /**
  301. * Saves the selected file.
  302. */
  303. void MEMainFrame::OnFileSaveFile() {
  304. idStr filename = m_materialTreeView->GetSaveFilename();
  305. if(filename.Length() > 0) {
  306. materialDocManager.SaveFile(filename);
  307. }
  308. }
  309. /**
  310. * Saves all modified materials.
  311. */
  312. void MEMainFrame::OnFileSaveAll() {
  313. materialDocManager.SaveAllMaterials();
  314. }
  315. /**
  316. * Enables the save material menu item if a material is selected and has been modified.
  317. */
  318. void MEMainFrame::OnFileSaveMaterialUpdate(CCmdUI *pCmdUI) {
  319. MaterialDoc* pDoc = materialDocManager.GetCurrentMaterialDoc();
  320. if(pCmdUI->m_pMenu == NULL) {
  321. pCmdUI->Enable(TRUE);
  322. return;
  323. }
  324. if(pDoc && pDoc->modified) {
  325. pCmdUI->Enable(TRUE);
  326. } else {
  327. pCmdUI->Enable(FALSE);
  328. }
  329. }
  330. /**
  331. * Enables the Save File menu item if the current file contains a modified material.
  332. */
  333. void MEMainFrame::OnFileSaveFileUpdate(CCmdUI *pCmdUI) {
  334. if(pCmdUI->m_pMenu == NULL) {
  335. pCmdUI->Enable(TRUE);
  336. return;
  337. }
  338. if(m_materialTreeView->CanSaveFile()) {
  339. pCmdUI->Enable(TRUE);
  340. } else {
  341. pCmdUI->Enable(FALSE);
  342. }
  343. }
  344. /**
  345. * Enables the Save All menu item if there are any materials that have been modified.
  346. */
  347. void MEMainFrame::OnFileSaveAllUpdate(CCmdUI *pCmdUI) {
  348. if(pCmdUI->m_pMenu == NULL) {
  349. pCmdUI->Enable(TRUE);
  350. return;
  351. }
  352. if(materialDocManager.IsAnyModified()) {
  353. pCmdUI->Enable(TRUE);
  354. } else {
  355. pCmdUI->Enable(FALSE);
  356. }
  357. }
  358. /**
  359. * Apply the selected material.
  360. */
  361. void MEMainFrame::OnApplyMaterial() {
  362. MaterialDoc* material = materialDocManager.GetCurrentMaterialDoc();
  363. if(material) {
  364. materialDocManager.ApplyMaterial(material);
  365. }
  366. }
  367. /**
  368. * Applies all modified materials in the selected file.
  369. */
  370. void MEMainFrame::OnApplyFile() {
  371. idStr filename = m_materialTreeView->GetSaveFilename();
  372. if(filename.Length() > 0) {
  373. materialDocManager.ApplyFile(filename);
  374. }
  375. }
  376. /**
  377. * Applies all modified materials.
  378. */
  379. void MEMainFrame::OnApplyAll() {
  380. materialDocManager.ApplyAll();
  381. }
  382. /**
  383. * Enables the Apply Material menu item if the current material has an apply waiting.
  384. */
  385. void MEMainFrame::OnApplyMaterialUpdate(CCmdUI *pCmdUI) {
  386. MaterialDoc* pDoc = materialDocManager.GetCurrentMaterialDoc();
  387. if(pCmdUI->m_pMenu == NULL) {
  388. pCmdUI->Enable(TRUE);
  389. return;
  390. }
  391. if(pDoc && pDoc->applyWaiting) {
  392. pCmdUI->Enable(TRUE);
  393. } else {
  394. pCmdUI->Enable(FALSE);
  395. }
  396. }
  397. /**
  398. * Enables the apply file menu item if the current file contains any materials
  399. * that need to be applied.
  400. */
  401. void MEMainFrame::OnApplyFileUpdate(CCmdUI *pCmdUI) {
  402. if(pCmdUI->m_pMenu == NULL) {
  403. pCmdUI->Enable(TRUE);
  404. return;
  405. }
  406. MaterialDoc* pDoc = materialDocManager.GetCurrentMaterialDoc();
  407. if(pDoc && materialDocManager.DoesFileNeedApply(pDoc->renderMaterial->GetFileName())) {
  408. pCmdUI->Enable(TRUE);
  409. } else {
  410. pCmdUI->Enable(FALSE);
  411. }
  412. }
  413. /**
  414. * Enables the apply all menu item if there are any materials that need
  415. * to be applied.
  416. */
  417. void MEMainFrame::OnApplyAllUpdate(CCmdUI *pCmdUI) {
  418. if(pCmdUI->m_pMenu == NULL) {
  419. pCmdUI->Enable(TRUE);
  420. return;
  421. }
  422. if(materialDocManager.DoesAnyNeedApply()) {
  423. pCmdUI->Enable(TRUE);
  424. } else {
  425. pCmdUI->Enable(FALSE);
  426. }
  427. }
  428. /**
  429. * Performs a cut operation on the selected material.
  430. */
  431. void MEMainFrame::OnEditCut() {
  432. CWnd* focus = GetFocus();
  433. if(focus) {
  434. if (focus->IsKindOf(RUNTIME_CLASS(MaterialTreeView))) {
  435. m_materialTreeView->OnCut();
  436. }
  437. }
  438. }
  439. /**
  440. * Performs a copy operation on the selected material or stage.
  441. */
  442. void MEMainFrame::OnEditCopy() {
  443. CWnd* focus = GetFocus();
  444. if(focus) {
  445. if (focus->IsKindOf(RUNTIME_CLASS(StageView))) {
  446. m_stageView->OnCopy();
  447. } else if (focus->IsKindOf(RUNTIME_CLASS(MaterialTreeView))) {
  448. m_materialTreeView->OnCopy();
  449. }
  450. }
  451. }
  452. /**
  453. * Performs a paste operation on the selected material or stage.
  454. */
  455. void MEMainFrame::OnEditPaste() {
  456. CWnd* focus = GetFocus();
  457. if(focus) {
  458. if (focus->IsKindOf(RUNTIME_CLASS(StageView))) {
  459. m_stageView->OnPaste();
  460. } else if (focus->IsKindOf(RUNTIME_CLASS(MaterialTreeView))) {
  461. m_materialTreeView->OnPaste();
  462. }
  463. }
  464. }
  465. /**
  466. * Performs a delete operation on the selected material or stage.
  467. */
  468. void MEMainFrame::OnEditDelete() {
  469. CWnd* focus = GetFocus();
  470. if(focus) {
  471. if (focus->IsKindOf(RUNTIME_CLASS(StageView))) {
  472. m_stageView->OnDeleteStage();
  473. } else if (focus->IsKindOf(RUNTIME_CLASS(MaterialTreeView))) {
  474. m_materialTreeView->OnDeleteMaterial();
  475. }
  476. }
  477. }
  478. /**
  479. * Performs a rename operation on the selected material or stage.
  480. */
  481. void MEMainFrame::OnEditRename() {
  482. CWnd* focus = GetFocus();
  483. if(focus) {
  484. if (focus->IsKindOf(RUNTIME_CLASS(StageView))) {
  485. m_stageView->OnRenameStage();
  486. } else if (focus->IsKindOf(RUNTIME_CLASS(MaterialTreeView))) {
  487. m_materialTreeView->OnRenameMaterial();
  488. }
  489. }
  490. }
  491. /**
  492. * Enable the cut menu item if a material is selected.
  493. */
  494. void MEMainFrame::OnEditCutUpdate(CCmdUI *pCmdUI) {
  495. if(pCmdUI->m_pMenu == NULL) {
  496. pCmdUI->Enable(TRUE);
  497. return;
  498. }
  499. BOOL enable = FALSE;
  500. CWnd* focus = GetFocus();
  501. if(focus) {
  502. if (focus->IsKindOf(RUNTIME_CLASS(StageView))) {
  503. if(m_stageView->CanCut()) {
  504. enable = TRUE;
  505. }
  506. } else if (focus->IsKindOf(RUNTIME_CLASS(MaterialTreeView))) {
  507. if(m_materialTreeView->CanCut()) {
  508. enable = TRUE;
  509. }
  510. } else if (focus->IsKindOf(RUNTIME_CLASS(CRichEditCtrl))) {
  511. enable = TRUE;
  512. }
  513. }
  514. pCmdUI->Enable(enable);
  515. }
  516. /**
  517. * Enables the copy menu item if a material or stage is selected.
  518. */
  519. void MEMainFrame::OnEditCopyUpdate(CCmdUI *pCmdUI) {
  520. if(pCmdUI->m_pMenu == NULL) {
  521. pCmdUI->Enable(TRUE);
  522. return;
  523. }
  524. BOOL enable = FALSE;
  525. CWnd* focus = GetFocus();
  526. if(focus) {
  527. if (focus->IsKindOf(RUNTIME_CLASS(StageView))) {
  528. if(m_stageView->CanCopy()) {
  529. enable = TRUE;
  530. }
  531. } else if (focus->IsKindOf(RUNTIME_CLASS(MaterialTreeView))) {
  532. if(m_materialTreeView->CanCopy()) {
  533. enable = TRUE;
  534. }
  535. } else if (focus->IsKindOf(RUNTIME_CLASS(CRichEditCtrl))) {
  536. enable = TRUE;
  537. }
  538. }
  539. pCmdUI->Enable(enable);
  540. }
  541. /**
  542. * Enables a paste operation when a material or stage has been copied.
  543. */
  544. void MEMainFrame::OnEditPasteUpdate(CCmdUI *pCmdUI) {
  545. if(pCmdUI->m_pMenu == NULL) {
  546. pCmdUI->Enable(TRUE);
  547. return;
  548. }
  549. BOOL enable = FALSE;
  550. CWnd* focus = GetFocus();
  551. if(focus) {
  552. if (focus->IsKindOf(RUNTIME_CLASS(StageView))) {
  553. if(m_stageView->CanPaste()) {
  554. enable = TRUE;
  555. }
  556. } else if (focus->IsKindOf(RUNTIME_CLASS(MaterialTreeView))) {
  557. if(m_materialTreeView->CanPaste()) {
  558. enable = TRUE;
  559. }
  560. } else if (focus->IsKindOf(RUNTIME_CLASS(CRichEditCtrl))) {
  561. enable = TRUE;
  562. }
  563. }
  564. pCmdUI->Enable(enable);
  565. }
  566. /**
  567. * Enables a delete operation when a material or stage is selected.
  568. */
  569. void MEMainFrame::OnEditDeleteUpdate(CCmdUI *pCmdUI) {
  570. if(pCmdUI->m_pMenu == NULL) {
  571. pCmdUI->Enable(TRUE);
  572. return;
  573. }
  574. BOOL enable = FALSE;
  575. CWnd* focus = GetFocus();
  576. if(focus) {
  577. if (focus->IsKindOf(RUNTIME_CLASS(StageView))) {
  578. if(m_stageView->CanDelete()) {
  579. enable = TRUE;
  580. }
  581. } else if (focus->IsKindOf(RUNTIME_CLASS(MaterialTreeView))) {
  582. if(m_materialTreeView->CanDelete()) {
  583. enable = TRUE;
  584. }
  585. } else if (focus->IsKindOf(RUNTIME_CLASS(CRichEditCtrl))) {
  586. enable = TRUE;
  587. }
  588. }
  589. pCmdUI->Enable(enable);
  590. }
  591. /**
  592. * Enables a rename operation when a material, folder or stage is selected.
  593. */
  594. void MEMainFrame::OnEditRenameUpdate(CCmdUI *pCmdUI) {
  595. if(pCmdUI->m_pMenu == NULL) {
  596. pCmdUI->Enable(TRUE);
  597. return;
  598. }
  599. BOOL enable = FALSE;
  600. CWnd* focus = GetFocus();
  601. if(focus) {
  602. if (focus->IsKindOf(RUNTIME_CLASS(StageView))) {
  603. if(m_stageView->CanRename()) {
  604. enable = TRUE;
  605. }
  606. } else if (focus->IsKindOf(RUNTIME_CLASS(MaterialTreeView))) {
  607. if(m_materialTreeView->CanRename()) {
  608. enable = TRUE;
  609. }
  610. }
  611. }
  612. pCmdUI->Enable(enable);
  613. }
  614. /**
  615. * Opens the find dialog.
  616. */
  617. void MEMainFrame::OnEditFind() {
  618. if (m_find== NULL)
  619. {
  620. m_find = new FindDialog(this);
  621. m_find->Create();
  622. m_find->ShowWindow(SW_SHOW);
  623. }
  624. else
  625. m_find->SetActiveWindow();
  626. }
  627. /**
  628. * Performs a search with the previously selected search parameters.
  629. */
  630. void MEMainFrame::OnEditFindNext() {
  631. FindNext(NULL);
  632. }
  633. /**
  634. * Performs an undo operation.
  635. */
  636. void MEMainFrame::OnEditUndo() {
  637. //Check for undo operation on special windows
  638. CWnd* focus = GetFocus();
  639. if(focus) {
  640. if (focus->IsKindOf(RUNTIME_CLASS(CRichEditCtrl))) {
  641. m_materialEditView->m_textView.Undo();
  642. return;
  643. }
  644. }
  645. materialDocManager.Undo();
  646. }
  647. /**
  648. * Performs a redo operation.
  649. */
  650. void MEMainFrame::OnEditRedo() {
  651. //Check for redo operation on special windows
  652. CWnd* focus = GetFocus();
  653. if(focus) {
  654. if (focus->IsKindOf(RUNTIME_CLASS(CRichEditCtrl))) {
  655. m_materialEditView->m_textView.Redo();
  656. return;
  657. }
  658. }
  659. materialDocManager.Redo();
  660. }
  661. /**
  662. * Enables the undo menu item if an undo is available.
  663. */
  664. void MEMainFrame::OnEditUndoUpdate(CCmdUI *pCmdUI) {
  665. if(pCmdUI->m_pMenu == NULL) {
  666. pCmdUI->Enable(TRUE);
  667. return;
  668. }
  669. CWnd* focus = GetFocus();
  670. if(focus) {
  671. if (focus->IsKindOf(RUNTIME_CLASS(CRichEditCtrl))) {
  672. pCmdUI->Enable(m_materialEditView->m_textView.CanUndo());
  673. return;
  674. }
  675. }
  676. pCmdUI->Enable(materialDocManager.IsUndoAvailable());
  677. }
  678. /**
  679. * Enables the redo menu item if a redo is available.
  680. */
  681. void MEMainFrame::OnEditRedoUpdate(CCmdUI *pCmdUI) {
  682. if(pCmdUI->m_pMenu == NULL) {
  683. pCmdUI->Enable(TRUE);
  684. return;
  685. }
  686. CWnd* focus = GetFocus();
  687. if(focus) {
  688. if (focus->IsKindOf(RUNTIME_CLASS(CRichEditCtrl))) {
  689. pCmdUI->Enable(m_materialEditView->m_textView.CanRedo());
  690. return;
  691. }
  692. }
  693. pCmdUI->Enable(materialDocManager.IsRedoAvailable());
  694. }
  695. /**
  696. * Toggles between including the file into the material list and not.
  697. */
  698. void MEMainFrame::OnViewIncludeFile() {
  699. CMenu* mmenu = GetMenu();
  700. UINT state = mmenu->GetMenuState(ID_VIEW_INCLUDEFILENAME, MF_BYCOMMAND);
  701. ASSERT(state != 0xFFFFFFFF);
  702. if (state & MF_CHECKED) {
  703. mmenu->CheckMenuItem(ID_VIEW_INCLUDEFILENAME, MF_UNCHECKED | MF_BYCOMMAND);
  704. m_materialTreeView->InitializeMaterialList(false);
  705. } else {
  706. mmenu->CheckMenuItem(ID_VIEW_INCLUDEFILENAME, MF_CHECKED | MF_BYCOMMAND);
  707. m_materialTreeView->InitializeMaterialList(true);
  708. }
  709. }
  710. /**
  711. * Executes the reloadARBPrograms console command for convinience.
  712. */
  713. void MEMainFrame::OnReloadArbPrograms() {
  714. cmdSystem->BufferCommandText(CMD_EXEC_NOW, "reloadARBprograms");
  715. }
  716. /**
  717. * Executes the reloadImages command to reload images that have been changed outside
  718. * of the editor.
  719. */
  720. void MEMainFrame::OnReloadImages() {
  721. cmdSystem->BufferCommandText(CMD_EXEC_NOW, "reloadImages");
  722. }
  723. /**
  724. * Called by the find dialog when it is closing.
  725. */
  726. void MEMainFrame::CloseFind() {
  727. m_find = NULL;
  728. }
  729. /**
  730. * Begins a search based on the provided parameters or the previously used
  731. * parameters.
  732. */
  733. void MEMainFrame::FindNext(MaterialSearchData_t* search) {
  734. if(search) {
  735. searchData = *search;
  736. } else {
  737. if(!searchData.searched) {
  738. return;
  739. }
  740. }
  741. //The material tree controls the searching
  742. if(!m_materialTreeView->FindNextMaterial(&searchData)) {
  743. MessageBox(va("Unable to find '%s'.", searchData.searchText.c_str()), "Find");
  744. }
  745. searchData.searched = true;
  746. }
  747. /**
  748. * Called when the selected material has changed.
  749. * @param pMaterial The newly selected material.
  750. */
  751. void MEMainFrame::MV_OnMaterialSelectionChange(MaterialDoc* pMaterial) {
  752. }