doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EditViewDlg.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 "qe3.h"
33 #include "Radiant.h"
34 #include "EditViewDlg.h"
35 
36 
37 // CEditViewDlg dialog
38 
39 IMPLEMENT_DYNAMIC(CEditViewDlg, CDialog)
40 CEditViewDlg::CEditViewDlg(CWnd* pParent /*=NULL*/)
41  : CDialog(CEditViewDlg::IDD, pParent)
42 {
43  findDlg = NULL;
44 }
45 
47 }
48 
49 void CEditViewDlg::DoDataExchange(CDataExchange* pDX) {
50  CDialog::DoDataExchange(pDX);
51  DDX_Control(pDX, IDC_EDIT_INFO, editInfo);
52 }
53 
54 
55 static UINT FindDialogMessage = ::RegisterWindowMessage(FINDMSGSTRING);
56 
57 BEGIN_MESSAGE_MAP(CEditViewDlg, CDialog)
58  ON_WM_SIZE()
59  ON_BN_CLICKED(IDC_BUTTON_OPEN, OnBnClickedButtonOpen)
60  ON_BN_CLICKED(IDC_BUTTON_SAVE, OnBnClickedButtonSave)
61  ON_WM_DESTROY()
62  ON_WM_TIMER()
63  ON_BN_CLICKED(IDC_BUTTON_GOTO, OnBnClickedButtonGoto)
64  ON_REGISTERED_MESSAGE(FindDialogMessage, OnFindDialogMessage)
65 END_MESSAGE_MAP()
66 
67 
68 // CEditViewDlg message handlers
69 
70 void CEditViewDlg::OnSize(UINT nType, int cx, int cy) {
71  CDialog::OnSize(nType, cx, cy);
72  if (GetSafeHwnd() == NULL) {
73  return;
74  }
75  CRect rect, crect;
76  GetClientRect(rect);
77  CWnd *wnd = GetDlgItem(IDC_BUTTON_OPEN);
78  if (wnd == NULL || (wnd && wnd->GetSafeHwnd() == NULL)) {
79  return;
80  }
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);
97 }
98 
100  if (findDlg) {
101  return;
102  }
103  findDlg = new CFindReplaceDialog();
104  findDlg->Create(TRUE, findStr, NULL, FR_DOWN, this);
105 
106 }
107 
109  CPreviewDlg *dlg = NULL;
111  if (dlg) {
112  if (mode == MATERIALS) {
113  const idMaterial *mat = declManager->FindMaterial(dlg->mediaName);
114  SetMaterialInfo(mat->GetName(), mat->GetFileName(), mat->GetLineNum());
115  } else {
116  SetGuiInfo(dlg->mediaName);
117  }
118  }
119 }
120 
122  if (fileName.Length()) {
123  CString text;
124  editInfo.GetWindowText(text);
125  fileSystem->WriteFile(fileName, text.GetBuffer(0), text.GetLength(), "fs_devpath");
126  if (mode == MATERIALS) {
127  declManager->Reload( false );
128  } else {
129  uiManager->Reload(false);
130  }
131  }
132 }
133 
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);
143  SetWindowText(va("Editing %s in file <%s>", (mode == MATERIALS) ? matName.c_str() : fileName.c_str(), fileName.c_str()));
144  editInfo.SetFocus();
145  }
146 }
147 
149  CDialog::OnInitDialog();
150 
151  mediaPreview.Create(IDD_DIALOG_EDITPREVIEW, this);
152  mediaPreview.ShowWindow(SW_SHOW);
153 
154  CRect rct;
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);
158  }
159 
160  editInfo.SetTabStops();
161  editInfo.SetLimitText(1024 * 1024);
162 
164 
165  SetTimer(1, 250, NULL);
166 
167  return TRUE; // return TRUE unless you set the focus to a control
168  // EXCEPTION: OCX Property Pages should return FALSE
169 }
170 
172  if (GetSafeHwnd()) {
173  CRect rct;
174  GetWindowRect(rct);
175  SaveRegistryInfo("Radiant::EditViewWindow", &rct, sizeof(rct));
176  }
177 
178  CDialog::OnDestroy();
179 }
180 
181 void CEditViewDlg::SetMaterialInfo(const char *name, const char *file, int _line) {
182  idStr str;
183  void *buf;
184  fileName = "";
185  matName = "";
186  line = 0;
187  str = fileSystem->OSPathToRelativePath( file );
188  int size = fileSystem->ReadFile( str, &buf );
189  if (size > 0) {
190  fileName = str;
191  matName = name;
192  line = _line - 1;
193  if (line < 0) {
194  line = 0;
195  }
196  editText = (char*)buf;
197  fileSystem->FreeFile(buf);
198  }
200 }
201 
202 void CEditViewDlg::SetGuiInfo(const char *name) {
203  fileName = "";
204  line = 0;
205  void *buf;
206  int size = fileSystem->ReadFile(name, &buf, NULL);
207  if (size > 0) {
208  fileName = name;
209  editText = (char*)buf;
210  fileSystem->FreeFile(buf);
211  }
213 }
214 
215 void CEditViewDlg::OnTimer(UINT nIDEvent) {
216  CDialog::OnTimer(nIDEvent);
217  CWnd *wnd = GetDlgItem(IDC_EDIT_LINE);
218  if (wnd) {
219  int start, end;
220  editInfo.GetSel(start, end);
221  wnd->SetWindowText(va("%i",editInfo.LineFromChar(start)));
222  }
223 
224 }
225 
227  CWnd *wnd = GetDlgItem(IDC_EDIT_GOTO);
228  if (wnd) {
229  CString str;
230  wnd->GetWindowText(str);
231  if (str.GetLength()) {
232  int l = atoi(str);
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();
239  editInfo.SetFocus();
240  }
241  }
242 }
243 
245 
246  if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == 's' || pMsg->wParam == 'S') && GetAsyncKeyState(VK_CONTROL) & 0x8000) {
248  return TRUE;
249  }
250 
251  if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == 'o' || pMsg->wParam == 'O') && GetAsyncKeyState(VK_CONTROL) & 0x8000) {
253  return TRUE;
254  }
255 
256  if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == 'f' || pMsg->wParam == 'F') && GetAsyncKeyState(VK_CONTROL) & 0x8000) {
257  ShowFindDlg();
258  return TRUE;
259  }
260 
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()));
264  // select zero chars
265  editInfo.SetSel(nPos, nPos);
266  // then replace that selection with a TAB
267  editInfo.ReplaceSel("\t", TRUE);
268  return TRUE;
269  }
270 
271  return CDialog::PreTranslateMessage(pMsg);
272 }
273 
274 LRESULT CEditViewDlg::OnFindDialogMessage(WPARAM wParam, LPARAM lParam) {
275  if (findDlg == NULL) {
276  return 0;
277  }
278 
279  if (findDlg->IsTerminating()) {
280  findDlg = NULL;
281  return 0;
282  }
283 
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);
290  CString str;
291  editInfo.GetWindowText(str);
292  editText = str;
293  int start, end;
294  editInfo.GetSel(start, end);
295  start = editText.Find(findStr, false, end);
296  if (start >= 0) {
297  editInfo.SetSel(start, start + findStr.Length());
298  editInfo.Invalidate();
299  editInfo.RedrawWindow();
300  }
301  }
302  return 0;
303 }
int GetLineNum(void) const
Definition: DeclManager.h:168
afx_msg LRESULT OnFindDialogMessage(WPARAM wParam, LPARAM lParam)
afx_msg void OnBnClickedButtonSave()
#define IDC_BUTTON_OPEN
void ShowFindDlg()
Definition: EditViewDlg.cpp:99
void SetMode(int _mode)
virtual ~CEditViewDlg()
Definition: EditViewDlg.cpp:46
const char * GetFileName(void) const
Definition: DeclManager.h:171
CONST PIXELFORMATDESCRIPTOR UINT
Definition: win_qgl.cpp:47
virtual int ReadFile(const char *relativePath, void **buffer, ID_TIME_T *timestamp=NULL)=0
int Length(void) const
Definition: Str.h:702
virtual BOOL PreTranslateMessage(MSG *pMsg)
idFileSystem * fileSystem
Definition: FileSystem.cpp:500
idStr fileName
Definition: EditViewDlg.h:59
CFindReplaceDialog * findDlg
Definition: EditViewDlg.h:56
const char * GetName(void) const
Definition: DeclManager.h:140
virtual BOOL OnInitDialog()
idStr mediaName
Definition: PreviewDlg.h:53
afx_msg void OnTimer(UINT nIDEvent)
afx_msg void OnDestroy()
virtual const idMaterial * FindMaterial(const char *name, bool makeDefault=true)=0
GLenum GLsizei len
Definition: glext.h:3472
bool LoadRegistryInfo(const char *pszName, void *pvBuf, long *plSize)
Definition: Radiant.cpp:405
idUserInterfaceManager * uiManager
virtual void FreeFile(void *buffer)=0
#define BOOL
Definition: mprintf.c:71
CEdit editInfo
Definition: EditViewDlg.h:64
virtual int WriteFile(const char *relativePath, const void *buffer, int size, const char *basePath="fs_savepath")=0
list l
Definition: prepare.py:17
virtual void DoDataExchange(CDataExchange *pDX)
Definition: EditViewDlg.cpp:49
idStr editText
Definition: EditViewDlg.h:61
afx_msg void OnBnClickedButtonOpen()
GLuint GLuint end
Definition: glext.h:2845
#define NULL
Definition: Lib.h:88
#define IDC_EDIT_LINE
void SetGuiInfo(const char *name)
GLint mode
Definition: glext.h:4165
void SetMedia(const char *_media)
idStr findStr
Definition: EditViewDlg.h:62
virtual void Reload(bool force)=0
bool SaveRegistryInfo(const char *pszName, void *pvBuf, long lSize)
Definition: Radiant.cpp:398
int Find(const char c, int start=0, int end=-1) const
Definition: Str.h:874
void UpdateEditPreview()
#define IDC_EDIT_GOTO
idDeclManager * declManager
afx_msg void OnBnClickedButtonGoto()
long LONG
static CPreviewDlg * ShowMaterialChooser()
Definition: EntityDlg.cpp:841
virtual void Reload(bool all)=0
static CPreviewDlg * ShowGuiChooser()
Definition: EntityDlg.cpp:814
const GLcharARB * name
Definition: glext.h:3629
GLsizeiptr size
Definition: glext.h:3112
Definition: Str.h:116
#define IDC_BUTTON_SAVE
#define IDD_DIALOG_EDITPREVIEW
const char * c_str(void) const
Definition: Str.h:487
#define IDC_BUTTON_GOTO
#define IDC_EDIT_INFO
#define IDC_STATIC_LINE
#define TRUE
Definition: mprintf.c:69
char * va(const char *fmt,...)
Definition: Str.cpp:1568
virtual const char * OSPathToRelativePath(const char *OSPath)=0
idStr matName
Definition: EditViewDlg.h:60
void SetMaterialInfo(const char *name, const char *file, int line)
GLuint start
Definition: glext.h:2845
CMediaPreviewDlg mediaPreview
Definition: EditViewDlg.h:57