calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / unx / gtk4 / surfacepaintable.cxx
blob2e8aa98b26a0b8da851c1e4c8c193022bfc81ad4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include "surfacepaintable.hxx"
12 struct _SurfacePaintable
14 GObject parent_instance;
15 int width;
16 int height;
17 cairo_surface_t* surface;
20 namespace
22 struct _SurfacePaintableClass : public GObjectClass
27 static void surface_paintable_snapshot(GdkPaintable* paintable, GdkSnapshot* snapshot, double width,
28 double height)
30 graphene_rect_t rect
31 = GRAPHENE_RECT_INIT(0.0f, 0.0f, static_cast<float>(width), static_cast<float>(height));
32 SurfacePaintable* self = SURFACE_PAINTABLE(paintable);
33 cairo_t* cr = gtk_snapshot_append_cairo(GTK_SNAPSHOT(snapshot), &rect);
34 cairo_set_source_surface(cr, self->surface, 0, 0);
35 cairo_paint(cr);
36 cairo_destroy(cr);
39 static GdkPaintableFlags surface_paintable_get_flags(GdkPaintable* /*paintable*/)
41 return static_cast<GdkPaintableFlags>(GDK_PAINTABLE_STATIC_SIZE
42 | GDK_PAINTABLE_STATIC_CONTENTS);
45 static int surface_paintable_get_intrinsic_width(GdkPaintable* paintable)
47 SurfacePaintable* self = SURFACE_PAINTABLE(paintable);
48 return self->width;
51 static int surface_paintable_get_intrinsic_height(GdkPaintable* paintable)
53 SurfacePaintable* self = SURFACE_PAINTABLE(paintable);
54 return self->height;
57 static void surface_paintable_init_interface(GdkPaintableInterface* iface)
59 iface->snapshot = surface_paintable_snapshot;
60 iface->get_flags = surface_paintable_get_flags;
61 iface->get_intrinsic_width = surface_paintable_get_intrinsic_width;
62 iface->get_intrinsic_height = surface_paintable_get_intrinsic_height;
65 G_DEFINE_TYPE_WITH_CODE(SurfacePaintable, surface_paintable, G_TYPE_OBJECT,
66 G_IMPLEMENT_INTERFACE(GDK_TYPE_PAINTABLE,
67 surface_paintable_init_interface));
69 static void surface_paintable_init(SurfacePaintable* self)
71 self->width = 0;
72 self->height = 0;
73 self->surface = nullptr;
75 // prevent loplugin:unreffun firing on macro generated function
76 (void)surface_paintable_get_instance_private(self);
79 static void surface_paintable_dispose(GObject* object)
81 SurfacePaintable* self = SURFACE_PAINTABLE(object);
82 cairo_surface_destroy(self->surface);
83 G_OBJECT_CLASS(surface_paintable_parent_class)->dispose(object);
86 static void surface_paintable_class_init(SurfacePaintableClass* klass)
88 GObjectClass* object_class = G_OBJECT_CLASS(klass);
89 object_class->dispose = surface_paintable_dispose;
92 void surface_paintable_set_source(SurfacePaintable* pPaintable, cairo_surface_t* pSource,
93 int nWidth, int nHeight)
95 pPaintable->surface = pSource;
96 pPaintable->width = nWidth;
97 pPaintable->height = nHeight;
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */