X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fmain.c;h=e35d50a096a3d3ba0be66a57393b184a50079c6c;hb=69037d6ddbe7e90d13d8a7a088d8c209a926190e;hp=7a5e641410865dcee879546b57a8e7aaed2f7d65;hpb=a78b442e4b673ac29d7dd29cfb2c9bca6f07130a;p=xournal.git
diff --git a/src/main.c b/src/main.c
index 7a5e641..e35d50a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,12 +1,23 @@
-#define ENABLE_XINPUT_BUGFIX 1
-/* change the above to 0 if you are experiencing calibration problems with
- XInput and want to try things differently
-*/
+/*
+ * 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
@@ -17,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;
@@ -26,21 +39,7 @@ struct BgPdf bgpdf; // the PDF loader stuff
struct UIData ui; // the user interface data
struct UndoItem *undo, *redo; // the undo and redo stacks
-void hide_unimplemented(void)
-{
- gtk_widget_hide(GET_COMPONENT("filePrintOptions"));
- gtk_widget_hide(GET_COMPONENT("journalFlatten"));
- gtk_widget_hide(GET_COMPONENT("papercolorOther"));
- gtk_widget_hide(GET_COMPONENT("toolsText"));
- gtk_widget_hide(GET_COMPONENT("buttonText"));
- gtk_widget_hide(GET_COMPONENT("toolsSelectRegion"));
- gtk_widget_hide(GET_COMPONENT("buttonSelectRegion"));
- gtk_widget_hide(GET_COMPONENT("colorOther"));
- gtk_widget_hide(GET_COMPONENT("toolsTextFont"));
- gtk_widget_hide(GET_COMPONENT("toolsDefaultText"));
- gtk_widget_hide(GET_COMPONENT("optionsSavePreferences"));
- gtk_widget_hide(GET_COMPONENT("helpIndex"));
-}
+double DEFAULT_ZOOM;
void init_stuff (int argc, char *argv[])
{
@@ -48,42 +47,38 @@ void init_stuff (int argc, char *argv[])
GList *dev_list;
GdkDevice *device;
GdkScreen *screen;
- int i;
+ int i, j;
struct Brush *b;
gboolean can_xinput, success;
gchar *tmppath, *tmpfn;
- // we need an empty canvas prior to creating the journal structures
- canvas = GNOME_CANVAS (gnome_canvas_new_aa ());
+ // create some data structures needed to populate the preferences
+ ui.default_page.bg = g_new(struct Background, 1);
// initialize config file names
tmppath = g_build_filename(g_get_home_dir(), CONFIG_DIR, NULL);
- g_mkdir(tmppath, 0700); // safer (MRU data may be confidential)
+ mkdir(tmppath, 0700); // safer (MRU data may be confidential)
ui.mrufile = g_build_filename(tmppath, MRU_FILE, NULL);
+ ui.configfile = g_build_filename(tmppath, CONFIG_FILE, NULL);
g_free(tmppath);
- // initialize data
- // TODO: load this from a preferences file
+ // initialize preferences
+ init_config_default();
+ load_config_from_file();
+ ui.font_name = g_strdup(ui.default_font_name);
+ ui.font_size = ui.default_font_size;
+ ui.hiliter_alpha_mask = 0xffffff00 + (guint)(255*ui.hiliter_opacity);
- ui.default_page.height = 792.0;
- ui.default_page.width = 612.0;
- ui.default_page.bg = g_new(struct Background, 1);
- ui.default_page.bg->type = BG_SOLID;
- ui.default_page.bg->color_no = COLOR_WHITE;
- ui.default_page.bg->color_rgba = predef_bgcolors_rgba[COLOR_WHITE];
- ui.default_page.bg->ruling = RULING_LINED;
+ // we need an empty canvas prior to creating the journal structures
+ canvas = GNOME_CANVAS (gnome_canvas_new_aa ());
+
+ // initialize data
ui.default_page.bg->canvas_item = NULL;
-
- ui.zoom = DEFAULT_ZOOM;
- ui.view_continuous = TRUE;
- ui.fullscreen = FALSE;
-
- ui.allow_xinput = TRUE;
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);
}
@@ -98,32 +93,67 @@ 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.toolno = TOOL_PEN;
- ui.cur_brush = ui.brushes + TOOL_PEN;
- ui.ruler = FALSE;
+ 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.brushes[TOOL_PEN].color_no = COLOR_BLACK;
- ui.brushes[TOOL_ERASER].color_no = COLOR_WHITE;
- ui.brushes[TOOL_HIGHLIGHTER].color_no = COLOR_YELLOW;
- for (i=0; i < NUM_STROKE_TOOLS; i++) {
- b = ui.brushes + i;
- b->tool_type = i;
- b->color_rgba = predef_colors_rgba[b->color_no];
- if (i == TOOL_HIGHLIGHTER) {
- b->color_rgba &= HILITER_ALPHA_MASK;
+ 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;
+ 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];
}
- b->thickness_no = THICKNESS_MEDIUM;
- b->thickness = predef_thickness[i][b->thickness_no];
- b->tool_options = 0;
- g_memmove(ui.default_brushes+i, ui.brushes+i, sizeof(struct Brush));
- }
+ for (i=0; istep_increment = 30;
- gtk_layout_get_vadjustment(GTK_LAYOUT (canvas))->step_increment = 30;
+ gtk_layout_get_hadjustment(GTK_LAYOUT (canvas))->step_increment = ui.scrollbar_step_increment;
+ gtk_layout_get_vadjustment(GTK_LAYOUT (canvas))->step_increment = ui.scrollbar_step_increment;
// set up the page size and canvas size
update_page_stuff();
@@ -149,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);
@@ -167,55 +199,94 @@ void init_stuff (int argc, char *argv[])
ui.screen_width = gdk_screen_get_width(screen);
ui.screen_height = gdk_screen_get_height(screen);
- ui.saved_toolno = -1;
-
can_xinput = FALSE;
dev_list = gdk_devices_list();
while (dev_list != NULL) {
device = (GdkDevice *)dev_list->data;
- if (device->source != GDK_SOURCE_MOUSE) {
+ if (device != gdk_device_get_core_pointer() && device->num_axes >= 2) {
/* get around a GDK bug: map the valuator range CORRECTLY to [0,1] */
-#if ENABLE_XINPUT_BUGFIX
+#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;
}
- else gdk_device_set_mode(device, GDK_MODE_DISABLED);
dev_list = dev_list->next;
}
if (!can_xinput)
gtk_widget_set_sensitive(GET_COMPONENT("optionsUseXInput"), FALSE);
ui.use_xinput = ui.allow_xinput && can_xinput;
- ui.antialias_bg = TRUE;
- ui.emulate_eraser = FALSE;
- ui.progressive_bg = TRUE;
gtk_check_menu_item_set_active(
- GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsUseXInput")), ui.use_xinput);
+ GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsProgressiveBG")), ui.progressive_bg);
gtk_check_menu_item_set_active(
- GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsAntialiasBG")), ui.antialias_bg);
+ GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsPrintRuling")), ui.print_ruling);
gtk_check_menu_item_set_active(
- GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsProgressiveBG")), ui.progressive_bg);
+ GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsAutoloadPdfXoj")), ui.autoload_pdf_xoj);
gtk_check_menu_item_set_active(
- GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsEmulateEraser")), ui.emulate_eraser);
-
+ 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();
-
+
update_undo_redo_enabled();
update_copy_paste_enabled();
+ update_vbox_order(ui.vertical_order[ui.fullscreen?1:0]);
+ gtk_widget_grab_focus(GTK_WIDGET(canvas));
// show everything...
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...)
@@ -233,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);
}
@@ -245,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,13 +344,14 @@ main (int argc, char *argv[])
winMain = create_winMain ();
init_stuff (argc, argv);
+ gtk_window_set_icon(GTK_WINDOW(winMain), create_pixbuf("xournal.png"));
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();
return 0;
}