Changeset 128

Show
Ignore:
Timestamp:
04/29/06 03:33:17 (2 years ago)
Author:
jordi
Message:

Now when the page number changes, the observers are informed. Also, when the page is the same it doesn't "change" (doesn't notify). If the page to go is outside the range, the document class then just ignores it.

Location:
trunk
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/IDocument.cxx

    r126 r128  
    285285 
    286286void 
     287IDocument::notifyPageChanged () 
     288{ 
     289    gint pageNum = getCurrentPageNum (); 
     290    for ( GList *item = g_list_first (m_Observers) ; NULL != item ; 
     291          item = g_list_next (item) ) 
     292    { 
     293        IDocumentObserver *observer = (IDocumentObserver *)item->data; 
     294        observer->notifyPageChanged (pageNum); 
     295    } 
     296} 
     297 
     298void 
    287299IDocument::load (const gchar *fileName, const gchar *password) 
    288300{ 
     301    m_CurrentPage = 1; 
     302    m_Rotation = 0; 
     303    m_Scale = 1.0f; 
     304     
    289305    JobLoad *job = new JobLoad (); 
    290306    job->setDocument (this); 
     
    850866IDocument::goToPage (gint pageNum) 
    851867{ 
    852     m_CurrentPage = CLAMP (pageNum, 1, getNumPages ()); 
    853  
    854     scheduleToRender (m_CurrentPage); 
    855     if ( 1 < m_CurrentPage ) 
    856     { 
    857         scheduleToRender (m_CurrentPage - 1); 
    858     } 
    859     if ( m_CurrentPage < getNumPages () ) 
    860     { 
    861         scheduleToRender (m_CurrentPage + 1); 
     868    if ( pageNum != m_CurrentPage && 1 <= pageNum && pageNum <= getNumPages ()) 
     869    { 
     870        m_CurrentPage = pageNum; 
     871         
     872        scheduleToRender (m_CurrentPage); 
     873        if ( 1 < m_CurrentPage ) 
     874        { 
     875            scheduleToRender (m_CurrentPage - 1); 
     876        } 
     877        if ( m_CurrentPage < getNumPages () ) 
     878        { 
     879            scheduleToRender (m_CurrentPage + 1); 
     880        } 
     881 
     882        notifyPageChanged (); 
    862883    } 
    863884} 
  • trunk/src/IDocument.h

    r126 r128  
    180180            void notifyLoadError (const GError *error); 
    181181            void notifyLoadPassword (const GError *error); 
     182            void notifyPageChanged (void); 
    182183             
    183184            const gchar *getTitle (void); 
  • trunk/src/IDocumentObserver.h

    r126 r128  
    2929            virtual void notifyLoadError (const GError *error) { } 
    3030            virtual void notifyLoadPassword (const GError *error) { } 
     31            virtual void notifyPageChanged (gint pageNum) { } 
    3132 
    3233        protected: 
  • trunk/src/PDFDocument.cxx

    r121 r128  
    144144    m_Outline = new DocumentOutline (); 
    145145    setOutline (m_Outline, outline); 
    146     // Set the current rotation angle and zoom level. 
    147     setRotation (0); 
    148     setZoom (1.0f); 
    149146 
    150147    return TRUE; 
     
    234231    // Get the number of pages and set the current to the first. 
    235232    setNumPages (poppler_document_get_n_pages (m_Document)); 
    236     goToFirstPage (); 
    237233} 
    238234 
  • trunk/tests/DumbDocument.cxx

    r122 r128  
    7070        m_Loaded = FALSE; 
    7171    } 
    72     setRotation (0); 
    73     setZoom (1.0f); 
    7472    return m_Loaded; 
    7573} 
  • trunk/tests/DumbDocumentObserver.cxx

    r126 r128  
    2424    IDocumentObserver () 
    2525{ 
     26    m_CurrentPage = 0; 
    2627    m_Error = NULL; 
    2728    m_NotifiedError = FALSE; 
     
    3940{ 
    4041    m_NotifiedLoad = TRUE; 
     42    m_CurrentPage = 1; 
    4143} 
    4244 
     
    5557} 
    5658 
     59void 
     60DumbDocumentObserver::notifyPageChanged (gint pageNum) 
     61{ 
     62    m_CurrentPage = pageNum; 
     63} 
     64 
    5765//////////////////////////////////////////////////////////////// 
    5866// Test purposes methods. 
     
    6270DumbDocumentObserver::getCurrentPage (void) 
    6371{ 
    64     return 0; 
     72    return m_CurrentPage; 
    6573} 
    6674 
  • trunk/tests/DumbDocumentObserver.h

    r126 r128  
    3030            void notifyLoadError (const GError *error); 
    3131            void notifyLoadPassword (const GError *error); 
     32            void notifyPageChanged (gint pageNum); 
    3233 
    3334            gint getCurrentPage (void); 
     
    4344 
    4445        protected: 
     46            gint m_CurrentPage; 
    4547            GError *m_Error; 
    4648            gboolean m_NotifiedError; 
  • trunk/tests/PDFDocumentTest.cxx

    r127 r128  
    308308} 
    309309 
    310 /* 
    311310/// 
    312311/// @brief Test changing pages. 
     
    321320    // First try with a 2 page document. 
    322321    gchar *testFile = getTestFile ("test2.pdf"); 
    323     CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 
     322    m_Document->load (testFile, NULL); 
    324323    while ( !m_Observer->loadFinished () ) { } 
    325324    CPPUNIT_ASSERT (m_Observer->notifiedLoaded ()); 
     
    368367    g_free (testFile); 
    369368    testFile = getTestFile ("test1.pdf"); 
    370     CPPUNIT_ASSERT (m_Document->loadFile (testFile, NULL, NULL)); 
     369    m_Document->load (testFile, NULL); 
    371370    while ( !m_Observer->loadFinished () ) { } 
    372371    CPPUNIT_ASSERT (m_Observer->notifiedLoaded ()); 
     
    427426    g_free (testFile); 
    428427} 
    429  
     428/* 
    430429/// 
    431430/// @brief Test rotating a page. 
  • trunk/tests/PDFDocumentTest.h

    r127 r128  
    3232        CPPUNIT_TEST (validFile); 
    3333        CPPUNIT_TEST (relativePath); 
    34 /*        CPPUNIT_TEST (pageChange); 
    35         CPPUNIT_TEST (pageRotate); 
     34        CPPUNIT_TEST (pageChange); 
     35/*        CPPUNIT_TEST (pageRotate); 
    3636        CPPUNIT_TEST (pageZoom); 
    3737        CPPUNIT_TEST (pageRender);*/