diff --git a/src/kits/interface/TextView.cpp b/src/kits/interface/TextView.cpp index fa6c492ced..c3ff1e8c64 100644 --- a/src/kits/interface/TextView.cpp +++ b/src/kits/interface/TextView.cpp @@ -1279,7 +1279,7 @@ BTextView::Cut(BClipboard *clipboard) _CancelInputMethod(); if (fUndo) { delete fUndo; - fUndo = new _BCutUndoBuffer_(this); + fUndo = new CutUndoBuffer(this); } Copy(clipboard); Delete(); @@ -1346,7 +1346,7 @@ BTextView::Paste(BClipboard *clipboard) if (fUndo) { delete fUndo; - fUndo = new _BPasteUndoBuffer_(this, text, len, runArray, + fUndo = new PasteUndoBuffer(this, text, len, runArray, runLen); } @@ -1370,7 +1370,7 @@ BTextView::Clear() // because when fUndo is NULL, undo is deactivated. if (fUndo) { delete fUndo; - fUndo = new _BClearUndoBuffer_(this); + fUndo = new ClearUndoBuffer(this); } Delete(); @@ -2083,8 +2083,7 @@ BTextView::TextRect() const /*! \brief Sets the insets from the bounds for the BTextView's text rectangle. */ void -BTextView::SetInsets(float _leftInset, float topInset, float rightInset, - float bottomInset) +BTextView::SetInsets(float left, float top, float right, float bottom) { // TODO: // * store in layout data @@ -2097,19 +2096,19 @@ BTextView::SetInsets(float _leftInset, float topInset, float rightInset, rectangle. */ void -BTextView::GetInsets(float* _leftInset, float* _topInset, float* _rightInset, - float* _bottomInset) const +BTextView::GetInsets(float* _left, float* _top, float* _right, + float* _bottom) const { BRect bounds = Bounds(); - if (_leftInset) - *_leftInset = fTextRect.left - bounds.left; - if (_topInset) - *_topInset = fTextRect.top - bounds.top; - if (_rightInset) - *_rightInset = bounds.right - fTextRect.right; - if (_bottomInset) - *_bottomInset = bounds.bottom - fTextRect.bottom; + if (_left) + *_left = fTextRect.left - bounds.left; + if (_top) + *_top = fTextRect.top - bounds.top; + if (_right) + *_right = bounds.right - fTextRect.right; + if (_bottom) + *_bottom = bounds.bottom - fTextRect.bottom; } @@ -2877,11 +2876,11 @@ void BTextView::_HandleBackspace() { if (fUndo) { - _BTypingUndoBuffer_ *undoBuffer = dynamic_cast<_BTypingUndoBuffer_ *>( + TypingUndoBuffer *undoBuffer = dynamic_cast( fUndo); if (!undoBuffer) { delete fUndo; - fUndo = undoBuffer = new _BTypingUndoBuffer_(this); + fUndo = undoBuffer = new TypingUndoBuffer(this); } undoBuffer->BackwardErase(); } @@ -3012,11 +3011,11 @@ void BTextView::_HandleDelete() { if (fUndo) { - _BTypingUndoBuffer_ *undoBuffer = dynamic_cast<_BTypingUndoBuffer_ *>( + TypingUndoBuffer *undoBuffer = dynamic_cast( fUndo); if (!undoBuffer) { delete fUndo; - fUndo = undoBuffer = new _BTypingUndoBuffer_(this); + fUndo = undoBuffer = new TypingUndoBuffer(this); } undoBuffer->ForwardErase(); } @@ -3156,11 +3155,10 @@ BTextView::_HandleAlphaKey(const char *bytes, int32 numBytes) { // TODO: block input if not editable (Andrew) if (fUndo) { - _BTypingUndoBuffer_ *undoBuffer - = dynamic_cast<_BTypingUndoBuffer_ *>(fUndo); + TypingUndoBuffer *undoBuffer = dynamic_cast(fUndo); if (!undoBuffer) { delete fUndo; - fUndo = undoBuffer = new _BTypingUndoBuffer_(this); + fUndo = undoBuffer = new TypingUndoBuffer(this); } undoBuffer->InputCharacter(numBytes); } @@ -4140,7 +4138,7 @@ BTextView::_MessageDropped(BMessage *inMessage, BPoint where, BPoint offset) if (fUndo) { delete fUndo; - fUndo = new _BDropUndoBuffer_(this, text, dataLen, runArray, + fUndo = new DropUndoBuffer(this, text, dataLen, runArray, runLen, dropOffset, internalDrop); } diff --git a/src/kits/interface/textview_support/UndoBuffer.cpp b/src/kits/interface/textview_support/UndoBuffer.cpp index d86883237f..7444fb5cfe 100644 --- a/src/kits/interface/textview_support/UndoBuffer.cpp +++ b/src/kits/interface/textview_support/UndoBuffer.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007, Haiku, Inc. + * Copyright 2003-2008, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -25,7 +25,7 @@ // #pragma mark - UndoBuffer -BTextView::UndoBuffer::UndoBuffer(BTextView *textView, undo_state state) +BTextView::UndoBuffer::UndoBuffer(BTextView* textView, undo_state state) : fTextView(textView), fTextData(NULL), @@ -37,7 +37,7 @@ BTextView::UndoBuffer::UndoBuffer(BTextView *textView, undo_state state) fTextView->GetSelection(&fStart, &fEnd); fTextLength = fEnd - fStart; - fTextData = (char *)malloc(fTextLength); + fTextData = (char*)malloc(fTextLength); memcpy(fTextData, fTextView->Text() + fStart, fTextLength); if (fTextView->IsStylable()) @@ -53,7 +53,7 @@ BTextView::UndoBuffer::~UndoBuffer() void -BTextView::UndoBuffer::Undo(BClipboard *clipboard) +BTextView::UndoBuffer::Undo(BClipboard* clipboard) { fRedo ? RedoSelf(clipboard) : UndoSelf(clipboard); @@ -62,16 +62,16 @@ BTextView::UndoBuffer::Undo(BClipboard *clipboard) undo_state -BTextView::UndoBuffer::State(bool *redo) +BTextView::UndoBuffer::State(bool* _isRedo) const { - *redo = fRedo; + *_isRedo = fRedo; return fState; } void -BTextView::UndoBuffer::UndoSelf(BClipboard *clipboard) +BTextView::UndoBuffer::UndoSelf(BClipboard* clipboard) { fTextView->Select(fStart, fStart); fTextView->Insert(fTextData, fTextLength, fRunArray); @@ -80,29 +80,29 @@ BTextView::UndoBuffer::UndoSelf(BClipboard *clipboard) void -BTextView::UndoBuffer::RedoSelf(BClipboard *clipboard) +BTextView::UndoBuffer::RedoSelf(BClipboard* clipboard) { } -// #pragma mark - _BCutUndoBuffer_ +// #pragma mark - CutUndoBuffer -_BCutUndoBuffer_::_BCutUndoBuffer_(BTextView *textView) +BTextView::CutUndoBuffer::CutUndoBuffer(BTextView* textView) : BTextView::UndoBuffer(textView, B_UNDO_CUT) { } -_BCutUndoBuffer_::~_BCutUndoBuffer_() +BTextView::CutUndoBuffer::~CutUndoBuffer() { } void -_BCutUndoBuffer_::RedoSelf(BClipboard *clipboard) +BTextView::CutUndoBuffer::RedoSelf(BClipboard* clipboard) { - BMessage *clip = NULL; + BMessage* clip = NULL; fTextView->Select(fStart, fStart); fTextView->Delete(fStart, fEnd); @@ -120,17 +120,18 @@ _BCutUndoBuffer_::RedoSelf(BClipboard *clipboard) } -// #pragma mark - _BPasteUndoBuffer_ +// #pragma mark - PasteUndoBuffer -_BPasteUndoBuffer_::_BPasteUndoBuffer_(BTextView *textView, const char *text, - int32 textLen, text_run_array *runArray, int32 runArrayLen) +BTextView::PasteUndoBuffer::PasteUndoBuffer(BTextView* textView, + const char* text, int32 textLen, text_run_array* runArray, + int32 runArrayLen) : BTextView::UndoBuffer(textView, B_UNDO_PASTE), fPasteText(NULL), fPasteTextLength(textLen), fPasteRunArray(NULL) { - fPasteText = (char *)malloc(fPasteTextLength); + fPasteText = (char*)malloc(fPasteTextLength); memcpy(fPasteText, text, fPasteTextLength); if (runArray) @@ -138,7 +139,7 @@ _BPasteUndoBuffer_::_BPasteUndoBuffer_(BTextView *textView, const char *text, } -_BPasteUndoBuffer_::~_BPasteUndoBuffer_() +BTextView::PasteUndoBuffer::~PasteUndoBuffer() { free(fPasteText); BTextView::FreeRunArray(fPasteRunArray); @@ -146,7 +147,7 @@ _BPasteUndoBuffer_::~_BPasteUndoBuffer_() void -_BPasteUndoBuffer_::UndoSelf(BClipboard *clipboard) +BTextView::PasteUndoBuffer::UndoSelf(BClipboard* clipboard) { fTextView->Select(fStart, fStart); fTextView->Delete(fStart, fStart + fPasteTextLength); @@ -156,7 +157,7 @@ _BPasteUndoBuffer_::UndoSelf(BClipboard *clipboard) void -_BPasteUndoBuffer_::RedoSelf(BClipboard *clipboard) +BTextView::PasteUndoBuffer::RedoSelf(BClipboard* clipboard) { fTextView->Select(fStart, fStart); fTextView->Delete(fStart, fEnd); @@ -165,34 +166,34 @@ _BPasteUndoBuffer_::RedoSelf(BClipboard *clipboard) } -// #pragma mark - _BClearUndoBuffer_ +// #pragma mark - ClearUndoBuffer -_BClearUndoBuffer_::_BClearUndoBuffer_(BTextView *textView) +BTextView::ClearUndoBuffer::ClearUndoBuffer(BTextView* textView) : BTextView::UndoBuffer(textView, B_UNDO_CLEAR) { } -_BClearUndoBuffer_::~_BClearUndoBuffer_() +BTextView::ClearUndoBuffer::~ClearUndoBuffer() { } void -_BClearUndoBuffer_::RedoSelf(BClipboard *clipboard) +BTextView::ClearUndoBuffer::RedoSelf(BClipboard* clipboard) { fTextView->Select(fStart, fStart); fTextView->Delete(fStart, fEnd); } -// #pragma mark - _BDropUndoBuffer_ +// #pragma mark - DropUndoBuffer -_BDropUndoBuffer_::_BDropUndoBuffer_(BTextView *textView, char const *text, - int32 textLen, text_run_array *runArray, int32 runArrayLen, - int32 location, bool internalDrop) +BTextView::DropUndoBuffer::DropUndoBuffer(BTextView* textView, + char const* text, int32 textLen, text_run_array* runArray, + int32 runArrayLen, int32 location, bool internalDrop) : BTextView::UndoBuffer(textView, B_UNDO_DROP), fDropText(NULL), fDropTextLength(textLen), @@ -201,7 +202,7 @@ _BDropUndoBuffer_::_BDropUndoBuffer_(BTextView *textView, char const *text, fInternalDrop = internalDrop; fDropLocation = location; - fDropText = (char *)malloc(fDropTextLength); + fDropText = (char*)malloc(fDropTextLength); memcpy(fDropText, text, fDropTextLength); if (runArray) @@ -212,7 +213,7 @@ _BDropUndoBuffer_::_BDropUndoBuffer_(BTextView *textView, char const *text, } -_BDropUndoBuffer_::~_BDropUndoBuffer_() +BTextView::DropUndoBuffer::~DropUndoBuffer() { free(fDropText); BTextView::FreeRunArray(fDropRunArray); @@ -220,7 +221,7 @@ _BDropUndoBuffer_::~_BDropUndoBuffer_() void -_BDropUndoBuffer_::UndoSelf(BClipboard *) +BTextView::DropUndoBuffer::UndoSelf(BClipboard* ) { fTextView->Select(fDropLocation, fDropLocation); fTextView->Delete(fDropLocation, fDropLocation + fDropTextLength); @@ -233,7 +234,7 @@ _BDropUndoBuffer_::UndoSelf(BClipboard *) void -_BDropUndoBuffer_::RedoSelf(BClipboard *) +BTextView::DropUndoBuffer::RedoSelf(BClipboard* ) { if (fInternalDrop) { fTextView->Select(fStart, fStart); @@ -245,10 +246,10 @@ _BDropUndoBuffer_::RedoSelf(BClipboard *) } -// #pragma mark - _BTypingUndoBuffer_ +// #pragma mark - TypingUndoBuffer -_BTypingUndoBuffer_::_BTypingUndoBuffer_(BTextView *textView) +BTextView::TypingUndoBuffer::TypingUndoBuffer(BTextView* textView) : BTextView::UndoBuffer(textView, B_UNDO_TYPING), fTypedText(NULL), fTypedStart(fStart), @@ -258,20 +259,20 @@ _BTypingUndoBuffer_::_BTypingUndoBuffer_(BTextView *textView) } -_BTypingUndoBuffer_::~_BTypingUndoBuffer_() +BTextView::TypingUndoBuffer::~TypingUndoBuffer() { free(fTypedText); } void -_BTypingUndoBuffer_::UndoSelf(BClipboard *clipboard) +BTextView::TypingUndoBuffer::UndoSelf(BClipboard* clipboard) { int32 len = fTypedEnd - fTypedStart; free(fTypedText); fTypedText = NULL; - fTypedText = (char *)malloc(len); + fTypedText = (char*)malloc(len); memcpy(fTypedText, fTextView->Text() + fTypedStart, len); fTextView->Select(fTypedStart, fTypedStart); @@ -283,7 +284,7 @@ _BTypingUndoBuffer_::UndoSelf(BClipboard *clipboard) void -_BTypingUndoBuffer_::RedoSelf(BClipboard *clipboard) +BTextView::TypingUndoBuffer::RedoSelf(BClipboard* clipboard) { fTextView->Select(fTypedStart, fTypedStart); fTextView->Delete(fTypedStart, fTypedStart + fTextLength); @@ -293,20 +294,20 @@ _BTypingUndoBuffer_::RedoSelf(BClipboard *clipboard) void -_BTypingUndoBuffer_::InputCharacter(int32 len) +BTextView::TypingUndoBuffer::InputCharacter(int32 len) { int32 start, end; fTextView->GetSelection(&start, &end); if (start != fTypedEnd || end != fTypedEnd) - Reset(); + _Reset(); fTypedEnd += len; } void -_BTypingUndoBuffer_::Reset() +BTextView::TypingUndoBuffer::_Reset() { free(fTextData); fTextView->GetSelection(&fStart, &fEnd); @@ -314,7 +315,7 @@ _BTypingUndoBuffer_::Reset() fTypedStart = fStart; fTypedEnd = fStart; - fTextData = (char *)malloc(fTextLength); + fTextData = (char*)malloc(fTextLength); memcpy(fTextData, fTextView->Text() + fStart, fTextLength); free(fTypedText); @@ -325,22 +326,22 @@ _BTypingUndoBuffer_::Reset() void -_BTypingUndoBuffer_::BackwardErase() +BTextView::TypingUndoBuffer::BackwardErase() { int32 start, end; fTextView->GetSelection(&start, &end); - const char *text = fTextView->Text(); + const char* text = fTextView->Text(); int32 charLen = UTF8PreviousCharLen(text + start, text); if (start != fTypedEnd || end != fTypedEnd) { - Reset(); + _Reset(); // if we've got a selection, we're already done if (start != end) return; } - char *buffer = (char *)malloc(fTextLength + charLen); + char* buffer = (char*)malloc(fTextLength + charLen); memcpy(buffer + charLen, fTextData, fTextLength); fTypedStart = start - charLen; @@ -356,7 +357,7 @@ _BTypingUndoBuffer_::BackwardErase() void -_BTypingUndoBuffer_::ForwardErase() +BTextView::TypingUndoBuffer::ForwardErase() { // TODO: Cleanup int32 start, end; @@ -366,12 +367,12 @@ _BTypingUndoBuffer_::ForwardErase() int32 charLen = UTF8NextCharLen(fTextView->Text() + start); if (start != fTypedEnd || end != fTypedEnd || fUndone > 0) { - Reset(); + _Reset(); // if we've got a selection, we're already done if (fStart == fEnd) { free(fTextData); fTextLength = charLen; - fTextData = (char *)malloc(fTextLength); + fTextData = (char*)malloc(fTextLength); // store the erased character for (int32 x = 0; x < charLen; x++) @@ -384,7 +385,7 @@ _BTypingUndoBuffer_::ForwardErase() // copy (malloc + memcpy vs realloc + memmove). int32 newLength = fTextLength + charLen; - char *buffer = (char *)malloc(newLength); + char* buffer = (char*)malloc(newLength); // copy the already stored data memcpy(buffer, fTextData, fTextLength); diff --git a/src/kits/interface/textview_support/UndoBuffer.h b/src/kits/interface/textview_support/UndoBuffer.h index 56d53299bd..0313e86263 100644 --- a/src/kits/interface/textview_support/UndoBuffer.h +++ b/src/kits/interface/textview_support/UndoBuffer.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007, Haiku, Inc. All Rights Reserved. + * Copyright 2003-2008, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -14,114 +14,123 @@ class BClipboard; + +// UndoBuffer class BTextView::UndoBuffer { public: - UndoBuffer(BTextView *, undo_state); - virtual ~UndoBuffer(); + UndoBuffer(BTextView* view, undo_state state); + virtual ~UndoBuffer(); - void Undo(BClipboard *); - undo_state State(bool *); + void Undo(BClipboard* clipboard); + undo_state State(bool* _isRedo) const; protected: - virtual void UndoSelf(BClipboard *); - virtual void RedoSelf(BClipboard *); + virtual void UndoSelf(BClipboard* clipboard); + virtual void RedoSelf(BClipboard* clipboard); - BTextView *fTextView; - int32 fStart; - int32 fEnd; + BTextView* fTextView; + int32 fStart; + int32 fEnd; - char *fTextData; - int32 fTextLength; - text_run_array *fRunArray; - int32 fRunArrayLength; - - bool fRedo; + char* fTextData; + int32 fTextLength; + text_run_array* fRunArray; + int32 fRunArrayLength; + + bool fRedo; private: - undo_state fState; + undo_state fState; }; -// ******** _BCutUndoBuffer_ ******* -class _BCutUndoBuffer_ : public BTextView::UndoBuffer { +// CutUndoBuffer +class BTextView::CutUndoBuffer : public BTextView::UndoBuffer { public: - _BCutUndoBuffer_(BTextView *textView); - ~_BCutUndoBuffer_(); + CutUndoBuffer(BTextView* textView); + virtual ~CutUndoBuffer(); protected: - virtual void RedoSelf(BClipboard *); + virtual void RedoSelf(BClipboard* clipboard); }; -// ******** _BPasteUndoBuffer_ ******* -class _BPasteUndoBuffer_ : public BTextView::UndoBuffer { +// PasteUndoBuffer +class BTextView::PasteUndoBuffer : public BTextView::UndoBuffer { public: - _BPasteUndoBuffer_(BTextView *, const char *, int32, text_run_array *, int32); - ~_BPasteUndoBuffer_(); + PasteUndoBuffer(BTextView* textView, + const char* text, int32 textLength, + text_run_array* runArray, + int32 runArrayLen); + virtual ~PasteUndoBuffer(); protected: - virtual void UndoSelf(BClipboard *); - virtual void RedoSelf(BClipboard *); + virtual void UndoSelf(BClipboard* clipboard); + virtual void RedoSelf(BClipboard* clipboard); private: - char *fPasteText; - int32 fPasteTextLength; - text_run_array *fPasteRunArray; + char* fPasteText; + int32 fPasteTextLength; + text_run_array* fPasteRunArray; }; -// ******** _BClearUndoBuffer_ ******* -class _BClearUndoBuffer_ : public BTextView::UndoBuffer { +// ClearUndoBuffer +class BTextView::ClearUndoBuffer : public BTextView::UndoBuffer { public: - _BClearUndoBuffer_(BTextView *textView); - ~_BClearUndoBuffer_(); + ClearUndoBuffer(BTextView* textView); + virtual ~ClearUndoBuffer(); protected: - virtual void RedoSelf(BClipboard *); + virtual void RedoSelf(BClipboard* clipboard); }; -// ******** _BDropUndoBuffer_ ******** -class _BDropUndoBuffer_ : public BTextView::UndoBuffer { +// DropUndoBuffer +class BTextView::DropUndoBuffer : public BTextView::UndoBuffer { public: - _BDropUndoBuffer_(BTextView *, char const *, int32, text_run_array *, int32, int32, bool); - ~_BDropUndoBuffer_(); + DropUndoBuffer(BTextView* textView, + char const* text, int32 textLength, + text_run_array* runArray, + int32 runArrayLength, int32 location, + bool internalDrop); + virtual ~DropUndoBuffer(); protected: - virtual void UndoSelf(BClipboard *); - virtual void RedoSelf(BClipboard *); + virtual void UndoSelf(BClipboard* clipboard); + virtual void RedoSelf(BClipboard* clipboard); private: - char *fDropText; - int32 fDropTextLength; - text_run_array *fDropRunArray; + char* fDropText; + int32 fDropTextLength; + text_run_array* fDropRunArray; - int32 fDropLocation; - bool fInternalDrop; + int32 fDropLocation; + bool fInternalDrop; }; -// ******** _BTypingUndoBuffer_ ******** -class _BTypingUndoBuffer_ : public BTextView::UndoBuffer { +// TypingUndoBuffer +class BTextView::TypingUndoBuffer : public BTextView::UndoBuffer { public: - _BTypingUndoBuffer_(BTextView *); - ~_BTypingUndoBuffer_(); + TypingUndoBuffer(BTextView* textView); + virtual ~TypingUndoBuffer(); - void InputCharacter(int32); - void BackwardErase(); - void ForwardErase(); + void InputCharacter(int32 length); + void BackwardErase(); + void ForwardErase(); protected: - virtual void RedoSelf(BClipboard *); - virtual void UndoSelf(BClipboard *); + virtual void RedoSelf(BClipboard* clipboard); + virtual void UndoSelf(BClipboard* clipboard); private: - void Reset(); + void _Reset(); - char *fTypedText; - int32 fTypedStart; - int32 fTypedEnd; - int32 fUndone; + char* fTypedText; + int32 fTypedStart; + int32 fTypedEnd; + int32 fUndone; }; #endif //__UNDOBUFFER_H