29 #include "../../idlib/precompiled.h"
32 #include "../../sys/win32/rc/Common_resource.h"
33 #include "../../sys/win32/rc/DeclEditor_resource.h"
35 #include "../comafx/DialogGoToLine.h"
36 #include "../comafx/CPathTreeCtrl.h"
40 #ifdef ID_DEBUG_MEMORY
49 static UINT FindDialogMessage = ::RegisterWindowMessage( FINDMSGSTRING );
53 { IDOK,
"save decl" },
54 { IDCANCEL,
"cancel" },
70 , matchWholeWords(false)
90 CDialog::DoDataExchange(pDX);
105 if ( WM_KEYFIRST <= pMsg->message && pMsg->message <= WM_KEYLAST ) {
110 return CWnd::PreTranslateMessage(pMsg);
127 if ( token ==
"{" ) {
129 }
else if ( token ==
"}" ) {
135 MessageBox(
"Missing opening brace!",
va(
"Error saving %s",
decl->
GetFileName() ), MB_OK | MB_ICONERROR );
139 MessageBox(
"Missing closing brace!",
va(
"Error saving %s",
decl->
GetFileName() ), MB_OK | MB_ICONERROR );
151 int line,
column, character;
166 int numCharsPerLine = 0;
167 int maxCharsPerLine = 0;
209 char *localDeclText = (
char *)_alloca( ( decl->
GetTextLength() + 1 ) *
sizeof(
char ) );
210 decl->
GetText( localDeclText );
211 declText = localDeclText;
215 declText.
Replace(
"\n",
"\r" );
216 declText.
Replace(
"\v",
"\r" );
222 for(
const char *ptr = declText.
c_str(); *ptr; ptr++ ) {
223 if ( *ptr ==
'\r' ) {
224 if ( numCharsPerLine > maxCharsPerLine ) {
225 maxCharsPerLine = numCharsPerLine;
229 }
else if ( *ptr ==
'\t' ) {
230 numCharsPerLine += TAB_SIZE;
239 rect.right = rect.left + maxCharsPerLine * FONT_WIDTH + 32;
241 rect.bottom = rect.top + numLines * (FONT_HEIGHT+8) + 24 + 56;
244 }
else if ( rect.right - rect.left > 1024 ) {
245 rect.right = rect.left + 1024;
249 }
else if ( rect.bottom - rect.top > 768 ) {
250 rect.bottom = rect.top + 768;
271 CDialog::OnInitDialog();
277 statusBar.CreateEx( SBARS_SIZEGRIP, WS_CHILD | WS_VISIBLE | CBRS_BOTTOM,
initialRect,
this, AFX_IDW_STATUS_BAR );
283 EnableToolTips(
TRUE );
296 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
297 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
304 ON_COMMAND(ID_EDIT_FIND, OnEditFind)
305 ON_COMMAND(ID_EDIT_REPLACE, OnEditReplace)
308 ON_REGISTERED_MESSAGE(FindDialogMessage, OnFindDialogMessage)
310 ON_NOTIFY(EN_MSGFILTER, IDC_DECLEDITOR_EDIT_TEXT, OnEnInputEdit)
312 ON_BN_CLICKED(IDOK, OnBnClickedOk)
313 ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
325 CDialog::OnActivate( nState, pWndOther, bMinimized );
343 CDialog::OnSetFocus( pOldWnd );
352 return CDialog::OnDestroy();
361 if ( GetSafeHwnd() ) {
363 GetWindowRect( rct );
366 CDialog::OnMove( x, y );
374 #define BORDER_SIZE 0
375 #define BUTTON_SPACE 4
376 #define TOOLBAR_HEIGHT 24
379 CRect clientRect, rect;
383 CDialog::OnSize( nType, cx, cy );
385 GetClientRect( clientRect );
391 rect.bottom = clientRect.Height() - 56;
392 declEdit.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
397 int width = rect.Width();
398 int height = rect.Height();
403 testButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
408 int width = rect.Width();
409 int height = rect.Height();
414 okButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
419 int width = rect.Width();
420 int height = rect.Height();
425 cancelButton.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
429 rect.left = clientRect.Width() - 2;
430 rect.top = clientRect.Height() - 2;
431 rect.right = clientRect.Width() - 2;
432 rect.bottom = clientRect.Height() - 2;
433 statusBar.MoveWindow( rect.left, rect.top, rect.Width(), rect.Height() );
436 UnlockWindowUpdate();
456 CDialog::OnSizing( nSide, lpRect );
458 if ( ( nSide - 1 ) % 3 == 0 ) {
459 if ( lpRect->right - lpRect->left <
initialRect.Width() ) {
460 lpRect->left = lpRect->right -
initialRect.Width();
462 }
else if ( ( nSide - 2 ) % 3 == 0 ) {
463 if ( lpRect->right - lpRect->left <
initialRect.Width() ) {
464 lpRect->right = lpRect->left +
initialRect.Width();
467 if ( nSide >= 3 && nSide <= 5 ) {
468 if ( lpRect->bottom - lpRect->top <
initialRect.Height() ) {
469 lpRect->top = lpRect->bottom -
initialRect.Height();
471 }
else if ( nSide >= 6 && nSide <= 9 ) {
472 if ( lpRect->bottom - lpRect->top <
initialRect.Height() ) {
473 lpRect->bottom = lpRect->top +
initialRect.Height();
487 if ( goToLineDlg.DoModal() != IDOK ) {
500 CString selText =
declEdit.GetSelText();
501 if ( selText.GetLength() ) {
507 findDlg =
new CFindReplaceDialog();
521 AfxMessageBox(
"The specified text was not found.", MB_OK | MB_ICONINFORMATION, 0 );
532 CString selText =
declEdit.GetSelText();
533 if ( selText.GetLength() ) {
539 findDlg =
new CFindReplaceDialog();
554 if (
findDlg->IsTerminating() ) {
568 if (
findDlg->ReplaceCurrent() ) {
569 long selStart, selEnd;
573 declEdit.GetSel( selStart, selEnd );
574 if ( selEnd > selStart ) {
586 if ( numReplaces == 0 ) {
587 AfxMessageBox(
"The specified text was not found.", MB_OK | MB_ICONINFORMATION, 0 );
589 AfxMessageBox(
va(
"Replaced %d occurances.", numReplaces ), MB_OK | MB_ICONINFORMATION, 0 );
612 MSGFILTER *msgFilter = (MSGFILTER *)pNMHDR;
614 if ( msgFilter->msg != 512 && msgFilter->msg != 33 ) {
635 declText.
Replace(
"\r",
"\r\n" );
636 declText.
Replace(
"\v",
"\r\n" );
638 declText.
Insert(
"\r\n\r\n", 0 );
645 char *oldDeclText = (
char *)_alloca( (
decl->
GetTextLength() + 1 ) *
sizeof(
char ) );
672 declText.
Replace(
"\r",
"\r\n" );
673 declText.
Replace(
"\v",
"\r\n" );
675 declText.
Insert(
"\r\n\r\n", 0 );
683 if ( MessageBox(
va(
"Declaration file %s has been modified outside of the editor.\r\nReload declarations and save?",
decl->
GetFileName() ),
684 va(
"Warning saving: %s",
decl->
GetFileName() ), MB_OKCANCEL | MB_ICONERROR ) != IDOK ) {
693 MessageBox(
va(
"Couldn't save: %s.\r\nMake sure the declaration file is not read-only.",
decl->
GetFileName() ),
710 if ( MessageBox(
"Cancel changes?",
"Cancel", MB_YESNO | MB_ICONQUESTION ) != IDYES ) {
int GetLineNum(void) const
BOOL DefaultOnToolTipNotify(const toolTip_t *toolTips, UINT id, NMHDR *pNMHDR, LRESULT *pResult)
bool ReplaceSourceFileText(void)
void StripLeading(const char c)
const char * GetFileName(void) const
afx_msg void OnEditFind()
CONST PIXELFORMATDESCRIPTOR UINT
void GetText(idStr &text) const
void SetStringColor(const COLORREF color, const COLORREF altColor=-1)
#define ID_DECLEDITOR_FIND_NEXT
void SetRange(int firstLine, int lastLine)
afx_msg void OnEditGoToLine()
static toolTip_t toolTips[]
void StripTrailing(const char c)
void UpdateStatusBar(void)
#define IDR_ACCELERATOR_DECLEDITOR
bool FindNext(const char *find, bool matchCase, bool matchWholeWords, bool searchForward)
bool SourceFileChanged(void) const
const char * GetName(void) const
void DeclBrowserReloadDeclarations(void)
CSyntaxRichEditCtrl declEdit
afx_msg BOOL OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult)
virtual BOOL OnInitDialog()
afx_msg void OnSize(UINT nType, int cx, int cy)
virtual ~DialogDeclEditor()
afx_msg void OnSizing(UINT nSide, LPRECT lpRect)
void SetText(const char *text)
bool TestDecl(const idStr &declText)
afx_msg void OnEditFindNext()
declType_t GetType(void) const
afx_msg void OnBnClickedOk()
afx_msg void OnBnClickedCancel()
virtual void DoDataExchange(CDataExchange *pDX)
void GetCursorPos(int &line, int &column, int &character) const
afx_msg void OnMove(int x, int y)
void Insert(const char a, int index)
virtual void Reload(bool force)=0
#define IDC_DECLEDITOR_EDIT_TEXT
virtual void Printf(const char *fmt,...) id_attribute((format(printf
int LoadMemory(const char *ptr, int length, const char *name, int startLine=1)
afx_msg void OnEnInputEdit(NMHDR *pNMHDR, LRESULT *pResult)
void LoadDecl(idDecl *decl)
GLenum GLsizei GLsizei height
void SetText(const char *text)
virtual const char * GetDeclNameFromType(declType_t type) const =0
idDeclManager * declManager
afx_msg void OnEnChangeEdit(NMHDR *pNMHDR, LRESULT *pResult)
#define ID_DECLEDITOR_GOTOLINE
#define IDC_DECLEDITOR_BUTTON_TEST
afx_msg void OnBnClickedTest()
afx_msg void OnSetFocus(CWnd *pOldWnd)
virtual const idDecl * DeclByIndex(declType_t type, int index, bool forceParse=true)=0
void Append(const char a)
CFindReplaceDialog * findDlg
afx_msg LRESULT OnFindDialogMessage(WPARAM wParam, LPARAM lParam)
const char * c_str(void) const
void GetText(char *text) const
char * va(const char *fmt,...)
GLenum GLenum GLvoid GLvoid * column
void Replace(const char *old, const char *nw)
virtual BOOL PreTranslateMessage(MSG *pMsg)
afx_msg void OnEditReplace()
int ReadToken(idToken *token)
bool LoadKeyWordsFromFile(const char *fileName)
int GetTextLength(void) const
int ReplaceAll(const char *find, const char *replace, bool matchCase, bool matchWholeWords)