]> git.donarmstrong.com Git - xournal.git/blobdiff - src/xo-callbacks.c
Release 0.3.3 (minor enhancements)
[xournal.git] / src / xo-callbacks.c
index 6fe75d9991b277efe761fdf8b8e54cb91134ead7..038507ad4724ae69c38de812836065d787d0dc2d 100644 (file)
@@ -25,7 +25,7 @@ on_fileNew_activate                    (GtkMenuItem     *menuitem,
 {
   if (close_journal()) {
     new_journal();
-    ui.zoom = DEFAULT_ZOOM;
+    ui.zoom = ui.startup_zoom;
     update_page_stuff();
     gtk_adjustment_set_value(gtk_layout_get_vadjustment(GTK_LAYOUT(canvas)), 0);
     gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
@@ -47,7 +47,7 @@ on_fileNewBackground_activate          (GtkMenuItem     *menuitem,
   
   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_ACCEPT, NULL);
+     GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
      
   filt_all = gtk_file_filter_new();
   gtk_file_filter_set_name(filt_all, "All files");
@@ -58,11 +58,13 @@ on_fileNewBackground_activate          (GtkMenuItem     *menuitem,
   gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_pdf);
   gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_all);
 
+  if (ui.default_path!=NULL) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (dialog), ui.default_path);
+
   attach_opt = gtk_check_button_new_with_label("Attach file to the journal");
   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(attach_opt), FALSE);
   gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER (dialog), attach_opt);
   
-  if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
+  if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
     gtk_widget_destroy(dialog);
     return;
   }
@@ -81,7 +83,7 @@ on_fileNewBackground_activate          (GtkMenuItem     *menuitem,
     gtk_main_iteration(); 
   }
   new_journal();
-  ui.zoom = DEFAULT_ZOOM;
+  ui.zoom = ui.startup_zoom;
   gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
   update_page_stuff();
   success = init_bgpdf(filename, TRUE, file_domain);
@@ -113,7 +115,7 @@ on_fileOpen_activate                   (GtkMenuItem     *menuitem,
   
   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_ACCEPT, NULL);
+     GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
      
   filt_all = gtk_file_filter_new();
   gtk_file_filter_set_name(filt_all, "All files");
@@ -123,8 +125,10 @@ on_fileOpen_activate                   (GtkMenuItem     *menuitem,
   gtk_file_filter_add_pattern(filt_xoj, "*.xoj");
   gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_xoj);
   gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_all);
-  
-  if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
+
+  if (ui.default_path!=NULL) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (dialog), ui.default_path);
+
+  if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
     gtk_widget_destroy(dialog);
     return;
   }
@@ -185,7 +189,7 @@ on_fileSaveAs_activate                 (GtkMenuItem     *menuitem,
   
   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_ACCEPT, NULL);
