-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathCScriptEditor.cpp
174 lines (148 loc) · 4.54 KB
/
CScriptEditor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Copyright (C) FlatGlobus([email protected]) All rights reserved.
//
// This file is a part of the WTLBuilder.
// The use and distribution terms for this software are covered by the
// Microsoft Public License (http://opensource.org/licenses/MS-PL)
// which can be found in the file MS-PL.txt at the root folder.
//////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "CScriptEditor.h"
#include "cfile.h"
#include "_util.h"
#include "Path.h"
//////////////////////////////////////////////////////////////////////////
const UINT CScriptEditor::_controlsToClip[] =
{
//{{WTLBUILDER_CTRLTOCLIP
//}}WTLBUILDER_CTRLTOCLIP
0
};
//////////////////////////////////////////////////////////////////////////
CScriptEditor::CScriptEditor(void):scriptError(NULL)
//{{WTLBUILDER_CONSTRUCTOR
//}}WTLBUILDER_CONSTRUCTOR
{
}
CScriptEditor::~CScriptEditor(void)
{
//{{WTLBUILDER_MEMBER_DESTRUCTION
//}}WTLBUILDER_MEMBER_DESTRUCTION
}
BOOL CScriptEditor::PreTranslateMessage(MSG* pMsg)
{
m_toolTip.RelayEvent(pMsg);
return thisClass::PreTranslateMessage(pMsg);
}
LRESULT CScriptEditor::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
m_toolTip.Create(m_hWnd);
//{{WTLBUILDER_MEMBER_CREATION
m_formFont.CreateFont(-12,0,0,0,FW_NORMAL,false,false,false,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_DONTCARE,_TEXT("MS Sans Serif"));
SetFont((HFONT)m_formFont);
ResizeClient(675,513);
SetWindowText(_TEXT("FrameWindowImpl0"));
m_edit.Create(m_hWnd,CRect(0,0,675,490),_TEXT(""),WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_HSCROLL|WS_TABSTOP|ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL|ES_WANTRETURN,0,IDC_EDIT);
m_edit.SetFont((HFONT)m_formFont);
m_statusbarctrl1.Create(m_hWnd,CRect(0,490,675,513),NULL,WS_CHILD|WS_VISIBLE|WS_TABSTOP,0,IDC_CSCRIPTEDITOR_STATUSBARCTRL1);
m_statusbarctrl1.SetFont((HFONT)m_formFont);
Menu2.LoadMenu(IDR_SCRIPT_EDITOR);
//}}WTLBUILDER_MEMBER_CREATION
//{{WTLBUILDER_POST_CREATION
SetMenu(Menu2);
m_hWndClient=(HWND)m_edit;
m_hWndStatusBar=(HWND)m_statusbarctrl1;
m_edit.SetFocus();
//}}WTLBUILDER_POST_CREATION
//{{WTLBUILDER_TABSTOP
//}}WTLBUILDER_TABSTOP
//m_hAccel = AtlLoadAccelerators(IDR_SCRIPT_EDITOR);
InitLayout();
return 0;
}
BOOL CScriptEditor::Create(HWND Parent,CScriptError *se)
{
thisClass::Create(Parent);
if(se)
{
scriptError = se;
SetWindowText(MakeString("Script Editor - [ %s ]",(LPCTSTR)scriptError->GetFile()));
CString text = LoadString(scriptError->GetFile());
int count = text.Replace("\n","\r\n");
m_edit.SetWindowText(text);
int idx = m_edit.LineIndex(scriptError->GetLine()-1);
idx+=scriptError->GetPos();
m_edit.SetSel(idx,idx);
}
return TRUE;
}
void CScriptEditor::DefineLayout()
{
//{{WTLBUILDER_ATTACH_CONTROLS
//}}WTLBUILDER_ATTACH_CONTROLS
}
void CScriptEditor::InitLayout()
{
//{{WTLBUILDER_INITLAYOUT
_minClientSize.cx = 675;
_minClientSize.cy = 513;
_prevClientSize = _minClientSize;
_minWindowSize.cx = 683;
_minWindowSize.cy = 567;
SetNPositions(1);
DefineLayout();
//}}WTLBUILDER_INITLAYOUT
//SetScrollSize(_minClientSize);
}
void CScriptEditor::GetDialogRect(LPRECT r)
{
GetClientRect(r);
if (r->right < m_sizeAll.cx)
{
r->right = m_sizeAll.cx;
}
if (r->bottom < m_sizeAll.cy)
{
r->bottom = m_sizeAll.cy;
}
}
void CScriptEditor::GetOffset(LPPOINT offset)
{
*offset = m_ptOffset;
}
void CScriptEditor::DoPaint(CDCHandle /*dc*/)
{
}
LRESULT CScriptEditor::OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
bHandled = FALSE;
return TRUE;
}
LRESULT CScriptEditor::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
bHandled = TRUE;
return 0;
}
LRESULT CScriptEditor::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
DestroyWindow();
return 0;
}
LRESULT CScriptEditor::OnFileSave(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CString text;
m_edit.GetWindowText(text);
SaveString(scriptError->GetFile(),text);
return 0;
}
LRESULT CScriptEditor::OnFileSaveAs(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
static _TCHAR Filter[] = _T("JScript Files (*.js)\0*.js\0");
CPath fn((LPCTSTR)scriptError->GetFile());
CFileDialog filedlg(FALSE,_T("*.js"),(LPCTSTR)fn,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST,Filter);
if(filedlg.DoModal(GetDesktopWindow())!=IDOK)
return 0;
CString text;
m_edit.GetWindowText(text);
SaveString(filedlg.m_szFileName,text);
return 0;
}