Ejemplo n.º 1
0
void
UndoWidget::HandleMouseUp
	(
	const JPoint&			pt,
	const JXMouseButton		button,
	const JXButtonStates&	buttonStates,
	const JXKeyModifiers&	modifiers
	)
{
	JPainter* p = NULL;

	// Make sure that the left button is pressed,
	// and that a drag painter exists
	if (button == kJXLeftButton && GetDragPainter(&p))
		{
		// Erase the last line that was drawn
		p->Line(itsStartPt, itsPrevPt);

		// Delete the drag painter
		DeleteDragPainter();

		// Add this set of points to our JArray
		itsPoints->AppendElement(itsStartPt);
		itsPoints->AppendElement(itsPrevPt);

		// Create the undo object to undo the addition of this line

		UndoLine* undo = new UndoLine(this);
		assert(undo != NULL);
		NewUndo(undo);

		// Tell the widget to redraw itself
		Refresh();
		}
}
void
GLUndoElementCut::Undo()
{
	// change value to old value
	GetData()->InsertElement(GetCell(), itsValue);

	// create undo object to change it back
	GLUndoElementAppend* undo = 
		new GLUndoElementAppend(GetTable(), GetCell());
	assert(undo != NULL);
	NewUndo(undo);
}
Ejemplo n.º 3
0
BOOL EnterInsertForUndo(PPOSITION Pos, ULONG Length)
{	ULONG ByteCount = CountBytes(Pos);

	CheckForUndoneToRelease(TRUE);
	EnableUndo();
	if (!LastUndo || (LastUndo->Pos != (ULONG)-1 &&
					  LastUndo->Pos != ByteCount - LastUndo->Inserted))
		if (!NewUndo()) return (FALSE);
	if (LastUndo->Pos == (ULONG)-1) LastUndo->Pos = ByteCount;
	LastUndo->Inserted += Length;
	return (TRUE);
}
void
GLUndoElementsChange::Undo()
{

	// we need to create this before we change the data, because
	// it needs to read the old data first. We can't yet call NewUndo, 
	// though, because that will delete us.

	GLUndoElementsChange* undo =
		new GLUndoElementsChange(GetTable(), GetStartCell(), GetEndCell(), GetType());
	assert(undo != NULL);
	
	GRaggedFloatTableData* data 		= GetData();
	JPoint start 						= GetStartCell();
	JPoint end 							= GetEndCell();
	GLUndoElementsBase::UndoType type 	= GetType();

	if (type == GLUndoElementsBase::kRows)
		{
		}
	else if (type == GLUndoElementsBase::kCols)
		{
		JSize cols = itsValues->GetElementCount();
		for (JSize i = 1; i <= cols; i++)
			{
			JArray<JFloat>* col = itsValues->NthElement(i);
			JSize rows = col->GetElementCount();
			for (JSize j = 1; j <= rows; j++)
				{
				JFloat value = col->GetElement(j);
				data->SetElement(j, i + start.x - 1, value);
				}
			}
		}
	else if (type == GLUndoElementsBase::kElements)
		{
		for (JSize i = start.x; i <= (JSize)end.x; i++)
			{
			JArray<JFloat>* col = itsValues->NthElement(i - start.x + 1);
			JSize rows = col->GetElementCount();
			for (JSize j = start.y; j <= start.y + rows -1; j++)
				{
				JFloat value = col->GetElement(j - start.y + 1);
				data->SetElement(j, i, value);
				}
			}
		}
		
	NewUndo(undo);
}
void
GLUndoElementsInsert::Undo()
{

	// we need to create this before we change the data, because
	// it needs to read the old data first. We can't yet call NewUndo, 
	// though, because that will delete us.

	GLUndoElementsCut* undo =
		new GLUndoElementsCut(GetTable(), GetStartCell(), GetEndCell(), GetType());
	assert(undo != NULL);
	
	GRaggedFloatTableData* data 		= GetData();
	JPoint start 						= GetStartCell();
	JPoint end 							= GetEndCell();
	GLUndoElementsBase::UndoType type 	= GetType();
	JSize cols							= data->GetDataColCount();

	if (type == GLUndoElementsBase::kRows)
		{
		for (JCoordinate i = start.y; i <= end.y; i++)
			{
			data->RemoveRow(start.y);
			}
		}
	else if (type == GLUndoElementsBase::kCols)
		{
		for (JCoordinate i = start.x; i <= end.x; i++)
			{
			data->RemoveCol(start.x);
			}
		}
	else if (type == GLUndoElementsBase::kElements)
		{
		for (JCoordinate i = start.x; i <= end.x; i++)
			{
			for (JCoordinate j = start.y; j <= end.y; j++)
				{
				if (data->CellValid(start.y, i))
					{
					data->RemoveElement(start.y, i);
					}
				}
			}
		}
		
	NewUndo(undo);
}
Ejemplo n.º 6
0
void
UndoWidget::RemoveLastLine()
{
	const JSize count = itsPoints->GetElementCount();
	assert(count >= 2);
	JPoint start = itsPoints->GetElement(count - 1);
	JPoint end = itsPoints->GetElement(count);
	itsPoints->RemoveElement(count);
	itsPoints->RemoveElement(count - 1);
	Refresh();

	RedoLine* redo = new RedoLine(this, start, end);
	assert(redo != NULL);

	NewUndo(redo);
}
void
GLUndoElementAppend::Undo()
{
	// get current value
	JFloat value = 0;
	GetData()->GetElement(GetCell(), &value);

	// change value to old value
	GetData()->RemoveElement(GetCell());

	// create undo object to change it back
	GLUndoElementCut* undo = 
		jnew GLUndoElementCut(GetTable(), GetCell(), value);
	assert(undo != NULL);
	NewUndo(undo);
}
Ejemplo n.º 8
0
void
UndoWidget::AddLine
	(
	const JPoint& start,
	const JPoint& end
	)
{
	// Add this set of points to our JArray
	itsPoints->AppendElement(start);
	itsPoints->AppendElement(end);

	// Tell the widget to redraw itself
	Refresh();

	UndoLine* undo = new UndoLine(this);
	assert(undo != NULL);

	NewUndo(undo);
}
Ejemplo n.º 9
0
void StartUndoSequence(void)
{
	if (ViewOnlyFlag) return;
	if (!(GlobalUndoFlags & UD_BYUNDO) && Redoing) {
		Redoing = FALSE;
		if (LastUndo!=NULL && LastUndo->UndoRef!=NULL)
			NextSequenceUndo = LastUndo->UndoRef;
	}
	if (StartWithRemove) CheckForUndoneToRelease(FALSE);
	if (UndoLimit!=(ULONG)-1 && UndoMemUsed>UndoLimit && FirstUndo!=NULL) {
		do {
			do {
				LPUNDO ToDelete = FirstUndo;

				if ((FirstUndo = FirstUndo->Next) == NULL) {
					LastUndo = NextSequenceUndo = NULL;
					UndoSequences = 1;
				}
				if (ToDelete->DelFill) {
					if (ToDelete->Flags & UD_GLOBALMEM) {
						UndoMemUsed -= GlobalSize(ToDelete->DelMem);
						GlobalFree(ToDelete->DelMem);
					} else UndoMemUsed -= ToDelete->DelFill;
				}
				UndoMemUsed -= sizeof(UNDO);
				_ffree(ToDelete);
			} while (FirstUndo && !(FirstUndo->Flags & UD_NEWOP));
		} while (FirstUndo!=NULL && UndoMemUsed>UndoLimit);
		--UndoSequences;
		if (FirstUndo) FirstUndo->Prev = NULL;
	}
	if (!LastUndo || !(LastUndo->Flags & UD_NEWOP)
				  ||   LastUndo->Pos != (ULONG)-1) {
		if (!NewUndo()) {
			NextSequenceUndo = NULL;
			return;
		}
		++UndoSequences;
	}
	LastUndo->Flags |= UD_NEWOP | GlobalUndoFlags;
	GlobalUndoFlags &= UD_BYUNDO;
	NextSequenceUndo = LastUndo;
}
Ejemplo n.º 10
0
BOOL EnterDeleteForUndo(PPOSITION Pos, ULONG Length, WORD Flags)
	/*Flags: 1=enter as selected, reselect after undo
	 *		 2=remove last undo information, cannot be undone later
	 */
{	LPBYTE   NewBuf = NULL;
	HGLOBAL  NewMem = 0;
	POSITION p;
	ULONG	 Inx;
	ULONG	 ByteCount = CountBytes(Pos);
	ULONG	 OldSize;
	LPUNDO	 Reallocated = NULL;

	if (Flags & 2) {
		if (!LastUndo->Inserted) return (FALSE);
		--LastUndo->Inserted;
		return (TRUE);
	}
	CheckForUndoneToRelease(TRUE);
	EnableUndo();
	if (!LastUndo ||
		(LastUndo->Pos != (ULONG)-1
		 && (LastUndo->Pos != ByteCount - LastUndo->Inserted
			 || (int)(Flags & 1) != ((LastUndo->Flags & UD_SELECT) != 0)
			 || !(LastUndo->Flags & UD_GLOBALMEM
				  && LastUndo->DelFill+Length > 64000))))
		if (!NewUndo()) return (FALSE);
	if (LastUndo->Pos == (ULONG)-1) LastUndo->Pos = ByteCount;
	if (!LastUndo->DelFill) {
		OldSize = 0;
		if (Length > 64000) {
			LastUndo->Flags |= UD_GLOBALMEM;
			NewMem = GlobalAlloc(GMEM_MOVEABLE, Length);
			if (NewMem) NewBuf = GlobalLock(NewMem);
		} else {
			assert(!(LastUndo->Flags & UD_GLOBALMEM));
			LastUndo->Flags &= ~UD_GLOBALMEM;
			Reallocated = (LPUNDO)_frealloc(LastUndo,
											(size_t)(sizeof(UNDO)+Length));
			if (Reallocated == NULL) return (FALSE);
			NewBuf = (LPBYTE)Reallocated + sizeof(UNDO);
		}
	} else {
		if (LastUndo->Flags & UD_GLOBALMEM) {
			OldSize = GlobalSize(LastUndo->DelMem);
			if (LastUndo->DelFill + Length > OldSize) {
				NewMem = GlobalReAlloc(LastUndo->DelMem,
									   LastUndo->DelFill + Length,
									   GMEM_MOVEABLE);
			} else NewMem = LastUndo->DelMem;
			if (NewMem) NewBuf = GlobalLock(NewMem);
		} else {
			Reallocated = (LPUNDO)_frealloc(LastUndo,
											(size_t)(sizeof(UNDO) + Length
														  + LastUndo->DelFill));
			if (Reallocated == NULL) return (FALSE);
			NewBuf = (LPBYTE)Reallocated + sizeof(UNDO);
			OldSize = 0;
		}
	}
	UndoMemUsed -= OldSize;
	if (NewBuf == NULL) {
		if (NewMem) GlobalFree(NewMem);
		return (FALSE);
	}
	if (Reallocated!=NULL && Reallocated!=LastUndo) {
		/*correct any references to this object...*/
		if (NextSequenceUndo == LastUndo) NextSequenceUndo = Reallocated;
		if (Reallocated->Prev != NULL) Reallocated->Prev->Next = Reallocated;
		if (FirstUndo == LastUndo) FirstUndo = Reallocated;
		LastUndo = Reallocated;
	}
	Inx = LastUndo->DelFill;
	if (NewMem) {
		UndoMemUsed += GlobalSize(NewMem);
		LastUndo->DelMem = NewMem;
	} else UndoMemUsed += Length;
	LastUndo->DelFill += Length;
	if (Flags & 1) LastUndo->Flags |= UD_SELECT;
	p = *Pos;
	while (Length) {
		UINT n, c = CharAt(&p);

		if (c == C_EOF) {
			/*should not occur!...*/
			assert(c != C_EOF);		/*!?*/
			LastUndo->DelFill -= Length;
			break;
		}
		if (Length > p.p->Fill - p.i) n = p.p->Fill - p.i;
		else n = (UINT)Length;
		assert(p.p->PageBuf);
		assert(n > 0);
		assert(n <= PAGESIZE);
		assert(p.i+n <= PAGESIZE);
		hmemcpy(NewBuf + Inx, p.p->PageBuf + p.i, n);
		Inx += n;
		p.i += n;
		Length -= n;
	}
	if (NewMem) GlobalUnlock(NewMem);
	return (TRUE);
}