2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
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.
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.
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/>.
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.
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.
26 ===========================================================================
29 #include "../../idlib/precompiled.h"
34 #include "EditViewDlg.h"
37 // CEditViewDlg dialog
39 IMPLEMENT_DYNAMIC(CEditViewDlg, CDialog)
40 CEditViewDlg::CEditViewDlg(CWnd* pParent /*=NULL*/)
41 : CDialog(CEditViewDlg::IDD, pParent)
46 CEditViewDlg::~CEditViewDlg() {
49 void CEditViewDlg::DoDataExchange(CDataExchange* pDX) {
50 CDialog::DoDataExchange(pDX);
51 DDX_Control(pDX, IDC_EDIT_INFO, editInfo);
55 static UINT FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
57 BEGIN_MESSAGE_MAP(CEditViewDlg, CDialog)
59 ON_BN_CLICKED(IDC_BUTTON_OPEN, OnBnClickedButtonOpen)
60 ON_BN_CLICKED(IDC_BUTTON_SAVE, OnBnClickedButtonSave)
63 ON_BN_CLICKED(IDC_BUTTON_GOTO, OnBnClickedButtonGoto)
64 ON_REGISTERED_MESSAGE(FindDialogMessage, OnFindDialogMessage)
68 // CEditViewDlg message handlers
70 void CEditViewDlg::OnSize(UINT nType, int cx, int cy) {
71 CDialog::OnSize(nType, cx, cy);
72 if (GetSafeHwnd() == NULL) {
77 CWnd *wnd = GetDlgItem(IDC_BUTTON_OPEN);
78 if (wnd == NULL || (wnd && wnd->GetSafeHwnd() == NULL)) {
81 wnd->GetWindowRect(crect);
82 wnd->SetWindowPos(NULL, 4, 4, crect.Width(), crect.Height(), SWP_SHOWWINDOW);
83 wnd = GetDlgItem(IDC_BUTTON_SAVE);
84 int left = 8 + crect.Width();
85 wnd->SetWindowPos(NULL, left, 4, crect.Width(), crect.Height(), SWP_SHOWWINDOW);
86 wnd = GetDlgItem(IDOK);
87 wnd->SetWindowPos(NULL, rect.Width() - crect.Width() - 4, 4, crect.Width(), crect.Height(), SWP_SHOWWINDOW);
88 editInfo.SetWindowPos(NULL, 4, 8 + crect.Height(), rect.Width() - 8, rect.Height() - crect.Height() * 2 - 16, SWP_SHOWWINDOW);
89 wnd = GetDlgItem(IDC_BUTTON_GOTO);
90 wnd->SetWindowPos(NULL, 4, rect.Height() - 4 - crect.Height(), crect.Width(), crect.Height(), SWP_SHOWWINDOW);
91 wnd = GetDlgItem(IDC_EDIT_GOTO);
92 wnd->SetWindowPos(NULL, 8 + crect.Width(), rect.Height() - 3 - crect.Height(), crect.Width() + 8, crect.Height() - 3, SWP_SHOWWINDOW);
93 wnd = GetDlgItem(IDC_STATIC_LINE);
94 wnd->SetWindowPos(NULL, 30 + crect.Width() * 2, rect.Height() - crect.Height(), crect.Width() * 2, crect.Height(), SWP_SHOWWINDOW);
95 wnd = GetDlgItem(IDC_EDIT_LINE);
96 wnd->SetWindowPos(NULL, 40 + crect.Width() * 3, rect.Height() - crect.Height(), crect.Width() + 8, crect.Height(), SWP_SHOWWINDOW);
99 void CEditViewDlg::ShowFindDlg() {
103 findDlg = new CFindReplaceDialog();
104 findDlg->Create(TRUE, findStr, NULL, FR_DOWN, this);
108 void CEditViewDlg::OnBnClickedButtonOpen() {
109 CPreviewDlg *dlg = NULL;
110 dlg = ((mode == MATERIALS) ? CEntityDlg::ShowMaterialChooser() : CEntityDlg::ShowGuiChooser());
112 if (mode == MATERIALS) {
113 const idMaterial *mat = declManager->FindMaterial(dlg->mediaName);
114 SetMaterialInfo(mat->GetName(), mat->GetFileName(), mat->GetLineNum());
116 SetGuiInfo(dlg->mediaName);
121 void CEditViewDlg::OnBnClickedButtonSave() {
122 if (fileName.Length()) {
124 editInfo.GetWindowText(text);
125 fileSystem->WriteFile(fileName, text.GetBuffer(0), text.GetLength(), "fs_devpath");
126 if (mode == MATERIALS) {
127 declManager->Reload( false );
129 uiManager->Reload(false);
134 void CEditViewDlg::UpdateEditPreview() {
135 if (GetSafeHwnd() && editInfo.GetSafeHwnd()) {
136 editInfo.SetWindowText(editText);
137 editInfo.LineScroll(line);
138 int cindex = editInfo.LineIndex(line);
139 int len = editInfo.LineLength(line);
140 editInfo.SetSel(cindex, cindex);
141 mediaPreview.SetMode((mode == MATERIALS) ? CMediaPreviewDlg::MATERIALS : CMediaPreviewDlg::GUIS);
142 mediaPreview.SetMedia((mode == MATERIALS) ? matName : fileName);
143 SetWindowText(va("Editing %s in file <%s>", (mode == MATERIALS) ? matName.c_str() : fileName.c_str(), fileName.c_str()));
148 BOOL CEditViewDlg::OnInitDialog() {
149 CDialog::OnInitDialog();
151 mediaPreview.Create(IDD_DIALOG_EDITPREVIEW, this);
152 mediaPreview.ShowWindow(SW_SHOW);
155 LONG lSize = sizeof(rct);
156 if (LoadRegistryInfo("Radiant::EditViewWindow", &rct, &lSize)) {
157 SetWindowPos(NULL, rct.left, rct.top, rct.Width(), rct.Height(), SWP_SHOWWINDOW);
160 editInfo.SetTabStops();
161 editInfo.SetLimitText(1024 * 1024);
165 SetTimer(1, 250, NULL);
167 return TRUE; // return TRUE unless you set the focus to a control
168 // EXCEPTION: OCX Property Pages should return FALSE
171 void CEditViewDlg::OnDestroy() {
175 SaveRegistryInfo("Radiant::EditViewWindow", &rct, sizeof(rct));
178 CDialog::OnDestroy();
181 void CEditViewDlg::SetMaterialInfo(const char *name, const char *file, int _line) {
187 str = fileSystem->OSPathToRelativePath( file );
188 int size = fileSystem->ReadFile( str, &buf );
196 editText = (char*)buf;
197 fileSystem->FreeFile(buf);
202 void CEditViewDlg::SetGuiInfo(const char *name) {
206 int size = fileSystem->ReadFile(name, &buf, NULL);
209 editText = (char*)buf;
210 fileSystem->FreeFile(buf);
215 void CEditViewDlg::OnTimer(UINT nIDEvent) {
216 CDialog::OnTimer(nIDEvent);
217 CWnd *wnd = GetDlgItem(IDC_EDIT_LINE);
220 editInfo.GetSel(start, end);
221 wnd->SetWindowText(va("%i",editInfo.LineFromChar(start)));
226 void CEditViewDlg::OnBnClickedButtonGoto() {
227 CWnd *wnd = GetDlgItem(IDC_EDIT_GOTO);
230 wnd->GetWindowText(str);
231 if (str.GetLength()) {
233 editInfo.SetSel(0, 0);
234 editInfo.LineScroll(l);
235 int cindex = editInfo.LineIndex(l);
236 int len = editInfo.LineLength(l);
237 editInfo.SetSel(cindex, cindex);
238 editInfo.RedrawWindow();
244 BOOL CEditViewDlg::PreTranslateMessage(MSG* pMsg) {
246 if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == 's' || pMsg->wParam == 'S') && GetAsyncKeyState(VK_CONTROL) & 0x8000) {
247 OnBnClickedButtonSave();
251 if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == 'o' || pMsg->wParam == 'O') && GetAsyncKeyState(VK_CONTROL) & 0x8000) {
252 OnBnClickedButtonOpen();
256 if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == 'f' || pMsg->wParam == 'F') && GetAsyncKeyState(VK_CONTROL) & 0x8000) {
261 if (pMsg->hwnd == editInfo.GetSafeHwnd() && (pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_TAB)) {
262 // get the char index of the caret position
263 int nPos = LOWORD(editInfo.CharFromPos(editInfo.GetCaretPos()));
265 editInfo.SetSel(nPos, nPos);
266 // then replace that selection with a TAB
267 editInfo.ReplaceSel("\t", TRUE);
271 return CDialog::PreTranslateMessage(pMsg);
274 LRESULT CEditViewDlg::OnFindDialogMessage(WPARAM wParam, LPARAM lParam) {
275 if (findDlg == NULL) {
279 if (findDlg->IsTerminating()) {
284 // If the FR_FINDNEXT flag is set,
285 // call the application-defined search routine
286 // to search for the requested string.
287 if(findDlg->FindNext()) {
288 //read data from dialog
289 findStr = findDlg->GetFindString().GetBuffer(0);
291 editInfo.GetWindowText(str);
294 editInfo.GetSel(start, end);
295 start = editText.Find(findStr, false, end);
297 editInfo.SetSel(start, start + findStr.Length());
298 editInfo.Invalidate();
299 editInfo.RedrawWindow();