#include "common.h" void TextEdit_UndoCommand(int WndNum){ extern MDIINFO MdiInfo[MAX_WNDNUM]; int i; TEXTEDIT_UNDOSTATE *pUndoState; //自動インデント中のインデントを無効にする if(MdiInfo[WndNum].IndentStr) CancelBeforeAutoIndent(WndNum); pUndoState=MdiInfo[WndNum].edit_undo; i=pUndoState->NowPos-1; if(i==-1) i=MAX_UNDONUM-1; if(!pUndoState->Command[i]){ MessageBeep(0); return; } pUndoState->NowPos=i; //選択範囲をセット GetCaretPosFromBufferIndex(MdiInfo[WndNum].pmti->buffer, pUndoState->Range[pUndoState->NowPos].cpMin, &MdiInfo[WndNum].pmti->StartCaretPos); GetCaretPosFromBufferIndex(MdiInfo[WndNum].pmti->buffer, pUndoState->Range[pUndoState->NowPos].cpMax, &MdiInfo[WndNum].pmti->EndCaretPos); switch(pUndoState->Command[pUndoState->NowPos]){ case TEXTEDIT_UNDO_KEY: case TEXTEDIT_UNDO_PASTE: TextEdit_Replace(WndNum,"",1); break; case TEXTEDIT_UNDO_SELKEY: TextEdit_Replace(WndNum,pUndoState->DelStr[pUndoState->NowPos],1); break; } TextEdit_ScrollCaret(WndNum,0); ResetCaretPos(WndNum); //元に戻す、やり直しメニューをリセット ResetState_UndoMenu(); } void TextEdit_RedoCommand(int WndNum){ extern MDIINFO MdiInfo[MAX_WNDNUM]; TEXTEDIT_UNDOSTATE *pUndoState; pUndoState=MdiInfo[WndNum].edit_undo; if(!pUndoState->Command[pUndoState->NowPos]){ MessageBeep(0); return; } switch(pUndoState->Command[pUndoState->NowPos]){ case TEXTEDIT_UNDO_KEY: case TEXTEDIT_UNDO_PASTE: //選択範囲をセット GetCaretPosFromBufferIndex(MdiInfo[WndNum].pmti->buffer, pUndoState->Range[pUndoState->NowPos].cpMin, &MdiInfo[WndNum].pmti->StartCaretPos); GetCaretPosFromBufferIndex(MdiInfo[WndNum].pmti->buffer, pUndoState->Range[pUndoState->NowPos].cpMin, &MdiInfo[WndNum].pmti->EndCaretPos); TextEdit_Replace(WndNum,pUndoState->KeyStr[pUndoState->NowPos],1); break; case TEXTEDIT_UNDO_SELKEY: //選択範囲をセット GetCaretPosFromBufferIndex(MdiInfo[WndNum].pmti->buffer, pUndoState->DelRange[pUndoState->NowPos].cpMin, &MdiInfo[WndNum].pmti->StartCaretPos); GetCaretPosFromBufferIndex(MdiInfo[WndNum].pmti->buffer, pUndoState->DelRange[pUndoState->NowPos].cpMax, &MdiInfo[WndNum].pmti->EndCaretPos); TextEdit_Replace(WndNum,pUndoState->KeyStr[pUndoState->NowPos],1); break; } TextEdit_ScrollCaret(WndNum,0); ResetCaretPos(WndNum); pUndoState->NowPos++; if(pUndoState->NowPos==MAX_UNDONUM) pUndoState->NowPos=0; //元に戻す、やり直しメニューをリセット ResetState_UndoMenu(); } BOOL bUndoDelimitation(char c){ if(c==' '||c=='\t'|| c=='\"'|| c==','||c==':'||c==';'|| c=='('||c==')'|| c=='+'||c=='-'||c=='*'||c=='/'||c=='^'||c=='\\'||c=='<'||c=='>'||c=='=') return 1; return 0; } void TextEdit_NoticeChanging(int WndNum,int Command,char *KeyStr,char *DelStr,CHARRANGE *Range,CHARRANGE *DelRange){ extern HANDLE hHeap; extern MDIINFO MdiInfo[MAX_WNDNUM]; int i; TEXTEDIT_UNDOSTATE *pUndoState; pUndoState=MdiInfo[WndNum].edit_undo; //Redoされた場合の不要なデータを削除する for(i=pUndoState->NowPos;;i++){ if(i==MAX_UNDONUM) i=0; if(pUndoState->Command[i]==0) break; TextEdit_DeleteUndoData(WndNum,i); } i=pUndoState->NowPos-1; if(i==-1) i=MAX_UNDONUM-1; if(pUndoState->Command[i]==Command&& pUndoState->Command[i]==TEXTEDIT_UNDO_KEY){ if(pUndoState->Range[i].cpMax==Range->cpMin&&KeyStr[0]!='\r'){ if(!(bUndoDelimitation(pUndoState->KeyStr[i][0])^bUndoDelimitation(KeyStr[0]))){ pUndoState->KeyStr[i]=(char *)HeapReAlloc(hHeap,0,pUndoState->KeyStr[i],lstrlen(pUndoState->KeyStr[i])+lstrlen(KeyStr)+1); lstrcat(pUndoState->KeyStr[i],KeyStr); pUndoState->Range[i].cpMax+=lstrlen(KeyStr); HeapDefaultFree(KeyStr); //元に戻す、やり直しメニューをリセット ResetState_UndoMenu(); return; } } } //データ更新 pUndoState->Command[pUndoState->NowPos]=Command; pUndoState->KeyStr[pUndoState->NowPos]=KeyStr; pUndoState->DelStr[pUndoState->NowPos]=DelStr; pUndoState->Range[pUndoState->NowPos]=*Range; if(DelRange) pUndoState->DelRange[pUndoState->NowPos]=*DelRange; pUndoState->NowPos++; if(pUndoState->NowPos==MAX_UNDONUM) pUndoState->NowPos=0; if(pUndoState->Command[pUndoState->NowPos]){ //一番古い情報を切り捨てる TextEdit_DeleteUndoData(WndNum,pUndoState->NowPos); } //元に戻す、やり直しメニューをリセット ResetState_UndoMenu(); } void TextEdit_DeleteUndoData(int WndNum,int pos){ extern MDIINFO MdiInfo[MAX_WNDNUM]; TEXTEDIT_UNDOSTATE *pUndoState; pUndoState=MdiInfo[WndNum].edit_undo; if(pUndoState->KeyStr[pos]) HeapDefaultFree(pUndoState->KeyStr[pos]); if(pUndoState->DelStr[pos]) HeapDefaultFree(pUndoState->DelStr[pos]); pUndoState->Command[pos]=0; }