Skip to content

Commit 20bb42b

Browse files
authored
[AppKit] Improve and simplify the manually bound constructors for NSBitmapImageRep slightly. (#22676)
Improve and simplify the manually bound constructors for NSBitmapImageRep by using the same pattern we use elsewhere for manually bound constructors. Also fix a few nullability issues.
1 parent 19dc1a4 commit 20bb42b

4 files changed

Lines changed: 25 additions & 31 deletions

File tree

src/AppKit/NSBitmapImageRep.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
namespace AppKit {
3333

3434
public partial class NSBitmapImageRep {
35-
static IntPtr selInitForIncrementalLoad = Selector.GetHandle ("initForIncrementalLoad");
35+
static string selInitForIncrementalLoad = "initForIncrementalLoad";
3636

3737
// Do not actually export because NSObjectFlag is not exportable.
3838
// The Objective C method already exists. This is just to allow
@@ -41,24 +41,21 @@ public partial class NSBitmapImageRep {
4141
private NSBitmapImageRep (NSObjectFlag a, NSObjectFlag b) : base (a)
4242
{
4343
if (IsDirectBinding) {
44-
Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSend (this.Handle, selInitForIncrementalLoad);
44+
InitializeHandle (ObjCRuntime.Messaging.IntPtr_objc_msgSend (this.Handle, Selector.GetHandle (selInitForIncrementalLoad)), selInitForIncrementalLoad);
4545
} else {
46-
Handle = ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper (this.SuperHandle, selInitForIncrementalLoad);
46+
InitializeHandle (ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper (this.SuperHandle, Selector.GetHandle (selInitForIncrementalLoad)), selInitForIncrementalLoad);
4747
}
4848
}
4949

50-
/// <param name="storageType">To be added.</param>
51-
/// <summary>To be added.</summary>
52-
/// <returns>To be added.</returns>
53-
/// <remarks>To be added.</remarks>
54-
public NSData RepresentationUsingTypeProperties (NSBitmapImageFileType storageType)
50+
/// <summary>Convert the bitmap to a specific file format.</summary>
51+
/// <param name="storageType">The target filetype for the bitmap image.</param>
52+
/// <returns>An <see cref="NSData" /> with the data of the bitmap stored as the specified file type.</returns>
53+
public NSData? RepresentationUsingTypeProperties (NSBitmapImageFileType storageType)
5554
{
56-
return RepresentationUsingTypeProperties (storageType, null);
55+
return RepresentationUsingTypeProperties (storageType, new NSDictionary ());
5756
}
5857

59-
/// <summary>To be added.</summary>
60-
/// <returns>To be added.</returns>
61-
/// <remarks>To be added.</remarks>
58+
/// <summary>Create a new <see cref="NSBitmapImageRep" /> that for incremental loading.</summary>
6259
public static NSBitmapImageRep IncrementalLoader ()
6360
{
6461
return new NSBitmapImageRep (NSObjectFlag.Empty, NSObjectFlag.Empty);

src/appkit.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,6 +2102,7 @@ NativeHandle Constructor (IntPtr planes, nint width, nint height, nint bps, nint
21022102
[Export ("imageRepsWithData:")]
21032103
NSImageRep [] ImageRepsWithData (NSData data);
21042104

2105+
[return: NullAllowed]
21052106
[Static]
21062107
[Export ("imageRepWithData:")]
21072108
NSImageRep ImageRepFromData (NSData data);
@@ -2145,16 +2146,20 @@ NativeHandle Constructor (IntPtr planes, nint width, nint height, nint bps, nint
21452146
[Export ("setCompression:factor:")]
21462147
void SetCompressionFactor (NSTiffCompression compression, float /* float, not CGFloat */ factor);
21472148

2149+
[NullAllowed]
21482150
[Export ("TIFFRepresentation")]
21492151
NSData TiffRepresentation { get; }
21502152

2153+
[return: NullAllowed]
21512154
[Export ("TIFFRepresentationUsingCompression:factor:")]
21522155
NSData TiffRepresentationUsingCompressionFactor (NSTiffCompression comp, float /* float, not CGFloat */ factor);
21532156

2157+
[return: NullAllowed]
21542158
[Static]
21552159
[Export ("TIFFRepresentationOfImageRepsInArray:")]
21562160
NSData ImagesAsTiff (NSImageRep [] imageReps);
21572161

2162+
[return: NullAllowed]
21582163
[Static]
21592164
[Export ("TIFFRepresentationOfImageRepsInArray:usingCompression:factor:")]
21602165
NSData ImagesAsTiff (NSImageRep [] imageReps, NSTiffCompression comp, float /* float, not CGFloat */ factor);
@@ -2164,6 +2169,7 @@ NativeHandle Constructor (IntPtr planes, nint width, nint height, nint bps, nint
21642169
//[Export ("getTIFFCompressionTypes:count:")]
21652170
//void GetTiffCompressionTypes (const NSTIFFCompression list, int numTypes);
21662171

2172+
[return: NullAllowed]
21672173
[Static]
21682174
[Export ("localizedNameForTIFFCompressionType:")]
21692175
string LocalizedNameForTiffCompressionType (NSTiffCompression compression);
@@ -2172,14 +2178,15 @@ NativeHandle Constructor (IntPtr planes, nint width, nint height, nint bps, nint
21722178
bool CanBeCompressedUsing (NSTiffCompression compression);
21732179

21742180
[Export ("colorizeByMappingGray:toColor:blackMapping:whiteMapping:")]
2175-
void Colorize (nfloat midPoint, NSColor midPointColor, NSColor shadowColor, NSColor lightColor);
2181+
void Colorize (nfloat midPoint, [NullAllowed] NSColor midPointColor, [NullAllowed] NSColor shadowColor, [NullAllowed] NSColor lightColor);
21762182

21772183
[Export ("incrementalLoadFromData:complete:")]
21782184
nint IncrementalLoad (NSData data, bool complete);
21792185

21802186
[Export ("setColor:atX:y:")]
21812187
void SetColorAt (NSColor color, nint x, nint y);
21822188

2189+
[return: NullAllowed]
21832190
[Export ("colorAtX:y:")]
21842191
NSColor ColorAt (nint x, nint y);
21852192

@@ -2189,20 +2196,24 @@ NativeHandle Constructor (IntPtr planes, nint width, nint height, nint bps, nint
21892196
//[Export ("setPixel:atX:y:")]
21902197
//void SetPixel (int[] p, int x, int y);
21912198

2199+
[NullAllowed]
21922200
[Export ("CGImage")]
21932201
CGImage CGImage { get; }
21942202

21952203
[Export ("colorSpace")]
21962204
NSColorSpace ColorSpace { get; }
21972205

2206+
[return: NullAllowed]
21982207
[Export ("bitmapImageRepByConvertingToColorSpace:renderingIntent:")]
21992208
NSBitmapImageRep ConvertingToColorSpace (NSColorSpace targetSpace, NSColorRenderingIntent renderingIntent);
22002209

2210+
[return: NullAllowed]
22012211
[Export ("bitmapImageRepByRetaggingWithColorSpace:")]
22022212
NSBitmapImageRep RetaggedWithColorSpace (NSColorSpace newSpace);
22032213

2214+
[return: NullAllowed]
22042215
[Export ("representationUsingType:properties:")]
2205-
NSData RepresentationUsingTypeProperties (NSBitmapImageFileType storageType, [NullAllowed] NSDictionary properties);
2216+
NSData RepresentationUsingTypeProperties (NSBitmapImageFileType storageType, NSDictionary properties);
22062217

22072218
/// <summary>To be added.</summary>
22082219
/// <value>To be added.</value>

tests/cecil-tests/SetHandleTest.KnownFailures.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace Cecil.Tests {
66
public partial class SetHandleTest {
77
static HashSet<string> knownFailuresNobodyCallsHandleSetter = new HashSet<string> {
88
"AddressBook.ABGroup::.ctor(AddressBook.ABRecord)",
9-
"AppKit.NSBitmapImageRep::.ctor(Foundation.NSObjectFlag,Foundation.NSObjectFlag)",
109
"AppKit.NSOpenGLPixelFormat::.ctor(AppKit.NSOpenGLPixelFormatAttribute[])",
1110
"AppKit.NSOpenGLPixelFormat::.ctor(System.Object[])",
1211
"CoreFoundation.CFMutableString::.ctor(CoreFoundation.CFString,System.IntPtr)",

tests/xtro-sharpie/api-annotations-dotnet/macOS-AppKit.ignore

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@
212212
!missing-null-allowed! 'AppKit.INSPasteboardWriting AppKit.NSTableViewDataSource::GetPasteboardWriterForRow(AppKit.NSTableView,System.IntPtr)' is missing an [NullAllowed] on return type
213213
!missing-null-allowed! 'AppKit.INSSharingServiceDelegate AppKit.NSSharingServicePickerDelegate::DelegateForSharingService(AppKit.NSSharingServicePicker,AppKit.NSSharingService)' is missing an [NullAllowed] on return type
214214
!missing-null-allowed! 'AppKit.NSAppearance AppKit.NSAppearance::GetAppearance(Foundation.NSString)' is missing an [NullAllowed] on return type
215-
!missing-null-allowed! 'AppKit.NSBitmapImageRep AppKit.NSBitmapImageRep::ConvertingToColorSpace(AppKit.NSColorSpace,AppKit.NSColorRenderingIntent)' is missing an [NullAllowed] on return type
216-
!missing-null-allowed! 'AppKit.NSBitmapImageRep AppKit.NSBitmapImageRep::RetaggedWithColorSpace(AppKit.NSColorSpace)' is missing an [NullAllowed] on return type
217215
!missing-null-allowed! 'AppKit.NSButton AppKit.NSAlert::get_SuppressionButton()' is missing an [NullAllowed] on return type
218216
!missing-null-allowed! 'AppKit.NSButton AppKit.NSWindow::StandardWindowButton(AppKit.NSWindowButton)' is missing an [NullAllowed] on return type
219217
!missing-null-allowed! 'AppKit.NSButton AppKit.NSWindow::StandardWindowButton(AppKit.NSWindowButton,AppKit.NSWindowStyle)' is missing an [NullAllowed] on return type
@@ -228,7 +226,6 @@
228226
!missing-null-allowed! 'AppKit.NSCell AppKit.NSTableViewDelegate::GetDataCell(AppKit.NSTableView,AppKit.NSTableColumn,System.IntPtr)' is missing an [NullAllowed] on parameter #1
229227
!missing-null-allowed! 'AppKit.NSCell AppKit.NSTableViewDelegate::GetDataCell(AppKit.NSTableView,AppKit.NSTableColumn,System.IntPtr)' is missing an [NullAllowed] on return type
230228
!missing-null-allowed! 'AppKit.NSCell[] AppKit.NSBrowser::SelectedCells()' is missing an [NullAllowed] on return type
231-
!missing-null-allowed! 'AppKit.NSColor AppKit.NSBitmapImageRep::ColorAt(System.IntPtr,System.IntPtr)' is missing an [NullAllowed] on return type
232229
!missing-null-allowed! 'AppKit.NSColor AppKit.NSBrowserCell::HighlightColorInView(AppKit.NSView)' is missing an [NullAllowed] on return type
233230
!missing-null-allowed! 'AppKit.NSColor AppKit.NSColor::BlendedColor(System.Runtime.InteropServices.NFloat,AppKit.NSColor)' is missing an [NullAllowed] on return type
234231
!missing-null-allowed! 'AppKit.NSColor AppKit.NSColor::FromCatalogName(System.String,System.String)' is missing an [NullAllowed] on return type
@@ -295,7 +292,6 @@
295292
!missing-null-allowed! 'AppKit.NSImage AppKit.NSTableView::GetIndicatorImage(AppKit.NSTableColumn)' is missing an [NullAllowed] on return type
296293
!missing-null-allowed! 'AppKit.NSImage AppKit.NSWorkspace::IconForFiles(System.String[])' is missing an [NullAllowed] on return type
297294
!missing-null-allowed! 'AppKit.NSImage Foundation.NSBundle::ImageForResource(System.String)' is missing an [NullAllowed] on return type
298-
!missing-null-allowed! 'AppKit.NSImageRep AppKit.NSBitmapImageRep::ImageRepFromData(Foundation.NSData)' is missing an [NullAllowed] on return type
299295
!missing-null-allowed! 'AppKit.NSImageRep AppKit.NSImage::BestRepresentation(CoreGraphics.CGRect,AppKit.NSGraphicsContext,Foundation.NSDictionary)' is missing an [NullAllowed] on return type
300296
!missing-null-allowed! 'AppKit.NSImageRep AppKit.NSImageRep::ImageRepFromFile(System.String)' is missing an [NullAllowed] on return type
301297
!missing-null-allowed! 'AppKit.NSImageRep AppKit.NSImageRep::ImageRepFromPasteboard(AppKit.NSPasteboard)' is missing an [NullAllowed] on return type
@@ -410,7 +406,6 @@
410406
!missing-null-allowed! 'AppKit.NSWindow[] AppKit.NSWindowDelegate::CustomWindowsToEnterFullScreen(AppKit.NSWindow)' is missing an [NullAllowed] on return type
411407
!missing-null-allowed! 'AppKit.NSWindow[] AppKit.NSWindowDelegate::CustomWindowsToExitFullScreen(AppKit.NSWindow)' is missing an [NullAllowed] on return type
412408
!missing-null-allowed! 'CoreGraphics.CGColorSpace AppKit.NSColorSpace::get_ColorSpace()' is missing an [NullAllowed] on return type
413-
!missing-null-allowed! 'CoreGraphics.CGImage AppKit.NSBitmapImageRep::get_CGImage()' is missing an [NullAllowed] on return type
414409
!missing-null-allowed! 'CoreGraphics.CGImage AppKit.NSImage::AsCGImage(CoreGraphics.CGRect&,AppKit.NSGraphicsContext,Foundation.NSDictionary)' is missing an [NullAllowed] on return type
415410
!missing-null-allowed! 'CoreGraphics.CGImage AppKit.NSImageRep::AsCGImage(CoreGraphics.CGRect&,AppKit.NSGraphicsContext,Foundation.NSDictionary)' is missing an [NullAllowed] on return type
416411
!missing-null-allowed! 'CoreGraphics.CGPoint AppKit.NSPanGestureRecognizer::TranslationInView(AppKit.NSView)' is missing an [NullAllowed] on parameter #0
@@ -427,11 +422,6 @@
427422
!missing-null-allowed! 'Foundation.NSAttributedString AppKit.NSHelpManager::Context(Foundation.NSObject)' is missing an [NullAllowed] on return type
428423
!missing-null-allowed! 'Foundation.NSAttributedString Foundation.NSBundle::GetContextHelp(System.String)' is missing an [NullAllowed] on return type
429424
!missing-null-allowed! 'Foundation.NSBundle AppKit.NSViewController::get_NibBundle()' is missing an [NullAllowed] on return type
430-
!missing-null-allowed! 'Foundation.NSData AppKit.NSBitmapImageRep::get_TiffRepresentation()' is missing an [NullAllowed] on return type
431-
!missing-null-allowed! 'Foundation.NSData AppKit.NSBitmapImageRep::ImagesAsTiff(AppKit.NSImageRep[])' is missing an [NullAllowed] on return type
432-
!missing-null-allowed! 'Foundation.NSData AppKit.NSBitmapImageRep::ImagesAsTiff(AppKit.NSImageRep[],AppKit.NSTiffCompression,System.Single)' is missing an [NullAllowed] on return type
433-
!missing-null-allowed! 'Foundation.NSData AppKit.NSBitmapImageRep::RepresentationUsingTypeProperties(AppKit.NSBitmapImageFileType,Foundation.NSDictionary)' is missing an [NullAllowed] on return type
434-
!missing-null-allowed! 'Foundation.NSData AppKit.NSBitmapImageRep::TiffRepresentationUsingCompressionFactor(AppKit.NSTiffCompression,System.Single)' is missing an [NullAllowed] on return type
435425
!missing-null-allowed! 'Foundation.NSData AppKit.NSColorSpace::get_ICCProfileData()' is missing an [NullAllowed] on return type
436426
!missing-null-allowed! 'Foundation.NSData AppKit.NSDocument::GetAsData(System.String,Foundation.NSError&)' is missing an [NullAllowed] on return type
437427
!missing-null-allowed! 'Foundation.NSData AppKit.NSImage::AsTiff(AppKit.NSTiffCompression,System.Single)' is missing an [NullAllowed] on return type
@@ -576,7 +566,6 @@
576566
!missing-null-allowed! 'System.IntPtr AppKit.NSPopUpButtonCell::IndexOfItemWithTargetandAction(Foundation.NSObject,ObjCRuntime.Selector)' is missing an [NullAllowed] on parameter #1
577567
!missing-null-allowed! 'System.IntPtr AppKit.NSRuleEditorDelegate::NumberOfChildren(AppKit.NSRuleEditor,Foundation.NSObject,AppKit.NSRuleEditorRowType)' is missing an [NullAllowed] on parameter #1
578568
!missing-null-allowed! 'System.IntPtr AppKit.NSSpellChecker::CountWords(System.String,System.String)' is missing an [NullAllowed] on parameter #1
579-
!missing-null-allowed! 'System.String AppKit.NSBitmapImageRep::LocalizedNameForTiffCompressionType(AppKit.NSTiffCompression)' is missing an [NullAllowed] on return type
580569
!missing-null-allowed! 'System.String AppKit.NSBrowser::ColumnTitle(System.IntPtr)' is missing an [NullAllowed] on return type
581570
!missing-null-allowed! 'System.String AppKit.NSBrowserDelegate::ColumnTitle(AppKit.NSBrowser,System.IntPtr)' is missing an [NullAllowed] on return type
582571
!missing-null-allowed! 'System.String AppKit.NSColorList::get_Name()' is missing an [NullAllowed] on return type
@@ -1017,7 +1006,6 @@
10171006
!missing-null-allowed! 'System.Void AppKit.NSWorkspace::RecycleUrls(Foundation.NSArray,AppKit.NSWorkspaceUrlHandler)' is missing an [NullAllowed] on parameter #1
10181007
!missing-null-allowed! 'System.Void Foundation.NSFileWrapper::set_Icon(AppKit.NSImage)' is missing an [NullAllowed] on parameter #0
10191008

1020-
!extra-null-allowed! 'Foundation.NSData AppKit.NSBitmapImageRep::RepresentationUsingTypeProperties(AppKit.NSBitmapImageFileType,Foundation.NSDictionary)' has a extraneous [NullAllowed] on parameter #1
10211009
!extra-null-allowed! 'Foundation.NSData Foundation.NSAttributedString::GetDocFormat(Foundation.NSRange,Foundation.NSDictionary)' has a extraneous [NullAllowed] on parameter #1
10221010
!extra-null-allowed! 'Foundation.NSData Foundation.NSAttributedString::GetRtf(Foundation.NSRange,Foundation.NSDictionary)' has a extraneous [NullAllowed] on parameter #1
10231011
!extra-null-allowed! 'Foundation.NSData Foundation.NSAttributedString::GetRtfd(Foundation.NSRange,Foundation.NSDictionary)' has a extraneous [NullAllowed] on parameter #1
@@ -1052,9 +1040,6 @@
10521040
!missing-null-allowed! 'System.String[] AppKit.NSSpellChecker::CompletionsForPartialWordRange(Foundation.NSRange,System.String,System.String,System.IntPtr)' is missing an [NullAllowed] on parameter #2
10531041
!missing-null-allowed! 'System.String[] AppKit.NSSpellChecker::GuessesForWordRange(Foundation.NSRange,System.String,System.String,System.IntPtr)' is missing an [NullAllowed] on parameter #2
10541042
!missing-null-allowed! 'System.Void AppKit.NSApplication::DiscardEvents(System.UIntPtr,AppKit.NSEvent)' is missing an [NullAllowed] on parameter #1
1055-
!missing-null-allowed! 'System.Void AppKit.NSBitmapImageRep::Colorize(System.Runtime.InteropServices.NFloat,AppKit.NSColor,AppKit.NSColor,AppKit.NSColor)' is missing an [NullAllowed] on parameter #1
1056-
!missing-null-allowed! 'System.Void AppKit.NSBitmapImageRep::Colorize(System.Runtime.InteropServices.NFloat,AppKit.NSColor,AppKit.NSColor,AppKit.NSColor)' is missing an [NullAllowed] on parameter #2
1057-
!missing-null-allowed! 'System.Void AppKit.NSBitmapImageRep::Colorize(System.Runtime.InteropServices.NFloat,AppKit.NSColor,AppKit.NSColor,AppKit.NSColor)' is missing an [NullAllowed] on parameter #3
10581043
!missing-null-allowed! 'System.Void AppKit.NSCell::EditWithFrame(CoreGraphics.CGRect,AppKit.NSView,AppKit.NSText,Foundation.NSObject,AppKit.NSEvent)' is missing an [NullAllowed] on parameter #4
10591044
!missing-null-allowed! 'System.Void AppKit.NSDocumentController::ReviewUnsavedDocuments(System.String,System.Boolean,Foundation.NSObject,ObjCRuntime.Selector,System.IntPtr)' is missing an [NullAllowed] on parameter #2
10601045
!missing-null-allowed! 'System.Void AppKit.NSDocumentController::ReviewUnsavedDocuments(System.String,System.Boolean,Foundation.NSObject,ObjCRuntime.Selector,System.IntPtr)' is missing an [NullAllowed] on parameter #3
@@ -1093,10 +1078,12 @@
10931078
## 42814697 NSViewLayerContentScaleDelegate defined in header but never used
10941079
!missing-protocol! NSViewLayerContentScaleDelegate not bound
10951080

1081+
## Bound manually because the signature conflicts with the default constructor
1082+
!missing-selector! NSBitmapImageRep::initForIncrementalLoad not bound
1083+
10961084
## recent fox top xtro reported additional missing API (to be reviewed)
10971085
!missing-selector! +NSBezierPath::bezierPath not bound
10981086
!missing-selector! +NSPDFPanel::panel not bound
1099-
!missing-selector! NSBitmapImageRep::initForIncrementalLoad not bound
11001087
!missing-selector! NSColor::init not bound
11011088
!missing-selector! NSObjectController::defaultFetchRequest not bound
11021089
!missing-selector! NSPasteboard::readFileWrapper not bound

0 commit comments

Comments
 (0)