Changeset 61 for trunk/src/DocumentOutline.cxx
- Timestamp:
- 04/14/06 12:36:20 (3 years ago)
- Files:
-
- 1 modified
-
trunk/src/DocumentOutline.cxx (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/DocumentOutline.cxx
r60 r61 17 17 18 18 #include <config.h> 19 20 // Poppler headers21 #include <goo/GooList.h>22 #include <Outline.h>23 #include <PDFDoc.h>24 #include <Link.h>25 26 19 #include "epdfview.h" 27 20 … … 34 27 /// @brief Constructs a new DocumentOutline. 35 28 /// 36 DocumentOutline::DocumentOutline ( PDFDoc *document)29 DocumentOutline::DocumentOutline () 37 30 { 38 31 m_Destination = 1; 39 m_Document = document;40 32 m_Children = NULL; 41 33 m_LastReturnedChild = NULL; … … 49 41 DocumentOutline::~DocumentOutline () 50 42 { 51 m_Document = NULL;52 43 m_Parent = NULL; 53 44 g_free (m_Title); … … 58 49 59 50 /// 60 /// @brief Get the outline's destination page. 51 /// @brief Adds a new outline's child. 52 /// 53 /// @param child The new child to add. 54 /// 55 void 56 DocumentOutline::addChild (DocumentOutline *child) 57 { 58 m_Children = g_list_append (m_Children, child); 59 } 60 61 /// 62 /// @brief Gets the outline's destination page. 61 63 /// 62 64 /// I'm only using the outlines as a way to go to an specific page, although … … 138 140 } 139 141 142 /// 143 /// @brief Sets the outline item's destination. 144 /// 145 /// @see getDestination(). 146 /// 147 /// @param destination The page number, starting from 1, that 148 /// this outline links to. 149 /// 140 150 void 141 151 DocumentOutline::setDestination (gint destination) … … 144 154 } 145 155 146 void 147 DocumentOutline::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 /// 206 void 207 DocumentOutline::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 156 /// 157 /// @brief Sets the item's parent. 158 /// 159 /// This is currently not used. 160 /// 161 /// @param parent The outline item's parent. 162 /// 217 163 void 218 164 DocumentOutline::setParent (DocumentOutline *parent) … … 221 167 } 222 168 169 /// 170 /// @brief Sets the outline item's title. 171 /// 172 /// @param title The title to set to the outline. 173 /// 223 174 void 224 175 DocumentOutline::setTitle (const char *title) … … 230 181 } 231 182 183 /// 184 /// @brief Deletes an outline item's child. 185 /// 186 /// This function is called by the destructor to delete all childs in 187 /// the m_Children list. 188 /// 189 /// @param child The data element in the list's item. 190 /// @param userData The data passed to the g_list_foreach() function. 191 /// Currently unused. 192 /// 232 193 void 233 194 deleteChild (gpointer child, gpointer userData)
