28 #include "ev-view-marshal.h"
83 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
85 fevent->focus_change.type = GDK_FOCUS_CHANGE;
86 fevent->focus_change.window = gtk_widget_get_window (widget);
87 fevent->focus_change.in = in;
88 if (fevent->focus_change.window)
89 g_object_ref (fevent->focus_change.window);
91 gtk_widget_send_focus_change (widget, fevent);
93 gdk_event_free (fevent);
101 screen = gtk_window_get_screen (GTK_WINDOW (window));
109 GtkTextIter start, end;
110 GtkTextBuffer *buffer;
113 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (window->text_view));
114 gtk_text_buffer_get_bounds (buffer, &start, &end);
115 contents = gtk_text_buffer_get_text (buffer, &start, &end,
FALSE);
125 GtkStyleProvider *provider;
127 properties = gtk_style_properties_new ();
128 gtk_style_properties_set (properties, 0,
129 "background-color", color,
132 provider = GTK_STYLE_PROVIDER (properties);
133 gtk_style_context_add_provider (gtk_widget_get_style_context (GTK_WIDGET (window)),
134 provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
135 gtk_style_context_add_provider (gtk_widget_get_style_context (window->close_button),
136 provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
137 gtk_style_context_add_provider (gtk_widget_get_style_context (window->resize_se),
138 provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
139 gtk_style_context_add_provider (gtk_widget_get_style_context (window->resize_sw),
140 provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
141 g_object_unref (properties);
148 gtk_widget_set_opacity (GTK_WIDGET (window), opacity);
149 gtk_widget_set_opacity (GTK_WIDGET (window->text_view), opacity);
159 gtk_window_set_title (GTK_WINDOW (window), label);
160 gtk_label_set_text (GTK_LABEL (window->title), label);
190 if (window->annotation) {
192 g_object_unref (window->annotation);
193 window->annotation = NULL;
196 (* G_OBJECT_CLASS (ev_annotation_window_parent_class)->dispose) (
object);
209 window->annotation = g_value_dup_object (value);
212 window->parent = g_value_get_object (value);
215 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
221 GdkEventButton *event,
224 if (event->type == GDK_BUTTON_PRESS && event->button == 1) {
225 gtk_window_begin_resize_drag (GTK_WINDOW (window),
226 window->resize_sw == ebox ?
227 GDK_WINDOW_EDGE_SOUTH_WEST :
228 GDK_WINDOW_EDGE_SOUTH_EAST,
229 event->button, event->x_root,
230 event->y_root, event->time);
241 GdkWindow *gdk_window = gtk_widget_get_window (widget);
246 if (gtk_widget_is_sensitive (widget)) {
247 GdkDisplay *display = gtk_widget_get_display (widget);
250 cursor = gdk_cursor_new_for_display (display,
251 widget == window->resize_sw ?
252 GDK_BOTTOM_LEFT_CORNER :
253 GDK_BOTTOM_RIGHT_CORNER);
254 gdk_window_set_cursor (gdk_window, cursor);
255 g_object_unref (cursor);
257 gdk_window_set_cursor (gdk_window, NULL);
263 GtkStateFlags previous_flags)
265 GtkStateFlags current_flags = gtk_widget_get_state_flags (widget);
267 if (current_flags & GTK_STATE_FLAG_BACKDROP)
268 gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (widget),
FALSE);
274 gtk_widget_hide (GTK_WIDGET (window));
280 GdkEventButton *event)
284 if (event->type == GDK_BUTTON_PRESS && event->button == 1) {
285 window->in_move =
TRUE;
286 window->x =
event->x_root -
event->x;
287 window->y =
event->y_root -
event->y;
288 gtk_window_begin_move_drag (GTK_WINDOW (widget),
302 GtkWidget *vbox, *hbox;
306 GtkIconTheme *icon_theme;
309 icon_theme = gtk_icon_theme_get_default ();
311 gtk_widget_set_can_focus (GTK_WIDGET (window),
TRUE);
313 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
316 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
318 icon = gtk_image_new ();
319 gtk_box_pack_start (GTK_BOX (hbox), icon,
FALSE,
FALSE, 0);
320 gtk_widget_show (icon);
322 header = gtk_event_box_new ();
323 gtk_widget_add_events (header, GDK_BUTTON_PRESS_MASK);
324 g_signal_connect_swapped (header,
"button-press-event",
328 window->title = gtk_label_new (NULL);
329 gtk_container_add (GTK_CONTAINER (header), window->title);
330 gtk_widget_show (window->title);
332 gtk_box_pack_start (GTK_BOX (hbox), header,
TRUE,
TRUE, 0);
333 gtk_widget_show (header);
335 window->close_button = gtk_button_new ();
336 gtk_button_set_relief (GTK_BUTTON (window->close_button), GTK_RELIEF_NONE);
337 gtk_container_set_border_width (GTK_CONTAINER (window->close_button), 0);
338 g_signal_connect_swapped (window->close_button,
"clicked",
342 GTK_ICON_LOOKUP_FORCE_SIZE, NULL);
343 icon = gtk_image_new_from_pixbuf (pixbuf);
344 g_object_unref (pixbuf);
345 gtk_container_add (GTK_CONTAINER (window->close_button), icon);
346 gtk_widget_show (icon);
348 gtk_box_pack_start (GTK_BOX (hbox), window->close_button,
FALSE,
FALSE, 0);
349 gtk_widget_show (window->close_button);
351 gtk_box_pack_start (GTK_BOX (vbox), hbox,
FALSE,
FALSE, 0);
352 gtk_widget_show (hbox);
355 swindow = gtk_scrolled_window_new (NULL, NULL);
356 window->text_view = gtk_text_view_new ();
357 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (window->text_view), GTK_WRAP_WORD);
358 g_signal_connect (window->text_view,
"state-flags-changed",
361 gtk_container_add (GTK_CONTAINER (swindow), window->text_view);
362 gtk_widget_show (window->text_view);
364 gtk_box_pack_start (GTK_BOX (vbox), swindow,
TRUE,
TRUE, 0);
365 gtk_widget_show (swindow);
368 gtk_window_set_has_resize_grip (GTK_WINDOW(window),
FALSE);
369 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
371 window->resize_sw = gtk_event_box_new ();
372 gtk_widget_add_events (window->resize_sw, GDK_BUTTON_PRESS_MASK);
373 g_signal_connect_swapped (window->resize_sw,
"button-press-event",
376 g_signal_connect (window->resize_sw,
"realize",
381 GTK_ICON_LOOKUP_FORCE_SIZE, NULL);
382 icon = gtk_image_new_from_pixbuf (pixbuf);
383 g_object_unref (pixbuf);
384 gtk_container_add (GTK_CONTAINER (window->resize_sw), icon);
385 gtk_widget_show (icon);
386 gtk_box_pack_start (GTK_BOX (hbox), window->resize_sw,
FALSE,
FALSE, 0);
387 gtk_widget_show (window->resize_sw);
389 window->resize_se = gtk_event_box_new ();
390 gtk_widget_add_events (window->resize_se, GDK_BUTTON_PRESS_MASK);
391 g_signal_connect_swapped (window->resize_se,
"button-press-event",
394 g_signal_connect (window->resize_se,
"realize",
399 GTK_ICON_LOOKUP_FORCE_SIZE, NULL);
400 icon = gtk_image_new_from_pixbuf (pixbuf);
401 g_object_unref (pixbuf);
402 gtk_container_add (GTK_CONTAINER (window->resize_se), icon);
403 gtk_widget_show (icon);
404 gtk_box_pack_end (GTK_BOX (hbox), window->resize_se,
FALSE,
FALSE, 0);
405 gtk_widget_show (window->resize_se);
407 gtk_box_pack_start (GTK_BOX (vbox), hbox,
FALSE,
FALSE, 0);
408 gtk_widget_show (hbox);
410 gtk_container_add (GTK_CONTAINER (window), vbox);
411 gtk_widget_show (vbox);
413 gtk_widget_add_events (GTK_WIDGET (window),
414 GDK_BUTTON_PRESS_MASK |
417 gtk_container_set_border_width (GTK_CONTAINER (window), 2);
419 gtk_window_set_decorated (GTK_WINDOW (window),
FALSE);
420 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window),
TRUE);
421 gtk_window_set_skip_pager_hint (GTK_WINDOW (window),
TRUE);
422 gtk_window_set_resizable (GTK_WINDOW (window),
TRUE);
427 guint n_construct_properties,
428 GObjectConstructParam *construct_params)
434 const gchar *contents;
441 object = G_OBJECT_CLASS (ev_annotation_window_parent_class)->constructor (type,
442 n_construct_properties,
445 annot = window->annotation;
448 gtk_window_set_transient_for (GTK_WINDOW (window), window->parent);
449 gtk_window_set_destroy_with_parent (GTK_WINDOW (window),
FALSE);
455 rect = &window->rect;
459 gtk_window_resize (GTK_WINDOW (window),
460 (gint)((rect->
x2 - rect->
x1) * scale),
461 (gint)((rect->
y2 - rect->
y1) * scale));
470 gtk_window_set_title (GTK_WINDOW (window), label);
471 gtk_label_set_text (GTK_LABEL (window->title), label);
475 GtkTextBuffer *buffer;
477 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (window->text_view));
478 gtk_text_buffer_set_text (buffer, contents, -1);
481 g_signal_connect (annot,
"notify::label",
484 g_signal_connect (annot,
"notify::rgba",
487 g_signal_connect (annot,
"notify::opacity",
496 GdkEventConfigure *event)
500 if (window->in_move &&
501 (window->x != event->x || window->y != event->y)) {
502 window->x =
event->x;
503 window->y =
event->y;
506 return GTK_WIDGET_CLASS (ev_annotation_window_parent_class)->configure_event (widget, event);
511 GdkEventFocus *event)
515 if (window->in_move) {
516 if (window->orig_x != window->x || window->orig_y != window->y) {
517 window->orig_x = window->x;
518 window->orig_y = window->y;
519 g_signal_emit (window,
signals[
MOVED], 0, window->x, window->y);
521 window->in_move =
FALSE;
524 gtk_widget_grab_focus (window->text_view);
526 gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (window->text_view),
TRUE);
533 GdkEventFocus *event)
546 if (event->keyval == GDK_KEY_Escape) {
551 return GTK_WIDGET_CLASS (ev_annotation_window_parent_class)->key_press_event (widget, event);
557 GObjectClass *g_object_class = G_OBJECT_CLASS (klass);
558 GtkWidgetClass *gtk_widget_class = GTK_WIDGET_CLASS (klass);
569 g_object_class_install_property (g_object_class,
571 g_param_spec_object (
"annotation",
573 "The annotation associated to the window",
576 G_PARAM_CONSTRUCT_ONLY |
577 G_PARAM_STATIC_STRINGS));
578 g_object_class_install_property (g_object_class,
580 g_param_spec_object (
"parent",
585 G_PARAM_CONSTRUCT_ONLY |
586 G_PARAM_STATIC_STRINGS));
588 g_signal_new (
"closed",
589 G_TYPE_FROM_CLASS (g_object_class),
590 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
593 g_cclosure_marshal_VOID__VOID,
594 G_TYPE_NONE, 0, G_TYPE_NONE);
596 g_signal_new (
"moved",
597 G_TYPE_FROM_CLASS (g_object_class),
598 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
601 ev_view_marshal_VOID__INT_INT,
603 G_TYPE_INT, G_TYPE_INT);
614 g_return_val_if_fail (GTK_IS_WINDOW (parent), NULL);
628 return window->annotation;
638 if (annot == window->annotation)
641 g_object_unref (window->annotation);
642 window->annotation = g_object_ref (annot);
644 g_object_notify (G_OBJECT (window),
"annotation");
652 return window->is_open;
660 g_return_if_fail (rect != NULL);
662 *rect = window->rect;
670 g_return_if_fail (rect != NULL);
672 window->rect = *rect;
680 if (!gtk_widget_has_focus (window->text_view)) {
681 gtk_widget_grab_focus (GTK_WIDGET (window));
691 if (gtk_widget_has_focus (window->text_view)) {