X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxfr1.C;h=c85a579eda9b472d8a8cfb1a8712e62c0905d691;hb=e8022b10a11e41d56897e3b066aa5180025165cc;hp=b455e36fd12e5a187d5da810232274955adbfed7;hpb=0eccdd1c3613e5170deb77b22174dd0afde833e9;p=lyx.git diff --git a/src/lyxfr1.C b/src/lyxfr1.C index b455e36fd1..c85a579eda 100644 --- a/src/lyxfr1.C +++ b/src/lyxfr1.C @@ -1,18 +1,18 @@ /* This file is part of -* ====================================================== -* -* LyX, The Document Processor -* -* Copyright (C) 1995 Matthias Ettrich, -* Copyright (C) 1995-1998 The LyX Team. -* -*======================================================*/ + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995 Matthias Ettrich, + * Copyright 1995-1999 The LyX Team. + * + * ====================================================== */ #include -#include -#include -#include +#include +#include +#include #ifdef __GNUG__ #pragma implementation @@ -26,12 +26,14 @@ #include "lyxfr1.h" #include "lyxfunc.h" #include "lyxscreen.h" -#include "error.h" +#include "debug.h" #include "lyxtext.h" #include "gettext.h" #include "LyXView.h" #include "lyx_gui_misc.h" #include "minibuffer.h" +#include "support/lstrings.h" +#include "support/textutils.h" extern BufferView *current_view; // called too many times in this file... extern MiniBuffer *minibuffer; @@ -41,8 +43,6 @@ const int LYXSEARCH_MAXLEN = 128; // function prototypes -bool IsLetterCharOrDigit(char ch); - // If nothing selected, select the word at the cursor. // Returns the current selection // Note: this function should be in LyXText! @@ -58,38 +58,31 @@ void SetSelectionOverLenChars(LyXText *lt, int len); //------------------------------------------------------------- -bool IsLetterCharOrDigit(char ch) -{ - return IsLetterChar(ch) || isdigit(ch); -} // Returns the current selection. If nothing is selected or if the selection // spans 2 paragraphs, an empty string is returned. -string const GetCurrentSelectionAsString(LyXText *lt) +string const GetCurrentSelectionAsString(LyXText * lt) { - LyXParagraph *par; - int pos; - int endpos; - int i; char sz[LYXSEARCH_MAXLEN]; - char ch; - bool fPrevIsSpace; sz[0] = 0; - par = lt->cursor.par; + LyXParagraph * par = lt->cursor.par; if (lt->selection && (lt->sel_cursor.par == par)) { // (selected) and (begin/end in same paragraph) - pos = lt->sel_start_cursor.pos; - endpos = lt->sel_end_cursor.pos; - i = 0; - fPrevIsSpace = false; + LyXParagraph::size_type pos = + lt->sel_start_cursor.pos; + LyXParagraph::size_type endpos = + lt->sel_end_cursor.pos; + int i = 0; + bool fPrevIsSpace = false; + char ch; while ((i < LYXSEARCH_MAXLEN-2) && (pos < par->Last()) && (pos < endpos)) { ch = par->GetChar(pos); //HB??: Maybe (ch <= ' ') - if ((ch == ' ') || ((unsigned char)ch <= LYX_META_INSET)) { + if ((ch == ' ') || (ch <= LyXParagraph::META_INSET)) { // consecutive spaces --> 1 space char if (fPrevIsSpace) { pos++; // Next text pos @@ -125,7 +118,7 @@ void SetSelectionOverLenChars(LyXText *lt, int len) { lt->sel_cursor = lt->cursor; int i; - for (i=0; i < len; i++) + for (i= 0; i < len; i++) lt->CursorRight(); lt->SetSelection(); } @@ -136,10 +129,10 @@ void SetSelectionOverLenChars(LyXText *lt, int len) void LyXFindReplace1::StartSearch() { LyXFindReplace0::StartSearch(); - SetReplaceEnabled(!current_view->currentBuffer()->isReadonly()); + SetReplaceEnabled(!current_view->buffer()->isReadonly()); searchForward = true; if (lsSearch.empty()) - SetSearchString(GetSelectionOrWordAtCursor(current_view->currentBuffer()->text)); + SetSearchString(GetSelectionOrWordAtCursor(current_view->buffer()->text)); } @@ -150,7 +143,7 @@ void LyXFindReplace1::SearchReplaceCB() if (!current_view->getScreen()) return; - if (current_view->currentBuffer()->isReadonly()) + if (current_view->buffer()->isReadonly()) return; // CutSelection cannot cut a single space, so we have to stop @@ -166,17 +159,17 @@ void LyXFindReplace1::SearchReplaceCB() string const replacestring = ReplaceString(); current_view->getScreen()->HideCursor(); - current_view->currentBuffer()->update(-2); + current_view->buffer()->update(-2); - ltCur = current_view->currentBuffer()->text; + ltCur = current_view->buffer()->text; if (ltCur->selection) { // clear the selection (if there is any) current_view->getScreen()->ToggleSelection(false); - current_view->currentBuffer()->text-> + current_view->buffer()->text-> ReplaceSelectionWithString(replacestring.c_str()); - current_view->currentBuffer()->text-> + current_view->buffer()->text-> SetSelectionOverString(replacestring.c_str()); - current_view->currentBuffer()->update(1); + current_view->buffer()->update(1); } // jump to next match: @@ -191,7 +184,7 @@ void LyXFindReplace1::SearchReplaceAllCB() if (!current_view->getScreen()) return; - if (current_view->currentBuffer()->isReadonly()) + if (current_view->buffer()->isReadonly()) return; // CutSelection cannot cut a single space, so we have to stop @@ -209,20 +202,20 @@ void LyXFindReplace1::SearchReplaceAllCB() current_view->getScreen()->HideCursor(); // start at top - current_view->currentBuffer()->text->ClearSelection(); - current_view->currentBuffer()->text->CursorTop(); + current_view->buffer()->text->ClearSelection(); + current_view->buffer()->text->CursorTop(); int replace_count = 0; do { - ltCur = current_view->currentBuffer()->text; + ltCur = current_view->buffer()->text; if (ltCur->selection) { - current_view->currentBuffer()->update(-2); + current_view->buffer()->update(-2); current_view->getScreen()->ToggleSelection(false); - current_view->currentBuffer()->text-> + current_view->buffer()->text-> ReplaceSelectionWithString(replacestring.c_str()); - current_view->currentBuffer()->text-> + current_view->buffer()->text-> SetSelectionOverString(replacestring.c_str()); - current_view->currentBuffer()->update(1); + current_view->buffer()->update(1); replace_count++; } } while( SearchCB(true) ); @@ -234,8 +227,7 @@ void LyXFindReplace1::SearchReplaceAllCB() if( replace_count == 1 ) { minibuffer->Set(_("1 string has been replaced.")); } else { - string str; - str += replace_count; + string str = tostr(replace_count); str += _(" strings have been replaced."); minibuffer->Set(str); } @@ -255,8 +247,8 @@ bool LyXFindReplace1::SearchCB(bool fForward) return(false); current_view->getScreen()->HideCursor(); - current_view->currentBuffer()->update(-2); - ltCur = current_view->currentBuffer()->text; + current_view->buffer()->update(-2); + ltCur = current_view->buffer()->text; if (ltCur->selection) ltCur->cursor = fForward ? ltCur->sel_end_cursor : ltCur->sel_start_cursor; @@ -266,14 +258,14 @@ bool LyXFindReplace1::SearchCB(bool fForward) if (!ValidSearchData() || (fForward ? SearchForward(ltCur) : SearchBackward(ltCur))) { - current_view->currentBuffer()->update(-2); + current_view->buffer()->update(-2); // clear the selection (if there is any) current_view->getScreen()->ToggleSelection(); - current_view->currentBuffer()->text->ClearSelection(); + current_view->buffer()->text->ClearSelection(); // set the new selection - SetSelectionOverLenChars(current_view->currentBuffer()->text, iLenSelected); + SetSelectionOverLenChars(current_view->buffer()->text, iLenSelected); current_view->getScreen()->ToggleSelection(false); minibuffer->Set(_("Found.")); result = true; @@ -293,15 +285,12 @@ bool LyXFindReplace1::SearchCB(bool fForward) // if the string can be found: return true and set the cursor to // the new position // (was: LyXText::SearchForward(char const* string) in text2.C ) -bool LyXFindReplace1::SearchForward(LyXText *lt) +bool LyXFindReplace1::SearchForward(LyXText * lt) { - LyXParagraph *par; - int pos; - - par = lt->cursor.par; - pos = lt->cursor.pos; + LyXParagraph * par = lt->cursor.par; + LyXParagraph::size_type pos = lt->cursor.pos; - while (par && !IsSearchStringInText(par,pos)) { + while (par && !IsSearchStringInText(par, pos)) { if (posLast()-1) pos++; else { @@ -310,7 +299,7 @@ bool LyXFindReplace1::SearchForward(LyXText *lt) } } if (par) { - lt->SetCursor(par,pos); + lt->SetCursor(par, pos); return true; } else return false; @@ -336,10 +325,10 @@ bool LyXFindReplace1::SearchBackward(LyXText *lt) pos = par->Last()-1; } while (par && pos<0); } - } while (par && !IsSearchStringInText(par,pos)); + } while (par && !IsSearchStringInText(par, pos)); if (par) { - lt->SetCursor(par,pos); + lt->SetCursor(par, pos); return true; } else return false; @@ -356,48 +345,41 @@ int LyXFindReplace1::CompareChars(char chSearch, char chText) { if (CaseSensitive()) return (chSearch - chText); - return (toupper((unsigned char) chSearch) - toupper((unsigned char) chText)); + return (toupper(chSearch) - toupper(chText)); } // returns true if the search string is at the specified position // (Copied from the original "LyXText::IsStringInText" in text2.C ) -bool LyXFindReplace1::IsSearchStringInText(LyXParagraph *par, int pos) +bool LyXFindReplace1::IsSearchStringInText(LyXParagraph * par, + LyXParagraph::size_type pos) { char chSrch = 0; char chText; - bool fPrevIsSpace; - int iText; - string::size_type iSrch; if (!par) return false; - fPrevIsSpace = false; - iText = 0; iSrch = 0; - while (pos+iText < par->Last() && + bool fPrevIsSpace = false; + int iText = 0; + string::size_type iSrch = 0; + while (pos + iText < par->Last() && iSrch < SearchString().length()) { chSrch = SearchString()[iSrch]; chText = par->GetChar(pos+iText); -// Why was this code there ??? Insets are *not* spaces! -// It seems that there is some code here to handle multiple spaces. I -// wonder why this is useful... (JMarc) -// if ((chText == ' ') || -// ((unsigned char)chText <= LYX_META_INSET)) if (chText == ' ') { if (fPrevIsSpace) { iText++; // next Text pos continue; // same search pos } -// chText = ' '; fPrevIsSpace = true; } else fPrevIsSpace = false; if (CompareChars(chSrch, chText) != 0) break; - iSrch++; - iText++; + ++iSrch; + ++iText; } if (iSrch < SearchString().length()) @@ -405,7 +387,7 @@ bool LyXFindReplace1::IsSearchStringInText(LyXParagraph *par, int pos) if (!MatchWord() || ((pos <= 0 || !IsLetterCharOrDigit(par->GetChar(pos-1))) - && (pos+iText >= par->Last() + && (pos + iText >= par->Last() || !IsLetterCharOrDigit(par->GetChar(pos + iText))))) { iLenSelected = iText; return true;