source: dev/trunk/ab5.0/abdev/ProjectEditor/Replace.cpp@ 460

Last change on this file since 460 was 81, checked in by dai_9181, 18 years ago

プロジェクトを開いていないときでもクラスビューの機能を有効にした。

File size: 11.0 KB
Line 
1#include "common.h"
2
3void TextEdit_ResetWordColor(int WndNum,CHARRANGE *pCharRange,int DocType){
4 extern HANDLE hHeap;
5 extern MDIINFO MdiInfo[MAX_WNDNUM];
6 int i,i2,IsStr;
7 char *pBuf,*pTemp;
8 CHARRANGE Range,cr2;
9
10 pBuf=MdiInfo[WndNum].pMdiTextEdit->buffer;
11
12 //行の先頭位置を取得
13 i=pCharRange->cpMin;
14 for(;i>0;i--){
15 if(pBuf[i-1]=='\r'&&pBuf[i]=='\n'){
16 i++;
17 break;
18 }
19 }
20 Range.cpMin=i;
21
22 //行の末端位置を取得
23 i=pCharRange->cpMax;
24 for(;;i++){
25 if(pBuf[i]=='\0') break;
26 if(pBuf[i]=='\r'&&pBuf[i+1]=='\n') break;
27 }
28 Range.cpMax=i;
29
30 //初期化(すべて黒色に戻す)
31 for(i=Range.cpMin;i<Range.cpMax;i++){
32 MdiInfo[WndNum].pMdiTextEdit->pColorRef[i]=tci.rgbDefault;
33 }
34
35 if(DocType==WNDTYPE_TEXT) return;
36
37 pTemp=(char *)HeapAlloc(hHeap,0,Range.cpMax-Range.cpMin+1);
38
39 for(i=Range.cpMin,IsStr=0;i<Range.cpMax;i++){
40 if((IsVariableTopChar(pBuf[i])||pBuf[i]=='#')&&IsStr==0){
41 cr2.cpMin=i;
42 for(i2=0;;i++,i2++){
43 if((!IsVariableChar(pBuf[i]))||pBuf[i]=='.'){
44 pTemp[i2]=0;
45 break;
46 }
47 pTemp[i2]=pBuf[i];
48 }
49 cr2.cpMax=i;
50
51 //予約語(青色)
52 BOOL bResult=0;
53 if(DocType==WNDTYPE_BASIC){
54 i2=IsBasicReservedWord(pTemp);
55 bResult=IsManagementCommand(i2);
56 }
57 else if(DocType==WNDTYPE_HTML) bResult=IsHtmlReservedWord(pTemp);
58
59 if(bResult){
60 for(i2=cr2.cpMin;i2<cr2.cpMax;i2++){
61 MdiInfo[WndNum].pMdiTextEdit->pColorRef[i2]=tci.rgbStatement;
62 }
63 }
64 }
65 if(IsStr||pBuf[i]=='\"'&&IsStr==0){
66 //文字列カラー(""で囲まれる範囲)
67 MdiInfo[WndNum].pMdiTextEdit->pColorRef[i]=tci.rgbString;
68 }
69 if(pBuf[i]=='\0') break;
70 if(pBuf[i]=='\"') IsStr^=1;
71 if(pBuf[i]=='\r'&&pBuf[i+1]=='\n'){
72 i++;
73 IsStr=0;
74 }
75 }
76
77 HeapDefaultFree(pTemp);
78}
79
80void TextEdit_Replace(int WndNum,char *str,BOOL bRedraw){
81 extern HANDLE hHeap;
82 extern MDIINFO MdiInfo[MAX_WNDNUM];
83 CHARRANGE Range,DelRange;
84
85 TextEdit_GetSel(WndNum,&DelRange);
86
87 Range.cpMin=DelRange.cpMin;
88 Range.cpMax=DelRange.cpMin+lstrlen(str);
89
90 //バッファ長を取得
91 int length;
92 length=lstrlen(MdiInfo[WndNum].pMdiTextEdit->buffer);
93
94 int delta;
95 delta=DelRange.cpMin-DelRange.cpMax+(Range.cpMax-Range.cpMin);
96 if(0<delta){
97 ////////////////////
98 // バッファを再確保
99 ////////////////////
100
101 MdiInfo[WndNum].pMdiTextEdit->buffer=(char *)HeapReAlloc(hHeap,
102 0,
103 MdiInfo[WndNum].pMdiTextEdit->buffer,
104 length+1+delta);
105
106 MdiInfo[WndNum].pMdiTextEdit->pColorRef=(COLORREF *)HeapReAlloc(hHeap,
107 0,
108 MdiInfo[WndNum].pMdiTextEdit->pColorRef,
109 (length+1+delta)*sizeof(COLORREF));
110 }
111
112
113 //ブレークポイントのオフセット分を計算
114 if(ProjectInfo.name[0]){
115 ProjectInfo.pobj_DBBreakPoint->replace(
116 MdiInfo[WndNum].path,
117 MdiInfo[WndNum].pMdiTextEdit->buffer,
118 &DelRange,
119 &Range,
120 str);
121 }
122 else{
123 extern CDBBreakPoint *pobj_DBBreakPoint;
124 pobj_DBBreakPoint->replace(
125 MdiInfo[WndNum].path,
126 MdiInfo[WndNum].pMdiTextEdit->buffer,
127 &DelRange,
128 &Range,
129 str);
130 }
131
132
133 //文字列バッファをスライドして、挿入
134 SlideString(MdiInfo[WndNum].pMdiTextEdit->buffer+DelRange.cpMax,
135 delta);
136 memcpy(MdiInfo[WndNum].pMdiTextEdit->buffer+Range.cpMin,str,lstrlen(str));
137
138 //文字カラーバッファをスライド
139 SlideBuffer(((char *)MdiInfo[WndNum].pMdiTextEdit->pColorRef)+DelRange.cpMax*sizeof(COLORREF),
140 (length-DelRange.cpMax) * sizeof(COLORREF),
141 delta*sizeof(COLORREF));
142 //色づけ
143 TextEdit_ResetWordColor(WndNum,&Range,MdiInfo[WndNum].DocType);
144
145 //新しいキャレット位置に変更
146 GetCaretPosFromBufferIndex(MdiInfo[WndNum].pMdiTextEdit->buffer,
147 Range.cpMax,
148 &MdiInfo[WndNum].pMdiTextEdit->StartCaretPos);
149 MdiInfo[WndNum].pMdiTextEdit->EndCaretPos=MdiInfo[WndNum].pMdiTextEdit->StartCaretPos;
150
151 //コントロールタブスペースの幅と行番号の文字数を更新
152 MdiInfo[WndNum].pMdiTextEdit->iWidth_ControlTabSpace=
153 GetControlTabSpace(WndNum,&MdiInfo[WndNum].pMdiTextEdit->iLineNumberTextCount);
154
155 if(bRedraw){
156 ///////////////
157 // 再描画
158 ///////////////
159
160 if(!TextEdit_ScrollCaret(WndNum,0)){
161 UpdateWindow(MdiInfo[WndNum].pMdiTextEdit->hEdit); //ちらつき防止
162 InvalidateRect(MdiInfo[WndNum].pMdiTextEdit->hEdit,NULL,0);
163 }
164
165 ResetCaretPos(WndNum,1);
166 }
167
168 //上下キャレット移動時の左右位置保持機能を解除
169 MdiInfo[WndNum].pMdiTextEdit->Temp_UpDown_CaretXPos=-1;
170
171 //編集メニューをリセット
172 ResetState_EditMenu();
173
174 if( ! MdiInfo[WndNum].pMdiTextEdit->IsModified() ){
175 //変更フラグをセット
176 MdiInfo[WndNum].pMdiTextEdit->Modify();
177 }
178
179
180 //if(ProjectInfo.name[0]){
181 //プロジェクトが開かれているとき
182 if(MdiInfo[WndNum].DocType==WNDTYPE_BASIC){
183 //クラスツリーを再表示
184 ResetClassTree(GetFileNum(WndNum));
185 }
186 //}
187}
188void TextEdit_ReplaceUpdateUndoData(int WndNum,char *str,BOOL bPaste,BOOL bRedraw){
189 extern HANDLE hHeap;
190 extern MDIINFO MdiInfo[MAX_WNDNUM];
191 int Command;
192 char *KeyStr,*DelStr;
193 char temporary[255];
194 CHARRANGE Range,DelRange;
195
196 if(MdiInfo[WndNum].IndentStr){
197 //自動インデントを有効にする
198 lstrcpy(temporary,MdiInfo[WndNum].IndentStr);
199
200 CancelBeforeAutoIndent(WndNum);
201 TextEdit_ReplaceUpdateUndoData(WndNum,temporary,0,1);
202 }
203
204 TextEdit_GetSel(WndNum,&DelRange);
205 if(DelRange.cpMin!=DelRange.cpMax){
206 Command=TEXTEDIT_UNDO_SELKEY;
207 DelStr=(char *)HeapAlloc(hHeap,0,DelRange.cpMax-DelRange.cpMin+1);
208
209 TextEdit_GetSelText(WndNum,&DelRange,DelStr);
210
211 Range.cpMin=DelRange.cpMin;
212 Range.cpMax=DelRange.cpMin;
213 }
214 else{
215 if(bPaste) Command=TEXTEDIT_UNDO_PASTE;
216 else Command=TEXTEDIT_UNDO_KEY;
217 DelStr=0;
218
219 Range=DelRange;
220 }
221 if(str[0]){
222 KeyStr=(char *)HeapAlloc(hHeap,0,lstrlen(str)+1);
223 lstrcpy(KeyStr,str);
224 Range.cpMax+=lstrlen(KeyStr);
225 }
226 else KeyStr=0;
227 TextEdit_NoticeChanging(WndNum,Command,KeyStr,DelStr,&Range,&DelRange);
228
229 TextEdit_Replace(WndNum,str,bRedraw);
230}
231
232
233void TextEdit_Convert(int id){
234 int i,i2;
235
236 int WndNum;
237 WndNum=GetWndNum(GetWindow(hClient,GW_CHILD));
238
239 CHARRANGE CharRange;
240 int length;
241 TextEdit_GetSel(WndNum,&CharRange);
242
243#ifdef THETEXT
244 if(id==IDM_CONV_HASRETURN||id==IDM_CONV_QUOTE){
245#else
246 if(id==IDM_CODEFORMAT){
247#endif
248 char *pBuf;
249 pBuf=MdiInfo[WndNum].pMdiTextEdit->buffer;
250
251 //行全体を選択(min)
252 for(i=CharRange.cpMin;i>0;i--){
253 if(pBuf[i-1]=='\r'&&pBuf[i]=='\n'){
254 i++;
255 break;
256 }
257 }
258 CharRange.cpMin=i;
259
260 //行全体を選択(max)
261 for(i=CharRange.cpMax;;i++){
262 if(pBuf[i]=='\r'&&pBuf[i+1]=='\n'||pBuf[i]=='\0') break;
263 }
264 CharRange.cpMax=i;
265
266 TextEdit_SetSel(WndNum,CharRange.cpMin,CharRange.cpMax,0);
267 }
268
269 length=CharRange.cpMax-CharRange.cpMin;
270
271 char *buffer,*temporary;
272 buffer=(char *)HeapAlloc(hHeap,0,length*3+1024);
273 temporary=(char *)HeapAlloc(hHeap,0,length*3+1024);
274 memcpy(buffer,MdiInfo[WndNum].pMdiTextEdit->buffer+CharRange.cpMin,length);
275 buffer[length]=0;
276
277 int x=0;
278 switch(id){
279 case IDM_CONV_ALPHA_SMALL:
280 CharLower(buffer);
281 break;
282 case IDM_CONV_ALPHA_BIG:
283 CharUpper(buffer);
284 break;
285 case IDM_CONV_HALF:
286 LCMapString(GetUserDefaultLCID(),LCMAP_HALFWIDTH,buffer,length+1,temporary,length*2+1);
287 lstrcpy(buffer,temporary);
288 break;
289 case IDM_CONV_MULTI:
290 LCMapString(GetUserDefaultLCID(),LCMAP_FULLWIDTH,buffer,length+1,temporary,length*2+1);
291 lstrcpy(buffer,temporary);
292 break;
293 case IDM_CONV_KATAKANA:
294 LCMapString(GetUserDefaultLCID(),LCMAP_KATAKANA,buffer,length+1,temporary,length*2+1);
295 lstrcpy(buffer,temporary);
296 break;
297 case IDM_CONV_HIRAGANA:
298 LCMapString(GetUserDefaultLCID(),LCMAP_HIRAGANA,buffer,length+1,temporary,length*2+1);
299 lstrcpy(buffer,temporary);
300 break;
301 case IDM_CONV_SPACE:
302 temporary=(char *)HeapReAlloc(hHeap,0,temporary,length*pobj_nv->TabSize+1);
303 buffer=(char *)HeapReAlloc(hHeap,0,buffer,length*pobj_nv->TabSize+1);
304 for(i=0,i2=0;;i++,i2++){
305 if(buffer[i]=='\t'){
306 memset(temporary+i2,' ',pobj_nv->TabSize);
307 i2+=pobj_nv->TabSize-1;
308 continue;
309 }
310 temporary[i2]=buffer[i];
311 if(buffer[i]=='\0') break;
312 }
313
314 lstrcpy(buffer,temporary);
315 break;
316 case IDM_CONV_TAB:
317 char szSpaceTemp[255];
318 memset(szSpaceTemp,' ',pobj_nv->TabSize);
319 szSpaceTemp[pobj_nv->TabSize]=0;
320
321 for(i=0,i2=0;;i++,i2++){
322 if(memcmp(buffer+i,szSpaceTemp,pobj_nv->TabSize)==0){
323 temporary[i2]='\t';
324 i+=pobj_nv->TabSize-1;
325 continue;
326 }
327 temporary[i2]=buffer[i];
328 if(buffer[i]=='\0') break;
329 }
330
331 lstrcpy(buffer,temporary);
332 break;
333
334#ifdef THETEXT
335 case IDM_CONV_HASRETURN:
336 //折り返し改行を挿入
337 int i3;
338 for(i=0,i2=0,x=0;;i++,i2++,x++){
339 if(buffer[i]=='\r'&&buffer[i+1]=='\n'){
340 temporary[i2++]=buffer[i++];
341 temporary[i2]=buffer[i];
342 x=-1;
343 continue;
344 }
345 if(x>pobj_nv->iMaxOneLineTextLength-2){
346 //自動改行(英単語を考慮)
347 int i3=0;
348 while(IsVariableChar(buffer[i-1])){
349 i--;
350 i2--;
351 x--;
352 i3++;
353 if(x==1){
354 i+=i3;
355 i2+=i3;
356 x+=i3;
357 break;
358 }
359 }
360 if(i3==1){
361 i++;
362 i2++;
363 x++;
364 }
365 temporary[i2++]='\r';
366 temporary[i2]='\n';
367 i--;
368 x=-1;
369 continue;
370 }
371
372 if(IsDBCSLeadByte(buffer[i])){
373 temporary[i2++]=buffer[i++];
374 temporary[i2]=buffer[i];
375 x++;
376 }
377 else{
378 temporary[i2]=buffer[i];
379
380 if(buffer[i]=='\t'){
381 //タブ文字
382 int tab;
383 tab=pobj_nv->TabSize;
384
385 if(x%tab==0) i3=tab;
386 else i3=tab-x%tab;
387 x+=i3-1;
388 }
389 }
390
391 if(buffer[i]=='\0') break;
392 }
393
394 lstrcpy(buffer,temporary);
395 break;
396 case IDM_CONV_QUOTE:
397 //引用文に変換
398 for(i=0,i2=0,x=0;;i++,i2++,x++){
399 if(x==0){
400 //"> " を挿入
401 temporary[i2++]='>';
402 temporary[i2++]=' ';
403 }
404 if(buffer[i]=='\r'&&buffer[i+1]=='\n'){
405 temporary[i2++]=buffer[i++];
406 temporary[i2]=buffer[i];
407 x=-1;
408 continue;
409 }
410 if(x>pobj_nv->iMaxOneLineTextLength-4){
411 //自動改行(英単語を考慮)
412 int i3=0;
413 while(IsVariableChar(buffer[i-1])){
414 i--;
415 i2--;
416 x--;
417 i3++;
418 if(x==1){
419 i+=i3;
420 i2+=i3;
421 x+=i3;
422 break;
423 }
424 }
425 if(i3==1){
426 i++;
427 i2++;
428 x++;
429 }
430 temporary[i2++]='\r';
431 temporary[i2]='\n';
432 i--;
433 x=-1;
434 continue;
435 }
436
437 if(IsDBCSLeadByte(buffer[i])){
438 temporary[i2++]=buffer[i++];
439 temporary[i2]=buffer[i];
440 x++;
441 }
442 else{
443 temporary[i2]=buffer[i];
444 if(buffer[i]=='\t'){
445 //タブ文字
446 int tab;
447 tab=pobj_nv->TabSize;
448
449 if(x%tab==0) i3=tab;
450 else i3=tab-x%tab;
451 x+=i3-1;
452 }
453 }
454
455 if(buffer[i]=='\0') break;
456 }
457
458 lstrcpy(buffer,temporary);
459 break;
460
461#else //ProjectEditor
462
463 case IDM_CODEFORMAT:
464 char *temp2;
465 temp2=CodeFormatter(buffer);
466 HeapDefaultFree(buffer);
467 buffer=temp2;
468 break;
469
470#endif
471 }
472
473
474
475 //テキストエディタの文字列をリプレイス
476 TextEdit_ReplaceUpdateUndoData(WndNum,
477 buffer,
478 1,
479 1);
480
481 HeapDefaultFree(buffer);
482 HeapDefaultFree(temporary);
483
484 //キャレット位置までスクロールする
485 TextEdit_ScrollCaret(WndNum,0);
486 ResetCaretPos(WndNum);
487}
Note: See TracBrowser for help on using the repository browser.