/// SimpleMarkText() static void SimpleMarkText(struct InstData *data, LONG startx, struct line_node *startline, LONG stopx, struct line_node *stopline) { ENTER(); if(Enabled(data)) { data->blockinfo.enabled = FALSE; MarkText(data, data->blockinfo.startx, data->blockinfo.startline, data->blockinfo.stopx, data->blockinfo.stopline); } // else { SetCursor(data, data->CPos_X, data->actualline, FALSE); } data->blockinfo.startline = startline; data->blockinfo.startx = startx; data->blockinfo.stopline = data->actualline = stopline; data->blockinfo.stopx = data->CPos_X = stopx; data->blockinfo.enabled = TRUE; ScrollIntoDisplay(data); MarkText(data, startx, startline, stopx, stopline); LEAVE(); }
long Redo(struct InstData *data) { ENTER(); D(DBF_UNDO, "undolevel: %ld undocur: %ld undofill: %ld", data->undolevel, data->undocur, data->undofill); // check if there something to redo at all if(data->undofill > 0 && data->undocur < data->undofill) { struct UserAction *buffer = (struct UserAction *)data->undopointer; if(Enabled(data)) { data->blockinfo.enabled = FALSE; MarkText(data->blockinfo.startx, data->blockinfo.startline, data->blockinfo.stopx, data->blockinfo.stopline, data); } // in case undocur is equal zero then we have to // set the undoavailable attribute to true to signal // others that undo is available if(data->undocur == 0) set(data->object, MUIA_TextEditor_UndoAvailable, TRUE); data->undopointer = (APTR)((char *)data->undopointer + sizeof(struct UserAction)); data->undocur++; // if(data->actualline != LineNode(buffer->y, data) || data->CPos_X != buffer->x) SetCursor(data->CPos_X, data->actualline, FALSE, data); data->CPos_X = buffer->x; data->actualline = LineNode(buffer->y, data); ScrollIntoDisplay(data); switch(buffer->type) { case ET_PASTECHAR: PasteChars(data->CPos_X++, data->actualline, 1, (char *)&buffer->del.character, buffer, data); break; case ET_BACKSPACECHAR: case ET_DELETECHAR: RemoveChars(data->CPos_X, data->actualline, 1, data); break; case ET_SPLITLINE: SplitLine(data->CPos_X, data->actualline, TRUE, NULL, data); break; case ET_MERGELINES: case ET_BACKSPACEMERGE: MergeLines(data->actualline, data); break; case ET_PASTEBLOCK: { struct Hook *oldhook = data->ImportHook; data->ImportHook = &ImPlainHook; InsertText(data, (char *)buffer->clip, TRUE); data->ImportHook = oldhook; MyFreePooled(data->mypool, buffer->clip); buffer->blk.x = data->CPos_X; buffer->blk.y = LineNr(data->actualline, data); } break; case ET_DELETEBLOCK_NOMOVE: case ET_DELETEBLOCK: { struct marking block = { TRUE, LineNode(buffer->y, data), buffer->x, LineNode(buffer->blk.y, data), buffer->blk.x }; char *clip = GetBlock(&block, data); CutBlock2(data, FALSE, FALSE, &block, TRUE); buffer->clip = (unsigned char *)clip; } break; default: // nothing to do break; } ScrollIntoDisplay(data); if(data->flags & FLG_Active) SetCursor(data->CPos_X, data->actualline, TRUE, data); // if undocur == undofill this signals that we // don't have any things to redo anymore. if(data->undocur == data->undofill) set(data->object, MUIA_TextEditor_RedoAvailable, FALSE); RETURN(TRUE); return(TRUE); } else { DoMethod(data->object, MUIM_TextEditor_HandleError, Error_NothingToRedo); RETURN(FALSE); return(FALSE); } }
long Undo(struct InstData *data) { ENTER(); D(DBF_UNDO, "undolevel: %ld undocur: %ld undofill: %ld", data->undolevel, data->undocur, data->undofill); // check if there is something in the undo // buffer available if(data->undolevel > 0 && data->undocur > 0) { struct UserAction *buffer; BOOL crsr_move = TRUE; if(Enabled(data)) { data->blockinfo.enabled = FALSE; MarkText(data->blockinfo.startx, data->blockinfo.startline, data->blockinfo.stopx, data->blockinfo.stopline, data); } // as the redo operation automatically // becomes available when undo is used we just // check here if we didn't yet set RedoAvailable // as we only want to set it once if(data->undocur == data->undofill) set(data->object, MUIA_TextEditor_RedoAvailable, TRUE); data->undopointer = (APTR)((char *)data->undopointer - sizeof(struct UserAction)); data->undocur--; buffer = (struct UserAction *)data->undopointer; // if(data->actualline != LineNode(buffer->y, data) || data->CPos_X != buffer->x) SetCursor(data->CPos_X, data->actualline, FALSE, data); data->CPos_X = buffer->x; data->actualline = LineNode(buffer->y, data); ScrollIntoDisplay(data); switch(buffer->type) { case ET_PASTECHAR: { buffer->del.character = *(data->actualline->line.Contents+data->CPos_X); buffer->del.style = GetStyle(data->CPos_X, data->actualline); buffer->del.flow = data->actualline->line.Flow; buffer->del.separator = data->actualline->line.Separator; RemoveChars(data->CPos_X, data->actualline, 1, data); } break; case ET_BACKSPACECHAR: { PasteChars(data->CPos_X++, data->actualline, 1, (char *)&buffer->del.character, buffer, data); } break; case ET_DELETECHAR: { PasteChars(data->CPos_X, data->actualline, 1, (char *)&buffer->del.character, buffer, data); } break; case ET_SPLITLINE: { MergeLines(data->actualline, data); } break; case ET_MERGELINES: { SplitLine(data->CPos_X, data->actualline, FALSE, buffer, data); } break; case ET_BACKSPACEMERGE: { SplitLine(data->CPos_X, data->actualline, TRUE, buffer, data); } break; case ET_PASTEBLOCK: { struct marking block = { TRUE, LineNode(buffer->y, data), buffer->x, LineNode(buffer->blk.y, data), buffer->blk.x }; char *clip = GetBlock(&block, data); CutBlock2(data, FALSE, FALSE, &block, TRUE); buffer->clip = (unsigned char *)clip; } break; case ET_DELETEBLOCK_NOMOVE: crsr_move = FALSE; // continue case ET_DELETEBLOCK: { struct Hook *oldhook = data->ImportHook; char *clip = (char *)buffer->clip; data->ImportHook = &ImPlainHook; InsertText(data, clip, crsr_move); data->ImportHook = oldhook; MyFreePooled(data->mypool, clip); buffer->blk.x = data->CPos_X; buffer->blk.y = LineNr(data->actualline, data); if(!crsr_move) { data->CPos_X = buffer->x; data->actualline = LineNode(buffer->y, data); } } break; default: // nothing to do break; } ScrollIntoDisplay(data); if(data->flags & FLG_Active) SetCursor(data->CPos_X, data->actualline, TRUE, data); // if there are no further undo levels we // have to set UndoAvailable to FALSE if(data->undocur == 0) { set(data->object, MUIA_TextEditor_UndoAvailable, FALSE); if(!(data->flags & FLG_UndoLost)) data->HasChanged = FALSE; } RETURN(TRUE); return(TRUE); } else { DoMethod(data->object, MUIM_TextEditor_HandleError, Error_NothingToUndo); RETURN(FALSE); return(FALSE); } }
LONG CutBlock2(struct InstData *data, BOOL Clipboard, BOOL NoCut, struct marking *newblock, BOOL update) { LONG tvisual_y, error; LONG startx, stopx; LONG res = 0; struct line_node *startline, *stopline; ENTER(); startx = newblock->startx; stopx = newblock->stopx; startline = newblock->startline; stopline = newblock->stopline; //D(DBF_STARTUP, "CutBlock2: %ld-%ld %lx-%lx %ld %ld", startx, stopx, startline, stopline, Clipboard, NoCut); if(startline != stopline) { struct line_node *c_startline = startline->next; data->update = FALSE; if(Clipboard == TRUE) { if(InitClipboard(data, IFFF_WRITE)) { D(DBF_CLIPBOARD, "writing FORM"); error = PushChunk(data->iff, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN); SHOWVALUE(DBF_CLIPBOARD, error); ClipChars(startx, startline, startline->line.Length-startx, data); } else { Clipboard = FALSE; } } while(c_startline != stopline) { if(Clipboard == TRUE) { ClipLine(c_startline, data); } if(NoCut == FALSE) { struct line_node *cc_startline = c_startline; MyFreePooled(data->mypool, c_startline->line.Contents); if(c_startline->line.Styles != NULL) MyFreePooled(data->mypool, c_startline->line.Styles); data->totallines -= c_startline->visual; c_startline = c_startline->next; //D(DBF_STARTUP, "FreeLine %08lx", cc_startline); FreeLine(cc_startline, data); } else c_startline = c_startline->next; } if(Clipboard == TRUE) { if(stopx != 0) ClipChars(0, stopline, stopx, data); EndClipSession(data); } if(NoCut == FALSE) { startline->next = stopline; stopline->previous = startline; //D(DBF_STARTUP, "RemoveChars: %ld %ld %08lx %ld", startx, stopx, startline, startline->line.Length); if(startline->line.Length-startx-1 > 0) RemoveChars(startx, startline, startline->line.Length-startx-1, data); if(stopx != 0) RemoveChars(0, stopline, stopx, data); data->CPos_X = startx; data->actualline = startline; MergeLines(startline, data); } } else { if(Clipboard == TRUE) { if(InitClipboard(data, IFFF_WRITE)) { D(DBF_CLIPBOARD, "writing FORM"); error = PushChunk(data->iff, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN); SHOWVALUE(DBF_CLIPBOARD, error); ClipChars(startx, startline, stopx-startx, data); EndClipSession(data); } if(update == TRUE && NoCut == TRUE) { MarkText(data->blockinfo.startx, data->blockinfo.startline, data->blockinfo.stopx, data->blockinfo.stopline, data); goto end; } } if(NoCut == FALSE) { data->CPos_X = startx; RemoveChars(startx, startline, stopx-startx, data); if(update == TRUE) goto end; } } tvisual_y = LineToVisual(startline, data)-1; if(tvisual_y < 0 || tvisual_y > data->maxlines) { //D(DBF_STARTUP, "ScrollIntoDisplay"); ScrollIntoDisplay(data); tvisual_y = 0; } if(update == TRUE) { //D(DBF_STARTUP, "DumpText! %ld %ld %ld", data->visual_y, tvisual_y, data->maxlines); data->update = TRUE; DumpText(data->visual_y+tvisual_y, tvisual_y, data->maxlines, TRUE, data); } res = tvisual_y; end: RETURN(res); return res; }