Пример #1
0
static gchar*
ev_view_accessible_get_text_after_offset (AtkText	    *text,
					  gint		    offset,
					  AtkTextBoundary   boundary_type,
					  gint		    *start_offset,
					  gint		    *end_offset)
{
	GtkWidget *widget;
	gpointer layout = NULL;
	GailTextUtil *gail_text = NULL;
	gchar *retval = NULL;
	GtkTextBuffer *buffer;

	widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
	if (widget == NULL)
		/* State is defunct */
		return NULL;

	buffer = ev_view_accessible_get_text_buffer (EV_VIEW_ACCESSIBLE (text), EV_VIEW (widget));
	if (!buffer)
		return NULL;

	gail_text = gail_text_util_new ();
	gail_text_util_buffer_setup (gail_text, buffer);
	retval = gail_text_util_get_text (gail_text, layout,
	                                  GAIL_AFTER_OFFSET, boundary_type,
	                                  offset, start_offset, end_offset);
	g_object_unref (gail_text);

	return retval;
}
Пример #2
0
EvView *
ev_page_accessible_get_view (EvPageAccessible *page_accessible)
{
	g_return_val_if_fail (EV_IS_PAGE_ACCESSIBLE (page_accessible), NULL);

	return EV_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (page_accessible->priv->view_accessible)));
}
Пример #3
0
static gchar*
ev_view_accessible_get_text (AtkText *text,
			     gint    start_pos,
			     gint    end_pos)
{
	GtkWidget *widget;
	GtkTextIter start, end;
	GtkTextBuffer *buffer;
	gchar *retval;

	widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
	if (widget == NULL)
		/* State is defunct */
		return NULL;

	buffer = ev_view_accessible_get_text_buffer (EV_VIEW_ACCESSIBLE (text), EV_VIEW (widget));
	if (!buffer)
		return NULL;

	gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
	gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
	retval = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);

	return retval;
}
Пример #4
0
/**
 * \fn void external_link_catch(GtkWidget *w, GObject *link)
 * \brief This function catch the signal when a clic is made on a note.
 * \param w The widget which triggered the call.
 * \param link ev_link_action.
 * \param editor The GUI structure.
 */
void external_link_catch(GtkWidget *widget, GObject *link, BrailleMusicEditor *editor) {
    EvLinkAction *l = EV_LINK_ACTION(link);
    ev_view_copy_link_address(EV_VIEW(widget), l);
    //get line:column link
    const gchar * lc = ev_link_action_get_uri(l);
    int line, column;
    int i = 0;
    char c = ' ', temp[2048];
    while(c != ':' || i >= strlen(lc)) {
        c = lc[i];
        temp[i] = c;
        i++;
    }
    temp[i+1]='\0';
    line = atoi(temp);
    line--;
    column = atoi(lc+i);
    GtkTextIter it;
    GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(editor->textview));
    if(gtk_text_buffer_get_line_count(buffer) < line ) {
        line = 0;
        column = 0;
    }

    gtk_text_buffer_get_iter_at_line(buffer, &it, line);
    while(column >0 && !gtk_text_iter_ends_line(&it)) {
        gtk_text_iter_forward_char(&it);
        column--;
    }
    gtk_widget_grab_focus(editor->textview);
    gtk_text_buffer_place_cursor(buffer, &it);
    gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(editor->textview), &it, 0.0, FALSE, 0.5, 0.5);
}
Пример #5
0
static gchar*
ev_view_accessible_get_selection (AtkText *text,
				  gint    selection_num,
				  gint    *start_pos,
				  gint    *end_pos)
{
	GtkWidget *widget;
	GtkTextBuffer *buffer;
	GtkTextIter start, end;
	gchar *retval = NULL;

	widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
	if (widget == NULL)
		/* State is defunct */
		return NULL;

	if (selection_num != 0)
		return NULL;

	buffer = ev_view_accessible_get_text_buffer (EV_VIEW_ACCESSIBLE (text), EV_VIEW (widget));
	if (!buffer)
		return NULL;

	gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
	*start_pos = gtk_text_iter_get_offset (&start);
	*end_pos = gtk_text_iter_get_offset (&end);

	if (*start_pos != *end_pos)
		retval = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);

	return retval;
}
Пример #6
0
static gunichar
ev_view_accessible_get_character_at_offset (AtkText *text,
					    gint    offset)
{
	GtkWidget *widget;
	GtkTextIter start, end;
	GtkTextBuffer *buffer;
	gchar *string;
	gunichar unichar;

	widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
	if (widget == NULL)
		/* State is defunct */
		return '\0';

	buffer = ev_view_accessible_get_text_buffer (EV_VIEW_ACCESSIBLE (text), EV_VIEW (widget));
	if (!buffer)
		return '\0';

	if (offset >= gtk_text_buffer_get_char_count (buffer))
		return '\0';

	gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
	end = start;
	gtk_text_iter_forward_char (&end);
	string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
	unichar = g_utf8_get_char (string);
	g_free(string);

	return unichar;
}
Пример #7
0
static gint
ev_view_accessible_get_n_selections (AtkText *text)
{
	GtkWidget *widget;
	GtkTextBuffer *buffer;
	GtkTextIter start, end;
	gint select_start, select_end;

	widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
	if (widget == NULL)
		/* State is defunct */
		return -1;

	buffer = ev_view_accessible_get_text_buffer (EV_VIEW_ACCESSIBLE (text), EV_VIEW (widget));
	if (!buffer)
		return -1;

	gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
	select_start = gtk_text_iter_get_offset (&start);
	select_end = gtk_text_iter_get_offset (&end);

	if (select_start != select_end)
		return 1;
	else
		return 0;
}
Пример #8
0
static gboolean
ev_view_accessible_idle_do_action (gpointer data)
{
	EvViewAccessiblePriv* priv = EV_VIEW_ACCESSIBLE_GET_PRIVATE (data);

	ev_view_scroll (EV_VIEW (gtk_accessible_get_widget (GTK_ACCESSIBLE (data))),
	                priv->idle_scroll,
	                FALSE);
	priv->action_idle_handler = 0;
	return FALSE;
}
Пример #9
0
static gint
ev_view_accessible_get_character_count (AtkText *text)
{
	GtkWidget *widget;
	GtkTextBuffer *buffer;
	gint retval;

	widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
	if (widget == NULL)
		/* State is defunct */
		return 0;

	buffer = ev_view_accessible_get_text_buffer (EV_VIEW_ACCESSIBLE (text), EV_VIEW (widget));
	if (!buffer)
		return 0;

	retval = gtk_text_buffer_get_char_count (buffer);

	return retval;
}
Пример #10
0
/**
 * \fn void show_score(BrailleMusicEditor *editor)
 * \brief This function create a scoreviewer in a widget.
 * \param editor The GUI structure.
 */
void show_score(BrailleMusicEditor *editor) {
    GError *err = NULL;
    GFile *file;
    gchar *filename = "score.pdf";
    file = g_file_new_for_commandline_arg (filename);
    gchar *uri = g_file_get_uri (file);
    g_object_unref (file);
    EvDocument *doc = ev_document_factory_get_document (uri, &err);
    if(err) {
        g_warning ("Trying to read the score pdf file %s gave an error: %s",
                   uri, err->message);
        if(err)
            g_error_free (err);
        err = NULL;
    } else {
        EvDocumentModel *docmodel = ev_document_model_new_with_document(EV_DOCUMENT(doc));
        ev_view_set_model(EV_VIEW(editor->score_view), EV_DOCUMENT_MODEL(docmodel));
        g_signal_connect(editor->score_view, "external-link",
                         G_CALLBACK(external_link_catch), editor);
    }
}
Пример #11
0
static gboolean
ev_view_accessible_set_caret_offset (AtkText *text, gint offset)
{
	GtkWidget *widget;
	GtkTextBuffer *buffer;
	GtkTextIter pos_itr;

	widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
	if (widget == NULL)
		/* State is defunct */
		return FALSE;

	buffer = ev_view_accessible_get_text_buffer (EV_VIEW_ACCESSIBLE (text), EV_VIEW (widget));
	if (!buffer)
		return FALSE;

	gtk_text_buffer_get_iter_at_offset (buffer, &pos_itr, offset);
	gtk_text_buffer_place_cursor (buffer, &pos_itr);

	return TRUE;
}
Пример #12
0
static gboolean
ev_view_accessible_add_selection (AtkText *text,
				  gint    start_pos,
				  gint    end_pos)
{
	GtkWidget *widget;
	GtkTextBuffer *buffer;
	GtkTextIter pos_itr;
	GtkTextIter start, end;
	gint select_start, select_end;
	gboolean retval = FALSE;

	widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
	if (widget == NULL)
		/* State is defunct */
		return FALSE;

	buffer = ev_view_accessible_get_text_buffer (EV_VIEW_ACCESSIBLE (text), EV_VIEW (widget));
	if (!buffer)
		return FALSE;

	gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
	select_start = gtk_text_iter_get_offset (&start);
	select_end = gtk_text_iter_get_offset (&end);

	/* If there is already a selection, then don't allow
	 * another to be added
	 */
	if (select_start == select_end) {
		gtk_text_buffer_get_iter_at_offset (buffer, &pos_itr, start_pos);
		gtk_text_buffer_move_mark_by_name (buffer, "selection_bound", &pos_itr);
		gtk_text_buffer_get_iter_at_offset (buffer, &pos_itr, end_pos);
		gtk_text_buffer_move_mark_by_name (buffer, "insert", &pos_itr);

		retval = TRUE;
	}

	return retval;
}
Пример #13
0
static gboolean
ev_view_accessible_remove_selection (AtkText *text,
				     gint    selection_num)
{
	GtkWidget *widget;
	GtkTextBuffer *buffer;
	GtkTextMark *cursor_mark;
	GtkTextIter cursor_itr;
	GtkTextIter start, end;
	gint select_start, select_end;
	gboolean retval = FALSE;

	widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
	if (widget == NULL)
		/* State is defunct */
		return FALSE;

	buffer = ev_view_accessible_get_text_buffer (EV_VIEW_ACCESSIBLE (text), EV_VIEW (widget));
	if (!buffer)
		return FALSE;

	gtk_text_buffer_get_selection_bounds(buffer, &start, &end);
	select_start = gtk_text_iter_get_offset(&start);
	select_end = gtk_text_iter_get_offset(&end);

	if (select_start != select_end) {
		/* Setting the start & end of the selected region
		 * to the caret position turns off the selection.
		 */
		cursor_mark = gtk_text_buffer_get_insert (buffer);
		gtk_text_buffer_get_iter_at_mark (buffer, &cursor_itr, cursor_mark);
		gtk_text_buffer_move_mark_by_name (buffer, "selection_bound", &cursor_itr);

		retval = TRUE;
	}

	return retval;
}
Пример #14
0
static AtkAttributeSet*
ev_view_accessible_get_run_attributes (AtkText *text,
				       gint    offset,
				       gint    *start_offset,
				       gint    *end_offset)
{
	GtkWidget *widget;
	GtkTextBuffer *buffer;
	AtkAttributeSet *retval;

	widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
	if (widget == NULL)
		/* State is defunct */
		return NULL;

	buffer = ev_view_accessible_get_text_buffer (EV_VIEW_ACCESSIBLE (text), EV_VIEW (widget));
	if (!buffer)
		return NULL;

	retval = gail_misc_buffer_get_run_attributes (buffer, offset,
	                                              start_offset, end_offset);

	return retval;
}
Пример #15
0
static gint
ev_view_accessible_get_caret_offset (AtkText *text)
{
	GtkWidget *widget;
	GtkTextBuffer *buffer;
	GtkTextMark *cursor_mark;
	GtkTextIter cursor_itr;
	gint retval;

	widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
	if (widget == NULL)
		/* State is defunct */
		return 0;

	buffer = ev_view_accessible_get_text_buffer (EV_VIEW_ACCESSIBLE (text), EV_VIEW (widget));
	if (!buffer)
		return 0;

	cursor_mark = gtk_text_buffer_get_insert (buffer);
	gtk_text_buffer_get_iter_at_mark (buffer, &cursor_itr, cursor_mark);
	retval = gtk_text_iter_get_offset (&cursor_itr);

	return retval;
}
Пример #16
0
static gint
ev_view_accessible_get_offset_at_point (AtkText      *text,
					gint         x,
					gint         y,
					AtkCoordType coords)
{
	GtkWidget *widget, *toplevel;
	EvRectangle *areas = NULL;
	EvRectangle *rect = NULL;
	guint n_areas = 0;
	guint i = 0;
	EvPageCache *page_cache;
	gint x_window, y_window, x_widget, y_widget;
	gint offset=-1, rx, ry;
	gdouble scale;
	GtkBorder border;
	GdkRectangle page_area;

	widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
	if (widget == NULL)
		/* State is defunct */
		return -1;

	page_cache = EV_VIEW (widget)->page_cache;
	if (!page_cache)
		return -1;

	ev_view_get_page_extents (EV_VIEW (widget), EV_VIEW (widget)->current_page,
	                          &page_area, &border);

	scale = EV_VIEW (widget)->scale;
	ev_page_cache_get_text_layout (page_cache, EV_VIEW (widget)->current_page, &areas, &n_areas);
	if (!areas)
		return -1;

	rx = x;
	ry = y;

	rx -= page_area.x;
	ry -= page_area.y;

	rx += EV_VIEW (widget)->scroll_x;
	ry += EV_VIEW (widget)->scroll_y;

	toplevel = gtk_widget_get_toplevel (widget);
	gtk_widget_translate_coordinates (widget, toplevel, 0, 0, &x_widget, &y_widget);
	rx -= x_widget;
	ry -= y_widget;

	if (coords == ATK_XY_SCREEN) {
		gdk_window_get_origin (gtk_widget_get_window (toplevel), &x_window, &y_window);
		rx -= x_window;
		ry -= y_window;
	}

	rx /= scale;
	ry /= scale;

	for (i = 0; i < n_areas; i++) {
		rect = areas + i;
		if (rx >= rect->x1 && rx <= rect->x2 &&
		    ry >= rect->y1 && ry <= rect->y2)
			offset = i;
	}

	return offset;
}
Пример #17
0
static void
ev_view_accessible_get_character_extents (AtkText      *text,
					  gint         offset,
					  gint         *x,
					  gint         *y,
					  gint         *width,
					  gint         *height,
					  AtkCoordType coords)
{
	GtkWidget *widget, *toplevel;
	EvRectangle *areas = NULL;
	EvRectangle *rect = NULL;
	guint n_areas = 0;
	EvPageCache *page_cache;
	gint x_widget, y_widget, x_window, y_window;
	gdouble scale;
	GtkBorder border;
	GdkRectangle page_area;

	widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
	if (widget == NULL)
		/* State is defunct */
		return;

	page_cache = EV_VIEW (widget)->page_cache;
	if (!page_cache)
		return;

	ev_view_get_page_extents (EV_VIEW (widget), EV_VIEW (widget)->current_page,
	                          &page_area, &border);

	scale = EV_VIEW (widget)->scale;
	ev_page_cache_get_text_layout (page_cache, EV_VIEW (widget)->current_page, &areas, &n_areas);
	if (!areas)
		return;

	if (offset >= n_areas)
		return;

	rect = areas + offset;
	*x = (int)(rect->x1 * scale);
	*y = (int)(rect->y1 * scale);

	*width = (int)(fabs (rect->x2 - rect->x1) * scale);
	*height = (int)(fabs (rect->y2 - rect->y1) * scale);

	toplevel = gtk_widget_get_toplevel (widget);
	gtk_widget_translate_coordinates (widget, toplevel, 0, 0, &x_widget, &y_widget);
	*x += x_widget;
	*y += y_widget;

	if (coords == ATK_XY_SCREEN) {
		gdk_window_get_origin (gtk_widget_get_window (toplevel), &x_window, &y_window);
		*x += x_window;
		*y += y_window;
	}

	*x -= EV_VIEW (widget)->scroll_x;
	*y -= EV_VIEW (widget)->scroll_y;

	*x += page_area.x;
	*y += page_area.y;
}