]> git.donarmstrong.com Git - xournal.git/blobdiff - src/xo-misc.c
Image patch
[xournal.git] / src / xo-misc.c
index a5329c3a49d8761ffba5bd28deb3aea9c177c1e4..bd65f1afbede9a8a3a9cde569a3c0a197a1cb581 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ *  This program is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This software is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of  
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
@@ -16,6 +31,7 @@
 #include "xo-file.h"
 #include "xo-paint.h"
 #include "xo-shapes.h"
+#include "xo-image.h"
 
 // some global constants
 
@@ -89,18 +105,43 @@ struct Page *new_page_with_bg(struct Background *bg, double width, double height
   return pg;
 }
 
+// change the current page if necessary for pointer at pt
+void set_current_page(gdouble *pt)
+{
+  gboolean page_change;
+  struct Page *tmppage;
+
+  page_change = FALSE;
+  tmppage = ui.cur_page;
+  while (ui.view_continuous && (pt[1] < - VIEW_CONTINUOUS_SKIP)) {
+    if (ui.pageno == 0) break;
+    page_change = TRUE;
+    ui.pageno--;
+    tmppage = g_list_nth_data(journal.pages, ui.pageno);
+    pt[1] += tmppage->height + VIEW_CONTINUOUS_SKIP;
+  }
+  while (ui.view_continuous && (pt[1] > tmppage->height + VIEW_CONTINUOUS_SKIP)) {
+    if (ui.pageno == journal.npages-1) break;
+    pt[1] -= tmppage->height + VIEW_CONTINUOUS_SKIP;
+    page_change = TRUE;
+    ui.pageno++;
+    tmppage = g_list_nth_data(journal.pages, ui.pageno);
+  }
+  if (page_change) do_switch_page(ui.pageno, FALSE, FALSE);
+}
+
 void realloc_cur_path(int n)
 {
   if (n <= ui.cur_path_storage_alloc) return;
-  ui.cur_path_storage_alloc = n+10;
-  ui.cur_path.coords = g_realloc(ui.cur_path.coords, 2*(n+10)*sizeof(double));
+  ui.cur_path_storage_alloc = n+100;
+  ui.cur_path.coords = g_realloc(ui.cur_path.coords, 2*(n+100)*sizeof(double));
 }
 
 void realloc_cur_widths(int n)
 {
   if (n <= ui.cur_widths_storage_alloc) return;
-  ui.cur_widths_storage_alloc = n+10;
-  ui.cur_widths = g_realloc(ui.cur_widths, (n+10)*sizeof(double));
+  ui.cur_widths_storage_alloc = n+100;
+  ui.cur_widths = g_realloc(ui.cur_widths, (n+100)*sizeof(double));
 }
 
 // undo utility functions
@@ -141,6 +182,11 @@ void clear_redo_stack(void)
       g_free(redo->item->font_name);
       g_free(redo->item);
     }
+    else if (redo->type == ITEM_IMAGE) {
+      g_object_unref(redo->item->image);
+      g_free(redo->item->image_png);
+      g_free(redo->item);
+    }
     else if (redo->type == ITEM_ERASURE || redo->type == ITEM_RECOGNIZER) {
       for (list = redo->erasurelist; list!=NULL; list=list->next) {
         erasure = (struct UndoErasureData *)list->data;
@@ -217,6 +263,10 @@ void clear_undo_stack(void)
         }
         if (erasure->item->type == ITEM_TEXT)
           { g_free(erasure->item->text); g_free(erasure->item->font_name); }
+        if (erasure->item->type == ITEM_IMAGE) {
+          g_object_unref(erasure->item->image);
+          g_free(erasure->item->image_png);
+        }
         g_free(erasure->item);
         g_list_free(erasure->replacement_items);
         g_free(erasure);
@@ -301,6 +351,10 @@ void delete_layer(struct Layer *l)
     if (item->type == ITEM_TEXT) {
       g_free(item->font_name); g_free(item->text);
     }
+    if (item->type == ITEM_IMAGE) {
+      g_object_unref(item->image);
+      g_free(item->image_png);
+    }
     // don't need to delete the canvas_item, as it's part of the group destroyed below
     g_free(item);
     l->items = g_list_delete_link(l->items, l->items);
@@ -340,6 +394,12 @@ void refstring_unref(struct Refstring *rs)
 
 // some helper functions
 
+int finite_sized(double x) // detect unrealistic coordinate values
+{
+  return (finite(x) && x<1E6 && x>-1E6);
+}
+
+
 void get_pointer_coords(GdkEvent *event, gdouble *ret)
 {
   double x, y;
@@ -349,6 +409,17 @@ void get_pointer_coords(GdkEvent *event, gdouble *ret)
   ret[1] -= ui.cur_page->voffset;
 }
 
+void get_current_pointer_coords(gdouble *ret)
+{
+  gint wx, wy, sx, sy;
+
+  gtk_widget_get_pointer((GtkWidget *)canvas, &wx, &wy);
+  gnome_canvas_get_scroll_offsets(canvas, &sx, &sy);
+  gnome_canvas_window_to_world(canvas, (double)(wx + sx), (double)(wy + sy), ret, ret+1);
+  ret[0] -= ui.cur_page->hoffset;
+  ret[1] -= ui.cur_page->voffset;
+}
+
 void fix_xinput_coords(GdkEvent *event)
 {
   double *axes, *px, *py, axis_width;
@@ -369,18 +440,17 @@ void fix_xinput_coords(GdkEvent *event)
   }
   else return; // nothing we know how to do
 
-  // use canvas window, not event window (else get GTK+ 2.11 bugs!)            
-  gdk_window_get_origin(GTK_WIDGET(canvas)->window, &wx, &wy);  
   gnome_canvas_get_scroll_offsets(canvas, &sx, &sy);
 
 #ifdef ENABLE_XINPUT_BUGFIX
   // fix broken events with the core pointer's location
-  if (!finite(axes[0]) || !finite(axes[1]) || (axes[0]==0. && axes[1]==0.)) {
+  if (!finite_sized(axes[0]) || !finite_sized(axes[1]) || axes[0]==0. || axes[1]==0.) {
     gdk_window_get_pointer(GTK_WIDGET(canvas)->window, &ix, &iy, NULL);
     *px = ix + sx; 
     *py = iy + sy;
   }
   else {
+    gdk_window_get_origin(GTK_WIDGET(canvas)->window, &wx, &wy);  
     axis_width = device->axes[0].max - device->axes[0].min;
     if (axis_width>EPSILON)
       *px = (axes[0]/axis_width)*ui.screen_width + sx - wx;
@@ -388,17 +458,50 @@ void fix_xinput_coords(GdkEvent *event)
     if (axis_width>EPSILON)
       *py = (axes[1]/axis_width)*ui.screen_height + sy - wy;
   }
+#else
+  if (!finite_sized(*px) || !finite_sized(*py) || *px==0. || *py==0.) {
+    gdk_window_get_pointer(GTK_WIDGET(canvas)->window, &ix, &iy, NULL);
+    *px = ix + sx; 
+    *py = iy + sy;
+  }
+  else {
+    /* with GTK+ 2.16 or earlier, the event comes from the parent gdkwindow
+       and so needs to be adjusted for scrolling */
+    if (gtk_major_version == 2 && gtk_minor_version <= 16) {
+      *px += sx;
+      *py += sy;
+    }
+    /* with GTK+ 2.17, events come improperly translated, and the event's
+       GdkWindow isn't even the same for ButtonDown as for MotionNotify... */
+    if (gtk_major_version == 2 && gtk_minor_version == 17) { // GTK+ 2.17 issues !!
+      gdk_window_get_position(GTK_WIDGET(canvas)->window, &wx, &wy);
+      *px += sx - wx;
+      *py += sy - wy;
+    }
+  }
 #endif
 }
 
 double get_pressure_multiplier(GdkEvent *event)
 {
+  double *axes;
   double rawpressure;
+  GdkDevice *device;
+
+  if (event->type == GDK_MOTION_NOTIFY) {
+    axes = event->motion.axes;
+    device = event->motion.device;
+  }
+  else {
+    axes = event->button.axes;
+    device = event->button.device;
+  }
   
-  if (event->button.device == gdk_device_get_core_pointer()
-      || event->button.device->num_axes <= 2) return 1.0;
+  if (device == gdk_device_get_core_pointer()
+      || device->num_axes <= 2) return 1.0;
 
-  rawpressure = event->button.axes[2]/(event->button.device->axes[2].max - event->button.device->axes[2].min);
+  rawpressure = axes[2]/(device->axes[2].max - device->axes[2].min);
+  if (!finite_sized(rawpressure)) return 1.0;
 
   return ((1-rawpressure)*ui.width_minimum_multiplier + rawpressure*ui.width_maximum_multiplier);
 }
@@ -480,6 +583,16 @@ void make_canvas_item_one(GnomeCanvasGroup *group, struct Item *item)
           "text", item->text, NULL);
     update_item_bbox(item);
   }
