Changeset 156

Show
Ignore:
Timestamp:
05/09/06 11:15:14 (2 years ago)
Author:
jordi
Message:

The FindPter? can now search new matches in forward directions (i.e., Find Next.)

Location:
trunk
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/FindPter.cxx

    r154 r156  
    2828{ 
    2929    g_assert (NULL != document && "Tried to set a NULL document."); 
    30      
     30 
     31    m_CurrentMatch = NULL; 
    3132    m_Document = document; 
     33    m_FindPage = 0; 
     34    m_FindResults = NULL; 
    3235    m_Job = NULL; 
    3336    m_View = NULL; 
     
    3841/// 
    3942FindPter::~FindPter () 
    40 { 
     43{     
    4144    m_Document = NULL; 
    4245    if ( NULL != m_Job ) 
     
    4447        m_Job->cancel (); 
    4548    } 
    46     delete m_View; 
     49    freeFindResults (); 
     50} 
     51 
     52/// 
     53/// @brief The Find Next button has been clicked. 
     54/// 
     55void 
     56FindPter::findNextActivated () 
     57{ 
     58    m_CurrentMatch = g_list_next (m_CurrentMatch); 
     59    if ( NULL != m_CurrentMatch ) 
     60    { 
     61        DocumentRectangle *rect = ((DocumentRectangle *)m_CurrentMatch->data); 
     62        m_Document->goToPage (m_FindPage); 
     63        m_Document->notifyFindChanged (rect); 
     64    } 
     65    else 
     66    { 
     67        IJob::queue (m_Job); 
     68    } 
     69} 
     70 
     71void 
     72FindPter::freeFindResults () 
     73{  
     74    for ( GList *item = g_list_first (m_FindResults) ; NULL != item ; 
     75          item = g_list_next (item) ) 
     76    { 
     77        DocumentRectangle *rect = (DocumentRectangle *)item->data; 
     78        delete rect; 
     79    } 
     80    g_list_free (m_FindResults); 
     81    m_FindResults = NULL; 
    4782} 
    4883 
     
    67102    m_View->setInformationText (_("Not Found!")); 
    68103    m_Document->notifyFindFinished (); 
     104} 
     105 
     106void 
     107FindPter::notifyFindResults (gint pageNum, GList *results) 
     108{ 
     109    m_FindPage = pageNum; 
     110    freeFindResults (); 
     111    m_FindResults = results; 
     112    m_CurrentMatch = g_list_first (m_FindResults); 
     113    m_Document->goToPage (m_FindPage); 
     114    DocumentRectangle *rect = (DocumentRectangle *)m_CurrentMatch->data; 
     115    m_Document->notifyFindChanged (rect); 
    69116} 
    70117 
  • trunk/src/FindPter.h

    r154 r156  
    3737            ~FindPter (void); 
    3838 
     39            void findNextActivated (void); 
    3940            IFindView &getView (void); 
    4041            void notifyFindFinished (void); 
     42            void notifyFindResults (gint pageNum, GList *results); 
    4143            void setView (IFindView *view); 
    4244            void textToFindChanged (void); 
    4345 
    4446        protected: 
     47            /// The current selected match from m_FindResults. 
     48            GList *m_CurrentMatch; 
    4549            /// The document to search to. 
    4650            IDocument *m_Document; 
     51            /// The current page that we found something. 
     52            gint m_FindPage; 
     53            /// The results on m_FindPage. 
     54            GList *m_FindResults; 
    4755            /// The current find job. 
    4856            JobFind *m_Job; 
    4957            /// The view that the presenter is controlling. 
    5058            IFindView *m_View; 
     59 
     60            void freeFindResults (void); 
    5161    }; 
    5262} 
  • trunk/src/IDocument.cxx

    r154 r156  
    203203 
    204204void 
     205IDocument::notifyFindChanged (DocumentRectangle *matchRect) 
     206{ 
     207    for ( GList *item = g_list_first (m_Observers) ; NULL != item ; 
     208          item = g_list_next (item) ) 
     209    { 
     210        IDocumentObserver *observer = (IDocumentObserver *)item->data; 
     211        observer->notifyFindChanged (matchRect); 
     212    }  
     213} 
     214 
     215void 
    205216IDocument::notifyFindFinished () 
    206217{ 
  • trunk/src/IDocument.h

    r154 r156  
    204204            void detach (const IDocumentObserver *observer); 
    205205 
     206            void notifyFindChanged (DocumentRectangle *matchRect); 
    206207            void notifyFindFinished (void); 
    207208            void notifyFindStarted (void); 
  • trunk/src/IDocumentObserver.h

    r154 r156  
    3232            /// @brief Destroys all dynamically allocated memory. 
    3333            virtual ~IDocumentObserver (void) { } 
     34 
     35            /// 
     36            /// @brief A find result has been changed. 
     37            /// 
     38            /// This is called every time the highligthed find result 
     39            /// is changed. 
     40            /// 
     41            /// @param matchRect The rectangle of the highligthed result. 
     42            /// 
     43            virtual void notifyFindChanged (DocumentRectangle *matchRect) { } 
    3444 
    3545            /// 
  • trunk/src/JobFind.cxx

    r154 r156  
    3333    m_FindPter = NULL; 
    3434    m_Results = NULL; 
     35    m_ResultsPage = 0; 
    3536    m_StartingPage = 0; 
    3637    m_TextToFind = g_strdup (""); 
     
    7576 
    7677gint 
     78JobFind::getResultsPage () 
     79{ 
     80    return m_ResultsPage; 
     81} 
     82 
     83gint 
    7784JobFind::getStartingPage (void) 
    7885{ 
     
    102109    if ( !canceled ) 
    103110    { 
    104         GList *result = getDocument ()->findTextInPage (getCurrentPage (), 
     111        gint currentPage = getCurrentPage (); 
     112        GList *result = getDocument ()->findTextInPage (currentPage, 
    105113                                                        getTextToFind ()); 
    106         gint nextPage = getCurrentPage () + 1; 
     114        gint nextPage = currentPage + 1; 
    107115        if ( nextPage > getDocument ()->getNumPages () ) 
    108116        { 
     
    114122        if ( NULL != result ) 
    115123        { 
    116             setResults (result); 
     124            setResults (currentPage, result); 
    117125            JOB_NOTIFIER (job_find_results, this); 
    118126        }         
     
    154162 
    155163void 
    156 JobFind::setResults (GList *results) 
     164JobFind::setResults (gint pageNum, GList *results) 
    157165{ 
    158166    g_assert (NULL != results && "Tried to set NULL results."); 
    159167 
    160168    m_Results = results; 
     169    m_ResultsPage = pageNum; 
    161170} 
    162171 
     
    197206 
    198207    JobFind *job = (JobFind *)data; 
     208    job->getFindPter ()->notifyFindResults (job->getResultsPage (), 
     209                                            job->getResults ()); 
    199210 
    200211    JOB_NOTIFIER_END (); 
  • trunk/src/JobFind.h

    r154 r156  
    3232            FindPter *getFindPter (void); 
    3333            GList *getResults (void); 
     34            gint getResultsPage (void); 
    3435            gint getStartingPage (void); 
    3536            const gchar *getTextToFind (void); 
     
    3940            void setDocument (IDocument *document); 
    4041            void setFindPter (FindPter *pter); 
    41             void setResults (GList *results); 
     42            void setResults (gint pageNum, GList *results); 
    4243            void setStartingPage (gint pageNum); 
    4344            void setTextToFind (const gchar *textToFind); 
     
    4950            FindPter *m_FindPter; 
    5051            GList *m_Results; 
     52            gint m_ResultsPage; 
    5153            gint m_StartingPage; 
    5254            gchar *m_TextToFind; 
  • trunk/tests/DumbDocumentObserver.cxx

    r154 r156  
    1919#include "DumbDocumentObserver.h" 
    2020 
     21G_LOCK_DEFINE_STATIC (Searching); 
     22 
    2123using namespace ePDFView; 
    2224 
     
    2628    m_CurrentPage = 0; 
    2729    m_Error = NULL; 
     30    m_FindMatchRect = NULL; 
    2831    m_NotifiedError = FALSE; 
    2932    m_NotifiedPassword = FALSE; 
     
    3235    m_NotifiedPageZoomed = FALSE; 
    3336    m_NotifiedReload = FALSE; 
     37    G_LOCK (Searching); 
    3438    m_Searching = FALSE; 
     39    G_UNLOCK (Searching); 
    3540    m_Zoom = 0.0; 
    3641} 
     
    4247 
    4348void 
     49DumbDocumentObserver::notifyFindChanged (DocumentRectangle *matchRect) 
     50{ 
     51    m_FindMatchRect = matchRect; 
     52    G_LOCK (Searching); 
     53    m_Searching = FALSE; 
     54    G_UNLOCK (Searching); 
     55} 
     56 
     57void 
    4458DumbDocumentObserver::notifyFindFinished () 
    4559{ 
     60    G_LOCK (Searching); 
    4661    m_Searching = FALSE; 
     62    G_UNLOCK (Searching); 
    4763} 
    4864 
     
    5066DumbDocumentObserver::notifyFindStarted () 
    5167{ 
     68    G_LOCK (Searching); 
    5269    m_Searching = TRUE; 
     70    G_UNLOCK (Searching); 
    5371} 
    5472 
     
    106124//////////////////////////////////////////////////////////////// 
    107125 
     126DocumentRectangle * 
     127DumbDocumentObserver::getFindMatchRect () 
     128{ 
     129    return m_FindMatchRect; 
     130} 
     131 
    108132gint 
    109133DumbDocumentObserver::getCurrentPage (void) 
     
    127151DumbDocumentObserver::isStillSearching (void) 
    128152{ 
    129     return m_Searching; 
     153    G_LOCK (Searching); 
     154    gboolean searching = m_Searching; 
     155    G_UNLOCK (Searching); 
     156    return searching; 
    130157} 
    131158 
  • trunk/tests/DumbDocumentObserver.h

    r154 r156  
    2727            ~DumbDocumentObserver (void); 
    2828 
     29            void notifyFindChanged (DocumentRectangle *matchRect); 
    2930            void notifyFindFinished (void); 
    3031            void notifyFindStarted (void); 
     
    4041            // Functions for test only purposes. 
    4142            gint getCurrentPage (void); 
     43            DocumentRectangle *getFindMatchRect (void); 
    4244            const GError *getLoadError (void); 
    4345            gdouble getZoom (void); 
     
    5456            gint m_CurrentPage; 
    5557            GError *m_Error; 
     58            DocumentRectangle *m_FindMatchRect; 
    5659            gboolean m_NotifiedError; 
    5760            gboolean m_NotifiedLoad; 
     
    6063            gboolean m_NotifiedPageZoomed; 
    6164            gboolean m_NotifiedReload; 
    62             gboolean m_Searching; 
     65            volatile gboolean m_Searching; 
    6366            gdouble m_Zoom; 
    6467    }; 
  • trunk/tests/FindPterTest.cxx

    r154 r156  
    6161    G_UNLOCK (JobRender); 
    6262 
    63     // Deleting the FindPter will also delete the DumbFindView. 
     63    // Deleting the FindPter will not delete the DumbFindView. 
    6464    delete m_FindPter; 
    6565    m_Document->detach (m_Observer); 
    6666    delete m_Observer; 
    6767    delete m_Document; 
     68    delete m_View; 
    6869} 
    6970 
     
    8485    CPPUNIT_ASSERT (!m_View->isFindPreviousSensitive ()); 
    8586 
    86     m_View->setTextToFind ("test"); 
     87    m_View->setTextToFind ("sensitivity"); 
    8788    CPPUNIT_ASSERT (m_View->isFindNextSensitive ()); 
    8889    CPPUNIT_ASSERT (m_View->isFindPreviousSensitive ()); 
     
    108109    CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("Not found!", infoText)); 
    109110} 
     111 
     112/// 
     113/// @brief Tests the Find Next button. 
     114/// 
     115/// When a search starts it tried to find the next text in the document. 
     116/// If the user presses the Find Next button, it will try to find the next 
     117/// found text in the document, searching forward. 
     118/// 
     119void 
     120FindPterTest::findNext () 
     121{ 
     122    m_View->setTextToFind ("first"); 
     123    while ( m_Observer->isStillSearching () ) { } 
     124     
     125    // The 'first' text appears twice in page 4 and also twice in 
     126    // page 5. So the first time it will set a rect on page 4. 
     127    CPPUNIT_ASSERT_EQUAL (4, m_Observer->getCurrentPage ()); 
     128    { 
     129        DocumentRectangle *rect = m_Observer->getFindMatchRect (); 
     130        CPPUNIT_ASSERT (NULL != rect); 
     131        CPPUNIT_ASSERT_DOUBLES_EQUAL (82.0000, rect->getX1 (), 0.0001); 
     132        CPPUNIT_ASSERT_DOUBLES_EQUAL (137.1100, rect->getY1 (), 0.0001); 
     133        CPPUNIT_ASSERT_DOUBLES_EQUAL (100.3400, rect->getX2 (), 0.0001); 
     134        CPPUNIT_ASSERT_DOUBLES_EQUAL (146.1100, rect->getY2 (), 0.0001); 
     135    } 
     136    
     137    m_Observer->notifyFindStarted (); 
     138    m_FindPter->findNextActivated (); 
     139    while ( m_Observer->isStillSearching () ) { } 
     140    CPPUNIT_ASSERT_EQUAL (4, m_Observer->getCurrentPage ()); 
     141    { 
     142        DocumentRectangle *rect = m_Observer->getFindMatchRect (); 
     143        CPPUNIT_ASSERT (NULL != rect); 
     144        CPPUNIT_ASSERT_DOUBLES_EQUAL (96.0000, rect->getX1 (), 0.0001); 
     145        CPPUNIT_ASSERT_DOUBLES_EQUAL (148.1100, rect->getY1 (), 0.0001); 
     146        CPPUNIT_ASSERT_DOUBLES_EQUAL (114.3400, rect->getX2 (), 0.0001); 
     147        CPPUNIT_ASSERT_DOUBLES_EQUAL (157.1100, rect->getY2 (), 0.0001); 
     148    } 
     149     
     150    m_Observer->notifyFindStarted (); 
     151    m_FindPter->findNextActivated (); 
     152    while ( m_Observer->isStillSearching () ) { } 
     153    CPPUNIT_ASSERT_EQUAL (5, m_Observer->getCurrentPage ()); 
     154    { 
     155        DocumentRectangle *rect = m_Observer->getFindMatchRect (); 
     156        CPPUNIT_ASSERT (NULL != rect); 
     157        CPPUNIT_ASSERT_DOUBLES_EQUAL (200.5943, rect->getX1 (), 0.0001); 
     158        CPPUNIT_ASSERT_DOUBLES_EQUAL (84.5980, rect->getY1 (), 0.0001); 
     159        CPPUNIT_ASSERT_DOUBLES_EQUAL (254.5158, rect->getX2 (), 0.0001); 
     160        CPPUNIT_ASSERT_DOUBLES_EQUAL (107.6147, rect->getY2 (), 0.0001); 
     161    } 
     162     
     163    m_Observer->notifyFindStarted (); 
     164    m_FindPter->findNextActivated (); 
     165    while ( m_Observer->isStillSearching () ) { } 
     166    CPPUNIT_ASSERT_EQUAL (5, m_Observer->getCurrentPage ()); 
     167    { 
     168        DocumentRectangle *rect = m_Observer->getFindMatchRect (); 
     169        CPPUNIT_ASSERT (NULL != rect); 
     170        CPPUNIT_ASSERT_DOUBLES_EQUAL (164.1700, rect->getX1 (), 0.0001); 
     171        CPPUNIT_ASSERT_DOUBLES_EQUAL (121.1020, rect->getY1 (), 0.0001); 
     172        CPPUNIT_ASSERT_DOUBLES_EQUAL (180.2800, rect->getX2 (), 0.0001); 
     173        CPPUNIT_ASSERT_DOUBLES_EQUAL (130.1020, rect->getY2 (), 0.0001); 
     174    } 
     175    
     176    m_Observer->notifyFindStarted (); 
     177    m_FindPter->findNextActivated (); 
     178    while ( m_Observer->isStillSearching () ) { } 
     179    CPPUNIT_ASSERT_EQUAL (5, m_Observer->getCurrentPage ()); 
     180    { 
     181        DocumentRectangle *rect = m_Observer->getFindMatchRect (); 
     182        CPPUNIT_ASSERT (NULL != rect); 
     183        CPPUNIT_ASSERT_DOUBLES_EQUAL (72.0000, rect->getX1 (), 0.0001); 
     184        CPPUNIT_ASSERT_DOUBLES_EQUAL (143.1745, rect->getY1 (), 0.0001); 
     185        CPPUNIT_ASSERT_DOUBLES_EQUAL (116.9349, rect->getX2 (), 0.0001); 
     186        CPPUNIT_ASSERT_DOUBLES_EQUAL (162.3553, rect->getY2 (), 0.0001); 
     187    } 
     188    
     189    // Clicking after the last result will start again. 
     190    m_Observer->notifyFindStarted (); 
     191    m_FindPter->findNextActivated (); 
     192    while ( m_Observer->isStillSearching () ) { } 
     193    CPPUNIT_ASSERT_EQUAL (4, m_Observer->getCurrentPage ()); 
     194    { 
     195        DocumentRectangle *rect = m_Observer->getFindMatchRect (); 
     196        CPPUNIT_ASSERT (NULL != rect); 
     197        CPPUNIT_ASSERT_DOUBLES_EQUAL (82.0000, rect->getX1 (), 0.0001); 
     198        CPPUNIT_ASSERT_DOUBLES_EQUAL (137.1100, rect->getY1 (), 0.0001); 
     199        CPPUNIT_ASSERT_DOUBLES_EQUAL (100.3400, rect->getX2 (), 0.0001); 
     200        CPPUNIT_ASSERT_DOUBLES_EQUAL (146.1100, rect->getY2 (), 0.0001); 
     201    } 
     202} 
  • trunk/tests/FindPterTest.h

    r154 r156  
    2828        CPPUNIT_TEST (viewSensitivity); 
    2929        CPPUNIT_TEST (textDoesNotExist); 
     30        CPPUNIT_TEST (findNext); 
    3031        CPPUNIT_TEST_SUITE_END (); 
    3132 
     
    3637            void viewSensitivity (void); 
    3738            void textDoesNotExist (void); 
     39            void findNext (void); 
    3840 
    3941        private: 
  • trunk/tests/Makefile.am

    r155 r156  
    2525    FindPterTest.h  \ 
    2626    main.cxx                \ 
    27     PDFDocumentTest.cxx \ 
    28     PDFDocumentTest.h   \ 
    2927    Utils.cxx               \ 
    3028    Utils.h 
     
    3432#   PagePterTest.cxx 
    3533#   PagePterTest.h 
     34#   PDFDocumentTest.cxx 
     35#   PDFDocumentTest.h 
    3636 
    3737test_epdfview_CXXFLAGS =                        \