1 // Scintilla source code edit control
2 // Wrappers.h - Encapsulation of GLib, GObject, Pango, Cairo, GTK, and GDK types
3 // Copyright 2022 by Neil Hodgson <neilh@scintilla.org>
4 // The License.txt file describes the conditions under which this software may be distributed.
9 namespace Scintilla::Internal
{
13 struct GFreeReleaser
{
15 void operator()(T
*object
) noexcept
{
20 using UniqueStr
= std::unique_ptr
<gchar
, GFreeReleaser
>;
24 struct GObjectReleaser
{
25 // Called by unique_ptr to destroy/free the object
27 void operator()(T
*object
) noexcept
{
28 g_object_unref(object
);
34 using UniquePangoContext
= std::unique_ptr
<PangoContext
, GObjectReleaser
>;
35 using UniquePangoLayout
= std::unique_ptr
<PangoLayout
, GObjectReleaser
>;
36 using UniquePangoFontMap
= std::unique_ptr
<PangoFontMap
, GObjectReleaser
>;
38 struct FontDescriptionReleaser
{
39 void operator()(PangoFontDescription
*fontDescription
) noexcept
{
40 pango_font_description_free(fontDescription
);
44 using UniquePangoFontDescription
= std::unique_ptr
<PangoFontDescription
, FontDescriptionReleaser
>;
46 struct FontMetricsReleaser
{
47 void operator()(PangoFontMetrics
*metrics
) noexcept
{
48 pango_font_metrics_unref(metrics
);
52 using UniquePangoFontMetrics
= std::unique_ptr
<PangoFontMetrics
, FontMetricsReleaser
>;
54 struct LayoutIterReleaser
{
55 // Called by unique_ptr to destroy/free the object
56 void operator()(PangoLayoutIter
*iter
) noexcept
{
57 pango_layout_iter_free(iter
);
61 using UniquePangoLayoutIter
= std::unique_ptr
<PangoLayoutIter
, LayoutIterReleaser
>;
65 struct CairoReleaser
{
66 void operator()(cairo_t
*context
) noexcept
{
67 cairo_destroy(context
);
71 using UniqueCairo
= std::unique_ptr
<cairo_t
, CairoReleaser
>;
73 struct CairoSurfaceReleaser
{
74 void operator()(cairo_surface_t
*psurf
) noexcept
{
75 cairo_surface_destroy(psurf
);
79 using UniqueCairoSurface
= std::unique_ptr
<cairo_surface_t
, CairoSurfaceReleaser
>;
83 using UniqueIMContext
= std::unique_ptr
<GtkIMContext
, GObjectReleaser
>;
87 struct GdkEventReleaser
{
88 void operator()(GdkEvent
*ev
) noexcept
{
93 using UniqueGdkEvent
= std::unique_ptr
<GdkEvent
, GdkEventReleaser
>;
95 inline void UnRefCursor(GdkCursor
*cursor
) noexcept
{
96 #if GTK_CHECK_VERSION(3,0,0)
97 g_object_unref(cursor
);
99 gdk_cursor_unref(cursor
);
103 [[nodiscard
]] inline GdkWindow
*WindowFromWidget(GtkWidget
*w
) noexcept
{
104 return gtk_widget_get_window(w
);