X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=inline;f=libview%2Fev-annotation-window.c;h=aa7babdd477d29ff6a567a4820d8639ca6759825;hb=e769474337c9a6ffdaed2327056e8de2f7ca9ee4;hp=1991168df35ba424b1cf932c1833e2f73971a373;hpb=229170c1870cdc32fdd7dcf28136f437dc4cbab2;p=evince.git diff --git a/libview/ev-annotation-window.c b/libview/ev-annotation-window.c index 1991168d..aa7babdd 100644 --- a/libview/ev-annotation-window.c +++ b/libview/ev-annotation-window.c @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "config.h" @@ -26,6 +26,7 @@ #include "ev-annotation-window.h" #include "ev-stock-icons.h" #include "ev-view-marshal.h" +#include "ev-document-misc.h" enum { PROP_0, @@ -52,7 +53,7 @@ struct _EvAnnotationWindow { GtkWidget *resize_sw; gboolean is_open; - EvRectangle *rect; + EvRectangle rect; gboolean in_move; gint x; @@ -83,37 +84,24 @@ send_focus_change (GtkWidget *widget, { GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE); - g_object_ref (widget); - - if (in) - GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS); - else - GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS); - fevent->focus_change.type = GDK_FOCUS_CHANGE; - fevent->focus_change.window = g_object_ref (widget->window); + fevent->focus_change.window = gtk_widget_get_window (widget); fevent->focus_change.in = in; + if (fevent->focus_change.window) + g_object_ref (fevent->focus_change.window); - gtk_widget_event (widget, fevent); - - g_object_notify (G_OBJECT (widget), "has-focus"); + gtk_widget_send_focus_change (widget, fevent); - g_object_unref (widget); gdk_event_free (fevent); } static gdouble -get_screen_dpi (GtkWindow *window) +get_screen_dpi (EvAnnotationWindow *window) { GdkScreen *screen; - gdouble xdpi, ydpi; - screen = gtk_window_get_screen (window); - - xdpi = 25.4 * gdk_screen_get_width (screen) / gdk_screen_get_width_mm (screen); - ydpi = 25.4 * gdk_screen_get_height (screen) / gdk_screen_get_height_mm (screen); - - return (xdpi + ydpi) / 2.0; + screen = gtk_window_get_screen (GTK_WINDOW (window)); + return ev_document_misc_get_screen_dpi (screen); } static GtkIconSize @@ -128,7 +116,7 @@ ev_annotation_window_get_icon_size (void) } static void -ev_annotation_window_check_contents_modified (EvAnnotationWindow *window) +ev_annotation_window_sync_contents (EvAnnotationWindow *window) { gchar *contents; GtkTextIter start, end; @@ -138,23 +126,8 @@ ev_annotation_window_check_contents_modified (EvAnnotationWindow *window) buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (window->text_view)); gtk_text_buffer_get_bounds (buffer, &start, &end); contents = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); - - if (contents && annot->contents) { - if (strcasecmp (contents, annot->contents) != 0) { - g_free (annot->contents); - annot->contents = contents; - annot->changed = TRUE; - } else { - g_free (contents); - } - } else if (annot->contents) { - g_free (annot->contents); - annot->contents = NULL; - annot->changed = TRUE; - } else if (contents) { - annot->contents = contents; - annot->changed = TRUE; - } + ev_annotation_set_contents (annot, contents); + g_free (contents); } static void @@ -166,10 +139,6 @@ ev_annotation_window_set_color (EvAnnotationWindow *window, gcolor = *color; - /* Allocate these colors */ - gdk_colormap_alloc_color (gtk_widget_get_colormap (GTK_WIDGET (window)), - &gcolor, FALSE, TRUE); - /* Apply colors to style */ rc_style = gtk_widget_get_modifier_style (GTK_WIDGET (window)); rc_style->base[GTK_STATE_NORMAL] = gcolor; @@ -189,22 +158,39 @@ ev_annotation_window_set_color (EvAnnotationWindow *window, g_object_unref (rc_style); } +static void +ev_annotation_window_label_changed (EvAnnotationMarkup *annot, + GParamSpec *pspec, + EvAnnotationWindow *window) +{ + const gchar *label = ev_annotation_markup_get_label (annot); + + gtk_window_set_title (GTK_WINDOW (window), label); + gtk_label_set_text (GTK_LABEL (window->title), label); +} + +static void +ev_annotation_window_color_changed (EvAnnotation *annot, + GParamSpec *pspec, + EvAnnotationWindow *window) +{ + GdkColor color; + + ev_annotation_get_color (annot, &color); + ev_annotation_window_set_color (window, &color); +} + static void ev_annotation_window_dispose (GObject *object) { EvAnnotationWindow *window = EV_ANNOTATION_WINDOW (object); if (window->annotation) { - ev_annotation_window_check_contents_modified (window); + ev_annotation_window_sync_contents (window); g_object_unref (window->annotation); window->annotation = NULL; } - if (window->rect) { - ev_rectangle_free (window->rect); - window->rect = NULL; - } - (* G_OBJECT_CLASS (ev_annotation_window_parent_class)->dispose) (object); } @@ -250,10 +236,12 @@ static void ev_annotation_window_set_resize_cursor (GtkWidget *widget, EvAnnotationWindow *window) { - if (!widget->window) + GdkWindow *gdk_window = gtk_widget_get_window (widget); + + if (!gdk_window) return; - if (GTK_WIDGET_IS_SENSITIVE (widget)) { + if (gtk_widget_is_sensitive (widget)) { GdkDisplay *display = gtk_widget_get_display (widget); GdkCursor *cursor; @@ -261,10 +249,10 @@ ev_annotation_window_set_resize_cursor (GtkWidget *widget, widget == window->resize_sw ? GDK_BOTTOM_LEFT_CORNER : GDK_BOTTOM_RIGHT_CORNER); - gdk_window_set_cursor (widget->window, cursor); + gdk_window_set_cursor (gdk_window, cursor); gdk_cursor_unref (cursor); } else { - gdk_window_set_cursor (widget->window, NULL); + gdk_window_set_cursor (gdk_window, NULL); } } @@ -292,7 +280,7 @@ ev_annotation_window_init (EvAnnotationWindow *window) GtkWidget *icon; GtkWidget *swindow; - GTK_WIDGET_SET_FLAGS (window, GTK_CAN_FOCUS); + gtk_widget_set_can_focus (GTK_WIDGET (window), TRUE); vbox = gtk_vbox_new (FALSE, 0); @@ -329,6 +317,7 @@ ev_annotation_window_init (EvAnnotationWindow *window) GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); window->text_view = gtk_text_view_new (); + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (window->text_view), GTK_WRAP_WORD); g_signal_connect (window->text_view, "button_press_event", G_CALLBACK (text_view_button_press), window); @@ -385,7 +374,7 @@ ev_annotation_window_init (EvAnnotationWindow *window) gtk_container_set_border_width (GTK_CONTAINER (window), 2); - gtk_window_set_accept_focus (GTK_WINDOW (window), FALSE); + gtk_window_set_accept_focus (GTK_WINDOW (window), TRUE); gtk_window_set_decorated (GTK_WINDOW (window), FALSE); gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window), TRUE); gtk_window_set_skip_pager_hint (GTK_WINDOW (window), TRUE); @@ -400,8 +389,10 @@ ev_annotation_window_constructor (GType type, GObject *object; EvAnnotationWindow *window; EvAnnotation *annot; - gchar *label; - gdouble opacity; + EvAnnotationMarkup *markup; + const gchar *contents; + const gchar *label; + GdkColor color; EvRectangle *rect; gdouble scale; @@ -410,37 +401,44 @@ ev_annotation_window_constructor (GType type, construct_params); window = EV_ANNOTATION_WINDOW (object); annot = window->annotation; + markup = EV_ANNOTATION_MARKUP (annot); gtk_window_set_transient_for (GTK_WINDOW (window), window->parent); gtk_window_set_destroy_with_parent (GTK_WINDOW (window), FALSE); - g_object_get (annot, - "label", &label, - "opacity", &opacity, - "is_open", &window->is_open, - "rectangle", &window->rect, - NULL); - rect = window->rect; + label = ev_annotation_markup_get_label (markup); + window->is_open = ev_annotation_markup_get_popup_is_open (markup); + ev_annotation_markup_get_rectangle (markup, &window->rect); + + rect = &window->rect; /* Rectangle is at doc resolution (72.0) */ - scale = get_screen_dpi (GTK_WINDOW (window)) / 72.0; + scale = get_screen_dpi (window) / 72.0; gtk_window_resize (GTK_WINDOW (window), (gint)((rect->x2 - rect->x1) * scale), (gint)((rect->y2 - rect->y1) * scale)); - ev_annotation_window_set_color (window, &annot->color); - gtk_widget_set_name (GTK_WIDGET (window), annot->name); + + ev_annotation_get_color (annot, &color); + ev_annotation_window_set_color (window, &color); + gtk_widget_set_name (GTK_WIDGET (window), ev_annotation_get_name (annot)); gtk_window_set_title (GTK_WINDOW (window), label); gtk_label_set_text (GTK_LABEL (window->title), label); - gtk_window_set_opacity (GTK_WINDOW (window), opacity); - g_free (label); - if (annot->contents) { + contents = ev_annotation_get_contents (annot); + if (contents) { GtkTextBuffer *buffer; buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (window->text_view)); - gtk_text_buffer_set_text (buffer, annot->contents, -1); + gtk_text_buffer_set_text (buffer, contents, -1); } + g_signal_connect (annot, "notify::label", + G_CALLBACK (ev_annotation_window_label_changed), + window); + g_signal_connect (annot, "notify::color", + G_CALLBACK (ev_annotation_window_color_changed), + window); + return object; } @@ -452,8 +450,8 @@ ev_annotation_window_button_press_event (GtkWidget *widget, if (event->type == GDK_BUTTON_PRESS && event->button == 1) { window->in_move = TRUE; - window->x = event->x; - window->y = event->y; + window->x = event->x_root - event->x; + window->y = event->y_root - event->y; gtk_window_begin_move_drag (GTK_WINDOW (widget), event->button, event->x_root, @@ -487,8 +485,12 @@ ev_annotation_window_focus_in_event (GtkWidget *widget, EvAnnotationWindow *window = EV_ANNOTATION_WINDOW (widget); if (window->in_move) { - window->orig_x = window->x; - window->orig_y = window->y; + if (window->orig_x != window->x || window->orig_y != window->y) { + window->orig_x = window->x; + window->orig_y = window->y; + g_signal_emit (window, signals[MOVED], 0, window->x, window->y); + } + window->in_move = FALSE; } return FALSE; @@ -500,11 +502,7 @@ ev_annotation_window_focus_out_event (GtkWidget *widget, { EvAnnotationWindow *window = EV_ANNOTATION_WINDOW (widget); - if (window->in_move && - (window->orig_x != window->x || window->orig_y != window->y)) { - window->in_move = FALSE; - g_signal_emit (window, signals[MOVED], 0, window->x, window->y); - } + ev_annotation_window_sync_contents (window); return FALSE; } @@ -596,7 +594,7 @@ ev_annotation_window_set_annotation (EvAnnotationWindow *window, g_object_unref (window->annotation); window->annotation = g_object_ref (annot); - ev_annotation_window_check_contents_modified (window); + ev_annotation_window_sync_contents (window); g_object_notify (G_OBJECT (window), "annotation"); } @@ -608,22 +606,24 @@ ev_annotation_window_is_open (EvAnnotationWindow *window) return window->is_open; } -const EvRectangle * -ev_annotation_window_get_rectangle (EvAnnotationWindow *window) +void +ev_annotation_window_get_rectangle (EvAnnotationWindow *window, + EvRectangle *rect) { - g_return_val_if_fail (EV_IS_ANNOTATION_WINDOW (window), NULL); + g_return_if_fail (EV_IS_ANNOTATION_WINDOW (window)); + g_return_if_fail (rect != NULL); - return window->rect; + *rect = window->rect; } void ev_annotation_window_set_rectangle (EvAnnotationWindow *window, - EvRectangle *rect) + const EvRectangle *rect) { g_return_if_fail (EV_IS_ANNOTATION_WINDOW (window)); g_return_if_fail (rect != NULL); - *window->rect = *rect; + window->rect = *rect; } void @@ -631,7 +631,7 @@ ev_annotation_window_grab_focus (EvAnnotationWindow *window) { g_return_if_fail (EV_IS_ANNOTATION_WINDOW (window)); - if (!GTK_WIDGET_HAS_FOCUS (window->text_view)) { + if (!gtk_widget_has_focus (window->text_view)) { gtk_widget_grab_focus (GTK_WIDGET (window)); send_focus_change (window->text_view, TRUE); } @@ -642,9 +642,9 @@ ev_annotation_window_ungrab_focus (EvAnnotationWindow *window) { g_return_if_fail (EV_IS_ANNOTATION_WINDOW (window)); - if (GTK_WIDGET_HAS_FOCUS (window->text_view)) { + if (gtk_widget_has_focus (window->text_view)) { send_focus_change (window->text_view, FALSE); } - ev_annotation_window_check_contents_modified (window); + ev_annotation_window_sync_contents (window); }