| | 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 | /// |
| | 102 | DocumentOutline * |
| | 103 | DocumentOutline::getNextChild () |
| | 104 | { |
| | 105 | m_LastReturnedChild = g_list_next (m_LastReturnedChild); |
| | 106 | if ( NULL != m_LastReturnedChild ) |
| | 107 | { |
| | 108 | return (DocumentOutline *)m_LastReturnedChild->data; |
| | 109 | } |
| 87 | | return ""; |
| 88 | | } |
| | 133 | if ( NULL == m_Title ) |
| | 134 | { |
| | 135 | return ""; |
| | 136 | } |
| | 137 | return m_Title; |
| | 138 | } |
| | 139 | |
| | 140 | void |
| | 141 | DocumentOutline::setDestination (gint destination) |
| | 142 | { |
| | 143 | m_Destination = destination; |
| | 144 | } |
| | 145 | |
| | 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 | |
| | 217 | void |
| | 218 | DocumentOutline::setParent (DocumentOutline *parent) |
| | 219 | { |
| | 220 | m_Parent = parent; |
| | 221 | } |
| | 222 | |
| | 223 | void |
| | 224 | DocumentOutline::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 | |
| | 232 | void |
| | 233 | deleteChild (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 | } |