2
* Copyright (C) 2007 Carlos Garcia Campos <carlosgc@gnome.org>
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, or (at your option)
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.
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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
26
OUTLINE_ACTION_TYPE_COLUMN,
27
OUTLINE_EXPAND_COLUMN,
28
OUTLINE_ACTION_COLUMN,
33
build_tree (PopplerDocument *document,
36
PopplerIndexIter *iter)
40
GtkTreeIter tree_iter;
41
PopplerIndexIter *child;
42
PopplerAction *action;
45
GEnumValue *enum_value;
47
action = poppler_index_iter_get_action (iter);
48
expand = poppler_index_iter_is_open (iter);
53
markup = g_markup_escape_text (action->any.title, -1);
54
enum_value = g_enum_get_value ((GEnumClass *) g_type_class_ref (POPPLER_TYPE_ACTION_TYPE), action->type);
56
if (action->type == POPPLER_ACTION_GOTO_DEST &&
57
action->goto_dest.dest->type == POPPLER_DEST_NAMED) {
61
gtk_tree_store_append (GTK_TREE_STORE (model), &tree_iter, parent);
62
gtk_tree_store_set (GTK_TREE_STORE (model), &tree_iter,
63
OUTLINE_TITLE_COLUMN, markup,
64
OUTLINE_ACTION_TYPE_COLUMN, enum_value->value_name,
65
OUTLINE_EXPAND_COLUMN, expand,
66
OUTLINE_ACTION_COLUMN, action,
68
g_object_weak_ref (G_OBJECT (model),
69
(GWeakNotify)poppler_action_free,
74
child = poppler_index_iter_get_child (iter);
76
build_tree (document, model, &tree_iter, child);
77
poppler_index_iter_free (child);
78
} while (poppler_index_iter_next (iter));
82
pgd_outline_create_model (PopplerDocument *document)
85
PopplerIndexIter *iter;
87
iter = poppler_index_iter_new (document);
89
model = GTK_TREE_MODEL (
90
gtk_tree_store_new (N_COLUMNS,
91
G_TYPE_STRING, G_TYPE_STRING,
92
G_TYPE_BOOLEAN, G_TYPE_POINTER));
93
build_tree (document, model, NULL, iter);
94
poppler_index_iter_free (iter);
96
GtkTreeIter tree_iter;
99
model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING));
100
gtk_list_store_append (GTK_LIST_STORE (model), &tree_iter);
101
markup = g_strdup_printf ("<span size=\"larger\" style=\"italic\">%s</span>",
102
"The document doesn't contain outline");
103
gtk_list_store_set (GTK_LIST_STORE (model), &tree_iter,
112
expand_open_links (GtkTreeView *tree_view,
119
if (gtk_tree_model_iter_children (model, &iter, parent)) {
121
gtk_tree_model_get (model, &iter,
122
OUTLINE_EXPAND_COLUMN, &expand,
127
path = gtk_tree_model_get_path (model, &iter);
128
gtk_tree_view_expand_row (tree_view, path, FALSE);
129
gtk_tree_path_free (path);
132
expand_open_links (tree_view, model, &iter);
133
} while (gtk_tree_model_iter_next (model, &iter));
138
pgd_outline_selection_changed (GtkTreeSelection *treeselection,
139
GtkWidget *action_view)
144
if (gtk_tree_selection_get_selected (treeselection, &model, &iter)) {
145
PopplerAction *action;
147
gtk_tree_model_get (model, &iter,
148
OUTLINE_ACTION_COLUMN, &action,
150
pgd_action_view_set_action (action_view, action);
155
pgd_outline_create_widget (PopplerDocument *document)
160
GtkCellRenderer *renderer;
161
GtkTreeSelection *selection;
162
GtkWidget *hpaned, *action;
164
hpaned = gtk_hpaned_new ();
166
action = pgd_action_view_new (document);
168
swindow = gtk_scrolled_window_new (NULL, NULL);
169
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
170
GTK_POLICY_AUTOMATIC,
171
GTK_POLICY_AUTOMATIC);
173
model = pgd_outline_create_model (document);
174
treeview = gtk_tree_view_new_with_model (model);
175
g_object_unref (model);
177
renderer = gtk_cell_renderer_text_new ();
178
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
181
"markup", OUTLINE_TITLE_COLUMN,
183
g_object_set (G_OBJECT (renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
184
g_object_set (G_OBJECT (gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), 0)),
185
"expand", TRUE, NULL);
187
if (GTK_IS_TREE_STORE (model)) {
188
renderer = gtk_cell_renderer_text_new ();
189
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
192
"text", OUTLINE_ACTION_TYPE_COLUMN,
195
expand_open_links (GTK_TREE_VIEW (treeview), model, NULL);
197
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
198
g_signal_connect (G_OBJECT (selection), "changed",
199
G_CALLBACK (pgd_outline_selection_changed),
202
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
206
gtk_container_add (GTK_CONTAINER (swindow), treeview);
207
gtk_widget_show (treeview);
209
gtk_paned_add1 (GTK_PANED (hpaned), swindow);
210
gtk_widget_show (swindow);
212
gtk_paned_add2 (GTK_PANED (hpaned), action);
213
gtk_widget_show (action);
215
gtk_paned_set_position (GTK_PANED (hpaned), 300);