]> git.donarmstrong.com Git - xournal.git/blobdiff - src/xo-callbacks.c
Image patch
[xournal.git] / src / xo-callbacks.c
index b1b35bb732cdae157317539a8b6edf0137154a6e..8c6f098a1cdc88566305da6b6181386ad3960a0d 100644 (file)
@@ -1,3 +1,19 @@
+/*
+ *  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
@@ -25,7 +41,6 @@ on_fileNew_activate                    (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   if (close_journal()) {
     new_journal();
     ui.zoom = ui.startup_zoom;
@@ -47,12 +62,14 @@ on_fileNewBackground_activate          (GtkMenuItem     *menuitem,
   gboolean success;
   
   end_text();
-  reset_focus();
   if (!ok_to_close()) return; // user aborted on save confirmation
   
   dialog = gtk_file_chooser_dialog_new(_("Open PDF"), GTK_WINDOW (winMain),
      GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
      GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
+#ifdef FILE_DIALOG_SIZE_BUGFIX
+  gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 400);
+#endif
      
   filt_all = gtk_file_filter_new();
   gtk_file_filter_set_name(filt_all, _("All files"));
@@ -118,12 +135,14 @@ on_fileOpen_activate                   (GtkMenuItem     *menuitem,
   gboolean success;
   
   end_text();
-  reset_focus();
   if (!ok_to_close()) return; // user aborted on save confirmation
   
   dialog = gtk_file_chooser_dialog_new(_("Open Journal"), GTK_WINDOW (winMain),
      GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
      GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
+#ifdef FILE_DIALOG_SIZE_BUGFIX
+  gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 400);
+#endif
      
   filt_all = gtk_file_filter_new();
   gtk_file_filter_set_name(filt_all, _("All files"));
@@ -165,7 +184,6 @@ on_fileSave_activate                   (GtkMenuItem     *menuitem,
   GtkWidget *dialog;
   
   end_text();
-  reset_focus();
   if (ui.filename == NULL) {
     on_fileSaveAs_activate(menuitem, user_data);
     return;
@@ -198,10 +216,12 @@ on_fileSaveAs_activate                 (GtkMenuItem     *menuitem,
   struct stat stat_buf;
   
   end_text();
-  reset_focus();
   dialog = gtk_file_chooser_dialog_new(_("Save Journal"), GTK_WINDOW (winMain),
      GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
      GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
+#ifdef FILE_DIALOG_SIZE_BUGFIX
+  gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 400);
+#endif
      
   if (ui.filename!=NULL) {
     gtk_file_chooser_set_filename(GTK_FILE_CHOOSER (dialog), ui.filename);
@@ -217,7 +237,7 @@ on_fileSaveAs_activate                 (GtkMenuItem     *menuitem,
   }
   else {
     curtime = time(NULL);
-    strftime(stime, 30, "%F-Note-%H-%M.xoj", localtime(&curtime));
+    strftime(stime, 30, "%Y-%m-%d-Note-%H-%M.xoj", localtime(&curtime));
     if (ui.default_path!=NULL)
       gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (dialog), ui.default_path);
     gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), stime);
@@ -299,7 +319,6 @@ on_filePrint_activate                  (GtkMenuItem     *menuitem,
   char *in_fn, *p;
 
   end_text();
-  reset_focus();
   if (!gtk_check_version(2, 10, 0)) {
     print = gtk_print_operation_new();
 /*
@@ -353,10 +372,12 @@ on_filePrintPDF_activate               (GtkMenuItem     *menuitem,
   gboolean warn;
   
   end_text();
-  reset_focus();
   dialog = gtk_file_chooser_dialog_new(_("Export to PDF"), GTK_WINDOW (winMain),
      GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
      GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
+#ifdef FILE_DIALOG_SIZE_BUGFIX
+  gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 400);
+#endif
      
   if (ui.filename!=NULL) {
     if (g_str_has_suffix(ui.filename, ".xoj")) {
@@ -369,7 +390,7 @@ on_filePrintPDF_activate               (GtkMenuItem     *menuitem,
     gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), g_basename(in_fn));
   } else {
     curtime = time(NULL);
-    strftime(stime, 30, "%F-Note-%H-%M.pdf", localtime(&curtime));
+    strftime(stime, 30, "%Y-%m-%d-Note-%H-%M.pdf", localtime(&curtime));
     if (ui.default_path!=NULL)
       gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (dialog), ui.default_path);
     gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), stime);
@@ -425,7 +446,6 @@ on_fileQuit_activate                   (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   if (ok_to_close()) gtk_main_quit ();
 }
 
@@ -445,10 +465,10 @@ on_editUndo_activate                   (GtkMenuItem     *menuitem,
   GnomeCanvasGroup *group;
   
   end_text();
-  reset_focus();
   if (undo == NULL) return; // nothing to undo!
   reset_selection(); // safer
-  if (undo->type == ITEM_STROKE || undo->type == ITEM_TEXT) {
+  reset_recognizer(); // safer
+  if (undo->type == ITEM_STROKE || undo->type == ITEM_TEXT || undo->type == ITEM_IMAGE) {
     // we're keeping the stroke info, but deleting the canvas item
     gtk_object_destroy(GTK_OBJECT(undo->item->canvas_item));
     undo->item->canvas_item = NULL;
@@ -659,10 +679,10 @@ on_editRedo_activate                   (GtkMenuItem     *menuitem,
   GnomeCanvasGroup *group;
   
   end_text();
-  reset_focus();
   if (redo == NULL) return; // nothing to redo!
   reset_selection(); // safer
-  if (redo->type == ITEM_STROKE || redo->type == ITEM_TEXT) {
+  reset_recognizer(); // safer
+  if (redo->type == ITEM_STROKE || redo->type == ITEM_TEXT || redo->type == ITEM_IMAGE) {
     // re-create the canvas_item
     make_canvas_item_one(redo->layer->group, redo->item);
     // reinsert the item on its layer
@@ -820,6 +840,12 @@ on_editRedo_activate                   (GtkMenuItem     *menuitem,
       if (it->type == ITEM_TEXT && it->canvas_item != NULL)
         gnome_canvas_item_set(it->canvas_item, 
           "fill-color-rgba", it->brush.color_rgba, NULL);
+      if (it->type == ITEM_IMAGE && it->canvas_item != NULL) {
+        // remark: a variable-width item might have lost its variable-width
+        group = (GnomeCanvasGroup *) it->canvas_item->parent;
+        gtk_object_destroy(GTK_OBJECT(it->canvas_item));
+        make_canvas_item_one(group, it);
+      }
     }
   }
   else if (redo->type == ITEM_TEXT_EDIT) {
@@ -861,7 +887,6 @@ on_editCut_activate                    (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   selection_to_clip();
   selection_delete();
 }
@@ -872,7 +897,6 @@ on_editCopy_activate                   (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   selection_to_clip();
 }
 
@@ -882,7 +906,6 @@ on_editPaste_activate                  (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   clipboard_paste();
 }
 
@@ -892,7 +915,6 @@ on_editDelete_activate                 (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   selection_delete();
 }
 
@@ -905,7 +927,6 @@ on_viewContinuous_activate             (GtkMenuItem     *menuitem,
   double yscroll;
   struct Page *pg;
 
-  reset_focus();
   if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem))) return;
   if (ui.view_continuous) return;
   ui.view_continuous = TRUE;
@@ -926,7 +947,6 @@ on_viewOnePage_activate                (GtkMenuItem     *menuitem,
   GtkAdjustment *v_adj;
   double yscroll;
   
-  reset_focus();
   if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem))) return;
   if (!ui.view_continuous) return;
   ui.view_continuous = FALSE;
@@ -943,12 +963,12 @@ void
 on_viewZoomIn_activate                 (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
-  reset_focus();
   if (ui.zoom > MAX_ZOOM) return;
   ui.zoom *= ui.zoom_step_factor;
   gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
   rescale_text_items();
   rescale_bg_pixmaps();
+  rescale_images();
 }
 
 
@@ -956,12 +976,12 @@ void
 on_viewZoomOut_activate                (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
-  reset_focus();
   if (ui.zoom < MIN_ZOOM) return;
   ui.zoom /= ui.zoom_step_factor;
   gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
   rescale_text_items();
   rescale_bg_pixmaps();
+  rescale_images();
 }
 
 
@@ -969,11 +989,11 @@ void
 on_viewNormalSize_activate             (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
-  reset_focus();
   ui.zoom = DEFAULT_ZOOM;
   gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
   rescale_text_items();
   rescale_bg_pixmaps();
+  rescale_images();
 }
 
 
@@ -981,11 +1001,11 @@ void
 on_viewPageWidth_activate              (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
-  reset_focus();
   ui.zoom = (GTK_WIDGET(canvas))->allocation.width/ui.cur_page->width;
   gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
   rescale_text_items();
   rescale_bg_pixmaps();
+  rescale_images();
 }
 
 
@@ -994,7 +1014,6 @@ on_viewFirstPage_activate              (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   do_switch_page(0, TRUE, FALSE);
 }
 
@@ -1004,7 +1023,6 @@ on_viewPreviousPage_activate           (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   if (ui.pageno == 0) return;
   do_switch_page(ui.pageno-1, TRUE, FALSE);
 }
@@ -1015,7 +1033,6 @@ on_viewNextPage_activate               (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   if (ui.pageno == journal.npages-1) { // create a page at end
     on_journalNewPageEnd_activate(menuitem, user_data);
     return;
@@ -1029,7 +1046,6 @@ on_viewLastPage_activate               (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   do_switch_page(journal.npages-1, TRUE, FALSE);
 }
 
@@ -1039,7 +1055,6 @@ on_viewShowLayer_activate              (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   if (ui.layerno == ui.cur_page->nlayers-1) return;
   reset_selection();
   ui.layerno++;
@@ -1054,7 +1069,6 @@ on_viewHideLayer_activate              (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   if (ui.layerno == -1) return;
   reset_selection();
   gnome_canvas_item_hide(GNOME_CANVAS_ITEM(ui.cur_layer->group));
@@ -1072,7 +1086,6 @@ on_journalNewPageBefore_activate       (GtkMenuItem     *menuitem,
   struct Page *pg;
 
   end_text();
-  reset_focus();
   reset_selection();
   pg = new_page(ui.cur_page);
   journal.pages = g_list_insert(journal.pages, pg, ui.pageno);
@@ -1093,7 +1106,6 @@ on_journalNewPageAfter_activate        (GtkMenuItem     *menuitem,
   struct Page *pg;
 
   end_text();
-  reset_focus();
   reset_selection();
   pg = new_page(ui.cur_page);
   journal.pages = g_list_insert(journal.pages, pg, ui.pageno+1);
@@ -1114,7 +1126,6 @@ on_journalNewPageEnd_activate          (GtkMenuItem     *menuitem,
   struct Page *pg;
 
   end_text();
-  reset_focus();
   reset_selection();
   pg = new_page((struct Page *)g_list_last(journal.pages)->data);
   journal.pages = g_list_append(journal.pages, pg);
@@ -1136,9 +1147,9 @@ on_journalDeletePage_activate          (GtkMenuItem     *menuitem,
   struct Layer *l;
 
   end_text();
-  reset_focus();
   if (journal.npages == 1) return;
   reset_selection();  
+  reset_recognizer(); // safer
   prepare_new_undo();
   undo->type = ITEM_DELETE_PAGE;
   undo->val = ui.pageno;
@@ -1171,7 +1182,6 @@ on_journalNewLayer_activate            (GtkMenuItem     *menuitem,
   struct Layer *l;
   
   end_text();
-  reset_focus();
   reset_selection();
   l = g_new(struct Layer, 1);
   l->items = NULL;
@@ -1201,9 +1211,9 @@ on_journalDeleteLayer_activate         (GtkMenuItem     *menuitem,
   GList *list;
   
   end_text();
-  reset_focus();
   if (ui.cur_layer == NULL) return;
   reset_selection();
+  reset_recognizer(); // safer
   prepare_new_undo();
   undo->type = ITEM_DELETE_LAYER;
   undo->val = ui.layerno;
@@ -1274,7 +1284,6 @@ on_journalPaperSize_activate           (GtkMenuItem     *menuitem,
   GList *pglist;
   
   end_text();
-  reset_focus();
   papersize_dialog = create_papersizeDialog();
   papersize_width = ui.cur_page->width;
   papersize_height = ui.cur_page->height;
@@ -1325,8 +1334,7 @@ on_papercolorWhite_activate            (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
-  process_papercolor_activate(menuitem, COLOR_WHITE);
+  process_papercolor_activate(menuitem, COLOR_WHITE, predef_bgcolors_rgba[COLOR_WHITE]);
 }
 
 
@@ -1335,8 +1343,7 @@ on_papercolorYellow_activate           (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
-  process_papercolor_activate(menuitem, COLOR_YELLOW);
+  process_papercolor_activate(menuitem, COLOR_YELLOW, predef_bgcolors_rgba[COLOR_YELLOW]);
 }
 
 
@@ -1345,8 +1352,7 @@ on_papercolorPink_activate             (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
-  process_papercolor_activate(menuitem, COLOR_RED);
+  process_papercolor_activate(menuitem, COLOR_RED, predef_bgcolors_rgba[COLOR_RED]);
 }
 
 
@@ -1355,8 +1361,7 @@ on_papercolorOrange_activate           (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
-  process_papercolor_activate(menuitem, COLOR_ORANGE);
+  process_papercolor_activate(menuitem, COLOR_ORANGE, predef_bgcolors_rgba[COLOR_ORANGE]);
 }
 
 
@@ -1365,8 +1370,7 @@ on_papercolorBlue_activate             (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
-  process_papercolor_activate(menuitem, COLOR_BLUE);
+  process_papercolor_activate(menuitem, COLOR_BLUE, predef_bgcolors_rgba[COLOR_BLUE]);
 }
 
 
@@ -1375,8 +1379,7 @@ on_papercolorGreen_activate            (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
-  process_papercolor_activate(menuitem, COLOR_GREEN);
+  process_papercolor_activate(menuitem, COLOR_GREEN, predef_bgcolors_rgba[COLOR_GREEN]);
 }
 
 
@@ -1384,7 +1387,25 @@ void
 on_papercolorOther_activate            (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
-
+  GtkWidget *dialog;
+  GtkColorSelection *colorsel;
+  gint result;
+  guint rgba;
+  GdkColor gdkcolor;
+  
+  end_text();
+  dialog = gtk_color_selection_dialog_new(_("Pick a Paper Color"));
+  colorsel = GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(dialog)->colorsel);
+  if (ui.cur_page->bg->type == BG_SOLID) rgba = ui.cur_page->bg->color_rgba;
+  else rgba = ui.default_page.bg->color_rgba;
+  rgb_to_gdkcolor(rgba, &gdkcolor);
+  gtk_color_selection_set_current_color(colorsel, &gdkcolor);
+  
+  if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
+    gtk_color_selection_get_current_color(colorsel, &gdkcolor);
+    process_papercolor_activate(menuitem, COLOR_OTHER, gdkcolor_to_rgba(gdkcolor, 0xffff));
+  }
+  gtk_widget_destroy(dialog);
 }
 
 
@@ -1393,7 +1414,6 @@ on_paperstylePlain_activate            (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   process_paperstyle_activate(menuitem, RULING_NONE);
 }
 
@@ -1403,7 +1423,6 @@ on_paperstyleLined_activate            (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   process_paperstyle_activate(menuitem, RULING_LINED);
 }
 
@@ -1413,7 +1432,6 @@ on_paperstyleRuled_activate            (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   process_paperstyle_activate(menuitem, RULING_RULED);
 }
 
@@ -1423,7 +1441,6 @@ on_paperstyleGraph_activate            (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   process_paperstyle_activate(menuitem, RULING_GRAPH);
 }
 
@@ -1442,10 +1459,12 @@ on_journalLoadBackground_activate      (GtkMenuItem     *menuitem,
   gboolean attach;
   
   end_text();
-  reset_focus();
   dialog = gtk_file_chooser_dialog_new(_("Open Background"), GTK_WINDOW (winMain),
      GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
      GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
+#ifdef FILE_DIALOG_SIZE_BUGFIX
+  gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 400);
+#endif
 
   filt_all = gtk_file_filter_new();
   gtk_file_filter_set_name(filt_all, _("All files"));
@@ -1546,6 +1565,7 @@ on_journalLoadBackground_activate      (GtkMenuItem     *menuitem,
     gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
     rescale_text_items();
     rescale_bg_pixmaps();
+    rescale_images();
   }
   do_switch_page(ui.pageno, TRUE, TRUE);
 }
@@ -1557,7 +1577,6 @@ on_journalScreenshot_activate          (GtkMenuItem     *menuitem,
   struct Background *bg;
   
   end_text();
-  reset_focus();
   reset_selection();
   gtk_window_iconify(GTK_WINDOW(winMain)); // hide ourselves
   gdk_display_sync(gdk_display_get_default());
@@ -1593,6 +1612,7 @@ on_journalScreenshot_activate          (GtkMenuItem     *menuitem,
     gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
     rescale_text_items();
     rescale_bg_pixmaps();
+    rescale_images();
   }
   do_switch_page(ui.pageno, TRUE, TRUE);
 }
@@ -1605,7 +1625,6 @@ on_journalApplyAllPages_activate       (GtkMenuItem     *menuitem,
   gboolean active;
   
   end_text();
-  reset_focus();
   active = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
   if (active == ui.bg_apply_all_pages) return;
   ui.bg_apply_all_pages = active;
@@ -1659,7 +1678,6 @@ on_toolsPen_activate                   (GtkMenuItem     *menuitem,
 
   ui.cur_mapping = 0; // don't use switch_mapping() (refreshes buttons too soon)
   end_text();
-  reset_focus();
   reset_selection();
   ui.toolno[ui.cur_mapping] = TOOL_PEN;
   ui.cur_brush = &(ui.brushes[ui.cur_mapping][TOOL_PEN]);
@@ -1690,7 +1708,6 @@ on_toolsEraser_activate                (GtkMenuItem     *menuitem,
   
   ui.cur_mapping = 0; // don't use switch_mapping() (refreshes buttons too soon)
   end_text();
-  reset_focus();
   reset_selection();
   ui.toolno[ui.cur_mapping] = TOOL_ERASER;
   ui.cur_brush = &(ui.brushes[ui.cur_mapping][TOOL_ERASER]);
@@ -1719,7 +1736,6 @@ on_toolsHighlighter_activate           (GtkMenuItem     *menuitem,
   
   ui.cur_mapping = 0; // don't use switch_mapping() (refreshes buttons too soon)
   end_text();
-  reset_focus();
   reset_selection();
   ui.toolno[ui.cur_mapping] = TOOL_HIGHLIGHTER;
   ui.cur_brush = &(ui.brushes[ui.cur_mapping][TOOL_HIGHLIGHTER]);
@@ -1749,7 +1765,6 @@ on_toolsText_activate                  (GtkMenuItem     *menuitem,
   if (ui.toolno[ui.cur_mapping] == TOOL_TEXT) return;
   
   ui.cur_mapping = 0; // don't use switch_mapping() (refreshes buttons too soon)
-  reset_focus();
   reset_selection();
   ui.toolno[ui.cur_mapping] = TOOL_TEXT;
   ui.cur_brush = &(ui.brushes[ui.cur_mapping][TOOL_PEN]);
@@ -1761,6 +1776,33 @@ on_toolsText_activate                  (GtkMenuItem     *menuitem,
 }
 
 
+void
+on_toolsImage_activate                 (GtkMenuItem *menuitem,
+                                        gpointer         user_data)
+{
+  if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_RADIO_MENU_ITEM) {
+    if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem)))
+      return;
+  } else {
+    if (!gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON (menuitem)))
+      return;
+  }
+  
+  if (ui.cur_mapping != 0 && !ui.button_switch_mapping) return; // not user-generated
+  if (ui.toolno[ui.cur_mapping] == TOOL_IMAGE) return;
+  
+  ui.cur_mapping = 0; // don't use switch_mapping() (refreshes buttons too soon)
+  end_text();
+  reset_selection();
+  ui.toolno[ui.cur_mapping] = TOOL_IMAGE;
+  update_mapping_linkings(-1);
+  update_tool_buttons();
+  update_tool_menu();
+  update_color_menu();
+  update_cursor();
+}
+
+
 void
 on_toolsSelectRegion_activate          (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
@@ -1786,7 +1828,6 @@ on_toolsSelectRectangle_activate       (GtkMenuItem     *menuitem,
   
   ui.cur_mapping = 0; // don't use switch_mapping() (refreshes buttons too soon)
   end_text();
-  reset_focus();
   ui.toolno[ui.cur_mapping] = TOOL_SELECTRECT;
   update_mapping_linkings(-1);
   update_tool_buttons();
@@ -1813,7 +1854,6 @@ on_toolsVerticalSpace_activate         (GtkMenuItem     *menuitem,
   
   ui.cur_mapping = 0; // don't use switch_mapping() (refreshes buttons too soon)
   end_text();
-  reset_focus();
   reset_selection();
   ui.toolno[ui.cur_mapping] = TOOL_VERTSPACE;
   update_mapping_linkings(-1);
@@ -1990,7 +2030,6 @@ on_eraserStandard_activate             (GtkMenuItem     *menuitem,
 {
   if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem))) return;
   end_text();
-  reset_focus();
   ui.brushes[0][TOOL_ERASER].tool_options = TOOLOPT_ERASER_STANDARD;
   update_mapping_linkings(TOOL_ERASER);
 }
@@ -2002,7 +2041,6 @@ on_eraserWhiteout_activate             (GtkMenuItem     *menuitem,
 {
   if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem))) return;
   end_text();
-  reset_focus();
   ui.brushes[0][TOOL_ERASER].tool_options = TOOLOPT_ERASER_WHITEOUT;
   update_mapping_linkings(TOOL_ERASER);
 }
@@ -2014,7 +2052,6 @@ on_eraserDeleteStrokes_activate        (GtkMenuItem     *menuitem,
 {
   if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem))) return;
   end_text();
-  reset_focus();
   ui.brushes[0][TOOL_ERASER].tool_options = TOOLOPT_ERASER_STROKES;
   update_mapping_linkings(TOOL_ERASER);
 }
@@ -2057,7 +2094,6 @@ on_toolsTextFont_activate              (GtkMenuItem     *menuitem,
   g_free(str);
   if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
     gtk_widget_destroy(dialog);
-    reset_focus();
     return;
   }
   str = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(dialog));
@@ -2071,7 +2107,6 @@ on_toolsDefaultPen_activate            (GtkMenuItem     *menuitem,
 {
   switch_mapping(0);
   end_text();
-  reset_focus();
   reset_selection();
   g_memmove(&(ui.brushes[0][TOOL_PEN]), ui.default_brushes+TOOL_PEN, sizeof(struct Brush));
   ui.toolno[0] = TOOL_PEN;
@@ -2091,7 +2126,6 @@ on_toolsDefaultEraser_activate         (GtkMenuItem     *menuitem,
 {
   switch_mapping(0);
   end_text();
-  reset_focus();
   reset_selection();
   g_memmove(&(ui.brushes[0][TOOL_ERASER]), ui.default_brushes+TOOL_ERASER, sizeof(struct Brush));
   ui.toolno[0] = TOOL_ERASER;
@@ -2111,7 +2145,6 @@ on_toolsDefaultHighlighter_activate    (GtkMenuItem     *menuitem,
 {
   switch_mapping(0);
   end_text();
-  reset_focus();
   reset_selection();
   g_memmove(&(ui.brushes[0][TOOL_HIGHLIGHTER]), ui.default_brushes+TOOL_HIGHLIGHTER, sizeof(struct Brush));
   ui.toolno[0] = TOOL_HIGHLIGHTER;
@@ -2130,7 +2163,6 @@ on_toolsDefaultText_activate           (GtkMenuItem     *menuitem,
 {
   switch_mapping(0);
   if (ui.toolno[0]!=TOOL_TEXT) end_text();
-  reset_focus();
   reset_selection();
   ui.toolno[0] = TOOL_TEXT;
   ui.cur_brush = &(ui.brushes[0][TOOL_PEN]);
@@ -2179,7 +2211,6 @@ on_toolsSetAsDefault_activate          (GtkMenuItem     *menuitem,
     ui.default_font_size = ui.font_size;
   }
   end_text();
-  reset_focus();
 }
 
 
@@ -2200,7 +2231,6 @@ on_toolsRuler_activate                 (GtkMenuItem     *menuitem,
 
   ui.cur_mapping = 0;  
   end_text();
-  reset_focus();
   if (ui.toolno[ui.cur_mapping]!=TOOL_PEN && ui.toolno[ui.cur_mapping]!=TOOL_HIGHLIGHTER) {
     reset_selection();
     ui.toolno[ui.cur_mapping] = TOOL_PEN;
@@ -2235,7 +2265,6 @@ on_toolsReco_activate                  (GtkMenuItem *menuitem,
   
   ui.cur_mapping = 0;
   end_text();
-  reset_focus();
   if (ui.toolno[ui.cur_mapping]!=TOOL_PEN && ui.toolno[ui.cur_mapping]!=TOOL_HIGHLIGHTER) {
     reset_selection();
     ui.toolno[ui.cur_mapping] = TOOL_PEN;
@@ -2261,7 +2290,6 @@ on_optionsSavePreferences_activate     (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   save_config_to_file();
 }
 
@@ -2282,11 +2310,10 @@ on_helpAbout_activate                  (GtkMenuItem     *menuitem,
   GtkLabel *labelTitle;
   
   end_text();
-  reset_focus();
   aboutDialog = create_aboutDialog ();
   labelTitle = GTK_LABEL(g_object_get_data(G_OBJECT(aboutDialog), "labelTitle"));
   gtk_label_set_markup(labelTitle, 
-    "<span size=\"xx-large\" weight=\"bold\">Xournal " VERSION "</span>");
+    "<span size=\"xx-large\" weight=\"bold\">Xournal " VERSION_STRING "</span>");
   gtk_dialog_run (GTK_DIALOG(aboutDialog));
   gtk_widget_destroy(aboutDialog);
 }
@@ -2301,7 +2328,6 @@ on_buttonToolDefault_clicked           (GtkToolButton   *toolbutton,
     return;
   }
   end_text();
-  reset_focus();
   switch_mapping(0);
   if (ui.toolno[0] < NUM_STROKE_TOOLS) {
     g_memmove(&(ui.brushes[0][ui.toolno[0]]), ui.default_brushes+ui.toolno[0], sizeof(struct Brush));
@@ -2350,8 +2376,6 @@ on_canvas_button_press_event           (GtkWidget       *widget,
                                         gpointer         user_data)
 {
   double pt[2];
-  gboolean page_change;
-  struct Page *tmppage;
   GtkWidget *dialog;
   int mapping;
   gboolean is_core;
@@ -2363,8 +2387,9 @@ on_canvas_button_press_event           (GtkWidget       *widget,
     event->device->name, event->x, event->y, event->button, event->state);
 #endif
 
-  if (ui.cur_item_type != ITEM_TEXT) // remove focus from other elements
-    gtk_widget_grab_focus(GTK_WIDGET(canvas));
+  // abort any page changes pending in the spin button, and take the focus
+  gtk_spin_button_set_value(GTK_SPIN_BUTTON(GET_COMPONENT("spinPageNo")), ui.pageno+1);
+  reset_focus();
     
   is_core = (event->device == gdk_device_get_core_pointer());
   if (!ui.use_xinput && !is_core) return FALSE;
@@ -2392,17 +2417,18 @@ on_canvas_button_press_event           (GtkWidget       *widget,
       else if (event->button == 5) scroll_event.scroll.direction = GDK_SCROLL_DOWN;
       else if (event->button == 6) scroll_event.scroll.direction = GDK_SCROLL_LEFT;
       else scroll_event.scroll.direction = GDK_SCROLL_RIGHT;
-      printf("sending...\n");
       gtk_widget_event(GET_COMPONENT("scrolledwindowMain"), &scroll_event);
     }
     return FALSE;
   }
   if ((event->state & (GDK_CONTROL_MASK|GDK_MOD1_MASK)) != 0) return FALSE;
     // no control-clicking or alt-clicking
+  if (!is_core) gdk_device_get_state(event->device, event->window, event->axes, NULL);
+    // synaptics touchpads send bogus axis values with ButtonDown
   if (!is_core)
     fix_xinput_coords((GdkEvent *)event);
 
-  if (!finite(event->x) || !finite(event->y)) return FALSE; // Xorg 7.3 bug
+  if (!finite_sized(event->x) || !finite_sized(event->y)) return FALSE; // Xorg 7.3 bug
 
   if (ui.cur_item_type == ITEM_TEXT) {
     if (!is_event_within_textview(event)) end_text();
@@ -2436,24 +2462,8 @@ on_canvas_button_press_event           (GtkWidget       *widget,
   else mapping = event->button-1;
 
   // check whether we're in a page
-  page_change = FALSE;
-  tmppage = ui.cur_page;
   get_pointer_coords((GdkEvent *)event, pt);
-  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);
+  set_current_page(pt);
   
   // can't paint on the background...
 
@@ -2472,6 +2482,9 @@ on_canvas_button_press_event           (GtkWidget       *widget,
   
   ui.which_mouse_button = event->button;
   switch_mapping(mapping);
+#ifdef WIN32
+  update_cursor();
+#endif
 
   // in text tool, clicking in a text area edits it
   if (ui.toolno[mapping] == TOOL_TEXT) {
@@ -2516,6 +2529,9 @@ on_canvas_button_press_event           (GtkWidget       *widget,
   else if (ui.toolno[mapping] == TOOL_TEXT) {
     start_text((GdkEvent *)event, NULL);
   }
+  else if (ui.toolno[mapping] == TOOL_IMAGE) {
+    insert_image((GdkEvent *)event);
+  }
   return FALSE;
 }
 
@@ -2573,7 +2589,25 @@ on_canvas_enter_notify_event           (GtkWidget       *widget,
                                         GdkEventCrossing *event,
                                         gpointer         user_data)
 {
+  GList *dev_list;
+  GdkDevice *dev;
 
+#ifdef INPUT_DEBUG
+  printf("DEBUG: enter notify\n");
+#endif
+    /* re-enable input devices after they've been emergency-disabled
+       by leave_notify */
+  if (!gtk_check_version(2, 17, 0)) {
+    gdk_flush();
+    gdk_error_trap_push();
+    for (dev_list = gdk_devices_list(); dev_list != NULL; dev_list = dev_list->next) {
+      dev = GDK_DEVICE(dev_list->data);
+      gdk_device_set_mode(dev, GDK_MODE_SCREEN);
+    }
+    ui.is_corestroke = ui.saved_is_corestroke;
+    gdk_flush();
+    gdk_error_trap_pop();
+  }
   return FALSE;
 }
 
