X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fxo-callbacks.c;h=50672f6b14737a2edbf462266894798a12ffbd1d;hb=69037d6ddbe7e90d13d8a7a088d8c209a926190e;hp=43c96fdfc409400a96e5d94aab9fd1ba0c7a6be1;hpb=cfd5ddfe5127ac20d01bd85c96ff16e39ca47696;p=xournal.git
diff --git a/src/xo-callbacks.c b/src/xo-callbacks.c
index 43c96fd..50672f6 100644
--- a/src/xo-callbacks.c
+++ b/src/xo-callbacks.c
@@ -1,3 +1,19 @@
+/*
+ * 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
@@ -17,6 +33,7 @@
#include "xo-misc.h"
#include "xo-file.h"
#include "xo-paint.h"
+#include "xo-selection.h"
#include "xo-print.h"
#include "xo-shapes.h"
@@ -221,7 +238,7 @@ on_fileSaveAs_activate (GtkMenuItem *menuitem,
}
else {
curtime = time(NULL);
- strftime(stime, 30, "%F-Note-%H-%M.xoj", localtime(&curtime));
+ strftime(stime, 30, "%Y-%m-%d-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);
@@ -374,7 +391,7 @@ on_filePrintPDF_activate (GtkMenuItem *menuitem,
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));
+ strftime(stime, 30, "%Y-%m-%d-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);
@@ -452,7 +469,7 @@ on_editUndo_activate (GtkMenuItem *menuitem,
if (undo == NULL) return; // nothing to undo!
reset_selection(); // safer
reset_recognizer(); // safer
- if (undo->type == ITEM_STROKE || undo->type == ITEM_TEXT) {
+ if (undo->type == ITEM_STROKE || undo->type == ITEM_TEXT || undo->type == ITEM_IMAGE) {
// 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;
@@ -666,7 +683,7 @@ on_editRedo_activate (GtkMenuItem *menuitem,
if (redo == NULL) return; // nothing to redo!
reset_selection(); // safer
reset_recognizer(); // safer
- if (redo->type == ITEM_STROKE || redo->type == ITEM_TEXT) {
+ if (redo->type == ITEM_STROKE || redo->type == ITEM_TEXT || redo->type == ITEM_IMAGE) {
// re-create the canvas_item
make_canvas_item_one(redo->layer->group, redo->item);
// reinsert the item on its layer
@@ -824,6 +841,12 @@ on_editRedo_activate (GtkMenuItem *menuitem,
if (it->type == ITEM_TEXT && it->canvas_item != NULL)
gnome_canvas_item_set(it->canvas_item,
"fill-color-rgba", it->brush.color_rgba, NULL);
+ if (it->type == ITEM_IMAGE && it->canvas_item != NULL) {
+ // remark: a variable-width item might have lost its variable-width
+ group = (GnomeCanvasGroup *) it->canvas_item->parent;
+ gtk_object_destroy(GTK_OBJECT(it->canvas_item));
+ make_canvas_item_one(group, it);
+ }
}
}
else if (redo->type == ITEM_TEXT_EDIT) {
@@ -946,6 +969,7 @@ on_viewZoomIn_activate (GtkMenuItem *menuitem,
gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
rescale_text_items();
rescale_bg_pixmaps();
+ rescale_images();
}
@@ -958,6 +982,7 @@ on_viewZoomOut_activate (GtkMenuItem *menuitem,
gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
rescale_text_items();
rescale_bg_pixmaps();
+ rescale_images();
}
@@ -969,6 +994,7 @@ on_viewNormalSize_activate (GtkMenuItem *menuitem,
gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
rescale_text_items();
rescale_bg_pixmaps();
+ rescale_images();
}
@@ -980,6 +1006,7 @@ on_viewPageWidth_activate (GtkMenuItem *menuitem,
gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
rescale_text_items();
rescale_bg_pixmaps();
+ rescale_images();
}
@@ -1308,7 +1335,7 @@ on_papercolorWhite_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
end_text();
- process_papercolor_activate(menuitem, COLOR_WHITE);
+ process_papercolor_activate(menuitem, COLOR_WHITE, predef_bgcolors_rgba[COLOR_WHITE]);
}
@@ -1317,7 +1344,7 @@ on_papercolorYellow_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
end_text();
- process_papercolor_activate(menuitem, COLOR_YELLOW);
+ process_papercolor_activate(menuitem, COLOR_YELLOW, predef_bgcolors_rgba[COLOR_YELLOW]);
}
@@ -1326,7 +1353,7 @@ on_papercolorPink_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
end_text();
- process_papercolor_activate(menuitem, COLOR_RED);
+ process_papercolor_activate(menuitem, COLOR_RED, predef_bgcolors_rgba[COLOR_RED]);
}
@@ -1335,7 +1362,7 @@ on_papercolorOrange_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
end_text();
- process_papercolor_activate(menuitem, COLOR_ORANGE);
+ process_papercolor_activate(menuitem, COLOR_ORANGE, predef_bgcolors_rgba[COLOR_ORANGE]);
}
@@ -1344,7 +1371,7 @@ on_papercolorBlue_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
end_text();
- process_papercolor_activate(menuitem, COLOR_BLUE);
+ process_papercolor_activate(menuitem, COLOR_BLUE, predef_bgcolors_rgba[COLOR_BLUE]);
}
@@ -1353,7 +1380,7 @@ on_papercolorGreen_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
end_text();
- process_papercolor_activate(menuitem, COLOR_GREEN);
+ process_papercolor_activate(menuitem, COLOR_GREEN, predef_bgcolors_rgba[COLOR_GREEN]);
}
@@ -1361,7 +1388,25 @@ void
on_papercolorOther_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
-
+ GtkWidget *dialog;
+ GtkColorSelection *colorsel;
+ gint result;
+ guint rgba;
+ GdkColor gdkcolor;
+
+ end_text();
+ dialog = gtk_color_selection_dialog_new(_("Pick a Paper Color"));
+ colorsel = GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(dialog)->colorsel);
+ if (ui.cur_page->bg->type == BG_SOLID) rgba = ui.cur_page->bg->color_rgba;
+ else rgba = ui.default_page.bg->color_rgba;
+ rgb_to_gdkcolor(rgba, &gdkcolor);
+ gtk_color_selection_set_current_color(colorsel, &gdkcolor);
+
+ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
+ gtk_color_selection_get_current_color(colorsel, &gdkcolor);
+ process_papercolor_activate(menuitem, COLOR_OTHER, gdkcolor_to_rgba(gdkcolor, 0xffff));
+ }
+ gtk_widget_destroy(dialog);
}
@@ -1521,6 +1566,7 @@ on_journalLoadBackground_activate (GtkMenuItem *menuitem,
gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
rescale_text_items();
rescale_bg_pixmaps();
+ rescale_images();
}
do_switch_page(ui.pageno, TRUE, TRUE);
}
@@ -1567,6 +1613,7 @@ on_journalScreenshot_activate (GtkMenuItem *menuitem,
gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
rescale_text_items();
rescale_bg_pixmaps();
+ rescale_images();
}
do_switch_page(ui.pageno, TRUE, TRUE);
}
@@ -1731,10 +1778,55 @@ on_toolsText_activate (GtkMenuItem *menuitem,
void
-on_toolsSelectRegion_activate (GtkMenuItem *menuitem,
+on_toolsImage_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 && !ui.button_switch_mapping) return; // not user-generated
+ if (ui.toolno[ui.cur_mapping] == TOOL_IMAGE) return;
+
+ ui.cur_mapping = 0; // don't use switch_mapping() (refreshes buttons too soon)
+ end_text();
+ reset_selection();
+ ui.toolno[ui.cur_mapping] = TOOL_IMAGE;
+ update_mapping_linkings(-1);
+ update_tool_buttons();
+ update_tool_menu();
+ update_color_menu();
+ update_cursor();
+}
+
+void
+on_toolsSelectRegion_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 && !ui.button_switch_mapping) return; // not user-generated
+ if (ui.toolno[ui.cur_mapping] == TOOL_SELECTREGION) return;
+
+ ui.cur_mapping = 0; // don't use switch_mapping() (refreshes buttons too soon)
+ end_text();
+ ui.toolno[ui.cur_mapping] = TOOL_SELECTREGION;
+ update_mapping_linkings(-1);
+ update_tool_buttons();
+ update_tool_menu();
+ update_color_menu();
+ update_cursor();
}
@@ -2240,7 +2332,7 @@ on_helpAbout_activate (GtkMenuItem *menuitem,
aboutDialog = create_aboutDialog ();
labelTitle = GTK_LABEL(g_object_get_data(G_OBJECT(aboutDialog), "labelTitle"));
gtk_label_set_markup(labelTitle,
- "Xournal " VERSION "");
+ "Xournal " VERSION_STRING "");
gtk_dialog_run (GTK_DIALOG(aboutDialog));
gtk_widget_destroy(aboutDialog);
}
@@ -2303,8 +2395,6 @@ on_canvas_button_press_event (GtkWidget *widget,
gpointer user_data)
{
double pt[2];
- gboolean page_change;
- struct Page *tmppage;
GtkWidget *dialog;
int mapping;
gboolean is_core;
@@ -2352,10 +2442,12 @@ on_canvas_button_press_event (GtkWidget *widget,
}
if ((event->state & (GDK_CONTROL_MASK|GDK_MOD1_MASK)) != 0) return FALSE;
// no control-clicking or alt-clicking
+ if (!is_core) gdk_device_get_state(event->device, event->window, event->axes, NULL);
+ // synaptics touchpads send bogus axis values with ButtonDown
if (!is_core)
fix_xinput_coords((GdkEvent *)event);
- if (!finite(event->x) || !finite(event->y)) return FALSE; // Xorg 7.3 bug
+ if (!finite_sized(event->x) || !finite_sized(event->y)) return FALSE; // Xorg 7.3 bug
if (ui.cur_item_type == ITEM_TEXT) {
if (!is_event_within_textview(event)) end_text();
@@ -2389,24 +2481,8 @@ on_canvas_button_press_event (GtkWidget *widget,
else mapping = event->button-1;
// check whether we're in a page
- page_change = FALSE;
- tmppage = ui.cur_page;
get_pointer_coords((GdkEvent *)event, pt);
- while (ui.view_continuous && (pt[1] < - VIEW_CONTINUOUS_SKIP)) {
- if (ui.pageno == 0) break;
- page_change = TRUE;
- ui.pageno--;
- tmppage = g_list_nth_data(journal.pages, ui.pageno);
- pt[1] += tmppage->height + VIEW_CONTINUOUS_SKIP;
- }
- while (ui.view_continuous && (pt[1] > tmppage->height + VIEW_CONTINUOUS_SKIP)) {
- if (ui.pageno == journal.npages-1) break;
- pt[1] -= tmppage->height + VIEW_CONTINUOUS_SKIP;
- page_change = TRUE;
- ui.pageno++;
- tmppage = g_list_nth_data(journal.pages, ui.pageno);
- }
- if (page_change) do_switch_page(ui.pageno, FALSE, FALSE);
+ set_current_page(pt);
// can't paint on the background...
@@ -2425,6 +2501,9 @@ on_canvas_button_press_event (GtkWidget *widget,
ui.which_mouse_button = event->button;
switch_mapping(mapping);
+#ifdef WIN32
+ update_cursor();
+#endif
// in text tool, clicking in a text area edits it
if (ui.toolno[mapping] == TOOL_TEXT) {
@@ -2460,6 +2539,9 @@ on_canvas_button_press_event (GtkWidget *widget,
do_eraser((GdkEvent *)event, ui.cur_brush->thickness/2,
ui.cur_brush->tool_options == TOOLOPT_ERASER_STROKES);
}
+ else if (ui.toolno[mapping] == TOOL_SELECTREGION) {
+ start_selectregion((GdkEvent *)event);
+ }
else if (ui.toolno[mapping] == TOOL_SELECTRECT) {
start_selectrect((GdkEvent *)event);
}
@@ -2469,6 +2551,9 @@ on_canvas_button_press_event (GtkWidget *widget,
else if (ui.toolno[mapping] == TOOL_TEXT) {
start_text((GdkEvent *)event, NULL);
}
+ else if (ui.toolno[mapping] == TOOL_IMAGE) {
+ insert_image((GdkEvent *)event);
+ }
return FALSE;
}
@@ -2501,6 +2586,9 @@ on_canvas_button_release_event (GtkWidget *widget,
else if (ui.cur_item_type == ITEM_ERASURE) {
finalize_erasure();
}
+ else if (ui.cur_item_type == ITEM_SELECTREGION) {
+ finalize_selectregion();
+ }
else if (ui.cur_item_type == ITEM_SELECTRECT) {
finalize_selectrect();
}
@@ -2526,7 +2614,25 @@ on_canvas_enter_notify_event (GtkWidget *widget,
GdkEventCrossing *event,
gpointer user_data)
{
+ GList *dev_list;
+ GdkDevice *dev;
+#ifdef INPUT_DEBUG
+ printf("DEBUG: enter notify\n");
+#endif
+ /* re-enable input devices after they've been emergency-disabled
+ by leave_notify */
+ if (!gtk_check_version(2, 17, 0)) {
+ gdk_flush();
+ gdk_error_trap_push();
+ for (dev_list = gdk_devices_list(); dev_list != NULL; dev_list = dev_list->next) {
+ dev = GDK_DEVICE(dev_list->data);
+ gdk_device_set_mode(dev, GDK_MODE_SCREEN);
+ }
+ ui.is_corestroke = ui.saved_is_corestroke;
+ gdk_flush();
+ gdk_error_trap_pop();
+ }
return FALSE;
}
@@ -2535,12 +2641,25 @@ on_canvas_leave_notify_event (GtkWidget *widget,
GdkEventCrossing *event,
gpointer user_data)
{
+ GList *dev_list;
+ GdkDevice *dev;
+
#ifdef INPUT_DEBUG
- printf("DEBUG: leave notify\n");
+ printf("DEBUG: leave notify (mode=%d, details=%d)\n", event->mode, event->detail);
#endif
- if (ui.need_emergency_disable_xinput) {
- gtk_widget_set_extension_events(GTK_WIDGET (canvas), GDK_EXTENSION_EVENTS_NONE);
- ui.need_emergency_disable_xinput = FALSE;
+ /* emergency disable XInput to avoid segfaults (GTK+ 2.17) or
+ interface non-responsiveness (GTK+ 2.18) */
+ if (!gtk_check_version(2, 17, 0)) {
+ gdk_flush();
+ gdk_error_trap_push();
+ for (dev_list = gdk_devices_list(); dev_list != NULL; dev_list = dev_list->next) {
+ dev = GDK_DEVICE(dev_list->data);
+ gdk_device_set_mode(dev, GDK_MODE_DISABLED);
+ }
+ ui.saved_is_corestroke = ui.is_corestroke;
+ ui.is_corestroke = TRUE;
+ gdk_flush();
+ gdk_error_trap_pop();
}
return FALSE;
}
@@ -2627,12 +2746,12 @@ on_canvas_motion_notify_event (GtkWidget *widget,
or if there's a selection (then we might want to change the mouse
cursor to indicate the possibility of resizing) */
if (ui.cur_item_type == ITEM_NONE && ui.selection==NULL) return FALSE;
- if (ui.cur_item_type == ITEM_TEXT) return FALSE;
+ if (ui.cur_item_type == ITEM_TEXT || ui.cur_item_type == ITEM_IMAGE) return FALSE;
is_core = (event->device == gdk_device_get_core_pointer());
if (!ui.use_xinput && !is_core) return FALSE;
if (!is_core) fix_xinput_coords((GdkEvent *)event);
- if (!finite(event->x) || !finite(event->y)) return FALSE; // Xorg 7.3 bug
+ if (!finite_sized(event->x) || !finite_sized(event->y)) return FALSE; // Xorg 7.3 bug
if (ui.selection!=NULL && ui.cur_item_type == ITEM_NONE) {
get_pointer_coords((GdkEvent *)event, pt);
@@ -2662,6 +2781,9 @@ on_canvas_motion_notify_event (GtkWidget *widget,
else if (ui.cur_item_type == ITEM_ERASURE) {
finalize_erasure();
}
+ else if (ui.cur_item_type == ITEM_SELECTREGION) {
+ finalize_selectregion();
+ }
else if (ui.cur_item_type == ITEM_SELECTRECT) {
finalize_selectrect();
}
@@ -2671,6 +2793,9 @@ on_canvas_motion_notify_event (GtkWidget *widget,
else if (ui.cur_item_type == ITEM_RESIZESEL) {
finalize_resizesel();
}
+ else if (ui.cur_item_type == ITEM_HAND) {
+ ui.cur_item_type = ITEM_NONE;
+ }
switch_mapping(0);
return FALSE;
}
@@ -2682,6 +2807,9 @@ on_canvas_motion_notify_event (GtkWidget *widget,
do_eraser((GdkEvent *)event, ui.cur_brush->thickness/2,
ui.cur_brush->tool_options == TOOLOPT_ERASER_STROKES);
}
+ else if (ui.cur_item_type == ITEM_SELECTREGION) {
+ continue_selectregion((GdkEvent *)event);
+ }
else if (ui.cur_item_type == ITEM_SELECTRECT) {
get_pointer_coords((GdkEvent *)event, pt);
ui.selection->bbox.right = pt[0];
@@ -2773,7 +2901,9 @@ on_optionsUseXInput_activate (GtkMenuItem *menuitem,
non-responsive).
*/
+#ifndef WIN32
if (!gtk_check_version(2, 17, 0)) {
+#endif
/* GTK+ 2.17 and later: everybody shares a single native window,
so we'll never get any core events, and we might as well set
extension events the way we're supposed to. Doing so helps solve
@@ -2781,14 +2911,18 @@ on_optionsUseXInput_activate (GtkMenuItem *menuitem,
events in 2.18 */
gtk_widget_set_extension_events(GTK_WIDGET (canvas),
ui.use_xinput?GDK_EXTENSION_EVENTS_ALL:GDK_EXTENSION_EVENTS_NONE);
+#ifndef WIN32
} else {
+#endif
/* GTK+ 2.16 and earlier: we only activate extension events on the
canvas's parent GdkWindow. This allows us to keep receiving core
events. */
gdk_input_set_extension_events(GTK_WIDGET(canvas)->window,
GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK,
ui.use_xinput?GDK_EXTENSION_EVENTS_ALL:GDK_EXTENSION_EVENTS_NONE);
+#ifndef WIN32
}
+#endif
update_mappings_menu();
}
@@ -3124,6 +3258,14 @@ on_button2Text_activate (GtkMenuItem *menuitem,
}
+void
+on_button2Image_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ process_mapping_activate(menuitem, 1, TOOL_IMAGE);
+}
+
+
void
on_button2SelectRegion_activate (GtkMenuItem *menuitem,
gpointer user_data)
@@ -3209,6 +3351,14 @@ on_button3Text_activate (GtkMenuItem *menuitem,
}
+void
+on_button3Image_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ process_mapping_activate(menuitem, 2, TOOL_IMAGE);
+}
+
+
void
on_button3SelectRegion_activate (GtkMenuItem *menuitem,
gpointer user_data)
@@ -3302,6 +3452,7 @@ on_viewSetZoom_activate (GtkMenuItem *menuitem,
gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
rescale_text_items();
rescale_bg_pixmaps();
+ rescale_images();
}
} while (response == GTK_RESPONSE_APPLY);
@@ -3420,13 +3571,11 @@ on_optionsPrintRuling_activate (GtkMenuItem *menuitem,
}
void
-on_optionsDiscardCore_activate (GtkMenuItem *menuitem,
+on_optionsAutoloadPdfXoj_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
end_text();
- ui.discard_corepointer =
- gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
- update_mappings_menu();
+ ui.autoload_pdf_xoj = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
}
void
@@ -3527,3 +3676,4 @@ on_optionsButtonsSwitchMappings_activate(GtkMenuItem *menuitem,
ui.button_switch_mapping = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
}
+