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