| 1 | /* |
| 2 | * Copyright © 2019 Matthias Clasen |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Lesser General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2.1 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public |
| 15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * Authors: Matthias Clasen <[email protected]> |
| 18 | */ |
| 19 | |
| 20 | #include "config.h"cxx . . $ `<file>/build/config.h`/ |
| 21 | |
| 22 | #include "gtkcustomsorter.h"cxx . . $ `<file>/gtk/gtkcustomsorter.h`/ |
| 23 | |
| 24 | #include "gtktypebuiltins.h"cxx . . $ `<file>/build/gtk/gtktypebuiltins.h`/ |
| 25 | |
| 26 | /** |
| 27 | * GtkCustomSorter: |
| 28 | * |
| 29 | * Sorts items via a callback function. |
| 30 | */ |
| 31 | struct _GtkCustomSortercxx . . $ _GtkCustomSorter# |
| 32 | { |
| 33 | GtkSortercxx . . $ GtkSorter# parent_instancecxx . . $ _GtkCustomSorter#parent_instance.; |
| 34 | |
| 35 | GCompareDataFunccxx . . $ GCompareDataFunc# sort_funccxx . . $ _GtkCustomSorter#sort_func.; |
| 36 | gpointercxx . . $ gpointer# user_datacxx . . $ _GtkCustomSorter#user_data.; |
| 37 | GDestroyNotifycxx . . $ GDestroyNotify# user_destroycxx . . $ _GtkCustomSorter#user_destroy.; |
| 38 | }; |
| 39 | |
| 40 | G_DEFINE_TYPEcxx . . $ `<external>/9567554376676449156/gtype.h:1834:9`! (GtkCustomSorter, gtk_custom_sorter, GTK_TYPE_SORTERcxx . . $ `gtk/gtksorter.h:70:9`!) |
| 41 | |
| 42 | static GtkOrderingcxx . . $ GtkOrdering# |
| 43 | gtk_custom_sorter_comparecxx . . $ gtk_custom_sorter_compare(ae33962cdb89a5a3). (GtkSortercxx . . $ GtkSorter# *sorter, |
| 44 | gpointercxx . . $ gpointer# item1, |
| 45 | gpointercxx . . $ gpointer# item2) |
| 46 | { |
| 47 | GtkCustomSortercxx . . $ GtkCustomSorter# *self = GTK_CUSTOM_SORTERcxx . . $ GTK_CUSTOM_SORTER(764f825ee570cdac). (sorter); |
| 48 | |
| 49 | if (!self->sort_funccxx . . $ _GtkCustomSorter#sort_func.) |
| 50 | return GTK_ORDERING_EQUALcxx . . $ GTK_ORDERING_EQUAL.; |
| 51 | |
| 52 | return gtk_ordering_from_cmpfunccxx . . $ gtk_ordering_from_cmpfunc(b5fe8e38d34aca1a). (self->sort_funccxx . . $ _GtkCustomSorter#sort_func. (item1, item2, self->user_datacxx . . $ _GtkCustomSorter#user_data.)); |
| 53 | } |
| 54 | |
| 55 | static GtkSorterOrdercxx . . $ GtkSorterOrder# |
| 56 | gtk_custom_sorter_get_ordercxx . . $ gtk_custom_sorter_get_order(4b53baa32927438b). (GtkSortercxx . . $ GtkSorter# *sorter) |
| 57 | { |
| 58 | GtkCustomSortercxx . . $ GtkCustomSorter# *self = GTK_CUSTOM_SORTERcxx . . $ GTK_CUSTOM_SORTER(764f825ee570cdac). (sorter); |
| 59 | |
| 60 | if (!self->sort_funccxx . . $ _GtkCustomSorter#sort_func.) |
| 61 | return GTK_SORTER_ORDER_NONEcxx . . $ GTK_SORTER_ORDER_NONE.; |
| 62 | |
| 63 | return GTK_SORTER_ORDER_PARTIALcxx . . $ GTK_SORTER_ORDER_PARTIAL.; |
| 64 | } |
| 65 | |
| 66 | static void |
| 67 | gtk_custom_sorter_disposecxx . . $ gtk_custom_sorter_dispose(6087475fa43034d3). (GObjectcxx . . $ GObject# *object) |
| 68 | { |
| 69 | GtkCustomSortercxx . . $ GtkCustomSorter# *self = GTK_CUSTOM_SORTERcxx . . $ GTK_CUSTOM_SORTER(764f825ee570cdac). (object); |
| 70 | |
| 71 | if (self->user_destroycxx . . $ _GtkCustomSorter#user_destroy.) |
| 72 | self->user_destroycxx . . $ _GtkCustomSorter#user_destroy. (self->user_datacxx . . $ _GtkCustomSorter#user_data.); |
| 73 | |
| 74 | self->sort_funccxx . . $ _GtkCustomSorter#sort_func. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 75 | self->user_destroycxx . . $ _GtkCustomSorter#user_destroy. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 76 | self->user_datacxx . . $ _GtkCustomSorter#user_data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 77 | |
| 78 | G_OBJECT_CLASScxx . . $ `<external>/1341695927569185362/gobject.h:61:9`! (gtk_custom_sorter_parent_class)->disposecxx . . $ _GObjectClass#dispose. (object); |
| 79 | } |
| 80 | |
| 81 | static void |
| 82 | gtk_custom_sorter_class_initcxx . . $ gtk_custom_sorter_class_init(d3d7bb9b2d63d8fc). (GtkCustomSorterClasscxx . . $ GtkCustomSorterClass# *class) |
| 83 | { |
| 84 | GtkSorterClasscxx . . $ GtkSorterClass# *sorter_class = GTK_SORTER_CLASScxx . . $ GTK_SORTER_CLASS(e026ce8a393ad6dd). (class); |
| 85 | GObjectClasscxx . . $ GObjectClass# *object_class = G_OBJECT_CLASScxx . . $ `<external>/1341695927569185362/gobject.h:61:9`! (class); |
| 86 | |
| 87 | sorter_class->comparecxx . . $ _GtkSorterClass#compare. = gtk_custom_sorter_comparecxx . . $ gtk_custom_sorter_compare(ae33962cdb89a5a3).; |
| 88 | sorter_class->get_ordercxx . . $ _GtkSorterClass#get_order. = gtk_custom_sorter_get_ordercxx . . $ gtk_custom_sorter_get_order(4b53baa32927438b).; |
| 89 | |
| 90 | object_class->disposecxx . . $ _GObjectClass#dispose. = gtk_custom_sorter_disposecxx . . $ gtk_custom_sorter_dispose(6087475fa43034d3).; |
| 91 | } |
| 92 | |
| 93 | static void |
| 94 | gtk_custom_sorter_initcxx . . $ gtk_custom_sorter_init(a87e2db1d22864c9). (GtkCustomSortercxx . . $ GtkCustomSorter# *self) |
| 95 | { |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * gtk_custom_sorter_new: |
| 100 | * @sort_func: (nullable): the `GCompareDataFunc` to use for sorting |
| 101 | * @user_data: (nullable): user data to pass to @sort_func |
| 102 | * @user_destroy: (nullable): destroy notify for @user_data |
| 103 | * |
| 104 | * Creates a new `GtkSorter` that works by calling |
| 105 | * @sort_func to compare items. |
| 106 | * |
| 107 | * If @sort_func is %NULL, all items are considered equal. |
| 108 | * |
| 109 | * Returns: a new `GtkCustomSorter` |
| 110 | */ |
| 111 | GtkCustomSortercxx . . $ GtkCustomSorter# * |
| 112 | gtk_custom_sorter_newcxx . . $ gtk_custom_sorter_new(23a2bd63ffcecdf9). (GCompareDataFunccxx . . $ GCompareDataFunc# sort_func, |
| 113 | gpointercxx . . $ gpointer# user_data, |
| 114 | GDestroyNotifycxx . . $ GDestroyNotify# user_destroy) |
| 115 | { |
| 116 | GtkCustomSortercxx . . $ GtkCustomSorter# *sorter; |
| 117 | |
| 118 | sorter = g_object_newcxx . . $ g_object_new(8485fe61b4be4c78). (GTK_TYPE_CUSTOM_SORTERcxx . . $ `gtk/gtkcustomsorter.h:31:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 119 | |
| 120 | gtk_custom_sorter_set_sort_funccxx . . $ gtk_custom_sorter_set_sort_func(fd2c42eb623ff2d). (sorter, sort_func, user_data, user_destroy); |
| 121 | |
| 122 | return sorter; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * gtk_custom_sorter_set_sort_func: |
| 127 | * @self: a `GtkCustomSorter` |
| 128 | * @sort_func: (nullable): function to sort items |
| 129 | * @user_data: (nullable): user data to pass to @match_func |
| 130 | * @user_destroy: destroy notify for @user_data |
| 131 | * |
| 132 | * Sets (or unsets) the function used for sorting items. |
| 133 | * |
| 134 | * If @sort_func is %NULL, all items are considered equal. |
| 135 | * |
| 136 | * If the sort func changes its sorting behavior, |
| 137 | * gtk_sorter_changed() needs to be called. |
| 138 | * |
| 139 | * If a previous function was set, its @user_destroy will be |
| 140 | * called now. |
| 141 | */ |
| 142 | void |
| 143 | gtk_custom_sorter_set_sort_funccxx . . $ gtk_custom_sorter_set_sort_func(fd2c42eb623ff2d). (GtkCustomSortercxx . . $ GtkCustomSorter# *self, |
| 144 | GCompareDataFunccxx . . $ GCompareDataFunc# sort_func, |
| 145 | gpointercxx . . $ gpointer# user_data, |
| 146 | GDestroyNotifycxx . . $ GDestroyNotify# user_destroy) |
| 147 | { |
| 148 | g_return_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:652:9`! (GTK_IS_CUSTOM_SORTER (self)); |
| 149 | g_return_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:652:9`! (sort_func || (user_data == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && !user_destroy)); |
| 150 | |
| 151 | if (self->user_destroycxx . . $ _GtkCustomSorter#user_destroy.) |
| 152 | self->user_destroycxx . . $ _GtkCustomSorter#user_destroy. (self->user_datacxx . . $ _GtkCustomSorter#user_data.); |
| 153 | |
| 154 | self->sort_funccxx . . $ _GtkCustomSorter#sort_func. = sort_func; |
| 155 | self->user_datacxx . . $ _GtkCustomSorter#user_data. = user_data; |
| 156 | self->user_destroycxx . . $ _GtkCustomSorter#user_destroy. = user_destroy; |
| 157 | |
| 158 | gtk_sorter_changedcxx . . $ gtk_sorter_changed(d5dbcecf33922a0). (GTK_SORTERcxx . . $ GTK_SORTER(cf32dcc2d2e89335). (self), GTK_SORTER_CHANGE_DIFFERENTcxx . . $ GTK_SORTER_CHANGE_DIFFERENT.); |
| 159 | } |