1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9#[cfg(all(
11 feature = "NSControl",
12 feature = "NSResponder",
13 feature = "NSTableColumn",
14 feature = "NSTableView",
15 feature = "NSView",
16 feature = "block2"
17))]
18pub type NSTableViewDiffableDataSourceCellProvider = *mut block2::DynBlock<
19 dyn Fn(
20 NonNull<NSTableView>,
21 NonNull<NSTableColumn>,
22 NSInteger,
23 NonNull<AnyObject>,
24 ) -> NonNull<NSView>,
25>;
26
27#[cfg(all(
29 feature = "NSControl",
30 feature = "NSResponder",
31 feature = "NSTableRowView",
32 feature = "NSTableView",
33 feature = "NSView",
34 feature = "block2"
35))]
36pub type NSTableViewDiffableDataSourceRowProvider = *mut block2::DynBlock<
37 dyn Fn(NonNull<NSTableView>, NSInteger, NonNull<AnyObject>) -> NonNull<NSTableRowView>,
38>;
39
40#[cfg(all(
42 feature = "NSControl",
43 feature = "NSResponder",
44 feature = "NSTableView",
45 feature = "NSView",
46 feature = "block2"
47))]
48pub type NSTableViewDiffableDataSourceSectionHeaderViewProvider = *mut block2::DynBlock<
49 dyn Fn(NonNull<NSTableView>, NSInteger, NonNull<AnyObject>) -> NonNull<NSView>,
50>;
51
52extern_class!(
53 #[unsafe(super(NSObject))]
55 #[derive(Debug, PartialEq, Eq, Hash)]
56 pub struct NSTableViewDiffableDataSource<
57 SectionIdentifierType: ?Sized = AnyObject,
58 ItemIdentifierType: ?Sized = AnyObject,
59 >;
60);
61
62impl<SectionIdentifierType: ?Sized + Message, ItemIdentifierType: ?Sized + Message>
63 NSTableViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType>
64{
65 #[inline]
71 pub unsafe fn cast_unchecked<
72 NewSectionIdentifierType: ?Sized + Message,
73 NewItemIdentifierType: ?Sized + Message,
74 >(
75 &self,
76 ) -> &NSTableViewDiffableDataSource<NewSectionIdentifierType, NewItemIdentifierType> {
77 unsafe { &*((self as *const Self).cast()) }
78 }
79}
80
81extern_conformance!(
82 unsafe impl<SectionIdentifierType: ?Sized, ItemIdentifierType: ?Sized> NSObjectProtocol
83 for NSTableViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType>
84 {
85 }
86);
87
88#[cfg(feature = "NSTableView")]
89extern_conformance!(
90 unsafe impl<SectionIdentifierType: ?Sized, ItemIdentifierType: ?Sized> NSTableViewDataSource
91 for NSTableViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType>
92 {
93 }
94);
95
96impl<SectionIdentifierType: Message, ItemIdentifierType: Message>
97 NSTableViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType>
98{
99 extern_methods!(
100 #[cfg(all(
101 feature = "NSControl",
102 feature = "NSResponder",
103 feature = "NSTableColumn",
104 feature = "NSTableView",
105 feature = "NSView",
106 feature = "block2"
107 ))]
108 #[unsafe(method(initWithTableView:cellProvider:))]
112 #[unsafe(method_family = init)]
113 pub unsafe fn initWithTableView_cellProvider(
114 this: Allocated<Self>,
115 table_view: &NSTableView,
116 cell_provider: NSTableViewDiffableDataSourceCellProvider,
117 ) -> Retained<Self>;
118
119 #[unsafe(method(init))]
120 #[unsafe(method_family = init)]
121 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
122
123 #[unsafe(method(new))]
124 #[unsafe(method_family = new)]
125 pub unsafe fn new() -> Retained<Self>;
126
127 #[cfg(feature = "NSDiffableDataSource")]
128 #[unsafe(method(snapshot))]
129 #[unsafe(method_family = none)]
130 pub fn snapshot(
131 &self,
132 ) -> Retained<NSDiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType>>;
133
134 #[cfg(feature = "NSDiffableDataSource")]
135 #[unsafe(method(applySnapshot:animatingDifferences:))]
136 #[unsafe(method_family = none)]
137 pub fn applySnapshot_animatingDifferences(
138 &self,
139 snapshot: &NSDiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType>,
140 animating_differences: bool,
141 );
142
143 #[cfg(all(feature = "NSDiffableDataSource", feature = "block2"))]
144 #[unsafe(method(applySnapshot:animatingDifferences:completion:))]
145 #[unsafe(method_family = none)]
146 pub fn applySnapshot_animatingDifferences_completion(
147 &self,
148 snapshot: &NSDiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType>,
149 animating_differences: bool,
150 completion: Option<&block2::DynBlock<dyn Fn()>>,
151 );
152
153 #[unsafe(method(itemIdentifierForRow:))]
154 #[unsafe(method_family = none)]
155 pub fn itemIdentifierForRow(&self, row: NSInteger) -> Option<Retained<ItemIdentifierType>>;
156
157 #[unsafe(method(rowForItemIdentifier:))]
158 #[unsafe(method_family = none)]
159 pub fn rowForItemIdentifier(&self, identifier: &ItemIdentifierType) -> NSInteger;
160
161 #[unsafe(method(sectionIdentifierForRow:))]
162 #[unsafe(method_family = none)]
163 pub fn sectionIdentifierForRow(
164 &self,
165 row: NSInteger,
166 ) -> Option<Retained<SectionIdentifierType>>;
167
168 #[unsafe(method(rowForSectionIdentifier:))]
169 #[unsafe(method_family = none)]
170 pub fn rowForSectionIdentifier(&self, identifier: &SectionIdentifierType) -> NSInteger;
171
172 #[cfg(all(
173 feature = "NSControl",
174 feature = "NSResponder",
175 feature = "NSTableRowView",
176 feature = "NSTableView",
177 feature = "NSView",
178 feature = "block2"
179 ))]
180 #[unsafe(method(rowViewProvider))]
185 #[unsafe(method_family = none)]
186 pub unsafe fn rowViewProvider(
187 &self,
188 mtm: MainThreadMarker,
189 ) -> NSTableViewDiffableDataSourceRowProvider;
190
191 #[cfg(all(
192 feature = "NSControl",
193 feature = "NSResponder",
194 feature = "NSTableRowView",
195 feature = "NSTableView",
196 feature = "NSView",
197 feature = "block2"
198 ))]
199 #[unsafe(method(setRowViewProvider:))]
207 #[unsafe(method_family = none)]
208 pub unsafe fn setRowViewProvider(
209 &self,
210 row_view_provider: NSTableViewDiffableDataSourceRowProvider,
211 );
212
213 #[cfg(all(
214 feature = "NSControl",
215 feature = "NSResponder",
216 feature = "NSTableView",
217 feature = "NSView",
218 feature = "block2"
219 ))]
220 #[unsafe(method(sectionHeaderViewProvider))]
225 #[unsafe(method_family = none)]
226 pub unsafe fn sectionHeaderViewProvider(
227 &self,
228 mtm: MainThreadMarker,
229 ) -> NSTableViewDiffableDataSourceSectionHeaderViewProvider;
230
231 #[cfg(all(
232 feature = "NSControl",
233 feature = "NSResponder",
234 feature = "NSTableView",
235 feature = "NSView",
236 feature = "block2"
237 ))]
238 #[unsafe(method(setSectionHeaderViewProvider:))]
246 #[unsafe(method_family = none)]
247 pub unsafe fn setSectionHeaderViewProvider(
248 &self,
249 section_header_view_provider: NSTableViewDiffableDataSourceSectionHeaderViewProvider,
250 );
251
252 #[cfg(feature = "NSTableView")]
253 #[unsafe(method(defaultRowAnimation))]
254 #[unsafe(method_family = none)]
255 pub fn defaultRowAnimation(&self) -> NSTableViewAnimationOptions;
256
257 #[cfg(feature = "NSTableView")]
258 #[unsafe(method(setDefaultRowAnimation:))]
260 #[unsafe(method_family = none)]
261 pub fn setDefaultRowAnimation(&self, default_row_animation: NSTableViewAnimationOptions);
262 );
263}