@@ -2582,12 +2616,25 @@ on_canvas_leave_notify_event           (GtkWidget       *widget,
                                         GdkEventCrossing *event,
                                         gpointer         user_data)
 {
+  GList *dev_list;
+  GdkDevice *dev;
+
 #ifdef INPUT_DEBUG
-  printf("DEBUG: leave notify\n");
+  printf("DEBUG: leave notify (mode=%d, details=%d)\n", event->mode, event->detail);
 #endif
-  if (ui.need_emergency_disable_xinput) {
-    gtk_widget_set_extension_events(GTK_WIDGET (canvas), GDK_EXTENSION_EVENTS_NONE);
-    ui.need_emergency_disable_xinput = FALSE;
+    /* emergency disable XInput to avoid segfaults (GTK+ 2.17) or 
+       interface non-responsiveness (GTK+ 2.18) */
+  if (!gtk_check_version(2, 17, 0)) {
+    gdk_flush();
+    gdk_error_trap_push();
+    for (dev_list = gdk_devices_list(); dev_list != NULL; dev_list = dev_list->next) {
+      dev = GDK_DEVICE(dev_list->data);
+      gdk_device_set_mode(dev, GDK_MODE_DISABLED);
+    }
+    ui.saved_is_corestroke = ui.is_corestroke;
+    ui.is_corestroke = TRUE;
+    gdk_flush();
+    gdk_error_trap_pop();
   }
   return FALSE;
 }
@@ -2608,28 +2655,53 @@ on_canvas_key_press_event              (GtkWidget       *widget,
                                         GdkEventKey     *event,
                                         gpointer         user_data)
 {
+  GtkAdjustment *adj;
+  gint pgheight;
+
   // Esc leaves text edition, or leaves fullscreen mode
   if (event->keyval == GDK_Escape) {
-    if (ui.cur_item_type == ITEM_TEXT) { end_text(); reset_focus(); }
-    else if (ui.fullscreen) do_fullscreen(FALSE);
+    if (ui.cur_item_type == ITEM_TEXT) { 
+      end_text(); 
+      return TRUE;
+    }
+    else if (ui.fullscreen) {
+      do_fullscreen(FALSE);
+      return TRUE;
+    }
+    else return FALSE;
   }
   
-  // If zoomed-out and in single page mode, switch pages with PgUp/PgDn.
-  if (!ui.view_continuous && 
-      (0.96 * ui.zoom * ui.cur_page->height < 
-       GTK_WIDGET(canvas)->allocation.height)) {
-    if (event->keyval == GDK_Page_Down) {
+  /* In single page mode, switch pages with PgUp/PgDn (or Up/Dn) 
+     when there's nowhere else to go. */
+  pgheight = GTK_WIDGET(canvas)->allocation.height;
+  adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(GET_COMPONENT("scrolledwindowMain")));
+
+  if (event->keyval == GDK_Page_Down || event->keyval == GDK_Down) {
+    if (!ui.view_continuous && 
+         (0.96 * ui.zoom * ui.cur_page->height < pgheight ||
+          adj->value == adj->upper-pgheight)) 
+    {
       end_text();
-      reset_focus();
-      if (ui.pageno == journal.npages-1) { return FALSE; }
-      do_switch_page(ui.pageno+1, TRUE, FALSE);
+      if (ui.pageno < journal.npages-1)
+        do_switch_page(ui.pageno+1, TRUE, FALSE);
+      return TRUE;
     }
-    if (event->keyval == GDK_Page_Up) {
+    if (adj->value == adj->upper-pgheight) return TRUE; // don't send focus away
+  }
+
+  if (event->keyval == GDK_Page_Up || event->keyval == GDK_Up) {
+    if (!ui.view_continuous && 
+         (0.96 * ui.zoom * ui.cur_page->height < pgheight ||
+          adj->value == adj->lower))
+    {
       end_text();
-      reset_focus();
-      if (ui.pageno == 0) { return FALSE; }
-      do_switch_page(ui.pageno-1, TRUE, FALSE);
+      if (ui.pageno != 0) {
+        do_switch_page(ui.pageno-1, TRUE, FALSE);
+        gtk_adjustment_set_value(adj, adj->upper-pgheight);
+      }
+      return TRUE;
     }
+    if (adj->value == adj->lower) return TRUE; // don't send focus away
   }
 
   return FALSE;
@@ -2649,12 +2721,12 @@ on_canvas_motion_notify_event          (GtkWidget       *widget,
      or if there's a selection (then we might want to change the mouse
      cursor to indicate the possibility of resizing) */  
   if (ui.cur_item_type == ITEM_NONE && ui.selection==NULL) return FALSE;
-  if (ui.cur_item_type == ITEM_TEXT) return FALSE;
+  if (ui.cur_item_type == ITEM_TEXT || ui.cur_item_type == ITEM_IMAGE) return FALSE;
 
   is_core = (event->device == gdk_device_get_core_pointer());
   if (!ui.use_xinput && !is_core) return FALSE;
   if (!is_core) fix_xinput_coords((GdkEvent *)event);
-  if (!finite(event->x) || !finite(event->y)) return FALSE; // Xorg 7.3 bug
+  if (!finite_sized(event->x) || !finite_sized(event->y)) return FALSE; // Xorg 7.3 bug
 
   if (ui.selection!=NULL && ui.cur_item_type == ITEM_NONE) {
     get_pointer_coords((GdkEvent *)event, pt);
@@ -2693,6 +2765,9 @@ on_canvas_motion_notify_event          (GtkWidget       *widget,
     else if (ui.cur_item_type == ITEM_RESIZESEL) {
       finalize_resizesel();
     }
+    else if (ui.cur_item_type == ITEM_HAND) {
+      ui.cur_item_type = ITEM_NONE;
+    }
     switch_mapping(0);
     return FALSE;
   }
@@ -2733,7 +2808,6 @@ on_comboLayer_changed                  (GtkComboBox     *combobox,
   if (ui.in_update_page_stuff) return; // avoid a bad retroaction
 
   end_text();
-  reset_focus();
 
   val = gtk_combo_box_get_active(combobox);
   if (val == -1) return;
@@ -2762,7 +2836,6 @@ on_winMain_delete_event                (GtkWidget       *widget,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   if (ok_to_close()) gtk_main_quit();
   return TRUE;
 }
@@ -2773,7 +2846,6 @@ on_optionsUseXInput_activate           (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   ui.allow_xinput = ui.use_xinput =
     gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
 
@@ -2798,7 +2870,9 @@ on_optionsUseXInput_activate           (GtkMenuItem     *menuitem,
    non-responsive). 
 */
 
+#ifndef WIN32
   if (!gtk_check_version(2, 17, 0)) {
+#endif
     /* GTK+ 2.17 and later: everybody shares a single native window,
        so we'll never get any core events, and we might as well set 
        extension events the way we're supposed to. Doing so helps solve 
@@ -2806,14 +2880,18 @@ on_optionsUseXInput_activate           (GtkMenuItem     *menuitem,
        events in 2.18 */
     gtk_widget_set_extension_events(GTK_WIDGET (canvas), 
        ui.use_xinput?GDK_EXTENSION_EVENTS_ALL:GDK_EXTENSION_EVENTS_NONE);
+#ifndef WIN32
   } else {
+#endif
     /* GTK+ 2.16 and earlier: we only activate extension events on the
        canvas's parent GdkWindow. This allows us to keep receiving core
        events. */
     gdk_input_set_extension_events(GTK_WIDGET(canvas)->window, 
       GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK,
       ui.use_xinput?GDK_EXTENSION_EVENTS_ALL:GDK_EXTENSION_EVENTS_NONE);
+#ifndef WIN32
   }
+#endif
   
   update_mappings_menu();
 }
@@ -2849,7 +2927,6 @@ on_vscroll_changed                     (GtkAdjustment   *adjustment,
     end_text();
     do_switch_page(ui.pageno, FALSE, FALSE);
   }
-  reset_focus();
   return;
 }
 
@@ -2860,9 +2937,13 @@ on_spinPageNo_value_changed            (GtkSpinButton   *spinbutton,
   int val;
 
   if (ui.in_update_page_stuff) return; // avoid a bad retroaction
-  
+
+  /* in preparation for end_text(), send focus to the canvas if it's not ours.
+     (avoid issues with Gtk trying to send focus to the dead text widget) */
+
+  if (!GTK_WIDGET_HAS_FOCUS(spinbutton))
+    gtk_widget_grab_focus(GTK_WIDGET(canvas));
   end_text();
-  reset_focus();
 
   val = gtk_spin_button_get_value_as_int(spinbutton) - 1;
 
@@ -2886,7 +2967,6 @@ on_journalDefaultBackground_activate   (GtkMenuItem     *menuitem,
   GList *pglist;
   
   end_text();
-  reset_focus();
   reset_selection();
   
   pg = ui.cur_page;
@@ -2923,7 +3003,6 @@ on_journalSetAsDefault_activate        (GtkMenuItem     *menuitem,
   if (ui.cur_page->bg->type != BG_SOLID) return;
   
   end_text();
-  reset_focus();
   prepare_new_undo();
   undo->type = ITEM_NEW_DEFAULT_BG;
   undo->val_x = ui.default_page.width;
@@ -3066,7 +3145,6 @@ on_optionsButtonMappings_activate      (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   ui.use_erasertip =
     gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
   update_mappings_menu();
@@ -3082,7 +3160,6 @@ on_optionsProgressiveBG_activate       (GtkMenuItem     *menuitem,
   active = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
   if (ui.progressive_bg == active) return;
   end_text();
-  reset_focus();
   ui.progressive_bg = active;
   if (!ui.progressive_bg) rescale_bg_pixmaps();
 }
@@ -3097,7 +3174,6 @@ on_mru_activate                        (GtkMenuItem     *menuitem,
   GtkWidget *dialog;
   
   end_text();
-  reset_focus();
   if (!ok_to_close()) return; // user aborted on save confirmation
   
   for (which = 0 ; which < MRU_SIZE; which++) {
@@ -3151,6 +3227,14 @@ on_button2Text_activate                (GtkMenuItem     *menuitem,
 }
 
 
+void
+on_button2Image_activate               (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+  process_mapping_activate(menuitem, 1, TOOL_IMAGE);
+}
+
+
 void
 on_button2SelectRegion_activate        (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
@@ -3183,7 +3267,6 @@ on_button2LinkBrush_activate           (GtkMenuItem     *menuitem,
   
   if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))) return;
   end_text();
-  reset_focus();
   ui.linked_brush[1] = BRUSH_LINKED;
   for (i=0;i<NUM_STROKE_TOOLS;i++) update_mapping_linkings(i);
 }
@@ -3195,7 +3278,6 @@ on_button2CopyBrush_activate           (GtkMenuItem     *menuitem,
 {
   if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))) return;
   end_text();
-  reset_focus();
   if (ui.toolno[1] >= NUM_STROKE_TOOLS) {
     ui.linked_brush[1] = BRUSH_STATIC;
     update_mappings_menu_linkings();
@@ -3238,6 +3320,14 @@ on_button3Text_activate                (GtkMenuItem     *menuitem,
 }
 
 
+void
+on_button3Image_activate               (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+  process_mapping_activate(menuitem, 2, TOOL_IMAGE);
+}
+
+
 void
 on_button3SelectRegion_activate        (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
@@ -3270,7 +3360,6 @@ on_button3LinkBrush_activate           (GtkMenuItem     *menuitem,
   
   if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))) return;
   end_text();
-  reset_focus();
   ui.linked_brush[2] = BRUSH_LINKED;
   for (i=0;i<NUM_STROKE_TOOLS;i++) update_mapping_linkings(i);
 }
@@ -3282,7 +3371,6 @@ on_button3CopyBrush_activate           (GtkMenuItem     *menuitem,
 {
   if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))) return;
   end_text();
-  reset_focus();
   if (ui.toolno[2] >= NUM_STROKE_TOOLS) {
     ui.linked_brush[2] = BRUSH_STATIC;
     update_mappings_menu_linkings();
@@ -3306,7 +3394,6 @@ on_viewSetZoom_activate                (GtkMenuItem     *menuitem,
   GtkSpinButton *spinZoom;
   
   end_text();
-  reset_focus();
   zoom_dialog = create_zoomDialog();
   zoom_percent = 100*ui.zoom / DEFAULT_ZOOM;
   spinZoom = GTK_SPIN_BUTTON(g_object_get_data(G_OBJECT(zoom_dialog), "spinZoom"));
@@ -3334,6 +3421,7 @@ on_viewSetZoom_activate                (GtkMenuItem     *menuitem,
       gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
       rescale_text_items();
       rescale_bg_pixmaps();
+      rescale_images();
     }
   } while (response == GTK_RESPONSE_APPLY);
   
@@ -3417,7 +3505,6 @@ on_toolsHand_activate                  (GtkMenuItem     *menuitem,
 
   ui.cur_mapping = 0;
   end_text();
-  reset_focus();
   reset_selection();
   ui.toolno[ui.cur_mapping] = TOOL_HAND;
   update_mapping_linkings(-1);
@@ -3449,19 +3536,15 @@ on_optionsPrintRuling_activate         (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   ui.print_ruling = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
 }
 
 void
-on_optionsDiscardCore_activate         (GtkMenuItem     *menuitem,
+on_optionsAutoloadPdfXoj_activate      (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
-  ui.discard_corepointer =
-    gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
-  update_mappings_menu();
+  ui.autoload_pdf_xoj = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
 }
 
 void
@@ -3479,7 +3562,6 @@ on_optionsLeftHanded_activate          (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   ui.left_handed = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
   gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(GET_COMPONENT("scrolledwindowMain")),
     ui.left_handed?GTK_CORNER_TOP_RIGHT:GTK_CORNER_TOP_LEFT);
@@ -3493,7 +3575,6 @@ on_optionsShortenMenus_activate        (GtkMenuItem     *menuitem,
   GtkWidget *w;
   
   end_text();
-  reset_focus();
   ui.shorten_menus = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
   
   /* go over the item list */
@@ -3525,7 +3606,6 @@ on_optionsAutoSavePrefs_activate       (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   ui.auto_save_prefs = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
 }
 
@@ -3535,7 +3615,6 @@ on_optionsPressureSensitive_activate   (GtkMenuItem     *menuitem,
 {
   int i;
   end_text();
-  reset_focus();
   ui.pressure_sensitivity =
     gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
   for (i=0; i<=NUM_BUTTONS; i++)
@@ -3562,8 +3641,8 @@ on_optionsButtonsSwitchMappings_activate(GtkMenuItem    *menuitem,
                                         gpointer         user_data)
 {
   end_text();
-  reset_focus();
   switch_mapping(0);
   ui.button_switch_mapping = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
 }
 
+