-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathEditDlg.cpp
More file actions
428 lines (410 loc) · 11.7 KB
/
EditDlg.cpp
File metadata and controls
428 lines (410 loc) · 11.7 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
//Copyright+LGPL
//-----------------------------------------------------------------------------------------------------------------------------------------------
// Copyright 2000-2013 Makoto Mori, Nobuyuki Oba
//-----------------------------------------------------------------------------------------------------------------------------------------------
// This file is part of MMTTY.
// MMTTY is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
// MMTTY is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License along with MMTTY. If not, see
// <http://www.gnu.org/licenses/>.
//-----------------------------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "EditDlg.h"
#include "MacroKey.h"
//---------------------------------------------------------------------
#pragma resource "*.dfm"
//TEditDlgBox *EditDlgBox;
//---------------------------------------------------------------------
__fastcall TEditDlgBox::TEditDlgBox(TComponent* AOwner)
: TForm(AOwner)
{
FormStyle = ((TForm *)AOwner)->FormStyle;
Font->Name = ((TForm *)AOwner)->Font->Name;
Font->Charset = ((TForm *)AOwner)->Font->Charset;
Memo->Font->Name = sys.m_BtnFontName;
Memo->Font->Charset = sys.m_BtnFontCharset;
m_JobSel = 0;
m_DisEvent = 0;
m_CurIndex = -1;
m_MacroSet = 0;
ShortCutName->Clear();
int i;
ShortCutName->Items->Add("NULL");
for( i = 0; KEYTBL[i].Key; i++ ){
ShortCutName->Items->Add(ToDXKey(KEYTBL[i].pName));
}
if( Font->Charset != SHIFTJIS_CHARSET ){
Caption = "Assign Macro";
CancelBtn->Caption = "Cancel";
LShort->Caption = "ShortCut";
LEntryName->Caption = "Name";
DelBtn->Caption = "Del";
NewNameBtn->Caption = "New Name";
TxBtn->Caption = "TX(F9)";
}
// SBHelp->Visible = !JanHelp.IsEmpty();
SBHelp->Visible = FALSE;
TxBtn->Enabled = !(sys.m_DisTX&1);
}
//---------------------------------------------------------------------
int __fastcall TEditDlgBox::Execute(AnsiString &as, WORD &nKey, TColor *pcol, int *Intval, int set)
{
m_MacroSet = set;
m_DisEvent++;
if( ButtonName->Text.IsEmpty() ){
ButtonName->Visible = FALSE;
LEntryName->Visible = FALSE;
}
else {
ButtonName->Visible = TRUE;
}
EntryName->Visible = FALSE;
DelBtn->Visible = FALSE;
NewNameBtn->Visible = FALSE;
Memo->Text = as;
if( pcol != NULL ){
PanelCol->Visible = TRUE;
LCol->Visible = TRUE;
PanelCol->Color = *pcol;
}
if( Intval != NULL ){
LMInt->Visible = TRUE;
EMInt->Visible = TRUE;
UDInt->Visible = TRUE;
LMUN->Visible = TRUE;
UDInt->Position = SHORT(*Intval);
}
ShortCutName->Text = GetKeyName(nKey);
if( ShowModal() == IDOK ){
as = Memo->Text;
nKey = GetKeyCode(AnsiString(ShortCutName->Text).c_str()); //JA7UDE 0428
if( pcol != NULL ){
*pcol = PanelCol->Color;
}
if( Intval != NULL ){
*Intval = UDInt->Position;
}
return TRUE;
}
else {
return FALSE;
}
}
//---------------------------------------------------------------------
void __fastcall TEditDlgBox::UpdateUI(void)
{
if( EntryName->Visible != FALSE ){
NewNameBtn->Enabled = (m_CurIndex >= 0) ? TRUE : FALSE;
DelBtn->Enabled = (m_CurIndex >= 0) ? TRUE : FALSE;
OKBtn->Enabled = ((!EntryName->Text.IsEmpty()) && (!Memo->Text.IsEmpty()) && Memo->Modified) ? TRUE : FALSE;
}
}
//---------------------------------------------------------------------
int __fastcall TEditDlgBox::EditMsg(void)
{
Caption = (Font->Charset != SHIFTJIS_CHARSET) ? "Edit Message":"定型メッセージの編集";
ButtonName->Visible = FALSE;
EntryName->Visible = TRUE;
DelBtn->Visible = TRUE;
NewNameBtn->Visible = TRUE;
if(Font->Charset != SHIFTJIS_CHARSET){
CancelBtn->Caption = "Close";
OKBtn->Caption = "Assign";
}
else {
CancelBtn->Caption = "閉じる";
OKBtn->Caption = "登録";
}
UpdateList();
// EntryName->SetFocus();
Memo->Clear();
if( !sys.m_MsgName[0].IsEmpty() ){
Memo->Text = sys.m_MsgList[0];
m_CurIndex = 0;
}
UpdateUI();
m_MacroSet = 0;
if( ShowModal() == IDOK ){
return TRUE;
}
else {
return FALSE;
}
}
//---------------------------------------------------------------------------
void __fastcall TEditDlgBox::UpdateList(void)
{
m_DisEvent++;
EntryName->Clear();
int i;
for( i = 0; i < MSGLISTMAX; i++ ){
if( sys.m_MsgName[i].IsEmpty() ) break;
EntryName->Items->Add(sys.m_MsgName[i]);
}
if( !sys.m_MsgName[0].IsEmpty() ){
EntryName->Text = sys.m_MsgName[0];
}
ShortCutName->Text = GetKeyName(sys.m_MsgKey[0]);
m_DisEvent--;
}
void __fastcall TEditDlgBox::EntryNameChange(TObject *Sender)
{
if( m_DisEvent ) return;
m_DisEvent++;
AnsiString ttl = EntryName->Text;
AnsiString as;
m_CurIndex = -1;
ShortCutName->Text = "NULL";
int i;
for( i = 0; i < MSGLISTMAX; i++ ){
if( sys.m_MsgName[i].IsEmpty() ) break;
if( sys.m_MsgName[i] == ttl ){
as = sys.m_MsgList[i];
Memo->Clear();
Memo->Text = as;
m_CurIndex = i;
ShortCutName->Text = GetKeyName(sys.m_MsgKey[i]);
break;
}
}
if( (m_CurIndex == -1) && (!EntryName->Text.IsEmpty()) && (!Memo->Text.IsEmpty()) ) Memo->Modified = TRUE;
UpdateUI();
m_DisEvent--;
}
//---------------------------------------------------------------------------
void __fastcall TEditDlgBox::NewNameBtnClick(TObject *Sender)
{
//AnsiString ttl = EntryName->Text; //JA7UDE 0428
UnicodeString ttl = EntryName->Text; //JA7UDE 0428
if( InputQuery("MMTTY", (Font->Charset != SHIFTJIS_CHARSET) ? "Input Name":"登録名(メッセージの別名)を入力", ttl) == TRUE ){
if( ttl.IsEmpty() ){
ttl = "無題";
}
sys.m_MsgName[m_CurIndex] = ttl;
EntryName->Text = ttl;
}
UpdateUI();
}
//---------------------------------------------------------------------------
void __fastcall TEditDlgBox::DelBtnClick(TObject *Sender)
{
if( YesNoMB((Font->Charset != SHIFTJIS_CHARSET)?"Delete [%s]. Are you sure?":"[%s]をリストから削除します.\r\n\r\nよろしおまっか?", EntryName->Text.c_str()) == IDYES ){
int i;
for( i = m_CurIndex; i < (MSGLISTMAX - 1); i++ ){
if( sys.m_MsgName[i].IsEmpty() ) break;
sys.m_MsgList[i] = sys.m_MsgList[i+1];
sys.m_MsgName[i] = sys.m_MsgName[i+1];
sys.m_MsgKey[i] = sys.m_MsgKey[i+1];
}
sys.m_MsgName[i] = "";
sys.m_MsgList[i] = "";
sys.m_MsgKey[i] = 0;
if( m_CurIndex ) m_CurIndex--;
if( m_CurIndex >= 0 ){
EntryName->Text = sys.m_MsgName[m_CurIndex];
Memo->Text = sys.m_MsgList[m_CurIndex];
ShortCutName->Text = GetKeyName(sys.m_MsgKey[m_CurIndex]);
}
else {
EntryName->Text = "";
Memo->Clear();
ShortCutName->Text = "";
}
UpdateList();
}
}
//---------------------------------------------------------------------------
void __fastcall TEditDlgBox::MemoChange(TObject *Sender)
{
if( m_DisEvent ) return;
UpdateUI();
}
//---------------------------------------------------------------------------
void __fastcall TEditDlgBox::OKBtnClick(TObject *Sender)
{
if( EntryName->Visible == FALSE ){
ModalResult = mrOk;
return;
}
if( EntryName->Text.IsEmpty() ) return;
if( Memo->Text.IsEmpty() ) return;
if( YesNoMB((Font->Charset != SHIFTJIS_CHARSET)?"Assign text to [%s]. Are you sure?":"[%s]に現在のテキストを定義します.\r\n\r\nよろしおまっか?", EntryName->Text.c_str()) == IDYES ){
EntryMsg(AnsiString(EntryName->Text), AnsiString(Memo->Text), GetKeyCode(AnsiString(ShortCutName->Text).c_str())); //JA7UDE 0428
Memo->Modified = FALSE;
}
UpdateUI();
}
//---------------------------------------------------------------------------
void __fastcall TEditDlgBox::ShortCutNameChange(TObject *Sender)
{
if( m_DisEvent ) return;
Memo->Modified = TRUE;
UpdateUI();
}
//---------------------------------------------------------------------------
void __fastcall TEditDlgBox::TxBtnClick(TObject *Sender)
{
if( Memo->Text.IsEmpty() ) return;
if( sys.m_DisTX&1 ) return;
m_JobSel = 1;
ModalResult = mrOk;
}
//---------------------------------------------------------------------------
void __fastcall TEditDlgBox::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
switch(Key){
case VK_F9:
Key = 0;
TxBtnClick(NULL);
break;
case VK_ESCAPE:
Key = 0;
ModalResult = mrCancel;
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TEditDlgBox::FormKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
switch(Key){
case VK_F9:
Key = 0;
break;
case VK_ESCAPE:
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TEditDlgBox::ClearBtnClick(TObject *Sender)
{
if( YesNoMB((Font->Charset != SHIFTJIS_CHARSET)?"Clear text and shortcut. Are you sure?":"テキストとショートカットを初期化します.\r\n\r\nよろしおまっか?") == IDYES ){
Memo->Text = "";
ShortCutName->Text = "NULL";
UDInt->Position = 0;
}
}
//---------------------------------------------------------------------------
void __fastcall TEditDlgBox::PanelColClick(TObject *Sender)
{
ColorDialog->Color = PanelCol->Color;
NormalWindow(this);
if( ColorDialog->Execute() == TRUE ){
PanelCol->Color = ColorDialog->Color;
}
TopWindow(this);
}
//---------------------------------------------------------------------------
int __fastcall TEditDlgBox::CheckLast(LPCSTR s, char c)
{
LPCSTR p = s + strlen(s) - 1;
for( ; p >= s; p-- ){
if( *p == c ) return 1;
if( isalpha(*p) || (*p == '%') ) return 0;
}
return 0;
}
//---------------------------------------------------------------------------
int __fastcall TEditDlgBox::CheckTop(LPCSTR s, char c)
{
LPCSTR p = s;
for( ; *p; p++ ){
if( *p == c ) return 1;
if( isalpha(*p) || (*p == '%') ) return 0;
}
return 0;
}
//---------------------------------------------------------------------------
void __fastcall TEditDlgBox::DeleteSpace(void)
{
AnsiString ws = Memo->Text.c_str();
LPSTR p = ws.c_str();
AnsiString as;
LPSTR bp = new char[strlen(p)+1];
LPSTR t = bp;
for( ; *p; p++ ){
if( *p != CR ){
if( *p == LF ){
*t = 0;
clipsp(bp);
if( *bp ) as += bp;
as += "\r\n";
t = bp;
}
else {
*t++ = *p;
}
}
}
*t = 0;
if( *bp ){
clipsp(bp);
if( *bp ) as += bp;
}
p = as.c_str();
t = lastp(p);
if( (*t == LF)||(*t == CR) ){
for( ; t >= p; t-- ){
if( (*t == LF)||(*t == CR) ){
*t = 0;
}
else {
break;
}
}
t++;
*t++ = CR;
*t = LF;
}
Memo->Text = p;
Memo->Modified = TRUE;
delete bp;
}
//---------------------------------------------------------------------------
void __fastcall TEditDlgBox::ComBtnClick(TObject *Sender)
{
TMacroKeyDlg *pBox = new TMacroKeyDlg(this);
AnsiString as, bs;
LPCSTR p;
int r = pBox->Execute(as, m_MacroSet);
switch(r){
case 1:
Memo->SetFocus();
for( p = as.c_str(); *p; p++ ){
::PostMessage(Memo->Handle, WM_CHAR, *p, 0);
}
break;
case 2: // 最後に追加
bs = Memo->Text;
if( !CheckLast(bs.c_str(), *as.c_str()) ){
bs += as.c_str();
Memo->Text = bs;
Memo->Modified = TRUE;
}
break;
case 3: // 先頭に追加
if( !CheckTop(AnsiString(Memo->Text).c_str(), *as.c_str()) ){ //JA7UDE 0428
as += Memo->Text.c_str();
Memo->Text = as.c_str();
Memo->Modified = TRUE;
}
break;
case -1: // 行末のスペースを削除
DeleteSpace();
break;
}
delete pBox;
UpdateUI();
Memo->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TEditDlgBox::SBHelpClick(TObject *Sender)
{
ShowHtmlHelp();
}
//---------------------------------------------------------------------------