-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAW_SEditor.pas
193 lines (155 loc) · 4.75 KB
/
AW_SEditor.pas
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
unit aw_SEditor;
{
The contents of this file are subject to the Mozilla Public License Version 1.0 (the
"License"); you may not use this file except in compliance with the License. You may
obtain a copy of the License at http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
WARRANTY OF ANY KIND, either express or implied. See the License for the
specific language governing rights and limitations under the License.
The Original Code is the ActiveX Scripting Components.
The Initial Developer of the Original Code is Alexander Wingrove <[email protected]>.
Portions created by Alexander Wingrove are Copyright (C) 1999 Alexander Wingrove.
All Rights Reserved.
Contributor(s): <none>
}
{
unit: aw_SEditor
version: 1.01, 17/06/99
components:
TawScriptEditorForm
}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls, Menus;
type
{ TawScriptEditorForm }
TawScriptEditorForm = class(TForm)
Memo: TMemo;
StatusPanel: TPanel;
ScriptStatusBar: TStatusBar;
Panel2: TPanel;
LanguageEdit: TEdit;
DummyMenu: TMainMenu;
EditMenu: TMenuItem;
MI_SelectAll: TMenuItem;
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormCreate(Sender: TObject);
procedure SetChange(Sender: TObject);
procedure MemoKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure MemoClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure MI_SelectAllClick(Sender: TObject);
procedure FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
FResult: integer;
Row, Col: cardinal;
procedure UpdateCharPos;
protected
{ Protected declarations }
procedure Save;
public
{ Public declarations }
procedure Open(const Script, Language: string);
end;
var
awScriptEditorForm: TawScriptEditorForm;
implementation
{$R *.DFM}
uses
aw_SCtrl;
{ TawScriptEditorForm }
procedure TawScriptEditorForm.FormCreate(Sender: TObject);
var
l_tstop: cardinal;
begin
// set memo's tabstop
l_tstop := 16; // 4 chars
SendMessage(Memo.Handle, EM_SETTABSTOPS, 1, cardinal(@l_tstop));
FResult := mrCancel;
end;
procedure TawScriptEditorForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
l_res: Word;
begin
if (Memo.Modified) or (LanguageEdit.Modified) then
l_res := MessageDlg('Save changes?', mtConfirmation, mbYesNoCancel, 0)
else
// nothing modified, so just exit
l_res := mrNo;
// save if they said yes
if l_res = mrYes then
begin
Save;
FResult := mrOK;
end;
// let them out unless they picked cancel
CanClose := (l_res <> mrCancel);
end;
procedure TawScriptEditorForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
ModalResult := FResult;
end;
{
********************************************************************************
* Util procedures
********************************************************************************
}
procedure TawScriptEditorForm.Open(const Script, Language: string);
begin
LanguageEdit.Text := Language;
Memo.Text := Script;
Memo.SelStart := 0;
UpdateCharPos;
ScriptStatusBar.Panels[1].Text := '';
end;
procedure TawScriptEditorForm.Save;
begin
with TawScriptEditor(Owner) do
begin
Code := Memo.Lines;
Language := LanguageEdit.Text;
if Assigned(OnChange) then
OnChange(Owner);
end;
end;
{
********************************************************************************
* UI procedures
********************************************************************************
}
procedure TawScriptEditorForm.UpdateCharPos;
begin
// send Windows messages to retreive row and col info
Row := SendMessage(Memo.Handle, EM_LINEFROMCHAR, -1, 0);
Col := Memo.SelStart - SendMessage(Memo.Handle, EM_LINEINDEX, Row, 0);
ScriptStatusBar.Panels[0].Text := 'Ln '+IntToStr(Row+1)+', Char '+IntToStr(Col+1);
end;
// called by both memo and lang. edit
procedure TawScriptEditorForm.SetChange(Sender: TObject);
begin
ScriptStatusBar.Panels[1].Text := 'Modified';
end;
procedure TawScriptEditorForm.MemoKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
UpdateCharPos;
end;
procedure TawScriptEditorForm.MemoClick(Sender: TObject);
begin
UpdateCharPos;
end;
procedure TawScriptEditorForm.MI_SelectAllClick(Sender: TObject);
begin
Memo.SelStart := 0;
Memo.SelLength := Length(Memo.Text)+1;
UpdateCharPos;
end;
procedure TawScriptEditorForm.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_ESCAPE then Close;
end;
end.