From ab125ea4dfd24e3b597b1cf74937a50a81c6c379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Aliste?= Date: Sat, 8 Dec 2012 10:33:21 -0300 Subject: [PATCH 2/2] glib: Update the demo to modify flags of annotations. --- glib/demo/annots.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/glib/demo/annots.c b/glib/demo/annots.c index 4d39ba3..609b69b 100644 --- a/glib/demo/annots.c +++ b/glib/demo/annots.c @@ -669,6 +669,49 @@ pgd_annots_selection_changed (GtkTreeSelection *treeselection, } static void +pgd_annots_flags_toggled (GtkCellRendererToggle *renderer, + gchar *path_str, + PgdAnnotsDemo *demo) +{ + gint column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT(renderer), "column")); + GtkTreeModel *model = GTK_TREE_MODEL (demo->model); + GtkTreeIter iter; + GtkTreePath *path = gtk_tree_path_new_from_string (path_str); + gboolean fixed; + PopplerAnnot *annot; + PopplerAnnotFlag flags, flag_bit; + + gtk_tree_model_get_iter (model, &iter, path); + gtk_tree_model_get (model, &iter, column, &fixed, ANNOTS_COLUMN, &annot,-1); + + fixed ^= 1; + flags = poppler_annot_get_flags (annot); + switch (column) + { + case ANNOTS_FLAG_INVISIBLE_COLUMN: + flag_bit = POPPLER_ANNOT_FLAG_INVISIBLE; + break; + case ANNOTS_FLAG_HIDDEN_COLUMN: + flag_bit = POPPLER_ANNOT_FLAG_HIDDEN; + break; + default: + flag_bit = POPPLER_ANNOT_FLAG_PRINT; + break; + } + + if (fixed) + flags = flags | flag_bit; + else + flags = flags & (~flag_bit); + + poppler_annot_set_flags (annot, flags); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, column, fixed, -1); + + pgd_annot_view_set_annot (demo, annot); + gtk_tree_path_free (path); +} + +static void pgd_annots_add_annot (GtkWidget *button, PgdAnnotsDemo *demo) { @@ -898,6 +941,10 @@ pgd_annots_create_widget (PopplerDocument *document) NULL); renderer = gtk_cell_renderer_toggle_new (); + g_signal_connect (G_OBJECT (renderer), "toggled", + G_CALLBACK (pgd_annots_flags_toggled), + (gpointer) demo); + g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (ANNOTS_FLAG_INVISIBLE_COLUMN)); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), ANNOTS_FLAG_INVISIBLE_COLUMN, "Invisible", renderer, @@ -905,6 +952,10 @@ pgd_annots_create_widget (PopplerDocument *document) NULL); renderer = gtk_cell_renderer_toggle_new (); + g_signal_connect (G_OBJECT (renderer), "toggled", + G_CALLBACK (pgd_annots_flags_toggled), + (gpointer) demo); + g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (ANNOTS_FLAG_HIDDEN_COLUMN)); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), ANNOTS_FLAG_HIDDEN_COLUMN, "Hidden", renderer, @@ -912,6 +963,10 @@ pgd_annots_create_widget (PopplerDocument *document) NULL); renderer = gtk_cell_renderer_toggle_new (); + g_signal_connect (G_OBJECT (renderer), "toggled", + G_CALLBACK (pgd_annots_flags_toggled), + (gpointer) demo); + g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (ANNOTS_FLAG_PRINT_COLUMN)); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), ANNOTS_FLAG_PRINT_COLUMN, "Print", renderer, -- 1.8.0.1