+  if (item->type == ITEM_IMAGE) {
+    item->canvas_item = gnome_canvas_item_new(group,
+          gnome_canvas_pixbuf_get_type(),
+          "pixbuf", item->image,
+          "x", item->bbox.left, "y", item->bbox.top,
+          "width", item->bbox.right - item->bbox.left,
+          "height", item->bbox.bottom - item->bbox.top,
+          "width-set", TRUE, "height-set", TRUE,
+          NULL);
+  }
 }
 
 void make_canvas_items(void)
@@ -575,29 +688,13 @@ void update_canvas_bg(struct Page *pg)
   
   if (pg->bg->type == BG_PIXMAP)
   {
-    if (ui.antialias_bg) {
-      set_cursor_busy(TRUE);
-      w = (int)floor(pg->width*ui.zoom+0.5);
-      h = (int)floor(pg->height*ui.zoom+0.5);
-      if (w == gdk_pixbuf_get_width(pg->bg->pixbuf) &&
-          h == gdk_pixbuf_get_height(pg->bg->pixbuf))
-        scaled_pix = gdk_pixbuf_ref(pg->bg->pixbuf);
-      else
-        scaled_pix = gdk_pixbuf_scale_simple(pg->bg->pixbuf, w, h, GDK_INTERP_BILINEAR);
-      pg->bg->pixbuf_scale = ui.zoom;
-      set_cursor_busy(FALSE);
-    }
-    else {
-      scaled_pix = gdk_pixbuf_ref(pg->bg->pixbuf);
-      pg->bg->pixbuf_scale = 0;
-    }
+    pg->bg->pixbuf_scale = 0;
     pg->bg->canvas_item = gnome_canvas_item_new(pg->group, 
         gnome_canvas_pixbuf_get_type(), 
-        "pixbuf", scaled_pix,
+        "pixbuf", pg->bg->pixbuf,
         "width", pg->width, "height", pg->height, 
         "width-set", TRUE, "height-set", TRUE, 
         NULL);
-    gdk_pixbuf_unref(scaled_pix);
     lower_canvas_item_to(pg->group, pg->bg->canvas_item, NULL);
   }
 
@@ -648,24 +745,11 @@ void rescale_bg_pixmaps(void)
     // in progressive mode we scale only visible pages
     if (ui.progressive_bg && !is_visible(pg)) continue;
 
