#include <string.h>
#include <gtk/gtk.h>
#include <libgnomecanvas/libgnomecanvas.h>
+#include <gdk/gdkkeysyms.h>
#include "xournal.h"
#include "xo-interface.h"
g_free(redo->item);
/* the strokes are unmapped, so there are no associated canvas items */
}
+ else if (redo->type == ITEM_TEXT) {
+ g_free(redo->item->text);
+ g_free(redo->item->font_name);
+ g_free(redo->item);
+ }
else if (redo->type == ITEM_ERASURE) {
for (list = redo->erasurelist; list!=NULL; list=list->next) {
erasure = (struct UndoErasureData *)list->data;
else if (redo->type == ITEM_NEW_LAYER) {
g_free(redo->layer);
}
+ else if (redo->type == ITEM_TEXT_EDIT || redo->type == ITEM_TEXT_ATTRIB) {
+ g_free(redo->str);
+ if (redo->type == ITEM_TEXT_ATTRIB) g_free(redo->brush);
+ }
u = redo;
redo = redo->next;
if (undo->type == ITEM_ERASURE) {
for (list = undo->erasurelist; list!=NULL; list=list->next) {
erasure = (struct UndoErasureData *)list->data;
- gnome_canvas_points_free(erasure->item->path);
+ if (erasure->item->type == ITEM_STROKE)
+ gnome_canvas_points_free(erasure->item->path);
+ if (erasure->item->type == ITEM_TEXT)
+ { g_free(erasure->item->text); g_free(erasure->item->font_name); }
g_free(erasure->item);
g_list_free(erasure->replacement_items);
g_free(erasure);
undo->page->group = NULL;
delete_page(undo->page);
}
+ else if (undo->type == ITEM_TEXT_EDIT || undo->type == ITEM_TEXT_ATTRIB) {
+ g_free(undo->str);
+ if (undo->type == ITEM_TEXT_ATTRIB) g_free(undo->brush);
+ }
u = undo;
undo = undo->next;
item = (struct Item *)l->items->data;
if (item->type == ITEM_STROKE && item->path != NULL)
gnome_canvas_points_free(item->path);
+ if (item->type == ITEM_TEXT) {
+ g_free(item->font_name); g_free(item->text);
+ }
// don't need to delete the canvas_item, as it's part of the group destroyed below
g_free(item);
l->items = g_list_delete_link(l->items, l->items);
void fix_xinput_coords(GdkEvent *event)
{
+#ifdef ENABLE_XINPUT_BUGFIX
double *axes, *px, *py, axis_width;
GdkDevice *device;
int wx, wy, sx, sy;
-
+
if (event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) {
axes = event->button.axes;
px = &(event->button.x);
}
else return; // nothing we know how to do
- gdk_window_get_origin(event->any.window, &wx, &wy);
+ // use canvas window, not event window (else get GTK+ 2.11 bugs!)
+ gdk_window_get_origin(GTK_WIDGET(canvas)->window, &wx, &wy);
gnome_canvas_get_scroll_offsets(canvas, &sx, &sy);
axis_width = device->axes[0].max - device->axes[0].min;
axis_width = device->axes[1].max - device->axes[1].min;
if (axis_width>EPSILON)
*py = (axes[1]/axis_width)*ui.screen_height + sy - wy;
+#endif
}
void update_item_bbox(struct Item *item)
{
int i;
- double *p;
+ gdouble *p, h, w;
if (item->type == ITEM_STROKE) {
item->bbox.left = item->bbox.right = item->path->coords[0];
if (p[1] > item->bbox.bottom) item->bbox.bottom = p[1];
}
}
+ if (item->type == ITEM_TEXT && item->canvas_item!=NULL) {
+ h=0.; w=0.;
+ g_object_get(item->canvas_item, "text_width", &w, "text_height", &h, NULL);
+ item->bbox.right = item->bbox.left + w;
+ item->bbox.bottom = item->bbox.top + h;
+ }
}
void make_page_clipbox(struct Page *pg)
gnome_canvas_path_def_unref(pg_clip);
}
+void make_canvas_item_one(GnomeCanvasGroup *group, struct Item *item)
+{
+ GnomeCanvasItem *i;
+ PangoFontDescription *font_desc;
+
+ if (item->type == ITEM_STROKE)
+ item->canvas_item = gnome_canvas_item_new(group,
+ gnome_canvas_line_get_type(), "points", item->path,
+ "cap-style", GDK_CAP_ROUND, "join-style", GDK_JOIN_ROUND,
+ "fill-color-rgba", item->brush.color_rgba,
+ "width-units", item->brush.thickness, NULL);
+ if (item->type == ITEM_TEXT) {
+ font_desc = pango_font_description_from_string(item->font_name);
+ pango_font_description_set_absolute_size(font_desc,
+ item->font_size*ui.zoom*PANGO_SCALE);
+ item->canvas_item = gnome_canvas_item_new(group,
+ gnome_canvas_text_get_type(),
+ "x", item->bbox.left, "y", item->bbox.top, "anchor", GTK_ANCHOR_NW,
+ "font-desc", font_desc, "fill-color-rgba", item->brush.color_rgba,
+ "text", item->text, NULL);
+ update_item_bbox(item);
+ }
+}
+
void make_canvas_items(void)
{
struct Page *pg;
pg->group, gnome_canvas_group_get_type(), NULL);
for (itemlist = l->items; itemlist!=NULL; itemlist = itemlist->next) {
item = (struct Item *)itemlist->data;
- if (item->type == ITEM_STROKE && item->canvas_item == NULL) {
- item->canvas_item = gnome_canvas_item_new(l->group,
- gnome_canvas_line_get_type(), "points", item->path,
- "cap-style", GDK_CAP_ROUND, "join-style", GDK_JOIN_ROUND,
- "fill-color-rgba", item->brush.color_rgba,
- "width-units", item->brush.thickness, NULL);
- }
+ if (item->canvas_item == NULL)
+ make_canvas_item_one(l->group, item);
}
}
}
g->item_list_end = g_list_last(g->item_list);
}
+void rgb_to_gdkcolor(guint rgba, GdkColor *color)
+{
+ color->pixel = 0;
+ color->red = ((rgba>>24)&0xff)*0x101;
+ color->green = ((rgba>>16)&0xff)*0x101;
+ color->blue = ((rgba>>8)&0xff)*0x101;
+}
+
// some interface functions
void update_thickness_buttons(void)
void update_color_buttons(void)
{
if (ui.selection!=NULL || (ui.toolno[ui.cur_mapping] != TOOL_PEN
- && ui.toolno[ui.cur_mapping] != TOOL_HIGHLIGHTER)) {
+ && ui.toolno[ui.cur_mapping] != TOOL_HIGHLIGHTER && ui.toolno[ui.cur_mapping] != TOOL_TEXT)) {
gtk_toggle_tool_button_set_active(
GTK_TOGGLE_TOOL_BUTTON(GET_COMPONENT("buttonColorOther")), TRUE);
} else
void update_color_menu(void)
{
if (ui.selection!=NULL || (ui.toolno[ui.cur_mapping] != TOOL_PEN
- && ui.toolno[ui.cur_mapping] != TOOL_HIGHLIGHTER)) {
+ && ui.toolno[ui.cur_mapping] != TOOL_HIGHLIGHTER && ui.toolno[ui.cur_mapping] != TOOL_TEXT)) {
gtk_check_menu_item_set_active(
GTK_CHECK_MENU_ITEM(GET_COMPONENT("colorNA")), TRUE);
} else
void update_mappings_menu(void)
{
gtk_widget_set_sensitive(GET_COMPONENT("optionsButtonMappings"), ui.use_xinput);
- gtk_widget_set_sensitive(GET_COMPONENT("optionsDiscardCoreEvents"), ui.use_xinput);
+ gtk_widget_set_sensitive(GET_COMPONENT("optionsDiscardCoreEvents"),
+ ui.use_xinput && (gtk_check_version(2, 11, 0)!=NULL));
gtk_check_menu_item_set_active(
GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsButtonMappings")), ui.use_erasertip);
gtk_check_menu_item_set_active(
void do_switch_page(int pg, gboolean rescroll, gboolean refresh_all)
{
- int i;
+ int i, cx, cy;
struct Layer *layer;
GList *list;
if (ui.progressive_bg) rescale_bg_pixmaps();
if (rescroll) { // scroll and force a refresh
+/* -- this seems to cause some display bugs ??
gtk_adjustment_set_value(gtk_layout_get_vadjustment(GTK_LAYOUT(canvas)),
- ui.cur_page->voffset*ui.zoom);
+ ui.cur_page->voffset*ui.zoom); */
+ gnome_canvas_get_scroll_offsets(canvas, &cx, &cy);
+ cy = ui.cur_page->voffset*ui.zoom;
+ gnome_canvas_scroll_to(canvas, cx, cy);
+
if (refresh_all)
gnome_canvas_set_pixels_per_unit(canvas, ui.zoom);
else if (!ui.view_continuous)
{
gtk_widget_set_sensitive(GET_COMPONENT("editCut"), ui.selection!=NULL);
gtk_widget_set_sensitive(GET_COMPONENT("editCopy"), ui.selection!=NULL);
+ gtk_widget_set_sensitive(GET_COMPONENT("editPaste"), ui.cur_item_type!=ITEM_TEXT);
gtk_widget_set_sensitive(GET_COMPONENT("editDelete"), ui.selection!=NULL);
gtk_widget_set_sensitive(GET_COMPONENT("buttonCut"), ui.selection!=NULL);
gtk_widget_set_sensitive(GET_COMPONENT("buttonCopy"), ui.selection!=NULL);
+ gtk_widget_set_sensitive(GET_COMPONENT("buttonPaste"), ui.cur_item_type!=ITEM_TEXT);
}
void update_mapping_linkings(int toolno)
{
ui.cur_brush->color_no = color;
if (ui.toolno[0] == TOOL_HIGHLIGHTER)
- ui.cur_brush->color_rgba = predef_colors_rgba[color] & HILITER_ALPHA_MASK;
+ ui.cur_brush->color_rgba = predef_colors_rgba[color] & ui.hiliter_alpha_mask;
else
ui.cur_brush->color_rgba = predef_colors_rgba[color];
update_mapping_linkings(ui.toolno[0]);
}
+void recolor_temp_text(int color_no, guint color_rgba)
+{
+ GdkColor gdkcolor;
+
+ if (ui.cur_item_type!=ITEM_TEXT) return;
+ if (ui.cur_item->text!=NULL && ui.cur_item->brush.color_rgba != color_rgba) {
+ prepare_new_undo();
+ undo->type = ITEM_TEXT_ATTRIB;
+ undo->item = ui.cur_item;
+ undo->str = g_strdup(ui.cur_item->font_name);
+ undo->val_x = ui.cur_item->font_size;
+ undo->brush = (struct Brush *)g_memdup(&(ui.cur_item->brush), sizeof(struct Brush));
+ }
+ ui.cur_item->brush.color_no = color_no;
+ ui.cur_item->brush.color_rgba = color_rgba;
+ rgb_to_gdkcolor(color_rgba, &gdkcolor);
+ gtk_widget_modify_text(ui.cur_item->widget, GTK_STATE_NORMAL, &gdkcolor);
+ gtk_widget_grab_focus(ui.cur_item->widget);
+}
+
void process_color_activate(GtkMenuItem *menuitem, int color)
{
if (GTK_OBJECT_TYPE(menuitem) == GTK_TYPE_RADIO_MENU_ITEM) {
}
if (ui.cur_mapping != 0) return; // not user-generated
+ reset_focus();
+
+ if (ui.cur_item_type == ITEM_TEXT)
+ recolor_temp_text(color, predef_colors_rgba[color]);
if (ui.selection != NULL) {
recolor_selection(color);
update_color_menu();
}
- if (ui.toolno[0] != TOOL_PEN && ui.toolno[0] != TOOL_HIGHLIGHTER) {
+ if (ui.toolno[0] != TOOL_PEN && ui.toolno[0] != TOOL_HIGHLIGHTER
+ && ui.toolno[0] != TOOL_TEXT) {
if (ui.selection != NULL) return;
+ end_text();
ui.toolno[0] = TOOL_PEN;
ui.cur_brush = &(ui.brushes[0][TOOL_PEN]);
update_tool_buttons();
if (ui.cur_mapping != 0) return; // not user-generated
if (ui.selection != NULL && GTK_OBJECT_TYPE(menuitem) != GTK_TYPE_RADIO_MENU_ITEM) {
+ reset_focus();
rethicken_selection(val);
update_thickness_buttons();
}
return;
}
+ if (ui.brushes[0][tool].thickness_no == val) return;
+ reset_focus();
+ end_text();
ui.brushes[0][tool].thickness_no = val;
ui.brushes[0][tool].thickness = predef_thickness[tool][val];
update_mapping_linkings(tool);
return (bgpdf.status != STATUS_NOT_INIT && bgpdf.create_pages);
}
+// send the focus back to the appropriate widget
+void reset_focus(void)
+{
+ if (ui.cur_item_type == ITEM_TEXT)
+ gtk_widget_grab_focus(ui.cur_item->widget);
+ else
+ gtk_widget_grab_focus(GTK_WIDGET(canvas));
+}
+
// selection / clipboard stuff
void reset_selection(void)
update_color_menu();
update_thickness_buttons();
update_color_buttons();
+ update_font_button();
}
void move_journal_items_by(GList *itemlist, double dx, double dy,
while (itemlist!=NULL) {
item = (struct Item *)itemlist->data;
- if (item->type == ITEM_STROKE) {
+ if (item->type == ITEM_STROKE)
for (pt=item->path->coords, i=0; i<item->path->num_points; i++, pt+=2)
{ pt[0] += dx; pt[1] += dy; }
+ if (item->type == ITEM_STROKE || item->type == ITEM_TEXT || item->type == ITEM_TEMP_TEXT) {
item->bbox.left += dx;
item->bbox.right += dx;
item->bbox.top += dy;
ui.cur_mapping = m;
if (ui.toolno[m] < NUM_STROKE_TOOLS)
ui.cur_brush = &(ui.brushes[m][ui.toolno[m]]);
+ if (ui.toolno[m] == TOOL_TEXT)
+ ui.cur_brush = &(ui.brushes[m][TOOL_PEN]);
update_tool_buttons();
update_color_menu();
update_cursor();
if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))) return;
if (ui.cur_mapping!=0) return;
if (ui.toolno[m] == tool) return;
+ end_text();
+ reset_focus();
+
ui.toolno[m] = tool;
ui.ruler[m] = FALSE;
if (ui.linked_brush[m] == BRUSH_LINKED
if (!present[i]) gtk_widget_hide(GET_COMPONENT(vbox_component_names[i]));
}
+gchar *make_cur_font_name(void)
+{
+ gchar *str;
+ struct Item *it;
+
+ if (ui.cur_item_type == ITEM_TEXT)
+ str = g_strdup_printf("%s %.1f", ui.cur_item->font_name, ui.cur_item->font_size);
+ else if (ui.selection!=NULL && ui.selection->items!=NULL &&
+ ui.selection->items->next==NULL &&
+ (it=(struct Item*)ui.selection->items->data)->type == ITEM_TEXT)
+ str = g_strdup_printf("%s %.1f", it->font_name, it->font_size);
+ else
+ str = g_strdup_printf("%s %.1f", ui.font_name, ui.font_size);
+ return str;
+}
+
+void update_font_button(void)
+{
+ gchar *str;
+
+ str = make_cur_font_name();
+ gtk_font_button_set_font_name(GTK_FONT_BUTTON(GET_COMPONENT("fontButton")), str);
+ g_free(str);
+}
+
+gboolean can_accel(GtkWidget *widget, guint id, gpointer data)
+{
+ return GTK_WIDGET_SENSITIVE(widget);
+}
+
+void allow_all_accels(void)
+{
+ g_signal_connect((gpointer) GET_COMPONENT("fileNew"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("fileOpen"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("fileSave"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("filePrint"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("filePrintPDF"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("fileQuit"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("editUndo"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("editRedo"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("editCut"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("editCopy"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("editPaste"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("editDelete"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("viewFullscreen"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("viewZoomIn"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("viewZoomOut"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("viewNormalSize"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("viewPageWidth"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("viewFirstPage"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("viewPreviousPage"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("viewNextPage"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("viewLastPage"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("toolsPen"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("toolsEraser"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("toolsHighlighter"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("toolsText"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+/* g_signal_connect((gpointer) GET_COMPONENT("toolsSelectRegion"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL); */
+ g_signal_connect((gpointer) GET_COMPONENT("toolsSelectRectangle"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("toolsVerticalSpace"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("toolsHand"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("toolsTextFont"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+ g_signal_connect((gpointer) GET_COMPONENT("toolsRuler"),
+ "can-activate-accel", G_CALLBACK(can_accel), NULL);
+}
+
+void add_scroll_bindings(void)
+{
+ GtkBindingSet *binding_set;
+
+ binding_set = gtk_binding_set_by_class(
+ G_OBJECT_GET_CLASS(GET_COMPONENT("scrolledwindowMain")));
+ gtk_binding_entry_add_signal(binding_set, GDK_Up, 0,
+ "scroll_child", 2, GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_BACKWARD,
+ G_TYPE_BOOLEAN, FALSE);
+ gtk_binding_entry_add_signal(binding_set, GDK_KP_Up, 0,
+ "scroll_child", 2, GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_BACKWARD,
+ G_TYPE_BOOLEAN, FALSE);
+ gtk_binding_entry_add_signal(binding_set, GDK_Down, 0,
+ "scroll_child", 2, GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_FORWARD,
+ G_TYPE_BOOLEAN, FALSE);
+ gtk_binding_entry_add_signal(binding_set, GDK_KP_Down, 0,
+ "scroll_child", 2, GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_FORWARD,
+ G_TYPE_BOOLEAN, FALSE);
+ gtk_binding_entry_add_signal(binding_set, GDK_Left, 0,
+ "scroll_child", 2, GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_BACKWARD,
+ G_TYPE_BOOLEAN, TRUE);
+ gtk_binding_entry_add_signal(binding_set, GDK_KP_Left, 0,
+ "scroll_child", 2, GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_BACKWARD,
+ G_TYPE_BOOLEAN, TRUE);
+ gtk_binding_entry_add_signal(binding_set, GDK_Right, 0,
+ "scroll_child", 2, GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_FORWARD,
+ G_TYPE_BOOLEAN, TRUE);
+ gtk_binding_entry_add_signal(binding_set, GDK_KP_Right, 0,
+ "scroll_child", 2, GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_FORWARD,
+ G_TYPE_BOOLEAN, TRUE);
+}
+
+gboolean is_event_within_textview(GdkEventButton *event)
+{
+ double pt[2];
+
+ if (ui.cur_item_type!=ITEM_TEXT) return FALSE;
+ get_pointer_coords((GdkEvent *)event, pt);
+ if (pt[0]<ui.cur_item->bbox.left || pt[0]>ui.cur_item->bbox.right) return FALSE;
+ if (pt[1]<ui.cur_item->bbox.top || pt[1]>ui.cur_item->bbox.bottom) return FALSE;
+ return TRUE;
+}