Changeset 156
- Timestamp:
- 05/09/06 11:15:14 (2 years ago)
- Location:
- trunk
- Files:
-
- 12 modified
-
src/FindPter.cxx (modified) (4 diffs)
-
src/FindPter.h (modified) (1 diff)
-
src/IDocument.cxx (modified) (1 diff)
-
src/IDocument.h (modified) (1 diff)
-
src/IDocumentObserver.h (modified) (1 diff)
-
src/JobFind.cxx (modified) (6 diffs)
-
src/JobFind.h (modified) (3 diffs)
-
tests/DumbDocumentObserver.cxx (modified) (7 diffs)
-
tests/DumbDocumentObserver.h (modified) (4 diffs)
-
tests/FindPterTest.cxx (modified) (3 diffs)
-
tests/FindPterTest.h (modified) (2 diffs)
-
tests/Makefile.am (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/FindPter.cxx
r154 r156 28 28 { 29 29 g_assert (NULL != document && "Tried to set a NULL document."); 30 30 31 m_CurrentMatch = NULL; 31 32 m_Document = document; 33 m_FindPage = 0; 34 m_FindResults = NULL; 32 35 m_Job = NULL; 33 36 m_View = NULL; … … 38 41 /// 39 42 FindPter::~FindPter () 40 { 43 { 41 44 m_Document = NULL; 42 45 if ( NULL != m_Job ) … … 44 47 m_Job->cancel (); 45 48 } 46 delete m_View; 49 freeFindResults (); 50 } 51 52 /// 53 /// @brief The Find Next button has been clicked. 54 /// 55 void 56 FindPter::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 71 void 72 FindPter::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; 47 82 } 48 83 … … 67 102 m_View->setInformationText (_("Not Found!")); 68 103 m_Document->notifyFindFinished (); 104 } 105 106 void 107 FindPter::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); 69 116 } 70 117 -
trunk/src/FindPter.h
r154 r156 37 37 ~FindPter (void); 38 38 39 void findNextActivated (void); 39 40 IFindView &getView (void); 40 41 void notifyFindFinished (void); 42 void notifyFindResults (gint pageNum, GList *results); 41 43 void setView (IFindView *view); 42 44 void textToFindChanged (void); 43 45 44 46 protected: 47 /// The current selected match from m_FindResults. 48 GList *m_CurrentMatch; 45 49 /// The document to search to. 46 50 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; 47 55 /// The current find job. 48 56 JobFind *m_Job; 49 57 /// The view that the presenter is controlling. 50 58 IFindView *m_View; 59 60 void freeFindResults (void); 51 61 }; 52 62 } -
trunk/src/IDocument.cxx
r154 r156 203 203 204 204 void 205 IDocument::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 215 void 205 216 IDocument::notifyFindFinished () 206 217 { -
trunk/src/IDocument.h
r154 r156 204 204 void detach (const IDocumentObserver *observer); 205 205 206 void notifyFindChanged (DocumentRectangle *matchRect); 206 207 void notifyFindFinished (void); 207 208 void notifyFindStarted (void); -
trunk/src/IDocumentObserver.h
r154 r156 32 32 /// @brief Destroys all dynamically allocated memory. 33 33 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) { } 34 44 35 45 /// -
trunk/src/JobFind.cxx
r154 r156 33 33 m_FindPter = NULL; 34 34 m_Results = NULL; 35 m_ResultsPage = 0; 35 36 m_StartingPage = 0; 36 37 m_TextToFind = g_strdup (""); … … 75 76 76 77 gint 78 JobFind::getResultsPage () 79 { 80 return m_ResultsPage; 81 } 82 83 gint 77 84 JobFind::getStartingPage (void) 78 85 { … … 102 109 if ( !canceled ) 103 110 { 104 GList *result = getDocument ()->findTextInPage (getCurrentPage (), 111 gint currentPage = getCurrentPage (); 112 GList *result = getDocument ()->findTextInPage (currentPage, 105 113 getTextToFind ()); 106 gint nextPage = getCurrentPage ()+ 1;114 gint nextPage = currentPage + 1; 107 115 if ( nextPage > getDocument ()->getNumPages () ) 108 116 { … … 114 122 if ( NULL != result ) 115 123 { 116 setResults ( result);124 setResults (currentPage, result); 117 125 JOB_NOTIFIER (job_find_results, this); 118 126 } … … 154 162 155 163 void 156 JobFind::setResults ( GList *results)164 JobFind::setResults (gint pageNum, GList *results) 157 165 { 158 166 g_assert (NULL != results && "Tried to set NULL results."); 159 167 160 168 m_Results = results; 169 m_ResultsPage = pageNum; 161 170 } 162 171 … … 197 206 198 207 JobFind *job = (JobFind *)data; 208 job->getFindPter ()->notifyFindResults (job->getResultsPage (), 209 job->getResults ()); 199 210 200 211 JOB_NOTIFIER_END (); -
trunk/src/JobFind.h
r154 r156 32 32 FindPter *getFindPter (void); 33 33 GList *getResults (void); 34 gint getResultsPage (void); 34 35 gint getStartingPage (void); 35 36 const gchar *getTextToFind (void); … … 39 40 void setDocument (IDocument *document); 40 41 void setFindPter (FindPter *pter); 41 void setResults ( GList *results);42 void setResults (gint pageNum, GList *results); 42 43 void setStartingPage (gint pageNum); 43 44 void setTextToFind (const gchar *textToFind); … … 49 50 FindPter *m_FindPter; 50 51 GList *m_Results; 52 gint m_ResultsPage; 51 53 gint m_StartingPage; 52 54 gchar *m_TextToFind; -
trunk/tests/DumbDocumentObserver.cxx
r154 r156 19 19 #include "DumbDocumentObserver.h" 20 20 21 G_LOCK_DEFINE_STATIC (Searching); 22 21 23 using namespace ePDFView; 22 24 … … 26 28 m_CurrentPage = 0; 27 29 m_Error = NULL; 30 m_FindMatchRect = NULL; 28 31 m_NotifiedError = FALSE; 29 32 m_NotifiedPassword = FALSE; … … 32 35 m_NotifiedPageZoomed = FALSE; 33 36 m_NotifiedReload = FALSE; 37 G_LOCK (Searching); 34 38 m_Searching = FALSE; 39 G_UNLOCK (Searching); 35 40 m_Zoom = 0.0; 36 41 } … … 42 47 43 48 void 49 DumbDocumentObserver::notifyFindChanged (DocumentRectangle *matchRect) 50 { 51 m_FindMatchRect = matchRect; 52 G_LOCK (Searching); 53 m_Searching = FALSE; 54 G_UNLOCK (Searching); 55 } 56 57 void 44 58 DumbDocumentObserver::notifyFindFinished () 45 59 { 60 G_LOCK (Searching); 46 61 m_Searching = FALSE; 62 G_UNLOCK (Searching); 47 63 } 48 64 … … 50 66 DumbDocumentObserver::notifyFindStarted () 51 67 { 68 G_LOCK (Searching); 52 69 m_Searching = TRUE; 70 G_UNLOCK (Searching); 53 71 } 54 72 … … 106 124 //////////////////////////////////////////////////////////////// 107 125 126 DocumentRectangle * 127 DumbDocumentObserver::getFindMatchRect () 128 { 129 return m_FindMatchRect; 130 } 131 108 132 gint 109 133 DumbDocumentObserver::getCurrentPage (void) … … 127 151 DumbDocumentObserver::isStillSearching (void) 128 152 { 129 return m_Searching; 153 G_LOCK (Searching); 154 gboolean searching = m_Searching; 155 G_UNLOCK (Searching); 156 return searching; 130 157 } 131 158 -
trunk/tests/DumbDocumentObserver.h
r154 r156 27 27 ~DumbDocumentObserver (void); 28 28 29 void notifyFindChanged (DocumentRectangle *matchRect); 29 30 void notifyFindFinished (void); 30 31 void notifyFindStarted (void); … … 40 41 // Functions for test only purposes. 41 42 gint getCurrentPage (void); 43 DocumentRectangle *getFindMatchRect (void); 42 44 const GError *getLoadError (void); 43 45 gdouble getZoom (void); … … 54 56 gint m_CurrentPage; 55 57 GError *m_Error; 58 DocumentRectangle *m_FindMatchRect; 56 59 gboolean m_NotifiedError; 57 60 gboolean m_NotifiedLoad; … … 60 63 gboolean m_NotifiedPageZoomed; 61 64 gboolean m_NotifiedReload; 62 gboolean m_Searching;65 volatile gboolean m_Searching; 63 66 gdouble m_Zoom; 64 67 }; -
trunk/tests/FindPterTest.cxx
r154 r156 61 61 G_UNLOCK (JobRender); 62 62 63 // Deleting the FindPter will alsodelete the DumbFindView.63 // Deleting the FindPter will not delete the DumbFindView. 64 64 delete m_FindPter; 65 65 m_Document->detach (m_Observer); 66 66 delete m_Observer; 67 67 delete m_Document; 68 delete m_View; 68 69 } 69 70 … … 84 85 CPPUNIT_ASSERT (!m_View->isFindPreviousSensitive ()); 85 86 86 m_View->setTextToFind (" test");87 m_View->setTextToFind ("sensitivity"); 87 88 CPPUNIT_ASSERT (m_View->isFindNextSensitive ()); 88 89 CPPUNIT_ASSERT (m_View->isFindPreviousSensitive ()); … … 108 109 CPPUNIT_ASSERT_EQUAL (0, g_ascii_strcasecmp ("Not found!", infoText)); 109 110 } 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 /// 119 void 120 FindPterTest::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 28 28 CPPUNIT_TEST (viewSensitivity); 29 29 CPPUNIT_TEST (textDoesNotExist); 30 CPPUNIT_TEST (findNext); 30 31 CPPUNIT_TEST_SUITE_END (); 31 32 … … 36 37 void viewSensitivity (void); 37 38 void textDoesNotExist (void); 39 void findNext (void); 38 40 39 41 private: -
trunk/tests/Makefile.am
r155 r156 25 25 FindPterTest.h \ 26 26 main.cxx \ 27 PDFDocumentTest.cxx \28 PDFDocumentTest.h \29 27 Utils.cxx \ 30 28 Utils.h … … 34 32 # PagePterTest.cxx 35 33 # PagePterTest.h 34 # PDFDocumentTest.cxx 35 # PDFDocumentTest.h 36 36 37 37 test_epdfview_CXXFLAGS = \