-    if (pg->bg->type == BG_PIXMAP && pg->bg->canvas_item!=NULL) { // do the rescaling ourselves
-      if (ui.antialias_bg) {
-        if (pg->bg->pixbuf_scale == ui.zoom) continue;
-        set_cursor_busy(TRUE);
-        pix = gdk_pixbuf_scale_simple(pg->bg->pixbuf,
-          (int)floor(pg->width*ui.zoom+0.5), (int)floor(pg->height*ui.zoom+0.5),
-          GDK_INTERP_BILINEAR);
-        gnome_canvas_item_set(pg->bg->canvas_item, "pixbuf", pix, NULL);
-        gdk_pixbuf_unref(pix);
-        pg->bg->pixbuf_scale = ui.zoom;
-        set_cursor_busy(FALSE);
-      } else
-      {
-        g_object_get(G_OBJECT(pg->bg->canvas_item), "pixbuf", &pix, NULL);
-        if (pix!=pg->bg->pixbuf)
-          gnome_canvas_item_set(pg->bg->canvas_item, "pixbuf", pg->bg->pixbuf, NULL);
-        pg->bg->pixbuf_scale = 0;
-      }
+    if (pg->bg->type == BG_PIXMAP && pg->bg->canvas_item!=NULL) {
+      g_object_get(G_OBJECT(pg->bg->canvas_item), "pixbuf", &pix, NULL);
+      if (pix!=pg->bg->pixbuf)
+        gnome_canvas_item_set(pg->bg->canvas_item, "pixbuf", pg->bg->pixbuf, NULL);
+      pg->bg->pixbuf_scale = 0;
     }
     if (pg->bg->type == BG_PDF) { 
       // make pixmap scale to correct size if current one is wrong
@@ -683,8 +767,8 @@ void rescale_bg_pixmaps(void)
       // request an asynchronous update to a better pixmap if needed
       zoom_to_request = MIN(ui.zoom, MAX_SAFE_RENDER_DPI/72.0);
       if (pg->bg->pixbuf_scale == zoom_to_request) continue;
-      add_bgpdf_request(pg->bg->file_page_seq, zoom_to_request);
-      pg->bg->pixbuf_scale = zoom_to_request;
+      if (add_bgpdf_request(pg->bg->file_page_seq, zoom_to_request))
+        pg->bg->pixbuf_scale = zoom_to_request;
     }
   }
 }
@@ -724,6 +808,16 @@ void rgb_to_gdkcolor(guint rgba, GdkColor *color)
   color->blue = ((rgba>>8)&0xff)*0x101;
 }
 
+guint32 gdkcolor_to_rgba(GdkColor gdkcolor, guint16 alpha) 
+{
+  guint32 rgba =  ((gdkcolor.red   & 0xff00) << 16) |
+                  ((gdkcolor.green & 0xff00) << 8)  |
+                  ((gdkcolor.blue  & 0xff00) )      |
+                  ((alpha & 0xff00) >> 8);
+
+  return rgba;
+}
+
 // some interface functions
 
 void update_thickness_buttons(void)
@@ -753,6 +847,9 @@ void update_thickness_buttons(void)
 
 void update_color_buttons(void)
 {
+  GdkColor gdkcolor;
+  GtkColorButton *colorbutton;
+  
   if (ui.selection!=NULL || (ui.toolno[ui.cur_mapping] != TOOL_PEN 
       && ui.toolno[ui.cur_mapping] != TOOL_HIGHLIGHTER && ui.toolno[ui.cur_mapping] != TOOL_TEXT)) {
     gtk_toggle_tool_button_set_active(
@@ -807,6 +904,22 @@ void update_color_buttons(void)
       gtk_toggle_tool_button_set_active(
         GTK_TOGGLE_TOOL_BUTTON(GET_COMPONENT("buttonColorOther")), TRUE);
   }
+
+  colorbutton = GTK_COLOR_BUTTON(GET_COMPONENT("buttonColorChooser"));
+  if ((ui.toolno[ui.cur_mapping] != TOOL_PEN && 
+       ui.toolno[ui.cur_mapping] != TOOL_HIGHLIGHTER && 
+       ui.toolno[ui.cur_mapping] != TOOL_TEXT))
+    gdkcolor.red = gdkcolor.blue = gdkcolor.green = 0;
+  else rgb_to_gdkcolor(ui.cur_brush->color_rgba, &gdkcolor);
+  gtk_color_button_set_color(colorbutton, &gdkcolor);
+  if (ui.toolno[ui.cur_mapping] == TOOL_HIGHLIGHTER) {
+    gtk_color_button_set_alpha(colorbutton,
+      (ui.cur_brush->color_rgba&0xff)*0x101);
+    gtk_color_button_set_use_alpha(colorbutton, TRUE);
+  } else {
+    gtk_color_button_set_alpha(colorbutton, 0xffff);
+    gtk_color_button_set_use_alpha(colorbutton, FALSE);
+  }
 }
 
 void update_tool_buttons(void)
@@ -828,6 +941,10 @@ void update_tool_buttons(void)
       gtk_toggle_tool_button_set_active(
         GTK_TOGGLE_TOOL_BUTTON(GET_COMPONENT("buttonText")), TRUE);
       break;
+    case TOOL_IMAGE:
+      gtk_toggle_tool_button_set_active(
+        GTK_TOGGLE_TOOL_BUTTON(GET_COMPONENT("buttonImage")), TRUE);
+      break;
     case TOOL_SELECTREGION:
       gtk_toggle_tool_button_set_active(
         GTK_TOGGLE_TOOL_BUTTON(GET_COMPONENT("buttonSelectRegion")), TRUE);
@@ -876,6 +993,10 @@ void update_tool_menu(void)
       gtk_check_menu_item_set_active(
         GTK_CHECK_MENU_ITEM(GET_COMPONENT("toolsText")), TRUE);
       break;
+    case TOOL_IMAGE:
+      gtk_check_menu_item_set_active(
+        GTK_CHECK_MENU_ITEM(GET_COMPONENT("toolsImage")), TRUE);
+      break;
     case TOOL_SELECTREGION:
       gtk_check_menu_item_set_active(
         GTK_CHECK_MENU_ITEM(GET_COMPONENT("toolsSelectRegion")), TRUE);
@@ -972,7 +1093,7 @@ void update_color_menu(void)
       break;
     default:
       gtk_check_menu_item_set_active(
-        GTK_CHECK_MENU_ITEM(GET_COMPONENT("colorOther")), TRUE);
+        GTK_CHECK_MENU_ITEM(GET_COMPONENT("colorNA")), TRUE);
   }
 }
 
