📄 xo-callbacks.c
字号:
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); g_free(in_fn); 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); 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); } set_cursor_busy(FALSE); g_free(filename);}voidon_fileQuit_activate (GtkMenuItem *menuitem, gpointer user_data){ end_text(); reset_focus(); if (ok_to_close()) gtk_main_quit ();}voidon_editUndo_activate (GtkMenuItem *menuitem, gpointer user_data){ struct UndoItem *u; GList *list, *itemlist; struct UndoErasureData *erasure; struct Item *it; struct Brush tmp_brush; struct Background *tmp_bg; double tmp_x, tmp_y; gchar *tmpstr; end_text(); reset_focus(); if (undo == NULL) return; // nothing to undo! reset_selection(); // safer if (undo->type == ITEM_STROKE || undo->type == ITEM_TEXT) { // we're keeping the stroke info, but deleting the canvas item gtk_object_destroy(GTK_OBJECT(undo->item->canvas_item)); undo->item->canvas_item = NULL; // we also remove the object from its layer! undo->layer->items = g_list_remove(undo->layer->items, undo->item); undo->layer->nitems--; } else if (undo->type == ITEM_ERASURE) { for (list = undo->erasurelist; list!=NULL; list = list->next) { erasure = (struct UndoErasureData *)list->data; // delete all the created items for (itemlist = erasure->replacement_items; itemlist!=NULL; itemlist = itemlist->next) { it = (struct Item *)itemlist->data; gtk_object_destroy(GTK_OBJECT(it->canvas_item)); it->canvas_item = NULL; undo->layer->items = g_list_remove(undo->layer->items, it); undo->layer->nitems--; } // recreate the deleted one make_canvas_item_one(undo->layer->group, erasure->item); undo->layer->items = g_list_insert(undo->layer->items, erasure->item, erasure->npos); if (erasure->npos == 0) lower_canvas_item_to(undo->layer->group, erasure->item->canvas_item, NULL); else lower_canvas_item_to(undo->layer->group, erasure->item->canvas_item, ((struct Item *)g_list_nth_data(undo->layer->items, erasure->npos-1))->canvas_item); undo->layer->nitems++; } } else if (undo->type == ITEM_NEW_BG_ONE || undo->type == ITEM_NEW_BG_RESIZE || undo->type == ITEM_PAPER_RESIZE) { if (undo->type != ITEM_PAPER_RESIZE) { // swap the two bg's tmp_bg = undo->page->bg; undo->page->bg = undo->bg; undo->bg = tmp_bg; undo->page->bg->canvas_item = undo->bg->canvas_item; undo->bg->canvas_item = NULL; } if (undo->type != ITEM_NEW_BG_ONE) { tmp_x = undo->page->width; tmp_y = undo->page->height; undo->page->width = undo->val_x; undo->page->height = undo->val_y; undo->val_x = tmp_x; undo->val_y = tmp_y; make_page_clipbox(undo->page); } update_canvas_bg(undo->page); 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; ui.default_page.bg = undo->bg; undo->bg = tmp_bg; tmp_x = ui.default_page.width; tmp_y = ui.default_page.height; ui.default_page.width = undo->val_x; ui.default_page.height = undo->val_y; undo->val_x = tmp_x; undo->val_y = tmp_y; } else if (undo->type == ITEM_NEW_PAGE) { // unmap the page; keep the page & its empty layer in memory if (undo->page->group!=NULL) gtk_object_destroy(GTK_OBJECT(undo->page->group)); // also destroys the background and layer's canvas items undo->page->group = NULL; undo->page->bg->canvas_item = NULL; journal.pages = g_list_remove(journal.pages, undo->page); journal.npages--; if (ui.cur_page == undo->page) ui.cur_page = NULL; // 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, 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, 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 (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, undo->layer2, undo->layer, undo->auxlist); } else if (undo->type == ITEM_PASTE) { for (itemlist = undo->itemlist; itemlist != NULL; itemlist = itemlist->next) { it = (struct Item *)itemlist->data; gtk_object_destroy(GTK_OBJECT(it->canvas_item)); it->canvas_item = NULL; undo->layer->items = g_list_remove(undo->layer->items, it); undo->layer->nitems--; } } else if (undo->type == ITEM_NEW_LAYER) { // unmap the layer; keep the empty layer in memory if (undo->layer->group!=NULL) gtk_object_destroy(GTK_OBJECT(undo->layer->group)); undo->layer->group = NULL; undo->page->layers = g_list_remove(undo->page->layers, undo->layer); undo->page->nlayers--; 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 if (undo->val == -1) { if (undo->layer2->group!=NULL) gtk_object_destroy(GTK_OBJECT(undo->layer2->group)); undo->layer2->group = NULL; undo->page->layers = g_list_remove(undo->page->layers, undo->layer2); undo->page->nlayers--; } // re-map the layer undo->layer->group = (GnomeCanvasGroup *) gnome_canvas_item_new( undo->page->group, gnome_canvas_group_get_type(), NULL); lower_canvas_item_to(undo->page->group, GNOME_CANVAS_ITEM(undo->layer->group), (undo->val >= 1) ? GNOME_CANVAS_ITEM(((struct Layer *) g_list_nth_data(undo->page->layers, undo->val-1))->group) : undo->page->bg->canvas_item); undo->page->layers = g_list_insert(undo->page->layers, undo->layer, (undo->val >= 0) ? undo->val:0); undo->page->nlayers++; for (itemlist = undo->layer->items; itemlist!=NULL; itemlist = itemlist->next) make_canvas_item_one(undo->layer->group, (struct Item *)itemlist->data); 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); if (it->type == ITEM_TEXT && it->canvas_item != NULL) gnome_canvas_item_set(it->canvas_item, "fill-color-rgba", it->brush.color_rgba, NULL); } } else if (undo->type == ITEM_TEXT_EDIT) { tmpstr = undo->str; undo->str = undo->item->text; undo->item->text = tmpstr; gnome_canvas_item_set(undo->item->canvas_item, "text", tmpstr, NULL); update_item_bbox(undo->item); } else if (undo->type == ITEM_TEXT_ATTRIB) { tmpstr = undo->str; undo->str = undo->item->font_name; undo->item->font_name = tmpstr; tmp_x = undo->val_x; undo->val_x = undo->item->font_size; undo->item->font_size = tmp_x; g_memmove(&tmp_brush, undo->brush, sizeof(struct Brush)); g_memmove(undo->brush, &(undo->item->brush), sizeof(struct Brush)); g_memmove(&(undo->item->brush), &tmp_brush, sizeof(struct Brush)); gnome_canvas_item_set(undo->item->canvas_item, "fill-color-rgba", undo->item->brush.color_rgba, NULL); update_text_item_displayfont(undo->item); update_item_bbox(undo->item); } // move item from undo to redo stack u = undo; undo = undo->next; u->next = redo; redo = u; ui.saved = FALSE; update_undo_redo_enabled(); if (u->multiop & MULTIOP_CONT_UNDO) on_editUndo_activate(NULL,NULL); // loop}voidon_editRedo_activate (GtkMenuItem *menuitem, gpointer user_data){ struct UndoItem *u; 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; gchar *tmpstr; end_text(); reset_focus(); if (redo == NULL) return; // nothing to redo! reset_selection(); // safer if (redo->type == ITEM_STROKE || redo->type == ITEM_TEXT) { // re-create the canvas_item make_canvas_item_one(redo->layer->group, redo->item); // reinsert the item on its layer redo->layer->items = g_list_append(redo->layer->items, redo->item); redo->layer->nitems++; } else if (redo->type == ITEM_ERASURE) { for (list = redo->erasurelist; list!=NULL; list = list->next) { erasure = (struct UndoErasureData *)list->data; target = g_list_find(redo->layer->items, erasure->item); // re-create all the created items for (itemlist = erasure->replacement_items; itemlist!=NULL; itemlist = itemlist->next) { it = (struct Item *)itemlist->data; make_canvas_item_one(redo->layer->group, it); redo->layer->items = g_list_insert_before(redo->layer->items, target, it); redo->layer->nitems++; lower_canvas_item_to(redo->layer->group, it->canvas_item, erasure->item->canvas_item); } // re-delete the deleted one gtk_object_destroy(GTK_OBJECT(erasure->item->canvas_item)); erasure->item->canvas_item = NULL; redo->layer->items = g_list_delete_link(redo->layer->items, target); redo->layer->nitems--; } } else if (redo->type == ITEM_NEW_BG_ONE || redo->type == ITEM_NEW_BG_RESIZE || redo->type == ITEM_PAPER_RESIZE) { if (redo->type != ITEM_PAPER_RESIZE) { // swap the two bg's tmp_bg = redo->page->bg; redo->page->bg = redo->bg; redo->bg = tmp_bg; redo->page->bg->canvas_item = redo->bg->canvas_item; redo->bg->canvas_item = NULL; } if (redo->type != ITEM_NEW_BG_ONE) { tmp_x = redo->page->width; tmp_y = redo->page->height; redo->page->width = redo->val_x; redo->page->height = redo->val_y; redo->val_x = tmp_x; redo->val_y = tmp_y; make_page_clipbox(redo->page); } update_canvas_bg(redo->page); 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; ui.default_page.bg = redo->bg; redo->bg = tmp_bg; tmp_x = ui.default_page.width; tmp_y = ui.default_page.height; ui.default_page.width = redo->val_x; ui.default_page.height = redo->val_y; redo->val_x = tmp_x; redo->val_y = tmp_y; } else if (redo->type == ITEM_NEW_PAGE) { // remap the page redo->page->bg->canvas_item = NULL; redo->page->group = (GnomeCanvasGroup *) gnome_canvas_item_new( gnome_canvas_root(canvas), gnome_canvas_clipgroup_get_type(), NULL); make_page_clipbox(redo->page); update_canvas_bg(redo->page); l = (struct Layer *)redo->page->layers->data; l->group = (GnomeCanvasGroup *) gnome_canvas_item_new( redo->page->group, gnome_canvas_group_get_type(), NULL); journal.pages = g_list_insert(journal.pages, redo->page, redo->val); journal.npages++; do_switch_page(redo->val, TRUE, TRUE); } else if (redo->type == ITEM_DELETE_PAGE) { // unmap all the canvas items gtk_object_destroy(GTK_OBJECT(redo->page->group)); redo->page->group = NULL; redo->page->bg->canvas_item = NULL; for (list = redo->page->layers; list!=NULL; list = list->next) { l = (struct Layer *)list->data; for (itemlist = l->items; itemlist!=NULL; itemlist = itemlist->next) ((struct Item *)itemlist->data)->canvas_item = NULL; l->group = NULL; } journal.pages = g_list_remove(journal.pages, redo->page); journal.npages--; 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, 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 (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, redo->layer, redo->layer2, NULL); } else if (redo->type == ITEM_PASTE) { for (itemlist = redo->itemlist; itemlist != NULL; itemlist = itemlist->next) { it = (struct Item *)itemlist->data; make_canvas_item_one(redo->layer->group, it); redo->layer->items = g_list_append(redo->layer->items, it); redo->layer->nitems++; } } else if (redo->type == ITEM_NEW_LAYER) { redo->layer->group = (GnomeCanvasGroup *) gnome_canvas_item_new( redo->page->group, gnome_canvas_group_get_type(), NULL); lower_canvas_item_to(redo->page->group, GNOME_CANVAS_ITEM(redo->layer->group), (redo->val >= 1) ? GNOME_CANVAS_ITEM(((struct Layer *) g_list_nth_data(redo->page->layers, redo->val-1))->group) : 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, FALSE); } else if (redo->type == ITEM_DELETE_LAYER) { gtk_object_destroy(GTK_OBJECT(redo->layer->group)); redo->layer->group = NULL; for (list=redo->layer->items; list!=NULL; list=list->next) ((struct Item *)list->data)->canvas_item = NULL; redo->page->layers = g_list_remove(redo->page->layers, redo->layer); redo->page->nlayers--; if (redo->val == -1) { redo->layer2->group = (GnomeCanvasGroup *)gnome_canvas_item_new( redo->page->group, gnome_canvas_group_get_type(), NULL); redo->page->layers = g_list_append(redo->page->layers, redo->layer2); redo->page->nlayers++; } 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -