| 1 |
// ePDFView - A lightweight PDF Viewer. |
|---|
| 2 |
// Copyright (C) 2006 Emma's Software. |
|---|
| 3 |
// |
|---|
| 4 |
// This program is free software; you can redistribute it and/or modify |
|---|
| 5 |
// it under the terms of the GNU General Public License as published by |
|---|
| 6 |
// the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 |
// (at your option) any later version. |
|---|
| 8 |
// |
|---|
| 9 |
// This program is distributed in the hope that it will be useful, |
|---|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 |
// GNU General Public License for more details. |
|---|
| 13 |
// |
|---|
| 14 |
// You should have received a copy of the GNU General Public License |
|---|
| 15 |
// along with this program; if not, write to the Free Software |
|---|
| 16 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 17 |
|
|---|
| 18 |
#include <config.h> |
|---|
| 19 |
#include "epdfview.h" |
|---|
| 20 |
|
|---|
| 21 |
using namespace ePDFView; |
|---|
| 22 |
|
|---|
| 23 |
// Forward declarations. |
|---|
| 24 |
static void deleteChild (gpointer child, gpointer userData); |
|---|
| 25 |
|
|---|
| 26 |
/// |
|---|
| 27 |
/// @brief Constructs a new DocumentOutline. |
|---|
| 28 |
/// |
|---|
| 29 |
DocumentOutline::DocumentOutline () |
|---|
| 30 |
{ |
|---|
| 31 |
m_Destination = 1; |
|---|
| 32 |
m_Children = NULL; |
|---|
| 33 |
m_LastReturnedChild = NULL; |
|---|
| 34 |
m_Parent = NULL; |
|---|
| 35 |
m_Title = NULL; |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
/// |
|---|
| 39 |
/// @brief Destroys any dynamically allocated memory for DocumentOutline. |
|---|
| 40 |
/// |
|---|
| 41 |
DocumentOutline::~DocumentOutline () |
|---|
| 42 |
{ |
|---|
| 43 |
m_Parent = NULL; |
|---|
| 44 |
g_free (m_Title); |
|---|
| 45 |
/// Delete the children. |
|---|
| 46 |
g_list_foreach (m_Children, deleteChild, NULL); |
|---|
| 47 |
g_list_free (m_Children); |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
/// |
|---|
| 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. |
|---|
| 63 |
/// |
|---|
| 64 |
/// I'm only using the outlines as a way to go to an specific page, although |
|---|
| 65 |
/// the PDF Specification says that an outline could open a page from another |
|---|
| 66 |
/// file, execute an application, etc... I won't use all those features and |
|---|
| 67 |
/// concentrate only on the pages. |
|---|
| 68 |
/// |
|---|
| 69 |
/// @return The destination page number for the outline number or 1 if the |
|---|
| 70 |
/// outline item has no page number (like the root outline item or |
|---|
| 71 |
/// other kinds of destinations). |
|---|
| 72 |
/// |
|---|
| 73 |
gint |
|---|
| 74 |
DocumentOutline::getDestinationPage () |
|---|
| 75 |
{ |
|---|
| 76 |
return m_Destination; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
/// |
|---|
| 80 |
/// @brief The first children of the outline item. |
|---|
| 81 |
/// |
|---|
| 82 |
/// @return The pointer to the first children of the outline item, or |
|---|
| 83 |
/// NULL if the outline has no children. |
|---|
| 84 |
/// |
|---|
| 85 |
DocumentOutline * |
|---|
| 86 |
DocumentOutline::getFirstChild () |
|---|
| 87 |
{ |
|---|
| 88 |
m_LastReturnedChild = g_list_first (m_Children); |
|---|
| 89 |
if ( NULL != m_LastReturnedChild ) |
|---|
| 90 |
{ |
|---|
| 91 |
return (DocumentOutline *)m_LastReturnedChild->data; |
|---|
| 92 |
} |
|---|
| 93 |
return NULL; |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
/// |
|---|
| 97 |
/// @brief Gets the next outline's child. |
|---|
| 98 |
/// |
|---|
| 99 |
/// @returns The next child after the one returned by the last call to |
|---|
| 100 |
/// getFirstChild() or getNextChild(). |
|---|
| 101 |
/// If no child has been returned yet (i.e., getFirstChild() hasn't |
|---|
| 102 |
/// been called yet) or there's no next child returns NULL. |
|---|
| 103 |
/// |
|---|
| 104 |
DocumentOutline * |
|---|
| 105 |
DocumentOutline::getNextChild () |
|---|
| 106 |
{ |
|---|
| 107 |
m_LastReturnedChild = g_list_next (m_LastReturnedChild); |
|---|
| 108 |
if ( NULL != m_LastReturnedChild ) |
|---|
| 109 |
{ |
|---|
| 110 |
return (DocumentOutline *)m_LastReturnedChild->data; |
|---|
| 111 |
} |
|---|
| 112 |
return NULL; |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
/// |
|---|
| 116 |
/// @brief Gets the number of children for this outline. |
|---|
| 117 |
/// |
|---|
| 118 |
/// @return The number of children this outline has. |
|---|
| 119 |
/// |
|---|
| 120 |
gint |
|---|
| 121 |
DocumentOutline::getNumChildren () |
|---|
| 122 |
{ |
|---|
| 123 |
return g_list_length (m_Children); |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
/// |
|---|
| 127 |
/// @brief Gets the outline's title. |
|---|
| 128 |
/// |
|---|
| 129 |
/// @return The title of the outline item or an empty string if the |
|---|
| 130 |
/// outline item has no title (like the root outline item). |
|---|
| 131 |
/// |
|---|
| 132 |
const gchar * |
|---|
| 133 |
DocumentOutline::getTitle () |
|---|
| 134 |
{ |
|---|
| 135 |
if ( NULL == m_Title ) |
|---|
| 136 |
{ |
|---|
| 137 |
return ""; |
|---|
| 138 |
} |
|---|
| 139 |
return m_Title; |
|---|
| 140 |
} |
|---|
| 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 |
/// |
|---|
| 150 |
void |
|---|
| 151 |
DocumentOutline::setDestination (gint destination) |
|---|
| 152 |
{ |
|---|
| 153 |
m_Destination = destination; |
|---|
| 154 |
} |
|---|
| 155 |
|
|---|
| 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 |
/// |
|---|
| 163 |
void |
|---|
| 164 |
DocumentOutline::setParent (DocumentOutline *parent) |
|---|
| 165 |
{ |
|---|
| 166 |
m_Parent = parent; |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
/// |
|---|
| 170 |
/// @brief Sets the outline item's title. |
|---|
| 171 |
/// |
|---|
| 172 |
/// @param title The title to set to the outline. |
|---|
| 173 |
/// |
|---|
| 174 |
void |
|---|
| 175 |
DocumentOutline::setTitle (const gchar *title) |
|---|
| 176 |
{ |
|---|
| 177 |
g_assert (NULL != title && "Tried to set a NULL title."); |
|---|
| 178 |
|
|---|
| 179 |
g_free (m_Title); |
|---|
| 180 |
m_Title = g_strdup (title); |
|---|
| 181 |
} |
|---|
| 182 |
|
|---|
| 183 |
/// |
|---|
| 184 |
/// @brief Deletes an outline item's child. |
|---|
| 185 |
/// |
|---|
| 186 |
/// This function is called by the destructor to delete all children 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 |
/// |
|---|
| 193 |
void |
|---|
| 194 |
deleteChild (gpointer child, gpointer userData) |
|---|
| 195 |
{ |
|---|
| 196 |
g_assert ( NULL != child && "An outline's child is NULL!"); |
|---|
| 197 |
|
|---|
| 198 |
DocumentOutline *outline = (DocumentOutline *)child; |
|---|
| 199 |
delete outline; |
|---|
| 200 |
} |
|---|