+
+void resize_journal_items_by(GList *itemlist, double scaling_x, double scaling_y,
+ double offset_x, double offset_y)
+{
+ struct Item *item;
+ GList *list;
+ double mean_scaling, temp;
+ double *pt, *wid;
+ GnomeCanvasGroup *group;
+ int i;
+
+ /* geometric mean of x and y scalings = rescaling for stroke widths
+ and for text font sizes */
+ mean_scaling = sqrt(fabs(scaling_x * scaling_y));
+
+ for (list = itemlist; list != NULL; list = list->next) {
+ item = (struct Item *)list->data;
+ if (item->type == ITEM_STROKE) {
+ item->brush.thickness = item->brush.thickness * mean_scaling;
+ for (i=0, pt=item->path->coords; i<item->path->num_points; i++, pt+=2) {
+ pt[0] = pt[0]*scaling_x + offset_x;
+ pt[1] = pt[1]*scaling_y + offset_y;
+ }
+ if (item->brush.variable_width)
+ for (i=0, wid=item->widths; i<item->path->num_points-1; i++, wid++)
+ *wid = *wid * mean_scaling;
+
+ item->bbox.left = item->bbox.left*scaling_x + offset_x;
+ item->bbox.right = item->bbox.right*scaling_x + offset_x;
+ item->bbox.top = item->bbox.top*scaling_y + offset_y;
+ item->bbox.bottom = item->bbox.bottom*scaling_y + offset_y;
+ if (item->bbox.left > item->bbox.right) {
+ temp = item->bbox.left;
+ item->bbox.left = item->bbox.right;
+ item->bbox.right = temp;
+ }
+ if (item->bbox.top > item->bbox.bottom) {
+ temp = item->bbox.top;
+ item->bbox.top = item->bbox.bottom;
+ item->bbox.bottom = temp;
+ }
+ }
+ if (item->type == ITEM_TEXT) {
+ /* must scale about NW corner -- all other points of the text box
+ are font- and zoom-dependent, so scaling about center of text box
+ couldn't be undone properly. FIXME? */
+ item->font_size *= mean_scaling;
+ item->bbox.left = item->bbox.left*scaling_x + offset_x;
+ item->bbox.top = item->bbox.top*scaling_y + offset_y;
+ }
+ // redraw the item
+ if (item->canvas_item!=NULL) {
+ group = (GnomeCanvasGroup *) item->canvas_item->parent;
+ gtk_object_destroy(GTK_OBJECT(item->canvas_item));
+ make_canvas_item_one(group, item);
+ }
+ }
+}
+
+// Switch between button mappings
+
+/* NOTE ABOUT BUTTON MAPPINGS: ui.cur_mapping is 0 except while a canvas
+ click event is being processed ... */
+
+void switch_mapping(int m)
+{
+ if (ui.cur_mapping == m) return;
+
+ 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();
+}
+
+void process_mapping_activate(GtkMenuItem *menuitem, int m, int tool)
+{
+ 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;
+ if (ui.linked_brush[m] == BRUSH_COPIED) {
+ ui.linked_brush[m] = BRUSH_STATIC;
+ update_mappings_menu_linkings();
+ }
+}
+
+// update the ordering of components in the main vbox
+
+const char *vbox_component_names[VBOX_MAIN_NITEMS]=
+ {"scrolledwindowMain", "menubar", "toolbarMain", "toolbarPen", "hbox1"};
+
+void update_vbox_order(int *order)
+{
+ int i, j;
+ GtkWidget *child;
+ GtkBox *vboxMain = GTK_BOX(GET_COMPONENT("vboxMain"));
+ gboolean present[VBOX_MAIN_NITEMS];
+
+ for (i=0; i<VBOX_MAIN_NITEMS; i++) present[i] = FALSE;
+ j=0;
+ for (i=0; i<VBOX_MAIN_NITEMS; i++) {
+ if (order[i]<0 || order[i]>=VBOX_MAIN_NITEMS) continue;
+ present[order[i]] = TRUE;
+ child = GET_COMPONENT(vbox_component_names[order[i]]);
+ gtk_box_reorder_child(vboxMain, child, j++);
+ gtk_widget_show(child);
+ }
+ for (i=1; i<VBOX_MAIN_NITEMS; i++) // hide others, but not the drawing area!
+ 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);
+ g_signal_connect((gpointer) GET_COMPONENT("toolsReco"),
+ "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;
+}
+
+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("toolsSelectRegion"));
+ gtk_widget_hide(GET_COMPONENT("buttonSelectRegion"));
+ gtk_widget_hide(GET_COMPONENT("button2SelectRegion"));
+ gtk_widget_hide(GET_COMPONENT("button3SelectRegion"));
+ gtk_widget_hide(GET_COMPONENT("colorOther"));
+ gtk_widget_hide(GET_COMPONENT("helpIndex"));
+
+ /* config file only works with glib 2.6 */
+ if (glib_minor_version<6) {
+ gtk_widget_hide(GET_COMPONENT("optionsAutoSavePrefs"));
+ gtk_widget_hide(GET_COMPONENT("optionsSavePreferences"));
+ }
+}