+     GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
      
   if (ui.filename!=NULL) {
     gtk_file_chooser_set_filename(GTK_FILE_CHOOSER (dialog), ui.filename);
@@ -202,6 +206,8 @@ on_fileSaveAs_activate                 (GtkMenuItem     *menuitem,
   else {
     curtime = time(NULL);
     strftime(stime, 30, "%F-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);
   }
      
@@ -215,10 +221,10 @@ on_fileSaveAs_activate                 (GtkMenuItem     *menuitem,
   gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_all);
   
   // somehow this doesn't seem to be set by default
-  gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
+  gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
 
   do {
-    if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
+    if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
       gtk_widget_destroy(dialog);
       return;
     }
@@ -355,18 +361,17 @@ on_filePrintPDF_activate               (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
 
-  GtkWidget *dialog;
+  GtkWidget *dialog, *warning_dialog;
   GtkFileFilter *filt_all, *filt_pdf;
   char *filename, *in_fn;
   char stime[30];
   time_t curtime;
-  GnomePrintJob *gpj;
-  GnomePrintConfig *config;
-
+  int response;
+  gboolean warn;
   
-  dialog = gtk_file_chooser_dialog_new("Print to PDF", GTK_WINDOW (winMain),
+  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_ACCEPT, NULL);
+     GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
      
   if (ui.filename!=NULL) {
     if (g_str_has_suffix(ui.filename, ".xoj")) {
@@ -380,6 +385,8 @@ on_filePrintPDF_activate               (GtkMenuItem     *menuitem,
   } else {
     curtime = time(NULL);
     strftime(stime, 30, "%F-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);
     in_fn = NULL;
   }
@@ -392,27 +399,37 @@ on_filePrintPDF_activate               (GtkMenuItem     *menuitem,
   gtk_file_filter_add_pattern(filt_pdf, "*.pdf");
   gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_pdf);
   gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_all);
+  gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
+  g_free(in_fn);
   
-  // somehow this doesn't seem to be set by default
-  gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
+  do {
+    if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
+      gtk_widget_destroy(dialog);
+      return;
+    }
+    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+    warn = g_file_test(filename, G_FILE_TEST_EXISTS);
+    if (warn) {
+      warning_dialog = gtk_message_dialog_new(GTK_WINDOW(winMain),
+        GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
+        "Should the file %s be overwritten?", filename);
+      if (gtk_dialog_run(GTK_DIALOG(warning_dialog)) == GTK_RESPONSE_YES)
+        warn = FALSE;
+      gtk_widget_destroy(warning_dialog);
+    }
+  } while(warn);
+    
+  gtk_widget_destroy(dialog);
 
-  if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
-    g_free(in_fn);
+  set_cursor_busy(TRUE);
+  if (!print_to_pdf(filename)) {
+    set_cursor_busy(FALSE);
+    dialog = gtk_message_dialog_new(GTK_WINDOW (winMain), GTK_DIALOG_DESTROY_WITH_PARENT,
+      GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Error creating file '%s'", filename);
+    gtk_dialog_run(GTK_DIALOG(dialog));
     gtk_widget_destroy(dialog);
-    return;
   }
-  filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
-  g_free(in_fn);
-  gtk_widget_destroy(dialog);
-  
-  config = gnome_print_config_default();
-  gnome_print_config_set(config, (guchar *)"Printer", (guchar *)"PDF");
-  gpj = gnome_print_job_new(config);
-  gnome_print_job_print_to_file(gpj, filename);
-  
-  print_job_render(gpj, 0, journal.npages-1);
-  gnome_print_config_unref(config);
-
+  set_cursor_busy(FALSE);
   g_free(filename);
 }
 
@@ -880,7 +897,7 @@ on_viewZoomIn_activate                 (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   if (ui.zoom > MAX_ZOOM) return;
-  ui.zoom *= 1.5;
+  ui.zoom *= ui.zoom_step_factor;
   gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
   rescale_bg_pixmaps();
 }
@@ -891,7 +908,7 @@ on_viewZoomOut_activate                (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
   if (ui.zoom < MIN_ZOOM) return;
-  ui.zoom /= 1.5;
+  ui.zoom /= ui.zoom_step_factor;
   gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
   rescale_bg_pixmaps();
 }
@@ -1169,12 +1186,7 @@ gboolean papersize_need_init, papersize_width_valid, papersize_height_valid;
 #define STD_SIZE_LETTER_R 3
 #define STD_SIZE_CUSTOM 4
 
-#define UNIT_CM 0
-#define UNIT_IN 1
-#define UNIT_PX 2
-#define UNIT_PT 3
-
-double unit_sizes[4] = {28.346, 72., 1/DEFAULT_ZOOM, 1.};
+double unit_sizes[4] = {28.346, 72., 72./DISPLAY_DPI_DEFAULT, 1.};
 double std_widths[STD_SIZE_CUSTOM] =  {595.27, 841.89, 612., 792.};
 double std_heights[STD_SIZE_CUSTOM] = {841.89, 595.27, 792., 612.};
 double std_units[STD_SIZE_CUSTOM] = {UNIT_CM, UNIT_CM, UNIT_IN, UNIT_IN};
@@ -1190,7 +1202,8 @@ on_journalPaperSize_activate           (GtkMenuItem     *menuitem,
   papersize_dialog = create_papersizeDialog();
   papersize_width = ui.cur_page->width;
   papersize_height = ui.cur_page->height;
-  papersize_unit = UNIT_CM;
+  papersize_unit = ui.default_unit;
+  unit_sizes[UNIT_PX] = 1./DEFAULT_ZOOM;
 //  if (ui.cur_page->bg->type == BG_PIXMAP) papersize_unit = UNIT_PX;
   papersize_std = STD_SIZE_CUSTOM;
   for (i=0;i<STD_SIZE_CUSTOM;i++)
@@ -1334,8 +1347,8 @@ on_journalLoadBackground_activate      (GtkMenuItem     *menuitem,
   
   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_ACCEPT, NULL);
-     
+     GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
+
   filt_all = gtk_file_filter_new();
   gtk_file_filter_set_name(filt_all, "All files");
   gtk_file_filter_add_pattern(filt_all, "*");
@@ -1361,8 +1374,10 @@ on_journalLoadBackground_activate      (GtkMenuItem     *menuitem,
   attach_opt = gtk_check_button_new_with_label("Attach file to the journal");
   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(attach_opt), FALSE);
   gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER (dialog), attach_opt);
+
+  if (ui.default_path!=NULL) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (dialog), ui.default_path);
   
-  if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
+  if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
     gtk_widget_destroy(dialog);
     return;
   }
@@ -2000,7 +2015,7 @@ void
 on_optionsSavePreferences_activate     (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
-
+  save_config_to_file();
 }
 
 
@@ -2085,17 +2100,20 @@ on_canvas_button_press_event           (GtkWidget       *widget,
   struct Page *tmppage;
   GtkWidget *dialog;
   int mapping;
-  
+  gboolean is_core;
+
   if (ui.cur_item_type != ITEM_NONE) return FALSE; // we're already doing something
   if (event->button > 3) return FALSE; // no painting with the mouse wheel!
 
-  if (ui.use_xinput) { 
-    if (event->device->source == GDK_SOURCE_MOUSE) return FALSE;
+  is_core = (event->device == gdk_device_get_core_pointer());
+  if (!ui.use_xinput && !is_core) return FALSE;
+  if (ui.use_xinput && is_core && ui.discard_corepointer) return FALSE;
+  if (!is_core) { 
     // re-get the axis values since Synaptics sends bogus ones
     gdk_device_get_state(event->device, event->window, event->axes, NULL);
     fix_xinput_coords((GdkEvent *)event);
   }
-  else if (event->device->source != GDK_SOURCE_MOUSE) return FALSE;
+  ui.is_corestroke = is_core;
 
   if (ui.use_erasertip && event->device->source == GDK_SOURCE_ERASER)
        mapping = NUM_BUTTONS;
@@ -2147,7 +2165,11 @@ on_canvas_button_press_event           (GtkWidget       *widget,
 
   // process the event
   
-  if (ui.toolno[mapping] == TOOL_PEN || ui.toolno[mapping] == TOOL_HIGHLIGHTER ||
+  if (ui.toolno[mapping] == TOOL_HAND) {
+    ui.cur_item_type = ITEM_HAND;
+    get_pointer_coords((GdkEvent *)event, ui.hand_refpt);
+  } 
+  else if (ui.toolno[mapping] == TOOL_PEN || ui.toolno[mapping] == TOOL_HIGHLIGHTER ||
         (ui.toolno[mapping] == TOOL_ERASER && ui.cur_brush->tool_options == TOOLOPT_ERASER_WHITEOUT)) {
     create_new_stroke((GdkEvent *)event);
   } 
@@ -2171,15 +2193,16 @@ on_canvas_button_release_event         (GtkWidget       *widget,
                                         GdkEventButton  *event,
                                         gpointer         user_data)
 {
+  gboolean is_core;
+  
   if (ui.cur_item_type == ITEM_NONE) return FALSE; // not doing anything
 
   if (event->button != ui.which_mouse_button) return FALSE; // ignore
 
-  if (ui.use_xinput) {
-    if (event->device->source == GDK_SOURCE_MOUSE) return FALSE;
-    fix_xinput_coords((GdkEvent *)event);
-  }
-  else if (event->device->source != GDK_SOURCE_MOUSE) return FALSE;
+  is_core = (event->device == gdk_device_get_core_pointer());
+  if (!ui.use_xinput && !is_core) return FALSE;
+  if (ui.use_xinput && is_core && !ui.is_corestroke) return FALSE;
+  if (!is_core) fix_xinput_coords((GdkEvent *)event);
 
   if (ui.cur_item_type == ITEM_STROKE) {
     finalize_stroke();
@@ -2193,6 +2216,9 @@ on_canvas_button_release_event         (GtkWidget       *widget,
   else if (ui.cur_item_type == ITEM_MOVESEL || ui.cur_item_type == ITEM_MOVESEL_VERT) {
     finalize_movesel();
   }
+  else if (ui.cur_item_type == ITEM_HAND) {
+    ui.cur_item_type = ITEM_NONE;
+  }
 
   switch_mapping(0);
   return FALSE;
@@ -2234,16 +2260,15 @@ on_canvas_motion_notify_event          (GtkWidget       *widget,
                                         GdkEventMotion  *event,
                                         gpointer         user_data)
 {
-  gboolean looks_wrong;
+  gboolean looks_wrong, is_core;
   double pt[2];
   
   if (ui.cur_item_type == ITEM_NONE) return FALSE; // we don't care
 
-  if (ui.use_xinput) { 
-    if (event->device->source == GDK_SOURCE_MOUSE) return FALSE;
-    fix_xinput_coords((GdkEvent *)event);
-  }
-  else if (event->device->source != GDK_SOURCE_MOUSE) return FALSE;
+  is_core = (event->device == gdk_device_get_core_pointer());
+  if (!ui.use_xinput && !is_core) return FALSE;
+  if (ui.use_xinput && is_core && !ui.is_corestroke) return FALSE;
+  if (!is_core) fix_xinput_coords((GdkEvent *)event);
 
   looks_wrong = !(event->state & (1<<(7+ui.which_mouse_button)));
   
@@ -2281,6 +2306,9 @@ on_canvas_motion_notify_event          (GtkWidget       *widget,
   else if (ui.cur_item_type == ITEM_MOVESEL || ui.cur_item_type == ITEM_MOVESEL_VERT) {
     continue_movesel((GdkEvent *)event);
   }
+  else if (ui.cur_item_type == ITEM_HAND) {
+    do_hand((GdkEvent *)event);
+  }
   
   return FALSE;
 }
@@ -2332,6 +2360,7 @@ on_optionsUseXInput_activate           (GtkMenuItem     *menuitem,
 {
   ui.allow_xinput = ui.use_xinput =
     gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
+  update_mappings_menu();
 }
 
 void
@@ -2394,22 +2423,34 @@ void
 on_journalDefaultBackground_activate   (GtkMenuItem     *menuitem,
                                         gpointer         user_data)
 {
+  struct Page *pg;
+  GList *pglist;
+  
   reset_selection();
-  prepare_new_undo();
-  undo->type = ITEM_NEW_BG_RESIZE;
-  undo->page = ui.cur_page;
-  undo->bg = ui.cur_page->bg;
-  undo->val_x = ui.cur_page->width;
-  undo->val_y = ui.cur_page->height; 
   
-  ui.cur_page->bg = (struct Background *)g_memdup(ui.default_page.bg, sizeof(struct Background));
-  ui.cur_page->width = ui.default_page.width;
-  ui.cur_page->height = ui.default_page.height;
-  ui.cur_page->bg->canvas_item = undo->bg->canvas_item;
-  undo->bg->canvas_item = NULL;
+  pg = ui.cur_page;
+  for (pglist = journal.pages; pglist!=NULL; pglist = pglist->next) {
+    if (ui.bg_apply_all_pages) pg = (struct Page *)pglist->data;
+    prepare_new_undo();
+    if (ui.bg_apply_all_pages) {
+      if (pglist->next!=NULL) undo->multiop |= MULTIOP_CONT_REDO;
+      if (pglist->prev!=NULL) undo->multiop |= MULTIOP_CONT_UNDO;
+    }
+    undo->type = ITEM_NEW_BG_RESIZE;
+    undo->page = pg;
+    undo->bg = pg->bg;
+    undo->val_x = pg->width;
+    undo->val_y = pg->height; 
+    pg->bg = (struct Background *)g_memdup(ui.default_page.bg, sizeof(struct Background));
+    pg->width = ui.default_page.width;
+    pg->height = ui.default_page.height;
+    pg->bg->canvas_item = undo->bg->canvas_item;
+    undo->bg->canvas_item = NULL;
   
-  make_page_clipbox(ui.cur_page);
-  update_canvas_bg(ui.cur_page);
+    make_page_clipbox(pg);
+    update_canvas_bg(pg);
+    if (!ui.bg_apply_all_pages) break;
+  }
   do_switch_page(ui.pageno, TRUE, TRUE);
 }
 
@@ -2554,17 +2595,15 @@ on_viewFullscreen_activate             (GtkMenuItem     *menuitem,
 
   if (active == ui.fullscreen) return;
   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) {
-    gtk_window_fullscreen(GTK_WINDOW(winMain));
-    gtk_widget_hide(GET_COMPONENT("menubar"));
-    gtk_widget_hide(GET_COMPONENT("hbox1"));
-  } 
-  else {
-    gtk_window_unfullscreen(GTK_WINDOW(winMain));
-    gtk_widget_show(GET_COMPONENT("menubar"));
-    gtk_widget_show(GET_COMPONENT("hbox1"));
-  }
+  if (ui.fullscreen) gtk_window_fullscreen(GTK_WINDOW(winMain));
+  else gtk_window_unfullscreen(GTK_WINDOW(winMain));
+  
+  update_vbox_order(ui.vertical_order[ui.fullscreen?1:0]);
 }
 
 
@@ -2804,3 +2843,165 @@ on_button3CopyBrush_activate           (GtkMenuItem     *menuitem,
     ui.ruler[2] = FALSE;
 }
 
+// the set zoom dialog
+
+GtkWidget *zoom_dialog;
+double zoom_percent;
+
+void
+on_viewSetZoom_activate                (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+  int response;
+  double test_w, test_h;
+  GtkSpinButton *spinZoom;
+  
+  zoom_dialog = create_zoomDialog();
+  zoom_percent = 100*ui.zoom / DEFAULT_ZOOM;
+  spinZoom = GTK_SPIN_BUTTON(g_object_get_data(G_OBJECT(zoom_dialog), "spinZoom"));
+  gtk_spin_button_set_increments(spinZoom, ui.zoom_step_increment, 5*ui.zoom_step_increment);
+  gtk_spin_button_set_value(spinZoom, zoom_percent);
+  test_w = 100*(GTK_WIDGET(canvas))->allocation.width/ui.cur_page->width/DEFAULT_ZOOM;
+  test_h = 100*(GTK_WIDGET(canvas))->allocation.height/ui.cur_page->height/DEFAULT_ZOOM;
+  if (zoom_percent > 99.9 && zoom_percent < 100.1) 
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_object_get_data(
+           G_OBJECT(zoom_dialog), "radioZoom100")), TRUE);
+  else if (zoom_percent > test_w-0.1 && zoom_percent < test_w+0.1)
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_object_get_data(
+           G_OBJECT(zoom_dialog), "radioZoomWidth")), TRUE);
+  else if (zoom_percent > test_h-0.1 && zoom_percent < test_h+0.1)
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_object_get_data(
+           G_OBJECT(zoom_dialog), "radioZoomHeight")), TRUE);
+  else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_object_get_data(
+           G_OBJECT(zoom_dialog), "radioZoom")), TRUE);
+  gtk_widget_show(zoom_dialog);
+  
+  do {
+    response = gtk_dialog_run(GTK_DIALOG(zoom_dialog));
+    if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) {
+      ui.zoom = DEFAULT_ZOOM*zoom_percent/100;
+      gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
+      rescale_bg_pixmaps();
+    }
+  } while (response == GTK_RESPONSE_APPLY);
+  
+  gtk_widget_destroy(zoom_dialog);
+}
+
+
+void
+on_spinZoom_value_changed              (GtkSpinButton   *spinbutton,
+                                        gpointer         user_data)
+{
+  double val;
+
+  val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(g_object_get_data(
+             G_OBJECT(zoom_dialog), "spinZoom")));
+  if (val<1) return;
+  if (val<10) val=10.;
+  if (val>1500) val=1500.;
+  if (val<zoom_percent-1 || val>zoom_percent+1)
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_object_get_data(
+           G_OBJECT(zoom_dialog), "radioZoom")), TRUE);
+  zoom_percent = val;
+}
+
+
+void
+on_radioZoom_toggled                   (GtkToggleButton *togglebutton,
+                                        gpointer         user_data)
+{
+  // nothing to do
+}
+
+
+void
+on_radioZoom100_toggled                (GtkToggleButton *togglebutton,
+                                        gpointer         user_data)
+{
+  if (!gtk_toggle_button_get_active(togglebutton)) return;
+  zoom_percent = 100.;
+  gtk_spin_button_set_value(GTK_SPIN_BUTTON(g_object_get_data(
+        G_OBJECT(zoom_dialog), "spinZoom")), zoom_percent);
+}
+
+
+void
+on_radioZoomWidth_toggled              (GtkToggleButton *togglebutton,
+                                        gpointer         user_data)
+{
+  if (!gtk_toggle_button_get_active(togglebutton)) return;
+  zoom_percent = 100*(GTK_WIDGET(canvas))->allocation.width/ui.cur_page->width/DEFAULT_ZOOM;
+  gtk_spin_button_set_value(GTK_SPIN_BUTTON(g_object_get_data(
+        G_OBJECT(zoom_dialog), "spinZoom")), zoom_percent);
+}
+
+
+void
+on_radioZoomHeight_toggled             (GtkToggleButton *togglebutton,
+                                        gpointer         user_data)
+{
+  if (!gtk_toggle_button_get_active(togglebutton)) return;
+  zoom_percent = 100*(GTK_WIDGET(canvas))->allocation.height/ui.cur_page->height/DEFAULT_ZOOM;
+  gtk_spin_button_set_value(GTK_SPIN_BUTTON(g_object_get_data(
+        G_OBJECT(zoom_dialog), "spinZoom")), zoom_percent);
+}
+
+
+void
+on_toolsHand_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) return;
+  if (ui.toolno[0] == TOOL_HAND) return;
+
+  reset_selection();
+  ui.toolno[0] = TOOL_HAND;
+  ui.ruler[0] = FALSE;
+  update_mapping_linkings(-1);
+  update_tool_buttons();
+  update_tool_menu();
+  update_color_menu();
+  update_cursor();
+}
+
+
+void
+on_button2Hand_activate                (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+  process_mapping_activate(menuitem, 1, TOOL_HAND);
+}
+
+
+void
+on_button3Hand_activate                (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+  process_mapping_activate(menuitem, 2, TOOL_HAND);
+}
+
+
+void
+on_optionsPrintRuling_activate         (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+  ui.print_ruling = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
+}
+
+void
+on_optionsDiscardCore_activate         (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+  ui.discard_corepointer =
+    gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
+  update_mappings_menu();
+}