Show
Ignore:
Timestamp:
04/14/06 12:08:30 (3 years ago)
Author:
jordi
Message:

The document's outlines are now loaded correctly, although I don't like the way is set up now...

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/DocumentOutline.cxx

    r58 r60  
    1717 
    1818#include <config.h> 
     19 
     20// Poppler headers 
     21#include <goo/GooList.h> 
     22#include <Outline.h> 
     23#include <PDFDoc.h> 
     24#include <Link.h> 
     25 
    1926#include "epdfview.h" 
    2027 
    2128using namespace ePDFView; 
    2229 
     30/// Forward declarations. 
     31static void deleteChild (gpointer child, gpointer userData); 
     32 
    2333/// 
    2434/// @brief Constructs a new DocumentOutline. 
    2535/// 
    26 DocumentOutline::DocumentOutline () 
    27 { 
     36DocumentOutline::DocumentOutline (PDFDoc *document) 
     37{ 
     38    m_Destination = 1; 
     39    m_Document = document; 
     40    m_Children = NULL; 
     41    m_LastReturnedChild = NULL; 
     42    m_Parent = NULL; 
     43    m_Title = NULL; 
    2844} 
    2945 
     
    3349DocumentOutline::~DocumentOutline () 
    3450{ 
     51    m_Document = NULL; 
     52    m_Parent = NULL; 
     53    g_free (m_Title); 
     54    /// Delete the children. 
     55    g_list_foreach (m_Children, deleteChild, NULL); 
     56    g_list_free (m_Children); 
    3557} 
    3658 
     
    5072DocumentOutline::getDestinationPage () 
    5173{ 
    52     return 1; 
     74    return m_Destination; 
    5375} 
    5476 
     
    6284DocumentOutline::getFirstChild () 
    6385{ 
     86    m_LastReturnedChild = g_list_first (m_Children); 
     87    if ( NULL != m_LastReturnedChild ) 
     88    { 
     89        return (DocumentOutline *)m_LastReturnedChild->data; 
     90    } 
     91    return NULL; 
     92} 
     93 
     94/// 
     95/// @brief Gets the next outline's child. 
     96/// 
     97/// @returns The next child after the one returned by the last call to  
     98///          getFirstChild() or getNextChild(). 
     99///          If no child has been returned yet (i.e., getFirstChild() hasn't 
     100///          been called yet) or there's no next child returns NULL. 
     101/// 
     102DocumentOutline * 
     103DocumentOutline::getNextChild () 
     104{ 
     105    m_LastReturnedChild = g_list_next (m_LastReturnedChild); 
     106    if ( NULL != m_LastReturnedChild ) 
     107    { 
     108        return (DocumentOutline *)m_LastReturnedChild->data; 
     109    } 
    64110    return NULL; 
    65111} 
     
    73119DocumentOutline::getNumChildren () 
    74120{ 
    75     return 0; 
     121    return g_list_length (m_Children); 
    76122} 
    77123 
     
    85131DocumentOutline::getTitle () 
    86132{ 
    87     return ""; 
    88 } 
     133    if ( NULL == m_Title ) 
     134    { 
     135        return ""; 
     136    } 
     137    return m_Title; 
     138} 
     139 
     140void 
     141DocumentOutline::setDestination (gint destination) 
     142{ 
     143    m_Destination = destination; 
     144} 
     145 
     146void 
     147DocumentOutline::setChildren (GooList *childrenList) 
     148{ 
     149    if ( NULL != childrenList ) 
     150    { 
     151        int numChildren = childrenList->getLength (); 
     152        for ( int childIndex = 0; childIndex < numChildren; childIndex++) 
     153        { 
     154            OutlineItem *item = (OutlineItem *)childrenList->get (childIndex); 
     155            // Get the title. 
     156            gchar *title = g_ucs4_to_utf8 (item->getTitle (),  
     157                                           item->getTitleLength (), 
     158                                           NULL, NULL, NULL);             
     159            // The page destination. 
     160            gint destination = 1; 
     161            LinkAction *action = item->getAction (); 
     162            if ( NULL != action ) 
     163            { 
     164                if ( action->isOk () && actionGoTo == action->getKind () ) 
     165                { 
     166                    LinkDest *dest = ((LinkGoTo *)action)->getDest (); 
     167                    if ( dest->isOk () && dest->isPageRef () ) 
     168                    { 
     169                        Ref ref = dest->getPageRef (); 
     170                        destination = m_Document->findPage (ref.num, ref.gen); 
     171                    } 
     172                    else if ( dest->isOk () ) 
     173                    { 
     174                        destination = dest->getPageNum (); 
     175                    } 
     176                } 
     177            } 
     178            // Create the child. 
     179            DocumentOutline *child = new DocumentOutline (m_Document); 
     180            child->setParent (this); 
     181            child->setTitle (title); 
     182            g_free (title); 
     183            child->setDestination (destination); 
     184            // Add to the list of children. 
     185            m_Children = g_list_append (m_Children, child); 
     186            // And add its own children. 
     187            if ( item->hasKids () ) 
     188            { 
     189                // I need to open the outline because if it's not  
     190                // open then the getKids() function returns NULL. 
     191                item->open (); 
     192                child->setChildren (item->getKids ()); 
     193            } 
     194        } 
     195    } 
     196} 
     197 
     198/// 
     199/// @brief Sets the outline. 
     200/// 
     201/// This is only called for the root outline element when loading a document. 
     202/// Fills in the list of outline items from the document. 
     203/// 
     204/// @param outline The outline from the documents. 
     205/// 
     206void 
     207DocumentOutline::setOutline (Outline *outline) 
     208{ 
     209    g_assert (NULL != outline && "Tried to set a NULL outline."); 
     210     
     211    setTitle (""); 
     212    setDestination (1); 
     213         
     214    setChildren (outline->getItems ()); 
     215} 
     216 
     217void 
     218DocumentOutline::setParent (DocumentOutline *parent) 
     219{ 
     220    m_Parent = parent; 
     221} 
     222 
     223void 
     224DocumentOutline::setTitle (const char *title) 
     225{ 
     226    g_assert (NULL != title && "Tried to set a NULL title."); 
     227 
     228    g_free (m_Title); 
     229    m_Title = g_strdup (title); 
     230} 
     231 
     232void 
     233deleteChild (gpointer child, gpointer userData) 
     234{ 
     235    g_assert ( NULL != child && "An outline's child is NULL!"); 
     236     
     237    DocumentOutline *outline = (DocumentOutline *)child; 
     238    delete outline; 
     239}