TARGET_DND_IMAGE
};
+enum {
+ PROP_0,
+ PROP_HADJUSTMENT,
+ PROP_VADJUSTMENT,
+ PROP_HSCROLL_POLICY,
+ PROP_VSCROLL_POLICY
+};
+
static guint signals[N_SIGNALS];
typedef enum {
/*** Scrolling ***/
static void view_update_range_and_current_page (EvView *view);
-static void set_scroll_adjustment (EvView *view,
- GtkOrientation orientation,
- GtkAdjustment *adjustment);
static void add_scroll_binding_keypad (GtkBindingSet *binding_set,
guint keyval,
GdkModifierType modifiers,
GtkRequisition *requisition);
static void ev_view_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
-static void ev_view_realize (GtkWidget *widget);
static gboolean ev_view_scroll_event (GtkWidget *widget,
GdkEventScroll *event);
static gboolean ev_view_draw (GtkWidget *widget,
gpointer data);
static void ev_view_update_primary_selection (EvView *ev_view);
-G_DEFINE_TYPE (EvView, ev_view, GTK_TYPE_LAYOUT)
+G_DEFINE_TYPE_WITH_CODE (EvView, ev_view, GTK_TYPE_FIXED,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
/* HeightToPage cache */
#define EV_HEIGHT_TO_PAGE_CACHE_KEY "ev-height-to-page-cache"
}
static void
-view_set_adjustment_values (EvView *view,
- GtkOrientation orientation)
+ev_view_set_adjustment_values (EvView *view,
+ GtkOrientation orientation)
{
GtkWidget *widget = GTK_WIDGET (view);
GtkAdjustment *adjustment;
}
static void
-set_scroll_adjustment (EvView *view,
- GtkOrientation orientation,
- GtkAdjustment *adjustment)
+ev_view_set_scroll_adjustment (EvView *view,
+ GtkOrientation orientation,
+ GtkAdjustment *adjustment)
{
GtkAdjustment **to_set;
+ const gchar *prop_name;
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ if (orientation == GTK_ORIENTATION_HORIZONTAL) {
to_set = &view->hadjustment;
- else
+ prop_name = "hadjustment";
+ } else {
to_set = &view->vadjustment;
+ prop_name = "vadjustment";
+ }
- if (*to_set != adjustment) {
- if (*to_set) {
- g_signal_handlers_disconnect_by_func (*to_set,
- (gpointer) on_adjustment_value_changed,
- view);
- g_object_unref (*to_set);
- }
-
- *to_set = adjustment;
- view_set_adjustment_values (view, orientation);
+ if (adjustment && adjustment == *to_set)
+ return;
- if (*to_set) {
- g_object_ref (*to_set);
- g_signal_connect (*to_set, "value_changed",
- G_CALLBACK (on_adjustment_value_changed), view);
- }
+ if (*to_set) {
+ g_signal_handlers_disconnect_by_func (*to_set,
+ (gpointer) on_adjustment_value_changed,
+ view);
+ g_object_unref (*to_set);
}
-}
-
-static void
-on_hadjustment_notify (EvView *view,
- GParamSpec *pspec,
- gpointer user_data)
-{
- set_scroll_adjustment (view, GTK_ORIENTATION_HORIZONTAL, gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (view)));
- on_adjustment_value_changed (NULL, view);
-}
+ if (!adjustment)
+ adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
+ g_signal_connect (adjustment, "value_changed",
+ G_CALLBACK (on_adjustment_value_changed),
+ view);
+ *to_set = g_object_ref_sink (adjustment);
+ ev_view_set_adjustment_values (view, orientation);
-static void
-on_vadjustment_notify (EvView *view,
- GParamSpec *pspec,
- gpointer user_data)
-{
- set_scroll_adjustment (view, GTK_ORIENTATION_VERTICAL, gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (view)));
- on_adjustment_value_changed (NULL, view);
+ g_object_notify (G_OBJECT (view), prop_name);
}
static void
form_field_mapping,
field, &view_area);
- gtk_layout_put (GTK_LAYOUT (view), field_widget, view_area.x, view_area.y);
+ gtk_fixed_put (GTK_FIXED (view), field_widget, view_area.x, view_area.y);
gtk_widget_show (field_widget);
gtk_widget_grab_focus (field_widget);
}
view->internal_size_request = FALSE;
}
- view_set_adjustment_values (view, GTK_ORIENTATION_HORIZONTAL);
- view_set_adjustment_values (view, GTK_ORIENTATION_VERTICAL);
+ ev_view_set_adjustment_values (view, GTK_ORIENTATION_HORIZONTAL);
+ ev_view_set_adjustment_values (view, GTK_ORIENTATION_VERTICAL);
if (view->document)
view_update_range_and_current_page (view);
NULL);
if (child_allocation.x != view_area.x ||
child_allocation.y != view_area.y) {
- gtk_layout_move (GTK_LAYOUT (widget), child, view_area.x, view_area.y);
+ gtk_fixed_move (GTK_FIXED (widget), child, view_area.x, view_area.y);
}
}
g_list_free (children);
}
}
-static void
-ev_view_realize (GtkWidget *widget)
-{
- EvView *view = EV_VIEW (widget);
- GdkWindow *bin_window;
- GtkStyle *style;
-
- if (GTK_WIDGET_CLASS (ev_view_parent_class)->realize)
- (* GTK_WIDGET_CLASS (ev_view_parent_class)->realize) (widget);
-
- bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
- gdk_window_set_events (bin_window,
- (gdk_window_get_events (bin_window) |
- GDK_EXPOSURE_MASK |
- GDK_BUTTON_PRESS_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_SCROLL_MASK |
- GDK_KEY_PRESS_MASK |
- GDK_POINTER_MOTION_MASK |
- GDK_POINTER_MOTION_HINT_MASK |
- GDK_ENTER_NOTIFY_MASK |
- GDK_LEAVE_NOTIFY_MASK));
-
- style = gtk_widget_get_style (widget);
- gdk_window_set_background (bin_window, &style->mid[GTK_STATE_NORMAL]);
-
- on_adjustment_value_changed (NULL, view);
-}
-
static gboolean
ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event)
{
GdkEventMotion *event)
{
EvView *view = EV_VIEW (widget);
- GdkWindow *bin_window;
+ GdkWindow *window;
gint x, y;
if (!view->document)
return FALSE;
- bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+ window = gtk_widget_get_window (widget);
- if (event->is_hint || event->window != bin_window) {
+ if (event->is_hint || event->window != window) {
gtk_widget_get_pointer (widget, &x, &y);
} else {
x = event->x;
G_OBJECT_CLASS (ev_view_parent_class)->dispose (object);
}
+static void
+ev_view_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EvView *view = EV_VIEW (object);
+
+ switch (prop_id) {
+ case PROP_HADJUSTMENT:
+ g_value_set_object (value, view->hadjustment);
+ break;
+ case PROP_VADJUSTMENT:
+ g_value_set_object (value, view->vadjustment);
+ break;
+ case PROP_HSCROLL_POLICY:
+ g_value_set_enum (value, view->hscroll_policy);
+ break;
+ case PROP_VSCROLL_POLICY:
+ g_value_set_enum (value, view->vscroll_policy);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+ev_view_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EvView *view = EV_VIEW (object);
+
+ switch (prop_id) {
+ case PROP_HADJUSTMENT:
+ ev_view_set_scroll_adjustment (view, GTK_ORIENTATION_HORIZONTAL,
+ (GtkAdjustment *) g_value_get_object (value));
+ break;
+ case PROP_VADJUSTMENT:
+ ev_view_set_scroll_adjustment (view, GTK_ORIENTATION_VERTICAL,
+ (GtkAdjustment *) g_value_get_object (value));
+ break;
+ case PROP_HSCROLL_POLICY:
+ view->hscroll_policy = g_value_get_enum (value);
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+ break;
+ case PROP_VSCROLL_POLICY:
+ view->vscroll_policy = g_value_get_enum (value);
+ gtk_widget_queue_resize (GTK_WIDGET (view));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
static AtkObject *
ev_view_get_accessible (GtkWidget *widget)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkBindingSet *binding_set;
+ object_class->get_property = ev_view_get_property;
+ object_class->set_property = ev_view_set_property;
object_class->dispose = ev_view_dispose;
object_class->finalize = ev_view_finalize;
widget_class->get_accessible = ev_view_get_accessible;
widget_class->size_request = ev_view_size_request;
widget_class->size_allocate = ev_view_size_allocate;
- widget_class->realize = ev_view_realize;
widget_class->scroll_event = ev_view_scroll_event;
widget_class->enter_notify_event = ev_view_enter_notify_event;
widget_class->leave_notify_event = ev_view_leave_notify_event;
class->binding_activated = ev_view_scroll;
+ /* Scrollable interface */
+ g_object_class_override_property (object_class, PROP_HADJUSTMENT, "hadjustment");
+ g_object_class_override_property (object_class, PROP_VADJUSTMENT, "vadjustment");
+ g_object_class_override_property (object_class, PROP_HSCROLL_POLICY, "hscroll-policy");
+ g_object_class_override_property (object_class, PROP_VSCROLL_POLICY, "vscroll-policy");
+
signals[SIGNAL_BINDING_ACTIVATED] = g_signal_new ("binding_activated",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
static void
ev_view_init (EvView *view)
{
+ gtk_widget_set_has_window (GTK_WIDGET (view), TRUE);
gtk_widget_set_can_focus (GTK_WIDGET (view), TRUE);
+ gtk_widget_set_events (GTK_WIDGET (view),
+ GDK_EXPOSURE_MASK |
+ GDK_BUTTON_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK |
+ GDK_SCROLL_MASK |
+ GDK_KEY_PRESS_MASK |
+ GDK_POINTER_MOTION_MASK |
+ GDK_POINTER_MOTION_HINT_MASK |
+ GDK_ENTER_NOTIFY_MASK |
+ GDK_LEAVE_NOTIFY_MASK);
+
view->start_page = -1;
view->end_page = -1;
view->spacing = 5;
view->pending_scroll = SCROLL_TO_KEEP_POSITION;
view->jump_to_find_result = TRUE;
view->highlight_find_results = FALSE;
-
- g_signal_connect (view, "notify::hadjustment", G_CALLBACK (on_hadjustment_notify), NULL);
- g_signal_connect (view, "notify::vadjustment", G_CALLBACK (on_vadjustment_notify), NULL);
-
- gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (view), NULL);
- gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (view), NULL);
}
/*** Callbacks ***/
EvView *view)
{
if (region) {
- GdkWindow *bin_window;
-
- bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
- gdk_window_invalidate_region (bin_window, region, TRUE);
+ gdk_window_invalidate_region (gtk_widget_get_window (GTK_WIDGET (view)), region, TRUE);
} else {
gtk_widget_queue_draw (GTK_WIDGET (view));
}
"x", &child_x,
"y", &child_y,
NULL);
- gtk_layout_move (GTK_LAYOUT (view), child, child_x + dx, child_y + dy);
+ gtk_fixed_move (GTK_FIXED (view), child, child_x + dx, child_y + dy);
}
g_list_free (children);
if (view->pending_resize) {
gtk_widget_queue_draw (GTK_WIDGET (view));
} else {
- GdkWindow *bin_window;
-
- bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
- gdk_window_scroll (bin_window, dx, dy);
+ gdk_window_scroll (gtk_widget_get_window (GTK_WIDGET (view)), dx, dy);
}
gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
/* Redraw the damaged region! */
if (region) {
- GdkWindow *bin_window;
GdkRectangle page_area;
GtkBorder border;
- bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
ev_view_get_page_extents (view, cur_page, &page_area, &border);
cairo_region_translate (region,
page_area.x + border.left - view->scroll_x,
page_area.y + border.top - view->scroll_y);
- gdk_window_invalidate_region (bin_window, region, TRUE);
+ gdk_window_invalidate_region (gtk_widget_get_window (GTK_WIDGET (view)), region, TRUE);
cairo_region_destroy (region);
}
}
{
GdkCursor *cursor = NULL;
GtkWidget *widget;
- GdkWindow *bin_window;
+ GdkWindow *window;
if (view->cursor == new_cursor) {
return;
view->cursor = new_cursor;
- bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+ window = gtk_widget_get_window (GTK_WIDGET (view));
widget = gtk_widget_get_toplevel (GTK_WIDGET (view));
cursor = ev_view_cursor_new (gtk_widget_get_display (widget), new_cursor);
- gdk_window_set_cursor (bin_window, cursor);
+ gdk_window_set_cursor (window, cursor);
gdk_flush ();
if (cursor)
gdk_cursor_unref (cursor);