8 #include <libgnomecanvas/libgnomecanvas.h>
10 #include <libgnomeprintui/gnome-print-dialog.h>
11 #include <glib/gstdio.h>
12 #include <gdk/gdkkeysyms.h>
15 #include "xo-callbacks.h"
16 #include "xo-interface.h"
17 #include "xo-support.h"
22 #include "xo-shapes.h"
25 on_fileNew_activate (GtkMenuItem *menuitem,
30 if (close_journal()) {
32 ui.zoom = ui.startup_zoom;
34 gtk_adjustment_set_value(gtk_layout_get_vadjustment(GTK_LAYOUT(canvas)), 0);
35 gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
41 on_fileNewBackground_activate (GtkMenuItem *menuitem,
44 GtkWidget *dialog, *attach_opt;
45 GtkFileFilter *filt_all, *filt_pdf;
52 if (!ok_to_close()) return; // user aborted on save confirmation
54 dialog = gtk_file_chooser_dialog_new(_("Open PDF"), GTK_WINDOW (winMain),
55 GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
56 GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
58 filt_all = gtk_file_filter_new();
59 gtk_file_filter_set_name(filt_all, _("All files"));
60 gtk_file_filter_add_pattern(filt_all, "*");
61 filt_pdf = gtk_file_filter_new();
62 gtk_file_filter_set_name(filt_pdf, _("PDF files"));
63 gtk_file_filter_add_pattern(filt_pdf, "*.pdf");
64 gtk_file_filter_add_pattern(filt_pdf, "*.PDF");
65 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_pdf);
66 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_all);
68 if (ui.default_path!=NULL) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (dialog), ui.default_path);
70 attach_opt = gtk_check_button_new_with_label(_("Attach file to the journal"));
71 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(attach_opt), FALSE);
72 gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER (dialog), attach_opt);
74 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
75 gtk_widget_destroy(dialog);
78 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
79 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(attach_opt)))
80 file_domain = DOMAIN_ATTACH;
81 else file_domain = DOMAIN_ABSOLUTE;
83 gtk_widget_destroy(dialog);
85 set_cursor_busy(TRUE);
86 ui.saved = TRUE; // force close_journal to work
88 while (bgpdf.status != STATUS_NOT_INIT) {
89 // waiting for pdf processes to finish dying
93 ui.zoom = ui.startup_zoom;
94 gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
96 success = init_bgpdf(filename, TRUE, file_domain);
97 set_cursor_busy(FALSE);
104 dialog = gtk_message_dialog_new(GTK_WINDOW (winMain), GTK_DIALOG_DESTROY_WITH_PARENT,
105 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Error opening file '%s'"), filename);
106 gtk_dialog_run(GTK_DIALOG(dialog));
107 gtk_widget_destroy(dialog);
113 on_fileOpen_activate (GtkMenuItem *menuitem,
117 GtkFileFilter *filt_all, *filt_xoj;
123 if (!ok_to_close()) return; // user aborted on save confirmation
125 dialog = gtk_file_chooser_dialog_new(_("Open Journal"), GTK_WINDOW (winMain),
126 GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
127 GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
129 filt_all = gtk_file_filter_new();
130 gtk_file_filter_set_name(filt_all, _("All files"));
131 gtk_file_filter_add_pattern(filt_all, "*");
132 filt_xoj = gtk_file_filter_new();
133 gtk_file_filter_set_name(filt_xoj, _("Xournal files"));
134 gtk_file_filter_add_pattern(filt_xoj, "*.xoj");
135 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_xoj);
136 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_all);
138 if (ui.default_path!=NULL) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (dialog), ui.default_path);
140 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
141 gtk_widget_destroy(dialog);
144 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
145 gtk_widget_destroy(dialog);
147 set_cursor_busy(TRUE);
148 success = open_journal(filename);
149 set_cursor_busy(FALSE);
150 if (success) { g_free(filename); return; }
153 dialog = gtk_message_dialog_new(GTK_WINDOW (winMain), GTK_DIALOG_DESTROY_WITH_PARENT,
154 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Error opening file '%s'"), filename);
155 gtk_dialog_run(GTK_DIALOG(dialog));
156 gtk_widget_destroy(dialog);
163 on_fileSave_activate (GtkMenuItem *menuitem,
170 if (ui.filename == NULL) {
171 on_fileSaveAs_activate(menuitem, user_data);
174 set_cursor_busy(TRUE);
175 if (save_journal(ui.filename)) { // success
176 set_cursor_busy(FALSE);
180 set_cursor_busy(FALSE);
182 dialog = gtk_message_dialog_new(GTK_WINDOW (winMain), GTK_DIALOG_DESTROY_WITH_PARENT,
183 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Error saving file '%s'"), ui.filename);
184 gtk_dialog_run(GTK_DIALOG(dialog));
185 gtk_widget_destroy(dialog);
190 on_fileSaveAs_activate (GtkMenuItem *menuitem,
193 GtkWidget *dialog, *warning_dialog;
194 GtkFileFilter *filt_all, *filt_xoj;
199 struct stat stat_buf;
203 dialog = gtk_file_chooser_dialog_new(_("Save Journal"), GTK_WINDOW (winMain),
204 GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
205 GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
207 if (ui.filename!=NULL) {
208 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER (dialog), ui.filename);
209 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), g_basename(ui.filename));
212 if (bgpdf.status!=STATUS_NOT_INIT && bgpdf.file_domain == DOMAIN_ABSOLUTE
213 && bgpdf.filename != NULL) {
214 filename = g_strdup_printf("%s.xoj", bgpdf.filename->s);
215 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER (dialog), filename);
216 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), g_basename(filename));
220 curtime = time(NULL);
221 strftime(stime, 30, "%F-Note-%H-%M.xoj", localtime(&curtime));
222 if (ui.default_path!=NULL)
223 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (dialog), ui.default_path);
224 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), stime);
227 filt_all = gtk_file_filter_new();
228 gtk_file_filter_set_name(filt_all, _("All files"));
229 gtk_file_filter_add_pattern(filt_all, "*");
230 filt_xoj = gtk_file_filter_new();
231 gtk_file_filter_set_name(filt_xoj, _("Xournal files"));
232 gtk_file_filter_add_pattern(filt_xoj, "*.xoj");
233 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_xoj);
234 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_all);
236 // somehow this doesn't seem to be set by default
237 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
240 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
241 gtk_widget_destroy(dialog);
244 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
245 warn = g_file_test (filename, G_FILE_TEST_EXISTS);
246 if (warn) { // ok to overwrite an empty file
247 if (!g_stat(filename, &stat_buf))
248 if (stat_buf.st_size == 0) warn=FALSE;
250 if (warn && ui.filename!=NULL) { // ok to overwrite oneself
251 if (ui.filename[0]=='/' && !strcmp(ui.filename, filename)) warn=FALSE;
252 if (ui.filename[0]!='/' && g_str_has_suffix(filename, ui.filename)) warn=FALSE;
255 warning_dialog = gtk_message_dialog_new(GTK_WINDOW(winMain),
256 GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
257 _("Should the file %s be overwritten?"), filename);
258 if (gtk_dialog_run(GTK_DIALOG(warning_dialog)) == GTK_RESPONSE_YES)
260 gtk_widget_destroy(warning_dialog);
264 gtk_widget_destroy(dialog);
266 set_cursor_busy(TRUE);
267 if (save_journal(filename)) { // success
269 set_cursor_busy(FALSE);
270 update_file_name(filename);
273 set_cursor_busy(FALSE);
275 dialog = gtk_message_dialog_new(GTK_WINDOW (winMain), GTK_DIALOG_DESTROY_WITH_PARENT,
276 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Error saving file '%s'"), filename);
277 gtk_dialog_run(GTK_DIALOG(dialog));
278 gtk_widget_destroy(dialog);
284 on_filePrintOptions_activate (GtkMenuItem *menuitem,
292 on_filePrint_activate (GtkMenuItem *menuitem,
295 GtkWidget *printDialog;
297 int fromPage, toPage;
301 GnomePrintConfig *config = gnome_print_config_default();
305 if (ui.filename!=NULL) {
306 if (g_str_has_suffix(ui.filename, ".xoj")) {
307 in_fn = g_strdup(ui.filename);
308 g_strlcpy(g_strrstr(in_fn, "xoj"), "pdf", 4);
311 in_fn = g_strdup_printf("%s.pdf", ui.filename);
312 gnome_print_config_set(config, (guchar *)"Printer", (guchar *)"PDF");
313 gnome_print_config_set(config, (guchar *)GNOME_PRINT_KEY_OUTPUT_FILENAME, (guchar *)in_fn);
314 gnome_print_config_set(config, (guchar *)"Settings.Transport.Backend.FileName", (guchar *)in_fn);
315 g_strlcpy(g_strrstr(in_fn, "pdf"), "ps", 3);
316 gnome_print_config_set(config, (guchar *)"Printer", (guchar *)"GENERIC");
317 gnome_print_config_set (config, (guchar *)GNOME_PRINT_KEY_OUTPUT_FILENAME, (guchar *)in_fn);
318 s = gnome_print_config_get(config, (guchar *)"Settings.Transport.Backend.FileName");
321 gnome_print_config_set(config, (guchar *)"Settings.Transport.Backend.FileName", (guchar *)in_fn);
326 gpj = gnome_print_job_new(config); /* was NULL */
327 gnome_print_config_unref(config);
329 printDialog = gnome_print_dialog_new(gpj, (guchar *) _("Print"), GNOME_PRINT_DIALOG_RANGE);
330 gnome_print_dialog_construct_range_page(GNOME_PRINT_DIALOG(printDialog),
331 GNOME_PRINT_RANGE_ALL | GNOME_PRINT_RANGE_RANGE,
332 1, journal.npages, (guchar *) _("Current page"), (guchar *) _("Pages"));
333 /* don't have "Current page" as option, else it becomes the default!! */
335 gtk_dialog_set_response_sensitive(GTK_DIALOG(printDialog),
336 GNOME_PRINT_DIALOG_RESPONSE_PREVIEW, FALSE);
337 /* the print-job-preview "feature" is completely, hopelessly broken */
339 response = gtk_dialog_run(GTK_DIALOG(printDialog));
341 gtk_widget_destroy(printDialog);
346 if (response == GNOME_PRINT_DIALOG_RESPONSE_PREVIEW) {
347 print_job_render(gpj, 0, journal.npages-1);
348 gtk_widget_destroy(printDialog);
349 preview = gnome_print_job_preview_new(gpj, (guchar *)"Preview");
350 try_fix_print_preview_ui(preview);
351 gtk_window_set_modal(GTK_WINDOW(preview), TRUE);
352 gtk_widget_show_all(preview);
356 if (response == GNOME_PRINT_DIALOG_RESPONSE_PRINT) {
357 switch(gnome_print_dialog_get_range(GNOME_PRINT_DIALOG(printDialog))) {
358 case GNOME_PRINT_RANGE_RANGE:
359 gnome_print_dialog_get_range_page(GNOME_PRINT_DIALOG(printDialog), &fromPage, &toPage);
365 toPage = journal.npages-1;
368 gtk_widget_destroy(printDialog);
369 print_job_render(gpj, fromPage, toPage);
375 on_filePrintPDF_activate (GtkMenuItem *menuitem,
379 GtkWidget *dialog, *warning_dialog;
380 GtkFileFilter *filt_all, *filt_pdf;
381 char *filename, *in_fn;
388 dialog = gtk_file_chooser_dialog_new(_("Export to PDF"), GTK_WINDOW (winMain),
389 GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
390 GTK_STOCK_SAVE, GTK_RESPONSE_OK, NULL);
392 if (ui.filename!=NULL) {
393 if (g_str_has_suffix(ui.filename, ".xoj")) {
394 in_fn = g_strdup(ui.filename);
395 g_strlcpy(g_strrstr(in_fn, "xoj"), "pdf", 4);
398 in_fn = g_strdup_printf("%s.pdf", ui.filename);
399 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER (dialog), in_fn);
400 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), g_basename(in_fn));
402 curtime = time(NULL);
403 strftime(stime, 30, "%F-Note-%H-%M.pdf", localtime(&curtime));
404 if (ui.default_path!=NULL)
405 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (dialog), ui.default_path);
406 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), stime);
410 filt_all = gtk_file_filter_new();
411 gtk_file_filter_set_name(filt_all, _("All files"));
412 gtk_file_filter_add_pattern(filt_all, "*");
413 filt_pdf = gtk_file_filter_new();
414 gtk_file_filter_set_name(filt_pdf, _("PDF files"));
415 gtk_file_filter_add_pattern(filt_pdf, "*.pdf");
416 gtk_file_filter_add_pattern(filt_pdf, "*.PDF");
417 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_pdf);
418 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_all);
419 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
423 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
424 gtk_widget_destroy(dialog);
427 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
428 warn = g_file_test(filename, G_FILE_TEST_EXISTS);
430 warning_dialog = gtk_message_dialog_new(GTK_WINDOW(winMain),
431 GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
432 _("Should the file %s be overwritten?"), filename);
433 if (gtk_dialog_run(GTK_DIALOG(warning_dialog)) == GTK_RESPONSE_YES)
435 gtk_widget_destroy(warning_dialog);
439 gtk_widget_destroy(dialog);
441 set_cursor_busy(TRUE);
442 if (!print_to_pdf(filename)) {
443 set_cursor_busy(FALSE);
444 dialog = gtk_message_dialog_new(GTK_WINDOW (winMain), GTK_DIALOG_DESTROY_WITH_PARENT,
445 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Error creating file '%s'"), filename);
446 gtk_dialog_run(GTK_DIALOG(dialog));
447 gtk_widget_destroy(dialog);
449 set_cursor_busy(FALSE);
455 on_fileQuit_activate (GtkMenuItem *menuitem,
460 if (ok_to_close()) gtk_main_quit ();
465 on_editUndo_activate (GtkMenuItem *menuitem,
469 GList *list, *itemlist;
470 struct UndoErasureData *erasure;
472 struct Brush tmp_brush;
473 struct Background *tmp_bg;
476 GnomeCanvasGroup *group;
480 if (undo == NULL) return; // nothing to undo!
481 reset_selection(); // safer
482 if (undo->type == ITEM_STROKE || undo->type == ITEM_TEXT) {
483 // we're keeping the stroke info, but deleting the canvas item
484 gtk_object_destroy(GTK_OBJECT(undo->item->canvas_item));
485 undo->item->canvas_item = NULL;
486 // we also remove the object from its layer!
487 undo->layer->items = g_list_remove(undo->layer->items, undo->item);
488 undo->layer->nitems--;
490 else if (undo->type == ITEM_ERASURE || undo->type == ITEM_RECOGNIZER) {
491 for (list = undo->erasurelist; list!=NULL; list = list->next) {
492 erasure = (struct UndoErasureData *)list->data;
493 // delete all the created items
494 for (itemlist = erasure->replacement_items; itemlist!=NULL; itemlist = itemlist->next) {
495 it = (struct Item *)itemlist->data;
496 gtk_object_destroy(GTK_OBJECT(it->canvas_item));
497 it->canvas_item = NULL;
498 undo->layer->items = g_list_remove(undo->layer->items, it);
499 undo->layer->nitems--;
501 // recreate the deleted one
502 make_canvas_item_one(undo->layer->group, erasure->item);
504 undo->layer->items = g_list_insert(undo->layer->items, erasure->item,
506 if (erasure->npos == 0)
507 lower_canvas_item_to(undo->layer->group, erasure->item->canvas_item, NULL);
509 lower_canvas_item_to(undo->layer->group, erasure->item->canvas_item,
510 ((struct Item *)g_list_nth_data(undo->layer->items, erasure->npos-1))->canvas_item);
511 undo->layer->nitems++;
514 else if (undo->type == ITEM_NEW_BG_ONE || undo->type == ITEM_NEW_BG_RESIZE
515 || undo->type == ITEM_PAPER_RESIZE) {
516 if (undo->type != ITEM_PAPER_RESIZE) {
518 tmp_bg = undo->page->bg;
519 undo->page->bg = undo->bg;
521 undo->page->bg->canvas_item = undo->bg->canvas_item;
522 undo->bg->canvas_item = NULL;
524 if (undo->type != ITEM_NEW_BG_ONE) {
525 tmp_x = undo->page->width;
526 tmp_y = undo->page->height;
527 undo->page->width = undo->val_x;
528 undo->page->height = undo->val_y;
531 make_page_clipbox(undo->page);
533 update_canvas_bg(undo->page);
534 do_switch_page(g_list_index(journal.pages, undo->page), TRUE, TRUE);
536 else if (undo->type == ITEM_NEW_DEFAULT_BG) {
537 tmp_bg = ui.default_page.bg;
538 ui.default_page.bg = undo->bg;
540 tmp_x = ui.default_page.width;
541 tmp_y = ui.default_page.height;
542 ui.default_page.width = undo->val_x;
543 ui.default_page.height = undo->val_y;
547 else if (undo->type == ITEM_NEW_PAGE) {
548 // unmap the page; keep the page & its empty layer in memory
549 if (undo->page->group!=NULL) gtk_object_destroy(GTK_OBJECT(undo->page->group));
550 // also destroys the background and layer's canvas items
551 undo->page->group = NULL;
552 undo->page->bg->canvas_item = NULL;
553 journal.pages = g_list_remove(journal.pages, undo->page);
555 if (ui.cur_page == undo->page) ui.cur_page = NULL;
556 // so do_switch_page() won't try to remap the layers of the defunct page
557 if (ui.pageno >= undo->val) ui.pageno--;
558 if (ui.pageno < 0) ui.pageno = 0;
559 do_switch_page(ui.pageno, TRUE, TRUE);
561 else if (undo->type == ITEM_DELETE_PAGE) {
562 journal.pages = g_list_insert(journal.pages, undo->page, undo->val);
564 make_canvas_items(); // re-create the canvas items
565 do_switch_page(undo->val, TRUE, TRUE);
567 else if (undo->type == ITEM_MOVESEL) {
568 for (itemlist = undo->itemlist; itemlist != NULL; itemlist = itemlist->next) {
569 it = (struct Item *)itemlist->data;
570 if (it->canvas_item != NULL) {
571 if (undo->layer != undo->layer2)
572 gnome_canvas_item_reparent(it->canvas_item, undo->layer->group);
573 gnome_canvas_item_move(it->canvas_item, -undo->val_x, -undo->val_y);
576 move_journal_items_by(undo->itemlist, -undo->val_x, -undo->val_y,
577 undo->layer2, undo->layer, undo->auxlist);
579 else if (undo->type == ITEM_RESIZESEL) {
580 resize_journal_items_by(undo->itemlist,
581 1/undo->scaling_x, 1/undo->scaling_y,
582 -undo->val_x/undo->scaling_x, -undo->val_y/undo->scaling_y);
584 else if (undo->type == ITEM_PASTE) {
585 for (itemlist = undo->itemlist; itemlist != NULL; itemlist = itemlist->next) {
586 it = (struct Item *)itemlist->data;
587 gtk_object_destroy(GTK_OBJECT(it->canvas_item));
588 it->canvas_item = NULL;
589 undo->layer->items = g_list_remove(undo->layer->items, it);
590 undo->layer->nitems--;
593 else if (undo->type == ITEM_NEW_LAYER) {
594 // unmap the layer; keep the empty layer in memory
595 if (undo->layer->group!=NULL) gtk_object_destroy(GTK_OBJECT(undo->layer->group));
596 undo->layer->group = NULL;
597 undo->page->layers = g_list_remove(undo->page->layers, undo->layer);
598 undo->page->nlayers--;
599 do_switch_page(ui.pageno, FALSE, FALSE); // don't stay with bad cur_layer info
601 else if (undo->type == ITEM_DELETE_LAYER) {
602 // special case of -1: deleted the last layer, created a new one
603 if (undo->val == -1) {
604 if (undo->layer2->group!=NULL) gtk_object_destroy(GTK_OBJECT(undo->layer2->group));
605 undo->layer2->group = NULL;
606 undo->page->layers = g_list_remove(undo->page->layers, undo->layer2);
607 undo->page->nlayers--;
610 undo->layer->group = (GnomeCanvasGroup *) gnome_canvas_item_new(
611 undo->page->group, gnome_canvas_group_get_type(), NULL);
612 lower_canvas_item_to(undo->page->group, GNOME_CANVAS_ITEM(undo->layer->group),
613 (undo->val >= 1) ? GNOME_CANVAS_ITEM(((struct Layer *)
614 g_list_nth_data(undo->page->layers, undo->val-1))->group) :
615 undo->page->bg->canvas_item);
616 undo->page->layers = g_list_insert(undo->page->layers, undo->layer,
617 (undo->val >= 0) ? undo->val:0);
618 undo->page->nlayers++;
620 for (itemlist = undo->layer->items; itemlist!=NULL; itemlist = itemlist->next)
621 make_canvas_item_one(undo->layer->group, (struct Item *)itemlist->data);
623 do_switch_page(ui.pageno, FALSE, FALSE); // show the restored layer & others...
625 else if (undo->type == ITEM_REPAINTSEL) {
626 for (itemlist = undo->itemlist, list = undo->auxlist; itemlist!=NULL;
627 itemlist = itemlist->next, list = list->next) {
628 it = (struct Item *)itemlist->data;
629 g_memmove(&tmp_brush, &(it->brush), sizeof(struct Brush));
630 g_memmove(&(it->brush), list->data, sizeof(struct Brush));
631 g_memmove(list->data, &tmp_brush, sizeof(struct Brush));
632 if (it->type == ITEM_STROKE && it->canvas_item != NULL) {
633 // remark: a variable-width item might have lost its variable-width
634 group = (GnomeCanvasGroup *) it->canvas_item->parent;
635 gtk_object_destroy(GTK_OBJECT(it->canvas_item));
636 make_canvas_item_one(group, it);
638 if (it->type == ITEM_TEXT && it->canvas_item != NULL)
639 gnome_canvas_item_set(it->canvas_item,
640 "fill-color-rgba", it->brush.color_rgba, NULL);
643 else if (undo->type == ITEM_TEXT_EDIT) {
645 undo->str = undo->item->text;
646 undo->item->text = tmpstr;
647 gnome_canvas_item_set(undo->item->canvas_item, "text", tmpstr, NULL);
648 update_item_bbox(undo->item);
650 else if (undo->type == ITEM_TEXT_ATTRIB) {
652 undo->str = undo->item->font_name;
653 undo->item->font_name = tmpstr;
655 undo->val_x = undo->item->font_size;
656 undo->item->font_size = tmp_x;
657 g_memmove(&tmp_brush, undo->brush, sizeof(struct Brush));
658 g_memmove(undo->brush, &(undo->item->brush), sizeof(struct Brush));
659 g_memmove(&(undo->item->brush), &tmp_brush, sizeof(struct Brush));
660 gnome_canvas_item_set(undo->item->canvas_item,
661 "fill-color-rgba", undo->item->brush.color_rgba, NULL);
662 update_text_item_displayfont(undo->item);
663 update_item_bbox(undo->item);
666 // move item from undo to redo stack
672 update_undo_redo_enabled();
673 if (u->multiop & MULTIOP_CONT_UNDO) on_editUndo_activate(NULL,NULL); // loop
678 on_editRedo_activate (GtkMenuItem *menuitem,
682 GList *list, *itemlist, *target;
683 struct UndoErasureData *erasure;
685 struct Brush tmp_brush;
686 struct Background *tmp_bg;
690 GnomeCanvasGroup *group;
694 if (redo == NULL) return; // nothing to redo!
695 reset_selection(); // safer
696 if (redo->type == ITEM_STROKE || redo->type == ITEM_TEXT) {
697 // re-create the canvas_item
698 make_canvas_item_one(redo->layer->group, redo->item);
699 // reinsert the item on its layer
700 redo->layer->items = g_list_append(redo->layer->items, redo->item);
701 redo->layer->nitems++;
703 else if (redo->type == ITEM_ERASURE || redo->type == ITEM_RECOGNIZER) {
704 for (list = redo->erasurelist; list!=NULL; list = list->next) {
705 erasure = (struct UndoErasureData *)list->data;
706 target = g_list_find(redo->layer->items, erasure->item);
707 // re-create all the created items
708 for (itemlist = erasure->replacement_items; itemlist!=NULL; itemlist = itemlist->next) {
709 it = (struct Item *)itemlist->data;
710 make_canvas_item_one(redo->layer->group, it);
711 redo->layer->items = g_list_insert_before(redo->layer->items, target, it);
712 redo->layer->nitems++;
713 lower_canvas_item_to(redo->layer->group, it->canvas_item, erasure->item->canvas_item);
715 // re-delete the deleted one
716 gtk_object_destroy(GTK_OBJECT(erasure->item->canvas_item));
717 erasure->item->canvas_item = NULL;
718 redo->layer->items = g_list_delete_link(redo->layer->items, target);
719 redo->layer->nitems--;
722 else if (redo->type == ITEM_NEW_BG_ONE || redo->type == ITEM_NEW_BG_RESIZE
723 || redo->type == ITEM_PAPER_RESIZE) {
724 if (redo->type != ITEM_PAPER_RESIZE) {
726 tmp_bg = redo->page->bg;
727 redo->page->bg = redo->bg;
729 redo->page->bg->canvas_item = redo->bg->canvas_item;
730 redo->bg->canvas_item = NULL;
732 if (redo->type != ITEM_NEW_BG_ONE) {
733 tmp_x = redo->page->width;
734 tmp_y = redo->page->height;
735 redo->page->width = redo->val_x;
736 redo->page->height = redo->val_y;
739 make_page_clipbox(redo->page);
741 update_canvas_bg(redo->page);
742 do_switch_page(g_list_index(journal.pages, redo->page), TRUE, TRUE);
744 else if (redo->type == ITEM_NEW_DEFAULT_BG) {
745 tmp_bg = ui.default_page.bg;
746 ui.default_page.bg = redo->bg;
748 tmp_x = ui.default_page.width;
749 tmp_y = ui.default_page.height;
750 ui.default_page.width = redo->val_x;
751 ui.default_page.height = redo->val_y;
755 else if (redo->type == ITEM_NEW_PAGE) {
757 redo->page->bg->canvas_item = NULL;
758 redo->page->group = (GnomeCanvasGroup *) gnome_canvas_item_new(
759 gnome_canvas_root(canvas), gnome_canvas_clipgroup_get_type(), NULL);
760 make_page_clipbox(redo->page);
761 update_canvas_bg(redo->page);
762 l = (struct Layer *)redo->page->layers->data;
763 l->group = (GnomeCanvasGroup *) gnome_canvas_item_new(
764 redo->page->group, gnome_canvas_group_get_type(), NULL);
766 journal.pages = g_list_insert(journal.pages, redo->page, redo->val);
768 do_switch_page(redo->val, TRUE, TRUE);
770 else if (redo->type == ITEM_DELETE_PAGE) {
771 // unmap all the canvas items
772 gtk_object_destroy(GTK_OBJECT(redo->page->group));
773 redo->page->group = NULL;
774 redo->page->bg->canvas_item = NULL;
775 for (list = redo->page->layers; list!=NULL; list = list->next) {
776 l = (struct Layer *)list->data;
777 for (itemlist = l->items; itemlist!=NULL; itemlist = itemlist->next)
778 ((struct Item *)itemlist->data)->canvas_item = NULL;
781 journal.pages = g_list_remove(journal.pages, redo->page);
783 if (ui.pageno > redo->val || ui.pageno == journal.npages) ui.pageno--;
785 // so do_switch_page() won't try to remap the layers of the defunct page
786 do_switch_page(ui.pageno, TRUE, TRUE);
788 else if (redo->type == ITEM_MOVESEL) {
789 for (itemlist = redo->itemlist; itemlist != NULL; itemlist = itemlist->next) {
790 it = (struct Item *)itemlist->data;
791 if (it->canvas_item != NULL) {
792 if (redo->layer != redo->layer2)
793 gnome_canvas_item_reparent(it->canvas_item, redo->layer2->group);
794 gnome_canvas_item_move(it->canvas_item, redo->val_x, redo->val_y);
797 move_journal_items_by(redo->itemlist, redo->val_x, redo->val_y,
798 redo->layer, redo->layer2, NULL);
800 else if (redo->type == ITEM_RESIZESEL) {
801 resize_journal_items_by(redo->itemlist,
802 redo->scaling_x, redo->scaling_y, redo->val_x, redo->val_y);
804 else if (redo->type == ITEM_PASTE) {
805 for (itemlist = redo->itemlist; itemlist != NULL; itemlist = itemlist->next) {
806 it = (struct Item *)itemlist->data;
807 make_canvas_item_one(redo->layer->group, it);
808 redo->layer->items = g_list_append(redo->layer->items, it);
809 redo->layer->nitems++;
812 else if (redo->type == ITEM_NEW_LAYER) {
813 redo->layer->group = (GnomeCanvasGroup *) gnome_canvas_item_new(
814 redo->page->group, gnome_canvas_group_get_type(), NULL);
815 lower_canvas_item_to(redo->page->group, GNOME_CANVAS_ITEM(redo->layer->group),
816 (redo->val >= 1) ? GNOME_CANVAS_ITEM(((struct Layer *)
817 g_list_nth_data(redo->page->layers, redo->val-1))->group) :
818 redo->page->bg->canvas_item);
819 redo->page->layers = g_list_insert(redo->page->layers, redo->layer, redo->val);
820 redo->page->nlayers++;
821 do_switch_page(ui.pageno, FALSE, FALSE);
823 else if (redo->type == ITEM_DELETE_LAYER) {
824 gtk_object_destroy(GTK_OBJECT(redo->layer->group));
825 redo->layer->group = NULL;
826 for (list=redo->layer->items; list!=NULL; list=list->next)
827 ((struct Item *)list->data)->canvas_item = NULL;
828 redo->page->layers = g_list_remove(redo->page->layers, redo->layer);
829 redo->page->nlayers--;
830 if (redo->val == -1) {
831 redo->layer2->group = (GnomeCanvasGroup *)gnome_canvas_item_new(
832 redo->page->group, gnome_canvas_group_get_type(), NULL);
833 redo->page->layers = g_list_append(redo->page->layers, redo->layer2);
834 redo->page->nlayers++;
836 do_switch_page(ui.pageno, FALSE, FALSE);
838 else if (redo->type == ITEM_REPAINTSEL) {
839 for (itemlist = redo->itemlist, list = redo->auxlist; itemlist!=NULL;
840 itemlist = itemlist->next, list = list->next) {
841 it = (struct Item *)itemlist->data;
842 g_memmove(&tmp_brush, &(it->brush), sizeof(struct Brush));
843 g_memmove(&(it->brush), list->data, sizeof(struct Brush));
844 g_memmove(list->data, &tmp_brush, sizeof(struct Brush));
845 if (it->type == ITEM_STROKE && it->canvas_item != NULL) {
846 // remark: a variable-width item might have lost its variable-width
847 group = (GnomeCanvasGroup *) it->canvas_item->parent;
848 gtk_object_destroy(GTK_OBJECT(it->canvas_item));
849 make_canvas_item_one(group, it);
851 if (it->type == ITEM_TEXT && it->canvas_item != NULL)
852 gnome_canvas_item_set(it->canvas_item,
853 "fill-color-rgba", it->brush.color_rgba, NULL);
856 else if (redo->type == ITEM_TEXT_EDIT) {
858 redo->str = redo->item->text;
859 redo->item->text = tmpstr;
860 gnome_canvas_item_set(redo->item->canvas_item, "text", tmpstr, NULL);
861 update_item_bbox(redo->item);
863 else if (redo->type == ITEM_TEXT_ATTRIB) {
865 redo->str = redo->item->font_name;
866 redo->item->font_name = tmpstr;
868 redo->val_x = redo->item->font_size;
869 redo->item->font_size = tmp_x;
870 g_memmove(&tmp_brush, redo->brush, sizeof(struct Brush));
871 g_memmove(redo->brush, &(redo->item->brush), sizeof(struct Brush));
872 g_memmove(&(redo->item->brush), &tmp_brush, sizeof(struct Brush));
873 gnome_canvas_item_set(redo->item->canvas_item,
874 "fill-color-rgba", redo->item->brush.color_rgba, NULL);
875 update_text_item_displayfont(redo->item);
876 update_item_bbox(redo->item);
879 // move item from redo to undo stack
885 update_undo_redo_enabled();
886 if (u->multiop & MULTIOP_CONT_REDO) on_editRedo_activate(NULL,NULL); // loop
891 on_editCut_activate (GtkMenuItem *menuitem,
902 on_editCopy_activate (GtkMenuItem *menuitem,
912 on_editPaste_activate (GtkMenuItem *menuitem,
922 on_editDelete_activate (GtkMenuItem *menuitem,
932 on_viewContinuous_activate (GtkMenuItem *menuitem,
935 GtkAdjustment *v_adj;
940 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem))) return;
941 if (ui.view_continuous) return;
942 ui.view_continuous = TRUE;
943 v_adj = gtk_layout_get_vadjustment(GTK_LAYOUT(canvas));
945 yscroll = gtk_adjustment_get_value(v_adj) - pg->voffset*ui.zoom;
947 gtk_adjustment_set_value(v_adj, yscroll + pg->voffset*ui.zoom);
949 gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
954 on_viewOnePage_activate (GtkMenuItem *menuitem,
957 GtkAdjustment *v_adj;
961 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem))) return;
962 if (!ui.view_continuous) return;
963 ui.view_continuous = FALSE;
964 v_adj = gtk_layout_get_vadjustment(GTK_LAYOUT(canvas));
965 yscroll = gtk_adjustment_get_value(v_adj) - ui.cur_page->voffset*ui.zoom;
967 gtk_adjustment_set_value(v_adj, yscroll + ui.cur_page->voffset*ui.zoom);
969 gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
974 on_viewZoomIn_activate (GtkMenuItem *menuitem,
978 if (ui.zoom > MAX_ZOOM) return;
979 ui.zoom *= ui.zoom_step_factor;
980 gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
981 rescale_text_items();
982 rescale_bg_pixmaps();
987 on_viewZoomOut_activate (GtkMenuItem *menuitem,
991 if (ui.zoom < MIN_ZOOM) return;
992 ui.zoom /= ui.zoom_step_factor;
993 gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
994 rescale_text_items();
995 rescale_bg_pixmaps();
1000 on_viewNormalSize_activate (GtkMenuItem *menuitem,
1004 ui.zoom = DEFAULT_ZOOM;
1005 gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
1006 rescale_text_items();
1007 rescale_bg_pixmaps();
1012 on_viewPageWidth_activate (GtkMenuItem *menuitem,
1016 ui.zoom = (GTK_WIDGET(canvas))->allocation.width/ui.cur_page->width;
1017 gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
1018 rescale_text_items();
1019 rescale_bg_pixmaps();
1024 on_viewFirstPage_activate (GtkMenuItem *menuitem,
1029 do_switch_page(0, TRUE, FALSE);
1034 on_viewPreviousPage_activate (GtkMenuItem *menuitem,
1039 if (ui.pageno == 0) return;
1040 do_switch_page(ui.pageno-1, TRUE, FALSE);
1045 on_viewNextPage_activate (GtkMenuItem *menuitem,
1050 if (ui.pageno == journal.npages-1) { // create a page at end
1051 on_journalNewPageEnd_activate(menuitem, user_data);
1054 do_switch_page(ui.pageno+1, TRUE, FALSE);
1059 on_viewLastPage_activate (GtkMenuItem *menuitem,
1064 do_switch_page(journal.npages-1, TRUE, FALSE);
1069 on_viewShowLayer_activate (GtkMenuItem *menuitem,
1074 if (ui.layerno == ui.cur_page->nlayers-1) return;
1077 ui.cur_layer = g_list_nth_data(ui.cur_page->layers, ui.layerno);
1078 gnome_canvas_item_show(GNOME_CANVAS_ITEM(ui.cur_layer->group));
1079 update_page_stuff();
1084 on_viewHideLayer_activate (GtkMenuItem *menuitem,
1089 if (ui.layerno == -1) return;
1091 gnome_canvas_item_hide(GNOME_CANVAS_ITEM(ui.cur_layer->group));
1093 if (ui.layerno<0) ui.cur_layer = NULL;
1094 else ui.cur_layer = g_list_nth_data(ui.cur_page->layers, ui.layerno);
1095 update_page_stuff();
1100 on_journalNewPageBefore_activate (GtkMenuItem *menuitem,
1108 pg = new_page(ui.cur_page);
1109 journal.pages = g_list_insert(journal.pages, pg, ui.pageno);
1111 do_switch_page(ui.pageno, TRUE, TRUE);
1114 undo->type = ITEM_NEW_PAGE;
1115 undo->val = ui.pageno;
1121 on_journalNewPageAfter_activate (GtkMenuItem *menuitem,
1129 pg = new_page(ui.cur_page);
1130 journal.pages = g_list_insert(journal.pages, pg, ui.pageno+1);
1132 do_switch_page(ui.pageno+1, TRUE, TRUE);
1135 undo->type = ITEM_NEW_PAGE;
1136 undo->val = ui.pageno;
1142 on_journalNewPageEnd_activate (GtkMenuItem *menuitem,
1150 pg = new_page((struct Page *)g_list_last(journal.pages)->data);
1151 journal.pages = g_list_append(journal.pages, pg);
1153 do_switch_page(journal.npages-1, TRUE, TRUE);
1156 undo->type = ITEM_NEW_PAGE;
1157 undo->val = ui.pageno;
1163 on_journalDeletePage_activate (GtkMenuItem *menuitem,
1166 GList *layerlist, *itemlist;
1171 if (journal.npages == 1) return;
1174 undo->type = ITEM_DELETE_PAGE;
1175 undo->val = ui.pageno;
1176 undo->page = ui.cur_page;
1178 // unmap all the canvas items
1179 gtk_object_destroy(GTK_OBJECT(ui.cur_page->group));
1180 ui.cur_page->group = NULL;
1181 ui.cur_page->bg->canvas_item = NULL;
1182 for (layerlist = ui.cur_page->layers; layerlist!=NULL; layerlist = layerlist->next) {
1183 l = (struct Layer *)layerlist->data;
1184 for (itemlist = l->items; itemlist!=NULL; itemlist = itemlist->next)
1185 ((struct Item *)itemlist->data)->canvas_item = NULL;
1189 journal.pages = g_list_remove(journal.pages, ui.cur_page);
1191 if (ui.pageno == journal.npages) ui.pageno--;
1193 // so do_switch_page() won't try to remap the layers of the defunct page
1194 do_switch_page(ui.pageno, TRUE, TRUE);
1199 on_journalNewLayer_activate (GtkMenuItem *menuitem,
1207 l = g_new(struct Layer, 1);
1210 l->group = (GnomeCanvasGroup *) gnome_canvas_item_new(
1211 ui.cur_page->group, gnome_canvas_group_get_type(), NULL);
1212 lower_canvas_item_to(ui.cur_page->group, GNOME_CANVAS_ITEM(l->group),
1213 (ui.cur_layer!=NULL)?(GNOME_CANVAS_ITEM(ui.cur_layer->group)):(ui.cur_page->bg->canvas_item));
1214 ui.cur_page->layers = g_list_insert(ui.cur_page->layers, l, ui.layerno+1);
1217 ui.cur_page->nlayers++;
1218 update_page_stuff();
1221 undo->type = ITEM_NEW_LAYER;
1222 undo->val = ui.layerno;
1224 undo->page = ui.cur_page;
1229 on_journalDeleteLayer_activate (GtkMenuItem *menuitem,
1236 if (ui.cur_layer == NULL) return;
1239 undo->type = ITEM_DELETE_LAYER;
1240 undo->val = ui.layerno;
1241 undo->layer = ui.cur_layer;
1242 undo->layer2 = NULL;
1243 undo->page = ui.cur_page;
1244 // delete all the canvas items
1245 gtk_object_destroy(GTK_OBJECT(ui.cur_layer->group));
1246 ui.cur_layer->group = NULL;
1247 for (list=ui.cur_layer->items; list!=NULL; list=list->next)
1248 ((struct Item *)list->data)->canvas_item = NULL;
1250 ui.cur_page->layers = g_list_remove(ui.cur_page->layers, ui.cur_layer);
1252 if (ui.cur_page->nlayers>=2) {
1253 ui.cur_page->nlayers--;
1255 if (ui.layerno<0) ui.cur_layer = NULL;
1256 else ui.cur_layer = (struct Layer *)g_list_nth_data(ui.cur_page->layers, ui.layerno);
1258 else { // special case: can't remove the last layer
1259 ui.cur_layer = g_new(struct Layer, 1);
1260 ui.cur_layer->items = NULL;
1261 ui.cur_layer->nitems = 0;
1262 ui.cur_layer->group = (GnomeCanvasGroup *) gnome_canvas_item_new(
1263 ui.cur_page->group, gnome_canvas_group_get_type(), NULL);
1264 ui.cur_page->layers = g_list_append(NULL, ui.cur_layer);
1266 undo->layer2 = ui.cur_layer;
1269 update_page_stuff();
1274 on_journalFlatten_activate (GtkMenuItem *menuitem,
1281 // the paper sizes dialog
1283 GtkWidget *papersize_dialog;
1284 int papersize_std, papersize_unit;
1285 double papersize_width, papersize_height;
1286 gboolean papersize_need_init, papersize_width_valid, papersize_height_valid;
1288 #define STD_SIZE_A4 0
1289 #define STD_SIZE_A4R 1
1290 #define STD_SIZE_LETTER 2
1291 #define STD_SIZE_LETTER_R 3
1292 #define STD_SIZE_CUSTOM 4
1294 double unit_sizes[4] = {28.346, 72., 72./DISPLAY_DPI_DEFAULT, 1.};
1295 double std_widths[STD_SIZE_CUSTOM] = {595.27, 841.89, 612., 792.};
1296 double std_heights[STD_SIZE_CUSTOM] = {841.89, 595.27, 792., 612.};
1297 double std_units[STD_SIZE_CUSTOM] = {UNIT_CM, UNIT_CM, UNIT_IN, UNIT_IN};
1300 on_journalPaperSize_activate (GtkMenuItem *menuitem,
1309 papersize_dialog = create_papersizeDialog();
1310 papersize_width = ui.cur_page->width;
1311 papersize_height = ui.cur_page->height;
1312 papersize_unit = ui.default_unit;
1313 unit_sizes[UNIT_PX] = 1./DEFAULT_ZOOM;
1314 // if (ui.cur_page->bg->type == BG_PIXMAP) papersize_unit = UNIT_PX;
1315 papersize_std = STD_SIZE_CUSTOM;
1316 for (i=0;i<STD_SIZE_CUSTOM;i++)
1317 if (fabs(papersize_width - std_widths[i])<0.1 &&
1318 fabs(papersize_height - std_heights[i])<0.1)
1319 { papersize_std = i; papersize_unit = std_units[i]; }
1320 papersize_need_init = TRUE;
1321 papersize_width_valid = papersize_height_valid = TRUE;
1323 gtk_widget_show(papersize_dialog);
1324 on_comboStdSizes_changed(GTK_COMBO_BOX(g_object_get_data(
1325 G_OBJECT(papersize_dialog), "comboStdSizes")), NULL);
1326 gtk_dialog_set_default_response(GTK_DIALOG(papersize_dialog), GTK_RESPONSE_OK);
1328 response = gtk_dialog_run(GTK_DIALOG(papersize_dialog));
1329 gtk_widget_destroy(papersize_dialog);
1330 if (response != GTK_RESPONSE_OK) return;
1333 for (pglist = journal.pages; pglist!=NULL; pglist = pglist->next) {
1334 if (ui.bg_apply_all_pages) pg = (struct Page *)pglist->data;
1336 if (ui.bg_apply_all_pages) {
1337 if (pglist->next!=NULL) undo->multiop |= MULTIOP_CONT_REDO;
1338 if (pglist->prev!=NULL) undo->multiop |= MULTIOP_CONT_UNDO;
1340 undo->type = ITEM_PAPER_RESIZE;
1342 undo->val_x = pg->width;
1343 undo->val_y = pg->height;
1344 if (papersize_width_valid) pg->width = papersize_width;
1345 if (papersize_height_valid) pg->height = papersize_height;
1346 make_page_clipbox(pg);
1347 update_canvas_bg(pg);
1348 if (!ui.bg_apply_all_pages) break;
1350 do_switch_page(ui.pageno, TRUE, TRUE);
1355 on_papercolorWhite_activate (GtkMenuItem *menuitem,
1360 process_papercolor_activate(menuitem, COLOR_WHITE);
1365 on_papercolorYellow_activate (GtkMenuItem *menuitem,
1370 process_papercolor_activate(menuitem, COLOR_YELLOW);
1375 on_papercolorPink_activate (GtkMenuItem *menuitem,
1380 process_papercolor_activate(menuitem, COLOR_RED);
1385 on_papercolorOrange_activate (GtkMenuItem *menuitem,
1390 process_papercolor_activate(menuitem, COLOR_ORANGE);
1395 on_papercolorBlue_activate (GtkMenuItem *menuitem,
1400 process_papercolor_activate(menuitem, COLOR_BLUE);
1405 on_papercolorGreen_activate (GtkMenuItem *menuitem,
1410 process_papercolor_activate(menuitem, COLOR_GREEN);
1415 on_papercolorOther_activate (GtkMenuItem *menuitem,
1423 on_paperstylePlain_activate (GtkMenuItem *menuitem,
1428 process_paperstyle_activate(menuitem, RULING_NONE);
1433 on_paperstyleLined_activate (GtkMenuItem *menuitem,
1438 process_paperstyle_activate(menuitem, RULING_LINED);
1443 on_paperstyleRuled_activate (GtkMenuItem *menuitem,
1448 process_paperstyle_activate(menuitem, RULING_RULED);
1453 on_paperstyleGraph_activate (GtkMenuItem *menuitem,
1458 process_paperstyle_activate(menuitem, RULING_GRAPH);
1463 on_journalLoadBackground_activate (GtkMenuItem *menuitem,
1466 GtkWidget *dialog, *attach_opt;
1467 struct Background *bg;
1470 GList *bglist, *bglistiter;
1471 GtkFileFilter *filt_all, *filt_pix, *filt_pspdf;
1477 dialog = gtk_file_chooser_dialog_new(_("Open Background"), GTK_WINDOW (winMain),
1478 GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1479 GTK_STOCK_OPEN, GTK_RESPONSE_OK, NULL);
1481 filt_all = gtk_file_filter_new();
1482 gtk_file_filter_set_name(filt_all, _("All files"));
1483 gtk_file_filter_add_pattern(filt_all, "*");
1484 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_all);
1486 #if GTK_CHECK_VERSION(2,6,0)
1488 if (!gtk_check_version(2, 6, 0)) {
1489 filt_pix = gtk_file_filter_new();
1490 gtk_file_filter_set_name(filt_pix, _("Bitmap files"));
1491 gtk_file_filter_add_pixbuf_formats(filt_pix);
1492 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_pix);
1497 filt_pspdf = gtk_file_filter_new();
1498 gtk_file_filter_set_name(filt_pspdf, _("PS/PDF files (as bitmaps)"));
1499 gtk_file_filter_add_pattern(filt_pspdf, "*.ps");
1500 gtk_file_filter_add_pattern(filt_pspdf, "*.PS");
1501 gtk_file_filter_add_pattern(filt_pspdf, "*.pdf");
1502 gtk_file_filter_add_pattern(filt_pspdf, "*.PDF");
1503 gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filt_pspdf);
1505 attach_opt = gtk_check_button_new_with_label(_("Attach file to the journal"));
1506 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(attach_opt), FALSE);
1507 gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER (dialog), attach_opt);
1509 if (ui.default_path!=NULL) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER (dialog), ui.default_path);
1511 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
1512 gtk_widget_destroy(dialog);
1515 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
1516 attach = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(attach_opt));
1517 gtk_widget_destroy(dialog);
1519 set_cursor_busy(TRUE);
1520 bg = attempt_load_pix_bg(filename, attach);
1521 if (bg != NULL) bglist = g_list_append(NULL, bg);
1522 else bglist = attempt_load_gv_bg(filename);
1523 set_cursor_busy(FALSE);
1525 if (bglist == NULL) {
1526 dialog = gtk_message_dialog_new(GTK_WINDOW(winMain), GTK_DIALOG_MODAL,
1527 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
1528 _("Error opening background '%s'"), filename);
1529 gtk_dialog_run(GTK_DIALOG(dialog));
1530 gtk_widget_destroy(dialog);
1539 for (bglistiter = bglist, pageno = ui.pageno;
1540 bglistiter!=NULL; bglistiter = bglistiter->next, pageno++) {
1542 if (bglistiter->next!=NULL) undo->multiop |= MULTIOP_CONT_REDO;
1543 if (bglistiter->prev!=NULL) undo->multiop |= MULTIOP_CONT_UNDO;
1545 bg = (struct Background *)bglistiter->data;
1547 if (pageno == journal.npages) {
1548 undo->type = ITEM_NEW_PAGE;
1549 pg = new_page_with_bg(bg,
1550 gdk_pixbuf_get_width(bg->pixbuf)/bg->pixbuf_scale,
1551 gdk_pixbuf_get_height(bg->pixbuf)/bg->pixbuf_scale);
1552 journal.pages = g_list_append(journal.pages, pg);
1558 pg = g_list_nth_data(journal.pages, pageno);
1559 undo->type = ITEM_NEW_BG_RESIZE;
1562 bg->canvas_item = undo->bg->canvas_item;
1563 undo->bg->canvas_item = NULL;
1564 undo->val_x = pg->width;
1565 undo->val_y = pg->height;
1567 pg->width = gdk_pixbuf_get_width(bg->pixbuf)/bg->pixbuf_scale;
1568 pg->height = gdk_pixbuf_get_height(bg->pixbuf)/bg->pixbuf_scale;
1569 make_page_clipbox(pg);
1570 update_canvas_bg(pg);
1574 g_list_free(bglist);
1575 if (ui.zoom != DEFAULT_ZOOM) {
1576 ui.zoom = DEFAULT_ZOOM;
1577 gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
1578 rescale_text_items();
1579 rescale_bg_pixmaps();
1581 do_switch_page(ui.pageno, TRUE, TRUE);
1585 on_journalScreenshot_activate (GtkMenuItem *menuitem,
1588 struct Background *bg;
1593 gtk_window_iconify(GTK_WINDOW(winMain)); // hide ourselves
1594 gdk_display_sync(gdk_display_get_default());
1596 if (ui.cursor!=NULL)
1597 gdk_cursor_unref(ui.cursor);
1598 ui.cursor = gdk_cursor_new(GDK_TCROSS);
1600 bg = attempt_screenshot_bg();
1602 gtk_window_deiconify(GTK_WINDOW(winMain));
1604 if (bg==NULL) return;
1607 undo->type = ITEM_NEW_BG_RESIZE;
1608 undo->page = ui.cur_page;
1609 undo->bg = ui.cur_page->bg;
1610 bg->canvas_item = undo->bg->canvas_item;
1611 undo->bg->canvas_item = NULL;
1612 undo->val_x = ui.cur_page->width;
1613 undo->val_y = ui.cur_page->height;
1615 ui.cur_page->bg = bg;
1616 ui.cur_page->width = gdk_pixbuf_get_width(bg->pixbuf)/bg->pixbuf_scale;
1617 ui.cur_page->height = gdk_pixbuf_get_height(bg->pixbuf)/bg->pixbuf_scale;
1619 make_page_clipbox(ui.cur_page);
1620 update_canvas_bg(ui.cur_page);
1622 if (ui.zoom != DEFAULT_ZOOM) {
1623 ui.zoom = DEFAULT_ZOOM;
1624 gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
1625 rescale_text_items();
1626 rescale_bg_pixmaps();
1628 do_switch_page(ui.pageno, TRUE, TRUE);
1633 on_journalApplyAllPages_activate (GtkMenuItem *menuitem,
1640 active = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
1641 if (active == ui.bg_apply_all_pages) return;
1642 ui.bg_apply_all_pages = active;
1643 update_page_stuff();
1645 /* THIS IS THE OLD VERSION OF THE FEATURE -- APPLIED CURRENT BG TO ALL
1649 if (ui.cur_page->bg->type != BG_SOLID) return;
1651 for (pglist = journal.pages; pglist!=NULL; pglist = pglist->next) {
1652 page = (struct Page *)pglist->data;
1654 undo->type = ITEM_NEW_BG_RESIZE;
1656 undo->bg = page->bg;
1657 undo->val_x = page->width;
1658 undo->val_y = page->height;
1659 if (pglist->next!=NULL) undo->multiop |= MULTIOP_CONT_REDO;
1660 if (pglist->prev!=NULL) undo->multiop |= MULTIOP_CONT_UNDO;
1661 page->bg = (struct Background *)g_memdup(ui.cur_page->bg, sizeof(struct Background));
1662 page->width = ui.cur_page->width;
1663 page->height = ui.cur_page->height;
1664 page->bg->canvas_item = undo->bg->canvas_item;
1665 undo->bg->canvas_item = NULL;
1667 make_page_clipbox(page);
1668 update_canvas_bg(page);
1670 do_switch_page(ui.pageno, TRUE, TRUE);
1677 on_toolsPen_activate (GtkMenuItem *menuitem,
1680 if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_RADIO_MENU_ITEM) {
1681 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem)))
1684 if (!gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON (menuitem)))
1688 if (ui.cur_mapping != 0) return;
1689 if (ui.toolno[0] == TOOL_PEN) return;
1694 ui.toolno[0] = TOOL_PEN;
1695 ui.cur_brush = &(ui.brushes[0][TOOL_PEN]);
1696 ui.cur_brush->ruler = ui.default_brushes[TOOL_PEN].ruler;
1697 ui.cur_brush->recognizer = ui.default_brushes[TOOL_PEN].recognizer;
1698 update_mapping_linkings(TOOL_PEN);
1699 update_tool_buttons();
1701 update_color_menu();
1707 on_toolsEraser_activate (GtkMenuItem *menuitem,
1710 if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_RADIO_MENU_ITEM) {
1711 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem)))
1714 if (!gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON (menuitem)))
1718 if (ui.cur_mapping != 0) return;
1719 if (ui.toolno[0] == TOOL_ERASER) return;
1724 ui.toolno[0] = TOOL_ERASER;
1725 ui.cur_brush = &(ui.brushes[0][TOOL_ERASER]);
1726 update_mapping_linkings(TOOL_ERASER);
1727 update_tool_buttons();
1729 update_color_menu();
1735 on_toolsHighlighter_activate (GtkMenuItem *menuitem,
1738 if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_RADIO_MENU_ITEM) {
1739 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem)))
1742 if (!gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON (menuitem)))
1746 if (ui.cur_mapping != 0) return; // not user-generated
1747 if (ui.toolno[0] == TOOL_HIGHLIGHTER) return;
1752 ui.toolno[0] = TOOL_HIGHLIGHTER;
1753 ui.cur_brush = &(ui.brushes[0][TOOL_HIGHLIGHTER]);
1754 ui.cur_brush->ruler = ui.default_brushes[TOOL_HIGHLIGHTER].ruler;
1755 ui.cur_brush->recognizer = ui.default_brushes[TOOL_HIGHLIGHTER].recognizer;
1756 update_mapping_linkings(TOOL_HIGHLIGHTER);
1757 update_tool_buttons();
1759 update_color_menu();
1765 on_toolsText_activate (GtkMenuItem *menuitem,
1768 if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_RADIO_MENU_ITEM) {
1769 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem)))
1772 if (!gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON (menuitem)))
1776 if (ui.cur_mapping != 0) return; // not user-generated
1777 if (ui.toolno[0] == TOOL_TEXT) return;
1781 ui.toolno[0] = TOOL_TEXT;
1782 ui.cur_brush = &(ui.brushes[0][TOOL_PEN]);
1783 update_mapping_linkings(-1);
1784 update_tool_buttons();
1786 update_color_menu();
1792 on_toolsSelectRegion_activate (GtkMenuItem *menuitem,
1800 on_toolsSelectRectangle_activate (GtkMenuItem *menuitem,
1803 if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_RADIO_MENU_ITEM) {
1804 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem)))
1807 if (!gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON (menuitem)))
1811 if (ui.cur_mapping != 0) return; // not user-generated
1812 if (ui.toolno[0] == TOOL_SELECTRECT) return;
1816 ui.toolno[0] = TOOL_SELECTRECT;
1817 update_mapping_linkings(-1);
1818 update_tool_buttons();
1820 update_color_menu();
1826 on_toolsVerticalSpace_activate (GtkMenuItem *menuitem,
1829 if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_RADIO_MENU_ITEM) {
1830 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem)))
1833 if (!gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON (menuitem)))
1837 if (ui.cur_mapping != 0) return; // not user-generated
1838 if (ui.toolno[0] == TOOL_VERTSPACE) return;
1843 ui.toolno[0] = TOOL_VERTSPACE;
1844 update_mapping_linkings(-1);
1845 update_tool_buttons();
1847 update_color_menu();
1853 on_colorBlack_activate (GtkMenuItem *menuitem,
1856 process_color_activate(menuitem, COLOR_BLACK);
1861 on_colorBlue_activate (GtkMenuItem *menuitem,
1864 process_color_activate(menuitem, COLOR_BLUE);
1870 on_colorRed_activate (GtkMenuItem *menuitem,
1873 process_color_activate(menuitem, COLOR_RED);
1878 on_colorGreen_activate (GtkMenuItem *menuitem,
1881 process_color_activate(menuitem, COLOR_GREEN);
1886 on_colorGray_activate (GtkMenuItem *menuitem,
1889 process_color_activate(menuitem, COLOR_GRAY);
1894 on_colorLightBlue_activate (GtkMenuItem *menuitem,
1897 process_color_activate(menuitem, COLOR_LIGHTBLUE);
1902 on_colorLightGreen_activate (GtkMenuItem *menuitem,
1905 process_color_activate(menuitem, COLOR_LIGHTGREEN);
1910 on_colorMagenta_activate (GtkMenuItem *menuitem,
1913 process_color_activate(menuitem, COLOR_MAGENTA);
1918 on_colorOrange_activate (GtkMenuItem *menuitem,
1921 process_color_activate(menuitem, COLOR_ORANGE);
1926 on_colorYellow_activate (GtkMenuItem *menuitem,
1929 process_color_activate(menuitem, COLOR_YELLOW);
1934 on_colorWhite_activate (GtkMenuItem *menuitem,
1937 process_color_activate(menuitem, COLOR_WHITE);
1942 on_colorOther_activate (GtkMenuItem *menuitem,
1950 on_penthicknessVeryFine_activate (GtkMenuItem *menuitem,
1953 process_thickness_activate(menuitem, TOOL_PEN, THICKNESS_VERYFINE);
1958 on_penthicknessFine_activate (GtkMenuItem *menuitem,
1961 process_thickness_activate(menuitem, TOOL_PEN, THICKNESS_FINE);
1966 on_penthicknessMedium_activate (GtkMenuItem *menuitem,
1969 process_thickness_activate(menuitem, TOOL_PEN, THICKNESS_MEDIUM);
1974 on_penthicknessThick_activate (GtkMenuItem *menuitem,
1977 process_thickness_activate(menuitem, TOOL_PEN, THICKNESS_THICK);
1982 on_penthicknessVeryThick_activate (GtkMenuItem *menuitem,
1985 process_thickness_activate(menuitem, TOOL_PEN, THICKNESS_VERYTHICK);
1990 on_eraserFine_activate (GtkMenuItem *menuitem,
1993 process_thickness_activate(menuitem, TOOL_ERASER, THICKNESS_FINE);
1998 on_eraserMedium_activate (GtkMenuItem *menuitem,
2001 process_thickness_activate(menuitem, TOOL_ERASER, THICKNESS_MEDIUM);
2006 on_eraserThick_activate (GtkMenuItem *menuitem,
2009 process_thickness_activate(menuitem, TOOL_ERASER, THICKNESS_THICK);
2014 on_eraserStandard_activate (GtkMenuItem *menuitem,
2017 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem))) return;
2020 ui.brushes[0][TOOL_ERASER].tool_options = TOOLOPT_ERASER_STANDARD;
2021 update_mapping_linkings(TOOL_ERASER);
2026 on_eraserWhiteout_activate (GtkMenuItem *menuitem,
2029 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem))) return;
2032 ui.brushes[0][TOOL_ERASER].tool_options = TOOLOPT_ERASER_WHITEOUT;
2033 update_mapping_linkings(TOOL_ERASER);
2038 on_eraserDeleteStrokes_activate (GtkMenuItem *menuitem,
2041 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem))) return;
2044 ui.brushes[0][TOOL_ERASER].tool_options = TOOLOPT_ERASER_STROKES;
2045 update_mapping_linkings(TOOL_ERASER);
2050 on_highlighterFine_activate (GtkMenuItem *menuitem,
2053 process_thickness_activate(menuitem, TOOL_HIGHLIGHTER, THICKNESS_FINE);
2058 on_highlighterMedium_activate (GtkMenuItem *menuitem,
2061 process_thickness_activate(menuitem, TOOL_HIGHLIGHTER, THICKNESS_MEDIUM);
2066 on_highlighterThick_activate (GtkMenuItem *menuitem,
2069 process_thickness_activate(menuitem, TOOL_HIGHLIGHTER, THICKNESS_THICK);
2074 on_toolsTextFont_activate (GtkMenuItem *menuitem,
2080 dialog = gtk_font_selection_dialog_new(_("Select Font"));
2081 str = make_cur_font_name();
2082 gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(dialog), str);
2084 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK) {
2085 gtk_widget_destroy(dialog);
2089 str = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(dialog));
2090 gtk_widget_destroy(dialog);
2091 process_font_sel(str);
2095 on_toolsDefaultPen_activate (GtkMenuItem *menuitem,
2102 g_memmove(&(ui.brushes[0][TOOL_PEN]), ui.default_brushes+TOOL_PEN, sizeof(struct Brush));
2103 ui.toolno[0] = TOOL_PEN;
2104 ui.cur_brush = &(ui.brushes[0][TOOL_PEN]);
2105 update_mapping_linkings(TOOL_PEN);
2106 update_tool_buttons();
2108 update_pen_props_menu();
2109 update_color_menu();
2115 on_toolsDefaultEraser_activate (GtkMenuItem *menuitem,
2122 g_memmove(&(ui.brushes[0][TOOL_ERASER]), ui.default_brushes+TOOL_ERASER, sizeof(struct Brush));
2123 ui.toolno[0] = TOOL_ERASER;
2124 ui.cur_brush = &(ui.brushes[0][TOOL_ERASER]);
2125 update_mapping_linkings(TOOL_ERASER);
2126 update_tool_buttons();
2128 update_eraser_props_menu();
2129 update_color_menu();
2135 on_toolsDefaultHighlighter_activate (GtkMenuItem *menuitem,
2142 g_memmove(&(ui.brushes[0][TOOL_HIGHLIGHTER]), ui.default_brushes+TOOL_HIGHLIGHTER, sizeof(struct Brush));
2143 ui.toolno[0] = TOOL_HIGHLIGHTER;
2144 ui.cur_brush = &(ui.brushes[0][TOOL_HIGHLIGHTER]);
2145 update_mapping_linkings(TOOL_HIGHLIGHTER);
2146 update_tool_buttons();
2148 update_highlighter_props_menu();
2149 update_color_menu();
2154 on_toolsDefaultText_activate (GtkMenuItem *menuitem,
2158 if (ui.toolno[0]!=TOOL_TEXT) end_text();
2161 ui.toolno[0] = TOOL_TEXT;
2162 ui.cur_brush = &(ui.brushes[0][TOOL_PEN]);
2163 ui.cur_brush->color_no = ui.default_brushes[TOOL_PEN].color_no;
2164 ui.cur_brush->color_rgba = ui.default_brushes[TOOL_PEN].color_rgba;
2165 g_free(ui.font_name);
2166 ui.font_name = g_strdup(ui.default_font_name);
2167 ui.font_size = ui.default_font_size;
2168 if (ui.cur_item_type == ITEM_TEXT) {
2169 refont_text_item(ui.cur_item, ui.font_name, ui.font_size);
2171 update_font_button();
2172 update_mapping_linkings(-1);
2173 update_tool_buttons();
2175 update_color_menu();
2181 on_toolsSetAsDefault_activate (GtkMenuItem *menuitem,
2186 if (ui.cur_mapping!=0) return;
2187 if (ui.toolno[0] < NUM_STROKE_TOOLS)
2188 g_memmove(ui.default_brushes+ui.toolno[0], &(ui.brushes[0][ui.toolno[0]]), sizeof(struct Brush));
2189 if (ui.toolno[0] == TOOL_TEXT) {
2190 if (ui.cur_item_type == ITEM_TEXT) {
2191 g_free(ui.font_name);
2192 ui.font_name = g_strdup(ui.cur_item->font_name);
2193 ui.font_size = ui.cur_item->font_size;
2195 else if (ui.selection!=NULL && ui.selection->items!=NULL &&
2196 ui.selection->items->next==NULL &&
2197 (it=(struct Item*)ui.selection->items->data)->type == ITEM_TEXT) {
2198 g_free(ui.font_name);
2199 ui.font_name = g_strdup(it->font_name);
2200 ui.font_size = it->font_size;
2202 g_free(ui.default_font_name);
2203 ui.default_font_name = g_strdup(ui.font_name);
2204 ui.default_font_size = ui.font_size;
2212 on_toolsRuler_activate (GtkMenuItem *menuitem,
2215 gboolean active, current;
2217 if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_CHECK_MENU_ITEM)
2218 active = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
2220 active = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON (menuitem));
2222 if (ui.cur_mapping != 0) return;
2223 current = (ui.toolno[0] == TOOL_PEN || ui.toolno[0] == TOOL_HIGHLIGHTER) && ui.cur_brush->ruler;
2224 if (active == current) return;
2228 if (ui.toolno[0]!=TOOL_PEN && ui.toolno[0]!=TOOL_HIGHLIGHTER) {
2230 ui.toolno[0] = TOOL_PEN;
2231 ui.cur_brush = &(ui.brushes[0][TOOL_PEN]);
2232 update_color_menu();
2233 update_tool_buttons();
2238 ui.cur_brush->ruler = active;
2239 if (active) ui.cur_brush->recognizer = FALSE;
2240 update_mapping_linkings(ui.toolno[0]);
2241 update_ruler_indicator();
2246 on_toolsReco_activate (GtkMenuItem *menuitem,
2249 gboolean active, current;
2251 if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_CHECK_MENU_ITEM)
2252 active = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
2254 active = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON (menuitem));
2256 if (ui.cur_mapping != 0) return;
2257 current = (ui.toolno[0] == TOOL_PEN || ui.toolno[0] == TOOL_HIGHLIGHTER) && ui.cur_brush->recognizer;
2258 if (active == current) return;
2262 if (ui.toolno[0]!=TOOL_PEN && ui.toolno[0]!=TOOL_HIGHLIGHTER) {
2264 ui.toolno[0] = TOOL_PEN;
2265 ui.cur_brush = &(ui.brushes[0][TOOL_PEN]);
2266 update_color_menu();
2267 update_tool_buttons();
2272 ui.cur_brush->recognizer = active;
2274 ui.cur_brush->ruler = FALSE;
2277 update_mapping_linkings(ui.toolno[0]);
2278 update_ruler_indicator();
2283 on_optionsSavePreferences_activate (GtkMenuItem *menuitem,
2288 save_config_to_file();
2293 on_helpIndex_activate (GtkMenuItem *menuitem,
2301 on_helpAbout_activate (GtkMenuItem *menuitem,
2304 GtkWidget *aboutDialog;
2305 GtkLabel *labelTitle;
2309 aboutDialog = create_aboutDialog ();
2310 labelTitle = GTK_LABEL(g_object_get_data(G_OBJECT(aboutDialog), "labelTitle"));
2311 gtk_label_set_markup(labelTitle,
2312 "<span size=\"xx-large\" weight=\"bold\">Xournal " VERSION "</span>");
2313 gtk_dialog_run (GTK_DIALOG(aboutDialog));
2314 gtk_widget_destroy(aboutDialog);
2319 on_buttonToolDefault_clicked (GtkToolButton *toolbutton,
2322 if (ui.toolno[0]==TOOL_TEXT) {
2323 on_toolsDefaultText_activate(NULL, NULL);
2329 if (ui.toolno[0] < NUM_STROKE_TOOLS) {
2330 g_memmove(&(ui.brushes[0][ui.toolno[0]]), ui.default_brushes+ui.toolno[0], sizeof(struct Brush));
2331 update_mapping_linkings(ui.toolno[0]);
2332 update_thickness_buttons();
2333 update_color_buttons();
2334 update_color_menu();
2335 if (ui.toolno[0] == TOOL_PEN) update_pen_props_menu();
2336 if (ui.toolno[0] == TOOL_ERASER) update_eraser_props_menu();
2337 if (ui.toolno[0] == TOOL_HIGHLIGHTER) update_highlighter_props_menu();
2344 on_buttonFine_clicked (GtkToolButton *toolbutton,
2347 if (ui.cur_mapping != 0) return;
2348 process_thickness_activate((GtkMenuItem*)toolbutton, ui.toolno[0], THICKNESS_FINE);
2353 on_buttonMedium_clicked (GtkToolButton *toolbutton,
2356 if (ui.cur_mapping != 0) return;
2357 process_thickness_activate((GtkMenuItem*)toolbutton, ui.toolno[0], THICKNESS_MEDIUM);
2362 on_buttonThick_clicked (GtkToolButton *toolbutton,
2365 if (ui.cur_mapping != 0) return;
2366 process_thickness_activate((GtkMenuItem*)toolbutton, ui.toolno[0], THICKNESS_THICK);
2371 on_canvas_button_press_event (GtkWidget *widget,
2372 GdkEventButton *event,
2376 gboolean page_change;
2377 struct Page *tmppage;
2383 is_core = (event->device == gdk_device_get_core_pointer());
2384 if (!ui.use_xinput && !is_core) return FALSE;
2385 if (ui.use_xinput && is_core && ui.discard_corepointer) return FALSE;
2386 if (event->button > 3) return FALSE; // no painting with the mouse wheel!
2387 if (event->type != GDK_BUTTON_PRESS) return FALSE;
2388 // double-clicks may have broken axes member (free'd) due to a bug in GDK
2390 fix_xinput_coords((GdkEvent *)event);
2393 printf("DEBUG: ButtonDown (%s) (x,y)=(%.2f,%.2f)\n",
2394 is_core?"core":"xinput", event->x, event->y);
2396 if (!finite(event->x) || !finite(event->y)) return FALSE; // Xorg 7.3 bug
2398 if (ui.cur_item_type == ITEM_TEXT && !is_event_within_textview(event))
2400 if (ui.cur_item_type == ITEM_STROKE && ui.is_corestroke && !is_core &&
2401 ui.cur_path.num_points == 1) {
2402 // Xorg 7.3+ sent core event before XInput event: fix initial point
2403 ui.is_corestroke = FALSE;
2404 get_pointer_coords((GdkEvent *)event, ui.cur_path.coords);
2406 if (ui.cur_item_type != ITEM_NONE) return FALSE; // we're already doing something
2408 ui.is_corestroke = is_core;
2410 if (ui.use_erasertip && event->device->source == GDK_SOURCE_ERASER)
2411 mapping = NUM_BUTTONS;
2412 else mapping = event->button-1;
2414 // check whether we're in a page
2415 page_change = FALSE;
2416 tmppage = ui.cur_page;
2417 get_pointer_coords((GdkEvent *)event, pt);
2418 while (ui.view_continuous && (pt[1] < - VIEW_CONTINUOUS_SKIP)) {
2419 if (ui.pageno == 0) break;
2422 tmppage = g_list_nth_data(journal.pages, ui.pageno);
2423 pt[1] += tmppage->height + VIEW_CONTINUOUS_SKIP;
2425 while (ui.view_continuous && (pt[1] > tmppage->height + VIEW_CONTINUOUS_SKIP)) {
2426 if (ui.pageno == journal.npages-1) break;
2427 pt[1] -= tmppage->height + VIEW_CONTINUOUS_SKIP;
2430 tmppage = g_list_nth_data(journal.pages, ui.pageno);
2432 if (page_change) do_switch_page(ui.pageno, FALSE, FALSE);
2434 // can't paint on the background...
2436 if (ui.cur_layer == NULL) {
2438 dialog = gtk_message_dialog_new(GTK_WINDOW(winMain), GTK_DIALOG_MODAL,
2439 GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, _("Drawing is not allowed on the "
2440 "background layer.\n Switching to Layer 1."));
2441 gtk_dialog_run(GTK_DIALOG(dialog));
2442 gtk_widget_destroy(dialog);
2443 on_viewShowLayer_activate(NULL, NULL);
2447 // switch mappings if needed
2449 ui.which_mouse_button = event->button;
2450 switch_mapping(mapping);
2452 // in text tool, clicking in a text area edits it
2453 if (ui.toolno[mapping] == TOOL_TEXT) {
2454 item = click_is_in_text(ui.cur_layer, pt[0], pt[1]);
2457 start_text((GdkEvent *)event, item);
2462 // if this can be a selection move or resize, then it takes precedence over anything else
2463 if (start_resizesel((GdkEvent *)event)) return FALSE;
2464 if (start_movesel((GdkEvent *)event)) return FALSE;
2466 if (ui.toolno[mapping] != TOOL_SELECTREGION && ui.toolno[mapping] != TOOL_SELECTRECT)
2469 // process the event
2471 if (ui.toolno[mapping] == TOOL_HAND) {
2472 ui.cur_item_type = ITEM_HAND;
2473 get_pointer_coords((GdkEvent *)event, ui.hand_refpt);
2474 ui.hand_refpt[0] += ui.cur_page->hoffset;
2475 ui.hand_refpt[1] += ui.cur_page->voffset;
2477 else if (ui.toolno[mapping] == TOOL_PEN || ui.toolno[mapping] == TOOL_HIGHLIGHTER ||
2478 (ui.toolno[mapping] == TOOL_ERASER && ui.cur_brush->tool_options == TOOLOPT_ERASER_WHITEOUT)) {
2479 create_new_stroke((GdkEvent *)event);
2481 else if (ui.toolno[mapping] == TOOL_ERASER) {
2482 ui.cur_item_type = ITEM_ERASURE;
2483 do_eraser((GdkEvent *)event, ui.cur_brush->thickness/2,
2484 ui.cur_brush->tool_options == TOOLOPT_ERASER_STROKES);
2486 else if (ui.toolno[mapping] == TOOL_SELECTRECT) {
2487 start_selectrect((GdkEvent *)event);
2489 else if (ui.toolno[mapping] == TOOL_VERTSPACE) {
2490 start_vertspace((GdkEvent *)event);
2492 else if (ui.toolno[mapping] == TOOL_TEXT) {
2493 start_text((GdkEvent *)event, NULL);
2500 on_canvas_button_release_event (GtkWidget *widget,
2501 GdkEventButton *event,
2506 if (ui.cur_item_type == ITEM_NONE) return FALSE; // not doing anything
2508 if (event->button != ui.which_mouse_button) return FALSE; // ignore
2510 is_core = (event->device == gdk_device_get_core_pointer());
2511 if (!ui.use_xinput && !is_core) return FALSE;
2512 if (ui.use_xinput && is_core && !ui.is_corestroke) return FALSE;
2513 if (!is_core) fix_xinput_coords((GdkEvent *)event);
2515 if (ui.cur_item_type == ITEM_STROKE) {
2517 if (ui.cur_brush->recognizer) recognize_patterns();
2519 else if (ui.cur_item_type == ITEM_ERASURE) {
2522 else if (ui.cur_item_type == ITEM_SELECTRECT) {
2523 finalize_selectrect();
2525 else if (ui.cur_item_type == ITEM_MOVESEL || ui.cur_item_type == ITEM_MOVESEL_VERT) {
2528 else if (ui.cur_item_type == ITEM_RESIZESEL) {
2529 finalize_resizesel();
2531 else if (ui.cur_item_type == ITEM_HAND) {
2532 ui.cur_item_type = ITEM_NONE;
2541 on_canvas_enter_notify_event (GtkWidget *widget,
2542 GdkEventCrossing *event,
2551 on_canvas_expose_event (GtkWidget *widget,
2552 GdkEventExpose *event,
2555 if (ui.view_continuous && ui.progressive_bg) rescale_bg_pixmaps();
2561 on_canvas_key_press_event (GtkWidget *widget,
2565 // If zoomed-out and in single page mode, switch pages with PgUp/PgDn.
2566 if (!ui.view_continuous &&
2567 (0.96 * ui.zoom * ui.cur_page->height <
2568 GTK_WIDGET(canvas)->allocation.height)) {
2569 if (event->keyval == GDK_Page_Down) {
2572 if (ui.pageno == journal.npages-1) { return FALSE; }
2573 do_switch_page(ui.pageno+1, TRUE, FALSE);
2575 if (event->keyval == GDK_Page_Up) {
2578 if (ui.pageno == 0) { return FALSE; }
2579 do_switch_page(ui.pageno-1, TRUE, FALSE);
2588 on_canvas_motion_notify_event (GtkWidget *widget,
2589 GdkEventMotion *event,
2592 gboolean looks_wrong, is_core;
2595 /* we don't care about this event unless some operation is in progress;
2596 or if there's a selection (then we might want to change the mouse
2597 cursor to indicate the possibility of resizing) */
2598 if (ui.cur_item_type == ITEM_NONE && ui.selection==NULL) return FALSE;
2600 is_core = (event->device == gdk_device_get_core_pointer());
2601 if (!ui.use_xinput && !is_core) return FALSE;
2602 if (!is_core) fix_xinput_coords((GdkEvent *)event);
2603 if (!finite(event->x) || !finite(event->y)) return FALSE; // Xorg 7.3 bug
2605 if (ui.selection!=NULL && ui.cur_item_type == ITEM_NONE) {
2606 get_pointer_coords((GdkEvent *)event, pt);
2607 update_cursor_for_resize(pt);
2611 if (ui.use_xinput && is_core && !ui.is_corestroke) return FALSE;
2612 if (!is_core) ui.is_corestroke = FALSE;
2615 printf("DEBUG: MotionNotify (%s) (x,y)=(%.2f,%.2f)\n",
2616 is_core?"core":"xinput", event->x, event->y);
2619 looks_wrong = !(event->state & (1<<(7+ui.which_mouse_button)));
2621 if (looks_wrong) { /* mouse button shouldn't be up... give up */
2622 if (ui.cur_item_type == ITEM_STROKE) {
2624 if (ui.cur_brush->recognizer) recognize_patterns();
2626 else if (ui.cur_item_type == ITEM_ERASURE) {
2629 else if (ui.cur_item_type == ITEM_SELECTRECT) {
2630 finalize_selectrect();
2632 else if (ui.cur_item_type == ITEM_MOVESEL || ui.cur_item_type == ITEM_MOVESEL_VERT) {
2635 else if (ui.cur_item_type == ITEM_RESIZESEL) {
2636 finalize_resizesel();
2642 if (ui.cur_item_type == ITEM_STROKE) {
2643 continue_stroke((GdkEvent *)event);
2645 else if (ui.cur_item_type == ITEM_ERASURE) {
2646 do_eraser((GdkEvent *)event, ui.cur_brush->thickness/2,
2647 ui.cur_brush->tool_options == TOOLOPT_ERASER_STROKES);
2649 else if (ui.cur_item_type == ITEM_SELECTRECT) {
2650 get_pointer_coords((GdkEvent *)event, pt);
2651 ui.selection->bbox.right = pt[0];
2652 ui.selection->bbox.bottom = pt[1];
2653 gnome_canvas_item_set(ui.selection->canvas_item,
2654 "x2", pt[0], "y2", pt[1], NULL);
2656 else if (ui.cur_item_type == ITEM_MOVESEL || ui.cur_item_type == ITEM_MOVESEL_VERT) {
2657 continue_movesel((GdkEvent *)event);
2659 else if (ui.cur_item_type == ITEM_RESIZESEL) {
2660 continue_resizesel((GdkEvent *)event);
2662 else if (ui.cur_item_type == ITEM_HAND) {
2663 do_hand((GdkEvent *)event);
2670 on_comboLayer_changed (GtkComboBox *combobox,
2675 if (ui.in_update_page_stuff) return; // avoid a bad retroaction
2680 val = gtk_combo_box_get_active(combobox);
2681 if (val == -1) return;
2682 val = ui.cur_page->nlayers-1-val;
2683 if (val == ui.layerno) return;
2686 while (val>ui.layerno) {
2688 ui.cur_layer = g_list_nth_data(ui.cur_page->layers, ui.layerno);
2689 gnome_canvas_item_show(GNOME_CANVAS_ITEM(ui.cur_layer->group));
2691 while (val<ui.layerno) {
2692 gnome_canvas_item_hide(GNOME_CANVAS_ITEM(ui.cur_layer->group));
2694 if (ui.layerno<0) ui.cur_layer = NULL;
2695 else ui.cur_layer = g_list_nth_data(ui.cur_page->layers, ui.layerno);
2697 update_page_stuff();
2702 on_winMain_delete_event (GtkWidget *widget,
2708 if (ok_to_close()) gtk_main_quit();
2714 on_optionsUseXInput_activate (GtkMenuItem *menuitem,
2719 ui.allow_xinput = ui.use_xinput =
2720 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
2722 /* Important note: we'd like ONLY the canvas window itself to receive
2723 XInput events, while its child window in the GDK hierarchy (also
2724 associated to the canvas widget) receives the core events.
2725 This way on_canvas_... will get both types of events -- otherwise,
2726 the proximity detection code in GDK is broken and we'll lose core
2729 Up to GTK+ 2.10, gtk_widget_set_extension_events() only sets
2730 extension events for the widget's main window itself; in GTK+ 2.11
2731 also traverses GDK child windows that belong to the widget
2732 and sets their extension events too. We want to avoid that.
2733 So we use gdk_input_set_extension_events() directly on the canvas.
2736 /* // this causes GTK+ 2.11 bugs
2737 gtk_widget_set_extension_events(GTK_WIDGET (canvas),
2738 ui.use_xinput?GDK_EXTENSION_EVENTS_ALL:GDK_EXTENSION_EVENTS_NONE);
2740 gdk_input_set_extension_events(GTK_WIDGET(canvas)->window,
2741 GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK,
2742 ui.use_xinput?GDK_EXTENSION_EVENTS_ALL:GDK_EXTENSION_EVENTS_NONE);
2744 update_mappings_menu();
2748 on_vscroll_changed (GtkAdjustment *adjustment,
2751 gboolean need_update;
2752 double viewport_top, viewport_bottom;
2753 struct Page *tmppage;
2755 if (!ui.view_continuous) return;
2757 if (ui.progressive_bg) rescale_bg_pixmaps();
2758 need_update = FALSE;
2759 viewport_top = adjustment->value / ui.zoom;
2760 viewport_bottom = (adjustment->value + adjustment->page_size) / ui.zoom;
2761 tmppage = ui.cur_page;
2762 while (viewport_top > tmppage->voffset + tmppage->height) {
2763 if (ui.pageno == journal.npages-1) break;
2766 tmppage = g_list_nth_data(journal.pages, ui.pageno);
2768 while (viewport_bottom < tmppage->voffset) {
2769 if (ui.pageno == 0) break;
2772 tmppage = g_list_nth_data(journal.pages, ui.pageno);
2776 do_switch_page(ui.pageno, FALSE, FALSE);
2783 on_spinPageNo_value_changed (GtkSpinButton *spinbutton,
2788 if (ui.in_update_page_stuff) return; // avoid a bad retroaction
2793 val = gtk_spin_button_get_value_as_int(spinbutton) - 1;
2795 if (val == journal.npages) { // create a page at end
2796 on_journalNewPageEnd_activate(NULL, NULL);
2800 if (val == ui.pageno) return;
2801 if (val < 0) val = 0;
2802 if (val > journal.npages-1) val = journal.npages-1;
2803 do_switch_page(val, TRUE, FALSE);
2808 on_journalDefaultBackground_activate (GtkMenuItem *menuitem,
2819 for (pglist = journal.pages; pglist!=NULL; pglist = pglist->next) {
2820 if (ui.bg_apply_all_pages) pg = (struct Page *)pglist->data;
2822 if (ui.bg_apply_all_pages) {
2823 if (pglist->next!=NULL) undo->multiop |= MULTIOP_CONT_REDO;
2824 if (pglist->prev!=NULL) undo->multiop |= MULTIOP_CONT_UNDO;
2826 undo->type = ITEM_NEW_BG_RESIZE;
2829 undo->val_x = pg->width;
2830 undo->val_y = pg->height;
2831 pg->bg = (struct Background *)g_memdup(ui.default_page.bg, sizeof(struct Background));
2832 pg->width = ui.default_page.width;
2833 pg->height = ui.default_page.height;
2834 pg->bg->canvas_item = undo->bg->canvas_item;
2835 undo->bg->canvas_item = NULL;
2837 make_page_clipbox(pg);
2838 update_canvas_bg(pg);
2839 if (!ui.bg_apply_all_pages) break;
2841 do_switch_page(ui.pageno, TRUE, TRUE);
2846 on_journalSetAsDefault_activate (GtkMenuItem *menuitem,
2849 if (ui.cur_page->bg->type != BG_SOLID) return;
2854 undo->type = ITEM_NEW_DEFAULT_BG;
2855 undo->val_x = ui.default_page.width;
2856 undo->val_y = ui.default_page.height;
2857 undo->bg = ui.default_page.bg;
2859 ui.default_page.width = ui.cur_page->width;
2860 ui.default_page.height = ui.cur_page->height;
2861 ui.default_page.bg = (struct Background *)g_memdup(ui.cur_page->bg, sizeof(struct Background));
2862 ui.default_page.bg->canvas_item = NULL;
2867 on_comboStdSizes_changed (GtkComboBox *combobox,
2871 GtkComboBox *comboUnit;
2875 if (papersize_need_init) {
2876 gtk_combo_box_set_active(combobox, papersize_std);
2877 papersize_need_init = FALSE;
2879 val = gtk_combo_box_get_active(combobox);
2880 if (val == -1 || val == papersize_std) return;
2881 papersize_std = val;
2882 if (val == STD_SIZE_CUSTOM) return;
2883 papersize_unit = std_units[val];
2884 papersize_width = std_widths[val];
2885 papersize_height = std_heights[val];
2887 comboUnit = GTK_COMBO_BOX(g_object_get_data(G_OBJECT(papersize_dialog), "comboUnit"));
2888 gtk_combo_box_set_active(comboUnit, papersize_unit);
2889 entry = GTK_ENTRY(g_object_get_data(G_OBJECT(papersize_dialog), "entryWidth"));
2890 g_snprintf(text, 20, "%.2f", papersize_width/unit_sizes[papersize_unit]);
2891 if (g_str_has_suffix(text, ".00"))
2892 g_snprintf(text, 20, "%d", (int) (papersize_width/unit_sizes[papersize_unit]));
2893 gtk_entry_set_text(entry, text);
2894 entry = GTK_ENTRY(g_object_get_data(G_OBJECT(papersize_dialog), "entryHeight"));
2895 g_snprintf(text, 20, "%.2f", papersize_height/unit_sizes[papersize_unit]);
2896 if (g_str_has_suffix(text, ".00"))
2897 g_snprintf(text, 20, "%d", (int) (papersize_height/unit_sizes[papersize_unit]));
2898 gtk_entry_set_text(entry, text);
2903 on_entryWidth_changed (GtkEditable *editable,
2909 GtkComboBox *comboStdSizes;
2911 text = gtk_entry_get_text(GTK_ENTRY(editable));
2912 val = strtod(text, &ptr);
2913 papersize_width_valid = (*ptr == 0 && val > 0.);
2914 if (!papersize_width_valid) return; // invalid entry
2915 val *= unit_sizes[papersize_unit];
2916 if (fabs(val - papersize_width) < 0.1) return; // no change
2917 papersize_std = STD_SIZE_CUSTOM;
2918 papersize_width = val;
2919 comboStdSizes = GTK_COMBO_BOX(g_object_get_data(G_OBJECT(papersize_dialog), "comboStdSizes"));
2920 gtk_combo_box_set_active(comboStdSizes, papersize_std);
2925 on_entryHeight_changed (GtkEditable *editable,
2931 GtkComboBox *comboStdSizes;
2933 text = gtk_entry_get_text(GTK_ENTRY(editable));
2934 val = strtod(text, &ptr);
2935 papersize_height_valid = (*ptr == 0 && val > 0.);
2936 if (!papersize_height_valid) return; // invalid entry
2937 val *= unit_sizes[papersize_unit];
2938 if (fabs(val - papersize_height) < 0.1) return; // no change
2939 papersize_std = STD_SIZE_CUSTOM;
2940 papersize_height = val;
2941 comboStdSizes = GTK_COMBO_BOX(g_object_get_data(G_OBJECT(papersize_dialog), "comboStdSizes"));
2942 gtk_combo_box_set_active(comboStdSizes, papersize_std);
2947 on_comboUnit_changed (GtkComboBox *combobox,
2954 val = gtk_combo_box_get_active(combobox);
2955 if (val == -1 || val == papersize_unit) return;
2956 papersize_unit = val;
2957 entry = GTK_ENTRY(g_object_get_data(G_OBJECT(papersize_dialog), "entryWidth"));
2958 if (papersize_width_valid) {
2959 g_snprintf(text, 20, "%.2f", papersize_width/unit_sizes[papersize_unit]);
2960 if (g_str_has_suffix(text, ".00"))
2961 g_snprintf(text, 20, "%d", (int) (papersize_width/unit_sizes[papersize_unit]));
2963 gtk_entry_set_text(entry, text);
2964 if (papersize_height_valid) {
2965 entry = GTK_ENTRY(g_object_get_data(G_OBJECT(papersize_dialog), "entryHeight"));
2966 g_snprintf(text, 20, "%.2f", papersize_height/unit_sizes[papersize_unit]);
2967 if (g_str_has_suffix(text, ".00"))
2968 g_snprintf(text, 20, "%d", (int) (papersize_height/unit_sizes[papersize_unit]));
2970 gtk_entry_set_text(entry, text);
2975 on_viewFullscreen_activate (GtkMenuItem *menuitem,
2980 if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_CHECK_MENU_ITEM)
2981 active = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
2983 active = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON (menuitem));
2985 if (active == ui.fullscreen) return;
2988 ui.fullscreen = active;
2989 gtk_check_menu_item_set_active(
2990 GTK_CHECK_MENU_ITEM(GET_COMPONENT("viewFullscreen")), ui.fullscreen);
2991 gtk_toggle_tool_button_set_active(
2992 GTK_TOGGLE_TOOL_BUTTON(GET_COMPONENT("buttonFullscreen")), ui.fullscreen);
2994 if (ui.fullscreen) gtk_window_fullscreen(GTK_WINDOW(winMain));
2995 else gtk_window_unfullscreen(GTK_WINDOW(winMain));
2997 update_vbox_order(ui.vertical_order[ui.fullscreen?1:0]);
3002 on_optionsButtonMappings_activate (GtkMenuItem *menuitem,
3008 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
3009 update_mappings_menu();
3014 on_optionsAntialiasBG_activate (GtkMenuItem *menuitem,
3019 active = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
3020 if (ui.antialias_bg == active) return;
3023 ui.antialias_bg = active;
3024 rescale_bg_pixmaps();
3029 on_optionsProgressiveBG_activate (GtkMenuItem *menuitem,
3034 active = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
3035 if (ui.progressive_bg == active) return;
3038 ui.progressive_bg = active;
3039 if (!ui.progressive_bg) rescale_bg_pixmaps();
3044 on_mru_activate (GtkMenuItem *menuitem,
3053 if (!ok_to_close()) return; // user aborted on save confirmation
3055 for (which = 0 ; which < MRU_SIZE; which++) {
3056 if (ui.mrumenu[which] == GTK_WIDGET(menuitem)) break;
3058 if (which == MRU_SIZE || ui.mru[which] == NULL) return; // not found...
3060 set_cursor_busy(TRUE);
3061 success = open_journal(ui.mru[which]);
3062 set_cursor_busy(FALSE);
3063 if (success) return;
3066 dialog = gtk_message_dialog_new(GTK_WINDOW (winMain), GTK_DIALOG_DESTROY_WITH_PARENT,
3067 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Error opening file '%s'"), ui.mru[which]);
3068 gtk_dialog_run(GTK_DIALOG(dialog));
3069 gtk_widget_destroy(dialog);
3070 delete_mru_entry(which);
3075 on_button2Pen_activate (GtkMenuItem *menuitem,
3078 process_mapping_activate(menuitem, 1, TOOL_PEN);
3083 on_button2Eraser_activate (GtkMenuItem *menuitem,
3086 process_mapping_activate(menuitem, 1, TOOL_ERASER);
3091 on_button2Highlighter_activate (GtkMenuItem *menuitem,
3094 process_mapping_activate(menuitem, 1, TOOL_HIGHLIGHTER);
3099 on_button2Text_activate (GtkMenuItem *menuitem,
3102 process_mapping_activate(menuitem, 1, TOOL_TEXT);
3107 on_button2SelectRegion_activate (GtkMenuItem *menuitem,
3110 process_mapping_activate(menuitem, 1, TOOL_SELECTREGION);
3115 on_button2SelectRectangle_activate (GtkMenuItem *menuitem,
3118 process_mapping_activate(menuitem, 1, TOOL_SELECTRECT);
3123 on_button2VerticalSpace_activate (GtkMenuItem *menuitem,
3126 process_mapping_activate(menuitem, 1, TOOL_VERTSPACE);
3131 on_button2LinkBrush_activate (GtkMenuItem *menuitem,
3136 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))) return;
3139 ui.linked_brush[1] = BRUSH_LINKED;
3140 for (i=0;i<NUM_STROKE_TOOLS;i++) update_mapping_linkings(i);
3145 on_button2CopyBrush_activate (GtkMenuItem *menuitem,
3148 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))) return;
3151 if (ui.toolno[1] >= NUM_STROKE_TOOLS) {
3152 ui.linked_brush[1] = BRUSH_STATIC;
3153 update_mappings_menu_linkings();
3156 ui.linked_brush[1] = BRUSH_COPIED;
3157 g_memmove(&(ui.brushes[1][ui.toolno[1]]), &(ui.brushes[0][ui.toolno[1]]), sizeof(struct Brush));
3162 on_button3Pen_activate (GtkMenuItem *menuitem,
3165 process_mapping_activate(menuitem, 2, TOOL_PEN);
3170 on_button3Eraser_activate (GtkMenuItem *menuitem,
3173 process_mapping_activate(menuitem, 2, TOOL_ERASER);
3178 on_button3Highlighter_activate (GtkMenuItem *menuitem,
3181 process_mapping_activate(menuitem, 2, TOOL_HIGHLIGHTER);
3186 on_button3Text_activate (GtkMenuItem *menuitem,
3189 process_mapping_activate(menuitem, 2, TOOL_TEXT);
3194 on_button3SelectRegion_activate (GtkMenuItem *menuitem,
3197 process_mapping_activate(menuitem, 2, TOOL_SELECTREGION);
3202 on_button3SelectRectangle_activate (GtkMenuItem *menuitem,
3205 process_mapping_activate(menuitem, 2, TOOL_SELECTRECT);
3210 on_button3VerticalSpace_activate (GtkMenuItem *menuitem,
3213 process_mapping_activate(menuitem, 2, TOOL_VERTSPACE);
3218 on_button3LinkBrush_activate (GtkMenuItem *menuitem,
3223 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))) return;
3226 ui.linked_brush[2] = BRUSH_LINKED;
3227 for (i=0;i<NUM_STROKE_TOOLS;i++) update_mapping_linkings(i);
3232 on_button3CopyBrush_activate (GtkMenuItem *menuitem,
3235 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))) return;
3238 if (ui.toolno[2] >= NUM_STROKE_TOOLS) {
3239 ui.linked_brush[2] = BRUSH_STATIC;
3240 update_mappings_menu_linkings();
3243 ui.linked_brush[2] = BRUSH_COPIED;
3244 g_memmove(&(ui.brushes[2][ui.toolno[2]]), &(ui.brushes[0][ui.toolno[2]]), sizeof(struct Brush));
3247 // the set zoom dialog
3249 GtkWidget *zoom_dialog;
3250 double zoom_percent;
3253 on_viewSetZoom_activate (GtkMenuItem *menuitem,
3257 double test_w, test_h;
3258 GtkSpinButton *spinZoom;
3262 zoom_dialog = create_zoomDialog();
3263 zoom_percent = 100*ui.zoom / DEFAULT_ZOOM;
3264 spinZoom = GTK_SPIN_BUTTON(g_object_get_data(G_OBJECT(zoom_dialog), "spinZoom"));
3265 gtk_spin_button_set_increments(spinZoom, ui.zoom_step_increment, 5*ui.zoom_step_increment);
3266 gtk_spin_button_set_value(spinZoom, zoom_percent);
3267 test_w = 100*(GTK_WIDGET(canvas))->allocation.width/ui.cur_page->width/DEFAULT_ZOOM;
3268 test_h = 100*(GTK_WIDGET(canvas))->allocation.height/ui.cur_page->height/DEFAULT_ZOOM;
3269 if (zoom_percent > 99.9 && zoom_percent < 100.1)
3270 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_object_get_data(
3271 G_OBJECT(zoom_dialog), "radioZoom100")), TRUE);
3272 else if (zoom_percent > test_w-0.1 && zoom_percent < test_w+0.1)
3273 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_object_get_data(
3274 G_OBJECT(zoom_dialog), "radioZoomWidth")), TRUE);
3275 else if (zoom_percent > test_h-0.1 && zoom_percent < test_h+0.1)
3276 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_object_get_data(
3277 G_OBJECT(zoom_dialog), "radioZoomHeight")), TRUE);
3278 else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_object_get_data(
3279 G_OBJECT(zoom_dialog), "radioZoom")), TRUE);
3280 gtk_widget_show(zoom_dialog);
3283 response = gtk_dialog_run(GTK_DIALOG(zoom_dialog));
3284 if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) {
3285 ui.zoom = DEFAULT_ZOOM*zoom_percent/100;
3286 gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
3287 rescale_text_items();
3288 rescale_bg_pixmaps();
3290 } while (response == GTK_RESPONSE_APPLY);
3292 gtk_widget_destroy(zoom_dialog);
3297 on_spinZoom_value_changed (GtkSpinButton *spinbutton,
3302 val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(g_object_get_data(
3303 G_OBJECT(zoom_dialog), "spinZoom")));
3305 if (val<10) val=10.;
3306 if (val>1500) val=1500.;
3307 if (val<zoom_percent-1 || val>zoom_percent+1)
3308 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g_object_get_data(
3309 G_OBJECT(zoom_dialog), "radioZoom")), TRUE);
3315 on_radioZoom_toggled (GtkToggleButton *togglebutton,
3323 on_radioZoom100_toggled (GtkToggleButton *togglebutton,
3326 if (!gtk_toggle_button_get_active(togglebutton)) return;
3327 zoom_percent = 100.;
3328 gtk_spin_button_set_value(GTK_SPIN_BUTTON(g_object_get_data(
3329 G_OBJECT(zoom_dialog), "spinZoom")), zoom_percent);
3334 on_radioZoomWidth_toggled (GtkToggleButton *togglebutton,
3337 if (!gtk_toggle_button_get_active(togglebutton)) return;
3338 zoom_percent = 100*(GTK_WIDGET(canvas))->allocation.width/ui.cur_page->width/DEFAULT_ZOOM;
3339 gtk_spin_button_set_value(GTK_SPIN_BUTTON(g_object_get_data(
3340 G_OBJECT(zoom_dialog), "spinZoom")), zoom_percent);
3345 on_radioZoomHeight_toggled (GtkToggleButton *togglebutton,
3348 if (!gtk_toggle_button_get_active(togglebutton)) return;
3349 zoom_percent = 100*(GTK_WIDGET(canvas))->allocation.height/ui.cur_page->height/DEFAULT_ZOOM;
3350 gtk_spin_button_set_value(GTK_SPIN_BUTTON(g_object_get_data(
3351 G_OBJECT(zoom_dialog), "spinZoom")), zoom_percent);
3356 on_toolsHand_activate (GtkMenuItem *menuitem,
3359 if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_RADIO_MENU_ITEM) {
3360 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem)))
3363 if (!gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON (menuitem)))
3367 if (ui.cur_mapping != 0) return;
3368 if (ui.toolno[0] == TOOL_HAND) return;
3373 ui.toolno[0] = TOOL_HAND;
3374 update_mapping_linkings(-1);
3375 update_tool_buttons();
3377 update_color_menu();
3383 on_button2Hand_activate (GtkMenuItem *menuitem,
3386 process_mapping_activate(menuitem, 1, TOOL_HAND);
3391 on_button3Hand_activate (GtkMenuItem *menuitem,
3394 process_mapping_activate(menuitem, 2, TOOL_HAND);
3399 on_optionsPrintRuling_activate (GtkMenuItem *menuitem,
3404 ui.print_ruling = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
3408 on_optionsDiscardCore_activate (GtkMenuItem *menuitem,
3413 ui.discard_corepointer =
3414 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
3415 update_mappings_menu();
3419 on_fontButton_font_set (GtkFontButton *fontbutton,
3424 str = g_strdup(gtk_font_button_get_font_name(fontbutton));
3425 process_font_sel(str);
3429 on_optionsLeftHanded_activate (GtkMenuItem *menuitem,
3434 ui.left_handed = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
3435 gtk_scrolled_window_set_placement(GTK_SCROLLED_WINDOW(GET_COMPONENT("scrolledwindowMain")),
3436 ui.left_handed?GTK_CORNER_TOP_RIGHT:GTK_CORNER_TOP_LEFT);
3440 on_optionsShortenMenus_activate (GtkMenuItem *menuitem,
3443 gchar *item, *nextptr;
3448 ui.shorten_menus = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
3450 /* go over the item list */
3451 item = ui.shorten_menu_items;
3452 while (*item==' ') item++;
3454 nextptr = strchr(item, ' ');
3455 if (nextptr!=NULL) *nextptr = 0;
3456 // hide or show the item
3457 w = GET_COMPONENT(item);
3459 if (ui.shorten_menus) gtk_widget_hide(w);
3460 else gtk_widget_show(w);
3463 if (nextptr==NULL) break;
3466 while (*item==' ') item++;
3469 // just in case someone tried to unhide stuff they shouldn't be seeing
3470 hide_unimplemented();
3471 // maybe we should also make sure the drawing area stays visible ?
3475 on_optionsAutoSavePrefs_activate (GtkMenuItem *menuitem,
3480 ui.auto_save_prefs = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
3484 on_optionsPressureSensitive_activate (GtkMenuItem *menuitem,
3490 ui.pressure_sensitivity =
3491 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
3492 for (i=0; i<=NUM_BUTTONS; i++)
3493 ui.brushes[i][TOOL_PEN].variable_width = ui.pressure_sensitivity;
3494 update_mappings_menu();