@@ -1083,12 +1204,9 @@ void update_mappings_menu_linkings(void)
 void update_mappings_menu(void)
 {
   gtk_widget_set_sensitive(GET_COMPONENT("optionsButtonMappings"), ui.use_xinput);
-  gtk_widget_set_sensitive(GET_COMPONENT("optionsDiscardCoreEvents"), ui.use_xinput);
   gtk_widget_set_sensitive(GET_COMPONENT("optionsPressureSensitive"), ui.use_xinput);
   gtk_check_menu_item_set_active(
     GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsButtonMappings")), ui.use_erasertip);
-  gtk_check_menu_item_set_active(
-    GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsDiscardCoreEvents")), ui.discard_corepointer);
   gtk_check_menu_item_set_active(
     GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsPressureSensitive")), ui.pressure_sensitivity);
 
@@ -1109,6 +1227,10 @@ void update_mappings_menu(void)
       gtk_check_menu_item_set_active(
         GTK_CHECK_MENU_ITEM(GET_COMPONENT("button2Text")), TRUE);
       break;
+    case TOOL_IMAGE:
+      gtk_check_menu_item_set_active(
+        GTK_CHECK_MENU_ITEM(GET_COMPONENT("button2Image")), TRUE);
+      break;
     case TOOL_SELECTREGION:
       gtk_check_menu_item_set_active(
         GTK_CHECK_MENU_ITEM(GET_COMPONENT("button2SelectRegion")), TRUE);
@@ -1139,6 +1261,10 @@ void update_mappings_menu(void)
       gtk_check_menu_item_set_active(
         GTK_CHECK_MENU_ITEM(GET_COMPONENT("button3Text")), TRUE);
       break;
+    case TOOL_IMAGE:
+      gtk_check_menu_item_set_active(
+        GTK_CHECK_MENU_ITEM(GET_COMPONENT("button3Image")), TRUE);
+      break;
     case TOOL_SELECTREGION:
       gtk_check_menu_item_set_active(
         GTK_CHECK_MENU_ITEM(GET_COMPONENT("button3SelectRegion")), TRUE);
@@ -1241,12 +1367,12 @@ void update_page_stuff(void)
   gtk_spin_button_set_range(spin, 1, journal.npages+1);
     /* npages+1 will be used to create a new page at end */
   gtk_spin_button_set_value(spin, ui.pageno+1);
-  g_snprintf(tmp, 10, " of %d", journal.npages);
+  g_snprintf(tmp, 10, _(" of %d"), journal.npages);
   gtk_label_set_text(GTK_LABEL(GET_COMPONENT("labelNumpages")), tmp);
 
   layerbox = GTK_COMBO_BOX(GET_COMPONENT("comboLayer"));
   if (ui.layerbox_length == 0) {
-    gtk_combo_box_prepend_text(layerbox, "Background");
+    gtk_combo_box_prepend_text(layerbox, _("Background"));
     ui.layerbox_length++;
   }
   while (ui.layerbox_length > ui.cur_page->nlayers+1) {
@@ -1254,12 +1380,14 @@ void update_page_stuff(void)
     ui.layerbox_length--;
   }
   while (ui.layerbox_length < ui.cur_page->nlayers+1) {
-    g_snprintf(tmp, 10, "Layer %d", ui.layerbox_length++);
+    g_snprintf(tmp, 10, _("Layer %d"), ui.layerbox_length++);
     gtk_combo_box_prepend_text(layerbox, tmp);
   }
   gtk_combo_box_set_active(layerbox, ui.cur_page->nlayers-1-ui.layerno);
   ui.in_update_page_stuff = FALSE;
   
+  gtk_container_forall(GTK_CONTAINER(layerbox), unset_flags, (gpointer)GTK_CAN_FOCUS);
+  
   // update the paper-style menu radio buttons
   
   if (ui.view_continuous)
@@ -1297,7 +1425,7 @@ void update_page_stuff(void)
         break;
       default:
         gtk_check_menu_item_set_active(
-          GTK_CHECK_MENU_ITEM(GET_COMPONENT("papercolorOther")), TRUE);
+          GTK_CHECK_MENU_ITEM(GET_COMPONENT("papercolorNA")), TRUE);
         break;
     }
     switch (ui.cur_page->bg->ruling) {
@@ -1370,15 +1498,20 @@ void update_file_name(char *filename)
   if (ui.filename != NULL) g_free(ui.filename);
   ui.filename = filename;
   if (filename == NULL) {
-    gtk_window_set_title(GTK_WINDOW (winMain), "Xournal");
+    gtk_window_set_title(GTK_WINDOW (winMain), _("Xournal"));
     return;
   }
   p = g_utf8_strrchr(filename, -1, '/');
   if (p == NULL) p = filename; 
   else p = g_utf8_next_char(p);
-  g_snprintf(tmp, 100, "Xournal - %s", p);
+  g_snprintf(tmp, 100, _("Xournal - %s"), p);
   gtk_window_set_title(GTK_WINDOW (winMain), tmp);
   new_mru_entry(filename);
+
+  if (filename[0]=='/') {
+    if (ui.default_path!=NULL) g_free(ui.default_path);
+    ui.default_path = g_path_get_dirname(filename);
+  }
 }
 
 void update_undo_redo_enabled(void)
@@ -1416,14 +1549,22 @@ void update_mapping_linkings(int toolno)
   }
 }
 
-void set_cur_color(int color)
+void set_cur_color(int color_no, guint color_rgba)
 {
-  ui.cur_brush->color_no = color;
-  if (ui.toolno[0] == TOOL_HIGHLIGHTER)
-    ui.cur_brush->color_rgba = predef_colors_rgba[color] & ui.hiliter_alpha_mask;
+  int which_mapping, tool;
+  
+  if (ui.toolno[ui.cur_mapping] == TOOL_HIGHLIGHTER) tool = TOOL_HIGHLIGHTER;
+  else tool = TOOL_PEN;
+  if (ui.cur_mapping>0 && ui.linked_brush[ui.cur_mapping]!=BRUSH_LINKED)
+    which_mapping = ui.cur_mapping;
+  else which_mapping = 0;
+
+  ui.brushes[which_mapping][tool].color_no = color_no;
+  if (tool == TOOL_HIGHLIGHTER && (color_rgba & 0xff) == 0xff)
+    ui.brushes[which_mapping][tool].color_rgba = color_rgba & ui.hiliter_alpha_mask;
   else
-    ui.cur_brush->color_rgba = predef_colors_rgba[color];
-  update_mapping_linkings(ui.toolno[0]);
+    ui.brushes[which_mapping][tool].color_rgba = color_rgba;
+  update_mapping_linkings(tool);
 }
 
 void recolor_temp_text(int color_no, guint color_rgba)
