Changeset 66

Show
Ignore:
Timestamp:
04/15/06 06:57:59 (2 years ago)
Author:
jordi
Message:

The main presenter shows the sidebar when the document has outlines. Also passes the outline to the view and accepts an activated outline to make change the page.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/IMainView.h

    r62 r66  
    264264 
    265265            /// 
     266            /// @brief Shows the sidebar. 
     267            /// 
     268            /// The presenter will call it just before to show the main window, 
     269            /// to let the view know if it must show the sidebar or not 
     270            /// when the main window will be displayed. 
     271            /// 
     272            /// After that, the presenter can call it to show or hide the 
     273            /// sidebar when the user toggles the "Show sidebar" option. 
     274            /// 
     275            /// @param show Set to TRUE if the sidebar should be shown. FALSE 
     276            ///             otherwise. 
     277            /// 
     278            virtual void showSidebar (gboolean show) = 0; 
     279 
     280            /// 
    266281            /// @brief Gives the number of pages that the document has. 
    267282            /// 
     
    324339            /// 
    325340            virtual void setTitle (const gchar *title) = 0; 
     341 
     342            /// 
     343            /// @brief Sets the document's outline. 
     344            /// 
     345            /// The presenter will call this function regardless if the 
     346            /// sidebar is shown or not. 
     347            /// 
     348            /// The view must make a tree view from the document's outline 
     349            /// and show it when the sidebar is shown. 
     350            /// 
     351            /// Also, when one of these outlines is activated (the user 
     352            /// clicks on one of them) the view must pass the pointer to the 
     353            /// activated outline when calling MainPter::outlineActivated(). 
     354            /// 
     355            /// @param outline The root outline to set. It can have no 
     356            ///                children. 
     357            /// 
     358            virtual void setOutline (DocumentOutline *outline) = 0; 
    326359 
    327360        protected: 
  • trunk/src/MainPter.cxx

    r65 r66  
    7676     
    7777    IMainView &view = getView (); 
     78    gboolean showSidebar = FALSE; 
    7879    if ( m_Document->isLoaded () ) 
    7980    { 
     
    9798        view.setTotalPages (m_Document->getNumPages ()); 
    9899 
     100        // Check if we should see the outlines. 
     101        showSidebar = (NULL != m_Document->getOutline () && 
     102                       0 < m_Document->getOutline ()->getNumChildren () && 
     103                       PageModeOutlines != m_Document->getPageMode ()); 
     104 
    99105        if ( canShowPage ) 
    100106        { 
     
    117123        view.sensitiveZoomFit (FALSE); 
    118124        view.sensitiveZoomWidth (FALSE); 
     125        showSidebar = FALSE; 
    119126    } 
    120      
     127    
     128    view.setOutline (m_Document->getOutline ()); 
     129    view.showSidebar (showSidebar); 
    121130    view.show ();  
    122131} 
     
    247256    openDocument (fileName, NULL, TRUE); 
    248257    g_free (fileName); 
     258} 
     259 
     260/// 
     261/// @brief The user activated an outline. 
     262/// 
     263/// When the sidebar is shown and the user clicks on a outline, the view 
     264/// should send to the presenter which outline has been activated, so the 
     265/// presenter can change the page to the pointed by the outline. 
     266/// 
     267/// @param outline The outline that has been activated. 
     268void 
     269MainPter::outlineActivated (DocumentOutline *outline) 
     270{ 
     271    g_assert (NULL != outline && "The outline activated is NULL."); 
     272     
     273    m_Document->goToPage (outline->getDestinationPage ()); 
     274    showPage (); 
    249275} 
    250276 
  • trunk/src/MainPter.h

    r65 r66  
    5151            void goToPreviousPageActivated (void); 
    5252            void openFileActivated (void); 
     53            void outlineActivated (DocumentOutline *outline); 
    5354            void reloadActivated (void); 
    5455            void rotateLeftActivated (void); 
  • trunk/tests/DumbDocument.cxx

    r65 r66  
    105105 
    106106void 
     107DumbDocument::setOutline (DocumentOutline *outline) 
     108{ 
     109    m_Outline = outline; 
     110} 
     111 
     112void 
    107113DumbDocument::setTestPassword (const gchar *password) 
    108114{ 
  • trunk/tests/DumbDocument.h

    r65 r66  
    3636            // Test functions. 
    3737            void setOpenError (DocumentError error); 
     38            void setOutline (DocumentOutline *outline); 
    3839            void setTestPassword (const gchar *password); 
    3940 
  • trunk/tests/DumbMainView.cxx

    r62 r66  
    3232    m_GoToPageText = g_strdup (""); 
    3333    m_OpenFileName = g_strdup (""); 
     34    m_Outline = NULL; 
    3435    m_Password = NULL; 
    3536    m_SensitiveGoToFirstPage = TRUE; 
     
    4748    m_Shown = FALSE; 
    4849    m_ShownError = FALSE; 
     50    m_ShownSidebar = FALSE; 
    4951    m_Title = g_strdup (""); 
    5052    m_TimesShownPassword = 0; 
     
    180182 
    181183void 
     184DumbMainView::setOutline (DocumentOutline *outline) 
     185{ 
     186    m_Outline = outline; 
     187} 
     188 
     189void 
    182190DumbMainView::show (void) 
    183191{ 
     
    195203{ 
    196204    m_DocumentPage = page; 
     205} 
     206 
     207void 
     208DumbMainView::showSidebar (gboolean show) 
     209{ 
     210    m_ShownSidebar = show; 
    197211} 
    198212 
     
    213227} 
    214228 
     229DocumentOutline * 
     230DumbMainView::getOutline () 
     231{ 
     232    return m_Outline; 
     233} 
     234 
    215235gint 
    216236DumbMainView::getTotalPages () 
     
    229249} 
    230250 
    231 gboolean 
    232 DumbMainView::isShown () 
    233 { 
    234     return m_Shown; 
    235 } 
    236  
    237251const gchar * 
    238252DumbMainView::getTitle () 
     
    311325{ 
    312326    return m_SensitiveZoomWidth; 
     327} 
     328 
     329gboolean 
     330DumbMainView::isShown () 
     331{ 
     332    return m_Shown; 
     333} 
     334 
     335gboolean 
     336DumbMainView::isShownSidebar () 
     337{ 
     338    return m_ShownSidebar; 
    313339} 
    314340 
  • trunk/tests/DumbMainView.h

    r62 r66  
    4747            void setGoToPageText (const char *text); 
    4848            void setTitle (const gchar *title); 
     49            void setOutline (DocumentOutline *outline); 
    4950            void show (void); 
    5051            void showErrorMessage (const gchar *title, const gchar *body); 
    5152            void showPage (DocumentPage *page); 
     53            void showSidebar (gboolean show); 
    5254 
    5355            // Methods for test purposes. 
    5456            gint countTimesShownPasswordPrompt (void); 
    55             gint getCurrentPage (void);             
     57            gint getCurrentPage (void); 
     58            DocumentOutline *getOutline (void); 
    5659            const gchar *getTitle (void); 
    5760            gint getTotalPages (void); 
     
    7073            gboolean isSensitiveZoomFit (void); 
    7174            gboolean isSensitiveZoomWidth (void); 
     75            gboolean isShownSidebar (void); 
    7276            void setOpenFileName (const gchar *fileName); 
    7377            void setPassword (const gchar *password); 
     
    7983            gchar *m_GoToPageText; 
    8084            gchar *m_OpenFileName; 
     85            DocumentOutline *m_Outline; 
    8186            gchar *m_Password; 
    8287            gboolean m_SensitiveGoToFirstPage; 
     
    9499            gboolean m_Shown; 
    95100            gboolean m_ShownError; 
     101            gboolean m_ShownSidebar; 
    96102            gint m_TimesShownPassword; 
    97103            gchar *m_Title; 
  • trunk/tests/MainPterTest.cxx

    r65 r66  
    5656/// the main window's title is 'PDF Viewer', the page selection  
    5757/// and zoom actions are unsensitived and the documentView has 
    58 /// no image yet. 
     58/// no image yet. Also the side bar won't be displayed, yet. 
    5959/// 
    6060void 
     
    7676    CPPUNIT_ASSERT (!m_View->isSensitiveZoomFit ()); 
    7777    CPPUNIT_ASSERT (!m_View->isSensitiveZoomWidth ()); 
     78    CPPUNIT_ASSERT (!m_View->isShownSidebar ()); 
    7879    CPPUNIT_ASSERT (!m_View->hasImagePageView ()); 
    7980} 
     
    8586/// document's file name, if it has no title. Also will sensitive the 
    8687/// go to next page, go to last page and all zoom actions. Also will 
    87 /// show the document's first page. 
     88/// show the document's first page. Since this document don't have 
     89/// outline, the sidebar won't be displayed. 
    8890/// 
    8991void 
     
    106108    CPPUNIT_ASSERT (m_View->isSensitiveZoomFit ()); 
    107109    CPPUNIT_ASSERT (m_View->isSensitiveZoomWidth ()); 
     110    CPPUNIT_ASSERT (!m_View->isShownSidebar ()); 
    108111    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    109112 
     
    125128    CPPUNIT_ASSERT (m_View->isSensitiveZoomFit ()); 
    126129    CPPUNIT_ASSERT (m_View->isSensitiveZoomWidth ()); 
     130    CPPUNIT_ASSERT (!m_View->isShownSidebar ()); 
    127131    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
    128132} 
     
    661665    CPPUNIT_ASSERT_EQUAL (1, m_View->countTimesShownPasswordPrompt ()); 
    662666} 
     667 
     668/// 
     669/// @brief Checks that the sidebar is shown when a document has outline. 
     670///  
     671/// From now, the sidebar is shown only for the outline (no thumbnails), 
     672/// so if a document has outline the sidebar should be shown with it. 
     673/// 
     674/// When the presenter needs to show the outline, it just passes the root 
     675/// outline item to the view, and the view must then render it whatever it 
     676/// can (a GtkTreeView in GTK, etc...) 
     677/// 
     678void 
     679MainPterTest::showSidebar () 
     680{ 
     681    DocumentOutline *outline = new DocumentOutline (); 
     682    DocumentOutline *child = new DocumentOutline (); 
     683    child->setParent (outline); 
     684    child->setTitle ("Outline 1"); 
     685    child->setDestination (2); 
     686    outline->addChild (child); 
     687    m_Document->setOutline (outline);     
     688    m_Document->setNumPages (4); 
     689     
     690    m_View->setOpenFileName ("/tmp/test.pdf"); 
     691    m_MainPter->openFileActivated (); 
     692    CPPUNIT_ASSERT (m_View->isShownSidebar ()); 
     693    CPPUNIT_ASSERT (outline == m_View->getOutline ()); 
     694    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     695 
     696    // When the user does click on a outline item, the view 
     697    // sends to the presenter the outline that has been activated. 
     698    // Then the presenter goes to that page. 
     699    m_MainPter->outlineActivated (child); 
     700    CPPUNIT_ASSERT_EQUAL (2, m_View->getCurrentPage ()); 
     701    CPPUNIT_ASSERT (m_View->hasImagePageView ()); 
     702} 
  • trunk/tests/MainPterTest.h

    r65 r66  
    4040        CPPUNIT_TEST (reloadEncrypted); 
    4141        CPPUNIT_TEST (reloadChangedPassword); 
     42        CPPUNIT_TEST (showSidebar); 
    4243        CPPUNIT_TEST_SUITE_END(); 
    4344 
     
    6061            void reloadEncrypted (void); 
    6162            void reloadChangedPassword (void); 
     63            void showSidebar (void); 
    6264 
    6365        private: