Beispiel #1
0
int main(int argc, char *argv[])
{    
    gtk_init(&argc, &argv);
    
    GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL);
    
    GtkWidget *table = gtk_table_new(2, 2, FALSE);
    gtk_container_add(GTK_CONTAINER(window), table);
    
    GtkWidget *layout = gtk_layout_new(NULL, NULL);
    gtk_layout_set_size(GTK_LAYOUT(layout), 2000, 800);
    gtk_table_attach(GTK_TABLE(table), layout, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
    GtkAdjustment *vadjustment = gtk_layout_get_vadjustment(GTK_LAYOUT(layout));
    GtkAdjustment *hadjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(layout));
    
    GtkWidget *vscrollbar = gtk_vscrollbar_new(vadjustment);
    gtk_table_attach(GTK_TABLE(table), vscrollbar, 1, 2, 0, 1, GTK_SHRINK, GTK_FILL | GTK_EXPAND, 0, 0);
    
    GtkWidget *hscrollbar = gtk_hscrollbar_new(hadjustment);
    gtk_table_attach(GTK_TABLE(table), hscrollbar, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
    
    gtk_widget_show_all(window);
    
    gtk_main();
    
    return 0;
}
Beispiel #2
0
static gboolean
do_adjustment (gpointer user_data)
{
	int row;
	GtkAdjustment *adj ;
	gfloat value, min_value, max_value;
	EReflow *reflow = user_data;

	row = reflow->cursor_row;
	if (row == -1)
		return FALSE;

	adj = gtk_layout_get_hadjustment (GTK_LAYOUT (GNOME_CANVAS_ITEM (reflow)->canvas));
	value = adj->value;

	if ((!reflow->items) || (!reflow->items[row]))
		return TRUE;
	min_value = reflow->items[row]->x2 - adj->page_size;
	max_value = reflow->items[row]->x1;

	if (value < min_value)
		value = min_value;

	if (value > max_value)
		value = max_value;

	if (value != adj->value) {
		adj->value = value;
		gtk_adjustment_value_changed (adj);
	}

	reflow->do_adjustment_idle_id = 0;

	return FALSE;
}
Beispiel #3
0
GtkAdjustment *nsgtk_layout_get_hadjustment(GtkLayout *layout)
{
#if GTK_CHECK_VERSION(3,0,0)
	return gtk_scrollable_get_hadjustment(GTK_SCROLLABLE(layout));
#else
	return gtk_layout_get_hadjustment(layout);
#endif
}
Beispiel #4
0
static gboolean
scroll_layout (gpointer data)
{
  GtkWidget *layout = data;
  GtkAdjustment *adj;

  adj = gtk_layout_get_hadjustment (GTK_LAYOUT (layout));
  gtk_adjustment_set_value (adj,
			    gtk_adjustment_get_value (adj) + 5.0);
  return TRUE;
}
Beispiel #5
0
/*
 * Return the DwWidget which is at position (vx, vy) in viewport coordinates.
 */
DwWidget* a_Dw_gtk_viewport_widget_at_viewport_point (GtkDwViewport *viewport,
                                                      gint32 vx,
                                                      gint32 vy)
{
   gint32 world_x, world_y;

   if (viewport->child) {
      world_x = vx + gtk_layout_get_hadjustment(GTK_LAYOUT(viewport))->value;
      world_y = vy + gtk_layout_get_vadjustment(GTK_LAYOUT(viewport))->value;
      return Dw_gtk_viewport_widget_at_point (viewport, world_x, world_y);
   } else
      return NULL;
}
Beispiel #6
0
/* Virtual functions */
static void
e_reflow_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
	GnomeCanvasItem *item;
	EReflow *reflow;

	item = GNOME_CANVAS_ITEM (object);
	reflow = E_REFLOW (object);

	switch (prop_id){
	case PROP_HEIGHT:
		reflow->height = g_value_get_double (value);
		reflow->need_reflow_columns = TRUE;
		e_canvas_item_request_reflow(item);
		break;
	case PROP_MINIMUM_WIDTH:
		reflow->minimum_width = g_value_get_double (value);
		if (GNOME_CANVAS_ITEM_REALIZED & GTK_OBJECT_FLAGS(object))
			set_empty(reflow);
		e_canvas_item_request_reflow(item);
		break;
	case PROP_EMPTY_MESSAGE:
		g_free(reflow->empty_message);
		reflow->empty_message = g_strdup(g_value_get_string (value));
		if (GNOME_CANVAS_ITEM_REALIZED & GTK_OBJECT_FLAGS(object))
			set_empty(reflow);
		break;
	case PROP_MODEL:
		connect_model (reflow, (EReflowModel *) g_value_get_object (value));
		break;
	case PROP_COLUMN_WIDTH:
		if (reflow->column_width != g_value_get_double (value)) {
			GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
			double old_width = reflow->column_width;

			reflow->column_width = g_value_get_double (value);
			adjustment->step_increment = (reflow->column_width + E_REFLOW_FULL_GUTTER) / 2;
			adjustment->page_increment = adjustment->page_size - adjustment->step_increment;
			gtk_adjustment_changed(adjustment);
			e_reflow_resize_children(item);
			e_canvas_item_request_reflow(item);

			reflow->need_column_resize = TRUE;
			gnome_canvas_item_request_update(item);

			if (old_width != reflow->column_width)
				column_width_changed (reflow);
		}
		break;
	}
}
int
on_screen_scroll(GtkAdjustment * adjustment, gpointer user_data)
{
    GtkAdjustment *adj = NULL;
    GtkWidget *w = NULL;
    AppData *app_data = get_app_data();
    ui_hide_arrows_if_exists(app_data->app_ui_data, FALSE);
    pdf_viewer_scroller_changed((PDFScroll) GPOINTER_TO_UINT(user_data));
   if ( display_mode ==1){
   	adj = gtk_layout_get_vadjustment(GTK_LAYOUT(app_data->app_ui_data->layout));
	if ( !adj) {
	/* Ignore when no document loaded */
	     if ( app_data->state == PDF_VIEWER_STATE_EMPTY ) {
		  ui_show_banner(GTK_WIDGET(app_data->app_ui_data->app_view),
						_("pdfv_ib_menu_not_available") );
            	  return TRUE;
             }
	     adj = gtk_layout_get_hadjustment(GTK_LAYOUT(app_data->app_ui_data->layout));
         }
/* If scroll is far left/top or page fits to screen then try to move to previous page */
	 //g_print("adj->value %f",adj->value);
         if ( adj->upper <= adj->page_size || adj->value < 0.0001 ) {
              w = gtk_ui_manager_get_widget(app_data->app_ui_data->ui_manager,
					"/ToolBar/pdfv_me_menu_page_previous");
	      if ( (w != NULL) && (GTK_WIDGET_IS_SENSITIVE(w))) {	
		   pdf_viewer_navigate_page(pdf_viewer_get_current_page()-1);
                   ui_update_current_page(app_data->app_ui_data);
		   adj = gtk_layout_get_vadjustment(GTK_LAYOUT(app_data->app_ui_data->layout));	
		   gtk_adjustment_set_value(adj,adj->value + adj->upper - adj->page_size -0.0001);
	      } else {
			if ( pdf_viewer_get_current_page() == 1) {
                             ui_show_banner(GTK_WIDGET(app_data->app_ui_data->app_view),
                                           _("pdfv_ib_first_page_reached"));
                    	}
                 }
          return TRUE;
           }                   	
	 if ( adj->page_size < adj->upper &&adj->value < ( adj->upper - adj->page_size ) ) {
	      return TRUE;	       
	 } else {
		if ( pdf_viewer_get_num_pages() != pdf_viewer_get_current_page() ) {
	           pdf_viewer_navigate_page(pdf_viewer_get_current_page()+1);
                   ui_update_current_page(app_data->app_ui_data);
		   adj = gtk_layout_get_vadjustment(GTK_LAYOUT(app_data->app_ui_data->layout));	
		   gtk_adjustment_set_value(adj,adj->value + 0.0001);
		}
	   }	
         return TRUE;     
   }        
}
Beispiel #8
0
static void
incarnate (EReflow *reflow)
{
	int column_width;
	int first_column;
	int last_column;
	int first_cell;
	int last_cell;
	int i;
	GtkAdjustment *adjustment = gtk_layout_get_hadjustment (GTK_LAYOUT (GNOME_CANVAS_ITEM (reflow)->canvas));

	column_width = reflow->column_width;

	first_column = adjustment->value - 1 + E_REFLOW_BORDER_WIDTH;
	first_column /= column_width + E_REFLOW_FULL_GUTTER;

	last_column = adjustment->value + adjustment->page_size + 1 - E_REFLOW_BORDER_WIDTH - E_REFLOW_DIVIDER_WIDTH;
	last_column /= column_width + E_REFLOW_FULL_GUTTER;
	last_column ++;

	if (first_column >= 0 && first_column < reflow->column_count)
		first_cell = reflow->columns[first_column];
	else
		first_cell = 0;

	if (last_column >= 0 && last_column < reflow->column_count)
		last_cell = reflow->columns[last_column];
	else
		last_cell = reflow->count;

	for (i = first_cell; i < last_cell; i++) {
		int unsorted = e_sorter_sorted_to_model (E_SORTER (reflow->sorter), i);
		if (reflow->items[unsorted] == NULL) {
			if (reflow->model) {
				reflow->items[unsorted] = e_reflow_model_incarnate (reflow->model, unsorted, GNOME_CANVAS_GROUP (reflow));
				g_object_set (reflow->items[unsorted],
					      "selected", e_selection_model_is_row_selected(E_SELECTION_MODEL(reflow->selection), unsorted),
					      "width", (double) reflow->column_width,
					      NULL);
			}
		}
	}
	reflow->incarnate_idle_id = 0;
}
Beispiel #9
0
/*
 * Drawing and resizing is done in this idle function.
 */
static gint Dw_gtk_viewport_draw_resize_idle (gpointer data)
{
   GtkDwViewport *viewport;
   GtkLayout *layout;
   GtkWidget *widget;
   DwRectangle viewport_area, world_area;
   GdkRectangle gtk_area;
   int i;

   viewport = GTK_DW_VIEWPORT (data);

   switch (viewport->draw_resize_action) {
   case DW_GTK_VIEWPORT_DRAW:
      for (i = 0; i < viewport->num_draw_areas; i++) {
         widget = GTK_WIDGET (viewport);
         layout = GTK_LAYOUT (viewport);

         viewport_area.x = gtk_layout_get_hadjustment(layout)->value;
         viewport_area.y = gtk_layout_get_vadjustment(layout)->value;;
         viewport_area.width = widget->allocation.width;
         viewport_area.height = widget->allocation.height;

         if (p_Dw_rectangle_intersect (&viewport->draw_areas[i],
                                       &viewport_area, &world_area)) {
            gtk_area.x = world_area.x - viewport_area.x;
            gtk_area.y = world_area.y - viewport_area.y;
            gtk_area.width = world_area.width;
            gtk_area.height = world_area.height;
            gtk_widget_draw (widget, &gtk_area);
         }
      }

      /* No more areas to be drawn. */
      viewport->num_draw_areas = 0;
      break;

   case DW_GTK_VIEWPORT_RESIZE:
      Dw_gtk_viewport_calc_size (viewport);
      break;
   }

   viewport->draw_resize_idle_id = 0;
   return FALSE;
}
Beispiel #10
0
static void
e_reflow_realize (GnomeCanvasItem *item)
{
	EReflow *reflow;
	GtkAdjustment *adjustment;
	int count;
	int i;

	reflow = E_REFLOW (item);

	if (GNOME_CANVAS_ITEM_CLASS(e_reflow_parent_class)->realize)
		(* GNOME_CANVAS_ITEM_CLASS(e_reflow_parent_class)->realize) (item);

	reflow->arrow_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW);
	reflow->default_cursor = gdk_cursor_new (GDK_LEFT_PTR);

	count = reflow->count;
	for(i = 0; i < count; i++) {
		if (reflow->items[i])
			gnome_canvas_item_set(reflow->items[i],
					      "width", reflow->column_width,
					      NULL);
	}

	set_empty(reflow);

	reflow->need_reflow_columns = TRUE;
	e_canvas_item_request_reflow(item);

	adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));

#if 0
	connect_set_adjustment (reflow);
#endif
	connect_adjustment (reflow, adjustment);

	adjustment->step_increment = (reflow->column_width + E_REFLOW_FULL_GUTTER) / 2;
	adjustment->page_increment = adjustment->page_size - adjustment->step_increment;
	gtk_adjustment_changed(adjustment);

	if (!item->canvas->aa) {
	}
}
Beispiel #11
0
int
clip_GTK_LAYOUTGETHADJUSTMENT(ClipMachine * cm)
{
	C_widget  *clay = _fetch_cw_arg(cm);
	C_widget * cadj ;
	GtkAdjustment *adj;
	CHECKCWID(clay,GTK_IS_LAYOUT);

	adj = gtk_layout_get_hadjustment(GTK_LAYOUT(clay->widget));
        if (adj)
        {
        	cadj = _list_get_cwidget(cm, adj);
                if (!cadj) cadj = _register_widget(cm, GTK_WIDGET(adj), NULL);
                if (cadj) _clip_mclone(cm, RETPTR(cm), &cadj->obj);
        }

	return 0;
err:
	return 1;
}
Beispiel #12
0
/*
 * Handle the mouse event and deliver it to the Dw widget.
 * Most is done in a_Dw_widget_mouse_event.
 */
static gint Dw_gtk_viewport_mouse_event (GtkWidget *widget,
                                         gint32 x,
                                         gint32 y,
                                         GdkEvent *event)
{
   GtkDwViewport *viewport;
   DwWidget *dw_widget;
   gint32 world_x, world_y;

   if (event == NULL || event->any.window == widget->window) {
      viewport = GTK_DW_VIEWPORT (widget);
      if (viewport->child) {
         world_x = x + gtk_layout_get_hadjustment(GTK_LAYOUT(viewport))->value;
         world_y = y + gtk_layout_get_vadjustment(GTK_LAYOUT(viewport))->value;
         dw_widget =
            Dw_gtk_viewport_widget_at_point (viewport, world_x, world_y);

         return Dw_widget_mouse_event (dw_widget, widget,
                                       world_x, world_y, event);
      }
   }

   return FALSE;
}
Beispiel #13
0
static void
move_to_found (HTMLSearch *info)
{
	HTMLEngine *e = info->engine;
	HTMLEngine *ep = get_root_engine (info->engine);
	HTMLObject *first = HTML_OBJECT (info->found->data);
	HTMLObject *last = HTML_OBJECT (g_list_last (info->found)->data);
	HTMLTextSlave *slave;
	GtkAdjustment *adjustment;
	GtkLayout *layout;
	gint x, y, ex, ey, w, h;
	gint nx = e->x_offset;
	gint ny = e->y_offset;

	/* x,y is top-left corner, ex+w,ey+h is bottom-right */
	html_object_calc_abs_position (first, &x, &y);
	add_iframe_off (e, &x, &y);

	/* find slave where starts selection and get its coordinates as upper-left corner */
	while (first->next && HTML_OBJECT_TYPE (first->next) == HTML_TYPE_TEXTSLAVE) {
		first = first->next;
		slave = HTML_TEXT_SLAVE (first);
		if (slave->posStart + slave->posLen >= info->start_pos) {
			html_object_calc_abs_position (HTML_OBJECT (slave), &x, &y);
			add_iframe_off (e, &x, &y);
			break;
		}
	}

	/* the same with last */
	html_object_calc_abs_position (last, &ex, &ey);

	while (last->next && HTML_OBJECT_TYPE (last->next) == HTML_TYPE_TEXTSLAVE) {
		last = last->next;
		slave = HTML_TEXT_SLAVE (last);
		if (slave->posStart + slave->posLen >= info->start_pos) {
			html_object_calc_abs_position (HTML_OBJECT (slave), &ex, &ey);
			add_iframe_off (e, &ex, &ey);
			break;
		}
	}

	y  -= first->ascent;
	ex += last->width;
	ey += last->descent;
	w = ex - x;
	h = ey - y;

	/* now calculate gtkhtml adustments */
	if (x <= ep->x_offset)
		nx = x;
	else if (x + w > ep->x_offset + ep->width)
		nx = x + w - ep->width;

	if (y <= ep->y_offset)
		ny = y;
	else if (y + h > ep->y_offset + ep->height)
		ny = y + h - ep->height;

	/* finally adjust them if they changed */
	layout = GTK_LAYOUT (ep->widget);
	if (ep->x_offset != nx) {
		adjustment = gtk_layout_get_hadjustment (layout);
		gtk_adjustment_set_value (adjustment, nx);
	}
	if (ep->y_offset != ny) {
		adjustment = gtk_layout_get_vadjustment (layout);
		gtk_adjustment_set_value (adjustment, ny);
	}
}
Beispiel #14
0
static void
e_reflow_update (GnomeCanvasItem *item, double affine[6], ArtSVP *clip_path, gint flags)
{
	EReflow *reflow;
	double x0, x1, y0, y1;

	reflow = E_REFLOW (item);

	if (GNOME_CANVAS_ITEM_CLASS(e_reflow_parent_class)->update)
		GNOME_CANVAS_ITEM_CLASS(e_reflow_parent_class)->update (item, affine, clip_path, flags);

	x0 = item->x1;
	y0 = item->y1;
	x1 = item->x2;
	y1 = item->y2;
	if ( x1 < x0 + reflow->width )
		x1 = x0 + reflow->width;
	if ( y1 < y0 + reflow->height )
		y1 = y0 + reflow->height;
	item->x2 = x1;
	item->y2 = y1;

	if (reflow->need_height_update) {
		x0 = item->x1;
		y0 = item->y1;
		x1 = item->x2;
		y1 = item->y2;
		if ( x0 > 0 )
			x0 = 0;
		if ( y0 > 0 )
			y0 = 0;
		if ( x1 < E_REFLOW(item)->width )
			x1 = E_REFLOW(item)->width;
		if ( x1 < E_REFLOW(item)->height )
			x1 = E_REFLOW(item)->height;

		gnome_canvas_request_redraw(item->canvas, x0, y0, x1, y1);
		reflow->need_height_update = FALSE;
	} else if (reflow->need_column_resize) {
		int x_rect, y_rect, width_rect, height_rect;
		int start_line = e_reflow_pick_line(reflow,
						    gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas))->value);
		gdouble running_width;
		int i;
		double column_width;

		if ( reflow->previous_temp_column_width != -1 ) {
			running_width = start_line * (reflow->column_width + E_REFLOW_FULL_GUTTER);
			column_width = reflow->previous_temp_column_width;
			running_width -= start_line * (column_width + E_REFLOW_FULL_GUTTER);
			running_width += E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
			y_rect = E_REFLOW_BORDER_WIDTH;
			width_rect = E_REFLOW_DIVIDER_WIDTH;
			height_rect = reflow->height - (E_REFLOW_BORDER_WIDTH * 2);

			for ( i = 0; i < reflow->column_count; i++) {
				x_rect = running_width;
				gnome_canvas_request_redraw(item->canvas, x_rect, y_rect, x_rect + width_rect, y_rect + height_rect);
				running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
			}
		}

		if ( reflow->temp_column_width != -1 ) {
			running_width = start_line * (reflow->column_width + E_REFLOW_FULL_GUTTER);
			column_width = reflow->temp_column_width;
			running_width -= start_line * (column_width + E_REFLOW_FULL_GUTTER);
			running_width += E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
			y_rect = E_REFLOW_BORDER_WIDTH;
			width_rect = E_REFLOW_DIVIDER_WIDTH;
			height_rect = reflow->height - (E_REFLOW_BORDER_WIDTH * 2);

			for ( i = 0; i < reflow->column_count; i++) {
				x_rect = running_width;
				gnome_canvas_request_redraw(item->canvas, x_rect, y_rect, x_rect + width_rect, y_rect + height_rect);
				running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
			}
		}

		reflow->previous_temp_column_width = reflow->temp_column_width;
		reflow->need_column_resize = FALSE;
	}
}
Beispiel #15
0
static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
				    int x, int y, int width, int height)
{
	int x_rect, y_rect, width_rect, height_rect;
	gdouble running_width;
	EReflow *reflow = E_REFLOW(item);
	int i;
	double column_width;

	if (GNOME_CANVAS_ITEM_CLASS(e_reflow_parent_class)->draw)
		GNOME_CANVAS_ITEM_CLASS(e_reflow_parent_class)->draw (item, drawable, x, y, width, height);
	column_width = reflow->column_width;
	running_width = E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
	x_rect = running_width;
	y_rect = E_REFLOW_BORDER_WIDTH;
	width_rect = E_REFLOW_DIVIDER_WIDTH;
	height_rect = reflow->height - (E_REFLOW_BORDER_WIDTH * 2);

	/* Compute first column to draw. */
	i = x;
	i /= column_width + E_REFLOW_FULL_GUTTER;
	running_width += i * (column_width + E_REFLOW_FULL_GUTTER);

	for ( ; i < reflow->column_count; i++) {
		if ( running_width > x + width )
			break;
		x_rect = running_width;
		gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style,
				   drawable,
				   GTK_STATE_ACTIVE,
				   GTK_SHADOW_NONE,
				   NULL,
				   GTK_WIDGET(item->canvas),
				   "reflow",
				   x_rect - x,
				   y_rect - y,
				   width_rect,
				   height_rect);
		running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
	}
	if (reflow->column_drag) {
		int start_line = e_reflow_pick_line(reflow,
						    gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas))->value);
		i = x - start_line * (column_width + E_REFLOW_FULL_GUTTER);
		running_width = start_line * (column_width + E_REFLOW_FULL_GUTTER);
		column_width = reflow->temp_column_width;
		running_width -= start_line * (column_width + E_REFLOW_FULL_GUTTER);
		i += start_line * (column_width + E_REFLOW_FULL_GUTTER);
		running_width += E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
		x_rect = running_width;
		y_rect = E_REFLOW_BORDER_WIDTH;
		width_rect = E_REFLOW_DIVIDER_WIDTH;
		height_rect = reflow->height - (E_REFLOW_BORDER_WIDTH * 2);

		/* Compute first column to draw. */
		i /= column_width + E_REFLOW_FULL_GUTTER;
		running_width += i * (column_width + E_REFLOW_FULL_GUTTER);

		for ( ; i < reflow->column_count; i++) {
			if ( running_width > x + width )
				break;
			x_rect = running_width;
			gdk_draw_rectangle(drawable,
					   GTK_WIDGET(item->canvas)->style->fg_gc[GTK_STATE_NORMAL],
					   TRUE,
					   x_rect - x,
					   y_rect - y,
					   width_rect - 1,
					   height_rect - 1);
			running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH;
		}
	}
}
Beispiel #16
0
static gboolean
e_reflow_event (GnomeCanvasItem *item, GdkEvent *event)
{
	EReflow *reflow;
	int return_val = FALSE;

	reflow = E_REFLOW (item);

	switch( event->type )
		{
		case GDK_KEY_PRESS:
			return_val = e_selection_model_key_press(reflow->selection, (GdkEventKey *) event);
			break;
#if 0
			if (event->key.keyval == GDK_Tab ||
			    event->key.keyval == GDK_KP_Tab ||
			    event->key.keyval == GDK_ISO_Left_Tab) {
				int i;
				int count;
				count = reflow->count;
				for (i = 0; i < count; i++) {
					int unsorted = e_sorter_sorted_to_model (E_SORTER (reflow->sorter), i);
					GnomeCanvasItem *item = reflow->items[unsorted];
					EFocus has_focus;
					if (item) {
						g_object_get(item,
							     "has_focus", &has_focus,
							     NULL);
						if (has_focus) {
							if (event->key.state & GDK_SHIFT_MASK) {
								if (i == 0)
									return FALSE;
								i--;
							} else {
								if (i == count - 1)
									return FALSE;
								i++;
							}

							unsorted = e_sorter_sorted_to_model (E_SORTER (reflow->sorter), i);
							if (reflow->items[unsorted] == NULL) {
								reflow->items[unsorted] = e_reflow_model_incarnate (reflow->model, unsorted, GNOME_CANVAS_GROUP (reflow));
							}

							item = reflow->items[unsorted];
							gnome_canvas_item_set(item,
									      "has_focus", (event->key.state & GDK_SHIFT_MASK) ? E_FOCUS_END : E_FOCUS_START,
									      NULL);
							return TRUE;
						}
					}
				}
			}
#endif
		case GDK_BUTTON_PRESS:
			switch(event->button.button)
				{
				case 1:
					{
						GdkEventButton *button = (GdkEventButton *) event;
						double n_x, max_x;
						n_x = button->x;
						n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH;
						n_x = fmod(n_x,(reflow->column_width + E_REFLOW_FULL_GUTTER));

						max_x = E_REFLOW_BORDER_WIDTH;
						max_x += (reflow->column_width + E_REFLOW_FULL_GUTTER) * reflow->column_count;
						if ( button->y >= E_REFLOW_BORDER_WIDTH && button->y <= reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER && max_x > button->x ) {
							/* don't allow to drag the first line*/
							if (e_reflow_pick_line(reflow, button->x) == 0)
								return TRUE;
							reflow->which_column_dragged = e_reflow_pick_line(reflow, button->x);
							reflow->start_x = reflow->which_column_dragged * (reflow->column_width + E_REFLOW_FULL_GUTTER) - E_REFLOW_DIVIDER_WIDTH / 2;
							reflow->temp_column_width = reflow->column_width;
							reflow->column_drag = TRUE;

							gnome_canvas_item_grab (item,
										GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK,
										reflow->arrow_cursor,
										button->time);

							reflow->previous_temp_column_width = -1;
							reflow->need_column_resize = TRUE;
							gnome_canvas_item_request_update(item);
							return TRUE;
						}
					}
					break;
				case 4:
					{
						GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
						gdouble new_value = adjustment->value;
						new_value -= adjustment->step_increment;
						gtk_adjustment_set_value(adjustment, new_value);
					}
					break;
				case 5:
					{
						GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
						gdouble new_value = adjustment->value;
						new_value += adjustment->step_increment;
						if ( new_value > adjustment->upper - adjustment->page_size )
							new_value = adjustment->upper - adjustment->page_size;
						gtk_adjustment_set_value(adjustment, new_value);
					}
					break;
				}
			break;
		case GDK_BUTTON_RELEASE:
			if (reflow->column_drag) {
				gdouble old_width = reflow->column_width;
				GdkEventButton *button = (GdkEventButton *) event;
				GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
				reflow->temp_column_width = reflow->column_width +
					(button->x - reflow->start_x)/(reflow->which_column_dragged - e_reflow_pick_line(reflow, adjustment->value));
				if ( reflow->temp_column_width < 50 )
					reflow->temp_column_width = 50;
				reflow->column_drag = FALSE;
				if ( old_width != reflow->temp_column_width ) {
					gtk_adjustment_set_value(adjustment, adjustment->value + e_reflow_pick_line(reflow, adjustment->value) * (reflow->temp_column_width - reflow->column_width));
					reflow->column_width = reflow->temp_column_width;
					adjustment->step_increment = (reflow->column_width + E_REFLOW_FULL_GUTTER) / 2;
					adjustment->page_increment = adjustment->page_size - adjustment->step_increment;
					gtk_adjustment_changed(adjustment);
					e_reflow_resize_children(item);
					e_canvas_item_request_reflow(item);
					gnome_canvas_request_redraw(item->canvas, 0, 0, reflow->width, reflow->height);
					column_width_changed (reflow);
				}
				reflow->need_column_resize = TRUE;
				gnome_canvas_item_request_update(item);
				gnome_canvas_item_ungrab (item, button->time);
				return TRUE;
			}
			break;
		case GDK_MOTION_NOTIFY:
			if (reflow->column_drag) {
				double old_width = reflow->temp_column_width;
				GdkEventMotion *motion = (GdkEventMotion *) event;
				GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas));
				reflow->temp_column_width = reflow->column_width +
					(motion->x - reflow->start_x)/(reflow->which_column_dragged - e_reflow_pick_line(reflow, adjustment->value));
				if (reflow->temp_column_width < 50)
					reflow->temp_column_width = 50;
				if (old_width != reflow->temp_column_width) {
					reflow->need_column_resize = TRUE;
					gnome_canvas_item_request_update(item);
				}
				return TRUE;
			} else {
				GdkEventMotion *motion = (GdkEventMotion *) event;
				double n_x, max_x;

				n_x = motion->x;
				n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH;
				n_x = fmod(n_x,(reflow->column_width + E_REFLOW_FULL_GUTTER));

				max_x = E_REFLOW_BORDER_WIDTH;
				max_x += (reflow->column_width + E_REFLOW_FULL_GUTTER) * reflow->column_count;

				if ( motion->y >= E_REFLOW_BORDER_WIDTH && motion->y <= reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER && max_x > motion->x) {
					if ( reflow->default_cursor_shown ) {
						gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, reflow->arrow_cursor);
						reflow->default_cursor_shown = FALSE;
					}
				} else
					if ( ! reflow->default_cursor_shown ) {
						gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, reflow->default_cursor);
						reflow->default_cursor_shown = TRUE;
					}

			}
			break;
		case GDK_ENTER_NOTIFY:
			if (!reflow->column_drag) {
				GdkEventCrossing *crossing = (GdkEventCrossing *) event;
				double n_x, max_x;
				n_x = crossing->x;
				n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH;
				n_x = fmod(n_x,(reflow->column_width + E_REFLOW_FULL_GUTTER));

				max_x = E_REFLOW_BORDER_WIDTH;
				max_x += (reflow->column_width + E_REFLOW_FULL_GUTTER) * reflow->column_count;
				if ( crossing->y >= E_REFLOW_BORDER_WIDTH && crossing->y <= reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER && max_x > crossing->x) {
					if ( reflow->default_cursor_shown ) {
						gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, reflow->arrow_cursor);
						reflow->default_cursor_shown = FALSE;
					}
				}
			}
			break;
		case GDK_LEAVE_NOTIFY:
			if (!reflow->column_drag) {
				GdkEventCrossing *crossing = (GdkEventCrossing *) event;
				double n_x;
				n_x = crossing->x;
				n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH;
				n_x = fmod(n_x,(reflow->column_width + E_REFLOW_FULL_GUTTER));
				if ( !( crossing->y >= E_REFLOW_BORDER_WIDTH && crossing->y <= reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER ) ) {
					if ( ! reflow->default_cursor_shown ) {
						gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, reflow->default_cursor);
						reflow->default_cursor_shown = TRUE;
					}
				}
			}
			break;
		default:
			break;
		}
	if (return_val)
		return return_val;
	else if (GNOME_CANVAS_ITEM_CLASS( e_reflow_parent_class )->event)
		return (* GNOME_CANVAS_ITEM_CLASS( e_reflow_parent_class )->event) (item, event);
	else
		return FALSE;
}
gboolean
on_screen_motion(GtkWidget * widget, GdkEventMotion * event,
                 gpointer user_data)
{
    AppUIData *app_ui_data = (AppUIData *) user_data;
    GtkAdjustment *adj;
    gdouble value;
    gint x, y;
    gint dx, dy;
    g_return_val_if_fail(app_ui_data != NULL, TRUE);

    /* ignore event if button is not pressed, or page is rendering */
    /* TODO could add test to ensure that document is loaded */
    if (!PDF_FLAGS_IS_SET(app_ui_data->flags, PDF_FLAGS_BUTTON_DOWN)
        || pdf_viewer_is_rendering() ) {
        return TRUE;
    }

    if (event->is_hint)
    {
        /* hint event, retrieve pointer location */
        gdk_window_get_pointer(event->window, &x, &y, NULL);
    }
    else
    {
        /* use motion event coordinates */
        x = (gint) event->x;
        y = (gint) event->y;
    }

    /* calculate delta values */
    dx = x - app_ui_data->lastx;
    dy = y - app_ui_data->lasty;

    if (!PDF_FLAGS_IS_SET(app_ui_data->flags, PDF_FLAGS_PANNING))
    {
        /* not panning yet, check if threshold exceeded */
        if (ABS(dx) > PANNING_THRESHOLD || ABS(dy) > PANNING_THRESHOLD)
        {
            /* start panning */
            PDF_FLAGS_SET(app_ui_data->flags, PDF_FLAGS_PANNING);

            /* don't move just yet */
            app_ui_data->lastx = x;
            app_ui_data->lasty = y;
        }
    }
    else
    {
        /* panning */

        /* retrieve and set vertical adjustment, ensure that range is not
         * exceeded */
        adj = gtk_layout_get_vadjustment(GTK_LAYOUT(app_ui_data->layout));
        value = adj->value - (gdouble) dy;
        if (value < adj->lower)
            value = adj->lower;
        else if (value > (adj->upper - adj->page_size))
            value = adj->upper - adj->page_size;
        gtk_adjustment_set_value(adj, value);

        /* retrieve and set horizontal adjustment */
        adj = gtk_layout_get_hadjustment(GTK_LAYOUT(app_ui_data->layout));
        value = adj->value - (gdouble) dx;
        if (value < adj->lower)
            value = adj->lower;
        else if (value > (adj->upper - adj->page_size))
            value = adj->upper - adj->page_size;
        gtk_adjustment_set_value(adj, value);

        /* NOTE on_screen_scroll handler is invoked automatically when
         * gtk_adjustment_set_value is called */
    }

    return FALSE;
}
void
html_engine_draw_cursor_in_area (HTMLEngine *engine,
                                 gint x,
                                 gint y,
                                 gint width,
                                 gint height)
{
	HTMLObject *obj;
	guint offset;
	gint x1, y1, x2, y2, sc_x, sc_y;
	GdkRectangle pos;
	GtkAdjustment *hadj, *vadj;

	if ((engine->editable || engine->caret_mode) && (engine->cursor_hide_count <= 0 && !engine->thaw_idle_id)) {
		html_engine_draw_table_cursor (engine);
		html_engine_draw_cell_cursor (engine);
		html_engine_draw_image_cursor (engine);
	}

	if (!cursor_enabled || engine->cursor_hide_count > 0 || !(engine->editable || engine->caret_mode) || engine->thaw_idle_id)
		return;

	obj = engine->cursor->object;
	if (obj == NULL || engine->window == NULL)
		return;

	offset = engine->cursor->offset;

	if (width < 0 || height < 0) {
		width = html_engine_get_doc_width (engine);
		height = html_engine_get_doc_height (engine);
		x = 0;
		y = 0;
	}

	html_object_get_cursor (obj, engine->painter, offset, &x1, &y1, &x2, &y2);
	while (obj) {
		if (html_object_is_frame (obj)) {
			x1 -= HTML_EMBEDDED (obj)->abs_x;
			x2 -= HTML_EMBEDDED (obj)->abs_x;
			y1 -= HTML_EMBEDDED (obj)->abs_y;
			y2 -= HTML_EMBEDDED (obj)->abs_y;
			break;
		}
		obj = obj->parent;
	}

	/* get scroll offset */
	hadj = gtk_layout_get_hadjustment (GTK_LAYOUT (engine->widget));
	vadj = gtk_layout_get_vadjustment (GTK_LAYOUT (engine->widget));
	sc_x = (gint) gtk_adjustment_get_value (hadj);
	sc_y = (gint) gtk_adjustment_get_value (vadj);

	pos.x = x1 - sc_x;
	pos.y = y1 - sc_y;
	pos.width = x2 - x1;
	pos.height = y2 - y1;

	gtk_im_context_set_cursor_location (GTK_HTML (engine->widget)->priv->im_context, &pos);

	if (clip_cursor (engine, x, y, width, height, &x1, &y1, &x2, &y2)) {
		cairo_t *cr;
		gboolean using_painter_cr;

		using_painter_cr = engine->painter &&
		    HTML_IS_GDK_PAINTER (engine->painter) &&
		    HTML_GDK_PAINTER (engine->painter)->cr != NULL;

		if (using_painter_cr) {
			HTMLGdkPainter *gdk_painter = HTML_GDK_PAINTER (engine->painter);

			cr = gdk_painter->cr;
			cairo_save (cr);

			x1 -= gdk_painter->x1;
			y1 -= gdk_painter->y1;
			x2 -= gdk_painter->x1;
			y2 -= gdk_painter->y1;
		} else {
			cr = gdk_cairo_create (engine->window);
		}

		cairo_set_source_rgb (cr, 1, 1, 1);
		cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE);
		cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
		cairo_move_to (cr, x1 + 0.5, y1 + 0.5);
		cairo_line_to (cr, x2 + 0.5, y2 - 0.5);
		cairo_set_line_width (cr, 1);
		cairo_stroke (cr);

		if (using_painter_cr)
			cairo_restore (cr);
		else
			cairo_destroy (cr);
	}
}
/* Callback for keypresses */
gboolean
key_press(GtkWidget * widget, GdkEventKey * event, gpointer data)
{
    AppUIData *app_ui_data;
    GtkAdjustment *adj = NULL;
    GtkWidget *w = NULL;

    app_ui_data = (AppUIData *) data;
    app_ui_data->key_pressed = event->keyval;
    
    switch (event->keyval)
    {
        /* F6 (or SELECT when file open) = toggle full screen mode */
        case GDK_KP_Enter:
        case GDK_Return:      
			if( !PDF_FLAGS_IS_SET(app_ui_data->flags,
				PDF_FLAGS_SELECT_KEY_ALLOWED ) ||
				pdf_viewer_get_num_pages() == 0 ) {
							
				break;
			}
			PDF_FLAGS_UNSET(app_ui_data->flags, PDF_FLAGS_SELECT_KEY_ALLOWED);			
        case GDK_F6:
            ui_toggle_fullscreen(app_ui_data,
	            !PDF_FLAGS_IS_SET(app_ui_data->flags, PDF_FLAGS_FULLSCREEN));
            return TRUE;
        case GDK_F4:           // we only return for menu key
        	return FALSE;
		case GDK_Escape:
            return FALSE;
    }

    if( key_press_disabled(app_ui_data, event) ) {
        return TRUE;
    }

    switch (event->keyval)
    {

		/* scrolling UP or LEFT is almost the same, just different
         * GtkAdjustments */
        /* UP = scroll up 20% */
        case GDK_KP_Up:
        case GDK_Up:
	    ui_hide_overlay_image(app_ui_data, app_ui_data->ovr_image_orig);//prasanna
            adj = gtk_layout_get_vadjustment(GTK_LAYOUT(app_ui_data->layout));

            /* LEFT = scroll left 20% */
        case GDK_KP_Left:
        case GDK_Left:
            
	    ui_hide_overlay_image(app_ui_data, app_ui_data->ovr_image_orig);//prasanna
            if (!adj) {

				/* Ignore when no document loaded */
				if( app_ui_data->app_data->state == PDF_VIEWER_STATE_EMPTY ) {
					/*ui_show_banner(GTK_WIDGET(app_ui_data->app_view),
						_("pdfv_ib_menu_not_available") );*/
            		return TRUE;
            	}

                adj = gtk_layout_get_hadjustment(
                	GTK_LAYOUT(app_ui_data->layout));
            }

            /* If scroll is far left/top or page fits to screen then try to
               move to previous page */
            if ( adj->upper <= adj->page_size || adj->value == 0.0 ) {
            	w = gtk_ui_manager_get_widget(app_ui_data->ui_manager,
					"/ToolBar/pdfv_me_menu_page_previous");

				if ((w != NULL) && (GTK_WIDGET_IS_SENSITIVE(w))) {
					on_page_previous(NULL, data);
					adj = gtk_layout_get_vadjustment(GTK_LAYOUT          (app_ui_data->layout));	
					gtk_adjustment_set_value(adj,adj->value + adj->upper - adj->page_size -0.0001);
				} else {
					if (pdf_viewer_get_current_page() == 1) {
                            ui_show_banner(GTK_WIDGET(app_ui_data->app_view),
                                           _("pdfv_ib_first_page_reached"));
                    }
                }

                return TRUE;
            }            
            
            /* scroll the page by 20% */            
            if (adj->lower <= adj->value - 0.2 * adj->page_size)
                gtk_adjustment_set_value(adj,
                                         adj->value - 0.2 * adj->page_size);
            else
                gtk_adjustment_set_value(adj, adj->lower);

            return TRUE;

            /* scrolling DOWN or RIGHT is almost the same, just different
             * GtkAdjustments */
            /* DOWN = scroll down 20% */
        case GDK_KP_Down:
	case GDK_Down:
	    ui_hide_overlay_image(app_ui_data, app_ui_data->ovr_image_orig);//prasanna
            adj = gtk_layout_get_vadjustment(GTK_LAYOUT(app_ui_data->layout));

            /* RIGHT = scroll to the right 20% */
        case GDK_KP_Right:
        case GDK_Right:
	    ui_hide_overlay_image(app_ui_data, app_ui_data->ovr_image_orig);//prasanna
			if( !adj ) {
	            adj = gtk_layout_get_hadjustment(GTK_LAYOUT(app_ui_data->layout));

				/* Ignore when no document loaded */
				if( app_ui_data->app_data->state == PDF_VIEWER_STATE_EMPTY ) {
					/*ui_show_banner(GTK_WIDGET(app_ui_data->app_view),
						_("pdfv_ib_menu_not_available") );*/
	           		return TRUE;
	           	}
	           	
	        }
            
	        if( adj->page_size < adj->upper &&
	           	adj->value < ( adj->upper - adj->page_size ) ) {
		           
				/* scroll the page by 20% */
	    	    if (adj->value + adj->page_size * 0.2 <=
	    	    	adj->upper - adj->page_size)
						gtk_adjustment_set_value(adj,
							adj->value + adj->page_size * 0.2);
	    	    else
					gtk_adjustment_set_value(adj, adj->upper - adj->page_size);
	    	    
			/* Move more space to move, to next page */             
			} else {
	           	on_page_next(NULL, data);
			}

            return TRUE;

	case GDK_KP_Space: 
        case GDK_space: 
                ui_hide_overlay_image(app_ui_data, app_ui_data->ovr_image_orig);
                adj = gtk_layout_get_vadjustment(GTK_LAYOUT(app_ui_data->layout));

		if (event->state & GDK_SHIFT_MASK) {
	            /* scroll the page up by one screen-height, when Shift+Spacebar is pressed*/		
                    if (adj->lower <= adj->value - adj->page_size)
                        gtk_adjustment_set_value(adj, adj->value - adj->page_size);
	            else
	                 gtk_adjustment_set_value(adj, adj->lower);
                 }
		else
		 {
	            /* scroll the page down by one screen-height, when Spacebar is pressed*/		
		    if( adj->page_size < adj->upper && 
				    adj->value < ( adj->upper - adj->page_size ) ) {
                	if (adj->value + adj->page_size <= adj->upper - adj->page_size)
                            gtk_adjustment_set_value(adj, adj->value + adj->page_size);
			else
		            gtk_adjustment_set_value(adj, adj->upper - adj->page_size);
	            }
	         }
	
		return TRUE;
				      
            /* display infoprint when maximum or minimum zoom level has been
             * reached. See Bugzilla 18393 */

        /* F8 = zoom out */
        case GDK_F8:
	        w = gtk_ui_manager_get_widget(app_ui_data->ui_manager,
				"/ToolBar/pdfv_me_menu_screen_zoom_out");
			if ((w != NULL) && (GTK_WIDGET_IS_SENSITIVE(w))) {
				pdf_viewer_zoom(DOC_ZOOM_OUT);
			} else if (pdf_viewer_get_zoom_percent() <= 50) {
				ui_show_banner(GTK_WIDGET(app_ui_data->app_view),
					_("pdfv_ib_minimum_zoom"));
			}
			return TRUE;

        /* F7 = zoom in */
        case GDK_F7:
	        w = gtk_ui_manager_get_widget(app_ui_data->ui_manager,
 	           "/ToolBar/pdfv_me_menu_screen_zoom_in");
            if ((w != NULL) && (GTK_WIDGET_IS_SENSITIVE(w))) {
				pdf_viewer_zoom(DOC_ZOOM_IN);
			} else if (pdf_viewer_get_zoom_percent() >= 400) {
	            ui_show_banner(GTK_WIDGET(app_ui_data->app_view),
	                _("pdfv_ib_maximum_zoom"));
			}
			return TRUE;

            /* 
             * RETURN/SELECT = if no document present Open file dialog else
             * full screen mode 
        case GDK_KP_Enter:
        case GDK_Return:
	        if( !PDF_FLAGS_IS_SET(app_ui_data->flags,
	        	PDF_FLAGS_SELECT_KEY_ALLOWED ) ) {
	        	break;
	        }
            PDF_FLAGS_UNSET(app_ui_data->flags, PDF_FLAGS_SELECT_KEY_ALLOWED);
            
            if( (pdf_viewer_get_num_pages() != 0) ||
                !(GTK_WIDGET_IS_SENSITIVE( gtk_ui_manager_get_widget
                  (app_ui_data->ui_manager,
                  	"/MenuBar/pdfv_me_main_menu_document/"
                  	"pdfv_me_menu_document_open")))) {

                ui_toggle_fullscreen(app_ui_data,
                	!PDF_FLAGS_IS_SET( app_ui_data->flags,
						PDF_FLAGS_FULLSCREEN));
                  	
            }
            
            return TRUE;
			*/

        default:
            break;
    }

    return FALSE;
}
Beispiel #20
0
void init_stuff (int argc, char *argv[])
{
  GtkWidget *w;
  GList *dev_list;
  GdkDevice *device;
  GdkScreen *screen;
  int i, j;
  struct Brush *b;
  gboolean can_xinput, success;
  gchar *tmppath, *tmpfn;

  // 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);
  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 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);

  // 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.layerbox_length = 0;

  if (argc > 2 || (argc == 2 && argv[1][0] == '-')) {
    printf(_("Invalid command line parameters.\n"
           "Usage: %s [filename.xoj]\n"), argv[0]);
    gtk_exit(0);
  }
   
  undo = NULL; redo = NULL;
  journal.pages = NULL;
  bgpdf.status = STATUS_NOT_INIT;

  new_journal();  
  
  ui.cur_item_type = ITEM_NONE;
  ui.cur_item = NULL;
  ui.cur_path.coords = NULL;
  ui.cur_path_storage_alloc = 0;
  ui.cur_path.ref_count = 1;
  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.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];
    }
  for (i=0; i<NUM_STROKE_TOOLS; i++)
    g_memmove(ui.default_brushes+i, &(ui.brushes[0][i]), sizeof(struct Brush));

  ui.cur_mapping = 0;
  ui.which_unswitch_button = 0;
  ui.in_proximity = FALSE;
  ui.warned_generate_fontconfig = FALSE;
  
  reset_recognizer();

  // initialize various interface elements
  
  gtk_window_set_default_size(GTK_WINDOW (winMain), ui.window_default_width, ui.window_default_height);
  if (ui.maximize_at_start) gtk_window_maximize(GTK_WINDOW (winMain));
  update_toolbar_and_menu();
  update_font_button();

  gtk_check_menu_item_set_active(
    GTK_CHECK_MENU_ITEM(GET_COMPONENT("journalApplyAllPages")), ui.bg_apply_all_pages);
  gtk_check_menu_item_set_active(
    GTK_CHECK_MENU_ITEM(GET_COMPONENT("journalNewPageKeepsBG")), ui.new_page_bg_from_pdf);
  if (ui.fullscreen) {
    gtk_check_menu_item_set_active(
      GTK_CHECK_MENU_ITEM(GET_COMPONENT("viewFullscreen")), TRUE);
    gtk_toggle_tool_button_set_active(
      GTK_TOGGLE_TOOL_BUTTON(GET_COMPONENT("buttonFullscreen")), TRUE);
    gtk_window_fullscreen(GTK_WINDOW(winMain));
  }
  gtk_button_set_relief(GTK_BUTTON(GET_COMPONENT("buttonColorChooser")), GTK_RELIEF_NONE);

  allow_all_accels();
  add_scroll_bindings();

  // prevent interface items from stealing focus
  // glade doesn't properly handle can_focus, so manually set it
  gtk_combo_box_set_focus_on_click(GTK_COMBO_BOX(GET_COMPONENT("comboLayer")), FALSE);
  g_signal_connect(GET_COMPONENT("spinPageNo"), "activate",
          G_CALLBACK(handle_activate_signal), NULL);
  gtk_container_forall(GTK_CONTAINER(winMain), unset_flags, (gpointer)GTK_CAN_FOCUS);
  GTK_WIDGET_SET_FLAGS(GTK_WIDGET(canvas), GTK_CAN_FOCUS);
  GTK_WIDGET_SET_FLAGS(GTK_WIDGET(GET_COMPONENT("spinPageNo")), GTK_CAN_FOCUS);
  
  // install hooks on button/key/activation events to make the spinPageNo lose focus
  gtk_container_forall(GTK_CONTAINER(winMain), install_focus_hooks, NULL);

  // set up and initialize the canvas

  gtk_widget_show (GTK_WIDGET (canvas));
  w = GET_COMPONENT("scrolledwindowMain");
  gtk_container_add (GTK_CONTAINER (w), GTK_WIDGET (canvas));
  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (w), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_widget_set_events (GTK_WIDGET (canvas), 
     GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK | 
     GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | 
     GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
     GDK_PROXIMITY_IN_MASK | GDK_PROXIMITY_OUT_MASK);
  gnome_canvas_set_pixels_per_unit (canvas, ui.zoom);
  gnome_canvas_set_center_scroll_region (canvas, TRUE);
  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();

  g_signal_connect ((gpointer) canvas, "button_press_event",
                    G_CALLBACK (on_canvas_button_press_event),
                    NULL);
  g_signal_connect ((gpointer) canvas, "button_release_event",
                    G_CALLBACK (on_canvas_button_release_event),
                    NULL);
  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, "proximity_in_event",
                    G_CALLBACK (on_canvas_proximity_event),
                    NULL);
  g_signal_connect ((gpointer) canvas, "proximity_out_event",
                    G_CALLBACK (on_canvas_proximity_event),
                    NULL);
  g_signal_connect ((gpointer) canvas, "expose_event",
                    G_CALLBACK (on_canvas_expose_event),
                    NULL);
  g_signal_connect ((gpointer) canvas, "key_press_event",
                    G_CALLBACK (on_canvas_key_press_event),
                    NULL);
  g_signal_connect ((gpointer) canvas, "motion_notify_event",
                    G_CALLBACK (on_canvas_motion_notify_event),
                    NULL);
  g_signal_connect ((gpointer) gtk_layout_get_vadjustment(GTK_LAYOUT(canvas)),
                    "value-changed", G_CALLBACK (on_vscroll_changed),
                    NULL);
  g_signal_connect ((gpointer) gtk_layout_get_hadjustment(GTK_LAYOUT(canvas)),
                    "value-changed", G_CALLBACK (on_hscroll_changed),
                    NULL);
  g_object_set_data (G_OBJECT (winMain), "canvas", canvas);

  screen = gtk_widget_get_screen(winMain);
  ui.screen_width = gdk_screen_get_width(screen);
  ui.screen_height = gdk_screen_get_height(screen);
  
  can_xinput = FALSE;
  dev_list = gdk_devices_list();
  while (dev_list != NULL) {
    device = (GdkDevice *)dev_list->data;
    if (device != gdk_device_get_core_pointer() && device->num_axes >= 2) {
      /* get around a GDK bug: map the valuator range CORRECTLY to [0,1] */
#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;
    }
    dev_list = dev_list->next;
  }
  if (!can_xinput)
    gtk_widget_set_sensitive(GET_COMPONENT("optionsUseXInput"), FALSE);

  ui.use_xinput = ui.allow_xinput && can_xinput;

  gtk_check_menu_item_set_active(
    GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsProgressiveBG")), ui.progressive_bg);
  gtk_check_menu_item_set_active(
    GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsPrintRuling")), ui.print_ruling);
  gtk_check_menu_item_set_active(
    GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsAutoloadPdfXoj")), ui.autoload_pdf_xoj);
  gtk_check_menu_item_set_active(
    GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsAutosaveXoj")), ui.autosave_enabled);
  gtk_check_menu_item_set_active(
    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);
  gtk_check_menu_item_set_active
    (GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsLargePenCursor")), ui.large_pencursor);
  gtk_check_menu_item_set_active(
    GTK_CHECK_MENU_ITEM(GET_COMPONENT("optionsPenCursor")), ui.pen_cursor);
  
  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...)
  
  if (argc == 1) return;
  set_cursor_busy(TRUE);
  if (g_path_is_absolute(argv[1]))
    tmpfn = g_strdup(argv[1]);
  else {
    tmppath = g_get_current_dir();
    tmpfn = g_build_filename(tmppath, argv[1], NULL);
    g_free(tmppath);
  }
  success = open_journal(tmpfn);
  g_free(tmpfn);
  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_dialog_run(GTK_DIALOG(w));
    gtk_widget_destroy(w);
  }
}