@@ -1446,39 +1587,40 @@ void recolor_temp_text(int color_no, guint color_rgba)
   gtk_widget_grab_focus(ui.cur_item->widget);
 }
 
-void process_color_activate(GtkMenuItem *menuitem, int color)
+void process_color_activate(GtkMenuItem *menuitem, int color_no, guint color_rgba)
 {
   if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_RADIO_MENU_ITEM) {
     if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem)))
       return;
-  } else {
+  } 
+  else if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_RADIO_TOOL_BUTTON) {
     if (!gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON (menuitem)))
       return;
   }
 
-  if (ui.cur_mapping != 0) return; // not user-generated
-  reset_focus();
+  if (ui.cur_mapping != 0 && !ui.button_switch_mapping) return; // not user-generated
 
   if (ui.cur_item_type == ITEM_TEXT)
-    recolor_temp_text(color, predef_colors_rgba[color]);
+    recolor_temp_text(color_no, color_rgba);
 
   if (ui.selection != NULL) {
-    recolor_selection(color);
+    recolor_selection(color_no, color_rgba);
     update_color_buttons();
     update_color_menu();
   }
   
-  if (ui.toolno[0] != TOOL_PEN && ui.toolno[0] != TOOL_HIGHLIGHTER
-      && ui.toolno[0] != TOOL_TEXT) {
+  if (ui.toolno[ui.cur_mapping] != TOOL_PEN && ui.toolno[ui.cur_mapping] != TOOL_HIGHLIGHTER
+      && ui.toolno[ui.cur_mapping] != TOOL_TEXT) {
     if (ui.selection != NULL) return;
+    ui.cur_mapping = 0;
     end_text();
-    ui.toolno[0] = TOOL_PEN;
-    ui.cur_brush = &(ui.brushes[0][TOOL_PEN]);
+    ui.toolno[ui.cur_mapping] = TOOL_PEN;
+    ui.cur_brush = &(ui.brushes[ui.cur_mapping][TOOL_PEN]);
     update_tool_buttons();
     update_tool_menu();
   }
   
-  set_cur_color(color);
+  set_cur_color(color_no, color_rgba);
   update_color_buttons();
   update_color_menu();
   update_cursor();
@@ -1486,6 +1628,8 @@ void process_color_activate(GtkMenuItem *menuitem, int color)
 
 void process_thickness_activate(GtkMenuItem *menuitem, int tool, int val)
 {
+  int which_mapping;
+  
   if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_RADIO_MENU_ITEM) {
     if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem)))
       return;
@@ -1494,10 +1638,9 @@ void process_thickness_activate(GtkMenuItem *menuitem, int tool, int val)
       return;
   }
 
-  if (ui.cur_mapping != 0) return; // not user-generated
+  if (ui.cur_mapping != 0 && !ui.button_switch_mapping) return; // not user-generated
 
   if (ui.selection != NULL && GTK_OBJECT_TYPE(menuitem) != GTK_TYPE_RADIO_MENU_ITEM) {
-    reset_focus();
     rethicken_selection(val);
     update_thickness_buttons();
   }
@@ -1507,11 +1650,13 @@ void process_thickness_activate(GtkMenuItem *menuitem, int tool, int val)
     return;
   }
 
-  if (ui.brushes[0][tool].thickness_no == val) return;
-  reset_focus();
+  if (ui.cur_mapping>0 && ui.linked_brush[ui.cur_mapping]!=BRUSH_LINKED)
+    which_mapping = ui.cur_mapping;
+  else which_mapping = 0;
+  if (ui.brushes[which_mapping][tool].thickness_no == val) return;
   end_text();
-  ui.brushes[0][tool].thickness_no = val;
-  ui.brushes[0][tool].thickness = predef_thickness[tool][val];
+  ui.brushes[which_mapping][tool].thickness_no = val;
+  ui.brushes[which_mapping][tool].thickness = predef_thickness[tool][val];
   update_mapping_linkings(tool);
   
   update_thickness_buttons();
@@ -1521,16 +1666,18 @@ void process_thickness_activate(GtkMenuItem *menuitem, int tool, int val)
   update_cursor();
 }
 
-void process_papercolor_activate(GtkMenuItem *menuitem, int color)
+void process_papercolor_activate(GtkMenuItem *menuitem, int color, guint rgba)
 {
   struct Page *pg;
   GList *pglist;
   gboolean hasdone;
 
-  if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem)))
-    return;
+  if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_RADIO_MENU_ITEM) {
+    if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem)))
+      return;
+  }
 
-  if ((ui.cur_page->bg->type != BG_SOLID) || ui.bg_apply_all_pages)
+  if ((ui.cur_page->bg->type != BG_SOLID) || ui.bg_apply_all_pages || color == COLOR_OTHER)
     gtk_check_menu_item_set_active(
       GTK_CHECK_MENU_ITEM(GET_COMPONENT("papercolorNA")), TRUE);
 
