source: dev/ProjectEditor/TextEditor_UndoRedo.cpp@ 27

Last change on this file since 27 was 24, checked in by dai_9181, 18 years ago

保存されていないドキュメントのタブに(*)をつける機能に対応。
MDITEXTEDITINFOをCMdiTextEditに変更。今後、オブジェクト指向化を進める。

File size: 4.9 KB
Line 
1#include "common.h"
2
3void TextEdit_UndoCommand(int WndNum){
4 extern MDIINFO MdiInfo[MAX_WNDNUM];
5 int i;
6 TEXTEDIT_UNDOSTATE *pUndoState;
7
8 //自動インデント中のインデントを無効にする
9 if(MdiInfo[WndNum].IndentStr) CancelBeforeAutoIndent(WndNum);
10
11 pUndoState=MdiInfo[WndNum].pMdiTextEdit->pTextEditUndoState;
12 i=pUndoState->NowPos-1;
13 if(i==-1) i=MAX_UNDONUM-1;
14 if(!pUndoState->Command[i]){
15 MessageBeep(0);
16 return;
17 }
18 pUndoState->NowPos=i;
19
20 //選択範囲をセット
21 GetCaretPosFromBufferIndex(MdiInfo[WndNum].pMdiTextEdit->buffer,
22 pUndoState->Range[pUndoState->NowPos].cpMin,
23 &MdiInfo[WndNum].pMdiTextEdit->StartCaretPos);
24 GetCaretPosFromBufferIndex(MdiInfo[WndNum].pMdiTextEdit->buffer,
25 pUndoState->Range[pUndoState->NowPos].cpMax,
26 &MdiInfo[WndNum].pMdiTextEdit->EndCaretPos);
27
28 switch(pUndoState->Command[pUndoState->NowPos]){
29 case TEXTEDIT_UNDO_KEY:
30 case TEXTEDIT_UNDO_PASTE:
31 TextEdit_Replace(WndNum,"",1);
32 break;
33 case TEXTEDIT_UNDO_SELKEY:
34 TextEdit_Replace(WndNum,pUndoState->DelStr[pUndoState->NowPos],1);
35 break;
36 }
37
38 TextEdit_ScrollCaret(WndNum,0);
39 ResetCaretPos(WndNum);
40
41 //元に戻す、やり直しメニューをリセット
42 ResetState_UndoMenu();
43
44 //変更を通知
45 MdiInfo[WndNum].pMdiTextEdit->NofityUndoRedoToModify();
46}
47void TextEdit_RedoCommand(int WndNum){
48 extern MDIINFO MdiInfo[MAX_WNDNUM];
49 TEXTEDIT_UNDOSTATE *pUndoState;
50
51 pUndoState=MdiInfo[WndNum].pMdiTextEdit->pTextEditUndoState;
52 if(!pUndoState->Command[pUndoState->NowPos]){
53 MessageBeep(0);
54 return;
55 }
56
57 switch(pUndoState->Command[pUndoState->NowPos]){
58 case TEXTEDIT_UNDO_KEY:
59 case TEXTEDIT_UNDO_PASTE:
60 //選択範囲をセット
61 GetCaretPosFromBufferIndex(MdiInfo[WndNum].pMdiTextEdit->buffer,
62 pUndoState->Range[pUndoState->NowPos].cpMin,
63 &MdiInfo[WndNum].pMdiTextEdit->StartCaretPos);
64 GetCaretPosFromBufferIndex(MdiInfo[WndNum].pMdiTextEdit->buffer,
65 pUndoState->Range[pUndoState->NowPos].cpMin,
66 &MdiInfo[WndNum].pMdiTextEdit->EndCaretPos);
67
68 TextEdit_Replace(WndNum,pUndoState->KeyStr[pUndoState->NowPos],1);
69 break;
70 case TEXTEDIT_UNDO_SELKEY:
71 //選択範囲をセット
72 GetCaretPosFromBufferIndex(MdiInfo[WndNum].pMdiTextEdit->buffer,
73 pUndoState->DelRange[pUndoState->NowPos].cpMin,
74 &MdiInfo[WndNum].pMdiTextEdit->StartCaretPos);
75 GetCaretPosFromBufferIndex(MdiInfo[WndNum].pMdiTextEdit->buffer,
76 pUndoState->DelRange[pUndoState->NowPos].cpMax,
77 &MdiInfo[WndNum].pMdiTextEdit->EndCaretPos);
78
79 TextEdit_Replace(WndNum,pUndoState->KeyStr[pUndoState->NowPos],1);
80 break;
81 }
82
83 TextEdit_ScrollCaret(WndNum,0);
84 ResetCaretPos(WndNum);
85
86 pUndoState->NowPos++;
87 if(pUndoState->NowPos==MAX_UNDONUM) pUndoState->NowPos=0;
88
89 //元に戻す、やり直しメニューをリセット
90 ResetState_UndoMenu();
91
92 //変更を通知
93 MdiInfo[WndNum].pMdiTextEdit->NofityUndoRedoToModify();
94}
95
96BOOL bUndoDelimitation(char c){
97 if(c==' '||c=='\t'||
98 c=='\"'||
99 c==','||c==':'||c==';'||
100 c=='('||c==')'||
101 c=='+'||c=='-'||c=='*'||c=='/'||c=='^'||c=='\\'||c=='<'||c=='>'||c=='=') return 1;
102 return 0;
103}
104void TextEdit_NoticeChanging(int WndNum,int Command,char *KeyStr,char *DelStr,CHARRANGE *Range,CHARRANGE *DelRange){
105 extern HANDLE hHeap;
106 extern MDIINFO MdiInfo[MAX_WNDNUM];
107 int i;
108 TEXTEDIT_UNDOSTATE *pUndoState;
109
110 pUndoState=MdiInfo[WndNum].pMdiTextEdit->pTextEditUndoState;
111
112 //Redoされた場合の不要なデータを削除する
113 for(i=pUndoState->NowPos;;i++){
114 if(i==MAX_UNDONUM) i=0;
115 if(pUndoState->Command[i]==0) break;
116 TextEdit_DeleteUndoData(pUndoState,i);
117 }
118
119 i=pUndoState->NowPos-1;
120 if(i==-1) i=MAX_UNDONUM-1;
121 if(pUndoState->Command[i]==Command&&
122 pUndoState->Command[i]==TEXTEDIT_UNDO_KEY){
123 if(pUndoState->Range[i].cpMax==Range->cpMin&&KeyStr[0]!='\r'){
124 if(!(bUndoDelimitation(pUndoState->KeyStr[i][0])^bUndoDelimitation(KeyStr[0]))){
125 pUndoState->KeyStr[i]=(char *)HeapReAlloc(hHeap,0,pUndoState->KeyStr[i],lstrlen(pUndoState->KeyStr[i])+lstrlen(KeyStr)+1);
126 lstrcat(pUndoState->KeyStr[i],KeyStr);
127 pUndoState->Range[i].cpMax+=lstrlen(KeyStr);
128
129 HeapDefaultFree(KeyStr);
130
131 //元に戻す、やり直しメニューをリセット
132 ResetState_UndoMenu();
133 return;
134 }
135 }
136 }
137
138 //データ更新
139 pUndoState->Command[pUndoState->NowPos]=Command;
140 pUndoState->KeyStr[pUndoState->NowPos]=KeyStr;
141 pUndoState->DelStr[pUndoState->NowPos]=DelStr;
142 pUndoState->Range[pUndoState->NowPos]=*Range;
143 if(DelRange) pUndoState->DelRange[pUndoState->NowPos]=*DelRange;
144
145 pUndoState->NowPos++;
146 if(pUndoState->NowPos==MAX_UNDONUM) pUndoState->NowPos=0;
147 if(pUndoState->Command[pUndoState->NowPos]){
148 //一番古い情報を切り捨てる
149 TextEdit_DeleteUndoData(pUndoState,pUndoState->NowPos);
150 }
151
152 //元に戻す、やり直しメニューをリセット
153 ResetState_UndoMenu();
154}
155
156void TextEdit_DeleteUndoData(TEXTEDIT_UNDOSTATE *pUndoState,int pos){
157 if(pUndoState->KeyStr[pos]) HeapDefaultFree(pUndoState->KeyStr[pos]);
158 if(pUndoState->DelStr[pos]) HeapDefaultFree(pUndoState->DelStr[pos]);
159 pUndoState->Command[pos]=0;
160}
Note: See TracBrowser for help on using the repository browser.