editeng/Library_editeng.mk | 3 editeng/qa/lookuptree/lookuptree_test.cxx | 219 +++-------------------- editeng/source/lookuptree/LatinLookupTree.cxx | 242 -------------------------- editeng/source/lookuptree/LatinTreeNode.cxx | 112 ------------ editeng/source/lookuptree/Node.cxx | 216 ----------------------- editeng/source/lookuptree/Trie.cxx | 8 include/editeng/LatinLookupTree.hxx | 74 ------- include/editeng/LatinTreeNode.hxx | 48 ----- include/editeng/LookupTree.hxx | 95 ---------- include/editeng/Node.hxx | 102 ---------- include/editeng/TreeHead.hxx | 49 ----- include/editeng/Trie.hxx | 2 sw/source/core/inc/txtfrm.hxx | 2 sw/source/core/text/frmpaint.cxx | 1 sw/source/core/text/inftxt.cxx | 37 +++ sw/source/core/text/inftxt.hxx | 2 sw/source/core/text/porrst.cxx | 4 sw/source/core/txtnode/fntcache.cxx | 40 +++- 18 files changed, 113 insertions(+), 1143 deletions(-)
New commits: commit fb99a6b9958815eb1ad27179d252a379ce8b79fd Author: Tomaž Vajngerl <[email protected]> Date: Tue Feb 4 11:19:42 2014 +0100 fdo#68071 NPC characters now use a fixed color. The color for non-printing characters (enable with CTRL+F10) has now been changed to a fixed color. Change-Id: I93dfc69fa4be1c1f1373f25434c8f4afa71355d3 diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx index 0000555..8445064 100644 --- a/sw/source/core/inc/txtfrm.hxx +++ b/sw/source/core/inc/txtfrm.hxx @@ -45,6 +45,8 @@ class SwScriptInfo; class SwViewOption; class SwWrongList; +#define NON_PRINTING_CHARACTER_COLOR RGB_COLORDATA( 0x6A, 0xBE, 0xD3 ) + /// Represents the visualization of a paragraph. class SwTxtFrm: public SwCntntFrm { diff --git a/sw/source/core/text/frmpaint.cxx b/sw/source/core/text/frmpaint.cxx index 422a049..358d134 100644 --- a/sw/source/core/text/frmpaint.cxx +++ b/sw/source/core/text/frmpaint.cxx @@ -560,6 +560,7 @@ sal_Bool SwTxtFrm::PaintEmpty( const SwRect &rRect, sal_Bool bCheck ) const aDrawInf.SetFont( pFnt ); aDrawInf.SetSnapToGrid( sal_False ); + pFnt->SetColor(NON_PRINTING_CHARACTER_COLOR); pFnt->_DrawText( aDrawInf ); } delete pClip; diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx index 73bbd5e..a65a1eb 100644 --- a/sw/source/core/text/inftxt.cxx +++ b/sw/source/core/text/inftxt.cxx @@ -934,6 +934,29 @@ void SwTxtPaintInfo::DrawRect( const SwRect &rRect, bool bNoGraphic, } } +void SwTxtPaintInfo::DrawSpecial( const SwLinePortion &rPor, sal_Unicode cChar, Color* pColor ) const +{ + if( OnWin() ) + { + KSHORT nOldWidth = rPor.Width(); + OUString sChar( cChar ); + SwPosSize aSize( GetTxtSize( sChar ) ); + + ((SwLinePortion&)rPor).Width( aSize.Width() ); + + SwRect aRect; + CalcRect( rPor, &aRect ); + + if( aRect.HasArea() ) + { + const sal_uInt8 nOptions = 0; + lcl_DrawSpecial( *this, rPor, aRect, pColor, cChar, nOptions ); + } + + ((SwLinePortion&)rPor).Width( nOldWidth ); + } +} + void SwTxtPaintInfo::DrawTab( const SwLinePortion &rPor ) const { if( OnWin() ) @@ -944,11 +967,10 @@ void SwTxtPaintInfo::DrawTab( const SwLinePortion &rPor ) const if ( ! aRect.HasArea() ) return; - const sal_Unicode cChar = GetTxtFrm()->IsRightToLeft() ? - CHAR_TAB_RTL : CHAR_TAB; - const sal_uInt8 nOptions = DRAW_SPECIAL_OPTIONS_CENTER | - DRAW_SPECIAL_OPTIONS_ROTATE; - lcl_DrawSpecial( *this, rPor, aRect, 0, cChar, nOptions ); + const sal_Unicode cChar = GetTxtFrm()->IsRightToLeft() ? CHAR_TAB_RTL : CHAR_TAB; + const sal_uInt8 nOptions = DRAW_SPECIAL_OPTIONS_CENTER | DRAW_SPECIAL_OPTIONS_ROTATE; + + lcl_DrawSpecial( *this, rPor, aRect, new Color(0x6a, 0xbe, 0xd3), cChar, nOptions ); } } @@ -967,7 +989,8 @@ void SwTxtPaintInfo::DrawLineBreak( const SwLinePortion &rPor ) const const sal_Unicode cChar = GetTxtFrm()->IsRightToLeft() ? CHAR_LINEBREAK_RTL : CHAR_LINEBREAK; const sal_uInt8 nOptions = 0; - lcl_DrawSpecial( *this, rPor, aRect, 0, cChar, nOptions ); + + lcl_DrawSpecial( *this, rPor, aRect, new Color(NON_PRINTING_CHARACTER_COLOR), cChar, nOptions ); } ((SwLinePortion&)rPor).Width( nOldWidth ); @@ -1064,7 +1087,7 @@ void SwTxtPaintInfo::DrawCheckBox( const SwFieldFormPortion &rPor, bool checked) if (OnWin() && SwViewOption::IsFieldShadings() && !GetOpt().IsPagePreview()) { - OutputDevice* pOut = (OutputDevice*)GetOut(); + OutputDevice* pOut = (OutputDevice*)GetOut(); pOut->Push( PUSH_LINECOLOR | PUSH_FILLCOLOR ); pOut->SetFillColor( SwViewOption::GetFieldShadingsColor() ); pOut->SetLineColor(); diff --git a/sw/source/core/text/inftxt.hxx b/sw/source/core/text/inftxt.hxx index 520dddc..dd77975 100644 --- a/sw/source/core/text/inftxt.hxx +++ b/sw/source/core/text/inftxt.hxx @@ -471,6 +471,8 @@ public: void DrawRect( const SwRect &rRect, bool bNoGraphic = false, bool bRetouche = true ) const; + + void DrawSpecial( const SwLinePortion &rPor, sal_Unicode cChar, Color* pColor ) const; void DrawTab( const SwLinePortion &rPor ) const; void DrawLineBreak( const SwLinePortion &rPor ) const; void DrawRedArrow( const SwLinePortion &rPor ) const; diff --git a/sw/source/core/text/porrst.cxx b/sw/source/core/text/porrst.cxx index 51e2bfc..10e9fec 100644 --- a/sw/source/core/text/porrst.cxx +++ b/sw/source/core/text/porrst.cxx @@ -69,9 +69,7 @@ void SwTmpEndPortion::Paint( const SwTxtPaintInfo &rInf ) const { if( rInf.OnWin() && rInf.GetOpt().IsParagraph() ) { - SwDefFontSave aSave( rInf ); - const OUString aTmp( CH_PAR ); - rInf.DrawText( aTmp, *this ); + rInf.DrawSpecial( *this, CH_PAR, new Color(NON_PRINTING_CHARACTER_COLOR) ); } } diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx index 8e2e3d4..7299bcb 100644 --- a/sw/source/core/txtnode/fntcache.cxx +++ b/sw/source/core/txtnode/fntcache.cxx @@ -1443,6 +1443,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) { const OUString* pStr = &rInf.GetText(); OUString aStr; + OUString aBulletOverlay; sal_Bool bBullet = rInf.GetBullet(); if( bSymbol ) bBullet = sal_False; @@ -1569,8 +1570,10 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) aStr = rInf.GetText().copy( nCopyStart, nCopyLen ); pStr = &aStr; - for( sal_Int32 i = 0; i < aStr.getLength(); ++i ) - if( CH_BLANK == aStr[ i ] ) + aBulletOverlay = rInf.GetText().copy( nCopyStart, nCopyLen ); + + for( sal_Int32 i = 0; i < aBulletOverlay.getLength(); ++i ) + if( CH_BLANK == aBulletOverlay[ i ] ) { /* fdo#72488 Hack: try to see if the space is zero width * and don't bother with inserting a bullet in this case. @@ -1578,9 +1581,17 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) if ((i + nCopyStart + 1 >= rInf.GetLen()) || pKernArray[i + nCopyStart] != pKernArray[ i + nCopyStart + 1]) { - aStr = aStr.replaceAt(i, 1, OUString(CH_BULLET)); + aBulletOverlay = aBulletOverlay.replaceAt(i, 1, OUString(CH_BULLET)); + } + else + { + aBulletOverlay = aBulletOverlay.replaceAt(i, 1, OUString(CH_BLANK)); } } + else + { + aBulletOverlay = aBulletOverlay.replaceAt(i, 1, OUString(CH_BLANK)); + } } sal_Int32 nCnt = rInf.GetText().getLength(); @@ -1808,6 +1819,29 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf ) rInf.GetOut().DrawTextArray( aPos, *pStr, pKernArray + nOffs, nTmpIdx + nOffs , nLen - nOffs ); + if (bBullet) + { + rInf.GetOut().Push(); + Color aPreviousColor = pTmpFont->GetColor(); + + FontUnderline aPreviousUnderline = pTmpFont->GetUnderline(); + FontUnderline aPreviousOverline = pTmpFont->GetOverline(); + FontStrikeout aPreviousStrikeout = pTmpFont->GetStrikeout(); + + pTmpFont->SetColor( Color(NON_PRINTING_CHARACTER_COLOR) ); + pTmpFont->SetUnderline(UNDERLINE_NONE); + pTmpFont->SetOverline(UNDERLINE_NONE); + pTmpFont->SetStrikeout(STRIKEOUT_NONE); + rInf.GetOut().SetFont( *pTmpFont ); + rInf.GetOut().DrawTextArray( aPos, aBulletOverlay, pKernArray + nOffs, + nTmpIdx + nOffs , nLen - nOffs ); + pTmpFont->SetColor( aPreviousColor ); + + pTmpFont->SetUnderline(aPreviousUnderline); + pTmpFont->SetOverline(aPreviousOverline); + pTmpFont->SetStrikeout(aPreviousStrikeout); + rInf.GetOut().Pop(); + } } } delete[] pScrArray; commit 0502a09431602baa9a8280b87b77df9ad04e94bc Author: Tomaž Vajngerl <[email protected]> Date: Sun Feb 2 15:16:36 2014 +0100 Remove LookupTree as it is replaced with Trie. Change-Id: I7611c5307e4d4e925dc3e54c6b3f2d1a47bd9080 diff --git a/editeng/Library_editeng.mk b/editeng/Library_editeng.mk index 21e2fd7..644bf98 100644 --- a/editeng/Library_editeng.mk +++ b/editeng/Library_editeng.mk @@ -115,9 +115,6 @@ $(eval $(call gb_Library_add_exception_objects,editeng,\ editeng/source/uno/unoviwou \ editeng/source/xml/xmltxtexp \ editeng/source/xml/xmltxtimp \ - editeng/source/lookuptree/LatinLookupTree \ - editeng/source/lookuptree/LatinTreeNode \ - editeng/source/lookuptree/Node \ editeng/source/lookuptree/Trie \ )) diff --git a/editeng/qa/lookuptree/lookuptree_test.cxx b/editeng/qa/lookuptree/lookuptree_test.cxx index 0bea3a5..e1a35f4 100644 --- a/editeng/qa/lookuptree/lookuptree_test.cxx +++ b/editeng/qa/lookuptree/lookuptree_test.cxx @@ -21,10 +21,6 @@ #include <cppunit/TestFixture.h> #include <cppunit/extensions/HelperMacros.h> #include <cppunit/plugin/TestPlugIn.h> - -#include <editeng/LookupTree.hxx> -#include <editeng/LatinLookupTree.hxx> - #include <editeng/Trie.hxx> namespace { @@ -32,12 +28,10 @@ namespace { class LookupTreeTest : public CppUnit::TestFixture { public: - void testLookupTree(); void testTrie(); void testTrieGetAllEntries(); CPPUNIT_TEST_SUITE(LookupTreeTest); - CPPUNIT_TEST(testLookupTree); CPPUNIT_TEST(testTrie); CPPUNIT_TEST(testTrieGetAllEntries); CPPUNIT_TEST_SUITE_END(); @@ -45,185 +39,6 @@ public: CPPUNIT_TEST_SUITE_REGISTRATION(LookupTreeTest); -void LookupTreeTest::testLookupTree() -{ - LookupTree* a = new LatinLookupTree( "a" ); - - a->insert( OUString("vorschlagnummer1"), 2 ); - a->insert( OUString("vorschlagnummer12") ); - a->insert( OUString("vorschlagnummer2") ); - - CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer1"), a->suggestAutoCompletion() ); - - a->insert( OUString("vorschlagnummer12") ); - CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer12"), a->suggestAutoCompletion() ); - - a->insert( OUString("vorschlagnummer2") ); - a->insert( OUString("vorschlagnummer2") ); - CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer2"), a->suggestAutoCompletion() ); - - a->insert( OUString("vorschlag"), 15 ); - CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() ); - - a->insert( OUString("vorschlagnummer2"), 16 ); - CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer2"), a->suggestAutoCompletion() ); - - a->remove( OUString("vorschlagnummer2") ); - CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() ); - - a->insert( OUString("vorschlag20"), 20 ); - CPPUNIT_ASSERT_EQUAL( OUString("vorschlag20"), a->suggestAutoCompletion() ); - - a->remove( OUString("vorschlag20") ); - CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() ); - - a->insert( OUString("vorschlagn"), 14 ); - CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() ); - - a->remove( OUString("vorschlag") ); - CPPUNIT_ASSERT_EQUAL( OUString("vorschlagn"), a->suggestAutoCompletion() ); - - a->remove( OUString("vorschlagn") ); - CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer12"), a->suggestAutoCompletion() ); - - a->insert( OUString("aber"), 1 ); - CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer12"), a->suggestAutoCompletion() ); - - a->advance( 'a' ); - CPPUNIT_ASSERT_EQUAL( OUString("ber"), a->suggestAutoCompletion() ); - - a->goBack(); - CPPUNIT_ASSERT_EQUAL( OUString("vorschlagnummer12"), a->suggestAutoCompletion() ); - - a->insert( OUString("vorschlag"), 15 ); - CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() ); - - a->insert( OUString("vorschlag13"), 13 ); - CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() ); - - a->gotoNode( "vorsch" ); - CPPUNIT_ASSERT_EQUAL( OUString("lag"), a->suggestAutoCompletion() ); - - a->advance( 'l' ); - CPPUNIT_ASSERT_EQUAL( OUString("ag"), a->suggestAutoCompletion() ); - - a->advance( 'a' ); - CPPUNIT_ASSERT_EQUAL( OUString("g13"), a->suggestAutoCompletion() ); - - a->advance( 'g' ); - CPPUNIT_ASSERT_EQUAL( OUString("13"), a->suggestAutoCompletion() ); - - a->advance( '1' ); - CPPUNIT_ASSERT_EQUAL( OUString("3"), a->suggestAutoCompletion() ); - - a->advance( '3' ); - CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() ); - - a->goBack(); - a->advance( 'z' ); - CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() ); - - /*a->gotoNode( "vorschlag13" ); - CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() ); - - a->advance( 'g' ); - a->advance( '1' ); - a->advance( '3' ); - a->remove( "vorschlag13" ); - CPPUNIT_ASSERT_EQUAL( OUString(""), a->suggestAutoCompletion() );*/ - - a->insert( "VeraHatMichL1eb.", 1000000 ); - a->returnToRoot(); - CPPUNIT_ASSERT_EQUAL( OUString("VeraHatMichL1eb."), a->suggestAutoCompletion() ); - - a->remove( "VeraHatMichL1eb." ); - a->gotoNode( "VeraHatMich" ); - CPPUNIT_ASSERT_EQUAL( OUString(""), a->suggestAutoCompletion() ); - - a->returnToRoot(); - CPPUNIT_ASSERT_EQUAL( OUString("vorschlag"), a->suggestAutoCompletion() ); - - a->gotoNode( "VeraLiebtMich" ); - a->insert( 600 ); - a->returnToRoot(); - CPPUNIT_ASSERT_EQUAL( OUString("VeraLiebtMich"), a->suggestAutoCompletion() ); - - a->insert( "VeraHatMichL1eb.", 1000000 ); - a->returnToRoot(); - CPPUNIT_ASSERT_EQUAL( OUString("VeraHatMichL1eb."), a->suggestAutoCompletion() ); - - a->remove( "VeraHatMichL1eb." ); - a->gotoNode( "VeraHatMich" ); - CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() ); - - a->advance( 'L' ); - CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() ); - - a->insert( "VeraHatMichL1eb.", 1000000 ); - a->returnToRoot(); - a->remove( "VeraHatMichL1eb." ); - a->gotoNode( "VeraHatMich" ); - CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() ); - - a->goBack(); - CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() ); - - a->insert( "VeraHatMichL1eb.", 1000000 ); - a->returnToRoot(); - a->remove( "VeraHatMichL1eb." ); - a->gotoNode( "VeraHatMich" ); - CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() ); - - a->goBack(); - CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() ); - - a->insert( "neu", 2000 ); - a->returnToRoot(); - CPPUNIT_ASSERT_EQUAL( OUString("neu"), a->suggestAutoCompletion() ); - - a->gotoNode( "ne" ); - CPPUNIT_ASSERT_EQUAL( OUString("u"), a->suggestAutoCompletion() ); - - a->advance( 'u' ); - a->advance( 'e' ); - a->advance( 'r' ); - a->insert(); - CPPUNIT_ASSERT ( a->suggestAutoCompletion().isEmpty() ); - - a->returnToRoot(); - CPPUNIT_ASSERT_EQUAL( OUString("neu"), a->suggestAutoCompletion() ); - - a->advance( 'n' ); - CPPUNIT_ASSERT_EQUAL( OUString("eu"), a->suggestAutoCompletion() ); - - a->advance( 'e' ); - CPPUNIT_ASSERT_EQUAL( OUString("uer"), a->suggestAutoCompletion() ); - - // Test unicode - OUString aQueryString = OStringToOUString( "H\xC3\xA4llo", RTL_TEXTENCODING_UTF8 ); - a->insert( aQueryString ); - a->returnToRoot(); - a->advance( 'H' ); - - OUString aAutocompletedString = a->suggestAutoCompletion(); - OUString aExpectedString = OStringToOUString( "\xC3\xA4llo", RTL_TEXTENCODING_UTF8 ); - - CPPUNIT_ASSERT_EQUAL( aExpectedString, aAutocompletedString ); - - OString aUtf8String( "\xe3\x81\x82\xe3\x81\x97\xe3\x81\x9f" ); - aQueryString = OStringToOUString( aUtf8String, RTL_TEXTENCODING_UTF8 ); - a->insert( aQueryString ); - - OUString aGotoString = OStringToOUString( "\xe3\x81\x82", RTL_TEXTENCODING_UTF8 ); - a->gotoNode( aGotoString ); - - aAutocompletedString = a->suggestAutoCompletion(); - aExpectedString = OStringToOUString( "\xe3\x81\x97\xe3\x81\x9f", RTL_TEXTENCODING_UTF8 ); - CPPUNIT_ASSERT_EQUAL( aExpectedString, aAutocompletedString ); - - delete a; -} - void LookupTreeTest::testTrie() { editeng::Trie trie; diff --git a/editeng/source/lookuptree/LatinLookupTree.cxx b/editeng/source/lookuptree/LatinLookupTree.cxx deleted file mode 100644 index cdc0a0b..0000000 --- a/editeng/source/lookuptree/LatinLookupTree.cxx +++ /dev/null @@ -1,242 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <editeng/LatinLookupTree.hxx> -#include <editeng/LatinTreeNode.hxx> - -LatinLookupTree::LatinLookupTree(OUString sLanguage) : - LookupTree( sLanguage ) -{ - for ( sal_Unicode i = 0; i < 52; ++i ) - { - m_pLeaves[i] = NULL; - } -} - -LatinLookupTree::~LatinLookupTree() -{ - freeMemory(); -} - -void LatinLookupTree::returnToRoot() -{ - if ( m_pCurrent == m_pHead ) - return; - - // If there is no entry in this node or the tree that sprouts from it. - if ( m_pCurrent && - m_pCurrent->m_pParent && - !m_pCurrent->m_nChildren && - !m_pCurrent->m_nKeyProbability ) - { - m_pCurrent->m_pParent->childHasChanged( m_pCurrent, 0, true ); - } - - m_pCurrent = m_pHead; -} - -void LatinLookupTree::gotoNode(OUString sNode) -{ - returnToRoot(); - - // walk down the tree... - for ( int i = 0; i < sNode.getLength(); i++ ) - { - m_pCurrent = m_pCurrent->advanceKey( sNode[i] ); - } -} - -void LatinLookupTree::advance(const sal_Unicode cKey) -{ - m_pCurrent = m_pCurrent->advanceKey( cKey ); -} - -void LatinLookupTree::goBack() -{ - if ( m_pCurrent->m_pParent ) // if we're not at the root - { - const Node* const pChild = m_pCurrent; - m_pCurrent = m_pCurrent->m_pParent; // set focus to parent - - // if this is an unused tree leaf - if ( !pChild->m_nChildren && !pChild->m_nKeyProbability ) - { - m_pCurrent->removeChild( m_pCurrent->getChildRef( pChild->m_cKey ) ); - } - } -} - -void LatinLookupTree::insert(OUString sKey, const int nProbability) -{ - if ( !sKey.isEmpty() && nProbability > 0 ) - { - insertKey( sKey, nProbability ); - } -} - -void LatinLookupTree::insert(const int nProbability) -{ - if ( m_pCurrent == this ) - return; - - // change probability - int proba = m_pCurrent->m_nKeyProbability += nProbability; - - // inform his parent - m_pCurrent->m_pParent->childHasChanged( m_pCurrent, proba ); -} - -void LatinLookupTree::remove(OUString sKey) -{ - returnToRoot(); - - if ( !sKey.isEmpty() ) - { - removeKey( sKey ); - } -} - -OUString LatinLookupTree::suggestAutoCompletion() const -{ - if ( !m_pCurrent ) - return OUString(); - - Node* pWalker = m_pCurrent; - - int distance = 0, nTargetProbability = 0; - OUString sSuggestion; - - while ( pWalker->m_pSuggest && ( distance < 2 || - // Make sure the suggestion is at least 2 chars long. - nTargetProbability == pWalker->m_nHighestProbaInSubtree ) ) - { - if ( distance < 2 ) - nTargetProbability = pWalker->m_nHighestProbaInSubtree; - - // follow the tree along the suggested route - pWalker = pWalker->m_pSuggest; - ++distance; - sSuggestion += OUString(pWalker->m_cKey); - } - - return sSuggestion; -} - -void LatinLookupTree::clear() -{ - freeMemory(); -} - -bool LatinLookupTree::isSeparatedlyHandled(const sal_Unicode cKey) const -{ - return - ( cKey >= 'a' && cKey <= 'z' ) - || ( cKey >= 'A' && cKey <= 'Z' ); -} - -Node*& LatinLookupTree::getChildRef(const sal_Unicode cKey, bool bCreatePlaceholder) -{ - int pos = -1; - - // determine position in array if possible - if ( cKey >= 'a' && cKey <= 'z' ) - { - pos = cKey - our_nLowerCaseA; - } - else if ( cKey >= 'A' && cKey <= 'Z' ) - { - pos = cKey - our_nUpperCaseA + 26; - } - - if ( pos != -1 ) - { - return m_pLeaves[pos]; - } - else - { - for ( std::list<Node*>::iterator i = m_lChildren.begin(); i != m_lChildren.end(); ++i ) - { - if ( (*i)->m_cKey == cKey ) - { - return *i; - } - } - if ( bCreatePlaceholder ) - { - // Create new entry in case there isn't one. - m_lChildren.push_back( NULL ); - return *(--m_lChildren.end()); - } - else - { - return our_pNodeNullPointer; - } - } -} - -void LatinLookupTree::evaluateSeparateStorage(int& nSuggest, Node*& pSuggest) const -{ - for ( sal_Unicode i = 0; i < 52; ++i ) - { - if ( m_pLeaves[i] ) - { - if ( m_pLeaves[i]->m_nHighestProbaInSubtree > nSuggest ) - { - nSuggest = m_pLeaves[i]->m_nHighestProbaInSubtree; - pSuggest = m_pLeaves[i]; - } - if ( m_pLeaves[i]->m_nKeyProbability > nSuggest ) - { - nSuggest = m_pLeaves[i]->m_nKeyProbability; - pSuggest = m_pLeaves[i]; - } - } - } -} - -void LatinLookupTree::freeMemory() -{ - // remove nodes from array - for ( sal_Unicode i = 0; i < 52; ++i ) - { - if ( m_pLeaves[i] ) - { - m_pLeaves[i]->freeMemory(); - delete m_pLeaves[i]; - m_pLeaves[i] = NULL; - } - } - // clear list - while ( m_lChildren.size() ) - { - Node* pTmp = m_lChildren.front(); - m_lChildren.pop_front(); - delete pTmp; - } -} - -Node* LatinLookupTree::newNode(Node* pParent, const sal_Unicode cKey, const int nProbability) -{ - return new LatinTreeNode( this, pParent, cKey, nProbability ); -} - -const unsigned int LatinLookupTree::our_nLowerCaseA = 97; -const unsigned int LatinLookupTree::our_nUpperCaseA = 65; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/editeng/source/lookuptree/LatinTreeNode.cxx b/editeng/source/lookuptree/LatinTreeNode.cxx deleted file mode 100644 index a7f10aa..0000000 --- a/editeng/source/lookuptree/LatinTreeNode.cxx +++ /dev/null @@ -1,112 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <editeng/LatinTreeNode.hxx> -#include <editeng/LatinLookupTree.hxx> - -LatinTreeNode::LatinTreeNode(TreeHead* pHead, Node* pParent, const sal_Unicode cKey, const int nProbability) : - Node( pHead, pParent, cKey, nProbability ) -{ - for ( sal_Unicode i = 0; i < 26; ++i ) - { - m_pLeaves[i] = NULL; - } -} - -LatinTreeNode::~LatinTreeNode() -{ - freeMemory(); -} - -bool LatinTreeNode::isSeparatedlyHandled(const sal_Unicode cKey) const -{ - return ( cKey >= 'a' && cKey <= 'z' ); -} - -Node*& LatinTreeNode::getChildRef(const sal_Unicode cKey, bool bCreatePlaceholder) -{ - // determine position in array if possible - if ( cKey >= 'a' && cKey <= 'z' ) - { - return m_pLeaves[cKey - LatinLookupTree::our_nLowerCaseA]; - } - else - { - for ( std::list<Node*>::iterator i = m_lChildren.begin(); i != m_lChildren.end(); ++i ) - { - if ( (*i)->m_cKey == cKey ) - { - return *i; - } - } - if ( bCreatePlaceholder ) - { - // Create new entry in case there isn't one. - m_lChildren.push_back( NULL ); - return *(--m_lChildren.end()); - } - else - { - return our_pNodeNullPointer; - } - } -} - -void LatinTreeNode::evaluateSeparateStorage(int& nSuggest, Node*& pSuggest) const -{ - for ( sal_Unicode i = 0; i < 26; ++i ) - { - if ( m_pLeaves[i] ) - { - if ( m_pLeaves[i]->m_nHighestProbaInSubtree > nSuggest ) - { - nSuggest = m_pLeaves[i]->m_nHighestProbaInSubtree; - pSuggest = m_pLeaves[i]; - } - if ( m_pLeaves[i]->m_nKeyProbability > nSuggest ) - { - nSuggest = m_pLeaves[i]->m_nKeyProbability; - pSuggest = m_pLeaves[i]; - } - } - } -} - -void LatinTreeNode::freeMemory() -{ - // remove nodes from array - for ( sal_Unicode i = 0; i < 26; ++i ) - { - if ( m_pLeaves[i] ) - { - m_pLeaves[i]->freeMemory(); - delete m_pLeaves[i]; - m_pLeaves[i] = NULL; - } - } - // clear list - while ( m_lChildren.size() ) - { - Node* pTmp = m_lChildren.front(); - m_lChildren.pop_front(); - delete pTmp; - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/editeng/source/lookuptree/Node.cxx b/editeng/source/lookuptree/Node.cxx deleted file mode 100644 index 2492a88..0000000 --- a/editeng/source/lookuptree/Node.cxx +++ /dev/null @@ -1,216 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <editeng/TreeHead.hxx> -#include <editeng/Node.hxx> - -Node::Node(TreeHead* const pHead, Node* const pParent, - const sal_Unicode cKey, const int nProbability ) : - m_cKey( cKey ), - m_nKeyProbability( nProbability ), - m_nHighestProbaInSubtree( 0 ), - m_pParent( pParent ), - m_pSuggest( NULL ), - m_pHead( pHead ), - m_nChildren( 0 ) -{ -} - -Node::~Node() -{ -} - -void Node::removeChild(Node*& pChild) -{ - const sal_Unicode cKey = pChild->m_cKey; - - if ( pChild ) - { - delete pChild; - pChild = NULL; - --m_nChildren; - } - - if ( !isSeparatedlyHandled( cKey ) ) - { - std::list<Node*>::iterator i = m_lChildren.begin(); - while ( i != m_lChildren.end() ) - { - if ( !(*i) ) - { - i = m_lChildren.erase( i ); - } - else - { - ++i; - } - } - } -} - -void Node::insertKey(OUString sKey, const int nProbability) -{ - if ( !sKey.isEmpty() ) - { - const sal_Unicode cKey = sKey[0]; - sKey = sKey.copy( 1 ); - - Node*& pChild = getChildRef( cKey, true ); - - if ( !pChild ) - { - pChild = m_pHead->newNode( this, cKey ); - ++m_nChildren; - } - - pChild->insertKey( sKey, nProbability ); - } - else - { - m_nKeyProbability += nProbability; - if ( m_pParent ) - { - // inform parent about change - int probability = m_nHighestProbaInSubtree > m_nKeyProbability ? m_nHighestProbaInSubtree : m_nKeyProbability; - m_pParent->childHasChanged( this, probability); - } - } -} - -// Removes a complete keyword starting from this node of the tree. -void Node::removeKey(OUString sKey) -{ - if ( !sKey.isEmpty() ) - { - Node*& pChild = getChildRef( sKey[0] ); - - if ( pChild ) - { - // recursive call downwards - pChild->removeKey( sKey.copy( 1 ) ); - } - // Else: Keyword to be removed couldn't be found within the tree. - // No further changes are going to be made. - } - else // If we are the node to be removed... - { - // ... remove our entry from tree... - m_nKeyProbability = 0; - // ... and make sure our parent is updated. - m_pParent->childHasChanged( this, m_nHighestProbaInSubtree, this != m_pHead->m_pCurrent ); - } -} - -Node *Node::advanceKey(const sal_Unicode cKey) -{ - Node*& pChild = getChildRef( cKey, true ); - - if ( !pChild ) - { - pChild = m_pHead->newNode( this, cKey ); - } - - return pChild; -} - -void Node::childHasChanged(Node *pChild, const int nProbability, bool bAllowRemoval) -{ - if ( nProbability > m_nHighestProbaInSubtree ) - { - m_pSuggest = pChild; - m_nHighestProbaInSubtree = nProbability; - - if ( m_pParent ) // recursive call upwards - { - int probabilityChange = nProbability > m_nKeyProbability ? nProbability : m_nKeyProbability; - m_pParent->childHasChanged( this, probabilityChange ); - } - } - else if ( !nProbability || nProbability < m_nHighestProbaInSubtree ) - { - bool bNewEvaluationRequired = m_pSuggest == pChild; - - if ( !nProbability && bAllowRemoval ) - { - // Remove child. Caller needs to make sure we are allowed to. - removeChild( getChildRef( pChild->m_cKey ) ); - } - - if ( bNewEvaluationRequired ) - { - // This is used to store whether we need to inform our parent about - // the changes within this node. - bool bNodeProbabilityChanged; - - reevaluateSuggestion( bNodeProbabilityChanged ); - - // If necessary, inform our parent about change via recursive call - if ( bNodeProbabilityChanged && m_pParent ) - { - bAllowRemoval = bAllowRemoval && this != m_pHead->m_pCurrent; - int probabilityChange = m_nHighestProbaInSubtree > m_nKeyProbability ? m_nHighestProbaInSubtree : m_nKeyProbability; - m_pParent->childHasChanged( this, probabilityChange, bAllowRemoval ); - } - } - } -} - -void Node::reevaluateSuggestion(bool& bNodeProbabilityChanged) -{ - if ( m_nChildren ) // find child with highest probability - { - int nSuggest = 0; - Node* pSuggest = NULL; - - // find child with highest probability in array - evaluateSeparateStorage( nSuggest, pSuggest ); - - // do the same thing within list - for ( std::list<Node*>::iterator i = m_lChildren.begin(); i != m_lChildren.end(); ++i ) - { - if ( (*i)->m_nHighestProbaInSubtree > nSuggest ) - { - nSuggest = (*i)->m_nHighestProbaInSubtree; - pSuggest = (*i); - } - if ( (*i)->m_nKeyProbability > nSuggest ) - { - nSuggest = (*i)->m_nKeyProbability; - pSuggest = (*i); - } - } - - // determine whether we need to inform our parent - bNodeProbabilityChanged = m_nHighestProbaInSubtree != nSuggest; - - m_pSuggest = pSuggest; - m_nHighestProbaInSubtree = nSuggest; - } - else // there are no children - { - m_pSuggest = NULL; - m_nHighestProbaInSubtree = 0; - - bNodeProbabilityChanged = true; - } -} - -Node* Node::our_pNodeNullPointer = NULL; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/editeng/LatinLookupTree.hxx b/include/editeng/LatinLookupTree.hxx deleted file mode 100644 index e35d62b..0000000 --- a/include/editeng/LatinLookupTree.hxx +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_EDITENG_LATINLOOKUPTREE_HXX -#define INCLUDED_EDITENG_LATINLOOKUPTREE_HXX - -#include <editeng/LookupTree.hxx> -#include <editeng/TreeHead.hxx> -#include <editeng/editengdllapi.h> - -/** - * LatinLookupTree implements a tree that is optimized for storing and looking - * up words that mainly consist of roman characters, although any other - * language can be handled, too. - */ -class EDITENG_DLLPUBLIC LatinLookupTree : public LookupTree, public TreeHead -{ -public: - - explicit LatinLookupTree(OUString sLanguage); - ~LatinLookupTree(); - - - /* =================== Implemented Virtuals From LookupTree =================== */ - void returnToRoot(); - void gotoNode(OUString sNode); - void advance(const sal_Unicode a); - void goBack(); - void insert(OUString sKey, const int nProbability = 1); - void insert(const int nProbability = 1); - void remove(OUString sKey); - OUString suggestAutoCompletion() const; - void clear(); - - /* =================== Implemented Virtuals From Node =================== */ - bool isSeparatedlyHandled(const sal_Unicode cKey) const; - Node*& getChildRef(const sal_Unicode cKey, bool bCreatePlaceholder = false); - void evaluateSeparateStorage(int& nSuggest, Node*& pSuggest) const; - void freeMemory(); - - - /* =================== Implemented Virtual From TreeHead =================== */ - Node* newNode(Node* pParent, const sal_Unicode cKey, const int nProbability = 0); - - /* =================== Member Variables =================== */ - // position of lower case letter 'a' within the selected char encoding. - static const unsigned int our_nLowerCaseA; - - // position of upper case letter 'A' within the selected char encoding. - static const unsigned int our_nUpperCaseA; - -private: - Node* m_pLeaves[52]; // handles [a-z] and [A-Z] -}; - -#endif // INCLUDED_EDITENG_LATINLOOKUPTREE_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/editeng/LatinTreeNode.hxx b/include/editeng/LatinTreeNode.hxx deleted file mode 100644 index 09a82f8..0000000 --- a/include/editeng/LatinTreeNode.hxx +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_EDITENG_LATINTREENODE_HXX -#define INCLUDED_EDITENG_LATINTREENODE_HXX - -#include <editeng/Node.hxx> - -/** - * LatinTreeNode represents a node within a LatinLookupTree. As en external - * caller, you should never have to do anything with this class directly. - * Use the class LatinLookupTree instead for constructing a new tree. - */ -class LatinTreeNode : public Node -{ -public: - explicit LatinTreeNode(TreeHead *pHead, Node* pParent, const sal_Unicode cKey, const int nProbability = 0); - ~LatinTreeNode(); - - /* =================== Implemented Virtuals From Node =================== */ - bool isSeparatedlyHandled(const sal_Unicode cKey) const; - Node*& getChildRef(const sal_Unicode cKey, bool bCreatePlaceholder = false); - void evaluateSeparateStorage(int& nSuggest, Node*& pSuggest) const; - void freeMemory(); - -private: - Node* m_pLeaves[26]; // handles [a-z] -}; - -#endif // INCLUDED_EDITENG_LATINTREENODE_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/editeng/LookupTree.hxx b/include/editeng/LookupTree.hxx deleted file mode 100644 index c961d11..0000000 --- a/include/editeng/LookupTree.hxx +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_EDITENG_LOOKUPTREE_HXX -#define INCLUDED_EDITENG_LOOKUPTREE_HXX - -#include <sal/types.h> -#include <rtl/ustring.hxx> -#include <editeng/editengdllapi.h> - -/** LookupTree is an interface class that allows for unified access to tree - * structures used for storing dictionnary words as well as their respective - * probabilities. - * It allows you to insert or remove words from the tree, navigate threw the - * tree along its branches and request for a suggestion for autocompletion - * according to the position within the tree. - * It also allows you to attribute a specific language to each tree so that - * it is possible to serve the correct auto completions even within a document - * that contains content in more than one language. - */ -class EDITENG_DLLPUBLIC LookupTree -{ -public: - explicit inline LookupTree(OUString sLanguage); - virtual ~LookupTree() {} - - inline OUString language() const; - - // Resets the current item to root. - virtual void returnToRoot() = 0; - - // Advances from the root position key by key towards the node keyed with - // the last char of sKey. - virtual void gotoNode(OUString sNode) = 0; - - // Advances from the current position towards the node keyed with cKey. - virtual void advance(const sal_Unicode cKey) = 0; - - // Sets the focus to the parent of the current node. Removes the current - // node if it is invalid. - virtual void goBack() = 0; - - // Inserts a complete keyword starting from the root node of the tree. - // Does not change the current position within the tree. - virtual void insert(OUString sKey, const int nProbability = 1) = 0; - - // Inserts a keyword with the given probability at the current position - // within the tree. Does not change the current position within the tree. - virtual void insert(const int nProbability = 1) = 0; - - // Removes a complete keyword starting from the root node of the tree. - // Does not change the current position within the tree. - virtual void remove(OUString sKey) = 0; - - // Returns the suggested autocompletion for the current location within - // the tree. - virtual OUString suggestAutoCompletion() const = 0; - - // Clears the tree and removes any information it contains. - virtual void clear() = 0; - - -private: - const OUString m_sLanguage; // language handled by this tree -}; - -LookupTree::LookupTree(OUString sLanguage) : - m_sLanguage( sLanguage ) -{ -} - -OUString LookupTree::language() const -{ - return m_sLanguage; -} - -#endif // INCLUDED_EDITENG_LOOKUPTREE_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/editeng/Node.hxx b/include/editeng/Node.hxx deleted file mode 100644 index 62e775d..0000000 --- a/include/editeng/Node.hxx +++ /dev/null @@ -1,102 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_EDITENG_NODE_HXX -#define INCLUDED_EDITENG_NODE_HXX - -#include <sal/types.h> -#include <rtl/ustring.hxx> -#include <list> - -class TreeHead; - -/** - * Node represents a node within a LookupTree. As en external caller, you - * should never have to do anything with this class directly. - * Use any of the classes derived from LookupTree instead for constructing a - * new tree. - */ -class Node -{ -public: - //explicit Node(TreeHead* const pHead); - explicit Node(TreeHead* const pHead, Node* const pParent = NULL, - const sal_Unicode cKey = 0, const int nProbability = 0); - - virtual ~Node(); - - // Removes the specified child from this node. Make sure you may remove it - // before doing so. - void removeChild(Node*& pChild); - - // Inserts a complete keyword starting from this node of the tree. - void insertKey(OUString sKey, const int nProbability); - // Removes a complete keyword starting from this node of the tree. - void removeKey(OUString sKey); - - // Returns the child node keyed with cKey. - Node* advanceKey(const sal_Unicode cKey); - - // Use this to inform a parent about its child having changed. - // Call this only with nProbability = 0 if you have made sure the node can - // be removed. - void childHasChanged(Node* pChild, const int nProbability, bool bAllowRemoval = false); - - // Rechose the node that is suggested for auto-completion - void reevaluateSuggestion(bool& bNodeProbabilityChanged); - - - /* =================== Virtuals =================== */ - virtual bool isSeparatedlyHandled(const sal_Unicode cKey) const = 0; - - // Returns a reference to the pointer to the child node for the requested - // char. Returns NULL if no such child could be found. - // IMPORTANT: In the latter case, you may NOT overwrite the return value, - // if you did not set bCreatePlaceholder to true. - virtual Node*& getChildRef(const sal_Unicode cKey, bool bCreatePlaceholder = false) = 0; - - // Sets nSuggest to the highest probability within the subtree and pSuggest - // to point to the (first) node with this probability. - virtual void evaluateSeparateStorage(int& nSuggest, Node*& pSuggest) const = 0; - - // Removes all child nodes and clears all memory. - virtual void freeMemory() = 0; - - /* =================== Member Variables =================== */ - const sal_Unicode m_cKey; // the char represented by this node - int m_nKeyProbability; // the number of occurrences of this key - - // the highest KeyProbability in the tree sprouting from this node - int m_nHighestProbaInSubtree; - - Node* const m_pParent; // the parent of this node - Node* m_pSuggest; // next node in chain to the suggested autocompletion - - TreeHead* const m_pHead; // head of the tree - - unsigned short m_nChildren; // the number of children of the node - std::list<Node*> m_lChildren; // all chars not handled by array - - // Allows returning a reference to a valid Null pointer. May NOT be overwritten. - static Node* our_pNodeNullPointer; -}; - -#endif // INCLUDED_EDITENG_NODE_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/editeng/TreeHead.hxx b/include/editeng/TreeHead.hxx deleted file mode 100644 index f36aff5..0000000 --- a/include/editeng/TreeHead.hxx +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_EDITENG_TREEHEAD_HXX -#define INCLUDED_EDITENG_TREEHEAD_HXX - -#include <editeng/Node.hxx> - -/** - * Represents the root node of a LookupTree. - */ -class TreeHead : public Node -{ -public: - explicit inline TreeHead(); - virtual ~TreeHead() {} - - /* =================== Virtuals =================== */ - virtual Node* newNode(Node* pParent, const sal_Unicode cKey, const int nProbability = 0) = 0; - - /* =================== Member Variables =================== */ - Node* m_pCurrent; // current location within the tree -}; - -TreeHead::TreeHead() : - Node( this ), - m_pCurrent( this ) -{ -} - -#endif // INCLUDED_EDITENG_TREEHEAD_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 569e5f023ea3dc86988365ac23ceef70b94b177d Author: Tomaž Vajngerl <[email protected]> Date: Sun Feb 2 15:02:36 2014 +0100 Add getAllElements (strings) for Trie. Change-Id: I9603cc51545f72fdb0854f2d76e2326706329000 diff --git a/editeng/qa/lookuptree/lookuptree_test.cxx b/editeng/qa/lookuptree/lookuptree_test.cxx index ab2f814..0bea3a5 100644 --- a/editeng/qa/lookuptree/lookuptree_test.cxx +++ b/editeng/qa/lookuptree/lookuptree_test.cxx @@ -34,10 +34,12 @@ class LookupTreeTest : public CppUnit::TestFixture public: void testLookupTree(); void testTrie(); + void testTrieGetAllEntries(); CPPUNIT_TEST_SUITE(LookupTreeTest); CPPUNIT_TEST(testLookupTree); CPPUNIT_TEST(testTrie); + CPPUNIT_TEST(testTrieGetAllEntries); CPPUNIT_TEST_SUITE_END(); }; @@ -227,11 +229,11 @@ void LookupTreeTest::testTrie() editeng::Trie trie; std::vector<OUString> suggestions; - trie.findSuggestions( OUString(""), suggestions); + trie.findSuggestions( OUString(), suggestions); CPPUNIT_ASSERT_EQUAL( (size_t) 0, suggestions.size() ); - trie.insert( OUString("") ); - trie.findSuggestions( OUString(""), suggestions); + trie.insert( OUString() ); + trie.findSuggestions( OUString(), suggestions); CPPUNIT_ASSERT_EQUAL( (size_t) 0, suggestions.size() ); trie.findSuggestions( OUString("a"), suggestions); @@ -302,7 +304,33 @@ void LookupTreeTest::testTrie() trie.findSuggestions( OUString(""), suggestions); CPPUNIT_ASSERT_EQUAL( (size_t) 6, suggestions.size() ); suggestions.clear(); +} + +void LookupTreeTest::testTrieGetAllEntries() +{ + editeng::Trie trie; + + std::vector<OUString> entries; + + trie.getAllEntries(entries); + CPPUNIT_ASSERT_EQUAL( (size_t) 0, entries.size() ); + + trie.insert("A"); + trie.getAllEntries(entries); + CPPUNIT_ASSERT_EQUAL( (size_t) 1, entries.size() ); + entries.clear(); + + trie.insert("B"); + trie.insert("C"); + trie.getAllEntries(entries); + CPPUNIT_ASSERT_EQUAL( (size_t) 3, entries.size() ); + entries.clear(); + trie.insert("AA"); + trie.insert("AAA"); + trie.getAllEntries(entries); + CPPUNIT_ASSERT_EQUAL( (size_t) 5, entries.size() ); + entries.clear(); } } // namespace end diff --git a/editeng/source/lookuptree/Trie.cxx b/editeng/source/lookuptree/Trie.cxx index 9314069..a0ca91e 100644 --- a/editeng/source/lookuptree/Trie.cxx +++ b/editeng/source/lookuptree/Trie.cxx @@ -196,5 +196,13 @@ void Trie::findSuggestions(OUString sWordPart, vector<OUString>& rSuggesstionLis } } +void Trie::getAllEntries(std::vector<OUString>& entries) +{ + if (mRoot != NULL) + { + mRoot->collectSuggestions(OUString(), entries); + } +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/editeng/Trie.hxx b/include/editeng/Trie.hxx index 6c48833..f5f42f0 100644 --- a/include/editeng/Trie.hxx +++ b/include/editeng/Trie.hxx @@ -32,7 +32,7 @@ public: void insert(OUString sInputString) const; void findSuggestions(OUString sWordPart, std::vector<OUString>& rSuggesstionList) const; - + void getAllEntries(std::vector<OUString>& entries); }; }
_______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