@@ -1538,7 +1685,7 @@ void process_papercolor_activate(GtkMenuItem *menuitem, int color)
   hasdone = FALSE;
   for (pglist = journal.pages; pglist!=NULL; pglist = pglist->next) {
     if (ui.bg_apply_all_pages) pg = (struct Page *)pglist->data;
-    if (pg->bg->type == BG_SOLID && pg->bg->color_no != color) {
+    if (pg->bg->type == BG_SOLID && pg->bg->color_rgba != rgba) {
       prepare_new_undo();
       if (hasdone) undo->multiop |= MULTIOP_CONT_UNDO;
       undo->multiop |= MULTIOP_CONT_REDO;
@@ -1549,7 +1696,7 @@ void process_papercolor_activate(GtkMenuItem *menuitem, int color)
       undo->bg->canvas_item = NULL;
 
       pg->bg->color_no = color;
-      pg->bg->color_rgba = predef_bgcolors_rgba[color];
+      pg->bg->color_rgba = rgba;
       update_canvas_bg(pg);
     }
     if (!ui.bg_apply_all_pages) break;
@@ -1602,6 +1749,10 @@ void process_paperstyle_activate(GtkMenuItem *menuitem, int style)
   if (must_upd) update_page_stuff();
 }
 
+#ifndef GTK_STOCK_DISCARD
+#define GTK_STOCK_DISCARD GTK_STOCK_NO
+#endif
+
 gboolean ok_to_close(void)
 {
   GtkWidget *dialog;
@@ -1609,9 +1760,12 @@ gboolean ok_to_close(void)
 
   if (ui.saved) return TRUE;
   dialog = gtk_message_dialog_new(GTK_WINDOW (winMain), GTK_DIALOG_DESTROY_WITH_PARENT,
-    GTK_MESSAGE_WARNING, GTK_BUTTONS_YES_NO, "Save changes to '%s'?",
-    (ui.filename!=NULL) ? ui.filename:"Untitled");
+    GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, _("Save changes to '%s'?"),
+    (ui.filename!=NULL) ? ui.filename:_("Untitled"));
+  gtk_dialog_add_button(GTK_DIALOG (dialog), GTK_STOCK_DISCARD, GTK_RESPONSE_NO);
+  gtk_dialog_add_button(GTK_DIALOG (dialog), GTK_STOCK_SAVE, GTK_RESPONSE_YES);
   gtk_dialog_add_button(GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+  gtk_dialog_set_default_response(GTK_DIALOG (dialog), GTK_RESPONSE_YES);
   response = gtk_dialog_run(GTK_DIALOG (dialog));
   gtk_widget_destroy(dialog);
   if (response == GTK_RESPONSE_CANCEL || response == GTK_RESPONSE_DELETE_EVENT) 
@@ -1624,13 +1778,13 @@ gboolean ok_to_close(void)
 }
 
 // send the focus back to the appropriate widget
+
 void reset_focus(void)
 {
   if (ui.cur_item_type == ITEM_TEXT)
     gtk_widget_grab_focus(ui.cur_item->widget);
   else
     gtk_widget_grab_focus(GTK_WIDGET(canvas));
-  reset_recognizer();
 }
 
 // selection / clipboard stuff
@@ -1665,7 +1819,8 @@ void move_journal_items_by(GList *itemlist, double dx, double dy,
     if (item->type == ITEM_STROKE)
       for (pt=item->path->coords, i=0; i<item->path->num_points; i++, pt+=2)
         { pt[0] += dx; pt[1] += dy; }
-    if (item->type == ITEM_STROKE || item->type == ITEM_TEXT || item->type == ITEM_TEMP_TEXT) {
+    if (item->type == ITEM_STROKE || item->type == ITEM_TEXT || 
+        item->type == ITEM_TEMP_TEXT || item->type == ITEM_IMAGE) {
       item->bbox.left += dx;
       item->bbox.right += dx;
       item->bbox.top += dy;
@@ -1748,6 +1903,22 @@ void resize_journal_items_by(GList *itemlist, double scaling_x, double scaling_y
       item->bbox.left = item->bbox.left*scaling_x + offset_x;
       item->bbox.top = item->bbox.top*scaling_y + offset_y;
     }
+    if (item->type == ITEM_IMAGE) {
+      item->bbox.left = item->bbox.left*scaling_x + offset_x;
+      item->bbox.right = item->bbox.right*scaling_x + offset_x;
+      item->bbox.top = item->bbox.top*scaling_y + offset_y;
+      item->bbox.bottom = item->bbox.bottom*scaling_y + offset_y;
+      if (item->bbox.left > item->bbox.right) {
+        temp = item->bbox.left;
+        item->bbox.left = item->bbox.right;
+        item->bbox.right = temp;
+      }
+      if (item->bbox.top > item->bbox.bottom) {
+        temp = item->bbox.top;
+        item->bbox.top = item->bbox.bottom;
+        item->bbox.bottom = temp;
+      }
+    }
     // redraw the item
     if (item->canvas_item!=NULL) {
       group = (GnomeCanvasGroup *) item->canvas_item->parent;
@@ -1760,7 +1931,9 @@ void resize_journal_items_by(GList *itemlist, double scaling_x, double scaling_y
 // Switch between button mappings
 
 /* NOTE ABOUT BUTTON MAPPINGS: ui.cur_mapping is 0 except while a canvas
-   click event is being processed ... */
+   click event is being processed ... or if ui.button_switch_mapping is
+   enabled and mappings are switched (but even then, canvas should have
+   a pointer grab from the initial click that switched the mapping) */
 
 void switch_mapping(int m)
 {
@@ -1771,6 +1944,8 @@ void switch_mapping(int m)
     ui.cur_brush = &(ui.brushes[m][ui.toolno[m]]);
   if (ui.toolno[m] == TOOL_TEXT)
     ui.cur_brush = &(ui.brushes[m][TOOL_PEN]);
+  if (m==0) ui.which_unswitch_button = 0;
+  
   update_tool_buttons();
   update_color_menu();
   update_cursor();
@@ -1779,10 +1954,10 @@ void switch_mapping(int m)
 void process_mapping_activate(GtkMenuItem *menuitem, int m, int tool)
 {
   if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))) return;
-  if (ui.cur_mapping!=0) return;
+  if (ui.cur_mapping!=0 && !ui.button_switch_mapping) return;
   if (ui.toolno[m] == tool) return;
+  switch_mapping(0);
   end_text();
-  reset_focus();
     
   ui.toolno[m] = tool;
   if (ui.linked_brush[m] == BRUSH_COPIED) {
@@ -1846,6 +2021,15 @@ gboolean can_accel(GtkWidget *widget, guint id, gpointer data)
   return GTK_WIDGET_SENSITIVE(widget);
 }
 
+gboolean can_accel_except_text(GtkWidget *widget, guint id, gpointer data)
+{
+  if (ui.cur_item_type == ITEM_TEXT) {
+    g_signal_stop_emission_by_name(widget, "can-activate-accel");
+    return FALSE;
+  }
+  return GTK_WIDGET_SENSITIVE(widget);
+}
+
 void allow_all_accels(void)
 {
   g_signal_connect((gpointer) GET_COMPONENT("fileNew"),
@@ -1885,9 +2069,9 @@ void allow_all_accels(void)
   g_signal_connect((gpointer) GET_COMPONENT("viewFirstPage"),
       "can-activate-accel", G_CALLBACK(can_accel), NULL);
   g_signal_connect((gpointer) GET_COMPONENT("viewPreviousPage"),
-      "can-activate-accel", G_CALLBACK(can_accel), NULL);
+      "can-activate-accel", G_CALLBACK(can_accel_except_text), NULL);
   g_signal_connect((gpointer) GET_COMPONENT("viewNextPage"),
-      "can-activate-accel", G_CALLBACK(can_accel), NULL);
+      "can-activate-accel", G_CALLBACK(can_accel_except_text), NULL);
   g_signal_connect((gpointer) GET_COMPONENT("viewLastPage"),
       "can-activate-accel", G_CALLBACK(can_accel), NULL);
   g_signal_connect((gpointer) GET_COMPONENT("toolsPen"),
@@ -1961,17 +2145,263 @@ void hide_unimplemented(void)
 {
   gtk_widget_hide(GET_COMPONENT("filePrintOptions"));
   gtk_widget_hide(GET_COMPONENT("journalFlatten"));  
-  gtk_widget_hide(GET_COMPONENT("papercolorOther")); 
   gtk_widget_hide(GET_COMPONENT("toolsSelectRegion"));
   gtk_widget_hide(GET_COMPONENT("buttonSelectRegion"));
   gtk_widget_hide(GET_COMPONENT("button2SelectRegion"));
   gtk_widget_hide(GET_COMPONENT("button3SelectRegion"));
-  gtk_widget_hide(GET_COMPONENT("colorOther"));
   gtk_widget_hide(GET_COMPONENT("helpIndex")); 
 
-  /* config file only works with glib 2.6 */
+  /* config file only works with glib 2.6 and beyond */
   if (glib_minor_version<6) {
     gtk_widget_hide(GET_COMPONENT("optionsAutoSavePrefs"));
     gtk_widget_hide(GET_COMPONENT("optionsSavePreferences"));
   }
+  /* gtkprint only works with gtk+ 2.10 and beyond */
+  if (gtk_check_version(2, 10, 0)) {
+    gtk_widget_hide(GET_COMPONENT("filePrint"));
+  }  
+  
+  /* screenshot feature doesn't work yet in Win32 */
+#ifdef WIN32
+  gtk_widget_hide(GET_COMPONENT("journalScreenshot"));
+#endif
 }  
+
+// toggle fullscreen mode
+void do_fullscreen(gboolean active)
+{
+  end_text();
+  ui.fullscreen = active;
+  gtk_check_menu_item_set_active(
+    GTK_CHECK_MENU_ITEM(GET_COMPONENT("viewFullscreen")), ui.fullscreen);
+  gtk_toggle_tool_button_set_active(
+    GTK_TOGGLE_TOOL_BUTTON(GET_COMPONENT("buttonFullscreen")), ui.fullscreen);
+
+  if (ui.fullscreen) {
+#ifdef WIN32
+    gtk_window_get_size(GTK_WINDOW(winMain), &ui.pre_fullscreen_width, &ui.pre_fullscreen_height);
+    gtk_widget_set_size_request(GTK_WIDGET(winMain), gdk_screen_width(),
+                                                     gdk_screen_height());
+#endif
+    gtk_window_fullscreen(GTK_WINDOW(winMain));
+  }
+  else {
+#ifdef WIN32
+    gtk_widget_set_size_request(GTK_WIDGET(winMain), -1, -1);
+    gtk_window_resize(GTK_WINDOW(winMain), ui.pre_fullscreen_width,
+                                           ui.pre_fullscreen_height);
+#endif
+    gtk_window_unfullscreen(GTK_WINDOW(winMain));
+  }
+
+  update_vbox_order(ui.vertical_order[ui.fullscreen?1:0]);
+}
+
+/* attempt to work around GTK+ 2.16/2.17 bugs where random interface
+   elements receive XInput events that they can't handle properly    */
+
+// prevent interface items from getting bogus XInput events
+
+gboolean filter_extended_events (GtkWidget *widget, GdkEvent *event,
+                                   gpointer user_data)
+{
+  if (event->type == GDK_MOTION_NOTIFY &&
+      event->motion.device != gdk_device_get_core_pointer())
+    return TRUE;
+  if ((event->type == GDK_BUTTON_PRESS || event->type == GDK_2BUTTON_PRESS ||
+      event->type == GDK_3BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) &&
+      event->button.device != gdk_device_get_core_pointer())
+    return TRUE;
+  return FALSE;
+}
+
+/* Code to turn an extended input event into a core event and send it to
+   a different GdkWindow -- e.g. could be used when a click in a text edit box
+   gets sent to the canvas instead due to incorrect event translation.
+   We now turn off xinput altogether while editing text under GTK+ 2.17, so
+   this isn't needed any more... but could become useful again someday!
+*/
+
+/*  
+gboolean fix_extended_events (GtkWidget *widget, GdkEvent *event,
+                                   gpointer user_data)
+{
+  int ix, iy;
+  GdkWindow *window;
+
+  if (user_data) window = (GdkWindow *)user_data;
+  else window = widget->window;
+
+  if (event->type == GDK_MOTION_NOTIFY &&
+      event->motion.device != gdk_device_get_core_pointer()) {
+//    printf("fixing motion\n");
+    gdk_window_get_pointer(window, &ix, &iy, NULL);
+    event->motion.x = ix; event->motion.y = iy;
+    event->motion.device = gdk_device_get_core_pointer();
+    g_object_unref(event->motion.window);
+    event->motion.window = g_object_ref(window);
+    gtk_widget_event(widget, event);
+    return TRUE;
+  }
+  if ((event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) &&
+      event->button.device != gdk_device_get_core_pointer()) {
+//    printf("fixing button from pos = %f, %f\n", event->button.x, event->button.y);
+    gdk_window_get_pointer(window, &ix, &iy, NULL);
+    event->button.x = ix; event->button.y = iy;
+    event->button.device = gdk_device_get_core_pointer();
+    g_object_unref(event->button.window);
+    event->button.window = g_object_ref(window);
+//    printf("fixing button to pos = %f, %f\n", event->button.x, event->button.y);
+    gtk_widget_event(widget, event);
+    return TRUE;
+  }
+  return FALSE;
+}
+*/
+
+
+/* When enter is pressed into page spinbox, send focus back to canvas. */
+
+gboolean handle_activate_signal(GtkWidget *widget, gpointer user_data)
+{
+  reset_focus();
+  return FALSE;
+}
+
+/* recursively unset widget flags */
+
+void unset_flags(GtkWidget *w, gpointer flag)
+{
+  GTK_WIDGET_UNSET_FLAGS(w, (GtkWidgetFlags)flag);
+  if(GTK_IS_CONTAINER(w))
+    gtk_container_forall(GTK_CONTAINER(w), unset_flags, flag);
+}
+
+/* reset focus when a key or button press event reaches someone, or when the
+   page-number spin button should relinquish control... */
+
+gboolean intercept_activate_events(GtkWidget *w, GdkEvent *ev, gpointer data)
+{
+  if (w == GET_COMPONENT("hbox1")) {
+    /* the event won't be processed since the hbox1 doesn't know what to do with it,
+       so we might as well kill it and avoid confusing ourselves when it gets
+       propagated further ... */
+    return TRUE;
+  }
+  if (w == GET_COMPONENT("spinPageNo")) {
+    /* we let the spin button take care of itself, and don't steal its focus,
+       unless the user presses Esc or Tab (in those cases we intervene) */
+    if (ev->type != GDK_KEY_PRESS) return FALSE;
+    if (ev->key.keyval == GDK_Escape) 
+       gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), ui.pageno+1); // abort
+    else if (ev->key.keyval != GDK_Tab && ev->key.keyval != GDK_ISO_Left_Tab)
+       return FALSE; // let the spin button process it
+  }
+
+  // otherwise, we want to make sure the canvas or text item gets focus back...
+  reset_focus();  
+  return FALSE;
+}
+
+void install_focus_hooks(GtkWidget *w, gpointer data)
+{
+  if (w == NULL) return;
+  g_signal_connect(w, "key-press-event", G_CALLBACK(intercept_activate_events), data);
+  g_signal_connect(w, "button-press-event", G_CALLBACK(intercept_activate_events), data);
+  if (GTK_IS_MENU_ITEM(w)) {
+    g_signal_connect(w, "activate", G_CALLBACK(intercept_activate_events), data);
+    install_focus_hooks(gtk_menu_item_get_submenu(GTK_MENU_ITEM(w)), data);
+  }
+  if(GTK_IS_CONTAINER(w))
+    gtk_container_forall(GTK_CONTAINER(w), install_focus_hooks, data);
+}
+
+// wrapper for missing poppler functions (defunct poppler-gdk api)
+
+static void
+wrapper_copy_cairo_surface_to_pixbuf (cairo_surface_t *surface,
+                             GdkPixbuf       *pixbuf)
+{
+  int cairo_width, cairo_height, cairo_rowstride;
+  unsigned char *pixbuf_data, *dst, *cairo_data;
+  int pixbuf_rowstride, pixbuf_n_channels;
+  unsigned int *src;
+  int x, y;
+
+  cairo_width = cairo_image_surface_get_width (surface);
+  cairo_height = cairo_image_surface_get_height (surface);
+  cairo_rowstride = cairo_image_surface_get_stride (surface);
+  cairo_data = cairo_image_surface_get_data (surface);
+
+  pixbuf_data = gdk_pixbuf_get_pixels (pixbuf);
+  pixbuf_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+  pixbuf_n_channels = gdk_pixbuf_get_n_channels (pixbuf);
+
+  if (cairo_width > gdk_pixbuf_get_width (pixbuf))
+    cairo_width = gdk_pixbuf_get_width (pixbuf);
+  if (cairo_height > gdk_pixbuf_get_height (pixbuf))
+    cairo_height = gdk_pixbuf_get_height (pixbuf);
+  for (y = 0; y < cairo_height; y++)
+    {
+      src = (unsigned int *) (cairo_data + y * cairo_rowstride);
+      dst = pixbuf_data + y * pixbuf_rowstride;
+      for (x = 0; x < cairo_width; x++) 
+       {
+         dst[0] = (*src >> 16) & 0xff;
+         dst[1] = (*src >> 8) & 0xff; 
+         dst[2] = (*src >> 0) & 0xff;
+         if (pixbuf_n_channels == 4)
+             dst[3] = (*src >> 24) & 0xff;
+         dst += pixbuf_n_channels;
+         src++;
+       }
+    }
+}      
+
+void
+wrapper_poppler_page_render_to_pixbuf (PopplerPage *page,
+                              int src_x, int src_y,
+                              int src_width, int src_height,
+                              double scale,
+                              int rotation,
+                              GdkPixbuf *pixbuf)
+{
+  cairo_t *cr;
+  cairo_surface_t *surface;
+
+  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+                                       src_width, src_height);
+  cr = cairo_create (surface);
+  cairo_save (cr);
+  switch (rotation) {
+  case 90:
+         cairo_translate (cr, src_x + src_width, -src_y);
+         break;
+  case 180:
+         cairo_translate (cr, src_x + src_width, src_y + src_height);
+         break;
+  case 270:
+         cairo_translate (cr, -src_x, src_y + src_height);
+         break;
+  default:
+         cairo_translate (cr, -src_x, -src_y);
+  }
+
+  if (scale != 1.0)
+         cairo_scale (cr, scale, scale);
+
+  if (rotation != 0)
+         cairo_rotate (cr, rotation * G_PI / 180.0);
+
+  poppler_page_render (page, cr);
+  cairo_restore (cr);
+
+  cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
+  cairo_set_source_rgb (cr, 1., 1., 1.);
+  cairo_paint (cr);
+
+  cairo_destroy (cr);
+
+  wrapper_copy_cairo_surface_to_pixbuf (surface, pixbuf);
+  cairo_surface_destroy (surface);
+}