/****************************************************************************** TrackDel: Delete current character in the tracking mode. The function returns TRUE if track-deletion is successful. ******************************************************************************/ BOOL TrackDel(PTERWND w, long line, int col, BOOL forward) { int font; LPWORD fmt; long SaveLine=CurLine; if (!TrackChanges) return false; font=GetCurCfmt(w,line,col); if (True(TerFont[font].style&PICT)) return false; // 20061208: delete of picture not yet supported for track-changes if (TerFont[font].InsRev==TrackRev) return false; // this character was inserted by the current reviewer, so it let be deleted normally if (True(TerFont[font].DelRev)) goto END; // already track deleted SaveUndo(w,line,col,line,col,'F'); // save undo of current formatting fmt=OpenCfmt(w,line); fmt[col]=SetTrackingFont(w,fmt[col],TRACK_DEL); CloseCfmt(w,line); END: if (forward) NextTextPos(w,&CurLine,&CurCol); return true; }
void IconDes::BeginResize() { CancelSelect(); FinishPaste(); SaveUndo(); Refresh(); SyncShow(); }
bool CommonPool::PrepareFilter() { if (sample_type == NONE) return false; player->Stop(); mainWindow->PostMessage(TRANSPORT_STOP); // stop playing if (selection == NONE) SelectAll(); // select all if noe is selected if (Prefs.save_undo) SaveUndo(); // save undo data return true; }
void IconDes::SetColor0(RGBA color) { FinishPaste(); doselection = false; rgbactrl.Mask(false); SaveUndo(); ImageBuffer ib(Current().image); MaskFill(ib, color, 255); Refresh(); SetCurrentImage(ib); SyncShow(); SetBar(); }
NAMESPACE_UPP void IconDes::LeftDown(Point p, dword flags) { SetFocus(); if(!IsCurrent()) return; SaveUndo(); startpoint = GetPos(p); if(IsPasting()) { if(Rect(Current().pastepos, Current().paste_image.GetSize()).Contains(startpoint)) { startpoint -= Current().pastepos; SetCapture(); } else FinishPaste(); return; } SetCapture(); Current().base_image = CurrentImage(); if(flags & K_SHIFT) { ImageBuffer ib(CurrentImage()); if(!doselection) { RGBA c = CurrentColor(); c.r += 127; MaskFill(ib, c, 0); } FloodFill(ib, CurrentColor(), startpoint, ib.GetSize()); SetCurrentImage(ib); if(!doselection) MaskSelection(); return; } if(selectrect) EmptyRectTool(startpoint, flags); else if(tool) (this->*tool)(startpoint, flags); }
void CWedDoc::Serialize(CArchive& ar, const char *docname) { CString num, str; CString filename = docname; PathToFname(filename); if (ar.IsStoring()) { // Writing CWaitCursor cursor; POSITION pos; pos = strlist.GetHeadPosition(); origlines = 0; while(TRUE) { CString line; if(!(origlines % 100)) { num.Format("Writing %s line %d", filename, origlines); message(num); } origlines++; if (!pos) break; line = strlist.GetNext(pos); // Obey tab save option if(Tab2Space || spaceify) ExpandTabs(line); // Dispose space from EOL line.TrimRight(); // Write out to file ar.WriteString(line); // Do end of line according to settings if(unix) ar.WriteString("\n"); else ar.WriteString("\r\n"); } num.Format("Wrote %s", filename); message(num); // If user decides to save, save undo/redo info as well SaveUndo(); SaveRedo(); } else { // Reading CWaitCursor cursor; char buff[DETECTSIZE]; strlist.RemoveAll(); // Determine file type CFile* fp = ar.GetFile(); int rlen = fp->Read(buff, DETECTSIZE); // File without a newline ---> default to DOS if(!strstr(buff, "\n")) unix = FALSE; else if (strstr(buff, "\r\n")) unix = FALSE; else unix = TRUE; // Take a wild guess for tabs if(!strstr(buff, "\t") && rlen > DETECTSIZE/2 ) { spaceify = TRUE; } // Start over on file fp->Seek(0,CFile::begin); origlines = 0; // Load file while(TRUE) { str = ""; if(!(origlines % 100)) { CString num; num.Format("Reading %s line %d", filename, origlines); message(num); } if(YieldToWinEx()) { readonly = TRUE; AfxMessageBox("Aborted load, partial buffer is readonly."); break; } TRY { if(!ar.ReadString(str)) break; } CATCH_ALL(ee); END_CATCH_ALL origlines++; TRY { strlist.AddTail(str); } CATCH(CMemoryException, ee) { //P2N("Memory exception\r\n"); break; } END_CATCH } // So unix can see an unlocked file // Let others see it // ReleaseFile(fp, 1); // Patch things up if( strlist.IsEmpty()) { //P2N("Empty file\r\n"); strlist.AddTail(""); } } }
/****************************************************************************** TrackDelBlock: Delete the specified block of text in the tracking mode. The function returns TRUE if track-deletion is successful. ******************************************************************************/ BOOL TrackDelBlock(PTERWND w, long BegLine, int BegCol, long EndLine, int EndCol, BOOL ResetHilight, BOOL repaint) { long l; int i,StartPos,EndPos,font; LPWORD fmt; LPINT NewFont=NULL; BOOL TrackDelTextFound; // indicates the text that needs to be deleted using the tracking method (not by simply removing the character) BOOL IsTrackDelLine; BOOL RevInsertedLine; long DelCount=0,GroupUndoRef,EndAbsPos,NewFontMax; if (!TrackChanges) return false; // check if text the text to be deleted using tracking method exists in the block TrackDelTextFound=false; for (l=BegLine;l<=EndLine;l++) { if (False(LineFlags2(l)&LFLAG2_INS_REV)) { // no text in this line inserted by a reviewer TrackDelTextFound=true; // this line needs to be deleted using the tracking method break; } StartPos=(l==BegLine)?BegCol:0; EndPos=(l==EndLine)?EndCol:LineLen(l); // exclusive fmt=OpenCfmt(w,l); for (i=StartPos;i<EndPos;i++) { font=fmt[i]; if (TerFont[font].InsRev!=TrackRev) { TrackDelTextFound=true; // this text needs to be deleted using the tracking method break; } } CloseCfmt(w,l); if (TrackDelTextFound) break; } if (!TrackDelTextFound) return false; // normal deletion will do // undo consists of saving the original text, and marking the resultant text as inserted EndAbsPos=RowColToAbs(w,EndLine,EndCol); GroupUndoRef=UndoRef; SaveUndo(w,BegLine,BegCol,EndLine,EndCol-1,'D'); // save undo // use font cache to better efficiency: 20070927 NewFontMax=TotalFonts; NewFont=MemAlloc(sizeof(int)*(NewFontMax+1)); for (i=0;i<NewFontMax;i++) NewFont[i]=-1; // 20070927: temporary field to store new font id generated for an existing font id // scan the range of text and do deletion of both types (regular delete and track-delete) for (l=BegLine;l<=EndLine;l++) { StartPos=(l==BegLine)?BegCol:0; EndPos=(l==EndLine)?EndCol:LineLen(l); // exclusive IsTrackDelLine=(False(LineFlags2(l)&LFLAG2_INS_REV)); // no text in this line inserted by a reviewer if (IsTrackDelLine) { // do track delete of the text in this line fmt=OpenCfmt(w,l); for (i=StartPos;i<EndPos;i++) { font=fmt[i]; if (TerFont[font].DelRev!=TrackRev) { if (font<NewFontMax && NewFont[font]>=0) fmt[i]=(WORD)NewFont[font]; // 20070927: use previously created font id else { fmt[i]=SetTrackingFont(w,fmt[i],TRACK_DEL); if (font<NewFontMax) NewFont[font]=fmt[i]; // save for next lookup } } } CloseCfmt(w,l); continue; } // check if the entire line contains the text entered by the current reviewer (and not deleted by another reviewer) RevInsertedLine=true; fmt=OpenCfmt(w,l); for (i=StartPos;i<EndPos;i++) { font=fmt[i]; if (TerFont[font].InsRev!=TrackRev || True(TerFont[font].DelRev)) { RevInsertedLine=false; break; } } CloseCfmt(w,l); if (RevInsertedLine && StartPos==0 && EndPos==LineLen(l)) { // delete the whole line DelCount+=LineLen(l); // number of characters actually removed if (l<CurLine) CurLine--; // adjust current line if (l==CurLine) { CurLine--; CurCol=LineLen(CurLine)-1; } MoveLineArrays(w,l,1,'D'); EndLine--; continue; } // scan each character in the line to perform indicated delete operation (regular delete or track-delete) fmt=OpenCfmt(w,l); for (i=StartPos;i<EndPos;i++) { font=fmt[i]; if (True(TerFont[font].DelRev)) continue; // already track-delete if (TerFont[font].InsRev==TrackRev) { // text inserted by the current reviewer - do regular delete MoveLineData(w,l,i,1,'D'); fmt=OpenCfmt(w,l); // MoveLineData invalidates the fmt pointer i--; // don't let i advance because the character deleted at this position EndPos--; DelCount++; if (l==CurLine && i<CurCol) CurCol--; } else { // regular text or text inserted by another reviewer - track delete if (TerFont[font].DelRev!=TrackRev) fmt[i]=SetTrackingFont(w,fmt[i],TRACK_DEL); } } CloseCfmt(w,l); } if (NewFont!=NULL) MemFree(NewFont); // release font cache NewFont=NULL; // mark the resultant text as inserted UndoRef=GroupUndoRef; EndAbsPos-=DelCount; // new ending pos AbsToRowCol(w,EndAbsPos,&EndLine,&EndCol); SaveUndo(w,BegLine,BegCol,EndLine,EndCol-1,'I'); // save undo if (CurLine>=TotalLines) CurLine=TotalLines-1; if (CurCol>=LineLen(CurLine)) CurCol=LineLen(CurLine)-1; if (CurCol<0) CurCol=0; if (ResetHilight) HilightType=HILIGHT_OFF; if (repaint) PaintTer(w); return true; }
/****************************************************************************** RejectChange: Reject the current changed text. ******************************************************************************/ BOOL RejectChange(PTERWND w, long line, int col) { int i,font,CurCfmt,RevId; long l,BegLine,EndLine; int BegCol,EndCol,StartPos,EndPos; LPWORD fmt; CurCfmt=GetCurCfmt(w,line,col); if (!IsTrackChangeFont(w,CurCfmt)) return false; // ** reject deletion ** if (TerFont[CurCfmt].DelRev>0) { BegLine=EndLine=line; BegCol=EndCol=col; if (!GetDelBeginPos(w,&BegLine, &BegCol)) return false; // 20060929: since deletion happens after insertion, reject deletion including any previous insertion if (!TerLocateChangedChar(hTerWnd,-1,TerFont[CurCfmt].DelRev,false,&EndLine,&EndCol,true)) return false; // Save undo for insertion SaveUndo(w,BegLine,BegCol,EndLine,EndCol,'F'); // save font ids // Reset reviewer ids for (l=BegLine;l<=EndLine;l++) { StartPos=(l==BegLine)?BegCol:0; EndPos=(l==EndLine)?EndCol:LineLen(l); // exclusive // scan each character in the line to perform indicated delete operation (regular delete or track-delete) fmt=OpenCfmt(w,l); for (i=StartPos;i<EndPos;i++) { font=fmt[i]; RevId=TerFont[font].DelRev; font=SetTrackingFont(w,font,TRACK_NO_DEL); // 20060929: turn-off deletion if (false && reviewer[RevId].DelColor==TerFont[font].TextColor) { // 20060908: commented out - reset color font=(int)GetNewColor(w,(WORD)font,(DWORD)CLR_AUTO,0L,l,i); } if (True(reviewer[RevId].DelStyle&TerFont[font].style)) { // reset style font=SetFontStyle(w,font,reviewer[RevId].DelStyle,false); // reset the reviewer style } fmt[i]=font; } CloseCfmt(w,l); } TerArg.modified++; return true; } // ** reject font change, 20080626 if (TerFont[CurCfmt].FmtRev>0) { BegLine=EndLine=line; BegCol=EndCol=col; if (!GetChangeBeginPos(w,&BegLine, &BegCol)) return false; if (!TerLocateChangedChar2(hTerWnd,-1,-1,TerFont[CurCfmt].FmtRev,false,&EndLine,&EndCol,true)) return false; // Save undo for insertion SaveUndo(w,BegLine,BegCol,EndLine,EndCol,'F'); // save font ids // Reset to original font id for (l=BegLine;l<=EndLine;l++) { StartPos=(l==BegLine)?BegCol:0; EndPos=(l==EndLine)?EndCol:LineLen(l); // exclusive // scan each character in the line to perform indicated delete operation (regular delete or track-delete) fmt=OpenCfmt(w,l); for (i=StartPos;i<EndPos;i++) { font=fmt[i]; if (TerFont[font].FmtRev==0) continue; // this can happen when rejecting a formatted string within an inserted text font=TerFont[font].FmtOrigFont; // reset to original font RevId=TerFont[font].FmtRev; if (RevId>0) { // this should not happen since the orig-font would be a normal font font=SetTrackingFont(w,font,TRACK_NO_FMT); //inase the original font if (True(reviewer[RevId].FmtStyle&TerFont[font].style)) { // reset style font=SetFontStyle(w,font,reviewer[RevId].FmtStyle,false); // reset the reviewer style } } fmt[i]=font; } CloseCfmt(w,l); } TerArg.modified++; return true; } // ** Reject insertion ** if (TerFont[CurCfmt].InsRev>0) { BOOL SaveUnprotDel=True(TerFlags&TFLAG_UNPROTECTED_DEL); BegLine=EndLine=line; BegCol=EndCol=col; if (!GetChangeBeginPos(w,&BegLine, &BegCol)) return false; if (!TerLocateChangedChar(hTerWnd,TerFont[CurCfmt].InsRev,TerFont[CurCfmt].DelRev,false,&EndLine,&EndCol,true)) return false; HilightBegRow=BegLine; HilightBegCol=BegCol; HilightEndRow=EndLine; HilightEndCol=EndCol; StretchHilight=false; HilightType=HILIGHT_CHAR; TerFlags|=TFLAG_UNPROTECTED_DEL; TerDeleteBlock(hTerWnd,false); if (!SaveUnprotDel) ResetUintFlag(TerFlags,TFLAG_UNPROTECTED_DEL); return true; } return true; }
/****************************************************************************** AcceptChange: Accept the current changed text. ******************************************************************************/ BOOL AcceptChange(PTERWND w, long line, int col) { int i,font,CurCfmt,RevId; long l,BegLine,EndLine; int BegCol,EndCol,StartPos,EndPos; LPWORD fmt; CurCfmt=GetCurCfmt(w,line,col); if (!IsTrackChangeFont(w,CurCfmt)) return false; BegLine=EndLine=line; BegCol=EndCol=col; if (!GetChangeBeginPos(w,&BegLine, &BegCol)) return false; if (!TerLocateChangedChar2(hTerWnd,TerFont[CurCfmt].InsRev,TerFont[CurCfmt].DelRev,TerFont[CurCfmt].FmtRev,false,&EndLine,&EndCol,true)) return false; // 20080626 // ** Accept deletion ** if (TerFont[CurCfmt].DelRev>0) { BOOL SaveUnprotDel=True(TerFlags&TFLAG_UNPROTECTED_DEL); HilightBegRow=BegLine; HilightBegCol=BegCol; HilightEndRow=EndLine; HilightEndCol=EndCol; StretchHilight=false; HilightType=HILIGHT_CHAR; TerFlags|=TFLAG_UNPROTECTED_DEL; TerDeleteBlock(hTerWnd,false); if (!SaveUnprotDel) ResetUintFlag(TerFlags,TFLAG_UNPROTECTED_DEL); return true; } // ** Accept insertion ** // Save undo for insertion SaveUndo(w,BegLine,BegCol,EndLine,EndCol,'F'); // save font ids // Reset reviewer ids for (l=BegLine;l<=EndLine;l++) { StartPos=(l==BegLine)?BegCol:0; EndPos=(l==EndLine)?EndCol:LineLen(l); // exclusive // scan each character in the line to perform indicated delete operation (regular delete or track-delete) fmt=OpenCfmt(w,l); for (i=StartPos;i<EndPos;i++) { font=fmt[i]; RevId=TerFont[font].InsRev; font=SetTrackingFont(w,font,TRACK_NONE); if (reviewer[RevId].InsColor==TerFont[font].TextColor) { // reset color font=(int)GetNewColor(w,(WORD)font,(DWORD)CLR_AUTO,0L,l,i); } if (True(reviewer[RevId].InsStyle&TerFont[font].style)) { // reset style font=SetFontStyle(w,font,reviewer[RevId].InsStyle,false); // reset the reviewer style } fmt[i]=font; } CloseCfmt(w,l); } TerArg.modified++; return true; }