Develop and Download Open Source Software

Browse Subversion Repository

Contents of /CopalPro/Result.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations) (download) (as text)
Thu Jul 28 09:05:52 2011 UTC (12 years, 9 months ago) by kaityo
File MIME type: text/x-c++src
File size: 10751 byte(s)
First Commit
1 //---------------------------------------------------------------------------
2 // スクリプトの実行結果を表示するフォーム
3 //---------------------------------------------------------------------------
4 #include <vcl.h>
5 #pragma hdrstop
6
7 #include "Main.h"
8 #include "Result.h"
9 //---------------------------------------------------------------------------
10 #pragma package(smart_init)
11 #pragma link "Base"
12 #pragma resource "*.dfm"
13 TFResult *FResult;
14 //---------------------------------------------------------------------------
15 __fastcall
16 TFResult::TFResult(TComponent* Owner)
17 : TFBase(Owner) {
18 //自分をドッキングする
19 Caption = "Result";
20 Width = 400;
21 Height = 400;
22 ManualDock(FMain->PageControl,FMain->PageControl,alClient);
23 FMain->PageControl->FindNextPage(FMain->PageControl->Pages[0],true,true);
24 Visible = true;
25 }
26 //---------------------------------------------------------------------------
27 void
28 TFResult::Init(void) {
29 // 実行ウィンドウのスクロールバーを元に戻す
30 REResult->Lines->Clear();
31 int firstline = REResult->Perform(EM_GETFIRSTVISIBLELINE,0,0);
32 REResult->Perform(EM_LINESCROLL,0,-firstline);
33 }
34 //---------------------------------------------------------------------------
35 /**
36 * 結果の読み込み
37 * TRichEdit->Lines->LoadFromStreamのラッパーになっている
38 */
39 //---------------------------------------------------------------------------
40 void
41 TFResult::LoadFromStream(TStream *Stream) {
42 REResult->Lines->LoadFromStream(Stream);
43 }
44 //---------------------------------------------------------------------------
45 /**
46 * ウィンドウにフォーカスをあてる
47 */
48 void
49 TFResult::SetWindowFocus(void) {
50 REResult->SetFocus();
51 }
52 //---------------------------------------------------------------------------
53 /**
54 * カーソル位置を画面内に配置するコード
55 */
56 void
57 TFResult::MakeCursorVisible(void) {
58 const int TopLineMargin = 5;
59 int firstline = REResult->Perform(EM_GETFIRSTVISIBLELINE,0,0);
60 int line = REResult->Perform(EM_LINEFROMCHAR,-1,0);
61 if(line>TopLineMargin) {
62 firstline += TopLineMargin;
63 REResult->Perform(EM_LINESCROLL,0,line-firstline);
64 } else {
65 REResult->Perform(EM_LINESCROLL,0,-firstline);
66 }
67 }
68 //---------------------------------------------------------------------------
69 /**
70 * 検索
71 */
72 void
73 TFResult::Find(void) {
74 FMain->FindDialog->OnFind = OnFind;
75 SearchOption.Clear();
76 FMain->FindDialog->FindText = FindWord;
77 if(!FMain->FindDialog->Execute()) {
78 return;
79 }
80 }
81 //---------------------------------------------------------------------------
82 void __fastcall
83 TFResult::OnFind(TObject *Sender) {
84 FMain->FindDialog->CloseDialog();
85 FindWord = FMain->FindDialog->FindText;
86 //オプションの設定
87 if (FMain->FindDialog->Options.Contains(frMatchCase)) {
88 SearchOption = SearchOption << stMatchCase;
89 }
90 if (FMain->FindDialog->Options.Contains(frWholeWord)) {
91 SearchOption = SearchOption << stWholeWord;
92 }
93 if (FMain->FindDialog->Options.Contains(frDown)) {
94 //下方向に検索
95 FindNext();
96 } else {
97 //上方向に検索
98 FindPrev();
99 }
100
101 }
102 //---------------------------------------------------------------------------
103 /**
104 * 次を検索
105 */
106 void
107 TFResult::FindNext(void) {
108 if(FindWord == "") {
109 Find();
110 return;
111 }
112
113 //現在のカーソル位置の行
114 int line = REResult->Perform(EM_LINEFROMCHAR,-1,0);
115
116 //カーソル行の頭の位置
117 int linetop = REResult->Perform(EM_LINEINDEX,line,0);
118 AnsiString Str = REResult->Lines->Strings[line];
119 int startpos = REResult->SelStart;
120 if(REResult->SelLength)
121 startpos++;
122 Str = Str.SubString(startpos - linetop+1,Str.Length()-startpos+linetop);
123
124 //現在の位置で見つかるか
125 int pos = Str.AnsiPos(FindWord);
126 if(pos!=0) {
127 pos += startpos-1;
128 REResult->SelStart = pos;
129 REResult->SelLength = FindWord.Length();
130 MakeCursorVisible();
131 return;
132 }
133 //以下の行を検索する
134 line++;
135 int count = REResult->Lines->Count;//毎回参照すると遅いので退避
136 while(line < count) {
137 Str = REResult->Lines->Strings[line];
138 int pos = Str.AnsiPos(FindWord);
139 if(pos!=0) {
140 int linetop = REResult->Perform(EM_LINEINDEX,line,0);
141 pos += linetop-1;
142 REResult->SelStart = pos;
143 REResult->SelLength = FindWord.Length();
144 MakeCursorVisible();
145 return;
146 } else {
147 line++;
148 }
149 }
150 }
151 //---------------------------------------------------------------------------
152 /**
153 * 与えられた文字列の最後にマッチする位置を返す
154 * マッチしなければ 0を返す
155 */
156 int
157 FindLast(AnsiString asTarget, AnsiString asFindWord) {
158 int pos = asTarget.AnsiPos(asFindWord);
159 if(pos==0) {
160 return 0;
161 }
162 while(1) {
163 asTarget = asTarget.SubString(pos+1,asTarget.Length()-pos);
164 int pos2 = asTarget.AnsiPos(asFindWord);
165 if(pos2!=0) {
166 pos+=pos2;
167 } else {
168 break;
169 }
170 }
171 return pos;
172 }
173 //---------------------------------------------------------------------------
174 void
175 TFResult::FindPrev(void) {
176
177 //現在のカーソル位置の行
178 int line = REResult->Perform(EM_LINEFROMCHAR,-1,0);
179
180 //カーソル行の頭の位置
181 int linetop = REResult->Perform(EM_LINEINDEX,line,0);
182 AnsiString Str = REResult->Lines->Strings[line];
183 Str = Str.SubString(0,REResult->SelStart-linetop-1);
184 int pos = FindLast(Str,FindWord);
185 if(pos!=0) {
186 pos += linetop-1;
187 REResult->SelStart = pos;
188 REResult->SelLength = FindWord.Length();
189 return;
190 } else {
191 line--;
192 }
193 while(line >= 0) {
194 Str = REResult->Lines->Strings[line];
195 int pos = FindLast(Str,FindWord);
196 if(pos!=0) {
197 int linetop = REResult->Perform(EM_LINEINDEX,line,0);
198 pos += linetop-1;
199 REResult->SelStart = pos;
200 REResult->SelLength = FindWord.Length();
201 MakeCursorVisible();
202 return;
203 } else {
204 line--;
205 }
206 }
207 }
208 //---------------------------------------------------------------------------
209 // クリップボード
210 //---------------------------------------------------------------------------
211 /**
212 * 切り取り
213 */
214 void
215 TFResult::Cut(void) {
216 if(REResult->SelText=="") {
217 return;
218 }
219 TClipboard *cb = Clipboard();
220 cb->AsText = REResult->SelText;
221 REResult->Lines->BeginUpdate();
222 REResult->Perform(EM_REPLACESEL,true,(int)"");
223 REResult->Lines->EndUpdate();
224 }
225 //---------------------------------------------------------------------------
226 /**
227 * コピー
228 */
229 void
230 TFResult::Copy(void) {
231 if(REResult->SelText=="") {
232 return;
233 }
234 TClipboard *cb = Clipboard();
235 cb->AsText = REResult->SelText;
236 }
237 //---------------------------------------------------------------------------
238 /**
239 * 貼り付け
240 */
241 void
242 TFResult::Paste(void) {
243 TClipboard *cb = Clipboard();
244 REResult->Lines->BeginUpdate();
245 REResult->Perform(EM_REPLACESEL,true,(int)(cb->AsText.c_str()));
246 REResult->Lines->EndUpdate();
247 }
248 //---------------------------------------------------------------------------
249 // エディット関連
250 //---------------------------------------------------------------------------
251 /**
252 * アンドゥ
253 */
254 void
255 TFResult::Undo(void) {
256 REResult->Perform(EM_UNDO,0,0);
257 }
258 //---------------------------------------------------------------------------
259 void __fastcall
260 TFResult::FormActivate(TObject *Sender) {
261 FMain->ChangeWindow(RESULT_WINDOW);
262 }
263 //---------------------------------------------------------------------------
264 /**
265 * ステータスバー表示用の文字列を作る
266 */
267 AnsiString
268 TFResult::GetCaretString(void) {
269 AnsiString as;
270 int line_number = SendMessage(REResult->Handle,EM_LINEFROMCHAR,REResult->SelStart,0);
271 int line_pos = SendMessage(REResult->Handle,EM_LINEINDEX,line_number,0);
272 int pos = REResult->SelStart - line_pos;
273 as+=" "+IntToStr(line_number+1);
274 as+=": ";
275 as+=IntToStr(pos+1);
276 if(REResult->SelLength!=0) {
277 as+=" ("+IntToStr(REResult->SelLength)+")";
278 }
279 return as;
280 }
281 //---------------------------------------------------------------------------
282 void
283 TFResult::Save(void) {
284 FMain->SaveDialog->FileName = "";
285 FMain->SaveDialog->Filter = "All Files(*.*)|*.*";
286 FMain->SaveDialog->Title = "実行結果を保存";
287 FMain->SaveDialog->InitialDir = GetMyCurrentDir();
288 FMain->SaveDialog->DefaultExt = "";
289
290 if(!FMain->SaveDialog->Execute()) {
291 return;
292 }
293 AnsiString FileName = FMain->SaveDialog->FileName;
294 if(FMain->SaveDialog->FileName.LowerCase().Trim() == FScript->GetFileName().LowerCase().Trim()) {
295 ShowMessage("結果ファイルでスクリプトファイルを上書きしようとしています。\nファイル名を変えて保存してください。");
296 return;
297 }
298 SaveToFile(FileName);
299 SetMyCurrentDir(ExtractFileDir(FileName));
300 FMain->UpdateStatusBar();
301 }
302 //---------------------------------------------------------------------------
303 void
304 TFResult::SaveAs(void) {
305 Save();
306 }
307 //---------------------------------------------------------------------------
308 /**
309 * ファイルに保存する
310 */
311 void
312 TFResult::SaveToFile(AnsiString FileName) {
313 FMain->GetCopalConfig()->SaveResultFile = FileName;
314 REResult->Lines->SaveToFile(FileName);
315 /*
316 if(FScript->GetCode()!=D_CRLF || FScript->GetDelimiter()!=C_SJIS)
317 {
318 //文字コード変換の必要あり
319 SaveConvertedFile(FileName,REResult->Lines->Text,FScript->GetCode(),FScript->GetDelimiter());
320 }
321 else
322 {
323 //文字コード変換の必要なし
324 REResult->Lines->SaveToFile(FileName);
325 }
326 */
327 }
328 //---------------------------------------------------------------------------
329 // イベント関連
330 //---------------------------------------------------------------------------
331 void __fastcall
332 TFResult::FormKeyUp(TObject *Sender, WORD &Key,
333 TShiftState Shift) {
334 FMain->UpdateMenu();
335 FMain->UpdateStatusBar();
336 }
337 //---------------------------------------------------------------------------
338 void __fastcall
339 TFResult::REResultChange(TObject *Sender) {
340 FMain->UpdateStatusBar();
341 }
342 //---------------------------------------------------------------------------
343
344 void __fastcall
345 TFResult::REResultMouseDown(TObject *Sender,
346 TMouseButton Button, TShiftState Shift, int X, int Y) {
347 FMain->UpdateStatusBar();
348 }
349 //---------------------------------------------------------------------------
350 void __fastcall
351 TFResult::REResultMouseUp(TObject *Sender,
352 TMouseButton Button, TShiftState Shift, int X, int Y) {
353 FMain->UpdateStatusBar();
354 }
355 //---------------------------------------------------------------------------
356
357 void __fastcall
358 TFResult::REResultKeyUp(TObject *Sender, WORD &Key, TShiftState Shift) {
359 FMain->UpdateStatusBar();
360 }
361 //---------------------------------------------------------------------------
362

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26