Changeset 67

Show
Ignore:
Timestamp:
04/15/06 10:40:50 (3 years ago)
Author:
jordi
Message:

Added support for named destinations for PDF outlines.
Now the view shows the links sidebar and allows to go to where they point if you double click on them...

Location:
trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/IMainView.h

    r66 r67  
    2525    class MainPter; 
    2626    class DocumentPage; 
     27    class DocumentOutline; 
    2728 
    2829    /// 
  • trunk/src/MainPter.cxx

    r66 r67  
    101101        showSidebar = (NULL != m_Document->getOutline () && 
    102102                       0 < m_Document->getOutline ()->getNumChildren () && 
    103                        PageModeOutlines != m_Document->getPageMode ()); 
     103                       PageModeOutlines == m_Document->getPageMode ()); 
    104104 
    105105        if ( canShowPage ) 
  • trunk/src/PDFDocument.cxx

    r65 r67  
    246246            gint destination = 1; 
    247247            LinkAction *action = item->getAction (); 
    248             if ( NULL != action && action->isOk () &&  
    249                  actionGoTo == action->getKind () )  
    250             { 
    251                 LinkDest *linkDestination = ((LinkGoTo *)action)->getDest (); 
    252                 if ( linkDestination->isOk () ) 
     248            if ( NULL != action && actionGoTo == action->getKind () && 
     249                 action->isOk () ) 
     250            { 
     251                LinkDest *linkDestination = NULL; 
     252                GooString *namedDest = ((LinkGoTo *)action)->getNamedDest (); 
     253                // getNamedDest() or getDest() will return NULL, just need to 
     254                // find which one. 
     255                if ( NULL != namedDest ) 
     256                { 
     257                    linkDestination = m_Document->findDest (namedDest); 
     258                } 
     259                else 
     260                { 
     261                    linkDestination = ((LinkGoTo *)action)->getDest (); 
     262                } 
     263                if ( NULL != linkDestination && linkDestination->isOk () ) 
    253264                { 
    254265                    if ( linkDestination->isPageRef () ) 
  • trunk/src/gtk/MainView.cxx

    r64 r67  
    2121#include <gettext.h> 
    2222#include <gtk/gtk.h> 
    23 #include <IMainView.h> 
    24 #include <MainPter.h> 
    25 #include <DocumentPage.h> 
     23#include <epdfview.h> 
    2624#include "StockIcons.h" 
    2725#include "MainView.h" 
     
    4543static void main_window_rotate_right_cb (GtkWidget *, gpointer); 
    4644static void main_window_open_file_cb (GtkWidget *, gpointer); 
     45static void main_window_outline_cb (GtkTreeView *, GtkTreePath *,  
     46                                    GtkTreeViewColumn *, gpointer); 
    4747static void main_window_quit_cb (GtkWidget *, gpointer); 
    4848static void main_window_zoom_fit_cb (GtkWidget *, gpointer); 
     
    134134    m_MainBox = gtk_vbox_new (FALSE, 0); 
    135135    gtk_container_add (GTK_CONTAINER (m_MainWindow), m_MainBox); 
     136    gtk_widget_show (m_MainBox); 
    136137    // Generate menu and tool bars. 
    137138    createUIManager (); 
     
    142143    GtkWidget *menuBar = gtk_ui_manager_get_widget (m_UIManager, "/MenuBar"); 
    143144    gtk_box_pack_start (GTK_BOX (m_MainBox), menuBar, FALSE, FALSE, 0); 
     145    gtk_widget_show (menuBar); 
    144146    GtkWidget *toolBar = gtk_ui_manager_get_widget (m_UIManager, "/ToolBar"); 
    145147    gtk_box_pack_start (GTK_BOX (m_MainBox), toolBar, FALSE, FALSE, 0); 
     148    gtk_widget_show (toolBar); 
    146149    // Add the current page tool item. 
    147150    createCurrentPage (); 
    148151    gtk_toolbar_insert (GTK_TOOLBAR (toolBar), m_CurrentPageToolItem, 
    149152                        CURRENT_PAGE_POS); 
     153    gtk_widget_show_all (GTK_WIDGET (m_CurrentPageToolItem)); 
    150154    gtk_toolbar_insert (GTK_TOOLBAR (toolBar), gtk_separator_tool_item_new (), 
    151155                        CURRENT_PAGE_POS + 1); 
    152156    // Create the page view 
    153     createPageView (); 
    154     gtk_box_pack_start (GTK_BOX (m_MainBox), m_PageViewScroll, TRUE, TRUE, 0); 
     157    GtkWidget *pageViewPaned = createPageView (); 
     158    gtk_box_pack_start (GTK_BOX (m_MainBox), pageViewPaned, TRUE, TRUE, 0); 
     159    gtk_widget_show (pageViewPaned); 
    155160 
    156161    // The status bar don't do anything, yet. But without the application 
     
    158163    GtkWidget *statusBar = gtk_statusbar_new (); 
    159164    gtk_box_pack_start (GTK_BOX (m_MainBox), statusBar, FALSE, FALSE, 0); 
     165    gtk_widget_show (statusBar); 
    160166} 
    161167 
     
    336342void  
    337343MainView::show (void) 
    338 { 
    339     gtk_widget_show_all (m_MainWindow); 
     344{     
     345    gtk_widget_show (m_MainWindow); 
    340346    gtk_window_maximize (GTK_WINDOW (m_MainWindow)); 
    341347} 
     
    365371} 
    366372 
     373void 
     374MainView::showSidebar (gboolean show) 
     375{ 
     376    if ( show ) 
     377    { 
     378        gtk_widget_show_all (m_Sidebar); 
     379    } 
     380    else 
     381    { 
     382        gtk_widget_hide (m_Sidebar); 
     383    } 
     384} 
     385 
    367386void  
    368387MainView::setTotalPages (gint pages) 
     
    402421} 
    403422 
     423void 
     424MainView::setOutline (DocumentOutline *outline) 
     425{ 
     426    gtk_tree_store_clear (m_Outline); 
     427    setOutlineChildren (outline, NULL); 
     428} 
     429 
    404430//////////////////////////////////////////////////////////////// 
    405431// GTK+ Functions. 
     
    433459/// @brief Creates the widget that will display the page. 
    434460/// 
    435 void 
     461/// Creates the image widget inside the scrolled window, but also creates 
     462/// the sidebar. 
     463/// 
     464/// Put both the sidebar and the image to a HPaned container. 
     465/// 
     466/// @return The HPaned where the sidebar and the scrolled window are. 
     467/// 
     468GtkWidget * 
    436469MainView::createPageView () 
    437470{ 
     471    // Create the image view. 
    438472    m_PageViewScroll = gtk_scrolled_window_new (NULL, NULL); 
    439473    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_PageViewScroll), 
     
    445479    gtk_scrolled_window_add_with_viewport ( 
    446480            GTK_SCROLLED_WINDOW (m_PageViewScroll), m_PageView); 
     481 
     482    // Create the side bar, with the outline tree. 
     483    m_Outline = gtk_tree_store_new (3, G_TYPE_STRING, G_TYPE_INT,  
     484                                       G_TYPE_POINTER); 
     485    GtkWidget *treeIndex =  
     486        gtk_tree_view_new_with_model (GTK_TREE_MODEL (m_Outline)); 
     487    gtk_widget_set_size_request (treeIndex, 200, -1); 
     488 
     489    GtkTreeViewColumn *column = gtk_tree_view_column_new (); 
     490    gtk_tree_view_column_set_expand (column, TRUE); 
     491    gtk_tree_view_column_set_title (column, _("Index")); 
     492    gtk_tree_view_append_column (GTK_TREE_VIEW (treeIndex), column); 
     493    
     494    { 
     495        GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); 
     496        GValue ellipsizeMode = { 0, }; 
     497        g_value_init (&ellipsizeMode, PANGO_TYPE_ELLIPSIZE_MODE); 
     498        g_value_set_enum (&ellipsizeMode, PANGO_ELLIPSIZE_END); 
     499        g_object_set_property (G_OBJECT (renderer), 
     500                               "ellipsize", &ellipsizeMode); 
     501        gtk_tree_view_column_pack_start (column, renderer, TRUE); 
     502        gtk_tree_view_column_set_attributes (column, renderer, "text", 0, NULL); 
     503    } 
     504             
     505    { 
     506        GtkCellRenderer *renderer = gtk_cell_renderer_text_new (); 
     507        gtk_tree_view_column_pack_end (column, renderer, FALSE); 
     508        gtk_tree_view_column_set_attributes (column, renderer, "text", 1, NULL); 
     509    } 
     510    // Set not selection for the tree index. 
     511    GtkTreeSelection *selection =  
     512        gtk_tree_view_get_selection (GTK_TREE_VIEW (treeIndex)); 
     513    gtk_tree_selection_set_mode (selection, GTK_SELECTION_NONE); 
     514    g_signal_connect (G_OBJECT (treeIndex), "row-activated", 
     515                      G_CALLBACK (main_window_outline_cb), m_Pter); 
     516 
     517    m_Sidebar = gtk_scrolled_window_new (NULL, NULL); 
     518    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_Sidebar), 
     519                                    GTK_POLICY_AUTOMATIC, 
     520                                    GTK_POLICY_AUTOMATIC); 
     521    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (m_Sidebar), 
     522                                         GTK_SHADOW_IN); 
     523    gtk_container_add (GTK_CONTAINER (m_Sidebar), treeIndex); 
     524 
     525 
     526    GtkWidget *hPaned = gtk_hpaned_new (); 
     527    gtk_paned_add1 (GTK_PANED (hPaned), m_Sidebar); 
     528    gtk_paned_add2 (GTK_PANED (hPaned), m_PageViewScroll); 
     529    gtk_widget_show_all (m_PageViewScroll); 
     530    gtk_widget_show (hPaned); 
     531 
     532    return hPaned; 
    447533} 
    448534 
     
    533619    g_list_foreach (iconList, (GFunc)g_object_unref, NULL); 
    534620    g_list_free (iconList); 
     621} 
     622 
     623 
     624void 
     625MainView::setOutlineChildren (DocumentOutline *outline, GtkTreeIter *rootIter) 
     626{ 
     627    if ( NULL != outline ) 
     628    {         
     629        DocumentOutline *child = outline->getFirstChild (); 
     630        while (NULL != child) 
     631        { 
     632            GtkTreeIter childIter;             
     633            gtk_tree_store_append (m_Outline, &childIter, rootIter); 
     634            gtk_tree_store_set (m_Outline, &childIter, 
     635                                0, child->getTitle (), 
     636                                1, child->getDestinationPage (), 
     637                                2, child, 
     638                                -1); 
     639            setOutlineChildren (child, &childIter); 
     640            child = outline->getNextChild (); 
     641        } 
     642    } 
    535643} 
    536644 
     
    690798 
    691799/// 
     800/// @brief The user selected an outline index item. 
     801/// 
     802void 
     803main_window_outline_cb (GtkTreeView *treeIndex, GtkTreePath *treePath, 
     804                        GtkTreeViewColumn *column, gpointer data) 
     805{ 
     806    g_assert ( NULL != data && "The data parameter is NULL."); 
     807 
     808    GtkTreeModel *indexModel = gtk_tree_view_get_model (treeIndex); 
     809    GtkTreeIter iter; 
     810    if ( gtk_tree_model_get_iter (indexModel, &iter, treePath) ) 
     811    { 
     812        gpointer outlineData; 
     813        gtk_tree_model_get (indexModel, &iter, 2, &outlineData, -1); 
     814        DocumentOutline *outline = (DocumentOutline *)outlineData; 
     815        MainPter *pter = (MainPter *)data; 
     816        pter->outlineActivated (outline); 
     817    }     
     818} 
     819 
     820/// 
    692821/// @brief Called when the window is closed or Quit is activated. 
    693822/// 
  • trunk/src/gtk/MainView.h

    r64 r67  
    4949            void showErrorMessage (const gchar *title, const gchar *body); 
    5050            void showPage (DocumentPage *page); 
     51            void showSidebar (gboolean show); 
    5152            void setTotalPages (gint pages); 
    5253            void setGoToPageText (const gchar *text); 
     
    5455            void getPageViewSize (gint *width, gint *height); 
    5556            void setTitle (const gchar *title); 
     57            void setOutline (DocumentOutline *outline); 
    5658 
    5759        protected: 
     
    6062            GtkWidget *m_MainWindow;  
    6163            GtkWidget *m_MainBox; 
     64            GtkTreeStore *m_Outline; 
    6265            GtkWidget *m_PageView; 
    6366            GtkWidget *m_PageViewScroll; 
     67            GtkWidget *m_Sidebar; 
    6468            gint m_TotalPages; 
    6569            GtkUIManager *m_UIManager; 
    6670 
    6771            void createCurrentPage (void); 
    68             void createPageView (void); 
     72            GtkWidget *createPageView (void); 
    6973            void createUIManager (void); 
    7074            GdkPixbuf *getPixbufFromPage (DocumentPage *page); 
    7175            void setMainWindowIcon (void); 
     76            void setOutlineChildren (DocumentOutline *outline,  
     77                                     GtkTreeIter *rootIter); 
    7278    }; 
    7379} 
  • trunk/tests/MainPterTest.cxx

    r66 r67  
    685685    child->setDestination (2); 
    686686    outline->addChild (child); 
     687    m_Document->setPageMode (PageModeOutlines); 
    687688    m_Document->setOutline (outline);     
    688689    m_Document->setNumPages (4);