From: Lars Gullik Bjønnes Date: Wed, 25 Apr 2001 19:33:52 +0000 (+0000) Subject: small fix for gcc 3.0, use std::transform in lstrings, implement chars-transpose X-Git-Tag: 1.6.10~21282 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=2b63437db26d42fd5e1fe4e65aef14c0c10074b1;p=features.git small fix for gcc 3.0, use std::transform in lstrings, implement chars-transpose git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1955 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 37c1640ee3..a6f510b7e2 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -1769,7 +1769,16 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) bv_->updateInset(TEXT(bv_)->inset_owner, true); update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); break; + + case LFUN_TRANSPOSE_CHARS: + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR); + TEXT(bv_)->TransposeChars(*bv_); + if (TEXT(bv_)->inset_owner) + bv_->updateInset(TEXT(bv_)->inset_owner, true); + update(TEXT(bv_), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + break; + case LFUN_INSERT_LABEL: MenuInsertLabel(bv_, argument); break; diff --git a/src/ChangeLog b/src/ChangeLog index 206c8b995e..6ef14d75e7 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2001-04-25 Lars Gullik Bjønnes + + * minibuffer.C: include + + * BufferView_pimpl.C: implement LFUN_TRANSPOSE_CHARS + + * LyXAction.C (init): add LFUN_TRANSPOSE_CHARS + + * commandtags.h: add LFUN_TRANSPOSE_CHARS + + * text.[Ch] (TransposeChars): new method + 2001-04-24 Lars Gullik Bjønnes * call message directly through LyXView instead of through LyXFunc diff --git a/src/LyXAction.C b/src/LyXAction.C index 4a4c09a3be..d9f6b8c3c7 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -439,6 +439,7 @@ void LyXAction::init() { LFUN_MESSAGE_POP, "message-pop", N_("Pop old message and show it in the minibuffer"), NoBuffer }, + { LFUN_TRANSPOSE_CHARS, "chars-transpose", "", Noop }, { LFUN_NOACTION, "", "", Noop } }; diff --git a/src/commandtags.h b/src/commandtags.h index 3d687b18e4..b40b042f55 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -283,6 +283,7 @@ enum kb_action { LFUN_MESSAGE, // Lgb 20010408 LFUN_MESSAGE_PUSH, // Lgb 20010410 LFUN_MESSAGE_POP, // Lgb 20010410 + LFUN_TRANSPOSE_CHARS, // Lgb 20010425 LFUN_LASTACTION /* this marks the end of the table */ }; diff --git a/src/lyxtext.h b/src/lyxtext.h index 8b2443e682..1c3ec4d6fc 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -329,7 +329,8 @@ public: }; /// Change the case of the word at cursor position. void ChangeWordCase(BufferView *, TextCase action); - + void TransposeChars(BufferView const &); + /** returns a printed row in a pixmap. The y value is needed to decide, wether it is selected text or not. This is a strange solution but faster. diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index bcfc2a10a2..74906a1cd4 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,7 @@ +2001-04-25 Lars Gullik Bjønnes + + * math_macrotable.C: include + 2001-04-25 Angus Leeming * array.h (operator<<): diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index 7173b236f4..8eeb66fe0e 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -1,5 +1,7 @@ #include +#include + #ifdef __GNUG__ #pragma implementation #endif diff --git a/src/minibuffer.C b/src/minibuffer.C index 5e1f324423..659b12a5d0 100644 --- a/src/minibuffer.C +++ b/src/minibuffer.C @@ -12,6 +12,8 @@ #include +#include + #ifdef __GNUG__ #pragma implementation #endif diff --git a/src/support/ChangeLog b/src/support/ChangeLog index a211a329f0..e84f04f151 100644 --- a/src/support/ChangeLog +++ b/src/support/ChangeLog @@ -1,3 +1,10 @@ +2001-04-25 Lars Gullik Bjønnes + + * lstrings.C : add two helper structs, local_lowercase and + local_uppercase. + (lowercase): change to use std::transform + (uppercase): change to use std::transform + 2001-04-25 Allan Rae * lyxstring.C : Assert got moved and Lars missed a few. diff --git a/src/support/lstrings.C b/src/support/lstrings.C index 20c92ff16e..03296f824e 100644 --- a/src/support/lstrings.C +++ b/src/support/lstrings.C @@ -26,6 +26,7 @@ using std::count; using std::transform; + #ifndef CXX_GLOBAL_CSTD using std::tolower; using std::toupper; @@ -193,38 +194,36 @@ char uppercase(char c) } +namespace { + +// since we cannot use std::tolower and std::toupper directly in the +// calls to std::transform yet, we use these helper clases. (Lgb) + +struct local_lowercase { + char operator()(char c) const { + return tolower(c); + } +}; + +struct local_uppercase { + char operator()(char c) const { + return toupper(c); + } +}; + +} // end of anon namespace + string const lowercase(string const & a) { string tmp(a); -#if 1 - string::iterator result = tmp.begin(); - string::iterator end = tmp.end(); - for (string::iterator first = tmp.begin(); - first != end; ++first, ++result) { - *result = lowercase(*first); - } -#else - // We want to use this one. (Lgb) - transform(tmp.begin(), tmp.end(), tmp.begin(), lowercase); -#endif + transform(tmp.begin(), tmp.end(), tmp.begin(), local_lowercase()); return tmp; } - string const uppercase(string const & a) { string tmp(a); -#if 1 - string::iterator result = tmp.begin(); - string::iterator end = tmp.end(); - for (string::iterator first = tmp.begin(); - first != end; ++first, ++result) { - *result = uppercase(*first); - } -#else - // We want to use this one. (Lgb) - transform(tmp.begin(), tmp.end(), tmp.begin(), uppercase); -#endif + transform(tmp.begin(), tmp.end(), tmp.begin(), local_uppercase()); return tmp; } @@ -473,7 +472,7 @@ string const subst(string const & a, char oldchar, char newchar) string const subst(string const & a, - char const * oldstr, string const & newstr) + char const * oldstr, string const & newstr) { lyx::Assert(oldstr); diff --git a/src/text.C b/src/text.C index 1dca2666d9..9dea165c55 100644 --- a/src/text.C +++ b/src/text.C @@ -2842,6 +2842,37 @@ void LyXText::ChangeWordCase(BufferView * bview, LyXText::TextCase action) } +void LyXText::TransposeChars(BufferView const & bview) +{ + LyXParagraph * tmppar = cursor.par(); + + SetUndo(bview.buffer(), Undo::FINISH, + tmppar->previous(), tmppar->next()); + + LyXParagraph::size_type tmppos = cursor.pos(); + + // First decide if it is possible to transpose at all + + // We are at the beginning of a paragraph. + if (tmppos == 0) return; + + // We are at the end of a paragraph. + if (tmppos == tmppar->size() - 1) return; + + unsigned char c1 = tmppar->GetChar(tmppos); + unsigned char c2 = tmppar->GetChar(tmppos - 1); + + if (c1 != LyXParagraph::META_INSET + && c2 != LyXParagraph::META_INSET) { + tmppar->SetChar(tmppos, c2); + tmppar->SetChar(tmppos - 1, c1); + } + // We should have an implementation that handles insets + // as well, but that will have to come later. (Lgb) + CheckParagraph(const_cast(&bview), tmppar, tmppos); +} + + void LyXText::Delete(BufferView * bview) { // this is a very easy implementation