#include <time.h>
#include <libgnomeprintui/gnome-print-dialog.h>
#include <glib/gstdio.h>
+#include <gdk/gdkkeysyms.h>
#include "xournal.h"
#include "xo-callbacks.h"
#include "xo-file.h"
#include "xo-paint.h"
#include "xo-print.h"
+#include "xo-shapes.h"
void
on_fileNew_activate (GtkMenuItem *menuitem,
on_filePrint_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
- GtkWidget *printDialog, *preview;
+ GtkWidget *printDialog;
GnomePrintJob *gpj;
int fromPage, toPage;
int response;
char *filename, *in_fn;
char stime[30];
time_t curtime;
- int response;
gboolean warn;
end_text();
struct Background *tmp_bg;
double tmp_x, tmp_y;
gchar *tmpstr;
+ GnomeCanvasGroup *group;
end_text();
reset_focus();
undo->layer->items = g_list_remove(undo->layer->items, undo->item);
undo->layer->nitems--;
}
- else if (undo->type == ITEM_ERASURE) {
+ else if (undo->type == ITEM_ERASURE || undo->type == ITEM_RECOGNIZER) {
for (list = undo->erasurelist; list!=NULL; list = list->next) {
erasure = (struct UndoErasureData *)list->data;
// delete all the created items
move_journal_items_by(undo->itemlist, -undo->val_x, -undo->val_y,
undo->layer2, undo->layer, undo->auxlist);
}
+ else if (undo->type == ITEM_RESIZESEL) {
+ resize_journal_items_by(undo->itemlist,
+ 1/undo->scaling_x, 1/undo->scaling_y,
+ -undo->val_x/undo->scaling_x, -undo->val_y/undo->scaling_y);
+ }
else if (undo->type == ITEM_PASTE) {
for (itemlist = undo->itemlist; itemlist != NULL; itemlist = itemlist->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_STROKE && 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);
+ }
if (it->type == ITEM_TEXT && it->canvas_item != NULL)
gnome_canvas_item_set(it->canvas_item,
"fill-color-rgba", it->brush.color_rgba, NULL);
struct Layer *l;
double tmp_x, tmp_y;
gchar *tmpstr;
+ GnomeCanvasGroup *group;
end_text();
reset_focus();
redo->layer->items = g_list_append(redo->layer->items, redo->item);
redo->layer->nitems++;
}
- else if (redo->type == ITEM_ERASURE) {
+ else if (redo->type == ITEM_ERASURE || redo->type == ITEM_RECOGNIZER) {
for (list = redo->erasurelist; list!=NULL; list = list->next) {
erasure = (struct UndoErasureData *)list->data;
target = g_list_find(redo->layer->items, erasure->item);
move_journal_items_by(redo->itemlist, redo->val_x, redo->val_y,
redo->layer, redo->layer2, NULL);
}
+ else if (redo->type == ITEM_RESIZESEL) {
+ resize_journal_items_by(redo->itemlist,
+ redo->scaling_x, redo->scaling_y, redo->val_x, redo->val_y);
+ }
else if (redo->type == ITEM_PASTE) {
for (itemlist = redo->itemlist; itemlist != NULL; itemlist = itemlist->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_STROKE && 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);
+ }
if (it->type == ITEM_TEXT && it->canvas_item != NULL)
gnome_canvas_item_set(it->canvas_item,
"fill-color-rgba", it->brush.color_rgba, NULL);
end_text();
reset_focus();
if (ui.pageno == journal.npages-1) { // create a page at end
- if (page_ops_forbidden()) return;
on_journalNewPageEnd_activate(menuitem, user_data);
return;
}
end_text();
reset_focus();
- if (page_ops_forbidden()) return;
reset_selection();
pg = new_page(ui.cur_page);
journal.pages = g_list_insert(journal.pages, pg, ui.pageno);
end_text();
reset_focus();
- if (page_ops_forbidden()) return;
reset_selection();
pg = new_page(ui.cur_page);
journal.pages = g_list_insert(journal.pages, pg, ui.pageno+1);
end_text();
reset_focus();
- if (page_ops_forbidden()) return;
reset_selection();
pg = new_page((struct Page *)g_list_last(journal.pages)->data);
journal.pages = g_list_append(journal.pages, pg);
end_text();
reset_focus();
- if (page_ops_forbidden()) return;
if (journal.npages == 1) return;
reset_selection();
prepare_new_undo();
reset_focus();
reset_selection();
ui.toolno[0] = TOOL_PEN;
- ui.ruler[0] = FALSE;
ui.cur_brush = &(ui.brushes[0][TOOL_PEN]);
+ ui.cur_brush->ruler = ui.default_brushes[TOOL_PEN].ruler;
+ ui.cur_brush->recognizer = ui.default_brushes[TOOL_PEN].recognizer;
update_mapping_linkings(TOOL_PEN);
update_tool_buttons();
update_tool_menu();
reset_focus();
reset_selection();
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();
reset_focus();
reset_selection();
ui.toolno[0] = TOOL_HIGHLIGHTER;
- ui.ruler[0] = FALSE;
ui.cur_brush = &(ui.brushes[0][TOOL_HIGHLIGHTER]);
+ ui.cur_brush->ruler = ui.default_brushes[TOOL_HIGHLIGHTER].ruler;
+ ui.cur_brush->recognizer = ui.default_brushes[TOOL_HIGHLIGHTER].recognizer;
update_mapping_linkings(TOOL_HIGHLIGHTER);
update_tool_buttons();
update_tool_menu();
reset_focus();
reset_selection();
ui.toolno[0] = TOOL_TEXT;
- ui.ruler[0] = FALSE;
ui.cur_brush = &(ui.brushes[0][TOOL_PEN]);
update_mapping_linkings(-1);
update_tool_buttons();
end_text();
reset_focus();
ui.toolno[0] = TOOL_SELECTRECT;
- ui.ruler[0] = FALSE;
update_mapping_linkings(-1);
update_tool_buttons();
update_tool_menu();
reset_focus();
reset_selection();
ui.toolno[0] = TOOL_VERTSPACE;
- ui.ruler[0] = FALSE;
update_mapping_linkings(-1);
update_tool_buttons();
update_tool_menu();
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();
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();
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();
reset_focus();
reset_selection();
ui.toolno[0] = TOOL_TEXT;
- ui.ruler[0] = FALSE;
ui.cur_brush = &(ui.brushes[0][TOOL_PEN]);
ui.cur_brush->color_no = ui.default_brushes[TOOL_PEN].color_no;
ui.cur_brush->color_rgba = ui.default_brushes[TOOL_PEN].color_rgba;
on_toolsRuler_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
- gboolean active;
+ gboolean active, current;
+
+ if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_CHECK_MENU_ITEM)
+ active = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
+ else
+ active = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON (menuitem));
+
+ if (ui.cur_mapping != 0) return;
+ current = (ui.toolno[0] == TOOL_PEN || ui.toolno[0] == TOOL_HIGHLIGHTER) && ui.cur_brush->ruler;
+ if (active == current) return;
+
+ end_text();
+ reset_focus();
+ if (ui.toolno[0]!=TOOL_PEN && ui.toolno[0]!=TOOL_HIGHLIGHTER) {
+ reset_selection();
+ 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.cur_brush->ruler = active;
+ if (active) ui.cur_brush->recognizer = FALSE;
+ update_mapping_linkings(ui.toolno[0]);
+ update_ruler_indicator();
+}
+
+
+void
+on_toolsReco_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ gboolean active, current;
if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_CHECK_MENU_ITEM)
active = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
active = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON (menuitem));
if (ui.cur_mapping != 0) return;
- if (active == ui.ruler[0]) return;
+ current = (ui.toolno[0] == TOOL_PEN || ui.toolno[0] == TOOL_HIGHLIGHTER) && ui.cur_brush->recognizer;
+ if (active == current) return;
end_text();
reset_focus();
- if (active && (ui.toolno[0]!=TOOL_PEN && ui.toolno[0]!=TOOL_HIGHLIGHTER)) {
+ if (ui.toolno[0]!=TOOL_PEN && ui.toolno[0]!=TOOL_HIGHLIGHTER) {
reset_selection();
ui.toolno[0] = TOOL_PEN;
ui.cur_brush = &(ui.brushes[0][TOOL_PEN]);
update_cursor();
}
- ui.ruler[0] = active;
+ ui.cur_brush->recognizer = active;
+ if (active) {
+ ui.cur_brush->ruler = FALSE;
+ reset_recognizer();
+ }
update_mapping_linkings(ui.toolno[0]);
update_ruler_indicator();
}
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();
if (event->button > 3) return FALSE; // no painting with the mouse wheel!
if (event->type != GDK_BUTTON_PRESS) return FALSE;
// double-clicks may have broken axes member (free'd) due to a bug in GDK
- if (!is_core) {
- // re-get the axis values since Synaptics sends bogus ones
- gdk_device_get_state(event->device, event->window, event->axes, NULL);
+ if (!is_core)
fix_xinput_coords((GdkEvent *)event);
- }
+
+#ifdef INPUT_DEBUG
+ printf("DEBUG: ButtonDown (%s) (x,y)=(%.2f,%.2f)\n",
+ is_core?"core":"xinput", event->x, event->y);
+#endif
+ if (!finite(event->x) || !finite(event->y)) return FALSE; // Xorg 7.3 bug
if (ui.cur_item_type == ITEM_TEXT && !is_event_within_textview(event))
end_text();
+ if (ui.cur_item_type == ITEM_STROKE && ui.is_corestroke && !is_core &&
+ ui.cur_path.num_points == 1) {
+ // Xorg 7.3+ sent core event before XInput event: fix initial point
+ ui.is_corestroke = FALSE;
+ get_pointer_coords((GdkEvent *)event, ui.cur_path.coords);
+ }
if (ui.cur_item_type != ITEM_NONE) return FALSE; // we're already doing something
ui.is_corestroke = is_core;
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
on_viewShowLayer_activate(NULL, NULL);
- return;
+ return FALSE;
}
// switch mappings if needed
}
}
- // if this can be a selection move, then it takes precedence over anything else
+ // if this can be a selection move or resize, then it takes precedence over anything else
+ if (start_resizesel((GdkEvent *)event)) return FALSE;
if (start_movesel((GdkEvent *)event)) return FALSE;
if (ui.toolno[mapping] != TOOL_SELECTREGION && ui.toolno[mapping] != TOOL_SELECTRECT)
if (ui.cur_item_type == ITEM_STROKE) {
finalize_stroke();
+ if (ui.cur_brush->recognizer) recognize_patterns();
}
else if (ui.cur_item_type == ITEM_ERASURE) {
finalize_erasure();
else if (ui.cur_item_type == ITEM_MOVESEL || ui.cur_item_type == ITEM_MOVESEL_VERT) {
finalize_movesel();
}
+ else if (ui.cur_item_type == ITEM_RESIZESEL) {
+ finalize_resizesel();
+ }
else if (ui.cur_item_type == ITEM_HAND) {
ui.cur_item_type = ITEM_NONE;
}
GdkEventKey *event,
gpointer user_data)
{
+ // If zoomed-out and in single page mode, switch pages with PgUp/PgDn.
+ if (!ui.view_continuous &&
+ (0.96 * ui.zoom * ui.cur_page->height <
+ GTK_WIDGET(canvas)->allocation.height)) {
+ if (event->keyval == GDK_Page_Down) {
+ end_text();
+ reset_focus();
+ if (ui.pageno == journal.npages-1) { return FALSE; }
+ do_switch_page(ui.pageno+1, TRUE, FALSE);
+ }
+ if (event->keyval == GDK_Page_Up) {
+ end_text();
+ reset_focus();
+ if (ui.pageno == 0) { return FALSE; }
+ do_switch_page(ui.pageno-1, TRUE, FALSE);
+ }
+ }
+
return FALSE;
}
{
gboolean looks_wrong, is_core;
double pt[2];
-
- if (ui.cur_item_type == ITEM_NONE) return FALSE; // we don't care
+
+ /* we don't care about this event unless some operation is in progress;
+ 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;
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 (!finite(event->x) || !finite(event->y)) return FALSE; // Xorg 7.3 bug
+
+ if (ui.selection!=NULL && ui.cur_item_type == ITEM_NONE) {
+ get_pointer_coords((GdkEvent *)event, pt);
+ update_cursor_for_resize(pt);
+ return FALSE;
+ }
+ if (ui.use_xinput && is_core && !ui.is_corestroke) return FALSE;
+ if (!is_core) ui.is_corestroke = FALSE;
+
+#ifdef INPUT_DEBUG
+ printf("DEBUG: MotionNotify (%s) (x,y)=(%.2f,%.2f)\n",
+ is_core?"core":"xinput", event->x, event->y);
+#endif
+
looks_wrong = !(event->state & (1<<(7+ui.which_mouse_button)));
if (looks_wrong) { /* mouse button shouldn't be up... give up */
if (ui.cur_item_type == ITEM_STROKE) {
finalize_stroke();
+ if (ui.cur_brush->recognizer) recognize_patterns();
}
else if (ui.cur_item_type == ITEM_ERASURE) {
finalize_erasure();
else if (ui.cur_item_type == ITEM_MOVESEL || ui.cur_item_type == ITEM_MOVESEL_VERT) {
finalize_movesel();
}
+ else if (ui.cur_item_type == ITEM_RESIZESEL) {
+ finalize_resizesel();
+ }
switch_mapping(0);
return FALSE;
}
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_RESIZESEL) {
+ continue_resizesel((GdkEvent *)event);
+ }
else if (ui.cur_item_type == ITEM_HAND) {
do_hand((GdkEvent *)event);
}
val = gtk_spin_button_get_value_as_int(spinbutton) - 1;
if (val == journal.npages) { // create a page at end
- if (page_ops_forbidden()) return;
on_journalNewPageEnd_activate(NULL, NULL);
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;
}
}
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
reset_focus();
reset_selection();
ui.toolno[0] = TOOL_HAND;
- ui.ruler[0] = FALSE;
update_mapping_linkings(-1);
update_tool_buttons();
update_tool_menu();
ui.auto_save_prefs = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
}
+void
+on_optionsPressureSensitive_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ int i;
+ end_text();
+ reset_focus();
+ ui.pressure_sensitivity =
+ gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (menuitem));
+ for (i=0; i<=NUM_BUTTONS; i++)
+ ui.brushes[i][TOOL_PEN].variable_width = ui.pressure_sensitivity;
+ update_mappings_menu();
+}
+