Index: abi/src/text/fmt/xp/fv_View.cpp =================================================================== RCS file: /cvsroot/abi/src/text/fmt/xp/fv_View.cpp,v retrieving revision 1.796 diff -u -r1.796 fv_View.cpp --- abi/src/text/fmt/xp/fv_View.cpp 17 May 2003 20:15:15 -0000 1.796 +++ abi/src/text/fmt/xp/fv_View.cpp 22 May 2003 09:46:08 -0000 @@ -159,8 +159,11 @@ m_pEditShadow(NULL), m_iSavedPosition(0), m_bNeedSavedPosition(false), - _m_matchCase(false), - _m_findNextString(0), + _m_bMatchCase(false), + _m_bReverseFind(false), + _m_bWholeWord(false), + _m_sFind(0), + _m_sReplace(0), m_bShowPara(false), m_viewMode(VIEW_PRINT), m_previewMode(PREVIEW_NONE), @@ -421,8 +424,8 @@ { DELETEP(m_caretListener); } - - FREEP(_m_findNextString); + FREEP(_m_sFind); + FREEP(_m_sReplace); FREEP(m_chg.propsChar); FREEP(m_chg.propsBlock); @@ -927,26 +930,26 @@ switch(focus) { case AV_FOCUS_HERE: - if (isSelectionEmpty() && (getPoint() > 0)) + if (isSelectionEmpty() && (getPoint() > 0) && m_pG->getCaret()) { m_pG->getCaret()->setBlink(m_bCursorBlink); } m_pApp->rememberFocussedFrame(m_pParentData); break; case AV_FOCUS_NEARBY: - if (isSelectionEmpty() && (getPoint() > 0)) + if (isSelectionEmpty() && (getPoint() > 0) && m_pG->getCaret()) { m_pG->getCaret()->setBlink(false); } break; case AV_FOCUS_MODELESS: - if (isSelectionEmpty() && (getPoint() > 0)) + if (isSelectionEmpty() && (getPoint() > 0) && m_pG->getCaret()) { m_pG->getCaret()->setBlink(false); } break; case AV_FOCUS_NONE: - if (isSelectionEmpty() && (getPoint() > 0)) + if (isSelectionEmpty() && (getPoint() > 0) && m_pG->getCaret()) { m_pG->getCaret()->setBlink(false); } @@ -1280,6 +1283,10 @@ return dPos ; } +PT_DocPosition FV_View::GetDocPosition( FV_DocPos dp ) { + return ( _getDocPos( dp )); + } + PT_DocPosition FV_View::saveSelectedImage (const UT_ByteBuf ** pBytes) { const char * dataId = NULL; @@ -4710,16 +4717,28 @@ \return True if string was found, false otherwise */ bool -FV_View::findNext(const UT_UCSChar* pFind, bool bMatchCase, - bool& bDoneEntireDocument) +FV_View::findNext(const UT_UCSChar* pFind, bool& bDoneEntireDocument) + +{ + findSetFindString(pFind); + return findNext(bDoneEntireDocument); +} + +bool +FV_View::findNext(bool& bDoneEntireDocument) { + if ((m_startPosition >=0) && (m_startPosition <2)) { + m_startPosition = 2; + setPoint(m_startPosition); + } + if (!isSelectionEmpty()) { _clearSelection(); } - UT_uint32* pPrefix = _computeFindPrefix(pFind, bMatchCase); - bool bRes = _findNext(pFind, pPrefix, bMatchCase, bDoneEntireDocument); + UT_uint32* pPrefix = _computeFindPrefix(_m_sFind); + bool bRes = _findNext(pPrefix, bDoneEntireDocument); FREEP(pPrefix); if (isSelectionEmpty()) @@ -4737,6 +4756,38 @@ return bRes; } +bool +FV_View::findPrev(const UT_UCSChar* pFind, bool& bDoneEntireDocument) +{ + findSetFindString(pFind); + return findPrev(bDoneEntireDocument); +} + +bool +FV_View::findPrev(bool& bDoneEntireDocument) +{ + if (!isSelectionEmpty()) + { + _clearSelection(); + } + + UT_uint32* pPrefix = _computeFindPrefix(_m_sFind); + bool bRes = _findPrev(pPrefix, bDoneEntireDocument); + FREEP(pPrefix); + + if (isSelectionEmpty()) + { + _updateInsertionPoint(); + } + else + { + _ensureInsertionPointOnScreen(); + _drawSelection(); + } + + notifyListeners(AV_CHG_MOTION); + return bRes; +} /*! Find operation reset @@ -4752,25 +4803,96 @@ m_doneFind = false; } +bool +FV_View::findSetFindString(const UT_UCSChar* pFind) +{ + FREEP(_m_sFind); + return UT_UCS4_cloneString(&_m_sFind, pFind); +} + +UT_UCSChar * +FV_View::findGetFindString(void) +{ + UT_UCSChar * string = NULL; + if (_m_sFind) + { + if (UT_UCS4_cloneString(&string, _m_sFind)) + return string; + } + else + { + if (UT_UCS4_cloneString_char(&string, "")) + return string; + } + + return NULL; +} + +bool +FV_View::findSetReplaceString(const UT_UCSChar* pReplace) +{ + FREEP(_m_sReplace); + return UT_UCS4_cloneString(&_m_sReplace, pReplace); +} + +UT_UCSChar * +FV_View::findGetReplaceString(void) +{ + UT_UCSChar * string = NULL; + if (_m_sReplace) + { + if (UT_UCS4_cloneString(&string, _m_sReplace)) + return string; + } + else + { + if (UT_UCS4_cloneString_char(&string, "")) + return string; + } + + return NULL; +} + +bool +FV_View::findSetReverseFind (bool newValue) +{ + bool oldValue = _m_bReverseFind; + _m_bReverseFind = newValue; + return oldValue; +} + +bool +FV_View::findGetReverseFind () +{ + return _m_bReverseFind; +} + +bool +FV_View::findSetMatchCase(bool newValue) +{ + bool oldValue = _m_bMatchCase; + _m_bMatchCase = newValue; + return oldValue; +} -/*! - Set find-next string - \param pFind String to find - \param bMatchCase True to match case, false to ignore case - \return True if there was enough memory to clone the string - This function is used for non-dialog search operations. -*/ bool -FV_View::findSetNextString(UT_UCSChar* pFind, bool bMatchCase) +FV_View::findGetMatchCase() { - UT_ASSERT(pFind); + return _m_bMatchCase; +} - // update case matching - _m_matchCase = bMatchCase; +bool +FV_View::findSetWholeWord(bool newValue) +{ + bool oldValue = _m_bWholeWord; + _m_bWholeWord = newValue; + return oldValue; +} - // update string - FREEP(_m_findNextString); - return UT_UCS4_cloneString(&_m_findNextString, pFind); +bool +FV_View::findGetWholeWord() +{ + return _m_bWholeWord; } /*! @@ -4783,10 +4905,18 @@ { bool bRes = false; - if (_m_findNextString && *_m_findNextString) + if (_m_sFind && *_m_sFind) { bool bTmp; - bRes = findNext(_m_findNextString, _m_matchCase, bTmp); + if (_m_bReverseFind) + { + bRes = findPrev(bTmp); + } + else + { + bRes = findNext(bTmp); + } + if (bRes) { _drawSelection(); @@ -4796,25 +4926,49 @@ return bRes; } +/*! + Find and replace string + \result bDoneEntireDocument True if entire document searched, + false otherwise + \return True if string was replaced, false otherwise +*/ +bool +FV_View::findReplaceReverse(bool& bDoneEntireDocument) +{ + UT_ASSERT(_m_sFind && _m_sReplace); + + UT_uint32* pPrefix = _computeFindPrefix(_m_sFind); + bool bRes = _findReplaceReverse(pPrefix, bDoneEntireDocument); + FREEP(pPrefix); + + updateScreen(); + + if (isSelectionEmpty()) + { + _updateInsertionPoint(); + } + else + { + _ensureInsertionPointOnScreen(); + _drawSelection(); + } + + return bRes; +} /*! Find and replace string - \param pFind String to find - \param pReplace String to replace it with - \param bMatchCase True to match case, false to ignore case \result bDoneEntireDocument True if entire document searched, false otherwise \return True if string was replaced, false otherwise */ bool -FV_View::findReplace(const UT_UCSChar* pFind, const UT_UCSChar* pReplace, - bool bMatchCase, bool& bDoneEntireDocument) +FV_View::findReplace(bool& bDoneEntireDocument) { - UT_ASSERT(pFind && pReplace); + UT_ASSERT(_m_sFind && _m_sReplace); - UT_uint32* pPrefix = _computeFindPrefix(pFind, bMatchCase); - bool bRes = _findReplace(pFind, pReplace, pPrefix, - bMatchCase, bDoneEntireDocument); + UT_uint32* pPrefix = _computeFindPrefix(_m_sFind); + bool bRes = _findReplace(pPrefix, bDoneEntireDocument); FREEP(pPrefix); updateScreen(); @@ -4832,33 +4986,35 @@ return bRes; } + /*! Find and replace all occurrences of string - \param pFind String to find - \param pReplace String to replace it with - \param bMatchCase True to match case, false to ignore case \return Number of replacements made */ UT_uint32 -FV_View::findReplaceAll(const UT_UCSChar* pFind, const UT_UCSChar* pReplace, - bool bMatchCase) +FV_View::findReplaceAll() { UT_uint32 iReplaced = 0; m_pDoc->beginUserAtomicGlob(); + if ((m_startPosition >=0) && (m_startPosition <2)) + { + m_startPosition = 2; + } + bool bDoneEntireDocument = false; // Compute search prefix - UT_uint32* pPrefix = _computeFindPrefix(pFind, bMatchCase); + UT_uint32* pPrefix = _computeFindPrefix(_m_sFind); // Prime with the first match - _findReplace is really // replace-then-find. - _findNext(pFind, pPrefix, bMatchCase, bDoneEntireDocument); + _findNext(pPrefix, bDoneEntireDocument); // Keep replacing until the end of the buffer is hit while (!bDoneEntireDocument) { - _findReplace(pFind, pReplace, pPrefix, bMatchCase,bDoneEntireDocument); + _findReplace(pPrefix, bDoneEntireDocument); iReplaced++; } @@ -7968,8 +8124,7 @@ pBL = _findBlockAtPosition(FanchStart); UT_ASSERT(pBL != 0); - - if (pBL->getFirstRun()->getNext()) + if (pBL && pBL->getFirstRun() && pBL->getFirstRun()->getNext()) { bWidthChange = pBL->getFirstRun()->getNext()->recalcWidth(); xxx_UT_DEBUGMSG(("run type %d, width change %d\n", pBL->getFirstRun()->getNext()->getType(),bWidthChange));