X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fmain.c;h=e35d50a096a3d3ba0be66a57393b184a50079c6c;hb=69037d6ddbe7e90d13d8a7a088d8c209a926190e;hp=cbe9415f42d71ff86cef2c0c8e62cca0c3d59bba;hpb=62e6c9d87f653624015e8dacd4c5e5abbec4cffa;p=xournal.git diff --git a/src/main.c b/src/main.c index cbe9415..e35d50a 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,23 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #ifdef HAVE_CONFIG_H # include #endif +#include #include #include #include @@ -12,6 +28,8 @@ #include "xo-callbacks.h" #include "xo-misc.h" #include "xo-file.h" +#include "xo-paint.h" +#include "xo-shapes.h" GtkWidget *winMain; GnomeCanvas *canvas; @@ -59,8 +77,8 @@ void init_stuff (int argc, char *argv[]) ui.layerbox_length = 0; if (argc > 2 || (argc == 2 && argv[1][0] == '-')) { - printf("Invalid command line parameters.\n" - "Usage: %s [filename.xoj]\n", argv[0]); + printf(_("Invalid command line parameters.\n" + "Usage: %s [filename.xoj]\n"), argv[0]); gtk_exit(0); } @@ -75,18 +93,23 @@ void init_stuff (int argc, char *argv[]) ui.cur_path.coords = NULL; ui.cur_path_storage_alloc = 0; ui.cur_path.ref_count = 1; + ui.cur_widths = NULL; + ui.cur_widths_storage_alloc = 0; ui.selection = NULL; ui.cursor = NULL; + ui.pen_cursor_pix = ui.hiliter_cursor_pix = NULL; ui.cur_brush = &(ui.brushes[0][ui.toolno[0]]); for (j=0; j<=NUM_BUTTONS; j++) for (i=0; i < NUM_STROKE_TOOLS; i++) { b = &(ui.brushes[j][i]); b->tool_type = i; - b->color_rgba = predef_colors_rgba[b->color_no]; - if (i == TOOL_HIGHLIGHTER) { - b->color_rgba &= ui.hiliter_alpha_mask; + if (b->color_no>=0) { + b->color_rgba = predef_colors_rgba[b->color_no]; + if (i == TOOL_HIGHLIGHTER) { + b->color_rgba &= ui.hiliter_alpha_mask; + } } b->thickness = predef_thickness[i][b->thickness_no]; } @@ -94,6 +117,9 @@ void init_stuff (int argc, char *argv[]) g_memmove(ui.default_brushes+i, &(ui.brushes[0][i]), sizeof(struct Brush)); ui.cur_mapping = 0; + ui.which_unswitch_button = 0; + + reset_recognizer(); // initialize various interface elements @@ -111,10 +137,23 @@ void init_stuff (int argc, char *argv[]) GTK_TOGGLE_TOOL_BUTTON(GET_COMPONENT("buttonFullscreen")), TRUE); gtk_window_fullscreen(GTK_WINDOW(winMain)); } + gtk_button_set_relief(GTK_BUTTON(GET_COMPONENT("buttonColorChooser")), GTK_RELIEF_NONE); allow_all_accels(); add_scroll_bindings(); + // prevent interface items from stealing focus + // glade doesn't properly handle can_focus, so manually set it + gtk_combo_box_set_focus_on_click(GTK_COMBO_BOX(GET_COMPONENT("comboLayer")), FALSE); + g_signal_connect(GET_COMPONENT("spinPageNo"), "activate", + G_CALLBACK(handle_activate_signal), NULL); + gtk_container_forall(GTK_CONTAINER(winMain), unset_flags, (gpointer)GTK_CAN_FOCUS); + GTK_WIDGET_SET_FLAGS(GTK_WIDGET(canvas), GTK_CAN_FOCUS); + GTK_WIDGET_SET_FLAGS(GTK_WIDGET(GET_COMPONENT("spinPageNo")), GTK_CAN_FOCUS); + + // install hooks on button/key/activation events to make the spinPageNo lose focus + gtk_container_forall(GTK_CONTAINER(winMain), install_focus_hooks, NULL); + // set up and initialize the canvas gtk_widget_show (GTK_WIDGET (canvas)); @@ -139,6 +178,9 @@ void init_stuff (int argc, char *argv[]) g_signal_connect ((gpointer) canvas, "enter_notify_event", G_CALLBACK (on_canvas_enter_notify_event), NULL); + g_signal_connect ((gpointer) canvas, "leave_notify_event", + G_CALLBACK (on_canvas_leave_notify_event), + NULL); g_signal_connect ((gpointer) canvas, "expose_event", G_CALLBACK (on_canvas_expose_event), NULL); @@ -161,13 +203,15 @@ void init_stuff (int argc, char *argv[]) dev_list = gdk_devices_list(); while (dev_list != NULL) { device = (GdkDevice *)dev_list->data; - if (device != gdk_device_get_core_pointer()) { + if (device != gdk_device_get_core_pointer() && device->num_axes >= 2) { /* get around a GDK bug: map the valuator range CORRECTLY to [0,1] */ #ifdef ENABLE_XINPUT_BUGFIX gdk_device_set_axis_use(device, 0, GDK_AXIS_IGNORE); gdk_device_set_axis_use(device, 1, GDK_AXIS_IGNORE); #endif gdk_device_set_mode(device, GDK_MODE_SCREEN); + if (g_strrstr(device->name, "raser")) + gdk_device_set_source(device, GDK_SOURCE_ERASER); can_xinput = TRUE; } dev_list = dev_list->next; @@ -177,18 +221,20 @@ void init_stuff (int argc, char *argv[]) ui.use_xinput = ui.allow_xinput && can_xinput; - gtk_check_menu_item_set_active( - GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsAntialiasBG")), ui.antialias_bg); gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsProgressiveBG")), ui.progressive_bg); gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsPrintRuling")), ui.print_ruling); + gtk_check_menu_item_set_active( + GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsAutoloadPdfXoj")), ui.autoload_pdf_xoj); gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsLeftHanded")), ui.left_handed); gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsShortenMenus")), ui.shorten_menus); gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsAutoSavePrefs")), ui.auto_save_prefs); + gtk_check_menu_item_set_active( + GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsButtonSwitchMapping")), ui.button_switch_mapping); hide_unimplemented(); @@ -201,16 +247,46 @@ void init_stuff (int argc, char *argv[]) gtk_widget_show (winMain); update_cursor(); - + /* this will cause extension events to get enabled/disabled, but we need the windows to be mapped first */ gtk_check_menu_item_set_active( GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsUseXInput")), ui.use_xinput); + /* fix a bug in GTK+ 2.16 and 2.17: scrollbars shouldn't get extended + input events from pointer motion when cursor moves into main window */ + + if (!gtk_check_version(2, 16, 0)) { + g_signal_connect ( + GET_COMPONENT("menubar"), + "event", G_CALLBACK (filter_extended_events), + NULL); + g_signal_connect ( + GET_COMPONENT("toolbarMain"), + "event", G_CALLBACK (filter_extended_events), + NULL); + g_signal_connect ( + GET_COMPONENT("toolbarPen"), + "event", G_CALLBACK (filter_extended_events), + NULL); + g_signal_connect ( + GET_COMPONENT("statusbar"), + "event", G_CALLBACK (filter_extended_events), + NULL); + g_signal_connect ( + (gpointer)(gtk_scrolled_window_get_vscrollbar(GTK_SCROLLED_WINDOW(w))), + "event", G_CALLBACK (filter_extended_events), + NULL); + g_signal_connect ( + (gpointer)(gtk_scrolled_window_get_hscrollbar(GTK_SCROLLED_WINDOW(w))), + "event", G_CALLBACK (filter_extended_events), + NULL); + } + // load the MRU init_mru(); - + // and finally, open a file specified on the command line // (moved here because display parameters weren't initialized yet...) @@ -228,7 +304,7 @@ void init_stuff (int argc, char *argv[]) set_cursor_busy(FALSE); if (!success) { w = gtk_message_dialog_new(GTK_WINDOW (winMain), GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Error opening file '%s'", argv[1]); + GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Error opening file '%s'"), argv[1]); gtk_dialog_run(GTK_DIALOG(w)); gtk_widget_destroy(w); } @@ -240,6 +316,12 @@ main (int argc, char *argv[]) { gchar *path, *path1, *path2; +#ifdef ENABLE_NLS + bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); +#endif + gtk_set_locale (); gtk_init (&argc, &argv); @@ -267,7 +349,6 @@ main (int argc, char *argv[]) gtk_main (); if (bgpdf.status != STATUS_NOT_INIT) shutdown_bgpdf(); - if (bgpdf.status != STATUS_NOT_INIT) end_bgpdf_shutdown(); save_mru_list(); if (ui.auto_save_prefs) save_config_to_file();