X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fxo-callbacks.c;h=038507ad4724ae69c38de812836065d787d0dc2d;hb=64fbee630efe4a6a731bcc7b68855d933946b050;hp=f2e6e3f72094128d14c76b14d3d52fa42fefba62;hpb=7d08b1657c217fdf035809033e79d5df53fae3af;p=xournal.git diff --git a/src/xo-callbacks.c b/src/xo-callbacks.c index f2e6e3f..038507a 100644 --- a/src/xo-callbacks.c +++ b/src/xo-callbacks.c @@ -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; } @@ -134,7 +138,7 @@ on_fileOpen_activate (GtkMenuItem *menuitem, set_cursor_busy(TRUE); success = open_journal(filename); set_cursor_busy(FALSE); - if (success) return; + if (success) { g_free(filename); return; } /* open failed */ dialog = gtk_message_dialog_new(GTK_WINDOW (winMain), GTK_DIALOG_DESTROY_WITH_PARENT, @@ -185,16 +189,25 @@ 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) { - if (ui.filename[0] == '/') - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER (dialog), ui.filename); - else - gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), ui.filename); - } else { + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER (dialog), ui.filename); + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), g_basename(ui.filename)); + } + else + if (bgpdf.status!=STATUS_NOT_INIT && bgpdf.file_domain == DOMAIN_ABSOLUTE + && bgpdf.filename != NULL) { + filename = g_strdup_printf("%s.xoj", bgpdf.filename->s); + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER (dialog), filename); + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), g_basename(filename)); + g_free(filename); + } + 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); } @@ -208,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; } @@ -329,6 +342,8 @@ on_filePrint_activate (GtkMenuItem *menuitem, switch(gnome_print_dialog_get_range(GNOME_PRINT_DIALOG(printDialog))) { case GNOME_PRINT_RANGE_RANGE: gnome_print_dialog_get_range_page(GNOME_PRINT_DIALOG(printDialog), &fromPage, &toPage); + fromPage--; + toPage--; break; default: fromPage = 0; @@ -346,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")) { @@ -366,12 +380,13 @@ on_filePrintPDF_activate (GtkMenuItem *menuitem, } else in_fn = g_strdup_printf("%s.pdf", ui.filename); - if (in_fn[0] == '/') - gtk_file_chooser_set_filename(GTK_FILE_CHOOSER (dialog), in_fn); - gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), in_fn); + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER (dialog), in_fn); + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER (dialog), g_basename(in_fn)); } else { curtime = time(NULL); strftime(stime, 30, "%F-Note-%H-%M.pdf", localtime(&curtime)); + 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; } @@ -384,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); } @@ -425,6 +450,7 @@ on_editUndo_activate (GtkMenuItem *menuitem, GList *list, *itemlist; struct UndoErasureData *erasure; struct Item *it; + struct Brush tmp_brush; struct Background *tmp_bg; double tmp_x, tmp_y; @@ -485,7 +511,7 @@ on_editUndo_activate (GtkMenuItem *menuitem, make_page_clipbox(undo->page); } update_canvas_bg(undo->page); - do_switch_page(g_list_index(journal.pages, undo->page), TRUE); + do_switch_page(g_list_index(journal.pages, undo->page), TRUE, TRUE); } else if (undo->type == ITEM_NEW_DEFAULT_BG) { tmp_bg = ui.default_page.bg; @@ -510,21 +536,25 @@ on_editUndo_activate (GtkMenuItem *menuitem, // so do_switch_page() won't try to remap the layers of the defunct page if (ui.pageno >= undo->val) ui.pageno--; if (ui.pageno < 0) ui.pageno = 0; - do_switch_page(ui.pageno, TRUE); + do_switch_page(ui.pageno, TRUE, TRUE); } else if (undo->type == ITEM_DELETE_PAGE) { journal.pages = g_list_insert(journal.pages, undo->page, undo->val); journal.npages++; make_canvas_items(); // re-create the canvas items - do_switch_page(undo->val, TRUE); + do_switch_page(undo->val, TRUE, TRUE); } else if (undo->type == ITEM_MOVESEL) { for (itemlist = undo->itemlist; itemlist != NULL; itemlist = itemlist->next) { it = (struct Item *)itemlist->data; - if (it->canvas_item != NULL) + if (it->canvas_item != NULL) { + if (undo->layer != undo->layer2) + gnome_canvas_item_reparent(it->canvas_item, undo->layer->group); gnome_canvas_item_move(it->canvas_item, -undo->val_x, -undo->val_y); + } } - move_journal_items_by(undo->itemlist, -undo->val_x, -undo->val_y); + move_journal_items_by(undo->itemlist, -undo->val_x, -undo->val_y, + undo->layer2, undo->layer, undo->auxlist); } else if (undo->type == ITEM_PASTE) { for (itemlist = undo->itemlist; itemlist != NULL; itemlist = itemlist->next) { @@ -541,7 +571,7 @@ on_editUndo_activate (GtkMenuItem *menuitem, undo->layer->group = NULL; undo->page->layers = g_list_remove(undo->page->layers, undo->layer); undo->page->nlayers--; - do_switch_page(ui.pageno, FALSE); // don't stay with bad cur_layer info + do_switch_page(ui.pageno, FALSE, FALSE); // don't stay with bad cur_layer info } else if (undo->type == ITEM_DELETE_LAYER) { // special case of -1: deleted the last layer, created a new one @@ -572,7 +602,20 @@ on_editUndo_activate (GtkMenuItem *menuitem, "width-units", it->brush.thickness, NULL); } } - do_switch_page(ui.pageno, FALSE); // show the restored layer & others... + do_switch_page(ui.pageno, FALSE, FALSE); // show the restored layer & others... + } + else if (undo->type == ITEM_REPAINTSEL) { + for (itemlist = undo->itemlist, list = undo->auxlist; itemlist!=NULL; + itemlist = itemlist->next, list = list->next) { + it = (struct Item *)itemlist->data; + g_memmove(&tmp_brush, &(it->brush), sizeof(struct Brush)); + g_memmove(&(it->brush), list->data, sizeof(struct Brush)); + g_memmove(list->data, &tmp_brush, sizeof(struct Brush)); + if (it->type == ITEM_STROKE && it->canvas_item != NULL) + gnome_canvas_item_set(it->canvas_item, + "fill-color-rgba", it->brush.color_rgba, + "width-units", it->brush.thickness, NULL); + } } // move item from undo to redo stack @@ -594,6 +637,7 @@ on_editRedo_activate (GtkMenuItem *menuitem, GList *list, *itemlist, *target; struct UndoErasureData *erasure; struct Item *it; + struct Brush tmp_brush; struct Background *tmp_bg; struct Layer *l; double tmp_x, tmp_y; @@ -654,7 +698,7 @@ on_editRedo_activate (GtkMenuItem *menuitem, make_page_clipbox(redo->page); } update_canvas_bg(redo->page); - do_switch_page(g_list_index(journal.pages, redo->page), TRUE); + do_switch_page(g_list_index(journal.pages, redo->page), TRUE, TRUE); } else if (redo->type == ITEM_NEW_DEFAULT_BG) { tmp_bg = ui.default_page.bg; @@ -680,7 +724,7 @@ on_editRedo_activate (GtkMenuItem *menuitem, journal.pages = g_list_insert(journal.pages, redo->page, redo->val); journal.npages++; - do_switch_page(redo->val, TRUE); + do_switch_page(redo->val, TRUE, TRUE); } else if (redo->type == ITEM_DELETE_PAGE) { // unmap all the canvas items @@ -698,15 +742,19 @@ on_editRedo_activate (GtkMenuItem *menuitem, if (ui.pageno > undo->val || ui.pageno == journal.npages) ui.pageno--; ui.cur_page = NULL; // so do_switch_page() won't try to remap the layers of the defunct page - do_switch_page(ui.pageno, TRUE); + do_switch_page(ui.pageno, TRUE, TRUE); } else if (redo->type == ITEM_MOVESEL) { for (itemlist = redo->itemlist; itemlist != NULL; itemlist = itemlist->next) { it = (struct Item *)itemlist->data; - if (it->canvas_item != NULL) + if (it->canvas_item != NULL) { + if (redo->layer != redo->layer2) + gnome_canvas_item_reparent(it->canvas_item, redo->layer2->group); gnome_canvas_item_move(it->canvas_item, redo->val_x, redo->val_y); + } } - move_journal_items_by(redo->itemlist, redo->val_x, redo->val_y); + move_journal_items_by(redo->itemlist, redo->val_x, redo->val_y, + redo->layer, redo->layer2, NULL); } else if (redo->type == ITEM_PASTE) { for (itemlist = redo->itemlist; itemlist != NULL; itemlist = itemlist->next) { @@ -729,7 +777,7 @@ on_editRedo_activate (GtkMenuItem *menuitem, redo->page->bg->canvas_item); redo->page->layers = g_list_insert(redo->page->layers, redo->layer, redo->val); redo->page->nlayers++; - do_switch_page(ui.pageno, FALSE); + do_switch_page(ui.pageno, FALSE, FALSE); } else if (redo->type == ITEM_DELETE_LAYER) { gtk_object_destroy(GTK_OBJECT(redo->layer->group)); @@ -744,7 +792,20 @@ on_editRedo_activate (GtkMenuItem *menuitem, redo->page->layers = g_list_append(redo->page->layers, redo->layer2); redo->page->nlayers++; } - do_switch_page(ui.pageno, FALSE); + do_switch_page(ui.pageno, FALSE, FALSE); + } + else if (redo->type == ITEM_REPAINTSEL) { + for (itemlist = redo->itemlist, list = redo->auxlist; itemlist!=NULL; + itemlist = itemlist->next, list = list->next) { + it = (struct Item *)itemlist->data; + g_memmove(&tmp_brush, &(it->brush), sizeof(struct Brush)); + g_memmove(&(it->brush), list->data, sizeof(struct Brush)); + g_memmove(list->data, &tmp_brush, sizeof(struct Brush)); + if (it->type == ITEM_STROKE && it->canvas_item != NULL) + gnome_canvas_item_set(it->canvas_item, + "fill-color-rgba", it->brush.color_rgba, + "width-units", it->brush.thickness, NULL); + } } // move item from redo to undo stack @@ -797,14 +858,16 @@ on_viewContinuous_activate (GtkMenuItem *menuitem, { GtkAdjustment *v_adj; double yscroll; + struct Page *pg; if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem))) return; if (ui.view_continuous) return; ui.view_continuous = TRUE; v_adj = gtk_layout_get_vadjustment(GTK_LAYOUT(canvas)); - yscroll = gtk_adjustment_get_value(v_adj) - ui.cur_page->voffset*ui.zoom; + pg = ui.cur_page; + yscroll = gtk_adjustment_get_value(v_adj) - pg->voffset*ui.zoom; update_page_stuff(); - gtk_adjustment_set_value(v_adj, yscroll + ui.cur_page->voffset*ui.zoom); + gtk_adjustment_set_value(v_adj, yscroll + pg->voffset*ui.zoom); // force a refresh gnome_canvas_set_pixels_per_unit(canvas, ui.zoom); } @@ -834,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(); } @@ -845,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(); } @@ -875,7 +938,7 @@ void on_viewFirstPage_activate (GtkMenuItem *menuitem, gpointer user_data) { - do_switch_page(0, TRUE); + do_switch_page(0, TRUE, FALSE); } @@ -884,7 +947,7 @@ on_viewPreviousPage_activate (GtkMenuItem *menuitem, gpointer user_data) { if (ui.pageno == 0) return; - do_switch_page(ui.pageno-1, TRUE); + do_switch_page(ui.pageno-1, TRUE, FALSE); } @@ -897,7 +960,7 @@ on_viewNextPage_activate (GtkMenuItem *menuitem, on_journalNewPageEnd_activate(menuitem, user_data); return; } - do_switch_page(ui.pageno+1, TRUE); + do_switch_page(ui.pageno+1, TRUE, FALSE); } @@ -905,7 +968,7 @@ void on_viewLastPage_activate (GtkMenuItem *menuitem, gpointer user_data) { - do_switch_page(journal.npages-1, TRUE); + do_switch_page(journal.npages-1, TRUE, FALSE); } @@ -947,7 +1010,7 @@ on_journalNewPageBefore_activate (GtkMenuItem *menuitem, pg = new_page(ui.cur_page); journal.pages = g_list_insert(journal.pages, pg, ui.pageno); journal.npages++; - do_switch_page(ui.pageno, TRUE); + do_switch_page(ui.pageno, TRUE, TRUE); prepare_new_undo(); undo->type = ITEM_NEW_PAGE; @@ -967,7 +1030,7 @@ on_journalNewPageAfter_activate (GtkMenuItem *menuitem, pg = new_page(ui.cur_page); journal.pages = g_list_insert(journal.pages, pg, ui.pageno+1); journal.npages++; - do_switch_page(ui.pageno+1, TRUE); + do_switch_page(ui.pageno+1, TRUE, TRUE); prepare_new_undo(); undo->type = ITEM_NEW_PAGE; @@ -987,7 +1050,7 @@ on_journalNewPageEnd_activate (GtkMenuItem *menuitem, pg = new_page((struct Page *)g_list_last(journal.pages)->data); journal.pages = g_list_append(journal.pages, pg); journal.npages++; - do_switch_page(journal.npages-1, TRUE); + do_switch_page(journal.npages-1, TRUE, TRUE); prepare_new_undo(); undo->type = ITEM_NEW_PAGE; @@ -1027,7 +1090,7 @@ on_journalDeletePage_activate (GtkMenuItem *menuitem, if (ui.pageno == journal.npages) ui.pageno--; ui.cur_page = NULL; // so do_switch_page() won't try to remap the layers of the defunct page - do_switch_page(ui.pageno, TRUE); + do_switch_page(ui.pageno, TRUE, TRUE); } @@ -1123,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}; @@ -1138,11 +1196,14 @@ on_journalPaperSize_activate (GtkMenuItem *menuitem, gpointer user_data) { int i, response; + struct Page *pg; + GList *pglist; 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;itype = ITEM_PAPER_RESIZE; - undo->page = ui.cur_page; - undo->val_x = ui.cur_page->width; - undo->val_y = ui.cur_page->height; - - if (papersize_width_valid) ui.cur_page->width = papersize_width; - if (papersize_height_valid) ui.cur_page->height = papersize_height; - make_page_clipbox(ui.cur_page); - update_canvas_bg(ui.cur_page); - do_switch_page(ui.pageno, TRUE); + 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_PAPER_RESIZE; + undo->page = pg; + undo->val_x = pg->width; + undo->val_y = pg->height; + if (papersize_width_valid) pg->width = papersize_width; + if (papersize_height_valid) pg->height = papersize_height; + make_page_clipbox(pg); + update_canvas_bg(pg); + if (!ui.bg_apply_all_pages) break; + } + do_switch_page(ui.pageno, TRUE, TRUE); } @@ -1279,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, "*"); @@ -1306,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; } @@ -1376,7 +1446,7 @@ on_journalLoadBackground_activate (GtkMenuItem *menuitem, gnome_canvas_set_pixels_per_unit(canvas, ui.zoom); rescale_bg_pixmaps(); } - do_switch_page(ui.pageno, TRUE); + do_switch_page(ui.pageno, TRUE, TRUE); } void @@ -1420,7 +1490,7 @@ on_journalScreenshot_activate (GtkMenuItem *menuitem, gnome_canvas_set_pixels_per_unit(canvas, ui.zoom); rescale_bg_pixmaps(); } - do_switch_page(ui.pageno, TRUE); + do_switch_page(ui.pageno, TRUE, TRUE); } @@ -1428,6 +1498,40 @@ void on_journalApplyAllPages_activate (GtkMenuItem *menuitem, gpointer user_data) { + gboolean active; + + active = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem)); + if (active == ui.bg_apply_all_pages) return; + ui.bg_apply_all_pages = active; + update_page_stuff(); + +/* THIS IS THE OLD VERSION OF THE FEATURE -- APPLIED CURRENT BG TO ALL + struct Page *page; + GList *pglist; + + if (ui.cur_page->bg->type != BG_SOLID) return; + reset_selection(); + for (pglist = journal.pages; pglist!=NULL; pglist = pglist->next) { + page = (struct Page *)pglist->data; + prepare_new_undo(); + undo->type = ITEM_NEW_BG_RESIZE; + undo->page = page; + undo->bg = page->bg; + undo->val_x = page->width; + undo->val_y = page->height; + if (pglist->next!=NULL) undo->multiop |= MULTIOP_CONT_REDO; + if (pglist->prev!=NULL) undo->multiop |= MULTIOP_CONT_UNDO; + page->bg = (struct Background *)g_memdup(ui.cur_page->bg, sizeof(struct Background)); + page->width = ui.cur_page->width; + page->height = ui.cur_page->height; + page->bg->canvas_item = undo->bg->canvas_item; + undo->bg->canvas_item = NULL; + + make_page_clipbox(page); + update_canvas_bg(page); + } + do_switch_page(ui.pageno, TRUE, TRUE); +*/ } @@ -1444,12 +1548,14 @@ on_toolsPen_activate (GtkMenuItem *menuitem, return; } - if (ui.toolno == TOOL_PEN) return; - + if (ui.cur_mapping != 0) return; + if (ui.toolno[0] == TOOL_PEN) return; + reset_selection(); - ui.toolno = TOOL_PEN; - ui.ruler = FALSE; - ui.cur_brush = ui.brushes+TOOL_PEN; + ui.toolno[0] = TOOL_PEN; + ui.ruler[0] = FALSE; + ui.cur_brush = &(ui.brushes[0][TOOL_PEN]); + update_mapping_linkings(TOOL_PEN); update_tool_buttons(); update_tool_menu(); update_color_menu(); @@ -1469,12 +1575,14 @@ on_toolsEraser_activate (GtkMenuItem *menuitem, return; } - if (ui.toolno == TOOL_ERASER) return; + if (ui.cur_mapping != 0) return; + if (ui.toolno[0] == TOOL_ERASER) return; reset_selection(); - ui.toolno = TOOL_ERASER; - ui.ruler = FALSE; - ui.cur_brush = ui.brushes+TOOL_ERASER; + ui.toolno[0] = TOOL_ERASER; + ui.ruler[0] = FALSE; + ui.cur_brush = &(ui.brushes[0][TOOL_ERASER]); + update_mapping_linkings(TOOL_ERASER); update_tool_buttons(); update_tool_menu(); update_color_menu(); @@ -1494,12 +1602,14 @@ on_toolsHighlighter_activate (GtkMenuItem *menuitem, return; } - if (ui.toolno == TOOL_HIGHLIGHTER) return; + if (ui.cur_mapping != 0) return; // not user-generated + if (ui.toolno[0] == TOOL_HIGHLIGHTER) return; reset_selection(); - ui.toolno = TOOL_HIGHLIGHTER; - ui.ruler = FALSE; - ui.cur_brush = ui.brushes+TOOL_HIGHLIGHTER; + ui.toolno[0] = TOOL_HIGHLIGHTER; + ui.ruler[0] = FALSE; + ui.cur_brush = &(ui.brushes[0][TOOL_HIGHLIGHTER]); + update_mapping_linkings(TOOL_HIGHLIGHTER); update_tool_buttons(); update_tool_menu(); update_color_menu(); @@ -1535,10 +1645,12 @@ on_toolsSelectRectangle_activate (GtkMenuItem *menuitem, return; } - if (ui.toolno == TOOL_SELECTRECT) return; + if (ui.cur_mapping != 0) return; // not user-generated + if (ui.toolno[0] == TOOL_SELECTRECT) return; - ui.toolno = TOOL_SELECTRECT; - ui.ruler = FALSE; + ui.toolno[0] = TOOL_SELECTRECT; + ui.ruler[0] = FALSE; + update_mapping_linkings(-1); update_tool_buttons(); update_tool_menu(); update_color_menu(); @@ -1558,11 +1670,13 @@ on_toolsVerticalSpace_activate (GtkMenuItem *menuitem, return; } - if (ui.toolno == TOOL_VERTSPACE) return; + if (ui.cur_mapping != 0) return; // not user-generated + if (ui.toolno[0] == TOOL_VERTSPACE) return; reset_selection(); - ui.toolno = TOOL_VERTSPACE; - ui.ruler = FALSE; + ui.toolno[0] = TOOL_VERTSPACE; + ui.ruler[0] = FALSE; + update_mapping_linkings(-1); update_tool_buttons(); update_tool_menu(); update_color_menu(); @@ -1736,7 +1850,8 @@ on_eraserStandard_activate (GtkMenuItem *menuitem, gpointer user_data) { if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem))) return; - ui.brushes[TOOL_ERASER].tool_options = TOOLOPT_ERASER_STANDARD; + ui.brushes[0][TOOL_ERASER].tool_options = TOOLOPT_ERASER_STANDARD; + update_mapping_linkings(TOOL_ERASER); } @@ -1745,7 +1860,8 @@ on_eraserWhiteout_activate (GtkMenuItem *menuitem, gpointer user_data) { if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem))) return; - ui.brushes[TOOL_ERASER].tool_options = TOOLOPT_ERASER_WHITEOUT; + ui.brushes[0][TOOL_ERASER].tool_options = TOOLOPT_ERASER_WHITEOUT; + update_mapping_linkings(TOOL_ERASER); } @@ -1754,7 +1870,8 @@ on_eraserDeleteStrokes_activate (GtkMenuItem *menuitem, gpointer user_data) { if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem))) return; - ui.brushes[TOOL_ERASER].tool_options = TOOLOPT_ERASER_STROKES; + ui.brushes[0][TOOL_ERASER].tool_options = TOOLOPT_ERASER_STROKES; + update_mapping_linkings(TOOL_ERASER); } @@ -1794,10 +1911,13 @@ void on_toolsDefaultPen_activate (GtkMenuItem *menuitem, gpointer user_data) { + switch_mapping(0); reset_selection(); - g_memmove(ui.brushes+TOOL_PEN, ui.default_brushes+TOOL_PEN, sizeof(struct Brush)); - ui.toolno = TOOL_PEN; - ui.cur_brush = ui.brushes+TOOL_PEN; + g_memmove(&(ui.brushes[0][TOOL_PEN]), ui.default_brushes+TOOL_PEN, sizeof(struct Brush)); + ui.toolno[0] = TOOL_PEN; + ui.cur_brush = &(ui.brushes[0][TOOL_PEN]); + ui.ruler[0] = FALSE; + update_mapping_linkings(TOOL_PEN); update_tool_buttons(); update_tool_menu(); update_pen_props_menu(); @@ -1810,10 +1930,13 @@ void on_toolsDefaultEraser_activate (GtkMenuItem *menuitem, gpointer user_data) { + switch_mapping(0); reset_selection(); - g_memmove(ui.brushes+TOOL_ERASER, ui.default_brushes+TOOL_ERASER, sizeof(struct Brush)); - ui.toolno = TOOL_ERASER; - ui.cur_brush = ui.brushes+TOOL_ERASER; + g_memmove(&(ui.brushes[0][TOOL_ERASER]), ui.default_brushes+TOOL_ERASER, sizeof(struct Brush)); + ui.toolno[0] = TOOL_ERASER; + ui.cur_brush = &(ui.brushes[0][TOOL_ERASER]); + ui.ruler[0] = FALSE; + update_mapping_linkings(TOOL_ERASER); update_tool_buttons(); update_tool_menu(); update_eraser_props_menu(); @@ -1826,10 +1949,13 @@ void on_toolsDefaultHighlighter_activate (GtkMenuItem *menuitem, gpointer user_data) { + switch_mapping(0); reset_selection(); - g_memmove(ui.brushes+TOOL_HIGHLIGHTER, ui.default_brushes+TOOL_HIGHLIGHTER, sizeof(struct Brush)); - ui.toolno = TOOL_HIGHLIGHTER; - ui.cur_brush = ui.brushes+TOOL_HIGHLIGHTER; + g_memmove(&(ui.brushes[0][TOOL_HIGHLIGHTER]), ui.default_brushes+TOOL_HIGHLIGHTER, sizeof(struct Brush)); + ui.toolno[0] = TOOL_HIGHLIGHTER; + ui.cur_brush = &(ui.brushes[0][TOOL_HIGHLIGHTER]); + ui.ruler[0] = FALSE; + update_mapping_linkings(TOOL_HIGHLIGHTER); update_tool_buttons(); update_tool_menu(); update_highlighter_props_menu(); @@ -1849,8 +1975,9 @@ void on_toolsSetAsDefault_activate (GtkMenuItem *menuitem, gpointer user_data) { - if (ui.toolno < NUM_STROKE_TOOLS) - g_memmove(ui.default_brushes+ui.toolno, ui.brushes+ui.toolno, sizeof(struct Brush)); + if (ui.cur_mapping!=0) return; + if (ui.toolno[0] < NUM_STROKE_TOOLS) + g_memmove(ui.default_brushes+ui.toolno[0], &(ui.brushes[0][ui.toolno[0]]), sizeof(struct Brush)); } @@ -1865,19 +1992,21 @@ on_toolsRuler_activate (GtkMenuItem *menuitem, else active = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON (menuitem)); - if (active == ui.ruler) return; + if (ui.cur_mapping != 0) return; + if (active == ui.ruler[0]) return; - if (active && (ui.toolno!=TOOL_PEN && ui.toolno!=TOOL_HIGHLIGHTER)) { + if (active && (ui.toolno[0]!=TOOL_PEN && ui.toolno[0]!=TOOL_HIGHLIGHTER)) { reset_selection(); - ui.toolno = TOOL_PEN; - ui.cur_brush = ui.brushes+TOOL_PEN; + ui.toolno[0] = TOOL_PEN; + ui.cur_brush = &(ui.brushes[0][TOOL_PEN]); update_color_menu(); update_tool_buttons(); update_tool_menu(); update_cursor(); } - ui.ruler = active; + ui.ruler[0] = active; + update_mapping_linkings(ui.toolno[0]); update_ruler_indicator(); } @@ -1886,7 +2015,7 @@ void on_optionsSavePreferences_activate (GtkMenuItem *menuitem, gpointer user_data) { - + save_config_to_file(); } @@ -1918,14 +2047,17 @@ void on_buttonToolDefault_clicked (GtkToolButton *toolbutton, gpointer user_data) { - if (ui.toolno < NUM_STROKE_TOOLS) { - g_memmove(ui.brushes+ui.toolno, ui.default_brushes+ui.toolno, sizeof(struct Brush)); + switch_mapping(0); + if (ui.toolno[0] < NUM_STROKE_TOOLS) { + g_memmove(&(ui.brushes[0][ui.toolno[0]]), ui.default_brushes+ui.toolno[0], sizeof(struct Brush)); + ui.ruler[0] = FALSE; + update_mapping_linkings(ui.toolno[0]); update_thickness_buttons(); update_color_buttons(); update_color_menu(); - if (ui.toolno == TOOL_PEN) update_pen_props_menu(); - if (ui.toolno == TOOL_ERASER) update_eraser_props_menu(); - if (ui.toolno == TOOL_HIGHLIGHTER) update_highlighter_props_menu(); + if (ui.toolno[0] == TOOL_PEN) update_pen_props_menu(); + if (ui.toolno[0] == TOOL_ERASER) update_eraser_props_menu(); + if (ui.toolno[0] == TOOL_HIGHLIGHTER) update_highlighter_props_menu(); update_cursor(); } } @@ -1935,7 +2067,8 @@ void on_buttonFine_clicked (GtkToolButton *toolbutton, gpointer user_data) { - process_thickness_activate((GtkMenuItem*)toolbutton, ui.toolno, THICKNESS_FINE); + if (ui.cur_mapping != 0) return; + process_thickness_activate((GtkMenuItem*)toolbutton, ui.toolno[0], THICKNESS_FINE); } @@ -1943,7 +2076,8 @@ void on_buttonMedium_clicked (GtkToolButton *toolbutton, gpointer user_data) { - process_thickness_activate((GtkMenuItem*)toolbutton, ui.toolno, THICKNESS_MEDIUM); + if (ui.cur_mapping != 0) return; + process_thickness_activate((GtkMenuItem*)toolbutton, ui.toolno[0], THICKNESS_MEDIUM); } @@ -1951,7 +2085,8 @@ void on_buttonThick_clicked (GtkToolButton *toolbutton, gpointer user_data) { - process_thickness_activate((GtkMenuItem*)toolbutton, ui.toolno, THICKNESS_THICK); + if (ui.cur_mapping != 0) return; + process_thickness_activate((GtkMenuItem*)toolbutton, ui.toolno[0], THICKNESS_THICK); } @@ -1964,31 +2099,25 @@ on_canvas_button_press_event (GtkWidget *widget, gboolean page_change; 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_xinput && event->device->source == GDK_SOURCE_ERASER) || - (ui.emulate_eraser && event->button >= 2)) { - ui.saved_toolno = ui.toolno; - ui.saved_ruler = ui.ruler; - reset_selection(); - ui.toolno = TOOL_ERASER; - ui.ruler = FALSE; - ui.cur_brush = ui.brushes + TOOL_ERASER; - update_tool_buttons(); - update_tool_menu(); - update_color_menu(); - update_cursor(); - } + if (ui.use_erasertip && event->device->source == GDK_SOURCE_ERASER) + mapping = NUM_BUTTONS; + else mapping = event->button-1; // check whether we're in a page page_change = FALSE; @@ -2008,21 +2137,11 @@ on_canvas_button_press_event (GtkWidget *widget, ui.pageno++; tmppage = g_list_nth_data(journal.pages, ui.pageno); } - if (page_change) do_switch_page(ui.pageno, FALSE); + if (page_change) do_switch_page(ui.pageno, FALSE, FALSE); // can't paint on the background... if (ui.cur_layer == NULL) { - if (ui.saved_toolno >=0) { - ui.toolno = ui.saved_toolno; - ui.ruler = ui.saved_ruler; - ui.saved_toolno = -1; - if (ui.toolno < NUM_STROKE_TOOLS) ui.cur_brush = ui.brushes + ui.toolno; - update_tool_buttons(); - update_tool_menu(); - update_color_menu(); - update_cursor(); - } /* warn */ dialog = gtk_message_dialog_new(GTK_WINDOW(winMain), GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "Drawing is not allowed on the " @@ -2032,24 +2151,37 @@ on_canvas_button_press_event (GtkWidget *widget, on_viewShowLayer_activate(NULL, NULL); return; } + + // switch mappings if needed - // process the event ui.which_mouse_button = event->button; + switch_mapping(mapping); + + // if this can be a selection move, then it takes precedence over anything else + if (start_movesel((GdkEvent *)event)) return FALSE; - if (ui.toolno == TOOL_PEN || ui.toolno == TOOL_HIGHLIGHTER || - (ui.toolno == TOOL_ERASER && ui.cur_brush->tool_options == TOOLOPT_ERASER_WHITEOUT)) { + if (ui.toolno[mapping] != TOOL_SELECTREGION && ui.toolno[mapping] != TOOL_SELECTRECT) + reset_selection(); + + // process the event + + 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); } - else if (ui.toolno == TOOL_ERASER) { + else if (ui.toolno[mapping] == TOOL_ERASER) { ui.cur_item_type = ITEM_ERASURE; do_eraser((GdkEvent *)event, ui.cur_brush->thickness/2, ui.cur_brush->tool_options == TOOLOPT_ERASER_STROKES); } - else if (ui.toolno == TOOL_SELECTRECT) { - if (!start_movesel((GdkEvent *)event)) - start_selectrect((GdkEvent *)event); + else if (ui.toolno[mapping] == TOOL_SELECTRECT) { + start_selectrect((GdkEvent *)event); } - else if (ui.toolno == TOOL_VERTSPACE) { + else if (ui.toolno[mapping] == TOOL_VERTSPACE) { start_vertspace((GdkEvent *)event); } return FALSE; @@ -2061,27 +2193,17 @@ 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.saved_toolno >= 0) { - ui.toolno = ui.saved_toolno; - ui.ruler = ui.saved_ruler; - ui.saved_toolno = -1; - if (ui.toolno < NUM_STROKE_TOOLS) ui.cur_brush = ui.brushes + ui.toolno; - update_tool_buttons(); - update_tool_menu(); - update_color_menu(); - update_cursor(); - } - if (ui.cur_item_type == ITEM_STROKE) { finalize_stroke(); } @@ -2091,10 +2213,14 @@ on_canvas_button_release_event (GtkWidget *widget, else if (ui.cur_item_type == ITEM_SELECTRECT) { finalize_selectrect(); } - else if (ui.cur_item_type == ITEM_MOVESEL) { + 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; } @@ -2114,7 +2240,7 @@ on_canvas_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data) { - + if (ui.view_continuous && ui.progressive_bg) rescale_bg_pixmaps(); return FALSE; } @@ -2134,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))); @@ -2157,9 +2282,10 @@ on_canvas_motion_notify_event (GtkWidget *widget, else if (ui.cur_item_type == ITEM_SELECTRECT) { finalize_selectrect(); } - else if (ui.cur_item_type == ITEM_MOVESEL) { + else if (ui.cur_item_type == ITEM_MOVESEL || ui.cur_item_type == ITEM_MOVESEL_VERT) { finalize_movesel(); } + switch_mapping(0); return FALSE; } @@ -2177,14 +2303,16 @@ on_canvas_motion_notify_event (GtkWidget *widget, gnome_canvas_item_set(ui.selection->canvas_item, "x2", pt[0], "y2", pt[1], NULL); } - else if (ui.cur_item_type == ITEM_MOVESEL) { + 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; } - void on_comboLayer_changed (GtkComboBox *combobox, gpointer user_data) @@ -2232,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 @@ -2261,7 +2390,7 @@ on_vscroll_changed (GtkAdjustment *adjustment, ui.pageno--; tmppage = g_list_nth_data(journal.pages, ui.pageno); } - if (need_update) do_switch_page(ui.pageno, FALSE); + if (need_update) do_switch_page(ui.pageno, FALSE, FALSE); return; } @@ -2286,7 +2415,7 @@ on_spinPageNo_value_changed (GtkSpinButton *spinbutton, if (val == ui.pageno) return; if (val < 0) val = 0; if (val > journal.npages-1) val = journal.npages-1; - do_switch_page(val, TRUE); + do_switch_page(val, TRUE, FALSE); } @@ -2294,23 +2423,35 @@ 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); - do_switch_page(ui.pageno, TRUE); + make_page_clipbox(pg); + update_canvas_bg(pg); + if (!ui.bg_apply_all_pages) break; + } + do_switch_page(ui.pageno, TRUE, TRUE); } @@ -2454,26 +2595,25 @@ 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]); } void -on_optionsEmulateEraser_activate (GtkMenuItem *menuitem, +on_optionsButtonMappings_activate (GtkMenuItem *menuitem, gpointer user_data) { - ui.emulate_eraser = + ui.use_erasertip = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem)); + update_mappings_menu(); } @@ -2502,3 +2642,366 @@ on_optionsProgressiveBG_activate (GtkMenuItem *menuitem, if (!ui.progressive_bg) rescale_bg_pixmaps(); } + +void +on_mru_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + int which; + gboolean success; + GtkWidget *dialog; + + if (!ok_to_close()) return; // user aborted on save confirmation + + for (which = 0 ; which < MRU_SIZE; which++) { + if (ui.mrumenu[which] == GTK_WIDGET(menuitem)) break; + } + if (which == MRU_SIZE || ui.mru[which] == NULL) return; // not found... + + set_cursor_busy(TRUE); + success = open_journal(ui.mru[which]); + set_cursor_busy(FALSE); + if (success) return; + + /* open failed */ + dialog = gtk_message_dialog_new(GTK_WINDOW (winMain), GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Error opening file '%s'", ui.mru[which]); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + delete_mru_entry(which); +} + + +void +on_button2Pen_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + process_mapping_activate(menuitem, 1, TOOL_PEN); +} + + +void +on_button2Eraser_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + process_mapping_activate(menuitem, 1, TOOL_ERASER); +} + + +void +on_button2Highlighter_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + process_mapping_activate(menuitem, 1, TOOL_HIGHLIGHTER); +} + + +void +on_button2Text_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +on_button2SelectRegion_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + process_mapping_activate(menuitem, 1, TOOL_SELECTREGION); +} + + +void +on_button2SelectRectangle_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + process_mapping_activate(menuitem, 1, TOOL_SELECTRECT); +} + + +void +on_button2VerticalSpace_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + process_mapping_activate(menuitem, 1, TOOL_VERTSPACE); +} + + +void +on_button2LinkBrush_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + int i; + + if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))) return; + ui.linked_brush[1] = BRUSH_LINKED; + for (i=0;i= NUM_STROKE_TOOLS) { + ui.linked_brush[1] = BRUSH_STATIC; + update_mappings_menu_linkings(); + return; + } + ui.linked_brush[1] = BRUSH_COPIED; + g_memmove(&(ui.brushes[1][ui.toolno[1]]), &(ui.brushes[0][ui.toolno[1]]), sizeof(struct Brush)); + ui.ruler[1] = ui.ruler[0]; + if (ui.toolno[1]!=TOOL_PEN && ui.toolno[1]!=TOOL_HIGHLIGHTER) + ui.ruler[1] = FALSE; +} + + +void +on_button3Pen_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + process_mapping_activate(menuitem, 2, TOOL_PEN); +} + + +void +on_button3Eraser_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + process_mapping_activate(menuitem, 2, TOOL_ERASER); +} + + +void +on_button3Highlighter_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + process_mapping_activate(menuitem, 2, TOOL_HIGHLIGHTER); +} + + +void +on_button3Text_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + +} + + +void +on_button3SelectRegion_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + process_mapping_activate(menuitem, 2, TOOL_SELECTREGION); +} + + +void +on_button3SelectRectangle_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + process_mapping_activate(menuitem, 2, TOOL_SELECTRECT); +} + + +void +on_button3VerticalSpace_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + process_mapping_activate(menuitem, 2, TOOL_VERTSPACE); +} + + +void +on_button3LinkBrush_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + int i; + + if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))) return; + ui.linked_brush[2] = BRUSH_LINKED; + for (i=0;i= NUM_STROKE_TOOLS) { + ui.linked_brush[2] = BRUSH_STATIC; + update_mappings_menu_linkings(); + return; + } + ui.linked_brush[2] = BRUSH_COPIED; + g_memmove(&(ui.brushes[2][ui.toolno[2]]), &(ui.brushes[0][ui.toolno[2]]), sizeof(struct Brush)); + ui.ruler[2] = ui.ruler[0]; + if (ui.toolno[2]!=TOOL_PEN && ui.toolno[2]!=TOOL_HIGHLIGHTER) + 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 (valzoom_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(); +}